flashrom 

flashrom Svn Source Tree

Root/trunk/programmer.c

1/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009,2010,2011 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 "flash.h"
22#include "programmer.h"
23
24/* No-op shutdown() for programmers which don't need special handling */
25int noop_shutdown(void)
26{
27return 0;
28}
29
30/* Fallback map() for programmers which don't need special handling */
31void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len)
32{
33/* FIXME: Should return phys_addr. */
34return NULL;
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 parallel style drivers not supporting writes */
43void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
44{
45}
46
47/* Little-endian fallback for drivers not supporting 16 bit accesses */
48void fallback_chip_writew(const struct flashctx *flash, uint16_t val,
49 chipaddr addr)
50{
51chip_writeb(flash, val & 0xff, addr);
52chip_writeb(flash, (val >> 8) & 0xff, addr + 1);
53}
54
55/* Little-endian fallback for drivers not supporting 16 bit accesses */
56uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr)
57{
58uint16_t val;
59val = chip_readb(flash, addr);
60val |= chip_readb(flash, addr + 1) << 8;
61return val;
62}
63
64/* Little-endian fallback for drivers not supporting 32 bit accesses */
65void fallback_chip_writel(const struct flashctx *flash, uint32_t val,
66 chipaddr addr)
67{
68chip_writew(flash, val & 0xffff, addr);
69chip_writew(flash, (val >> 16) & 0xffff, addr + 2);
70}
71
72/* Little-endian fallback for drivers not supporting 32 bit accesses */
73uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr)
74{
75uint32_t val;
76val = chip_readw(flash, addr);
77val |= chip_readw(flash, addr + 2) << 16;
78return val;
79}
80
81void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
82{
83size_t i;
84for (i = 0; i < len; i++)
85chip_writeb(flash, buf[i], addr + i);
86return;
87}
88
89void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf,
90 chipaddr addr, size_t len)
91{
92size_t i;
93for (i = 0; i < len; i++)
94buf[i] = chip_readb(flash, addr + i);
95return;
96}
97
98int register_par_master(const struct par_master *mst,
99 const enum chipbustype buses)
100{
101struct registered_master rmst;
102if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel ||
103 !mst->chip_writen || !mst->chip_readb || !mst->chip_readw ||
104 !mst->chip_readl || !mst->chip_readn) {
105msg_perr("%s called with incomplete master definition. "
106 "Please report a bug at flashrom@flashrom.org\n",
107 __func__);
108return ERROR_FLASHROM_BUG;
109}
110
111rmst.buses_supported = buses;
112rmst.par = *mst;
113return register_master(&rmst);
114}
115
116/* The limit of 4 is totally arbitrary. */
117#define MASTERS_MAX 4
118struct registered_master registered_masters[MASTERS_MAX];
119int registered_master_count = 0;
120
121/* This function copies the struct registered_master parameter. */
122int register_master(const struct registered_master *mst)
123{
124if (registered_master_count >= MASTERS_MAX) {
125msg_perr("Tried to register more than %i master "
126 "interfaces.\n", MASTERS_MAX);
127return ERROR_FLASHROM_LIMIT;
128}
129registered_masters[registered_master_count] = *mst;
130registered_master_count++;
131
132return 0;
133}
134
135enum chipbustype get_buses_supported(void)
136{
137int i;
138enum chipbustype ret = BUS_NONE;
139
140for (i = 0; i < registered_master_count; i++)
141ret |= registered_masters[i].buses_supported;
142
143return ret;
144}

Archive Download this file

Revision: HEAD