diff options
author | Rafał Miłecki <zajec5@gmail.com> | 2013-01-06 15:28:50 -0500 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-02-04 02:26:30 -0500 |
commit | a2f74a7dacc1c17a0b146eb3112217874c5db436 (patch) | |
tree | c745afac1c501aefd47b60e85cbc0d3912c9ee4b | |
parent | 396afe553bd607dca4d28b00b6cab2ea826acba2 (diff) |
mtd: bcm47xxsflash: add own struct for abstrating bus type
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
-rw-r--r-- | drivers/mtd/devices/bcm47xxsflash.c | 37 | ||||
-rw-r--r-- | drivers/mtd/devices/bcm47xxsflash.h | 15 | ||||
-rw-r--r-- | include/linux/bcma/bcma_driver_chipcommon.h | 1 |
3 files changed, 40 insertions, 13 deletions
diff --git a/drivers/mtd/devices/bcm47xxsflash.c b/drivers/mtd/devices/bcm47xxsflash.c index 4714584aa993..8fe1a097161b 100644 --- a/drivers/mtd/devices/bcm47xxsflash.c +++ b/drivers/mtd/devices/bcm47xxsflash.c | |||
@@ -5,6 +5,8 @@ | |||
5 | #include <linux/platform_device.h> | 5 | #include <linux/platform_device.h> |
6 | #include <linux/bcma/bcma.h> | 6 | #include <linux/bcma/bcma.h> |
7 | 7 | ||
8 | #include "bcm47xxsflash.h" | ||
9 | |||
8 | MODULE_LICENSE("GPL"); | 10 | MODULE_LICENSE("GPL"); |
9 | MODULE_DESCRIPTION("Serial flash driver for BCMA bus"); | 11 | MODULE_DESCRIPTION("Serial flash driver for BCMA bus"); |
10 | 12 | ||
@@ -13,26 +15,27 @@ static const char *probes[] = { "bcm47xxpart", NULL }; | |||
13 | static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, | 15 | static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, |
14 | size_t *retlen, u_char *buf) | 16 | size_t *retlen, u_char *buf) |
15 | { | 17 | { |
16 | struct bcma_sflash *sflash = mtd->priv; | 18 | struct bcm47xxsflash *b47s = mtd->priv; |
17 | 19 | ||
18 | /* Check address range */ | 20 | /* Check address range */ |
19 | if ((from + len) > mtd->size) | 21 | if ((from + len) > mtd->size) |
20 | return -EINVAL; | 22 | return -EINVAL; |
21 | 23 | ||
22 | memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(sflash->window + from), | 24 | memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from), |
23 | len); | 25 | len); |
24 | 26 | ||
25 | return len; | 27 | return len; |
26 | } | 28 | } |
27 | 29 | ||
28 | static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash, | 30 | static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s) |
29 | struct mtd_info *mtd) | ||
30 | { | 31 | { |
31 | mtd->priv = sflash; | 32 | struct mtd_info *mtd = &b47s->mtd; |
33 | |||
34 | mtd->priv = b47s; | ||
32 | mtd->name = "bcm47xxsflash"; | 35 | mtd->name = "bcm47xxsflash"; |
33 | mtd->owner = THIS_MODULE; | 36 | mtd->owner = THIS_MODULE; |
34 | mtd->type = MTD_ROM; | 37 | mtd->type = MTD_ROM; |
35 | mtd->size = sflash->size; | 38 | mtd->size = b47s->size; |
36 | mtd->_read = bcm47xxsflash_read; | 39 | mtd->_read = bcm47xxsflash_read; |
37 | 40 | ||
38 | /* TODO: implement writing support and verify/change following code */ | 41 | /* TODO: implement writing support and verify/change following code */ |
@@ -43,16 +46,23 @@ static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash, | |||
43 | static int bcm47xxsflash_probe(struct platform_device *pdev) | 46 | static int bcm47xxsflash_probe(struct platform_device *pdev) |
44 | { | 47 | { |
45 | struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); | 48 | struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); |
49 | struct bcm47xxsflash *b47s; | ||
46 | int err; | 50 | int err; |
47 | 51 | ||
48 | sflash->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL); | 52 | b47s = kzalloc(sizeof(*b47s), GFP_KERNEL); |
49 | if (!sflash->mtd) { | 53 | if (!b47s) { |
50 | err = -ENOMEM; | 54 | err = -ENOMEM; |
51 | goto out; | 55 | goto out; |
52 | } | 56 | } |
53 | bcm47xxsflash_fill_mtd(sflash, sflash->mtd); | 57 | sflash->priv = b47s; |
58 | |||
59 | b47s->window = sflash->window; | ||
60 | b47s->blocksize = sflash->blocksize; | ||
61 | b47s->numblocks = sflash->numblocks; | ||
62 | b47s->size = sflash->size; | ||
63 | bcm47xxsflash_fill_mtd(b47s); | ||
54 | 64 | ||
55 | err = mtd_device_parse_register(sflash->mtd, probes, NULL, NULL, 0); | 65 | err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); |
56 | if (err) { | 66 | if (err) { |
57 | pr_err("Failed to register MTD device: %d\n", err); | 67 | pr_err("Failed to register MTD device: %d\n", err); |
58 | goto err_dev_reg; | 68 | goto err_dev_reg; |
@@ -61,7 +71,7 @@ static int bcm47xxsflash_probe(struct platform_device *pdev) | |||
61 | return 0; | 71 | return 0; |
62 | 72 | ||
63 | err_dev_reg: | 73 | err_dev_reg: |
64 | kfree(sflash->mtd); | 74 | kfree(&b47s->mtd); |
65 | out: | 75 | out: |
66 | return err; | 76 | return err; |
67 | } | 77 | } |
@@ -69,9 +79,10 @@ out: | |||
69 | static int bcm47xxsflash_remove(struct platform_device *pdev) | 79 | static int bcm47xxsflash_remove(struct platform_device *pdev) |
70 | { | 80 | { |
71 | struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); | 81 | struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); |
82 | struct bcm47xxsflash *b47s = sflash->priv; | ||
72 | 83 | ||
73 | mtd_device_unregister(sflash->mtd); | 84 | mtd_device_unregister(&b47s->mtd); |
74 | kfree(sflash->mtd); | 85 | kfree(b47s); |
75 | 86 | ||
76 | return 0; | 87 | return 0; |
77 | } | 88 | } |
diff --git a/drivers/mtd/devices/bcm47xxsflash.h b/drivers/mtd/devices/bcm47xxsflash.h new file mode 100644 index 000000000000..ebf6f710e23c --- /dev/null +++ b/drivers/mtd/devices/bcm47xxsflash.h | |||
@@ -0,0 +1,15 @@ | |||
1 | #ifndef __BCM47XXSFLASH_H | ||
2 | #define __BCM47XXSFLASH_H | ||
3 | |||
4 | #include <linux/mtd/mtd.h> | ||
5 | |||
6 | struct bcm47xxsflash { | ||
7 | u32 window; | ||
8 | u32 blocksize; | ||
9 | u16 numblocks; | ||
10 | u32 size; | ||
11 | |||
12 | struct mtd_info mtd; | ||
13 | }; | ||
14 | |||
15 | #endif /* BCM47XXSFLASH */ | ||
diff --git a/include/linux/bcma/bcma_driver_chipcommon.h b/include/linux/bcma/bcma_driver_chipcommon.h index 9a0e3fa3ca95..a5bfda6b0a76 100644 --- a/include/linux/bcma/bcma_driver_chipcommon.h +++ b/include/linux/bcma/bcma_driver_chipcommon.h | |||
@@ -528,6 +528,7 @@ struct bcma_sflash { | |||
528 | u32 size; | 528 | u32 size; |
529 | 529 | ||
530 | struct mtd_info *mtd; | 530 | struct mtd_info *mtd; |
531 | void *priv; | ||
531 | }; | 532 | }; |
532 | #endif | 533 | #endif |
533 | 534 | ||