blob: 903f88bbf95e6c9e1c51c6cbca559719ad869050 [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"
26
27int dummy_init(void)
28{
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000029 int i;
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000030 printf_debug("%s\n", __func__);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000031
32 /* "all" is equivalent to specifying no type. */
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000033 if (programmer_param && (!strcmp(programmer_param, "all"))) {
34 free(programmer_param);
35 programmer_param = NULL;
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000036 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000037 if (!programmer_param)
38 programmer_param = strdup("parallel,lpc,fwh,spi");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000039 /* Convert the parameters to lowercase. */
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000040 for (i = 0; programmer_param[i] != '\0'; i++)
41 programmer_param[i] = (char)tolower(programmer_param[i]);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000042
43 buses_supported = CHIP_BUSTYPE_NONE;
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000044 if (strstr(programmer_param, "parallel")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000045 buses_supported |= CHIP_BUSTYPE_PARALLEL;
46 printf_debug("Enabling support for %s flash.\n", "parallel");
47 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000048 if (strstr(programmer_param, "lpc")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000049 buses_supported |= CHIP_BUSTYPE_LPC;
50 printf_debug("Enabling support for %s flash.\n", "LPC");
51 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000052 if (strstr(programmer_param, "fwh")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000053 buses_supported |= CHIP_BUSTYPE_FWH;
54 printf_debug("Enabling support for %s flash.\n", "FWH");
55 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000056 if (strstr(programmer_param, "spi")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000057 buses_supported |= CHIP_BUSTYPE_SPI;
58 spi_controller = SPI_CONTROLLER_DUMMY;
59 printf_debug("Enabling support for %s flash.\n", "SPI");
60 }
61 if (buses_supported == CHIP_BUSTYPE_NONE)
62 printf_debug("Support for all flash bus types disabled.\n");
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000063 free(programmer_param);
Uwe Hermanne9d04d42009-06-02 19:54:22 +000064 return 0;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000065}
66
67int dummy_shutdown(void)
68{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000069 printf_debug("%s\n", __func__);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000070 return 0;
71}
72
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000073void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
74{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000075 printf_debug("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000076 __func__, descr, (unsigned long)len, phys_addr);
77 return (void *)phys_addr;
78}
79
80void dummy_unmap(void *virt_addr, size_t len)
81{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000082 printf_debug("%s: Unmapping 0x%lx bytes at %p\n",
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000083 __func__, (unsigned long)len, virt_addr);
84}
85
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000086void dummy_chip_writeb(uint8_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000087{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000088 printf_debug("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000089}
90
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000091void dummy_chip_writew(uint16_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000092{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000093 printf_debug("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000094}
95
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000096void dummy_chip_writel(uint32_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000097{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000098 printf_debug("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000099}
100
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000101void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
102{
103 size_t i;
104 printf_debug("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
105 __func__, addr, (unsigned long)len);
106 for (i = 0; i < len; i++) {
107 if ((i % 16) == 0)
108 printf_debug("\n");
109 printf_debug("%02x ", buf[i])
110 }
111}
112
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000113uint8_t dummy_chip_readb(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000114{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000115 printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000116 return 0xff;
117}
118
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000119uint16_t dummy_chip_readw(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000120{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000121 printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000122 return 0xffff;
123}
124
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000125uint32_t dummy_chip_readl(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000126{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000127 printf_debug("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000128 return 0xffffffff;
129}
130
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000131void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len)
132{
133 printf_debug("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
134 __func__, addr, (unsigned long)len);
135 memset(buf, 0xff, len);
136 return;
137}
138
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000139int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000140 const unsigned char *writearr, unsigned char *readarr)
141{
142 int i;
143
144 printf_debug("%s:", __func__);
145
146 printf_debug(" writing %u bytes:", writecnt);
147 for (i = 0; i < writecnt; i++)
148 printf_debug(" 0x%02x", writearr[i]);
149
150 printf_debug(" reading %u bytes:", readcnt);
151 for (i = 0; i < readcnt; i++) {
152 printf_debug(" 0xff");
153 readarr[i] = 0xff;
154 }
155
156 printf_debug("\n");
157 return 0;
158}