board-gpr.c 6.4 KB

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