2f00217fa44e906605d2a2f041db5cbe7a8deafe
[sfrench/cifs-2.6.git] / arch / arm / mach-s3c24xx / mach-vr1000.c
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (c) 2003-2008 Simtec Electronics
4 //   Ben Dooks <ben@simtec.co.uk>
5 //
6 // Machine support for Thorcom VR1000 board. Designed for Thorcom by
7 // Simtec Electronics, http://www.simtec.co.uk/
8
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/list.h>
13 #include <linux/timer.h>
14 #include <linux/init.h>
15 #include <linux/gpio.h>
16 #include <linux/gpio/machine.h>
17 #include <linux/dm9000.h>
18 #include <linux/i2c.h>
19
20 #include <linux/serial.h>
21 #include <linux/tty.h>
22 #include <linux/serial_8250.h>
23 #include <linux/serial_reg.h>
24 #include <linux/serial_s3c.h>
25 #include <linux/io.h>
26
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29 #include <asm/mach/irq.h>
30
31 #include <asm/irq.h>
32 #include <asm/mach-types.h>
33
34 #include <linux/platform_data/leds-s3c24xx.h>
35 #include <linux/platform_data/i2c-s3c2410.h>
36 #include <linux/platform_data/asoc-s3c24xx_simtec.h>
37
38 #include <mach/hardware.h>
39 #include <mach/regs-gpio.h>
40 #include <mach/gpio-samsung.h>
41
42 #include <plat/cpu.h>
43 #include <plat/devs.h>
44 #include <plat/gpio-cfg.h>
45
46 #include "bast.h"
47 #include "common.h"
48 #include "simtec.h"
49 #include "vr1000.h"
50
51 /* macros for virtual address mods for the io space entries */
52 #define VA_C5(item) ((unsigned long)(item) + BAST_VAM_CS5)
53 #define VA_C4(item) ((unsigned long)(item) + BAST_VAM_CS4)
54 #define VA_C3(item) ((unsigned long)(item) + BAST_VAM_CS3)
55 #define VA_C2(item) ((unsigned long)(item) + BAST_VAM_CS2)
56
57 /* macros to modify the physical addresses for io space */
58
59 #define PA_CS2(item) (__phys_to_pfn((item) + S3C2410_CS2))
60 #define PA_CS3(item) (__phys_to_pfn((item) + S3C2410_CS3))
61 #define PA_CS4(item) (__phys_to_pfn((item) + S3C2410_CS4))
62 #define PA_CS5(item) (__phys_to_pfn((item) + S3C2410_CS5))
63
64 static struct map_desc vr1000_iodesc[] __initdata = {
65   /* ISA IO areas */
66   {
67           .virtual      = (u32)S3C24XX_VA_ISA_BYTE,
68           .pfn          = PA_CS2(BAST_PA_ISAIO),
69           .length       = SZ_16M,
70           .type         = MT_DEVICE,
71   }, {
72           .virtual      = (u32)S3C24XX_VA_ISA_WORD,
73           .pfn          = PA_CS3(BAST_PA_ISAIO),
74           .length       = SZ_16M,
75           .type         = MT_DEVICE,
76   },
77
78   /*  CPLD control registers, and external interrupt controls */
79   {
80           .virtual      = (u32)VR1000_VA_CTRL1,
81           .pfn          = __phys_to_pfn(VR1000_PA_CTRL1),
82           .length       = SZ_1M,
83           .type         = MT_DEVICE,
84   }, {
85           .virtual      = (u32)VR1000_VA_CTRL2,
86           .pfn          = __phys_to_pfn(VR1000_PA_CTRL2),
87           .length       = SZ_1M,
88           .type         = MT_DEVICE,
89   }, {
90           .virtual      = (u32)VR1000_VA_CTRL3,
91           .pfn          = __phys_to_pfn(VR1000_PA_CTRL3),
92           .length       = SZ_1M,
93           .type         = MT_DEVICE,
94   }, {
95           .virtual      = (u32)VR1000_VA_CTRL4,
96           .pfn          = __phys_to_pfn(VR1000_PA_CTRL4),
97           .length       = SZ_1M,
98           .type         = MT_DEVICE,
99   },
100 };
101
102 #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
103 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
104 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
105
106 static struct s3c2410_uartcfg vr1000_uartcfgs[] __initdata = {
107         [0] = {
108                 .hwport      = 0,
109                 .flags       = 0,
110                 .ucon        = UCON,
111                 .ulcon       = ULCON,
112                 .ufcon       = UFCON,
113         },
114         [1] = {
115                 .hwport      = 1,
116                 .flags       = 0,
117                 .ucon        = UCON,
118                 .ulcon       = ULCON,
119                 .ufcon       = UFCON,
120         },
121         /* port 2 is not actually used */
122         [2] = {
123                 .hwport      = 2,
124                 .flags       = 0,
125                 .ucon        = UCON,
126                 .ulcon       = ULCON,
127                 .ufcon       = UFCON,
128         }
129 };
130
131 /* definitions for the vr1000 extra 16550 serial ports */
132
133 #define VR1000_BAUDBASE (3692307)
134
135 #define VR1000_SERIAL_MAPBASE(x) (VR1000_PA_SERIAL + 0x80 + ((x) << 5))
136
137 static struct plat_serial8250_port serial_platform_data[] = {
138         [0] = {
139                 .mapbase        = VR1000_SERIAL_MAPBASE(0),
140                 .irq            = VR1000_IRQ_SERIAL + 0,
141                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
142                 .iotype         = UPIO_MEM,
143                 .regshift       = 0,
144                 .uartclk        = VR1000_BAUDBASE,
145         },
146         [1] = {
147                 .mapbase        = VR1000_SERIAL_MAPBASE(1),
148                 .irq            = VR1000_IRQ_SERIAL + 1,
149                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
150                 .iotype         = UPIO_MEM,
151                 .regshift       = 0,
152                 .uartclk        = VR1000_BAUDBASE,
153         },
154         [2] = {
155                 .mapbase        = VR1000_SERIAL_MAPBASE(2),
156                 .irq            = VR1000_IRQ_SERIAL + 2,
157                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
158                 .iotype         = UPIO_MEM,
159                 .regshift       = 0,
160                 .uartclk        = VR1000_BAUDBASE,
161         },
162         [3] = {
163                 .mapbase        = VR1000_SERIAL_MAPBASE(3),
164                 .irq            = VR1000_IRQ_SERIAL + 3,
165                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
166                 .iotype         = UPIO_MEM,
167                 .regshift       = 0,
168                 .uartclk        = VR1000_BAUDBASE,
169         },
170         { },
171 };
172
173 static struct platform_device serial_device = {
174         .name                   = "serial8250",
175         .id                     = PLAT8250_DEV_PLATFORM,
176         .dev                    = {
177                 .platform_data  = serial_platform_data,
178         },
179 };
180
181 /* DM9000 ethernet devices */
182
183 static struct resource vr1000_dm9k0_resource[] = {
184         [0] = DEFINE_RES_MEM(S3C2410_CS5 + VR1000_PA_DM9000, 4),
185         [1] = DEFINE_RES_MEM(S3C2410_CS5 + VR1000_PA_DM9000 + 0x40, 0x40),
186         [2] = DEFINE_RES_NAMED(VR1000_IRQ_DM9000A, 1, NULL, IORESOURCE_IRQ \
187                                                 | IORESOURCE_IRQ_HIGHLEVEL),
188 };
189
190 static struct resource vr1000_dm9k1_resource[] = {
191         [0] = DEFINE_RES_MEM(S3C2410_CS5 + VR1000_PA_DM9000 + 0x80, 4),
192         [1] = DEFINE_RES_MEM(S3C2410_CS5 + VR1000_PA_DM9000 + 0xC0, 0x40),
193         [2] = DEFINE_RES_NAMED(VR1000_IRQ_DM9000N, 1, NULL, IORESOURCE_IRQ \
194                                                 | IORESOURCE_IRQ_HIGHLEVEL),
195 };
196
197 /* for the moment we limit ourselves to 16bit IO until some
198  * better IO routines can be written and tested
199 */
200
201 static struct dm9000_plat_data vr1000_dm9k_platdata = {
202         .flags          = DM9000_PLATF_16BITONLY,
203 };
204
205 static struct platform_device vr1000_dm9k0 = {
206         .name           = "dm9000",
207         .id             = 0,
208         .num_resources  = ARRAY_SIZE(vr1000_dm9k0_resource),
209         .resource       = vr1000_dm9k0_resource,
210         .dev            = {
211                 .platform_data = &vr1000_dm9k_platdata,
212         }
213 };
214
215 static struct platform_device vr1000_dm9k1 = {
216         .name           = "dm9000",
217         .id             = 1,
218         .num_resources  = ARRAY_SIZE(vr1000_dm9k1_resource),
219         .resource       = vr1000_dm9k1_resource,
220         .dev            = {
221                 .platform_data = &vr1000_dm9k_platdata,
222         }
223 };
224
225 /* LEDS */
226
227 static struct gpiod_lookup_table vr1000_led1_gpio_table = {
228         .dev_id = "s3c24xx_led.1",
229         .table = {
230                 GPIO_LOOKUP("GPB", 0, NULL, GPIO_ACTIVE_HIGH),
231                 { },
232         },
233 };
234
235 static struct gpiod_lookup_table vr1000_led2_gpio_table = {
236         .dev_id = "s3c24xx_led.2",
237         .table = {
238                 GPIO_LOOKUP("GPB", 1, NULL, GPIO_ACTIVE_HIGH),
239                 { },
240         },
241 };
242
243 static struct gpiod_lookup_table vr1000_led3_gpio_table = {
244         .dev_id = "s3c24xx_led.3",
245         .table = {
246                 GPIO_LOOKUP("GPB", 2, NULL, GPIO_ACTIVE_HIGH),
247                 { },
248         },
249 };
250
251 static struct s3c24xx_led_platdata vr1000_led1_pdata = {
252         .name           = "led1",
253         .def_trigger    = "",
254 };
255
256 static struct s3c24xx_led_platdata vr1000_led2_pdata = {
257         .name           = "led2",
258         .def_trigger    = "",
259 };
260
261 static struct s3c24xx_led_platdata vr1000_led3_pdata = {
262         .name           = "led3",
263         .def_trigger    = "",
264 };
265
266 static struct platform_device vr1000_led1 = {
267         .name           = "s3c24xx_led",
268         .id             = 1,
269         .dev            = {
270                 .platform_data  = &vr1000_led1_pdata,
271         },
272 };
273
274 static struct platform_device vr1000_led2 = {
275         .name           = "s3c24xx_led",
276         .id             = 2,
277         .dev            = {
278                 .platform_data  = &vr1000_led2_pdata,
279         },
280 };
281
282 static struct platform_device vr1000_led3 = {
283         .name           = "s3c24xx_led",
284         .id             = 3,
285         .dev            = {
286                 .platform_data  = &vr1000_led3_pdata,
287         },
288 };
289
290 /* I2C devices. */
291
292 static struct i2c_board_info vr1000_i2c_devs[] __initdata = {
293         {
294                 I2C_BOARD_INFO("tlv320aic23", 0x1a),
295         }, {
296                 I2C_BOARD_INFO("tmp101", 0x48),
297         }, {
298                 I2C_BOARD_INFO("m41st87", 0x68),
299         },
300 };
301
302 /* devices for this board */
303
304 static struct platform_device *vr1000_devices[] __initdata = {
305         &s3c2410_device_dclk,
306         &s3c_device_ohci,
307         &s3c_device_lcd,
308         &s3c_device_wdt,
309         &s3c_device_i2c0,
310         &s3c_device_adc,
311         &serial_device,
312         &vr1000_dm9k0,
313         &vr1000_dm9k1,
314         &vr1000_led1,
315         &vr1000_led2,
316         &vr1000_led3,
317 };
318
319 static void vr1000_power_off(void)
320 {
321         gpio_direction_output(S3C2410_GPB(9), 1);
322 }
323
324 static void __init vr1000_map_io(void)
325 {
326         pm_power_off = vr1000_power_off;
327
328         s3c24xx_init_io(vr1000_iodesc, ARRAY_SIZE(vr1000_iodesc));
329         s3c24xx_init_uarts(vr1000_uartcfgs, ARRAY_SIZE(vr1000_uartcfgs));
330         samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
331 }
332
333 static void __init vr1000_init_time(void)
334 {
335         s3c2410_init_clocks(12000000);
336         samsung_timer_init();
337 }
338
339 static void __init vr1000_init(void)
340 {
341         s3c_i2c0_set_platdata(NULL);
342
343         /* Disable pull-up on LED lines and register GPIO lookups */
344         s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
345         s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_NONE);
346         s3c_gpio_setpull(S3C2410_GPB(2), S3C_GPIO_PULL_NONE);
347         gpiod_add_lookup_table(&vr1000_led1_gpio_table);
348         gpiod_add_lookup_table(&vr1000_led2_gpio_table);
349         gpiod_add_lookup_table(&vr1000_led3_gpio_table);
350
351         platform_add_devices(vr1000_devices, ARRAY_SIZE(vr1000_devices));
352
353         i2c_register_board_info(0, vr1000_i2c_devs,
354                                 ARRAY_SIZE(vr1000_i2c_devs));
355
356         nor_simtec_init();
357         simtec_audio_add(NULL, true, NULL);
358
359         WARN_ON(gpio_request(S3C2410_GPB(9), "power off"));
360 }
361
362 MACHINE_START(VR1000, "Thorcom-VR1000")
363         /* Maintainer: Ben Dooks <ben@simtec.co.uk> */
364         .atag_offset    = 0x100,
365         .map_io         = vr1000_map_io,
366         .init_machine   = vr1000_init,
367         .init_irq       = s3c2410_init_irq,
368         .init_time      = vr1000_init_time,
369 MACHINE_END