commandProcessing.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * arch/arm/mach-orion5x/dns323-setup.c
  3. *
  4. * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
  5. *
  6. * Support for HW Rev C1:
  7. *
  8. * Copyright (C) 2010 Benjamin Herrenschmidt <benh@kernel.crashing.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. */
  16. #include <linux/gpio.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/delay.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/pci.h>
  22. #include <linux/irq.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/mv643xx_eth.h>
  25. #include <linux/leds.h>
  26. #include <linux/gpio_keys.h>
  27. #include <linux/input.h>
  28. #include <linux/i2c.h>
  29. #include <linux/ata_platform.h>
  30. #include <linux/phy.h>
  31. #include <linux/marvell_phy.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/pci.h>
  35. #include <asm/system_info.h>
  36. #include <mach/orion5x.h>
  37. #include <plat/orion-gpio.h>
  38. #include "common.h"
  39. #include "mpp.h"
  40. /* Rev A1 and B1 */
  41. #define DNS323_GPIO_LED_RIGHT_AMBER 1
  42. #define DNS323_GPIO_LED_LEFT_AMBER 2
  43. #define DNS323_GPIO_SYSTEM_UP 3
  44. #define DNS323_GPIO_LED_POWER1 4
  45. #define DNS323_GPIO_LED_POWER2 5
  46. #define DNS323_GPIO_OVERTEMP 6
  47. #define DNS323_GPIO_RTC 7
  48. #define DNS323_GPIO_POWER_OFF 8
  49. #define DNS323_GPIO_KEY_POWER 9
  50. #define DNS323_GPIO_KEY_RESET 10
  51. /* Rev C1 */
  52. #define DNS323C_GPIO_KEY_POWER 1
  53. #define DNS323C_GPIO_POWER_OFF 2
  54. #define DNS323C_GPIO_LED_RIGHT_AMBER 8
  55. #define DNS323C_GPIO_LED_LEFT_AMBER 9
  56. #define DNS323C_GPIO_LED_POWER 17
  57. #define DNS323C_GPIO_FAN_BIT1 18
  58. #define DNS323C_GPIO_FAN_BIT0 19
  59. /* Exposed to userspace, do not change */
  60. enum {
  61. DNS323_REV_A1, /* 0 */
  62. DNS323_REV_B1, /* 1 */
  63. DNS323_REV_C1, /* 2 */
  64. };
  65. /****************************************************************************
  66. * PCI setup
  67. */
  68. static int __init dns323_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  69. {
  70. int irq;
  71. /*
  72. * Check for devices with hard-wired IRQs.
  73. */
  74. irq = orion5x_pci_map_irq(dev, slot, pin);
  75. if (irq != -1)
  76. return irq;
  77. return -1;
  78. }
  79. static struct hw_pci dns323_pci __initdata = {
  80. .nr_controllers = 2,
  81. .setup = orion5x_pci_sys_setup,
  82. .scan = orion5x_pci_sys_scan_bus,
  83. .map_irq = dns323_pci_map_irq,
  84. };
  85. static int __init dns323_pci_init(void)
  86. {
  87. /* Rev B1 and C1 doesn't really use its PCI bus, and initialising PCI
  88. * gets in the way of initialising the SATA controller.
  89. */
  90. if (machine_is_dns323() && system_rev == DNS323_REV_A1)
  91. pci_common_init(&dns323_pci);
  92. return 0;
  93. }
  94. subsys_initcall(dns323_pci_init);
  95. /****************************************************************************
  96. * 8MiB NOR flash (Spansion S29GL064M90TFIR4)
  97. *
  98. * Layout as used by D-Link:
  99. * 0x00000000-0x00010000 : "MTD1"
  100. * 0x00010000-0x00020000 : "MTD2"
  101. * 0x00020000-0x001a0000 : "Linux Kernel"
  102. * 0x001a0000-0x007d0000 : "File System"
  103. * 0x007d0000-0x00800000 : "u-boot"
  104. */
  105. #define DNS323_NOR_BOOT_BASE 0xf4000000
  106. #define DNS323_NOR_BOOT_SIZE SZ_8M
  107. static struct mtd_partition dns323_partitions[] = {
  108. {
  109. .name = "MTD1",
  110. .size = 0x00010000,
  111. .offset = 0,
  112. }, {
  113. .name = "MTD2",
  114. .size = 0x00010000,
  115. .offset = 0x00010000,
  116. }, {
  117. .name = "Linux Kernel",
  118. .size = 0x00180000,
  119. .offset = 0x00020000,
  120. }, {
  121. .name = "File System",
  122. .size = 0x00630000,
  123. .offset = 0x001A0000,
  124. }, {
  125. .name = "u-boot",
  126. .size = 0x00030000,
  127. .offset = 0x007d0000,
  128. },
  129. };
  130. static struct physmap_flash_data dns323_nor_flash_data = {
  131. .width = 1,
  132. .parts = dns323_partitions,
  133. .nr_parts = ARRAY_SIZE(dns323_partitions)
  134. };
  135. static struct resource dns323_nor_flash_resource = {
  136. .flags = IORESOURCE_MEM,
  137. .start = DNS323_NOR_BOOT_BASE,
  138. .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1,
  139. };
  140. static struct platform_device dns323_nor_flash = {
  141. .name = "physmap-flash",
  142. .id = 0,
  143. .dev = {
  144. .platform_data = &dns323_nor_flash_data,
  145. },
  146. .resource = &dns323_nor_flash_resource,
  147. .num_resources = 1,
  148. };
  149. /****************************************************************************
  150. * Ethernet
  151. */
  152. static struct mv643xx_eth_platform_data dns323_eth_data = {
  153. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  154. };
  155. /* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these
  156. * functions be kept somewhere?
  157. */
  158. static int __init dns323_parse_hex_nibble(char n)
  159. {
  160. if (n >= '0' && n <= '9')
  161. return n - '0';
  162. if (n >= 'A' && n <= 'F')
  163. return n - 'A' + 10;
  164. if (n >= 'a' && n <= 'f')
  165. return n - 'a' + 10;
  166. return -1;
  167. }
  168. static int __init dns323_parse_hex_byte(const char *b)
  169. {
  170. int hi;
  171. int lo;
  172. hi = dns323_parse_hex_nibble(b[0]);
  173. lo = dns323_parse_hex_nibble(b[1]);
  174. if (hi < 0 || lo < 0)
  175. return -1;
  176. return (hi << 4) | lo;
  177. }
  178. static int __init dns323_read_mac_addr(void)
  179. {
  180. u_int8_t addr[6];
  181. int i;
  182. char *mac_page;
  183. /* MAC address is stored as a regular ol' string in /dev/mtdblock4
  184. * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80).
  185. */
  186. mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024);
  187. if (!mac_page)
  188. return -ENOMEM;
  189. /* Sanity check the string we're looking at */
  190. for (i = 0; i < 5; i++) {
  191. if (*(mac_page + (i * 3) + 2) != ':') {
  192. goto error_fail;
  193. }
  194. }
  195. for (i = 0; i < 6; i++) {
  196. int byte;
  197. byte = dns323_parse_hex_byte(mac_page + (i * 3));
  198. if (byte < 0) {
  199. goto error_fail;
  200. }
  201. addr[i] = byte;
  202. }
  203. iounmap(mac_page);
  204. printk("DNS-323: Found ethernet MAC address: ");
  205. for (i = 0; i < 6; i++)
  206. printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
  207. memcpy(dns323_eth_data.mac_addr, addr, 6);
  208. return 0;
  209. error_fail:
  210. iounmap(mac_page);
  211. return -EINVAL;
  212. }
  213. /****************************************************************************
  214. * GPIO LEDs (simple - doesn't use hardware blinking support)
  215. */
  216. static struct gpio_led dns323ab_leds[] = {
  217. {
  218. .name = "power:blue",
  219. .gpio = DNS323_GPIO_LED_POWER2,
  220. .default_trigger = "default-on",
  221. }, {
  222. .name = "right:amber",
  223. .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
  224. .active_low = 1,
  225. }, {
  226. .name = "left:amber",
  227. .gpio = DNS323_GPIO_LED_LEFT_AMBER,
  228. .active_low = 1,
  229. },
  230. };
  231. static struct gpio_led dns323c_leds[] = {
  232. {
  233. .name = "power:blue",
  234. .gpio = DNS323C_GPIO_LED_POWER,
  235. .default_trigger = "timer",
  236. .active_low = 1,
  237. }, {
  238. .name = "right:amber",
  239. .gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
  240. .active_low = 1,
  241. }, {
  242. .name = "left:amber",
  243. .gpio = DNS323C_GPIO_LED_LEFT_AMBER,
  244. .active_low = 1,
  245. },
  246. };
  247. static struct gpio_led_platform_data dns323ab_led_data = {
  248. .num_leds = ARRAY_SIZE(dns323ab_leds),
  249. .leds = dns323ab_leds,
  250. .gpio_blink_set = orion_gpio_led_blink_set,
  251. };