mach-rb941.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * MikroTik RouterBOARD 941-2nD support
  3. *
  4. * Copyright (C) 2016 Sergey Sergeev <adron@yapic.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/export.h>
  11. #include <linux/pci.h>
  12. #include <linux/ath9k_platform.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/phy.h>
  15. #include <linux/ar8216_platform.h>
  16. #include <linux/rle.h>
  17. #include <linux/routerboot.h>
  18. #include <linux/gpio.h>
  19. #include <linux/mtd/mtd.h>
  20. //#include <linux/mtd/nand.h>
  21. #include <linux/mtd/partitions.h>
  22. #include <asm/mach-ath79/ar71xx_regs.h>
  23. #include <asm/mach-ath79/ath79.h>
  24. #include <asm/mach-ath79/irq.h>
  25. #include "common.h"
  26. #include "dev-ap9x-pci.h"
  27. #include "dev-eth.h"
  28. #include "dev-spi.h"
  29. #include "dev-gpio-buttons.h"
  30. #include "dev-leds-gpio.h"
  31. #include "dev-m25p80.h"
  32. //#include "dev-usb.h"
  33. #include "dev-wmac.h"
  34. #include "machtypes.h"
  35. #include "routerboot.h"
  36. #define RB941_GPIO_LED_ACT 14
  37. #define RB941_GPIO_BTN_RESET 16
  38. #define RB941_KEYS_POLL_INTERVAL 20 /* msecs */
  39. #define RB941_KEYS_DEBOUNCE_INTERVAL (3 * RB941_KEYS_POLL_INTERVAL)
  40. #define RB_ROUTERBOOT_OFFSET 0x0000
  41. #define RB_ROUTERBOOT_SIZE 0xe000
  42. #define RB_HARD_CFG_OFFSET 0xe000
  43. #define RB_HARD_CFG_SIZE 0x1000
  44. #define RB_BIOS_OFFSET 0xf000
  45. #define RB_BIOS_SIZE 0x1000
  46. #define RB_ROUTERBOOT2_OFFSET 0x10000
  47. #define RB_ROUTERBOOT2_SIZE 0xf000
  48. #define RB_SOFT_CFG_OFFSET 0x1f000
  49. #define RB_SOFT_CFG_SIZE 0x1000
  50. #define RB_ROOTFS_OFFSET 0x20000
  51. #define RB_ROOTFS_SIZE 0x9e0000
  52. #define RB_KERNEL_OFFSET 0xa00000
  53. #define RB_KERNEL_SIZE MTDPART_SIZ_FULL
  54. void __init rb941_wlan_init(void)
  55. {
  56. char *art_buf;
  57. u8 wlan_mac[ETH_ALEN];
  58. art_buf = rb_get_wlan_data();
  59. if (art_buf == NULL)
  60. return;
  61. ath79_init_mac(wlan_mac, ath79_mac_base, 11);
  62. ath79_register_wmac(art_buf + 0x1000, wlan_mac);
  63. kfree(art_buf);
  64. }
  65. static struct mtd_partition rb941_spi_partitions[] = {
  66. {
  67. .name = "routerboot",
  68. .offset = RB_ROUTERBOOT_OFFSET,
  69. .mask_flags = MTD_WRITEABLE,
  70. .size = RB_ROUTERBOOT_SIZE,
  71. }, {
  72. .name = "hard_config",
  73. .offset = RB_HARD_CFG_OFFSET,
  74. .size = RB_HARD_CFG_SIZE,
  75. .mask_flags = MTD_WRITEABLE,
  76. }, {
  77. .name = "bios",
  78. .offset = RB_BIOS_OFFSET,
  79. .size = RB_BIOS_SIZE,
  80. .mask_flags = MTD_WRITEABLE,
  81. }, {
  82. .name = "routerboot2",
  83. .offset = RB_ROUTERBOOT2_OFFSET,
  84. .size = RB_ROUTERBOOT2_SIZE,
  85. .mask_flags = MTD_WRITEABLE,
  86. }, {
  87. .name = "soft_config",
  88. .offset = RB_SOFT_CFG_OFFSET,
  89. .size = RB_SOFT_CFG_SIZE,
  90. }, {
  91. .name = "rootfs",
  92. .offset = RB_ROOTFS_OFFSET,
  93. .size = RB_ROOTFS_SIZE,
  94. }, {
  95. .name = "kernel",
  96. .offset = RB_KERNEL_OFFSET,
  97. .size = RB_KERNEL_SIZE,
  98. }
  99. };
  100. static struct flash_platform_data rb941_spi_flash_data = {
  101. .parts = rb941_spi_partitions,
  102. .nr_parts = ARRAY_SIZE(rb941_spi_partitions),
  103. };
  104. static struct gpio_led rb941_leds[] __initdata = {
  105. {
  106. .name = "rb:green:act",
  107. .gpio = RB941_GPIO_LED_ACT,
  108. .active_low = 1,
  109. },
  110. };
  111. static struct gpio_keys_button rb941_gpio_keys[] __initdata = {
  112. {
  113. .desc = "Reset button",
  114. .type = EV_KEY,
  115. .code = KEY_RESTART,
  116. .debounce_interval = RB941_KEYS_DEBOUNCE_INTERVAL,
  117. .gpio = RB941_GPIO_BTN_RESET,
  118. .active_low = 1,
  119. },
  120. };
  121. static void __init rb941_setup(void)
  122. {
  123. const struct rb_info *info;
  124. //try to get rb_info data
  125. info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x20000);
  126. if (!info){
  127. pr_err("%s: Can't get rb_info data from flash!\n", __func__);
  128. //return -EINVAL; //Not critical ... continue!
  129. }
  130. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  131. ath79_register_m25p80(&rb941_spi_flash_data);
  132. ath79_register_mdio(0, 0x0);
  133. /* WAN. We have no WAN. Only LAN. */
  134. /*ath79_switch_data.phy4_mii_en = 1;
  135. ath79_switch_data.phy_poll_mask = BIT(4);
  136. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  137. ath79_eth0_data.phy_mask = BIT(4);
  138. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  139. ath79_register_eth(0); */
  140. /* LAN */
  141. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  142. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  143. ath79_register_eth(1);
  144. //ath79_register_usb();
  145. rb941_wlan_init();
  146. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb941_leds), rb941_leds);
  147. ath79_register_gpio_keys_polled(-1, RB941_KEYS_POLL_INTERVAL,
  148. ARRAY_SIZE(rb941_gpio_keys),
  149. rb941_gpio_keys);
  150. }
  151. MIPS_MACHINE(ATH79_MACH_RB_941, "H951L", "MikroTik RouterBOARD 941-2nD", rb941_setup);