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