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. */ |
| 38 | if (!strcmp(dummytype, "all")) { |
| 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); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 69 | return 0; |
| 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 | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 106 | uint8_t dummy_chip_readb(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 107 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 108 | printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 109 | return 0xff; |
| 110 | } |
| 111 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 112 | uint16_t dummy_chip_readw(const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 113 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 114 | printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 115 | return 0xffff; |
| 116 | } |
| 117 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 118 | uint32_t dummy_chip_readl(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 0xffffffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 121 | return 0xffffffff; |
| 122 | } |
| 123 | |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 124 | int dummy_spi_command(unsigned int writecnt, unsigned int readcnt, |
| 125 | const unsigned char *writearr, unsigned char *readarr) |
| 126 | { |
| 127 | int i; |
| 128 | |
| 129 | printf_debug("%s:", __func__); |
| 130 | |
| 131 | printf_debug(" writing %u bytes:", writecnt); |
| 132 | for (i = 0; i < writecnt; i++) |
| 133 | printf_debug(" 0x%02x", writearr[i]); |
| 134 | |
| 135 | printf_debug(" reading %u bytes:", readcnt); |
| 136 | for (i = 0; i < readcnt; i++) { |
| 137 | printf_debug(" 0xff"); |
| 138 | readarr[i] = 0xff; |
| 139 | } |
| 140 | |
| 141 | printf_debug("\n"); |
| 142 | return 0; |
| 143 | } |