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>
43 #include <mach/gpio.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 mtd_partition
*parts
;
61 struct onenand_chip onenand
;
62 struct completion irq_done
;
63 struct completion dma_done
;
66 int (*setup
)(void __iomem
*base
, int *freq_ptr
);
67 struct regulator
*regulator
;
70 static const char *part_probes
[] = { "cmdlinepart", NULL
, };
72 static void omap2_onenand_dma_cb(int lch
, u16 ch_status
, void *data
)
74 struct omap2_onenand
*c
= data
;
76 complete(&c
->dma_done
);
79 static irqreturn_t
omap2_onenand_interrupt(int irq
, void *dev_id
)
81 struct omap2_onenand
*c
= dev_id
;
83 complete(&c
->irq_done
);
88 static inline unsigned short read_reg(struct omap2_onenand
*c
, int reg
)
90 return readw(c
->onenand
.base
+ reg
);
93 static inline void write_reg(struct omap2_onenand
*c
, unsigned short value
,
96 writew(value
, c
->onenand
.base
+ reg
);
99 static void wait_err(char *msg
, int state
, unsigned int ctrl
, unsigned int intr
)
101 printk(KERN_ERR
"onenand_wait: %s! state %d ctrl 0x%04x intr 0x%04x\n",
102 msg
, state
, ctrl
, intr
);
105 static void wait_warn(char *msg
, int state
, unsigned int ctrl
,
108 printk(KERN_WARNING
"onenand_wait: %s! state %d ctrl 0x%04x "
109 "intr 0x%04x\n", msg
, state
, ctrl
, intr
);
112 static int omap2_onenand_wait(struct mtd_info
*mtd
, int state
)
114 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
115 struct onenand_chip
*this = mtd
->priv
;
116 unsigned int intr
= 0;
117 unsigned int ctrl
, ctrl_mask
;
118 unsigned long timeout
;
121 if (state
== FL_RESETING
|| state
== FL_PREPARING_ERASE
||
122 state
== FL_VERIFYING_ERASE
) {
124 unsigned int intr_flags
= ONENAND_INT_MASTER
;
128 intr_flags
|= ONENAND_INT_RESET
;
130 case FL_PREPARING_ERASE
:
131 intr_flags
|= ONENAND_INT_ERASE
;
133 case FL_VERIFYING_ERASE
:
140 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
141 if (intr
& ONENAND_INT_MASTER
)
144 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
145 if (ctrl
& ONENAND_CTRL_ERROR
) {
146 wait_err("controller error", state
, ctrl
, intr
);
149 if ((intr
& intr_flags
) == intr_flags
)
151 /* Continue in wait for interrupt branch */
154 if (state
!= FL_READING
) {
157 /* Turn interrupts on */
158 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
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
);
167 INIT_COMPLETION(c
->irq_done
);
169 result
= gpio_get_value(c
->gpio_irq
);
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
);
181 result
= wait_for_completion_timeout(&c
->irq_done
,
182 msecs_to_jiffies(20));
184 /* Timeout after 20ms */
185 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
186 if (ctrl
& ONENAND_CTRL_ONGO
&&
189 * The operation seems to be still going
190 * so give it some more time.
196 ONENAND_REG_INTERRUPT
);
197 wait_err("timeout", state
, ctrl
, intr
);
200 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
201 if ((intr
& ONENAND_INT_MASTER
) == 0)
202 wait_warn("timeout", state
, ctrl
, intr
);
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
);
213 timeout
= jiffies
+ msecs_to_jiffies(20);
215 if (time_before(jiffies
, timeout
)) {
216 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
217 if (intr
& ONENAND_INT_MASTER
)
220 /* Timeout after 20ms */
221 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
222 if (ctrl
& ONENAND_CTRL_ONGO
) {
224 * The operation seems to be still going
225 * so give it some more time.
230 msecs_to_jiffies(20);
239 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
240 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
242 if (intr
& ONENAND_INT_READ
) {
243 int ecc
= read_reg(c
, ONENAND_REG_ECC_STATUS
);
246 unsigned int addr1
, addr8
;
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",
254 mtd
->ecc_stats
.failed
++;
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
++;
263 } else if (state
== FL_READING
) {
264 wait_err("timeout", state
, ctrl
, intr
);
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");
278 ctrl_mask
&= ~0x8000;
280 if (ctrl
& ctrl_mask
)
281 wait_warn("unexpected controller status", state
, ctrl
, intr
);
286 static inline int omap2_onenand_bufferram_offset(struct mtd_info
*mtd
, int area
)
288 struct onenand_chip
*this = mtd
->priv
;
290 if (ONENAND_CURRENT_BUFFERRAM(this)) {
291 if (area
== ONENAND_DATARAM
)
292 return this->writesize
;
293 if (area
== ONENAND_SPARERAM
)
300 #if defined(CONFIG_ARCH_OMAP3) || defined(MULTI_OMAP2)
302 static int omap3_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
303 unsigned char *buffer
, int offset
,
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
;
310 unsigned long timeout
;
311 void *buf
= (void *)buffer
;
313 volatile unsigned *done
;
315 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
316 if (bram_offset
& 3 || (size_t)buf
& 3 || count
< 384)
319 /* panic_write() may be in an interrupt context */
320 if (in_interrupt() || oops_in_progress
)
323 if (buf
>= high_memory
) {
326 if (((size_t)buf
& PAGE_MASK
) !=
327 ((size_t)(buf
+ count
- 1) & PAGE_MASK
))
329 p1
= vmalloc_to_page(buf
);
332 buf
= page_address(p1
) + ((size_t)buf
& ~PAGE_MASK
);
338 memcpy(buf
+ count
, this->base
+ bram_offset
+ count
, xtra
);
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",
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
,
354 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
357 INIT_COMPLETION(c
->dma_done
);
358 omap_start_dma(c
->dma_channel
);
360 timeout
= jiffies
+ msecs_to_jiffies(20);
361 done
= &c
->dma_done
.done
;
362 while (time_before(jiffies
, timeout
))
366 dma_unmap_single(&c
->pdev
->dev
, dma_dst
, count
, DMA_FROM_DEVICE
);
369 dev_err(&c
->pdev
->dev
, "timeout waiting for DMA\n");
376 memcpy(buf
, this->base
+ bram_offset
, count
);
380 static int omap3_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
381 const unsigned char *buffer
,
382 int offset
, size_t count
)
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
;
388 unsigned long timeout
;
389 void *buf
= (void *)buffer
;
390 volatile unsigned *done
;
392 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
393 if (bram_offset
& 3 || (size_t)buf
& 3 || count
< 384)
396 /* panic_write() may be in an interrupt context */
397 if (in_interrupt() || oops_in_progress
)
400 if (buf
>= high_memory
) {
403 if (((size_t)buf
& PAGE_MASK
) !=
404 ((size_t)(buf
+ count
- 1) & PAGE_MASK
))
406 p1
= vmalloc_to_page(buf
);
409 buf
= page_address(p1
) + ((size_t)buf
& ~PAGE_MASK
);
412 dma_src
= dma_map_single(&c
->pdev
->dev
, buf
, count
, DMA_TO_DEVICE
);
413 dma_dst
= c
->phys_base
+ bram_offset
;
414 if (dma_mapping_error(&c
->pdev
->dev
, dma_src
)) {
415 dev_err(&c
->pdev
->dev
,
416 "Couldn't DMA map a %d byte buffer\n",
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
,
425 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
428 INIT_COMPLETION(c
->dma_done
);
429 omap_start_dma(c
->dma_channel
);
431 timeout
= jiffies
+ msecs_to_jiffies(20);
432 done
= &c
->dma_done
.done
;
433 while (time_before(jiffies
, timeout
))
437 dma_unmap_single(&c
->pdev
->dev
, dma_src
, count
, DMA_TO_DEVICE
);
440 dev_err(&c
->pdev
->dev
, "timeout waiting for DMA\n");
447 memcpy(this->base
+ bram_offset
, buf
, count
);
453 int omap3_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
454 unsigned char *buffer
, int offset
,
457 int omap3_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
458 const unsigned char *buffer
,
459 int offset
, size_t count
);
463 #if defined(CONFIG_ARCH_OMAP2) || defined(MULTI_OMAP2)
465 static int omap2_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
466 unsigned char *buffer
, int offset
,
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
;
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
),
484 dma_src
= c
->phys_base
+ bram_offset
;
485 dma_dst
= dma_map_single(&c
->pdev
->dev
, buffer
, count
,
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",
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
,
498 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
501 INIT_COMPLETION(c
->dma_done
);
502 omap_start_dma(c
->dma_channel
);
503 wait_for_completion(&c
->dma_done
);
505 dma_unmap_single(&c
->pdev
->dev
, dma_dst
, count
, DMA_FROM_DEVICE
);
510 static int omap2_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
511 const unsigned char *buffer
,
512 int offset
, size_t count
)
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
;
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
,
529 dma_src
= dma_map_single(&c
->pdev
->dev
, (void *) buffer
, count
,
531 dma_dst
= c
->phys_base
+ bram_offset
;
532 if (dma_mapping_error(&c
->pdev
->dev
, dma_src
)) {
533 dev_err(&c
->pdev
->dev
,
534 "Couldn't DMA map a %d byte buffer\n",
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
,
543 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
546 INIT_COMPLETION(c
->dma_done
);
547 omap_start_dma(c
->dma_channel
);
548 wait_for_completion(&c
->dma_done
);
550 dma_unmap_single(&c
->pdev
->dev
, dma_src
, count
, DMA_TO_DEVICE
);
557 int omap2_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
558 unsigned char *buffer
, int offset
,
561 int omap2_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
562 const unsigned char *buffer
,
563 int offset
, size_t count
);
567 static struct platform_driver omap2_onenand_driver
;
569 static int __adjust_timing(struct device
*dev
, void *data
)
572 struct omap2_onenand
*c
;
574 c
= dev_get_drvdata(dev
);
576 BUG_ON(c
->setup
== NULL
);
578 /* DMA is not in use so this is all that is needed */
579 /* Revisit for OMAP3! */
580 ret
= c
->setup(c
->onenand
.base
, &c
->freq
);
585 int omap2_onenand_rephase(void)
587 return driver_for_each_device(&omap2_onenand_driver
.driver
, NULL
,
588 NULL
, __adjust_timing
);
591 static void omap2_onenand_shutdown(struct platform_device
*pdev
)
593 struct omap2_onenand
*c
= dev_get_drvdata(&pdev
->dev
);
595 /* With certain content in the buffer RAM, the OMAP boot ROM code
596 * can recognize the flash chip incorrectly. Zero it out before
599 memset((__force
void *)c
->onenand
.base
, 0, ONENAND_BUFRAM_SIZE
);
602 static int omap2_onenand_enable(struct mtd_info
*mtd
)
605 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
607 ret
= regulator_enable(c
->regulator
);
609 dev_err(&c
->pdev
->dev
, "can't enable regulator\n");
614 static int omap2_onenand_disable(struct mtd_info
*mtd
)
617 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
619 ret
= regulator_disable(c
->regulator
);
621 dev_err(&c
->pdev
->dev
, "can't disable regulator\n");
626 static int __devinit
omap2_onenand_probe(struct platform_device
*pdev
)
628 struct omap_onenand_platform_data
*pdata
;
629 struct omap2_onenand
*c
;
630 struct onenand_chip
*this;
633 pdata
= pdev
->dev
.platform_data
;
635 dev_err(&pdev
->dev
, "platform data missing\n");
639 c
= kzalloc(sizeof(struct omap2_onenand
), GFP_KERNEL
);
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 */
653 r
= gpmc_cs_request(c
->gpmc_cs
, ONENAND_IO_SIZE
, &c
->phys_base
);
655 dev_err(&pdev
->dev
, "Cannot request GPMC CS\n");
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
);
666 c
->onenand
.base
= ioremap(c
->phys_base
, ONENAND_IO_SIZE
);
667 if (c
->onenand
.base
== NULL
) {
669 goto err_release_mem_region
;
672 if (pdata
->onenand_setup
!= NULL
) {
673 r
= pdata
->onenand_setup(c
->onenand
.base
, &c
->freq
);
675 dev_err(&pdev
->dev
, "Onenand platform setup failed: "
679 c
->setup
= pdata
->onenand_setup
;
683 if ((r
= gpio_request(c
->gpio_irq
, "OneNAND irq")) < 0) {
684 dev_err(&pdev
->dev
, "Failed to request GPIO%d for "
685 "OneNAND\n", c
->gpio_irq
);
688 gpio_direction_input(c
->gpio_irq
);
690 if ((r
= request_irq(gpio_to_irq(c
->gpio_irq
),
691 omap2_onenand_interrupt
, IRQF_TRIGGER_RISING
,
692 pdev
->dev
.driver
->name
, c
)) < 0)
693 goto err_release_gpio
;
696 if (c
->dma_channel
>= 0) {
697 r
= omap_request_dma(0, pdev
->dev
.driver
->name
,
698 omap2_onenand_dma_cb
, (void *) c
,
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
);
711 "failed to allocate DMA for OneNAND, "
712 "using PIO instead\n");
717 dev_info(&pdev
->dev
, "initializing on CS%d, phys base 0x%08lx, virtual "
718 "base %p, freq %d MHz\n", c
->gpmc_cs
, c
->phys_base
,
719 c
->onenand
.base
, c
->freq
);
722 c
->mtd
.name
= dev_name(&pdev
->dev
);
723 c
->mtd
.priv
= &c
->onenand
;
724 c
->mtd
.owner
= THIS_MODULE
;
726 c
->mtd
.dev
.parent
= &pdev
->dev
;
729 if (c
->dma_channel
>= 0) {
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
;
735 this->read_bufferram
= omap2_onenand_read_bufferram
;
736 this->write_bufferram
= omap2_onenand_write_bufferram
;
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
;
746 c
->onenand
.enable
= omap2_onenand_enable
;
747 c
->onenand
.disable
= omap2_onenand_disable
;
750 if (pdata
->skip_initial_unlocking
)
751 this->options
|= ONENAND_SKIP_INITIAL_UNLOCKING
;
753 if ((r
= onenand_scan(&c
->mtd
, 1)) < 0)
754 goto err_release_regulator
;
756 r
= parse_mtd_partitions(&c
->mtd
, part_probes
, &c
->parts
, 0);
758 r
= mtd_device_register(&c
->mtd
, c
->parts
, r
);
759 else if (pdata
->parts
!= NULL
)
760 r
= mtd_device_register(&c
->mtd
, pdata
->parts
, pdata
->nr_parts
);
762 r
= mtd_device_register(&c
->mtd
, NULL
, 0);
764 goto err_release_onenand
;
766 platform_set_drvdata(pdev
, c
);
771 onenand_release(&c
->mtd
);
772 err_release_regulator
:
773 regulator_put(c
->regulator
);
775 if (c
->dma_channel
!= -1)
776 omap_free_dma(c
->dma_channel
);
778 free_irq(gpio_to_irq(c
->gpio_irq
), c
);
781 gpio_free(c
->gpio_irq
);
783 iounmap(c
->onenand
.base
);
784 err_release_mem_region
:
785 release_mem_region(c
->phys_base
, ONENAND_IO_SIZE
);
787 gpmc_cs_free(c
->gpmc_cs
);
795 static int __devexit
omap2_onenand_remove(struct platform_device
*pdev
)
797 struct omap2_onenand
*c
= dev_get_drvdata(&pdev
->dev
);
799 onenand_release(&c
->mtd
);
800 regulator_put(c
->regulator
);
801 if (c
->dma_channel
!= -1)
802 omap_free_dma(c
->dma_channel
);
803 omap2_onenand_shutdown(pdev
);
804 platform_set_drvdata(pdev
, NULL
);
806 free_irq(gpio_to_irq(c
->gpio_irq
), c
);
807 gpio_free(c
->gpio_irq
);
809 iounmap(c
->onenand
.base
);
810 release_mem_region(c
->phys_base
, ONENAND_IO_SIZE
);
811 gpmc_cs_free(c
->gpmc_cs
);
818 static struct platform_driver omap2_onenand_driver
= {
819 .probe
= omap2_onenand_probe
,
820 .remove
= __devexit_p(omap2_onenand_remove
),
821 .shutdown
= omap2_onenand_shutdown
,
824 .owner
= THIS_MODULE
,
828 static int __init
omap2_onenand_init(void)
830 printk(KERN_INFO
"OneNAND driver initializing\n");
831 return platform_driver_register(&omap2_onenand_driver
);
834 static void __exit
omap2_onenand_exit(void)
836 platform_driver_unregister(&omap2_onenand_driver
);
839 module_init(omap2_onenand_init
);
840 module_exit(omap2_onenand_exit
);
842 MODULE_ALIAS("platform:" DRIVER_NAME
);
843 MODULE_LICENSE("GPL");
844 MODULE_AUTHOR("Jarkko Lavinen <jarkko.lavinen@nokia.com>");
845 MODULE_DESCRIPTION("Glue layer for OneNAND flash on OMAP2 / OMAP3");