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 <fcntl.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <errno.h> |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 28 | #include "flash.h" |
| 29 | |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 30 | char *dummytype = NULL; |
| 31 | |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 32 | int dummy_init(void) |
| 33 | { |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 34 | int i; |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 35 | printf_debug("%s\n", __func__); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 36 | |
| 37 | /* "all" is equivalent to specifying no type. */ |
Carl-Daniel Hailfinger | 945d26a | 2009-06-05 17:04:37 +0000 | [diff] [blame] | 38 | if (dummytype && (!strcmp(dummytype, "all"))) { |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 39 | free(dummytype); |
| 40 | dummytype = NULL; |
| 41 | } |
| 42 | if (!dummytype) |
| 43 | dummytype = strdup("parallel,lpc,fwh,spi"); |
| 44 | /* Convert the parameters to lowercase. */ |
| 45 | for (i = 0; dummytype[i] != '\0'; i++) |
| 46 | dummytype[i] = (char)tolower(dummytype[i]); |
| 47 | |
| 48 | buses_supported = CHIP_BUSTYPE_NONE; |
| 49 | if (strstr(dummytype, "parallel")) { |
| 50 | buses_supported |= CHIP_BUSTYPE_PARALLEL; |
| 51 | printf_debug("Enabling support for %s flash.\n", "parallel"); |
| 52 | } |
| 53 | if (strstr(dummytype, "lpc")) { |
| 54 | buses_supported |= CHIP_BUSTYPE_LPC; |
| 55 | printf_debug("Enabling support for %s flash.\n", "LPC"); |
| 56 | } |
| 57 | if (strstr(dummytype, "fwh")) { |
| 58 | buses_supported |= CHIP_BUSTYPE_FWH; |
| 59 | printf_debug("Enabling support for %s flash.\n", "FWH"); |
| 60 | } |
| 61 | if (strstr(dummytype, "spi")) { |
| 62 | buses_supported |= CHIP_BUSTYPE_SPI; |
| 63 | spi_controller = SPI_CONTROLLER_DUMMY; |
| 64 | printf_debug("Enabling support for %s flash.\n", "SPI"); |
| 65 | } |
| 66 | if (buses_supported == CHIP_BUSTYPE_NONE) |
| 67 | printf_debug("Support for all flash bus types disabled.\n"); |
| 68 | free(dummytype); |
Uwe Hermann | e9d04d4 | 2009-06-02 19:54:22 +0000 | [diff] [blame] | 69 | return 0; |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int dummy_shutdown(void) |
| 73 | { |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 74 | printf_debug("%s\n", __func__); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 78 | void *dummy_map(const char *descr, unsigned long phys_addr, size_t len) |
| 79 | { |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 80 | 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] | 81 | __func__, descr, (unsigned long)len, phys_addr); |
| 82 | return (void *)phys_addr; |
| 83 | } |
| 84 | |
| 85 | void dummy_unmap(void *virt_addr, size_t len) |
| 86 | { |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 87 | printf_debug("%s: Unmapping 0x%lx bytes at %p\n", |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 88 | __func__, (unsigned long)len, virt_addr); |
| 89 | } |
| 90 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 91 | void dummy_chip_writeb(uint8_t val, chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 92 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 93 | 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] | 94 | } |
| 95 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 96 | void dummy_chip_writew(uint16_t val, chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 97 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 98 | 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] | 99 | } |
| 100 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 101 | void dummy_chip_writel(uint32_t val, chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 102 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 103 | 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] | 104 | } |
| 105 | |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 106 | void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len) |
| 107 | { |
| 108 | size_t i; |
| 109 | printf_debug("%s: addr=0x%lx, len=0x%08lx, writing data (hex):", |
| 110 | __func__, addr, (unsigned long)len); |
| 111 | for (i = 0; i < len; i++) { |
| 112 | if ((i % 16) == 0) |
| 113 | printf_debug("\n"); |
| 114 | printf_debug("%02x ", buf[i]) |
| 115 | } |
| 116 | } |
| 117 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 118 | uint8_t dummy_chip_readb(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 119 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 120 | printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 121 | return 0xff; |
| 122 | } |
| 123 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 124 | uint16_t dummy_chip_readw(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 125 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 126 | printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 127 | return 0xffff; |
| 128 | } |
| 129 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 130 | uint32_t dummy_chip_readl(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 131 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 132 | printf_debug("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 133 | return 0xffffffff; |
| 134 | } |
| 135 | |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 136 | void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len) |
| 137 | { |
| 138 | printf_debug("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n", |
| 139 | __func__, addr, (unsigned long)len); |
| 140 | memset(buf, 0xff, len); |
| 141 | return; |
| 142 | } |
| 143 | |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 144 | int dummy_spi_command(unsigned int writecnt, unsigned int readcnt, |
| 145 | const unsigned char *writearr, unsigned char *readarr) |
| 146 | { |
| 147 | int i; |
| 148 | |
| 149 | printf_debug("%s:", __func__); |
| 150 | |
| 151 | printf_debug(" writing %u bytes:", writecnt); |
| 152 | for (i = 0; i < writecnt; i++) |
| 153 | printf_debug(" 0x%02x", writearr[i]); |
| 154 | |
| 155 | printf_debug(" reading %u bytes:", readcnt); |
| 156 | for (i = 0; i < readcnt; i++) { |
| 157 | printf_debug(" 0xff"); |
| 158 | readarr[i] = 0xff; |
| 159 | } |
| 160 | |
| 161 | printf_debug("\n"); |
| 162 | return 0; |
| 163 | } |