6155f70fbab54058652a185666de9b21eee8fe68
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / dev-nfc.c
1 /*
2  *  Atheros AR934X SoCs built-in NAND flash controller support
3  *
4  *  Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/delay.h>
13 #include <linux/init.h>
14 #include <linux/irq.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/etherdevice.h>
17 #include <linux/platform_device.h>
18 #include <linux/platform/ar934x_nfc.h>
19
20 #include <asm/mach-ath79/ath79.h>
21 #include <asm/mach-ath79/ar71xx_regs.h>
22
23 #include "dev-nfc.h"
24
25 static struct resource ath79_nfc_resources[2];
26 static u64 ar934x_nfc_dmamask = DMA_BIT_MASK(32);
27 static struct ar934x_nfc_platform_data ath79_nfc_data;
28
29 static struct platform_device ath79_nfc_device = {
30         .name           = AR934X_NFC_DRIVER_NAME,
31         .id             = -1,
32         .resource       = ath79_nfc_resources,
33         .num_resources  = ARRAY_SIZE(ath79_nfc_resources),
34         .dev = {
35                 .dma_mask = &ar934x_nfc_dmamask,
36                 .coherent_dma_mask = DMA_BIT_MASK(32),
37                 .platform_data = &ath79_nfc_data,
38         },
39 };
40
41 static void ar934x_nfc_hw_reset(bool active)
42 {
43         if (active) {
44                 ath79_device_reset_set(AR934X_RESET_NANDF);
45                 udelay(100);
46
47                 ath79_device_reset_set(AR934X_RESET_ETH_SWITCH_ANALOG);
48                 udelay(250);
49         } else {
50                 ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH_ANALOG);
51                 udelay(250);
52
53                 ath79_device_reset_clear(AR934X_RESET_NANDF);
54                 udelay(100);
55         }
56 }
57
58 static void ar934x_nfc_setup(void)
59 {
60         ath79_nfc_resources[0].start = AR934X_NFC_BASE;
61         ath79_nfc_resources[0].end = AR934X_NFC_BASE + AR934X_NFC_SIZE - 1;
62         ath79_nfc_resources[0].flags = IORESOURCE_MEM;
63
64         ath79_nfc_resources[1].start = ATH79_MISC_IRQ(21);
65         ath79_nfc_resources[1].end = ATH79_MISC_IRQ(21);
66         ath79_nfc_resources[1].flags = IORESOURCE_IRQ;
67
68         ath79_nfc_data.hw_reset = ar934x_nfc_hw_reset;
69
70         platform_device_register(&ath79_nfc_device);
71 }
72
73 void __init ath79_nfc_set_select_chip(void (*f)(int chip_no))
74 {
75         ath79_nfc_data.select_chip = f;
76 }
77
78 void __init ath79_nfc_set_scan_fixup(int (*f)(struct mtd_info *mtd))
79 {
80         ath79_nfc_data.scan_fixup = f;
81 }
82
83 void __init ath79_nfc_set_swap_dma(bool enable)
84 {
85         ath79_nfc_data.swap_dma = enable;
86 }
87
88 void __init ath79_nfc_set_parts(struct mtd_partition *parts, int nr_parts)
89 {
90         ath79_nfc_data.parts = parts;
91         ath79_nfc_data.nr_parts = nr_parts;
92 }
93
94 void __init ath79_register_nfc(void)
95 {
96         if (soc_is_ar934x())
97                 ar934x_nfc_setup();
98         else
99                 BUG();
100 }