mtd: bcm47xxsflash: implement ChipCommon R/W ops
PATCH 1/2 mtd: bcm47xxsflash: implement ChipCommon R/W ops
They are needed for erasing/writing. Use a magic pointers and small functions to preapre code for adding other buses suppoer in the future (like SSB).
--- drivers/mtd/devices/bcm47xxsflash.c | 13 +++++++++++++ drivers/mtd/devices/bcm47xxsflash.h | 2 ++ 2 files changed, 15 insertions(+)
drivers/mtd/devices/bcm47xxsflash.c +13 -0
@@ -48,6 +48,17 @@ static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s)* BCMA **************************************************/ +static int bcm47xxsflash_bcma_cc_read (struct bcm47xxsflash *b47s,u16 offset) +{ +return bcma_cc_read32 (b47s->bcma_cc, offset); +} + +static void bcm47xxsflash_bcma_cc_write (struct bcm47xxsflash *b47s,u16 offset, +u32 value) +{ +bcma_cc_write32 (b47s->bcma_cc, offset, value); +} +static int bcm47xxsflash_bcma_probe (struct platform_device *pdev) {struct bcma_sflash *sflash =dev_get_platdata (&pdev->dev);
@@ -62,6 +73,8 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) sflash->priv = b47s; b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash); + b47s->cc_read = bcm47xxsflash_bcma_cc_read; + b47s->cc_write = bcm47xxsflash_bcma_cc_write;switch (b47s->bcma_cc->capabilities &BCMA_CC_CAP_FLASHT ) {case BCMA_CC_FLASHT_STSER :
drivers/mtd/devices/bcm47xxsflash.h +2 -0
@@ -60,6 +60,8 @@ enum bcm47xxsflash_type {struct bcm47xxsflash {struct bcma_drv_cc *bcma_cc; +int (*cc_read)(struct bcm47xxsflash *b47s,u16 offset); +void (*cc_write)(struct bcm47xxsflash *b47s,u16 offset,u32 value);enum bcm47xxsflash_type type;
Signature · 1 line
1.7.10.4
PATCH 2/2 mtd: bcm47xxsflash: implement polling chip status
--- drivers/mtd/devices/bcm47xxsflash.c | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
drivers/mtd/devices/bcm47xxsflash.c +55 -0
@@ -1,6 +1,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/delay.h> #include <linux/mtd/mtd.h> #include <linux/platform_device.h> #include <linux/bcma/bcma.h>
@@ -12,6 +13,57 @@ MODULE_DESCRIPTION("Serial flash driver for BCMA bus");static const char *const probes[] = {"bcm47xxpart" ,NULL }; +/************************************************** +* Various helpers +**************************************************/ + +static void bcm47xxsflash_cmd (struct bcm47xxsflash *b47s,u32 opcode) +{ +int i; + + b47s->cc_write (b47s,BCMA_CC_FLASHCTL ,BCMA_CC_FLASHCTL_START | opcode); +for (i =0 ; i <1000 ; i++) { +if (!(b47s->cc_read (b47s,BCMA_CC_FLASHCTL ) & +BCMA_CC_FLASHCTL_BUSY )) +return ; +cpu_relax (); + } +pr_err ("Control command failed (timeout)!\n" ); +} + +static int bcm47xxsflash_poll (struct bcm47xxsflash *b47s,int timeout) +{ +unsigned long deadline = jiffies + timeout; + +do { +switch (b47s->type) { +case BCM47XXSFLASH_TYPE_ST : +bcm47xxsflash_cmd (b47s,OPCODE_ST_RDSR ); +if (!(b47s->cc_read (b47s,BCMA_CC_FLASHDATA ) & +SR_ST_WIP )) +return 0 ; +break ; +case BCM47XXSFLASH_TYPE_ATMEL : +bcm47xxsflash_cmd (b47s,OPCODE_AT_STATUS ); +if (b47s->cc_read (b47s,BCMA_CC_FLASHDATA ) & +SR_AT_READY ) +return 0 ; +break ; + } + +cpu_relax (); +udelay (1 ); + }while (!time_after_eq (jiffies, deadline)); + +pr_err ("Timeout waiting for flash to be ready!\n" ); + +return -EBUSY ; +} + +/************************************************** +* MTD ops +**************************************************/ +static int bcm47xxsflash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf) {
@@ -97,6 +149,9 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) goto err_dev_reg; } +if (bcm47xxsflash_poll (b47s,HZ /10 )) +pr_warn ("Serial flash busy\n" ); +return 0 ; err_dev_reg:
Signature · 1 line
1.7.10.4
PATCH v2 1/2 mtd: bcm47xxsflash: implement ChipCommon R/W ops
In reply to Rafał MiłeckiThey are needed for erasing/writing. Use a magic pointers and small functions to preapre code for adding other buses support in the future (like SSB).
---
V2: fix typo in commit message
--- drivers/mtd/devices/bcm47xxsflash.c | 13 +++++++++++++ drivers/mtd/devices/bcm47xxsflash.h | 2 ++ 2 files changed, 15 insertions(+)
drivers/mtd/devices/bcm47xxsflash.c +13 -0
@@ -48,6 +48,17 @@ static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s)* BCMA **************************************************/ +static int bcm47xxsflash_bcma_cc_read (struct bcm47xxsflash *b47s,u16 offset) +{ +return bcma_cc_read32 (b47s->bcma_cc, offset); +} + +static void bcm47xxsflash_bcma_cc_write (struct bcm47xxsflash *b47s,u16 offset, +u32 value) +{ +bcma_cc_write32 (b47s->bcma_cc, offset, value); +} +static int bcm47xxsflash_bcma_probe (struct platform_device *pdev) {struct bcma_sflash *sflash =dev_get_platdata (&pdev->dev);
@@ -62,6 +73,8 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) sflash->priv = b47s; b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash); + b47s->cc_read = bcm47xxsflash_bcma_cc_read; + b47s->cc_write = bcm47xxsflash_bcma_cc_write;switch (b47s->bcma_cc->capabilities &BCMA_CC_CAP_FLASHT ) {case BCMA_CC_FLASHT_STSER :
drivers/mtd/devices/bcm47xxsflash.h +2 -0
@@ -60,6 +60,8 @@ enum bcm47xxsflash_type {struct bcm47xxsflash {struct bcma_drv_cc *bcma_cc; +int (*cc_read)(struct bcm47xxsflash *b47s,u16 offset); +void (*cc_write)(struct bcm47xxsflash *b47s,u16 offset,u32 value);enum bcm47xxsflash_type type;
Signature · 1 line
1.7.10.4
2013/3/24 Rafał Miłecki <[email protected]>:
Quoted 3 lines
They are needed for erasing/writing. Use a magic pointers and small functions to preapre code for adding other buses suppoer in the future (like SSB).
David: is there a chance for picking up that 2 patches for 3.10?
Signature · 1 line
Rafał
Artem Bityutskiy
AppliedQuoted 5 lines · Rafał Miłecki
They are needed for erasing/writing. Use a magic pointers and small functions to preapre code for adding other buses suppoer in the future (like SSB).
Signed-off-by Rafał Miłecki <[email protected]>
Pushed to l2-mtd.git, thanks!
Signature · 2 lines
Best Regards, Artem Bityutskiy