blob: 5b65e5bd5d80cbb6cb784515b57a1151a3103f25 [file] [log] [blame]
hailfingerec022272010-01-06 10:21:00 +00001/*
2 * This file is part of the flashrom project.
3 *
Souvik Ghoshd75cd672016-06-17 14:21:39 -07004 * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger
hailfingerec022272010-01-06 10:21:00 +00005 *
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
hailfingerec022272010-01-06 10:21:00 +000021#include "flash.h"
hailfinger76bb7e92011-11-09 23:40:00 +000022#include "programmer.h"
23
Vadim Bendebury066143d2018-07-16 18:20:33 -070024/*
25 * The following two variables are used in the code even if the ich support is
26 * not compiled in, this is why they are exported through programmer.h and
27 * defined here.
28 */
29enum ich_chipset ich_generation = CHIPSET_ICH_UNKNOWN;
30int ich_dry_run;
31
Patrick Georgi0a9533a2017-02-03 19:28:38 +010032static const struct par_master par_master_none = {
David Hendricksac1d25c2016-08-09 17:00:58 -070033 .chip_readb = noop_chip_readb,
34 .chip_readw = fallback_chip_readw,
35 .chip_readl = fallback_chip_readl,
36 .chip_readn = fallback_chip_readn,
37 .chip_writeb = noop_chip_writeb,
38 .chip_writew = fallback_chip_writew,
39 .chip_writel = fallback_chip_writel,
40 .chip_writen = fallback_chip_writen,
41};
42
Patrick Georgi0a9533a2017-02-03 19:28:38 +010043const struct par_master *par_master = &par_master_none;
David Hendricksac1d25c2016-08-09 17:00:58 -070044
hailfingerec022272010-01-06 10:21:00 +000045/* No-op shutdown() for programmers which don't need special handling */
46int noop_shutdown(void)
47{
48 return 0;
49}
50
51/* Fallback map() for programmers which don't need special handling */
Patrick Georgi4befc162017-02-03 18:32:01 +010052void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +000053{
54 /* FIXME: Should return phys_addr. */
stepand0d220f2011-01-24 19:15:51 +000055 return NULL;
hailfingerec022272010-01-06 10:21:00 +000056}
57
58/* No-op/fallback unmap() for programmers which don't need special handling */
59void fallback_unmap(void *virt_addr, size_t len)
60{
61}
62
David Hendricksac1d25c2016-08-09 17:00:58 -070063/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
64uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr)
65{
66 return 0xff;
67}
68
69/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070070void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000071{
72}
73
74/* Little-endian fallback for drivers not supporting 16 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070075void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000076{
Souvik Ghoshd75cd672016-06-17 14:21:39 -070077 chip_writeb(flash, val & 0xff, addr);
78 chip_writeb(flash, (val >> 8) & 0xff, addr + 1);
hailfingerec022272010-01-06 10:21:00 +000079}
80
81/* Little-endian fallback for drivers not supporting 16 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070082uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000083{
84 uint16_t val;
Souvik Ghoshd75cd672016-06-17 14:21:39 -070085 val = chip_readb(flash, addr);
86 val |= chip_readb(flash, addr + 1) << 8;
hailfingerec022272010-01-06 10:21:00 +000087 return val;
88}
89
90/* Little-endian fallback for drivers not supporting 32 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070091void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000092{
Souvik Ghoshd75cd672016-06-17 14:21:39 -070093 chip_writew(flash, val & 0xffff, addr);
94 chip_writew(flash, (val >> 16) & 0xffff, addr + 2);
hailfingerec022272010-01-06 10:21:00 +000095}
96
97/* Little-endian fallback for drivers not supporting 32 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070098uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000099{
100 uint32_t val;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700101 val = chip_readw(flash, addr);
102 val |= chip_readw(flash, addr + 2) << 16;
hailfingerec022272010-01-06 10:21:00 +0000103 return val;
104}
105
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700106void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +0000107{
108 size_t i;
109 for (i = 0; i < len; i++)
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700110 chip_writeb(flash, buf[i], addr + i);
hailfingerec022272010-01-06 10:21:00 +0000111 return;
112}
113
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700114void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +0000115{
116 size_t i;
117 for (i = 0; i < len; i++)
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700118 buf[i] = chip_readb(flash, addr + i);
hailfingerec022272010-01-06 10:21:00 +0000119 return;
120}
hailfinger76bb7e92011-11-09 23:40:00 +0000121
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100122void register_par_master(const struct par_master *pgm, const enum chipbustype buses)
hailfinger76bb7e92011-11-09 23:40:00 +0000123{
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100124 par_master = pgm;
David Hendricksac1d25c2016-08-09 17:00:58 -0700125 buses_supported |= buses;
hailfinger76bb7e92011-11-09 23:40:00 +0000126}
David Hendricksba0827a2013-05-03 20:25:40 -0700127
128struct programmer_alias aliases[] = {
David Hendricksac1d25c2016-08-09 17:00:58 -0700129 { "ec", ALIAS_EC },
130 { "host", ALIAS_HOST },
David Hendricksba0827a2013-05-03 20:25:40 -0700131 { NULL },
132};
133struct programmer_alias *alias;