blob: 5f88fc4abeab0daac8c41bd59da4023d3dca52d3 [file] [log] [blame]
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +00001/*
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 Hailfingerc3129202009-05-09 00:54:55 +000021#include <string.h>
22#include <stdlib.h>
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000023#include <ctype.h>
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000024#include <sys/types.h>
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000025#include "flash.h"
Carl-Daniel Hailfinger1b0ba892010-06-20 10:58:32 +000026#include "chipdrivers.h"
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000027
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000028static void tolower_string(char *str)
29{
30 for (; *str != '\0'; str++)
31 *str = (char)tolower((unsigned char)*str);
32}
33
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000034int dummy_init(void)
35{
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000036 char *bustext = NULL;
37
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000038 msg_pspew("%s\n", __func__);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000039
Carl-Daniel Hailfinger2b6dcb32010-07-08 10:13:37 +000040 bustext = extract_programmer_param("bus");
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000041 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
42 if (!bustext)
43 bustext = strdup("parallel+lpc+fwh+spi");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000044 /* Convert the parameters to lowercase. */
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000045 tolower_string(bustext);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000046
47 buses_supported = CHIP_BUSTYPE_NONE;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000048 if (strstr(bustext, "parallel")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000049 buses_supported |= CHIP_BUSTYPE_PARALLEL;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000050 msg_pdbg("Enabling support for %s flash.\n", "parallel");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000051 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000052 if (strstr(bustext, "lpc")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000053 buses_supported |= CHIP_BUSTYPE_LPC;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000054 msg_pdbg("Enabling support for %s flash.\n", "LPC");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000055 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000056 if (strstr(bustext, "fwh")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000057 buses_supported |= CHIP_BUSTYPE_FWH;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000058 msg_pdbg("Enabling support for %s flash.\n", "FWH");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000059 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000060 if (strstr(bustext, "spi")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000061 buses_supported |= CHIP_BUSTYPE_SPI;
62 spi_controller = SPI_CONTROLLER_DUMMY;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000063 msg_pdbg("Enabling support for %s flash.\n", "SPI");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000064 }
65 if (buses_supported == CHIP_BUSTYPE_NONE)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000066 msg_pdbg("Support for all flash bus types disabled.\n");
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +000067 free(bustext);
Uwe Hermanne9d04d42009-06-02 19:54:22 +000068 return 0;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000069}
70
71int dummy_shutdown(void)
72{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000073 msg_pspew("%s\n", __func__);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000074 return 0;
75}
76
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000077void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
78{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000079 msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
80 __func__, descr, (unsigned long)len, phys_addr);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000081 return (void *)phys_addr;
82}
83
84void dummy_unmap(void *virt_addr, size_t len)
85{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000086 msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
87 __func__, (unsigned long)len, virt_addr);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000088}
89
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000090void dummy_chip_writeb(uint8_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000091{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000092 msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000093}
94
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000095void dummy_chip_writew(uint16_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000096{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000097 msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000098}
99
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000100void dummy_chip_writel(uint32_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000101{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000102 msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000103}
104
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000105void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
106{
107 size_t i;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000108 msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
109 __func__, addr, (unsigned long)len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000110 for (i = 0; i < len; i++) {
111 if ((i % 16) == 0)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000112 msg_pspew("\n");
113 msg_pspew("%02x ", buf[i]);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000114 }
115}
116
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000117uint8_t dummy_chip_readb(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000118{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000119 msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000120 return 0xff;
121}
122
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000123uint16_t dummy_chip_readw(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000124{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000125 msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000126 return 0xffff;
127}
128
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000129uint32_t dummy_chip_readl(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000130{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000131 msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000132 return 0xffffffff;
133}
134
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000135void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len)
136{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000137 msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
138 __func__, addr, (unsigned long)len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000139 memset(buf, 0xff, len);
140 return;
141}
142
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000143int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000144 const unsigned char *writearr, unsigned char *readarr)
145{
146 int i;
147
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000148 msg_pspew("%s:", __func__);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000149
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000150 msg_pspew(" writing %u bytes:", writecnt);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000151 for (i = 0; i < writecnt; i++)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000152 msg_pspew(" 0x%02x", writearr[i]);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000153
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000154 msg_pspew(" reading %u bytes:", readcnt);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000155 for (i = 0; i < readcnt; i++) {
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000156 msg_pspew(" 0xff");
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000157 readarr[i] = 0xff;
158 }
159
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000160 msg_pspew("\n");
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000161 return 0;
162}
Carl-Daniel Hailfinger1b0ba892010-06-20 10:58:32 +0000163
164int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
165{
166 /* Maximum read length is unlimited, use 64kB. */
167 return spi_read_chunked(flash, buf, start, len, 64 * 1024);
168}
169