333-ath9k-add-support-for-endian-swap-of-eeprom-from-pla.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From: Felix Fietkau <[email protected]>
  2. Date: Sat, 18 Oct 2014 18:24:15 +0200
  3. Subject: [PATCH] ath9k: add support for endian swap of eeprom from
  4. platform data
  5. On some devices (especially little-endian ones), the flash EEPROM data
  6. has a different endian, which needs to be detected.
  7. Add a flag to the platform data to allow overriding that behavior
  8. Signed-off-by: Felix Fietkau <[email protected]>
  9. ---
  10. --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
  11. +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
  12. @@ -262,7 +262,7 @@ static int ath9k_hw_def_check_eeprom(str
  13. {
  14. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  15. struct ath_common *common = ath9k_hw_common(ah);
  16. - u16 *eepdata, temp, magic, magic2;
  17. + u16 *eepdata, temp, magic;
  18. u32 sum = 0, el;
  19. bool need_swap = false;
  20. int i, addr, size;
  21. @@ -272,27 +272,16 @@ static int ath9k_hw_def_check_eeprom(str
  22. return false;
  23. }
  24. - if (!ath9k_hw_use_flash(ah)) {
  25. - ath_dbg(common, EEPROM, "Read Magic = 0x%04X\n", magic);
  26. -
  27. - if (magic != AR5416_EEPROM_MAGIC) {
  28. - magic2 = swab16(magic);
  29. -
  30. - if (magic2 == AR5416_EEPROM_MAGIC) {
  31. - size = sizeof(struct ar5416_eeprom_def);
  32. - need_swap = true;
  33. - eepdata = (u16 *) (&ah->eeprom);
  34. -
  35. - for (addr = 0; addr < size / sizeof(u16); addr++) {
  36. - temp = swab16(*eepdata);
  37. - *eepdata = temp;
  38. - eepdata++;
  39. - }
  40. - } else {
  41. - ath_err(common,
  42. - "Invalid EEPROM Magic. Endianness mismatch.\n");
  43. - return -EINVAL;
  44. - }
  45. + if (swab16(magic) == AR5416_EEPROM_MAGIC &&
  46. + !(ah->ah_flags & AH_NO_EEP_SWAP)) {
  47. + size = sizeof(struct ar5416_eeprom_def);
  48. + need_swap = true;
  49. + eepdata = (u16 *) (&ah->eeprom);
  50. +
  51. + for (addr = 0; addr < size / sizeof(u16); addr++) {
  52. + temp = swab16(*eepdata);
  53. + *eepdata = temp;
  54. + eepdata++;
  55. }
  56. }
  57. --- a/drivers/net/wireless/ath/ath9k/hw.h
  58. +++ b/drivers/net/wireless/ath/ath9k/hw.h
  59. @@ -731,6 +731,7 @@ enum ath_cal_list {
  60. #define AH_USE_EEPROM 0x1
  61. #define AH_UNPLUGGED 0x2 /* The card has been physically removed. */
  62. #define AH_FASTCC 0x4
  63. +#define AH_NO_EEP_SWAP 0x8 /* Do not swap EEPROM data */
  64. struct ath_hw {
  65. struct ath_ops reg_ops;
  66. --- a/drivers/net/wireless/ath/ath9k/init.c
  67. +++ b/drivers/net/wireless/ath/ath9k/init.c
  68. @@ -531,6 +531,8 @@ static int ath9k_init_softc(u16 devid, s
  69. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  70. ah->get_mac_revision = pdata->get_mac_revision;
  71. ah->external_reset = pdata->external_reset;
  72. + if (!pdata->endian_check)
  73. + ah->ah_flags |= AH_NO_EEP_SWAP;
  74. }
  75. common->ops = &ah->reg_ops;
  76. --- a/include/linux/ath9k_platform.h
  77. +++ b/include/linux/ath9k_platform.h
  78. @@ -31,6 +31,7 @@ struct ath9k_platform_data {
  79. u32 gpio_mask;
  80. u32 gpio_val;
  81. + bool endian_check;
  82. bool is_clk_25mhz;
  83. bool tx_gain_buffalo;