source: trunk/drkaiser.c @ 1474

Revision 1474, 3.0 KB checked in by hailfinger, 7 weeks ago (diff)

Add struct flashctx * parameter to all functions accessing flash chips.

All programmer access function prototypes except init have been made
static and moved to the respective file.

A few internal functions in flash chip drivers had chipaddr parameters
which are no longer needed.

The lines touched by flashctx changes have been adjusted to 80 columns
except in header files.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Michael Karcher <flashrom@…>

Line 
1/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Joerg Fischer <turboj@web.de>
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 <stdlib.h>
22#include "flash.h"
23#include "programmer.h"
24
25#define PCI_VENDOR_ID_DRKAISER          0x1803
26
27#define PCI_MAGIC_DRKAISER_ADDR         0x50
28#define PCI_MAGIC_DRKAISER_VALUE        0xa971
29
30#define DRKAISER_MEMMAP_SIZE           (1024 * 128)
31
32/* Mask to restrict flash accesses to the 128kB memory window. */
33#define DRKAISER_MEMMAP_MASK            ((1 << 17) - 1)
34
35const struct pcidev_status drkaiser_pcidev[] = {
36        {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"},
37        {},
38};
39
40static uint8_t *drkaiser_bar;
41
42static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val,
43                                 chipaddr addr);
44static uint8_t drkaiser_chip_readb(const struct flashctx *flash,
45                                   const chipaddr addr);
46static const struct par_programmer par_programmer_drkaiser = {
47                .chip_readb             = drkaiser_chip_readb,
48                .chip_readw             = fallback_chip_readw,
49                .chip_readl             = fallback_chip_readl,
50                .chip_readn             = fallback_chip_readn,
51                .chip_writeb            = drkaiser_chip_writeb,
52                .chip_writew            = fallback_chip_writew,
53                .chip_writel            = fallback_chip_writel,
54                .chip_writen            = fallback_chip_writen,
55};
56
57static int drkaiser_shutdown(void *data)
58{
59        physunmap(drkaiser_bar, DRKAISER_MEMMAP_SIZE);
60        /* Flash write is disabled automatically by PCI restore. */
61        pci_cleanup(pacc);
62        release_io_perms();
63        return 0;
64};
65
66int drkaiser_init(void)
67{
68        uint32_t addr;
69
70        get_io_perms();
71
72        addr = pcidev_init(PCI_BASE_ADDRESS_2, drkaiser_pcidev);
73
74        /* Write magic register to enable flash write. */
75        rpci_write_word(pcidev_dev, PCI_MAGIC_DRKAISER_ADDR,
76                        PCI_MAGIC_DRKAISER_VALUE);
77
78        /* Map 128kB flash memory window. */
79        drkaiser_bar = physmap("Dr. Kaiser PC-Waechter flash memory",
80                               addr, DRKAISER_MEMMAP_SIZE);
81
82        if (register_shutdown(drkaiser_shutdown, NULL))
83                return 1;
84
85        max_rom_decode.parallel = 128 * 1024;
86        register_par_programmer(&par_programmer_drkaiser, BUS_PARALLEL);
87
88        return 0;
89}
90
91static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val,
92                                 chipaddr addr)
93{
94        pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
95}
96
97static uint8_t drkaiser_chip_readb(const struct flashctx *flash,
98                                   const chipaddr addr)
99{
100        return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK));
101}
Note: See TracBrowser for help on using the repository browser.