blob: f64691d8faad8bca49a2acfa7fff656d99658ce1 [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 <fcntl.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <errno.h>
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000028#include "flash.h"
29
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000030char *dummytype = NULL;
31
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000032int dummy_init(void)
33{
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000034 int i;
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000035 printf_debug("%s\n", __func__);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000036
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);
Uwe Hermanne9d04d42009-06-02 19:54:22 +000069 return 0;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000070}
71
72int dummy_shutdown(void)
73{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000074 printf_debug("%s\n", __func__);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000075 return 0;
76}
77
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000078void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
79{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000080 printf_debug("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000081 __func__, descr, (unsigned long)len, phys_addr);
82 return (void *)phys_addr;
83}
84
85void dummy_unmap(void *virt_addr, size_t len)
86{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000087 printf_debug("%s: Unmapping 0x%lx bytes at %p\n",
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000088 __func__, (unsigned long)len, virt_addr);
89}
90
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000091void dummy_chip_writeb(uint8_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%02x\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_writew(uint16_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%04x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000099}
100
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000101void dummy_chip_writel(uint32_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000102{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000103 printf_debug("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000104}
105
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000106uint8_t dummy_chip_readb(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000107{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000108 printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000109 return 0xff;
110}
111
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000112uint16_t dummy_chip_readw(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000113{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000114 printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000115 return 0xffff;
116}
117
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000118uint32_t dummy_chip_readl(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000119{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000120 printf_debug("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000121 return 0xffffffff;
122}
123
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000124int 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}