blob: 5eabdaf9975e37aa95f1ab59dc01cde10abbbb18 [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"
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +000022#include "programmer.h"
23
24static const struct par_programmer par_programmer_none = {
25 .chip_readb = noop_chip_readb,
26 .chip_readw = fallback_chip_readw,
27 .chip_readl = fallback_chip_readl,
28 .chip_readn = fallback_chip_readn,
29 .chip_writeb = noop_chip_writeb,
30 .chip_writew = fallback_chip_writew,
31 .chip_writel = fallback_chip_writel,
32 .chip_writen = fallback_chip_writen,
33};
34
35const struct par_programmer *par_programmer = &par_programmer_none;
Carl-Daniel Hailfingercc1802d2010-01-06 10:21:00 +000036
37/* No-op shutdown() for programmers which don't need special handling */
38int noop_shutdown(void)
39{
40 return 0;
41}
42
43/* Fallback map() for programmers which don't need special handling */
44void *fallback_map(const char *descr, unsigned long phys_addr, size_t len)
45{
46 /* FIXME: Should return phys_addr. */
Peter Huewe73f8ec82011-01-24 19:15:51 +000047 return NULL;
Carl-Daniel Hailfingercc1802d2010-01-06 10:21:00 +000048}
49
50/* No-op/fallback unmap() for programmers which don't need special handling */
51void fallback_unmap(void *virt_addr, size_t len)
52{
53}
54
55/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
56uint8_t noop_chip_readb(const chipaddr addr)
57{
58 return 0xff;
59}
60
61/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
62void noop_chip_writeb(uint8_t val, chipaddr addr)
63{
64}
65
66/* Little-endian fallback for drivers not supporting 16 bit accesses */
67void fallback_chip_writew(uint16_t val, chipaddr addr)
68{
69 chip_writeb(val & 0xff, addr);
70 chip_writeb((val >> 8) & 0xff, addr + 1);
71}
72
73/* Little-endian fallback for drivers not supporting 16 bit accesses */
74uint16_t fallback_chip_readw(const chipaddr addr)
75{
76 uint16_t val;
77 val = chip_readb(addr);
78 val |= chip_readb(addr + 1) << 8;
79 return val;
80}
81
82/* Little-endian fallback for drivers not supporting 32 bit accesses */
83void fallback_chip_writel(uint32_t val, chipaddr addr)
84{
85 chip_writew(val & 0xffff, addr);
86 chip_writew((val >> 16) & 0xffff, addr + 2);
87}
88
89/* Little-endian fallback for drivers not supporting 32 bit accesses */
90uint32_t fallback_chip_readl(const chipaddr addr)
91{
92 uint32_t val;
93 val = chip_readw(addr);
94 val |= chip_readw(addr + 2) << 16;
95 return val;
96}
97
98void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
99{
100 size_t i;
101 for (i = 0; i < len; i++)
102 chip_writeb(buf[i], addr + i);
103 return;
104}
105
106void fallback_chip_readn(uint8_t *buf, chipaddr addr, size_t len)
107{
108 size_t i;
109 for (i = 0; i < len; i++)
110 buf[i] = chip_readb(addr + i);
111 return;
112}
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000113
114void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses)
115{
116 par_programmer = pgm;
117 buses_supported |= buses;
118}