blob: 016086781f07c40cf672b59626a2c9da8a1a0657 [file] [log] [blame]
Carl-Daniel Hailfingercc1802d2010-01-06 10:21:00 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009,2010 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 Hailfingercc1802d2010-01-06 10:21:00 +000021#include "flash.h"
22
23/* No-op shutdown() for programmers which don't need special handling */
24int noop_shutdown(void)
25{
26 return 0;
27}
28
29/* Fallback map() for programmers which don't need special handling */
30void *fallback_map(const char *descr, unsigned long phys_addr, size_t len)
31{
32 /* FIXME: Should return phys_addr. */
33 return 0;
34}
35
36/* No-op/fallback unmap() for programmers which don't need special handling */
37void fallback_unmap(void *virt_addr, size_t len)
38{
39}
40
41/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
42uint8_t noop_chip_readb(const chipaddr addr)
43{
44 return 0xff;
45}
46
47/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
48void noop_chip_writeb(uint8_t val, chipaddr addr)
49{
50}
51
52/* Little-endian fallback for drivers not supporting 16 bit accesses */
53void fallback_chip_writew(uint16_t val, chipaddr addr)
54{
55 chip_writeb(val & 0xff, addr);
56 chip_writeb((val >> 8) & 0xff, addr + 1);
57}
58
59/* Little-endian fallback for drivers not supporting 16 bit accesses */
60uint16_t fallback_chip_readw(const chipaddr addr)
61{
62 uint16_t val;
63 val = chip_readb(addr);
64 val |= chip_readb(addr + 1) << 8;
65 return val;
66}
67
68/* Little-endian fallback for drivers not supporting 32 bit accesses */
69void fallback_chip_writel(uint32_t val, chipaddr addr)
70{
71 chip_writew(val & 0xffff, addr);
72 chip_writew((val >> 16) & 0xffff, addr + 2);
73}
74
75/* Little-endian fallback for drivers not supporting 32 bit accesses */
76uint32_t fallback_chip_readl(const chipaddr addr)
77{
78 uint32_t val;
79 val = chip_readw(addr);
80 val |= chip_readw(addr + 2) << 16;
81 return val;
82}
83
84void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
85{
86 size_t i;
87 for (i = 0; i < len; i++)
88 chip_writeb(buf[i], addr + i);
89 return;
90}
91
92void fallback_chip_readn(uint8_t *buf, chipaddr addr, size_t len)
93{
94 size_t i;
95 for (i = 0; i < len; i++)
96 buf[i] = chip_readb(addr + i);
97 return;
98}