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 <prom.h>
  37. const char *get_system_type(void)
  38. {
  39. return "GPR";
  40. }
  41. void __init prom_init(void)
  42. {
  43. unsigned char *memsize_str;
  44. unsigned long memsize;
  45. prom_argc = fw_arg0;
  46. prom_argv = (char **)fw_arg1;
  47. prom_envp = (char **)fw_arg2;
  48. prom_init_cmdline();
  49. memsize_str = prom_getenv("memsize");
  50. if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
  51. memsize = 0x04000000;
  52. add_memory_region(0, memsize, BOOT_MEM_RAM);
  53. }
  54. void prom_putchar(unsigned char c)
  55. {
  56. alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
  57. }
  58. static void gpr_reset(char *c)
  59. {
  60. /* switch System-LED to orange (red# and green# on) */
  61. alchemy_gpio_direction_output(4, 0);
  62. alchemy_gpio_direction_output(5, 0);
  63. /* trigger watchdog to reset board in 200ms */
  64. printk(KERN_EMERG "Triggering watchdog soft reset...\n");
  65. raw_local_irq_disable();
  66. alchemy_gpio_direction_output(1, 0);
  67. udelay(1);
  68. alchemy_gpio_set_value(1, 1);
  69. while (1)
  70. cpu_wait();
  71. }
  72. static void gpr_power_off(void)
  73. {
  74. while (1)
  75. cpu_wait();
  76. }
  77. void __init board_setup(void)
  78. {
  79. printk(KERN_INFO "Trapeze ITS GPR board\n");
  80. pm_power_off = gpr_power_off;
  81. _machine_halt = gpr_power_off;
  82. _machine_restart = gpr_reset;
  83. /* Enable UART1/3 */
  84. alchemy_uart_enable(AU1000_UART3_PHYS_ADDR);
  85. alchemy_uart_enable(AU1000_UART1_PHYS_ADDR);
  86. /* Take away Reset of UMTS-card */
  87. alchemy_gpio_direction_output(215, 1);
  88. }
  89. /*
  90. * Watchdog
  91. */
  92. static struct resource gpr_wdt_resource[] = {
  93. [0] = {
  94. .start = 1,
  95. .end = 1,
  96. .name = "gpr-adm6320-wdt",
  97. .flags = IORESOURCE_IRQ,
  98. }
  99. };
  100. static struct platform_device gpr_wdt_device = {
  101. .name = "adm6320-wdt",
  102. .id = 0,
  103. .num_resources = ARRAY_SIZE(gpr_wdt_resource),
  104. .resource = gpr_wdt_resource,
  105. };
  106. /*
  107. * FLASH
  108. *
  109. * 0x00000000-0x00200000 : "kernel"
  110. * 0x00200000-0x00a00000 : "rootfs"
  111. * 0x01d00000-0x01f00000 : "config"
  112. * 0x01c00000-0x01d00000 : "yamon"
  113. * 0x01d00000-0x01d40000 : "yamon env vars"
  114. * 0x00000000-0x00a00000 : "kernel+rootfs"
  115. */
  116. static struct mtd_partition gpr_mtd_partitions[] = {
  117. {
  118. .name = "kernel",
  119. .size = 0x00200000,
  120. .offset = 0,
  121. },
  122. {
  123. .name = "rootfs",
  124. .size = 0x00800000,
  125. .offset = MTDPART_OFS_APPEND,
  126. .mask_flags = MTD_WRITEABLE,
  127. },
  128. {
  129. .name = "config",
  130. .size = 0x00200000,
  131. .offset = 0x01d00000,
  132. },
  133. {
  134. .name = "yamon",
  135. .size = 0x00100000,
  136. .offset = 0x01c00000,
  137. },
  138. {
  139. .name = "yamon env vars",
  140. .size = 0x00040000,
  141. .offset = MTDPART_OFS_APPEND,
  142. },
  143. {
  144. .name = "kernel+rootfs",
  145. .size = 0x00a00000,
  146. .offset = 0,
  147. },
  148. };
  149. static struct physmap_flash_data gpr_flash_data = {
  150. .width = 4,
  151. .nr_parts = ARRAY_SIZE(gpr_mtd_partitions),
  152. .parts = gpr_mtd_partitions,
  153. };
  154. static struct resource gpr_mtd_resource = {
  155. .start = 0x1e000000,
  156. .end = 0x1fffffff,
  157. .flags = IORESOURCE_MEM,
  158. };
  159. static struct platform_device gpr_mtd_device = {
  160. .name = "physmap-flash",
  161. .dev = {
  162. .platform_data = &gpr_flash_data,
  163. },
  164. .num_resources = 1,
  165. .resource = &gpr_mtd_resource,
  166. };
  167. /*
  168. * LEDs
  169. */
  170. static struct gpio_led gpr_gpio_leds[] = {
  171. { /* green */
  172. .name = "gpr:green",
  173. .gpio = 4,
  174. .active_low = 1,
  175. },
  176. { /* red */
  177. .name = "gpr:red",
  178. .gpio = 5,
  179. .active_low = 1,
  180. }
  181. };
  182. static struct gpio_led_platform_data gpr_led_data = {
  183. .num_leds = ARRAY_SIZE(gpr_gpio_leds),
  184. .leds = gpr_gpio_leds,
  185. };
  186. static struct platform_device gpr_led_devices = {
  187. .name = "leds-gpio",
  188. .id = -1,
  189. .dev = {
  190. .platform_data = &gpr_led_data,
  191. }
  192. };
  193. /*
  194. * I2C
  195. */
  196. static struct i2c_gpio_platform_data gpr_i2c_data = {
  197. .sda_pin = 209,
  198. .sda_is_open_drain = 1,
  199. .scl_pin = 210,
  200. .scl_is_open_drain = 1,
  201. .udelay = 2, /* ~100 kHz */
  202. .timeout = HZ,
  203. };
  204. static struct platform_device gpr_i2c_device = {
  205. .name = "i2c-gpio",
  206. .id = -1,
  207. .dev.platform_data = &gpr_i2c_data,
  208. };
  209. static struct i2c_board_info gpr_i2c_info[] __initdata = {
  210. {
  211. I2C_BOARD_INFO("lm83", 0x18),
  212. .type = "lm83"
  213. }
  214. };
  215. static struct resource alchemy_pci_host_res[] = {
  216. [0] = {
  217. .start = AU1500_PCI_PHYS_ADDR,
  218. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  219. .flags = IORESOURCE_MEM,
  220. },
  221. };
  222. static int gpr_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  223. {
  224. if ((slot == 0) && (pin == 1))
  225. return AU1550_PCI_INTA;
  226. else if ((slot == 0) && (pin == 2))
  227. return AU1550_PCI_INTB;
  228. return 0xff;
  229. }
  230. static struct alchemy_pci_platdata gpr_pci_pd = {
  231. .board_map_irq = gpr_map_pci_irq,
  232. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  233. PCI_CONFIG_CH |
  234. #if defined(__MIPSEB__)
  235. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  236. #else
  237. 0,
  238. #endif
  239. };
  240. static struct platform_device gpr_pci_host_dev = {
  241. .dev.platform_data = &gpr_pci_pd,
  242. .name = "alchemy-pci",
  243. .id = 0,
  244. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  245. .resource = alchemy_pci_host_res,
  246. };
  247. static struct platform_device *gpr_devices[] __initdata = {
  248. &gpr_wdt_device,
  249. &gpr_mtd_device,
  250. &gpr_i2c_device,
  251. &gpr_led_devices,
  252. };
  253. static int __init gpr_pci_init(void)
  254. {
  255. return platform_device_register(&gpr_pci_host_dev);
  256. }
  257. /* must be arch_initcall; MIPS PCI scans busses in a subsys_initcall */
  258. arch_initcall(gpr_pci_init);
  259. static int __init gpr_dev_init(void)
  260. {
  261. i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info));
  262. return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
  263. }
  264. device_initcall(gpr_dev_init);