dns323-setup.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * arch/arm/mach-orion/dns323-setup.c
  3. *
  4. * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/pci.h>
  16. #include <linux/irq.h>
  17. #include <linux/mtd/physmap.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/leds.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/i2c.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/gpio.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/pci.h>
  27. #include <asm/arch/orion.h>
  28. #include <asm/arch/platform.h>
  29. #include "common.h"
  30. #define DNS323_GPIO_LED_RIGHT_AMBER 1
  31. #define DNS323_GPIO_LED_LEFT_AMBER 2
  32. #define DNS323_GPIO_LED_POWER 5
  33. #define DNS323_GPIO_OVERTEMP 6
  34. #define DNS323_GPIO_RTC 7
  35. #define DNS323_GPIO_POWER_OFF 8
  36. #define DNS323_GPIO_KEY_POWER 9
  37. #define DNS323_GPIO_KEY_RESET 10
  38. /****************************************************************************
  39. * PCI setup
  40. */
  41. static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  42. {
  43. /* PCI-E */
  44. if (dev->bus->number == orion_pcie_local_bus_nr())
  45. return IRQ_ORION_PCIE0_INT;
  46. pr_err("%s: requested mapping for unknown bus\n", __func__);
  47. return -1;
  48. }
  49. static struct hw_pci dns323_pci __initdata = {
  50. .nr_controllers = 1,
  51. .swizzle = pci_std_swizzle,
  52. .setup = orion_pci_sys_setup,
  53. .scan = orion_pci_sys_scan_bus,
  54. .map_irq = dns323_pci_map_irq,
  55. };
  56. static int __init dns323_pci_init(void)
  57. {
  58. if (machine_is_dns323())
  59. pci_common_init(&dns323_pci);
  60. return 0;
  61. }
  62. subsys_initcall(dns323_pci_init);
  63. /****************************************************************************
  64. * Ethernet
  65. */
  66. static struct mv643xx_eth_platform_data dns323_eth_data = {
  67. .phy_addr = 8,
  68. .force_phy_addr = 1,
  69. };
  70. /****************************************************************************
  71. * 8MiB NOR flash (Spansion S29GL064M90TFIR4)
  72. *
  73. * Layout as used by D-Link:
  74. * 0x00000000-0x00010000 : "MTD1"
  75. * 0x00010000-0x00020000 : "MTD2"
  76. * 0x00020000-0x001a0000 : "Linux Kernel"
  77. * 0x001a0000-0x007d0000 : "File System"
  78. * 0x007d0000-0x00800000 : "u-boot"
  79. */
  80. #define DNS323_NOR_BOOT_BASE 0xf4000000
  81. #define DNS323_NOR_BOOT_SIZE SZ_8M
  82. static struct mtd_partition dns323_partitions[] = {
  83. {
  84. .name = "MTD1",
  85. .size = 0x00010000,
  86. .offset = 0,
  87. }, {
  88. .name = "MTD2",
  89. .size = 0x00010000,
  90. .offset = 0x00010000,
  91. }, {
  92. .name = "Linux Kernel",
  93. .size = 0x00180000,
  94. .offset = 0x00020000,
  95. }, {
  96. .name = "File System",
  97. .size = 0x00630000,
  98. .offset = 0x001A0000,
  99. }, {
  100. .name = "u-boot",
  101. .size = 0x00030000,
  102. .offset = 0x007d0000,
  103. }
  104. };
  105. static struct physmap_flash_data dns323_nor_flash_data = {
  106. .width = 1,
  107. .parts = dns323_partitions,
  108. .nr_parts = ARRAY_SIZE(dns323_partitions)
  109. };
  110. static struct resource dns323_nor_flash_resource = {
  111. .flags = IORESOURCE_MEM,
  112. .start = DNS323_NOR_BOOT_BASE,
  113. .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1,
  114. };
  115. static struct platform_device dns323_nor_flash = {
  116. .name = "physmap-flash",
  117. .id = 0,
  118. .dev = { .platform_data = &dns323_nor_flash_data, },
  119. .resource = &dns323_nor_flash_resource,
  120. .num_resources = 1,
  121. };
  122. /****************************************************************************
  123. * GPIO LEDs (simple - doesn't use hardware blinking support)
  124. */
  125. static struct gpio_led dns323_leds[] = {
  126. {
  127. .name = "power:blue",
  128. .gpio = DNS323_GPIO_LED_POWER,
  129. .active_low = 1,
  130. }, {
  131. .name = "right:amber",
  132. .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
  133. .active_low = 1,
  134. }, {
  135. .name = "left:amber",
  136. .gpio = DNS323_GPIO_LED_LEFT_AMBER,
  137. .active_low = 1,
  138. },
  139. };
  140. static struct gpio_led_platform_data dns323_led_data = {
  141. .num_leds = ARRAY_SIZE(dns323_leds),
  142. .leds = dns323_leds,
  143. };
  144. static struct platform_device dns323_gpio_leds = {
  145. .name = "leds-gpio",
  146. .id = -1,
  147. .dev = { .platform_data = &dns323_led_data, },
  148. };
  149. /****************************************************************************
  150. * GPIO Attached Keys
  151. */
  152. static struct gpio_keys_button dns323_buttons[] = {
  153. {
  154. .code = KEY_RESTART,
  155. .gpio = DNS323_GPIO_KEY_RESET,
  156. .desc = "Reset Button",
  157. .active_low = 1,
  158. },
  159. {
  160. .code = KEY_POWER,
  161. .gpio = DNS323_GPIO_KEY_POWER,
  162. .desc = "Power Button",
  163. .active_low = 1,
  164. }
  165. };
  166. static struct gpio_keys_platform_data dns323_button_data = {
  167. .buttons = dns323_buttons,
  168. .nbuttons = ARRAY_SIZE(dns323_buttons),
  169. };
  170. static struct platform_device dns323_button_device = {
  171. .name = "gpio-keys",
  172. .id = -1,
  173. .num_resources = 0,
  174. .dev = { .platform_data = &dns323_button_data, },
  175. };
  176. /****************************************************************************
  177. * General Setup
  178. */
  179. static struct platform_device *dns323_plat_devices[] __initdata = {
  180. &dns323_nor_flash,
  181. &dns323_gpio_leds,
  182. &dns323_button_device,
  183. };
  184. /*
  185. * On the DNS-323 the following devices are attached via I2C:
  186. *
  187. * i2c addr | chip | description
  188. * 0x3e | GMT G760Af | fan speed PWM controller
  189. * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
  190. * 0x68 | ST M41T80 | RTC w/ alarm
  191. */
  192. static struct i2c_board_info __initdata dns323_i2c_devices[] = {
  193. {
  194. I2C_BOARD_INFO("g760a", 0x3e),
  195. .type = "g760a",
  196. },
  197. #if 0
  198. /* this entry requires the new-style driver model lm75 driver,
  199. * for the meantime "insmod lm75.ko force_lm75=0,0x48" is needed */
  200. {
  201. I2C_BOARD_INFO("lm75", 0x48),
  202. .type = "g751",
  203. },
  204. #endif
  205. {
  206. I2C_BOARD_INFO("rtc-m41t80", 0x68),
  207. .type = "m41t80",
  208. }
  209. };
  210. /* DNS-323 specific power off method */
  211. static void dns323_power_off(void)
  212. {
  213. pr_info("%s: triggering power-off...\n", __func__);
  214. gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
  215. }
  216. static void __init dns323_init(void)
  217. {
  218. /* Setup basic Orion functions. Need to be called early. */
  219. orion_init();
  220. /* setup flash mapping
  221. * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
  222. */
  223. orion_setup_cpu_win(ORION_DEV_BOOT, DNS323_NOR_BOOT_BASE,
  224. DNS323_NOR_BOOT_SIZE, -1);
  225. /* DNS-323 has a Marvell 88X7042 SATA controller attached via PCIE
  226. *
  227. * Open a special address decode windows for the PCIE WA.
  228. */
  229. orion_write(ORION_REGS_VIRT_BASE | 0x20074, ORION_PCIE_WA_PHYS_BASE);
  230. orion_write(ORION_REGS_VIRT_BASE | 0x20070,
  231. (0x7941 | (((ORION_PCIE_WA_SIZE >> 16) - 1)) << 16));
  232. /* set MPP to 0 as D-Link's 2.6.12.6 kernel did */
  233. orion_write(MPP_0_7_CTRL, 0);
  234. orion_write(MPP_8_15_CTRL, 0);
  235. orion_write(MPP_16_19_CTRL, 0);
  236. orion_write(MPP_DEV_CTRL, 0);
  237. /* Define used GPIO pins
  238. GPIO Map:
  239. | 0 | | PEX_RST_OUT (not controlled by GPIO)
  240. | 1 | Out | right amber LED (= sata ch0 LED) (low-active)
  241. | 2 | Out | left amber LED (= sata ch1 LED) (low-active)
  242. | 3 | Out | //unknown//
  243. | 4 | Out | power button LED (low-active, together with pin #5)
  244. | 5 | Out | power button LED (low-active, together with pin #4)
  245. | 6 | In | GMT G751-2f overtemp. shutdown signal (low-active)
  246. | 7 | In | M41T80 nIRQ/OUT/SQW signal
  247. | 8 | Out | triggers power off (high-active)
  248. | 9 | In | power button switch (low-active)
  249. | 10 | In | reset button switch (low-active)
  250. | 11 | Out | //unknown//
  251. | 12 | Out | //unknown//
  252. | 13 | Out | //unknown//
  253. | 14 | Out | //unknown//
  254. | 15 | Out | //unknown//
  255. */
  256. orion_gpio_set_valid_pins(0x07f6);
  257. /* register dns323 specific power-off method */
  258. if ((gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0)
  259. || (gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0))
  260. pr_err("DNS323: failed to setup power-off GPIO\n");
  261. pm_power_off = dns323_power_off;
  262. /* register flash and other platform devices */
  263. platform_add_devices(dns323_plat_devices,
  264. ARRAY_SIZE(dns323_plat_devices));
  265. i2c_register_board_info(0, dns323_i2c_devices,
  266. ARRAY_SIZE(dns323_i2c_devices));
  267. orion_eth_init(&dns323_eth_data);
  268. }
  269. /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
  270. MACHINE_START(DNS323, "D-Link DNS-323")
  271. /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */
  272. .phys_io = ORION_REGS_PHYS_BASE,
  273. .io_pg_offst = ((ORION_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  274. .boot_params = 0x00000100,
  275. .init_machine = dns323_init,
  276. .map_io = orion_map_io,
  277. .init_irq = orion_init_irq,
  278. .timer = &orion_timer,
  279. MACHINE_END