30bdbb2a81bdaad301dd0bec6c2c60bbfa1c9862
[openwrt/staging/chunkeey.git] / target / linux / brcm47xx / patches-3.8 / 030-mtd-bcm47xxsflash-add-own-struct-for-abstrating-bus-.patch
1 --- a/drivers/mtd/devices/bcm47xxsflash.c
2 +++ b/drivers/mtd/devices/bcm47xxsflash.c
3 @@ -5,6 +5,8 @@
4 #include <linux/platform_device.h>
5 #include <linux/bcma/bcma.h>
6
7 +#include "bcm47xxsflash.h"
8 +
9 MODULE_LICENSE("GPL");
10 MODULE_DESCRIPTION("Serial flash driver for BCMA bus");
11
12 @@ -13,26 +15,27 @@ static const char *probes[] = { "bcm47xx
13 static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
14 size_t *retlen, u_char *buf)
15 {
16 - struct bcma_sflash *sflash = mtd->priv;
17 + struct bcm47xxsflash *b47s = mtd->priv;
18
19 /* Check address range */
20 if ((from + len) > mtd->size)
21 return -EINVAL;
22
23 - memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(sflash->window + from),
24 + memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
25 len);
26
27 return len;
28 }
29
30 -static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
31 - struct mtd_info *mtd)
32 +static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s)
33 {
34 - mtd->priv = sflash;
35 + struct mtd_info *mtd = &b47s->mtd;
36 +
37 + mtd->priv = b47s;
38 mtd->name = "bcm47xxsflash";
39 mtd->owner = THIS_MODULE;
40 mtd->type = MTD_ROM;
41 - mtd->size = sflash->size;
42 + mtd->size = b47s->size;
43 mtd->_read = bcm47xxsflash_read;
44
45 /* TODO: implement writing support and verify/change following code */
46 @@ -43,16 +46,23 @@ static void bcm47xxsflash_fill_mtd(struc
47 static int bcm47xxsflash_probe(struct platform_device *pdev)
48 {
49 struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
50 + struct bcm47xxsflash *b47s;
51 int err;
52
53 - sflash->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
54 - if (!sflash->mtd) {
55 + b47s = kzalloc(sizeof(*b47s), GFP_KERNEL);
56 + if (!b47s) {
57 err = -ENOMEM;
58 goto out;
59 }
60 - bcm47xxsflash_fill_mtd(sflash, sflash->mtd);
61 + sflash->priv = b47s;
62 +
63 + b47s->window = sflash->window;
64 + b47s->blocksize = sflash->blocksize;
65 + b47s->numblocks = sflash->numblocks;
66 + b47s->size = sflash->size;
67 + bcm47xxsflash_fill_mtd(b47s);
68
69 - err = mtd_device_parse_register(sflash->mtd, probes, NULL, NULL, 0);
70 + err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
71 if (err) {
72 pr_err("Failed to register MTD device: %d\n", err);
73 goto err_dev_reg;
74 @@ -61,7 +71,7 @@ static int bcm47xxsflash_probe(struct pl
75 return 0;
76
77 err_dev_reg:
78 - kfree(sflash->mtd);
79 + kfree(&b47s->mtd);
80 out:
81 return err;
82 }
83 @@ -69,9 +79,10 @@ out:
84 static int bcm47xxsflash_remove(struct platform_device *pdev)
85 {
86 struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
87 + struct bcm47xxsflash *b47s = sflash->priv;
88
89 - mtd_device_unregister(sflash->mtd);
90 - kfree(sflash->mtd);
91 + mtd_device_unregister(&b47s->mtd);
92 + kfree(b47s);
93
94 return 0;
95 }
96 --- /dev/null
97 +++ b/drivers/mtd/devices/bcm47xxsflash.h
98 @@ -0,0 +1,15 @@
99 +#ifndef __BCM47XXSFLASH_H
100 +#define __BCM47XXSFLASH_H
101 +
102 +#include <linux/mtd/mtd.h>
103 +
104 +struct bcm47xxsflash {
105 + u32 window;
106 + u32 blocksize;
107 + u16 numblocks;
108 + u32 size;
109 +
110 + struct mtd_info mtd;
111 +};
112 +
113 +#endif /* BCM47XXSFLASH */
114 --- a/include/linux/bcma/bcma_driver_chipcommon.h
115 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
116 @@ -528,6 +528,7 @@ struct bcma_sflash {
117 u32 size;
118
119 struct mtd_info *mtd;
120 + void *priv;
121 };
122 #endif
123