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