dev-ap9x-pci.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac)
  37. {
  38. switch (wmac) {
  39. case 0:
  40. return &ap9x_wmac0_data;
  41. case 1:
  42. return &ap9x_wmac1_data;
  43. }
  44. return NULL;
  45. }
  46. __init void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
  47. {
  48. switch (wmac) {
  49. case 0:
  50. ap9x_wmac0_data.gpio_mask = mask;
  51. ap9x_wmac0_data.gpio_val = val;
  52. break;
  53. case 1:
  54. ap9x_wmac1_data.gpio_mask = mask;
  55. ap9x_wmac1_data.gpio_val = val;
  56. break;
  57. }
  58. }
  59. __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
  60. int num_leds)
  61. {
  62. switch (wmac) {
  63. case 0:
  64. ap9x_wmac0_data.leds = leds;
  65. ap9x_wmac0_data.num_leds = num_leds;
  66. break;
  67. case 1:
  68. ap9x_wmac1_data.leds = leds;
  69. ap9x_wmac1_data.num_leds = num_leds;
  70. break;
  71. }
  72. }
  73. static int ap91_pci_plat_dev_init(struct pci_dev *dev)
  74. {
  75. switch (PCI_SLOT(dev->devfn)) {
  76. case 0:
  77. dev->dev.platform_data = &ap9x_wmac0_data;
  78. break;
  79. }
  80. return 0;
  81. }
  82. __init void ap91_pci_init(u8 *cal_data, u8 *mac_addr)
  83. {
  84. if (cal_data)
  85. memcpy(ap9x_wmac0_data.eeprom_data, cal_data,
  86. sizeof(ap9x_wmac0_data.eeprom_data));
  87. if (mac_addr) {
  88. memcpy(ap9x_wmac0_mac, mac_addr, sizeof(ap9x_wmac0_mac));
  89. ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
  90. }
  91. ath79_pci_set_plat_dev_init(ap91_pci_plat_dev_init);
  92. ath79_register_pci();
  93. pci_enable_ath9k_fixup(0, ap9x_wmac0_data.eeprom_data);
  94. }
  95. __init void ap91_pci_init_simple(void)
  96. {
  97. ap91_pci_init(NULL, NULL);
  98. ap9x_wmac0_data.eeprom_name = "pci_wmac0.eeprom";
  99. }
  100. static int ap94_pci_plat_dev_init(struct pci_dev *dev)
  101. {
  102. switch (PCI_SLOT(dev->devfn)) {
  103. case 17:
  104. dev->dev.platform_data = &ap9x_wmac0_data;
  105. break;
  106. case 18:
  107. dev->dev.platform_data = &ap9x_wmac1_data;
  108. break;
  109. }
  110. return 0;
  111. }
  112. __init void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
  113. u8 *cal_data1, u8 *mac_addr1)
  114. {
  115. if (cal_data0)
  116. memcpy(ap9x_wmac0_data.eeprom_data, cal_data0,
  117. sizeof(ap9x_wmac0_data.eeprom_data));
  118. if (cal_data1)
  119. memcpy(ap9x_wmac1_data.eeprom_data, cal_data1,
  120. sizeof(ap9x_wmac1_data.eeprom_data));
  121. if (mac_addr0) {
  122. memcpy(ap9x_wmac0_mac, mac_addr0, sizeof(ap9x_wmac0_mac));
  123. ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
  124. }
  125. if (mac_addr1) {
  126. memcpy(ap9x_wmac1_mac, mac_addr1, sizeof(ap9x_wmac1_mac));
  127. ap9x_wmac1_data.macaddr = ap9x_wmac1_mac;
  128. }
  129. ath79_pci_set_plat_dev_init(ap94_pci_plat_dev_init);
  130. ath79_register_pci();
  131. pci_enable_ath9k_fixup(17, ap9x_wmac0_data.eeprom_data);
  132. pci_enable_ath9k_fixup(18, ap9x_wmac1_data.eeprom_data);
  133. }