board-gpr.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * GPR board platform device registration (Au1550)
  3. *
  4. * Copyright (C) 2010 Wolfgang Grandegger <wg@denx.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/delay.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/kernel.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pm.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/mtd/physmap.h>
  28. #include <linux/leds.h>
  29. #include <linux/gpio.h>
  30. #include <linux/i2c.h>
  31. #include <linux/i2c-gpio.h>
  32. #include <asm/bootinfo.h>
  33. #include <asm/idle.h>
  34. #include <asm/reboot.h>
  35. #include <asm/mach-au1x00/au1000.h>
  36. #include <asm/mach-au1x00/gpio-au1000.h>
  37. #include <prom.h>
  38. const char *get_system_type(void)
  39. {
  40. return "GPR";
  41. }
  42. void __init prom_init(void)
  43. {
  44. unsigned char *memsize_str;
  45. unsigned long memsize;
  46. prom_argc = fw_arg0;
  47. prom_argv = (char **)fw_arg1;
  48. prom_envp = (char **)fw_arg2;
  49. prom_init_cmdline();
  50. memsize_str = prom_getenv("memsize");
  51. if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
  52. memsize = 0x04000000;
  53. add_memory_region(0, memsize, BOOT_MEM_RAM);
  54. }
  55. void prom_putchar(unsigned char c)
  56. {
  57. alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
  58. }
  59. static void gpr_reset(char *c)
  60. {
  61. /* switch System-LED to orange (red# and green# on) */
  62. alchemy_gpio_direction_output(4, 0);
  63. alchemy_gpio_direction_output(5, 0);
  64. /* trigger watchdog to reset board in 200ms */
  65. printk(KERN_EMERG "Triggering watchdog soft reset...\n");
  66. raw_local_irq_disable();
  67. alchemy_gpio_direction_output(1, 0);
  68. udelay(1);
  69. alchemy_gpio_set_value(1, 1);
  70. while (1)
  71. cpu_wait();
  72. }
  73. static void gpr_power_off(void)
  74. {
  75. while (1)
  76. cpu_wait();
  77. }
  78. void __init board_setup(void)
  79. {
  80. printk(KERN_INFO "Trapeze ITS GPR board\n");
  81. pm_power_off = gpr_power_off;
  82. _machine_halt = gpr_power_off;
  83. _machine_restart = gpr_reset;
  84. /* Enable UART1/3 */
  85. alchemy_uart_enable(AU1000_UART3_PHYS_ADDR);
  86. alchemy_uart_enable(AU1000_UART1_PHYS_ADDR);
  87. /* Take away Reset of UMTS-card */
  88. alchemy_gpio_direction_output(215, 1);
  89. }
  90. /*
  91. * Watchdog
  92. */
  93. static struct resource gpr_wdt_resource[] = {
  94. [0] = {
  95. .start = 1,
  96. .end = 1,
  97. .name = "gpr-adm6320-wdt",
  98. .flags = IORESOURCE_IRQ,
  99. }
  100. };
  101. static struct platform_device gpr_wdt_device = {
  102. .name = "adm6320-wdt",
  103. .id = 0,
  104. .num_resources = ARRAY_SIZE(gpr_wdt_resource),
  105. .resource = gpr_wdt_resource,
  106. };
  107. /*
  108. * FLASH
  109. *
  110. * 0x00000000-0x00200000 : "kernel"
  111. * 0x00200000-0x00a00000 : "rootfs"
  112. * 0x01d00000-0x01f00000 : "config"
  113. * 0x01c00000-0x01d00000 : "yamon"
  114. * 0x01d00000-0x01d40000 : "yamon env vars"
  115. * 0x00000000-0x00a00000 : "kernel+rootfs"
  116. */
  117. static struct mtd_partition gpr_mtd_partitions[] = {
  118. {
  119. .name = "kernel",
  120. .size = 0x00200000,
  121. .offset = 0,
  122. },
  123. {
  124. .name = "rootfs",
  125. .size = 0x00800000,
  126. .offset = MTDPART_OFS_APPEND,
  127. .mask_flags = MTD_WRITEABLE,
  128. },
  129. {
  130. .name = "config",
  131. .size = 0x00200000,
  132. .offset = 0x01d00000,
  133. },
  134. {
  135. .name = "yamon",
  136. .size = 0x00100000,
  137. .offset = 0x01c00000,
  138. },
  139. {
  140. .name = "yamon env vars",
  141. .size = 0x00040000,
  142. .offset = MTDPART_OFS_APPEND,
  143. },
  144. {
  145. .name = "kernel+rootfs",
  146. .size = 0x00a00000,
  147. .offset = 0,
  148. },
  149. };
  150. static struct physmap_flash_data gpr_flash_data = {
  151. .width = 4,
  152. .nr_parts = ARRAY_SIZE(gpr_mtd_partitions),
  153. .parts = gpr_mtd_partitions,
  154. };
  155. static struct resource gpr_mtd_resource = {
  156. .start = 0x1e000000,
  157. .end = 0x1fffffff,
  158. .flags = IORESOURCE_MEM,
  159. };
  160. static struct platform_device gpr_mtd_device = {
  161. .name = "physmap-flash",
  162. .dev = {
  163. .platform_data = &gpr_flash_data,
  164. },
  165. .num_resources = 1,
  166. .resource = &gpr_mtd_resource,
  167. };
  168. /*
  169. * LEDs
  170. */
  171. static struct gpio_led gpr_gpio_leds[] = {
  172. { /* green */
  173. .name = "gpr:green",
  174. .gpio = 4,
  175. .active_low = 1,
  176. },
  177. { /* red */
  178. .name = "gpr:red",
  179. .gpio = 5,
  180. .active_low = 1,
  181. }
  182. };
  183. static struct gpio_led_platform_data gpr_led_data = {
  184. .num_leds = ARRAY_SIZE(gpr_gpio_leds),
  185. .leds = gpr_gpio_leds,
  186. };
  187. static struct platform_device gpr_led_devices = {
  188. .name = "leds-gpio",
  189. .id = -1,
  190. .dev = {
  191. .platform_data = &gpr_led_data,
  192. }
  193. };
  194. /*
  195. * I2C
  196. */
  197. static struct i2c_gpio_platform_data gpr_i2c_data = {
  198. .sda_pin = 209,
  199. .sda_is_open_drain = 1,
  200. .scl_pin = 210,
  201. .scl_is_open_drain = 1,
  202. .udelay = 2, /* ~100 kHz */
  203. .timeout = HZ,
  204. };
  205. static struct platform_device gpr_i2c_device = {
  206. .name = "i2c-gpio",
  207. .id = -1,
  208. .dev.platform_data = &gpr_i2c_data,
  209. };
  210. static struct i2c_board_info gpr_i2c_info[] __initdata = {
  211. {
  212. I2C_BOARD_INFO("lm83", 0x18),
  213. .type = "lm83"
  214. }
  215. };
  216. static struct resource alchemy_pci_host_res[] = {
  217. [0] = {
  218. .start = AU1500_PCI_PHYS_ADDR,
  219. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  220. .flags = IORESOURCE_MEM,
  221. },
  222. };
  223. static int gpr_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  224. {
  225. if ((slot == 0) && (pin == 1))
  226. return AU1550_PCI_INTA;
  227. else if ((slot == 0) && (pin == 2))
  228. return AU1550_PCI_INTB;
  229. return 0xff;
  230. }
  231. static struct alchemy_pci_platdata gpr_pci_pd = {
  232. .board_map_irq = gpr_map_pci_irq,
  233. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  234. PCI_CONFIG_CH |
  235. #if defined(__MIPSEB__)
  236. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  237. #else
  238. 0,
  239. #endif
  240. };
  241. static struct platform_device gpr_pci_host_dev = {
  242. .dev.platform_data = &gpr_pci_pd,
  243. .name = "alchemy-pci",
  244. .id = 0,
  245. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  246. .resource = alchemy_pci_host_res,
  247. };
  248. static struct platform_device *gpr_devices[] __initdata = {
  249. &gpr_wdt_device,
  250. &gpr_mtd_device,
  251. &gpr_i2c_device,
  252. &gpr_led_devices,
  253. };
  254. static int __init gpr_pci_init(void)
  255. {
  256. return platform_device_register(&gpr_pci_host_dev);
  257. }
  258. /* must be arch_initcall; MIPS PCI scans busses in a subsys_initcall */
  259. arch_initcall(gpr_pci_init);
  260. static int __init gpr_dev_init(void)
  261. {
  262. i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info));
  263. return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
  264. }
  265. device_initcall(gpr_dev_init);