dev-ap9x-pci.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Atheros AP9X reference board PCI initialization
  3. *
  4. * Copyright (C) 2009-2012 Gabor Juhos <juhosg@openwrt.org>
  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/pci.h>
  11. #include <linux/ath9k_platform.h>
  12. #include <linux/delay.h>
  13. #include <asm/mach-ath79/ath79.h>
  14. #include "dev-ap9x-pci.h"
  15. #include "pci-ath9k-fixup.h"
  16. #include "pci.h"
  17. static struct ath9k_platform_data ap9x_wmac0_data = {
  18. .led_pin = -1,
  19. };
  20. static struct ath9k_platform_data ap9x_wmac1_data = {
  21. .led_pin = -1,
  22. };
  23. static char ap9x_wmac0_mac[6];
  24. static char ap9x_wmac1_mac[6];
  25. __init void ap9x_pci_setup_wmac_led_pin(unsigned wmac, int pin)
  26. {
  27. switch (wmac) {
  28. case 0:
  29. ap9x_wmac0_data.led_pin = pin;
  30. break;
  31. case 1:
  32. ap9x_wmac1_data.led_pin = pin;
  33. break;
  34. }
  35. }
  36. __init void ap9x_pci_setup_wmac_led_name(unsigned wmac, const char *led_name)
  37. {
  38. switch (wmac) {
  39. case 0:
  40. ap9x_wmac0_data.led_name = led_name;
  41. break;
  42. case 1:
  43. ap9x_wmac1_data.led_name = led_name;
  44. break;
  45. }
  46. }
  47. __init struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac)
  48. {
  49. switch (wmac) {
  50. case 0:
  51. return &ap9x_wmac0_data;
  52. case 1:
  53. return &ap9x_wmac1_data;
  54. }
  55. return NULL;
  56. }
  57. __init void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
  58. {
  59. switch (wmac) {
  60. case 0:
  61. ap9x_wmac0_data.gpio_mask = mask;
  62. ap9x_wmac0_data.gpio_val = val;
  63. break;
  64. case 1:
  65. ap9x_wmac1_data.gpio_mask = mask;
  66. ap9x_wmac1_data.gpio_val = val;
  67. break;
  68. }
  69. }
  70. __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
  71. int num_leds)
  72. {
  73. switch (wmac) {
  74. case 0:
  75. ap9x_wmac0_data.leds = leds;
  76. ap9x_wmac0_data.num_leds = num_leds;
  77. break;
  78. case 1:
  79. ap9x_wmac1_data.leds = leds;
  80. ap9x_wmac1_data.num_leds = num_leds;
  81. break;
  82. }
  83. }
  84. __init void ap9x_pci_setup_wmac_btns(unsigned wmac,
  85. struct gpio_keys_button *btns,
  86. unsigned num_btns, unsigned poll_interval)
  87. {
  88. struct ath9k_platform_data *ap9x_wmac_data;
  89. if (!(ap9x_wmac_data = ap9x_pci_get_wmac_data(wmac)))
  90. return;
  91. ap9x_wmac_data->btns = btns;
  92. ap9x_wmac_data->num_btns = num_btns;
  93. ap9x_wmac_data->btn_poll_interval = poll_interval;
  94. }
  95. static int ap91_pci_plat_dev_init(struct pci_dev *dev)
  96. {
  97. switch (PCI_SLOT(dev->devfn)) {
  98. case 0:
  99. dev->dev.platform_data = &ap9x_wmac0_data;
  100. break;
  101. }
  102. return 0;
  103. }
  104. __init void ap91_pci_init(u8 *cal_data, u8 *mac_addr)
  105. {
  106. if (cal_data)
  107. memcpy(ap9x_wmac0_data.eeprom_data, cal_data,
  108. sizeof(ap9x_wmac0_data.eeprom_data));
  109. if (mac_addr) {
  110. memcpy(ap9x_wmac0_mac, mac_addr, sizeof(ap9x_wmac0_mac));
  111. ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
  112. }
  113. ath79_pci_set_plat_dev_init(ap91_pci_plat_dev_init);
  114. ath79_register_pci();
  115. pci_enable_ath9k_fixup(0, ap9x_wmac0_data.eeprom_data);
  116. }
  117. __init void ap91_pci_init_simple(void)
  118. {
  119. ap91_pci_init(NULL, NULL);
  120. ap9x_wmac0_data.eeprom_name = "pci_wmac0.eeprom";
  121. }
  122. static int ap94_pci_plat_dev_init(struct pci_dev *dev)
  123. {
  124. switch (PCI_SLOT(dev->devfn)) {
  125. case 17:
  126. dev->dev.platform_data = &ap9x_wmac0_data;
  127. break;
  128. case 18:
  129. dev->dev.platform_data = &ap9x_wmac1_data;
  130. break;
  131. }
  132. return 0;
  133. }
  134. __init void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  135. u8 *cal_data1, u8 *mac_addr1)
  136. {
  137. if (cal_data0)
  138. memcpy(ap9x_wmac0_data.eeprom_data, cal_data0,
  139. sizeof(ap9x_wmac0_data.eeprom_data));
  140. if (cal_data1)
  141. memcpy(ap9x_wmac1_data.eeprom_data, cal_data1,
  142. sizeof(ap9x_wmac1_data.eeprom_data));
  143. if (mac_addr0) {
  144. memcpy(ap9x_wmac0_mac, mac_addr0, sizeof(ap9x_wmac0_mac));
  145. ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
  146. }
  147. if (mac_addr1) {
  148. memcpy(ap9x_wmac1_mac, mac_addr1, sizeof(ap9x_wmac1_mac));
  149. ap9x_wmac1_data.macaddr = ap9x_wmac1_mac;
  150. }
  151. ath79_pci_set_plat_dev_init(ap94_pci_plat_dev_init);
  152. ath79_register_pci();
  153. pci_enable_ath9k_fixup(17, ap9x_wmac0_data.eeprom_data);
  154. pci_enable_ath9k_fixup(18, ap9x_wmac1_data.eeprom_data);
  155. }