mach-nbg460n.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Zyxel NBG 460N/550N/550NH board support
  3. *
  4. * Copyright (C) 2010 Michael Kurz <michi.kurz@googlemail.com>
  5. *
  6. * based on mach-tl-wr1043nd.c
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/i2c.h>
  14. #include <linux/i2c-algo-bit.h>
  15. #include <linux/i2c-gpio.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/rtl8366.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include "dev-eth.h"
  22. #include "dev-gpio-buttons.h"
  23. #include "dev-leds-gpio.h"
  24. #include "dev-m25p80.h"
  25. #include "dev-wmac.h"
  26. #include "machtypes.h"
  27. /* LEDs */
  28. #define NBG460N_GPIO_LED_WPS 3
  29. #define NBG460N_GPIO_LED_WAN 6
  30. #define NBG460N_GPIO_LED_POWER 14
  31. #define NBG460N_GPIO_LED_WLAN 15
  32. /* Buttons */
  33. #define NBG460N_GPIO_BTN_WPS 12
  34. #define NBG460N_GPIO_BTN_RESET 21
  35. #define NBG460N_KEYS_POLL_INTERVAL 20 /* msecs */
  36. #define NBG460N_KEYS_DEBOUNCE_INTERVAL (3 * NBG460N_KEYS_POLL_INTERVAL)
  37. /* RTC chip PCF8563 I2C interface */
  38. #define NBG460N_GPIO_PCF8563_SDA 8
  39. #define NBG460N_GPIO_PCF8563_SCK 7
  40. /* Switch configuration I2C interface */
  41. #define NBG460N_GPIO_RTL8366_SDA 16
  42. #define NBG460N_GPIO_RTL8366_SCK 18
  43. static struct mtd_partition nbg460n_partitions[] = {
  44. {
  45. .name = "Bootbase",
  46. .offset = 0,
  47. .size = 0x010000,
  48. .mask_flags = MTD_WRITEABLE,
  49. }, {
  50. .name = "U-Boot Config",
  51. .offset = 0x010000,
  52. .size = 0x030000,
  53. }, {
  54. .name = "U-Boot",
  55. .offset = 0x040000,
  56. .size = 0x030000,
  57. }, {
  58. .name = "linux",
  59. .offset = 0x070000,
  60. .size = 0x0e0000,
  61. }, {
  62. .name = "rootfs",
  63. .offset = 0x150000,
  64. .size = 0x2a0000,
  65. }, {
  66. .name = "CalibData",
  67. .offset = 0x3f0000,
  68. .size = 0x010000,
  69. .mask_flags = MTD_WRITEABLE,
  70. }, {
  71. .name = "firmware",
  72. .offset = 0x070000,
  73. .size = 0x380000,
  74. }
  75. };
  76. static struct flash_platform_data nbg460n_flash_data = {
  77. .parts = nbg460n_partitions,
  78. .nr_parts = ARRAY_SIZE(nbg460n_partitions),
  79. };
  80. static struct gpio_led nbg460n_leds_gpio[] __initdata = {
  81. {
  82. .name = "nbg460n:green:power",
  83. .gpio = NBG460N_GPIO_LED_POWER,
  84. .active_low = 0,
  85. .default_trigger = "default-on",
  86. }, {
  87. .name = "nbg460n:green:wps",
  88. .gpio = NBG460N_GPIO_LED_WPS,
  89. .active_low = 0,
  90. }, {
  91. .name = "nbg460n:green:wlan",
  92. .gpio = NBG460N_GPIO_LED_WLAN,
  93. .active_low = 0,
  94. }, {
  95. /* Not really for controlling the LED,
  96. when set low the LED blinks uncontrollable */
  97. .name = "nbg460n:green:wan",
  98. .gpio = NBG460N_GPIO_LED_WAN,
  99. .active_low = 0,
  100. }
  101. };
  102. static struct gpio_keys_button nbg460n_gpio_keys[] __initdata = {
  103. {
  104. .desc = "reset",
  105. .type = EV_KEY,
  106. .code = KEY_RESTART,
  107. .debounce_interval = NBG460N_KEYS_DEBOUNCE_INTERVAL,
  108. .gpio = NBG460N_GPIO_BTN_RESET,
  109. .active_low = 1,
  110. }, {
  111. .desc = "wps",
  112. .type = EV_KEY,
  113. .code = KEY_WPS_BUTTON,
  114. .debounce_interval = NBG460N_KEYS_DEBOUNCE_INTERVAL,
  115. .gpio = NBG460N_GPIO_BTN_WPS,
  116. .active_low = 1,
  117. }
  118. };
  119. static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
  120. .sda_pin = NBG460N_GPIO_PCF8563_SDA,
  121. .scl_pin = NBG460N_GPIO_PCF8563_SCK,
  122. .udelay = 10,
  123. };
  124. static struct platform_device nbg460n_i2c_device = {
  125. .name = "i2c-gpio",
  126. .id = -1,
  127. .num_resources = 0,
  128. .resource = NULL,
  129. .dev = {
  130. .platform_data = &nbg460n_i2c_device_platdata,
  131. },
  132. };
  133. static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
  134. {
  135. I2C_BOARD_INFO("pcf8563", 0x51),
  136. },
  137. };
  138. static void nbg460n_i2c_init(void)
  139. {
  140. /* The gpio interface */
  141. platform_device_register(&nbg460n_i2c_device);
  142. /* I2C devices */
  143. i2c_register_board_info(0, nbg460n_i2c_devs,
  144. ARRAY_SIZE(nbg460n_i2c_devs));
  145. }
  146. static struct rtl8366_platform_data nbg460n_rtl8366s_data = {
  147. .gpio_sda = NBG460N_GPIO_RTL8366_SDA,
  148. .gpio_sck = NBG460N_GPIO_RTL8366_SCK,
  149. };
  150. static struct platform_device nbg460n_rtl8366s_device = {
  151. .name = RTL8366S_DRIVER_NAME,
  152. .id = -1,
  153. .dev = {
  154. .platform_data = &nbg460n_rtl8366s_data,
  155. }
  156. };
  157. static void __init nbg460n_setup(void)
  158. {
  159. /* end of bootloader sector contains mac address */
  160. u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
  161. /* last sector contains wlan calib data */
  162. u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  163. /* LAN Port */
  164. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  165. ath79_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  166. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  167. ath79_eth0_data.speed = SPEED_1000;
  168. ath79_eth0_data.duplex = DUPLEX_FULL;
  169. /* WAN Port */
  170. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
  171. ath79_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
  172. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  173. ath79_eth1_data.phy_mask = 0x10;
  174. ath79_register_eth(0);
  175. ath79_register_eth(1);
  176. /* register the switch phy */
  177. platform_device_register(&nbg460n_rtl8366s_device);
  178. /* register flash */
  179. ath79_register_m25p80(&nbg460n_flash_data);
  180. ath79_register_wmac(eeprom, mac);
  181. /* register RTC chip */
  182. nbg460n_i2c_init();
  183. ath79_register_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
  184. nbg460n_leds_gpio);
  185. ath79_register_gpio_keys_polled(-1, NBG460N_KEYS_POLL_INTERVAL,
  186. ARRAY_SIZE(nbg460n_gpio_keys),
  187. nbg460n_gpio_keys);
  188. }
  189. MIPS_MACHINE(ATH79_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH",
  190. nbg460n_setup);