Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 21 | #include <string.h> |
| 22 | #include <stdlib.h> |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 23 | #include <ctype.h> |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 24 | #include <sys/types.h> |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 25 | #include "flash.h" |
| 26 | |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 27 | char *dummytype = NULL; |
| 28 | |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 29 | int dummy_init(void) |
| 30 | { |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 31 | int i; |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 32 | printf_debug("%s\n", __func__); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 33 | |
| 34 | /* "all" is equivalent to specifying no type. */ |
Carl-Daniel Hailfinger | 945d26a | 2009-06-05 17:04:37 +0000 | [diff] [blame] | 35 | if (dummytype && (!strcmp(dummytype, "all"))) { |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 36 | free(dummytype); |
| 37 | dummytype = NULL; |
| 38 | } |
| 39 | if (!dummytype) |
| 40 | dummytype = strdup("parallel,lpc,fwh,spi"); |
| 41 | /* Convert the parameters to lowercase. */ |
| 42 | for (i = 0; dummytype[i] != '\0'; i++) |
| 43 | dummytype[i] = (char)tolower(dummytype[i]); |
| 44 | |
| 45 | buses_supported = CHIP_BUSTYPE_NONE; |
| 46 | if (strstr(dummytype, "parallel")) { |
| 47 | buses_supported |= CHIP_BUSTYPE_PARALLEL; |
| 48 | printf_debug("Enabling support for %s flash.\n", "parallel"); |
| 49 | } |
| 50 | if (strstr(dummytype, "lpc")) { |
| 51 | buses_supported |= CHIP_BUSTYPE_LPC; |
| 52 | printf_debug("Enabling support for %s flash.\n", "LPC"); |
| 53 | } |
| 54 | if (strstr(dummytype, "fwh")) { |
| 55 | buses_supported |= CHIP_BUSTYPE_FWH; |
| 56 | printf_debug("Enabling support for %s flash.\n", "FWH"); |
| 57 | } |
| 58 | if (strstr(dummytype, "spi")) { |
| 59 | buses_supported |= CHIP_BUSTYPE_SPI; |
| 60 | spi_controller = SPI_CONTROLLER_DUMMY; |
| 61 | printf_debug("Enabling support for %s flash.\n", "SPI"); |
| 62 | } |
| 63 | if (buses_supported == CHIP_BUSTYPE_NONE) |
| 64 | printf_debug("Support for all flash bus types disabled.\n"); |
| 65 | free(dummytype); |
Uwe Hermann | e9d04d4 | 2009-06-02 19:54:22 +0000 | [diff] [blame] | 66 | return 0; |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | int dummy_shutdown(void) |
| 70 | { |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 71 | printf_debug("%s\n", __func__); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 75 | void *dummy_map(const char *descr, unsigned long phys_addr, size_t len) |
| 76 | { |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 77 | printf_debug("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n", |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 78 | __func__, descr, (unsigned long)len, phys_addr); |
| 79 | return (void *)phys_addr; |
| 80 | } |
| 81 | |
| 82 | void dummy_unmap(void *virt_addr, size_t len) |
| 83 | { |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 84 | printf_debug("%s: Unmapping 0x%lx bytes at %p\n", |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 85 | __func__, (unsigned long)len, virt_addr); |
| 86 | } |
| 87 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 88 | void dummy_chip_writeb(uint8_t val, chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 89 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 90 | printf_debug("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 93 | void dummy_chip_writew(uint16_t val, chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 94 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 95 | printf_debug("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 98 | void dummy_chip_writel(uint32_t val, chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 99 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 100 | printf_debug("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 103 | void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len) |
| 104 | { |
| 105 | size_t i; |
| 106 | printf_debug("%s: addr=0x%lx, len=0x%08lx, writing data (hex):", |
| 107 | __func__, addr, (unsigned long)len); |
| 108 | for (i = 0; i < len; i++) { |
| 109 | if ((i % 16) == 0) |
| 110 | printf_debug("\n"); |
| 111 | printf_debug("%02x ", buf[i]) |
| 112 | } |
| 113 | } |
| 114 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 115 | uint8_t dummy_chip_readb(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 116 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 117 | printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 118 | return 0xff; |
| 119 | } |
| 120 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 121 | uint16_t dummy_chip_readw(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 122 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 123 | printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 124 | return 0xffff; |
| 125 | } |
| 126 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 127 | uint32_t dummy_chip_readl(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 128 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 129 | printf_debug("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 130 | return 0xffffffff; |
| 131 | } |
| 132 | |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 133 | void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len) |
| 134 | { |
| 135 | printf_debug("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n", |
| 136 | __func__, addr, (unsigned long)len); |
| 137 | memset(buf, 0xff, len); |
| 138 | return; |
| 139 | } |
| 140 | |
Carl-Daniel Hailfinger | d047829 | 2009-07-10 21:08:55 +0000 | [diff] [blame] | 141 | int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 142 | const unsigned char *writearr, unsigned char *readarr) |
| 143 | { |
| 144 | int i; |
| 145 | |
| 146 | printf_debug("%s:", __func__); |
| 147 | |
| 148 | printf_debug(" writing %u bytes:", writecnt); |
| 149 | for (i = 0; i < writecnt; i++) |
| 150 | printf_debug(" 0x%02x", writearr[i]); |
| 151 | |
| 152 | printf_debug(" reading %u bytes:", readcnt); |
| 153 | for (i = 0; i < readcnt; i++) { |
| 154 | printf_debug(" 0xff"); |
| 155 | readarr[i] = 0xff; |
| 156 | } |
| 157 | |
| 158 | printf_debug("\n"); |
| 159 | return 0; |
| 160 | } |