aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/sharpsl.c
diff options
context:
space:
mode:
authorDmitry Baryshkov <dbaryshkov@gmail.com>2008-10-16 09:58:18 -0400
committerDmitry Baryshkov <dbaryshkov@gmail.com>2008-10-29 14:06:37 -0400
commita4e4f29cbeec200c12c6f3ebedc053a581f90b48 (patch)
tree620a2bdf4fb2c913b231e2eb8381e3eba9ec6fee /drivers/mtd/nand/sharpsl.c
parent2206ef1c5f6002e474b8eff8a56b6b7fd2efbe8f (diff)
[MTD] sharpsl_nand: move io addr to struct sharpsl_nand
Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
Diffstat (limited to 'drivers/mtd/nand/sharpsl.c')
-rw-r--r--drivers/mtd/nand/sharpsl.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 6851806b7015..328e02ee3d8e 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -29,18 +29,20 @@
29struct sharpsl_nand { 29struct sharpsl_nand {
30 struct mtd_info mtd; 30 struct mtd_info mtd;
31 struct nand_chip chip; 31 struct nand_chip chip;
32
33 void __iomem *io;
32}; 34};
33 35
34static void __iomem *sharpsl_io_base; 36#define mtd_to_sharpsl(_mtd) container_of(_mtd, struct sharpsl_nand, mtd)
35 37
36/* register offset */ 38/* register offset */
37#define ECCLPLB sharpsl_io_base+0x00 /* line parity 7 - 0 bit */ 39#define ECCLPLB 0x00 /* line parity 7 - 0 bit */
38#define ECCLPUB sharpsl_io_base+0x04 /* line parity 15 - 8 bit */ 40#define ECCLPUB 0x04 /* line parity 15 - 8 bit */
39#define ECCCP sharpsl_io_base+0x08 /* column parity 5 - 0 bit */ 41#define ECCCP 0x08 /* column parity 5 - 0 bit */
40#define ECCCNTR sharpsl_io_base+0x0C /* ECC byte counter */ 42#define ECCCNTR 0x0C /* ECC byte counter */
41#define ECCCLRR sharpsl_io_base+0x10 /* cleare ECC */ 43#define ECCCLRR 0x10 /* cleare ECC */
42#define FLASHIO sharpsl_io_base+0x14 /* Flash I/O */ 44#define FLASHIO 0x14 /* Flash I/O */
43#define FLASHCTL sharpsl_io_base+0x18 /* Flash Control */ 45#define FLASHCTL 0x18 /* Flash Control */
44 46
45/* Flash control bit */ 47/* Flash control bit */
46#define FLRYBY (1 << 5) 48#define FLRYBY (1 << 5)
@@ -85,6 +87,7 @@ static struct mtd_partition sharpsl_nand_default_partition_info[] = {
85static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, 87static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd,
86 unsigned int ctrl) 88 unsigned int ctrl)
87{ 89{
90 struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd);
88 struct nand_chip *chip = mtd->priv; 91 struct nand_chip *chip = mtd->priv;
89 92
90 if (ctrl & NAND_CTRL_CHANGE) { 93 if (ctrl & NAND_CTRL_CHANGE) {
@@ -94,7 +97,7 @@ static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd,
94 97
95 bits ^= 0x11; 98 bits ^= 0x11;
96 99
97 writeb((readb(FLASHCTL) & ~0x17) | bits, FLASHCTL); 100 writeb((readb(sharpsl->io + FLASHCTL) & ~0x17) | bits, sharpsl->io + FLASHCTL);
98 } 101 }
99 102
100 if (cmd != NAND_CMD_NONE) 103 if (cmd != NAND_CMD_NONE)
@@ -128,20 +131,23 @@ static struct nand_ecclayout akita_oobinfo = {
128 131
129static int sharpsl_nand_dev_ready(struct mtd_info *mtd) 132static int sharpsl_nand_dev_ready(struct mtd_info *mtd)
130{ 133{
131 return !((readb(FLASHCTL) & FLRYBY) == 0); 134 struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd);
135 return !((readb(sharpsl->io + FLASHCTL) & FLRYBY) == 0);
132} 136}
133 137
134static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode) 138static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode)
135{ 139{
136 writeb(0, ECCCLRR); 140 struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd);
141 writeb(0, sharpsl->io + ECCCLRR);
137} 142}
138 143
139static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code) 144static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code)
140{ 145{
141 ecc_code[0] = ~readb(ECCLPUB); 146 struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd);
142 ecc_code[1] = ~readb(ECCLPLB); 147 ecc_code[0] = ~readb(sharpsl->io + ECCLPUB);
143 ecc_code[2] = (~readb(ECCCP) << 2) | 0x03; 148 ecc_code[1] = ~readb(sharpsl->io + ECCLPLB);
144 return readb(ECCCNTR) != 0; 149 ecc_code[2] = (~readb(sharpsl->io + ECCCP) << 2) | 0x03;
150 return readb(sharpsl->io + ECCCNTR) != 0;
145} 151}
146 152
147#ifdef CONFIG_MTD_PARTITIONS 153#ifdef CONFIG_MTD_PARTITIONS
@@ -174,8 +180,8 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
174 } 180 }
175 181
176 /* map physical address */ 182 /* map physical address */
177 sharpsl_io_base = ioremap(r->start, resource_size(r)); 183 sharpsl->io = ioremap(r->start, resource_size(r));
178 if (!sharpsl_io_base) { 184 if (!sharpsl->io) {
179 printk("ioremap to access Sharp SL NAND chip failed\n"); 185 printk("ioremap to access Sharp SL NAND chip failed\n");
180 err = -EIO; 186 err = -EIO;
181 goto err_ioremap; 187 goto err_ioremap;
@@ -193,11 +199,11 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
193 /* 199 /*
194 * PXA initialize 200 * PXA initialize
195 */ 201 */
196 writeb(readb(FLASHCTL) | FLWP, FLASHCTL); 202 writeb(readb(sharpsl->io + FLASHCTL) | FLWP, sharpsl->io + FLASHCTL);
197 203
198 /* Set address of NAND IO lines */ 204 /* Set address of NAND IO lines */
199 this->IO_ADDR_R = FLASHIO; 205 this->IO_ADDR_R = sharpsl->io + FLASHIO;
200 this->IO_ADDR_W = FLASHIO; 206 this->IO_ADDR_W = sharpsl->io + FLASHIO;
201 /* Set address of hardware control function */ 207 /* Set address of hardware control function */
202 this->cmd_ctrl = sharpsl_nand_hwcontrol; 208 this->cmd_ctrl = sharpsl_nand_hwcontrol;
203 this->dev_ready = sharpsl_nand_dev_ready; 209 this->dev_ready = sharpsl_nand_dev_ready;
@@ -218,12 +224,8 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
218 224
219 /* Scan to find existence of the device */ 225 /* Scan to find existence of the device */
220 err = nand_scan(&sharpsl->mtd, 1); 226 err = nand_scan(&sharpsl->mtd, 1);
221 if (err) { 227 if (err)
222 platform_set_drvdata(pdev, NULL); 228 goto err_scan;
223 iounmap(sharpsl_io_base);
224 kfree(sharpsl);
225 return err;
226 }
227 229
228 /* Register the partitions */ 230 /* Register the partitions */
229 sharpsl->mtd.name = "sharpsl-nand"; 231 sharpsl->mtd.name = "sharpsl-nand";
@@ -252,6 +254,9 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
252 /* Return happy */ 254 /* Return happy */
253 return 0; 255 return 0;
254 256
257err_scan:
258 platform_set_drvdata(pdev, NULL);
259 iounmap(sharpsl->io);
255err_ioremap: 260err_ioremap:
256err_get_res: 261err_get_res:
257 kfree(sharpsl); 262 kfree(sharpsl);
@@ -270,7 +275,7 @@ static int __devexit sharpsl_nand_remove(struct platform_device *pdev)
270 275
271 platform_set_drvdata(pdev, NULL); 276 platform_set_drvdata(pdev, NULL);
272 277
273 iounmap(sharpsl_io_base); 278 iounmap(sharpsl->io);
274 279
275 /* Free the MTD device structure */ 280 /* Free the MTD device structure */
276 kfree(sharpsl); 281 kfree(sharpsl);