bf5f8f8d3b5f72fab3ea181a856f1a36c2e38ca1
[pandora-kernel.git] / arch / sh / boards / mach-kfr2r09 / setup.c
1 /*
2  * KFR2R09 board support code
3  *
4  * Copyright (C) 2009 Magnus Damm
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License.  See the file "COPYING" in the main directory of this archive
8  * for more details.
9  */
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/interrupt.h>
13 #include <linux/mtd/physmap.h>
14 #include <linux/delay.h>
15 #include <linux/clk.h>
16 #include <linux/gpio.h>
17 #include <linux/input.h>
18 #include <asm/clock.h>
19 #include <asm/machvec.h>
20 #include <asm/io.h>
21 #include <asm/sh_keysc.h>
22 #include <cpu/sh7724.h>
23
24 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
25 {
26         {
27                 .name = "boot",
28                 .offset = 0,
29                 .size = (4 * 1024 * 1024),
30                 .mask_flags = MTD_WRITEABLE,    /* Read-only */
31         },
32         {
33                 .name = "other",
34                 .offset = MTDPART_OFS_APPEND,
35                 .size = MTDPART_SIZ_FULL,
36         },
37 };
38
39 static struct physmap_flash_data kfr2r09_nor_flash_data = {
40         .width          = 2,
41         .parts          = kfr2r09_nor_flash_partitions,
42         .nr_parts       = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
43 };
44
45 static struct resource kfr2r09_nor_flash_resources[] = {
46         [0] = {
47                 .name           = "NOR Flash",
48                 .start          = 0x00000000,
49                 .end            = 0x03ffffff,
50                 .flags          = IORESOURCE_MEM,
51         }
52 };
53
54 static struct platform_device kfr2r09_nor_flash_device = {
55         .name           = "physmap-flash",
56         .resource       = kfr2r09_nor_flash_resources,
57         .num_resources  = ARRAY_SIZE(kfr2r09_nor_flash_resources),
58         .dev            = {
59                 .platform_data = &kfr2r09_nor_flash_data,
60         },
61 };
62
63 static struct sh_keysc_info kfr2r09_sh_keysc_info = {
64         .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
65         .scan_timing = 3,
66         .delay = 10,
67         .keycodes = {
68                 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
69                 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
70                 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
71                 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
72                 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
73                 0, 0, 0, 0, 0
74         },
75 };
76
77 static struct resource kfr2r09_sh_keysc_resources[] = {
78         [0] = {
79                 .name   = "KEYSC",
80                 .start  = 0x044b0000,
81                 .end    = 0x044b000f,
82                 .flags  = IORESOURCE_MEM,
83         },
84         [1] = {
85                 .start  = 79,
86                 .flags  = IORESOURCE_IRQ,
87         },
88 };
89
90 static struct platform_device kfr2r09_sh_keysc_device = {
91         .name           = "sh_keysc",
92         .id             = 0, /* "keysc0" clock */
93         .num_resources  = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
94         .resource       = kfr2r09_sh_keysc_resources,
95         .dev    = {
96                 .platform_data  = &kfr2r09_sh_keysc_info,
97         },
98 };
99
100 static struct platform_device *kfr2r09_devices[] __initdata = {
101         &kfr2r09_nor_flash_device,
102         &kfr2r09_sh_keysc_device,
103 };
104
105 #define BSC_CS0BCR 0xfec10004
106 #define BSC_CS0WCR 0xfec10024
107
108 static int __init kfr2r09_devices_setup(void)
109 {
110         /* enable SCIF1 serial port for YC401 console support */
111         gpio_request(GPIO_FN_SCIF1_RXD, NULL);
112         gpio_request(GPIO_FN_SCIF1_TXD, NULL);
113
114         /* setup NOR flash at CS0 */
115         ctrl_outl(0x36db0400, BSC_CS0BCR);
116         ctrl_outl(0x00000500, BSC_CS0WCR);
117
118         /* setup KEYSC pins */
119         gpio_request(GPIO_FN_KEYOUT0, NULL);
120         gpio_request(GPIO_FN_KEYOUT1, NULL);
121         gpio_request(GPIO_FN_KEYOUT2, NULL);
122         gpio_request(GPIO_FN_KEYOUT3, NULL);
123         gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
124         gpio_request(GPIO_FN_KEYIN0, NULL);
125         gpio_request(GPIO_FN_KEYIN1, NULL);
126         gpio_request(GPIO_FN_KEYIN2, NULL);
127         gpio_request(GPIO_FN_KEYIN3, NULL);
128         gpio_request(GPIO_FN_KEYIN4, NULL);
129         gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
130
131         return platform_add_devices(kfr2r09_devices,
132                                     ARRAY_SIZE(kfr2r09_devices));
133 }
134 device_initcall(kfr2r09_devices_setup);
135
136 /* Return the board specific boot mode pin configuration */
137 static int kfr2r09_mode_pins(void)
138 {
139         /* MD0=1, MD1=1, MD2=0: Clock Mode 3
140          * MD3=0: 16-bit Area0 Bus Width
141          * MD5=1: Little Endian
142          * MD8=1: Test Mode Disabled
143          */
144         return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
145 }
146
147 /*
148  * The Machine Vector
149  */
150 static struct sh_machine_vector mv_kfr2r09 __initmv = {
151         .mv_name                = "kfr2r09",
152         .mv_mode_pins           = kfr2r09_mode_pins,
153 };