2 * linux/drivers/mtd/onenand/omap2.c
4 * OneNAND driver for OMAP2 / OMAP3
6 * Copyright © 2005-2006 Nokia Corporation
8 * Author: Jarkko Lavinen <jarkko.lavinen@nokia.com> and Juha Yrjölä
9 * IRQ and DMA support written by Timo Teras
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.
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
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.
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>
35 #include <linux/dma-mapping.h>
37 #include <linux/slab.h>
38 #include <linux/regulator/consumer.h>
40 #include <asm/mach/flash.h>
41 #include <plat/gpmc.h>
42 #include <plat/onenand.h>
47 #include <plat/board.h>
49 #define DRIVER_NAME "omap2-onenand"
51 #define ONENAND_IO_SIZE SZ_128K
52 #define ONENAND_BUFRAM_SIZE (1024 * 5)
54 struct omap2_onenand
{
55 struct platform_device
*pdev
;
57 unsigned long phys_base
;
60 struct onenand_chip onenand
;
61 struct completion irq_done
;
62 struct completion dma_done
;
65 int (*setup
)(void __iomem
*base
, int *freq_ptr
);
66 struct regulator
*regulator
;
69 static void omap2_onenand_dma_cb(int lch
, u16 ch_status
, void *data
)
71 struct omap2_onenand
*c
= data
;
73 complete(&c
->dma_done
);
76 static irqreturn_t
omap2_onenand_interrupt(int irq
, void *dev_id
)
78 struct omap2_onenand
*c
= dev_id
;
80 complete(&c
->irq_done
);
85 static inline unsigned short read_reg(struct omap2_onenand
*c
, int reg
)
87 return readw(c
->onenand
.base
+ reg
);
90 static inline void write_reg(struct omap2_onenand
*c
, unsigned short value
,
93 writew(value
, c
->onenand
.base
+ reg
);
96 static void wait_err(char *msg
, int state
, unsigned int ctrl
, unsigned int intr
)
98 printk(KERN_ERR
"onenand_wait: %s! state %d ctrl 0x%04x intr 0x%04x\n",
99 msg
, state
, ctrl
, intr
);
102 static void wait_warn(char *msg
, int state
, unsigned int ctrl
,
105 printk(KERN_WARNING
"onenand_wait: %s! state %d ctrl 0x%04x "
106 "intr 0x%04x\n", msg
, state
, ctrl
, intr
);
109 static int omap2_onenand_wait(struct mtd_info
*mtd
, int state
)
111 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
112 struct onenand_chip
*this = mtd
->priv
;
113 unsigned int intr
= 0;
114 unsigned int ctrl
, ctrl_mask
;
115 unsigned long timeout
;
118 if (state
== FL_RESETING
|| state
== FL_PREPARING_ERASE
||
119 state
== FL_VERIFYING_ERASE
) {
121 unsigned int intr_flags
= ONENAND_INT_MASTER
;
125 intr_flags
|= ONENAND_INT_RESET
;
127 case FL_PREPARING_ERASE
:
128 intr_flags
|= ONENAND_INT_ERASE
;
130 case FL_VERIFYING_ERASE
:
137 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
138 if (intr
& ONENAND_INT_MASTER
)
141 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
142 if (ctrl
& ONENAND_CTRL_ERROR
) {
143 wait_err("controller error", state
, ctrl
, intr
);
146 if ((intr
& intr_flags
) == intr_flags
)
148 /* Continue in wait for interrupt branch */
151 if (state
!= FL_READING
) {
154 /* Turn interrupts on */
155 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
156 if (!(syscfg
& ONENAND_SYS_CFG1_IOBE
)) {
157 syscfg
|= ONENAND_SYS_CFG1_IOBE
;
158 write_reg(c
, syscfg
, ONENAND_REG_SYS_CFG1
);
159 if (cpu_is_omap34xx())
160 /* Add a delay to let GPIO settle */
161 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
164 INIT_COMPLETION(c
->irq_done
);
166 result
= gpio_get_value(c
->gpio_irq
);
168 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
169 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
170 wait_err("gpio error", state
, ctrl
, intr
);
178 result
= wait_for_completion_timeout(&c
->irq_done
,
179 msecs_to_jiffies(20));
181 /* Timeout after 20ms */
182 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
183 if (ctrl
& ONENAND_CTRL_ONGO
&&
186 * The operation seems to be still going
187 * so give it some more time.
193 ONENAND_REG_INTERRUPT
);
194 wait_err("timeout", state
, ctrl
, intr
);
197 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
198 if ((intr
& ONENAND_INT_MASTER
) == 0)
199 wait_warn("timeout", state
, ctrl
, intr
);
205 /* Turn interrupts off */
206 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
207 syscfg
&= ~ONENAND_SYS_CFG1_IOBE
;
208 write_reg(c
, syscfg
, ONENAND_REG_SYS_CFG1
);
210 timeout
= jiffies
+ msecs_to_jiffies(20);
212 if (time_before(jiffies
, timeout
)) {
213 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
214 if (intr
& ONENAND_INT_MASTER
)
217 /* Timeout after 20ms */
218 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
219 if (ctrl
& ONENAND_CTRL_ONGO
) {
221 * The operation seems to be still going
222 * so give it some more time.
227 msecs_to_jiffies(20);
236 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
237 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
239 if (intr
& ONENAND_INT_READ
) {
240 int ecc
= read_reg(c
, ONENAND_REG_ECC_STATUS
);
243 unsigned int addr1
, addr8
;
245 addr1
= read_reg(c
, ONENAND_REG_START_ADDRESS1
);
246 addr8
= read_reg(c
, ONENAND_REG_START_ADDRESS8
);
247 if (ecc
& ONENAND_ECC_2BIT_ALL
) {
248 printk(KERN_ERR
"onenand_wait: ECC error = "
249 "0x%04x, addr1 %#x, addr8 %#x\n",
251 mtd
->ecc_stats
.failed
++;
253 } else if (ecc
& ONENAND_ECC_1BIT_ALL
) {
254 printk(KERN_NOTICE
"onenand_wait: correctable "
255 "ECC error = 0x%04x, addr1 %#x, "
256 "addr8 %#x\n", ecc
, addr1
, addr8
);
257 mtd
->ecc_stats
.corrected
++;
260 } else if (state
== FL_READING
) {
261 wait_err("timeout", state
, ctrl
, intr
);
265 if (ctrl
& ONENAND_CTRL_ERROR
) {
266 wait_err("controller error", state
, ctrl
, intr
);
267 if (ctrl
& ONENAND_CTRL_LOCK
)
268 printk(KERN_ERR
"onenand_wait: "
269 "Device is write protected!!!\n");
275 ctrl_mask
&= ~0x8000;
277 if (ctrl
& ctrl_mask
)
278 wait_warn("unexpected controller status", state
, ctrl
, intr
);
283 static inline int omap2_onenand_bufferram_offset(struct mtd_info
*mtd
, int area
)
285 struct onenand_chip
*this = mtd
->priv
;
287 if (ONENAND_CURRENT_BUFFERRAM(this)) {
288 if (area
== ONENAND_DATARAM
)
289 return this->writesize
;
290 if (area
== ONENAND_SPARERAM
)
297 #if defined(CONFIG_ARCH_OMAP3) || defined(MULTI_OMAP2)
299 static int omap3_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
300 unsigned char *buffer
, int offset
,
303 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
304 struct onenand_chip
*this = mtd
->priv
;
305 dma_addr_t dma_src
, dma_dst
;
307 unsigned long timeout
;
308 void *buf
= (void *)buffer
;
310 volatile unsigned *done
;
312 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
313 if (bram_offset
& 3 || (size_t)buf
& 3 || count
< 384)
316 /* panic_write() may be in an interrupt context */
317 if (in_interrupt() || oops_in_progress
)
320 if (buf
>= high_memory
) {
323 if (((size_t)buf
& PAGE_MASK
) !=
324 ((size_t)(buf
+ count
- 1) & PAGE_MASK
))
326 p1
= vmalloc_to_page(buf
);
329 buf
= page_address(p1
) + ((size_t)buf
& ~PAGE_MASK
);
335 memcpy(buf
+ count
, this->base
+ bram_offset
+ count
, xtra
);
338 dma_src
= c
->phys_base
+ bram_offset
;
339 dma_dst
= dma_map_single(&c
->pdev
->dev
, buf
, count
, DMA_FROM_DEVICE
);
340 if (dma_mapping_error(&c
->pdev
->dev
, dma_dst
)) {
341 dev_err(&c
->pdev
->dev
,
342 "Couldn't DMA map a %d byte buffer\n",
347 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S32
,
348 count
>> 2, 1, 0, 0, 0);
349 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
351 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
354 INIT_COMPLETION(c
->dma_done
);
355 omap_start_dma(c
->dma_channel
);
357 timeout
= jiffies
+ msecs_to_jiffies(20);
358 done
= &c
->dma_done
.done
;
359 while (time_before(jiffies
, timeout
))
363 dma_unmap_single(&c
->pdev
->dev
, dma_dst
, count
, DMA_FROM_DEVICE
);
366 dev_err(&c
->pdev
->dev
, "timeout waiting for DMA\n");
373 memcpy(buf
, this->base
+ bram_offset
, count
);
377 static int omap3_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
378 const unsigned char *buffer
,
379 int offset
, size_t count
)
381 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
382 struct onenand_chip
*this = mtd
->priv
;
383 dma_addr_t dma_src
, dma_dst
;
385 unsigned long timeout
;
386 void *buf
= (void *)buffer
;
387 volatile unsigned *done
;
389 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
390 if (bram_offset
& 3 || (size_t)buf
& 3 || count
< 384)
393 /* panic_write() may be in an interrupt context */
394 if (in_interrupt() || oops_in_progress
)
397 if (buf
>= high_memory
) {
400 if (((size_t)buf
& PAGE_MASK
) !=
401 ((size_t)(buf
+ count
- 1) & PAGE_MASK
))
403 p1
= vmalloc_to_page(buf
);
406 buf
= page_address(p1
) + ((size_t)buf
& ~PAGE_MASK
);
409 dma_src
= dma_map_single(&c
->pdev
->dev
, buf
, count
, DMA_TO_DEVICE
);
410 dma_dst
= c
->phys_base
+ bram_offset
;
411 if (dma_mapping_error(&c
->pdev
->dev
, dma_src
)) {
412 dev_err(&c
->pdev
->dev
,
413 "Couldn't DMA map a %d byte buffer\n",
418 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S32
,
419 count
>> 2, 1, 0, 0, 0);
420 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
422 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
425 INIT_COMPLETION(c
->dma_done
);
426 omap_start_dma(c
->dma_channel
);
428 timeout
= jiffies
+ msecs_to_jiffies(20);
429 done
= &c
->dma_done
.done
;
430 while (time_before(jiffies
, timeout
))
434 dma_unmap_single(&c
->pdev
->dev
, dma_src
, count
, DMA_TO_DEVICE
);
437 dev_err(&c
->pdev
->dev
, "timeout waiting for DMA\n");
444 memcpy(this->base
+ bram_offset
, buf
, count
);
450 int omap3_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
451 unsigned char *buffer
, int offset
,
454 int omap3_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
455 const unsigned char *buffer
,
456 int offset
, size_t count
);
460 #if defined(CONFIG_ARCH_OMAP2) || defined(MULTI_OMAP2)
462 static int omap2_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
463 unsigned char *buffer
, int offset
,
466 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
467 struct onenand_chip
*this = mtd
->priv
;
468 dma_addr_t dma_src
, dma_dst
;
471 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
472 /* DMA is not used. Revisit PM requirements before enabling it. */
473 if (1 || (c
->dma_channel
< 0) ||
474 ((void *) buffer
>= (void *) high_memory
) || (bram_offset
& 3) ||
475 (((unsigned int) buffer
) & 3) || (count
< 1024) || (count
& 3)) {
476 memcpy(buffer
, (__force
void *)(this->base
+ bram_offset
),
481 dma_src
= c
->phys_base
+ bram_offset
;
482 dma_dst
= dma_map_single(&c
->pdev
->dev
, buffer
, count
,
484 if (dma_mapping_error(&c
->pdev
->dev
, dma_dst
)) {
485 dev_err(&c
->pdev
->dev
,
486 "Couldn't DMA map a %d byte buffer\n",
491 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S32
,
492 count
/ 4, 1, 0, 0, 0);
493 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
495 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
498 INIT_COMPLETION(c
->dma_done
);
499 omap_start_dma(c
->dma_channel
);
500 wait_for_completion(&c
->dma_done
);
502 dma_unmap_single(&c
->pdev
->dev
, dma_dst
, count
, DMA_FROM_DEVICE
);
507 static int omap2_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
508 const unsigned char *buffer
,
509 int offset
, size_t count
)
511 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
512 struct onenand_chip
*this = mtd
->priv
;
513 dma_addr_t dma_src
, dma_dst
;
516 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
517 /* DMA is not used. Revisit PM requirements before enabling it. */
518 if (1 || (c
->dma_channel
< 0) ||
519 ((void *) buffer
>= (void *) high_memory
) || (bram_offset
& 3) ||
520 (((unsigned int) buffer
) & 3) || (count
< 1024) || (count
& 3)) {
521 memcpy((__force
void *)(this->base
+ bram_offset
), buffer
,
526 dma_src
= dma_map_single(&c
->pdev
->dev
, (void *) buffer
, count
,
528 dma_dst
= c
->phys_base
+ bram_offset
;
529 if (dma_mapping_error(&c
->pdev
->dev
, dma_src
)) {
530 dev_err(&c
->pdev
->dev
,
531 "Couldn't DMA map a %d byte buffer\n",
536 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S16
,
537 count
/ 2, 1, 0, 0, 0);
538 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
540 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
543 INIT_COMPLETION(c
->dma_done
);
544 omap_start_dma(c
->dma_channel
);
545 wait_for_completion(&c
->dma_done
);
547 dma_unmap_single(&c
->pdev
->dev
, dma_src
, count
, DMA_TO_DEVICE
);
554 int omap2_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
555 unsigned char *buffer
, int offset
,
558 int omap2_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
559 const unsigned char *buffer
,
560 int offset
, size_t count
);
564 static struct platform_driver omap2_onenand_driver
;
566 static int __adjust_timing(struct device
*dev
, void *data
)
569 struct omap2_onenand
*c
;
571 c
= dev_get_drvdata(dev
);
573 BUG_ON(c
->setup
== NULL
);
575 /* DMA is not in use so this is all that is needed */
576 /* Revisit for OMAP3! */
577 ret
= c
->setup(c
->onenand
.base
, &c
->freq
);
582 int omap2_onenand_rephase(void)
584 return driver_for_each_device(&omap2_onenand_driver
.driver
, NULL
,
585 NULL
, __adjust_timing
);
588 static void omap2_onenand_shutdown(struct platform_device
*pdev
)
590 struct omap2_onenand
*c
= dev_get_drvdata(&pdev
->dev
);
592 /* With certain content in the buffer RAM, the OMAP boot ROM code
593 * can recognize the flash chip incorrectly. Zero it out before
596 memset((__force
void *)c
->onenand
.base
, 0, ONENAND_BUFRAM_SIZE
);
599 static int omap2_onenand_enable(struct mtd_info
*mtd
)
602 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
604 ret
= regulator_enable(c
->regulator
);
606 dev_err(&c
->pdev
->dev
, "can't enable regulator\n");
611 static int omap2_onenand_disable(struct mtd_info
*mtd
)
614 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
616 ret
= regulator_disable(c
->regulator
);
618 dev_err(&c
->pdev
->dev
, "can't disable regulator\n");
623 static int __devinit
omap2_onenand_probe(struct platform_device
*pdev
)
625 struct omap_onenand_platform_data
*pdata
;
626 struct omap2_onenand
*c
;
627 struct onenand_chip
*this;
630 pdata
= pdev
->dev
.platform_data
;
632 dev_err(&pdev
->dev
, "platform data missing\n");
636 c
= kzalloc(sizeof(struct omap2_onenand
), GFP_KERNEL
);
640 init_completion(&c
->irq_done
);
641 init_completion(&c
->dma_done
);
642 c
->gpmc_cs
= pdata
->cs
;
643 c
->gpio_irq
= pdata
->gpio_irq
;
644 c
->dma_channel
= pdata
->dma_channel
;
645 if (c
->dma_channel
< 0) {
646 /* if -1, don't use DMA */
650 r
= gpmc_cs_request(c
->gpmc_cs
, ONENAND_IO_SIZE
, &c
->phys_base
);
652 dev_err(&pdev
->dev
, "Cannot request GPMC CS\n");
656 if (request_mem_region(c
->phys_base
, ONENAND_IO_SIZE
,
657 pdev
->dev
.driver
->name
) == NULL
) {
658 dev_err(&pdev
->dev
, "Cannot reserve memory region at 0x%08lx, "
659 "size: 0x%x\n", c
->phys_base
, ONENAND_IO_SIZE
);
663 c
->onenand
.base
= ioremap(c
->phys_base
, ONENAND_IO_SIZE
);
664 if (c
->onenand
.base
== NULL
) {
666 goto err_release_mem_region
;
669 if (pdata
->onenand_setup
!= NULL
) {
670 r
= pdata
->onenand_setup(c
->onenand
.base
, &c
->freq
);
672 dev_err(&pdev
->dev
, "Onenand platform setup failed: "
676 c
->setup
= pdata
->onenand_setup
;
680 if ((r
= gpio_request(c
->gpio_irq
, "OneNAND irq")) < 0) {
681 dev_err(&pdev
->dev
, "Failed to request GPIO%d for "
682 "OneNAND\n", c
->gpio_irq
);
685 gpio_direction_input(c
->gpio_irq
);
687 if ((r
= request_irq(gpio_to_irq(c
->gpio_irq
),
688 omap2_onenand_interrupt
, IRQF_TRIGGER_RISING
,
689 pdev
->dev
.driver
->name
, c
)) < 0)
690 goto err_release_gpio
;
693 if (c
->dma_channel
>= 0) {
694 r
= omap_request_dma(0, pdev
->dev
.driver
->name
,
695 omap2_onenand_dma_cb
, (void *) c
,
698 omap_set_dma_write_mode(c
->dma_channel
,
699 OMAP_DMA_WRITE_NON_POSTED
);
700 omap_set_dma_src_data_pack(c
->dma_channel
, 1);
701 omap_set_dma_src_burst_mode(c
->dma_channel
,
702 OMAP_DMA_DATA_BURST_8
);
703 omap_set_dma_dest_data_pack(c
->dma_channel
, 1);
704 omap_set_dma_dest_burst_mode(c
->dma_channel
,
705 OMAP_DMA_DATA_BURST_8
);
708 "failed to allocate DMA for OneNAND, "
709 "using PIO instead\n");
714 dev_info(&pdev
->dev
, "initializing on CS%d, phys base 0x%08lx, virtual "
715 "base %p, freq %d MHz\n", c
->gpmc_cs
, c
->phys_base
,
716 c
->onenand
.base
, c
->freq
);
719 c
->mtd
.name
= dev_name(&pdev
->dev
);
720 c
->mtd
.priv
= &c
->onenand
;
721 c
->mtd
.owner
= THIS_MODULE
;
723 c
->mtd
.dev
.parent
= &pdev
->dev
;
726 if (c
->dma_channel
>= 0) {
727 this->wait
= omap2_onenand_wait
;
728 if (cpu_is_omap34xx()) {
729 this->read_bufferram
= omap3_onenand_read_bufferram
;
730 this->write_bufferram
= omap3_onenand_write_bufferram
;
732 this->read_bufferram
= omap2_onenand_read_bufferram
;
733 this->write_bufferram
= omap2_onenand_write_bufferram
;
737 if (pdata
->regulator_can_sleep
) {
738 c
->regulator
= regulator_get(&pdev
->dev
, "vonenand");
739 if (IS_ERR(c
->regulator
)) {
740 dev_err(&pdev
->dev
, "Failed to get regulator\n");
741 r
= PTR_ERR(c
->regulator
);
742 goto err_release_dma
;
744 c
->onenand
.enable
= omap2_onenand_enable
;
745 c
->onenand
.disable
= omap2_onenand_disable
;
748 if (pdata
->skip_initial_unlocking
)
749 this->options
|= ONENAND_SKIP_INITIAL_UNLOCKING
;
751 if ((r
= onenand_scan(&c
->mtd
, 1)) < 0)
752 goto err_release_regulator
;
754 r
= mtd_device_parse_register(&c
->mtd
, NULL
, NULL
,
755 pdata
? pdata
->parts
: NULL
,
756 pdata
? pdata
->nr_parts
: 0);
758 goto err_release_onenand
;
760 platform_set_drvdata(pdev
, c
);
765 onenand_release(&c
->mtd
);
766 err_release_regulator
:
767 regulator_put(c
->regulator
);
769 if (c
->dma_channel
!= -1)
770 omap_free_dma(c
->dma_channel
);
772 free_irq(gpio_to_irq(c
->gpio_irq
), c
);
775 gpio_free(c
->gpio_irq
);
777 iounmap(c
->onenand
.base
);
778 err_release_mem_region
:
779 release_mem_region(c
->phys_base
, ONENAND_IO_SIZE
);
781 gpmc_cs_free(c
->gpmc_cs
);
788 static int __devexit
omap2_onenand_remove(struct platform_device
*pdev
)
790 struct omap2_onenand
*c
= dev_get_drvdata(&pdev
->dev
);
792 onenand_release(&c
->mtd
);
793 regulator_put(c
->regulator
);
794 if (c
->dma_channel
!= -1)
795 omap_free_dma(c
->dma_channel
);
796 omap2_onenand_shutdown(pdev
);
797 platform_set_drvdata(pdev
, NULL
);
799 free_irq(gpio_to_irq(c
->gpio_irq
), c
);
800 gpio_free(c
->gpio_irq
);
802 iounmap(c
->onenand
.base
);
803 release_mem_region(c
->phys_base
, ONENAND_IO_SIZE
);
804 gpmc_cs_free(c
->gpmc_cs
);
810 static struct platform_driver omap2_onenand_driver
= {
811 .probe
= omap2_onenand_probe
,
812 .remove
= __devexit_p(omap2_onenand_remove
),
813 .shutdown
= omap2_onenand_shutdown
,
816 .owner
= THIS_MODULE
,
820 static int __init
omap2_onenand_init(void)
822 printk(KERN_INFO
"OneNAND driver initializing\n");
823 return platform_driver_register(&omap2_onenand_driver
);
826 static void __exit
omap2_onenand_exit(void)
828 platform_driver_unregister(&omap2_onenand_driver
);
831 module_init(omap2_onenand_init
);
832 module_exit(omap2_onenand_exit
);
834 MODULE_ALIAS("platform:" DRIVER_NAME
);
835 MODULE_LICENSE("GPL");
836 MODULE_AUTHOR("Jarkko Lavinen <jarkko.lavinen@nokia.com>");
837 MODULE_DESCRIPTION("Glue layer for OneNAND flash on OMAP2 / OMAP3");