1/*
2 * arch/arm/mach-iop32x/em7210.c
3 *
4 * Board support code for the Lanner EM7210 platforms.
5 *
6 * Based on arch/arm/mach-iop32x/iq31244.c file.
7 *
8 * Copyright (C) 2007 Arnaud Patard <arnaud.patard@rtp-net.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/mm.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/pci.h>
20#include <linux/pm.h>
21#include <linux/serial_core.h>
22#include <linux/serial_8250.h>
23#include <linux/mtd/physmap.h>
24#include <linux/platform_device.h>
25#include <linux/i2c.h>
26#include <linux/gpio.h>
27#include <mach/hardware.h>
28#include <linux/io.h>
29#include <linux/irq.h>
30#include <asm/mach/arch.h>
31#include <asm/mach/map.h>
32#include <asm/mach/pci.h>
33#include <asm/mach/time.h>
34#include <asm/mach-types.h>
35#include <mach/time.h>
36#include "gpio-iop32x.h"
37
38static void __init em7210_timer_init(void)
39{
40	/* http://www.kwaak.net/fotos/fotos-nas/slide_24.html */
41	/* 33.333 MHz crystal.                                */
42	iop_init_time(200000000);
43}
44
45/*
46 * EM7210 RTC
47 */
48static struct i2c_board_info __initdata em7210_i2c_devices[] = {
49	{
50		I2C_BOARD_INFO("rs5c372a", 0x32),
51	},
52};
53
54/*
55 * EM7210 I/O
56 */
57static struct map_desc em7210_io_desc[] __initdata = {
58	{	/* on-board devices */
59		.virtual	= IQ31244_UART,
60		.pfn		= __phys_to_pfn(IQ31244_UART),
61		.length		= 0x00100000,
62		.type		= MT_DEVICE,
63	},
64};
65
66void __init em7210_map_io(void)
67{
68	iop3xx_map_io();
69	iotable_init(em7210_io_desc, ARRAY_SIZE(em7210_io_desc));
70}
71
72
73/*
74 * EM7210 PCI
75 */
76#define INTA	IRQ_IOP32X_XINT0
77#define INTB	IRQ_IOP32X_XINT1
78#define INTC	IRQ_IOP32X_XINT2
79#define INTD	IRQ_IOP32X_XINT3
80
81static int __init
82em7210_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
83{
84	static int pci_irq_table[][4] = {
85		/*
86		 * PCI IDSEL/INTPIN->INTLINE
87		 * A       B       C       D
88		 */
89		{INTB, INTB, INTB, INTB}, /* console / uart */
90		{INTA, INTA, INTA, INTA}, /* 1st 82541      */
91		{INTD, INTD, INTD, INTD}, /* 2nd 82541      */
92		{INTC, INTC, INTC, INTC}, /* GD31244        */
93		{INTD, INTA, INTA, INTA}, /* mini-PCI       */
94		{INTD, INTC, INTA, INTA}, /* NEC USB        */
95	};
96
97	if (pin < 1 || pin > 4)
98		return -1;
99
100	return pci_irq_table[slot % 6][pin - 1];
101}
102
103static struct hw_pci em7210_pci __initdata = {
104	.nr_controllers = 1,
105	.ops		= &iop3xx_ops,
106	.setup		= iop3xx_pci_setup,
107	.preinit	= iop3xx_pci_preinit,
108	.map_irq	= em7210_pci_map_irq,
109};
110
111static int __init em7210_pci_init(void)
112{
113	if (machine_is_em7210())
114		pci_common_init(&em7210_pci);
115
116	return 0;
117}
118
119subsys_initcall(em7210_pci_init);
120
121
122/*
123 * EM7210 Flash
124 */
125static struct physmap_flash_data em7210_flash_data = {
126	.width		= 2,
127};
128
129static struct resource em7210_flash_resource = {
130	.start		= 0xf0000000,
131	.end		= 0xf1ffffff,
132	.flags		= IORESOURCE_MEM,
133};
134
135static struct platform_device em7210_flash_device = {
136	.name		= "physmap-flash",
137	.id		= 0,
138	.dev		= {
139		.platform_data	= &em7210_flash_data,
140	},
141	.num_resources	= 1,
142	.resource	= &em7210_flash_resource,
143};
144
145
146/*
147 * EM7210 UART
148 * The physical address of the serial port is 0xfe800000,
149 * so it can be used for physical and virtual address.
150 */
151static struct plat_serial8250_port em7210_serial_port[] = {
152	{
153		.mapbase	= IQ31244_UART,
154		.membase	= (char *)IQ31244_UART,
155		.irq		= IRQ_IOP32X_XINT1,
156		.flags		= UPF_SKIP_TEST,
157		.iotype		= UPIO_MEM,
158		.regshift	= 0,
159		.uartclk	= 1843200,
160	},
161	{ },
162};
163
164static struct resource em7210_uart_resource = {
165	.start		= IQ31244_UART,
166	.end		= IQ31244_UART + 7,
167	.flags		= IORESOURCE_MEM,
168};
169
170static struct platform_device em7210_serial_device = {
171	.name		= "serial8250",
172	.id		= PLAT8250_DEV_PLATFORM,
173	.dev		= {
174		.platform_data		= em7210_serial_port,
175	},
176	.num_resources	= 1,
177	.resource	= &em7210_uart_resource,
178};
179
180#define EM7210_HARDWARE_POWER 0
181
182void em7210_power_off(void)
183{
184	int ret;
185
186	ret = gpio_direction_output(EM7210_HARDWARE_POWER, 1);
187	if (ret)
188		pr_crit("could not drive power off GPIO high\n");
189}
190
191static int __init em7210_request_gpios(void)
192{
193	int ret;
194
195	if (!machine_is_em7210())
196		return 0;
197
198	ret = gpio_request(EM7210_HARDWARE_POWER, "power");
199	if (ret) {
200		pr_err("could not request power off GPIO\n");
201		return 0;
202	}
203
204	pm_power_off = em7210_power_off;
205
206	return 0;
207}
208device_initcall(em7210_request_gpios);
209
210static void __init em7210_init_machine(void)
211{
212	register_iop32x_gpio();
213	platform_device_register(&em7210_serial_device);
214	platform_device_register(&iop3xx_i2c0_device);
215	platform_device_register(&iop3xx_i2c1_device);
216	platform_device_register(&em7210_flash_device);
217	platform_device_register(&iop3xx_dma_0_channel);
218	platform_device_register(&iop3xx_dma_1_channel);
219
220	i2c_register_board_info(0, em7210_i2c_devices,
221		ARRAY_SIZE(em7210_i2c_devices));
222}
223
224MACHINE_START(EM7210, "Lanner EM7210")
225	.atag_offset	= 0x100,
226	.map_io		= em7210_map_io,
227	.init_irq	= iop32x_init_irq,
228	.init_time	= em7210_timer_init,
229	.init_machine	= em7210_init_machine,
230	.restart	= iop3xx_restart,
231MACHINE_END
232