em7210.c 4.9 KB

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