Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mtd/onenand/omap2.c |
| 3 | * |
| 4 | * OneNAND driver for OMAP2 / OMAP3 |
| 5 | * |
| 6 | * Copyright © 2005-2006 Nokia Corporation |
| 7 | * |
| 8 | * Author: Jarkko Lavinen <jarkko.lavinen@nokia.com> and Juha Yrjölä |
| 9 | * IRQ and DMA support written by Timo Teras |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License version 2 as published by |
| 13 | * the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 18 | * more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along with |
| 21 | * this program; see the file COPYING. If not, write to the Free Software |
| 22 | * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/device.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/mtd/mtd.h> |
| 30 | #include <linux/mtd/onenand.h> |
| 31 | #include <linux/mtd/partitions.h> |
| 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/delay.h> |
Adrian Hunter | cbbd695 | 2008-11-24 14:44:36 +0200 | [diff] [blame] | 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 38 | #include <linux/regulator/consumer.h> |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 39 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 40 | #include <asm/mach/flash.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 41 | #include <plat/gpmc.h> |
| 42 | #include <plat/onenand.h> |
Russell King | 1bc857f | 2011-07-26 10:54:55 +0100 | [diff] [blame^] | 43 | #include <asm/gpio.h> |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 44 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 45 | #include <plat/dma.h> |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 46 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 47 | #include <plat/board.h> |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 48 | |
| 49 | #define DRIVER_NAME "omap2-onenand" |
| 50 | |
| 51 | #define ONENAND_IO_SIZE SZ_128K |
| 52 | #define ONENAND_BUFRAM_SIZE (1024 * 5) |
| 53 | |
| 54 | struct omap2_onenand { |
| 55 | struct platform_device *pdev; |
| 56 | int gpmc_cs; |
| 57 | unsigned long phys_base; |
| 58 | int gpio_irq; |
| 59 | struct mtd_info mtd; |
| 60 | struct mtd_partition *parts; |
| 61 | struct onenand_chip onenand; |
| 62 | struct completion irq_done; |
| 63 | struct completion dma_done; |
| 64 | int dma_channel; |
| 65 | int freq; |
Adrian Hunter | 3ad2d86 | 2011-02-07 10:46:59 +0200 | [diff] [blame] | 66 | int (*setup)(void __iomem *base, int *freq_ptr); |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 67 | struct regulator *regulator; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 68 | }; |
| 69 | |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 70 | static const char *part_probes[] = { "cmdlinepart", NULL, }; |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 71 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 72 | static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data) |
| 73 | { |
| 74 | struct omap2_onenand *c = data; |
| 75 | |
| 76 | complete(&c->dma_done); |
| 77 | } |
| 78 | |
| 79 | static irqreturn_t omap2_onenand_interrupt(int irq, void *dev_id) |
| 80 | { |
| 81 | struct omap2_onenand *c = dev_id; |
| 82 | |
| 83 | complete(&c->irq_done); |
| 84 | |
| 85 | return IRQ_HANDLED; |
| 86 | } |
| 87 | |
| 88 | static inline unsigned short read_reg(struct omap2_onenand *c, int reg) |
| 89 | { |
| 90 | return readw(c->onenand.base + reg); |
| 91 | } |
| 92 | |
| 93 | static inline void write_reg(struct omap2_onenand *c, unsigned short value, |
| 94 | int reg) |
| 95 | { |
| 96 | writew(value, c->onenand.base + reg); |
| 97 | } |
| 98 | |
| 99 | static void wait_err(char *msg, int state, unsigned int ctrl, unsigned int intr) |
| 100 | { |
| 101 | printk(KERN_ERR "onenand_wait: %s! state %d ctrl 0x%04x intr 0x%04x\n", |
| 102 | msg, state, ctrl, intr); |
| 103 | } |
| 104 | |
| 105 | static void wait_warn(char *msg, int state, unsigned int ctrl, |
| 106 | unsigned int intr) |
| 107 | { |
| 108 | printk(KERN_WARNING "onenand_wait: %s! state %d ctrl 0x%04x " |
| 109 | "intr 0x%04x\n", msg, state, ctrl, intr); |
| 110 | } |
| 111 | |
| 112 | static int omap2_onenand_wait(struct mtd_info *mtd, int state) |
| 113 | { |
| 114 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
Roman Tereshonkov | d19d7b4 | 2010-11-03 12:55:20 +0200 | [diff] [blame] | 115 | struct onenand_chip *this = mtd->priv; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 116 | unsigned int intr = 0; |
Roman Tereshonkov | d19d7b4 | 2010-11-03 12:55:20 +0200 | [diff] [blame] | 117 | unsigned int ctrl, ctrl_mask; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 118 | unsigned long timeout; |
| 119 | u32 syscfg; |
| 120 | |
Mika Korhonen | 7207302 | 2009-10-23 07:50:43 +0200 | [diff] [blame] | 121 | if (state == FL_RESETING || state == FL_PREPARING_ERASE || |
| 122 | state == FL_VERIFYING_ERASE) { |
| 123 | int i = 21; |
| 124 | unsigned int intr_flags = ONENAND_INT_MASTER; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 125 | |
Mika Korhonen | 7207302 | 2009-10-23 07:50:43 +0200 | [diff] [blame] | 126 | switch (state) { |
| 127 | case FL_RESETING: |
| 128 | intr_flags |= ONENAND_INT_RESET; |
| 129 | break; |
| 130 | case FL_PREPARING_ERASE: |
| 131 | intr_flags |= ONENAND_INT_ERASE; |
| 132 | break; |
| 133 | case FL_VERIFYING_ERASE: |
| 134 | i = 101; |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | while (--i) { |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 139 | udelay(1); |
| 140 | intr = read_reg(c, ONENAND_REG_INTERRUPT); |
| 141 | if (intr & ONENAND_INT_MASTER) |
| 142 | break; |
| 143 | } |
| 144 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); |
| 145 | if (ctrl & ONENAND_CTRL_ERROR) { |
| 146 | wait_err("controller error", state, ctrl, intr); |
| 147 | return -EIO; |
| 148 | } |
Roman Tereshonkov | c497dd5 | 2011-02-07 10:47:01 +0200 | [diff] [blame] | 149 | if ((intr & intr_flags) == intr_flags) |
| 150 | return 0; |
| 151 | /* Continue in wait for interrupt branch */ |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if (state != FL_READING) { |
| 155 | int result; |
| 156 | |
| 157 | /* Turn interrupts on */ |
| 158 | syscfg = read_reg(c, ONENAND_REG_SYS_CFG1); |
Adrian Hunter | 782b7a3 | 2008-08-14 14:00:12 +0300 | [diff] [blame] | 159 | if (!(syscfg & ONENAND_SYS_CFG1_IOBE)) { |
| 160 | syscfg |= ONENAND_SYS_CFG1_IOBE; |
| 161 | write_reg(c, syscfg, ONENAND_REG_SYS_CFG1); |
| 162 | if (cpu_is_omap34xx()) |
| 163 | /* Add a delay to let GPIO settle */ |
| 164 | syscfg = read_reg(c, ONENAND_REG_SYS_CFG1); |
| 165 | } |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 166 | |
| 167 | INIT_COMPLETION(c->irq_done); |
| 168 | if (c->gpio_irq) { |
David Brownell | 0b84b5c | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 169 | result = gpio_get_value(c->gpio_irq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 170 | if (result == -1) { |
| 171 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); |
| 172 | intr = read_reg(c, ONENAND_REG_INTERRUPT); |
| 173 | wait_err("gpio error", state, ctrl, intr); |
| 174 | return -EIO; |
| 175 | } |
| 176 | } else |
| 177 | result = 0; |
| 178 | if (result == 0) { |
| 179 | int retry_cnt = 0; |
| 180 | retry: |
| 181 | result = wait_for_completion_timeout(&c->irq_done, |
| 182 | msecs_to_jiffies(20)); |
| 183 | if (result == 0) { |
| 184 | /* Timeout after 20ms */ |
| 185 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); |
Roman Tereshonkov | d19d7b4 | 2010-11-03 12:55:20 +0200 | [diff] [blame] | 186 | if (ctrl & ONENAND_CTRL_ONGO && |
| 187 | !this->ongoing) { |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 188 | /* |
| 189 | * The operation seems to be still going |
| 190 | * so give it some more time. |
| 191 | */ |
| 192 | retry_cnt += 1; |
| 193 | if (retry_cnt < 3) |
| 194 | goto retry; |
| 195 | intr = read_reg(c, |
| 196 | ONENAND_REG_INTERRUPT); |
| 197 | wait_err("timeout", state, ctrl, intr); |
| 198 | return -EIO; |
| 199 | } |
| 200 | intr = read_reg(c, ONENAND_REG_INTERRUPT); |
| 201 | if ((intr & ONENAND_INT_MASTER) == 0) |
| 202 | wait_warn("timeout", state, ctrl, intr); |
| 203 | } |
| 204 | } |
| 205 | } else { |
Adrian Hunter | 8afbc11 | 2008-08-25 12:01:31 +0300 | [diff] [blame] | 206 | int retry_cnt = 0; |
| 207 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 208 | /* Turn interrupts off */ |
| 209 | syscfg = read_reg(c, ONENAND_REG_SYS_CFG1); |
| 210 | syscfg &= ~ONENAND_SYS_CFG1_IOBE; |
| 211 | write_reg(c, syscfg, ONENAND_REG_SYS_CFG1); |
| 212 | |
| 213 | timeout = jiffies + msecs_to_jiffies(20); |
Adrian Hunter | 8afbc11 | 2008-08-25 12:01:31 +0300 | [diff] [blame] | 214 | while (1) { |
| 215 | if (time_before(jiffies, timeout)) { |
| 216 | intr = read_reg(c, ONENAND_REG_INTERRUPT); |
| 217 | if (intr & ONENAND_INT_MASTER) |
| 218 | break; |
| 219 | } else { |
| 220 | /* Timeout after 20ms */ |
| 221 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); |
| 222 | if (ctrl & ONENAND_CTRL_ONGO) { |
| 223 | /* |
| 224 | * The operation seems to be still going |
| 225 | * so give it some more time. |
| 226 | */ |
| 227 | retry_cnt += 1; |
| 228 | if (retry_cnt < 3) { |
| 229 | timeout = jiffies + |
| 230 | msecs_to_jiffies(20); |
| 231 | continue; |
| 232 | } |
| 233 | } |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 234 | break; |
Adrian Hunter | 8afbc11 | 2008-08-25 12:01:31 +0300 | [diff] [blame] | 235 | } |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | intr = read_reg(c, ONENAND_REG_INTERRUPT); |
| 240 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); |
| 241 | |
| 242 | if (intr & ONENAND_INT_READ) { |
| 243 | int ecc = read_reg(c, ONENAND_REG_ECC_STATUS); |
| 244 | |
| 245 | if (ecc) { |
| 246 | unsigned int addr1, addr8; |
| 247 | |
| 248 | addr1 = read_reg(c, ONENAND_REG_START_ADDRESS1); |
| 249 | addr8 = read_reg(c, ONENAND_REG_START_ADDRESS8); |
| 250 | if (ecc & ONENAND_ECC_2BIT_ALL) { |
| 251 | printk(KERN_ERR "onenand_wait: ECC error = " |
| 252 | "0x%04x, addr1 %#x, addr8 %#x\n", |
| 253 | ecc, addr1, addr8); |
| 254 | mtd->ecc_stats.failed++; |
| 255 | return -EBADMSG; |
| 256 | } else if (ecc & ONENAND_ECC_1BIT_ALL) { |
| 257 | printk(KERN_NOTICE "onenand_wait: correctable " |
| 258 | "ECC error = 0x%04x, addr1 %#x, " |
| 259 | "addr8 %#x\n", ecc, addr1, addr8); |
| 260 | mtd->ecc_stats.corrected++; |
| 261 | } |
| 262 | } |
| 263 | } else if (state == FL_READING) { |
| 264 | wait_err("timeout", state, ctrl, intr); |
| 265 | return -EIO; |
| 266 | } |
| 267 | |
| 268 | if (ctrl & ONENAND_CTRL_ERROR) { |
| 269 | wait_err("controller error", state, ctrl, intr); |
| 270 | if (ctrl & ONENAND_CTRL_LOCK) |
| 271 | printk(KERN_ERR "onenand_wait: " |
| 272 | "Device is write protected!!!\n"); |
| 273 | return -EIO; |
| 274 | } |
| 275 | |
Roman Tereshonkov | d19d7b4 | 2010-11-03 12:55:20 +0200 | [diff] [blame] | 276 | ctrl_mask = 0xFE9F; |
| 277 | if (this->ongoing) |
| 278 | ctrl_mask &= ~0x8000; |
| 279 | |
| 280 | if (ctrl & ctrl_mask) |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 281 | wait_warn("unexpected controller status", state, ctrl, intr); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static inline int omap2_onenand_bufferram_offset(struct mtd_info *mtd, int area) |
| 287 | { |
| 288 | struct onenand_chip *this = mtd->priv; |
| 289 | |
| 290 | if (ONENAND_CURRENT_BUFFERRAM(this)) { |
| 291 | if (area == ONENAND_DATARAM) |
Mika Korhonen | 00acf4a | 2009-06-11 14:05:07 +0300 | [diff] [blame] | 292 | return this->writesize; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 293 | if (area == ONENAND_SPARERAM) |
| 294 | return mtd->oobsize; |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | #if defined(CONFIG_ARCH_OMAP3) || defined(MULTI_OMAP2) |
| 301 | |
| 302 | static int omap3_onenand_read_bufferram(struct mtd_info *mtd, int area, |
| 303 | unsigned char *buffer, int offset, |
| 304 | size_t count) |
| 305 | { |
| 306 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
| 307 | struct onenand_chip *this = mtd->priv; |
| 308 | dma_addr_t dma_src, dma_dst; |
| 309 | int bram_offset; |
| 310 | unsigned long timeout; |
| 311 | void *buf = (void *)buffer; |
| 312 | size_t xtra; |
| 313 | volatile unsigned *done; |
| 314 | |
| 315 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; |
| 316 | if (bram_offset & 3 || (size_t)buf & 3 || count < 384) |
| 317 | goto out_copy; |
| 318 | |
Adrian Hunter | a29f280 | 2009-03-23 14:57:38 +0200 | [diff] [blame] | 319 | /* panic_write() may be in an interrupt context */ |
Aaro Koskinen | 932f5d2 | 2010-02-10 19:03:19 +0200 | [diff] [blame] | 320 | if (in_interrupt() || oops_in_progress) |
Adrian Hunter | a29f280 | 2009-03-23 14:57:38 +0200 | [diff] [blame] | 321 | goto out_copy; |
| 322 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 323 | if (buf >= high_memory) { |
| 324 | struct page *p1; |
| 325 | |
| 326 | if (((size_t)buf & PAGE_MASK) != |
| 327 | ((size_t)(buf + count - 1) & PAGE_MASK)) |
| 328 | goto out_copy; |
| 329 | p1 = vmalloc_to_page(buf); |
| 330 | if (!p1) |
| 331 | goto out_copy; |
| 332 | buf = page_address(p1) + ((size_t)buf & ~PAGE_MASK); |
| 333 | } |
| 334 | |
| 335 | xtra = count & 3; |
| 336 | if (xtra) { |
| 337 | count -= xtra; |
| 338 | memcpy(buf + count, this->base + bram_offset + count, xtra); |
| 339 | } |
| 340 | |
| 341 | dma_src = c->phys_base + bram_offset; |
| 342 | dma_dst = dma_map_single(&c->pdev->dev, buf, count, DMA_FROM_DEVICE); |
| 343 | if (dma_mapping_error(&c->pdev->dev, dma_dst)) { |
| 344 | dev_err(&c->pdev->dev, |
| 345 | "Couldn't DMA map a %d byte buffer\n", |
| 346 | count); |
| 347 | goto out_copy; |
| 348 | } |
| 349 | |
| 350 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S32, |
| 351 | count >> 2, 1, 0, 0, 0); |
| 352 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 353 | dma_src, 0, 0); |
| 354 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 355 | dma_dst, 0, 0); |
| 356 | |
| 357 | INIT_COMPLETION(c->dma_done); |
| 358 | omap_start_dma(c->dma_channel); |
| 359 | |
| 360 | timeout = jiffies + msecs_to_jiffies(20); |
| 361 | done = &c->dma_done.done; |
| 362 | while (time_before(jiffies, timeout)) |
| 363 | if (*done) |
| 364 | break; |
| 365 | |
| 366 | dma_unmap_single(&c->pdev->dev, dma_dst, count, DMA_FROM_DEVICE); |
| 367 | |
| 368 | if (!*done) { |
| 369 | dev_err(&c->pdev->dev, "timeout waiting for DMA\n"); |
| 370 | goto out_copy; |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | |
| 375 | out_copy: |
| 376 | memcpy(buf, this->base + bram_offset, count); |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int omap3_onenand_write_bufferram(struct mtd_info *mtd, int area, |
| 381 | const unsigned char *buffer, |
| 382 | int offset, size_t count) |
| 383 | { |
| 384 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
| 385 | struct onenand_chip *this = mtd->priv; |
| 386 | dma_addr_t dma_src, dma_dst; |
| 387 | int bram_offset; |
| 388 | unsigned long timeout; |
| 389 | void *buf = (void *)buffer; |
| 390 | volatile unsigned *done; |
| 391 | |
| 392 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; |
| 393 | if (bram_offset & 3 || (size_t)buf & 3 || count < 384) |
| 394 | goto out_copy; |
| 395 | |
| 396 | /* panic_write() may be in an interrupt context */ |
Aaro Koskinen | 932f5d2 | 2010-02-10 19:03:19 +0200 | [diff] [blame] | 397 | if (in_interrupt() || oops_in_progress) |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 398 | goto out_copy; |
| 399 | |
| 400 | if (buf >= high_memory) { |
| 401 | struct page *p1; |
| 402 | |
| 403 | if (((size_t)buf & PAGE_MASK) != |
| 404 | ((size_t)(buf + count - 1) & PAGE_MASK)) |
| 405 | goto out_copy; |
| 406 | p1 = vmalloc_to_page(buf); |
| 407 | if (!p1) |
| 408 | goto out_copy; |
| 409 | buf = page_address(p1) + ((size_t)buf & ~PAGE_MASK); |
| 410 | } |
| 411 | |
| 412 | dma_src = dma_map_single(&c->pdev->dev, buf, count, DMA_TO_DEVICE); |
| 413 | dma_dst = c->phys_base + bram_offset; |
Mika Westerberg | 4a70b7d | 2010-03-24 12:10:48 +0200 | [diff] [blame] | 414 | if (dma_mapping_error(&c->pdev->dev, dma_src)) { |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 415 | dev_err(&c->pdev->dev, |
| 416 | "Couldn't DMA map a %d byte buffer\n", |
| 417 | count); |
| 418 | return -1; |
| 419 | } |
| 420 | |
| 421 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S32, |
| 422 | count >> 2, 1, 0, 0, 0); |
| 423 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 424 | dma_src, 0, 0); |
| 425 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 426 | dma_dst, 0, 0); |
| 427 | |
| 428 | INIT_COMPLETION(c->dma_done); |
| 429 | omap_start_dma(c->dma_channel); |
| 430 | |
| 431 | timeout = jiffies + msecs_to_jiffies(20); |
| 432 | done = &c->dma_done.done; |
| 433 | while (time_before(jiffies, timeout)) |
| 434 | if (*done) |
| 435 | break; |
| 436 | |
Mika Westerberg | 4a70b7d | 2010-03-24 12:10:48 +0200 | [diff] [blame] | 437 | dma_unmap_single(&c->pdev->dev, dma_src, count, DMA_TO_DEVICE); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 438 | |
| 439 | if (!*done) { |
| 440 | dev_err(&c->pdev->dev, "timeout waiting for DMA\n"); |
| 441 | goto out_copy; |
| 442 | } |
| 443 | |
| 444 | return 0; |
| 445 | |
| 446 | out_copy: |
| 447 | memcpy(this->base + bram_offset, buf, count); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | #else |
| 452 | |
| 453 | int omap3_onenand_read_bufferram(struct mtd_info *mtd, int area, |
| 454 | unsigned char *buffer, int offset, |
| 455 | size_t count); |
| 456 | |
| 457 | int omap3_onenand_write_bufferram(struct mtd_info *mtd, int area, |
| 458 | const unsigned char *buffer, |
| 459 | int offset, size_t count); |
| 460 | |
| 461 | #endif |
| 462 | |
| 463 | #if defined(CONFIG_ARCH_OMAP2) || defined(MULTI_OMAP2) |
| 464 | |
| 465 | static int omap2_onenand_read_bufferram(struct mtd_info *mtd, int area, |
| 466 | unsigned char *buffer, int offset, |
| 467 | size_t count) |
| 468 | { |
| 469 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
| 470 | struct onenand_chip *this = mtd->priv; |
| 471 | dma_addr_t dma_src, dma_dst; |
| 472 | int bram_offset; |
| 473 | |
| 474 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; |
| 475 | /* DMA is not used. Revisit PM requirements before enabling it. */ |
| 476 | if (1 || (c->dma_channel < 0) || |
| 477 | ((void *) buffer >= (void *) high_memory) || (bram_offset & 3) || |
| 478 | (((unsigned int) buffer) & 3) || (count < 1024) || (count & 3)) { |
| 479 | memcpy(buffer, (__force void *)(this->base + bram_offset), |
| 480 | count); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | dma_src = c->phys_base + bram_offset; |
| 485 | dma_dst = dma_map_single(&c->pdev->dev, buffer, count, |
| 486 | DMA_FROM_DEVICE); |
| 487 | if (dma_mapping_error(&c->pdev->dev, dma_dst)) { |
| 488 | dev_err(&c->pdev->dev, |
| 489 | "Couldn't DMA map a %d byte buffer\n", |
| 490 | count); |
| 491 | return -1; |
| 492 | } |
| 493 | |
| 494 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S32, |
| 495 | count / 4, 1, 0, 0, 0); |
| 496 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 497 | dma_src, 0, 0); |
| 498 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 499 | dma_dst, 0, 0); |
| 500 | |
| 501 | INIT_COMPLETION(c->dma_done); |
| 502 | omap_start_dma(c->dma_channel); |
| 503 | wait_for_completion(&c->dma_done); |
| 504 | |
| 505 | dma_unmap_single(&c->pdev->dev, dma_dst, count, DMA_FROM_DEVICE); |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static int omap2_onenand_write_bufferram(struct mtd_info *mtd, int area, |
| 511 | const unsigned char *buffer, |
| 512 | int offset, size_t count) |
| 513 | { |
| 514 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
| 515 | struct onenand_chip *this = mtd->priv; |
| 516 | dma_addr_t dma_src, dma_dst; |
| 517 | int bram_offset; |
| 518 | |
| 519 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; |
| 520 | /* DMA is not used. Revisit PM requirements before enabling it. */ |
| 521 | if (1 || (c->dma_channel < 0) || |
| 522 | ((void *) buffer >= (void *) high_memory) || (bram_offset & 3) || |
| 523 | (((unsigned int) buffer) & 3) || (count < 1024) || (count & 3)) { |
| 524 | memcpy((__force void *)(this->base + bram_offset), buffer, |
| 525 | count); |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | dma_src = dma_map_single(&c->pdev->dev, (void *) buffer, count, |
| 530 | DMA_TO_DEVICE); |
| 531 | dma_dst = c->phys_base + bram_offset; |
Mika Westerberg | 4a70b7d | 2010-03-24 12:10:48 +0200 | [diff] [blame] | 532 | if (dma_mapping_error(&c->pdev->dev, dma_src)) { |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 533 | dev_err(&c->pdev->dev, |
| 534 | "Couldn't DMA map a %d byte buffer\n", |
| 535 | count); |
| 536 | return -1; |
| 537 | } |
| 538 | |
| 539 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S16, |
| 540 | count / 2, 1, 0, 0, 0); |
| 541 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 542 | dma_src, 0, 0); |
| 543 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, |
| 544 | dma_dst, 0, 0); |
| 545 | |
| 546 | INIT_COMPLETION(c->dma_done); |
| 547 | omap_start_dma(c->dma_channel); |
| 548 | wait_for_completion(&c->dma_done); |
| 549 | |
Mika Westerberg | 4a70b7d | 2010-03-24 12:10:48 +0200 | [diff] [blame] | 550 | dma_unmap_single(&c->pdev->dev, dma_src, count, DMA_TO_DEVICE); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | #else |
| 556 | |
| 557 | int omap2_onenand_read_bufferram(struct mtd_info *mtd, int area, |
| 558 | unsigned char *buffer, int offset, |
| 559 | size_t count); |
| 560 | |
| 561 | int omap2_onenand_write_bufferram(struct mtd_info *mtd, int area, |
| 562 | const unsigned char *buffer, |
| 563 | int offset, size_t count); |
| 564 | |
| 565 | #endif |
| 566 | |
| 567 | static struct platform_driver omap2_onenand_driver; |
| 568 | |
| 569 | static int __adjust_timing(struct device *dev, void *data) |
| 570 | { |
| 571 | int ret = 0; |
| 572 | struct omap2_onenand *c; |
| 573 | |
| 574 | c = dev_get_drvdata(dev); |
| 575 | |
| 576 | BUG_ON(c->setup == NULL); |
| 577 | |
| 578 | /* DMA is not in use so this is all that is needed */ |
| 579 | /* Revisit for OMAP3! */ |
Adrian Hunter | 3ad2d86 | 2011-02-07 10:46:59 +0200 | [diff] [blame] | 580 | ret = c->setup(c->onenand.base, &c->freq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 581 | |
| 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | int omap2_onenand_rephase(void) |
| 586 | { |
| 587 | return driver_for_each_device(&omap2_onenand_driver.driver, NULL, |
| 588 | NULL, __adjust_timing); |
| 589 | } |
| 590 | |
Mika Korhonen | d3412db | 2009-05-21 23:09:42 +0300 | [diff] [blame] | 591 | static void omap2_onenand_shutdown(struct platform_device *pdev) |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 592 | { |
| 593 | struct omap2_onenand *c = dev_get_drvdata(&pdev->dev); |
| 594 | |
| 595 | /* With certain content in the buffer RAM, the OMAP boot ROM code |
| 596 | * can recognize the flash chip incorrectly. Zero it out before |
| 597 | * soft reset. |
| 598 | */ |
| 599 | memset((__force void *)c->onenand.base, 0, ONENAND_BUFRAM_SIZE); |
| 600 | } |
| 601 | |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 602 | static int omap2_onenand_enable(struct mtd_info *mtd) |
| 603 | { |
| 604 | int ret; |
| 605 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
| 606 | |
| 607 | ret = regulator_enable(c->regulator); |
| 608 | if (ret != 0) |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 609 | dev_err(&c->pdev->dev, "can't enable regulator\n"); |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 610 | |
| 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | static int omap2_onenand_disable(struct mtd_info *mtd) |
| 615 | { |
| 616 | int ret; |
| 617 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); |
| 618 | |
| 619 | ret = regulator_disable(c->regulator); |
| 620 | if (ret != 0) |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 621 | dev_err(&c->pdev->dev, "can't disable regulator\n"); |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 622 | |
| 623 | return ret; |
| 624 | } |
| 625 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 626 | static int __devinit omap2_onenand_probe(struct platform_device *pdev) |
| 627 | { |
| 628 | struct omap_onenand_platform_data *pdata; |
| 629 | struct omap2_onenand *c; |
Roman Tereshonkov | c93ff6b | 2011-02-17 13:44:42 +0200 | [diff] [blame] | 630 | struct onenand_chip *this; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 631 | int r; |
| 632 | |
| 633 | pdata = pdev->dev.platform_data; |
| 634 | if (pdata == NULL) { |
| 635 | dev_err(&pdev->dev, "platform data missing\n"); |
| 636 | return -ENODEV; |
| 637 | } |
| 638 | |
| 639 | c = kzalloc(sizeof(struct omap2_onenand), GFP_KERNEL); |
| 640 | if (!c) |
| 641 | return -ENOMEM; |
| 642 | |
| 643 | init_completion(&c->irq_done); |
| 644 | init_completion(&c->dma_done); |
| 645 | c->gpmc_cs = pdata->cs; |
| 646 | c->gpio_irq = pdata->gpio_irq; |
| 647 | c->dma_channel = pdata->dma_channel; |
| 648 | if (c->dma_channel < 0) { |
| 649 | /* if -1, don't use DMA */ |
| 650 | c->gpio_irq = 0; |
| 651 | } |
| 652 | |
| 653 | r = gpmc_cs_request(c->gpmc_cs, ONENAND_IO_SIZE, &c->phys_base); |
| 654 | if (r < 0) { |
| 655 | dev_err(&pdev->dev, "Cannot request GPMC CS\n"); |
| 656 | goto err_kfree; |
| 657 | } |
| 658 | |
| 659 | if (request_mem_region(c->phys_base, ONENAND_IO_SIZE, |
| 660 | pdev->dev.driver->name) == NULL) { |
| 661 | dev_err(&pdev->dev, "Cannot reserve memory region at 0x%08lx, " |
| 662 | "size: 0x%x\n", c->phys_base, ONENAND_IO_SIZE); |
| 663 | r = -EBUSY; |
| 664 | goto err_free_cs; |
| 665 | } |
| 666 | c->onenand.base = ioremap(c->phys_base, ONENAND_IO_SIZE); |
| 667 | if (c->onenand.base == NULL) { |
| 668 | r = -ENOMEM; |
| 669 | goto err_release_mem_region; |
| 670 | } |
| 671 | |
| 672 | if (pdata->onenand_setup != NULL) { |
Adrian Hunter | 3ad2d86 | 2011-02-07 10:46:59 +0200 | [diff] [blame] | 673 | r = pdata->onenand_setup(c->onenand.base, &c->freq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 674 | if (r < 0) { |
| 675 | dev_err(&pdev->dev, "Onenand platform setup failed: " |
| 676 | "%d\n", r); |
| 677 | goto err_iounmap; |
| 678 | } |
| 679 | c->setup = pdata->onenand_setup; |
| 680 | } |
| 681 | |
| 682 | if (c->gpio_irq) { |
Jarkko Nikula | 73069e3 | 2009-01-15 13:09:52 +0200 | [diff] [blame] | 683 | if ((r = gpio_request(c->gpio_irq, "OneNAND irq")) < 0) { |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 684 | dev_err(&pdev->dev, "Failed to request GPIO%d for " |
| 685 | "OneNAND\n", c->gpio_irq); |
| 686 | goto err_iounmap; |
| 687 | } |
David Brownell | 40e3925 | 2008-12-10 17:35:26 -0800 | [diff] [blame] | 688 | gpio_direction_input(c->gpio_irq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 689 | |
David Brownell | 15f74b0 | 2008-12-10 17:35:26 -0800 | [diff] [blame] | 690 | if ((r = request_irq(gpio_to_irq(c->gpio_irq), |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 691 | omap2_onenand_interrupt, IRQF_TRIGGER_RISING, |
| 692 | pdev->dev.driver->name, c)) < 0) |
| 693 | goto err_release_gpio; |
| 694 | } |
| 695 | |
| 696 | if (c->dma_channel >= 0) { |
| 697 | r = omap_request_dma(0, pdev->dev.driver->name, |
| 698 | omap2_onenand_dma_cb, (void *) c, |
| 699 | &c->dma_channel); |
| 700 | if (r == 0) { |
| 701 | omap_set_dma_write_mode(c->dma_channel, |
| 702 | OMAP_DMA_WRITE_NON_POSTED); |
| 703 | omap_set_dma_src_data_pack(c->dma_channel, 1); |
| 704 | omap_set_dma_src_burst_mode(c->dma_channel, |
| 705 | OMAP_DMA_DATA_BURST_8); |
| 706 | omap_set_dma_dest_data_pack(c->dma_channel, 1); |
| 707 | omap_set_dma_dest_burst_mode(c->dma_channel, |
| 708 | OMAP_DMA_DATA_BURST_8); |
| 709 | } else { |
| 710 | dev_info(&pdev->dev, |
| 711 | "failed to allocate DMA for OneNAND, " |
| 712 | "using PIO instead\n"); |
| 713 | c->dma_channel = -1; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | dev_info(&pdev->dev, "initializing on CS%d, phys base 0x%08lx, virtual " |
Adrian Hunter | 3ad2d86 | 2011-02-07 10:46:59 +0200 | [diff] [blame] | 718 | "base %p, freq %d MHz\n", c->gpmc_cs, c->phys_base, |
| 719 | c->onenand.base, c->freq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 720 | |
| 721 | c->pdev = pdev; |
Kay Sievers | 475b44c | 2009-01-06 10:44:38 -0800 | [diff] [blame] | 722 | c->mtd.name = dev_name(&pdev->dev); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 723 | c->mtd.priv = &c->onenand; |
| 724 | c->mtd.owner = THIS_MODULE; |
| 725 | |
David Brownell | 87f39f0 | 2009-03-26 00:42:50 -0700 | [diff] [blame] | 726 | c->mtd.dev.parent = &pdev->dev; |
| 727 | |
Roman Tereshonkov | c93ff6b | 2011-02-17 13:44:42 +0200 | [diff] [blame] | 728 | this = &c->onenand; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 729 | if (c->dma_channel >= 0) { |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 730 | this->wait = omap2_onenand_wait; |
| 731 | if (cpu_is_omap34xx()) { |
| 732 | this->read_bufferram = omap3_onenand_read_bufferram; |
| 733 | this->write_bufferram = omap3_onenand_write_bufferram; |
| 734 | } else { |
| 735 | this->read_bufferram = omap2_onenand_read_bufferram; |
| 736 | this->write_bufferram = omap2_onenand_write_bufferram; |
| 737 | } |
| 738 | } |
| 739 | |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 740 | if (pdata->regulator_can_sleep) { |
| 741 | c->regulator = regulator_get(&pdev->dev, "vonenand"); |
| 742 | if (IS_ERR(c->regulator)) { |
| 743 | dev_err(&pdev->dev, "Failed to get regulator\n"); |
| 744 | goto err_release_dma; |
| 745 | } |
| 746 | c->onenand.enable = omap2_onenand_enable; |
| 747 | c->onenand.disable = omap2_onenand_disable; |
| 748 | } |
| 749 | |
Roman Tereshonkov | c93ff6b | 2011-02-17 13:44:42 +0200 | [diff] [blame] | 750 | if (pdata->skip_initial_unlocking) |
| 751 | this->options |= ONENAND_SKIP_INITIAL_UNLOCKING; |
| 752 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 753 | if ((r = onenand_scan(&c->mtd, 1)) < 0) |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 754 | goto err_release_regulator; |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 755 | |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 756 | r = parse_mtd_partitions(&c->mtd, part_probes, &c->parts, 0); |
| 757 | if (r > 0) |
Jamie Iles | ff6e1b2 | 2011-05-23 10:23:38 +0100 | [diff] [blame] | 758 | r = mtd_device_register(&c->mtd, c->parts, r); |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 759 | else if (pdata->parts != NULL) |
Jamie Iles | ff6e1b2 | 2011-05-23 10:23:38 +0100 | [diff] [blame] | 760 | r = mtd_device_register(&c->mtd, pdata->parts, pdata->nr_parts); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 761 | else |
Jamie Iles | ff6e1b2 | 2011-05-23 10:23:38 +0100 | [diff] [blame] | 762 | r = mtd_device_register(&c->mtd, NULL, 0); |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 763 | if (r) |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 764 | goto err_release_onenand; |
| 765 | |
| 766 | platform_set_drvdata(pdev, c); |
| 767 | |
| 768 | return 0; |
| 769 | |
| 770 | err_release_onenand: |
| 771 | onenand_release(&c->mtd); |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 772 | err_release_regulator: |
| 773 | regulator_put(c->regulator); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 774 | err_release_dma: |
| 775 | if (c->dma_channel != -1) |
| 776 | omap_free_dma(c->dma_channel); |
| 777 | if (c->gpio_irq) |
David Brownell | 15f74b0 | 2008-12-10 17:35:26 -0800 | [diff] [blame] | 778 | free_irq(gpio_to_irq(c->gpio_irq), c); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 779 | err_release_gpio: |
| 780 | if (c->gpio_irq) |
Jarkko Nikula | 73069e3 | 2009-01-15 13:09:52 +0200 | [diff] [blame] | 781 | gpio_free(c->gpio_irq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 782 | err_iounmap: |
| 783 | iounmap(c->onenand.base); |
| 784 | err_release_mem_region: |
| 785 | release_mem_region(c->phys_base, ONENAND_IO_SIZE); |
| 786 | err_free_cs: |
| 787 | gpmc_cs_free(c->gpmc_cs); |
| 788 | err_kfree: |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 789 | kfree(c->parts); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 790 | kfree(c); |
| 791 | |
| 792 | return r; |
| 793 | } |
| 794 | |
| 795 | static int __devexit omap2_onenand_remove(struct platform_device *pdev) |
| 796 | { |
| 797 | struct omap2_onenand *c = dev_get_drvdata(&pdev->dev); |
| 798 | |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 799 | onenand_release(&c->mtd); |
Adrian Hunter | 9ac4e61 | 2010-02-19 15:39:53 +0100 | [diff] [blame] | 800 | regulator_put(c->regulator); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 801 | if (c->dma_channel != -1) |
| 802 | omap_free_dma(c->dma_channel); |
| 803 | omap2_onenand_shutdown(pdev); |
| 804 | platform_set_drvdata(pdev, NULL); |
| 805 | if (c->gpio_irq) { |
David Brownell | 15f74b0 | 2008-12-10 17:35:26 -0800 | [diff] [blame] | 806 | free_irq(gpio_to_irq(c->gpio_irq), c); |
Jarkko Nikula | 73069e3 | 2009-01-15 13:09:52 +0200 | [diff] [blame] | 807 | gpio_free(c->gpio_irq); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 808 | } |
| 809 | iounmap(c->onenand.base); |
| 810 | release_mem_region(c->phys_base, ONENAND_IO_SIZE); |
Mika Korhonen | 3cae1cc | 2009-06-25 15:32:19 +0300 | [diff] [blame] | 811 | gpmc_cs_free(c->gpmc_cs); |
Adrian Hunter | 263a8c8 | 2009-12-30 07:40:16 +0100 | [diff] [blame] | 812 | kfree(c->parts); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 813 | kfree(c); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static struct platform_driver omap2_onenand_driver = { |
| 819 | .probe = omap2_onenand_probe, |
Mika Korhonen | d3412db | 2009-05-21 23:09:42 +0300 | [diff] [blame] | 820 | .remove = __devexit_p(omap2_onenand_remove), |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 821 | .shutdown = omap2_onenand_shutdown, |
| 822 | .driver = { |
| 823 | .name = DRIVER_NAME, |
| 824 | .owner = THIS_MODULE, |
| 825 | }, |
| 826 | }; |
| 827 | |
| 828 | static int __init omap2_onenand_init(void) |
| 829 | { |
| 830 | printk(KERN_INFO "OneNAND driver initializing\n"); |
| 831 | return platform_driver_register(&omap2_onenand_driver); |
| 832 | } |
| 833 | |
| 834 | static void __exit omap2_onenand_exit(void) |
| 835 | { |
| 836 | platform_driver_unregister(&omap2_onenand_driver); |
| 837 | } |
| 838 | |
| 839 | module_init(omap2_onenand_init); |
| 840 | module_exit(omap2_onenand_exit); |
| 841 | |
Axel Lin | c804c73 | 2011-03-07 11:04:24 +0800 | [diff] [blame] | 842 | MODULE_ALIAS("platform:" DRIVER_NAME); |
Adrian Hunter | 36cd4fb | 2008-08-06 10:08:46 +0300 | [diff] [blame] | 843 | MODULE_LICENSE("GPL"); |
| 844 | MODULE_AUTHOR("Jarkko Lavinen <jarkko.lavinen@nokia.com>"); |
| 845 | MODULE_DESCRIPTION("Glue layer for OneNAND flash on OMAP2 / OMAP3"); |