diff options
Diffstat (limited to 'drivers/mtd/nand/spia.c')
-rw-r--r-- | drivers/mtd/nand/spia.c | 101 |
1 files changed, 53 insertions, 48 deletions
diff --git a/drivers/mtd/nand/spia.c b/drivers/mtd/nand/spia.c index 9cf1ce718ec1..1f6d429b1583 100644 --- a/drivers/mtd/nand/spia.c +++ b/drivers/mtd/nand/spia.c | |||
@@ -39,16 +39,16 @@ static struct mtd_info *spia_mtd = NULL; | |||
39 | */ | 39 | */ |
40 | #define SPIA_IO_BASE 0xd0000000 /* Start of EP7212 IO address space */ | 40 | #define SPIA_IO_BASE 0xd0000000 /* Start of EP7212 IO address space */ |
41 | #define SPIA_FIO_BASE 0xf0000000 /* Address where flash is mapped */ | 41 | #define SPIA_FIO_BASE 0xf0000000 /* Address where flash is mapped */ |
42 | #define SPIA_PEDR 0x0080 /* | 42 | #define SPIA_PEDR 0x0080 /* |
43 | * IO offset to Port E data register | 43 | * IO offset to Port E data register |
44 | * where the CLE, ALE and NCE pins | 44 | * where the CLE, ALE and NCE pins |
45 | * are wired to. | 45 | * are wired to. |
46 | */ | 46 | */ |
47 | #define SPIA_PEDDR 0x00c0 /* | 47 | #define SPIA_PEDDR 0x00c0 /* |
48 | * IO offset to Port E data direction | 48 | * IO offset to Port E data direction |
49 | * register so we can control the IO | 49 | * register so we can control the IO |
50 | * lines. | 50 | * lines. |
51 | */ | 51 | */ |
52 | 52 | ||
53 | /* | 53 | /* |
54 | * Module stuff | 54 | * Module stuff |
@@ -69,79 +69,84 @@ module_param(spia_peddr, int, 0); | |||
69 | */ | 69 | */ |
70 | static const struct mtd_partition partition_info[] = { | 70 | static const struct mtd_partition partition_info[] = { |
71 | { | 71 | { |
72 | .name = "SPIA flash partition 1", | 72 | .name = "SPIA flash partition 1", |
73 | .offset = 0, | 73 | .offset = 0, |
74 | .size = 2*1024*1024 | 74 | .size = 2 * 1024 * 1024}, |
75 | }, | ||
76 | { | 75 | { |
77 | .name = "SPIA flash partition 2", | 76 | .name = "SPIA flash partition 2", |
78 | .offset = 2*1024*1024, | 77 | .offset = 2 * 1024 * 1024, |
79 | .size = 6*1024*1024 | 78 | .size = 6 * 1024 * 1024} |
80 | } | ||
81 | }; | 79 | }; |
82 | #define NUM_PARTITIONS 2 | ||
83 | 80 | ||
81 | #define NUM_PARTITIONS 2 | ||
84 | 82 | ||
85 | /* | 83 | /* |
86 | * hardware specific access to control-lines | 84 | * hardware specific access to control-lines |
87 | */ | 85 | * |
88 | static void spia_hwcontrol(struct mtd_info *mtd, int cmd){ | 86 | * ctrl: |
89 | 87 | * NAND_CNE: bit 0 -> bit 2 | |
90 | switch(cmd){ | 88 | * NAND_CLE: bit 1 -> bit 0 |
89 | * NAND_ALE: bit 2 -> bit 1 | ||
90 | */ | ||
91 | static void spia_hwcontrol(struct mtd_info *mtd, int cmd) | ||
92 | { | ||
93 | struct nand_chip *chip = mtd->priv; | ||
91 | 94 | ||
92 | case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x01; break; | 95 | if (ctrl & NAND_CTRL_CHANGE) { |
93 | case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break; | 96 | void __iomem *addr = spia_io_base + spia_pedr; |
97 | unsigned char bits; | ||
94 | 98 | ||
95 | case NAND_CTL_SETALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x02; break; | 99 | bits = (ctrl & NAND_CNE) << 2; |
96 | case NAND_CTL_CLRALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x02; break; | 100 | bits |= (ctrl & NAND_CLE | NAND_ALE) >> 1; |
101 | writeb((readb(addr) & ~0x7) | bits, addr); | ||
102 | } | ||
97 | 103 | ||
98 | case NAND_CTL_SETNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x04; break; | 104 | if (cmd != NAND_CMD_NONE) |
99 | case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x04; break; | 105 | writeb(cmd, chip->IO_ADDR_W); |
100 | } | ||
101 | } | 106 | } |
102 | 107 | ||
103 | /* | 108 | /* |
104 | * Main initialization routine | 109 | * Main initialization routine |
105 | */ | 110 | */ |
106 | int __init spia_init (void) | 111 | static int __init spia_init(void) |
107 | { | 112 | { |
108 | struct nand_chip *this; | 113 | struct nand_chip *this; |
109 | 114 | ||
110 | /* Allocate memory for MTD device structure and private data */ | 115 | /* Allocate memory for MTD device structure and private data */ |
111 | spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), | 116 | spia_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
112 | GFP_KERNEL); | ||
113 | if (!spia_mtd) { | 117 | if (!spia_mtd) { |
114 | printk ("Unable to allocate SPIA NAND MTD device structure.\n"); | 118 | printk("Unable to allocate SPIA NAND MTD device structure.\n"); |
115 | return -ENOMEM; | 119 | return -ENOMEM; |
116 | } | 120 | } |
117 | 121 | ||
118 | /* Get pointer to private data */ | 122 | /* Get pointer to private data */ |
119 | this = (struct nand_chip *) (&spia_mtd[1]); | 123 | this = (struct nand_chip *)(&spia_mtd[1]); |
120 | 124 | ||
121 | /* Initialize structures */ | 125 | /* Initialize structures */ |
122 | memset((char *) spia_mtd, 0, sizeof(struct mtd_info)); | 126 | memset(spia_mtd, 0, sizeof(struct mtd_info)); |
123 | memset((char *) this, 0, sizeof(struct nand_chip)); | 127 | memset(this, 0, sizeof(struct nand_chip)); |
124 | 128 | ||
125 | /* Link the private data with the MTD structure */ | 129 | /* Link the private data with the MTD structure */ |
126 | spia_mtd->priv = this; | 130 | spia_mtd->priv = this; |
131 | spia_mtd->owner = THIS_MODULE; | ||
127 | 132 | ||
128 | /* | 133 | /* |
129 | * Set GPIO Port E control register so that the pins are configured | 134 | * Set GPIO Port E control register so that the pins are configured |
130 | * to be outputs for controlling the NAND flash. | 135 | * to be outputs for controlling the NAND flash. |
131 | */ | 136 | */ |
132 | (*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07; | 137 | (*(volatile unsigned char *)(spia_io_base + spia_peddr)) = 0x07; |
133 | 138 | ||
134 | /* Set address of NAND IO lines */ | 139 | /* Set address of NAND IO lines */ |
135 | this->IO_ADDR_R = (void __iomem *) spia_fio_base; | 140 | this->IO_ADDR_R = (void __iomem *)spia_fio_base; |
136 | this->IO_ADDR_W = (void __iomem *) spia_fio_base; | 141 | this->IO_ADDR_W = (void __iomem *)spia_fio_base; |
137 | /* Set address of hardware control function */ | 142 | /* Set address of hardware control function */ |
138 | this->hwcontrol = spia_hwcontrol; | 143 | this->cmd_ctrl = spia_hwcontrol; |
139 | /* 15 us command delay time */ | 144 | /* 15 us command delay time */ |
140 | this->chip_delay = 15; | 145 | this->chip_delay = 15; |
141 | 146 | ||
142 | /* Scan to find existence of the device */ | 147 | /* Scan to find existence of the device */ |
143 | if (nand_scan (spia_mtd, 1)) { | 148 | if (nand_scan(spia_mtd, 1)) { |
144 | kfree (spia_mtd); | 149 | kfree(spia_mtd); |
145 | return -ENXIO; | 150 | return -ENXIO; |
146 | } | 151 | } |
147 | 152 | ||
@@ -151,22 +156,22 @@ int __init spia_init (void) | |||
151 | /* Return happy */ | 156 | /* Return happy */ |
152 | return 0; | 157 | return 0; |
153 | } | 158 | } |
159 | |||
154 | module_init(spia_init); | 160 | module_init(spia_init); |
155 | 161 | ||
156 | /* | 162 | /* |
157 | * Clean up routine | 163 | * Clean up routine |
158 | */ | 164 | */ |
159 | #ifdef MODULE | 165 | static void __exit spia_cleanup(void) |
160 | static void __exit spia_cleanup (void) | ||
161 | { | 166 | { |
162 | /* Release resources, unregister device */ | 167 | /* Release resources, unregister device */ |
163 | nand_release (spia_mtd); | 168 | nand_release(spia_mtd); |
164 | 169 | ||
165 | /* Free the MTD device structure */ | 170 | /* Free the MTD device structure */ |
166 | kfree (spia_mtd); | 171 | kfree(spia_mtd); |
167 | } | 172 | } |
173 | |||
168 | module_exit(spia_cleanup); | 174 | module_exit(spia_cleanup); |
169 | #endif | ||
170 | 175 | ||
171 | MODULE_LICENSE("GPL"); | 176 | MODULE_LICENSE("GPL"); |
172 | MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com"); | 177 | MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com"); |