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