blob: ef835d82cdb95ecb7f43d36a80f1dc7c9870a5b6 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/*
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#include <linux/gpio/machine.h>
20#include <linux/i2c.h>
21#include <linux/i2c-algo-bit.h>
22#include <linux/platform_data/i2c-gpio.h>
23#include <linux/platform_data/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 "devices.h"
37#include <mach/gpio-ks8695.h>
38
39#include "generic.h"
40
41static struct gpiod_lookup_table acs5k_i2c_gpiod_table = {
42 .dev_id = "i2c-gpio",
43 .table = {
44 GPIO_LOOKUP_IDX("KS8695", 4, NULL, 0,
45 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
46 GPIO_LOOKUP_IDX("KS8695", 5, NULL, 1,
47 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
48 },
49};
50
51static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = {
52 .udelay = 10,
53};
54
55static struct platform_device acs5k_i2c_device = {
56 .name = "i2c-gpio",
57 .id = -1,
58 .num_resources = 0,
59 .resource = NULL,
60 .dev = {
61 .platform_data = &acs5k_i2c_device_platdata,
62 },
63};
64
65static int acs5k_pca9555_setup(struct i2c_client *client,
66 unsigned gpio_base, unsigned ngpio,
67 void *context)
68{
69 static int acs5k_gpio_value[] = {
70 -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, -1, 0, 1, 0, -1, -1
71 };
72 int n;
73
74 for (n = 0; n < ARRAY_SIZE(acs5k_gpio_value); ++n) {
75 gpio_request(gpio_base + n, "ACS-5000 GPIO Expander");
76 if (acs5k_gpio_value[n] < 0)
77 gpio_direction_input(gpio_base + n);
78 else
79 gpio_direction_output(gpio_base + n,
80 acs5k_gpio_value[n]);
81 gpio_export(gpio_base + n, 0); /* Export, direction locked down */
82 }
83
84 return 0;
85}
86
87static struct pca953x_platform_data acs5k_i2c_pca9555_platdata = {
88 .gpio_base = 16, /* Start directly after the CPU's GPIO */
89 .invert = 0, /* Do not invert */
90 .setup = acs5k_pca9555_setup,
91};
92
93static struct i2c_board_info acs5k_i2c_devs[] __initdata = {
94 {
95 I2C_BOARD_INFO("pcf8563", 0x51),
96 },
97 {
98 I2C_BOARD_INFO("pca9555", 0x20),
99 .platform_data = &acs5k_i2c_pca9555_platdata,
100 },
101};
102
103static void acs5k_i2c_init(void)
104{
105 /* The gpio interface */
106 gpiod_add_lookup_table(&acs5k_i2c_gpiod_table);
107 platform_device_register(&acs5k_i2c_device);
108 /* I2C devices */
109 i2c_register_board_info(0, acs5k_i2c_devs,
110 ARRAY_SIZE(acs5k_i2c_devs));
111}
112
113static struct mtd_partition acs5k_nor_partitions[] = {
114 [0] = {
115 .name = "Boot Agent and config",
116 .size = SZ_256K,
117 .offset = 0,
118 .mask_flags = MTD_WRITEABLE,
119 },
120 [1] = {
121 .name = "Kernel",
122 .size = SZ_1M,
123 .offset = SZ_256K,
124 },
125 [2] = {
126 .name = "SquashFS1",
127 .size = SZ_2M,
128 .offset = SZ_256K + SZ_1M,
129 },
130 [3] = {
131 .name = "SquashFS2",
132 .size = SZ_4M + SZ_2M,
133 .offset = SZ_256K + SZ_1M + SZ_2M,
134 },
135 [4] = {
136 .name = "Data",
137 .size = SZ_16M + SZ_4M + SZ_2M + SZ_512K, /* 22.5 MB */
138 .offset = SZ_256K + SZ_8M + SZ_1M,
139 }
140};
141
142static struct physmap_flash_data acs5k_nor_pdata = {
143 .width = 4,
144 .nr_parts = ARRAY_SIZE(acs5k_nor_partitions),
145 .parts = acs5k_nor_partitions,
146};
147
148static struct resource acs5k_nor_resource[] = {
149 [0] = {
150 .start = SZ_32M, /* We expect the bootloader to map
151 * the flash here.
152 */
153 .end = SZ_32M + SZ_16M - 1,
154 .flags = IORESOURCE_MEM,
155 },
156 [1] = {
157 .start = SZ_32M + SZ_16M,
158 .end = SZ_32M + SZ_32M - SZ_256K - 1,
159 .flags = IORESOURCE_MEM,
160 }
161};
162
163static struct platform_device acs5k_device_nor = {
164 .name = "physmap-flash",
165 .id = -1,
166 .num_resources = ARRAY_SIZE(acs5k_nor_resource),
167 .resource = acs5k_nor_resource,
168 .dev = {
169 .platform_data = &acs5k_nor_pdata,
170 },
171};
172
173static void __init acs5k_register_nor(void)
174{
175 int ret;
176
177 if (acs5k_nor_partitions[0].mask_flags == 0)
178 printk(KERN_WARNING "Warning: Unprotecting bootloader and configuration partition\n");
179
180 ret = platform_device_register(&acs5k_device_nor);
181 if (ret < 0)
182 printk(KERN_ERR "failed to register physmap-flash device\n");
183}
184
185static int __init acs5k_protection_setup(char *s)
186{
187 /* We can't allocate anything here but we should be able
188 * to trivially parse s and decide if we can protect the
189 * bootloader partition or not
190 */
191 if (strcmp(s, "no") == 0)
192 acs5k_nor_partitions[0].mask_flags = 0;
193
194 return 1;
195}
196
197__setup("protect_bootloader=", acs5k_protection_setup);
198
199static void __init acs5k_init_gpio(void)
200{
201 int i;
202
203 ks8695_register_gpios();
204 for (i = 0; i < 4; ++i)
205 gpio_request(i, "ACS5K IRQ");
206 gpio_request(7, "ACS5K KS_FRDY");
207 for (i = 8; i < 16; ++i)
208 gpio_request(i, "ACS5K Unused");
209
210 gpio_request(3, "ACS5K CAN Control");
211 gpio_request(6, "ACS5K Heartbeat");
212 gpio_direction_output(3, 1); /* Default CAN_RESET high */
213 gpio_direction_output(6, 0); /* Default KS8695_ACTIVE low */
214 gpio_export(3, 0); /* export CAN_RESET as output only */
215 gpio_export(6, 0); /* export KS8695_ACTIVE as output only */
216}
217
218static void __init acs5k_init(void)
219{
220 acs5k_init_gpio();
221
222 /* Network device */
223 ks8695_add_device_lan(); /* eth0 = LAN */
224 ks8695_add_device_wan(); /* ethX = WAN */
225
226 /* NOR devices */
227 acs5k_register_nor();
228
229 /* I2C bus */
230 acs5k_i2c_init();
231}
232
233MACHINE_START(ACS5K, "Brivo Systems LLC ACS-5000 Master board")
234 /* Maintainer: Simtec Electronics. */
235 .atag_offset = 0x100,
236 .map_io = ks8695_map_io,
237 .init_irq = ks8695_init_irq,
238 .init_machine = acs5k_init,
239 .init_time = ks8695_timer_init,
240 .restart = ks8695_restart,
241MACHINE_END