mirror of https://gitee.com/openkylin/linux.git
mtd: bcm47xxsflash: add own struct for abstrating bus type
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
This commit is contained in:
parent
396afe553b
commit
a2f74a7dac
|
@ -5,6 +5,8 @@
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/bcma/bcma.h>
|
#include <linux/bcma/bcma.h>
|
||||||
|
|
||||||
|
#include "bcm47xxsflash.h"
|
||||||
|
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_DESCRIPTION("Serial flash driver for BCMA bus");
|
MODULE_DESCRIPTION("Serial flash driver for BCMA bus");
|
||||||
|
|
||||||
|
@ -13,26 +15,27 @@ static const char *probes[] = { "bcm47xxpart", NULL };
|
||||||
static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
|
static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
|
||||||
size_t *retlen, u_char *buf)
|
size_t *retlen, u_char *buf)
|
||||||
{
|
{
|
||||||
struct bcma_sflash *sflash = mtd->priv;
|
struct bcm47xxsflash *b47s = mtd->priv;
|
||||||
|
|
||||||
/* Check address range */
|
/* Check address range */
|
||||||
if ((from + len) > mtd->size)
|
if ((from + len) > mtd->size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(sflash->window + from),
|
memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
|
||||||
len);
|
len);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
|
static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s)
|
||||||
struct mtd_info *mtd)
|
|
||||||
{
|
{
|
||||||
mtd->priv = sflash;
|
struct mtd_info *mtd = &b47s->mtd;
|
||||||
|
|
||||||
|
mtd->priv = b47s;
|
||||||
mtd->name = "bcm47xxsflash";
|
mtd->name = "bcm47xxsflash";
|
||||||
mtd->owner = THIS_MODULE;
|
mtd->owner = THIS_MODULE;
|
||||||
mtd->type = MTD_ROM;
|
mtd->type = MTD_ROM;
|
||||||
mtd->size = sflash->size;
|
mtd->size = b47s->size;
|
||||||
mtd->_read = bcm47xxsflash_read;
|
mtd->_read = bcm47xxsflash_read;
|
||||||
|
|
||||||
/* TODO: implement writing support and verify/change following code */
|
/* TODO: implement writing support and verify/change following code */
|
||||||
|
@ -43,16 +46,23 @@ static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
|
||||||
static int bcm47xxsflash_probe(struct platform_device *pdev)
|
static int bcm47xxsflash_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
|
struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
|
||||||
|
struct bcm47xxsflash *b47s;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
sflash->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
|
b47s = kzalloc(sizeof(*b47s), GFP_KERNEL);
|
||||||
if (!sflash->mtd) {
|
if (!b47s) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
bcm47xxsflash_fill_mtd(sflash, sflash->mtd);
|
sflash->priv = b47s;
|
||||||
|
|
||||||
err = mtd_device_parse_register(sflash->mtd, probes, NULL, NULL, 0);
|
b47s->window = sflash->window;
|
||||||
|
b47s->blocksize = sflash->blocksize;
|
||||||
|
b47s->numblocks = sflash->numblocks;
|
||||||
|
b47s->size = sflash->size;
|
||||||
|
bcm47xxsflash_fill_mtd(b47s);
|
||||||
|
|
||||||
|
err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
|
||||||
if (err) {
|
if (err) {
|
||||||
pr_err("Failed to register MTD device: %d\n", err);
|
pr_err("Failed to register MTD device: %d\n", err);
|
||||||
goto err_dev_reg;
|
goto err_dev_reg;
|
||||||
|
@ -61,7 +71,7 @@ static int bcm47xxsflash_probe(struct platform_device *pdev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_dev_reg:
|
err_dev_reg:
|
||||||
kfree(sflash->mtd);
|
kfree(&b47s->mtd);
|
||||||
out:
|
out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -69,9 +79,10 @@ static int bcm47xxsflash_probe(struct platform_device *pdev)
|
||||||
static int bcm47xxsflash_remove(struct platform_device *pdev)
|
static int bcm47xxsflash_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
|
struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
|
||||||
|
struct bcm47xxsflash *b47s = sflash->priv;
|
||||||
|
|
||||||
mtd_device_unregister(sflash->mtd);
|
mtd_device_unregister(&b47s->mtd);
|
||||||
kfree(sflash->mtd);
|
kfree(b47s);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef __BCM47XXSFLASH_H
|
||||||
|
#define __BCM47XXSFLASH_H
|
||||||
|
|
||||||
|
#include <linux/mtd/mtd.h>
|
||||||
|
|
||||||
|
struct bcm47xxsflash {
|
||||||
|
u32 window;
|
||||||
|
u32 blocksize;
|
||||||
|
u16 numblocks;
|
||||||
|
u32 size;
|
||||||
|
|
||||||
|
struct mtd_info mtd;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* BCM47XXSFLASH */
|
|
@ -528,6 +528,7 @@ struct bcma_sflash {
|
||||||
u32 size;
|
u32 size;
|
||||||
|
|
||||||
struct mtd_info *mtd;
|
struct mtd_info *mtd;
|
||||||
|
void *priv;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue