blob: 3fb25b48fd59dfde7e0f551bb6e7e367d40f3421 [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{
27 flash->mst->par.chip_writeb(flash, val, addr);
28}
29
30void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
31{
32 flash->mst->par.chip_writew(flash, val, addr);
33}
34
35void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
36{
37 flash->mst->par.chip_writel(flash, val, addr);
38}
39
40void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
41{
42 flash->mst->par.chip_writen(flash, buf, addr, len);
43}
44
45uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr)
46{
47 return flash->mst->par.chip_readb(flash, addr);
48}
49
50uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr)
51{
52 return flash->mst->par.chip_readw(flash, addr);
53}
54
55uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr)
56{
57 return flash->mst->par.chip_readl(flash, addr);
58}
59
60void chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr,
61 size_t len)
62{
63 flash->mst->par.chip_readn(flash, buf, addr, len);
64}
65
66int register_par_master(const struct par_master *mst,
67 const enum chipbustype buses,
68 void *data)
69{
70 struct registered_master rmst;
71
72 if (mst->shutdown) {
73 if (register_shutdown(mst->shutdown, data)) {
74 mst->shutdown(data); /* cleanup */
75 return 1;
76 }
77 }
78
79 if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel ||
80 !mst->chip_writen || !mst->chip_readb || !mst->chip_readw ||
81 !mst->chip_readl || !mst->chip_readn) {
82 msg_perr("%s called with incomplete master definition.\n"
Nico Huberc3b02dc2023-08-12 01:13:45 +020083 "Please report a bug at flashprog@flashprog.org\n",
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100084 __func__);
Nico Huberc3b02dc2023-08-12 01:13:45 +020085 return ERROR_FLASHPROG_BUG;
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100086 }
87
88 rmst.buses_supported = buses;
89 rmst.par = *mst;
90 if (data)
91 rmst.par.data = data;
92 return register_master(&rmst);
93}