blob: 8ebd6959fd0efae7d06bf4d0c679e1d4287e82c0 [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 Hailfinger3ac101c2010-01-09 04:32:23 +000030 msg_pspew("%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++)
Jonathan A. Kollaschd8dfc442010-02-16 00:49:50 +000041 programmer_param[i] =
42 (char)tolower((unsigned char)programmer_param[i]);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000043
44 buses_supported = CHIP_BUSTYPE_NONE;
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000045 if (strstr(programmer_param, "parallel")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000046 buses_supported |= CHIP_BUSTYPE_PARALLEL;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000047 msg_pdbg("Enabling support for %s flash.\n", "parallel");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000048 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000049 if (strstr(programmer_param, "lpc")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000050 buses_supported |= CHIP_BUSTYPE_LPC;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000051 msg_pdbg("Enabling support for %s flash.\n", "LPC");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000052 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000053 if (strstr(programmer_param, "fwh")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000054 buses_supported |= CHIP_BUSTYPE_FWH;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000055 msg_pdbg("Enabling support for %s flash.\n", "FWH");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000056 }
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000057 if (strstr(programmer_param, "spi")) {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000058 buses_supported |= CHIP_BUSTYPE_SPI;
59 spi_controller = SPI_CONTROLLER_DUMMY;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000060 msg_pdbg("Enabling support for %s flash.\n", "SPI");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +000061 }
62 if (buses_supported == CHIP_BUSTYPE_NONE)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000063 msg_pdbg("Support for all flash bus types disabled.\n");
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000064 free(programmer_param);
Uwe Hermanne9d04d42009-06-02 19:54:22 +000065 return 0;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000066}
67
68int dummy_shutdown(void)
69{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000070 msg_pspew("%s\n", __func__);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000071 return 0;
72}
73
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000074void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
75{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000076 msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
77 __func__, descr, (unsigned long)len, phys_addr);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000078 return (void *)phys_addr;
79}
80
81void dummy_unmap(void *virt_addr, size_t len)
82{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000083 msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
84 __func__, (unsigned long)len, virt_addr);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000085}
86
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000087void dummy_chip_writeb(uint8_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000088{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000089 msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000090}
91
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000092void dummy_chip_writew(uint16_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000093{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000094 msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000095}
96
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000097void dummy_chip_writel(uint32_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000098{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +000099 msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000100}
101
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000102void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
103{
104 size_t i;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000105 msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
106 __func__, addr, (unsigned long)len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000107 for (i = 0; i < len; i++) {
108 if ((i % 16) == 0)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000109 msg_pspew("\n");
110 msg_pspew("%02x ", buf[i]);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000111 }
112}
113
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000114uint8_t dummy_chip_readb(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000115{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000116 msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000117 return 0xff;
118}
119
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000120uint16_t dummy_chip_readw(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000121{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000122 msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000123 return 0xffff;
124}
125
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000126uint32_t dummy_chip_readl(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000127{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000128 msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000129 return 0xffffffff;
130}
131
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000132void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len)
133{
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000134 msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
135 __func__, addr, (unsigned long)len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000136 memset(buf, 0xff, len);
137 return;
138}
139
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000140int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000141 const unsigned char *writearr, unsigned char *readarr)
142{
143 int i;
144
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000145 msg_pspew("%s:", __func__);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000146
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000147 msg_pspew(" writing %u bytes:", writecnt);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000148 for (i = 0; i < writecnt; i++)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000149 msg_pspew(" 0x%02x", writearr[i]);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000150
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000151 msg_pspew(" reading %u bytes:", readcnt);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000152 for (i = 0; i < readcnt; i++) {
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000153 msg_pspew(" 0xff");
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000154 readarr[i] = 0xff;
155 }
156
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000157 msg_pspew("\n");
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000158 return 0;
159}