ARM: gpio: convert includes of mach/gpio.h and asm/gpio.h to linux/gpio.h
[pandora-kernel.git] / arch / arm / mach-ks8695 / board-acs5k.c
1 /*
2  * arch/arm/mach-ks8695/board-acs5k.c
3  *
4  * Brivo Systems LLC, ACS-5000 Master Board
5  *
6  * Copyright 2008 Simtec Electronics
7  *                Daniel Silverstone <dsilvers@simtec.co.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 #include <linux/gpio.h>
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/interrupt.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19
20 #include <linux/i2c.h>
21 #include <linux/i2c-algo-bit.h>
22 #include <linux/i2c-gpio.h>
23 #include <linux/i2c/pca953x.h>
24
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/map.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/mtd/partitions.h>
29
30 #include <asm/mach-types.h>
31
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/irq.h>
35
36 #include <mach/devices.h>
37
38 #include "generic.h"
39
40 static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = {
41         .sda_pin        = 4,
42         .scl_pin        = 5,
43         .udelay         = 10,
44 };
45
46 static struct platform_device acs5k_i2c_device = {
47         .name           = "i2c-gpio",
48         .id             = -1,
49         .num_resources  = 0,
50         .resource       = NULL,
51         .dev            = {
52                 .platform_data  = &acs5k_i2c_device_platdata,
53         },
54 };
55
56 static int acs5k_pca9555_setup(struct i2c_client *client,
57                                unsigned gpio_base, unsigned ngpio,
58                                void *context)
59 {
60         static int acs5k_gpio_value[] = {
61                 -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, -1, 0, 1, 0, -1, -1
62         };
63         int n;
64
65         for (n = 0; n < ARRAY_SIZE(acs5k_gpio_value); ++n) {
66                 gpio_request(gpio_base + n, "ACS-5000 GPIO Expander");
67                 if (acs5k_gpio_value[n] < 0)
68                         gpio_direction_input(gpio_base + n);
69                 else
70                         gpio_direction_output(gpio_base + n,
71                                               acs5k_gpio_value[n]);
72                 gpio_export(gpio_base + n, 0); /* Export, direction locked down */
73         }
74
75         return 0;
76 }
77
78 static struct pca953x_platform_data acs5k_i2c_pca9555_platdata = {
79         .gpio_base      = 16, /* Start directly after the CPU's GPIO */
80         .invert         = 0, /* Do not invert */
81         .setup          = acs5k_pca9555_setup,
82 };
83
84 static struct i2c_board_info acs5k_i2c_devs[] __initdata = {
85         {
86                 I2C_BOARD_INFO("pcf8563", 0x51),
87         },
88         {
89                 I2C_BOARD_INFO("pca9555", 0x20),
90                 .platform_data = &acs5k_i2c_pca9555_platdata,
91         },
92 };
93
94 static void __devinit acs5k_i2c_init(void)
95 {
96         /* The gpio interface */
97         platform_device_register(&acs5k_i2c_device);
98         /* I2C devices */
99         i2c_register_board_info(0, acs5k_i2c_devs,
100                                 ARRAY_SIZE(acs5k_i2c_devs));
101 }
102
103 static struct mtd_partition acs5k_nor_partitions[] = {
104         [0] = {
105                 .name   = "Boot Agent and config",
106                 .size   = SZ_256K,
107                 .offset = 0,
108                 .mask_flags = MTD_WRITEABLE,
109         },
110         [1] = {
111                 .name   = "Kernel",
112                 .size   = SZ_1M,
113                 .offset = SZ_256K,
114         },
115         [2] = {
116                 .name   = "SquashFS1",
117                 .size   = SZ_2M,
118                 .offset = SZ_256K + SZ_1M,
119         },
120         [3] = {
121                 .name   = "SquashFS2",
122                 .size   = SZ_4M + SZ_2M,
123                 .offset = SZ_256K + SZ_1M + SZ_2M,
124         },
125         [4] = {
126                 .name   = "Data",
127                 .size   = SZ_16M + SZ_4M + SZ_2M + SZ_512K, /* 22.5 MB */
128                 .offset = SZ_256K + SZ_8M + SZ_1M,
129         }
130 };
131
132 static struct physmap_flash_data acs5k_nor_pdata = {
133         .width          = 4,
134         .nr_parts       = ARRAY_SIZE(acs5k_nor_partitions),
135         .parts          = acs5k_nor_partitions,
136 };
137
138 static struct resource acs5k_nor_resource[] = {
139         [0] = {
140                 .start = SZ_32M, /* We expect the bootloader to map
141                                   * the flash here.
142                                   */
143                 .end   = SZ_32M + SZ_16M - 1,
144                 .flags = IORESOURCE_MEM,
145         },
146         [1] = {
147                 .start = SZ_32M + SZ_16M,
148                 .end   = SZ_32M + SZ_32M - SZ_256K - 1,
149                 .flags = IORESOURCE_MEM,
150         }
151 };
152
153 static struct platform_device acs5k_device_nor = {
154         .name           = "physmap-flash",
155         .id             = -1,
156         .num_resources  = ARRAY_SIZE(acs5k_nor_resource),
157         .resource       = acs5k_nor_resource,
158         .dev            = {
159                 .platform_data = &acs5k_nor_pdata,
160         },
161 };
162
163 static void __init acs5k_register_nor(void)
164 {
165         int ret;
166
167         if (acs5k_nor_partitions[0].mask_flags == 0)
168                 printk(KERN_WARNING "Warning: Unprotecting bootloader and configuration partition\n");
169
170         ret = platform_device_register(&acs5k_device_nor);
171         if (ret < 0)
172                 printk(KERN_ERR "failed to register physmap-flash device\n");
173 }
174
175 static int __init acs5k_protection_setup(char *s)
176 {
177         /* We can't allocate anything here but we should be able
178          * to trivially parse s and decide if we can protect the
179          * bootloader partition or not
180          */
181         if (strcmp(s, "no") == 0)
182                 acs5k_nor_partitions[0].mask_flags = 0;
183
184         return 1;
185 }
186
187 __setup("protect_bootloader=", acs5k_protection_setup);
188
189 static void __init acs5k_init_gpio(void)
190 {
191         int i;
192
193         ks8695_register_gpios();
194         for (i = 0; i < 4; ++i)
195                 gpio_request(i, "ACS5K IRQ");
196         gpio_request(7, "ACS5K KS_FRDY");
197         for (i = 8; i < 16; ++i)
198                 gpio_request(i, "ACS5K Unused");
199
200         gpio_request(3, "ACS5K CAN Control");
201         gpio_request(6, "ACS5K Heartbeat");
202         gpio_direction_output(3, 1); /* Default CAN_RESET high */
203         gpio_direction_output(6, 0); /* Default KS8695_ACTIVE low */
204         gpio_export(3, 0); /* export CAN_RESET as output only */
205         gpio_export(6, 0); /* export KS8695_ACTIVE as output only */
206 }
207
208 static void __init acs5k_init(void)
209 {
210         acs5k_init_gpio();
211
212         /* Network device */
213         ks8695_add_device_lan();        /* eth0 = LAN */
214         ks8695_add_device_wan();        /* ethX = WAN */
215
216         /* NOR devices */
217         acs5k_register_nor();
218
219         /* I2C bus */
220         acs5k_i2c_init();
221 }
222
223 MACHINE_START(ACS5K, "Brivo Systems LLC ACS-5000 Master board")
224         /* Maintainer: Simtec Electronics. */
225         .boot_params    = KS8695_SDRAM_PA + 0x100,
226         .map_io         = ks8695_map_io,
227         .init_irq       = ks8695_init_irq,
228         .init_machine   = acs5k_init,
229         .timer          = &ks8695_timer,
230 MACHINE_END