eeprom.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  4. * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
  5. */
  6. #ifndef __MT7601U_EEPROM_H
  7. #define __MT7601U_EEPROM_H
  8. struct mt7601u_dev;
  9. #define MT7601U_EE_MAX_VER 0x0d
  10. #define MT7601U_EEPROM_SIZE 256
  11. #define MT7601U_DEFAULT_TX_POWER 6
  12. enum mt76_eeprom_field {
  13. MT_EE_CHIP_ID = 0x00,
  14. MT_EE_VERSION_FAE = 0x02,
  15. MT_EE_VERSION_EE = 0x03,
  16. MT_EE_MAC_ADDR = 0x04,
  17. MT_EE_NIC_CONF_0 = 0x34,
  18. MT_EE_NIC_CONF_1 = 0x36,
  19. MT_EE_COUNTRY_REGION = 0x39,
  20. MT_EE_FREQ_OFFSET = 0x3a,
  21. MT_EE_NIC_CONF_2 = 0x42,
  22. MT_EE_LNA_GAIN = 0x44,
  23. MT_EE_RSSI_OFFSET = 0x46,
  24. MT_EE_TX_POWER_DELTA_BW40 = 0x50,
  25. MT_EE_TX_POWER_OFFSET = 0x52,
  26. MT_EE_TX_TSSI_SLOPE = 0x6e,
  27. MT_EE_TX_TSSI_OFFSET_GROUP = 0x6f,
  28. MT_EE_TX_TSSI_OFFSET = 0x76,
  29. MT_EE_TX_TSSI_TARGET_POWER = 0xd0,
  30. MT_EE_REF_TEMP = 0xd1,
  31. MT_EE_FREQ_OFFSET_COMPENSATION = 0xdb,
  32. MT_EE_TX_POWER_BYRATE_BASE = 0xde,
  33. MT_EE_USAGE_MAP_START = 0x1e0,
  34. MT_EE_USAGE_MAP_END = 0x1fc,
  35. };
  36. #define MT_EE_NIC_CONF_0_RX_PATH GENMASK(3, 0)
  37. #define MT_EE_NIC_CONF_0_TX_PATH GENMASK(7, 4)
  38. #define MT_EE_NIC_CONF_0_BOARD_TYPE GENMASK(13, 12)
  39. #define MT_EE_NIC_CONF_1_HW_RF_CTRL BIT(0)
  40. #define MT_EE_NIC_CONF_1_TEMP_TX_ALC BIT(1)
  41. #define MT_EE_NIC_CONF_1_LNA_EXT_2G BIT(2)
  42. #define MT_EE_NIC_CONF_1_LNA_EXT_5G BIT(3)
  43. #define MT_EE_NIC_CONF_1_TX_ALC_EN BIT(13)
  44. #define MT_EE_NIC_CONF_2_RX_STREAM GENMASK(3, 0)
  45. #define MT_EE_NIC_CONF_2_TX_STREAM GENMASK(7, 4)
  46. #define MT_EE_NIC_CONF_2_HW_ANTDIV BIT(8)
  47. #define MT_EE_NIC_CONF_2_XTAL_OPTION GENMASK(10, 9)
  48. #define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11)
  49. #define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13)
  50. #define MT_EE_TX_POWER_BYRATE(i) (MT_EE_TX_POWER_BYRATE_BASE + \
  51. (i) * 4)
  52. #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \
  53. MT_EE_USAGE_MAP_START + 1)
  54. enum mt7601u_eeprom_access_modes {
  55. MT_EE_READ = 0,
  56. MT_EE_PHYSICAL_READ = 1,
  57. };
  58. struct power_per_rate {
  59. u8 raw; /* validated s6 value */
  60. s8 bw20; /* sign-extended int */
  61. s8 bw40; /* sign-extended int */
  62. };
  63. /* Power per rate - one value per two rates */
  64. struct mt7601u_rate_power {
  65. struct power_per_rate cck[2];
  66. struct power_per_rate ofdm[4];
  67. struct power_per_rate ht[4];
  68. };
  69. struct reg_channel_bounds {
  70. u8 start;
  71. u8 num;
  72. };
  73. struct mt7601u_eeprom_params {
  74. bool tssi_enabled;
  75. u8 rf_freq_off;
  76. s8 rssi_offset[2];
  77. s8 ref_temp;
  78. s8 lna_gain;
  79. u8 chan_pwr[14];
  80. struct mt7601u_rate_power power_rate_table;
  81. s8 real_cck_bw20[2];
  82. /* TSSI stuff - only with internal TX ALC */
  83. struct tssi_data {
  84. int tx0_delta_offset;
  85. u8 slope;
  86. u8 offset[3];
  87. } tssi_data;
  88. struct reg_channel_bounds reg;
  89. };
  90. int mt7601u_eeprom_init(struct mt7601u_dev *dev);
  91. static inline u32 s6_validate(u32 reg)
  92. {
  93. WARN_ON(reg & ~GENMASK(5, 0));
  94. return reg & GENMASK(5, 0);
  95. }
  96. static inline int s6_to_int(u32 reg)
  97. {
  98. int s6;
  99. s6 = s6_validate(reg);
  100. if (s6 & BIT(5))
  101. s6 -= BIT(6);
  102. return s6;
  103. }
  104. static inline u32 int_to_s6(int val)
  105. {
  106. if (val < -0x20)
  107. return 0x20;
  108. if (val > 0x1f)
  109. return 0x1f;
  110. return val & 0x3f;
  111. }
  112. #endif