Skip to content

Commit c0fcbc5

Browse files
rmileckiDavid Woodhouse
authored andcommitted
mtd: bcm47xxsflash: implement erasing support
Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 8268df2 commit c0fcbc5

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

drivers/mtd/devices/bcm47xxsflash.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,42 @@ static int bcm47xxsflash_poll(struct bcm47xxsflash *b47s, int timeout)
6464
* MTD ops
6565
**************************************************/
6666

67+
static int bcm47xxsflash_erase(struct mtd_info *mtd, struct erase_info *erase)
68+
{
69+
struct bcm47xxsflash *b47s = mtd->priv;
70+
int err;
71+
72+
switch (b47s->type) {
73+
case BCM47XXSFLASH_TYPE_ST:
74+
bcm47xxsflash_cmd(b47s, OPCODE_ST_WREN);
75+
b47s->cc_write(b47s, BCMA_CC_FLASHADDR, erase->addr);
76+
/* Newer flashes have "sub-sectors" which can be erased
77+
* independently with a new command: ST_SSE. The ST_SE command
78+
* erases 64KB just as before.
79+
*/
80+
if (b47s->blocksize < (64 * 1024))
81+
bcm47xxsflash_cmd(b47s, OPCODE_ST_SSE);
82+
else
83+
bcm47xxsflash_cmd(b47s, OPCODE_ST_SE);
84+
break;
85+
case BCM47XXSFLASH_TYPE_ATMEL:
86+
b47s->cc_write(b47s, BCMA_CC_FLASHADDR, erase->addr << 1);
87+
bcm47xxsflash_cmd(b47s, OPCODE_AT_PAGE_ERASE);
88+
break;
89+
}
90+
91+
err = bcm47xxsflash_poll(b47s, HZ);
92+
if (err)
93+
erase->state = MTD_ERASE_FAILED;
94+
else
95+
erase->state = MTD_ERASE_DONE;
96+
97+
if (erase->callback)
98+
erase->callback(erase);
99+
100+
return err;
101+
}
102+
67103
static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
68104
size_t *retlen, u_char *buf)
69105
{
@@ -88,12 +124,15 @@ static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s)
88124
mtd->name = "bcm47xxsflash";
89125
mtd->owner = THIS_MODULE;
90126
mtd->type = MTD_ROM;
91-
mtd->size = b47s->size;
92-
mtd->_read = bcm47xxsflash_read;
93127

94128
/* TODO: implement writing support and verify/change following code */
95129
mtd->flags = MTD_CAP_ROM;
130+
mtd->size = b47s->size;
131+
mtd->erasesize = b47s->blocksize;
96132
mtd->writebufsize = mtd->writesize = 1;
133+
134+
mtd->_erase = bcm47xxsflash_erase;
135+
mtd->_read = bcm47xxsflash_read;
97136
}
98137

99138
/**************************************************

0 commit comments

Comments
 (0)