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 <linux/platform_data/mtd-onenand-omap2.h>
44 #include <linux/omap-dma.h>
46 #define DRIVER_NAME "omap2-onenand"
48 #define ONENAND_BUFRAM_SIZE (1024 * 5)
50 struct omap2_onenand
{
51 struct platform_device
*pdev
;
53 unsigned long phys_base
;
54 unsigned int mem_size
;
57 struct onenand_chip onenand
;
58 struct completion irq_done
;
59 struct completion dma_done
;
62 int (*setup
)(void __iomem
*base
, int *freq_ptr
);
63 struct regulator
*regulator
;
67 static void omap2_onenand_dma_cb(int lch
, u16 ch_status
, void *data
)
69 struct omap2_onenand
*c
= data
;
71 complete(&c
->dma_done
);
74 static irqreturn_t
omap2_onenand_interrupt(int irq
, void *dev_id
)
76 struct omap2_onenand
*c
= dev_id
;
78 complete(&c
->irq_done
);
83 static inline unsigned short read_reg(struct omap2_onenand
*c
, int reg
)
85 return readw(c
->onenand
.base
+ reg
);
88 static inline void write_reg(struct omap2_onenand
*c
, unsigned short value
,
91 writew(value
, c
->onenand
.base
+ reg
);
94 static void wait_err(char *msg
, int state
, unsigned int ctrl
, unsigned int intr
)
96 printk(KERN_ERR
"onenand_wait: %s! state %d ctrl 0x%04x intr 0x%04x\n",
97 msg
, state
, ctrl
, intr
);
100 static void wait_warn(char *msg
, int state
, unsigned int ctrl
,
103 printk(KERN_WARNING
"onenand_wait: %s! state %d ctrl 0x%04x "
104 "intr 0x%04x\n", msg
, state
, ctrl
, intr
);
107 static int omap2_onenand_wait(struct mtd_info
*mtd
, int state
)
109 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
110 struct onenand_chip
*this = mtd
->priv
;
111 unsigned int intr
= 0;
112 unsigned int ctrl
, ctrl_mask
;
113 unsigned long timeout
;
116 if (state
== FL_RESETING
|| state
== FL_PREPARING_ERASE
||
117 state
== FL_VERIFYING_ERASE
) {
119 unsigned int intr_flags
= ONENAND_INT_MASTER
;
123 intr_flags
|= ONENAND_INT_RESET
;
125 case FL_PREPARING_ERASE
:
126 intr_flags
|= ONENAND_INT_ERASE
;
128 case FL_VERIFYING_ERASE
:
135 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
136 if (intr
& ONENAND_INT_MASTER
)
139 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
140 if (ctrl
& ONENAND_CTRL_ERROR
) {
141 wait_err("controller error", state
, ctrl
, intr
);
144 if ((intr
& intr_flags
) == intr_flags
)
146 /* Continue in wait for interrupt branch */
149 if (state
!= FL_READING
) {
152 /* Turn interrupts on */
153 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
154 if (!(syscfg
& ONENAND_SYS_CFG1_IOBE
)) {
155 syscfg
|= ONENAND_SYS_CFG1_IOBE
;
156 write_reg(c
, syscfg
, ONENAND_REG_SYS_CFG1
);
157 if (c
->flags
& ONENAND_IN_OMAP34XX
)
158 /* Add a delay to let GPIO settle */
159 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
162 INIT_COMPLETION(c
->irq_done
);
164 result
= gpio_get_value(c
->gpio_irq
);
166 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
167 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
168 wait_err("gpio error", state
, ctrl
, intr
);
176 result
= wait_for_completion_timeout(&c
->irq_done
,
177 msecs_to_jiffies(20));
179 /* Timeout after 20ms */
180 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
181 if (ctrl
& ONENAND_CTRL_ONGO
&&
184 * The operation seems to be still going
185 * so give it some more time.
191 ONENAND_REG_INTERRUPT
);
192 wait_err("timeout", state
, ctrl
, intr
);
195 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
196 if ((intr
& ONENAND_INT_MASTER
) == 0)
197 wait_warn("timeout", state
, ctrl
, intr
);
203 /* Turn interrupts off */
204 syscfg
= read_reg(c
, ONENAND_REG_SYS_CFG1
);
205 syscfg
&= ~ONENAND_SYS_CFG1_IOBE
;
206 write_reg(c
, syscfg
, ONENAND_REG_SYS_CFG1
);
208 timeout
= jiffies
+ msecs_to_jiffies(20);
210 if (time_before(jiffies
, timeout
)) {
211 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
212 if (intr
& ONENAND_INT_MASTER
)
215 /* Timeout after 20ms */
216 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
217 if (ctrl
& ONENAND_CTRL_ONGO
) {
219 * The operation seems to be still going
220 * so give it some more time.
225 msecs_to_jiffies(20);
234 intr
= read_reg(c
, ONENAND_REG_INTERRUPT
);
235 ctrl
= read_reg(c
, ONENAND_REG_CTRL_STATUS
);
237 if (intr
& ONENAND_INT_READ
) {
238 int ecc
= read_reg(c
, ONENAND_REG_ECC_STATUS
);
241 unsigned int addr1
, addr8
;
243 addr1
= read_reg(c
, ONENAND_REG_START_ADDRESS1
);
244 addr8
= read_reg(c
, ONENAND_REG_START_ADDRESS8
);
245 if (ecc
& ONENAND_ECC_2BIT_ALL
) {
246 printk(KERN_ERR
"onenand_wait: ECC error = "
247 "0x%04x, addr1 %#x, addr8 %#x\n",
249 mtd
->ecc_stats
.failed
++;
251 } else if (ecc
& ONENAND_ECC_1BIT_ALL
) {
252 printk(KERN_NOTICE
"onenand_wait: correctable "
253 "ECC error = 0x%04x, addr1 %#x, "
254 "addr8 %#x\n", ecc
, addr1
, addr8
);
255 mtd
->ecc_stats
.corrected
++;
258 } else if (state
== FL_READING
) {
259 wait_err("timeout", state
, ctrl
, intr
);
263 if (ctrl
& ONENAND_CTRL_ERROR
) {
264 wait_err("controller error", state
, ctrl
, intr
);
265 if (ctrl
& ONENAND_CTRL_LOCK
)
266 printk(KERN_ERR
"onenand_wait: "
267 "Device is write protected!!!\n");
273 ctrl_mask
&= ~0x8000;
275 if (ctrl
& ctrl_mask
)
276 wait_warn("unexpected controller status", state
, ctrl
, intr
);
281 static inline int omap2_onenand_bufferram_offset(struct mtd_info
*mtd
, int area
)
283 struct onenand_chip
*this = mtd
->priv
;
285 if (ONENAND_CURRENT_BUFFERRAM(this)) {
286 if (area
== ONENAND_DATARAM
)
287 return this->writesize
;
288 if (area
== ONENAND_SPARERAM
)
295 #if defined(CONFIG_ARCH_OMAP3) || defined(MULTI_OMAP2)
297 static int omap3_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
298 unsigned char *buffer
, int offset
,
301 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
302 struct onenand_chip
*this = mtd
->priv
;
303 dma_addr_t dma_src
, dma_dst
;
305 unsigned long timeout
;
306 void *buf
= (void *)buffer
;
308 volatile unsigned *done
;
310 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
311 if (bram_offset
& 3 || (size_t)buf
& 3 || count
< 384)
314 /* panic_write() may be in an interrupt context */
315 if (in_interrupt() || oops_in_progress
)
318 if (buf
>= high_memory
) {
321 if (((size_t)buf
& PAGE_MASK
) !=
322 ((size_t)(buf
+ count
- 1) & PAGE_MASK
))
324 p1
= vmalloc_to_page(buf
);
327 buf
= page_address(p1
) + ((size_t)buf
& ~PAGE_MASK
);
333 memcpy(buf
+ count
, this->base
+ bram_offset
+ count
, xtra
);
336 dma_src
= c
->phys_base
+ bram_offset
;
337 dma_dst
= dma_map_single(&c
->pdev
->dev
, buf
, count
, DMA_FROM_DEVICE
);
338 if (dma_mapping_error(&c
->pdev
->dev
, dma_dst
)) {
339 dev_err(&c
->pdev
->dev
,
340 "Couldn't DMA map a %d byte buffer\n",
345 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S32
,
346 count
>> 2, 1, 0, 0, 0);
347 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
349 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
352 INIT_COMPLETION(c
->dma_done
);
353 omap_start_dma(c
->dma_channel
);
355 timeout
= jiffies
+ msecs_to_jiffies(20);
356 done
= &c
->dma_done
.done
;
357 while (time_before(jiffies
, timeout
))
361 dma_unmap_single(&c
->pdev
->dev
, dma_dst
, count
, DMA_FROM_DEVICE
);
364 dev_err(&c
->pdev
->dev
, "timeout waiting for DMA\n");
371 memcpy(buf
, this->base
+ bram_offset
, count
);
375 static int omap3_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
376 const unsigned char *buffer
,
377 int offset
, size_t count
)
379 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
380 struct onenand_chip
*this = mtd
->priv
;
381 dma_addr_t dma_src
, dma_dst
;
383 unsigned long timeout
;
384 void *buf
= (void *)buffer
;
385 volatile unsigned *done
;
387 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
388 if (bram_offset
& 3 || (size_t)buf
& 3 || count
< 384)
391 /* panic_write() may be in an interrupt context */
392 if (in_interrupt() || oops_in_progress
)
395 if (buf
>= high_memory
) {
398 if (((size_t)buf
& PAGE_MASK
) !=
399 ((size_t)(buf
+ count
- 1) & PAGE_MASK
))
401 p1
= vmalloc_to_page(buf
);
404 buf
= page_address(p1
) + ((size_t)buf
& ~PAGE_MASK
);
407 dma_src
= dma_map_single(&c
->pdev
->dev
, buf
, count
, DMA_TO_DEVICE
);
408 dma_dst
= c
->phys_base
+ bram_offset
;
409 if (dma_mapping_error(&c
->pdev
->dev
, dma_src
)) {
410 dev_err(&c
->pdev
->dev
,
411 "Couldn't DMA map a %d byte buffer\n",
416 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S32
,
417 count
>> 2, 1, 0, 0, 0);
418 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
420 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
423 INIT_COMPLETION(c
->dma_done
);
424 omap_start_dma(c
->dma_channel
);
426 timeout
= jiffies
+ msecs_to_jiffies(20);
427 done
= &c
->dma_done
.done
;
428 while (time_before(jiffies
, timeout
))
432 dma_unmap_single(&c
->pdev
->dev
, dma_src
, count
, DMA_TO_DEVICE
);
435 dev_err(&c
->pdev
->dev
, "timeout waiting for DMA\n");
442 memcpy(this->base
+ bram_offset
, buf
, count
);
448 static int omap3_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
449 unsigned char *buffer
, int offset
,
455 static int omap3_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
456 const unsigned char *buffer
,
457 int offset
, size_t count
)
464 #if defined(CONFIG_ARCH_OMAP2) || defined(MULTI_OMAP2)
466 static int omap2_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
467 unsigned char *buffer
, int offset
,
470 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
471 struct onenand_chip
*this = mtd
->priv
;
472 dma_addr_t dma_src
, dma_dst
;
475 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
476 /* DMA is not used. Revisit PM requirements before enabling it. */
477 if (1 || (c
->dma_channel
< 0) ||
478 ((void *) buffer
>= (void *) high_memory
) || (bram_offset
& 3) ||
479 (((unsigned int) buffer
) & 3) || (count
< 1024) || (count
& 3)) {
480 memcpy(buffer
, (__force
void *)(this->base
+ bram_offset
),
485 dma_src
= c
->phys_base
+ bram_offset
;
486 dma_dst
= dma_map_single(&c
->pdev
->dev
, buffer
, count
,
488 if (dma_mapping_error(&c
->pdev
->dev
, dma_dst
)) {
489 dev_err(&c
->pdev
->dev
,
490 "Couldn't DMA map a %d byte buffer\n",
495 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S32
,
496 count
/ 4, 1, 0, 0, 0);
497 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
499 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
502 INIT_COMPLETION(c
->dma_done
);
503 omap_start_dma(c
->dma_channel
);
504 wait_for_completion(&c
->dma_done
);
506 dma_unmap_single(&c
->pdev
->dev
, dma_dst
, count
, DMA_FROM_DEVICE
);
511 static int omap2_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
512 const unsigned char *buffer
,
513 int offset
, size_t count
)
515 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
516 struct onenand_chip
*this = mtd
->priv
;
517 dma_addr_t dma_src
, dma_dst
;
520 bram_offset
= omap2_onenand_bufferram_offset(mtd
, area
) + area
+ offset
;
521 /* DMA is not used. Revisit PM requirements before enabling it. */
522 if (1 || (c
->dma_channel
< 0) ||
523 ((void *) buffer
>= (void *) high_memory
) || (bram_offset
& 3) ||
524 (((unsigned int) buffer
) & 3) || (count
< 1024) || (count
& 3)) {
525 memcpy((__force
void *)(this->base
+ bram_offset
), buffer
,
530 dma_src
= dma_map_single(&c
->pdev
->dev
, (void *) buffer
, count
,
532 dma_dst
= c
->phys_base
+ bram_offset
;
533 if (dma_mapping_error(&c
->pdev
->dev
, dma_src
)) {
534 dev_err(&c
->pdev
->dev
,
535 "Couldn't DMA map a %d byte buffer\n",
540 omap_set_dma_transfer_params(c
->dma_channel
, OMAP_DMA_DATA_TYPE_S16
,
541 count
/ 2, 1, 0, 0, 0);
542 omap_set_dma_src_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
544 omap_set_dma_dest_params(c
->dma_channel
, 0, OMAP_DMA_AMODE_POST_INC
,
547 INIT_COMPLETION(c
->dma_done
);
548 omap_start_dma(c
->dma_channel
);
549 wait_for_completion(&c
->dma_done
);
551 dma_unmap_single(&c
->pdev
->dev
, dma_src
, count
, DMA_TO_DEVICE
);
558 static int omap2_onenand_read_bufferram(struct mtd_info
*mtd
, int area
,
559 unsigned char *buffer
, int offset
,
565 static int omap2_onenand_write_bufferram(struct mtd_info
*mtd
, int area
,
566 const unsigned char *buffer
,
567 int offset
, size_t count
)
574 static struct platform_driver omap2_onenand_driver
;
576 static int __adjust_timing(struct device
*dev
, void *data
)
579 struct omap2_onenand
*c
;
581 c
= dev_get_drvdata(dev
);
583 BUG_ON(c
->setup
== NULL
);
585 /* DMA is not in use so this is all that is needed */
586 /* Revisit for OMAP3! */
587 ret
= c
->setup(c
->onenand
.base
, &c
->freq
);
592 int omap2_onenand_rephase(void)
594 return driver_for_each_device(&omap2_onenand_driver
.driver
, NULL
,
595 NULL
, __adjust_timing
);
598 static void omap2_onenand_shutdown(struct platform_device
*pdev
)
600 struct omap2_onenand
*c
= dev_get_drvdata(&pdev
->dev
);
602 /* With certain content in the buffer RAM, the OMAP boot ROM code
603 * can recognize the flash chip incorrectly. Zero it out before
606 memset((__force
void *)c
->onenand
.base
, 0, ONENAND_BUFRAM_SIZE
);
609 static int omap2_onenand_enable(struct mtd_info
*mtd
)
612 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
614 ret
= regulator_enable(c
->regulator
);
616 dev_err(&c
->pdev
->dev
, "can't enable regulator\n");
621 static int omap2_onenand_disable(struct mtd_info
*mtd
)
624 struct omap2_onenand
*c
= container_of(mtd
, struct omap2_onenand
, mtd
);
626 ret
= regulator_disable(c
->regulator
);
628 dev_err(&c
->pdev
->dev
, "can't disable regulator\n");
633 static int omap2_onenand_probe(struct platform_device
*pdev
)
635 struct omap_onenand_platform_data
*pdata
;
636 struct omap2_onenand
*c
;
637 struct onenand_chip
*this;
639 struct resource
*res
;
640 struct mtd_part_parser_data ppdata
= {};
642 pdata
= dev_get_platdata(&pdev
->dev
);
644 dev_err(&pdev
->dev
, "platform data missing\n");
648 c
= kzalloc(sizeof(struct omap2_onenand
), GFP_KERNEL
);
652 init_completion(&c
->irq_done
);
653 init_completion(&c
->dma_done
);
654 c
->flags
= pdata
->flags
;
655 c
->gpmc_cs
= pdata
->cs
;
656 c
->gpio_irq
= pdata
->gpio_irq
;
657 c
->dma_channel
= pdata
->dma_channel
;
658 if (c
->dma_channel
< 0) {
659 /* if -1, don't use DMA */
663 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
666 dev_err(&pdev
->dev
, "error getting memory resource\n");
670 c
->phys_base
= res
->start
;
671 c
->mem_size
= resource_size(res
);
673 if (request_mem_region(c
->phys_base
, c
->mem_size
,
674 pdev
->dev
.driver
->name
) == NULL
) {
675 dev_err(&pdev
->dev
, "Cannot reserve memory region at 0x%08lx, size: 0x%x\n",
676 c
->phys_base
, c
->mem_size
);
680 c
->onenand
.base
= ioremap(c
->phys_base
, c
->mem_size
);
681 if (c
->onenand
.base
== NULL
) {
683 goto err_release_mem_region
;
686 if (pdata
->onenand_setup
!= NULL
) {
687 r
= pdata
->onenand_setup(c
->onenand
.base
, &c
->freq
);
689 dev_err(&pdev
->dev
, "Onenand platform setup failed: "
693 c
->setup
= pdata
->onenand_setup
;
697 if ((r
= gpio_request(c
->gpio_irq
, "OneNAND irq")) < 0) {
698 dev_err(&pdev
->dev
, "Failed to request GPIO%d for "
699 "OneNAND\n", c
->gpio_irq
);
702 gpio_direction_input(c
->gpio_irq
);
704 if ((r
= request_irq(gpio_to_irq(c
->gpio_irq
),
705 omap2_onenand_interrupt
, IRQF_TRIGGER_RISING
,
706 pdev
->dev
.driver
->name
, c
)) < 0)
707 goto err_release_gpio
;
710 if (c
->dma_channel
>= 0) {
711 r
= omap_request_dma(0, pdev
->dev
.driver
->name
,
712 omap2_onenand_dma_cb
, (void *) c
,
715 omap_set_dma_write_mode(c
->dma_channel
,
716 OMAP_DMA_WRITE_NON_POSTED
);
717 omap_set_dma_src_data_pack(c
->dma_channel
, 1);
718 omap_set_dma_src_burst_mode(c
->dma_channel
,
719 OMAP_DMA_DATA_BURST_8
);
720 omap_set_dma_dest_data_pack(c
->dma_channel
, 1);
721 omap_set_dma_dest_burst_mode(c
->dma_channel
,
722 OMAP_DMA_DATA_BURST_8
);
725 "failed to allocate DMA for OneNAND, "
726 "using PIO instead\n");
731 dev_info(&pdev
->dev
, "initializing on CS%d, phys base 0x%08lx, virtual "
732 "base %p, freq %d MHz\n", c
->gpmc_cs
, c
->phys_base
,
733 c
->onenand
.base
, c
->freq
);
736 c
->mtd
.name
= dev_name(&pdev
->dev
);
737 c
->mtd
.priv
= &c
->onenand
;
738 c
->mtd
.owner
= THIS_MODULE
;
740 c
->mtd
.dev
.parent
= &pdev
->dev
;
743 if (c
->dma_channel
>= 0) {
744 this->wait
= omap2_onenand_wait
;
745 if (c
->flags
& ONENAND_IN_OMAP34XX
) {
746 this->read_bufferram
= omap3_onenand_read_bufferram
;
747 this->write_bufferram
= omap3_onenand_write_bufferram
;
749 this->read_bufferram
= omap2_onenand_read_bufferram
;
750 this->write_bufferram
= omap2_onenand_write_bufferram
;
754 if (pdata
->regulator_can_sleep
) {
755 c
->regulator
= regulator_get(&pdev
->dev
, "vonenand");
756 if (IS_ERR(c
->regulator
)) {
757 dev_err(&pdev
->dev
, "Failed to get regulator\n");
758 r
= PTR_ERR(c
->regulator
);
759 goto err_release_dma
;
761 c
->onenand
.enable
= omap2_onenand_enable
;
762 c
->onenand
.disable
= omap2_onenand_disable
;
765 if (pdata
->skip_initial_unlocking
)
766 this->options
|= ONENAND_SKIP_INITIAL_UNLOCKING
;
768 if ((r
= onenand_scan(&c
->mtd
, 1)) < 0)
769 goto err_release_regulator
;
771 ppdata
.of_node
= pdata
->of_node
;
772 r
= mtd_device_parse_register(&c
->mtd
, NULL
, &ppdata
,
773 pdata
? pdata
->parts
: NULL
,
774 pdata
? pdata
->nr_parts
: 0);
776 goto err_release_onenand
;
778 platform_set_drvdata(pdev
, c
);
783 onenand_release(&c
->mtd
);
784 err_release_regulator
:
785 regulator_put(c
->regulator
);
787 if (c
->dma_channel
!= -1)
788 omap_free_dma(c
->dma_channel
);
790 free_irq(gpio_to_irq(c
->gpio_irq
), c
);
793 gpio_free(c
->gpio_irq
);
795 iounmap(c
->onenand
.base
);
796 err_release_mem_region
:
797 release_mem_region(c
->phys_base
, c
->mem_size
);
804 static int omap2_onenand_remove(struct platform_device
*pdev
)
806 struct omap2_onenand
*c
= dev_get_drvdata(&pdev
->dev
);
808 onenand_release(&c
->mtd
);
809 regulator_put(c
->regulator
);
810 if (c
->dma_channel
!= -1)
811 omap_free_dma(c
->dma_channel
);
812 omap2_onenand_shutdown(pdev
);
814 free_irq(gpio_to_irq(c
->gpio_irq
), c
);
815 gpio_free(c
->gpio_irq
);
817 iounmap(c
->onenand
.base
);
818 release_mem_region(c
->phys_base
, c
->mem_size
);
824 static struct platform_driver omap2_onenand_driver
= {
825 .probe
= omap2_onenand_probe
,
826 .remove
= omap2_onenand_remove
,
827 .shutdown
= omap2_onenand_shutdown
,
830 .owner
= THIS_MODULE
,
834 module_platform_driver(omap2_onenand_driver
);
836 MODULE_ALIAS("platform:" DRIVER_NAME
);
837 MODULE_LICENSE("GPL");
838 MODULE_AUTHOR("Jarkko Lavinen <jarkko.lavinen@nokia.com>");
839 MODULE_DESCRIPTION("Glue layer for OneNAND flash on OMAP2 / OMAP3");