blob: c03aeadb3531b3eabff1f77a2785ae346f7a768b [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>
23#include <fcntl.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <errno.h>
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000027#include "flash.h"
28
29int dummy_init(void)
30{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000031 printf_debug("%s\n", __func__);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +000032 flashbus = BUS_TYPE_DUMMY_SPI;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000033 return 0;
34}
35
36int dummy_shutdown(void)
37{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000038 printf_debug("%s\n", __func__);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000039 return 0;
40}
41
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000042void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
43{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000044 printf_debug("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000045 __func__, descr, (unsigned long)len, phys_addr);
46 return (void *)phys_addr;
47}
48
49void dummy_unmap(void *virt_addr, size_t len)
50{
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +000051 printf_debug("%s: Unmapping 0x%lx bytes at %p\n",
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000052 __func__, (unsigned long)len, virt_addr);
53}
54
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000055void dummy_chip_writeb(uint8_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000056{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000057 printf_debug("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000058}
59
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000060void dummy_chip_writew(uint16_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000061{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000062 printf_debug("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000063}
64
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000065void dummy_chip_writel(uint32_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000066{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000067 printf_debug("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000068}
69
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000070uint8_t dummy_chip_readb(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000071{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000072 printf_debug("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000073 return 0xff;
74}
75
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000076uint16_t dummy_chip_readw(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000077{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000078 printf_debug("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000079 return 0xffff;
80}
81
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000082uint32_t dummy_chip_readl(const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000083{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000084 printf_debug("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000085 return 0xffffffff;
86}
87
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +000088int dummy_spi_command(unsigned int writecnt, unsigned int readcnt,
89 const unsigned char *writearr, unsigned char *readarr)
90{
91 int i;
92
93 printf_debug("%s:", __func__);
94
95 printf_debug(" writing %u bytes:", writecnt);
96 for (i = 0; i < writecnt; i++)
97 printf_debug(" 0x%02x", writearr[i]);
98
99 printf_debug(" reading %u bytes:", readcnt);
100 for (i = 0; i < readcnt; i++) {
101 printf_debug(" 0xff");
102 readarr[i] = 0xff;
103 }
104
105 printf_debug("\n");
106 return 0;
107}