| 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 |
| 5 | |
| 6 | |
| 7 | Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> |
| 8 | --- |
| 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 |
| 16 | |
| 17 | --- a/arch/mips/bcm47xx/Makefile |
| 18 | +++ b/arch/mips/bcm47xx/Makefile |
| 19 | @@ -3,5 +3,5 @@ |
| 20 | # under Linux. |
| 21 | # |
| 22 | |
| 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 |
| 26 | --- /dev/null |
| 27 | +++ b/arch/mips/bcm47xx/bus.c |
| 28 | @@ -0,0 +1,94 @@ |
| 29 | +/* |
| 30 | + * BCM947xx nvram variable access |
| 31 | + * |
| 32 | + * Copyright (C) 2011 Hauke Mehrtens <hauke@hauke-m.de> |
| 33 | + * |
| 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. |
| 38 | + */ |
| 39 | + |
| 40 | +#include <bus.h> |
| 41 | + |
| 42 | +static int bcm47xx_sflash_bcma_read(struct bcm47xx_sflash *dev, u32 offset, u32 len, u8 *buf) |
| 43 | +{ |
| 44 | + return bcma_sflash_read(dev->bcc, offset, len, buf); |
| 45 | +} |
| 46 | + |
| 47 | +static int bcm47xx_sflash_bcma_poll(struct bcm47xx_sflash *dev, u32 offset) |
| 48 | +{ |
| 49 | + return bcma_sflash_poll(dev->bcc, offset); |
| 50 | +} |
| 51 | + |
| 52 | +static int bcm47xx_sflash_bcma_write(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf) |
| 53 | +{ |
| 54 | + return bcma_sflash_write(dev->bcc, offset, len, buf); |
| 55 | +} |
| 56 | + |
| 57 | +static int bcm47xx_sflash_bcma_erase(struct bcm47xx_sflash *dev, u32 offset) |
| 58 | +{ |
| 59 | + return bcma_sflash_erase(dev->bcc, offset); |
| 60 | +} |
| 61 | + |
| 62 | +static int bcm47xx_sflash_bcma_commit(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf) |
| 63 | +{ |
| 64 | + return bcma_sflash_commit(dev->bcc, offset, len, buf); |
| 65 | +} |
| 66 | + |
| 67 | +void bcm47xx_sflash_struct_bcma_init(struct bcm47xx_sflash *sflash, struct bcma_drv_cc *bcc) |
| 68 | +{ |
| 69 | + sflash->sflash_type = BCM47XX_BUS_TYPE_BCMA; |
| 70 | + sflash->bcc = bcc; |
| 71 | + |
| 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; |
| 77 | + |
| 78 | + sflash->blocksize = bcc->sflash.blocksize; |
| 79 | + sflash->numblocks = bcc->sflash.numblocks; |
| 80 | + sflash->size = bcc->sflash.size; |
| 81 | +} |
| 82 | + |
| 83 | +static int bcm47xx_sflash_ssb_read(struct bcm47xx_sflash *dev, u32 offset, u32 len, u8 *buf) |
| 84 | +{ |
| 85 | + return ssb_sflash_read(dev->scc, offset, len, buf); |
| 86 | +} |
| 87 | + |
| 88 | +static int bcm47xx_sflash_ssb_poll(struct bcm47xx_sflash *dev, u32 offset) |
| 89 | +{ |
| 90 | + return ssb_sflash_poll(dev->scc, offset); |
| 91 | +} |
| 92 | + |
| 93 | +static int bcm47xx_sflash_ssb_write(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf) |
| 94 | +{ |
| 95 | + return ssb_sflash_write(dev->scc, offset, len, buf); |
| 96 | +} |
| 97 | + |
| 98 | +static int bcm47xx_sflash_ssb_erase(struct bcm47xx_sflash *dev, u32 offset) |
| 99 | +{ |
| 100 | + return ssb_sflash_erase(dev->scc, offset); |
| 101 | +} |
| 102 | + |
| 103 | +static int bcm47xx_sflash_ssb_commit(struct bcm47xx_sflash *dev, u32 offset, u32 len, const u8 *buf) |
| 104 | +{ |
| 105 | + return ssb_sflash_commit(dev->scc, offset, len, buf); |
| 106 | +} |
| 107 | + |
| 108 | +void bcm47xx_sflash_struct_ssb_init(struct bcm47xx_sflash *sflash, struct ssb_chipcommon *scc) |
| 109 | +{ |
| 110 | + sflash->sflash_type = BCM47XX_BUS_TYPE_SSB; |
| 111 | + sflash->scc = scc; |
| 112 | + |
| 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; |
| 118 | + |
| 119 | + sflash->blocksize = scc->sflash.blocksize; |
| 120 | + sflash->numblocks = scc->sflash.numblocks; |
| 121 | + sflash->size = scc->sflash.size; |
| 122 | +} |
| 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); |
| 128 | |
| 129 | +struct bcm47xx_sflash bcm47xx_sflash; |
| 130 | + |
| 131 | static void bcm47xx_machine_restart(char *command) |
| 132 | { |
| 133 | printk(KERN_ALERT "Please stand by while rebooting the system...\n"); |
| 134 | @@ -290,6 +292,9 @@ static void __init bcm47xx_register_ssb( |
| 135 | if (err) |
| 136 | panic("Failed to initialize SSB bus (err %d)\n", err); |
| 137 | |
| 138 | + if (bcm47xx_bus.ssb.chipco.flash_type == SSB_SFLASH) |
| 139 | + bcm47xx_sflash_struct_ssb_init(&bcm47xx_sflash, &bcm47xx_bus.ssb.chipco); |
| 140 | + |
| 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); |
| 146 | if (err) |
| 147 | panic("Failed to initialize BCMA bus (err %d)\n", err); |
| 148 | + |
| 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); |
| 151 | } |
| 152 | #endif |
| 153 | |
| 154 | --- /dev/null |
| 155 | +++ b/arch/mips/include/asm/mach-bcm47xx/bus.h |
| 156 | @@ -0,0 +1,37 @@ |
| 157 | +/* |
| 158 | + * BCM947xx nvram variable access |
| 159 | + * |
| 160 | + * Copyright (C) 2011 Hauke Mehrtens <hauke@hauke-m.de> |
| 161 | + * |
| 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. |
| 166 | + */ |
| 167 | + |
| 168 | +#include <linux/ssb/ssb.h> |
| 169 | +#include <linux/bcma/bcma.h> |
| 170 | +#include <bcm47xx.h> |
| 171 | + |
| 172 | +struct bcm47xx_sflash { |
| 173 | + enum bcm47xx_bus_type sflash_type; |
| 174 | + union { |
| 175 | + struct ssb_chipcommon *scc; |
| 176 | + struct bcma_drv_cc *bcc; |
| 177 | + }; |
| 178 | + |
| 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); |
| 184 | + |
| 185 | + u32 blocksize; /* Block size */ |
| 186 | + u32 numblocks; /* Number of blocks */ |
| 187 | + u32 size; /* Total size in bytes */ |
| 188 | +}; |
| 189 | + |
| 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); |
| 192 | + |
| 193 | +extern struct bcm47xx_sflash bcm47xx_sflash; |
| 194 | |