1 From 4f314ac9edbc80897f158fdb4e1b1de8a2d0d432 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 24 Jul 2011 21:10:49 +0200
4 Subject: [PATCH 16/26] brcm47xx: add common interface for sflash
7 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
9 arch/mips/bcm47xx/Makefile | 2 +-
10 arch/mips/bcm47xx/bus.c | 94 ++++++++++++++++++++++++++++++
11 arch/mips/bcm47xx/setup.c | 8 +++
12 arch/mips/include/asm/mach-bcm47xx/bus.h | 37 ++++++++++++
13 4 files changed, 140 insertions(+), 1 deletions(-)
14 create mode 100644 arch/mips/bcm47xx/bus.c
15 create mode 100644 arch/mips/include/asm/mach-bcm47xx/bus.h
17 --- a/arch/mips/bcm47xx/Makefile
18 +++ b/arch/mips/bcm47xx/Makefile
23 -obj-y += gpio.o irq.o nvram.o prom.o serial.o setup.o time.o
24 +obj-y += gpio.o irq.o nvram.o prom.o serial.o setup.o time.o bus.o
25 obj-$(CONFIG_BCM47XX_SSB) += wgt634u.o
27 +++ b/arch/mips/bcm47xx/bus.c
30 + * BCM947xx nvram variable access
32 + * Copyright (C) 2011 Hauke Mehrtens <hauke@hauke-m.de>
34 + * This program is free software; you can redistribute it and/or modify it
35 + * under the terms of the GNU General Public License as published by the
36 + * Free Software Foundation; either version 2 of the License, or (at your
37 + * option) any later version.
42 +static int bcm47xx_sflash_bcma_read(struct bcm47xx_sflash *dev, u32 offset, u32 len, u8 *buf)
44 + return bcma_sflash_read(dev->bcc, offset, len, buf);
47 +static int bcm47xx_sflash_bcma_poll(struct bcm47xx_sflash *dev, u32 offset)
49 + return bcma_sflash_poll(dev->bcc, offset);
52 +static int bcm47xx_sflash_bcma_write(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf)
54 + return bcma_sflash_write(dev->bcc, offset, len, buf);
57 +static int bcm47xx_sflash_bcma_erase(struct bcm47xx_sflash *dev, u32 offset)
59 + return bcma_sflash_erase(dev->bcc, offset);
62 +static int bcm47xx_sflash_bcma_commit(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf)
64 + return bcma_sflash_commit(dev->bcc, offset, len, buf);
67 +void bcm47xx_sflash_struct_bcma_init(struct bcm47xx_sflash *sflash, struct bcma_drv_cc *bcc)
69 + sflash->sflash_type = BCM47XX_BUS_TYPE_BCMA;
72 + sflash->read = bcm47xx_sflash_bcma_read;
73 + sflash->poll = bcm47xx_sflash_bcma_poll;
74 + sflash->write = bcm47xx_sflash_bcma_write;
75 + sflash->erase = bcm47xx_sflash_bcma_erase;
76 + sflash->commit = bcm47xx_sflash_bcma_commit;
78 + sflash->blocksize = bcc->sflash.blocksize;
79 + sflash->numblocks = bcc->sflash.numblocks;
80 + sflash->size = bcc->sflash.size;
83 +static int bcm47xx_sflash_ssb_read(struct bcm47xx_sflash *dev, u32 offset, u32 len, u8 *buf)
85 + return ssb_sflash_read(dev->scc, offset, len, buf);
88 +static int bcm47xx_sflash_ssb_poll(struct bcm47xx_sflash *dev, u32 offset)
90 + return ssb_sflash_poll(dev->scc, offset);
93 +static int bcm47xx_sflash_ssb_write(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf)
95 + return ssb_sflash_write(dev->scc, offset, len, buf);
98 +static int bcm47xx_sflash_ssb_erase(struct bcm47xx_sflash *dev, u32 offset)
100 + return ssb_sflash_erase(dev->scc, offset);
103 +static int bcm47xx_sflash_ssb_commit(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf)
105 + return ssb_sflash_commit(dev->scc, offset, len, buf);
108 +void bcm47xx_sflash_struct_ssb_init(struct bcm47xx_sflash *sflash, struct ssb_chipcommon *scc)
110 + sflash->sflash_type = BCM47XX_BUS_TYPE_SSB;
113 + sflash->read = bcm47xx_sflash_ssb_read;
114 + sflash->poll = bcm47xx_sflash_ssb_poll;
115 + sflash->write = bcm47xx_sflash_ssb_write;
116 + sflash->erase = bcm47xx_sflash_ssb_erase;
117 + sflash->commit = bcm47xx_sflash_ssb_commit;
119 + sflash->blocksize = scc->sflash.blocksize;
120 + sflash->numblocks = scc->sflash.numblocks;
121 + sflash->size = scc->sflash.size;
123 --- a/arch/mips/bcm47xx/setup.c
124 +++ b/arch/mips/bcm47xx/setup.c
125 @@ -42,6 +42,8 @@ EXPORT_SYMBOL(bcm47xx_bus);
126 enum bcm47xx_bus_type bcm47xx_bus_type;
127 EXPORT_SYMBOL(bcm47xx_bus_type);
129 +struct bcm47xx_sflash bcm47xx_sflash;
131 static void bcm47xx_machine_restart(char *command)
133 printk(KERN_ALERT "Please stand by while rebooting the system...\n");
134 @@ -290,6 +292,9 @@ static void __init bcm47xx_register_ssb(
136 panic("Failed to initialize SSB bus (err %d)\n", err);
138 + if (bcm47xx_bus.ssb.chipco.flash_type == SSB_SFLASH)
139 + bcm47xx_sflash_struct_ssb_init(&bcm47xx_sflash, &bcm47xx_bus.ssb.chipco);
141 mcore = &bcm47xx_bus.ssb.mipscore;
142 if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
143 if (strstr(buf, "console=ttyS1")) {
144 @@ -314,6 +319,9 @@ static void __init bcm47xx_register_bcma
145 err = bcma_host_soc_register(&bcm47xx_bus.bcma);
147 panic("Failed to initialize BCMA bus (err %d)\n", err);
149 + if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == BCMA_SFLASH)
150 + bcm47xx_sflash_struct_bcma_init(&bcm47xx_sflash, &bcm47xx_bus.bcma.bus.drv_cc);
155 +++ b/arch/mips/include/asm/mach-bcm47xx/bus.h
158 + * BCM947xx nvram variable access
160 + * Copyright (C) 2011 Hauke Mehrtens <hauke@hauke-m.de>
162 + * This program is free software; you can redistribute it and/or modify it
163 + * under the terms of the GNU General Public License as published by the
164 + * Free Software Foundation; either version 2 of the License, or (at your
165 + * option) any later version.
168 +#include <linux/ssb/ssb.h>
169 +#include <linux/bcma/bcma.h>
170 +#include <bcm47xx.h>
172 +struct bcm47xx_sflash {
173 + enum bcm47xx_bus_type sflash_type;
175 + struct ssb_chipcommon *scc;
176 + struct bcma_drv_cc *bcc;
179 + int (*read)(struct bcm47xx_sflash *dev, u32 offset, u32 len, u8 *buf);
180 + int (*poll)(struct bcm47xx_sflash *dev, u32 offset);
181 + int (*write)(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf);
182 + int (*erase)(struct bcm47xx_sflash *dev, u32 offset);
183 + int (*commit)(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf);
185 + u32 blocksize; /* Block size */
186 + u32 numblocks; /* Number of blocks */
187 + u32 size; /* Total size in bytes */
190 +void bcm47xx_sflash_struct_bcma_init(struct bcm47xx_sflash *sflash, struct bcma_drv_cc *bcc);
191 +void bcm47xx_sflash_struct_ssb_init(struct bcm47xx_sflash *sflash, struct ssb_chipcommon *scc);
193 +extern struct bcm47xx_sflash bcm47xx_sflash;