blob: abed3455c37dd5232bd970a48647335d2eac13ad [file] [log] [blame]
Edward O'Callaghan63f6a372022-08-12 12:56:43 +10001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com>
6 * Copyright (C) 2005-2008 coresystems GmbH
7 * Copyright (C) 2008,2009 Carl-Daniel Hailfinger
8 * Copyright (C) 2016 secunet Security Networks AG
9 * (Written by Nico Huber <nico.huber@secunet.com> for secunet)
10 * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21
22#include "flash.h"
23#include "programmer.h"
24
25void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
26{
Nico Huber9a11cbf2023-01-13 01:19:07 +010027 flash->mst.par->chip_writeb(flash, val, addr);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100028}
29
30void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
31{
Nico Huber9a11cbf2023-01-13 01:19:07 +010032 flash->mst.par->chip_writew(flash, val, addr);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100033}
34
35void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
36{
Nico Huber9a11cbf2023-01-13 01:19:07 +010037 flash->mst.par->chip_writel(flash, val, addr);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100038}
39
40void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
41{
Nico Huber9a11cbf2023-01-13 01:19:07 +010042 flash->mst.par->chip_writen(flash, buf, addr, len);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100043}
44
45uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr)
46{
Nico Huber9a11cbf2023-01-13 01:19:07 +010047 return flash->mst.par->chip_readb(flash, addr);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100048}
49
50uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr)
51{
Nico Huber9a11cbf2023-01-13 01:19:07 +010052 return flash->mst.par->chip_readw(flash, addr);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100053}
54
55uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr)
56{
Nico Huber9a11cbf2023-01-13 01:19:07 +010057 return flash->mst.par->chip_readl(flash, addr);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100058}
59
60void chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr,
61 size_t len)
62{
Nico Huber9a11cbf2023-01-13 01:19:07 +010063 flash->mst.par->chip_readn(flash, buf, addr, len);
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100064}
65
Nico Huber89569d62023-01-12 23:31:40 +010066int register_par_master(const struct par_master *mst, const enum chipbustype buses,
67 const size_t max_rom_decode, void *data)
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100068{
69 struct registered_master rmst;
70
71 if (mst->shutdown) {
72 if (register_shutdown(mst->shutdown, data)) {
73 mst->shutdown(data); /* cleanup */
74 return 1;
75 }
76 }
77
78 if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel ||
79 !mst->chip_writen || !mst->chip_readb || !mst->chip_readw ||
80 !mst->chip_readl || !mst->chip_readn) {
81 msg_perr("%s called with incomplete master definition.\n"
Nico Huberc3b02dc2023-08-12 01:13:45 +020082 "Please report a bug at flashprog@flashprog.org\n",
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100083 __func__);
Nico Huberc3b02dc2023-08-12 01:13:45 +020084 return ERROR_FLASHPROG_BUG;
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100085 }
86
Nico Huber89569d62023-01-12 23:31:40 +010087 if (max_rom_decode)
88 rmst.max_rom_decode = max_rom_decode;
89 else
90 rmst.max_rom_decode = DEFAULT_MAX_DECODE_PARALLEL;
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100091 rmst.buses_supported = buses;
92 rmst.par = *mst;
93 if (data)
94 rmst.par.data = data;
95 return register_master(&rmst);
96}