History

Merge tag 'staging-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging

Pull IIO and staging driver updates from Greg KH: "Here is the big set of staging and IIO driver updates for 5.15-rc1. Also included in here are the counter driver subsystem updates as the IIO drivers needed them. Lots of churn in some staging drivers, we dropped the "old" rtl8188eu driver and replaced it with a newer version of the driver that had been maintained out-of-tree by Larry with the end goal of actually being able to get this driver out of staging eventually. Despite that driver being "newer" the line count of this pull request is going up. Some drivers moved out of staging as well, which is always nice to see, that is why there are additions to the mfc and misc driver subsystems. All of these were acked by the various subsystem maintainers involved. But by far, as normal, it's coding style cleanups all over the drivers/staging/ tree in here. Full details of these changes are in the shortlog. All of these have been in linux-next for a while with no reported problems" [ Note: the r8188eu merge clashed with commit 89939e890605 ("staging: rtlwifi: use siocdevprivate") from the networking tree. When resolving the issue, I noted that the whole r8188eu rtw_android code is dead since commit ae7471cae00a ("staging: r8188eu: remove rtw_ioctl function"). End result: the merge resolution was to throw all of that away, rather than do the mindless fixup to code that isn't actually reachable - Linus ] * tag 'staging-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (551 commits) staging: vt6655: Remove filenames in files staging: r8188eu: add extra TODO entries staging: vt6656: Remove filenames in files staging: wlan-ng: fix invalid assignment warning staging: r8188eu: rename fields of struct rtl_ps staging: r8188eu: remove ODM_DynamicPrimaryCCA_DupRTS() staging: r8188eu: rename fields of struct dyn_primary_cca staging: r8188eu: rename struct field Wifi_Error_Status staging: r8188eu: Provide a TODO file for this driver staging: r8188eu: remove unneeded variable staging: r8188eu: remove unneeded conversions to bool staging: r8188eu: remove {read,write}_macreg staging: r8188eu: core: remove condition with no effect staging: r8188eu: remove ethernet.h header file staging: r8188eu: remove ip.h header file staging: r8188eu: remove if_ether.h header file staging: r8188eu: make rtw_deinit_intf_priv return void staging: r8188eu: use is_multicast_ether_addr in os_dep/recv_linux.c staging: r8188eu: use is_multicast_ether_addr in hal/rtl8188eu_xmit.c staging: r8188eu: use is_multicast_ether_addr in core/rtw_xmit.c ...

Linus Torvalds committed 5 years ago

Commit ebf435d2 parents c6c3c57 4adb389508 files · +70162 −37823Browse files

Unified · Split

508 files
  1. Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 +31 −0
  2. Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml +0 −61
  3. Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +46 −9
  4. Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml +19 −0
  5. Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml +134 −0
  6. Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml +1 −0
  7. Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml +268 −0
  8. Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml +79 −0
  9. Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml +70 −0
  10. Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml +51 −0
  11. Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml +97 −0
  12. Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml +50 −0
  13. Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml +47 −0
  14. Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml +75 −0
  15. Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml +60 −0
  16. Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml +62 −0
  17. Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml +52 −0
  18. Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml +60 −0
  19. Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml +46 −0
  20. Documentation/devicetree/bindings/mfd/hisilicon,hi6421-spmi-pmic.yaml +17 −14
  21. Documentation/devicetree/bindings/trivial-devices.yaml +6 −0
  22. MAINTAINERS +27 −4
  23. drivers/counter/104-quad-8.c +29 −18
  24. drivers/counter/counter.c +25 −25
  25. drivers/counter/ftm-quaddec.c +2 −3
  26. drivers/counter/intel-qep.c +3 −4
  27. drivers/counter/interrupt-cnt.c +7 −4
  28. drivers/counter/microchip-tcb-capture.c +11 −5
  29. drivers/counter/stm32-lptimer-cnt.c +10 −8
  30. drivers/counter/stm32-timer-cnt.c +5 −5
  31. drivers/counter/ti-eqep.c +21 −16
  32. drivers/iio/accel/Kconfig +3 −2
  33. drivers/iio/accel/adxl345.h +0 −1
  34. drivers/iio/accel/adxl345_core.c +9 −20
  35. drivers/iio/accel/adxl345_i2c.c +0 −6
  36. drivers/iio/accel/adxl345_spi.c +0 −6
  37. drivers/iio/accel/bma220_spi.c +37 −42
  38. drivers/iio/accel/bmc150-accel-core.c +64 −14
  39. drivers/iio/accel/bmc150-accel-i2c.c +8 −2
  40. drivers/iio/accel/bmc150-accel-spi.c +9 −1
  41. drivers/iio/accel/bmc150-accel.h +19 −1
  42. drivers/iio/accel/da280.c +9 −17
  43. drivers/iio/accel/da311.c +9 −17
  44. drivers/iio/accel/dmard10.c +10 −17
  45. drivers/iio/accel/hid-sensor-accel-3d.c +4 −6
  46. drivers/iio/accel/st_accel.h +0 −4
  47. drivers/iio/accel/st_accel_buffer.c +3 −13
  48. drivers/iio/accel/st_accel_core.c +3 −11
  49. drivers/iio/accel/st_accel_i2c.c +1 −2
  50. drivers/iio/accel/st_accel_spi.c +1 −1
  51. drivers/iio/adc/Kconfig +10 −0
  52. drivers/iio/adc/Makefile +1 −0
  53. drivers/iio/adc/ep93xx_adc.c +3 −3
  54. drivers/iio/adc/fsl-imx25-gcq.c +7 −10
  55. drivers/iio/adc/ingenic-adc.c +93 −9
  56. drivers/iio/adc/meson_saradc.c +14 −6
  57. drivers/iio/adc/rockchip_saradc.c +61 −8
  58. drivers/iio/adc/rzg2l_adc.c +600 −0
  59. drivers/iio/chemical/Kconfig +11 −0
  60. drivers/iio/chemical/Makefile +1 −0
  61. drivers/iio/chemical/sgp40.c +378 −0
  62. drivers/iio/common/st_sensors/st_sensors_buffer.c +0 −2
  63. drivers/iio/common/st_sensors/st_sensors_core.c +1 −0
  64. drivers/iio/common/st_sensors/st_sensors_core.h +1 −0
  65. drivers/iio/common/st_sensors/st_sensors_i2c.c +1 −2
  66. drivers/iio/common/st_sensors/st_sensors_spi.c +1 −2
  67. drivers/iio/common/st_sensors/st_sensors_trigger.c +0 −1
  68. drivers/iio/dac/ad5624r_spi.c +17 −1
  69. drivers/iio/dac/max5821.c +17 −24
  70. drivers/iio/gyro/hid-sensor-gyro-3d.c +4 −7
  71. drivers/iio/gyro/st_gyro.h +0 −4
  72. drivers/iio/gyro/st_gyro_buffer.c +3 −13
  73. drivers/iio/gyro/st_gyro_core.c +3 −12
  74. drivers/iio/gyro/st_gyro_i2c.c +1 −1
  75. drivers/iio/gyro/st_gyro_spi.c +1 −1
  76. drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +18 −4
  77. drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +16 −2
  78. drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +2 −13
  79. drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c +1 −0
  80. drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +2 −1
  81. drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +2 −1
  82. drivers/iio/industrialio-buffer.c +5 −4
  83. drivers/iio/industrialio-core.c +29 −4
  84. drivers/iio/light/adjd_s311.c +9 −44
  85. drivers/iio/light/cm3323.c +7 −0
  86. drivers/iio/light/hid-sensor-als.c +4 −7
  87. drivers/iio/light/hid-sensor-prox.c +4 −7
  88. drivers/iio/light/si1145.c +0 −1
  89. drivers/iio/light/tcs3414.c +19 −29
  90. drivers/iio/magnetometer/st_magn.h +0 −12
  91. drivers/iio/magnetometer/st_magn_buffer.c +3 −13
  92. drivers/iio/magnetometer/st_magn_core.c +4 −13
  93. drivers/iio/magnetometer/st_magn_i2c.c +1 −1
  94. drivers/iio/magnetometer/st_magn_spi.c +1 −1
  95. drivers/iio/orientation/hid-sensor-incl-3d.c +4 −7
  96. drivers/iio/potentiometer/Kconfig +10 −0
  97. drivers/iio/potentiometer/Makefile +1 −0
  98. drivers/iio/potentiometer/ad5110.c +344 −0
  99. drivers/iio/potentiometer/max5481.c +9 −13
  100. drivers/iio/pressure/hid-sensor-press.c +28 −23
  101. drivers/iio/pressure/hp03.c +7 −29
  102. drivers/iio/pressure/st_pressure.h +0 −5
  103. drivers/iio/pressure/st_pressure_buffer.c +3 −13
  104. drivers/iio/pressure/st_pressure_core.c +3 −13
  105. drivers/iio/pressure/st_pressure_i2c.c +2 −1
  106. drivers/iio/pressure/st_pressure_spi.c +1 −1
  107. drivers/iio/proximity/rfd77402.c +33 −50
  108. drivers/iio/proximity/sx9310.c +16 −32
  109. drivers/iio/proximity/vcnl3020.c +335 −16
  110. drivers/iio/temperature/ltc2983.c +14 −16
  111. drivers/iio/temperature/tmp006.c +31 −22
  112. drivers/mfd/Kconfig +16 −0
  113. drivers/mfd/Makefile +1 −0
  114. drivers/mfd/hi6421-spmi-pmic.c +72 −0
  115. drivers/misc/Kconfig +10 −0
  116. drivers/misc/Makefile +1 −0
  117. drivers/misc/hi6421v600-irq.c +307 −0
  118. drivers/staging/Kconfig +1 −3
  119. drivers/staging/Makefile +1 −2
  120. drivers/staging/board/board.c +6 −1
  121. drivers/staging/clocking-wizard/Kconfig +1 −1
  122. drivers/staging/fbtft/fbtft-core.c +10 −13
  123. drivers/staging/gdm724x/netlink_k.c +2 −2
  124. drivers/staging/hikey9xx/Kconfig +0 −19
  125. drivers/staging/hikey9xx/Makefile +0 −3
  126. drivers/staging/hikey9xx/TODO +0 −5
  127. drivers/staging/hikey9xx/hi6421-spmi-pmic.c +0 −311
  128. drivers/staging/ks7010/ks7010_sdio.c +1 −1
  129. drivers/staging/ks7010/ks_wlan_net.c +5 −5
  130. drivers/staging/most/video/video.c +2 −2
  131. drivers/staging/mt7621-pci/pci-mt7621.c +11 −2
  132. drivers/staging/qlge/qlge_dbg.c +2 −2
  133. drivers/staging/r8188eu/Kconfig +4 −3
  134. drivers/staging/r8188eu/Makefile +105 −0
  135. drivers/staging/r8188eu/TODO +16 −0
  136. drivers/staging/r8188eu/core/rtw_ap.c +474 −289
  137. drivers/staging/r8188eu/core/rtw_br_ext.c +717 −0
  138. drivers/staging/r8188eu/core/rtw_cmd.c +2128 −0
  139. drivers/staging/r8188eu/core/rtw_debug.c +904 −0
  140. drivers/staging/r8188eu/core/rtw_efuse.c +848 −0
  141. drivers/staging/r8188eu/core/rtw_ieee80211.c +1539 −0
  142. drivers/staging/r8188eu/core/rtw_io.c +299 −0
  143. drivers/staging/r8188eu/core/rtw_ioctl_set.c +891 −0
  144. drivers/staging/r8188eu/core/rtw_iol.c +192 −0
  145. drivers/staging/r8188eu/core/rtw_led.c +1612 −0
  146. drivers/staging/r8188eu/core/rtw_mlme.c +713 −401
  147. drivers/staging/r8188eu/core/rtw_mlme_ext.c +8327 −0
  148. drivers/staging/r8188eu/core/rtw_mp.c +935 −0
  149. drivers/staging/r8188eu/core/rtw_mp_ioctl.c +1170 −0
  150. drivers/staging/r8188eu/core/rtw_p2p.c +1997 −0
  151. drivers/staging/r8188eu/core/rtw_pwrctrl.c +189 −165
  152. drivers/staging/r8188eu/core/rtw_recv.c +567 −321
  153. drivers/staging/r8188eu/core/rtw_rf.c +24 −10
  154. drivers/staging/r8188eu/core/rtw_security.c +1656 −0
  155. drivers/staging/r8188eu/core/rtw_sreset.c +62 −0
  156. drivers/staging/r8188eu/core/rtw_sta_mgt.c +150 −121
  157. drivers/staging/r8188eu/core/rtw_wlan_util.c +605 −335
  158. drivers/staging/r8188eu/core/rtw_xmit.c +576 −264
  159. drivers/staging/r8188eu/hal/Hal8188EPwrSeq.c +69 −0
  160. drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.c +83 −65
  161. drivers/staging/r8188eu/hal/HalHWImg8188E_BB.c +247 −226
  162. drivers/staging/r8188eu/hal/HalHWImg8188E_MAC.c +213 −0
  163. drivers/staging/r8188eu/hal/HalHWImg8188E_RF.c +250 −0
  164. drivers/staging/r8188eu/hal/HalPhyRf_8188e.c +1264 −0
  165. drivers/staging/r8188eu/hal/HalPwrSeqCmd.c +95 −0
  166. drivers/staging/r8188eu/hal/hal_com.c +131 −58
  167. drivers/staging/r8188eu/hal/hal_intf.c +441 −0
  168. drivers/staging/r8188eu/hal/odm.c +1968 −0
  169. drivers/staging/r8188eu/hal/odm_HWConfig.c +567 −0
  170. drivers/staging/r8188eu/hal/odm_RTL8188E.c +337 −0
  171. drivers/staging/r8188eu/hal/odm_RegConfig8188E.c +98 −0
  172. drivers/staging/r8188eu/hal/odm_debug.c +6 −0
  173. drivers/staging/r8188eu/hal/odm_interface.c +178 −0
  174. drivers/staging/r8188eu/hal/rtl8188e_cmd.c +284 −138
  175. drivers/staging/r8188eu/hal/rtl8188e_dm.c +238 −0
  176. drivers/staging/r8188eu/hal/rtl8188e_hal_init.c +2304 −0
  177. drivers/staging/r8188eu/hal/rtl8188e_mp.c +798 −0
  178. drivers/staging/r8188eu/hal/rtl8188e_phycfg.c +1105 −0
  179. drivers/staging/r8188eu/hal/rtl8188e_rf6052.c +550 −0
  180. drivers/staging/r8188eu/hal/rtl8188e_rxdesc.c +18 −25
  181. drivers/staging/r8188eu/hal/rtl8188e_sreset.c +64 −0
  182. drivers/staging/r8188eu/hal/rtl8188e_xmit.c +5 −8
  183. drivers/staging/r8188eu/hal/rtl8188eu_led.c +94 −0
  184. drivers/staging/r8188eu/hal/rtl8188eu_recv.c +117 −0
  185. drivers/staging/r8188eu/hal/rtl8188eu_xmit.c +119 −85
  186. drivers/staging/r8188eu/hal/usb_halinit.c +785 −393
  187. drivers/staging/r8188eu/hal/usb_ops_linux.c +562 −0
  188. drivers/staging/r8188eu/include/Hal8188EPhyCfg.h +107 −33
  189. drivers/staging/r8188eu/include/Hal8188EPhyReg.h +1072 −0
  190. drivers/staging/r8188eu/include/Hal8188EPwrSeq.h +155 −0
  191. drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h +64 −0
  192. drivers/staging/r8188eu/include/HalHWImg8188E_BB.h +27 −0
  193. drivers/staging/r8188eu/include/HalHWImg8188E_FW.h +16 −0
  194. drivers/staging/r8188eu/include/HalHWImg8188E_MAC.h +13 −0
  195. drivers/staging/r8188eu/include/HalHWImg8188E_RF.h +13 −0
  196. drivers/staging/r8188eu/include/HalPhyRf_8188e.h +41 −0
  197. drivers/staging/r8188eu/include/HalPwrSeqCmd.h +110 −0
  198. drivers/staging/r8188eu/include/HalVerDef.h +149 −0
  199. drivers/staging/r8188eu/include/basic_types.h +45 −56
  200. drivers/staging/r8188eu/include/drv_types.h +323 −0
  201. drivers/staging/r8188eu/include/hal_com.h +17 −11
  202. drivers/staging/r8188eu/include/hal_intf.h +411 −0
  203. drivers/staging/r8188eu/include/ieee80211.h +582 −98
  204. drivers/staging/r8188eu/include/ieee80211_ext.h +271 −0
  205. drivers/staging/r8188eu/include/ioctl_cfg80211.h +91 −0
  206. drivers/staging/r8188eu/include/mlme_osdep.h +6 −8
  207. drivers/staging/r8188eu/include/mp_custom_oid.h +333 −0
  208. drivers/staging/r8188eu/include/odm.h +161 −66
  209. drivers/staging/r8188eu/include/odm_HWConfig.h +26 −11
  210. drivers/staging/r8188eu/include/odm_RTL8188E.h +36 −0
  211. drivers/staging/r8188eu/include/odm_RegConfig8188E.h +27 −0
  212. drivers/staging/r8188eu/include/odm_RegDefine11AC.h +29 −0
  213. drivers/staging/r8188eu/include/odm_RegDefine11N.h +143 −0
  214. drivers/staging/r8188eu/include/odm_interface.h +147 −0
  215. drivers/staging/r8188eu/include/odm_precomp.h +29 −16
  216. drivers/staging/r8188eu/include/odm_reg.h +89 −0
  217. drivers/staging/r8188eu/include/odm_types.h +45 −0
  218. drivers/staging/r8188eu/include/osdep_intf.h +64 −0
  219. drivers/staging/r8188eu/include/osdep_service.h +315 −0
  220. drivers/staging/r8188eu/include/recv_osdep.h +37 −0
  221. drivers/staging/r8188eu/include/rtl8188e_cmd.h +42 −6
  222. drivers/staging/r8188eu/include/rtl8188e_dm.h +14 −7
  223. drivers/staging/r8188eu/include/rtl8188e_hal.h +171 −52
  224. drivers/staging/r8188eu/include/rtl8188e_led.h +18 −0
  225. drivers/staging/r8188eu/include/rtl8188e_recv.h +11 −11
  226. drivers/staging/r8188eu/include/rtl8188e_rf.h +19 −0
  227. drivers/staging/r8188eu/include/rtl8188e_spec.h +359 −98
  228. drivers/staging/r8188eu/include/rtl8188e_sreset.h +15 −0
  229. drivers/staging/r8188eu/include/rtl8188e_xmit.h +22 −29
  230. drivers/staging/r8188eu/include/rtw_ap.h +10 −8
  231. drivers/staging/r8188eu/include/rtw_br_ext.h +49 −0
  232. drivers/staging/r8188eu/include/rtw_cmd.h +975 −0
  233. drivers/staging/r8188eu/include/rtw_debug.h +231 −0
  234. drivers/staging/r8188eu/include/rtw_eeprom.h +16 −16
  235. drivers/staging/r8188eu/include/rtw_efuse.h +134 −0
  236. drivers/staging/r8188eu/include/rtw_event.h +97 −0
  237. drivers/staging/r8188eu/include/rtw_ht.h +28 −0
  238. drivers/staging/r8188eu/include/rtw_io.h +367 −0
  239. drivers/staging/r8188eu/include/rtw_ioctl.h +21 −14
  240. drivers/staging/r8188eu/include/rtw_ioctl_rtl.h +63 −0
  241. drivers/staging/r8188eu/include/rtw_ioctl_set.h +33 −0
  242. drivers/staging/r8188eu/include/rtw_iol.h +68 −0
  243. drivers/staging/r8188eu/include/rtw_led.h +181 −0
  244. drivers/staging/r8188eu/include/rtw_mlme.h +632 −0
  245. drivers/staging/r8188eu/include/rtw_mlme_ext.h +266 −89
  246. drivers/staging/r8188eu/include/rtw_mp.h +474 −0
  247. drivers/staging/r8188eu/include/rtw_mp_ioctl.h +242 −0
  248. drivers/staging/r8188eu/include/rtw_mp_phy_regdef.h +1063 −0
  249. drivers/staging/r8188eu/include/rtw_p2p.h +119 −0
  250. drivers/staging/r8188eu/include/rtw_pwrctrl.h +48 −27
  251. drivers/staging/r8188eu/include/rtw_recv.h +413 −0
  252. drivers/staging/r8188eu/include/rtw_rf.h +23 −14
  253. drivers/staging/r8188eu/include/rtw_security.h +134 −34
  254. drivers/staging/r8188eu/include/rtw_sreset.h +34 −0
  255. drivers/staging/r8188eu/include/rtw_xmit.h +43 −28
  256. drivers/staging/r8188eu/include/sta_info.h +35 −26
  257. drivers/staging/r8188eu/include/usb_ops.h +72 −0
  258. drivers/staging/r8188eu/include/usb_ops_linux.h +39 −0
  259. drivers/staging/r8188eu/include/usb_osintf.h +29 −0
  260. drivers/staging/r8188eu/include/usb_vendor_req.h +35 −0
  261. drivers/staging/r8188eu/include/wifi.h +1029 −0
  262. drivers/staging/r8188eu/include/wlan_bssdef.h +118 −31
  263. drivers/staging/r8188eu/include/xmit_osdep.h +51 −0
  264. drivers/staging/r8188eu/os_dep/ioctl_linux.c +6649 −0
  265. drivers/staging/r8188eu/os_dep/mlme_linux.c +216 −0
  266. drivers/staging/r8188eu/os_dep/os_intfs.c +1199 −0
  267. drivers/staging/r8188eu/os_dep/osdep_service.c +343 −0
  268. drivers/staging/r8188eu/os_dep/recv_linux.c +102 −26
  269. drivers/staging/r8188eu/os_dep/usb_intf.c +781 −0
  270. drivers/staging/r8188eu/os_dep/usb_ops_linux.c +253 −0
  271. drivers/staging/r8188eu/os_dep/xmit_linux.c +96 −34
  272. drivers/staging/rtl8188eu/Makefile +0 −56
  273. drivers/staging/rtl8188eu/TODO +0 −14
  274. drivers/staging/rtl8188eu/core/rtw_cmd.c +0 −1219
  275. drivers/staging/rtl8188eu/core/rtw_efuse.c +0 −876
  276. drivers/staging/rtl8188eu/core/rtw_ieee80211.c +0 −992
  277. drivers/staging/rtl8188eu/core/rtw_ioctl_set.c +0 −512
  278. drivers/staging/rtl8188eu/core/rtw_iol.c +0 −19
  279. drivers/staging/rtl8188eu/core/rtw_led.c +0 −460
  280. drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +0 −5172
  281. drivers/staging/rtl8188eu/core/rtw_security.c +0 −869
  282. drivers/staging/rtl8188eu/core/rtw_sreset.c +0 −21
  283. drivers/staging/rtl8188eu/hal/fw.c +0 −202
  284. drivers/staging/rtl8188eu/hal/hal_intf.c +0 −60
  285. drivers/staging/rtl8188eu/hal/mac_cfg.c +0 −120
  286. drivers/staging/rtl8188eu/hal/odm.c +0 −966
  287. drivers/staging/rtl8188eu/hal/odm_hwconfig.c +0 −397
  288. drivers/staging/rtl8188eu/hal/odm_rtl8188e.c +0 −335
  289. drivers/staging/rtl8188eu/hal/phy.c +0 −1276
  290. drivers/staging/rtl8188eu/hal/pwrseq.c +0 −88
  291. drivers/staging/rtl8188eu/hal/pwrseqcmd.c +0 −80
  292. drivers/staging/rtl8188eu/hal/rf.c +0 −289
  293. drivers/staging/rtl8188eu/hal/rf_cfg.c +0 −247
  294. drivers/staging/rtl8188eu/hal/rtl8188e_dm.c +0 −217
  295. drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c +0 −523
  296. drivers/staging/rtl8188eu/hal/rtl8188eu_led.c +0 −55
  297. drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c +0 −83
  298. drivers/staging/rtl8188eu/include/HalVerDef.h +0 −37
  299. drivers/staging/rtl8188eu/include/drv_types.h +0 −176
  300. drivers/staging/rtl8188eu/include/fw.h +0 −44
  301. drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h +0 −201
  302. drivers/staging/rtl8188eu/include/hal8188e_rate_adaptive.h +0 −74
  303. drivers/staging/rtl8188eu/include/hal_intf.h +0 −223
  304. drivers/staging/rtl8188eu/include/mon.h +0 −28
  305. drivers/staging/rtl8188eu/include/odm_rtl8188e.h +0 −39
  306. drivers/staging/rtl8188eu/include/odm_types.h +0 −24
  307. drivers/staging/rtl8188eu/include/osdep_intf.h +0 −37
  308. drivers/staging/rtl8188eu/include/osdep_service.h +0 −81
  309. drivers/staging/rtl8188eu/include/phy.h +0 −26
  310. drivers/staging/rtl8188eu/include/phydm_reg.h +0 −22
  311. drivers/staging/rtl8188eu/include/phydm_regdefine11n.h +0 −53
  312. drivers/staging/rtl8188eu/include/pwrseq.h +0 −242
  313. drivers/staging/rtl8188eu/include/pwrseqcmd.h +0 −52
  314. drivers/staging/rtl8188eu/include/recv_osdep.h +0 −26
  315. drivers/staging/rtl8188eu/include/rf.h +0 −12
  316. drivers/staging/rtl8188eu/include/rtw_android.h +0 −51
  317. drivers/staging/rtl8188eu/include/rtw_cmd.h +0 −361
  318. drivers/staging/rtl8188eu/include/rtw_efuse.h +0 −67
  319. drivers/staging/rtl8188eu/include/rtw_event.h +0 −81
  320. drivers/staging/rtl8188eu/include/rtw_ht.h +0 −26
  321. drivers/staging/rtl8188eu/include/rtw_ioctl_set.h +0 −28
  322. drivers/staging/rtl8188eu/include/rtw_iol.h +0 −14
  323. drivers/staging/rtl8188eu/include/rtw_led.h +0 −98
  324. drivers/staging/rtl8188eu/include/rtw_mlme.h +0 −355
  325. drivers/staging/rtl8188eu/include/rtw_recv.h +0 −262
  326. drivers/staging/rtl8188eu/include/rtw_sreset.h +0 −30
  327. drivers/staging/rtl8188eu/include/usb_ops_linux.h +0 −26
  328. drivers/staging/rtl8188eu/include/wifi.h +0 −355
  329. drivers/staging/rtl8188eu/include/xmit_osdep.h +0 −32
  330. drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +0 −2777
  331. drivers/staging/rtl8188eu/os_dep/mlme_linux.c +0 −167
  332. drivers/staging/rtl8188eu/os_dep/mon.c +0 −183
  333. drivers/staging/rtl8188eu/os_dep/os_intfs.c +0 −658
  334. drivers/staging/rtl8188eu/os_dep/osdep_service.c +0 −63
  335. drivers/staging/rtl8188eu/os_dep/rtw_android.c +0 −231
  336. drivers/staging/rtl8188eu/os_dep/usb_intf.c +0 −485
  337. drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c +0 −644
  338. drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +1 −1
  339. drivers/staging/rtl8192e/rtl8192e/rtl_core.c +0 −5
  340. drivers/staging/rtl8192e/rtllib_crypt_ccmp.c +3 −1
  341. drivers/staging/rtl8192e/rtllib_rx.c +17 −40
  342. drivers/staging/rtl8192e/rtllib_softmac.c +2 −1
  343. drivers/staging/rtl8192e/rtllib_softmac_wx.c +7 −11
  344. drivers/staging/rtl8192u/ieee80211/ieee80211.h +2 −2
  345. drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c +3 −1
  346. drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +14 −35
  347. drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +2 −1
  348. drivers/staging/rtl8192u/r8192U_core.c +1 −1
  349. drivers/staging/rtl8192u/r819xU_phy.c +44 −48
  350. drivers/staging/rtl8712/hal_init.c +0 −1
  351. drivers/staging/rtl8712/os_intfs.c +1 −1
  352. drivers/staging/rtl8712/osdep_service.h +1 −1
  353. drivers/staging/rtl8712/wifi.h +0 −48
  354. drivers/staging/rtl8723bs/Kconfig +1 −2
  355. drivers/staging/rtl8723bs/Makefile +0 −1
  356. drivers/staging/rtl8723bs/core/rtw_ap.c +65 −70
  357. drivers/staging/rtl8723bs/core/rtw_cmd.c +27 −27
  358. drivers/staging/rtl8723bs/core/rtw_debug.c +4 −15
  359. drivers/staging/rtl8723bs/core/rtw_ieee80211.c +58 −96
  360. drivers/staging/rtl8723bs/core/rtw_io.c +2 −11
  361. drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +16 −87
  362. drivers/staging/rtl8723bs/core/rtw_mlme.c +116 −147
  363. drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +147 −150
  364. drivers/staging/rtl8723bs/core/rtw_recv.c +3 −3
  365. drivers/staging/rtl8723bs/core/rtw_rf.c +0 −1
  366. drivers/staging/rtl8723bs/core/rtw_security.c +18 −18
  367. drivers/staging/rtl8723bs/core/rtw_wlan_util.c +58 −89
  368. drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +0 −464
  369. drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.h +0 −1
  370. drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c +0 −414
  371. drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.h +0 −1
  372. drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h +0 −8
  373. drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c +8 −9
  374. drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c +1 −85
  375. drivers/staging/rtl8723bs/hal/HalPhyRf.c +26 −41
  376. drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c +82 −109
  377. drivers/staging/rtl8723bs/hal/Mp_Precomp.h +0 −2
  378. drivers/staging/rtl8723bs/hal/hal_btcoex.c +2 −109
  379. drivers/staging/rtl8723bs/hal/hal_com.c +6 −166
  380. drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +64 −383
  381. drivers/staging/rtl8723bs/hal/hal_sdio.c +0 −1
  382. drivers/staging/rtl8723bs/hal/odm.c +12 −44
  383. drivers/staging/rtl8723bs/hal/odm.h +0 −25
  384. drivers/staging/rtl8723bs/hal/odm_CfoTracking.c +17 −19
  385. drivers/staging/rtl8723bs/hal/odm_CfoTracking.h +1 −1
  386. drivers/staging/rtl8723bs/hal/odm_DIG.c +1 −4
  387. drivers/staging/rtl8723bs/hal/odm_HWConfig.c +175 −168
  388. drivers/staging/rtl8723bs/hal/odm_HWConfig.h +4 −25
  389. drivers/staging/rtl8723bs/hal/odm_NoiseMonitor.c +10 −13
  390. drivers/staging/rtl8723bs/hal/odm_RTL8723B.c +0 −36
  391. drivers/staging/rtl8723bs/hal/odm_RTL8723B.h +0 −14
  392. drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.c +3 −4
  393. drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h +3 −8
  394. drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h +0 −2
  395. drivers/staging/rtl8723bs/hal/odm_precomp.h +0 −1
  396. drivers/staging/rtl8723bs/hal/odm_reg.h +0 −4
  397. drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c +11 −12
  398. drivers/staging/rtl8723bs/hal/rtl8723b_dm.c +0 −12
  399. drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c +18 −66
  400. drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c +21 −31
  401. drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c +5 −16
  402. drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c +0 −1
  403. drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c +1 −2
  404. drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c +0 −1
  405. drivers/staging/rtl8723bs/hal/sdio_halinit.c +0 −2
  406. drivers/staging/rtl8723bs/include/Hal8192CPhyReg.h +0 −4
  407. drivers/staging/rtl8723bs/include/HalVerDef.h +0 −18
  408. drivers/staging/rtl8723bs/include/drv_types.h +0 −9
  409. drivers/staging/rtl8723bs/include/ethernet.h +0 −14
  410. drivers/staging/rtl8723bs/include/hal_btcoex.h +0 −3
  411. drivers/staging/rtl8723bs/include/hal_com.h +1 −34
  412. drivers/staging/rtl8723bs/include/hal_com_phycfg.h +4 −16
  413. drivers/staging/rtl8723bs/include/hal_com_reg.h +0 −19
  414. drivers/staging/rtl8723bs/include/hal_data.h +7 −17
  415. drivers/staging/rtl8723bs/include/hal_pg.h +3 −5
  416. drivers/staging/rtl8723bs/include/hal_phy.h +1 −2
  417. drivers/staging/rtl8723bs/include/ieee80211.h +5 −37
  418. drivers/staging/rtl8723bs/include/osdep_intf.h +0 −2
  419. drivers/staging/rtl8723bs/include/osdep_service.h +0 −4
  420. drivers/staging/rtl8723bs/include/rtl8723b_xmit.h +0 −8
  421. drivers/staging/rtl8723bs/include/rtw_ioctl_set.h +0 −1
  422. drivers/staging/rtl8723bs/include/rtw_mlme.h +3 −3
  423. drivers/staging/rtl8723bs/include/rtw_recv.h +2 −0
  424. drivers/staging/rtl8723bs/include/rtw_rf.h +0 −10
  425. drivers/staging/rtl8723bs/include/wifi.h +0 −8
  426. drivers/staging/rtl8723bs/include/wlan_bssdef.h +36 −56
  427. drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +105 −68
  428. drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +63 −3226
  429. drivers/staging/rtl8723bs/os_dep/mlme_linux.c +0 −4
  430. drivers/staging/rtl8723bs/os_dep/os_intfs.c +4 −28
  431. drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c +0 −1
  432. drivers/staging/rts5208/rtsx_scsi.c +3 −7
  433. drivers/staging/sm750fb/sm750.c +26 −26
  434. drivers/staging/sm750fb/sm750.h +6 −6
  435. drivers/staging/sm750fb/sm750_cursor.c +2 −2
  436. drivers/staging/sm750fb/sm750_hw.c +31 −31
  437. drivers/staging/vc04_services/Kconfig +24 −4
  438. drivers/staging/vc04_services/Makefile +4 −1
  439. drivers/staging/vc04_services/bcm2835-audio/bcm2835.h +1 −1
  440. drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +1 −1
  441. drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +0 −564
  442. drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +715 −1615
  443. drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +82 −0
  444. drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +1 −1
  445. drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +1440 −0
  446. drivers/staging/vt6655/baseband.c +0 −2
  447. drivers/staging/vt6655/baseband.h +0 −2
  448. drivers/staging/vt6655/card.c +0 −1
  449. drivers/staging/vt6655/card.h +0 −2
  450. drivers/staging/vt6655/channel.c +0 −2
  451. drivers/staging/vt6655/channel.h +0 −1
  452. drivers/staging/vt6655/desc.h +0 −2
  453. drivers/staging/vt6655/device.h +0 −2
  454. drivers/staging/vt6655/device_cfg.h +1 −5
  455. drivers/staging/vt6655/device_main.c +0 −2
  456. drivers/staging/vt6655/dpc.c +0 −2
  457. drivers/staging/vt6655/dpc.h +0 −2
  458. drivers/staging/vt6655/key.c +0 −2
  459. drivers/staging/vt6655/key.h +0 −2
  460. drivers/staging/vt6655/mac.c +0 −3
  461. drivers/staging/vt6655/mac.h +0 −2
  462. drivers/staging/vt6655/power.c +0 −2
  463. drivers/staging/vt6655/power.h +0 −2
  464. drivers/staging/vt6655/rf.c +0 −2
  465. drivers/staging/vt6655/rf.h +0 −2
  466. drivers/staging/vt6655/rxtx.c +0 −2
  467. drivers/staging/vt6655/rxtx.h +0 −2
  468. drivers/staging/vt6655/srom.c +0 −2
  469. drivers/staging/vt6655/srom.h +0 −2
  470. drivers/staging/vt6655/tmacro.h +0 −2
  471. drivers/staging/vt6655/upc.h +0 −2
  472. drivers/staging/vt6656/baseband.c +0 −2
  473. drivers/staging/vt6656/baseband.h +0 −2
  474. drivers/staging/vt6656/card.c +0 −1
  475. drivers/staging/vt6656/card.h +0 −2
  476. drivers/staging/vt6656/channel.c +0 −2
  477. drivers/staging/vt6656/channel.h +0 −2
  478. drivers/staging/vt6656/desc.h +0 −2
  479. drivers/staging/vt6656/device.h +0 −4
  480. drivers/staging/vt6656/key.c +0 −2
  481. drivers/staging/vt6656/key.h +0 −2
  482. drivers/staging/vt6656/mac.c +0 −2
  483. drivers/staging/vt6656/mac.h +0 −2
  484. drivers/staging/vt6656/main_usb.c +0 −2
  485. drivers/staging/vt6656/power.c +0 −2
  486. drivers/staging/vt6656/power.h +0 −2
  487. drivers/staging/vt6656/rf.c +0 −2
  488. drivers/staging/vt6656/rf.h +0 −2
  489. drivers/staging/vt6656/rxtx.c +0 −2
  490. drivers/staging/vt6656/rxtx.h +0 −2
  491. drivers/staging/vt6656/usbpipe.c +0 −2
  492. drivers/staging/vt6656/usbpipe.h +0 −2
  493. drivers/staging/vt6656/wcmd.c +0 −2
  494. drivers/staging/vt6656/wcmd.h +0 −2
  495. drivers/staging/wlan-ng/hfa384x.h +3 −16
  496. drivers/staging/wlan-ng/hfa384x_usb.c +6 −7
  497. drivers/staging/wlan-ng/p80211conv.c +24 −24
  498. drivers/staging/wlan-ng/p80211conv.h +1 −1
  499. drivers/staging/wlan-ng/p80211hdr.h +8 −22
  500. drivers/staging/wlan-ng/p80211mgmt.h +12 −12
  501. drivers/staging/wlan-ng/p80211netdev.c +6 −6
  502. drivers/staging/wlan-ng/p80211netdev.h +1 −1
  503. drivers/staging/wlan-ng/prism2fw.c +4 −4
  504. drivers/staging/wlan-ng/prism2mib.c +10 −0
  505. drivers/staging/wlan-ng/prism2sta.c +3 −3
  506. include/dt-bindings/iio/adc/ingenic,adc.h +1 −0
  507. include/linux/counter.h +16 −16
  508. include/linux/mfd/hi6421-spmi-pmic.h +0 −5
Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40+31−0
@@ -0,0 +1,31 @@
1+What: /sys/bus/iio/devices/iio:deviceX/out_temp_raw
2+Date: August 2021
3+KernelVersion: 5.15
4+Contact: Andreas Klinger <ak@it-klinger.de>
5+Description:
6+ Set the temperature. This value is sent to the sensor for
7+ temperature compensation.
8+ Default value: 25000 (25 °C)
9+
10+What: /sys/bus/iio/devices/iio:deviceX/out_humidityrelative_raw
11+Date: August 2021
12+KernelVersion: 5.15
13+Contact: Andreas Klinger <ak@it-klinger.de>
14+Description:
15+ Set the relative humidity. This value is sent to the sensor for
16+ humidity compensation.
17+ Default value: 50000 (50 % relative humidity)
18+
19+What: /sys/bus/iio/devices/iio:deviceX/in_resistance_calibbias
20+Date: August 2021
21+KernelVersion: 5.15
22+Contact: Andreas Klinger <ak@it-klinger.de>
23+Description:
24+ Set the bias value for the resistance which is used for
25+ calculation of in_concentration_input as follows:
26+
27+ x = (in_resistance_raw - in_resistance_calibbias) * 0.65
28+
29+ in_concentration_input = 500 / (1 + e^x)
30+
31+ Default value: 30000
Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml+0−61
@@ -1,61 +0,0 @@
1−# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2−%YAML 1.2
3−---
4−$id: http://devicetree.org/schemas/iio/accel/bosch,bma180.yaml#
5−$schema: http://devicetree.org/meta-schemas/core.yaml#
6−
7−title: Bosch BMA023 / BMA150/ BMA180 / BMA250 / SMB380 triaxial accelerometers
8−
9−maintainers:
10− - Jonathan Cameron <jic23@kernel.org>
11−
12−description: |
13− https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMA150.pdf
14− http://omapworld.com/BMA180_111_1002839.pdf
15− http://ae-bst.resource.bosch.com/media/products/dokumente/bma250/bst-bma250-ds002-05.pdf
16−
17−properties:
18− compatible:
19− enum:
20− - bosch,bma023
21− - bosch,bma150
22− - bosch,bma180
23− - bosch,bma250
24− - bosch,smb380
25−
26− reg:
27− maxItems: 1
28−
29− vdd-supply: true
30−
31− vddio-supply: true
32−
33− interrupts:
34− minItems: 1
35− maxItems: 2
36− description: |
37− Type should be either IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING.
38− For the bma250 the first interrupt listed must be the one
39− connected to the INT1 pin, the second (optional) interrupt
40− listed must be the one connected to the INT2 pin.
41−
42−required:
43− - compatible
44− - reg
45−
46−additionalProperties: false
47−
48−examples:
49− - |
50− #include <dt-bindings/interrupt-controller/irq.h>
51− i2c {
52− #address-cells = <1>;
53− #size-cells = <0>;
54− accel@40 {
55− compatible = "bosch,bma180";
56− reg = <0x40>;
57− interrupt-parent = <&gpio6>;
58− interrupts = <18 (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)>;
59− };
60− };
61−...
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml+46−9
@@ -8,6 +8,7 @@ title: Bosch BMA255 and Similar Accelerometers · 7 unmodified lines
88
99 maintainers:
1010 - Linus Walleij <linus.walleij@linaro.org>
11+ - Stephan Gerhold <stephan@gerhold.net>
1112
1213 description:
1314 3 axis accelerometers with varying range and I2C or SPI
@@ -16,15 +17,24 @@ description: · 2 unmodified lines
1617 properties:
1718 compatible:
1819 enum:
19− - bosch,bmc150_accel
20− - bosch,bmi055_accel
20+ # bmc150-accel driver in Linux
21+ - bosch,bma222
22+ - bosch,bma222e
23+ - bosch,bma250e
2124 - bosch,bma253
2225 - bosch,bma254
2326 - bosch,bma255
24− - bosch,bma250e
25− - bosch,bma222
26− - bosch,bma222e
2727 - bosch,bma280
28+ - bosch,bmc150_accel
29+ - bosch,bmc156_accel
30+ - bosch,bmi055_accel
31+
32+ # bma180 driver in Linux
33+ - bosch,bma023
34+ - bosch,bma150
35+ - bosch,bma180
36+ - bosch,bma250
37+ - bosch,smb380
2838
2939 reg:
3040 maxItems: 1
@@ -36,9 +46,21 @@ properties: · 5 unmodified lines
3646 minItems: 1
3747 maxItems: 2
3848 description: |
39− The first interrupt listed must be the one connected to the INT1 pin,
40− the second (optional) interrupt listed must be the one connected to the
41− INT2 pin (if available).
49+ Without interrupt-names, the first interrupt listed must be the one
50+ connected to the INT1 pin, the second (optional) interrupt listed must be
51+ the one connected to the INT2 pin (if available). The type should be
52+ IRQ_TYPE_EDGE_RISING.
53+
54+ BMC156 does not have an INT1 pin, therefore the first interrupt pin is
55+ always treated as INT2.
56+
57+ interrupt-names:
58+ minItems: 1
59+ maxItems: 2
60+ items:
61+ enum:
62+ - INT1
63+ - INT2
4264
4365 mount-matrix:
4466 description: an optional 3x3 mounting rotation matrix.
@@ -63,7 +85,22 @@ examples: · 18 unmodified lines
6385 reg = <0x08>;
6486 vddio-supply = <&vddio>;
6587 vdd-supply = <&vdd>;
66− interrupts = <57 IRQ_TYPE_EDGE_FALLING>;
88+ interrupts = <57 IRQ_TYPE_EDGE_RISING>;
89+ interrupt-names = "INT1";
90+ };
91+ };
92+ - |
93+ #include <dt-bindings/interrupt-controller/irq.h>
94+ i2c {
95+ #address-cells = <1>;
96+ #size-cells = <0>;
97+ accelerometer@10 {
98+ compatible = "bosch,bmc156_accel";
99+ reg = <0x10>;
100+ vddio-supply = <&vddio>;
101+ vdd-supply = <&vdd>;
102+ interrupts = <116 IRQ_TYPE_EDGE_RISING>;
103+ interrupt-names = "INT2";
67104 };
68105 };
69106 - |
Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml+19−0
@@ -23,6 +23,8 @@ properties: · 22 unmodified lines
2323 enum:
2424 - ingenic,jz4725b-adc
2525 - ingenic,jz4740-adc
26+ - ingenic,jz4760-adc
27+ - ingenic,jz4760b-adc
2628 - ingenic,jz4770-adc
2729
2830 '#io-channel-cells':
@@ -43,6 +45,23 @@ properties: · 14 unmodified lines
4345 interrupts:
4446 maxItems: 1
4547
48+ ingenic,use-internal-divider:
49+ description:
50+ If present, battery voltage is read from the VBAT_IR pin, which has an
51+ internal 1/4 divider. If absent, it is read through the VBAT_ER pin,
52+ which does not have such a divider.
53+ type: boolean
54+
55+if:
56+ not:
57+ properties:
58+ compatible:
59+ contains:
60+ const: ingenic,jz4760b-adc
61+then:
62+ properties:
63+ ingenic,use-internal-divider: false
64+
4665 required:
4766 - compatible
4867 - '#io-channel-cells'
Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml+134−0
@@ -0,0 +1,134 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/adc/renesas,rzg2l-adc.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Renesas RZ/G2L ADC
8+
9+maintainers:
10+ - Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
11+
12+description: |
13+ A/D Converter block is a successive approximation analog-to-digital converter
14+ with a 12-bit accuracy. Up to eight analog input channels can be selected.
15+ Conversions can be performed in single or repeat mode. Result of the ADC is
16+ stored in a 32-bit data register corresponding to each channel.
17+
18+properties:
19+ compatible:
20+ items:
21+ - enum:
22+ - renesas,r9a07g044-adc # RZ/G2{L,LC}
23+ - const: renesas,rzg2l-adc
24+
25+ reg:
26+ maxItems: 1
27+
28+ interrupts:
29+ maxItems: 1
30+
31+ clocks:
32+ items:
33+ - description: converter clock
34+ - description: peripheral clock
35+
36+ clock-names:
37+ items:
38+ - const: adclk
39+ - const: pclk
40+
41+ power-domains:
42+ maxItems: 1
43+
44+ resets:
45+ maxItems: 2
46+
47+ reset-names:
48+ items:
49+ - const: presetn
50+ - const: adrst-n
51+
52+ '#address-cells':
53+ const: 1
54+
55+ '#size-cells':
56+ const: 0
57+
58+required:
59+ - compatible
60+ - reg
61+ - interrupts
62+ - clocks
63+ - clock-names
64+ - power-domains
65+ - resets
66+ - reset-names
67+
68+patternProperties:
69+ "^channel@[0-7]$":
70+ $ref: "adc.yaml"
71+ type: object
72+ description: |
73+ Represents the external channels which are connected to the ADC.
74+
75+ properties:
76+ reg:
77+ description: |
78+ The channel number. It can have up to 8 channels numbered from 0 to 7.
79+ items:
80+ - minimum: 0
81+ maximum: 7
82+
83+ required:
84+ - reg
85+
86+ additionalProperties: false
87+
88+additionalProperties: false
89+
90+examples:
91+ - |
92+ #include <dt-bindings/clock/r9a07g044-cpg.h>
93+ #include <dt-bindings/interrupt-controller/arm-gic.h>
94+
95+ adc: adc@10059000 {
96+ compatible = "renesas,r9a07g044-adc", "renesas,rzg2l-adc";
97+ reg = <0x10059000 0x400>;
98+ interrupts = <GIC_SPI 347 IRQ_TYPE_EDGE_RISING>;
99+ clocks = <&cpg CPG_MOD R9A07G044_ADC_ADCLK>,
100+ <&cpg CPG_MOD R9A07G044_ADC_PCLK>;
101+ clock-names = "adclk", "pclk";
102+ power-domains = <&cpg>;
103+ resets = <&cpg R9A07G044_ADC_PRESETN>,
104+ <&cpg R9A07G044_ADC_ADRST_N>;
105+ reset-names = "presetn", "adrst-n";
106+
107+ #address-cells = <1>;
108+ #size-cells = <0>;
109+
110+ channel@0 {
111+ reg = <0>;
112+ };
113+ channel@1 {
114+ reg = <1>;
115+ };
116+ channel@2 {
117+ reg = <2>;
118+ };
119+ channel@3 {
120+ reg = <3>;
121+ };
122+ channel@4 {
123+ reg = <4>;
124+ };
125+ channel@5 {
126+ reg = <5>;
127+ };
128+ channel@6 {
129+ reg = <6>;
130+ };
131+ channel@7 {
132+ reg = <7>;
133+ };
134+ };
Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml+1−0
@@ -20,6 +20,7 @@ properties: · 19 unmodified lines
2020 - rockchip,px30-saradc
2121 - rockchip,rk3308-saradc
2222 - rockchip,rk3328-saradc
23+ - rockchip,rk3568-saradc
2324 - rockchip,rv1108-saradc
2425 - const: rockchip,rk3399-saradc
2526
Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml+268−0
@@ -0,0 +1,268 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5064.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5064 and similar DACs
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+description: |
14+ A range of similar DAC devices with between 1 and 12 channels. Some parts
15+ have internal references, others require a single shared external reference
16+ and the remainder have a separate reference pin for each DAC.
17+
18+properties:
19+ compatible:
20+ oneOf:
21+ - description: I2C devics
22+ enum:
23+ - adi,ad5024
24+ - adi,ad5025
25+ - adi,ad5044
26+ - adi,ad5045
27+ - adi,ad5064
28+ - adi,ad5064-1
29+ - adi,ad5065
30+ - adi,ad5628-1
31+ - adi,ad5628-2
32+ - adi,ad5648-1
33+ - adi,ad5648-2
34+ - adi,ad5666-1
35+ - adi,ad5666-2
36+ - adi,ad5668-1
37+ - adi,ad5668-2
38+ - adi,ad5668-3
39+ - description: SPI devices
40+ enum:
41+ - adi,ad5625
42+ - adi,ad5625r-1v25
43+ - adi,ad5625r-2v5
44+ - adi,ad5627
45+ - adi,ad5627r-1v25
46+ - adi,ad5627r-2v5
47+ - adi,ad5629-1
48+ - adi,ad5629-2
49+ - adi,ad5629-3
50+ - adi,ad5645r-1v25
51+ - adi,ad5645r-2v5
52+ - adi,ad5665
53+ - adi,ad5665r-1v25
54+ - adi,ad5665r-2v5
55+ - adi,ad5667
56+ - adi,ad5667r-1v25
57+ - adi,ad5667r-2v5
58+ - adi,ad5669-1
59+ - adi,ad5669-2
60+ - adi,ad5669-3
61+ - lltc,ltc2606
62+ - lltc,ltc2607
63+ - lltc,ltc2609
64+ - lltc,ltc2616
65+ - lltc,ltc2617
66+ - lltc,ltc2619
67+ - lltc,ltc2626
68+ - lltc,ltc2627
69+ - lltc,ltc2629
70+ - lltc,ltc2631-l12
71+ - lltc,ltc2631-h12
72+ - lltc,ltc2631-l10
73+ - lltc,ltc2631-h10
74+ - lltc,ltc2631-l8
75+ - lltc,ltc2631-h8
76+ - lltc,ltc2633-l12
77+ - lltc,ltc2633-h12
78+ - lltc,ltc2633-l10
79+ - lltc,ltc2633-h10
80+ - lltc,ltc2633-l8
81+ - lltc,ltc2633-h8
82+ - lltc,ltc2635-l12
83+ - lltc,ltc2635-h12
84+ - lltc,ltc2635-l10
85+ - lltc,ltc2635-h10
86+ - lltc,ltc2635-l8
87+ - lltc,ltc2635-h8
88+
89+ reg:
90+ maxItems: 1
91+
92+ vrefA-supply: true
93+ vrefB-supply: true
94+ vrefC-supply: true
95+ vrefD-supply: true
96+ vref-supply: true
97+
98+ spi-max-frequency: true
99+
100+additionalProperties: false
101+
102+required:
103+ - compatible
104+ - reg
105+
106+allOf:
107+ - # Shared external vref, no internal reference
108+ if:
109+ properties:
110+ compatible:
111+ contains:
112+ enum:
113+ - adi,ad5064-1
114+ - adi,ad5625
115+ - adi,ad5627
116+ - adi,ad5665
117+ - adi,ad5667
118+ - lltc,ltc2606
119+ - lltc,ltc2607
120+ - lltc,ltc2616
121+ - lltc,ltc2617
122+ - lltc,ltc2626
123+ - lltc,ltc2627
124+ then:
125+ properties:
126+ vref-supply: true
127+ vrefA-supply: false
128+ vrefB-supply: false
129+ vrefC-supply: false
130+ vrefD-supply: false
131+ required:
132+ - vref-supply
133+ - # Shared external vref, internal reference available
134+ if:
135+ properties:
136+ compatible:
137+ contains:
138+ enum:
139+ - adi,ad5625r-1v25
140+ - adi,ad5625r-2v5
141+ - adi,ad5627r-1v25
142+ - adi,ad5627r-2v5
143+ - adi,ad5628-1
144+ - adi,ad5628-2
145+ - adi,ad5629-1
146+ - adi,ad5629-2
147+ - adi,ad5629-3
148+ - adi,ad5645r-1v25
149+ - adi,ad5645r-2v5
150+ - adi,ad5647r-1v25
151+ - adi,ad5647r-2v5
152+ - adi,ad5648-1
153+ - adi,ad5648-2
154+ - adi,ad5665r-1v25
155+ - adi,ad5665r-2v5
156+ - adi,ad5666-1
157+ - adi,ad5666-2
158+ - adi,ad5667r-1v25
159+ - adi,ad5667r-2v5
160+ - adi,ad5668-1
161+ - adi,ad5668-2
162+ - adi,ad5668-3
163+ - adi,ad5669-1
164+ - adi,ad5669-2
165+ - adi,ad5669-3
166+ - lltc,ltc2631-l12
167+ - lltc,ltc2631-h12
168+ - lltc,ltc2631-l10
169+ - lltc,ltc2631-h10
170+ - lltc,ltc2631-l8
171+ - lltc,ltc2631-h8
172+ - lltc,ltc2633-l12
173+ - lltc,ltc2633-h12
174+ - lltc,ltc2633-l10
175+ - lltc,ltc2633-h10
176+ - lltc,ltc2633-l8
177+ - lltc,ltc2633-h8
178+ - lltc,ltc2635-l12
179+ - lltc,ltc2635-h12
180+ - lltc,ltc2635-l10
181+ - lltc,ltc2635-h10
182+ - lltc,ltc2635-l8
183+ - lltc,ltc2635-h8
184+ then:
185+ properties:
186+ vref-supply: true
187+ vrefA-supply: false
188+ vrefB-supply: false
189+ vrefC-supply: false
190+ vrefD-supply: false
191+ - # 4 input devices, separate vrefs, no internal reference
192+ if:
193+ properties:
194+ compatible:
195+ contains:
196+ enum:
197+ - adi,ad5024
198+ - adi,ad5044
199+ - adi,ad5064
200+ - lltc,ltc2609
201+ - lltc,ltc2619
202+ - lltc,ltc2629
203+ then:
204+ properties:
205+ vrefA-supply: true
206+ vrefB-supply: true
207+ vrefC-supply: true
208+ vrefD-supply: true
209+ vref-supply: false
210+ required:
211+ - vrefA-supply
212+ - vrefB-supply
213+ - vrefC-supply
214+ - vrefD-supply
215+ - # 2 input devices, separate vrefs, no internal reference
216+ if:
217+ properties:
218+ compatible:
219+ contains:
220+ enum:
221+ - adi,ad5025
222+ - adi,ad5045
223+ - adi,ad5065
224+ then:
225+ properties:
226+ vrefA-supply: true
227+ vrefB-supply: true
228+ vrefC-supply: false
229+ vrefD-supply: false
230+ vref-supply: false
231+ required:
232+ - vrefA-supply
233+ - vrefB-supply
234+
235+examples:
236+ - |
237+ spi {
238+ #address-cells = <1>;
239+ #size-cells = <0>;
240+ dac@0 {
241+ reg = <0>;
242+ compatible = "adi,ad5625";
243+ vref-supply = <&dac_vref>;
244+ };
245+ };
246+ - |
247+ spi {
248+ #address-cells = <1>;
249+ #size-cells = <0>;
250+ dac@0 {
251+ reg = <0>;
252+ compatible = "adi,ad5625r-1v25";
253+ };
254+ };
255+ - |
256+ i2c {
257+ #address-cells = <1>;
258+ #size-cells = <0>;
259+ dac@42 {
260+ reg = <0x42>;
261+ compatible = "adi,ad5024";
262+ vrefA-supply = <&dac_vref>;
263+ vrefB-supply = <&dac_vref>;
264+ vrefC-supply = <&dac_vref2>;
265+ vrefD-supply = <&dac_vref2>;
266+ };
267+ };
268+...
Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml+79−0
@@ -0,0 +1,79 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5360.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5360 and similar DACs
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+properties:
14+ compatible:
15+ enum:
16+ - adi,ad5360
17+ - adi,ad5361
18+ - adi,ad5363
19+ - adi,ad5370
20+ - adi,ad5371
21+ - adi,ad5372
22+ - adi,ad5373
23+
24+ reg:
25+ maxItems: 1
26+
27+ vref0-supply: true
28+ vref1-supply: true
29+ vref2-supply: true
30+
31+ spi-max-frequency: true
32+
33+additionalProperties: false
34+
35+required:
36+ - compatible
37+ - reg
38+ - vref0-supply
39+ - vref1-supply
40+
41+allOf:
42+ - if:
43+ properties:
44+ compatible:
45+ contains:
46+ enum:
47+ - adi,ad5360
48+ - adi,ad5361
49+ - adi,ad5363
50+ - adi,ad5370
51+ - adi,ad5372
52+ - adi,ad5373
53+ then:
54+ properties:
55+ vref2-supply: false
56+ - if:
57+ properties:
58+ compatible:
59+ contains:
60+ enum:
61+ - adi,ad5371
62+ then:
63+ required:
64+ - vref2-supply
65+
66+examples:
67+ - |
68+ spi {
69+ #address-cells = <1>;
70+ #size-cells = <0>;
71+ dac@0 {
72+ reg = <0>;
73+ compatible = "adi,ad5371";
74+ vref0-supply = <&dac_vref0>;
75+ vref1-supply = <&dac_vref1>;
76+ vref2-supply = <&dac_vref2>;
77+ };
78+ };
79+...
Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml+70−0
@@ -0,0 +1,70 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5380.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5380 and similar DACs
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+description: |
14+ DAC devices supporting both SPI and I2C interfaces.
15+properties:
16+ compatible:
17+ enum:
18+ - adi,ad5380-3
19+ - adi,ad5380-5
20+ - adi,ad5381-3
21+ - adi,ad5381-5
22+ - adi,ad5382-3
23+ - adi,ad5382-5
24+ - adi,ad5383-3
25+ - adi,ad5383-5
26+ - adi,ad5384-3
27+ - adi,ad5384-5
28+ - adi,ad5390-3
29+ - adi,ad5390-5
30+ - adi,ad5391-3
31+ - adi,ad5391-5
32+ - adi,ad5392-3
33+ - adi,ad5392-5
34+
35+ reg:
36+ maxItems: 1
37+
38+ vref-supply:
39+ description:
40+ If not supplied devices will use internal regulators.
41+
42+ spi-max-frequency: true
43+
44+additionalProperties: false
45+
46+required:
47+ - compatible
48+ - reg
49+
50+examples:
51+ - |
52+ spi {
53+ #address-cells = <1>;
54+ #size-cells = <0>;
55+ dac@0 {
56+ reg = <0>;
57+ compatible = "adi,ad5390-5";
58+ vref-supply = <&dacvref>;
59+ };
60+ };
61+ - |
62+ i2c {
63+ #address-cells = <1>;
64+ #size-cells = <0>;
65+ dac@42 {
66+ reg = <0x42>;
67+ compatible = "adi,ad5380-3";
68+ };
69+ };
70+...
Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml+51−0
@@ -0,0 +1,51 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5421.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5421 DAC
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+description: |
14+ AD5421 is designed for us in loop-powered, 4 mA to 20 mA smart transmitter
15+ applications. It provides a 16-bit DAC, current amplifier, voltage regulator
16+ to drive the loop and a voltage reference.
17+
18+properties:
19+ compatible:
20+ const: adi,ad5421
21+
22+ reg:
23+ maxItems: 1
24+
25+ interrupts:
26+ maxItems: 1
27+ description: Fault signal.
28+
29+ spi-max-frequency: true
30+
31+required:
32+ - compatible
33+ - reg
34+
35+additionalProperties: false
36+
37+examples:
38+ - |
39+ #include <dt-bindings/interrupt-controller/irq.h>
40+ spi {
41+ #address-cells = <1>;
42+ #size-cells = <0>;
43+
44+ dac@0 {
45+ compatible = "adi,ad5421";
46+ reg = <0>;
47+ spi-max-frequency = <30000000>;
48+ interrupts = <55 IRQ_TYPE_LEVEL_HIGH>;
49+ };
50+ };
51+...
Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml+97−0
@@ -0,0 +1,97 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5449.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5449 and similar DACs
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+description:
14+ Family of multiplying DACs from Analog Devices
15+
16+properties:
17+ compatible:
18+ enum:
19+ - adi,ad5415
20+ - adi,ad5426
21+ - adi,ad5429
22+ - adi,ad5432
23+ - adi,ad5439
24+ - adi,ad5443
25+ - adi,ad5449
26+
27+ reg:
28+ maxItems: 1
29+
30+ spi-max-frequency: true
31+
32+ VREF-supply: true
33+ VREFA-supply: true
34+ VREFB-supply: true
35+
36+additionalProperties: false
37+
38+required:
39+ - compatible
40+ - reg
41+
42+allOf:
43+ - if:
44+ properties:
45+ compatible:
46+ contains:
47+ enum:
48+ - adi,ad5415
49+ - adi,ad5426
50+ - adi,ad5432
51+ then:
52+ properties:
53+ VREF-supply: true
54+ VREFA-supply: false
55+ VREFB-supply: false
56+ required:
57+ - VREF-supply
58+ - if:
59+ properties:
60+ compatible:
61+ contains:
62+ enum:
63+ - adi,ad5429
64+ - adi,ad5439
65+ - adi,ad5449
66+ then:
67+ properties:
68+ VREF-supply: false
69+ VREFA-supply: true
70+ VREFB-supply: true
71+ required:
72+ - VREFA-supply
73+ - VREFB-supply
74+
75+examples:
76+ - |
77+ spi {
78+ #address-cells = <1>;
79+ #size-cells = <0>;
80+ dac@0 {
81+ reg = <0>;
82+ compatible = "adi,ad5415";
83+ VREF-supply = <&dac_ref>;
84+ };
85+ };
86+ - |
87+ spi {
88+ #address-cells = <1>;
89+ #size-cells = <0>;
90+ dac@0 {
91+ reg = <0>;
92+ compatible = "adi,ad5429";
93+ VREFA-supply = <&dac_refA>;
94+ VREFB-supply = <&dac_refB>;
95+ };
96+ };
97+...
Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml+50−0
@@ -0,0 +1,50 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5504.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5501 and AD5504 DACs
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+description:
14+ High voltage (up to 60V) DACs with temperature sensor alarm function
15+
16+properties:
17+ compatible:
18+ enum:
19+ - adi,ad5501
20+ - adi,ad5504
21+
22+ reg:
23+ maxItems: 1
24+
25+ interrupts:
26+ description: Used for temperature alarm.
27+ maxItems: 1
28+
29+ vcc-supply: true
30+
31+additionalProperties: false
32+
33+required:
34+ - compatible
35+ - reg
36+
37+examples:
38+ - |
39+ #include <dt-bindings/interrupt-controller/irq.h>
40+ spi {
41+ #address-cells = <1>;
42+ #size-cells = <0>;
43+ dac@0 {
44+ reg = <0>;
45+ compatible = "adi,ad5504";
46+ vcc-supply = <&dac_vcc>;
47+ interrupts = <55 IRQ_TYPE_EDGE_FALLING>;
48+ };
49+ };
50+...
Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml+47−0
@@ -0,0 +1,47 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5624r.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5624r and similar DACs
8+
9+maintainers:
10+ - Jonathan Cameron <jic23@kernel.org>
11+
12+properties:
13+ compatible:
14+ enum:
15+ - adi,ad5624r3
16+ - adi,ad5644r3
17+ - adi,ad5664r3
18+ - adi,ad5624r5
19+ - adi,ad5644r5
20+ - adi,ad5664r5
21+
22+ reg:
23+ maxItems: 1
24+
25+ spi-max-frequency: true
26+
27+ vref-supply:
28+ description: If not present, internal reference will be used.
29+
30+additionalProperties: false
31+
32+required:
33+ - compatible
34+ - reg
35+
36+examples:
37+ - |
38+ spi {
39+ #address-cells = <1>;
40+ #size-cells = <0>;
41+ dac@0 {
42+ reg = <0>;
43+ compatible = "adi,ad5624r3";
44+ vref-supply = <&vref>;
45+ };
46+ };
47+...
Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml+75−0
@@ -0,0 +1,75 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5686.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5360 and similar DACs
8+
9+maintainers:
10+ - Michael Hennerich <michael.hennerich@analog.com>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+properties:
14+ compatible:
15+ oneOf:
16+ - description: SPI devices
17+ enum:
18+ - adi,ad5310r
19+ - adi,ad5672r
20+ - adi,ad5674r
21+ - adi,ad5676
22+ - adi,ad5676r
23+ - adi,ad5679r
24+ - adi,ad5681r
25+ - adi,ad5682r
26+ - adi,ad5683
27+ - adi,ad5683r
28+ - adi,ad5684
29+ - adi,ad5684r
30+ - adi,ad5685r
31+ - adi,ad5686
32+ - adi,ad5686r
33+ - description: I2C devices
34+ enum:
35+ - adi,ad5311r
36+ - adi,ad5338r
37+ - adi,ad5671r
38+ - adi,ad5675r
39+ - adi,ad5691r
40+ - adi,ad5692r
41+ - adi,ad5693
42+ - adi,ad5693r
43+ - adi,ad5694
44+ - adi,ad5694r
45+ - adi,ad5695r
46+ - adi,ad5696
47+ - adi,ad5696r
48+
49+
50+ reg:
51+ maxItems: 1
52+
53+ vcc-supply:
54+ description: If not supplied the internal reference is used.
55+
56+ spi-max-frequency: true
57+
58+additionalProperties: false
59+
60+required:
61+ - compatible
62+ - reg
63+
64+examples:
65+ - |
66+ spi {
67+ #address-cells = <1>;
68+ #size-cells = <0>;
69+ dac@0 {
70+ reg = <0>;
71+ compatible = "adi,ad5310r";
72+ vcc-supply = <&dac_vref0>;
73+ };
74+ };
75+...
Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml+60−0
@@ -0,0 +1,60 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5761.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5761 and similar DACs
8+
9+maintainers:
10+ - Ricardo Ribalda <ribalda@kernel.org>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+properties:
14+
15+ compatible:
16+ enum:
17+ - adi,ad5721
18+ - adi,ad5721r
19+ - adi,ad5761
20+ - adi,ad5761r
21+
22+ reg:
23+ maxItems: 1
24+
25+ spi-max-frequency: true
26+
27+ vref-supply:
28+ description: If not supplied, internal reference will be used.
29+
30+additionalProperties: false
31+
32+required:
33+ - compatible
34+ - reg
35+
36+allOf:
37+ - if:
38+ properties:
39+ compatible:
40+ contains:
41+ enum:
42+ - adi,ad5721
43+ - adi,ad5761
44+ then:
45+ required:
46+ - vref-supply
47+
48+examples:
49+ - |
50+ spi {
51+ #address-cells = <1>;
52+ #size-cells = <0>;
53+
54+ dac@0 {
55+ compatible = "adi,ad5721";
56+ reg = <0>;
57+ vref-supply = <&dac_vref>;
58+ };
59+ };
60+...
Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml+62−0
@@ -0,0 +1,62 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5764.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5744 and AD5764 DAC families
8+
9+maintainers:
10+ - Lars-Peter Clausen <lars@metafoo.de>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+properties:
14+
15+ compatible:
16+ enum:
17+ - adi,ad5744
18+ - adi,ad5744r
19+ - adi,ad5764
20+ - adi,ad5764r
21+
22+ reg:
23+ maxItems: 1
24+
25+ spi-max-frequency: true
26+
27+ vrefAB-supply: true
28+ vrefCD-supply: true
29+
30+additionalProperties: false
31+
32+required:
33+ - compatible
34+ - reg
35+
36+allOf:
37+ - if:
38+ properties:
39+ compatible:
40+ contains:
41+ enum:
42+ - adi,ad5744
43+ - adi,ad5764
44+ then:
45+ required:
46+ - vrefAB-supply
47+ - vrefCD-supply
48+
49+examples:
50+ - |
51+ spi {
52+ #address-cells = <1>;
53+ #size-cells = <0>;
54+
55+ dac@0 {
56+ compatible = "adi,ad5744";
57+ reg = <0>;
58+ vrefAB-supply = <&dac_vref>;
59+ vrefCD-supply = <&dac_vref>;
60+ };
61+ };
62+...
Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml+52−0
@@ -0,0 +1,52 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad5791.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD5791 and similar DACs
8+
9+maintainers:
10+ - Michael Hennerich <michael.hennerich@analog.com>
11+ - Jonathan Cameron <jic23@kernel.org>
12+
13+properties:
14+
15+ compatible:
16+ enum:
17+ - adi,ad5760
18+ - adi,ad5780
19+ - adi,ad5781
20+ - adi,ad5790
21+ - adi,ad5791
22+
23+ reg:
24+ maxItems: 1
25+
26+ spi-max-frequency: true
27+
28+ vdd-supply: true
29+ vss-supply: true
30+
31+additionalProperties: false
32+
33+required:
34+ - compatible
35+ - reg
36+ - vdd-supply
37+ - vss-supply
38+
39+examples:
40+ - |
41+ spi {
42+ #address-cells = <1>;
43+ #size-cells = <0>;
44+
45+ dac@0 {
46+ compatible = "adi,ad5791";
47+ reg = <0>;
48+ vss-supply = <&dac_vss>;
49+ vdd-supply = <&dac_vdd>;
50+ };
51+ };
52+...
Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml+60−0
@@ -0,0 +1,60 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/adi,ad8801.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD8801 and AD8803 DACs
8+
9+maintainers:
10+ - Jonathan Cameron <jic23@kernel.org>
11+
12+properties:
13+
14+ compatible:
15+ enum:
16+ - adi,ad8801
17+ - adi,ad8803
18+
19+ reg:
20+ maxItems: 1
21+
22+ spi-max-frequency: true
23+
24+ vrefh-supply: true
25+ vrefl-supply: true
26+
27+additionalProperties: false
28+
29+required:
30+ - compatible
31+ - reg
32+ - vrefh-supply
33+
34+allOf:
35+ - if:
36+ properties:
37+ compatible:
38+ contains:
39+ const: adi,ad8803
40+ then:
41+ required:
42+ - vrefl-supply
43+ else:
44+ properties:
45+ vrefl-supply: false
46+
47+examples:
48+ - |
49+ spi {
50+ #address-cells = <1>;
51+ #size-cells = <0>;
52+
53+ dac@0 {
54+ compatible = "adi,ad8803";
55+ reg = <0>;
56+ vrefl-supply = <&dac_vrefl>;
57+ vrefh-supply = <&dac_vrefh>;
58+ };
59+ };
60+...
Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml+46−0
@@ -0,0 +1,46 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/dac/microchip,mcp4922.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Microchip MCP4902, MCP4912 and MPC4922 dual output SPI DACs
8+
9+maintainers:
10+ - Jonathan Cameron <jic23@kernel.org>
11+ - Michael Welling <mwelling@ieee.org>
12+
13+properties:
14+ compatible:
15+ enum:
16+ - microchip,mcp4902
17+ - microchip,mcp4912
18+ - microchip,mcp4922
19+
20+ reg:
21+ maxItems: 1
22+
23+ spi-max-frequency: true
24+
25+ vref-supply: true
26+
27+additionalProperties: false
28+
29+required:
30+ - compatible
31+ - reg
32+ - vref-supply
33+
34+examples:
35+ - |
36+ spi {
37+ #address-cells = <1>;
38+ #size-cells = <0>;
39+
40+ dac@0 {
41+ compatible = "microchip,mcp4912";
42+ reg = <0>;
43+ vref-supply = <&dac_vref>;
44+ };
45+ };
46+...
Documentation/devicetree/bindings/mfd/hisilicon,hi6421-spmi-pmic.yamlrenamed from drivers/staging/hikey9xx/hisilicon,hi6421-spmi-pmic.yaml+17−14
@@ -34,13 +34,14 @@ properties: · 33 unmodified lines
3434
3535 interrupt-controller: true
3636
37− gpios:
37+ interrupts:
3838 maxItems: 1
39− description: GPIO used for IRQs
4039
4140 regulators:
4241 type: object
4342
43+ additionalProperties: false
44+
4445 properties:
4546 '#address-cells':
4647 const: 1
@@ -49,11 +50,13 @@ properties: · 2 unmodified lines
4950 const: 0
5051
5152 patternProperties:
52− '^ldo[0-9]+@[0-9a-f]$':
53+ '^ldo[0-9]+$':
5354 type: object
5455
5556 $ref: "/schemas/regulator/regulator.yaml#"
5657
58+ unevaluatedProperties: false
59+
5760 required:
5861 - compatible
5962 - reg
@@ -63,69 +66,69 @@ additionalProperties: false · 3 unmodified lines
6366
6467 examples:
6568 - |
66− /* pmic properties */
6769
6870 pmic: pmic@0 {
69− compatible = "hisilicon,hi6421-spmi";
71+ compatible = "hisilicon,hi6421v600-spmi";
7072 reg = <0 0>;
7173
7274 #interrupt-cells = <2>;
7375 interrupt-controller;
74− gpios = <&gpio28 0 0>;
76+ interrupt-parent = <&gpio28>;
77+ interrupts = <0 0>;
7578
7679 regulators {
7780 #address-cells = <1>;
7881 #size-cells = <0>;
7982
80− ldo3: LDO3 {
83+ ldo3: ldo3 {
8184 regulator-name = "ldo3";
8285 regulator-min-microvolt = <1500000>;
8386 regulator-max-microvolt = <2000000>;
8487 regulator-boot-on;
8588 };
8689
87− ldo4: LDO4 {
90+ ldo4: ldo4 {
8891 regulator-name = "ldo4";
8992 regulator-min-microvolt = <1725000>;
9093 regulator-max-microvolt = <1900000>;
9194 regulator-boot-on;
9295 };
9396
94− ldo9: LDO9 {
97+ ldo9: ldo9 {
9598 regulator-name = "ldo9";
9699 regulator-min-microvolt = <1750000>;
97100 regulator-max-microvolt = <3300000>;
98101 regulator-boot-on;
99102 };
100103
101− ldo15: LDO15 {
104+ ldo15: ldo15 {
102105 regulator-name = "ldo15";
103106 regulator-min-microvolt = <1800000>;
104107 regulator-max-microvolt = <3000000>;
105108 regulator-always-on;
106109 };
107110
108− ldo16: LDO16 {
111+ ldo16: ldo16 {
109112 regulator-name = "ldo16";
110113 regulator-min-microvolt = <1800000>;
111114 regulator-max-microvolt = <3000000>;
112115 regulator-boot-on;
113116 };
114117
115− ldo17: LDO17 {
118+ ldo17: ldo17 {
116119 regulator-name = "ldo17";
117120 regulator-min-microvolt = <2500000>;
118121 regulator-max-microvolt = <3300000>;
119122 };
120123
121− ldo33: LDO33 {
124+ ldo33: ldo33 {
122125 regulator-name = "ldo33";
123126 regulator-min-microvolt = <2500000>;
124127 regulator-max-microvolt = <3300000>;
125128 regulator-boot-on;
126129 };
127130
128− ldo34: LDO34 {
131+ ldo34: ldo34 {
129132 regulator-name = "ldo34";
130133 regulator-min-microvolt = <2600000>;
131134 regulator-max-microvolt = <3300000>;
Documentation/devicetree/bindings/trivial-devices.yaml+6−0
@@ -33,6 +33,8 @@ properties: · 32 unmodified lines
3333 - ad,ad7414
3434 # ADM9240: Complete System Hardware Monitor for uProcessor-Based Systems
3535 - ad,adm9240
36+ # AD5110 - Nonvolatile Digital Potentiometer
37+ - adi,ad5110
3638 # Analog Devices ADP5585 Keypad Decoder and I/O Expansion
3739 - adi,adp5585
3840 # Analog Devices ADP5585 Keypad Decoder and I/O Expansion with support for Row5
@@ -61,6 +63,8 @@ properties: · 22 unmodified lines
6163 - capella,cm32181
6264 # CM3232: Ambient Light Sensor
6365 - capella,cm3232
66+ # CM3323: Ambient Light Sensor
67+ - capella,cm3323
6468 # High-Precision Digital Thermometer
6569 - dallas,ds1631
6670 # Total-Elapsed-Time Recorder with Alarm
@@ -269,6 +273,8 @@ properties: · 202 unmodified lines
269273 - sensirion,sgpc3
270274 # Sensirion multi-pixel gas sensor with I2C interface
271275 - sensirion,sgp30
276+ # Sensirion gas sensor with I2C interface
277+ - sensirion,sgp40
272278 # Sensortek 3 axis accelerometer
273279 - sensortek,stk8312
274280 # Sensortek 3 axis accelerometer
MAINTAINERS+27−4
@@ -459,6 +459,12 @@ S: Maintained · 458 unmodified lines
459459 W: https://parisc.wiki.kernel.org/index.php/AD1889
460460 F: sound/pci/ad1889.*
461461
462+AD5110 ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER
463+M: Mugilraj Dhavachelvan <dmugil2000@gmail.com>
464+L: linux-iio@vger.kernel.org
465+S: Supported
466+F: drivers/iio/potentiometer/ad5110.c
467+
462468 AD525X ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER
463469 M: Michael Hennerich <michael.hennerich@analog.com>
464470 S: Supported
@@ -8462,10 +8468,12 @@ S: Maintained · 7997 unmodified lines
84628468 F: Documentation/devicetree/bindings/spmi/hisilicon,hisi-spmi-controller.yaml
84638469 F: drivers/spmi/hisi-spmi-controller.c
84648470
8465−HISILICON STAGING DRIVERS FOR HIKEY 960/970
8471+HISILICON SPMI PMIC DRIVER FOR HIKEY 6421v600
84668472 M: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
8473+L: linux-kernel@vger.kernel.org
84678474 S: Maintained
8468−F: drivers/staging/hikey9xx/
8475+F: Documentation/devicetree/bindings/mfd/hisilicon,hi6421-spmi-pmic.yaml
8476+F: drivers/mfd/hi6421-spmi-pmic.c
84698477
84708478 HISILICON TRUE RANDOM NUMBER GENERATOR V2 SUPPORT
84718479 M: Zaibo Xu <xuzaibo@huawei.com>
@@ -15899,6 +15907,14 @@ L: linux-renesas-soc@vger.kernel.org · 7427 unmodified lines
1589915907 S: Maintained
1590015908 F: drivers/phy/renesas/phy-rcar-gen3-usb*.c
1590115909
15910+RENESAS RZ/G2L A/D DRIVER
15911+M: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
15912+L: linux-iio@vger.kernel.org
15913+L: linux-renesas-soc@vger.kernel.org
15914+S: Supported
15915+F: Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml
15916+F: drivers/iio/adc/rzg2l_adc.c
15917+
1590215918 RESET CONTROLLER FRAMEWORK
1590315919 M: Philipp Zabel <p.zabel@pengutronix.de>
1590415920 S: Maintained
@@ -16766,6 +16782,12 @@ F: drivers/iio/chemical/scd30_core.c · 861 unmodified lines
1676616782 F: drivers/iio/chemical/scd30_i2c.c
1676716783 F: drivers/iio/chemical/scd30_serial.c
1676816784
16785+SENSIRION SGP40 GAS SENSOR DRIVER
16786+M: Andreas Klinger <ak@it-klinger.de>
16787+S: Maintained
16788+F: Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40
16789+F: drivers/iio/chemical/sgp40.c
16790+
1676916791 SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
1677016792 M: Tomasz Duszynski <tduszyns@gmail.com>
1677116793 S: Maintained
@@ -17670,8 +17692,9 @@ F: drivers/staging/olpc_dcon/ · 898 unmodified lines
1767017692
1767117693 STAGING - REALTEK RTL8188EU DRIVERS
1767217694 M: Larry Finger <Larry.Finger@lwfinger.net>
17673−S: Odd Fixes
17674−F: drivers/staging/rtl8188eu/
17695+M: Phillip Potter <phil@philpotter.co.uk>
17696+S: Supported
17697+F: drivers/staging/r8188eu/
1767517698
1767617699 STAGING - REALTEK RTL8712U DRIVERS
1767717700 M: Larry Finger <Larry.Finger@lwfinger.net>
drivers/counter/104-quad-8.c+29−18
@@ -28,6 +28,7 @@ MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses"); · 27 unmodified lines
2828
2929 /**
3030 * struct quad8 - device private data structure
31+ * @lock: lock to prevent clobbering device states during R/W ops
3132 * @counter: instance of the counter_device
3233 * @fck_prescaler: array of filter clock prescaler configurations
3334 * @preset: array of preset values
@@ -97,7 +98,8 @@ struct quad8 { · 63 unmodified lines
9798 #define QUAD8_CMR_QUADRATURE_X4 0x18
9899
99100 static int quad8_signal_read(struct counter_device *counter,
100− struct counter_signal *signal, enum counter_signal_value *val)
101+ struct counter_signal *signal,
102+ enum counter_signal_level *level)
101103 {
102104 const struct quad8 *const priv = counter->priv;
103105 unsigned int state;
@@ -109,7 +111,7 @@ static int quad8_signal_read(struct counter_device *counter, · 5 unmodified lines
109111 state = inb(priv->base + QUAD8_REG_INDEX_INPUT_LEVELS)
110112 & BIT(signal->id - 16);
111113
112− *val = (state) ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW;
114+ *level = (state) ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
113115
114116 return 0;
115117 }
@@ -154,7 +156,7 @@ static int quad8_count_write(struct counter_device *counter, · 38 unmodified lines
154156
155157 /* Only 24-bit values are supported */
156158 if (val > 0xFFFFFF)
157− return -EINVAL;
159+ return -ERANGE;
158160
159161 mutex_lock(&priv->lock);
160162
@@ -193,11 +195,11 @@ enum quad8_count_function { · 32 unmodified lines
193195 QUAD8_COUNT_FUNCTION_QUADRATURE_X4
194196 };
195197
196−static const enum counter_count_function quad8_count_functions_list[] = {
197− [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = COUNTER_COUNT_FUNCTION_PULSE_DIRECTION,
198− [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A,
199− [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A,
200− [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4
198+static const enum counter_function quad8_count_functions_list[] = {
199+ [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = COUNTER_FUNCTION_PULSE_DIRECTION,
200+ [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = COUNTER_FUNCTION_QUADRATURE_X1_A,
201+ [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = COUNTER_FUNCTION_QUADRATURE_X2_A,
202+ [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = COUNTER_FUNCTION_QUADRATURE_X4
201203 };
202204
203205 static int quad8_function_get(struct counter_device *counter,
@@ -273,6 +275,10 @@ static int quad8_function_set(struct counter_device *counter, · 69 unmodified lines
273275 *scale = 2;
274276 mode_cfg |= QUAD8_CMR_QUADRATURE_X4;
275277 break;
278+ default:
279+ /* should never reach this path */
280+ mutex_unlock(&priv->lock);
281+ return -EINVAL;
276282 }
277283 }
278284
@@ -349,7 +355,7 @@ static int quad8_action_get(struct counter_device *counter, · 70 unmodified lines
349355 case QUAD8_COUNT_FUNCTION_PULSE_DIRECTION:
350356 if (synapse->signal->id == signal_a_id)
351357 *action = QUAD8_SYNAPSE_ACTION_RISING_EDGE;
352− break;
358+ return 0;
353359 case QUAD8_COUNT_FUNCTION_QUADRATURE_X1:
354360 if (synapse->signal->id == signal_a_id) {
355361 quad8_direction_get(counter, count, &direction);
@@ -359,17 +365,18 @@ static int quad8_action_get(struct counter_device *counter, · 3 unmodified lines
359365 else
360366 *action = QUAD8_SYNAPSE_ACTION_FALLING_EDGE;
361367 }
362− break;
368+ return 0;
363369 case QUAD8_COUNT_FUNCTION_QUADRATURE_X2:
364370 if (synapse->signal->id == signal_a_id)
365371 *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES;
366− break;
372+ return 0;
367373 case QUAD8_COUNT_FUNCTION_QUADRATURE_X4:
368374 *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES;
369− break;
375+ return 0;
376+ default:
377+ /* should never reach this path */
378+ return -EINVAL;
370379 }
371−
372− return 0;
373380 }
374381
375382 static const struct counter_ops quad8_ops = {
@@ -529,6 +536,9 @@ static int quad8_count_mode_set(struct counter_device *counter, · 153 unmodified lines
529536 case COUNTER_COUNT_MODE_MODULO_N:
530537 cnt_mode = 3;
531538 break;
539+ default:
540+ /* should never reach this path */
541+ return -EINVAL;
532542 }
533543
534544 mutex_lock(&priv->lock);
@@ -661,7 +671,7 @@ static ssize_t quad8_count_preset_write(struct counter_device *counter, · 126 unmodified lines
661671
662672 /* Only 24-bit values are supported */
663673 if (preset > 0xFFFFFF)
664− return -EINVAL;
674+ return -ERANGE;
665675
666676 mutex_lock(&priv->lock);
667677
@@ -706,7 +716,7 @@ static ssize_t quad8_count_ceiling_write(struct counter_device *counter, · 38 unmodified lines
706716
707717 /* Only 24-bit values are supported */
708718 if (ceiling > 0xFFFFFF)
709− return -EINVAL;
719+ return -ERANGE;
710720
711721 mutex_lock(&priv->lock);
712722
@@ -715,12 +725,13 @@ static ssize_t quad8_count_ceiling_write(struct counter_device *counter, · 2 unmodified lines
715725 case 1:
716726 case 3:
717727 quad8_preset_register_set(priv, count->id, ceiling);
718− break;
728+ mutex_unlock(&priv->lock);
729+ return len;
719730 }
720731
721732 mutex_unlock(&priv->lock);
722733
723− return len;
734+ return -EINVAL;
724735 }
725736
726737 static ssize_t quad8_count_preset_enable_read(struct counter_device *counter,
drivers/counter/counter.c+25−25
@@ -289,9 +289,9 @@ struct counter_signal_unit { · 288 unmodified lines
289289 struct counter_signal *signal;
290290 };
291291
292−static const char *const counter_signal_value_str[] = {
293− [COUNTER_SIGNAL_LOW] = "low",
294− [COUNTER_SIGNAL_HIGH] = "high"
292+static const char *const counter_signal_level_str[] = {
293+ [COUNTER_SIGNAL_LEVEL_LOW] = "low",
294+ [COUNTER_SIGNAL_LEVEL_HIGH] = "high"
295295 };
296296
297297 static ssize_t counter_signal_show(struct device *dev,
@@ -302,13 +302,13 @@ static ssize_t counter_signal_show(struct device *dev, · 4 unmodified lines
302302 const struct counter_signal_unit *const component = devattr->component;
303303 struct counter_signal *const signal = component->signal;
304304 int err;
305− enum counter_signal_value val;
305+ enum counter_signal_level level;
306306
307− err = counter->ops->signal_read(counter, signal, &val);
307+ err = counter->ops->signal_read(counter, signal, &level);
308308 if (err)
309309 return err;
310310
311− return sprintf(buf, "%s\n", counter_signal_value_str[val]);
311+ return sprintf(buf, "%s\n", counter_signal_level_str[level]);
312312 }
313313
314314 struct counter_name_unit {
@@ -744,15 +744,15 @@ static ssize_t counter_count_store(struct device *dev, · 429 unmodified lines
744744 return len;
745745 }
746746
747−static const char *const counter_count_function_str[] = {
748− [COUNTER_COUNT_FUNCTION_INCREASE] = "increase",
749− [COUNTER_COUNT_FUNCTION_DECREASE] = "decrease",
750− [COUNTER_COUNT_FUNCTION_PULSE_DIRECTION] = "pulse-direction",
751− [COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a",
752− [COUNTER_COUNT_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b",
753− [COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a",
754− [COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b",
755− [COUNTER_COUNT_FUNCTION_QUADRATURE_X4] = "quadrature x4"
747+static const char *const counter_function_str[] = {
748+ [COUNTER_FUNCTION_INCREASE] = "increase",
749+ [COUNTER_FUNCTION_DECREASE] = "decrease",
750+ [COUNTER_FUNCTION_PULSE_DIRECTION] = "pulse-direction",
751+ [COUNTER_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a",
752+ [COUNTER_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b",
753+ [COUNTER_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a",
754+ [COUNTER_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b",
755+ [COUNTER_FUNCTION_QUADRATURE_X4] = "quadrature x4"
756756 };
757757
758758 static ssize_t counter_function_show(struct device *dev,
@@ -764,7 +764,7 @@ static ssize_t counter_function_show(struct device *dev, · 5 unmodified lines
764764 const struct counter_count_unit *const component = devattr->component;
765765 struct counter_count *const count = component->count;
766766 size_t func_index;
767− enum counter_count_function function;
767+ enum counter_function function;
768768
769769 err = counter->ops->function_get(counter, count, &func_index);
770770 if (err)
@@ -773,7 +773,7 @@ static ssize_t counter_function_show(struct device *dev, · 2 unmodified lines
773773 count->function = func_index;
774774
775775 function = count->functions_list[func_index];
776− return sprintf(buf, "%s\n", counter_count_function_str[function]);
776+ return sprintf(buf, "%s\n", counter_function_str[function]);
777777 }
778778
779779 static ssize_t counter_function_store(struct device *dev,
@@ -785,14 +785,14 @@ static ssize_t counter_function_store(struct device *dev, · 5 unmodified lines
785785 struct counter_count *const count = component->count;
786786 const size_t num_functions = count->num_functions;
787787 size_t func_index;
788− enum counter_count_function function;
788+ enum counter_function function;
789789 int err;
790790 struct counter_device *const counter = dev_get_drvdata(dev);
791791
792792 /* Find requested Count function mode */
793793 for (func_index = 0; func_index < num_functions; func_index++) {
794794 function = count->functions_list[func_index];
795− if (sysfs_streq(buf, counter_count_function_str[function]))
795+ if (sysfs_streq(buf, counter_function_str[function]))
796796 break;
797797 }
798798 /* Return error if requested Count function mode not found */
@@ -880,25 +880,25 @@ err_free_attr_list: · 81 unmodified lines
880880 }
881881
882882 struct counter_func_avail_unit {
883− const enum counter_count_function *functions_list;
883+ const enum counter_function *functions_list;
884884 size_t num_functions;
885885 };
886886
887−static ssize_t counter_count_function_available_show(struct device *dev,
887+static ssize_t counter_function_available_show(struct device *dev,
888888 struct device_attribute *attr, char *buf)
889889 {
890890 const struct counter_device_attr *const devattr = to_counter_attr(attr);
891891 const struct counter_func_avail_unit *const component = devattr->component;
892− const enum counter_count_function *const func_list = component->functions_list;
892+ const enum counter_function *const func_list = component->functions_list;
893893 const size_t num_functions = component->num_functions;
894894 size_t i;
895− enum counter_count_function function;
895+ enum counter_function function;
896896 ssize_t len = 0;
897897
898898 for (i = 0; i < num_functions; i++) {
899899 function = func_list[i];
900900 len += sprintf(buf + len, "%s\n",
901− counter_count_function_str[function]);
901+ counter_function_str[function]);
902902 }
903903
904904 return len;
@@ -968,7 +968,7 @@ static int counter_count_attributes_create( · 63 unmodified lines
968968 parm.group = group;
969969 parm.prefix = "";
970970 parm.name = "function_available";
971− parm.show = counter_count_function_available_show;
971+ parm.show = counter_function_available_show;
972972 parm.store = NULL;
973973 parm.component = avail_comp;
974974 err = counter_attribute_create(&parm);
drivers/counter/ftm-quaddec.c+2−3
@@ -171,9 +171,8 @@ enum ftm_quaddec_count_function { · 170 unmodified lines
171171 FTM_QUADDEC_COUNT_ENCODER_MODE_1,
172172 };
173173
174−static const enum counter_count_function ftm_quaddec_count_functions[] = {
175− [FTM_QUADDEC_COUNT_ENCODER_MODE_1] =
176− COUNTER_COUNT_FUNCTION_QUADRATURE_X4
174+static const enum counter_function ftm_quaddec_count_functions[] = {
175+ [FTM_QUADDEC_COUNT_ENCODER_MODE_1] = COUNTER_FUNCTION_QUADRATURE_X4
177176 };
178177
179178 static int ftm_quaddec_count_read(struct counter_device *counter,
drivers/counter/intel-qep.c+3−4
@@ -8,7 +8,6 @@ · 7 unmodified lines
88 * Author: Jarkko Nikula <jarkko.nikula@linux.intel.com>
99 * Author: Raymond Tan <raymond.tan@intel.com>
1010 */
11−#include <linux/bitops.h>
1211 #include <linux/counter.h>
1312 #include <linux/kernel.h>
1413 #include <linux/module.h>
@@ -127,8 +126,8 @@ static int intel_qep_count_read(struct counter_device *counter, · 112 unmodified lines
127126 return 0;
128127 }
129128
130−static const enum counter_count_function intel_qep_count_functions[] = {
131− COUNTER_COUNT_FUNCTION_QUADRATURE_X4,
129+static const enum counter_function intel_qep_count_functions[] = {
130+ COUNTER_FUNCTION_QUADRATURE_X4,
132131 };
133132
134133 static int intel_qep_function_get(struct counter_device *counter,
@@ -320,7 +319,7 @@ static ssize_t spike_filter_ns_write(struct counter_device *counter, · 185 unmodified lines
320319 }
321320
322321 if (length > INTEL_QEPFLT_MAX_COUNT(length))
323− return -EINVAL;
322+ return -ERANGE;
324323
325324 mutex_lock(&qep->lock);
326325 if (qep->enabled) {
drivers/counter/interrupt-cnt.c+7−4
@@ -107,13 +107,16 @@ static int interrupt_cnt_write(struct counter_device *counter, · 106 unmodified lines
107107 {
108108 struct interrupt_cnt_priv *priv = counter->priv;
109109
110+ if (val != (typeof(priv->count.counter))val)
111+ return -ERANGE;
112+
110113 atomic_set(&priv->count, val);
111114
112115 return 0;
113116 }
114117
115−static const enum counter_count_function interrupt_cnt_functions[] = {
116− COUNTER_COUNT_FUNCTION_INCREASE,
118+static const enum counter_function interrupt_cnt_functions[] = {
119+ COUNTER_FUNCTION_INCREASE,
117120 };
118121
119122 static int interrupt_cnt_function_get(struct counter_device *counter,
@@ -127,7 +130,7 @@ static int interrupt_cnt_function_get(struct counter_device *counter, · 7 unmodified lines
127130
128131 static int interrupt_cnt_signal_read(struct counter_device *counter,
129132 struct counter_signal *signal,
130− enum counter_signal_value *val)
133+ enum counter_signal_level *level)
131134 {
132135 struct interrupt_cnt_priv *priv = counter->priv;
133136 int ret;
@@ -139,7 +142,7 @@ static int interrupt_cnt_signal_read(struct counter_device *counter, · 5 unmodified lines
139142 if (ret < 0)
140143 return ret;
141144
142− *val = ret ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW;
145+ *level = ret ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
143146
144147 return 0;
145148 }
drivers/counter/microchip-tcb-capture.c+11−5
@@ -37,9 +37,9 @@ enum mchp_tc_count_function { · 36 unmodified lines
3737 MCHP_TC_FUNCTION_QUADRATURE,
3838 };
3939
40−static const enum counter_count_function mchp_tc_count_functions[] = {
41− [MCHP_TC_FUNCTION_INCREASE] = COUNTER_COUNT_FUNCTION_INCREASE,
42− [MCHP_TC_FUNCTION_QUADRATURE] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4,
40+static const enum counter_function mchp_tc_count_functions[] = {
41+ [MCHP_TC_FUNCTION_INCREASE] = COUNTER_FUNCTION_INCREASE,
42+ [MCHP_TC_FUNCTION_QUADRATURE] = COUNTER_FUNCTION_QUADRATURE_X4,
4343 };
4444
4545 enum mchp_tc_synapse_action {
@@ -133,6 +133,9 @@ static int mchp_tc_count_function_set(struct counter_device *counter, · 87 unmodified lines
133133 bmr |= ATMEL_TC_QDEN | ATMEL_TC_POSEN;
134134 cmr |= ATMEL_TC_ETRGEDG_RISING | ATMEL_TC_ABETRG | ATMEL_TC_XC0;
135135 break;
136+ default:
137+ /* should never reach this path */
138+ return -EINVAL;
136139 }
137140
138141 regmap_write(priv->regmap, ATMEL_TC_BMR, bmr);
@@ -155,7 +158,7 @@ static int mchp_tc_count_function_set(struct counter_device *counter, · 16 unmodified lines
155158
156159 static int mchp_tc_count_signal_read(struct counter_device *counter,
157160 struct counter_signal *signal,
158− enum counter_signal_value *val)
161+ enum counter_signal_level *lvl)
159162 {
160163 struct mchp_tc_data *const priv = counter->priv;
161164 bool sigstatus;
@@ -168,7 +171,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter, · 6 unmodified lines
168171 else
169172 sigstatus = (sr & ATMEL_TC_MTIOA);
170173
171− *val = sigstatus ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW;
174+ *lvl = sigstatus ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
172175
173176 return 0;
174177 }
@@ -226,6 +229,9 @@ static int mchp_tc_count_action_set(struct counter_device *counter, · 51 unmodified lines
226229 case MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE:
227230 edge = ATMEL_TC_ETRGEDG_BOTH;
228231 break;
232+ default:
233+ /* should never reach this path */
234+ return -EINVAL;
229235 }
230236
231237 return regmap_write_bits(priv->regmap,
drivers/counter/stm32-lptimer-cnt.c+10−8
@@ -134,9 +134,9 @@ enum stm32_lptim_cnt_function { · 133 unmodified lines
134134 STM32_LPTIM_ENCODER_BOTH_EDGE,
135135 };
136136
137−static const enum counter_count_function stm32_lptim_cnt_functions[] = {
138− [STM32_LPTIM_COUNTER_INCREASE] = COUNTER_COUNT_FUNCTION_INCREASE,
139− [STM32_LPTIM_ENCODER_BOTH_EDGE] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4,
137+static const enum counter_function stm32_lptim_cnt_functions[] = {
138+ [STM32_LPTIM_COUNTER_INCREASE] = COUNTER_FUNCTION_INCREASE,
139+ [STM32_LPTIM_ENCODER_BOTH_EDGE] = COUNTER_FUNCTION_QUADRATURE_X4,
140140 };
141141
142142 enum stm32_lptim_synapse_action {
@@ -206,9 +206,10 @@ static int stm32_lptim_cnt_function_set(struct counter_device *counter, · 63 unmodified lines
206206 priv->quadrature_mode = 1;
207207 priv->polarity = STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES;
208208 return 0;
209+ default:
210+ /* should never reach this path */
211+ return -EINVAL;
209212 }
210−
211− return -EINVAL;
212213 }
213214
214215 static ssize_t stm32_lptim_cnt_enable_read(struct counter_device *counter,
@@ -282,7 +283,7 @@ static ssize_t stm32_lptim_cnt_ceiling_write(struct counter_device *counter, · 67 unmodified lines
282283 return ret;
283284
284285 if (ceiling > STM32_LPTIM_MAX_ARR)
285− return -EINVAL;
286+ return -ERANGE;
286287
287288 priv->ceiling = ceiling;
288289
@@ -326,9 +327,10 @@ static int stm32_lptim_cnt_action_get(struct counter_device *counter, · 37 unmodified lines
326327 case STM32_LPTIM_ENCODER_BOTH_EDGE:
327328 *action = priv->polarity;
328329 return 0;
330+ default:
331+ /* should never reach this path */
332+ return -EINVAL;
329333 }
330−
331− return -EINVAL;
332334 }
333335
334336 static int stm32_lptim_cnt_action_set(struct counter_device *counter,
drivers/counter/stm32-timer-cnt.c+5−5
@@ -50,11 +50,11 @@ enum stm32_count_function { · 49 unmodified lines
5050 STM32_COUNT_ENCODER_MODE_3,
5151 };
5252
53−static const enum counter_count_function stm32_count_functions[] = {
54− [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_COUNT_FUNCTION_INCREASE,
55− [STM32_COUNT_ENCODER_MODE_1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A,
56− [STM32_COUNT_ENCODER_MODE_2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B,
57− [STM32_COUNT_ENCODER_MODE_3] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4,
53+static const enum counter_function stm32_count_functions[] = {
54+ [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_FUNCTION_INCREASE,
55+ [STM32_COUNT_ENCODER_MODE_1] = COUNTER_FUNCTION_QUADRATURE_X2_A,
56+ [STM32_COUNT_ENCODER_MODE_2] = COUNTER_FUNCTION_QUADRATURE_X2_B,
57+ [STM32_COUNT_ENCODER_MODE_3] = COUNTER_FUNCTION_QUADRATURE_X4,
5858 };
5959
6060 static int stm32_count_read(struct counter_device *counter,
drivers/counter/ti-eqep.c+21−16
@@ -157,7 +157,7 @@ static int ti_eqep_action_get(struct counter_device *counter, · 156 unmodified lines
157157 * QEPA and QEPB trigger QCLK.
158158 */
159159 *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES;
160− break;
160+ return 0;
161161 case TI_EQEP_COUNT_FUNC_DIR_COUNT:
162162 /* In direction-count mode only rising edge of QEPA is counted
163163 * and QEPB gives direction.
@@ -165,12 +165,14 @@ static int ti_eqep_action_get(struct counter_device *counter, · 1 unmodified line
165165 switch (synapse->signal->id) {
166166 case TI_EQEP_SIGNAL_QEPA:
167167 *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE;
168− break;
169− default:
168+ return 0;
169+ case TI_EQEP_SIGNAL_QEPB:
170170 *action = TI_EQEP_SYNAPSE_ACTION_NONE;
171− break;
171+ return 0;
172+ default:
173+ /* should never reach this path */
174+ return -EINVAL;
172175 }
173− break;
174176 case TI_EQEP_COUNT_FUNC_UP_COUNT:
175177 case TI_EQEP_COUNT_FUNC_DOWN_COUNT:
176178 /* In up/down-count modes only QEPA is counted and QEPB is not
@@ -186,15 +188,18 @@ static int ti_eqep_action_get(struct counter_device *counter, · 9 unmodified lines
186188 *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES;
187189 else
188190 *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE;
189− break;
190− default:
191+ return 0;
192+ case TI_EQEP_SIGNAL_QEPB:
191193 *action = TI_EQEP_SYNAPSE_ACTION_NONE;
192− break;
194+ return 0;
195+ default:
196+ /* should never reach this path */
197+ return -EINVAL;
193198 }
194− break;
199+ default:
200+ /* should never reach this path */
201+ return -EINVAL;
195202 }
196−
197− return 0;
198203 }
199204
200205 static const struct counter_ops ti_eqep_counter_ops = {
@@ -289,11 +294,11 @@ static struct counter_signal ti_eqep_signals[] = { · 88 unmodified lines
289294 },
290295 };
291296
292−static const enum counter_count_function ti_eqep_position_functions[] = {
293− [TI_EQEP_COUNT_FUNC_QUAD_COUNT] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4,
294− [TI_EQEP_COUNT_FUNC_DIR_COUNT] = COUNTER_COUNT_FUNCTION_PULSE_DIRECTION,
295− [TI_EQEP_COUNT_FUNC_UP_COUNT] = COUNTER_COUNT_FUNCTION_INCREASE,
296− [TI_EQEP_COUNT_FUNC_DOWN_COUNT] = COUNTER_COUNT_FUNCTION_DECREASE,
297+static const enum counter_function ti_eqep_position_functions[] = {
298+ [TI_EQEP_COUNT_FUNC_QUAD_COUNT] = COUNTER_FUNCTION_QUADRATURE_X4,
299+ [TI_EQEP_COUNT_FUNC_DIR_COUNT] = COUNTER_FUNCTION_PULSE_DIRECTION,
300+ [TI_EQEP_COUNT_FUNC_UP_COUNT] = COUNTER_FUNCTION_INCREASE,
301+ [TI_EQEP_COUNT_FUNC_DOWN_COUNT] = COUNTER_FUNCTION_DECREASE,
297302 };
298303
299304 static const enum counter_synapse_action ti_eqep_position_synapse_actions[] = {
drivers/iio/accel/Kconfig+3−2
@@ -143,10 +143,11 @@ config BMC150_ACCEL · 142 unmodified lines
143143 select BMC150_ACCEL_SPI if SPI
144144 help
145145 Say yes here to build support for the following Bosch accelerometers:
146− BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055.
146+ BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156
147+ BMI055.
147148
148149 Note that some of these are combo modules:
149− - BMC150: accelerometer and magnetometer
150+ - BMC150/BMC156: accelerometer and magnetometer
150151 - BMI055: accelerometer and gyroscope
151152
152153 This driver is only implementing accelerometer part, which has
drivers/iio/accel/adxl345.h+0−1
@@ -15,6 +15,5 @@ enum adxl345_device_type { · 14 unmodified lines
1515
1616 int adxl345_core_probe(struct device *dev, struct regmap *regmap,
1717 enum adxl345_device_type type, const char *name);
18−int adxl345_core_remove(struct device *dev);
1918
2019 #endif /* _ADXL345_H_ */
drivers/iio/accel/adxl345_core.c+9−20
@@ -208,6 +208,11 @@ static const struct iio_info adxl345_info = { · 207 unmodified lines
208208 .write_raw_get_fmt = adxl345_write_raw_get_fmt,
209209 };
210210
211+static void adxl345_powerdown(void *regmap)
212+{
213+ regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY);
214+}
215+
211216 int adxl345_core_probe(struct device *dev, struct regmap *regmap,
212217 enum adxl345_device_type type, const char *name)
213218 {
@@ -233,7 +238,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, · 19 unmodified lines
233238 return -ENOMEM;
234239
235240 data = iio_priv(indio_dev);
236− dev_set_drvdata(dev, indio_dev);
237241 data->regmap = regmap;
238242 data->type = type;
239243 /* Enable full-resolution mode */
@@ -260,29 +264,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, · 20 unmodified lines
260264 return ret;
261265 }
262266
263− ret = iio_device_register(indio_dev);
264− if (ret < 0) {
265− dev_err(dev, "iio_device_register failed: %d\n", ret);
266− regmap_write(data->regmap, ADXL345_REG_POWER_CTL,
267− ADXL345_POWER_CTL_STANDBY);
268− }
267+ ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap);
268+ if (ret < 0)
269+ return ret;
269270
270− return ret;
271+ return devm_iio_device_register(dev, indio_dev);
271272 }
272273 EXPORT_SYMBOL_GPL(adxl345_core_probe);
273274
274−int adxl345_core_remove(struct device *dev)
275−{
276− struct iio_dev *indio_dev = dev_get_drvdata(dev);
277− struct adxl345_data *data = iio_priv(indio_dev);
278−
279− iio_device_unregister(indio_dev);
280−
281− return regmap_write(data->regmap, ADXL345_REG_POWER_CTL,
282− ADXL345_POWER_CTL_STANDBY);
283−}
284−EXPORT_SYMBOL_GPL(adxl345_core_remove);
285−
286275 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
287276 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer core driver");
288277 MODULE_LICENSE("GPL v2");
drivers/iio/accel/adxl345_i2c.c+0−6
@@ -38,11 +38,6 @@ static int adxl345_i2c_probe(struct i2c_client *client, · 37 unmodified lines
3838 id->name);
3939 }
4040
41−static int adxl345_i2c_remove(struct i2c_client *client)
42−{
43− return adxl345_core_remove(&client->dev);
44−}
45−
4641 static const struct i2c_device_id adxl345_i2c_id[] = {
4742 { "adxl345", ADXL345 },
4843 { "adxl375", ADXL375 },
@@ -65,7 +60,6 @@ static struct i2c_driver adxl345_i2c_driver = { · 16 unmodified lines
6560 .of_match_table = adxl345_of_match,
6661 },
6762 .probe = adxl345_i2c_probe,
68− .remove = adxl345_i2c_remove,
6963 .id_table = adxl345_i2c_id,
7064 };
7165
drivers/iio/accel/adxl345_spi.c+0−6
@@ -42,11 +42,6 @@ static int adxl345_spi_probe(struct spi_device *spi) · 41 unmodified lines
4242 return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name);
4343 }
4444
45−static int adxl345_spi_remove(struct spi_device *spi)
46−{
47− return adxl345_core_remove(&spi->dev);
48−}
49−
5045 static const struct spi_device_id adxl345_spi_id[] = {
5146 { "adxl345", ADXL345 },
5247 { "adxl375", ADXL375 },
@@ -69,7 +64,6 @@ static struct spi_driver adxl345_spi_driver = { · 16 unmodified lines
6964 .of_match_table = adxl345_of_match,
7065 },
7166 .probe = adxl345_spi_probe,
72− .remove = adxl345_spi_remove,
7367 .id_table = adxl345_spi_id,
7468 };
7569
drivers/iio/accel/bma220_spi.c+37−42
@@ -218,20 +218,33 @@ static int bma220_init(struct spi_device *spi) · 217 unmodified lines
218218 return 0;
219219 }
220220
221−static int bma220_deinit(struct spi_device *spi)
221+static int bma220_power(struct spi_device *spi, bool up)
222222 {
223− int ret;
224−
225− /* Make sure the chip is powered off */
226− ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
227− if (ret == BMA220_SUSPEND_SLEEP)
223+ int i, ret;
224+
225+ /**
226+ * The chip can be suspended/woken up by a simple register read.
227+ * So, we need up to 2 register reads of the suspend register
228+ * to make sure that the device is in the desired state.
229+ */
230+ for (i = 0; i < 2; i++) {
228231 ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
229− if (ret < 0)
230− return ret;
231− if (ret == BMA220_SUSPEND_SLEEP)
232− return -EBUSY;
232+ if (ret < 0)
233+ return ret;
233234
234− return 0;
235+ if (up && ret == BMA220_SUSPEND_SLEEP)
236+ return 0;
237+
238+ if (!up && ret == BMA220_SUSPEND_WAKE)
239+ return 0;
240+ }
241+
242+ return -EBUSY;
243+}
244+
245+static void bma220_deinit(void *spi)
246+{
247+ bma220_power(spi, false);
235248 }
236249
237250 static int bma220_probe(struct spi_device *spi)
@@ -248,7 +261,6 @@ static int bma220_probe(struct spi_device *spi) · 10 unmodified lines
248261
249262 data = iio_priv(indio_dev);
250263 data->spi_device = spi;
251− spi_set_drvdata(spi, indio_dev);
252264 mutex_init(&data->lock);
253265
254266 indio_dev->info = &bma220_info;
@@ -262,49 +274,33 @@ static int bma220_probe(struct spi_device *spi) · 7 unmodified lines
262274 if (ret)
263275 return ret;
264276
265− ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
266− bma220_trigger_handler, NULL);
267− if (ret < 0) {
268− dev_err(&spi->dev, "iio triggered buffer setup failed\n");
269− goto err_suspend;
270− }
277+ ret = devm_add_action_or_reset(&spi->dev, bma220_deinit, spi);
278+ if (ret)
279+ return ret;
271280
272− ret = iio_device_register(indio_dev);
281+ ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
282+ iio_pollfunc_store_time,
283+ bma220_trigger_handler, NULL);
273284 if (ret < 0) {
274− dev_err(&spi->dev, "iio_device_register failed\n");
275− iio_triggered_buffer_cleanup(indio_dev);
276− goto err_suspend;
285+ dev_err(&spi->dev, "iio triggered buffer setup failed\n");
286+ return ret;
277287 }
278288
279− return 0;
280−
281−err_suspend:
282− return bma220_deinit(spi);
283−}
284−
285−static int bma220_remove(struct spi_device *spi)
286−{
287− struct iio_dev *indio_dev = spi_get_drvdata(spi);
288−
289− iio_device_unregister(indio_dev);
290− iio_triggered_buffer_cleanup(indio_dev);
291−
292− return bma220_deinit(spi);
289+ return devm_iio_device_register(&spi->dev, indio_dev);
293290 }
294291
295292 static __maybe_unused int bma220_suspend(struct device *dev)
296293 {
297− struct bma220_data *data = iio_priv(dev_get_drvdata(dev));
294+ struct spi_device *spi = to_spi_device(dev);
298295
299− /* The chip can be suspended/woken up by a simple register read. */
300− return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND);
296+ return bma220_power(spi, false);
301297 }
302298
303299 static __maybe_unused int bma220_resume(struct device *dev)
304300 {
305− struct bma220_data *data = iio_priv(dev_get_drvdata(dev));
301+ struct spi_device *spi = to_spi_device(dev);
306302
307− return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND);
303+ return bma220_power(spi, true);
308304 }
309305 static SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume);
310306
@@ -326,7 +322,6 @@ static struct spi_driver bma220_driver = { · 15 unmodified lines
326322 .acpi_match_table = bma220_acpi_id,
327323 },
328324 .probe = bma220_probe,
329− .remove = bma220_remove,
330325 .id_table = bma220_spi_id,
331326 };
332327 module_spi_driver(bma220_driver);
drivers/iio/accel/bmc150-accel-core.c+64−14
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/delay.h>
1111 #include <linux/slab.h>
1212 #include <linux/acpi.h>
13+#include <linux/of_irq.h>
1314 #include <linux/pm.h>
1415 #include <linux/pm_runtime.h>
1516 #include <linux/iio/iio.h>
@@ -57,12 +58,18 @@ · 41 unmodified lines
5758 #define BMC150_ACCEL_RESET_VAL 0xB6
5859
5960 #define BMC150_ACCEL_REG_INT_MAP_0 0x19
60−#define BMC150_ACCEL_INT_MAP_0_BIT_SLOPE BIT(2)
61+#define BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE BIT(2)
6162
6263 #define BMC150_ACCEL_REG_INT_MAP_1 0x1A
63−#define BMC150_ACCEL_INT_MAP_1_BIT_DATA BIT(0)
64−#define BMC150_ACCEL_INT_MAP_1_BIT_FWM BIT(1)
65−#define BMC150_ACCEL_INT_MAP_1_BIT_FFULL BIT(2)
64+#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA BIT(0)
65+#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM BIT(1)
66+#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FFULL BIT(2)
67+#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FFULL BIT(5)
68+#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM BIT(6)
69+#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA BIT(7)
70+
71+#define BMC150_ACCEL_REG_INT_MAP_2 0x1B
72+#define BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE BIT(2)
6673
6774 #define BMC150_ACCEL_REG_INT_RST_LATCH 0x21
6875 #define BMC150_ACCEL_INT_MODE_LATCH_RESET 0x80
@@ -81,6 +88,7 @@ · 12 unmodified lines
8188
8289 #define BMC150_ACCEL_REG_INT_OUT_CTRL 0x20
8390 #define BMC150_ACCEL_INT_OUT_CTRL_INT1_LVL BIT(0)
91+#define BMC150_ACCEL_INT_OUT_CTRL_INT2_LVL BIT(2)
8492
8593 #define BMC150_ACCEL_REG_INT_5 0x27
8694 #define BMC150_ACCEL_SLOPE_DUR_MASK 0x03
@@ -476,21 +484,24 @@ static bool bmc150_apply_acpi_orientation(struct device *dev, · 389 unmodified lines
476484 }
477485 #endif
478486
479−static const struct bmc150_accel_interrupt_info {
487+struct bmc150_accel_interrupt_info {
480488 u8 map_reg;
481489 u8 map_bitmask;
482490 u8 en_reg;
483491 u8 en_bitmask;
484−} bmc150_accel_interrupts[BMC150_ACCEL_INTERRUPTS] = {
492+};
493+
494+static const struct bmc150_accel_interrupt_info
495+bmc150_accel_interrupts_int1[BMC150_ACCEL_INTERRUPTS] = {
485496 { /* data ready interrupt */
486497 .map_reg = BMC150_ACCEL_REG_INT_MAP_1,
487− .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_DATA,
498+ .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA,
488499 .en_reg = BMC150_ACCEL_REG_INT_EN_1,
489500 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN,
490501 },
491502 { /* motion interrupt */
492503 .map_reg = BMC150_ACCEL_REG_INT_MAP_0,
493− .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_SLOPE,
504+ .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE,
494505 .en_reg = BMC150_ACCEL_REG_INT_EN_0,
495506 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X |
496507 BMC150_ACCEL_INT_EN_BIT_SLP_Y |
@@ -498,19 +509,56 @@ static const struct bmc150_accel_interrupt_info { · 1 unmodified line
498509 },
499510 { /* fifo watermark interrupt */
500511 .map_reg = BMC150_ACCEL_REG_INT_MAP_1,
501− .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_FWM,
512+ .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM,
513+ .en_reg = BMC150_ACCEL_REG_INT_EN_1,
514+ .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN,
515+ },
516+};
517+
518+static const struct bmc150_accel_interrupt_info
519+bmc150_accel_interrupts_int2[BMC150_ACCEL_INTERRUPTS] = {
520+ { /* data ready interrupt */
521+ .map_reg = BMC150_ACCEL_REG_INT_MAP_1,
522+ .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA,
523+ .en_reg = BMC150_ACCEL_REG_INT_EN_1,
524+ .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN,
525+ },
526+ { /* motion interrupt */
527+ .map_reg = BMC150_ACCEL_REG_INT_MAP_2,
528+ .map_bitmask = BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE,
529+ .en_reg = BMC150_ACCEL_REG_INT_EN_0,
530+ .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X |
531+ BMC150_ACCEL_INT_EN_BIT_SLP_Y |
532+ BMC150_ACCEL_INT_EN_BIT_SLP_Z
533+ },
534+ { /* fifo watermark interrupt */
535+ .map_reg = BMC150_ACCEL_REG_INT_MAP_1,
536+ .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM,
502537 .en_reg = BMC150_ACCEL_REG_INT_EN_1,
503538 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN,
504539 },
505540 };
506541
507542 static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
508− struct bmc150_accel_data *data)
543+ struct bmc150_accel_data *data, int irq)
509544 {
545+ const struct bmc150_accel_interrupt_info *irq_info = NULL;
546+ struct device *dev = regmap_get_device(data->regmap);
510547 int i;
511548
549+ /*
550+ * For now we map all interrupts to the same output pin.
551+ * However, some boards may have just INT2 (and not INT1) connected,
552+ * so we try to detect which IRQ it is based on the interrupt-names.
553+ * Without interrupt-names, we assume the irq belongs to INT1.
554+ */
555+ irq_info = bmc150_accel_interrupts_int1;
556+ if (data->type == BOSCH_BMC156 ||
557+ irq == of_irq_get_byname(dev->of_node, "INT2"))
558+ irq_info = bmc150_accel_interrupts_int2;
559+
512560 for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
513− data->interrupts[i].info = &bmc150_accel_interrupts[i];
561+ data->interrupts[i].info = &irq_info[i];
514562 }
515563
516564 static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
@@ -1127,7 +1175,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { · 610 unmodified lines
11271175 {306458, BMC150_ACCEL_DEF_RANGE_16G} },
11281176 },
11291177 {
1130− .name = "BMA253/BMA254/BMA255/BMC150/BMI055",
1178+ .name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055",
11311179 .chip_id = 0xFA,
11321180 .channels = bmc150_accel_channels,
11331181 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1614,7 +1662,8 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data) · 480 unmodified lines
16141662 }
16151663
16161664 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
1617− const char *name, bool block_supported)
1665+ enum bmc150_type type, const char *name,
1666+ bool block_supported)
16181667 {
16191668 const struct attribute **fifo_attrs;
16201669 struct bmc150_accel_data *data;
@@ -1629,6 +1678,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, · 8 unmodified lines
16291678 dev_set_drvdata(dev, indio_dev);
16301679
16311680 data->regmap = regmap;
1681+ data->type = type;
16321682
16331683 if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) {
16341684 ret = iio_read_mount_matrix(dev, &data->orientation);
@@ -1714,7 +1764,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, · 79 unmodified lines
17141764 goto err_buffer_cleanup;
17151765 }
17161766
1717− bmc150_accel_interrupts_setup(indio_dev, data);
1767+ bmc150_accel_interrupts_setup(indio_dev, data, irq);
17181768
17191769 ret = bmc150_accel_triggers_setup(indio_dev, data);
17201770 if (ret)
drivers/iio/accel/bmc150-accel-i2c.c+8−2
@@ -176,6 +176,7 @@ static int bmc150_accel_probe(struct i2c_client *client, · 175 unmodified lines
176176 {
177177 struct regmap *regmap;
178178 const char *name = NULL;
179+ enum bmc150_type type = BOSCH_UNKNOWN;
179180 bool block_supported =
180181 i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
181182 i2c_check_functionality(client->adapter,
@@ -188,10 +189,13 @@ static int bmc150_accel_probe(struct i2c_client *client, · 6 unmodified lines
188189 return PTR_ERR(regmap);
189190 }
190191
191− if (id)
192+ if (id) {
192193 name = id->name;
194+ type = id->driver_data;
195+ }
193196
194− ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported);
197+ ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq,
198+ type, name, block_supported);
195199 if (ret)
196200 return ret;
197201
@@ -236,6 +240,7 @@ static const struct i2c_device_id bmc150_accel_id[] = { · 38 unmodified lines
236240 {"bma255"},
237241 {"bma280"},
238242 {"bmc150_accel"},
243+ {"bmc156_accel", BOSCH_BMC156},
239244 {"bmi055_accel"},
240245 {}
241246 };
@@ -251,6 +256,7 @@ static const struct of_device_id bmc150_accel_of_match[] = { · 9 unmodified lines
251256 { .compatible = "bosch,bma255" },
252257 { .compatible = "bosch,bma280" },
253258 { .compatible = "bosch,bmc150_accel" },
259+ { .compatible = "bosch,bmc156_accel" },
254260 { .compatible = "bosch,bmi055_accel" },
255261 { },
256262 };
drivers/iio/accel/bmc150-accel-spi.c+9−1
@@ -16,6 +16,8 @@ · 15 unmodified lines
1616 static int bmc150_accel_probe(struct spi_device *spi)
1717 {
1818 struct regmap *regmap;
19+ const char *name = NULL;
20+ enum bmc150_type type = BOSCH_UNKNOWN;
1921 const struct spi_device_id *id = spi_get_device_id(spi);
2022
2123 regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
@@ -24,7 +26,12 @@ static int bmc150_accel_probe(struct spi_device *spi) · 2 unmodified lines
2426 return PTR_ERR(regmap);
2527 }
2628
27− return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
29+ if (id) {
30+ name = id->name;
31+ type = id->driver_data;
32+ }
33+
34+ return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name,
2835 true);
2936 }
3037
@@ -54,6 +61,7 @@ static const struct spi_device_id bmc150_accel_id[] = { · 23 unmodified lines
5461 {"bma255"},
5562 {"bma280"},
5663 {"bmc150_accel"},
64+ {"bmc156_accel", BOSCH_BMC156},
5765 {"bmi055_accel"},
5866 {}
5967 };
drivers/iio/accel/bmc150-accel.h+19−1
@@ -13,6 +13,22 @@ struct i2c_client; · 12 unmodified lines
1313 struct bmc150_accel_chip_info;
1414 struct bmc150_accel_interrupt_info;
1515
16+/*
17+ * We can often guess better than "UNKNOWN" based on the device IDs
18+ * but unfortunately this information is not always accurate. There are some
19+ * devices where ACPI firmware specifies an ID like "BMA250E" when the device
20+ * actually has a BMA222E. The driver attempts to detect those by reading the
21+ * chip ID from the registers but this information is not always enough either.
22+ *
23+ * Therefore, this enum should be only used when the chip ID detection is not
24+ * enough and we can be reasonably sure that the device IDs are reliable
25+ * in practice (e.g. for device tree platforms).
26+ */
27+enum bmc150_type {
28+ BOSCH_UNKNOWN,
29+ BOSCH_BMC156,
30+};
31+
1632 struct bmc150_accel_interrupt {
1733 const struct bmc150_accel_interrupt_info *info;
1834 atomic_t users;
@@ -62,6 +78,7 @@ struct bmc150_accel_data { · 43 unmodified lines
6278 int ev_enable_state;
6379 int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
6480 const struct bmc150_accel_chip_info *chip_info;
81+ enum bmc150_type type;
6582 struct i2c_client *second_device;
6683 void (*resume_callback)(struct device *dev);
6784 struct delayed_work resume_work;
@@ -69,7 +86,8 @@ struct bmc150_accel_data { · 1 unmodified line
6986 };
7087
7188 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
72− const char *name, bool block_supported);
89+ enum bmc150_type type, const char *name,
90+ bool block_supported);
7391 int bmc150_accel_core_remove(struct device *dev);
7492 extern const struct dev_pm_ops bmc150_accel_pm_ops;
7593 extern const struct regmap_config bmc150_regmap_conf;
drivers/iio/accel/da280.c+9−17
@@ -100,6 +100,11 @@ static enum da280_chipset da280_match_acpi_device(struct device *dev) · 99 unmodified lines
100100 return (enum da280_chipset) id->driver_data;
101101 }
102102
103+static void da280_disable(void *client)
104+{
105+ da280_enable(client, false);
106+}
107+
103108 static int da280_probe(struct i2c_client *client,
104109 const struct i2c_device_id *id)
105110 {
@@ -118,7 +123,6 @@ static int da280_probe(struct i2c_client *client, · 12 unmodified lines
118123
119124 data = iio_priv(indio_dev);
120125 data->client = client;
121− i2c_set_clientdata(client, indio_dev);
122126
123127 indio_dev->info = &da280_info;
124128 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -142,22 +146,11 @@ static int da280_probe(struct i2c_client *client, · 17 unmodified lines
142146 if (ret < 0)
143147 return ret;
144148
145− ret = iio_device_register(indio_dev);
146− if (ret < 0) {
147− dev_err(&client->dev, "device_register failed\n");
148− da280_enable(client, false);
149− }
150−
151− return ret;
152−}
153−
154−static int da280_remove(struct i2c_client *client)
155−{
156− struct iio_dev *indio_dev = i2c_get_clientdata(client);
157−
158− iio_device_unregister(indio_dev);
149+ ret = devm_add_action_or_reset(&client->dev, da280_disable, client);
150+ if (ret)
151+ return ret;
159152
160− return da280_enable(client, false);
153+ return devm_iio_device_register(&client->dev, indio_dev);
161154 }
162155
163156 #ifdef CONFIG_PM_SLEEP
@@ -194,7 +187,6 @@ static struct i2c_driver da280_driver = { · 30 unmodified lines
194187 .pm = &da280_pm_ops,
195188 },
196189 .probe = da280_probe,
197− .remove = da280_remove,
198190 .id_table = da280_i2c_id,
199191 };
200192
drivers/iio/accel/da311.c+9−17
@@ -212,6 +212,11 @@ static const struct iio_info da311_info = { · 211 unmodified lines
212212 .read_raw = da311_read_raw,
213213 };
214214
215+static void da311_disable(void *client)
216+{
217+ da311_enable(client, false);
218+}
219+
215220 static int da311_probe(struct i2c_client *client,
216221 const struct i2c_device_id *id)
217222 {
@@ -229,7 +234,6 @@ static int da311_probe(struct i2c_client *client, · 11 unmodified lines
229234
230235 data = iio_priv(indio_dev);
231236 data->client = client;
232− i2c_set_clientdata(client, indio_dev);
233237
234238 indio_dev->info = &da311_info;
235239 indio_dev->name = "da311";
@@ -245,22 +249,11 @@ static int da311_probe(struct i2c_client *client, · 9 unmodified lines
245249 if (ret < 0)
246250 return ret;
247251
248− ret = iio_device_register(indio_dev);
249− if (ret < 0) {
250− dev_err(&client->dev, "device_register failed\n");
251− da311_enable(client, false);
252− }
253−
254− return ret;
255−}
256−
257−static int da311_remove(struct i2c_client *client)
258−{
259− struct iio_dev *indio_dev = i2c_get_clientdata(client);
260−
261− iio_device_unregister(indio_dev);
252+ ret = devm_add_action_or_reset(&client->dev, da311_disable, client);
253+ if (ret)
254+ return ret;
262255
263− return da311_enable(client, false);
256+ return devm_iio_device_register(&client->dev, indio_dev);
264257 }
265258
266259 #ifdef CONFIG_PM_SLEEP
@@ -289,7 +282,6 @@ static struct i2c_driver da311_driver = { · 22 unmodified lines
289282 .pm = &da311_pm_ops,
290283 },
291284 .probe = da311_probe,
292− .remove = da311_remove,
293285 .id_table = da311_i2c_id,
294286 };
295287
drivers/iio/accel/dmard10.c+10−17
@@ -170,6 +170,11 @@ static const struct iio_info dmard10_info = { · 169 unmodified lines
170170 .read_raw = dmard10_read_raw,
171171 };
172172
173+static void dmard10_shutdown_cleanup(void *client)
174+{
175+ dmard10_shutdown(client);
176+}
177+
173178 static int dmard10_probe(struct i2c_client *client,
174179 const struct i2c_device_id *id)
175180 {
@@ -194,7 +199,6 @@ static int dmard10_probe(struct i2c_client *client, · 18 unmodified lines
194199
195200 data = iio_priv(indio_dev);
196201 data->client = client;
197− i2c_set_clientdata(client, indio_dev);
198202
199203 indio_dev->info = &dmard10_info;
200204 indio_dev->name = "dmard10";
@@ -206,22 +210,12 @@ static int dmard10_probe(struct i2c_client *client, · 5 unmodified lines
206210 if (ret < 0)
207211 return ret;
208212
209− ret = iio_device_register(indio_dev);
210− if (ret < 0) {
211− dev_err(&client->dev, "device_register failed\n");
212− dmard10_shutdown(client);
213− }
214−
215− return ret;
216−}
217−
218−static int dmard10_remove(struct i2c_client *client)
219−{
220− struct iio_dev *indio_dev = i2c_get_clientdata(client);
221−
222− iio_device_unregister(indio_dev);
213+ ret = devm_add_action_or_reset(&client->dev, dmard10_shutdown_cleanup,
214+ client);
215+ if (ret)
216+ return ret;
223217
224− return dmard10_shutdown(client);
218+ return devm_iio_device_register(&client->dev, indio_dev);
225219 }
226220
227221 #ifdef CONFIG_PM_SLEEP
@@ -250,7 +244,6 @@ static struct i2c_driver dmard10_driver = { · 22 unmodified lines
250244 .pm = &dmard10_pm_ops,
251245 },
252246 .probe = dmard10_probe,
253− .remove = dmard10_remove,
254247 .id_table = dmard10_i2c_id,
255248 };
256249
drivers/iio/accel/hid-sensor-accel-3d.c+4−6
@@ -367,7 +367,8 @@ static int hid_accel_3d_probe(struct platform_device *pdev) · 366 unmodified lines
367367 dev_err(&pdev->dev, "failed to setup common attributes\n");
368368 return ret;
369369 }
370− indio_dev->channels = kmemdup(channel_spec, channel_size, GFP_KERNEL);
370+ indio_dev->channels = devm_kmemdup(&pdev->dev, channel_spec,
371+ channel_size, GFP_KERNEL);
371372
372373 if (!indio_dev->channels) {
373374 dev_err(&pdev->dev, "failed to duplicate channels\n");
@@ -378,7 +379,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) · 4 unmodified lines
378379 hsdev->usage, accel_state);
379380 if (ret) {
380381 dev_err(&pdev->dev, "failed to setup attributes\n");
381− goto error_free_dev_mem;
382+ return ret;
382383 }
383384
384385 indio_dev->info = &accel_3d_info;
@@ -391,7 +392,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) · 6 unmodified lines
391392 &accel_state->common_attributes);
392393 if (ret < 0) {
393394 dev_err(&pdev->dev, "trigger setup failed\n");
394− goto error_free_dev_mem;
395+ return ret;
395396 }
396397
397398 ret = iio_device_register(indio_dev);
@@ -416,8 +417,6 @@ error_iio_unreg: · 18 unmodified lines
416417 iio_device_unregister(indio_dev);
417418 error_remove_trigger:
418419 hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes);
419−error_free_dev_mem:
420− kfree(indio_dev->channels);
421420 return ret;
422421 }
423422
@@ -431,7 +430,6 @@ static int hid_accel_3d_remove(struct platform_device *pdev) · 7 unmodified lines
431430 sensor_hub_remove_callback(hsdev, hsdev->usage);
432431 iio_device_unregister(indio_dev);
433432 hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes);
434− kfree(indio_dev->channels);
435433
436434 return 0;
437435 }
drivers/iio/accel/st_accel.h+0−4
@@ -64,7 +64,6 @@ enum st_accel_type { · 63 unmodified lines
6464
6565 #ifdef CONFIG_IIO_BUFFER
6666 int st_accel_allocate_ring(struct iio_dev *indio_dev);
67−void st_accel_deallocate_ring(struct iio_dev *indio_dev);
6867 int st_accel_trig_set_state(struct iio_trigger *trig, bool state);
6968 #define ST_ACCEL_TRIGGER_SET_STATE (&st_accel_trig_set_state)
7069 #else /* CONFIG_IIO_BUFFER */
@@ -72,9 +71,6 @@ static inline int st_accel_allocate_ring(struct iio_dev *indio_dev) · 1 unmodified line
7271 {
7372 return 0;
7473 }
75−static inline void st_accel_deallocate_ring(struct iio_dev *indio_dev)
76−{
77−}
7874 #define ST_ACCEL_TRIGGER_SET_STATE NULL
7975 #endif /* CONFIG_IIO_BUFFER */
8076
drivers/iio/accel/st_accel_buffer.c+3−13
@@ -9,14 +9,9 @@ · 8 unmodified lines
99
1010 #include <linux/module.h>
1111 #include <linux/kernel.h>
12−#include <linux/slab.h>
13−#include <linux/stat.h>
14−#include <linux/interrupt.h>
15−#include <linux/i2c.h>
16−#include <linux/delay.h>
1712 #include <linux/iio/iio.h>
1813 #include <linux/iio/buffer.h>
19−#include <linux/iio/trigger_consumer.h>
14+#include <linux/iio/trigger.h>
2015 #include <linux/iio/triggered_buffer.h>
2116
2217 #include <linux/iio/common/st_sensors.h>
@@ -67,13 +62,8 @@ static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = { · 44 unmodified lines
6762
6863 int st_accel_allocate_ring(struct iio_dev *indio_dev)
6964 {
70− return iio_triggered_buffer_setup(indio_dev, NULL,
71− &st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
72−}
73−
74−void st_accel_deallocate_ring(struct iio_dev *indio_dev)
75−{
76− iio_triggered_buffer_cleanup(indio_dev);
65+ return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
66+ NULL, &st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
7767 }
7868
7969 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
drivers/iio/accel/st_accel_core.c+3−11
@@ -9,17 +9,13 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12+#include <linux/mutex.h>
13+#include <linux/sysfs.h>
1214 #include <linux/slab.h>
1315 #include <linux/acpi.h>
14−#include <linux/errno.h>
15−#include <linux/types.h>
16−#include <linux/interrupt.h>
17−#include <linux/i2c.h>
18−#include <linux/irq.h>
1916 #include <linux/iio/iio.h>
2017 #include <linux/iio/sysfs.h>
2118 #include <linux/iio/trigger.h>
22−#include <linux/iio/buffer.h>
2319
2420 #include <linux/iio/common/st_sensors.h>
2521 #include "st_accel.h"
@@ -1381,7 +1377,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) · 1355 unmodified lines
13811377 err = st_sensors_allocate_trigger(indio_dev,
13821378 ST_ACCEL_TRIGGER_OPS);
13831379 if (err < 0)
1384− goto st_accel_probe_trigger_error;
1380+ return err;
13851381 }
13861382
13871383 err = iio_device_register(indio_dev);
@@ -1396,8 +1392,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev) · 8 unmodified lines
13961392 st_accel_device_register_error:
13971393 if (adata->irq > 0)
13981394 st_sensors_deallocate_trigger(indio_dev);
1399−st_accel_probe_trigger_error:
1400− st_accel_deallocate_ring(indio_dev);
14011395 return err;
14021396 }
14031397 EXPORT_SYMBOL(st_accel_common_probe);
@@ -1409,8 +1403,6 @@ void st_accel_common_remove(struct iio_dev *indio_dev) · 5 unmodified lines
14091403 iio_device_unregister(indio_dev);
14101404 if (adata->irq > 0)
14111405 st_sensors_deallocate_trigger(indio_dev);
1412−
1413− st_accel_deallocate_ring(indio_dev);
14141406 }
14151407 EXPORT_SYMBOL(st_accel_common_remove);
14161408
drivers/iio/accel/st_accel_i2c.c+1−2
@@ -9,11 +9,10 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/acpi.h>
1414 #include <linux/i2c.h>
1515 #include <linux/iio/iio.h>
16−#include <linux/property.h>
1716
1817 #include <linux/iio/common/st_sensors_i2c.h>
1918 #include "st_accel.h"
drivers/iio/accel/st_accel_spi.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/spi/spi.h>
1414 #include <linux/iio/iio.h>
1515
drivers/iio/adc/Kconfig+10−0
@@ -887,6 +887,16 @@ config ROCKCHIP_SARADC · 886 unmodified lines
887887 To compile this driver as a module, choose M here: the
888888 module will be called rockchip_saradc.
889889
890+config RZG2L_ADC
891+ tristate "Renesas RZ/G2L ADC driver"
892+ depends on ARCH_R9A07G044 || COMPILE_TEST
893+ help
894+ Say yes here to build support for the ADC found in Renesas
895+ RZ/G2L family.
896+
897+ To compile this driver as a module, choose M here: the
898+ module will be called rzg2l_adc.
899+
890900 config SC27XX_ADC
891901 tristate "Spreadtrum SC27xx series PMICs ADC"
892902 depends on MFD_SC27XX_PMIC || COMPILE_TEST
drivers/iio/adc/Makefile+1−0
@@ -82,6 +82,7 @@ obj-$(CONFIG_QCOM_PM8XXX_XOADC) += qcom-pm8xxx-xoadc.o · 81 unmodified lines
8282 obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o
8383 obj-$(CONFIG_RN5T618_ADC) += rn5t618-adc.o
8484 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
85+obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o
8586 obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o
8687 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
8788 obj-$(CONFIG_STX104) += stx104.o
drivers/iio/adc/ep93xx_adc.c+3−3
@@ -205,7 +205,7 @@ static int ep93xx_adc_probe(struct platform_device *pdev) · 204 unmodified lines
205205 */
206206 }
207207
208− ret = clk_enable(priv->clk);
208+ ret = clk_prepare_enable(priv->clk);
209209 if (ret) {
210210 dev_err(&pdev->dev, "Cannot enable clock\n");
211211 return ret;
@@ -213,7 +213,7 @@ static int ep93xx_adc_probe(struct platform_device *pdev) · 1 unmodified line
213213
214214 ret = iio_device_register(iiodev);
215215 if (ret)
216− clk_disable(priv->clk);
216+ clk_disable_unprepare(priv->clk);
217217
218218 return ret;
219219 }
@@ -224,7 +224,7 @@ static int ep93xx_adc_remove(struct platform_device *pdev) · 4 unmodified lines
224224 struct ep93xx_adc_priv *priv = iio_priv(iiodev);
225225
226226 iio_device_unregister(iiodev);
227− clk_disable(priv->clk);
227+ clk_disable_unprepare(priv->clk);
228228
229229 return 0;
230230 }
drivers/iio/adc/fsl-imx25-gcq.c+7−10
@@ -201,11 +201,11 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, · 200 unmodified lines
201201 */
202202 priv->vref[MX25_ADC_REFP_INT] = NULL;
203203 priv->vref[MX25_ADC_REFP_EXT] =
204− devm_regulator_get_optional(&pdev->dev, "vref-ext");
204+ devm_regulator_get_optional(dev, "vref-ext");
205205 priv->vref[MX25_ADC_REFP_XP] =
206− devm_regulator_get_optional(&pdev->dev, "vref-xp");
206+ devm_regulator_get_optional(dev, "vref-xp");
207207 priv->vref[MX25_ADC_REFP_YP] =
208− devm_regulator_get_optional(&pdev->dev, "vref-yp");
208+ devm_regulator_get_optional(dev, "vref-yp");
209209
210210 for_each_child_of_node(np, child) {
211211 u32 reg;
@@ -307,7 +307,7 @@ static int mx25_gcq_probe(struct platform_device *pdev) · 95 unmodified lines
307307 int ret;
308308 int i;
309309
310− indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
310+ indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
311311 if (!indio_dev)
312312 return -ENOMEM;
313313
@@ -347,14 +347,11 @@ static int mx25_gcq_probe(struct platform_device *pdev) · 33 unmodified lines
347347 goto err_vref_disable;
348348 }
349349
350− priv->irq = platform_get_irq(pdev, 0);
351− if (priv->irq <= 0) {
352− ret = priv->irq;
353− if (!ret)
354− ret = -ENXIO;
350+ ret = platform_get_irq(pdev, 0);
351+ if (ret < 0)
355352 goto err_clk_unprepare;
356− }
357353
354+ priv->irq = ret;
358355 ret = request_irq(priv->irq, mx25_gcq_irq, 0, pdev->name, priv);
359356 if (ret) {
360357 dev_err(dev, "Failed requesting IRQ\n");
drivers/iio/adc/ingenic-adc.c+93−9
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #define JZ_ADC_REG_CFG_SAMPLE_NUM(n) ((n) << 10)
3838 #define JZ_ADC_REG_CFG_PULL_UP(n) ((n) << 16)
3939 #define JZ_ADC_REG_CFG_CMD_SEL BIT(22)
40+#define JZ_ADC_REG_CFG_VBAT_SEL BIT(30)
4041 #define JZ_ADC_REG_CFG_TOUCH_OPS_MASK (BIT(31) | GENMASK(23, 10))
4142 #define JZ_ADC_REG_ADCLK_CLKDIV_LSB 0
4243 #define JZ4725B_ADC_REG_ADCLK_CLKDIV10US_LSB 16
@@ -71,6 +72,7 @@ · 28 unmodified lines
7172 #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS 10
7273 #define JZ4740_ADC_BATTERY_HIGH_VREF (7500 * 0.986)
7374 #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS 12
75+#define JZ4760_ADC_BATTERY_VREF 2500
7476 #define JZ4770_ADC_BATTERY_VREF 1200
7577 #define JZ4770_ADC_BATTERY_VREF_BITS 12
7678
@@ -92,7 +94,7 @@ struct ingenic_adc_soc_data { · 15 unmodified lines
9294 const int *battery_scale_avail;
9395 size_t battery_scale_avail_size;
9496 unsigned int battery_vref_mode: 1;
95− unsigned int has_aux2: 1;
97+ unsigned int has_aux_md: 1;
9698 const struct iio_chan_spec *channels;
9799 unsigned int num_channels;
98100 int (*init_clk_div)(struct device *dev, struct ingenic_adc *adc);
@@ -295,6 +297,10 @@ static const int jz4740_adc_battery_scale_avail[] = { · 196 unmodified lines
295297 JZ_ADC_BATTERY_LOW_VREF, JZ_ADC_BATTERY_LOW_VREF_BITS,
296298 };
297299
300+static const int jz4760_adc_battery_scale_avail[] = {
301+ JZ4760_ADC_BATTERY_VREF, JZ4770_ADC_BATTERY_VREF_BITS,
302+};
303+
298304 static const int jz4770_adc_battery_raw_avail[] = {
299305 0, 1, (1 << JZ4770_ADC_BATTERY_VREF_BITS) - 1,
300306 };
@@ -400,6 +406,47 @@ static const struct iio_chan_spec jz4740_channels[] = { · 99 unmodified lines
400406 },
401407 };
402408
409+static const struct iio_chan_spec jz4760_channels[] = {
410+ {
411+ .extend_name = "aux",
412+ .type = IIO_VOLTAGE,
413+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
414+ BIT(IIO_CHAN_INFO_SCALE),
415+ .indexed = 1,
416+ .channel = INGENIC_ADC_AUX0,
417+ .scan_index = -1,
418+ },
419+ {
420+ .extend_name = "aux1",
421+ .type = IIO_VOLTAGE,
422+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
423+ BIT(IIO_CHAN_INFO_SCALE),
424+ .indexed = 1,
425+ .channel = INGENIC_ADC_AUX,
426+ .scan_index = -1,
427+ },
428+ {
429+ .extend_name = "aux2",
430+ .type = IIO_VOLTAGE,
431+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
432+ BIT(IIO_CHAN_INFO_SCALE),
433+ .indexed = 1,
434+ .channel = INGENIC_ADC_AUX2,
435+ .scan_index = -1,
436+ },
437+ {
438+ .extend_name = "battery",
439+ .type = IIO_VOLTAGE,
440+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
441+ BIT(IIO_CHAN_INFO_SCALE),
442+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW) |
443+ BIT(IIO_CHAN_INFO_SCALE),
444+ .indexed = 1,
445+ .channel = INGENIC_ADC_BATTERY,
446+ .scan_index = -1,
447+ },
448+};
449+
403450 static const struct iio_chan_spec jz4770_channels[] = {
404451 {
405452 .type = IIO_VOLTAGE,
@@ -506,7 +553,7 @@ static const struct ingenic_adc_soc_data jz4725b_adc_soc_data = { · 100 unmodified lines
506553 .battery_scale_avail = jz4725b_adc_battery_scale_avail,
507554 .battery_scale_avail_size = ARRAY_SIZE(jz4725b_adc_battery_scale_avail),
508555 .battery_vref_mode = true,
509− .has_aux2 = false,
556+ .has_aux_md = false,
510557 .channels = jz4740_channels,
511558 .num_channels = ARRAY_SIZE(jz4740_channels),
512559 .init_clk_div = jz4725b_adc_init_clk_div,
@@ -520,12 +567,26 @@ static const struct ingenic_adc_soc_data jz4740_adc_soc_data = { · 7 unmodified lines
520567 .battery_scale_avail = jz4740_adc_battery_scale_avail,
521568 .battery_scale_avail_size = ARRAY_SIZE(jz4740_adc_battery_scale_avail),
522569 .battery_vref_mode = true,
523− .has_aux2 = false,
570+ .has_aux_md = false,
524571 .channels = jz4740_channels,
525572 .num_channels = ARRAY_SIZE(jz4740_channels),
526573 .init_clk_div = NULL, /* no ADCLK register on JZ4740 */
527574 };
528575
576+static const struct ingenic_adc_soc_data jz4760_adc_soc_data = {
577+ .battery_high_vref = JZ4760_ADC_BATTERY_VREF,
578+ .battery_high_vref_bits = JZ4770_ADC_BATTERY_VREF_BITS,
579+ .battery_raw_avail = jz4770_adc_battery_raw_avail,
580+ .battery_raw_avail_size = ARRAY_SIZE(jz4770_adc_battery_raw_avail),
581+ .battery_scale_avail = jz4760_adc_battery_scale_avail,
582+ .battery_scale_avail_size = ARRAY_SIZE(jz4760_adc_battery_scale_avail),
583+ .battery_vref_mode = false,
584+ .has_aux_md = true,
585+ .channels = jz4760_channels,
586+ .num_channels = ARRAY_SIZE(jz4760_channels),
587+ .init_clk_div = jz4770_adc_init_clk_div,
588+};
589+
529590 static const struct ingenic_adc_soc_data jz4770_adc_soc_data = {
530591 .battery_high_vref = JZ4770_ADC_BATTERY_VREF,
531592 .battery_high_vref_bits = JZ4770_ADC_BATTERY_VREF_BITS,
@@ -534,7 +595,7 @@ static const struct ingenic_adc_soc_data jz4770_adc_soc_data = { · 2 unmodified lines
534595 .battery_scale_avail = jz4770_adc_battery_scale_avail,
535596 .battery_scale_avail_size = ARRAY_SIZE(jz4770_adc_battery_scale_avail),
536597 .battery_vref_mode = false,
537− .has_aux2 = true,
598+ .has_aux_md = true,
538599 .channels = jz4770_channels,
539600 .num_channels = ARRAY_SIZE(jz4770_channels),
540601 .init_clk_div = jz4770_adc_init_clk_div,
@@ -569,7 +630,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, · 28 unmodified lines
569630 struct iio_chan_spec const *chan,
570631 int *val)
571632 {
572− int bit, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
633+ int cmd, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
573634 struct ingenic_adc *adc = iio_priv(iio_dev);
574635
575636 ret = clk_enable(adc->clk);
@@ -579,11 +640,22 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, · 3 unmodified lines
579640 return ret;
580641 }
581642
582− /* We cannot sample AUX/AUX2 in parallel. */
643+ /* We cannot sample the aux channels in parallel. */
583644 mutex_lock(&adc->aux_lock);
584− if (adc->soc_data->has_aux2 && engine == 0) {
585− bit = BIT(chan->channel == INGENIC_ADC_AUX2);
586− ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit);
645+ if (adc->soc_data->has_aux_md && engine == 0) {
646+ switch (chan->channel) {
647+ case INGENIC_ADC_AUX0:
648+ cmd = 0;
649+ break;
650+ case INGENIC_ADC_AUX:
651+ cmd = 1;
652+ break;
653+ case INGENIC_ADC_AUX2:
654+ cmd = 2;
655+ break;
656+ }
657+
658+ ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd);
587659 }
588660
589661 ret = ingenic_adc_capture(adc, engine);
@@ -591,6 +663,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev, · 1 unmodified line
591663 goto out;
592664
593665 switch (chan->channel) {
666+ case INGENIC_ADC_AUX0:
594667 case INGENIC_ADC_AUX:
595668 case INGENIC_ADC_AUX2:
596669 *val = readw(adc->base + JZ_ADC_REG_ADSDAT);
@@ -621,6 +694,7 @@ static int ingenic_adc_read_raw(struct iio_dev *iio_dev, · 24 unmodified lines
621694 return ingenic_adc_read_chan_info_raw(iio_dev, chan, val);
622695 case IIO_CHAN_INFO_SCALE:
623696 switch (chan->channel) {
697+ case INGENIC_ADC_AUX0:
624698 case INGENIC_ADC_AUX:
625699 case INGENIC_ADC_AUX2:
626700 *val = JZ_ADC_AUX_VREF;
@@ -806,6 +880,14 @@ static int ingenic_adc_probe(struct platform_device *pdev) · 179 unmodified lines
806880 /* Put hardware in a known passive state. */
807881 writeb(0x00, adc->base + JZ_ADC_REG_ENABLE);
808882 writeb(0xff, adc->base + JZ_ADC_REG_CTRL);
883+
884+ /* JZ4760B specific */
885+ if (device_property_present(dev, "ingenic,use-internal-divider"))
886+ ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL,
887+ JZ_ADC_REG_CFG_VBAT_SEL);
888+ else
889+ ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 0);
890+
809891 usleep_range(2000, 3000); /* Must wait at least 2ms. */
810892 clk_disable(adc->clk);
811893
@@ -832,6 +914,8 @@ static int ingenic_adc_probe(struct platform_device *pdev) · 20 unmodified lines
832914 static const struct of_device_id ingenic_adc_of_match[] = {
833915 { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, },
834916 { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, },
917+ { .compatible = "ingenic,jz4760-adc", .data = &jz4760_adc_soc_data, },
918+ { .compatible = "ingenic,jz4760b-adc", .data = &jz4760_adc_soc_data, },
835919 { .compatible = "ingenic,jz4770-adc", .data = &jz4770_adc_soc_data, },
836920 { },
837921 };
drivers/iio/adc/meson_saradc.c+14−6
@@ -347,7 +347,7 @@ static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev, · 346 unmodified lines
347347 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
348348 int regval, fifo_chan, fifo_val, count;
349349
350− if(!wait_for_completion_timeout(&priv->done,
350+ if (!wait_for_completion_timeout(&priv->done,
351351 msecs_to_jiffies(MESON_SAR_ADC_TIMEOUT)))
352352 return -ETIMEDOUT;
353353
@@ -497,8 +497,8 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev) · 143 unmodified lines
497497 if (priv->param->has_bl30_integration) {
498498 /* prevent BL30 from using the SAR ADC while we are using it */
499499 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
500− MESON_SAR_ADC_DELAY_KERNEL_BUSY,
501− MESON_SAR_ADC_DELAY_KERNEL_BUSY);
500+ MESON_SAR_ADC_DELAY_KERNEL_BUSY,
501+ MESON_SAR_ADC_DELAY_KERNEL_BUSY);
502502
503503 /*
504504 * wait until BL30 releases it's lock (so we can use the SAR
@@ -525,7 +525,7 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev) · 20 unmodified lines
525525 if (priv->param->has_bl30_integration)
526526 /* allow BL30 to use the SAR ADC again */
527527 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
528− MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
528+ MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
529529
530530 mutex_unlock(&indio_dev->mlock);
531531 }
@@ -791,7 +791,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev) · 259 unmodified lines
791791 * on the vendor driver), which we don't support at the moment.
792792 */
793793 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
794− MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL, 0);
794+ MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL, 0);
795795
796796 /* disable all channels by default */
797797 regmap_write(priv->regmap, MESON_SAR_ADC_CHAN_LIST, 0x0);
@@ -1104,6 +1104,14 @@ static const struct meson_sar_adc_param meson_sar_adc_gxl_param = { · 306 unmodified lines
11041104 .resolution = 12,
11051105 };
11061106
1107+static const struct meson_sar_adc_param meson_sar_adc_g12a_param = {
1108+ .has_bl30_integration = false,
1109+ .clock_rate = 1200000,
1110+ .bandgap_reg = MESON_SAR_ADC_REG11,
1111+ .regmap_config = &meson_sar_adc_regmap_config_gxbb,
1112+ .resolution = 12,
1113+};
1114+
11071115 static const struct meson_sar_adc_data meson_sar_adc_meson8_data = {
11081116 .param = &meson_sar_adc_meson8_param,
11091117 .name = "meson-meson8-saradc",
@@ -1140,7 +1148,7 @@ static const struct meson_sar_adc_data meson_sar_adc_axg_data = { · 30 unmodified lines
11401148 };
11411149
11421150 static const struct meson_sar_adc_data meson_sar_adc_g12a_data = {
1143− .param = &meson_sar_adc_gxl_param,
1151+ .param = &meson_sar_adc_g12a_param,
11441152 .name = "meson-g12a-saradc",
11451153 };
11461154
drivers/iio/adc/rockchip_saradc.c+61−8
@@ -35,7 +35,7 @@ · 34 unmodified lines
3535 #define SARADC_DLY_PU_SOC_MASK 0x3f
3636
3737 #define SARADC_TIMEOUT msecs_to_jiffies(100)
38−#define SARADC_MAX_CHANNELS 6
38+#define SARADC_MAX_CHANNELS 8
3939
4040 struct rockchip_saradc_data {
4141 const struct iio_chan_spec *channels;
@@ -49,10 +49,12 @@ struct rockchip_saradc { · 7 unmodified lines
4949 struct clk *clk;
5050 struct completion completion;
5151 struct regulator *vref;
52+ int uv_vref;
5253 struct reset_control *reset;
5354 const struct rockchip_saradc_data *data;
5455 u16 last_val;
5556 const struct iio_chan_spec *last_chan;
57+ struct notifier_block nb;
5658 };
5759
5860 static void rockchip_saradc_power_down(struct rockchip_saradc *info)
@@ -105,13 +107,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev, · 46 unmodified lines
105107 mutex_unlock(&indio_dev->mlock);
106108 return IIO_VAL_INT;
107109 case IIO_CHAN_INFO_SCALE:
108− ret = regulator_get_voltage(info->vref);
109− if (ret < 0) {
110− dev_err(&indio_dev->dev, "failed to get voltage\n");
111− return ret;
112− }
113−
114− *val = ret / 1000;
110+ *val = info->uv_vref / 1000;
115111 *val2 = chan->scan_type.realbits;
116112 return IIO_VAL_FRACTIONAL_LOG2;
117113 default:
@@ -192,6 +188,23 @@ static const struct rockchip_saradc_data rk3399_saradc_data = { · 74 unmodified lines
192188 .clk_rate = 1000000,
193189 };
194190
191+static const struct iio_chan_spec rockchip_rk3568_saradc_iio_channels[] = {
192+ SARADC_CHANNEL(0, "adc0", 10),
193+ SARADC_CHANNEL(1, "adc1", 10),
194+ SARADC_CHANNEL(2, "adc2", 10),
195+ SARADC_CHANNEL(3, "adc3", 10),
196+ SARADC_CHANNEL(4, "adc4", 10),
197+ SARADC_CHANNEL(5, "adc5", 10),
198+ SARADC_CHANNEL(6, "adc6", 10),
199+ SARADC_CHANNEL(7, "adc7", 10),
200+};
201+
202+static const struct rockchip_saradc_data rk3568_saradc_data = {
203+ .channels = rockchip_rk3568_saradc_iio_channels,
204+ .num_channels = ARRAY_SIZE(rockchip_rk3568_saradc_iio_channels),
205+ .clk_rate = 1000000,
206+};
207+
195208 static const struct of_device_id rockchip_saradc_match[] = {
196209 {
197210 .compatible = "rockchip,saradc",
@@ -202,6 +215,9 @@ static const struct of_device_id rockchip_saradc_match[] = { · 4 unmodified lines
202215 }, {
203216 .compatible = "rockchip,rk3399-saradc",
204217 .data = &rk3399_saradc_data,
218+ }, {
219+ .compatible = "rockchip,rk3568-saradc",
220+ .data = &rk3568_saradc_data,
205221 },
206222 {},
207223 };
@@ -278,6 +294,26 @@ out: · 70 unmodified lines
278294 return IRQ_HANDLED;
279295 }
280296
297+static int rockchip_saradc_volt_notify(struct notifier_block *nb,
298+ unsigned long event,
299+ void *data)
300+{
301+ struct rockchip_saradc *info =
302+ container_of(nb, struct rockchip_saradc, nb);
303+
304+ if (event & REGULATOR_EVENT_VOLTAGE_CHANGE)
305+ info->uv_vref = (unsigned long)data;
306+
307+ return NOTIFY_OK;
308+}
309+
310+static void rockchip_saradc_regulator_unreg_notifier(void *data)
311+{
312+ struct rockchip_saradc *info = data;
313+
314+ regulator_unregister_notifier(info->vref, &info->nb);
315+}
316+
281317 static int rockchip_saradc_probe(struct platform_device *pdev)
282318 {
283319 struct rockchip_saradc *info = NULL;
@@ -390,6 +426,12 @@ static int rockchip_saradc_probe(struct platform_device *pdev) · 106 unmodified lines
390426 return ret;
391427 }
392428
429+ ret = regulator_get_voltage(info->vref);
430+ if (ret < 0)
431+ return ret;
432+
433+ info->uv_vref = ret;
434+
393435 ret = clk_prepare_enable(info->pclk);
394436 if (ret < 0) {
395437 dev_err(&pdev->dev, "failed to enable pclk\n");
@@ -430,6 +472,17 @@ static int rockchip_saradc_probe(struct platform_device *pdev) · 34 unmodified lines
430472 if (ret)
431473 return ret;
432474
475+ info->nb.notifier_call = rockchip_saradc_volt_notify;
476+ ret = regulator_register_notifier(info->vref, &info->nb);
477+ if (ret)
478+ return ret;
479+
480+ ret = devm_add_action_or_reset(&pdev->dev,
481+ rockchip_saradc_regulator_unreg_notifier,
482+ info);
483+ if (ret)
484+ return ret;
485+
433486 return devm_iio_device_register(&pdev->dev, indio_dev);
434487 }
435488
drivers/iio/adc/rzg2l_adc.c+600−0
@@ -0,0 +1,600 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * RZ/G2L A/D Converter driver
4+ *
5+ * Copyright (c) 2021 Renesas Electronics Europe GmbH
6+ *
7+ * Author: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
8+ */
9+
10+#include <linux/bitfield.h>
11+#include <linux/clk.h>
12+#include <linux/completion.h>
13+#include <linux/delay.h>
14+#include <linux/iio/iio.h>
15+#include <linux/interrupt.h>
16+#include <linux/io.h>
17+#include <linux/mod_devicetable.h>
18+#include <linux/module.h>
19+#include <linux/platform_device.h>
20+#include <linux/pm_runtime.h>
21+#include <linux/reset.h>
22+
23+#define DRIVER_NAME "rzg2l-adc"
24+
25+#define RZG2L_ADM(n) ((n) * 0x4)
26+#define RZG2L_ADM0_ADCE BIT(0)
27+#define RZG2L_ADM0_ADBSY BIT(1)
28+#define RZG2L_ADM0_PWDWNB BIT(2)
29+#define RZG2L_ADM0_SRESB BIT(15)
30+#define RZG2L_ADM1_TRG BIT(0)
31+#define RZG2L_ADM1_MS BIT(2)
32+#define RZG2L_ADM1_BS BIT(4)
33+#define RZG2L_ADM1_EGA_MASK GENMASK(13, 12)
34+#define RZG2L_ADM2_CHSEL_MASK GENMASK(7, 0)
35+#define RZG2L_ADM3_ADIL_MASK GENMASK(31, 24)
36+#define RZG2L_ADM3_ADCMP_MASK GENMASK(23, 16)
37+#define RZG2L_ADM3_ADCMP_E FIELD_PREP(RZG2L_ADM3_ADCMP_MASK, 0xe)
38+#define RZG2L_ADM3_ADSMP_MASK GENMASK(15, 0)
39+
40+#define RZG2L_ADINT 0x20
41+#define RZG2L_ADINT_INTEN_MASK GENMASK(7, 0)
42+#define RZG2L_ADINT_CSEEN BIT(16)
43+#define RZG2L_ADINT_INTS BIT(31)
44+
45+#define RZG2L_ADSTS 0x24
46+#define RZG2L_ADSTS_CSEST BIT(16)
47+#define RZG2L_ADSTS_INTST_MASK GENMASK(7, 0)
48+
49+#define RZG2L_ADIVC 0x28
50+#define RZG2L_ADIVC_DIVADC_MASK GENMASK(8, 0)
51+#define RZG2L_ADIVC_DIVADC_4 FIELD_PREP(RZG2L_ADIVC_DIVADC_MASK, 0x4)
52+
53+#define RZG2L_ADFIL 0x2c
54+
55+#define RZG2L_ADCR(n) (0x30 + ((n) * 0x4))
56+#define RZG2L_ADCR_AD_MASK GENMASK(11, 0)
57+
58+#define RZG2L_ADSMP_DEFUALT_SAMPLING 0x578
59+
60+#define RZG2L_ADC_MAX_CHANNELS 8
61+#define RZG2L_ADC_CHN_MASK 0x7
62+#define RZG2L_ADC_TIMEOUT usecs_to_jiffies(1 * 4)
63+
64+struct rzg2l_adc_data {
65+ const struct iio_chan_spec *channels;
66+ u8 num_channels;
67+};
68+
69+struct rzg2l_adc {
70+ void __iomem *base;
71+ struct clk *pclk;
72+ struct clk *adclk;
73+ struct reset_control *presetn;
74+ struct reset_control *adrstn;
75+ struct completion completion;
76+ const struct rzg2l_adc_data *data;
77+ struct mutex lock;
78+ u16 last_val[RZG2L_ADC_MAX_CHANNELS];
79+};
80+
81+static const char * const rzg2l_adc_channel_name[] = {
82+ "adc0",
83+ "adc1",
84+ "adc2",
85+ "adc3",
86+ "adc4",
87+ "adc5",
88+ "adc6",
89+ "adc7",
90+};
91+
92+static unsigned int rzg2l_adc_readl(struct rzg2l_adc *adc, u32 reg)
93+{
94+ return readl(adc->base + reg);
95+}
96+
97+static void rzg2l_adc_writel(struct rzg2l_adc *adc, unsigned int reg, u32 val)
98+{
99+ writel(val, adc->base + reg);
100+}
101+
102+static void rzg2l_adc_pwr(struct rzg2l_adc *adc, bool on)
103+{
104+ u32 reg;
105+
106+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(0));
107+ if (on)
108+ reg |= RZG2L_ADM0_PWDWNB;
109+ else
110+ reg &= ~RZG2L_ADM0_PWDWNB;
111+ rzg2l_adc_writel(adc, RZG2L_ADM(0), reg);
112+ udelay(2);
113+}
114+
115+static void rzg2l_adc_start_stop(struct rzg2l_adc *adc, bool start)
116+{
117+ int timeout = 5;
118+ u32 reg;
119+
120+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(0));
121+ if (start)
122+ reg |= RZG2L_ADM0_ADCE;
123+ else
124+ reg &= ~RZG2L_ADM0_ADCE;
125+ rzg2l_adc_writel(adc, RZG2L_ADM(0), reg);
126+
127+ if (start)
128+ return;
129+
130+ do {
131+ usleep_range(100, 200);
132+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(0));
133+ timeout--;
134+ if (!timeout) {
135+ pr_err("%s stopping ADC timed out\n", __func__);
136+ break;
137+ }
138+ } while (((reg & RZG2L_ADM0_ADBSY) || (reg & RZG2L_ADM0_ADCE)));
139+}
140+
141+static void rzg2l_set_trigger(struct rzg2l_adc *adc)
142+{
143+ u32 reg;
144+
145+ /*
146+ * Setup ADM1 for SW trigger
147+ * EGA[13:12] - Set 00 to indicate hardware trigger is invalid
148+ * BS[4] - Enable 1-buffer mode
149+ * MS[1] - Enable Select mode
150+ * TRG[0] - Enable software trigger mode
151+ */
152+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(1));
153+ reg &= ~RZG2L_ADM1_EGA_MASK;
154+ reg &= ~RZG2L_ADM1_BS;
155+ reg &= ~RZG2L_ADM1_TRG;
156+ reg |= RZG2L_ADM1_MS;
157+ rzg2l_adc_writel(adc, RZG2L_ADM(1), reg);
158+}
159+
160+static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch)
161+{
162+ u32 reg;
163+
164+ if (rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_ADBSY)
165+ return -EBUSY;
166+
167+ rzg2l_set_trigger(adc);
168+
169+ /* Select analog input channel subjected to conversion. */
170+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(2));
171+ reg &= ~RZG2L_ADM2_CHSEL_MASK;
172+ reg |= BIT(ch);
173+ rzg2l_adc_writel(adc, RZG2L_ADM(2), reg);
174+
175+ /*
176+ * Setup ADINT
177+ * INTS[31] - Select pulse signal
178+ * CSEEN[16] - Enable channel select error interrupt
179+ * INTEN[7:0] - Select channel interrupt
180+ */
181+ reg = rzg2l_adc_readl(adc, RZG2L_ADINT);
182+ reg &= ~RZG2L_ADINT_INTS;
183+ reg &= ~RZG2L_ADINT_INTEN_MASK;
184+ reg |= (RZG2L_ADINT_CSEEN | BIT(ch));
185+ rzg2l_adc_writel(adc, RZG2L_ADINT, reg);
186+
187+ return 0;
188+}
189+
190+static int rzg2l_adc_set_power(struct iio_dev *indio_dev, bool on)
191+{
192+ struct device *dev = indio_dev->dev.parent;
193+
194+ if (on)
195+ return pm_runtime_resume_and_get(dev);
196+
197+ return pm_runtime_put_sync(dev);
198+}
199+
200+static int rzg2l_adc_conversion(struct iio_dev *indio_dev, struct rzg2l_adc *adc, u8 ch)
201+{
202+ int ret;
203+
204+ ret = rzg2l_adc_set_power(indio_dev, true);
205+ if (ret)
206+ return ret;
207+
208+ ret = rzg2l_adc_conversion_setup(adc, ch);
209+ if (ret) {
210+ rzg2l_adc_set_power(indio_dev, false);
211+ return ret;
212+ }
213+
214+ reinit_completion(&adc->completion);
215+
216+ rzg2l_adc_start_stop(adc, true);
217+
218+ if (!wait_for_completion_timeout(&adc->completion, RZG2L_ADC_TIMEOUT)) {
219+ rzg2l_adc_writel(adc, RZG2L_ADINT,
220+ rzg2l_adc_readl(adc, RZG2L_ADINT) & ~RZG2L_ADINT_INTEN_MASK);
221+ rzg2l_adc_start_stop(adc, false);
222+ rzg2l_adc_set_power(indio_dev, false);
223+ return -ETIMEDOUT;
224+ }
225+
226+ return rzg2l_adc_set_power(indio_dev, false);
227+}
228+
229+static int rzg2l_adc_read_raw(struct iio_dev *indio_dev,
230+ struct iio_chan_spec const *chan,
231+ int *val, int *val2, long mask)
232+{
233+ struct rzg2l_adc *adc = iio_priv(indio_dev);
234+ int ret;
235+ u8 ch;
236+
237+ switch (mask) {
238+ case IIO_CHAN_INFO_RAW:
239+ if (chan->type != IIO_VOLTAGE)
240+ return -EINVAL;
241+
242+ mutex_lock(&adc->lock);
243+ ch = chan->channel & RZG2L_ADC_CHN_MASK;
244+ ret = rzg2l_adc_conversion(indio_dev, adc, ch);
245+ if (ret) {
246+ mutex_unlock(&adc->lock);
247+ return ret;
248+ }
249+ *val = adc->last_val[ch];
250+ mutex_unlock(&adc->lock);
251+
252+ return IIO_VAL_INT;
253+
254+ default:
255+ return -EINVAL;
256+ }
257+}
258+
259+static int rzg2l_adc_read_label(struct iio_dev *iio_dev,
260+ const struct iio_chan_spec *chan,
261+ char *label)
262+{
263+ if (chan->channel >= RZG2L_ADC_MAX_CHANNELS)
264+ return -EINVAL;
265+
266+ return sysfs_emit(label, "%s\n", rzg2l_adc_channel_name[chan->channel]);
267+}
268+
269+static const struct iio_info rzg2l_adc_iio_info = {
270+ .read_raw = rzg2l_adc_read_raw,
271+ .read_label = rzg2l_adc_read_label,
272+};
273+
274+static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id)
275+{
276+ struct rzg2l_adc *adc = dev_id;
277+ unsigned long intst;
278+ u32 reg;
279+ int ch;
280+
281+ reg = rzg2l_adc_readl(adc, RZG2L_ADSTS);
282+
283+ /* A/D conversion channel select error interrupt */
284+ if (reg & RZG2L_ADSTS_CSEST) {
285+ rzg2l_adc_writel(adc, RZG2L_ADSTS, reg);
286+ return IRQ_HANDLED;
287+ }
288+
289+ intst = reg & RZG2L_ADSTS_INTST_MASK;
290+ if (!intst)
291+ return IRQ_NONE;
292+
293+ for_each_set_bit(ch, &intst, RZG2L_ADC_MAX_CHANNELS)
294+ adc->last_val[ch] = rzg2l_adc_readl(adc, RZG2L_ADCR(ch)) & RZG2L_ADCR_AD_MASK;
295+
296+ /* clear the channel interrupt */
297+ rzg2l_adc_writel(adc, RZG2L_ADSTS, reg);
298+
299+ complete(&adc->completion);
300+
301+ return IRQ_HANDLED;
302+}
303+
304+static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc)
305+{
306+ struct iio_chan_spec *chan_array;
307+ struct fwnode_handle *fwnode;
308+ struct rzg2l_adc_data *data;
309+ unsigned int channel;
310+ int num_channels;
311+ int ret;
312+ u8 i;
313+
314+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
315+ if (!data)
316+ return -ENOMEM;
317+
318+ num_channels = device_get_child_node_count(&pdev->dev);
319+ if (!num_channels) {
320+ dev_err(&pdev->dev, "no channel children\n");
321+ return -ENODEV;
322+ }
323+
324+ if (num_channels > RZG2L_ADC_MAX_CHANNELS) {
325+ dev_err(&pdev->dev, "num of channel children out of range\n");
326+ return -EINVAL;
327+ }
328+
329+ chan_array = devm_kcalloc(&pdev->dev, num_channels, sizeof(*chan_array),
330+ GFP_KERNEL);
331+ if (!chan_array)
332+ return -ENOMEM;
333+
334+ i = 0;
335+ device_for_each_child_node(&pdev->dev, fwnode) {
336+ ret = fwnode_property_read_u32(fwnode, "reg", &channel);
337+ if (ret)
338+ return ret;
339+
340+ if (channel >= RZG2L_ADC_MAX_CHANNELS)
341+ return -EINVAL;
342+
343+ chan_array[i].type = IIO_VOLTAGE;
344+ chan_array[i].indexed = 1;
345+ chan_array[i].channel = channel;
346+ chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
347+ chan_array[i].datasheet_name = rzg2l_adc_channel_name[channel];
348+ i++;
349+ }
350+
351+ data->num_channels = num_channels;
352+ data->channels = chan_array;
353+ adc->data = data;
354+
355+ return 0;
356+}
357+
358+static int rzg2l_adc_hw_init(struct rzg2l_adc *adc)
359+{
360+ int timeout = 5;
361+ u32 reg;
362+ int ret;
363+
364+ ret = clk_prepare_enable(adc->pclk);
365+ if (ret)
366+ return ret;
367+
368+ /* SW reset */
369+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(0));
370+ reg |= RZG2L_ADM0_SRESB;
371+ rzg2l_adc_writel(adc, RZG2L_ADM(0), reg);
372+
373+ while (!(rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_SRESB)) {
374+ if (!timeout) {
375+ ret = -EBUSY;
376+ goto exit_hw_init;
377+ }
378+ timeout--;
379+ usleep_range(100, 200);
380+ }
381+
382+ /* Only division by 4 can be set */
383+ reg = rzg2l_adc_readl(adc, RZG2L_ADIVC);
384+ reg &= ~RZG2L_ADIVC_DIVADC_MASK;
385+ reg |= RZG2L_ADIVC_DIVADC_4;
386+ rzg2l_adc_writel(adc, RZG2L_ADIVC, reg);
387+
388+ /*
389+ * Setup AMD3
390+ * ADIL[31:24] - Should be always set to 0
391+ * ADCMP[23:16] - Should be always set to 0xe
392+ * ADSMP[15:0] - Set default (0x578) sampling period
393+ */
394+ reg = rzg2l_adc_readl(adc, RZG2L_ADM(3));
395+ reg &= ~RZG2L_ADM3_ADIL_MASK;
396+ reg &= ~RZG2L_ADM3_ADCMP_MASK;
397+ reg &= ~RZG2L_ADM3_ADSMP_MASK;
398+ reg |= (RZG2L_ADM3_ADCMP_E | RZG2L_ADSMP_DEFUALT_SAMPLING);
399+ rzg2l_adc_writel(adc, RZG2L_ADM(3), reg);
400+
401+exit_hw_init:
402+ clk_disable_unprepare(adc->pclk);
403+
404+ return 0;
405+}
406+
407+static void rzg2l_adc_pm_runtime_disable(void *data)
408+{
409+ struct device *dev = data;
410+
411+ pm_runtime_disable(dev->parent);
412+}
413+
414+static void rzg2l_adc_pm_runtime_set_suspended(void *data)
415+{
416+ struct device *dev = data;
417+
418+ pm_runtime_set_suspended(dev->parent);
419+}
420+
421+static void rzg2l_adc_reset_assert(void *data)
422+{
423+ reset_control_assert(data);
424+}
425+
426+static int rzg2l_adc_probe(struct platform_device *pdev)
427+{
428+ struct device *dev = &pdev->dev;
429+ struct iio_dev *indio_dev;
430+ struct rzg2l_adc *adc;
431+ int ret;
432+ int irq;
433+
434+ indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
435+ if (!indio_dev)
436+ return -ENOMEM;
437+
438+ adc = iio_priv(indio_dev);
439+
440+ ret = rzg2l_adc_parse_properties(pdev, adc);
441+ if (ret)
442+ return ret;
443+
444+ mutex_init(&adc->lock);
445+
446+ adc->base = devm_platform_ioremap_resource(pdev, 0);
447+ if (IS_ERR(adc->base))
448+ return PTR_ERR(adc->base);
449+
450+ adc->pclk = devm_clk_get(dev, "pclk");
451+ if (IS_ERR(adc->pclk)) {
452+ dev_err(dev, "Failed to get pclk");
453+ return PTR_ERR(adc->pclk);
454+ }
455+
456+ adc->adclk = devm_clk_get(dev, "adclk");
457+ if (IS_ERR(adc->adclk)) {
458+ dev_err(dev, "Failed to get adclk");
459+ return PTR_ERR(adc->adclk);
460+ }
461+
462+ adc->adrstn = devm_reset_control_get_exclusive(dev, "adrst-n");
463+ if (IS_ERR(adc->adrstn)) {
464+ dev_err(dev, "failed to get adrstn\n");
465+ return PTR_ERR(adc->adrstn);
466+ }
467+
468+ adc->presetn = devm_reset_control_get_exclusive(dev, "presetn");
469+ if (IS_ERR(adc->presetn)) {
470+ dev_err(dev, "failed to get presetn\n");
471+ return PTR_ERR(adc->presetn);
472+ }
473+
474+ ret = reset_control_deassert(adc->adrstn);
475+ if (ret) {
476+ dev_err(&pdev->dev, "failed to deassert adrstn pin, %d\n", ret);
477+ return ret;
478+ }
479+
480+ ret = devm_add_action_or_reset(&pdev->dev,
481+ rzg2l_adc_reset_assert, adc->adrstn);
482+ if (ret) {
483+ dev_err(&pdev->dev, "failed to register adrstn assert devm action, %d\n",
484+ ret);
485+ return ret;
486+ }
487+
488+ ret = reset_control_deassert(adc->presetn);
489+ if (ret) {
490+ dev_err(&pdev->dev, "failed to deassert presetn pin, %d\n", ret);
491+ return ret;
492+ }
493+
494+ ret = devm_add_action_or_reset(&pdev->dev,
495+ rzg2l_adc_reset_assert, adc->presetn);
496+ if (ret) {
497+ dev_err(&pdev->dev, "failed to register presetn assert devm action, %d\n",
498+ ret);
499+ return ret;
500+ }
501+
502+ ret = rzg2l_adc_hw_init(adc);
503+ if (ret) {
504+ dev_err(&pdev->dev, "failed to initialize ADC HW, %d\n", ret);
505+ return ret;
506+ }
507+
508+ irq = platform_get_irq(pdev, 0);
509+ if (irq < 0) {
510+ dev_err(dev, "no irq resource\n");
511+ return irq;
512+ }
513+
514+ ret = devm_request_irq(dev, irq, rzg2l_adc_isr,
515+ 0, dev_name(dev), adc);
516+ if (ret < 0)
517+ return ret;
518+
519+ init_completion(&adc->completion);
520+
521+ platform_set_drvdata(pdev, indio_dev);
522+
523+ indio_dev->name = DRIVER_NAME;
524+ indio_dev->info = &rzg2l_adc_iio_info;
525+ indio_dev->modes = INDIO_DIRECT_MODE;
526+ indio_dev->channels = adc->data->channels;
527+ indio_dev->num_channels = adc->data->num_channels;
528+
529+ pm_runtime_set_suspended(dev);
530+ ret = devm_add_action_or_reset(&pdev->dev,
531+ rzg2l_adc_pm_runtime_set_suspended, &indio_dev->dev);
532+ if (ret)
533+ return ret;
534+
535+ pm_runtime_enable(dev);
536+ ret = devm_add_action_or_reset(&pdev->dev,
537+ rzg2l_adc_pm_runtime_disable, &indio_dev->dev);
538+ if (ret)
539+ return ret;
540+
541+ return devm_iio_device_register(dev, indio_dev);
542+}
543+
544+static const struct of_device_id rzg2l_adc_match[] = {
545+ { .compatible = "renesas,rzg2l-adc",},
546+ { /* sentinel */ }
547+};
548+MODULE_DEVICE_TABLE(of, rzg2l_adc_match);
549+
550+static int __maybe_unused rzg2l_adc_pm_runtime_suspend(struct device *dev)
551+{
552+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
553+ struct rzg2l_adc *adc = iio_priv(indio_dev);
554+
555+ rzg2l_adc_pwr(adc, false);
556+ clk_disable_unprepare(adc->adclk);
557+ clk_disable_unprepare(adc->pclk);
558+
559+ return 0;
560+}
561+
562+static int __maybe_unused rzg2l_adc_pm_runtime_resume(struct device *dev)
563+{
564+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
565+ struct rzg2l_adc *adc = iio_priv(indio_dev);
566+ int ret;
567+
568+ ret = clk_prepare_enable(adc->pclk);
569+ if (ret)
570+ return ret;
571+
572+ ret = clk_prepare_enable(adc->adclk);
573+ if (ret)
574+ return ret;
575+
576+ rzg2l_adc_pwr(adc, true);
577+
578+ return 0;
579+}
580+
581+static const struct dev_pm_ops rzg2l_adc_pm_ops = {
582+ SET_RUNTIME_PM_OPS(rzg2l_adc_pm_runtime_suspend,
583+ rzg2l_adc_pm_runtime_resume,
584+ NULL)
585+};
586+
587+static struct platform_driver rzg2l_adc_driver = {
588+ .probe = rzg2l_adc_probe,
589+ .driver = {
590+ .name = DRIVER_NAME,
591+ .of_match_table = rzg2l_adc_match,
592+ .pm = &rzg2l_adc_pm_ops,
593+ },
594+};
595+
596+module_platform_driver(rzg2l_adc_driver);
597+
598+MODULE_AUTHOR("Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>");
599+MODULE_DESCRIPTION("Renesas RZ/G2L ADC driver");
600+MODULE_LICENSE("GPL v2");
drivers/iio/chemical/Kconfig+11−0
@@ -131,6 +131,17 @@ config SENSIRION_SGP30 · 130 unmodified lines
131131 To compile this driver as module, choose M here: the
132132 module will be called sgp30.
133133
134+config SENSIRION_SGP40
135+ tristate "Sensirion SGP40 gas sensor"
136+ depends on I2C
137+ select CRC8
138+ help
139+ Say Y here to build I2C interface to support Sensirion SGP40 gas
140+ sensor
141+
142+ To compile this driver as module, choose M here: the
143+ module will be called sgp40.
144+
134145 config SPS30
135146 tristate
136147 select IIO_BUFFER
drivers/iio/chemical/Makefile+1−0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SCD30_CORE) += scd30_core.o · 15 unmodified lines
1616 obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o
1717 obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o
1818 obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o
19+obj-$(CONFIG_SENSIRION_SGP40) += sgp40.o
1920 obj-$(CONFIG_SPS30) += sps30.o
2021 obj-$(CONFIG_SPS30_I2C) += sps30_i2c.o
2122 obj-$(CONFIG_SPS30_SERIAL) += sps30_serial.o
drivers/iio/chemical/sgp40.c+378−0
@@ -0,0 +1,378 @@
1+// SPDX-License-Identifier: GPL-2.0+
2+/*
3+ * sgp40.c - Support for Sensirion SGP40 Gas Sensor
4+ *
5+ * Copyright (C) 2021 Andreas Klinger <ak@it-klinger.de>
6+ *
7+ * I2C slave address: 0x59
8+ *
9+ * Datasheet can be found here:
10+ * https://www.sensirion.com/file/datasheet_sgp40
11+ *
12+ * There are two functionalities supported:
13+ *
14+ * 1) read raw logarithmic resistance value from sensor
15+ * --> useful to pass it to the algorithm of the sensor vendor for
16+ * measuring deteriorations and improvements of air quality.
17+ *
18+ * 2) calculate an estimated absolute voc index (0 - 500 index points) for
19+ * measuring the air quality.
20+ * For this purpose the value of the resistance for which the voc index
21+ * will be 250 can be set up using calibbias.
22+ *
23+ * Compensation values of relative humidity and temperature can be set up
24+ * by writing to the out values of temp and humidityrelative.
25+ */
26+
27+#include <linux/delay.h>
28+#include <linux/crc8.h>
29+#include <linux/module.h>
30+#include <linux/mutex.h>
31+#include <linux/i2c.h>
32+#include <linux/iio/iio.h>
33+
34+/*
35+ * floating point calculation of voc is done as integer
36+ * where numbers are multiplied by 1 << SGP40_CALC_POWER
37+ */
38+#define SGP40_CALC_POWER 14
39+
40+#define SGP40_CRC8_POLYNOMIAL 0x31
41+#define SGP40_CRC8_INIT 0xff
42+
43+DECLARE_CRC8_TABLE(sgp40_crc8_table);
44+
45+struct sgp40_data {
46+ struct device *dev;
47+ struct i2c_client *client;
48+ int rht;
49+ int temp;
50+ int res_calibbias;
51+ /* Prevent concurrent access to rht, tmp, calibbias */
52+ struct mutex lock;
53+};
54+
55+struct sgp40_tg_measure {
56+ u8 command[2];
57+ __be16 rht_ticks;
58+ u8 rht_crc;
59+ __be16 temp_ticks;
60+ u8 temp_crc;
61+} __packed;
62+
63+struct sgp40_tg_result {
64+ __be16 res_ticks;
65+ u8 res_crc;
66+} __packed;
67+
68+static const struct iio_chan_spec sgp40_channels[] = {
69+ {
70+ .type = IIO_CONCENTRATION,
71+ .channel2 = IIO_MOD_VOC,
72+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
73+ },
74+ {
75+ .type = IIO_RESISTANCE,
76+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
77+ BIT(IIO_CHAN_INFO_CALIBBIAS),
78+ },
79+ {
80+ .type = IIO_TEMP,
81+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
82+ .output = 1,
83+ },
84+ {
85+ .type = IIO_HUMIDITYRELATIVE,
86+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
87+ .output = 1,
88+ },
89+};
90+
91+/*
92+ * taylor approximation of e^x:
93+ * y = 1 + x + x^2 / 2 + x^3 / 6 + x^4 / 24 + ... + x^n / n!
94+ *
95+ * Because we are calculating x real value multiplied by 2^power we get
96+ * an additional 2^power^n to divide for every element. For a reasonable
97+ * precision this would overflow after a few iterations. Therefore we
98+ * divide the x^n part whenever its about to overflow (xmax).
99+ */
100+
101+static u32 sgp40_exp(int exp, u32 power, u32 rounds)
102+{
103+ u32 x, y, xp;
104+ u32 factorial, divider, xmax;
105+ int sign = 1;
106+ int i;
107+
108+ if (exp == 0)
109+ return 1 << power;
110+ else if (exp < 0) {
111+ sign = -1;
112+ exp *= -1;
113+ }
114+
115+ xmax = 0x7FFFFFFF / exp;
116+ x = exp;
117+ xp = 1;
118+ factorial = 1;
119+ y = 1 << power;
120+ divider = 0;
121+
122+ for (i = 1; i <= rounds; i++) {
123+ xp *= x;
124+ factorial *= i;
125+ y += (xp >> divider) / factorial;
126+ divider += power;
127+ /* divide when next multiplication would overflow */
128+ if (xp >= xmax) {
129+ xp >>= power;
130+ divider -= power;
131+ }
132+ }
133+
134+ if (sign == -1)
135+ return (1 << (power * 2)) / y;
136+ else
137+ return y;
138+}
139+
140+static int sgp40_calc_voc(struct sgp40_data *data, u16 resistance_raw, int *voc)
141+{
142+ int x;
143+ u32 exp = 0;
144+
145+ /* we calculate as a multiple of 16384 (2^14) */
146+ mutex_lock(&data->lock);
147+ x = ((int)resistance_raw - data->res_calibbias) * 106;
148+ mutex_unlock(&data->lock);
149+
150+ /* voc = 500 / (1 + e^x) */
151+ exp = sgp40_exp(x, SGP40_CALC_POWER, 18);
152+ *voc = 500 * ((1 << (SGP40_CALC_POWER * 2)) / ((1<<SGP40_CALC_POWER) + exp));
153+
154+ dev_dbg(data->dev, "raw: %d res_calibbias: %d x: %d exp: %d voc: %d\n",
155+ resistance_raw, data->res_calibbias, x, exp, *voc);
156+
157+ return 0;
158+}
159+
160+static int sgp40_measure_resistance_raw(struct sgp40_data *data, u16 *resistance_raw)
161+{
162+ int ret;
163+ struct i2c_client *client = data->client;
164+ u32 ticks;
165+ u16 ticks16;
166+ u8 crc;
167+ struct sgp40_tg_measure tg = {.command = {0x26, 0x0F}};
168+ struct sgp40_tg_result tgres;
169+
170+ mutex_lock(&data->lock);
171+
172+ ticks = (data->rht / 10) * 65535 / 10000;
173+ ticks16 = (u16)clamp(ticks, 0u, 65535u); /* clamp between 0 .. 100 %rH */
174+ tg.rht_ticks = cpu_to_be16(ticks16);
175+ tg.rht_crc = crc8(sgp40_crc8_table, (u8 *)&tg.rht_ticks, 2, SGP40_CRC8_INIT);
176+
177+ ticks = ((data->temp + 45000) / 10 ) * 65535 / 17500;
178+ ticks16 = (u16)clamp(ticks, 0u, 65535u); /* clamp between -45 .. +130 °C */
179+ tg.temp_ticks = cpu_to_be16(ticks16);
180+ tg.temp_crc = crc8(sgp40_crc8_table, (u8 *)&tg.temp_ticks, 2, SGP40_CRC8_INIT);
181+
182+ mutex_unlock(&data->lock);
183+
184+ ret = i2c_master_send(client, (const char *)&tg, sizeof(tg));
185+ if (ret != sizeof(tg)) {
186+ dev_warn(data->dev, "i2c_master_send ret: %d sizeof: %zu\n", ret, sizeof(tg));
187+ return -EIO;
188+ }
189+ msleep(30);
190+
191+ ret = i2c_master_recv(client, (u8 *)&tgres, sizeof(tgres));
192+ if (ret < 0)
193+ return ret;
194+ if (ret != sizeof(tgres)) {
195+ dev_warn(data->dev, "i2c_master_recv ret: %d sizeof: %zu\n", ret, sizeof(tgres));
196+ return -EIO;
197+ }
198+
199+ crc = crc8(sgp40_crc8_table, (u8 *)&tgres.res_ticks, 2, SGP40_CRC8_INIT);
200+ if (crc != tgres.res_crc) {
201+ dev_err(data->dev, "CRC error while measure-raw\n");
202+ return -EIO;
203+ }
204+
205+ *resistance_raw = be16_to_cpu(tgres.res_ticks);
206+
207+ return 0;
208+}
209+
210+static int sgp40_read_raw(struct iio_dev *indio_dev,
211+ struct iio_chan_spec const *chan, int *val,
212+ int *val2, long mask)
213+{
214+ struct sgp40_data *data = iio_priv(indio_dev);
215+ int ret, voc;
216+ u16 resistance_raw;
217+
218+ switch (mask) {
219+ case IIO_CHAN_INFO_RAW:
220+ switch (chan->type) {
221+ case IIO_RESISTANCE:
222+ ret = sgp40_measure_resistance_raw(data, &resistance_raw);
223+ if (ret)
224+ return ret;
225+
226+ *val = resistance_raw;
227+ return IIO_VAL_INT;
228+ case IIO_TEMP:
229+ mutex_lock(&data->lock);
230+ *val = data->temp;
231+ mutex_unlock(&data->lock);
232+ return IIO_VAL_INT;
233+ case IIO_HUMIDITYRELATIVE:
234+ mutex_lock(&data->lock);
235+ *val = data->rht;
236+ mutex_unlock(&data->lock);
237+ return IIO_VAL_INT;
238+ default:
239+ return -EINVAL;
240+ }
241+ case IIO_CHAN_INFO_PROCESSED:
242+ ret = sgp40_measure_resistance_raw(data, &resistance_raw);
243+ if (ret)
244+ return ret;
245+
246+ ret = sgp40_calc_voc(data, resistance_raw, &voc);
247+ if (ret)
248+ return ret;
249+
250+ *val = voc / (1 << SGP40_CALC_POWER);
251+ /*
252+ * calculation should fit into integer, where:
253+ * voc <= (500 * 2^SGP40_CALC_POWER) = 8192000
254+ * (with SGP40_CALC_POWER = 14)
255+ */
256+ *val2 = ((voc % (1 << SGP40_CALC_POWER)) * 244) / (1 << (SGP40_CALC_POWER - 12));
257+ dev_dbg(data->dev, "voc: %d val: %d.%06d\n", voc, *val, *val2);
258+ return IIO_VAL_INT_PLUS_MICRO;
259+ case IIO_CHAN_INFO_CALIBBIAS:
260+ mutex_lock(&data->lock);
261+ *val = data->res_calibbias;
262+ mutex_unlock(&data->lock);
263+ return IIO_VAL_INT;
264+ default:
265+ return -EINVAL;
266+ }
267+}
268+
269+static int sgp40_write_raw(struct iio_dev *indio_dev,
270+ struct iio_chan_spec const *chan, int val,
271+ int val2, long mask)
272+{
273+ struct sgp40_data *data = iio_priv(indio_dev);
274+
275+ switch (mask) {
276+ case IIO_CHAN_INFO_RAW:
277+ switch (chan->type) {
278+ case IIO_TEMP:
279+ if ((val < -45000) || (val > 130000))
280+ return -EINVAL;
281+
282+ mutex_lock(&data->lock);
283+ data->temp = val;
284+ mutex_unlock(&data->lock);
285+ return 0;
286+ case IIO_HUMIDITYRELATIVE:
287+ if ((val < 0) || (val > 100000))
288+ return -EINVAL;
289+
290+ mutex_lock(&data->lock);
291+ data->rht = val;
292+ mutex_unlock(&data->lock);
293+ return 0;
294+ default:
295+ return -EINVAL;
296+ }
297+ case IIO_CHAN_INFO_CALIBBIAS:
298+ if ((val < 20000) || (val > 52768))
299+ return -EINVAL;
300+
301+ mutex_lock(&data->lock);
302+ data->res_calibbias = val;
303+ mutex_unlock(&data->lock);
304+ return 0;
305+ }
306+ return -EINVAL;
307+}
308+
309+static const struct iio_info sgp40_info = {
310+ .read_raw = sgp40_read_raw,
311+ .write_raw = sgp40_write_raw,
312+};
313+
314+static int sgp40_probe(struct i2c_client *client,
315+ const struct i2c_device_id *id)
316+{
317+ struct device *dev = &client->dev;
318+ struct iio_dev *indio_dev;
319+ struct sgp40_data *data;
320+ int ret;
321+
322+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
323+ if (!indio_dev)
324+ return -ENOMEM;
325+
326+ data = iio_priv(indio_dev);
327+ data->client = client;
328+ data->dev = dev;
329+
330+ crc8_populate_msb(sgp40_crc8_table, SGP40_CRC8_POLYNOMIAL);
331+
332+ mutex_init(&data->lock);
333+
334+ /* set default values */
335+ data->rht = 50000; /* 50 % */
336+ data->temp = 25000; /* 25 °C */
337+ data->res_calibbias = 30000; /* resistance raw value for voc index of 250 */
338+
339+ indio_dev->info = &sgp40_info;
340+ indio_dev->name = id->name;
341+ indio_dev->modes = INDIO_DIRECT_MODE;
342+ indio_dev->channels = sgp40_channels;
343+ indio_dev->num_channels = ARRAY_SIZE(sgp40_channels);
344+
345+ ret = devm_iio_device_register(dev, indio_dev);
346+ if (ret)
347+ dev_err(dev, "failed to register iio device\n");
348+
349+ return ret;
350+}
351+
352+static const struct i2c_device_id sgp40_id[] = {
353+ { "sgp40" },
354+ { }
355+};
356+
357+MODULE_DEVICE_TABLE(i2c, sgp40_id);
358+
359+static const struct of_device_id sgp40_dt_ids[] = {
360+ { .compatible = "sensirion,sgp40" },
361+ { }
362+};
363+
364+MODULE_DEVICE_TABLE(of, sgp40_dt_ids);
365+
366+static struct i2c_driver sgp40_driver = {
367+ .driver = {
368+ .name = "sgp40",
369+ .of_match_table = sgp40_dt_ids,
370+ },
371+ .probe = sgp40_probe,
372+ .id_table = sgp40_id,
373+};
374+module_i2c_driver(sgp40_driver);
375+
376+MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
377+MODULE_DESCRIPTION("Sensirion SGP40 gas sensor");
378+MODULE_LICENSE("GPL v2");
drivers/iio/common/st_sensors/st_sensors_buffer.c+0−2
@@ -9,13 +9,11 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
1312 #include <linux/iio/iio.h>
1413 #include <linux/iio/trigger.h>
1514 #include <linux/interrupt.h>
1615 #include <linux/iio/buffer.h>
1716 #include <linux/iio/trigger_consumer.h>
18−#include <linux/iio/triggered_buffer.h>
1917 #include <linux/irqreturn.h>
2018 #include <linux/regmap.h>
2119
drivers/iio/common/st_sensors/st_sensors_core.c+1−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/slab.h>
1313 #include <linux/delay.h>
1414 #include <linux/iio/iio.h>
15+#include <linux/mutex.h>
1516 #include <linux/property.h>
1617 #include <linux/regulator/consumer.h>
1718 #include <linux/regmap.h>
drivers/iio/common/st_sensors/st_sensors_core.h+1−0
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 */
55 #ifndef __ST_SENSORS_CORE_H
66 #define __ST_SENSORS_CORE_H
7+struct iio_dev;
78 int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
89 u8 reg_addr, u8 mask, u8 data);
910 #endif
drivers/iio/common/st_sensors/st_sensors_i2c.c+1−2
@@ -7,15 +7,14 @@ · 6 unmodified lines
77 * Denis Ciocca <denis.ciocca@st.com>
88 */
99
10+#include <linux/i2c.h>
1011 #include <linux/kernel.h>
1112 #include <linux/module.h>
12−#include <linux/slab.h>
1313 #include <linux/iio/iio.h>
1414 #include <linux/regmap.h>
1515
1616 #include <linux/iio/common/st_sensors_i2c.h>
1717
18−
1918 #define ST_SENSORS_I2C_MULTIREAD 0x80
2019
2120 static const struct regmap_config st_sensors_i2c_regmap_config = {
drivers/iio/common/st_sensors/st_sensors_spi.c+1−2
@@ -9,13 +9,12 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
1312 #include <linux/iio/iio.h>
1413 #include <linux/property.h>
1514 #include <linux/regmap.h>
15+#include <linux/spi/spi.h>
1616
1717 #include <linux/iio/common/st_sensors_spi.h>
18−#include "st_sensors_core.h"
1918
2019 #define ST_SENSORS_SPI_MULTIREAD 0xc0
2120
drivers/iio/common/st_sensors/st_sensors_trigger.c+0−1
@@ -9,7 +9,6 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
1312 #include <linux/iio/iio.h>
1413 #include <linux/iio/trigger.h>
1514 #include <linux/interrupt.h>
drivers/iio/dac/ad5624r_spi.c+17−1
@@ -229,7 +229,7 @@ static int ad5624r_probe(struct spi_device *spi) · 228 unmodified lines
229229 if (!indio_dev)
230230 return -ENOMEM;
231231 st = iio_priv(indio_dev);
232− st->reg = devm_regulator_get(&spi->dev, "vcc");
232+ st->reg = devm_regulator_get_optional(&spi->dev, "vref");
233233 if (!IS_ERR(st->reg)) {
234234 ret = regulator_enable(st->reg);
235235 if (ret)
@@ -240,6 +240,22 @@ static int ad5624r_probe(struct spi_device *spi) · 4 unmodified lines
240240 goto error_disable_reg;
241241
242242 voltage_uv = ret;
243+ } else {
244+ if (PTR_ERR(st->reg) != -ENODEV)
245+ return PTR_ERR(st->reg);
246+ /* Backwards compatibility. This naming is not correct */
247+ st->reg = devm_regulator_get_optional(&spi->dev, "vcc");
248+ if (!IS_ERR(st->reg)) {
249+ ret = regulator_enable(st->reg);
250+ if (ret)
251+ return ret;
252+
253+ ret = regulator_get_voltage(st->reg);
254+ if (ret < 0)
255+ goto error_disable_reg;
256+
257+ voltage_uv = ret;
258+ }
243259 }
244260
245261 spi_set_drvdata(spi, indio_dev);
drivers/iio/dac/max5821.c+17−24
@@ -294,6 +294,11 @@ static const struct iio_info max5821_info = { · 293 unmodified lines
294294 .write_raw = max5821_write_raw,
295295 };
296296
297+static void max5821_regulator_disable(void *reg)
298+{
299+ regulator_disable(reg);
300+}
301+
297302 static int max5821_probe(struct i2c_client *client,
298303 const struct i2c_device_id *id)
299304 {
@@ -306,7 +311,6 @@ static int max5821_probe(struct i2c_client *client, · 6 unmodified lines
306311 if (!indio_dev)
307312 return -ENOMEM;
308313 data = iio_priv(indio_dev);
309− i2c_set_clientdata(client, indio_dev);
310314 data->client = client;
311315 mutex_init(&data->lock);
312316
@@ -321,21 +325,29 @@ static int max5821_probe(struct i2c_client *client, · 8 unmodified lines
321325 ret = PTR_ERR(data->vref_reg);
322326 dev_err(&client->dev,
323327 "Failed to get vref regulator: %d\n", ret);
324− goto error_free_reg;
328+ return ret;
325329 }
326330
327331 ret = regulator_enable(data->vref_reg);
328332 if (ret) {
329333 dev_err(&client->dev,
330334 "Failed to enable vref regulator: %d\n", ret);
331− goto error_free_reg;
335+ return ret;
336+ }
337+
338+ ret = devm_add_action_or_reset(&client->dev, max5821_regulator_disable,
339+ data->vref_reg);
340+ if (ret) {
341+ dev_err(&client->dev,
342+ "Failed to add action to managed regulator: %d\n", ret);
343+ return ret;
332344 }
333345
334346 ret = regulator_get_voltage(data->vref_reg);
335347 if (ret < 0) {
336348 dev_err(&client->dev,
337349 "Failed to get voltage on regulator: %d\n", ret);
338− goto error_disable_reg;
350+ return ret;
339351 }
340352
341353 data->vref_mv = ret / 1000;
@@ -346,25 +358,7 @@ static int max5821_probe(struct i2c_client *client, · 4 unmodified lines
346358 indio_dev->modes = INDIO_DIRECT_MODE;
347359 indio_dev->info = &max5821_info;
348360
349− return iio_device_register(indio_dev);
350−
351−error_disable_reg:
352− regulator_disable(data->vref_reg);
353−
354−error_free_reg:
355−
356− return ret;
357−}
358−
359−static int max5821_remove(struct i2c_client *client)
360−{
361− struct iio_dev *indio_dev = i2c_get_clientdata(client);
362− struct max5821_data *data = iio_priv(indio_dev);
363−
364− iio_device_unregister(indio_dev);
365− regulator_disable(data->vref_reg);
366−
367− return 0;
361+ return devm_iio_device_register(&client->dev, indio_dev);
368362 }
369363
370364 static const struct i2c_device_id max5821_id[] = {
@@ -386,7 +380,6 @@ static struct i2c_driver max5821_driver = { · 15 unmodified lines
386380 .pm = &max5821_pm_ops,
387381 },
388382 .probe = max5821_probe,
389− .remove = max5821_remove,
390383 .id_table = max5821_id,
391384 };
392385 module_i2c_driver(max5821_driver);
drivers/iio/gyro/hid-sensor-gyro-3d.c+4−7
@@ -303,8 +303,8 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) · 302 unmodified lines
303303 return ret;
304304 }
305305
306− indio_dev->channels = kmemdup(gyro_3d_channels,
307− sizeof(gyro_3d_channels), GFP_KERNEL);
306+ indio_dev->channels = devm_kmemdup(&pdev->dev, gyro_3d_channels,
307+ sizeof(gyro_3d_channels), GFP_KERNEL);
308308 if (!indio_dev->channels) {
309309 dev_err(&pdev->dev, "failed to duplicate channels\n");
310310 return -ENOMEM;
@@ -315,7 +315,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) · 4 unmodified lines
315315 HID_USAGE_SENSOR_GYRO_3D, gyro_state);
316316 if (ret) {
317317 dev_err(&pdev->dev, "failed to setup attributes\n");
318− goto error_free_dev_mem;
318+ return ret;
319319 }
320320
321321 indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
@@ -329,7 +329,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) · 7 unmodified lines
329329 &gyro_state->common_attributes);
330330 if (ret < 0) {
331331 dev_err(&pdev->dev, "trigger setup failed\n");
332− goto error_free_dev_mem;
332+ return ret;
333333 }
334334
335335 ret = iio_device_register(indio_dev);
@@ -354,8 +354,6 @@ error_iio_unreg: · 18 unmodified lines
354354 iio_device_unregister(indio_dev);
355355 error_remove_trigger:
356356 hid_sensor_remove_trigger(indio_dev, &gyro_state->common_attributes);
357−error_free_dev_mem:
358− kfree(indio_dev->channels);
359357 return ret;
360358 }
361359
@@ -369,7 +367,6 @@ static int hid_gyro_3d_remove(struct platform_device *pdev) · 7 unmodified lines
369367 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D);
370368 iio_device_unregister(indio_dev);
371369 hid_sensor_remove_trigger(indio_dev, &gyro_state->common_attributes);
372− kfree(indio_dev->channels);
373370
374371 return 0;
375372 }
drivers/iio/gyro/st_gyro.h+0−4
@@ -26,7 +26,6 @@ · 25 unmodified lines
2626
2727 #ifdef CONFIG_IIO_BUFFER
2828 int st_gyro_allocate_ring(struct iio_dev *indio_dev);
29−void st_gyro_deallocate_ring(struct iio_dev *indio_dev);
3029 int st_gyro_trig_set_state(struct iio_trigger *trig, bool state);
3130 #define ST_GYRO_TRIGGER_SET_STATE (&st_gyro_trig_set_state)
3231 #else /* CONFIG_IIO_BUFFER */
@@ -34,9 +33,6 @@ static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev) · 1 unmodified line
3433 {
3534 return 0;
3635 }
37−static inline void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
38−{
39−}
4036 #define ST_GYRO_TRIGGER_SET_STATE NULL
4137 #endif /* CONFIG_IIO_BUFFER */
4238
drivers/iio/gyro/st_gyro_buffer.c+3−13
@@ -9,14 +9,9 @@ · 8 unmodified lines
99
1010 #include <linux/module.h>
1111 #include <linux/kernel.h>
12−#include <linux/slab.h>
13−#include <linux/stat.h>
14−#include <linux/interrupt.h>
15−#include <linux/i2c.h>
16−#include <linux/delay.h>
1712 #include <linux/iio/iio.h>
1813 #include <linux/iio/buffer.h>
19−#include <linux/iio/trigger_consumer.h>
14+#include <linux/iio/trigger.h>
2015 #include <linux/iio/triggered_buffer.h>
2116
2217 #include <linux/iio/common/st_sensors.h>
@@ -66,13 +61,8 @@ static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = { · 43 unmodified lines
6661
6762 int st_gyro_allocate_ring(struct iio_dev *indio_dev)
6863 {
69− return iio_triggered_buffer_setup(indio_dev, NULL,
70− &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
71−}
72−
73−void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
74−{
75− iio_triggered_buffer_cleanup(indio_dev);
64+ return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
65+ NULL, &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
7666 }
7767
7868 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
drivers/iio/gyro/st_gyro_core.c+3−12
@@ -9,17 +9,12 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
13−#include <linux/errno.h>
14−#include <linux/types.h>
12+#include <linux/mutex.h>
1513 #include <linux/interrupt.h>
16−#include <linux/i2c.h>
17−#include <linux/irq.h>
18−#include <linux/delay.h>
14+#include <linux/sysfs.h>
1915 #include <linux/iio/iio.h>
2016 #include <linux/iio/sysfs.h>
2117 #include <linux/iio/trigger.h>
22−#include <linux/iio/buffer.h>
2318
2419 #include <linux/iio/common/st_sensors.h>
2520 #include "st_gyro.h"
@@ -517,7 +512,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) · 491 unmodified lines
517512 err = st_sensors_allocate_trigger(indio_dev,
518513 ST_GYRO_TRIGGER_OPS);
519514 if (err < 0)
520− goto st_gyro_probe_trigger_error;
515+ return err;
521516 }
522517
523518 err = iio_device_register(indio_dev);
@@ -532,8 +527,6 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) · 8 unmodified lines
532527 st_gyro_device_register_error:
533528 if (gdata->irq > 0)
534529 st_sensors_deallocate_trigger(indio_dev);
535−st_gyro_probe_trigger_error:
536− st_gyro_deallocate_ring(indio_dev);
537530 return err;
538531 }
539532 EXPORT_SYMBOL(st_gyro_common_probe);
@@ -545,8 +538,6 @@ void st_gyro_common_remove(struct iio_dev *indio_dev) · 5 unmodified lines
545538 iio_device_unregister(indio_dev);
546539 if (gdata->irq > 0)
547540 st_sensors_deallocate_trigger(indio_dev);
548−
549− st_gyro_deallocate_ring(indio_dev);
550541 }
551542 EXPORT_SYMBOL(st_gyro_common_remove);
552543
drivers/iio/gyro/st_gyro_i2c.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/i2c.h>
1414 #include <linux/iio/iio.h>
1515
drivers/iio/gyro/st_gyro_spi.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/spi/spi.h>
1414 #include <linux/iio/iio.h>
1515
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c+18−4
@@ -143,6 +143,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 142 unmodified lines
143143 .config = &chip_config_6050,
144144 .fifo_size = 1024,
145145 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
146+ .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
146147 },
147148 {
148149 .whoami = INV_MPU6500_WHOAMI_VALUE,
@@ -151,6 +152,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
151152 .config = &chip_config_6500,
152153 .fifo_size = 512,
153154 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
155+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
154156 },
155157 {
156158 .whoami = INV_MPU6515_WHOAMI_VALUE,
@@ -159,6 +161,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
159161 .config = &chip_config_6500,
160162 .fifo_size = 512,
161163 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
164+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
162165 },
163166 {
164167 .whoami = INV_MPU6880_WHOAMI_VALUE,
@@ -167,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
167170 .config = &chip_config_6500,
168171 .fifo_size = 4096,
169172 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
173+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
170174 },
171175 {
172176 .whoami = INV_MPU6000_WHOAMI_VALUE,
@@ -175,6 +179,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
175179 .config = &chip_config_6050,
176180 .fifo_size = 1024,
177181 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
182+ .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
178183 },
179184 {
180185 .whoami = INV_MPU9150_WHOAMI_VALUE,
@@ -183,6 +188,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
183188 .config = &chip_config_6050,
184189 .fifo_size = 1024,
185190 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
191+ .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME},
186192 },
187193 {
188194 .whoami = INV_MPU9250_WHOAMI_VALUE,
@@ -191,6 +197,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
191197 .config = &chip_config_6500,
192198 .fifo_size = 512,
193199 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
200+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
194201 },
195202 {
196203 .whoami = INV_MPU9255_WHOAMI_VALUE,
@@ -199,6 +206,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
199206 .config = &chip_config_6500,
200207 .fifo_size = 512,
201208 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
209+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
202210 },
203211 {
204212 .whoami = INV_ICM20608_WHOAMI_VALUE,
@@ -207,6 +215,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
207215 .config = &chip_config_6500,
208216 .fifo_size = 512,
209217 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
218+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
210219 },
211220 {
212221 .whoami = INV_ICM20609_WHOAMI_VALUE,
@@ -215,6 +224,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
215224 .config = &chip_config_6500,
216225 .fifo_size = 4 * 1024,
217226 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
227+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
218228 },
219229 {
220230 .whoami = INV_ICM20689_WHOAMI_VALUE,
@@ -223,6 +233,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
223233 .config = &chip_config_6500,
224234 .fifo_size = 4 * 1024,
225235 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
236+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
226237 },
227238 {
228239 .whoami = INV_ICM20602_WHOAMI_VALUE,
@@ -231,6 +242,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
231242 .config = &chip_config_6500,
232243 .fifo_size = 1008,
233244 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
245+ .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME},
234246 },
235247 {
236248 .whoami = INV_ICM20690_WHOAMI_VALUE,
@@ -239,6 +251,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
239251 .config = &chip_config_6500,
240252 .fifo_size = 1024,
241253 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
254+ .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME},
242255 },
243256 {
244257 .whoami = INV_IAM20680_WHOAMI_VALUE,
@@ -247,6 +260,7 @@ static const struct inv_mpu6050_hw hw_info[] = { · 2 unmodified lines
247260 .config = &chip_config_6500,
248261 .fifo_size = 512,
249262 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
263+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
250264 },
251265 };
252266
@@ -379,12 +393,12 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, · 126 unmodified lines
379393 sleep = 0;
380394 if (en) {
381395 if (mask & INV_MPU6050_SENSOR_ACCL) {
382− if (sleep < INV_MPU6050_ACCEL_UP_TIME)
383− sleep = INV_MPU6050_ACCEL_UP_TIME;
396+ if (sleep < st->hw->startup_time.accel)
397+ sleep = st->hw->startup_time.accel;
384398 }
385399 if (mask & INV_MPU6050_SENSOR_GYRO) {
386− if (sleep < INV_MPU6050_GYRO_UP_TIME)
387− sleep = INV_MPU6050_GYRO_UP_TIME;
400+ if (sleep < st->hw->startup_time.gyro)
401+ sleep = st->hw->startup_time.gyro;
388402 }
389403 } else {
390404 if (mask & INV_MPU6050_SENSOR_GYRO) {
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h+16−2
@@ -149,6 +149,10 @@ struct inv_mpu6050_hw { · 148 unmodified lines
149149 int offset;
150150 int scale;
151151 } temp;
152+ struct {
153+ unsigned int accel;
154+ unsigned int gyro;
155+ } startup_time;
152156 };
153157
154158 /*
@@ -320,11 +324,21 @@ struct inv_mpu6050_state { · 165 unmodified lines
320324 /* delay time in milliseconds */
321325 #define INV_MPU6050_POWER_UP_TIME 100
322326 #define INV_MPU6050_TEMP_UP_TIME 100
323−#define INV_MPU6050_ACCEL_UP_TIME 20
324−#define INV_MPU6050_GYRO_UP_TIME 35
327+#define INV_MPU6050_ACCEL_STARTUP_TIME 20
328+#define INV_MPU6050_GYRO_STARTUP_TIME 60
325329 #define INV_MPU6050_GYRO_DOWN_TIME 150
326330 #define INV_MPU6050_SUSPEND_DELAY_MS 2000
327331
332+#define INV_MPU6500_GYRO_STARTUP_TIME 70
333+#define INV_MPU6500_ACCEL_STARTUP_TIME 30
334+
335+#define INV_ICM20602_GYRO_STARTUP_TIME 100
336+#define INV_ICM20602_ACCEL_STARTUP_TIME 20
337+
338+#define INV_ICM20690_GYRO_STARTUP_TIME 80
339+#define INV_ICM20690_ACCEL_STARTUP_TIME 10
340+
341+
328342 /* delay time in microseconds */
329343 #define INV_MPU6050_REG_UP_TIME_MIN 5000
330344 #define INV_MPU6050_REG_UP_TIME_MAX 10000
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c+2−13
@@ -91,22 +91,11 @@ static unsigned int inv_scan_query(struct iio_dev *indio_dev) · 90 unmodified lines
9191
9292 static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st)
9393 {
94− unsigned int gyro_skip = 0;
95− unsigned int magn_skip = 0;
96− unsigned int skip_samples;
97−
98− /* gyro first sample is out of specs, skip it */
99− if (st->chip_config.gyro_fifo_enable)
100− gyro_skip = 1;
94+ unsigned int skip_samples = 0;
10195
10296 /* mag first sample is always not ready, skip it */
10397 if (st->chip_config.magn_fifo_enable)
104− magn_skip = 1;
105−
106− /* compute first samples to skip */
107− skip_samples = gyro_skip;
108− if (magn_skip > skip_samples)
109− skip_samples = magn_skip;
98+ skip_samples = 1;
11099
111100 return skip_samples;
112101 }
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c+1−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/device.h>
1111 #include <linux/err.h>
1212 #include <linux/module.h>
13+#include <linux/regmap.h>
1314 #include <linux/regulator/consumer.h>
1415
1516 #include <linux/iio/common/st_sensors.h>
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c+2−1
@@ -10,7 +10,8 @@ · 9 unmodified lines
1010 #include <linux/i2c.h>
1111 #include <linux/kernel.h>
1212 #include <linux/module.h>
13−#include <linux/slab.h>
13+#include <linux/mod_devicetable.h>
14+#include <linux/regmap.h>
1415
1516 #include <linux/iio/common/st_sensors_i2c.h>
1617
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c+2−1
@@ -9,7 +9,8 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
13+#include <linux/regmap.h>
1314 #include <linux/spi/spi.h>
1415
1516 #include <linux/iio/common/st_sensors_spi.h>
drivers/iio/industrialio-buffer.c+5−4
@@ -354,13 +354,14 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, · 353 unmodified lines
354354 const unsigned long *mask;
355355 unsigned long *trialmask;
356356
357− trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL);
358− if (trialmask == NULL)
359− return -ENOMEM;
360357 if (!indio_dev->masklength) {
361358 WARN(1, "Trying to set scanmask prior to registering buffer\n");
362− goto err_invalid_mask;
359+ return -EINVAL;
363360 }
361+
362+ trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
363+ if (!trialmask)
364+ return -ENOMEM;
364365 bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength);
365366 set_bit(bit, trialmask);
366367
drivers/iio/industrialio-core.c+29−4
@@ -740,10 +740,13 @@ static ssize_t iio_read_channel_label(struct device *dev, · 739 unmodified lines
740740 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
741741 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
742742
743− if (!indio_dev->info->read_label)
744− return -EINVAL;
743+ if (indio_dev->info->read_label)
744+ return indio_dev->info->read_label(indio_dev, this_attr->c, buf);
745+
746+ if (this_attr->c->extend_name)
747+ return sprintf(buf, "%s\n", this_attr->c->extend_name);
745748
746− return indio_dev->info->read_label(indio_dev, this_attr->c, buf);
749+ return -EINVAL;
747750 }
748751
749752 static ssize_t iio_read_channel_info(struct device *dev,
@@ -1183,7 +1186,7 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev, · 433 unmodified lines
11831186 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
11841187 int ret;
11851188
1186− if (!indio_dev->info->read_label)
1189+ if (!indio_dev->info->read_label && !chan->extend_name)
11871190 return 0;
11881191
11891192 ret = __iio_add_chan_devattr("label",
@@ -1858,6 +1861,24 @@ static int iio_check_unique_scan_index(struct iio_dev *indio_dev) · 668 unmodified lines
18581861 return 0;
18591862 }
18601863
1864+static int iio_check_extended_name(const struct iio_dev *indio_dev)
1865+{
1866+ unsigned int i;
1867+
1868+ if (!indio_dev->info->read_label)
1869+ return 0;
1870+
1871+ for (i = 0; i < indio_dev->num_channels; i++) {
1872+ if (indio_dev->channels[i].extend_name) {
1873+ dev_err(&indio_dev->dev,
1874+ "Cannot use labels and extend_name at the same time\n");
1875+ return -EINVAL;
1876+ }
1877+ }
1878+
1879+ return 0;
1880+}
1881+
18611882 static const struct iio_buffer_setup_ops noop_ring_setup_ops;
18621883
18631884 int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
@@ -1882,6 +1903,10 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) · 18 unmodified lines
18821903 if (ret < 0)
18831904 return ret;
18841905
1906+ ret = iio_check_extended_name(indio_dev);
1907+ if (ret < 0)
1908+ return ret;
1909+
18851910 iio_device_register_debugfs(indio_dev);
18861911
18871912 ret = iio_buffers_alloc_sysfs_and_mask(indio_dev);
drivers/iio/light/adjd_s311.c+9−44
@@ -54,7 +54,10 @@ · 53 unmodified lines
5454
5555 struct adjd_s311_data {
5656 struct i2c_client *client;
57− u16 *buffer;
57+ struct {
58+ s16 chans[4];
59+ s64 ts __aligned(8);
60+ } scan;
5861 };
5962
6063 enum adjd_s311_channel_idx {
@@ -129,10 +132,10 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) · 68 unmodified lines
129132 if (ret < 0)
130133 goto done;
131134
132− data->buffer[j++] = ret & ADJD_S311_DATA_MASK;
135+ data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK;
133136 }
134137
135− iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns);
138+ iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns);
136139
137140 done:
138141 iio_trigger_notify_done(indio_dev->trig);
@@ -225,23 +228,9 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev, · 86 unmodified lines
225228 return -EINVAL;
226229 }
227230
228−static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev,
229− const unsigned long *scan_mask)
230−{
231− struct adjd_s311_data *data = iio_priv(indio_dev);
232−
233− kfree(data->buffer);
234− data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
235− if (data->buffer == NULL)
236− return -ENOMEM;
237−
238− return 0;
239−}
240−
241231 static const struct iio_info adjd_s311_info = {
242232 .read_raw = adjd_s311_read_raw,
243233 .write_raw = adjd_s311_write_raw,
244− .update_scan_mode = adjd_s311_update_scan_mode,
245234 };
246235
247236 static int adjd_s311_probe(struct i2c_client *client,
@@ -256,7 +245,6 @@ static int adjd_s311_probe(struct i2c_client *client, · 8 unmodified lines
256245 return -ENOMEM;
257246
258247 data = iio_priv(indio_dev);
259− i2c_set_clientdata(client, indio_dev);
260248 data->client = client;
261249
262250 indio_dev->info = &adjd_s311_info;
@@ -265,34 +253,12 @@ static int adjd_s311_probe(struct i2c_client *client, · 2 unmodified lines
265253 indio_dev->num_channels = ARRAY_SIZE(adjd_s311_channels);
266254 indio_dev->modes = INDIO_DIRECT_MODE;
267255
268− err = iio_triggered_buffer_setup(indio_dev, NULL,
269− adjd_s311_trigger_handler, NULL);
256+ err = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL,
257+ adjd_s311_trigger_handler, NULL);
270258 if (err < 0)
271259 return err;
272260
273− err = iio_device_register(indio_dev);
274− if (err)
275− goto exit_unreg_buffer;
276−
277− dev_info(&client->dev, "ADJD-S311 color sensor registered\n");
278−
279− return 0;
280−
281−exit_unreg_buffer:
282− iio_triggered_buffer_cleanup(indio_dev);
283− return err;
284−}
285−
286−static int adjd_s311_remove(struct i2c_client *client)
287−{
288− struct iio_dev *indio_dev = i2c_get_clientdata(client);
289− struct adjd_s311_data *data = iio_priv(indio_dev);
290−
291− iio_device_unregister(indio_dev);
292− iio_triggered_buffer_cleanup(indio_dev);
293− kfree(data->buffer);
294−
295− return 0;
261+ return devm_iio_device_register(&client->dev, indio_dev);
296262 }
297263
298264 static const struct i2c_device_id adjd_s311_id[] = {
@@ -306,7 +272,6 @@ static struct i2c_driver adjd_s311_driver = { · 7 unmodified lines
306272 .name = ADJD_S311_DRV_NAME,
307273 },
308274 .probe = adjd_s311_probe,
309− .remove = adjd_s311_remove,
310275 .id_table = adjd_s311_id,
311276 };
312277 module_i2c_driver(adjd_s311_driver);
drivers/iio/light/cm3323.c+7−0
@@ -256,9 +256,16 @@ static const struct i2c_device_id cm3323_id[] = { · 255 unmodified lines
256256 };
257257 MODULE_DEVICE_TABLE(i2c, cm3323_id);
258258
259+static const struct of_device_id cm3323_of_match[] = {
260+ { .compatible = "capella,cm3323", },
261+ { /* sentinel */ }
262+};
263+MODULE_DEVICE_TABLE(of, cm3323_of_match);
264+
259265 static struct i2c_driver cm3323_driver = {
260266 .driver = {
261267 .name = CM3323_DRV_NAME,
268+ .of_match_table = cm3323_of_match,
262269 },
263270 .probe = cm3323_probe,
264271 .id_table = cm3323_id,
drivers/iio/light/hid-sensor-als.c+4−7
@@ -294,8 +294,8 @@ static int hid_als_probe(struct platform_device *pdev) · 293 unmodified lines
294294 return ret;
295295 }
296296
297− indio_dev->channels = kmemdup(als_channels,
298− sizeof(als_channels), GFP_KERNEL);
297+ indio_dev->channels = devm_kmemdup(&pdev->dev, als_channels,
298+ sizeof(als_channels), GFP_KERNEL);
299299 if (!indio_dev->channels) {
300300 dev_err(&pdev->dev, "failed to duplicate channels\n");
301301 return -ENOMEM;
@@ -306,7 +306,7 @@ static int hid_als_probe(struct platform_device *pdev) · 4 unmodified lines
306306 HID_USAGE_SENSOR_ALS, als_state);
307307 if (ret) {
308308 dev_err(&pdev->dev, "failed to setup attributes\n");
309− goto error_free_dev_mem;
309+ return ret;
310310 }
311311
312312 indio_dev->num_channels =
@@ -321,7 +321,7 @@ static int hid_als_probe(struct platform_device *pdev) · 8 unmodified lines
321321 &als_state->common_attributes);
322322 if (ret < 0) {
323323 dev_err(&pdev->dev, "trigger setup failed\n");
324− goto error_free_dev_mem;
324+ return ret;
325325 }
326326
327327 ret = iio_device_register(indio_dev);
@@ -346,8 +346,6 @@ error_iio_unreg: · 18 unmodified lines
346346 iio_device_unregister(indio_dev);
347347 error_remove_trigger:
348348 hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes);
349−error_free_dev_mem:
350− kfree(indio_dev->channels);
351349 return ret;
352350 }
353351
@@ -361,7 +359,6 @@ static int hid_als_remove(struct platform_device *pdev) · 7 unmodified lines
361359 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS);
362360 iio_device_unregister(indio_dev);
363361 hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes);
364− kfree(indio_dev->channels);
365362
366363 return 0;
367364 }
drivers/iio/light/hid-sensor-prox.c+4−7
@@ -253,8 +253,8 @@ static int hid_prox_probe(struct platform_device *pdev) · 252 unmodified lines
253253 return ret;
254254 }
255255
256− indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels),
257− GFP_KERNEL);
256+ indio_dev->channels = devm_kmemdup(&pdev->dev, prox_channels,
257+ sizeof(prox_channels), GFP_KERNEL);
258258 if (!indio_dev->channels) {
259259 dev_err(&pdev->dev, "failed to duplicate channels\n");
260260 return -ENOMEM;
@@ -265,7 +265,7 @@ static int hid_prox_probe(struct platform_device *pdev) · 4 unmodified lines
265265 HID_USAGE_SENSOR_PROX, prox_state);
266266 if (ret) {
267267 dev_err(&pdev->dev, "failed to setup attributes\n");
268− goto error_free_dev_mem;
268+ return ret;
269269 }
270270
271271 indio_dev->num_channels = ARRAY_SIZE(prox_channels);
@@ -279,7 +279,7 @@ static int hid_prox_probe(struct platform_device *pdev) · 7 unmodified lines
279279 &prox_state->common_attributes);
280280 if (ret) {
281281 dev_err(&pdev->dev, "trigger setup failed\n");
282− goto error_free_dev_mem;
282+ return ret;
283283 }
284284
285285 ret = iio_device_register(indio_dev);
@@ -304,8 +304,6 @@ error_iio_unreg: · 18 unmodified lines
304304 iio_device_unregister(indio_dev);
305305 error_remove_trigger:
306306 hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes);
307−error_free_dev_mem:
308− kfree(indio_dev->channels);
309307 return ret;
310308 }
311309
@@ -319,7 +317,6 @@ static int hid_prox_remove(struct platform_device *pdev) · 7 unmodified lines
319317 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PROX);
320318 iio_device_unregister(indio_dev);
321319 hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes);
322− kfree(indio_dev->channels);
323320
324321 return 0;
325322 }
drivers/iio/light/si1145.c+0−1
@@ -220,7 +220,6 @@ static int __si1145_command_reset(struct si1145_data *data) · 219 unmodified lines
220220 return -ETIMEDOUT;
221221 }
222222 msleep(SI1145_COMMAND_MINSLEEP_MS);
223− continue;
224223 }
225224 }
226225
drivers/iio/light/tcs3414.c+19−29
@@ -267,6 +267,18 @@ static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = { · 266 unmodified lines
267267 .predisable = tcs3414_buffer_predisable,
268268 };
269269
270+static int tcs3414_powerdown(struct tcs3414_data *data)
271+{
272+ return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
273+ data->control & ~(TCS3414_CONTROL_POWER |
274+ TCS3414_CONTROL_ADC_EN));
275+}
276+
277+static void tcs3414_powerdown_cleanup(void *data)
278+{
279+ tcs3414_powerdown(data);
280+}
281+
270282 static int tcs3414_probe(struct i2c_client *client,
271283 const struct i2c_device_id *id)
272284 {
@@ -309,6 +321,11 @@ static int tcs3414_probe(struct i2c_client *client, · 36 unmodified lines
309321 if (ret < 0)
310322 return ret;
311323
324+ ret = devm_add_action_or_reset(&client->dev, tcs3414_powerdown_cleanup,
325+ data);
326+ if (ret < 0)
327+ return ret;
328+
312329 data->timing = TCS3414_INTEG_12MS; /* free running */
313330 ret = i2c_smbus_write_byte_data(data->client, TCS3414_TIMING,
314331 data->timing);
@@ -320,38 +337,12 @@ static int tcs3414_probe(struct i2c_client *client, · 5 unmodified lines
320337 return ret;
321338 data->gain = ret;
322339
323− ret = iio_triggered_buffer_setup(indio_dev, NULL,
340+ ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL,
324341 tcs3414_trigger_handler, &tcs3414_buffer_setup_ops);
325342 if (ret < 0)
326343 return ret;
327344
328− ret = iio_device_register(indio_dev);
329− if (ret < 0)
330− goto buffer_cleanup;
331−
332− return 0;
333−
334−buffer_cleanup:
335− iio_triggered_buffer_cleanup(indio_dev);
336− return ret;
337−}
338−
339−static int tcs3414_powerdown(struct tcs3414_data *data)
340−{
341− return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
342− data->control & ~(TCS3414_CONTROL_POWER |
343− TCS3414_CONTROL_ADC_EN));
344−}
345−
346−static int tcs3414_remove(struct i2c_client *client)
347−{
348− struct iio_dev *indio_dev = i2c_get_clientdata(client);
349−
350− iio_device_unregister(indio_dev);
351− iio_triggered_buffer_cleanup(indio_dev);
352− tcs3414_powerdown(iio_priv(indio_dev));
353−
354− return 0;
345+ return devm_iio_device_register(&client->dev, indio_dev);
355346 }
356347
357348 #ifdef CONFIG_PM_SLEEP
@@ -385,7 +376,6 @@ static struct i2c_driver tcs3414_driver = { · 27 unmodified lines
385376 .pm = &tcs3414_pm_ops,
386377 },
387378 .probe = tcs3414_probe,
388− .remove = tcs3414_remove,
389379 .id_table = tcs3414_id,
390380 };
391381 module_i2c_driver(tcs3414_driver);
drivers/iio/magnetometer/st_magn.h+0−12
@@ -25,25 +25,13 @@ · 24 unmodified lines
2525
2626 #ifdef CONFIG_IIO_BUFFER
2727 int st_magn_allocate_ring(struct iio_dev *indio_dev);
28−void st_magn_deallocate_ring(struct iio_dev *indio_dev);
2928 int st_magn_trig_set_state(struct iio_trigger *trig, bool state);
3029 #define ST_MAGN_TRIGGER_SET_STATE (&st_magn_trig_set_state)
3130 #else /* CONFIG_IIO_BUFFER */
32−static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq)
33−{
34− return 0;
35−}
36−static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq)
37−{
38− return;
39−}
4031 static inline int st_magn_allocate_ring(struct iio_dev *indio_dev)
4132 {
4233 return 0;
4334 }
44−static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev)
45−{
46−}
4735 #define ST_MAGN_TRIGGER_SET_STATE NULL
4836 #endif /* CONFIG_IIO_BUFFER */
4937
drivers/iio/magnetometer/st_magn_buffer.c+3−13
@@ -9,14 +9,9 @@ · 8 unmodified lines
99
1010 #include <linux/module.h>
1111 #include <linux/kernel.h>
12−#include <linux/slab.h>
13−#include <linux/stat.h>
14−#include <linux/interrupt.h>
15−#include <linux/i2c.h>
16−#include <linux/delay.h>
1712 #include <linux/iio/iio.h>
1813 #include <linux/iio/buffer.h>
19−#include <linux/iio/trigger_consumer.h>
14+#include <linux/iio/trigger.h>
2015 #include <linux/iio/triggered_buffer.h>
2116
2217 #include <linux/iio/common/st_sensors.h>
@@ -46,13 +41,8 @@ static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = { · 23 unmodified lines
4641
4742 int st_magn_allocate_ring(struct iio_dev *indio_dev)
4843 {
49− return iio_triggered_buffer_setup(indio_dev, NULL,
50− &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
51−}
52−
53−void st_magn_deallocate_ring(struct iio_dev *indio_dev)
54−{
55− iio_triggered_buffer_cleanup(indio_dev);
44+ return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
45+ NULL, &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
5646 }
5747
5848 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
drivers/iio/magnetometer/st_magn_core.c+4−13
@@ -9,16 +9,11 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
13−#include <linux/errno.h>
14−#include <linux/types.h>
15−#include <linux/interrupt.h>
16−#include <linux/i2c.h>
17−#include <linux/irq.h>
18−#include <linux/delay.h>
12+#include <linux/mutex.h>
13+#include <linux/sysfs.h>
1914 #include <linux/iio/iio.h>
2015 #include <linux/iio/sysfs.h>
21−#include <linux/iio/buffer.h>
16+#include <linux/iio/trigger.h>
2217
2318 #include <linux/iio/common/st_sensors.h>
2419 #include "st_magn.h"
@@ -652,7 +647,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev) · 627 unmodified lines
652647 err = st_sensors_allocate_trigger(indio_dev,
653648 ST_MAGN_TRIGGER_OPS);
654649 if (err < 0)
655− goto st_magn_probe_trigger_error;
650+ return err;
656651 }
657652
658653 err = iio_device_register(indio_dev);
@@ -667,8 +662,6 @@ int st_magn_common_probe(struct iio_dev *indio_dev) · 8 unmodified lines
667662 st_magn_device_register_error:
668663 if (mdata->irq > 0)
669664 st_sensors_deallocate_trigger(indio_dev);
670−st_magn_probe_trigger_error:
671− st_magn_deallocate_ring(indio_dev);
672665 return err;
673666 }
674667 EXPORT_SYMBOL(st_magn_common_probe);
@@ -680,8 +673,6 @@ void st_magn_common_remove(struct iio_dev *indio_dev) · 5 unmodified lines
680673 iio_device_unregister(indio_dev);
681674 if (mdata->irq > 0)
682675 st_sensors_deallocate_trigger(indio_dev);
683−
684− st_magn_deallocate_ring(indio_dev);
685676 }
686677 EXPORT_SYMBOL(st_magn_common_remove);
687678
drivers/iio/magnetometer/st_magn_i2c.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/i2c.h>
1414 #include <linux/iio/iio.h>
1515
drivers/iio/magnetometer/st_magn_spi.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/spi/spi.h>
1414 #include <linux/iio/iio.h>
1515
drivers/iio/orientation/hid-sensor-incl-3d.c+4−7
@@ -326,8 +326,8 @@ static int hid_incl_3d_probe(struct platform_device *pdev) · 325 unmodified lines
326326 return ret;
327327 }
328328
329− indio_dev->channels = kmemdup(incl_3d_channels,
330− sizeof(incl_3d_channels), GFP_KERNEL);
329+ indio_dev->channels = devm_kmemdup(&pdev->dev, incl_3d_channels,
330+ sizeof(incl_3d_channels), GFP_KERNEL);
331331 if (!indio_dev->channels) {
332332 dev_err(&pdev->dev, "failed to duplicate channels\n");
333333 return -ENOMEM;
@@ -339,7 +339,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev) · 5 unmodified lines
339339 incl_state);
340340 if (ret) {
341341 dev_err(&pdev->dev, "failed to setup attributes\n");
342− goto error_free_dev_mem;
342+ return ret;
343343 }
344344
345345 indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
@@ -353,7 +353,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev) · 7 unmodified lines
353353 &incl_state->common_attributes);
354354 if (ret) {
355355 dev_err(&pdev->dev, "trigger setup failed\n");
356− goto error_free_dev_mem;
356+ return ret;
357357 }
358358
359359 ret = iio_device_register(indio_dev);
@@ -379,8 +379,6 @@ error_iio_unreg: · 19 unmodified lines
379379 iio_device_unregister(indio_dev);
380380 error_remove_trigger:
381381 hid_sensor_remove_trigger(indio_dev, &incl_state->common_attributes);
382−error_free_dev_mem:
383− kfree(indio_dev->channels);
384382 return ret;
385383 }
386384
@@ -394,7 +392,6 @@ static int hid_incl_3d_remove(struct platform_device *pdev) · 7 unmodified lines
394392 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_INCLINOMETER_3D);
395393 iio_device_unregister(indio_dev);
396394 hid_sensor_remove_trigger(indio_dev, &incl_state->common_attributes);
397− kfree(indio_dev->channels);
398395
399396 return 0;
400397 }
drivers/iio/potentiometer/Kconfig+10−0
@@ -6,6 +6,16 @@ · 5 unmodified lines
66
77 menu "Digital potentiometers"
88
9+config AD5110
10+ tristate "Analog Devices AD5110 and similar Digital Potentiometer driver"
11+ depends on I2C
12+ help
13+ Say yes here to build support for the Analog Devices AD5110, AD5112
14+ and AD5114 digital potentiometer chip.
15+
16+ To compile this driver as a module, choose M here: the
17+ module will be called ad5110.
18+
919 config AD5272
1020 tristate "Analog Devices AD5272 and similar Digital Potentiometer driver"
1121 depends on I2C
drivers/iio/potentiometer/Makefile+1−0
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 #
55
66 # When adding new entries keep the list in alphabetical order
7+obj-$(CONFIG_AD5110) += ad5110.o
78 obj-$(CONFIG_AD5272) += ad5272.o
89 obj-$(CONFIG_DS1803) += ds1803.o
910 obj-$(CONFIG_MAX5432) += max5432.o
drivers/iio/potentiometer/ad5110.c+344−0
@@ -0,0 +1,344 @@
1+// SPDX-License-Identifier: GPL-2.0+
2+/*
3+ * Analog Devices AD5110 digital potentiometer driver
4+ *
5+ * Copyright (C) 2021 Mugilraj Dhavachelvan <dmugil2000@gmail.com>
6+ *
7+ * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5110_5112_5114.pdf
8+ */
9+
10+#include <linux/bitfield.h>
11+#include <linux/delay.h>
12+#include <linux/device.h>
13+#include <linux/i2c.h>
14+#include <linux/module.h>
15+
16+#include <linux/iio/iio.h>
17+#include <linux/iio/sysfs.h>
18+
19+/* AD5110 commands */
20+#define AD5110_EEPROM_WR 1
21+#define AD5110_RDAC_WR 2
22+#define AD5110_SHUTDOWN 3
23+#define AD5110_RESET 4
24+#define AD5110_RDAC_RD 5
25+#define AD5110_EEPROM_RD 6
26+
27+/* AD5110_EEPROM_RD data */
28+#define AD5110_WIPER_POS 0
29+#define AD5110_RESISTOR_TOL 1
30+
31+#define AD5110_WIPER_RESISTANCE 70
32+
33+struct ad5110_cfg {
34+ int max_pos;
35+ int kohms;
36+ int shift;
37+};
38+
39+enum ad5110_type {
40+ AD5110_10,
41+ AD5110_80,
42+ AD5112_05,
43+ AD5112_10,
44+ AD5112_80,
45+ AD5114_10,
46+ AD5114_80,
47+};
48+
49+static const struct ad5110_cfg ad5110_cfg[] = {
50+ [AD5110_10] = { .max_pos = 128, .kohms = 10 },
51+ [AD5110_80] = { .max_pos = 128, .kohms = 80 },
52+ [AD5112_05] = { .max_pos = 64, .kohms = 5, .shift = 1 },
53+ [AD5112_10] = { .max_pos = 64, .kohms = 10, .shift = 1 },
54+ [AD5112_80] = { .max_pos = 64, .kohms = 80, .shift = 1 },
55+ [AD5114_10] = { .max_pos = 32, .kohms = 10, .shift = 2 },
56+ [AD5114_80] = { .max_pos = 32, .kohms = 80, .shift = 2 },
57+};
58+
59+struct ad5110_data {
60+ struct i2c_client *client;
61+ s16 tol; /* resistor tolerance */
62+ bool enable;
63+ struct mutex lock;
64+ const struct ad5110_cfg *cfg;
65+ /*
66+ * DMA (thus cache coherency maintenance) requires the
67+ * transfer buffers to live in their own cache lines.
68+ */
69+ u8 buf[2] ____cacheline_aligned;
70+};
71+
72+static const struct iio_chan_spec ad5110_channels[] = {
73+ {
74+ .type = IIO_RESISTANCE,
75+ .output = 1,
76+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_OFFSET) |
77+ BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_ENABLE),
78+ },
79+};
80+
81+static int ad5110_read(struct ad5110_data *data, u8 cmd, int *val)
82+{
83+ int ret;
84+
85+ mutex_lock(&data->lock);
86+ data->buf[0] = cmd;
87+ data->buf[1] = *val;
88+
89+ ret = i2c_master_send_dmasafe(data->client, data->buf, sizeof(data->buf));
90+ if (ret < 0) {
91+ goto error;
92+ } else if (ret != sizeof(data->buf)) {
93+ ret = -EIO;
94+ goto error;
95+ }
96+
97+ ret = i2c_master_recv_dmasafe(data->client, data->buf, 1);
98+ if (ret < 0) {
99+ goto error;
100+ } else if (ret != 1) {
101+ ret = -EIO;
102+ goto error;
103+ }
104+
105+ *val = data->buf[0];
106+ ret = 0;
107+
108+error:
109+ mutex_unlock(&data->lock);
110+ return ret;
111+}
112+
113+static int ad5110_write(struct ad5110_data *data, u8 cmd, u8 val)
114+{
115+ int ret;
116+
117+ mutex_lock(&data->lock);
118+ data->buf[0] = cmd;
119+ data->buf[1] = val;
120+
121+ ret = i2c_master_send_dmasafe(data->client, data->buf, sizeof(data->buf));
122+ if (ret < 0) {
123+ goto error;
124+ } else if (ret != sizeof(data->buf)) {
125+ ret = -EIO;
126+ goto error;
127+ }
128+
129+ ret = 0;
130+
131+error:
132+ mutex_unlock(&data->lock);
133+ return ret;
134+}
135+
136+static int ad5110_resistor_tol(struct ad5110_data *data, u8 cmd, int val)
137+{
138+ int ret;
139+
140+ ret = ad5110_read(data, cmd, &val);
141+ if (ret)
142+ return ret;
143+
144+ data->tol = data->cfg->kohms * (val & GENMASK(6, 0)) * 10 / 8;
145+ if (!(val & BIT(7)))
146+ data->tol *= -1;
147+
148+ return 0;
149+}
150+
151+static ssize_t store_eeprom_show(struct device *dev,
152+ struct device_attribute *attr,
153+ char *buf)
154+{
155+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
156+ struct ad5110_data *data = iio_priv(indio_dev);
157+ int val = AD5110_WIPER_POS;
158+ int ret;
159+
160+ ret = ad5110_read(data, AD5110_EEPROM_RD, &val);
161+ if (ret)
162+ return ret;
163+
164+ val = val >> data->cfg->shift;
165+ return iio_format_value(buf, IIO_VAL_INT, 1, &val);
166+}
167+
168+static ssize_t store_eeprom_store(struct device *dev,
169+ struct device_attribute *attr,
170+ const char *buf, size_t len)
171+{
172+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
173+ struct ad5110_data *data = iio_priv(indio_dev);
174+ int ret;
175+
176+ ret = ad5110_write(data, AD5110_EEPROM_WR, 0);
177+ if (ret) {
178+ dev_err(&data->client->dev, "RDAC to EEPROM write failed\n");
179+ return ret;
180+ }
181+
182+ /* The storing of EEPROM data takes approximately 18 ms. */
183+ msleep(20);
184+
185+ return len;
186+}
187+
188+static IIO_DEVICE_ATTR_RW(store_eeprom, 0);
189+
190+static struct attribute *ad5110_attributes[] = {
191+ &iio_dev_attr_store_eeprom.dev_attr.attr,
192+ NULL
193+};
194+
195+static const struct attribute_group ad5110_attribute_group = {
196+ .attrs = ad5110_attributes,
197+};
198+
199+static int ad5110_read_raw(struct iio_dev *indio_dev,
200+ struct iio_chan_spec const *chan,
201+ int *val, int *val2, long mask)
202+{
203+ struct ad5110_data *data = iio_priv(indio_dev);
204+ int ret;
205+
206+ switch (mask) {
207+ case IIO_CHAN_INFO_RAW:
208+ ret = ad5110_read(data, AD5110_RDAC_RD, val);
209+ if (ret)
210+ return ret;
211+
212+ *val = *val >> data->cfg->shift;
213+ return IIO_VAL_INT;
214+ case IIO_CHAN_INFO_OFFSET:
215+ *val = AD5110_WIPER_RESISTANCE * data->cfg->max_pos;
216+ *val2 = 1000 * data->cfg->kohms + data->tol;
217+ return IIO_VAL_FRACTIONAL;
218+ case IIO_CHAN_INFO_SCALE:
219+ *val = 1000 * data->cfg->kohms + data->tol;
220+ *val2 = data->cfg->max_pos;
221+ return IIO_VAL_FRACTIONAL;
222+ case IIO_CHAN_INFO_ENABLE:
223+ *val = data->enable;
224+ return IIO_VAL_INT;
225+ default:
226+ return -EINVAL;
227+ }
228+}
229+
230+static int ad5110_write_raw(struct iio_dev *indio_dev,
231+ struct iio_chan_spec const *chan,
232+ int val, int val2, long mask)
233+{
234+ struct ad5110_data *data = iio_priv(indio_dev);
235+ int ret;
236+
237+ switch (mask) {
238+ case IIO_CHAN_INFO_RAW:
239+ if (val > data->cfg->max_pos || val < 0)
240+ return -EINVAL;
241+
242+ return ad5110_write(data, AD5110_RDAC_WR, val << data->cfg->shift);
243+ case IIO_CHAN_INFO_ENABLE:
244+ if (val < 0 || val > 1)
245+ return -EINVAL;
246+ if (data->enable == val)
247+ return 0;
248+ ret = ad5110_write(data, AD5110_SHUTDOWN, val ? 0 : 1);
249+ if (ret)
250+ return ret;
251+ data->enable = val;
252+ return 0;
253+ default:
254+ return -EINVAL;
255+ }
256+}
257+
258+static const struct iio_info ad5110_info = {
259+ .read_raw = ad5110_read_raw,
260+ .write_raw = ad5110_write_raw,
261+ .attrs = &ad5110_attribute_group,
262+};
263+
264+#define AD5110_COMPATIBLE(of_compatible, cfg) { \
265+ .compatible = of_compatible, \
266+ .data = &ad5110_cfg[cfg], \
267+}
268+
269+static const struct of_device_id ad5110_of_match[] = {
270+ AD5110_COMPATIBLE("adi,ad5110-10", AD5110_10),
271+ AD5110_COMPATIBLE("adi,ad5110-80", AD5110_80),
272+ AD5110_COMPATIBLE("adi,ad5112-05", AD5112_05),
273+ AD5110_COMPATIBLE("adi,ad5112-10", AD5112_10),
274+ AD5110_COMPATIBLE("adi,ad5112-80", AD5112_80),
275+ AD5110_COMPATIBLE("adi,ad5114-10", AD5114_10),
276+ AD5110_COMPATIBLE("adi,ad5114-80", AD5114_80),
277+ { }
278+};
279+MODULE_DEVICE_TABLE(of, ad5110_of_match);
280+
281+static const struct i2c_device_id ad5110_id[] = {
282+ { "ad5110-10", AD5110_10 },
283+ { "ad5110-80", AD5110_80 },
284+ { "ad5112-05", AD5112_05 },
285+ { "ad5112-10", AD5112_10 },
286+ { "ad5112-80", AD5112_80 },
287+ { "ad5114-10", AD5114_10 },
288+ { "ad5114-80", AD5114_80 },
289+ { }
290+};
291+MODULE_DEVICE_TABLE(i2c, ad5110_id);
292+
293+static int ad5110_probe(struct i2c_client *client)
294+{
295+ struct device *dev = &client->dev;
296+ struct iio_dev *indio_dev;
297+ struct ad5110_data *data;
298+ int ret;
299+
300+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
301+ if (!indio_dev)
302+ return -ENOMEM;
303+
304+ data = iio_priv(indio_dev);
305+ data->client = client;
306+ mutex_init(&data->lock);
307+ data->enable = 1;
308+ data->cfg = device_get_match_data(dev);
309+
310+ /* refresh RDAC register with EEPROM */
311+ ret = ad5110_write(data, AD5110_RESET, 0);
312+ if (ret) {
313+ dev_err(dev, "Refresh RDAC with EEPROM failed\n");
314+ return ret;
315+ }
316+
317+ ret = ad5110_resistor_tol(data, AD5110_EEPROM_RD, AD5110_RESISTOR_TOL);
318+ if (ret) {
319+ dev_err(dev, "Read resistor tolerance failed\n");
320+ return ret;
321+ }
322+
323+ indio_dev->modes = INDIO_DIRECT_MODE;
324+ indio_dev->info = &ad5110_info;
325+ indio_dev->channels = ad5110_channels;
326+ indio_dev->num_channels = ARRAY_SIZE(ad5110_channels);
327+ indio_dev->name = client->name;
328+
329+ return devm_iio_device_register(dev, indio_dev);
330+}
331+
332+static struct i2c_driver ad5110_driver = {
333+ .driver = {
334+ .name = "ad5110",
335+ .of_match_table = ad5110_of_match,
336+ },
337+ .probe_new = ad5110_probe,
338+ .id_table = ad5110_id,
339+};
340+module_i2c_driver(ad5110_driver);
341+
342+MODULE_AUTHOR("Mugilraj Dhavachelvan <dmugil2000@gmail.com>");
343+MODULE_DESCRIPTION("AD5110 digital potentiometer");
344+MODULE_LICENSE("GPL v2");
drivers/iio/potentiometer/max5481.c+9−13
@@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = { · 124 unmodified lines
125125 };
126126 MODULE_DEVICE_TABLE(of, max5481_match);
127127
128+static void max5481_wiper_save(void *data)
129+{
130+ max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
131+}
132+
128133 static int max5481_probe(struct spi_device *spi)
129134 {
130135 struct iio_dev *indio_dev;
@@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi) · 5 unmodified lines
136141 if (!indio_dev)
137142 return -ENOMEM;
138143
139− spi_set_drvdata(spi, indio_dev);
140144 data = iio_priv(indio_dev);
141145
142146 data->spi = spi;
@@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi) · 15 unmodified lines
158162 if (ret < 0)
159163 return ret;
160164
161− return iio_device_register(indio_dev);
162−}
163−
164−static int max5481_remove(struct spi_device *spi)
165−{
166− struct iio_dev *indio_dev = spi_get_drvdata(spi);
167− struct max5481_data *data = iio_priv(indio_dev);
168−
169− iio_device_unregister(indio_dev);
165+ ret = devm_add_action(&spi->dev, max5481_wiper_save, data);
166+ if (ret < 0)
167+ return ret;
170168
171− /* save wiper reg to NV reg */
172− return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
169+ return devm_iio_device_register(&spi->dev, indio_dev);
173170 }
174171
175172 static const struct spi_device_id max5481_id_table[] = {
@@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = { · 11 unmodified lines
187184 .of_match_table = max5481_match,
188185 },
189186 .probe = max5481_probe,
190− .remove = max5481_remove,
191187 .id_table = max5481_id_table,
192188 };
193189
drivers/iio/pressure/hid-sensor-press.c+28−23
@@ -13,17 +13,24 @@ · 12 unmodified lines
1313 #include <linux/iio/buffer.h>
1414 #include "../common/hid-sensors/hid-sensor-trigger.h"
1515
16−#define CHANNEL_SCAN_INDEX_PRESSURE 0
16+enum {
17+ CHANNEL_SCAN_INDEX_PRESSURE,
18+ CHANNEL_SCAN_INDEX_TIMESTAMP,
19+};
1720
1821 struct press_state {
1922 struct hid_sensor_hub_callbacks callbacks;
2023 struct hid_sensor_common common_attributes;
2124 struct hid_sensor_hub_attribute_info press_attr;
22− u32 press_data;
25+ struct {
26+ u32 press_data;
27+ u64 timestamp __aligned(8);
28+ } scan;
2329 int scale_pre_decml;
2430 int scale_post_decml;
2531 int scale_precision;
2632 int value_offset;
33+ s64 timestamp;
2734 };
2835
2936 static const u32 press_sensitivity_addresses[] = {
@@ -41,7 +48,9 @@ static const struct iio_chan_spec press_channels[] = { · 11 unmodified lines
4148 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
4249 BIT(IIO_CHAN_INFO_HYSTERESIS),
4350 .scan_index = CHANNEL_SCAN_INDEX_PRESSURE,
44− }
51+ },
52+ IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP)
53+
4554 };
4655
4756 /* Adjust channel real bits based on report descriptor */
@@ -154,14 +163,6 @@ static const struct iio_info press_info = { · 106 unmodified lines
154163 .write_raw = &press_write_raw,
155164 };
156165
157−/* Function to push data to buffer */
158−static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data,
159− int len)
160−{
161− dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
162− iio_push_to_buffers(indio_dev, data);
163−}
164−
165166 /* Callback handler to send event after all samples are received and captured */
166167 static int press_proc_event(struct hid_sensor_hub_device *hsdev,
167168 unsigned usage_id,
@@ -171,10 +172,13 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev, · 3 unmodified lines
171172 struct press_state *press_state = iio_priv(indio_dev);
172173
173174 dev_dbg(&indio_dev->dev, "press_proc_event\n");
174− if (atomic_read(&press_state->common_attributes.data_ready))
175− hid_sensor_push_data(indio_dev,
176− &press_state->press_data,
177− sizeof(press_state->press_data));
175+ if (atomic_read(&press_state->common_attributes.data_ready)) {
176+ if (!press_state->timestamp)
177+ press_state->timestamp = iio_get_time_ns(indio_dev);
178+
179+ iio_push_to_buffers_with_timestamp(
180+ indio_dev, &press_state->scan, press_state->timestamp);
181+ }
178182
179183 return 0;
180184 }
@@ -191,9 +195,13 @@ static int press_capture_sample(struct hid_sensor_hub_device *hsdev, · 10 unmodified lines
191195
192196 switch (usage_id) {
193197 case HID_USAGE_SENSOR_ATMOSPHERIC_PRESSURE:
194− press_state->press_data = *(u32 *)raw_data;
198+ press_state->scan.press_data = *(u32 *)raw_data;
195199 ret = 0;
196200 break;
201+ case HID_USAGE_SENSOR_TIME_TIMESTAMP:
202+ press_state->timestamp = hid_sensor_convert_timestamp(
203+ &press_state->common_attributes, *(s64 *)raw_data);
204+ break;
197205 default:
198206 break;
199207 }
@@ -259,8 +267,8 @@ static int hid_press_probe(struct platform_device *pdev) · 59 unmodified lines
259267 return ret;
260268 }
261269
262− indio_dev->channels = kmemdup(press_channels, sizeof(press_channels),
263− GFP_KERNEL);
270+ indio_dev->channels = devm_kmemdup(&pdev->dev, press_channels,
271+ sizeof(press_channels), GFP_KERNEL);
264272 if (!indio_dev->channels) {
265273 dev_err(&pdev->dev, "failed to duplicate channels\n");
266274 return -ENOMEM;
@@ -271,7 +279,7 @@ static int hid_press_probe(struct platform_device *pdev) · 4 unmodified lines
271279 HID_USAGE_SENSOR_PRESSURE, press_state);
272280 if (ret) {
273281 dev_err(&pdev->dev, "failed to setup attributes\n");
274− goto error_free_dev_mem;
282+ return ret;
275283 }
276284
277285 indio_dev->num_channels =
@@ -286,7 +294,7 @@ static int hid_press_probe(struct platform_device *pdev) · 8 unmodified lines
286294 &press_state->common_attributes);
287295 if (ret) {
288296 dev_err(&pdev->dev, "trigger setup failed\n");
289− goto error_free_dev_mem;
297+ return ret;
290298 }
291299
292300 ret = iio_device_register(indio_dev);
@@ -311,8 +319,6 @@ error_iio_unreg: · 18 unmodified lines
311319 iio_device_unregister(indio_dev);
312320 error_remove_trigger:
313321 hid_sensor_remove_trigger(indio_dev, &press_state->common_attributes);
314−error_free_dev_mem:
315− kfree(indio_dev->channels);
316322 return ret;
317323 }
318324
@@ -326,7 +332,6 @@ static int hid_press_remove(struct platform_device *pdev) · 7 unmodified lines
326332 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PRESSURE);
327333 iio_device_unregister(indio_dev);
328334 hid_sensor_remove_trigger(indio_dev, &press_state->common_attributes);
329− kfree(indio_dev->channels);
330335
331336 return 0;
332337 }
drivers/iio/pressure/hp03.c+7−29
@@ -242,47 +242,26 @@ static int hp03_probe(struct i2c_client *client, · 241 unmodified lines
242242 * which has it's dedicated I2C address and contains
243243 * the calibration constants for the sensor.
244244 */
245− priv->eeprom_client = i2c_new_dummy_device(client->adapter, HP03_EEPROM_ADDR);
245+ priv->eeprom_client = devm_i2c_new_dummy_device(dev, client->adapter,
246+ HP03_EEPROM_ADDR);
246247 if (IS_ERR(priv->eeprom_client)) {
247248 dev_err(dev, "New EEPROM I2C device failed\n");
248249 return PTR_ERR(priv->eeprom_client);
249250 }
250251
251− priv->eeprom_regmap = regmap_init_i2c(priv->eeprom_client,
252− &hp03_regmap_config);
252+ priv->eeprom_regmap = devm_regmap_init_i2c(priv->eeprom_client,
253+ &hp03_regmap_config);
253254 if (IS_ERR(priv->eeprom_regmap)) {
254255 dev_err(dev, "Failed to allocate EEPROM regmap\n");
255− ret = PTR_ERR(priv->eeprom_regmap);
256− goto err_cleanup_eeprom_client;
256+ return PTR_ERR(priv->eeprom_regmap);
257257 }
258258
259− ret = iio_device_register(indio_dev);
259+ ret = devm_iio_device_register(dev, indio_dev);
260260 if (ret) {
261261 dev_err(dev, "Failed to register IIO device\n");
262− goto err_cleanup_eeprom_regmap;
262+ return ret;
263263 }
264264
265− i2c_set_clientdata(client, indio_dev);
266−
267− return 0;
268−
269−err_cleanup_eeprom_regmap:
270− regmap_exit(priv->eeprom_regmap);
271−
272−err_cleanup_eeprom_client:
273− i2c_unregister_device(priv->eeprom_client);
274− return ret;
275−}
276−
277−static int hp03_remove(struct i2c_client *client)
278−{
279− struct iio_dev *indio_dev = i2c_get_clientdata(client);
280− struct hp03_priv *priv = iio_priv(indio_dev);
281−
282− iio_device_unregister(indio_dev);
283− regmap_exit(priv->eeprom_regmap);
284− i2c_unregister_device(priv->eeprom_client);
285−
286265 return 0;
287266 }
288267
@@ -304,7 +283,6 @@ static struct i2c_driver hp03_driver = { · 15 unmodified lines
304283 .of_match_table = hp03_of_match,
305284 },
306285 .probe = hp03_probe,
307− .remove = hp03_remove,
308286 .id_table = hp03_id,
309287 };
310288 module_i2c_driver(hp03_driver);
drivers/iio/pressure/st_pressure.h+0−5
@@ -43,7 +43,6 @@ static __maybe_unused const struct st_sensors_platform_data default_press_pdata · 42 unmodified lines
4343
4444 #ifdef CONFIG_IIO_BUFFER
4545 int st_press_allocate_ring(struct iio_dev *indio_dev);
46−void st_press_deallocate_ring(struct iio_dev *indio_dev);
4746 int st_press_trig_set_state(struct iio_trigger *trig, bool state);
4847 #define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state)
4948 #else /* CONFIG_IIO_BUFFER */
@@ -51,10 +50,6 @@ static inline int st_press_allocate_ring(struct iio_dev *indio_dev) · 1 unmodified line
5150 {
5251 return 0;
5352 }
54−
55−static inline void st_press_deallocate_ring(struct iio_dev *indio_dev)
56−{
57−}
5853 #define ST_PRESS_TRIGGER_SET_STATE NULL
5954 #endif /* CONFIG_IIO_BUFFER */
6055
drivers/iio/pressure/st_pressure_buffer.c+3−13
@@ -9,14 +9,9 @@ · 8 unmodified lines
99
1010 #include <linux/module.h>
1111 #include <linux/kernel.h>
12−#include <linux/slab.h>
13−#include <linux/stat.h>
14−#include <linux/interrupt.h>
15−#include <linux/i2c.h>
16−#include <linux/delay.h>
1712 #include <linux/iio/iio.h>
1813 #include <linux/iio/buffer.h>
19−#include <linux/iio/trigger_consumer.h>
14+#include <linux/iio/trigger.h>
2015 #include <linux/iio/triggered_buffer.h>
2116
2217 #include <linux/iio/common/st_sensors.h>
@@ -46,13 +41,8 @@ static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = { · 23 unmodified lines
4641
4742 int st_press_allocate_ring(struct iio_dev *indio_dev)
4843 {
49− return iio_triggered_buffer_setup(indio_dev, NULL,
50− &st_sensors_trigger_handler, &st_press_buffer_setup_ops);
51−}
52−
53−void st_press_deallocate_ring(struct iio_dev *indio_dev)
54−{
55− iio_triggered_buffer_cleanup(indio_dev);
44+ return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
45+ NULL, &st_sensors_trigger_handler, &st_press_buffer_setup_ops);
5646 }
5747
5848 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
drivers/iio/pressure/st_pressure_core.c+3−13
@@ -9,17 +9,11 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
13−#include <linux/errno.h>
14−#include <linux/types.h>
15−#include <linux/interrupt.h>
16−#include <linux/i2c.h>
17−#include <linux/irq.h>
18−#include <linux/delay.h>
12+#include <linux/mutex.h>
13+#include <linux/sysfs.h>
1914 #include <linux/iio/iio.h>
2015 #include <linux/iio/sysfs.h>
2116 #include <linux/iio/trigger.h>
22−#include <linux/iio/buffer.h>
2317 #include <asm/unaligned.h>
2418
2519 #include <linux/iio/common/st_sensors.h>
@@ -724,7 +718,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) · 698 unmodified lines
724718 err = st_sensors_allocate_trigger(indio_dev,
725719 ST_PRESS_TRIGGER_OPS);
726720 if (err < 0)
727− goto st_press_probe_trigger_error;
721+ return err;
728722 }
729723
730724 err = iio_device_register(indio_dev);
@@ -739,8 +733,6 @@ int st_press_common_probe(struct iio_dev *indio_dev) · 8 unmodified lines
739733 st_press_device_register_error:
740734 if (press_data->irq > 0)
741735 st_sensors_deallocate_trigger(indio_dev);
742−st_press_probe_trigger_error:
743− st_press_deallocate_ring(indio_dev);
744736 return err;
745737 }
746738 EXPORT_SYMBOL(st_press_common_probe);
@@ -752,8 +744,6 @@ void st_press_common_remove(struct iio_dev *indio_dev) · 5 unmodified lines
752744 iio_device_unregister(indio_dev);
753745 if (press_data->irq > 0)
754746 st_sensors_deallocate_trigger(indio_dev);
755−
756− st_press_deallocate_ring(indio_dev);
757747 }
758748 EXPORT_SYMBOL(st_press_common_remove);
759749
drivers/iio/pressure/st_pressure_i2c.c+2−1
@@ -7,9 +7,10 @@ · 6 unmodified lines
77 * Denis Ciocca <denis.ciocca@st.com>
88 */
99
10+#include <linux/acpi.h>
1011 #include <linux/kernel.h>
1112 #include <linux/module.h>
12−#include <linux/slab.h>
13+#include <linux/mod_devicetable.h>
1314 #include <linux/i2c.h>
1415 #include <linux/iio/iio.h>
1516
drivers/iio/pressure/st_pressure_spi.c+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/module.h>
12−#include <linux/slab.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/spi/spi.h>
1414 #include <linux/iio/iio.h>
1515
drivers/iio/proximity/rfd77402.c+33−50
@@ -90,18 +90,18 @@ static const struct iio_chan_spec rfd77402_channels[] = { · 89 unmodified lines
9090 },
9191 };
9292
93−static int rfd77402_set_state(struct rfd77402_data *data, u8 state, u16 check)
93+static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check)
9494 {
9595 int ret;
9696
97− ret = i2c_smbus_write_byte_data(data->client, RFD77402_CMD_R,
97+ ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R,
9898 state | RFD77402_CMD_VALID);
9999 if (ret < 0)
100100 return ret;
101101
102102 usleep_range(10000, 20000);
103103
104− ret = i2c_smbus_read_word_data(data->client, RFD77402_STATUS_R);
104+ ret = i2c_smbus_read_word_data(client, RFD77402_STATUS_R);
105105 if (ret < 0)
106106 return ret;
107107 if ((ret & RFD77402_STATUS_PM_MASK) != check)
@@ -110,24 +110,24 @@ static int rfd77402_set_state(struct rfd77402_data *data, u8 state, u16 check) · 2 unmodified lines
110110 return 0;
111111 }
112112
113−static int rfd77402_measure(struct rfd77402_data *data)
113+static int rfd77402_measure(struct i2c_client *client)
114114 {
115115 int ret;
116116 int tries = 10;
117117
118− ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_ON,
118+ ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
119119 RFD77402_STATUS_MCPU_ON);
120120 if (ret < 0)
121121 return ret;
122122
123− ret = i2c_smbus_write_byte_data(data->client, RFD77402_CMD_R,
123+ ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R,
124124 RFD77402_CMD_SINGLE |
125125 RFD77402_CMD_VALID);
126126 if (ret < 0)
127127 goto err;
128128
129129 while (tries-- > 0) {
130− ret = i2c_smbus_read_byte_data(data->client, RFD77402_ICSR);
130+ ret = i2c_smbus_read_byte_data(client, RFD77402_ICSR);
131131 if (ret < 0)
132132 goto err;
133133 if (ret & RFD77402_ICSR_RESULT)
@@ -140,7 +140,7 @@ static int rfd77402_measure(struct rfd77402_data *data) · 6 unmodified lines
140140 goto err;
141141 }
142142
143− ret = i2c_smbus_read_word_data(data->client, RFD77402_RESULT_R);
143+ ret = i2c_smbus_read_word_data(client, RFD77402_RESULT_R);
144144 if (ret < 0)
145145 goto err;
146146
@@ -153,7 +153,7 @@ static int rfd77402_measure(struct rfd77402_data *data) · 6 unmodified lines
153153 return (ret & RFD77402_RESULT_DIST_MASK) >> 2;
154154
155155 err:
156− rfd77402_set_state(data, RFD77402_CMD_MCPU_OFF,
156+ rfd77402_set_state(client, RFD77402_CMD_MCPU_OFF,
157157 RFD77402_STATUS_MCPU_OFF);
158158 return ret;
159159 }
@@ -168,7 +168,7 @@ static int rfd77402_read_raw(struct iio_dev *indio_dev, · 8 unmodified lines
168168 switch (mask) {
169169 case IIO_CHAN_INFO_RAW:
170170 mutex_lock(&data->lock);
171− ret = rfd77402_measure(data);
171+ ret = rfd77402_measure(data->client);
172172 mutex_unlock(&data->lock);
173173 if (ret < 0)
174174 return ret;
@@ -188,23 +188,23 @@ static const struct iio_info rfd77402_info = { · 13 unmodified lines
188188 .read_raw = rfd77402_read_raw,
189189 };
190190
191−static int rfd77402_init(struct rfd77402_data *data)
191+static int rfd77402_init(struct i2c_client *client)
192192 {
193193 int ret, i;
194194
195− ret = rfd77402_set_state(data, RFD77402_CMD_STANDBY,
195+ ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY,
196196 RFD77402_STATUS_STANDBY);
197197 if (ret < 0)
198198 return ret;
199199
200200 /* configure INT pad as push-pull, active low */
201− ret = i2c_smbus_write_byte_data(data->client, RFD77402_ICSR,
201+ ret = i2c_smbus_write_byte_data(client, RFD77402_ICSR,
202202 RFD77402_ICSR_INT_MODE);
203203 if (ret < 0)
204204 return ret;
205205
206206 /* I2C configuration */
207− ret = i2c_smbus_write_word_data(data->client, RFD77402_I2C_INIT_CFG,
207+ ret = i2c_smbus_write_word_data(client, RFD77402_I2C_INIT_CFG,
208208 RFD77402_I2C_ADDR_INCR |
209209 RFD77402_I2C_DATA_INCR |
210210 RFD77402_I2C_HOST_DEBUG |
@@ -213,45 +213,50 @@ static int rfd77402_init(struct rfd77402_data *data) · 2 unmodified lines
213213 return ret;
214214
215215 /* set initialization */
216− ret = i2c_smbus_write_word_data(data->client, RFD77402_PMU_CFG, 0x0500);
216+ ret = i2c_smbus_write_word_data(client, RFD77402_PMU_CFG, 0x0500);
217217 if (ret < 0)
218218 return ret;
219219
220− ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_OFF,
220+ ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_OFF,
221221 RFD77402_STATUS_MCPU_OFF);
222222 if (ret < 0)
223223 return ret;
224224
225225 /* set initialization */
226− ret = i2c_smbus_write_word_data(data->client, RFD77402_PMU_CFG, 0x0600);
226+ ret = i2c_smbus_write_word_data(client, RFD77402_PMU_CFG, 0x0600);
227227 if (ret < 0)
228228 return ret;
229229
230− ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_ON,
230+ ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
231231 RFD77402_STATUS_MCPU_ON);
232232 if (ret < 0)
233233 return ret;
234234
235235 for (i = 0; i < ARRAY_SIZE(rf77402_tof_config); i++) {
236− ret = i2c_smbus_write_word_data(data->client,
236+ ret = i2c_smbus_write_word_data(client,
237237 rf77402_tof_config[i].reg,
238238 rf77402_tof_config[i].val);
239239 if (ret < 0)
240240 return ret;
241241 }
242242
243− ret = rfd77402_set_state(data, RFD77402_CMD_STANDBY,
243+ ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY,
244244 RFD77402_STATUS_STANDBY);
245245
246246 return ret;
247247 }
248248
249−static int rfd77402_powerdown(struct rfd77402_data *data)
249+static int rfd77402_powerdown(struct i2c_client *client)
250250 {
251− return rfd77402_set_state(data, RFD77402_CMD_STANDBY,
251+ return rfd77402_set_state(client, RFD77402_CMD_STANDBY,
252252 RFD77402_STATUS_STANDBY);
253253 }
254254
255+static void rfd77402_disable(void *client)
256+{
257+ rfd77402_powerdown(client);
258+}
259+
255260 static int rfd77402_probe(struct i2c_client *client,
256261 const struct i2c_device_id *id)
257262 {
@@ -270,7 +275,6 @@ static int rfd77402_probe(struct i2c_client *client, · 12 unmodified lines
270275 return -ENOMEM;
271276
272277 data = iio_priv(indio_dev);
273− i2c_set_clientdata(client, indio_dev);
274278 data->client = client;
275279 mutex_init(&data->lock);
276280
@@ -280,46 +284,26 @@ static int rfd77402_probe(struct i2c_client *client, · 3 unmodified lines
280284 indio_dev->name = RFD77402_DRV_NAME;
281285 indio_dev->modes = INDIO_DIRECT_MODE;
282286
283− ret = rfd77402_init(data);
287+ ret = rfd77402_init(client);
284288 if (ret < 0)
285289 return ret;
286290
287− ret = iio_device_register(indio_dev);
291+ ret = devm_add_action_or_reset(&client->dev, rfd77402_disable, client);
288292 if (ret)
289− goto err_powerdown;
290−
291− return 0;
292−
293−err_powerdown:
294− rfd77402_powerdown(data);
295− return ret;
296−}
297−
298−static int rfd77402_remove(struct i2c_client *client)
299−{
300− struct iio_dev *indio_dev = i2c_get_clientdata(client);
301−
302− iio_device_unregister(indio_dev);
303− rfd77402_powerdown(iio_priv(indio_dev));
293+ return ret;
304294
305− return 0;
295+ return devm_iio_device_register(&client->dev, indio_dev);
306296 }
307297
308298 #ifdef CONFIG_PM_SLEEP
309299 static int rfd77402_suspend(struct device *dev)
310300 {
311− struct rfd77402_data *data = iio_priv(i2c_get_clientdata(
312− to_i2c_client(dev)));
313−
314− return rfd77402_powerdown(data);
301+ return rfd77402_powerdown(to_i2c_client(dev));
315302 }
316303
317304 static int rfd77402_resume(struct device *dev)
318305 {
319− struct rfd77402_data *data = iio_priv(i2c_get_clientdata(
320− to_i2c_client(dev)));
321−
322− return rfd77402_init(data);
306+ return rfd77402_init(to_i2c_client(dev));
323307 }
324308 #endif
325309
@@ -337,7 +321,6 @@ static struct i2c_driver rfd77402_driver = { · 11 unmodified lines
337321 .pm = &rfd77402_pm_ops,
338322 },
339323 .probe = rfd77402_probe,
340− .remove = rfd77402_remove,
341324 .id_table = rfd77402_id,
342325 };
343326
drivers/iio/proximity/sx9310.c+16−32
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include <linux/mod_devicetable.h>
2121 #include <linux/module.h>
2222 #include <linux/pm.h>
23+#include <linux/property.h>
2324 #include <linux/regmap.h>
2425 #include <linux/regulator/consumer.h>
2526 #include <linux/slab.h>
@@ -1221,10 +1222,9 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) · 1195 unmodified lines
12211222 }
12221223
12231224 static const struct sx9310_reg_default *
1224−sx9310_get_default_reg(struct sx9310_data *data, int idx,
1225+sx9310_get_default_reg(struct device *dev, int idx,
12251226 struct sx9310_reg_default *reg_def)
12261227 {
1227− const struct device_node *np = data->client->dev.of_node;
12281228 u32 combined[SX9310_NUM_CHANNELS];
12291229 u32 start = 0, raw = 0, pos = 0;
12301230 unsigned long comb_mask = 0;
@@ -1232,40 +1232,24 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, · 1 unmodified line
12321232 const char *res;
12331233
12341234 memcpy(reg_def, &sx9310_default_regs[idx], sizeof(*reg_def));
1235− if (!np)
1236− return reg_def;
1237−
12381235 switch (reg_def->reg) {
12391236 case SX9310_REG_PROX_CTRL2:
1240− if (of_property_read_bool(np, "semtech,cs0-ground")) {
1237+ if (device_property_read_bool(dev, "semtech,cs0-ground")) {
12411238 reg_def->def &= ~SX9310_REG_PROX_CTRL2_SHIELDEN_MASK;
12421239 reg_def->def |= SX9310_REG_PROX_CTRL2_SHIELDEN_GROUND;
12431240 }
12441241
1245− count = of_property_count_elems_of_size(np, "semtech,combined-sensors",
1246− sizeof(u32));
1247− if (count > 0 && count <= ARRAY_SIZE(combined)) {
1248− ret = of_property_read_u32_array(np, "semtech,combined-sensors",
1249− combined, count);
1250− if (ret)
1251− break;
1252− } else {
1253− /*
1254− * Either the property does not exist in the DT or the
1255− * number of entries is incorrect.
1256− */
1242+ count = device_property_count_u32(dev, "semtech,combined-sensors");
1243+ if (count < 0 || count > ARRAY_SIZE(combined))
12571244 break;
1258− }
1259− for (i = 0; i < count; i++) {
1260− if (combined[i] >= SX9310_NUM_CHANNELS) {
1261− /* Invalid sensor (invalid DT). */
1262− break;
1263− }
1264− comb_mask |= BIT(combined[i]);
1265− }
1266− if (i < count)
1245+ ret = device_property_read_u32_array(dev, "semtech,combined-sensors",
1246+ combined, count);
1247+ if (ret)
12671248 break;
12681249
1250+ for (i = 0; i < count; i++)
1251+ comb_mask |= BIT(combined[i]);
1252+
12691253 reg_def->def &= ~SX9310_REG_PROX_CTRL2_COMBMODE_MASK;
12701254 if (comb_mask == (BIT(3) | BIT(2) | BIT(1) | BIT(0)))
12711255 reg_def->def |= SX9310_REG_PROX_CTRL2_COMBMODE_CS0_CS1_CS2_CS3;
@@ -1278,7 +1262,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, · 6 unmodified lines
12781262
12791263 break;
12801264 case SX9310_REG_PROX_CTRL4:
1281− ret = of_property_read_string(np, "semtech,resolution", &res);
1265+ ret = device_property_read_string(dev, "semtech,resolution", &res);
12821266 if (ret)
12831267 break;
12841268
@@ -1302,7 +1286,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, · 17 unmodified lines
13021286
13031287 break;
13041288 case SX9310_REG_PROX_CTRL5:
1305− ret = of_property_read_u32(np, "semtech,startup-sensor", &start);
1289+ ret = device_property_read_u32(dev, "semtech,startup-sensor", &start);
13061290 if (ret) {
13071291 start = FIELD_GET(SX9310_REG_PROX_CTRL5_STARTUPSENS_MASK,
13081292 reg_def->def);
@@ -1312,7 +1296,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, · 3 unmodified lines
13121296 reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL5_STARTUPSENS_MASK,
13131297 start);
13141298
1315− ret = of_property_read_u32(np, "semtech,proxraw-strength", &raw);
1299+ ret = device_property_read_u32(dev, "semtech,proxraw-strength", &raw);
13161300 if (ret) {
13171301 raw = FIELD_GET(SX9310_REG_PROX_CTRL5_RAWFILT_MASK,
13181302 reg_def->def);
@@ -1325,7 +1309,7 @@ sx9310_get_default_reg(struct sx9310_data *data, int idx, · 6 unmodified lines
13251309 raw);
13261310 break;
13271311 case SX9310_REG_PROX_CTRL7:
1328− ret = of_property_read_u32(np, "semtech,avg-pos-strength", &pos);
1312+ ret = device_property_read_u32(dev, "semtech,avg-pos-strength", &pos);
13291313 if (ret)
13301314 break;
13311315
@@ -1361,7 +1345,7 @@ static int sx9310_init_device(struct iio_dev *indio_dev) · 29 unmodified lines
13611345
13621346 /* Program some sane defaults. */
13631347 for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) {
1364− initval = sx9310_get_default_reg(data, i, &tmp);
1348+ initval = sx9310_get_default_reg(&indio_dev->dev, i, &tmp);
13651349 ret = regmap_write(data->regmap, initval->reg, initval->def);
13661350 if (ret)
13671351 return ret;
drivers/iio/proximity/vcnl3020.c+335−16
@@ -2,8 +2,6 @@ · 1 unmodified line
22 /*
33 * Support for Vishay VCNL3020 proximity sensor on i2c bus.
44 * Based on Vishay VCNL4000 driver code.
5− *
6− * TODO: interrupts.
75 */
86
97 #include <linux/module.h>
@@ -11,9 +9,10 @@ · 1 unmodified line
119 #include <linux/err.h>
1210 #include <linux/delay.h>
1311 #include <linux/regmap.h>
12+#include <linux/interrupt.h>
1413
1514 #include <linux/iio/iio.h>
16−#include <linux/iio/sysfs.h>
15+#include <linux/iio/events.h>
1716
1817 #define VCNL3020_PROD_ID 0x21
1918
@@ -37,6 +36,21 @@ · 17 unmodified lines
3736 * measurement
3837 */
3938
39+/* Enables periodic proximity measurement */
40+#define VCNL_PS_EN BIT(1)
41+
42+/* Enables state machine and LP oscillator for self timed measurements */
43+#define VCNL_PS_SELFTIMED_EN BIT(0)
44+
45+/* Bit masks for ICR */
46+
47+/* Enable interrupts on low or high thresholds */
48+#define VCNL_ICR_THRES_EN BIT(1)
49+
50+/* Bit masks for ISR */
51+#define VCNL_INT_TH_HI BIT(0) /* High threshold hit */
52+#define VCNL_INT_TH_LOW BIT(1) /* Low threshold hit */
53+
4054 #define VCNL_ON_DEMAND_TIMEOUT_US 100000
4155 #define VCNL_POLL_US 20000
4256
@@ -57,12 +71,14 @@ static const int vcnl3020_prox_sampling_frequency[][2] = { · 14 unmodified lines
5771 * @dev: vcnl3020 device.
5872 * @rev: revision id.
5973 * @lock: lock for protecting access to device hardware registers.
74+ * @buf: DMA safe __be16 buffer.
6075 */
6176 struct vcnl3020_data {
6277 struct regmap *regmap;
6378 struct device *dev;
6479 u8 rev;
6580 struct mutex lock;
81+ __be16 buf ____cacheline_aligned;
6682 };
6783
6884 /**
@@ -140,14 +156,34 @@ static int vcnl3020_init(struct vcnl3020_data *data) · 71 unmodified lines
140156 vcnl3020_led_current_property);
141157 };
142158
159+static bool vcnl3020_is_in_periodic_mode(struct vcnl3020_data *data)
160+{
161+ int rc;
162+ unsigned int cmd;
163+
164+ rc = regmap_read(data->regmap, VCNL_COMMAND, &cmd);
165+ if (rc) {
166+ dev_err(data->dev,
167+ "Error (%d) reading command register\n", rc);
168+ return false;
169+ }
170+
171+ return !!(cmd & VCNL_PS_SELFTIMED_EN);
172+}
173+
143174 static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val)
144175 {
145176 int rc;
146177 unsigned int reg;
147− __be16 res;
148178
149179 mutex_lock(&data->lock);
150180
181+ /* Protect against event capture. */
182+ if (vcnl3020_is_in_periodic_mode(data)) {
183+ rc = -EBUSY;
184+ goto err_unlock;
185+ }
186+
151187 rc = regmap_write(data->regmap, VCNL_COMMAND, VCNL_PS_OD);
152188 if (rc)
153189 goto err_unlock;
@@ -163,12 +199,12 @@ static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val) · 9 unmodified lines
163199 }
164200
165201 /* high & low result bytes read */
166− rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &res,
167− sizeof(res));
202+ rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &data->buf,
203+ sizeof(data->buf));
168204 if (rc)
169205 goto err_unlock;
170206
171− *val = be16_to_cpu(res);
207+ *val = be16_to_cpu(data->buf);
172208
173209 err_unlock:
174210 mutex_unlock(&data->lock);
@@ -200,6 +236,15 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val, · 25 unmodified lines
200236 {
201237 unsigned int i;
202238 int index = -1;
239+ int rc;
240+
241+ mutex_lock(&data->lock);
242+
243+ /* Protect against event capture. */
244+ if (vcnl3020_is_in_periodic_mode(data)) {
245+ rc = -EBUSY;
246+ goto err_unlock;
247+ }
203248
204249 for (i = 0; i < ARRAY_SIZE(vcnl3020_prox_sampling_frequency); i++) {
205250 if (val == vcnl3020_prox_sampling_frequency[i][0] &&
@@ -209,18 +254,250 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val, · 3 unmodified lines
209254 }
210255 }
211256
212− if (index < 0)
257+ if (index < 0) {
258+ rc = -EINVAL;
259+ goto err_unlock;
260+ }
261+
262+ rc = regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index);
263+ if (rc)
264+ dev_err(data->dev,
265+ "Error (%d) writing proximity rate register\n", rc);
266+
267+err_unlock:
268+ mutex_unlock(&data->lock);
269+
270+ return rc;
271+}
272+
273+static bool vcnl3020_is_thr_enabled(struct vcnl3020_data *data)
274+{
275+ int rc;
276+ unsigned int icr;
277+
278+ rc = regmap_read(data->regmap, VCNL_PS_ICR, &icr);
279+ if (rc) {
280+ dev_err(data->dev,
281+ "Error (%d) reading ICR register\n", rc);
282+ return false;
283+ }
284+
285+ return !!(icr & VCNL_ICR_THRES_EN);
286+}
287+
288+static int vcnl3020_read_event(struct iio_dev *indio_dev,
289+ const struct iio_chan_spec *chan,
290+ enum iio_event_type type,
291+ enum iio_event_direction dir,
292+ enum iio_event_info info,
293+ int *val, int *val2)
294+{
295+ int rc;
296+ struct vcnl3020_data *data = iio_priv(indio_dev);
297+
298+ switch (info) {
299+ case IIO_EV_INFO_VALUE:
300+ switch (dir) {
301+ case IIO_EV_DIR_RISING:
302+ rc = regmap_bulk_read(data->regmap, VCNL_PS_HI_THR_HI,
303+ &data->buf, sizeof(data->buf));
304+ if (rc < 0)
305+ return rc;
306+ *val = be16_to_cpu(data->buf);
307+ return IIO_VAL_INT;
308+ case IIO_EV_DIR_FALLING:
309+ rc = regmap_bulk_read(data->regmap, VCNL_PS_LO_THR_HI,
310+ &data->buf, sizeof(data->buf));
311+ if (rc < 0)
312+ return rc;
313+ *val = be16_to_cpu(data->buf);
314+ return IIO_VAL_INT;
315+ default:
316+ return -EINVAL;
317+ }
318+ default:
213319 return -EINVAL;
320+ }
321+}
322+
323+static int vcnl3020_write_event(struct iio_dev *indio_dev,
324+ const struct iio_chan_spec *chan,
325+ enum iio_event_type type,
326+ enum iio_event_direction dir,
327+ enum iio_event_info info,
328+ int val, int val2)
329+{
330+ int rc;
331+ struct vcnl3020_data *data = iio_priv(indio_dev);
332+
333+ mutex_lock(&data->lock);
214334
215− return regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index);
335+ switch (info) {
336+ case IIO_EV_INFO_VALUE:
337+ switch (dir) {
338+ case IIO_EV_DIR_RISING:
339+ /* 16 bit word/ low * high */
340+ data->buf = cpu_to_be16(val);
341+ rc = regmap_bulk_write(data->regmap, VCNL_PS_HI_THR_HI,
342+ &data->buf, sizeof(data->buf));
343+ if (rc < 0)
344+ goto err_unlock;
345+ rc = IIO_VAL_INT;
346+ goto err_unlock;
347+ case IIO_EV_DIR_FALLING:
348+ data->buf = cpu_to_be16(val);
349+ rc = regmap_bulk_write(data->regmap, VCNL_PS_LO_THR_HI,
350+ &data->buf, sizeof(data->buf));
351+ if (rc < 0)
352+ goto err_unlock;
353+ rc = IIO_VAL_INT;
354+ goto err_unlock;
355+ default:
356+ rc = -EINVAL;
357+ goto err_unlock;
358+ }
359+ default:
360+ rc = -EINVAL;
361+ goto err_unlock;
362+ }
363+err_unlock:
364+ mutex_unlock(&data->lock);
365+
366+ return rc;
216367 }
217368
369+static int vcnl3020_enable_periodic(struct iio_dev *indio_dev,
370+ struct vcnl3020_data *data)
371+{
372+ int rc;
373+ int cmd;
374+
375+ mutex_lock(&data->lock);
376+
377+ /* Enable periodic measurement of proximity data. */
378+ cmd = VCNL_PS_EN | VCNL_PS_SELFTIMED_EN;
379+
380+ rc = regmap_write(data->regmap, VCNL_COMMAND, cmd);
381+ if (rc) {
382+ dev_err(data->dev,
383+ "Error (%d) writing command register\n", rc);
384+ goto err_unlock;
385+ }
386+
387+ /*
388+ * Enable interrupts on threshold, for proximity data by
389+ * default.
390+ */
391+ rc = regmap_write(data->regmap, VCNL_PS_ICR, VCNL_ICR_THRES_EN);
392+ if (rc)
393+ dev_err(data->dev,
394+ "Error (%d) reading ICR register\n", rc);
395+
396+err_unlock:
397+ mutex_unlock(&data->lock);
398+
399+ return rc;
400+}
401+
402+static int vcnl3020_disable_periodic(struct iio_dev *indio_dev,
403+ struct vcnl3020_data *data)
404+{
405+ int rc;
406+
407+ mutex_lock(&data->lock);
408+
409+ rc = regmap_write(data->regmap, VCNL_COMMAND, 0);
410+ if (rc) {
411+ dev_err(data->dev,
412+ "Error (%d) writing command register\n", rc);
413+ goto err_unlock;
414+ }
415+
416+ rc = regmap_write(data->regmap, VCNL_PS_ICR, 0);
417+ if (rc) {
418+ dev_err(data->dev,
419+ "Error (%d) writing ICR register\n", rc);
420+ goto err_unlock;
421+ }
422+
423+ /* Clear interrupt flag bit */
424+ rc = regmap_write(data->regmap, VCNL_ISR, 0);
425+ if (rc)
426+ dev_err(data->dev,
427+ "Error (%d) writing ISR register\n", rc);
428+
429+err_unlock:
430+ mutex_unlock(&data->lock);
431+
432+ return rc;
433+}
434+
435+static int vcnl3020_config_threshold(struct iio_dev *indio_dev, bool state)
436+{
437+ struct vcnl3020_data *data = iio_priv(indio_dev);
438+
439+ if (state) {
440+ return vcnl3020_enable_periodic(indio_dev, data);
441+ } else {
442+ if (!vcnl3020_is_thr_enabled(data))
443+ return 0;
444+ return vcnl3020_disable_periodic(indio_dev, data);
445+ }
446+}
447+
448+static int vcnl3020_write_event_config(struct iio_dev *indio_dev,
449+ const struct iio_chan_spec *chan,
450+ enum iio_event_type type,
451+ enum iio_event_direction dir,
452+ int state)
453+{
454+ switch (chan->type) {
455+ case IIO_PROXIMITY:
456+ return vcnl3020_config_threshold(indio_dev, state);
457+ default:
458+ return -EINVAL;
459+ }
460+}
461+
462+static int vcnl3020_read_event_config(struct iio_dev *indio_dev,
463+ const struct iio_chan_spec *chan,
464+ enum iio_event_type type,
465+ enum iio_event_direction dir)
466+{
467+ struct vcnl3020_data *data = iio_priv(indio_dev);
468+
469+ switch (chan->type) {
470+ case IIO_PROXIMITY:
471+ return vcnl3020_is_thr_enabled(data);
472+ default:
473+ return -EINVAL;
474+ }
475+}
476+
477+static const struct iio_event_spec vcnl3020_event_spec[] = {
478+ {
479+ .type = IIO_EV_TYPE_THRESH,
480+ .dir = IIO_EV_DIR_RISING,
481+ .mask_separate = BIT(IIO_EV_INFO_VALUE),
482+ }, {
483+ .type = IIO_EV_TYPE_THRESH,
484+ .dir = IIO_EV_DIR_FALLING,
485+ .mask_separate = BIT(IIO_EV_INFO_VALUE),
486+ }, {
487+ .type = IIO_EV_TYPE_THRESH,
488+ .dir = IIO_EV_DIR_EITHER,
489+ .mask_separate = BIT(IIO_EV_INFO_ENABLE),
490+ },
491+};
492+
218493 static const struct iio_chan_spec vcnl3020_channels[] = {
219494 {
220495 .type = IIO_PROXIMITY,
221496 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
222497 BIT(IIO_CHAN_INFO_SAMP_FREQ),
223498 .info_mask_separate_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
499+ .event_spec = vcnl3020_event_spec,
500+ .num_event_specs = ARRAY_SIZE(vcnl3020_event_spec),
224501 },
225502 };
226503
@@ -251,17 +528,11 @@ static int vcnl3020_write_raw(struct iio_dev *indio_dev, · 24 unmodified lines
251528 struct iio_chan_spec const *chan,
252529 int val, int val2, long mask)
253530 {
254− int rc;
255531 struct vcnl3020_data *data = iio_priv(indio_dev);
256532
257533 switch (mask) {
258534 case IIO_CHAN_INFO_SAMP_FREQ:
259− rc = iio_device_claim_direct_mode(indio_dev);
260− if (rc)
261− return rc;
262− rc = vcnl3020_write_proxy_samp_freq(data, val, val2);
263− iio_device_release_direct_mode(indio_dev);
264− return rc;
535+ return vcnl3020_write_proxy_samp_freq(data, val, val2);
265536 default:
266537 return -EINVAL;
267538 }
@@ -287,6 +558,10 @@ static const struct iio_info vcnl3020_info = { · 19 unmodified lines
287558 .read_raw = vcnl3020_read_raw,
288559 .write_raw = vcnl3020_write_raw,
289560 .read_avail = vcnl3020_read_avail,
561+ .read_event_value = vcnl3020_read_event,
562+ .write_event_value = vcnl3020_write_event,
563+ .read_event_config = vcnl3020_read_event_config,
564+ .write_event_config = vcnl3020_write_event_config,
290565 };
291566
292567 static const struct regmap_config vcnl3020_regmap_config = {
@@ -295,6 +570,37 @@ static const struct regmap_config vcnl3020_regmap_config = { · 2 unmodified lines
295570 .max_register = VCNL_PS_MOD_ADJ,
296571 };
297572
573+static irqreturn_t vcnl3020_handle_irq_thread(int irq, void *p)
574+{
575+ struct iio_dev *indio_dev = p;
576+ struct vcnl3020_data *data = iio_priv(indio_dev);
577+ unsigned int isr;
578+ int rc;
579+
580+ rc = regmap_read(data->regmap, VCNL_ISR, &isr);
581+ if (rc) {
582+ dev_err(data->dev, "Error (%d) reading reg (0x%x)\n",
583+ rc, VCNL_ISR);
584+ return IRQ_HANDLED;
585+ }
586+
587+ if (!(isr & VCNL_ICR_THRES_EN))
588+ return IRQ_NONE;
589+
590+ iio_push_event(indio_dev,
591+ IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1,
592+ IIO_EV_TYPE_THRESH,
593+ IIO_EV_DIR_RISING),
594+ iio_get_time_ns(indio_dev));
595+
596+ rc = regmap_write(data->regmap, VCNL_ISR, isr & VCNL_ICR_THRES_EN);
597+ if (rc)
598+ dev_err(data->dev, "Error (%d) writing in reg (0x%x)\n",
599+ rc, VCNL_ISR);
600+
601+ return IRQ_HANDLED;
602+}
603+
298604 static int vcnl3020_probe(struct i2c_client *client)
299605 {
300606 struct vcnl3020_data *data;
@@ -327,6 +633,19 @@ static int vcnl3020_probe(struct i2c_client *client) · 26 unmodified lines
327633 indio_dev->name = "vcnl3020";
328634 indio_dev->modes = INDIO_DIRECT_MODE;
329635
636+ if (client->irq) {
637+ rc = devm_request_threaded_irq(&client->dev, client->irq,
638+ NULL, vcnl3020_handle_irq_thread,
639+ IRQF_ONESHOT, indio_dev->name,
640+ indio_dev);
641+ if (rc) {
642+ dev_err(&client->dev,
643+ "Error (%d) irq request failed (%u)\n", rc,
644+ client->irq);
645+ return rc;
646+ }
647+ }
648+
330649 return devm_iio_device_register(&client->dev, indio_dev);
331650 }
332651
drivers/iio/temperature/ltc2983.c+14−16
@@ -89,6 +89,8 @@ · 88 unmodified lines
8989
9090 #define LTC2983_STATUS_START_MASK BIT(7)
9191 #define LTC2983_STATUS_START(x) FIELD_PREP(LTC2983_STATUS_START_MASK, x)
92+#define LTC2983_STATUS_UP_MASK GENMASK(7, 6)
93+#define LTC2983_STATUS_UP(reg) FIELD_GET(LTC2983_STATUS_UP_MASK, reg)
9294
9395 #define LTC2983_STATUS_CHAN_SEL_MASK GENMASK(4, 0)
9496 #define LTC2983_STATUS_CHAN_SEL(x) \
@@ -1362,17 +1364,16 @@ put_child: · 1267 unmodified lines
13621364
13631365 static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
13641366 {
1365− u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0;
1367+ u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status;
13661368 int ret;
1367− unsigned long time;
1368−
1369− /* make sure the device is up */
1370− time = wait_for_completion_timeout(&st->completion,
1371− msecs_to_jiffies(250));
13721369
1373− if (!time) {
1370+ /* make sure the device is up: start bit (7) is 0 and done bit (6) is 1 */
1371+ ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status,
1372+ LTC2983_STATUS_UP(status) == 1, 25000,
1373+ 25000 * 10);
1374+ if (ret) {
13741375 dev_err(&st->spi->dev, "Device startup timed out\n");
1375− return -ETIMEDOUT;
1376+ return ret;
13761377 }
13771378
13781379 st->iio_chan = devm_kzalloc(&st->spi->dev,
@@ -1492,10 +1493,11 @@ static int ltc2983_probe(struct spi_device *spi) · 113 unmodified lines
14921493 ret = ltc2983_parse_dt(st);
14931494 if (ret)
14941495 return ret;
1495− /*
1496− * let's request the irq now so it is used to sync the device
1497− * startup in ltc2983_setup()
1498− */
1496+
1497+ ret = ltc2983_setup(st, true);
1498+ if (ret)
1499+ return ret;
1500+
14991501 ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler,
15001502 IRQF_TRIGGER_RISING, name, st);
15011503 if (ret) {
@@ -1503,10 +1505,6 @@ static int ltc2983_probe(struct spi_device *spi) · 1 unmodified line
15031505 return ret;
15041506 }
15051507
1506− ret = ltc2983_setup(st, true);
1507− if (ret)
1508− return ret;
1509−
15101508 indio_dev->name = name;
15111509 indio_dev->num_channels = st->iio_channels;
15121510 indio_dev->channels = st->iio_chan;
drivers/iio/temperature/tmp006.c+31−22
@@ -193,6 +193,25 @@ static bool tmp006_check_identification(struct i2c_client *client) · 192 unmodified lines
193193 return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC;
194194 }
195195
196+static int tmp006_power(struct device *dev, bool up)
197+{
198+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
199+ struct tmp006_data *data = iio_priv(indio_dev);
200+
201+ if (up)
202+ data->config |= TMP006_CONFIG_MOD_MASK;
203+ else
204+ data->config &= ~TMP006_CONFIG_MOD_MASK;
205+
206+ return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
207+ data->config);
208+}
209+
210+static void tmp006_powerdown_cleanup(void *dev)
211+{
212+ tmp006_power(dev, false);
213+}
214+
196215 static int tmp006_probe(struct i2c_client *client,
197216 const struct i2c_device_id *id)
198217 {
@@ -228,38 +247,29 @@ static int tmp006_probe(struct i2c_client *client, · 29 unmodified lines
228247 return ret;
229248 data->config = ret;
230249
231− return iio_device_register(indio_dev);
232−}
233−
234−static int tmp006_powerdown(struct tmp006_data *data)
235−{
236− return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
237− data->config & ~TMP006_CONFIG_MOD_MASK);
238−}
239−
240−static int tmp006_remove(struct i2c_client *client)
241−{
242− struct iio_dev *indio_dev = i2c_get_clientdata(client);
250+ if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) {
251+ ret = tmp006_power(&client->dev, true);
252+ if (ret < 0)
253+ return ret;
254+ }
243255
244− iio_device_unregister(indio_dev);
245− tmp006_powerdown(iio_priv(indio_dev));
256+ ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup,
257+ &client->dev);
258+ if (ret < 0)
259+ return ret;
246260
247− return 0;
261+ return devm_iio_device_register(&client->dev, indio_dev);
248262 }
249263
250264 #ifdef CONFIG_PM_SLEEP
251265 static int tmp006_suspend(struct device *dev)
252266 {
253− struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
254− return tmp006_powerdown(iio_priv(indio_dev));
267+ return tmp006_power(dev, false);
255268 }
256269
257270 static int tmp006_resume(struct device *dev)
258271 {
259− struct tmp006_data *data = iio_priv(i2c_get_clientdata(
260− to_i2c_client(dev)));
261− return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
262− data->config | TMP006_CONFIG_MOD_MASK);
272+ return tmp006_power(dev, true);
263273 }
264274 #endif
265275
@@ -277,7 +287,6 @@ static struct i2c_driver tmp006_driver = { · 11 unmodified lines
277287 .pm = &tmp006_pm_ops,
278288 },
279289 .probe = tmp006_probe,
280− .remove = tmp006_remove,
281290 .id_table = tmp006_id,
282291 };
283292 module_i2c_driver(tmp006_driver);
drivers/mfd/Kconfig+16−0
@@ -510,6 +510,22 @@ config MFD_HI6421_PMIC · 509 unmodified lines
510510 menus in order to enable them.
511511 We communicate with the Hi6421 via memory-mapped I/O.
512512
513+config MFD_HI6421_SPMI
514+ tristate "HiSilicon Hi6421v600 SPMI PMU/Codec IC"
515+ depends on OF
516+ depends on SPMI
517+ select MFD_CORE
518+ select REGMAP_SPMI
519+ help
520+ Add support for HiSilicon Hi6421v600 SPMI PMIC. Hi6421 includes
521+ multi-functions, such as regulators, RTC, codec, Coulomb counter,
522+ etc.
523+
524+ This driver includes core APIs _only_. You have to select
525+ individual components like voltage regulators under corresponding
526+ menus in order to enable them.
527+ We communicate with the Hi6421v600 via a SPMI bus.
528+
513529 config MFD_HI655X_PMIC
514530 tristate "HiSilicon Hi655X series PMU/Codec IC"
515531 depends on ARCH_HISI || COMPILE_TEST
drivers/mfd/Makefile+1−0
@@ -231,6 +231,7 @@ obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o · 230 unmodified lines
231231 obj-$(CONFIG_MFD_IQS62X) += iqs62x.o
232232 obj-$(CONFIG_MFD_MENF21BMC) += menf21bmc.o
233233 obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o
234+obj-$(CONFIG_MFD_HI6421_SPMI) += hi6421-spmi-pmic.o
234235 obj-$(CONFIG_MFD_HI655X_PMIC) += hi655x-pmic.o
235236 obj-$(CONFIG_MFD_DLN2) += dln2.o
236237 obj-$(CONFIG_MFD_RT4831) += rt4831.o
drivers/mfd/hi6421-spmi-pmic.c+72−0
@@ -0,0 +1,72 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Device driver for regulators in HISI PMIC IC
4+ *
5+ * Copyright (c) 2013 Linaro Ltd.
6+ * Copyright (c) 2011 Hisilicon.
7+ * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd.
8+ */
9+
10+#include <linux/mfd/core.h>
11+#include <linux/mfd/hi6421-spmi-pmic.h>
12+#include <linux/module.h>
13+#include <linux/platform_device.h>
14+#include <linux/regmap.h>
15+#include <linux/slab.h>
16+#include <linux/spmi.h>
17+
18+static const struct mfd_cell hi6421v600_devs[] = {
19+ { .name = "hi6421v600-irq", },
20+ { .name = "hi6421v600-regulator", },
21+};
22+
23+static const struct regmap_config regmap_config = {
24+ .reg_bits = 16,
25+ .val_bits = BITS_PER_BYTE,
26+ .max_register = 0xffff,
27+ .fast_io = true
28+};
29+
30+static int hi6421_spmi_pmic_probe(struct spmi_device *sdev)
31+{
32+ struct device *dev = &sdev->dev;
33+ int ret;
34+ struct hi6421_spmi_pmic *ddata;
35+ ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
36+ if (!ddata)
37+ return -ENOMEM;
38+
39+ ddata->regmap = devm_regmap_init_spmi_ext(sdev, &regmap_config);
40+ if (IS_ERR(ddata->regmap))
41+ return PTR_ERR(ddata->regmap);
42+
43+ ddata->dev = dev;
44+
45+ dev_set_drvdata(&sdev->dev, ddata);
46+
47+ ret = devm_mfd_add_devices(&sdev->dev, PLATFORM_DEVID_NONE,
48+ hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs),
49+ NULL, 0, NULL);
50+ if (ret < 0)
51+ dev_err(dev, "Failed to add child devices: %d\n", ret);
52+
53+ return ret;
54+}
55+
56+static const struct of_device_id pmic_spmi_id_table[] = {
57+ { .compatible = "hisilicon,hi6421-spmi" },
58+ { }
59+};
60+MODULE_DEVICE_TABLE(of, pmic_spmi_id_table);
61+
62+static struct spmi_driver hi6421_spmi_pmic_driver = {
63+ .driver = {
64+ .name = "hi6421-spmi-pmic",
65+ .of_match_table = pmic_spmi_id_table,
66+ },
67+ .probe = hi6421_spmi_pmic_probe,
68+};
69+module_spmi_driver(hi6421_spmi_pmic_driver);
70+
71+MODULE_DESCRIPTION("HiSilicon Hi6421v600 SPMI PMIC driver");
72+MODULE_LICENSE("GPL v2");
drivers/misc/Kconfig+10−0
@@ -220,6 +220,16 @@ config GEHC_ACHC · 219 unmodified lines
220220 To compile this driver as a module, choose M here: the
221221 module will be called gehc-achc.
222222
223+config HI6421V600_IRQ
224+ tristate "HiSilicon Hi6421v600 IRQ and powerkey"
225+ depends on OF
226+ depends on SPMI
227+ select MFD_CORE
228+ select REGMAP_SPMI
229+ help
230+ This driver provides IRQ handling for Hi6421v600, used on
231+ some Kirin chipsets, like the one at Hikey 970.
232+
223233 config HP_ILO
224234 tristate "Channel interface driver for the HP iLO processor"
225235 depends on PCI
drivers/misc/Makefile+1−0
@@ -58,3 +58,4 @@ obj-$(CONFIG_HABANA_AI) += habanalabs/ · 57 unmodified lines
5858 obj-$(CONFIG_UACCE) += uacce/
5959 obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o
6060 obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
61+obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o
drivers/misc/hi6421v600-irq.c+307−0
@@ -0,0 +1,307 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Device driver for irqs in HISI PMIC IC
4+ *
5+ * Copyright (c) 2013 Linaro Ltd.
6+ * Copyright (c) 2011 Hisilicon.
7+ * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd.
8+ */
9+
10+#include <linux/bitops.h>
11+#include <linux/interrupt.h>
12+#include <linux/irq.h>
13+#include <linux/mfd/hi6421-spmi-pmic.h>
14+#include <linux/module.h>
15+#include <linux/of_gpio.h>
16+#include <linux/platform_device.h>
17+#include <linux/slab.h>
18+#include <linux/irqdomain.h>
19+#include <linux/regmap.h>
20+
21+struct hi6421v600_irq {
22+ struct device *dev;
23+ struct irq_domain *domain;
24+ int irq;
25+ unsigned int *irqs;
26+ struct regmap *regmap;
27+
28+ /* Protect IRQ mask changes */
29+ spinlock_t lock;
30+};
31+
32+enum hi6421v600_irq_list {
33+ OTMP = 0,
34+ VBUS_CONNECT,
35+ VBUS_DISCONNECT,
36+ ALARMON_R,
37+ HOLD_6S,
38+ HOLD_1S,
39+ POWERKEY_UP,
40+ POWERKEY_DOWN,
41+ OCP_SCP_R,
42+ COUL_R,
43+ SIM0_HPD_R,
44+ SIM0_HPD_F,
45+ SIM1_HPD_R,
46+ SIM1_HPD_F,
47+
48+ PMIC_IRQ_LIST_MAX
49+};
50+
51+#define HISI_IRQ_BANK_SIZE 2
52+
53+/*
54+ * IRQ number for the power key button and mask for both UP and DOWN IRQs
55+ */
56+#define HISI_POWERKEY_IRQ_NUM 0
57+#define HISI_IRQ_POWERKEY_UP_DOWN (BIT(POWERKEY_DOWN) | BIT(POWERKEY_UP))
58+
59+/*
60+ * Registers for IRQ address and IRQ mask bits
61+ *
62+ * Please notice that we need to regmap a larger region, as other
63+ * registers are used by the irqs.
64+ * See drivers/irq/hi6421-irq.c.
65+ */
66+#define SOC_PMIC_IRQ_MASK_0_ADDR 0x0202
67+#define SOC_PMIC_IRQ0_ADDR 0x0212
68+
69+/*
70+ * The IRQs are mapped as:
71+ *
72+ * ====================== ============= ============ =====
73+ * IRQ MASK REGISTER IRQ REGISTER BIT
74+ * ====================== ============= ============ =====
75+ * OTMP 0x0202 0x212 bit 0
76+ * VBUS_CONNECT 0x0202 0x212 bit 1
77+ * VBUS_DISCONNECT 0x0202 0x212 bit 2
78+ * ALARMON_R 0x0202 0x212 bit 3
79+ * HOLD_6S 0x0202 0x212 bit 4
80+ * HOLD_1S 0x0202 0x212 bit 5
81+ * POWERKEY_UP 0x0202 0x212 bit 6
82+ * POWERKEY_DOWN 0x0202 0x212 bit 7
83+ *
84+ * OCP_SCP_R 0x0203 0x213 bit 0
85+ * COUL_R 0x0203 0x213 bit 1
86+ * SIM0_HPD_R 0x0203 0x213 bit 2
87+ * SIM0_HPD_F 0x0203 0x213 bit 3
88+ * SIM1_HPD_R 0x0203 0x213 bit 4
89+ * SIM1_HPD_F 0x0203 0x213 bit 5
90+ * ====================== ============= ============ =====
91+ *
92+ * Each mask register contains 8 bits. The ancillary macros below
93+ * convert a number from 0 to 14 into a register address and a bit mask
94+ */
95+#define HISI_IRQ_MASK_REG(irq_data) (SOC_PMIC_IRQ_MASK_0_ADDR + \
96+ (irqd_to_hwirq(irq_data) / BITS_PER_BYTE))
97+#define HISI_IRQ_MASK_BIT(irq_data) BIT(irqd_to_hwirq(irq_data) & (BITS_PER_BYTE - 1))
98+#define HISI_8BITS_MASK 0xff
99+
100+static irqreturn_t hi6421v600_irq_handler(int irq, void *__priv)
101+{
102+ struct hi6421v600_irq *priv = __priv;
103+ unsigned long pending;
104+ unsigned int in;
105+ int i, offset;
106+
107+ for (i = 0; i < HISI_IRQ_BANK_SIZE; i++) {
108+ regmap_read(priv->regmap, SOC_PMIC_IRQ0_ADDR + i, &in);
109+
110+ /* Mark pending IRQs as handled */
111+ regmap_write(priv->regmap, SOC_PMIC_IRQ0_ADDR + i, in);
112+
113+ pending = in & HISI_8BITS_MASK;
114+
115+ if (i == HISI_POWERKEY_IRQ_NUM &&
116+ (pending & HISI_IRQ_POWERKEY_UP_DOWN) == HISI_IRQ_POWERKEY_UP_DOWN) {
117+ /*
118+ * If both powerkey down and up IRQs are received,
119+ * handle them at the right order
120+ */
121+ generic_handle_irq(priv->irqs[POWERKEY_DOWN]);
122+ generic_handle_irq(priv->irqs[POWERKEY_UP]);
123+ pending &= ~HISI_IRQ_POWERKEY_UP_DOWN;
124+ }
125+
126+ if (!pending)
127+ continue;
128+
129+ for_each_set_bit(offset, &pending, BITS_PER_BYTE) {
130+ generic_handle_irq(priv->irqs[offset + i * BITS_PER_BYTE]);
131+ }
132+ }
133+
134+ return IRQ_HANDLED;
135+}
136+
137+static void hi6421v600_irq_mask(struct irq_data *d)
138+{
139+ struct hi6421v600_irq *priv = irq_data_get_irq_chip_data(d);
140+ unsigned long flags;
141+ unsigned int data;
142+ u32 offset;
143+
144+ offset = HISI_IRQ_MASK_REG(d);
145+
146+ spin_lock_irqsave(&priv->lock, flags);
147+
148+ regmap_read(priv->regmap, offset, &data);
149+ data |= HISI_IRQ_MASK_BIT(d);
150+ regmap_write(priv->regmap, offset, data);
151+
152+ spin_unlock_irqrestore(&priv->lock, flags);
153+}
154+
155+static void hi6421v600_irq_unmask(struct irq_data *d)
156+{
157+ struct hi6421v600_irq *priv = irq_data_get_irq_chip_data(d);
158+ u32 data, offset;
159+ unsigned long flags;
160+
161+ offset = HISI_IRQ_MASK_REG(d);
162+
163+ spin_lock_irqsave(&priv->lock, flags);
164+
165+ regmap_read(priv->regmap, offset, &data);
166+ data &= ~HISI_IRQ_MASK_BIT(d);
167+ regmap_write(priv->regmap, offset, data);
168+
169+ spin_unlock_irqrestore(&priv->lock, flags);
170+}
171+
172+static struct irq_chip hi6421v600_pmu_irqchip = {
173+ .name = "hi6421v600-irq",
174+ .irq_mask = hi6421v600_irq_mask,
175+ .irq_unmask = hi6421v600_irq_unmask,
176+ .irq_disable = hi6421v600_irq_mask,
177+ .irq_enable = hi6421v600_irq_unmask,
178+};
179+
180+static int hi6421v600_irq_map(struct irq_domain *d, unsigned int virq,
181+ irq_hw_number_t hw)
182+{
183+ struct hi6421v600_irq *priv = d->host_data;
184+
185+ irq_set_chip_and_handler_name(virq, &hi6421v600_pmu_irqchip,
186+ handle_simple_irq, "hi6421v600");
187+ irq_set_chip_data(virq, priv);
188+ irq_set_irq_type(virq, IRQ_TYPE_NONE);
189+
190+ return 0;
191+}
192+
193+static const struct irq_domain_ops hi6421v600_domain_ops = {
194+ .map = hi6421v600_irq_map,
195+ .xlate = irq_domain_xlate_twocell,
196+};
197+
198+static void hi6421v600_irq_init(struct hi6421v600_irq *priv)
199+{
200+ int i;
201+ unsigned int pending;
202+
203+ /* Mask all IRQs */
204+ for (i = 0; i < HISI_IRQ_BANK_SIZE; i++)
205+ regmap_write(priv->regmap, SOC_PMIC_IRQ_MASK_0_ADDR + i,
206+ HISI_8BITS_MASK);
207+
208+ /* Mark all IRQs as handled */
209+ for (i = 0; i < HISI_IRQ_BANK_SIZE; i++) {
210+ regmap_read(priv->regmap, SOC_PMIC_IRQ0_ADDR + i, &pending);
211+ regmap_write(priv->regmap, SOC_PMIC_IRQ0_ADDR + i,
212+ HISI_8BITS_MASK);
213+ }
214+}
215+
216+static int hi6421v600_irq_probe(struct platform_device *pdev)
217+{
218+ struct device *pmic_dev = pdev->dev.parent;
219+ struct device_node *np = pmic_dev->of_node;
220+ struct platform_device *pmic_pdev;
221+ struct device *dev = &pdev->dev;
222+ struct hi6421v600_irq *priv;
223+ struct hi6421_spmi_pmic *pmic;
224+ unsigned int virq;
225+ int i, ret;
226+
227+ /*
228+ * This driver is meant to be called by hi6421-spmi-core,
229+ * which should first set drvdata. If this doesn't happen, hit
230+ * a warn on and return.
231+ */
232+ pmic = dev_get_drvdata(pmic_dev);
233+ if (WARN_ON(!pmic))
234+ return -ENODEV;
235+
236+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
237+ if (!priv)
238+ return -ENOMEM;
239+
240+ priv->dev = dev;
241+ priv->regmap = pmic->regmap;
242+
243+ spin_lock_init(&priv->lock);
244+
245+ pmic_pdev = container_of(pmic_dev, struct platform_device, dev);
246+
247+ priv->irq = platform_get_irq(pmic_pdev, 0);
248+ if (priv->irq < 0) {
249+ dev_err(dev, "Error %d when getting IRQs\n", priv->irq);
250+ return priv->irq;
251+ }
252+
253+ platform_set_drvdata(pdev, priv);
254+
255+ hi6421v600_irq_init(priv);
256+
257+ priv->irqs = devm_kzalloc(dev, PMIC_IRQ_LIST_MAX * sizeof(int), GFP_KERNEL);
258+ if (!priv->irqs)
259+ return -ENOMEM;
260+
261+ priv->domain = irq_domain_add_simple(np, PMIC_IRQ_LIST_MAX, 0,
262+ &hi6421v600_domain_ops, priv);
263+ if (!priv->domain) {
264+ dev_err(dev, "Failed to create IRQ domain\n");
265+ return -ENODEV;
266+ }
267+
268+ for (i = 0; i < PMIC_IRQ_LIST_MAX; i++) {
269+ virq = irq_create_mapping(priv->domain, i);
270+ if (!virq) {
271+ dev_err(dev, "Failed to map H/W IRQ\n");
272+ return -ENODEV;
273+ }
274+ priv->irqs[i] = virq;
275+ }
276+
277+ ret = devm_request_threaded_irq(dev,
278+ priv->irq, hi6421v600_irq_handler,
279+ NULL,
280+ IRQF_TRIGGER_LOW | IRQF_SHARED | IRQF_NO_SUSPEND,
281+ "pmic", priv);
282+ if (ret < 0) {
283+ dev_err(dev, "Failed to start IRQ handling thread: error %d\n",
284+ ret);
285+ return ret;
286+ }
287+
288+ return 0;
289+}
290+
291+static const struct platform_device_id hi6421v600_irq_table[] = {
292+ { .name = "hi6421v600-irq" },
293+ {},
294+};
295+MODULE_DEVICE_TABLE(platform, hi6421v600_irq_table);
296+
297+static struct platform_driver hi6421v600_irq_driver = {
298+ .id_table = hi6421v600_irq_table,
299+ .driver = {
300+ .name = "hi6421v600-irq",
301+ },
302+ .probe = hi6421v600_irq_probe,
303+};
304+module_platform_driver(hi6421v600_irq_driver);
305+
306+MODULE_DESCRIPTION("HiSilicon Hi6421v600 IRQ driver");
307+MODULE_LICENSE("GPL v2");
drivers/staging/Kconfig+1−3
@@ -36,7 +36,7 @@ source "drivers/staging/rtl8723bs/Kconfig" · 35 unmodified lines
3636
3737 source "drivers/staging/rtl8712/Kconfig"
3838
39−source "drivers/staging/rtl8188eu/Kconfig"
39+source "drivers/staging/r8188eu/Kconfig"
4040
4141 source "drivers/staging/rts5208/Kconfig"
4242
@@ -102,6 +102,4 @@ source "drivers/staging/qlge/Kconfig" · 59 unmodified lines
102102
103103 source "drivers/staging/wfx/Kconfig"
104104
105−source "drivers/staging/hikey9xx/Kconfig"
106−
107105 endif # STAGING
drivers/staging/Makefile+1−2
@@ -8,7 +8,7 @@ obj-$(CONFIG_RTL8192U) += rtl8192u/ · 7 unmodified lines
88 obj-$(CONFIG_RTL8192E) += rtl8192e/
99 obj-$(CONFIG_RTL8723BS) += rtl8723bs/
1010 obj-$(CONFIG_R8712U) += rtl8712/
11−obj-$(CONFIG_R8188EU) += rtl8188eu/
11+obj-$(CONFIG_R8188EU) += r8188eu/
1212 obj-$(CONFIG_RTS5208) += rts5208/
1313 obj-$(CONFIG_NETLOGIC_XLR_NET) += netlogic/
1414 obj-$(CONFIG_OCTEON_ETHERNET) += octeon/
@@ -41,4 +41,3 @@ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ · 26 unmodified lines
4141 obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
4242 obj-$(CONFIG_QLGE) += qlge/
4343 obj-$(CONFIG_WFX) += wfx/
44−obj-y += hikey9xx/
drivers/staging/board/board.c+6−1
@@ -136,6 +136,7 @@ int __init board_staging_register_clock(const struct board_staging_clk *bsc) · 135 unmodified lines
136136 static int board_staging_add_dev_domain(struct platform_device *pdev,
137137 const char *domain)
138138 {
139+ struct device *dev = &pdev->dev;
139140 struct of_phandle_args pd_args;
140141 struct device_node *np;
141142
@@ -148,7 +149,11 @@ static int board_staging_add_dev_domain(struct platform_device *pdev, · 6 unmodified lines
148149 pd_args.np = np;
149150 pd_args.args_count = 0;
150151
151− return of_genpd_add_device(&pd_args, &pdev->dev);
152+ /* Initialization similar to device_pm_init_common() */
153+ spin_lock_init(&dev->power.lock);
154+ dev->power.early_init = true;
155+
156+ return of_genpd_add_device(&pd_args, dev);
152157 }
153158 #else
154159 static inline int board_staging_add_dev_domain(struct platform_device *pdev,
drivers/staging/clocking-wizard/Kconfig+1−1
@@ -5,6 +5,6 @@ · 4 unmodified lines
55
66 config COMMON_CLK_XLNX_CLKWZRD
77 tristate "Xilinx Clocking Wizard"
8− depends on COMMON_CLK && OF && IOMEM
8+ depends on COMMON_CLK && OF && HAS_IOMEM
99 help
1010 Support for the Xilinx Clocking Wizard IP core clock generator.
drivers/staging/fbtft/fbtft-core.c+10−13
@@ -992,9 +992,7 @@ out_free: · 991 unmodified lines
992992 int fbtft_init_display(struct fbtft_par *par)
993993 {
994994 int buf[64];
995− char msg[128];
996− char str[16];
997− int i = 0;
995+ int i;
998996 int j;
999997
1000998 /* sanity check */
@@ -1005,9 +1003,11 @@ int fbtft_init_display(struct fbtft_par *par) · 4 unmodified lines
10051003 }
10061004
10071005 /* make sure stop marker exists */
1008− for (i = 0; i < FBTFT_MAX_INIT_SEQUENCE; i++)
1006+ for (i = 0; i < FBTFT_MAX_INIT_SEQUENCE; i++) {
10091007 if (par->init_sequence[i] == -3)
10101008 break;
1009+ }
1010+
10111011 if (i == FBTFT_MAX_INIT_SEQUENCE) {
10121012 dev_err(par->info->device,
10131013 "missing stop marker at end of init sequence\n");
@@ -1036,17 +1036,14 @@ int fbtft_init_display(struct fbtft_par *par) · 22 unmodified lines
10361036 switch (par->init_sequence[i]) {
10371037 case -1:
10381038 i++;
1039+
10391040 /* make debug message */
1040− strcpy(msg, "");
1041− j = i + 1;
1042− while (par->init_sequence[j] >= 0) {
1043− sprintf(str, "0x%02X ", par->init_sequence[j]);
1044− strcat(msg, str);
1045− j++;
1046− }
1041+ for (j = 0; par->init_sequence[i + 1 + j] >= 0; j++);
1042+
10471043 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
1048− "init: write(0x%02X) %s\n",
1049− par->init_sequence[i], msg);
1044+ "init: write(0x%02X) %*ph\n",
1045+ par->init_sequence[i], j,
1046+ &par->init_sequence[i + 1]);
10501047
10511048 /* Write */
10521049 j = 0;
drivers/staging/gdm724x/netlink_k.c+2−2
@@ -19,8 +19,8 @@ static DEFINE_MUTEX(netlink_mutex); · 18 unmodified lines
1919 #define ND_NLMSG_SPACE(len) (NLMSG_SPACE(len) + ND_IFINDEX_LEN)
2020 #define ND_NLMSG_DATA(nlh) ((void *)((char *)NLMSG_DATA(nlh) + \
2121 ND_IFINDEX_LEN))
22−#define ND_NLMSG_S_LEN(len) (len + ND_IFINDEX_LEN)
23−#define ND_NLMSG_R_LEN(nlh) (nlh->nlmsg_len - ND_IFINDEX_LEN)
22+#define ND_NLMSG_S_LEN(len) ((len) + ND_IFINDEX_LEN)
23+#define ND_NLMSG_R_LEN(nlh) ((nlh)->nlmsg_len - ND_IFINDEX_LEN)
2424 #define ND_NLMSG_IFIDX(nlh) NLMSG_DATA(nlh)
2525 #define ND_MAX_MSG_LEN (1024 * 32)
2626
drivers/staging/hikey9xx/Kconfig+0−19
@@ -1,19 +0,0 @@
1−# SPDX-License-Identifier: GPL-2.0
2−
3−# to be placed at drivers/mfd
4−config MFD_HI6421_SPMI
5− tristate "HiSilicon Hi6421v600 SPMI PMU/Codec IC"
6− depends on HAS_IOMEM
7− depends on OF
8− depends on SPMI
9− select MFD_CORE
10− select REGMAP_SPMI
11− help
12− Add support for HiSilicon Hi6421v600 SPMI PMIC. Hi6421 includes
13− multi-functions, such as regulators, RTC, codec, Coulomb counter,
14− etc.
15−
16− This driver includes core APIs _only_. You have to select
17− individual components like voltage regulators under corresponding
18− menus in order to enable them.
19− We communicate with the Hi6421v600 via a SPMI bus.
drivers/staging/hikey9xx/Makefile+0−3
@@ -1,3 +0,0 @@
1−# SPDX-License-Identifier: GPL-2.0
2−
3−obj-$(CONFIG_MFD_HI6421_SPMI) += hi6421-spmi-pmic.o
drivers/staging/hikey9xx/TODO+0−5
@@ -1,5 +0,0 @@
1−ToDo list:
2−
3−- Port other drivers needed by Hikey 960/970;
4−- Test drivers on Hikey 960;
5−- Validate device tree bindings.
drivers/staging/hikey9xx/hi6421-spmi-pmic.c+0−311
@@ -1,311 +0,0 @@
1−// SPDX-License-Identifier: GPL-2.0
2−/*
3− * Device driver for regulators in HISI PMIC IC
4− *
5− * Copyright (c) 2013 Linaro Ltd.
6− * Copyright (c) 2011 Hisilicon.
7− * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd
8− */
9−
10−#include <linux/bitops.h>
11−#include <linux/interrupt.h>
12−#include <linux/irq.h>
13−#include <linux/mfd/core.h>
14−#include <linux/mfd/hi6421-spmi-pmic.h>
15−#include <linux/module.h>
16−#include <linux/of_gpio.h>
17−#include <linux/platform_device.h>
18−#include <linux/slab.h>
19−#include <linux/spmi.h>
20−
21−enum hi6421_spmi_pmic_irq_list {
22− OTMP = 0,
23− VBUS_CONNECT,
24− VBUS_DISCONNECT,
25− ALARMON_R,
26− HOLD_6S,
27− HOLD_1S,
28− POWERKEY_UP,
29− POWERKEY_DOWN,
30− OCP_SCP_R,
31− COUL_R,
32− SIM0_HPD_R,
33− SIM0_HPD_F,
34− SIM1_HPD_R,
35− SIM1_HPD_F,
36−
37− PMIC_IRQ_LIST_MAX
38−};
39−
40−#define HISI_IRQ_BANK_SIZE 2
41−
42−/*
43− * IRQ number for the power key button and mask for both UP and DOWN IRQs
44− */
45−#define HISI_POWERKEY_IRQ_NUM 0
46−#define HISI_IRQ_POWERKEY_UP_DOWN (BIT(POWERKEY_DOWN) | BIT(POWERKEY_UP))
47−
48−/*
49− * Registers for IRQ address and IRQ mask bits
50− *
51− * Please notice that we need to regmap a larger region, as other
52− * registers are used by the regulators.
53− * See drivers/regulator/hi6421-regulator.c.
54− */
55−#define SOC_PMIC_IRQ_MASK_0_ADDR 0x0202
56−#define SOC_PMIC_IRQ0_ADDR 0x0212
57−
58−/*
59− * The IRQs are mapped as:
60− *
61− * ====================== ============= ============ =====
62− * IRQ MASK REGISTER IRQ REGISTER BIT
63− * ====================== ============= ============ =====
64− * OTMP 0x0202 0x212 bit 0
65− * VBUS_CONNECT 0x0202 0x212 bit 1
66− * VBUS_DISCONNECT 0x0202 0x212 bit 2
67− * ALARMON_R 0x0202 0x212 bit 3
68− * HOLD_6S 0x0202 0x212 bit 4
69− * HOLD_1S 0x0202 0x212 bit 5
70− * POWERKEY_UP 0x0202 0x212 bit 6
71− * POWERKEY_DOWN 0x0202 0x212 bit 7
72− *
73− * OCP_SCP_R 0x0203 0x213 bit 0
74− * COUL_R 0x0203 0x213 bit 1
75− * SIM0_HPD_R 0x0203 0x213 bit 2
76− * SIM0_HPD_F 0x0203 0x213 bit 3
77− * SIM1_HPD_R 0x0203 0x213 bit 4
78− * SIM1_HPD_F 0x0203 0x213 bit 5
79− * ====================== ============= ============ =====
80− *
81− * Each mask register contains 8 bits. The ancillary macros below
82− * convert a number from 0 to 14 into a register address and a bit mask
83− */
84−#define HISI_IRQ_MASK_REG(irq_data) (SOC_PMIC_IRQ_MASK_0_ADDR + \
85− (irqd_to_hwirq(irq_data) / BITS_PER_BYTE))
86−#define HISI_IRQ_MASK_BIT(irq_data) BIT(irqd_to_hwirq(irq_data) & (BITS_PER_BYTE - 1))
87−#define HISI_8BITS_MASK 0xff
88−
89−static const struct mfd_cell hi6421v600_devs[] = {
90− { .name = "hi6421v600-regulator", },
91−};
92−
93−static irqreturn_t hi6421_spmi_irq_handler(int irq, void *priv)
94−{
95− struct hi6421_spmi_pmic *ddata = (struct hi6421_spmi_pmic *)priv;
96− unsigned long pending;
97− unsigned int in;
98− int i, offset;
99−
100− for (i = 0; i < HISI_IRQ_BANK_SIZE; i++) {
101− regmap_read(ddata->regmap, SOC_PMIC_IRQ0_ADDR + i, &in);
102−
103− /* Mark pending IRQs as handled */
104− regmap_write(ddata->regmap, SOC_PMIC_IRQ0_ADDR + i, in);
105−
106− pending = in & HISI_8BITS_MASK;
107−
108− if (i == HISI_POWERKEY_IRQ_NUM &&
109− (pending & HISI_IRQ_POWERKEY_UP_DOWN) == HISI_IRQ_POWERKEY_UP_DOWN) {
110− /*
111− * If both powerkey down and up IRQs are received,
112− * handle them at the right order
113− */
114− generic_handle_irq(ddata->irqs[POWERKEY_DOWN]);
115− generic_handle_irq(ddata->irqs[POWERKEY_UP]);
116− pending &= ~HISI_IRQ_POWERKEY_UP_DOWN;
117− }
118−
119− if (!pending)
120− continue;
121−
122− for_each_set_bit(offset, &pending, BITS_PER_BYTE) {
123− generic_handle_irq(ddata->irqs[offset + i * BITS_PER_BYTE]);
124− }
125− }
126−
127− return IRQ_HANDLED;
128−}
129−
130−static void hi6421_spmi_irq_mask(struct irq_data *d)
131−{
132− struct hi6421_spmi_pmic *ddata = irq_data_get_irq_chip_data(d);
133− unsigned long flags;
134− unsigned int data;
135− u32 offset;
136−
137− offset = HISI_IRQ_MASK_REG(d);
138−
139− spin_lock_irqsave(&ddata->lock, flags);
140−
141− regmap_read(ddata->regmap, offset, &data);
142− data |= HISI_IRQ_MASK_BIT(d);
143− regmap_write(ddata->regmap, offset, data);
144−
145− spin_unlock_irqrestore(&ddata->lock, flags);
146−}
147−
148−static void hi6421_spmi_irq_unmask(struct irq_data *d)
149−{
150− struct hi6421_spmi_pmic *ddata = irq_data_get_irq_chip_data(d);
151− u32 data, offset;
152− unsigned long flags;
153−
154− offset = HISI_IRQ_MASK_REG(d);
155−
156− spin_lock_irqsave(&ddata->lock, flags);
157−
158− regmap_read(ddata->regmap, offset, &data);
159− data &= ~HISI_IRQ_MASK_BIT(d);
160− regmap_write(ddata->regmap, offset, data);
161−
162− spin_unlock_irqrestore(&ddata->lock, flags);
163−}
164−
165−static struct irq_chip hi6421_spmi_pmu_irqchip = {
166− .name = "hi6421v600-irq",
167− .irq_mask = hi6421_spmi_irq_mask,
168− .irq_unmask = hi6421_spmi_irq_unmask,
169− .irq_disable = hi6421_spmi_irq_mask,
170− .irq_enable = hi6421_spmi_irq_unmask,
171−};
172−
173−static int hi6421_spmi_irq_map(struct irq_domain *d, unsigned int virq,
174− irq_hw_number_t hw)
175−{
176− struct hi6421_spmi_pmic *ddata = d->host_data;
177−
178− irq_set_chip_and_handler_name(virq, &hi6421_spmi_pmu_irqchip,
179− handle_simple_irq, "hi6421v600");
180− irq_set_chip_data(virq, ddata);
181− irq_set_irq_type(virq, IRQ_TYPE_NONE);
182−
183− return 0;
184−}
185−
186−static const struct irq_domain_ops hi6421_spmi_domain_ops = {
187− .map = hi6421_spmi_irq_map,
188− .xlate = irq_domain_xlate_twocell,
189−};
190−
191−static void hi6421_spmi_pmic_irq_init(struct hi6421_spmi_pmic *ddata)
192−{
193− int i;
194− unsigned int pending;
195−
196− /* Mask all IRQs */
197− for (i = 0; i < HISI_IRQ_BANK_SIZE; i++)
198− regmap_write(ddata->regmap, SOC_PMIC_IRQ_MASK_0_ADDR + i,
199− HISI_8BITS_MASK);
200−
201− /* Mark all IRQs as handled */
202− for (i = 0; i < HISI_IRQ_BANK_SIZE; i++) {
203− regmap_read(ddata->regmap, SOC_PMIC_IRQ0_ADDR + i, &pending);
204− regmap_write(ddata->regmap, SOC_PMIC_IRQ0_ADDR + i,
205− HISI_8BITS_MASK);
206− }
207−}
208−
209−static const struct regmap_config regmap_config = {
210− .reg_bits = 16,
211− .val_bits = BITS_PER_BYTE,
212− .max_register = 0xffff,
213− .fast_io = true
214−};
215−
216−static int hi6421_spmi_pmic_probe(struct spmi_device *pdev)
217−{
218− struct device *dev = &pdev->dev;
219− struct device_node *np = dev->of_node;
220− struct hi6421_spmi_pmic *ddata;
221− unsigned int virq;
222− int ret, i;
223−
224− ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
225− if (!ddata)
226− return -ENOMEM;
227−
228− ddata->regmap = devm_regmap_init_spmi_ext(pdev, &regmap_config);
229− if (IS_ERR(ddata->regmap))
230− return PTR_ERR(ddata->regmap);
231−
232− spin_lock_init(&ddata->lock);
233−
234− ddata->dev = dev;
235−
236− ddata->gpio = of_get_gpio(np, 0);
237− if (ddata->gpio < 0)
238− return ddata->gpio;
239−
240− if (!gpio_is_valid(ddata->gpio))
241− return -EINVAL;
242−
243− ret = devm_gpio_request_one(dev, ddata->gpio, GPIOF_IN, "pmic");
244− if (ret < 0) {
245− dev_err(dev, "Failed to request gpio%d\n", ddata->gpio);
246− return ret;
247− }
248−
249− ddata->irq = gpio_to_irq(ddata->gpio);
250−
251− hi6421_spmi_pmic_irq_init(ddata);
252−
253− ddata->irqs = devm_kzalloc(dev, PMIC_IRQ_LIST_MAX * sizeof(int), GFP_KERNEL);
254− if (!ddata->irqs)
255− return -ENOMEM;
256−
257− ddata->domain = irq_domain_add_simple(np, PMIC_IRQ_LIST_MAX, 0,
258− &hi6421_spmi_domain_ops, ddata);
259− if (!ddata->domain) {
260− dev_err(dev, "Failed to create IRQ domain\n");
261− return -ENODEV;
262− }
263−
264− for (i = 0; i < PMIC_IRQ_LIST_MAX; i++) {
265− virq = irq_create_mapping(ddata->domain, i);
266− if (!virq) {
267− dev_err(dev, "Failed to map H/W IRQ\n");
268− return -ENODEV;
269− }
270− ddata->irqs[i] = virq;
271− }
272−
273− ret = devm_request_threaded_irq(dev,
274− ddata->irq, hi6421_spmi_irq_handler,
275− NULL,
276− IRQF_TRIGGER_LOW | IRQF_SHARED | IRQF_NO_SUSPEND,
277− "pmic", ddata);
278− if (ret < 0) {
279− dev_err(dev, "Failed to start IRQ handling thread: error %d\n",
280− ret);
281− return ret;
282− }
283−
284− dev_set_drvdata(&pdev->dev, ddata);
285−
286− ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
287− hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs),
288− NULL, 0, NULL);
289− if (ret < 0)
290− dev_err(dev, "Failed to add child devices: %d\n", ret);
291−
292− return ret;
293−}
294−
295−static const struct of_device_id pmic_spmi_id_table[] = {
296− { .compatible = "hisilicon,hi6421-spmi" },
297− { }
298−};
299−MODULE_DEVICE_TABLE(of, pmic_spmi_id_table);
300−
301−static struct spmi_driver hi6421_spmi_pmic_driver = {
302− .driver = {
303− .name = "hi6421-spmi-pmic",
304− .of_match_table = pmic_spmi_id_table,
305− },
306− .probe = hi6421_spmi_pmic_probe,
307−};
308−module_spmi_driver(hi6421_spmi_pmic_driver);
309−
310−MODULE_DESCRIPTION("HiSilicon Hi6421v600 SPMI PMIC driver");
311−MODULE_LICENSE("GPL v2");
drivers/staging/ks7010/ks7010_sdio.c+1−1
@@ -939,9 +939,9 @@ static void ks7010_private_init(struct ks_wlan_private *priv, · 938 unmodified lines
939939 memset(&priv->wstats, 0, sizeof(priv->wstats));
940940
941941 /* sleep mode */
942+ atomic_set(&priv->sleepstatus.status, 0);
942943 atomic_set(&priv->sleepstatus.doze_request, 0);
943944 atomic_set(&priv->sleepstatus.wakeup_request, 0);
944− atomic_set(&priv->sleepstatus.wakeup_request, 0);
945945
946946 trx_device_init(priv);
947947 hostif_init(priv);
drivers/staging/ks7010/ks_wlan_net.c+5−5
@@ -158,13 +158,13 @@ static int ks_wlan_get_name(struct net_device *dev, · 157 unmodified lines
158158
159159 /* for SLEEP MODE */
160160 if (priv->dev_state < DEVICE_STATE_READY)
161− strcpy(cwrq->name, "NOT READY!");
161+ strscpy(cwrq->name, "NOT READY!", sizeof(cwrq->name));
162162 else if (priv->reg.phy_type == D_11B_ONLY_MODE)
163− strcpy(cwrq->name, "IEEE 802.11b");
163+ strscpy(cwrq->name, "IEEE 802.11b", sizeof(cwrq->name));
164164 else if (priv->reg.phy_type == D_11G_ONLY_MODE)
165− strcpy(cwrq->name, "IEEE 802.11g");
165+ strscpy(cwrq->name, "IEEE 802.11g", sizeof(cwrq->name));
166166 else
167− strcpy(cwrq->name, "IEEE 802.11b/g");
167+ strscpy(cwrq->name, "IEEE 802.11b/g", sizeof(cwrq->name));
168168
169169 return 0;
170170 }
@@ -1808,8 +1808,8 @@ static int ks_wlan_get_firmware_version(struct net_device *dev, · 1637 unmodified lines
18081808 {
18091809 struct ks_wlan_private *priv = netdev_priv(dev);
18101810
1811− strcpy(extra, priv->firmware_version);
18121811 dwrq->length = priv->version_size + 1;
1812+ strscpy(extra, priv->firmware_version, dwrq->length);
18131813 return 0;
18141814 }
18151815
drivers/staging/most/video/video.c+2−2
@@ -258,7 +258,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, · 257 unmodified lines
258258 if (f->index)
259259 return -EINVAL;
260260
261− strcpy(f->description, "MPEG");
261+ strscpy(f->description, "MPEG", sizeof(f->description));
262262 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
263263 f->flags = V4L2_FMT_FLAG_COMPRESSED;
264264 f->pixelformat = V4L2_PIX_FMT_MPEG;
@@ -306,7 +306,7 @@ static int vidioc_enum_input(struct file *file, void *priv, · 41 unmodified lines
306306 if (input->index >= V4L2_CMP_MAX_INPUT)
307307 return -EINVAL;
308308
309− strcpy(input->name, "MOST Video");
309+ strscpy(input->name, "MOST Video", sizeof(input->name));
310310 input->type |= V4L2_INPUT_TYPE_CAMERA;
311311 input->audioset = 0;
312312
drivers/staging/mt7621-pci/pci-mt7621.c+11−2
@@ -56,6 +56,7 @@ · 55 unmodified lines
5656 #define PCIE_BAR_ENABLE BIT(0)
5757 #define PCIE_PORT_INT_EN(x) BIT(20 + (x))
5858 #define PCIE_PORT_LINKUP BIT(0)
59+#define PCIE_PORT_CNT 3
5960
6061 #define PERST_DELAY_MS 100
6162
@@ -388,10 +389,11 @@ static void mt7621_pcie_reset_ep_deassert(struct mt7621_pcie *pcie) · 326 unmodified lines
388389 msleep(PERST_DELAY_MS);
389390 }
390391
391−static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
392+static int mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
392393 {
393394 struct device *dev = pcie->dev;
394395 struct mt7621_pcie_port *port, *tmp;
396+ u8 num_disabled = 0;
395397 int err;
396398
397399 mt7621_pcie_reset_assert(pcie);
@@ -423,6 +425,7 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie) · 25 unmodified lines
423425 slot);
424426 mt7621_control_assert(port);
425427 port->enabled = false;
428+ num_disabled++;
426429
427430 if (slot == 0) {
428431 tmp = port;
@@ -433,6 +436,8 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie) · 4 unmodified lines
433436 phy_power_off(tmp->phy);
434437 }
435438 }
439+
440+ return (num_disabled != PCIE_PORT_CNT) ? 0 : -ENODEV;
436441 }
437442
438443 static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
@@ -540,7 +545,11 @@ static int mt7621_pci_probe(struct platform_device *pdev) · 101 unmodified lines
540545 return err;
541546 }
542547
543− mt7621_pcie_init_ports(pcie);
548+ err = mt7621_pcie_init_ports(pcie);
549+ if (err) {
550+ dev_err(dev, "Nothing connected in virtual bridges\n");
551+ return 0;
552+ }
544553
545554 err = mt7621_pcie_enable_ports(bridge);
546555 if (err) {
drivers/staging/qlge/qlge_dbg.c+2−2
@@ -733,7 +733,7 @@ int qlge_core_dump(struct qlge_adapter *qdev, struct qlge_mpi_coredump *mpi_core · 732 unmodified lines
733733 }
734734
735735 /* Insert the global header */
736− memset(&(mpi_coredump->mpi_global_header), 0,
736+ memset(&mpi_coredump->mpi_global_header, 0,
737737 sizeof(struct mpi_coredump_global_header));
738738 mpi_coredump->mpi_global_header.cookie = MPI_COREDUMP_COOKIE;
739739 mpi_coredump->mpi_global_header.header_size =
@@ -1221,7 +1221,7 @@ static void qlge_gen_reg_dump(struct qlge_adapter *qdev, · 481 unmodified lines
12211221 {
12221222 int i, status;
12231223
1224− memset(&(mpi_coredump->mpi_global_header), 0,
1224+ memset(&mpi_coredump->mpi_global_header, 0,
12251225 sizeof(struct mpi_coredump_global_header));
12261226 mpi_coredump->mpi_global_header.cookie = MPI_COREDUMP_COOKIE;
12271227 mpi_coredump->mpi_global_header.header_size =
drivers/staging/r8188eu/Kconfigrenamed from drivers/staging/rtl8188eu/Kconfig+4−3
@@ -9,14 +9,15 @@ config R8188EU · 8 unmodified lines
99 select LIB80211_CRYPT_WEP
1010 select LIB80211_CRYPT_CCMP
1111 help
12− This option adds the Realtek RTL8188EU USB device such as TP-Link TL-WN725N.
13− If built as a module, it will be called r8188eu.
12+ This option adds support for the Realtek RTL8188EU chipset, used in USB
13+ devices such as the ASUS USB-N10 Nano. This newer driver is based on GitHub
14+ sources for version v4.1.4_6773.20130222, and contains modifications for
15+ newer kernel features. If built as a module, it will be called r8188eu.
1416
1517 if R8188EU
1618
1719 config 88EU_AP_MODE
1820 bool "Realtek RTL8188EU AP mode"
19− default y
2021 help
2122 This option enables Access Point mode. Unless you know that your system
2223 will never be used as an AP, or the target system has limited memory,
drivers/staging/r8188eu/Makefile+105−0
@@ -0,0 +1,105 @@
1+SHELL := /bin/bash
2+EXTRA_CFLAGS += $(USER_EXTRA_CFLAGS)
3+EXTRA_CFLAGS += -O1
4+
5+ccflags-y += -D__CHECK_ENDIAN__
6+
7+CONFIG_BT_COEXIST = n
8+CONFIG_WOWLAN = n
9+
10+OUTSRC_FILES := \
11+ hal/HalHWImg8188E_MAC.o \
12+ hal/HalHWImg8188E_BB.o \
13+ hal/HalHWImg8188E_RF.o \
14+ hal/HalPhyRf_8188e.o \
15+ hal/HalPwrSeqCmd.o \
16+ hal/Hal8188EPwrSeq.o \
17+ hal/Hal8188ERateAdaptive.o\
18+ hal/hal_intf.o \
19+ hal/hal_com.o \
20+ hal/odm.o \
21+ hal/odm_debug.o \
22+ hal/odm_interface.o \
23+ hal/odm_HWConfig.o \
24+ hal/odm_RegConfig8188E.o\
25+ hal/odm_RTL8188E.o \
26+ hal/rtl8188e_cmd.o \
27+ hal/rtl8188e_dm.o \
28+ hal/rtl8188e_hal_init.o \
29+ hal/rtl8188e_mp.o \
30+ hal/rtl8188e_phycfg.o \
31+ hal/rtl8188e_rf6052.o \
32+ hal/rtl8188e_rxdesc.o \
33+ hal/rtl8188e_sreset.o \
34+ hal/rtl8188e_xmit.o \
35+ hal/rtl8188eu_led.o \
36+ hal/rtl8188eu_recv.o \
37+ hal/rtl8188eu_xmit.o \
38+ hal/usb_halinit.o \
39+ hal/usb_ops_linux.o
40+
41+RTL871X = rtl8188e
42+
43+HCI_NAME = usb
44+
45+_OS_INTFS_FILES := \
46+ os_dep/ioctl_linux.o \
47+ os_dep/mlme_linux.o \
48+ os_dep/os_intfs.o \
49+ os_dep/osdep_service.o \
50+ os_dep/recv_linux.o \
51+ os_dep/usb_intf.o \
52+ os_dep/usb_ops_linux.o \
53+ os_dep/xmit_linux.o
54+
55+_HAL_INTFS_FILES += $(OUTSRC_FILES)
56+
57+ifeq ($(CONFIG_BT_COEXIST), y)
58+EXTRA_CFLAGS += -DCONFIG_BT_COEXIST
59+endif
60+
61+ifeq ($(CONFIG_WOWLAN), y)
62+EXTRA_CFLAGS += -DCONFIG_WOWLAN
63+endif
64+
65+SUBARCH := $(shell uname -m | sed -e "s/i.86/i386/; s/ppc.*/powerpc/; s/armv.l/arm/; s/aarch64/arm64/;")
66+
67+ARCH ?= $(SUBARCH)
68+CROSS_COMPILE ?=
69+KVER ?= $(if $(KERNELRELEASE),$(KERNELRELEASE),$(shell uname -r))
70+KSRC ?= $(if $(KERNEL_SRC),$(KERNEL_SRC),/lib/modules/$(KVER)/build)
71+MODDESTDIR := /lib/modules/$(KVER)/kernel/drivers/net/wireless
72+INSTALL_PREFIX :=
73+
74+rtk_core := \
75+ core/rtw_ap.o \
76+ core/rtw_br_ext.o \
77+ core/rtw_cmd.o \
78+ core/rtw_debug.o \
79+ core/rtw_efuse.o \
80+ core/rtw_ieee80211.o \
81+ core/rtw_io.o \
82+ core/rtw_ioctl_set.o \
83+ core/rtw_iol.o \
84+ core/rtw_led.o \
85+ core/rtw_mlme.o \
86+ core/rtw_mlme_ext.o \
87+ core/rtw_mp.o \
88+ core/rtw_mp_ioctl.o \
89+ core/rtw_pwrctrl.o \
90+ core/rtw_p2p.o \
91+ core/rtw_recv.o \
92+ core/rtw_rf.o \
93+ core/rtw_security.o \
94+ core/rtw_sreset.o \
95+ core/rtw_sta_mgt.o \
96+ core/rtw_wlan_util.o \
97+ core/rtw_xmit.o
98+
99+r8188eu-y += $(rtk_core)
100+
101+r8188eu-y += $(_HAL_INTFS_FILES)
102+
103+r8188eu-y += $(_OS_INTFS_FILES)
104+
105+obj-$(CONFIG_R8188EU) := r8188eu.o
drivers/staging/r8188eu/TODO+16−0
@@ -0,0 +1,16 @@
1+To-do list:
2+
3+* Correct the coding style according to Linux guidelines; please read the document
4+ at https://www.kernel.org/doc/html/latest/process/coding-style.html.
5+* Remove unnecessary debugging/printing macros; for those that are still needed
6+ use the proper kernel API (pr_debug(), dev_dbg(), netdev_dbg()).
7+* Remove dead code such as unusued functions, variables, fields, etc..
8+* Use in-kernel API and remove unnecessary wrappers where possible.
9+* Fix bugs due to code that sleeps in atomic context.
10+* Remove the HAL layer and migrate its functionality into the relevant parts of
11+ the driver.
12+* Switch to use LIB80211.
13+* Switch to use MAC80211.
14+* Switch to use CFG80211.
15+* Improve the error handling of various functions, particularly those that use
16+ existing kernel APIs.
drivers/staging/r8188eu/core/rtw_ap.crenamed from drivers/staging/rtl8188eu/core/rtw_ap.c+474−289
@@ -1,18 +1,12 @@
11 // SPDX-License-Identifier: GPL-2.0
2−/******************************************************************************
3− *
4− * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5− *
6− ******************************************************************************/
7−#define _RTW_AP_C_
2+/* Copyright(c) 2007 - 2012 Realtek Corporation. */
83
9−#include <linux/ieee80211.h>
4+#define _RTW_AP_C_
105
11−#include <osdep_service.h>
12−#include <drv_types.h>
13−#include <wifi.h>
14−#include <ieee80211.h>
15−#include <asm/unaligned.h>
6+#include "../include/osdep_service.h"
7+#include "../include/drv_types.h"
8+#include "../include/wifi.h"
9+#include "../include/ieee80211.h"
1610
1711 #ifdef CONFIG_88EU_AP_MODE
1812
@@ -61,86 +55,86 @@ static void update_BCNTIM(struct adapter *padapter) · 42 unmodified lines
6155 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6256 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
6357 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
64− unsigned char *pie = pnetwork_mlmeext->ies;
65− u8 *p, *dst_ie, *premainder_ie = NULL;
66− u8 *pbackup_remainder_ie = NULL;
67− uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
58+ unsigned char *pie = pnetwork_mlmeext->IEs;
6859
6960 /* update TIM IE */
70− p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, WLAN_EID_TIM, &tim_ielen,
71− pnetwork_mlmeext->ie_length - _FIXED_IE_LENGTH_);
72− if (p && tim_ielen > 0) {
73− tim_ielen += 2;
74− premainder_ie = p + tim_ielen;
75− tim_ie_offset = (int)(p - pie);
76− remainder_ielen = pnetwork_mlmeext->ie_length -
77− tim_ie_offset - tim_ielen;
78− /* append TIM IE from dst_ie offset */
79− dst_ie = p;
80− } else {
81− tim_ielen = 0;
61+ if (true) {
62+ u8 *p, *dst_ie, *premainder_ie = NULL;
63+ u8 *pbackup_remainder_ie = NULL;
64+ __le16 tim_bitmap_le;
65+ uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
66+
67+ tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
68+
69+ p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
70+ if (p && tim_ielen > 0) {
71+ tim_ielen += 2;
72+ premainder_ie = p + tim_ielen;
73+ tim_ie_offset = (int)(p - pie);
74+ remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
75+ /* append TIM IE from dst_ie offset */
76+ dst_ie = p;
77+ } else {
78+ tim_ielen = 0;
8279
83− /* calculate head_len */
84− offset = _FIXED_IE_LENGTH_;
85− offset += pnetwork_mlmeext->ssid.ssid_length + 2;
80+ /* calculate head_len */
81+ offset = _FIXED_IE_LENGTH_;
82+ offset += pnetwork_mlmeext->Ssid.SsidLength + 2;
8683
87− /* get supported rates len */
88− p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, WLAN_EID_SUPP_RATES,
89− &tmp_len, (pnetwork_mlmeext->ie_length -
90− _BEACON_IE_OFFSET_));
91− if (p)
92− offset += tmp_len + 2;
84+ /* get supported rates len */
85+ p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
86+ if (p)
87+ offset += tmp_len + 2;
9388
94− /* DS Parameter Set IE, len = 3 */
95− offset += 3;
89+ /* DS Parameter Set IE, len = 3 */
90+ offset += 3;
9691
97− premainder_ie = pie + offset;
92+ premainder_ie = pie + offset;
9893
99− remainder_ielen = pnetwork_mlmeext->ie_length -
100− offset - tim_ielen;
94+ remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
10195
102− /* append TIM IE from offset */
103− dst_ie = pie + offset;
104− }
96+ /* append TIM IE from offset */
97+ dst_ie = pie + offset;
98+ }
10599
106− if (remainder_ielen > 0) {
107− pbackup_remainder_ie = rtw_malloc(remainder_ielen);
108− if (pbackup_remainder_ie && premainder_ie)
109− memcpy(pbackup_remainder_ie, premainder_ie,
110− remainder_ielen);
111− }
112− *dst_ie++ = WLAN_EID_TIM;
100+ if (remainder_ielen > 0) {
101+ pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
102+ if (pbackup_remainder_ie && premainder_ie)
103+ memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
104+ }
105+ *dst_ie++ = _TIM_IE_;
113106
114− if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fc))
115− tim_ielen = 5;
116− else
117− tim_ielen = 4;
107+ if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fc))
108+ tim_ielen = 5;
109+ else
110+ tim_ielen = 4;
118111
119− *dst_ie++ = tim_ielen;
112+ *dst_ie++ = tim_ielen;
120113
121− *dst_ie++ = 0;/* DTIM count */
122− *dst_ie++ = 1;/* DTIM period */
114+ *dst_ie++ = 0;/* DTIM count */
115+ *dst_ie++ = 1;/* DTIM period */
123116
124− if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
125− *dst_ie++ = BIT(0);/* bitmap ctrl */
126− else
127− *dst_ie++ = 0;
117+ if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
118+ *dst_ie++ = BIT(0);/* bitmap ctrl */
119+ else
120+ *dst_ie++ = 0;
128121
129− if (tim_ielen == 4) {
130− *dst_ie++ = pstapriv->tim_bitmap & 0xff;
131− } else if (tim_ielen == 5) {
132− put_unaligned_le16(pstapriv->tim_bitmap, dst_ie);
133− dst_ie += 2;
134− }
122+ if (tim_ielen == 4) {
123+ *dst_ie++ = *(u8 *)&tim_bitmap_le;
124+ } else if (tim_ielen == 5) {
125+ memcpy(dst_ie, &tim_bitmap_le, 2);
126+ dst_ie += 2;
127+ }
135128
136− /* copy remainder IE */
137− if (pbackup_remainder_ie) {
138− memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
129+ /* copy remainder IE */
130+ if (pbackup_remainder_ie) {
131+ memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
139132
140− kfree(pbackup_remainder_ie);
133+ kfree(pbackup_remainder_ie);
134+ }
135+ offset = (uint)(dst_ie - pie);
136+ pnetwork_mlmeext->IELength = offset + remainder_ielen;
141137 }
142− offset = (uint)(dst_ie - pie);
143− pnetwork_mlmeext->ie_length = offset + remainder_ielen;
144138
145139 set_tx_beacon_cmd(padapter);
146140 }
@@ -149,10 +143,8 @@ static u8 chk_sta_is_alive(struct sta_info *psta) · 2 unmodified lines
149143 {
150144 u8 ret = false;
151145
152− if ((psta->sta_stats.last_rx_data_pkts +
153− psta->sta_stats.last_rx_ctrl_pkts) ==
154− (psta->sta_stats.rx_data_pkts +
155− psta->sta_stats.rx_ctrl_pkts))
146+ if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) ==
147+ (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts))
156148 ;
157149 else
158150 ret = true;
@@ -162,11 +154,11 @@ static u8 chk_sta_is_alive(struct sta_info *psta) · 3 unmodified lines
162154 return ret;
163155 }
164156
165−void expire_timeout_chk(struct adapter *padapter)
157+void expire_timeout_chk(struct adapter *padapter)
166158 {
167− struct list_head *phead;
159+ struct list_head *phead, *plist;
168160 u8 updated = 0;
169− struct sta_info *psta, *temp;
161+ struct sta_info *psta = NULL;
170162 struct sta_priv *pstapriv = &padapter->stapriv;
171163 u8 chk_alive_num = 0;
172164 char chk_alive_list[NUM_STA];
@@ -175,14 +167,22 @@ void expire_timeout_chk(struct adapter *padapter) · 2 unmodified lines
175167 spin_lock_bh(&pstapriv->auth_list_lock);
176168
177169 phead = &pstapriv->auth_list;
170+ plist = phead->next;
171+
178172 /* check auth_queue */
179− list_for_each_entry_safe(psta, temp, phead, auth_list) {
173+ while (phead != plist) {
174+ psta = container_of(plist, struct sta_info, auth_list);
175+ plist = plist->next;
176+
180177 if (psta->expire_to > 0) {
181178 psta->expire_to--;
182179 if (psta->expire_to == 0) {
183180 list_del_init(&psta->auth_list);
184181 pstapriv->auth_list_cnt--;
185182
183+ DBG_88E("auth expire %6ph\n",
184+ psta->hwaddr);
185+
186186 spin_unlock_bh(&pstapriv->auth_list_lock);
187187
188188 spin_lock_bh(&pstapriv->sta_hash_lock);
@@ -192,6 +192,7 @@ void expire_timeout_chk(struct adapter *padapter) · 3 unmodified lines
192192 spin_lock_bh(&pstapriv->auth_list_lock);
193193 }
194194 }
195+
195196 }
196197 spin_unlock_bh(&pstapriv->auth_list_lock);
197198
@@ -200,8 +201,13 @@ void expire_timeout_chk(struct adapter *padapter) · 2 unmodified lines
200201 spin_lock_bh(&pstapriv->asoc_list_lock);
201202
202203 phead = &pstapriv->asoc_list;
204+ plist = phead->next;
205+
203206 /* check asoc_queue */
204− list_for_each_entry_safe(psta, temp, phead, asoc_list) {
207+ while (phead != plist) {
208+ psta = container_of(plist, struct sta_info, asoc_list);
209+ plist = plist->next;
210+
205211 if (chk_sta_is_alive(psta) || !psta->expire_to) {
206212 psta->expire_to = pstapriv->expire_to;
207213 psta->keep_alive_trycnt = 0;
@@ -220,18 +226,13 @@ void expire_timeout_chk(struct adapter *padapter) · 12 unmodified lines
220226
221227 if (psta->state & WIFI_SLEEP_STATE) {
222228 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
223− /* to check if alive by another methods
224− * if station is at ps mode.
225− */
229+ /* to check if alive by another methods if station is at ps mode. */
226230 psta->expire_to = pstapriv->expire_to;
227231 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
228232
229− /* to update bcn with tim_bitmap
230− * for this station
231− */
233+ /* to update bcn with tim_bitmap for this station */
232234 pstapriv->tim_bitmap |= BIT(psta->aid);
233− update_beacon(padapter, WLAN_EID_TIM, NULL,
234− false);
235+ update_beacon(padapter, _TIM_IE_, NULL, false);
235236
236237 if (!pmlmeext->active_keep_alive_check)
237238 continue;
@@ -240,24 +241,27 @@ void expire_timeout_chk(struct adapter *padapter) · 2 unmodified lines
240241 if (pmlmeext->active_keep_alive_check) {
241242 int stainfo_offset;
242243
243− stainfo_offset =
244− rtw_stainfo_offset(pstapriv, psta);
244+ stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
245245 if (stainfo_offset_valid(stainfo_offset))
246− chk_alive_list[chk_alive_num++] =
247− stainfo_offset;
246+ chk_alive_list[chk_alive_num++] = stainfo_offset;
248247 continue;
249248 }
250249
251250 list_del_init(&psta->asoc_list);
252251 pstapriv->asoc_list_cnt--;
253252
254− updated = ap_free_sta(padapter, psta, true,
255− WLAN_REASON_DEAUTH_LEAVING);
253+ DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state);
254+ updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
256255 } else {
257256 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
258257 if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt) &&
259− padapter->xmitpriv.free_xmitframe_cnt < (NR_XMITFRAME / pstapriv->asoc_list_cnt / 2))
258+ padapter->xmitpriv.free_xmitframe_cnt < (NR_XMITFRAME / pstapriv->asoc_list_cnt / 2)) {
259+ DBG_88E("%s sta:%pM, sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__,
260+ (psta->hwaddr), psta->sleepq_len,
261+ padapter->xmitpriv.free_xmitframe_cnt,
262+ pstapriv->asoc_list_cnt);
260263 wakeup_sta_to_xmit(padapter, psta);
264+ }
261265 }
262266 }
263267
@@ -276,34 +280,32 @@ void expire_timeout_chk(struct adapter *padapter) · 12 unmodified lines
276280 for (i = 0; i < chk_alive_num; i++) {
277281 int ret = _FAIL;
278282
279− psta = rtw_get_stainfo_by_offset(pstapriv,
280− chk_alive_list[i]);
283+ psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
281284
282− if (psta->state & WIFI_SLEEP_STATE) {
283− ret = issue_nulldata(padapter, psta->hwaddr,
284− 0, 1, 50);
285− } else {
286− ret = issue_nulldata(padapter, psta->hwaddr,
287− 0, 3, 50);
288− }
285+ if (psta->state & WIFI_SLEEP_STATE)
286+ ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
287+ else
288+ ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
289289
290290 psta->keep_alive_trycnt++;
291291 if (ret == _SUCCESS) {
292+ DBG_88E("asoc check, sta(%pM) is alive\n", (psta->hwaddr));
292293 psta->expire_to = pstapriv->expire_to;
293294 psta->keep_alive_trycnt = 0;
294295 continue;
295296 } else if (psta->keep_alive_trycnt <= 3) {
297+ DBG_88E("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
296298 psta->expire_to = 1;
297299 continue;
298300 }
299301
300302 psta->keep_alive_trycnt = 0;
301303
304+ DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state);
302305 spin_lock_bh(&pstapriv->asoc_list_lock);
303306 list_del_init(&psta->asoc_list);
304307 pstapriv->asoc_list_cnt--;
305− updated = ap_free_sta(padapter, psta, true,
306− WLAN_REASON_DEAUTH_LEAVING);
308+ updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
307309 spin_unlock_bh(&pstapriv->asoc_list_lock);
308310 }
309311
@@ -317,10 +319,14 @@ void expire_timeout_chk(struct adapter *padapter) · 7 unmodified lines
317319 void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
318320 {
319321 int i;
322+ u8 rf_type;
320323 u32 init_rate = 0;
321324 unsigned char sta_band = 0, raid, shortGIrate = false;
325+ unsigned char limit;
322326 unsigned int tx_ra_bitmap = 0;
323327 struct ht_priv *psta_ht = NULL;
328+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
329+ struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
324330
325331 if (psta)
326332 psta_ht = &psta->htpriv;
@@ -337,20 +343,31 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level) · 10 unmodified lines
337343 }
338344 /* n mode ra_bitmap */
339345 if (psta_ht->ht_option) {
340− for (i = 0; i < 8; i++)
341− if (psta_ht->ht_cap.mcs.rx_mask[0] & BIT(i))
346+ rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
347+ if (rf_type == RF_2T2R)
348+ limit = 16;/* 2R */
349+ else
350+ limit = 8;/* 1R */
351+
352+ for (i = 0; i < limit; i++) {
353+ if (psta_ht->ht_cap.mcs.rx_mask[i / 8] & BIT(i % 8))
342354 tx_ra_bitmap |= BIT(i + 12);
355+ }
343356
344357 /* max short GI rate */
345358 shortGIrate = psta_ht->sgi;
346359 }
347360
348− if (tx_ra_bitmap & 0xffff000)
349− sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
350− else if (tx_ra_bitmap & 0xff0)
351− sta_band |= WIRELESS_11G | WIRELESS_11B;
352− else
353− sta_band |= WIRELESS_11B;
361+ if (pcur_network->Configuration.DSConfig > 14) {
362+ sta_band |= WIRELESS_INVALID;
363+ } else {
364+ if (tx_ra_bitmap & 0xffff000)
365+ sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
366+ else if (tx_ra_bitmap & 0xff0)
367+ sta_band |= WIRELESS_11G | WIRELESS_11B;
368+ else
369+ sta_band |= WIRELESS_11B;
370+ }
354371
355372 psta->wireless_mode = sta_band;
356373
@@ -369,6 +386,9 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level) · 12 unmodified lines
369386
370387 tx_ra_bitmap |= ((raid << 28) & 0xf0000000);
371388
389+ DBG_88E("%s => mac_id:%d , raid:%d , bitmap = 0x%x, arg = 0x%x\n",
390+ __func__, psta->mac_id, raid, tx_ra_bitmap, arg);
391+
372392 /* bitmap[0:27] = tx_rate_bitmap */
373393 /* bitmap[28:31]= Rate Adaptive id */
374394 /* arg[0:4] = macid */
@@ -382,17 +402,19 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level) · 7 unmodified lines
382402 psta->raid = raid;
383403 psta->init_rate = init_rate;
384404
405+ } else {
406+ DBG_88E("station aid %d exceed the max number\n", psta->aid);
385407 }
386408 }
387409
388−static void update_bmc_sta(struct adapter *padapter)
410+void update_bmc_sta(struct adapter *padapter)
389411 {
390412 u32 init_rate = 0;
391413 unsigned char network_type, raid;
392414 int i, supportRateNum = 0;
393415 unsigned int tx_ra_bitmap = 0;
394416 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
395− struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
417+ struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
396418 struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
397419
398420 if (psta) {
@@ -404,14 +426,13 @@ static void update_bmc_sta(struct adapter *padapter) · 5 unmodified lines
404426
405427 psta->ieee8021x_blocked = 0;
406428
407− memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));
429+ memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
408430
409431 /* prepare for add_RATid */
410432 supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
411− network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates);
433+ network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, 1);
412434
413− memcpy(psta->bssrateset, &pcur_network->SupportedRates,
414− supportRateNum);
435+ memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
415436 psta->bssratelen = supportRateNum;
416437
417438 /* b/g mode ra_bitmap */
@@ -420,13 +441,16 @@ static void update_bmc_sta(struct adapter *padapter) · 2 unmodified lines
420441 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i] & 0x7f);
421442 }
422443
423− /* force to b mode */
424− network_type = WIRELESS_11B;
425− tx_ra_bitmap = 0xf;
444+ if (pcur_network->Configuration.DSConfig > 14) {
445+ network_type = WIRELESS_INVALID;
446+ } else {
447+ /* force to b mode */
448+ network_type = WIRELESS_11B;
449+ tx_ra_bitmap = 0xf;
450+ }
426451
427452 raid = networktype_to_raid(network_type);
428− init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) &
429− 0x3f;
453+ init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & 0x3f;
430454
431455 /* ap mode */
432456 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
@@ -437,6 +461,7 @@ static void update_bmc_sta(struct adapter *padapter) · 4 unmodified lines
437461 arg = psta->mac_id & 0x1f;
438462 arg |= BIT(7);
439463 tx_ra_bitmap |= ((raid << 28) & 0xf0000000);
464+ DBG_88E("update_bmc_sta, mask = 0x%x, arg = 0x%x\n", tx_ra_bitmap, arg);
440465
441466 /* bitmap[0:27] = tx_rate_bitmap */
442467 /* bitmap[28:31]= Rate Adaptive id */
@@ -448,12 +473,14 @@ static void update_bmc_sta(struct adapter *padapter) · 5 unmodified lines
448473 psta->raid = raid;
449474 psta->init_rate = init_rate;
450475
451− rtw_stassoc_hw_rpt(padapter, psta);
476+ rtw_sta_media_status_rpt(padapter, psta, 1);
452477
453478 spin_lock_bh(&psta->lock);
454479 psta->state = _FW_LINKED;
455480 spin_unlock_bh(&psta->lock);
456481
482+ } else {
483+ DBG_88E("add_RATid_bmc_sta error!\n");
457484 }
458485 }
459486
@@ -471,8 +498,11 @@ void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta) · 11 unmodified lines
471498 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
472499 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
473500 struct ht_priv *phtpriv_sta = &psta->htpriv;
501+ u16 sta_cap_info;
502+ u16 ap_cap_info;
474503
475504 psta->mac_id = psta->aid + 1;
505+ DBG_88E("%s\n", __func__);
476506
477507 /* ap mode */
478508 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
@@ -490,17 +520,16 @@ void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta) · 11 unmodified lines
490520 if (phtpriv_sta->ht_option) {
491521 /* check if sta supports rx ampdu */
492522 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
523+ sta_cap_info = le16_to_cpu(phtpriv_sta->ht_cap.cap_info);
524+ ap_cap_info = le16_to_cpu(phtpriv_ap->ht_cap.cap_info);
493525
494526 /* check if sta support s Short GI */
495− if (le16_to_cpu(phtpriv_sta->ht_cap.cap_info &
496− phtpriv_ap->ht_cap.cap_info) &
527+ if ((sta_cap_info & ap_cap_info) &
497528 (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40))
498529 phtpriv_sta->sgi = true;
499530
500531 /* bwmode */
501− if (le16_to_cpu(phtpriv_sta->ht_cap.cap_info &
502− phtpriv_ap->ht_cap.cap_info) &
503− IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
532+ if ((sta_cap_info & ap_cap_info) & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
504533 phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
505534 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
506535 }
@@ -522,7 +551,7 @@ void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta) · 15 unmodified lines
522551
523552 /* todo: init other variables */
524553
525− memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));
554+ memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
526555
527556 spin_lock_bh(&psta->lock);
528557 psta->state |= _FW_LINKED;
@@ -531,23 +560,32 @@ void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta) · 2 unmodified lines
531560
532561 static void update_hw_ht_param(struct adapter *padapter)
533562 {
534− u8 max_ampdu_len;
535− u8 min_mpdu_spacing;
536− struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
537− struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
563+ unsigned char max_AMPDU_len;
564+ unsigned char min_MPDU_spacing;
565+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
566+ struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
538567
539− /* handle A-MPDU parameter field
540− * ampdu_params_info [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
541− * ampdu_params_info [4:2]:Min MPDU Start Spacing
542− */
543− max_ampdu_len = pmlmeinfo->HT_caps.ampdu_params_info & 0x03;
544− min_mpdu_spacing = (pmlmeinfo->HT_caps.ampdu_params_info & 0x1c) >> 2;
568+ DBG_88E("%s\n", __func__);
569+
570+ /* handle A-MPDU parameter field */
571+ /*
572+ AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
573+ AMPDU_para [4:2]:Min MPDU Start Spacing
574+ */
575+ max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
545576
546− rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, &min_mpdu_spacing);
547− rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, &max_ampdu_len);
577+ min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
548578
549− /* Config SM Power Save setting */
550− pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->HT_caps.cap_info) & 0x0C) >> 2;
579+ rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
580+
581+ rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
582+
583+ /* */
584+ /* Config SM Power Save setting */
585+ /* */
586+ pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & 0x0C) >> 2;
587+ if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
588+ DBG_88E("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
551589 }
552590
553591 static void start_bss_network(struct adapter *padapter, u8 *pbuf)
@@ -556,27 +594,28 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) · 2 unmodified lines
556594 u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
557595 u16 bcn_interval;
558596 u32 acparm;
559− uint ie_len;
597+ int ie_len;
560598 struct registry_priv *pregpriv = &padapter->registrypriv;
561599 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
562600 struct security_priv *psecuritypriv = &padapter->securitypriv;
563− struct wlan_bssid_ex *pnetwork = &pmlmepriv->cur_network.network;
601+ struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
564602 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
565603 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
566604 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
567605 struct HT_info_element *pht_info = NULL;
606+#ifdef CONFIG_88EU_P2P
607+ struct wifidirect_info *pwdinfo = &padapter->wdinfo;
608+#endif /* CONFIG_88EU_P2P */
568609
569610 bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
570611 cur_channel = pnetwork->Configuration.DSConfig;
571612 cur_bwmode = HT_CHANNEL_WIDTH_20;
572613 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
573614
574− /* check if there is wps ie,
575− * if there is wpsie in beacon, the hostapd will update
576− * beacon twice when stating hostapd, and at first time the
577− * security ie (RSN/WPA IE) will not include in beacon.
578− */
579− if (!rtw_get_wps_ie(pnetwork->ies + _FIXED_IE_LENGTH_, pnetwork->ie_length - _FIXED_IE_LENGTH_, NULL, NULL))
615+ /* check if there is wps ie, */
616+ /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
617+ /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */
618+ if (!rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
580619 pmlmeext->bstart_bss = true;
581620
582621 /* todo: update wmm, ht cap */
@@ -589,11 +628,8 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) · 6 unmodified lines
589628 update_hw_ht_param(padapter);
590629 }
591630
592− /* setting only at first time */
593− if (!pmlmepriv->cur_network.join_res) {
594− /* WEP Key will be set before this function, do not
595− * clear CAM.
596− */
631+ if (pmlmepriv->cur_network.join_res != true) { /* setting only at first time */
632+ /* WEP Key will be set before this function, do not clear CAM. */
597633 if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) &&
598634 (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
599635 flush_all_cam_entry(padapter); /* clear CAM */
@@ -620,8 +656,7 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) · 20 unmodified lines
620656 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
621657
622658 /* Beacon Control related register */
623− rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL,
624− (u8 *)(&bcn_interval));
659+ rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
625660
626661 UpdateBrateTbl(padapter, pnetwork->SupportedRates);
627662 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
@@ -631,10 +666,7 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) · 3 unmodified lines
631666 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
632667 }
633668 /* set channel, bwmode */
634− p = rtw_get_ie(pnetwork->ies + sizeof(struct ndis_802_11_fixed_ie),
635− WLAN_EID_HT_OPERATION, &ie_len,
636− pnetwork->ie_length -
637− sizeof(struct ndis_802_11_fixed_ie));
669+ p = rtw_get_ie((pnetwork->IEs + sizeof(struct ndis_802_11_fixed_ie)), _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - sizeof(struct ndis_802_11_fixed_ie)));
638670 if (p && ie_len) {
639671 pht_info = (struct HT_info_element *)(p + 2);
640672
@@ -654,11 +686,11 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) · 13 unmodified lines
654686 }
655687 }
656688 }
657− /* TODO: need to judge the phy parameters on concurrent
658− * mode for single phy
659− */
689+ /* TODO: need to judge the phy parameters on concurrent mode for single phy */
660690 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
661691
692+ DBG_88E("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode, cur_ch_offset);
693+
662694 /* */
663695 pmlmeext->cur_channel = cur_channel;
664696 pmlmeext->cur_bwmode = cur_bwmode;
@@ -668,17 +700,23 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf) · 3 unmodified lines
668700 /* update cur_wireless_mode */
669701 update_wireless_mode(padapter);
670702
671− /* update capability after cur_wireless_mode updated */
672− update_capinfo(padapter, rtw_get_capability(pnetwork));
703+ /* udpate capability after cur_wireless_mode updated */
704+ update_capinfo(padapter, rtw_get_capability((struct wlan_bssid_ex *)pnetwork));
673705
674706 /* let pnetwork_mlmeext == pnetwork_mlme. */
675707 memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
676708
709+#ifdef CONFIG_88EU_P2P
710+ memcpy(pwdinfo->p2p_group_ssid, pnetwork->Ssid.Ssid, pnetwork->Ssid.SsidLength);
711+ pwdinfo->p2p_group_ssid_len = pnetwork->Ssid.SsidLength;
712+#endif /* CONFIG_88EU_P2P */
713+
677714 if (pmlmeext->bstart_bss) {
678− update_beacon(padapter, WLAN_EID_TIM, NULL, false);
715+ update_beacon(padapter, _TIM_IE_, NULL, false);
679716
680717 /* issue beacon frame */
681− send_beacon(padapter);
718+ if (send_beacon(padapter) == _FAIL)
719+ DBG_88E("issue_beacon, fail!\n");
682720 }
683721
684722 /* update bc/mc sta_info */
@@ -702,8 +740,8 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 17 unmodified lines
702740 struct registry_priv *pregistrypriv = &padapter->registrypriv;
703741 struct security_priv *psecuritypriv = &padapter->securitypriv;
704742 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
705− struct wlan_bssid_ex *pbss_network = &pmlmepriv->cur_network.network;
706− u8 *ie = pbss_network->ies;
743+ struct wlan_bssid_ex *pbss_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
744+ u8 *ie = pbss_network->IEs;
707745
708746 /* SSID */
709747 /* Supported rates */
@@ -716,24 +754,26 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 6 unmodified lines
716754 /* ht_capab, ht_oper */
717755 /* WPS IE */
718756
719− if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
757+ DBG_88E("%s, len =%d\n", __func__, len);
758+
759+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
720760 return _FAIL;
721761
722− if (len < 0 || len > MAX_IE_SZ)
762+ if (len > MAX_IE_SZ)
723763 return _FAIL;
724764
725− pbss_network->ie_length = len;
765+ pbss_network->IELength = len;
726766
727767 memset(ie, 0, MAX_IE_SZ);
728768
729− memcpy(ie, pbuf, pbss_network->ie_length);
769+ memcpy(ie, pbuf, pbss_network->IELength);
730770
731771 if (pbss_network->InfrastructureMode != Ndis802_11APMode)
732772 return _FAIL;
733773
734774 pbss_network->Rssi = 0;
735775
736− ether_addr_copy(pbss_network->MacAddress, myid(&padapter->eeprompriv));
776+ memcpy(pbss_network->MacAddress, myid(&padapter->eeprompriv), ETH_ALEN);
737777
738778 /* beacon interval */
739779 p = rtw_get_beacon_interval_from_ie(ie);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
@@ -743,20 +783,17 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 3 unmodified lines
743783 cap = get_unaligned_le16(ie);
744784
745785 /* SSID */
746− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_SSID, &ie_len,
747− pbss_network->ie_length - _BEACON_IE_OFFSET_);
786+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
748787 if (p && ie_len > 0) {
749− ie_len = min_t(int, ie_len, sizeof(pbss_network->ssid.ssid));
750− memset(&pbss_network->ssid, 0, sizeof(struct ndis_802_11_ssid));
751− memcpy(pbss_network->ssid.ssid, p + 2, ie_len);
752− pbss_network->ssid.ssid_length = ie_len;
788+ memset(&pbss_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
789+ memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
790+ pbss_network->Ssid.SsidLength = ie_len;
753791 }
754792
755793 /* channel */
756794 channel = 0;
757795 pbss_network->Configuration.Length = 0;
758− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_DS_PARAMS, &ie_len,
759− (pbss_network->ie_length - _BEACON_IE_OFFSET_));
796+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
760797 if (p && ie_len > 0)
761798 channel = *(p + 2);
762799
@@ -764,31 +801,25 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 1 unmodified line
764801
765802 memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
766803 /* get supported rates */
767− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_SUPP_RATES, &ie_len,
768− pbss_network->ie_length - _BEACON_IE_OFFSET_);
804+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
769805 if (p) {
770− ie_len = min_t(int, ie_len, NDIS_802_11_LENGTH_RATES_EX);
771806 memcpy(supportRate, p + 2, ie_len);
772807 supportRateNum = ie_len;
773808 }
774809
775810 /* get ext_supported rates */
776− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_EXT_SUPP_RATES,
777− &ie_len, pbss_network->ie_length - _BEACON_IE_OFFSET_);
811+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
778812 if (p) {
779− ie_len = min_t(int, ie_len,
780− NDIS_802_11_LENGTH_RATES_EX - supportRateNum);
781813 memcpy(supportRate + supportRateNum, p + 2, ie_len);
782814 supportRateNum += ie_len;
783815 }
784816
785− network_type = rtw_check_network_type(supportRate);
817+ network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
786818
787819 rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
788820
789821 /* parsing ERP_IE */
790− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_ERP_INFO, &ie_len,
791− pbss_network->ie_length - _BEACON_IE_OFFSET_);
822+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
792823 if (p && ie_len > 0)
793824 ERP_IE_handler(padapter, (struct ndis_802_11_var_ie *)p);
794825
@@ -805,8 +836,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 10 unmodified lines
805836 pairwise_cipher = 0;
806837 psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
807838 psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
808− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_RSN, &ie_len,
809− pbss_network->ie_length - _BEACON_IE_OFFSET_);
839+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
810840 if (p && ie_len > 0) {
811841 if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
812842 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
@@ -825,8 +855,8 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 12 unmodified lines
825855 psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
826856 psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
827857 for (p = ie + _BEACON_IE_OFFSET_;; p += (ie_len + 2)) {
828− p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
829− pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2));
858+ p = rtw_get_ie(p, _SSN_IE_1_, &ie_len,
859+ (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
830860 if ((p) && (!memcmp(p + 2, OUI1, 4))) {
831861 if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher,
832862 &pairwise_cipher, NULL) == _SUCCESS) {
@@ -841,7 +871,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 8 unmodified lines
841871 }
842872 break;
843873 }
844− if ((!p) || (ie_len == 0))
874+ if (!p || ie_len == 0)
845875 break;
846876 }
847877
@@ -850,17 +880,14 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 2 unmodified lines
850880 pmlmepriv->qospriv.qos_option = 0;
851881 if (pregistrypriv->wmm_enable) {
852882 for (p = ie + _BEACON_IE_OFFSET_;; p += (ie_len + 2)) {
853− p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
854− pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2));
883+ p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len,
884+ (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
855885 if ((p) && !memcmp(p + 2, WMM_PARA_IE, 6)) {
856886 pmlmepriv->qospriv.qos_option = 1;
857887
858− /* QoS Info, support U-APSD */
859− *(p + 8) |= BIT(7);
888+ *(p + 8) |= BIT(7);/* QoS Info, support U-APSD */
860889
861− /* disable all ACM bits since the WMM
862− * admission control is not supported
863− */
890+ /* disable all ACM bits since the WMM admission control is not supported */
864891 *(p + 10) &= ~BIT(4); /* BE */
865892 *(p + 14) &= ~BIT(4); /* BK */
866893 *(p + 18) &= ~BIT(4); /* VI */
@@ -868,20 +895,23 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 1 unmodified line
868895 break;
869896 }
870897
871− if ((!p) || (ie_len == 0))
898+ if (!p || ie_len == 0)
872899 break;
873900 }
874901 }
875902 /* parsing HT_CAP_IE */
876− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_HT_CAPABILITY, &ie_len,
877− pbss_network->ie_length - _BEACON_IE_OFFSET_);
903+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len,
904+ (pbss_network->IELength - _BEACON_IE_OFFSET_));
878905 if (p && ie_len > 0) {
906+ u8 rf_type;
879907 struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p + 2);
880908
881909 pHT_caps_ie = p;
882910 ht_cap = true;
883911 network_type |= WIRELESS_11_24N;
884912
913+ rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
914+
885915 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
886916 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
887917 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY & (0x07 << 2));
@@ -891,15 +921,16 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 3 unmodified lines
891921 /* set Max Rx AMPDU size to 64K */
892922 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_FACTOR & 0x03);
893923
894− pht_cap->mcs.rx_mask[0] = 0xff;
895− pht_cap->mcs.rx_mask[1] = 0x0;
896− ie_len = min_t(int, ie_len, sizeof(pmlmepriv->htpriv.ht_cap));
924+ if (rf_type == RF_1T1R) {
925+ pht_cap->mcs.rx_mask[0] = 0xff;
926+ pht_cap->mcs.rx_mask[1] = 0x0;
927+ }
897928 memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
898929 }
899930
900931 /* parsing HT_INFO_IE */
901− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_HT_OPERATION, &ie_len,
902− pbss_network->ie_length - _BEACON_IE_OFFSET_);
932+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len,
933+ (pbss_network->IELength - _BEACON_IE_OFFSET_));
903934 if (p && ie_len > 0)
904935 pHT_info_ie = p;
905936 switch (network_type) {
@@ -912,9 +943,6 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 6 unmodified lines
912943 case WIRELESS_11BG_24N:
913944 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
914945 break;
915− case WIRELESS_11A:
916− pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
917− break;
918946 default:
919947 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
920948 break;
@@ -942,7 +970,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len) · 21 unmodified lines
942970 HT_info_handler(padapter, (struct ndis_802_11_var_ie *)pHT_info_ie);
943971 }
944972
945− pbss_network->Length = get_wlan_bssid_ex_sz(pbss_network);
973+ pbss_network->Length = get_wlan_bssid_ex_sz((struct wlan_bssid_ex *)pbss_network);
946974
947975 /* issue beacon to start bss network */
948976 start_bss_network(padapter, (u8 *)pbss_network);
@@ -967,6 +995,8 @@ void rtw_set_macaddr_acl(struct adapter *padapter, int mode) · 18 unmodified lines
967995 struct sta_priv *pstapriv = &padapter->stapriv;
968996 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
969997
998+ DBG_88E("%s, mode =%d\n", __func__, mode);
999+
9701000 pacl_list->mode = mode;
9711001 }
9721002
@@ -980,18 +1010,24 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr) · 7 unmodified lines
9801010 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
9811011 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
9821012
1013+ DBG_88E("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, (addr));
1014+
9831015 if ((NUM_ACL - 1) < pacl_list->num)
9841016 return -1;
9851017
9861018 spin_lock_bh(&pacl_node_q->lock);
9871019
9881020 phead = get_list_head(pacl_node_q);
989− list_for_each(plist, phead) {
990− paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
1021+ plist = phead->next;
1022+
1023+ while (phead != plist) {
1024+ paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1025+ plist = plist->next;
9911026
9921027 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
9931028 if (paclnode->valid) {
9941029 added = true;
1030+ DBG_88E("%s, sta has been added\n", __func__);
9951031 break;
9961032 }
9971033 }
@@ -1010,7 +1046,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr) · 12 unmodified lines
10101046 if (!paclnode->valid) {
10111047 INIT_LIST_HEAD(&paclnode->list);
10121048
1013− ether_addr_copy(paclnode->addr, addr);
1049+ memcpy(paclnode->addr, addr, ETH_ALEN);
10141050
10151051 paclnode->valid = true;
10161052
@@ -1022,6 +1058,8 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr) · 5 unmodified lines
10221058 }
10231059 }
10241060
1061+ DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1062+
10251063 spin_unlock_bh(&pacl_node_q->lock);
10261064
10271065 return ret;
@@ -1029,16 +1067,24 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr) · 1 unmodified line
10291067
10301068 int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
10311069 {
1032− struct list_head *phead;
1033− struct rtw_wlan_acl_node *paclnode, *temp;
1070+ struct list_head *plist, *phead;
1071+ int ret = 0;
1072+ struct rtw_wlan_acl_node *paclnode;
10341073 struct sta_priv *pstapriv = &padapter->stapriv;
10351074 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
10361075 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
10371076
1077+ DBG_88E("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, (addr));
1078+
10381079 spin_lock_bh(&pacl_node_q->lock);
10391080
10401081 phead = get_list_head(pacl_node_q);
1041− list_for_each_entry_safe(paclnode, temp, phead, list) {
1082+ plist = phead->next;
1083+
1084+ while (phead != plist) {
1085+ paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1086+ plist = plist->next;
1087+
10421088 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
10431089 if (paclnode->valid) {
10441090 paclnode->valid = false;
@@ -1052,7 +1098,13 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr) · 7 unmodified lines
10521098
10531099 spin_unlock_bh(&pacl_node_q->lock);
10541100
1055− return 0;
1101+ DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1102+ return ret;
1103+}
1104+
1105+static void update_bcn_fixed_ie(struct adapter *padapter)
1106+{
1107+ DBG_88E("%s\n", __func__);
10561108 }
10571109
10581110 static void update_bcn_erpinfo_ie(struct adapter *padapter)
@@ -1061,24 +1113,24 @@ static void update_bcn_erpinfo_ie(struct adapter *padapter) · 2 unmodified lines
10611113 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10621114 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
10631115 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1064− unsigned char *p, *ie = pnetwork->ies;
1116+ unsigned char *p, *ie = pnetwork->IEs;
10651117 u32 len = 0;
10661118
1119+ DBG_88E("%s, ERP_enable =%d\n", __func__, pmlmeinfo->ERP_enable);
1120+
10671121 if (!pmlmeinfo->ERP_enable)
10681122 return;
10691123
10701124 /* parsing ERP_IE */
1071− p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_ERP_INFO, &len,
1072− (pnetwork->ie_length - _BEACON_IE_OFFSET_));
1125+ p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len,
1126+ (pnetwork->IELength - _BEACON_IE_OFFSET_));
10731127 if (p && len > 0) {
10741128 struct ndis_802_11_var_ie *pIE = (struct ndis_802_11_var_ie *)p;
10751129
10761130 if (pmlmepriv->num_sta_non_erp == 1)
1077− pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT |
1078− RTW_ERP_INFO_USE_PROTECTION;
1131+ pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
10791132 else
1080− pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT |
1081− RTW_ERP_INFO_USE_PROTECTION);
1133+ pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
10821134
10831135 if (pmlmepriv->num_sta_no_short_preamble > 0)
10841136 pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
@@ -1089,6 +1141,31 @@ static void update_bcn_erpinfo_ie(struct adapter *padapter) · 4 unmodified lines
10891141 }
10901142 }
10911143
1144+static void update_bcn_htcap_ie(struct adapter *padapter)
1145+{
1146+ DBG_88E("%s\n", __func__);
1147+}
1148+
1149+static void update_bcn_htinfo_ie(struct adapter *padapter)
1150+{
1151+ DBG_88E("%s\n", __func__);
1152+}
1153+
1154+static void update_bcn_rsn_ie(struct adapter *padapter)
1155+{
1156+ DBG_88E("%s\n", __func__);
1157+}
1158+
1159+static void update_bcn_wpa_ie(struct adapter *padapter)
1160+{
1161+ DBG_88E("%s\n", __func__);
1162+}
1163+
1164+static void update_bcn_wmm_ie(struct adapter *padapter)
1165+{
1166+ DBG_88E("%s\n", __func__);
1167+}
1168+
10921169 static void update_bcn_wps_ie(struct adapter *padapter)
10931170 {
10941171 u8 *pwps_ie = NULL, *pwps_ie_src;
@@ -1098,15 +1175,12 @@ static void update_bcn_wps_ie(struct adapter *padapter) · 3 unmodified lines
10981175 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
10991176 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
11001177 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1101− unsigned char *ie = pnetwork->ies;
1102− u32 ielen = pnetwork->ie_length;
1178+ unsigned char *ie = pnetwork->IEs;
1179+ u32 ielen = pnetwork->IELength;
11031180
1104− pwps_ie_src = pmlmepriv->wps_beacon_ie;
1105− if (!pwps_ie_src)
1106− return;
1181+ DBG_88E("%s\n", __func__);
11071182
1108− pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_,
1109− ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
1183+ pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
11101184
11111185 if (!pwps_ie || wps_ielen == 0)
11121186 return;
@@ -1118,31 +1192,49 @@ static void update_bcn_wps_ie(struct adapter *padapter) · 5 unmodified lines
11181192 remainder_ielen = ielen - wps_offset - wps_ielen;
11191193
11201194 if (remainder_ielen > 0) {
1121− pbackup_remainder_ie = rtw_malloc(remainder_ielen);
1195+ pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
11221196 if (pbackup_remainder_ie)
11231197 memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
11241198 }
11251199
1200+ pwps_ie_src = pmlmepriv->wps_beacon_ie;
1201+ if (!pwps_ie_src)
1202+ goto exit;
1203+
11261204 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
1127− if (wps_offset + wps_ielen + 2 + remainder_ielen <= MAX_IE_SZ) {
1205+ if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
11281206 memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
1129− pwps_ie += wps_ielen + 2;
1207+ pwps_ie += (wps_ielen + 2);
11301208
11311209 if (pbackup_remainder_ie)
11321210 memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
11331211
1134− /* update ie_length */
1135− pnetwork->ie_length = wps_offset + wps_ielen + 2 + remainder_ielen;
1212+ /* update IELength */
1213+ pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
11361214 }
11371215
1216+exit:
11381217 kfree(pbackup_remainder_ie);
11391218 }
11401219
1220+static void update_bcn_p2p_ie(struct adapter *padapter)
1221+{
1222+}
1223+
11411224 static void update_bcn_vendor_spec_ie(struct adapter *padapter, u8 *oui)
11421225 {
1226+ DBG_88E("%s\n", __func__);
11431227
1144− if (!memcmp(WPS_OUI, oui, 4))
1228+ if (!memcmp(RTW_WPA_OUI, oui, 4))
1229+ update_bcn_wpa_ie(padapter);
1230+ else if (!memcmp(WMM_OUI, oui, 4))
1231+ update_bcn_wmm_ie(padapter);
1232+ else if (!memcmp(WPS_OUI, oui, 4))
11451233 update_bcn_wps_ie(padapter);
1234+ else if (!memcmp(P2P_OUI, oui, 4))
1235+ update_bcn_p2p_ie(padapter);
1236+ else
1237+ DBG_88E("unknown OUI type!\n");
11461238 }
11471239
11481240 void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
@@ -1162,13 +1254,25 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx) · 13 unmodified lines
11621254 spin_lock_bh(&pmlmepriv->bcn_update_lock);
11631255
11641256 switch (ie_id) {
1165− case WLAN_EID_TIM:
1257+ case 0xFF:
1258+ update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1259+ break;
1260+ case _TIM_IE_:
11661261 update_BCNTIM(padapter);
11671262 break;
1168− case WLAN_EID_ERP_INFO:
1263+ case _ERPINFO_IE_:
11691264 update_bcn_erpinfo_ie(padapter);
11701265 break;
1171− case WLAN_EID_VENDOR_SPECIFIC:
1266+ case _HT_CAPABILITY_IE_:
1267+ update_bcn_htcap_ie(padapter);
1268+ break;
1269+ case _RSN_IE_2_:
1270+ update_bcn_rsn_ie(padapter);
1271+ break;
1272+ case _HT_ADD_INFO_IE_:
1273+ update_bcn_htinfo_ie(padapter);
1274+ break;
1275+ case _VENDOR_SPECIFIC_IE_:
11721276 update_bcn_vendor_spec_ie(padapter, oui);
11731277 break;
11741278 default:
@@ -1184,17 +1288,17 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx) · 9 unmodified lines
11841288 }
11851289
11861290 /*
1187− * op_mode
1188− * Set to 0 (HT pure) under the following conditions
1189− * - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1190− * - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1191− * Set to 1 (HT non-member protection) if there may be non-HT STAs
1192− * in both the primary and the secondary channel
1193− * Set to 2 if only HT STAs are associated in BSS,
1194− * however and at least one 20 MHz HT STA is associated
1195− * Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1196− * (currently non-GF HT station is considered as non-HT STA also)
1197− */
1291+op_mode
1292+Set to 0 (HT pure) under the followign conditions
1293+ - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1294+ - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1295+Set to 1 (HT non-member protection) if there may be non-HT STAs
1296+ in both the primary and the secondary channel
1297+Set to 2 if only HT STAs are associated in BSS,
1298+ however and at least one 20 MHz HT STA is associated
1299+Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1300+ (currently non-GF HT station is considered as non-HT STA also)
1301+*/
11981302 static int rtw_ht_operation_update(struct adapter *padapter)
11991303 {
12001304 u16 cur_op_mode, new_op_mode;
@@ -1205,6 +1309,9 @@ static int rtw_ht_operation_update(struct adapter *padapter) · 4 unmodified lines
12051309 if (pmlmepriv->htpriv.ht_option)
12061310 return 0;
12071311
1312+ DBG_88E("%s current operation mode = 0x%X\n",
1313+ __func__, pmlmepriv->ht_op_mode);
1314+
12081315 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
12091316 pmlmepriv->num_sta_ht_no_gf) {
12101317 pmlmepriv->ht_op_mode |=
@@ -1254,12 +1361,15 @@ static int rtw_ht_operation_update(struct adapter *padapter) · 43 unmodified lines
12541361 op_mode_changes++;
12551362 }
12561363
1364+ DBG_88E("%s new operation mode = 0x%X changes =%d\n",
1365+ __func__, pmlmepriv->ht_op_mode, op_mode_changes);
1366+
12571367 return op_mode_changes;
12581368 }
12591369
12601370 void associated_clients_update(struct adapter *padapter, u8 updated)
12611371 {
1262− /* update associated stations cap. */
1372+ /* update associcated stations cap. */
12631373 if (updated) {
12641374 struct list_head *phead, *plist;
12651375 struct sta_info *psta = NULL;
@@ -1268,9 +1378,13 @@ void associated_clients_update(struct adapter *padapter, u8 updated) · 2 unmodified lines
12681378 spin_lock_bh(&pstapriv->asoc_list_lock);
12691379
12701380 phead = &pstapriv->asoc_list;
1381+ plist = phead->next;
1382+
12711383 /* check asoc_queue */
1272− list_for_each(plist, phead) {
1273− psta = list_entry(plist, struct sta_info, asoc_list);
1384+ while (phead != plist) {
1385+ psta = container_of(plist, struct sta_info, asoc_list);
1386+
1387+ plist = plist->next;
12741388
12751389 VCS_update(padapter, psta);
12761390 }
@@ -1319,7 +1433,7 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) · 42 unmodified lines
13191433
13201434 if (pmlmepriv->num_sta_non_erp == 1) {
13211435 beacon_updated = true;
1322− update_beacon(padapter, WLAN_EID_ERP_INFO, NULL, true);
1436+ update_beacon(padapter, _ERPINFO_IE_, NULL, true);
13231437 }
13241438 }
13251439 } else {
@@ -1330,12 +1444,12 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) · 4 unmodified lines
13301444
13311445 if (pmlmepriv->num_sta_non_erp == 0) {
13321446 beacon_updated = true;
1333− update_beacon(padapter, WLAN_EID_ERP_INFO, NULL, true);
1447+ update_beacon(padapter, _ERPINFO_IE_, NULL, true);
13341448 }
13351449 }
13361450 }
13371451
1338− if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1452+ if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
13391453 if (!psta->no_short_slot_time_set) {
13401454 psta->no_short_slot_time_set = 1;
13411455
@@ -1364,6 +1478,9 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) · 22 unmodified lines
13641478 if (psta->flags & WLAN_STA_HT) {
13651479 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
13661480
1481+ DBG_88E("HT: STA %pM HT Capabilities Info: 0x%04x\n",
1482+ (psta->hwaddr), ht_capab);
1483+
13671484 if (psta->no_ht_set) {
13681485 psta->no_ht_set = 0;
13691486 pmlmepriv->num_sta_no_ht--;
@@ -1374,6 +1491,9 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) · 4 unmodified lines
13741491 psta->no_ht_gf_set = 1;
13751492 pmlmepriv->num_sta_ht_no_gf++;
13761493 }
1494+ DBG_88E("%s STA %pM - no greenfield, num of non-gf stations %d\n",
1495+ __func__, (psta->hwaddr),
1496+ pmlmepriv->num_sta_ht_no_gf);
13771497 }
13781498
13791499 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH_20_40) == 0) {
@@ -1381,21 +1501,31 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) · 1 unmodified line
13811501 psta->ht_20mhz_set = 1;
13821502 pmlmepriv->num_sta_ht_20mhz++;
13831503 }
1504+ DBG_88E("%s STA %pM - 20 MHz HT, num of 20MHz HT STAs %d\n",
1505+ __func__, (psta->hwaddr),
1506+ pmlmepriv->num_sta_ht_20mhz);
13841507 }
13851508 } else {
13861509 if (!psta->no_ht_set) {
13871510 psta->no_ht_set = 1;
13881511 pmlmepriv->num_sta_no_ht++;
13891512 }
1513+ if (pmlmepriv->htpriv.ht_option) {
1514+ DBG_88E("%s STA %pM - no HT, num of non-HT stations %d\n",
1515+ __func__, (psta->hwaddr),
1516+ pmlmepriv->num_sta_no_ht);
1517+ }
13901518 }
13911519
13921520 if (rtw_ht_operation_update(padapter) > 0) {
1393− update_beacon(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1394− update_beacon(padapter, WLAN_EID_HT_OPERATION, NULL, true);
1521+ update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
1522+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
13951523 }
13961524
1397− /* update associated stations cap. */
1525+ /* update associcated stations cap. */
13981526 associated_clients_update(padapter, beacon_updated);
1527+
1528+ DBG_88E("%s, updated =%d\n", __func__, beacon_updated);
13991529 }
14001530
14011531 u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta)
@@ -1422,7 +1552,7 @@ u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta) · 20 unmodified lines
14221552 pmlmepriv->num_sta_non_erp--;
14231553 if (pmlmepriv->num_sta_non_erp == 0) {
14241554 beacon_updated = true;
1425− update_beacon(padapter, WLAN_EID_ERP_INFO, NULL, true);
1555+ update_beacon(padapter, _ERPINFO_IE_, NULL, true);
14261556 }
14271557 }
14281558
@@ -1452,11 +1582,13 @@ u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta) · 23 unmodified lines
14521582 }
14531583
14541584 if (rtw_ht_operation_update(padapter) > 0) {
1455− update_beacon(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1456− update_beacon(padapter, WLAN_EID_HT_OPERATION, NULL, true);
1585+ update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
1586+ update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
14571587 }
14581588
1459− /* update associated stations cap. */
1589+ /* update associcated stations cap. */
1590+
1591+ DBG_88E("%s, updated =%d\n", __func__, beacon_updated);
14601592
14611593 return beacon_updated;
14621594 }
@@ -1501,22 +1633,66 @@ u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta, · 38 unmodified lines
15011633 return beacon_updated;
15021634 }
15031635
1636+int rtw_ap_inform_ch_switch(struct adapter *padapter, u8 new_ch, u8 ch_offset)
1637+{
1638+ struct list_head *phead, *plist;
1639+ int ret = 0;
1640+ struct sta_info *psta = NULL;
1641+ struct sta_priv *pstapriv = &padapter->stapriv;
1642+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1643+ struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1644+ u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1645+
1646+ if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
1647+ return ret;
1648+
1649+ DBG_88E(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
1650+ FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
1651+
1652+ spin_lock_bh(&pstapriv->asoc_list_lock);
1653+ phead = &pstapriv->asoc_list;
1654+ plist = phead->next;
1655+
1656+ /* for each sta in asoc_queue */
1657+ while (phead != plist) {
1658+ psta = container_of(plist, struct sta_info, asoc_list);
1659+ plist = plist->next;
1660+
1661+ issue_action_spct_ch_switch(padapter, psta->hwaddr, new_ch, ch_offset);
1662+ psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
1663+ }
1664+ spin_unlock_bh(&pstapriv->asoc_list_lock);
1665+
1666+ issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
1667+
1668+ return ret;
1669+}
1670+
15041671 int rtw_sta_flush(struct adapter *padapter)
15051672 {
1506− struct list_head *phead;
1507− struct sta_info *psta, *temp;
1673+ struct list_head *phead, *plist;
1674+ int ret = 0;
1675+ struct sta_info *psta = NULL;
15081676 struct sta_priv *pstapriv = &padapter->stapriv;
15091677 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
15101678 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
15111679 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
15121680
1681+ DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1682+
15131683 if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
1514− return 0;
1684+ return ret;
15151685
15161686 spin_lock_bh(&pstapriv->asoc_list_lock);
15171687 phead = &pstapriv->asoc_list;
1688+ plist = phead->next;
1689+
15181690 /* free sta asoc_queue */
1519− list_for_each_entry_safe(psta, temp, phead, asoc_list) {
1691+ while (phead != plist) {
1692+ psta = container_of(plist, struct sta_info, asoc_list);
1693+
1694+ plist = plist->next;
1695+
15201696 list_del_init(&psta->asoc_list);
15211697 pstapriv->asoc_list_cnt--;
15221698
@@ -1528,7 +1704,7 @@ int rtw_sta_flush(struct adapter *padapter) · 5 unmodified lines
15281704
15291705 associated_clients_update(padapter, true);
15301706
1531− return 0;
1707+ return ret;
15321708 }
15331709
15341710 /* called > TSR LEVEL for USB or SDIO Interface*/
@@ -1604,6 +1780,9 @@ void start_ap_mode(struct adapter *padapter) · 69 unmodified lines
16041780 pmlmepriv->wps_probe_resp_ie = NULL;
16051781 pmlmepriv->wps_assoc_resp_ie = NULL;
16061782
1783+ pmlmepriv->p2p_beacon_ie = NULL;
1784+ pmlmepriv->p2p_probe_resp_ie = NULL;
1785+
16071786 /* for ACL */
16081787 INIT_LIST_HEAD(&pacl_list->acl_node_q.queue);
16091788 pacl_list->num = 0;
@@ -1616,7 +1795,8 @@ void start_ap_mode(struct adapter *padapter) · 6 unmodified lines
16161795
16171796 void stop_ap_mode(struct adapter *padapter)
16181797 {
1619− struct rtw_wlan_acl_node *paclnode, *n;
1798+ struct list_head *phead, *plist;
1799+ struct rtw_wlan_acl_node *paclnode;
16201800 struct sta_info *psta = NULL;
16211801 struct sta_priv *pstapriv = &padapter->stapriv;
16221802 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -1627,16 +1807,19 @@ void stop_ap_mode(struct adapter *padapter) · 4 unmodified lines
16271807 pmlmepriv->update_bcn = false;
16281808 pmlmeext->bstart_bss = false;
16291809
1630− /* reset and init security priv , this can refine with
1631− * rtw_reset_securitypriv
1632− */
1810+ /* reset and init security priv , this can refine with rtw_reset_securitypriv */
16331811 memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
16341812 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
16351813 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
16361814
16371815 /* for ACL */
16381816 spin_lock_bh(&pacl_node_q->lock);
1639− list_for_each_entry_safe(paclnode, n, &pacl_node_q->queue, list) {
1817+ phead = get_list_head(pacl_node_q);
1818+ plist = phead->next;
1819+ while (phead != plist) {
1820+ paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1821+ plist = plist->next;
1822+
16401823 if (paclnode->valid) {
16411824 paclnode->valid = false;
16421825
@@ -1647,6 +1830,8 @@ void stop_ap_mode(struct adapter *padapter) · 4 unmodified lines
16471830 }
16481831 spin_unlock_bh(&pacl_node_q->lock);
16491832
1833+ DBG_88E("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num);
1834+
16501835 rtw_sta_flush(padapter);
16511836
16521837 /* free_assoc_sta_resources */
drivers/staging/r8188eu/core/rtw_br_ext.c+717−0
@@ -0,0 +1,717 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2011 Realtek Corporation. i*/
3+
4+#define _RTW_BR_EXT_C_
5+
6+#include "../include/linux/if_arp.h"
7+#include "../include/net/ip.h"
8+#include "../include/linux/atalk.h"
9+#include "../include/linux/udp.h"
10+#include "../include/linux/if_pppox.h"
11+
12+#include "../include/drv_types.h"
13+#include "../include/rtw_br_ext.h"
14+#include "../include/usb_osintf.h"
15+#include "../include/recv_osdep.h"
16+
17+#ifndef csum_ipv6_magic
18+#include "../include/net/ip6_checksum.h"
19+#endif
20+
21+#include "../include/linux/ipv6.h"
22+#include "../include/linux/icmpv6.h"
23+#include "../include/net/ndisc.h"
24+#include "../include/net/checksum.h"
25+
26+#define NAT25_IPV4 01
27+#define NAT25_IPV6 02
28+#define NAT25_IPX 03
29+#define NAT25_APPLE 04
30+#define NAT25_PPPOE 05
31+
32+#define RTL_RELAY_TAG_LEN (ETH_ALEN)
33+#define TAG_HDR_LEN 4
34+
35+#define MAGIC_CODE 0x8186
36+#define MAGIC_CODE_LEN 2
37+#define WAIT_TIME_PPPOE 5 /* waiting time for pppoe server in sec */
38+
39+/*-----------------------------------------------------------------
40+ How database records network address:
41+ 0 1 2 3 4 5 6 7 8 9 10
42+ |----|----|----|----|----|----|----|----|----|----|----|
43+ IPv4 |type| | IP addr |
44+ IPX |type| Net addr | Node addr |
45+ IPX |type| Net addr |Sckt addr|
46+ Apple |type| Network |node|
47+ PPPoE |type| SID | AC MAC |
48+-----------------------------------------------------------------*/
49+
50+/* Find a tag in pppoe frame and return the pointer */
51+static unsigned char *__nat25_find_pppoe_tag(struct pppoe_hdr *ph, unsigned short type)
52+{
53+ unsigned char *cur_ptr, *start_ptr;
54+ unsigned short tagLen, tagType;
55+
56+ start_ptr = cur_ptr = (unsigned char *)ph->tag;
57+ while ((cur_ptr - start_ptr) < ntohs(ph->length)) {
58+ /* prevent un-alignment access */
59+ tagType = (unsigned short)((cur_ptr[0] << 8) + cur_ptr[1]);
60+ tagLen = (unsigned short)((cur_ptr[2] << 8) + cur_ptr[3]);
61+ if (tagType == type)
62+ return cur_ptr;
63+ cur_ptr = cur_ptr + TAG_HDR_LEN + tagLen;
64+ }
65+ return NULL;
66+}
67+
68+static int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
69+{
70+ struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
71+ int data_len;
72+
73+ data_len = tag->tag_len + TAG_HDR_LEN;
74+ if (skb_tailroom(skb) < data_len) {
75+ _DEBUG_ERR("skb_tailroom() failed in add SID tag!\n");
76+ return -1;
77+ }
78+
79+ skb_put(skb, data_len);
80+ /* have a room for new tag */
81+ memmove(((unsigned char *)ph->tag + data_len), (unsigned char *)ph->tag, ntohs(ph->length));
82+ ph->length = htons(ntohs(ph->length) + data_len);
83+ memcpy((unsigned char *)ph->tag, tag, data_len);
84+ return data_len;
85+}
86+
87+static int skb_pull_and_merge(struct sk_buff *skb, unsigned char *src, int len)
88+{
89+ int tail_len;
90+ unsigned long end, tail;
91+
92+ if ((src+len) > skb_tail_pointer(skb) || skb->len < len)
93+ return -1;
94+
95+ tail = (unsigned long)skb_tail_pointer(skb);
96+ end = (unsigned long)src+len;
97+ if (tail < end)
98+ return -1;
99+
100+ tail_len = (int)(tail-end);
101+ if (tail_len > 0)
102+ memmove(src, src+len, tail_len);
103+
104+ skb_trim(skb, skb->len-len);
105+ return 0;
106+}
107+
108+static unsigned long __nat25_timeout(struct adapter *priv)
109+{
110+ unsigned long timeout;
111+
112+ timeout = jiffies - NAT25_AGEING_TIME*HZ;
113+
114+ return timeout;
115+}
116+
117+static int __nat25_has_expired(struct adapter *priv,
118+ struct nat25_network_db_entry *fdb)
119+{
120+ if (time_before_eq(fdb->ageing_timer, __nat25_timeout(priv)))
121+ return 1;
122+
123+ return 0;
124+}
125+
126+static void __nat25_generate_ipv4_network_addr(unsigned char *networkAddr,
127+ unsigned int *ipAddr)
128+{
129+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
130+
131+ networkAddr[0] = NAT25_IPV4;
132+ memcpy(networkAddr+7, (unsigned char *)ipAddr, 4);
133+}
134+
135+static void __nat25_generate_pppoe_network_addr(unsigned char *networkAddr,
136+ unsigned char *ac_mac, __be16 *sid)
137+{
138+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
139+
140+ networkAddr[0] = NAT25_PPPOE;
141+ memcpy(networkAddr+1, (unsigned char *)sid, 2);
142+ memcpy(networkAddr+3, (unsigned char *)ac_mac, 6);
143+}
144+
145+static void __nat25_generate_ipv6_network_addr(unsigned char *networkAddr,
146+ unsigned int *ipAddr)
147+{
148+ memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
149+
150+ networkAddr[0] = NAT25_IPV6;
151+ memcpy(networkAddr+1, (unsigned char *)ipAddr, 16);
152+}
153+
154+static unsigned char *scan_tlv(unsigned char *data, int len, unsigned char tag, unsigned char len8b)
155+{
156+ while (len > 0) {
157+ if (*data == tag && *(data+1) == len8b && len >= len8b*8)
158+ return data+2;
159+
160+ len -= (*(data+1))*8;
161+ data += (*(data+1))*8;
162+ }
163+ return NULL;
164+}
165+
166+static int update_nd_link_layer_addr(unsigned char *data, int len, unsigned char *replace_mac)
167+{
168+ struct icmp6hdr *icmphdr = (struct icmp6hdr *)data;
169+ unsigned char *mac;
170+
171+ if (icmphdr->icmp6_type == NDISC_ROUTER_SOLICITATION) {
172+ if (len >= 8) {
173+ mac = scan_tlv(&data[8], len-8, 1, 1);
174+ if (mac) {
175+ _DEBUG_INFO("Router Solicitation, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
176+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
177+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
178+ memcpy(mac, replace_mac, 6);
179+ return 1;
180+ }
181+ }
182+ } else if (icmphdr->icmp6_type == NDISC_ROUTER_ADVERTISEMENT) {
183+ if (len >= 16) {
184+ mac = scan_tlv(&data[16], len-16, 1, 1);
185+ if (mac) {
186+ _DEBUG_INFO("Router Advertisement, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
187+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
188+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
189+ memcpy(mac, replace_mac, 6);
190+ return 1;
191+ }
192+ }
193+ } else if (icmphdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
194+ if (len >= 24) {
195+ mac = scan_tlv(&data[24], len-24, 1, 1);
196+ if (mac) {
197+ _DEBUG_INFO("Neighbor Solicitation, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
198+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
199+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
200+ memcpy(mac, replace_mac, 6);
201+ return 1;
202+ }
203+ }
204+ } else if (icmphdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT) {
205+ if (len >= 24) {
206+ mac = scan_tlv(&data[24], len-24, 2, 1);
207+ if (mac) {
208+ _DEBUG_INFO("Neighbor Advertisement, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
209+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
210+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
211+ memcpy(mac, replace_mac, 6);
212+ return 1;
213+ }
214+ }
215+ } else if (icmphdr->icmp6_type == NDISC_REDIRECT) {
216+ if (len >= 40) {
217+ mac = scan_tlv(&data[40], len-40, 2, 1);
218+ if (mac) {
219+ _DEBUG_INFO("Redirect, replace MAC From: %02x:%02x:%02x:%02x:%02x:%02x, To: %02x:%02x:%02x:%02x:%02x:%02x\n",
220+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
221+ replace_mac[0], replace_mac[1], replace_mac[2], replace_mac[3], replace_mac[4], replace_mac[5]);
222+ memcpy(mac, replace_mac, 6);
223+ return 1;
224+ }
225+ }
226+ }
227+ return 0;
228+}
229+
230+static int __nat25_network_hash(unsigned char *networkAddr)
231+{
232+ if (networkAddr[0] == NAT25_IPV4) {
233+ unsigned long x;
234+
235+ x = networkAddr[7] ^ networkAddr[8] ^ networkAddr[9] ^ networkAddr[10];
236+
237+ return x & (NAT25_HASH_SIZE - 1);
238+ } else if (networkAddr[0] == NAT25_IPX) {
239+ unsigned long x;
240+
241+ x = networkAddr[1] ^ networkAddr[2] ^ networkAddr[3] ^ networkAddr[4] ^ networkAddr[5] ^
242+ networkAddr[6] ^ networkAddr[7] ^ networkAddr[8] ^ networkAddr[9] ^ networkAddr[10];
243+
244+ return x & (NAT25_HASH_SIZE - 1);
245+ } else if (networkAddr[0] == NAT25_APPLE) {
246+ unsigned long x;
247+
248+ x = networkAddr[1] ^ networkAddr[2] ^ networkAddr[3];
249+
250+ return x & (NAT25_HASH_SIZE - 1);
251+ } else if (networkAddr[0] == NAT25_PPPOE) {
252+ unsigned long x;
253+
254+ x = networkAddr[0] ^ networkAddr[1] ^ networkAddr[2] ^ networkAddr[3] ^ networkAddr[4] ^ networkAddr[5] ^ networkAddr[6] ^ networkAddr[7] ^ networkAddr[8];
255+
256+ return x & (NAT25_HASH_SIZE - 1);
257+ } else if (networkAddr[0] == NAT25_IPV6) {
258+ unsigned long x;
259+
260+ x = networkAddr[1] ^ networkAddr[2] ^ networkAddr[3] ^ networkAddr[4] ^ networkAddr[5] ^
261+ networkAddr[6] ^ networkAddr[7] ^ networkAddr[8] ^ networkAddr[9] ^ networkAddr[10] ^
262+ networkAddr[11] ^ networkAddr[12] ^ networkAddr[13] ^ networkAddr[14] ^ networkAddr[15] ^
263+ networkAddr[16];
264+
265+ return x & (NAT25_HASH_SIZE - 1);
266+ } else {
267+ unsigned long x = 0;
268+ int i;
269+
270+ for (i = 0; i < MAX_NETWORK_ADDR_LEN; i++)
271+ x ^= networkAddr[i];
272+
273+ return x & (NAT25_HASH_SIZE - 1);
274+ }
275+}
276+
277+static void __network_hash_link(struct adapter *priv,
278+ struct nat25_network_db_entry *ent, int hash)
279+{
280+ /* Caller must spin_lock already! */
281+ ent->next_hash = priv->nethash[hash];
282+ if (ent->next_hash)
283+ ent->next_hash->pprev_hash = &ent->next_hash;
284+ priv->nethash[hash] = ent;
285+ ent->pprev_hash = &priv->nethash[hash];
286+}
287+
288+static void __network_hash_unlink(struct nat25_network_db_entry *ent)
289+{
290+ /* Caller must spin_lock already! */
291+ *ent->pprev_hash = ent->next_hash;
292+ if (ent->next_hash)
293+ ent->next_hash->pprev_hash = ent->pprev_hash;
294+ ent->next_hash = NULL;
295+ ent->pprev_hash = NULL;
296+}
297+
298+static void __nat25_db_network_insert(struct adapter *priv,
299+ unsigned char *macAddr, unsigned char *networkAddr)
300+{
301+ struct nat25_network_db_entry *db;
302+ int hash;
303+
304+ spin_lock_bh(&priv->br_ext_lock);
305+ hash = __nat25_network_hash(networkAddr);
306+ db = priv->nethash[hash];
307+ while (db) {
308+ if (!memcmp(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN)) {
309+ memcpy(db->macAddr, macAddr, ETH_ALEN);
310+ db->ageing_timer = jiffies;
311+ spin_unlock_bh(&priv->br_ext_lock);
312+ return;
313+ }
314+ db = db->next_hash;
315+ }
316+ db = kmalloc(sizeof(*db), GFP_ATOMIC);
317+ if (!db) {
318+ spin_unlock_bh(&priv->br_ext_lock);
319+ return;
320+ }
321+ memcpy(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN);
322+ memcpy(db->macAddr, macAddr, ETH_ALEN);
323+ atomic_set(&db->use_count, 1);
324+ db->ageing_timer = jiffies;
325+
326+ __network_hash_link(priv, db, hash);
327+
328+ spin_unlock_bh(&priv->br_ext_lock);
329+}
330+
331+static void __nat25_db_print(struct adapter *priv)
332+{
333+}
334+
335+/*
336+ * NAT2.5 interface
337+ */
338+
339+void nat25_db_cleanup(struct adapter *priv)
340+{
341+ int i;
342+
343+ spin_lock_bh(&priv->br_ext_lock);
344+
345+ for (i = 0; i < NAT25_HASH_SIZE; i++) {
346+ struct nat25_network_db_entry *f;
347+ f = priv->nethash[i];
348+ while (f) {
349+ struct nat25_network_db_entry *g;
350+
351+ g = f->next_hash;
352+ if (priv->scdb_entry == f) {
353+ memset(priv->scdb_mac, 0, ETH_ALEN);
354+ memset(priv->scdb_ip, 0, 4);
355+ priv->scdb_entry = NULL;
356+ }
357+ __network_hash_unlink(f);
358+ kfree(f);
359+ f = g;
360+ }
361+ }
362+ spin_unlock_bh(&priv->br_ext_lock);
363+}
364+
365+void nat25_db_expire(struct adapter *priv)
366+{
367+ int i;
368+
369+ spin_lock_bh(&priv->br_ext_lock);
370+
371+ for (i = 0; i < NAT25_HASH_SIZE; i++) {
372+ struct nat25_network_db_entry *f;
373+ f = priv->nethash[i];
374+
375+ while (f) {
376+ struct nat25_network_db_entry *g;
377+ g = f->next_hash;
378+
379+ if (__nat25_has_expired(priv, f)) {
380+ if (atomic_dec_and_test(&f->use_count)) {
381+ if (priv->scdb_entry == f) {
382+ memset(priv->scdb_mac, 0, ETH_ALEN);
383+ memset(priv->scdb_ip, 0, 4);
384+ priv->scdb_entry = NULL;
385+ }
386+ __network_hash_unlink(f);
387+ kfree(f);
388+ }
389+ }
390+ f = g;
391+ }
392+ }
393+ spin_unlock_bh(&priv->br_ext_lock);
394+}
395+
396+int nat25_db_handle(struct adapter *priv, struct sk_buff *skb, int method)
397+{
398+ unsigned short protocol;
399+ unsigned char networkAddr[MAX_NETWORK_ADDR_LEN];
400+ unsigned int tmp;
401+
402+ if (!skb)
403+ return -1;
404+
405+ if ((method <= NAT25_MIN) || (method >= NAT25_MAX))
406+ return -1;
407+
408+ protocol = be16_to_cpu(*((__be16 *)(skb->data + 2 * ETH_ALEN)));
409+
410+ /*---------------------------------------------------*/
411+ /* Handle IP frame */
412+ /*---------------------------------------------------*/
413+ if (protocol == ETH_P_IP) {
414+ struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
415+
416+ if (((unsigned char *)(iph) + (iph->ihl<<2)) >= (skb->data + ETH_HLEN + skb->len)) {
417+ DEBUG_WARN("NAT25: malformed IP packet !\n");
418+ return -1;
419+ }
420+
421+ switch (method) {
422+ case NAT25_CHECK:
423+ return -1;
424+ case NAT25_INSERT:
425+ /* some multicast with source IP is all zero, maybe other case is illegal */
426+ /* in class A, B, C, host address is all zero or all one is illegal */
427+ if (iph->saddr == 0)
428+ return 0;
429+ tmp = be32_to_cpu(iph->saddr);
430+ DEBUG_INFO("NAT25: Insert IP, SA =%08x, DA =%08x\n", tmp, iph->daddr);
431+ __nat25_generate_ipv4_network_addr(networkAddr, &tmp);
432+ /* record source IP address and , source mac address into db */
433+ __nat25_db_network_insert(priv, skb->data+ETH_ALEN, networkAddr);
434+
435+ __nat25_db_print(priv);
436+ return 0;
437+ default:
438+ return -1;
439+ }
440+ } else if (protocol == ETH_P_ARP) {
441+ /*---------------------------------------------------*/
442+ /* Handle ARP frame */
443+ /*---------------------------------------------------*/
444+ struct arphdr *arp = (struct arphdr *)(skb->data + ETH_HLEN);
445+ unsigned char *arp_ptr = (unsigned char *)(arp + 1);
446+ unsigned int *sender;
447+
448+ if (arp->ar_pro != __constant_htons(ETH_P_IP)) {
449+ DEBUG_WARN("NAT25: arp protocol unknown (%4x)!\n", be16_to_cpu(arp->ar_pro));
450+ return -1;
451+ }
452+
453+ switch (method) {
454+ case NAT25_CHECK:
455+ return 0; /* skb_copy for all ARP frame */
456+ case NAT25_INSERT:
457+ DEBUG_INFO("NAT25: Insert ARP, MAC =%02x%02x%02x%02x%02x%02x\n", arp_ptr[0],
458+ arp_ptr[1], arp_ptr[2], arp_ptr[3], arp_ptr[4], arp_ptr[5]);
459+
460+ /* change to ARP sender mac address to wlan STA address */
461+ memcpy(arp_ptr, GET_MY_HWADDR(priv), ETH_ALEN);
462+ arp_ptr += arp->ar_hln;
463+ sender = (unsigned int *)arp_ptr;
464+ __nat25_generate_ipv4_network_addr(networkAddr, sender);
465+ __nat25_db_network_insert(priv, skb->data+ETH_ALEN, networkAddr);
466+ __nat25_db_print(priv);
467+ return 0;
468+ default:
469+ return -1;
470+ }
471+ } else if ((protocol == ETH_P_PPP_DISC) ||
472+ (protocol == ETH_P_PPP_SES)) {
473+ /*---------------------------------------------------*/
474+ /* Handle PPPoE frame */
475+ /*---------------------------------------------------*/
476+ struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
477+ unsigned short *pMagic;
478+
479+ switch (method) {
480+ case NAT25_CHECK:
481+ if (ph->sid == 0)
482+ return 0;
483+ return 1;
484+ case NAT25_INSERT:
485+ if (ph->sid == 0) { /* Discovery phase according to tag */
486+ if (ph->code == PADI_CODE || ph->code == PADR_CODE) {
487+ if (priv->ethBrExtInfo.addPPPoETag) {
488+ struct pppoe_tag *tag, *pOldTag;
489+ unsigned char tag_buf[40];
490+ int old_tag_len = 0;
491+
492+ tag = (struct pppoe_tag *)tag_buf;
493+ pOldTag = (struct pppoe_tag *)__nat25_find_pppoe_tag(ph, ntohs(PTT_RELAY_SID));
494+ if (pOldTag) { /* if SID existed, copy old value and delete it */
495+ old_tag_len = ntohs(pOldTag->tag_len);
496+ if (old_tag_len+TAG_HDR_LEN+MAGIC_CODE_LEN+RTL_RELAY_TAG_LEN > sizeof(tag_buf)) {
497+ DEBUG_ERR("SID tag length too long!\n");
498+ return -1;
499+ }
500+
501+ memcpy(tag->tag_data+MAGIC_CODE_LEN+RTL_RELAY_TAG_LEN,
502+ pOldTag->tag_data, old_tag_len);
503+
504+ if (skb_pull_and_merge(skb, (unsigned char *)pOldTag, TAG_HDR_LEN+old_tag_len) < 0) {
505+ DEBUG_ERR("call skb_pull_and_merge() failed in PADI/R packet!\n");
506+ return -1;
507+ }
508+ ph->length = htons(ntohs(ph->length)-TAG_HDR_LEN-old_tag_len);
509+ }
510+
511+ tag->tag_type = PTT_RELAY_SID;
512+ tag->tag_len = htons(MAGIC_CODE_LEN+RTL_RELAY_TAG_LEN+old_tag_len);
513+
514+ /* insert the magic_code+client mac in relay tag */
515+ pMagic = (unsigned short *)tag->tag_data;
516+ *pMagic = htons(MAGIC_CODE);
517+ memcpy(tag->tag_data+MAGIC_CODE_LEN, skb->data+ETH_ALEN, ETH_ALEN);
518+
519+ /* Add relay tag */
520+ if (__nat25_add_pppoe_tag(skb, tag) < 0)
521+ return -1;
522+
523+ DEBUG_INFO("NAT25: Insert PPPoE, forward %s packet\n",
524+ (ph->code == PADI_CODE ? "PADI" : "PADR"));
525+ } else { /* not add relay tag */
526+ if (priv->pppoe_connection_in_progress &&
527+ memcmp(skb->data+ETH_ALEN, priv->pppoe_addr, ETH_ALEN)) {
528+ DEBUG_ERR("Discard PPPoE packet due to another PPPoE connection is in progress!\n");
529+ return -2;
530+ }
531+
532+ if (priv->pppoe_connection_in_progress == 0)
533+ memcpy(priv->pppoe_addr, skb->data+ETH_ALEN, ETH_ALEN);
534+
535+ priv->pppoe_connection_in_progress = WAIT_TIME_PPPOE;
536+ }
537+ } else {
538+ return -1;
539+ }
540+ } else { /* session phase */
541+ DEBUG_INFO("NAT25: Insert PPPoE, insert session packet to %s\n", skb->dev->name);
542+
543+ __nat25_generate_pppoe_network_addr(networkAddr, skb->data, &ph->sid);
544+
545+ __nat25_db_network_insert(priv, skb->data+ETH_ALEN, networkAddr);
546+
547+ __nat25_db_print(priv);
548+
549+ if (!priv->ethBrExtInfo.addPPPoETag &&
550+ priv->pppoe_connection_in_progress &&
551+ !memcmp(skb->data+ETH_ALEN, priv->pppoe_addr, ETH_ALEN))
552+ priv->pppoe_connection_in_progress = 0;
553+ }
554+ return 0;
555+ default:
556+ return -1;
557+ }
558+ } else if (protocol == 0x888e) {
559+ /*---------------------------------------------------*/
560+ /* Handle EAP frame */
561+ /*---------------------------------------------------*/
562+ switch (method) {
563+ case NAT25_CHECK:
564+ return -1;
565+ case NAT25_INSERT:
566+ return 0;
567+ default:
568+ return -1;
569+ }
570+ } else if ((protocol == 0xe2ae) || (protocol == 0xe2af)) {
571+ /*---------------------------------------------------*/
572+ /* Handle C-Media proprietary frame */
573+ /*---------------------------------------------------*/
574+ switch (method) {
575+ case NAT25_CHECK:
576+ return -1;
577+ case NAT25_INSERT:
578+ return 0;
579+ default:
580+ return -1;
581+ }
582+ } else if (protocol == ETH_P_IPV6) {
583+ /*------------------------------------------------*/
584+ /* Handle IPV6 frame */
585+ /*------------------------------------------------*/
586+ struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + ETH_HLEN);
587+
588+ if (sizeof(*iph) >= (skb->len - ETH_HLEN)) {
589+ DEBUG_WARN("NAT25: malformed IPv6 packet !\n");
590+ return -1;
591+ }
592+
593+ switch (method) {
594+ case NAT25_CHECK:
595+ if (skb->data[0] & 1)
596+ return 0;
597+ return -1;
598+ case NAT25_INSERT:
599+ DEBUG_INFO("NAT25: Insert IP, SA =%4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x,"
600+ " DA =%4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x\n",
601+ iph->saddr.s6_addr16[0], iph->saddr.s6_addr16[1], iph->saddr.s6_addr16[2], iph->saddr.s6_addr16[3],
602+ iph->saddr.s6_addr16[4], iph->saddr.s6_addr16[5], iph->saddr.s6_addr16[6], iph->saddr.s6_addr16[7],
603+ iph->daddr.s6_addr16[0], iph->daddr.s6_addr16[1], iph->daddr.s6_addr16[2], iph->daddr.s6_addr16[3],
604+ iph->daddr.s6_addr16[4], iph->daddr.s6_addr16[5], iph->daddr.s6_addr16[6], iph->daddr.s6_addr16[7]);
605+
606+ if (memcmp(&iph->saddr, "\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0", 16)) {
607+ __nat25_generate_ipv6_network_addr(networkAddr, (unsigned int *)&iph->saddr);
608+ __nat25_db_network_insert(priv, skb->data+ETH_ALEN, networkAddr);
609+ __nat25_db_print(priv);
610+
611+ if (iph->nexthdr == IPPROTO_ICMPV6 &&
612+ skb->len > (ETH_HLEN + sizeof(*iph) + 4)) {
613+ if (update_nd_link_layer_addr(skb->data + ETH_HLEN + sizeof(*iph),
614+ skb->len - ETH_HLEN - sizeof(*iph), GET_MY_HWADDR(priv))) {
615+ struct icmp6hdr *hdr = (struct icmp6hdr *)(skb->data + ETH_HLEN + sizeof(*iph));
616+ hdr->icmp6_cksum = 0;
617+ hdr->icmp6_cksum = csum_ipv6_magic(&iph->saddr, &iph->daddr,
618+ iph->payload_len,
619+ IPPROTO_ICMPV6,
620+ csum_partial((__u8 *)hdr, iph->payload_len, 0));
621+ }
622+ }
623+ }
624+ return 0;
625+ default:
626+ return -1;
627+ }
628+ }
629+ return -1;
630+}
631+
632+#define SERVER_PORT 67
633+#define CLIENT_PORT 68
634+#define DHCP_MAGIC 0x63825363
635+#define BROADCAST_FLAG 0x8000
636+
637+struct dhcpMessage {
638+ u_int8_t op;
639+ u_int8_t htype;
640+ u_int8_t hlen;
641+ u_int8_t hops;
642+ u_int32_t xid;
643+ __be16 secs;
644+ __be16 flags;
645+ __be32 ciaddr;
646+ __be32 yiaddr;
647+ __be32 siaddr;
648+ __be32 giaddr;
649+ u_int8_t chaddr[16];
650+ u_int8_t sname[64];
651+ u_int8_t file[128];
652+ __be32 cookie;
653+ u_int8_t options[308]; /* 312 - cookie */
654+};
655+
656+void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
657+{
658+ if (!skb)
659+ return;
660+
661+ if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
662+ __be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
663+
664+ if (protocol == __constant_htons(ETH_P_IP)) { /* IP */
665+ struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
666+
667+ if (iph->protocol == IPPROTO_UDP) { /* UDP */
668+ struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
669+
670+ if ((udph->source == __constant_htons(CLIENT_PORT)) &&
671+ (udph->dest == __constant_htons(SERVER_PORT))) { /* DHCP request */
672+ struct dhcpMessage *dhcph =
673+ (struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
674+ u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
675+
676+ if (cookie == DHCP_MAGIC) { /* match magic word */
677+ if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
678+ /* if not broadcast */
679+ register int sum = 0;
680+
681+ DEBUG_INFO("DHCP: change flag of DHCP request to broadcast.\n");
682+ /* or BROADCAST flag */
683+ dhcph->flags |= htons(BROADCAST_FLAG);
684+ /* recalculate checksum */
685+ sum = ~(udph->check) & 0xffff;
686+ sum += be16_to_cpu(dhcph->flags);
687+ while (sum >> 16)
688+ sum = (sum & 0xffff) + (sum >> 16);
689+ udph->check = ~sum;
690+ }
691+ }
692+ }
693+ }
694+ }
695+ }
696+}
697+
698+void *scdb_findEntry(struct adapter *priv, unsigned char *macAddr,
699+ unsigned char *ipAddr)
700+{
701+ unsigned char networkAddr[MAX_NETWORK_ADDR_LEN];
702+ struct nat25_network_db_entry *db;
703+ int hash;
704+
705+ __nat25_generate_ipv4_network_addr(networkAddr, (unsigned int *)ipAddr);
706+ hash = __nat25_network_hash(networkAddr);
707+ db = priv->nethash[hash];
708+ while (db) {
709+ if (!memcmp(db->networkAddr, networkAddr, MAX_NETWORK_ADDR_LEN)) {
710+ return (void *)db;
711+ }
712+
713+ db = db->next_hash;
714+ }
715+
716+ return NULL;
717+}
drivers/staging/r8188eu/core/rtw_cmd.c+2128−0
@@ -0,0 +1,2128 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2012 Realtek Corporation. */
3+
4+#define _RTW_CMD_C_
5+
6+#include "../include/osdep_service.h"
7+#include "../include/drv_types.h"
8+#include "../include/recv_osdep.h"
9+#include "../include/mlme_osdep.h"
10+#include "../include/rtw_br_ext.h"
11+#include "../include/rtw_mlme_ext.h"
12+
13+/*
14+Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
15+No irqsave is necessary.
16+*/
17+
18+static int _rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
19+{
20+ int res = _SUCCESS;
21+
22+ sema_init(&pcmdpriv->cmd_queue_sema, 0);
23+ /* sema_init(&(pcmdpriv->cmd_done_sema), 0); */
24+ sema_init(&pcmdpriv->terminate_cmdthread_sema, 0);
25+
26+ _rtw_init_queue(&pcmdpriv->cmd_queue);
27+
28+ /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
29+
30+ pcmdpriv->cmd_seq = 1;
31+
32+ pcmdpriv->cmd_allocated_buf = kzalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ,
33+ GFP_KERNEL);
34+
35+ if (!pcmdpriv->cmd_allocated_buf) {
36+ res = _FAIL;
37+ goto exit;
38+ }
39+
40+ pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((size_t)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ - 1));
41+
42+ pcmdpriv->rsp_allocated_buf = kzalloc(MAX_RSPSZ + 4, GFP_KERNEL);
43+
44+ if (!pcmdpriv->rsp_allocated_buf) {
45+ res = _FAIL;
46+ goto exit;
47+ }
48+
49+ pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((size_t)(pcmdpriv->rsp_allocated_buf) & 3);
50+
51+ pcmdpriv->cmd_issued_cnt = 0;
52+ pcmdpriv->cmd_done_cnt = 0;
53+ pcmdpriv->rsp_cnt = 0;
54+exit:
55+
56+ return res;
57+}
58+
59+static void c2h_wk_callback(struct work_struct *work);
60+
61+static int _rtw_init_evt_priv(struct evt_priv *pevtpriv)
62+{
63+ int res = _SUCCESS;
64+
65+ /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
66+ atomic_set(&pevtpriv->event_seq, 0);
67+ pevtpriv->evt_done_cnt = 0;
68+
69+ _init_workitem(&pevtpriv->c2h_wk, c2h_wk_callback, NULL);
70+ pevtpriv->c2h_wk_alive = false;
71+ pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN + 1);
72+
73+ return res;
74+}
75+
76+void rtw_free_evt_priv(struct evt_priv *pevtpriv)
77+{
78+ _cancel_workitem_sync(&pevtpriv->c2h_wk);
79+ while (pevtpriv->c2h_wk_alive)
80+ msleep(10);
81+
82+ while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
83+ void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);
84+ if (c2h && c2h != (void *)pevtpriv)
85+ kfree(c2h);
86+ }
87+}
88+
89+static void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
90+{
91+ if (pcmdpriv) {
92+ kfree(pcmdpriv->cmd_allocated_buf);
93+ kfree(pcmdpriv->rsp_allocated_buf);
94+ }
95+}
96+
97+/*
98+Calling Context:
99+
100+rtw_enqueue_cmd can only be called between kernel thread,
101+since only spin_lock is used.
102+
103+ISR/Call-Back functions can't call this sub-function.
104+
105+*/
106+
107+static int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj)
108+{
109+ unsigned long flags;
110+
111+ if (!obj)
112+ goto exit;
113+
114+ spin_lock_irqsave(&queue->lock, flags);
115+
116+ list_add_tail(&obj->list, &queue->queue);
117+
118+ spin_unlock_irqrestore(&queue->lock, flags);
119+
120+exit:
121+
122+ return _SUCCESS;
123+}
124+
125+static struct cmd_obj *_rtw_dequeue_cmd(struct __queue *queue)
126+{
127+ struct cmd_obj *obj;
128+ unsigned long flags;
129+
130+ spin_lock_irqsave(&queue->lock, flags);
131+ if (list_empty(&queue->queue)) {
132+ obj = NULL;
133+ } else {
134+ obj = container_of((&queue->queue)->next, struct cmd_obj, list);
135+ rtw_list_delete(&obj->list);
136+ }
137+
138+ spin_unlock_irqrestore(&queue->lock, flags);
139+
140+ return obj;
141+}
142+
143+u32 rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
144+{
145+ u32 res;
146+
147+ res = _rtw_init_cmd_priv(pcmdpriv);
148+
149+ return res;
150+}
151+
152+u32 rtw_init_evt_priv(struct evt_priv *pevtpriv)
153+{
154+ int res;
155+
156+ res = _rtw_init_evt_priv(pevtpriv);
157+
158+ return res;
159+}
160+
161+void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
162+{
163+ _rtw_free_cmd_priv(pcmdpriv);
164+}
165+
166+static int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
167+{
168+ u8 bAllow = false; /* set to true to allow enqueuing cmd when hw_init_completed is false */
169+
170+ /* To decide allow or not */
171+ if ((pcmdpriv->padapter->pwrctrlpriv.bHWPwrPindetect) &&
172+ (!pcmdpriv->padapter->registrypriv.usbss_enable)) {
173+ if (cmd_obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
174+ struct drvextra_cmd_parm *pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)cmd_obj->parmbuf;
175+ if (pdrvextra_cmd_parm->ec_id == POWER_SAVING_CTRL_WK_CID)
176+ bAllow = true;
177+ }
178+ }
179+
180+ if (cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
181+ bAllow = true;
182+
183+ if ((!pcmdpriv->padapter->hw_init_completed && !bAllow) ||
184+ !pcmdpriv->cmdthd_running) /* com_thread not running */
185+ return _FAIL;
186+ return _SUCCESS;
187+}
188+
189+u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
190+{
191+ int res = _FAIL;
192+ struct adapter *padapter = pcmdpriv->padapter;
193+
194+ if (!cmd_obj)
195+ goto exit;
196+
197+ cmd_obj->padapter = padapter;
198+
199+ res = rtw_cmd_filter(pcmdpriv, cmd_obj);
200+ if (_FAIL == res) {
201+ rtw_free_cmd_obj(cmd_obj);
202+ goto exit;
203+ }
204+
205+ res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
206+
207+ if (res == _SUCCESS)
208+ up(&pcmdpriv->cmd_queue_sema);
209+
210+exit:
211+
212+ return res;
213+}
214+
215+struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv)
216+{
217+ struct cmd_obj *cmd_obj;
218+
219+ cmd_obj = _rtw_dequeue_cmd(&pcmdpriv->cmd_queue);
220+
221+ return cmd_obj;
222+}
223+
224+void rtw_cmd_clr_isr(struct cmd_priv *pcmdpriv)
225+{
226+
227+ pcmdpriv->cmd_done_cnt++;
228+ /* up(&(pcmdpriv->cmd_done_sema)); */
229+
230+}
231+
232+void rtw_free_cmd_obj(struct cmd_obj *pcmd)
233+{
234+
235+ if ((pcmd->cmdcode != _JoinBss_CMD_) && (pcmd->cmdcode != _CreateBss_CMD_)) {
236+ /* free parmbuf in cmd_obj */
237+ kfree(pcmd->parmbuf);
238+ }
239+
240+ if (pcmd->rsp) {
241+ if (pcmd->rspsz != 0) {
242+ /* free rsp in cmd_obj */
243+ kfree(pcmd->rsp);
244+ }
245+ }
246+
247+ /* free cmd_obj */
248+ kfree(pcmd);
249+
250+}
251+
252+int rtw_cmd_thread(void *context)
253+{
254+ u8 ret;
255+ struct cmd_obj *pcmd;
256+ u8 *pcmdbuf;
257+ u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf);
258+ void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd);
259+ struct adapter *padapter = (struct adapter *)context;
260+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
261+
262+ thread_enter("RTW_CMD_THREAD");
263+
264+ pcmdbuf = pcmdpriv->cmd_buf;
265+
266+ pcmdpriv->cmdthd_running = true;
267+ up(&pcmdpriv->terminate_cmdthread_sema);
268+
269+ while (1) {
270+ if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
271+ break;
272+
273+ if (padapter->bDriverStopped ||
274+ padapter->bSurpriseRemoved) {
275+ DBG_88E("%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
276+ __func__, padapter->bDriverStopped, padapter->bSurpriseRemoved, __LINE__);
277+ break;
278+ }
279+_next:
280+ if (padapter->bDriverStopped ||
281+ padapter->bSurpriseRemoved) {
282+ DBG_88E("%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
283+ __func__, padapter->bDriverStopped, padapter->bSurpriseRemoved, __LINE__);
284+ break;
285+ }
286+
287+ pcmd = rtw_dequeue_cmd(pcmdpriv);
288+ if (!pcmd)
289+ continue;
290+
291+ if (_FAIL == rtw_cmd_filter(pcmdpriv, pcmd)) {
292+ pcmd->res = H2C_DROPPED;
293+ goto post_process;
294+ }
295+
296+ pcmdpriv->cmd_issued_cnt++;
297+
298+ pcmd->cmdsz = _RND4((pcmd->cmdsz));/* _RND4 */
299+
300+ memcpy(pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
301+
302+ if (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) {
303+ cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns;
304+
305+ if (cmd_hdl) {
306+ ret = cmd_hdl(pcmd->padapter, pcmdbuf);
307+ pcmd->res = ret;
308+ }
309+
310+ pcmdpriv->cmd_seq++;
311+ } else {
312+ pcmd->res = H2C_PARAMETERS_ERROR;
313+ }
314+
315+ cmd_hdl = NULL;
316+
317+post_process:
318+
319+ /* call callback function for post-processed */
320+ if (pcmd->cmdcode < ARRAY_SIZE(rtw_cmd_callback)) {
321+ pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback;
322+ if (!pcmd_callback)
323+ rtw_free_cmd_obj(pcmd);
324+ else
325+ /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!= NULL) */
326+ pcmd_callback(pcmd->padapter, pcmd);/* need conider that free cmd_obj in rtw_cmd_callback */
327+ } else {
328+ rtw_free_cmd_obj(pcmd);
329+ }
330+
331+ flush_signals_thread();
332+
333+ goto _next;
334+ }
335+ pcmdpriv->cmdthd_running = false;
336+
337+ /* free all cmd_obj resources */
338+ do {
339+ pcmd = rtw_dequeue_cmd(pcmdpriv);
340+ if (!pcmd)
341+ break;
342+
343+ /* DBG_88E("%s: leaving... drop cmdcode:%u\n", __func__, pcmd->cmdcode); */
344+
345+ rtw_free_cmd_obj(pcmd);
346+ } while (1);
347+
348+ up(&pcmdpriv->terminate_cmdthread_sema);
349+
350+ thread_exit();
351+}
352+
353+u8 rtw_setstandby_cmd(struct adapter *padapter, uint action)
354+{
355+ struct cmd_obj *ph2c;
356+ struct usb_suspend_parm *psetusbsuspend;
357+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
358+
359+ u8 ret = _SUCCESS;
360+
361+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
362+ if (!ph2c) {
363+ ret = _FAIL;
364+ goto exit;
365+ }
366+
367+ psetusbsuspend = kzalloc(sizeof(struct usb_suspend_parm), GFP_ATOMIC);
368+ if (!psetusbsuspend) {
369+ kfree(ph2c);
370+ ret = _FAIL;
371+ goto exit;
372+ }
373+
374+ psetusbsuspend->action = action;
375+
376+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetusbsuspend, GEN_CMD_CODE(_SetUsbSuspend));
377+
378+ ret = rtw_enqueue_cmd(pcmdpriv, ph2c);
379+
380+exit:
381+
382+ return ret;
383+}
384+
385+/*
386+rtw_sitesurvey_cmd(~)
387+ ### NOTE:#### (!!!!)
388+ MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
389+*/
390+u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid, int ssid_num,
391+ struct rtw_ieee80211_channel *ch, int ch_num)
392+{
393+ u8 res = _FAIL;
394+ struct cmd_obj *ph2c;
395+ struct sitesurvey_parm *psurveyPara;
396+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
397+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
398+
399+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
400+ rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
401+ }
402+
403+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
404+ p2p_ps_wk_cmd(padapter, P2P_PS_SCAN, 1);
405+ }
406+
407+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
408+ if (!ph2c)
409+ return _FAIL;
410+
411+ psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
412+ if (!psurveyPara) {
413+ kfree(ph2c);
414+ return _FAIL;
415+ }
416+
417+ rtw_free_network_queue(padapter, false);
418+
419+ init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
420+
421+ /* psurveyPara->bsslimit = 48; */
422+ psurveyPara->scan_mode = pmlmepriv->scan_mode;
423+
424+ /* prepare ssid list */
425+ if (ssid) {
426+ int i;
427+ for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
428+ if (ssid[i].SsidLength) {
429+ memcpy(&psurveyPara->ssid[i], &ssid[i], sizeof(struct ndis_802_11_ssid));
430+ psurveyPara->ssid_num++;
431+ }
432+ }
433+ }
434+
435+ /* prepare channel list */
436+ if (ch) {
437+ int i;
438+ for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
439+ if (ch[i].hw_value && !(ch[i].flags & RTW_IEEE80211_CHAN_DISABLED)) {
440+ memcpy(&psurveyPara->ch[i], &ch[i], sizeof(struct rtw_ieee80211_channel));
441+ psurveyPara->ch_num++;
442+ }
443+ }
444+ }
445+
446+ set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
447+
448+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
449+
450+ if (res == _SUCCESS) {
451+ pmlmepriv->scan_start_time = jiffies;
452+
453+ _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT);
454+
455+ rtw_led_control(padapter, LED_CTL_SITE_SURVEY);
456+
457+ pmlmepriv->scan_interval = SCAN_INTERVAL;/* 30*2 sec = 60sec */
458+ } else {
459+ _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
460+ }
461+
462+ return res;
463+}
464+
465+u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset)
466+{
467+ struct cmd_obj *ph2c;
468+ struct setdatarate_parm *pbsetdataratepara;
469+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
470+ u8 res = _SUCCESS;
471+
472+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
473+ if (!ph2c) {
474+ res = _FAIL;
475+ goto exit;
476+ }
477+
478+ pbsetdataratepara = kzalloc(sizeof(struct setdatarate_parm), GFP_ATOMIC);
479+ if (!pbsetdataratepara) {
480+ kfree(ph2c);
481+ res = _FAIL;
482+ goto exit;
483+ }
484+
485+ init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara, GEN_CMD_CODE(_SetDataRate));
486+ pbsetdataratepara->mac_id = 5;
487+ memcpy(pbsetdataratepara->datarates, rateset, NumRates);
488+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
489+exit:
490+
491+ return res;
492+}
493+
494+u8 rtw_setbasicrate_cmd(struct adapter *padapter, u8 *rateset)
495+{
496+ struct cmd_obj *ph2c;
497+ struct setbasicrate_parm *pssetbasicratepara;
498+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
499+ u8 res = _SUCCESS;
500+
501+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
502+ if (!ph2c) {
503+ res = _FAIL;
504+ goto exit;
505+ }
506+ pssetbasicratepara = kzalloc(sizeof(struct setbasicrate_parm), GFP_ATOMIC);
507+
508+ if (!pssetbasicratepara) {
509+ kfree(ph2c);
510+ res = _FAIL;
511+ goto exit;
512+ }
513+
514+ init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara, _SetBasicRate_CMD_);
515+
516+ memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
517+
518+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
519+exit:
520+
521+ return res;
522+}
523+
524+/*
525+unsigned char rtw_setphy_cmd(unsigned char *adapter)
526+
527+1. be called only after rtw_update_registrypriv_dev_network(~) or mp testing program
528+2. for AdHoc/Ap mode or mp mode?
529+
530+*/
531+u8 rtw_setphy_cmd(struct adapter *padapter, u8 modem, u8 ch)
532+{
533+ struct cmd_obj *ph2c;
534+ struct setphy_parm *psetphypara;
535+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
536+ u8 res = _SUCCESS;
537+
538+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
539+ if (!ph2c) {
540+ res = _FAIL;
541+ goto exit;
542+ }
543+ psetphypara = kzalloc(sizeof(struct setphy_parm), GFP_ATOMIC);
544+
545+ if (!psetphypara) {
546+ kfree(ph2c);
547+ res = _FAIL;
548+ goto exit;
549+ }
550+
551+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetphypara, _SetPhy_CMD_);
552+
553+ psetphypara->modem = modem;
554+ psetphypara->rfchannel = ch;
555+
556+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
557+exit:
558+
559+ return res;
560+}
561+
562+u8 rtw_setbbreg_cmd(struct adapter *padapter, u8 offset, u8 val)
563+{
564+ struct cmd_obj *ph2c;
565+ struct writeBB_parm *pwritebbparm;
566+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
567+ u8 res = _SUCCESS;
568+
569+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
570+ if (!ph2c) {
571+ res = _FAIL;
572+ goto exit;
573+ }
574+ pwritebbparm = kzalloc(sizeof(struct writeBB_parm), GFP_ATOMIC);
575+
576+ if (!pwritebbparm) {
577+ kfree(ph2c);
578+ res = _FAIL;
579+ goto exit;
580+ }
581+
582+ init_h2fwcmd_w_parm_no_rsp(ph2c, pwritebbparm, GEN_CMD_CODE(_SetBBReg));
583+
584+ pwritebbparm->offset = offset;
585+ pwritebbparm->value = val;
586+
587+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
588+exit:
589+
590+ return res;
591+}
592+
593+u8 rtw_getbbreg_cmd(struct adapter *padapter, u8 offset, u8 *pval)
594+{
595+ struct cmd_obj *ph2c;
596+ struct readBB_parm *prdbbparm;
597+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
598+ u8 res = _SUCCESS;
599+
600+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
601+ if (!ph2c) {
602+ res = _FAIL;
603+ goto exit;
604+ }
605+ prdbbparm = kzalloc(sizeof(struct readBB_parm), GFP_ATOMIC);
606+
607+ if (!prdbbparm) {
608+ kfree(ph2c);
609+ return _FAIL;
610+ }
611+
612+ INIT_LIST_HEAD(&ph2c->list);
613+ ph2c->cmdcode = GEN_CMD_CODE(_GetBBReg);
614+ ph2c->parmbuf = (unsigned char *)prdbbparm;
615+ ph2c->cmdsz = sizeof(struct readBB_parm);
616+ ph2c->rsp = pval;
617+ ph2c->rspsz = sizeof(struct readBB_rsp);
618+
619+ prdbbparm->offset = offset;
620+
621+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
622+exit:
623+
624+ return res;
625+}
626+
627+u8 rtw_setrfreg_cmd(struct adapter *padapter, u8 offset, u32 val)
628+{
629+ struct cmd_obj *ph2c;
630+ struct writeRF_parm *pwriterfparm;
631+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
632+ u8 res = _SUCCESS;
633+
634+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
635+ if (!ph2c) {
636+ res = _FAIL;
637+ goto exit;
638+ }
639+ pwriterfparm = kzalloc(sizeof(struct writeRF_parm), GFP_ATOMIC);
640+
641+ if (!pwriterfparm) {
642+ kfree(ph2c);
643+ res = _FAIL;
644+ goto exit;
645+ }
646+
647+ init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
648+
649+ pwriterfparm->offset = offset;
650+ pwriterfparm->value = val;
651+
652+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
653+exit:
654+
655+ return res;
656+}
657+
658+u8 rtw_getrfreg_cmd(struct adapter *padapter, u8 offset, u8 *pval)
659+{
660+ struct cmd_obj *ph2c;
661+ struct readRF_parm *prdrfparm;
662+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
663+ u8 res = _SUCCESS;
664+
665+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
666+ if (!ph2c) {
667+ res = _FAIL;
668+ goto exit;
669+ }
670+
671+ prdrfparm = kzalloc(sizeof(struct readRF_parm), GFP_ATOMIC);
672+ if (!prdrfparm) {
673+ kfree(ph2c);
674+ res = _FAIL;
675+ goto exit;
676+ }
677+
678+ INIT_LIST_HEAD(&ph2c->list);
679+ ph2c->cmdcode = GEN_CMD_CODE(_GetRFReg);
680+ ph2c->parmbuf = (unsigned char *)prdrfparm;
681+ ph2c->cmdsz = sizeof(struct readRF_parm);
682+ ph2c->rsp = pval;
683+ ph2c->rspsz = sizeof(struct readRF_rsp);
684+
685+ prdrfparm->offset = offset;
686+
687+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
688+
689+exit:
690+
691+ return res;
692+}
693+
694+void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
695+{
696+
697+
698+ kfree(pcmd->parmbuf);
699+ kfree(pcmd);
700+
701+ if (padapter->registrypriv.mp_mode == 1)
702+ padapter->mppriv.workparam.bcompleted = true;
703+
704+}
705+
706+void rtw_readtssi_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
707+{
708+
709+
710+ kfree(pcmd->parmbuf);
711+ kfree(pcmd);
712+
713+ if (padapter->registrypriv.mp_mode == 1)
714+ padapter->mppriv.workparam.bcompleted = true;
715+
716+}
717+
718+u8 rtw_createbss_cmd(struct adapter *padapter)
719+{
720+ struct cmd_obj *pcmd;
721+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
722+ struct wlan_bssid_ex *pdev_network = &padapter->registrypriv.dev_network;
723+ u8 res = _SUCCESS;
724+
725+ rtw_led_control(padapter, LED_CTL_START_TO_LINK);
726+
727+ pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
728+ if (!pcmd) {
729+ res = _FAIL;
730+ goto exit;
731+ }
732+
733+ INIT_LIST_HEAD(&pcmd->list);
734+ pcmd->cmdcode = _CreateBss_CMD_;
735+ pcmd->parmbuf = (unsigned char *)pdev_network;
736+ pcmd->cmdsz = get_wlan_bssid_ex_sz((struct wlan_bssid_ex *)pdev_network);
737+ pcmd->rsp = NULL;
738+ pcmd->rspsz = 0;
739+ pdev_network->Length = pcmd->cmdsz;
740+ res = rtw_enqueue_cmd(pcmdpriv, pcmd);
741+exit:
742+
743+ return res;
744+}
745+
746+u8 rtw_createbss_cmd_ex(struct adapter *padapter, unsigned char *pbss, unsigned int sz)
747+{
748+ struct cmd_obj *pcmd;
749+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
750+ u8 res = _SUCCESS;
751+
752+ pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
753+ if (!pcmd) {
754+ res = _FAIL;
755+ goto exit;
756+ }
757+
758+ INIT_LIST_HEAD(&pcmd->list);
759+ pcmd->cmdcode = GEN_CMD_CODE(_CreateBss);
760+ pcmd->parmbuf = pbss;
761+ pcmd->cmdsz = sz;
762+ pcmd->rsp = NULL;
763+ pcmd->rspsz = 0;
764+
765+ res = rtw_enqueue_cmd(pcmdpriv, pcmd);
766+
767+exit:
768+
769+ return res;
770+}
771+
772+u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
773+{
774+ u8 res = _SUCCESS;
775+ uint t_len = 0;
776+ struct wlan_bssid_ex *psecnetwork;
777+ struct cmd_obj *pcmd;
778+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
779+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
780+ struct qos_priv *pqospriv = &pmlmepriv->qospriv;
781+ struct security_priv *psecuritypriv = &padapter->securitypriv;
782+ struct registry_priv *pregistrypriv = &padapter->registrypriv;
783+ struct ht_priv *phtpriv = &pmlmepriv->htpriv;
784+ enum ndis_802_11_network_infra ndis_network_mode = pnetwork->network.InfrastructureMode;
785+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
786+ struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
787+
788+ rtw_led_control(padapter, LED_CTL_START_TO_LINK);
789+
790+ pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
791+ if (!pcmd) {
792+ res = _FAIL;
793+ goto exit;
794+ }
795+ /* for IEs is fix buf size */
796+ t_len = sizeof(struct wlan_bssid_ex);
797+
798+ /* for hidden ap to set fw_state here */
799+ if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE)) {
800+ switch (ndis_network_mode) {
801+ case Ndis802_11IBSS:
802+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
803+ break;
804+ case Ndis802_11Infrastructure:
805+ set_fwstate(pmlmepriv, WIFI_STATION_STATE);
806+ break;
807+ case Ndis802_11APMode:
808+ case Ndis802_11AutoUnknown:
809+ case Ndis802_11InfrastructureMax:
810+ break;
811+ }
812+ }
813+
814+ psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss;
815+ if (!psecnetwork) {
816+ kfree(pcmd);
817+ res = _FAIL;
818+ goto exit;
819+ }
820+
821+ memset(psecnetwork, 0, t_len);
822+
823+ memcpy(psecnetwork, &pnetwork->network, get_wlan_bssid_ex_sz(&pnetwork->network));
824+
825+ psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength;
826+
827+ if (psecnetwork->IELength - 12 < 255) {
828+ memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], psecnetwork->IELength - 12);
829+ } else {
830+ memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], 255);
831+ }
832+
833+ psecnetwork->IELength = 0;
834+ /* Added by Albert 2009/02/18 */
835+ /* If the the driver wants to use the bssid to create the connection. */
836+ /* If not, we have to copy the connecting AP's MAC address to it so that */
837+ /* the driver just has the bssid information for PMKIDList searching. */
838+
839+ if (!pmlmepriv->assoc_by_bssid)
840+ memcpy(&pmlmepriv->assoc_bssid[0], &pnetwork->network.MacAddress[0], ETH_ALEN);
841+
842+ psecnetwork->IELength = rtw_restruct_sec_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0], pnetwork->network.IELength);
843+
844+ pqospriv->qos_option = 0;
845+
846+ if (pregistrypriv->wmm_enable) {
847+ u32 tmp_len;
848+
849+ tmp_len = rtw_restruct_wmm_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0], pnetwork->network.IELength, psecnetwork->IELength);
850+
851+ if (psecnetwork->IELength != tmp_len) {
852+ psecnetwork->IELength = tmp_len;
853+ pqospriv->qos_option = 1; /* There is WMM IE in this corresp. beacon */
854+ } else {
855+ pqospriv->qos_option = 0;/* There is no WMM IE in this corresp. beacon */
856+ }
857+ }
858+
859+ phtpriv->ht_option = false;
860+ if (pregistrypriv->ht_enable) {
861+ /* Added by Albert 2010/06/23 */
862+ /* For the WEP mode, we will use the bg mode to do the connection to avoid some IOT issue. */
863+ /* Especially for Realtek 8192u SoftAP. */
864+ if ((padapter->securitypriv.dot11PrivacyAlgrthm != _WEP40_) &&
865+ (padapter->securitypriv.dot11PrivacyAlgrthm != _WEP104_) &&
866+ (padapter->securitypriv.dot11PrivacyAlgrthm != _TKIP_)) {
867+ /* rtw_restructure_ht_ie */
868+ rtw_restructure_ht_ie(padapter, &pnetwork->network.IEs[0], &psecnetwork->IEs[0],
869+ pnetwork->network.IELength, &psecnetwork->IELength);
870+ }
871+ }
872+
873+ pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->network.IEs, pnetwork->network.IELength);
874+
875+ if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_TENDA)
876+ padapter->pwrctrlpriv.smart_ps = 0;
877+ else
878+ padapter->pwrctrlpriv.smart_ps = padapter->registrypriv.smart_ps;
879+
880+ DBG_88E("%s: smart_ps =%d\n", __func__, padapter->pwrctrlpriv.smart_ps);
881+
882+ pcmd->cmdsz = get_wlan_bssid_ex_sz(psecnetwork);/* get cmdsz before endian conversion */
883+
884+ INIT_LIST_HEAD(&pcmd->list);
885+ pcmd->cmdcode = _JoinBss_CMD_;/* GEN_CMD_CODE(_JoinBss) */
886+ pcmd->parmbuf = (unsigned char *)psecnetwork;
887+ pcmd->rsp = NULL;
888+ pcmd->rspsz = 0;
889+
890+ res = rtw_enqueue_cmd(pcmdpriv, pcmd);
891+
892+exit:
893+
894+ return res;
895+}
896+
897+u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueue) /* for sta_mode */
898+{
899+ struct cmd_obj *cmdobj = NULL;
900+ struct disconnect_parm *param = NULL;
901+ struct cmd_priv *cmdpriv = &padapter->cmdpriv;
902+ u8 res = _SUCCESS;
903+
904+ /* prepare cmd parameter */
905+ param = kzalloc(sizeof(*param), GFP_ATOMIC);
906+ if (!param) {
907+ res = _FAIL;
908+ goto exit;
909+ }
910+ param->deauth_timeout_ms = deauth_timeout_ms;
911+
912+ if (enqueue) {
913+ /* need enqueue, prepare cmd_obj and enqueue */
914+ cmdobj = kzalloc(sizeof(*cmdobj), GFP_ATOMIC);
915+ if (!cmdobj) {
916+ res = _FAIL;
917+ kfree(param);
918+ goto exit;
919+ }
920+ init_h2fwcmd_w_parm_no_rsp(cmdobj, param, _DisConnect_CMD_);
921+ res = rtw_enqueue_cmd(cmdpriv, cmdobj);
922+ } else {
923+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
924+ if (H2C_SUCCESS != disconnect_hdl(padapter, (u8 *)param))
925+ res = _FAIL;
926+ kfree(param);
927+ }
928+
929+exit:
930+
931+ return res;
932+}
933+
934+u8 rtw_setopmode_cmd(struct adapter *padapter, enum ndis_802_11_network_infra networktype)
935+{
936+ struct cmd_obj *ph2c;
937+ struct setopmode_parm *psetop;
938+
939+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
940+ u8 res = _SUCCESS;
941+
942+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
943+ if (!ph2c) {
944+ res = false;
945+ goto exit;
946+ }
947+ psetop = kzalloc(sizeof(struct setopmode_parm), GFP_KERNEL);
948+
949+ if (!psetop) {
950+ kfree(ph2c);
951+ res = false;
952+ goto exit;
953+ }
954+
955+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
956+ psetop->mode = (u8)networktype;
957+
958+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
959+
960+exit:
961+
962+ return res;
963+}
964+
965+u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key)
966+{
967+ struct cmd_obj *ph2c;
968+ struct set_stakey_parm *psetstakey_para;
969+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
970+ struct set_stakey_rsp *psetstakey_rsp = NULL;
971+
972+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
973+ struct security_priv *psecuritypriv = &padapter->securitypriv;
974+ struct sta_info *sta = (struct sta_info *)psta;
975+ u8 res = _SUCCESS;
976+
977+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
978+ if (!ph2c) {
979+ res = _FAIL;
980+ goto exit;
981+ }
982+
983+ psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL);
984+ if (!psetstakey_para) {
985+ kfree(ph2c);
986+ res = _FAIL;
987+ goto exit;
988+ }
989+
990+ psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_KERNEL);
991+ if (!psetstakey_rsp) {
992+ kfree(ph2c);
993+ kfree(psetstakey_para);
994+ res = _FAIL;
995+ goto exit;
996+ }
997+
998+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
999+ ph2c->rsp = (u8 *)psetstakey_rsp;
1000+ ph2c->rspsz = sizeof(struct set_stakey_rsp);
1001+
1002+ memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
1003+
1004+ if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
1005+ psetstakey_para->algorithm = (unsigned char)psecuritypriv->dot11PrivacyAlgrthm;
1006+ else
1007+ GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false);
1008+
1009+ if (unicast_key)
1010+ memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
1011+ else
1012+ memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16);
1013+
1014+ /* jeff: set this because at least sw key is ready */
1015+ padapter->securitypriv.busetkipkey = true;
1016+
1017+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1018+
1019+exit:
1020+
1021+ return res;
1022+}
1023+
1024+u8 rtw_clearstakey_cmd(struct adapter *padapter, u8 *psta, u8 entry, u8 enqueue)
1025+{
1026+ struct cmd_obj *ph2c;
1027+ struct set_stakey_parm *psetstakey_para;
1028+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1029+ struct set_stakey_rsp *psetstakey_rsp = NULL;
1030+ struct sta_info *sta = (struct sta_info *)psta;
1031+ u8 res = _SUCCESS;
1032+
1033+ if (!enqueue) {
1034+ clear_cam_entry(padapter, entry);
1035+ } else {
1036+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1037+ if (!ph2c) {
1038+ res = _FAIL;
1039+ goto exit;
1040+ }
1041+
1042+ psetstakey_para = kzalloc(sizeof(struct set_stakey_parm),
1043+ GFP_ATOMIC);
1044+ if (!psetstakey_para) {
1045+ kfree(ph2c);
1046+ res = _FAIL;
1047+ goto exit;
1048+ }
1049+
1050+ psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp),
1051+ GFP_ATOMIC);
1052+ if (!psetstakey_rsp) {
1053+ kfree(ph2c);
1054+ kfree(psetstakey_para);
1055+ res = _FAIL;
1056+ goto exit;
1057+ }
1058+
1059+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
1060+ ph2c->rsp = (u8 *)psetstakey_rsp;
1061+ ph2c->rspsz = sizeof(struct set_stakey_rsp);
1062+
1063+ memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
1064+
1065+ psetstakey_para->algorithm = _NO_PRIVACY_;
1066+
1067+ psetstakey_para->id = entry;
1068+
1069+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1070+ }
1071+exit:
1072+
1073+ return res;
1074+}
1075+
1076+u8 rtw_setrttbl_cmd(struct adapter *padapter, struct setratable_parm *prate_table)
1077+{
1078+ struct cmd_obj *ph2c;
1079+ struct setratable_parm *psetrttblparm;
1080+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1081+ u8 res = _SUCCESS;
1082+
1083+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
1084+ if (!ph2c) {
1085+ res = _FAIL;
1086+ goto exit;
1087+ }
1088+ psetrttblparm = kzalloc(sizeof(struct setratable_parm), GFP_KERNEL);
1089+
1090+ if (!psetrttblparm) {
1091+ kfree(ph2c);
1092+ res = _FAIL;
1093+ goto exit;
1094+ }
1095+
1096+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable));
1097+
1098+ memcpy(psetrttblparm, prate_table, sizeof(struct setratable_parm));
1099+
1100+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1101+exit:
1102+
1103+ return res;
1104+}
1105+
1106+u8 rtw_getrttbl_cmd(struct adapter *padapter, struct getratable_rsp *pval)
1107+{
1108+ struct cmd_obj *ph2c;
1109+ struct getratable_parm *pgetrttblparm;
1110+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1111+ u8 res = _SUCCESS;
1112+
1113+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
1114+ if (!ph2c) {
1115+ res = _FAIL;
1116+ goto exit;
1117+ }
1118+ pgetrttblparm = kzalloc(sizeof(struct getratable_parm), GFP_KERNEL);
1119+
1120+ if (!pgetrttblparm) {
1121+ kfree(ph2c);
1122+ res = _FAIL;
1123+ goto exit;
1124+ }
1125+
1126+/* init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable)); */
1127+
1128+ INIT_LIST_HEAD(&ph2c->list);
1129+ ph2c->cmdcode = GEN_CMD_CODE(_GetRaTable);
1130+ ph2c->parmbuf = (unsigned char *)pgetrttblparm;
1131+ ph2c->cmdsz = sizeof(struct getratable_parm);
1132+ ph2c->rsp = (u8 *)pval;
1133+ ph2c->rspsz = sizeof(struct getratable_rsp);
1134+
1135+ pgetrttblparm->rsvd = 0x0;
1136+
1137+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1138+exit:
1139+
1140+ return res;
1141+}
1142+
1143+u8 rtw_setassocsta_cmd(struct adapter *padapter, u8 *mac_addr)
1144+{
1145+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1146+ struct cmd_obj *ph2c;
1147+ struct set_assocsta_parm *psetassocsta_para;
1148+ struct set_stakey_rsp *psetassocsta_rsp = NULL;
1149+
1150+ u8 res = _SUCCESS;
1151+
1152+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1153+ if (!ph2c) {
1154+ res = _FAIL;
1155+ goto exit;
1156+ }
1157+
1158+ psetassocsta_para = kzalloc(sizeof(struct set_assocsta_parm), GFP_ATOMIC);
1159+ if (!psetassocsta_para) {
1160+ kfree(ph2c);
1161+ res = _FAIL;
1162+ goto exit;
1163+ }
1164+
1165+ psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
1166+ if (!psetassocsta_rsp) {
1167+ kfree(ph2c);
1168+ kfree(psetassocsta_para);
1169+ return _FAIL;
1170+ }
1171+
1172+ init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
1173+ ph2c->rsp = (u8 *)psetassocsta_rsp;
1174+ ph2c->rspsz = sizeof(struct set_assocsta_rsp);
1175+
1176+ memcpy(psetassocsta_para->addr, mac_addr, ETH_ALEN);
1177+
1178+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1179+
1180+exit:
1181+
1182+ return res;
1183+ }
1184+
1185+u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr)
1186+{
1187+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1188+ struct cmd_obj *ph2c;
1189+ struct addBaReq_parm *paddbareq_parm;
1190+ u8 res = _SUCCESS;
1191+
1192+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1193+ if (!ph2c) {
1194+ res = _FAIL;
1195+ goto exit;
1196+ }
1197+
1198+ paddbareq_parm = kzalloc(sizeof(struct addBaReq_parm), GFP_ATOMIC);
1199+ if (!paddbareq_parm) {
1200+ kfree(ph2c);
1201+ res = _FAIL;
1202+ goto exit;
1203+ }
1204+
1205+ paddbareq_parm->tid = tid;
1206+ memcpy(paddbareq_parm->addr, addr, ETH_ALEN);
1207+
1208+ init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm, GEN_CMD_CODE(_AddBAReq));
1209+
1210+ /* DBG_88E("rtw_addbareq_cmd, tid =%d\n", tid); */
1211+
1212+ /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
1213+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1214+
1215+exit:
1216+
1217+ return res;
1218+}
1219+
1220+u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
1221+{
1222+ struct cmd_obj *ph2c;
1223+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1224+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1225+ u8 res = _SUCCESS;
1226+
1227+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1228+ if (!ph2c) {
1229+ res = _FAIL;
1230+ goto exit;
1231+ }
1232+
1233+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1234+ if (!pdrvextra_cmd_parm) {
1235+ kfree(ph2c);
1236+ res = _FAIL;
1237+ goto exit;
1238+ }
1239+
1240+ pdrvextra_cmd_parm->ec_id = DYNAMIC_CHK_WK_CID;
1241+ pdrvextra_cmd_parm->type_size = 0;
1242+ pdrvextra_cmd_parm->pbuf = (u8 *)padapter;
1243+
1244+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1245+
1246+ /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
1247+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1248+exit:
1249+
1250+ return res;
1251+}
1252+
1253+u8 rtw_set_ch_cmd(struct adapter *padapter, u8 ch, u8 bw, u8 ch_offset, u8 enqueue)
1254+{
1255+ struct cmd_obj *pcmdobj;
1256+ struct set_ch_parm *set_ch_parm;
1257+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1258+
1259+ u8 res = _SUCCESS;
1260+
1261+ DBG_88E(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
1262+ FUNC_NDEV_ARG(padapter->pnetdev), ch, bw, ch_offset);
1263+
1264+ /* check input parameter */
1265+
1266+ /* prepare cmd parameter */
1267+ set_ch_parm = kzalloc(sizeof(*set_ch_parm), GFP_ATOMIC);
1268+ if (!set_ch_parm) {
1269+ res = _FAIL;
1270+ goto exit;
1271+ }
1272+ set_ch_parm->ch = ch;
1273+ set_ch_parm->bw = bw;
1274+ set_ch_parm->ch_offset = ch_offset;
1275+
1276+ if (enqueue) {
1277+ /* need enqueue, prepare cmd_obj and enqueue */
1278+ pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1279+ if (!pcmdobj) {
1280+ kfree(set_ch_parm);
1281+ res = _FAIL;
1282+ goto exit;
1283+ }
1284+
1285+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, set_ch_parm, GEN_CMD_CODE(_SetChannel));
1286+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
1287+ } else {
1288+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
1289+ if (H2C_SUCCESS != set_ch_hdl(padapter, (u8 *)set_ch_parm))
1290+ res = _FAIL;
1291+
1292+ kfree(set_ch_parm);
1293+ }
1294+
1295+ /* do something based on res... */
1296+
1297+exit:
1298+
1299+ DBG_88E(FUNC_NDEV_FMT" res:%u\n", FUNC_NDEV_ARG(padapter->pnetdev), res);
1300+
1301+ return res;
1302+}
1303+
1304+u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
1305+{
1306+ struct cmd_obj *pcmdobj;
1307+ struct SetChannelPlan_param *setChannelPlan_param;
1308+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1309+
1310+ u8 res = _SUCCESS;
1311+
1312+ /* check input parameter */
1313+ if (!rtw_is_channel_plan_valid(chplan)) {
1314+ res = _FAIL;
1315+ goto exit;
1316+ }
1317+
1318+ /* prepare cmd parameter */
1319+ setChannelPlan_param = kzalloc(sizeof(struct SetChannelPlan_param),
1320+ GFP_KERNEL);
1321+ if (!setChannelPlan_param) {
1322+ res = _FAIL;
1323+ goto exit;
1324+ }
1325+ setChannelPlan_param->channel_plan = chplan;
1326+
1327+ if (enqueue) {
1328+ /* need enqueue, prepare cmd_obj and enqueue */
1329+ pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
1330+ if (!pcmdobj) {
1331+ kfree(setChannelPlan_param);
1332+ res = _FAIL;
1333+ goto exit;
1334+ }
1335+
1336+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelPlan_param, GEN_CMD_CODE(_SetChannelPlan));
1337+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
1338+ } else {
1339+ /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
1340+ if (H2C_SUCCESS != set_chplan_hdl(padapter, (unsigned char *)setChannelPlan_param))
1341+ res = _FAIL;
1342+
1343+ kfree(setChannelPlan_param);
1344+ }
1345+
1346+ /* do something based on res... */
1347+ if (res == _SUCCESS)
1348+ padapter->mlmepriv.ChannelPlan = chplan;
1349+
1350+exit:
1351+
1352+ return res;
1353+}
1354+
1355+u8 rtw_led_blink_cmd(struct adapter *padapter, struct LED_871x *pLed)
1356+{
1357+ struct cmd_obj *pcmdobj;
1358+ struct LedBlink_param *ledBlink_param;
1359+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1360+
1361+ u8 res = _SUCCESS;
1362+
1363+ pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1364+ if (!pcmdobj) {
1365+ res = _FAIL;
1366+ goto exit;
1367+ }
1368+
1369+ ledBlink_param = kzalloc(sizeof(struct LedBlink_param), GFP_ATOMIC);
1370+ if (!ledBlink_param) {
1371+ kfree(pcmdobj);
1372+ res = _FAIL;
1373+ goto exit;
1374+ }
1375+
1376+ ledBlink_param->pLed = pLed;
1377+
1378+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, ledBlink_param, GEN_CMD_CODE(_LedBlink));
1379+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
1380+
1381+exit:
1382+
1383+ return res;
1384+}
1385+
1386+u8 rtw_set_csa_cmd(struct adapter *padapter, u8 new_ch_no)
1387+{
1388+ struct cmd_obj *pcmdobj;
1389+ struct SetChannelSwitch_param *setChannelSwitch_param;
1390+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1391+
1392+ u8 res = _SUCCESS;
1393+
1394+ pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1395+ if (!pcmdobj) {
1396+ res = _FAIL;
1397+ goto exit;
1398+ }
1399+
1400+ setChannelSwitch_param = kzalloc(sizeof(struct SetChannelSwitch_param),
1401+ GFP_ATOMIC);
1402+ if (!setChannelSwitch_param) {
1403+ kfree(pcmdobj);
1404+ res = _FAIL;
1405+ goto exit;
1406+ }
1407+
1408+ setChannelSwitch_param->new_ch_no = new_ch_no;
1409+
1410+ init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelSwitch_param, GEN_CMD_CODE(_SetChannelSwitch));
1411+ res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
1412+
1413+exit:
1414+
1415+ return res;
1416+}
1417+
1418+u8 rtw_tdls_cmd(struct adapter *padapter, u8 *addr, u8 option)
1419+{
1420+ return _SUCCESS;
1421+}
1422+
1423+static void traffic_status_watchdog(struct adapter *padapter)
1424+{
1425+ u8 bEnterPS;
1426+ u8 bBusyTraffic = false, bTxBusyTraffic = false, bRxBusyTraffic = false;
1427+ u8 bHigherBusyTraffic = false, bHigherBusyRxTraffic = false, bHigherBusyTxTraffic = false;
1428+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1429+
1430+ /* */
1431+ /* Determine if our traffic is busy now */
1432+ /* */
1433+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1434+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 100 ||
1435+ pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 100) {
1436+ bBusyTraffic = true;
1437+
1438+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
1439+ bRxBusyTraffic = true;
1440+ else
1441+ bTxBusyTraffic = true;
1442+ }
1443+
1444+ /* Higher Tx/Rx data. */
1445+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1446+ pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 4000) {
1447+ bHigherBusyTraffic = true;
1448+
1449+ if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
1450+ bHigherBusyRxTraffic = true;
1451+ else
1452+ bHigherBusyTxTraffic = true;
1453+ }
1454+
1455+ /* check traffic for powersaving. */
1456+ if (((pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod + pmlmepriv->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1457+ (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 2))
1458+ bEnterPS = false;
1459+ else
1460+ bEnterPS = true;
1461+
1462+ /* LeisurePS only work in infra mode. */
1463+ if (bEnterPS)
1464+ LPS_Enter(padapter);
1465+ else
1466+ LPS_Leave(padapter);
1467+ } else {
1468+ LPS_Leave(padapter);
1469+ }
1470+
1471+ pmlmepriv->LinkDetectInfo.NumRxOkInPeriod = 0;
1472+ pmlmepriv->LinkDetectInfo.NumTxOkInPeriod = 0;
1473+ pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1474+ pmlmepriv->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
1475+ pmlmepriv->LinkDetectInfo.bTxBusyTraffic = bTxBusyTraffic;
1476+ pmlmepriv->LinkDetectInfo.bRxBusyTraffic = bRxBusyTraffic;
1477+ pmlmepriv->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1478+ pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1479+ pmlmepriv->LinkDetectInfo.bHigherBusyTxTraffic = bHigherBusyTxTraffic;
1480+}
1481+
1482+static void dynamic_chk_wk_hdl(struct adapter *padapter, u8 *pbuf, int sz)
1483+{
1484+ struct mlme_priv *pmlmepriv;
1485+
1486+ padapter = (struct adapter *)pbuf;
1487+ pmlmepriv = &padapter->mlmepriv;
1488+
1489+#ifdef CONFIG_88EU_AP_MODE
1490+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
1491+ expire_timeout_chk(padapter);
1492+#endif
1493+
1494+ rtw_hal_sreset_xmit_status_check(padapter);
1495+
1496+ linked_status_chk(padapter);
1497+ traffic_status_watchdog(padapter);
1498+
1499+ rtw_hal_dm_watchdog(padapter);
1500+}
1501+
1502+static void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type)
1503+{
1504+ struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
1505+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1506+ u8 mstatus;
1507+
1508+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
1509+ check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))
1510+ return;
1511+
1512+ switch (lps_ctrl_type) {
1513+ case LPS_CTRL_SCAN:
1514+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1515+ /* connect */
1516+ LPS_Leave(padapter);
1517+ }
1518+ break;
1519+ case LPS_CTRL_JOINBSS:
1520+ LPS_Leave(padapter);
1521+ break;
1522+ case LPS_CTRL_CONNECT:
1523+ mstatus = 1;/* connect */
1524+ /* Reset LPS Setting */
1525+ padapter->pwrctrlpriv.LpsIdleCount = 0;
1526+ rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
1527+ break;
1528+ case LPS_CTRL_DISCONNECT:
1529+ mstatus = 0;/* disconnect */
1530+ LPS_Leave(padapter);
1531+ rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
1532+ break;
1533+ case LPS_CTRL_SPECIAL_PACKET:
1534+ /* DBG_88E("LPS_CTRL_SPECIAL_PACKET\n"); */
1535+ pwrpriv->DelayLPSLastTimeStamp = jiffies;
1536+ LPS_Leave(padapter);
1537+ break;
1538+ case LPS_CTRL_LEAVE:
1539+ LPS_Leave(padapter);
1540+ break;
1541+ default:
1542+ break;
1543+ }
1544+
1545+}
1546+
1547+u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
1548+{
1549+ struct cmd_obj *ph2c;
1550+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1551+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1552+ /* struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv; */
1553+ u8 res = _SUCCESS;
1554+
1555+ /* if (!pwrctrlpriv->bLeisurePs) */
1556+ /* return res; */
1557+
1558+ if (enqueue) {
1559+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1560+ if (!ph2c) {
1561+ res = _FAIL;
1562+ goto exit;
1563+ }
1564+
1565+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1566+ GFP_ATOMIC);
1567+ if (!pdrvextra_cmd_parm) {
1568+ kfree(ph2c);
1569+ res = _FAIL;
1570+ goto exit;
1571+ }
1572+
1573+ pdrvextra_cmd_parm->ec_id = LPS_CTRL_WK_CID;
1574+ pdrvextra_cmd_parm->type_size = lps_ctrl_type;
1575+ pdrvextra_cmd_parm->pbuf = NULL;
1576+
1577+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1578+
1579+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1580+ } else {
1581+ lps_ctrl_wk_hdl(padapter, lps_ctrl_type);
1582+ }
1583+
1584+exit:
1585+
1586+ return res;
1587+}
1588+
1589+static void rpt_timer_setting_wk_hdl(struct adapter *padapter, u16 min_time)
1590+{
1591+ rtw_hal_set_hwreg(padapter, HW_VAR_RPT_TIMER_SETTING, (u8 *)(&min_time));
1592+}
1593+
1594+u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 min_time)
1595+{
1596+ struct cmd_obj *ph2c;
1597+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1598+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1599+
1600+ u8 res = _SUCCESS;
1601+
1602+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1603+ if (!ph2c) {
1604+ res = _FAIL;
1605+ goto exit;
1606+ }
1607+
1608+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1609+ GFP_ATOMIC);
1610+ if (!pdrvextra_cmd_parm) {
1611+ kfree(ph2c);
1612+ res = _FAIL;
1613+ goto exit;
1614+ }
1615+
1616+ pdrvextra_cmd_parm->ec_id = RTP_TIMER_CFG_WK_CID;
1617+ pdrvextra_cmd_parm->type_size = min_time;
1618+ pdrvextra_cmd_parm->pbuf = NULL;
1619+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1620+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1621+exit:
1622+
1623+ return res;
1624+}
1625+
1626+static void antenna_select_wk_hdl(struct adapter *padapter, u8 antenna)
1627+{
1628+ rtw_hal_set_hwreg(padapter, HW_VAR_ANTENNA_DIVERSITY_SELECT, (u8 *)(&antenna));
1629+}
1630+
1631+u8 rtw_antenna_select_cmd(struct adapter *padapter, u8 antenna, u8 enqueue)
1632+{
1633+ struct cmd_obj *ph2c;
1634+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1635+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1636+ u8 support_ant_div;
1637+ u8 res = _SUCCESS;
1638+
1639+ rtw_hal_get_def_var(padapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &support_ant_div);
1640+ if (!support_ant_div)
1641+ return res;
1642+
1643+ if (enqueue) {
1644+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
1645+ if (!ph2c) {
1646+ res = _FAIL;
1647+ goto exit;
1648+ }
1649+
1650+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm),
1651+ GFP_KERNEL);
1652+ if (!pdrvextra_cmd_parm) {
1653+ kfree(ph2c);
1654+ res = _FAIL;
1655+ goto exit;
1656+ }
1657+
1658+ pdrvextra_cmd_parm->ec_id = ANT_SELECT_WK_CID;
1659+ pdrvextra_cmd_parm->type_size = antenna;
1660+ pdrvextra_cmd_parm->pbuf = NULL;
1661+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1662+
1663+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1664+ } else {
1665+ antenna_select_wk_hdl(padapter, antenna);
1666+ }
1667+exit:
1668+
1669+ return res;
1670+}
1671+
1672+static void power_saving_wk_hdl(struct adapter *padapter, u8 *pbuf, int sz)
1673+{
1674+ rtw_ps_processor(padapter);
1675+}
1676+
1677+#ifdef CONFIG_88EU_P2P
1678+u8 p2p_protocol_wk_cmd(struct adapter *padapter, int intCmdType)
1679+{
1680+ struct cmd_obj *ph2c;
1681+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1682+ struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1683+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1684+ u8 res = _SUCCESS;
1685+
1686+ if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
1687+ return res;
1688+
1689+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1690+ if (!ph2c) {
1691+ res = _FAIL;
1692+ goto exit;
1693+ }
1694+
1695+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1696+ if (!pdrvextra_cmd_parm) {
1697+ kfree(ph2c);
1698+ res = _FAIL;
1699+ goto exit;
1700+ }
1701+
1702+ pdrvextra_cmd_parm->ec_id = P2P_PROTO_WK_CID;
1703+ pdrvextra_cmd_parm->type_size = intCmdType; /* As the command tppe. */
1704+ pdrvextra_cmd_parm->pbuf = NULL; /* Must be NULL here */
1705+
1706+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1707+
1708+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1709+
1710+exit:
1711+
1712+ return res;
1713+}
1714+#endif /* CONFIG_88EU_P2P */
1715+
1716+u8 rtw_ps_cmd(struct adapter *padapter)
1717+{
1718+ struct cmd_obj *ppscmd;
1719+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1720+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1721+
1722+ u8 res = _SUCCESS;
1723+
1724+ ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1725+ if (!ppscmd) {
1726+ res = _FAIL;
1727+ goto exit;
1728+ }
1729+
1730+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1731+ if (!pdrvextra_cmd_parm) {
1732+ kfree(ppscmd);
1733+ res = _FAIL;
1734+ goto exit;
1735+ }
1736+
1737+ pdrvextra_cmd_parm->ec_id = POWER_SAVING_CTRL_WK_CID;
1738+ pdrvextra_cmd_parm->pbuf = NULL;
1739+ init_h2fwcmd_w_parm_no_rsp(ppscmd, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1740+
1741+ res = rtw_enqueue_cmd(pcmdpriv, ppscmd);
1742+
1743+exit:
1744+
1745+ return res;
1746+}
1747+
1748+#ifdef CONFIG_88EU_AP_MODE
1749+
1750+static void rtw_chk_hi_queue_hdl(struct adapter *padapter)
1751+{
1752+ int cnt = 0;
1753+ struct sta_info *psta_bmc;
1754+ struct sta_priv *pstapriv = &padapter->stapriv;
1755+
1756+ psta_bmc = rtw_get_bcmc_stainfo(padapter);
1757+ if (!psta_bmc)
1758+ return;
1759+
1760+ if (psta_bmc->sleepq_len == 0) {
1761+ u8 val = 0;
1762+
1763+ /* while ((rtw_read32(padapter, 0x414)&0x00ffff00)!= 0) */
1764+ /* while ((rtw_read32(padapter, 0x414)&0x0000ff00)!= 0) */
1765+
1766+ rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
1767+
1768+ while (!val) {
1769+ msleep(100);
1770+
1771+ cnt++;
1772+
1773+ if (cnt > 10)
1774+ break;
1775+
1776+ rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
1777+ }
1778+
1779+ if (cnt <= 10) {
1780+ pstapriv->tim_bitmap &= ~BIT(0);
1781+ pstapriv->sta_dz_bitmap &= ~BIT(0);
1782+
1783+ update_beacon(padapter, _TIM_IE_, NULL, false);
1784+ } else { /* re check again */
1785+ rtw_chk_hi_queue_cmd(padapter);
1786+ }
1787+ }
1788+}
1789+
1790+u8 rtw_chk_hi_queue_cmd(struct adapter *padapter)
1791+{
1792+ struct cmd_obj *ph2c;
1793+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1794+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1795+ u8 res = _SUCCESS;
1796+
1797+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1798+ if (!ph2c) {
1799+ res = _FAIL;
1800+ goto exit;
1801+ }
1802+
1803+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1804+ if (!pdrvextra_cmd_parm) {
1805+ kfree(ph2c);
1806+ res = _FAIL;
1807+ goto exit;
1808+ }
1809+
1810+ pdrvextra_cmd_parm->ec_id = CHECK_HIQ_WK_CID;
1811+ pdrvextra_cmd_parm->type_size = 0;
1812+ pdrvextra_cmd_parm->pbuf = NULL;
1813+
1814+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1815+
1816+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1817+exit:
1818+ return res;
1819+}
1820+#endif
1821+
1822+u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt)
1823+{
1824+ struct cmd_obj *ph2c;
1825+ struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1826+ struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1827+ u8 res = _SUCCESS;
1828+
1829+ ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1830+ if (!ph2c) {
1831+ res = _FAIL;
1832+ goto exit;
1833+ }
1834+
1835+ pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1836+ if (!pdrvextra_cmd_parm) {
1837+ kfree(ph2c);
1838+ res = _FAIL;
1839+ goto exit;
1840+ }
1841+
1842+ pdrvextra_cmd_parm->ec_id = C2H_WK_CID;
1843+ pdrvextra_cmd_parm->type_size = c2h_evt ? 16 : 0;
1844+ pdrvextra_cmd_parm->pbuf = c2h_evt;
1845+
1846+ init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
1847+
1848+ res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1849+
1850+exit:
1851+
1852+ return res;
1853+}
1854+
1855+static s32 c2h_evt_hdl(struct adapter *adapter, struct c2h_evt_hdr *c2h_evt, c2h_id_filter filter)
1856+{
1857+ s32 ret = _FAIL;
1858+ u8 buf[16];
1859+
1860+ if (!c2h_evt) {
1861+ /* No c2h event in cmd_obj, read c2h event before handling*/
1862+ if (c2h_evt_read(adapter, buf) == _SUCCESS) {
1863+ c2h_evt = (struct c2h_evt_hdr *)buf;
1864+
1865+ if (filter && !filter(c2h_evt->id))
1866+ goto exit;
1867+
1868+ ret = rtw_hal_c2h_handler(adapter, c2h_evt);
1869+ }
1870+ } else {
1871+ if (filter && !filter(c2h_evt->id))
1872+ goto exit;
1873+
1874+ ret = rtw_hal_c2h_handler(adapter, c2h_evt);
1875+ }
1876+exit:
1877+ return ret;
1878+}
1879+
1880+static void c2h_wk_callback(struct work_struct *work)
1881+{
1882+ struct evt_priv *evtpriv = container_of(work, struct evt_priv, c2h_wk);
1883+ struct adapter *adapter = container_of(evtpriv, struct adapter, evtpriv);
1884+ struct c2h_evt_hdr *c2h_evt;
1885+ c2h_id_filter ccx_id_filter = rtw_hal_c2h_id_filter_ccx(adapter);
1886+
1887+ evtpriv->c2h_wk_alive = true;
1888+
1889+ while (!rtw_cbuf_empty(evtpriv->c2h_queue)) {
1890+ if ((c2h_evt = (struct c2h_evt_hdr *)rtw_cbuf_pop(evtpriv->c2h_queue)) != NULL) {
1891+ /* This C2H event is read, clear it */
1892+ c2h_evt_clear(adapter);
1893+ } else {
1894+ c2h_evt = kmalloc(16, GFP_KERNEL);
1895+ if (c2h_evt) {
1896+ /* This C2H event is not read, read & clear now */
1897+ if (c2h_evt_read(adapter, (u8 *)c2h_evt) != _SUCCESS) {
1898+ kfree(c2h_evt);
1899+ continue;
1900+ }
1901+ } else {
1902+ return;
1903+ }
1904+ }
1905+
1906+ /* Special pointer to trigger c2h_evt_clear only */
1907+ if ((void *)c2h_evt == (void *)evtpriv)
1908+ continue;
1909+
1910+ if (!c2h_evt_exist(c2h_evt)) {
1911+ kfree(c2h_evt);
1912+ continue;
1913+ }
1914+
1915+ if (ccx_id_filter(c2h_evt->id)) {
1916+ /* Handle CCX report here */
1917+ rtw_hal_c2h_handler(adapter, c2h_evt);
1918+ kfree(c2h_evt);
1919+ } else {
1920+#ifdef CONFIG_88EU_P2P
1921+ /* Enqueue into cmd_thread for others */
1922+ rtw_c2h_wk_cmd(adapter, (u8 *)c2h_evt);
1923+#endif
1924+ }
1925+ }
1926+
1927+ evtpriv->c2h_wk_alive = false;
1928+}
1929+
1930+u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf)
1931+{
1932+ struct drvextra_cmd_parm *pdrvextra_cmd;
1933+
1934+ if (!pbuf)
1935+ return H2C_PARAMETERS_ERROR;
1936+
1937+ pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf;
1938+
1939+ switch (pdrvextra_cmd->ec_id) {
1940+ case DYNAMIC_CHK_WK_CID:
1941+ dynamic_chk_wk_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
1942+ break;
1943+ case POWER_SAVING_CTRL_WK_CID:
1944+ power_saving_wk_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
1945+ break;
1946+ case LPS_CTRL_WK_CID:
1947+ lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type_size);
1948+ break;
1949+ case RTP_TIMER_CFG_WK_CID:
1950+ rpt_timer_setting_wk_hdl(padapter, pdrvextra_cmd->type_size);
1951+ break;
1952+ case ANT_SELECT_WK_CID:
1953+ antenna_select_wk_hdl(padapter, pdrvextra_cmd->type_size);
1954+ break;
1955+#ifdef CONFIG_88EU_P2P
1956+ case P2P_PS_WK_CID:
1957+ p2p_ps_wk_hdl(padapter, pdrvextra_cmd->type_size);
1958+ break;
1959+ case P2P_PROTO_WK_CID:
1960+ /* Commented by Albert 2011/07/01 */
1961+ /* I used the type_size as the type command */
1962+ p2p_protocol_wk_hdl(padapter, pdrvextra_cmd->type_size);
1963+ break;
1964+#endif
1965+#ifdef CONFIG_88EU_AP_MODE
1966+ case CHECK_HIQ_WK_CID:
1967+ rtw_chk_hi_queue_hdl(padapter);
1968+ break;
1969+#endif /* CONFIG_88EU_AP_MODE */
1970+ case C2H_WK_CID:
1971+ c2h_evt_hdl(padapter, (struct c2h_evt_hdr *)pdrvextra_cmd->pbuf, NULL);
1972+ break;
1973+ default:
1974+ break;
1975+ }
1976+
1977+ if (pdrvextra_cmd->pbuf && pdrvextra_cmd->type_size > 0)
1978+ kfree(pdrvextra_cmd->pbuf);
1979+
1980+ return H2C_SUCCESS;
1981+}
1982+
1983+void rtw_survey_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1984+{
1985+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1986+
1987+ if (pcmd->res == H2C_DROPPED) {
1988+ /* TODO: cancel timer and do timeout handler directly... */
1989+ /* need to make timeout handlerOS independent */
1990+ _set_timer(&pmlmepriv->scan_to_timer, 1);
1991+ } else if (pcmd->res != H2C_SUCCESS) {
1992+ _set_timer(&pmlmepriv->scan_to_timer, 1);
1993+ }
1994+
1995+ /* free cmd */
1996+ rtw_free_cmd_obj(pcmd);
1997+
1998+}
1999+void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
2000+{
2001+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2002+
2003+ if (pcmd->res != H2C_SUCCESS) {
2004+ spin_lock_bh(&pmlmepriv->lock);
2005+ set_fwstate(pmlmepriv, _FW_LINKED);
2006+ spin_unlock_bh(&pmlmepriv->lock);
2007+
2008+ return;
2009+ } else /* clear bridge database */
2010+ nat25_db_cleanup(padapter);
2011+
2012+ /* free cmd */
2013+ rtw_free_cmd_obj(pcmd);
2014+}
2015+
2016+void rtw_joinbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
2017+{
2018+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2019+
2020+ if (pcmd->res == H2C_DROPPED) {
2021+ /* TODO: cancel timer and do timeout handler directly... */
2022+ /* need to make timeout handlerOS independent */
2023+ _set_timer(&pmlmepriv->assoc_timer, 1);
2024+ } else if (pcmd->res != H2C_SUCCESS) {
2025+ _set_timer(&pmlmepriv->assoc_timer, 1);
2026+ }
2027+
2028+ rtw_free_cmd_obj(pcmd);
2029+}
2030+
2031+void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
2032+{
2033+ u8 timer_cancelled;
2034+ struct sta_info *psta = NULL;
2035+ struct wlan_network *pwlan = NULL;
2036+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2037+ struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf;
2038+ struct wlan_network *tgt_network = &pmlmepriv->cur_network;
2039+
2040+ if (pcmd->res != H2C_SUCCESS)
2041+ _set_timer(&pmlmepriv->assoc_timer, 1);
2042+
2043+ _cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled);
2044+
2045+ spin_lock_bh(&pmlmepriv->lock);
2046+
2047+ if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
2048+ psta = rtw_get_stainfo(&padapter->stapriv, pnetwork->MacAddress);
2049+ if (!psta) {
2050+ psta = rtw_alloc_stainfo(&padapter->stapriv, pnetwork->MacAddress);
2051+ if (!psta)
2052+ goto createbss_cmd_fail;
2053+ }
2054+
2055+ rtw_indicate_connect(padapter);
2056+ } else {
2057+
2058+ pwlan = _rtw_alloc_network(pmlmepriv);
2059+ spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2060+ if (!pwlan) {
2061+ pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue);
2062+ if (!pwlan) {
2063+ spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2064+ goto createbss_cmd_fail;
2065+ }
2066+ pwlan->last_scanned = jiffies;
2067+ } else {
2068+ list_add_tail(&pwlan->list, &pmlmepriv->scanned_queue.queue);
2069+ }
2070+
2071+ pnetwork->Length = get_wlan_bssid_ex_sz(pnetwork);
2072+ memcpy(&pwlan->network, pnetwork, pnetwork->Length);
2073+
2074+ memcpy(&tgt_network->network, pnetwork, (get_wlan_bssid_ex_sz(pnetwork)));
2075+
2076+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
2077+
2078+ spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2079+ /* we will set _FW_LINKED when there is one more sat to join us (rtw_stassoc_event_callback) */
2080+ }
2081+
2082+createbss_cmd_fail:
2083+
2084+ spin_unlock_bh(&pmlmepriv->lock);
2085+
2086+ rtw_free_cmd_obj(pcmd);
2087+
2088+}
2089+
2090+void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
2091+{
2092+ struct sta_priv *pstapriv = &padapter->stapriv;
2093+ struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *)(pcmd->rsp);
2094+ struct sta_info *psta = rtw_get_stainfo(pstapriv, psetstakey_rsp->addr);
2095+
2096+ if (!psta)
2097+ goto exit;
2098+exit:
2099+ rtw_free_cmd_obj(pcmd);
2100+
2101+}
2102+
2103+void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *pcmd)
2104+{
2105+ struct sta_priv *pstapriv = &padapter->stapriv;
2106+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2107+ struct set_assocsta_parm *passocsta_parm = (struct set_assocsta_parm *)(pcmd->parmbuf);
2108+ struct set_assocsta_rsp *passocsta_rsp = (struct set_assocsta_rsp *)(pcmd->rsp);
2109+ struct sta_info *psta = rtw_get_stainfo(pstapriv, passocsta_parm->addr);
2110+
2111+ if (!psta)
2112+ goto exit;
2113+
2114+ psta->aid = passocsta_rsp->cam_id;
2115+ psta->mac_id = passocsta_rsp->cam_id;
2116+
2117+ spin_lock_bh(&pmlmepriv->lock);
2118+
2119+ if (check_fwstate(pmlmepriv, WIFI_MP_STATE) && check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
2120+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
2121+
2122+ set_fwstate(pmlmepriv, _FW_LINKED);
2123+ spin_unlock_bh(&pmlmepriv->lock);
2124+
2125+exit:
2126+ rtw_free_cmd_obj(pcmd);
2127+
2128+}
drivers/staging/r8188eu/core/rtw_debug.c+904−0
@@ -0,0 +1,904 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2012 Realtek Corporation. */
3+
4+#define _RTW_DEBUG_C_
5+
6+#include "../include/rtw_debug.h"
7+#include "../include/drv_types.h"
8+
9+int proc_get_drv_version(char *page, char **start,
10+ off_t offset, int count,
11+ int *eof, void *data)
12+{
13+ int len = 0;
14+
15+ len += snprintf(page + len, count - len, "%s\n", DRIVERVERSION);
16+
17+ *eof = 1;
18+ return len;
19+}
20+
21+int proc_get_write_reg(char *page, char **start,
22+ off_t offset, int count,
23+ int *eof, void *data)
24+{
25+ *eof = 1;
26+ return 0;
27+}
28+
29+int proc_set_write_reg(struct file *file, const char __user *buffer,
30+ unsigned long count, void *data)
31+{
32+ struct net_device *dev = (struct net_device *)data;
33+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
34+ char tmp[32];
35+ u32 addr, val, len;
36+
37+ if (count < 3) {
38+ DBG_88E("argument size is less than 3\n");
39+ return -EFAULT;
40+ }
41+
42+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
43+ int num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
44+
45+ if (num != 3) {
46+ DBG_88E("invalid write_reg parameter!\n");
47+ return count;
48+ }
49+ switch (len) {
50+ case 1:
51+ rtw_write8(padapter, addr, (u8)val);
52+ break;
53+ case 2:
54+ rtw_write16(padapter, addr, (u16)val);
55+ break;
56+ case 4:
57+ rtw_write32(padapter, addr, val);
58+ break;
59+ default:
60+ DBG_88E("error write length =%d", len);
61+ break;
62+ }
63+ }
64+ return count;
65+}
66+
67+static u32 proc_get_read_addr = 0xeeeeeeee;
68+static u32 proc_get_read_len = 0x4;
69+
70+int proc_get_read_reg(char *page, char **start,
71+ off_t offset, int count,
72+ int *eof, void *data)
73+{
74+ struct net_device *dev = data;
75+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
76+
77+ int len = 0;
78+
79+ if (proc_get_read_addr == 0xeeeeeeee) {
80+ *eof = 1;
81+ return len;
82+ }
83+
84+ switch (proc_get_read_len) {
85+ case 1:
86+ len += snprintf(page + len, count - len, "rtw_read8(0x%x)=0x%x\n", proc_get_read_addr, rtw_read8(padapter, proc_get_read_addr));
87+ break;
88+ case 2:
89+ len += snprintf(page + len, count - len, "rtw_read16(0x%x)=0x%x\n", proc_get_read_addr, rtw_read16(padapter, proc_get_read_addr));
90+ break;
91+ case 4:
92+ len += snprintf(page + len, count - len, "rtw_read32(0x%x)=0x%x\n", proc_get_read_addr, rtw_read32(padapter, proc_get_read_addr));
93+ break;
94+ default:
95+ len += snprintf(page + len, count - len, "error read length=%d\n", proc_get_read_len);
96+ break;
97+ }
98+
99+ *eof = 1;
100+ return len;
101+}
102+
103+int proc_set_read_reg(struct file *file, const char __user *buffer,
104+ unsigned long count, void *data)
105+{
106+ char tmp[16];
107+ u32 addr, len;
108+
109+ if (count < 2) {
110+ DBG_88E("argument size is less than 2\n");
111+ return -EFAULT;
112+ }
113+
114+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
115+ int num = sscanf(tmp, "%x %x", &addr, &len);
116+
117+ if (num != 2) {
118+ DBG_88E("invalid read_reg parameter!\n");
119+ return count;
120+ }
121+
122+ proc_get_read_addr = addr;
123+
124+ proc_get_read_len = len;
125+ }
126+
127+ return count;
128+}
129+
130+int proc_get_fwstate(char *page, char **start,
131+ off_t offset, int count,
132+ int *eof, void *data)
133+{
134+ struct net_device *dev = data;
135+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
136+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
137+
138+ int len = 0;
139+
140+ len += snprintf(page + len, count - len, "fwstate=0x%x\n", get_fwstate(pmlmepriv));
141+
142+ *eof = 1;
143+ return len;
144+}
145+
146+int proc_get_sec_info(char *page, char **start,
147+ off_t offset, int count,
148+ int *eof, void *data)
149+{
150+ struct net_device *dev = data;
151+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
152+ struct security_priv *psecuritypriv = &padapter->securitypriv;
153+
154+ int len = 0;
155+
156+ len += snprintf(page + len, count - len, "auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",
157+ psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
158+ psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus);
159+
160+ *eof = 1;
161+ return len;
162+}
163+
164+int proc_get_mlmext_state(char *page, char **start,
165+ off_t offset, int count,
166+ int *eof, void *data)
167+{
168+ struct net_device *dev = data;
169+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
170+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
171+ struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
172+
173+ int len = 0;
174+
175+ len += snprintf(page + len, count - len, "pmlmeinfo->state=0x%x\n", pmlmeinfo->state);
176+
177+ *eof = 1;
178+ return len;
179+}
180+
181+int proc_get_qos_option(char *page, char **start,
182+ off_t offset, int count,
183+ int *eof, void *data)
184+{
185+ struct net_device *dev = data;
186+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
187+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
188+
189+ int len = 0;
190+
191+ len += snprintf(page + len, count - len, "qos_option=%d\n", pmlmepriv->qospriv.qos_option);
192+
193+ *eof = 1;
194+ return len;
195+}
196+
197+int proc_get_ht_option(char *page, char **start,
198+ off_t offset, int count,
199+ int *eof, void *data)
200+{
201+ struct net_device *dev = data;
202+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
203+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
204+
205+ int len = 0;
206+ len += snprintf(page + len, count - len, "ht_option=%d\n", pmlmepriv->htpriv.ht_option);
207+ *eof = 1;
208+ return len;
209+}
210+
211+int proc_get_rf_info(char *page, char **start,
212+ off_t offset, int count,
213+ int *eof, void *data)
214+{
215+ struct net_device *dev = data;
216+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
217+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
218+ int len = 0;
219+
220+ len += snprintf(page + len, count - len, "cur_ch=%d, cur_bw=%d, cur_ch_offet=%d\n",
221+ pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
222+ *eof = 1;
223+ return len;
224+}
225+
226+int proc_get_ap_info(char *page, char **start,
227+ off_t offset, int count,
228+ int *eof, void *data)
229+{
230+ struct sta_info *psta;
231+ struct net_device *dev = data;
232+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
233+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
234+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
235+ struct wlan_network *cur_network = &pmlmepriv->cur_network;
236+ struct sta_priv *pstapriv = &padapter->stapriv;
237+ int len = 0;
238+
239+ psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
240+ if (psta) {
241+ int i;
242+ struct recv_reorder_ctrl *preorder_ctrl;
243+
244+ len += snprintf(page + len, count - len, "SSID=%s\n", cur_network->network.Ssid.Ssid);
245+ len += snprintf(page + len, count - len, "sta's macaddr:%pM\n", psta->hwaddr);
246+ len += snprintf(page + len, count - len, "cur_channel=%d, cur_bwmode=%d, cur_ch_offset=%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
247+ len += snprintf(page + len, count - len, "rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
248+ len += snprintf(page + len, count - len, "state=0x%x, aid=%d, macid=%d, raid=%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
249+ len += snprintf(page + len, count - len, "qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
250+ len += snprintf(page + len, count - len, "bwmode=%d, ch_offset=%d, sgi=%d\n", psta->htpriv.bwmode, psta->htpriv.ch_offset, psta->htpriv.sgi);
251+ len += snprintf(page + len, count - len, "ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
252+ len += snprintf(page + len, count - len, "agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
253+
254+ for (i = 0; i < 16; i++) {
255+ preorder_ctrl = &psta->recvreorder_ctrl[i];
256+ if (preorder_ctrl->enable)
257+ len += snprintf(page + len, count - len, "tid=%d, indicate_seq=%d\n", i, preorder_ctrl->indicate_seq);
258+ }
259+ } else {
260+ len += snprintf(page + len, count - len, "can't get sta's macaddr, cur_network's macaddr: %pM\n", cur_network->network.MacAddress);
261+ }
262+
263+ *eof = 1;
264+ return len;
265+}
266+
267+int proc_get_adapter_state(char *page, char **start,
268+ off_t offset, int count,
269+ int *eof, void *data)
270+{
271+ struct net_device *dev = data;
272+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
273+ int len = 0;
274+
275+ len += snprintf(page + len, count - len, "bSurpriseRemoved=%d, bDriverStopped=%d\n",
276+ padapter->bSurpriseRemoved, padapter->bDriverStopped);
277+
278+ *eof = 1;
279+ return len;
280+}
281+
282+int proc_get_trx_info(char *page, char **start,
283+ off_t offset, int count,
284+ int *eof, void *data)
285+{
286+ struct net_device *dev = data;
287+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
288+ struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
289+ struct recv_priv *precvpriv = &padapter->recvpriv;
290+ int len = 0;
291+
292+ len += snprintf(page + len, count - len, "free_xmitbuf_cnt=%d, free_xmitframe_cnt=%d, free_ext_xmitbuf_cnt=%d, free_recvframe_cnt=%d\n",
293+ pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt, pxmitpriv->free_xmit_extbuf_cnt, precvpriv->free_recvframe_cnt);
294+ len += snprintf(page + len, count - len, "rx_urb_pending_cn=%d\n", precvpriv->rx_pending_cnt);
295+
296+ *eof = 1;
297+ return len;
298+}
299+
300+int proc_get_mac_reg_dump1(char *page, char **start,
301+ off_t offset, int count,
302+ int *eof, void *data)
303+{
304+ struct net_device *dev = data;
305+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
306+ int len = 0;
307+ int i, j = 1;
308+
309+ len += snprintf(page + len, count - len, "\n======= MAC REG =======\n");
310+
311+ for (i = 0x0; i < 0x300; i += 4) {
312+ if (j % 4 == 1)
313+ len += snprintf(page + len, count - len, "0x%02x", i);
314+ len += snprintf(page + len, count - len, " 0x%08x ", rtw_read32(padapter, i));
315+ if ((j++) % 4 == 0)
316+ len += snprintf(page + len, count - len, "\n");
317+ }
318+
319+ *eof = 1;
320+ return len;
321+}
322+
323+int proc_get_mac_reg_dump2(char *page, char **start,
324+ off_t offset, int count,
325+ int *eof, void *data)
326+{
327+ struct net_device *dev = data;
328+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
329+ int len = 0;
330+ int i, j = 1;
331+
332+ len += snprintf(page + len, count - len, "\n======= MAC REG =======\n");
333+ memset(page, 0, count);
334+ for (i = 0x300; i < 0x600; i += 4) {
335+ if (j % 4 == 1)
336+ len += snprintf(page + len, count - len, "0x%02x", i);
337+ len += snprintf(page + len, count - len, " 0x%08x ", rtw_read32(padapter, i));
338+ if ((j++) % 4 == 0)
339+ len += snprintf(page + len, count - len, "\n");
340+ }
341+
342+ *eof = 1;
343+ return len;
344+}
345+
346+int proc_get_mac_reg_dump3(char *page, char **start,
347+ off_t offset, int count,
348+ int *eof, void *data)
349+{
350+ struct net_device *dev = data;
351+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
352+ int len = 0;
353+ int i, j = 1;
354+
355+ len += snprintf(page + len, count - len, "\n======= MAC REG =======\n");
356+
357+ for (i = 0x600; i < 0x800; i += 4) {
358+ if (j % 4 == 1)
359+ len += snprintf(page + len, count - len, "0x%02x", i);
360+ len += snprintf(page + len, count - len, " 0x%08x ", rtw_read32(padapter, i));
361+ if ((j++) % 4 == 0)
362+ len += snprintf(page + len, count - len, "\n");
363+ }
364+
365+ *eof = 1;
366+ return len;
367+}
368+
369+int proc_get_bb_reg_dump1(char *page, char **start,
370+ off_t offset, int count,
371+ int *eof, void *data)
372+{
373+ struct net_device *dev = data;
374+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
375+ int len = 0;
376+ int i, j = 1;
377+
378+ len += snprintf(page + len, count - len, "\n======= BB REG =======\n");
379+ for (i = 0x800; i < 0xB00; i += 4) {
380+ if (j % 4 == 1)
381+ len += snprintf(page + len, count - len, "0x%02x", i);
382+ len += snprintf(page + len, count - len, " 0x%08x ", rtw_read32(padapter, i));
383+ if ((j++) % 4 == 0)
384+ len += snprintf(page + len, count - len, "\n");
385+ }
386+ *eof = 1;
387+ return len;
388+}
389+
390+int proc_get_bb_reg_dump2(char *page, char **start,
391+ off_t offset, int count,
392+ int *eof, void *data)
393+{
394+ struct net_device *dev = data;
395+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
396+ int len = 0;
397+ int i, j = 1;
398+
399+ len += snprintf(page + len, count - len, "\n======= BB REG =======\n");
400+ for (i = 0xB00; i < 0xE00; i += 4) {
401+ if (j % 4 == 1)
402+ len += snprintf(page + len, count - len, "0x%02x", i);
403+ len += snprintf(page + len, count - len, " 0x%08x ", rtw_read32(padapter, i));
404+ if ((j++) % 4 == 0)
405+ len += snprintf(page + len, count - len, "\n");
406+ }
407+ *eof = 1;
408+ return len;
409+}
410+
411+int proc_get_bb_reg_dump3(char *page, char **start,
412+ off_t offset, int count,
413+ int *eof, void *data)
414+{
415+ struct net_device *dev = data;
416+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
417+ int len = 0;
418+ int i, j = 1;
419+
420+ len += snprintf(page + len, count - len, "\n======= BB REG =======\n");
421+ for (i = 0xE00; i < 0x1000; i += 4) {
422+ if (j % 4 == 1)
423+ len += snprintf(page + len, count - len, "0x%02x", i);
424+ len += snprintf(page + len, count - len, " 0x%08x ", rtw_read32(padapter, i));
425+ if ((j++) % 4 == 0)
426+ len += snprintf(page + len, count - len, "\n");
427+ }
428+ *eof = 1;
429+ return len;
430+}
431+
432+int proc_get_rf_reg_dump1(char *page, char **start,
433+ off_t offset, int count,
434+ int *eof, void *data)
435+{
436+ struct net_device *dev = data;
437+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
438+ int len = 0;
439+ int i, j = 1, path;
440+ u32 value;
441+
442+ len += snprintf(page + len, count - len, "\n======= RF REG =======\n");
443+ path = 1;
444+ len += snprintf(page + len, count - len, "\nRF_Path(%x)\n", path);
445+ for (i = 0; i < 0xC0; i++) {
446+ value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
447+ if (j % 4 == 1)
448+ len += snprintf(page + len, count - len, "0x%02x ", i);
449+ len += snprintf(page + len, count - len, " 0x%08x ", value);
450+ if ((j++) % 4 == 0)
451+ len += snprintf(page + len, count - len, "\n");
452+ }
453+ *eof = 1;
454+ return len;
455+}
456+
457+int proc_get_rf_reg_dump2(char *page, char **start,
458+ off_t offset, int count,
459+ int *eof, void *data)
460+{
461+ struct net_device *dev = data;
462+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
463+ int len = 0;
464+ int i, j = 1, path;
465+ u32 value;
466+
467+ len += snprintf(page + len, count - len, "\n======= RF REG =======\n");
468+ path = 1;
469+ len += snprintf(page + len, count - len, "\nRF_Path(%x)\n", path);
470+ for (i = 0xC0; i < 0x100; i++) {
471+ value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
472+ if (j % 4 == 1)
473+ len += snprintf(page + len, count - len, "0x%02x ", i);
474+ len += snprintf(page + len, count - len, " 0x%08x ", value);
475+ if ((j++) % 4 == 0)
476+ len += snprintf(page + len, count - len, "\n");
477+ }
478+ *eof = 1;
479+ return len;
480+}
481+
482+int proc_get_rf_reg_dump3(char *page, char **start,
483+ off_t offset, int count,
484+ int *eof, void *data)
485+{
486+ struct net_device *dev = data;
487+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
488+ int len = 0;
489+ int i, j = 1, path;
490+ u32 value;
491+
492+ len += snprintf(page + len, count - len, "\n======= RF REG =======\n");
493+ path = 2;
494+ len += snprintf(page + len, count - len, "\nRF_Path(%x)\n", path);
495+ for (i = 0; i < 0xC0; i++) {
496+ value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
497+ if (j % 4 == 1)
498+ len += snprintf(page + len, count - len, "0x%02x ", i);
499+ len += snprintf(page + len, count - len, " 0x%08x ", value);
500+ if ((j++) % 4 == 0)
501+ len += snprintf(page + len, count - len, "\n");
502+ }
503+
504+ *eof = 1;
505+ return len;
506+}
507+
508+int proc_get_rf_reg_dump4(char *page, char **start,
509+ off_t offset, int count,
510+ int *eof, void *data)
511+{
512+ struct net_device *dev = data;
513+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
514+ int len = 0;
515+ int i, j = 1, path;
516+ u32 value;
517+
518+ len += snprintf(page + len, count - len, "\n======= RF REG =======\n");
519+ path = 2;
520+ len += snprintf(page + len, count - len, "\nRF_Path(%x)\n", path);
521+ for (i = 0xC0; i < 0x100; i++) {
522+ value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
523+ if (j % 4 == 1)
524+ len += snprintf(page + len, count - len, "0x%02x ", i);
525+ len += snprintf(page + len, count - len, " 0x%08x ", value);
526+ if ((j++) % 4 == 0)
527+ len += snprintf(page + len, count - len, "\n");
528+ }
529+ *eof = 1;
530+ return len;
531+}
532+
533+int proc_get_rx_signal(char *page, char **start,
534+ off_t offset, int count,
535+ int *eof, void *data)
536+{
537+ struct net_device *dev = data;
538+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
539+ int len = 0;
540+
541+ len = snprintf(page + len, count,
542+ "rssi:%d\n"
543+ "rxpwdb:%d\n"
544+ "signal_strength:%u\n"
545+ "signal_qual:%u\n"
546+ "noise:%u\n",
547+ padapter->recvpriv.rssi,
548+ padapter->recvpriv.rxpwdb,
549+ padapter->recvpriv.signal_strength,
550+ padapter->recvpriv.signal_qual,
551+ padapter->recvpriv.noise
552+ );
553+
554+ *eof = 1;
555+ return len;
556+}
557+
558+int proc_set_rx_signal(struct file *file, const char __user *buffer,
559+ unsigned long count, void *data)
560+{
561+ struct net_device *dev = (struct net_device *)data;
562+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
563+ char tmp[32];
564+ u32 is_signal_dbg;
565+ s32 signal_strength;
566+
567+ if (count < 1)
568+ return -EFAULT;
569+
570+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
571+ int num = sscanf(tmp, "%u %u", &is_signal_dbg, &signal_strength);
572+ is_signal_dbg = is_signal_dbg == 0 ? 0 : 1;
573+ if (is_signal_dbg && num != 2)
574+ return count;
575+
576+ signal_strength = signal_strength > 100 ? 100 : signal_strength;
577+ signal_strength = signal_strength < 0 ? 0 : signal_strength;
578+
579+ padapter->recvpriv.is_signal_dbg = is_signal_dbg;
580+ padapter->recvpriv.signal_strength_dbg = signal_strength;
581+
582+ if (is_signal_dbg)
583+ DBG_88E("set %s %u\n", "DBG_SIGNAL_STRENGTH", signal_strength);
584+ else
585+ DBG_88E("set %s\n", "HW_SIGNAL_STRENGTH");
586+ }
587+ return count;
588+}
589+
590+int proc_get_ht_enable(char *page, char **start,
591+ off_t offset, int count,
592+ int *eof, void *data)
593+{
594+ struct net_device *dev = data;
595+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
596+ struct registry_priv *pregpriv = &padapter->registrypriv;
597+ int len = 0;
598+
599+ if (pregpriv)
600+ len += snprintf(page + len, count - len,
601+ "%d\n",
602+ pregpriv->ht_enable
603+ );
604+ *eof = 1;
605+ return len;
606+}
607+
608+int proc_set_ht_enable(struct file *file, const char __user *buffer,
609+ unsigned long count, void *data)
610+{
611+ struct net_device *dev = (struct net_device *)data;
612+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
613+ struct registry_priv *pregpriv = &padapter->registrypriv;
614+ char tmp[32];
615+ s32 mode = 0;
616+
617+ if (count < 1)
618+ return -EFAULT;
619+
620+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
621+ if (pregpriv) {
622+ pregpriv->ht_enable = mode;
623+ pr_info("ht_enable=%d\n", pregpriv->ht_enable);
624+ }
625+ }
626+
627+ return count;
628+}
629+
630+int proc_get_cbw40_enable(char *page, char **start,
631+ off_t offset, int count,
632+ int *eof, void *data)
633+{
634+ struct net_device *dev = data;
635+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
636+ struct registry_priv *pregpriv = &padapter->registrypriv;
637+
638+ int len = 0;
639+
640+ if (pregpriv)
641+ len += snprintf(page + len, count - len,
642+ "%d\n",
643+ pregpriv->cbw40_enable
644+ );
645+
646+ *eof = 1;
647+ return len;
648+}
649+
650+int proc_set_cbw40_enable(struct file *file, const char __user *buffer,
651+ unsigned long count, void *data)
652+{
653+ struct net_device *dev = (struct net_device *)data;
654+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
655+ struct registry_priv *pregpriv = &padapter->registrypriv;
656+ char tmp[32];
657+ s32 mode = 0;
658+
659+ if (count < 1)
660+ return -EFAULT;
661+
662+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
663+ if (pregpriv) {
664+ pregpriv->cbw40_enable = mode;
665+ pr_info("cbw40_enable=%d\n", mode);
666+ }
667+ }
668+ return count;
669+}
670+
671+int proc_get_ampdu_enable(char *page, char **start,
672+ off_t offset, int count,
673+ int *eof, void *data)
674+{
675+ struct net_device *dev = data;
676+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
677+ struct registry_priv *pregpriv = &padapter->registrypriv;
678+
679+ int len = 0;
680+
681+ if (pregpriv)
682+ len += snprintf(page + len, count - len,
683+ "%d\n",
684+ pregpriv->ampdu_enable
685+ );
686+
687+ *eof = 1;
688+ return len;
689+}
690+
691+int proc_set_ampdu_enable(struct file *file, const char __user *buffer,
692+ unsigned long count, void *data)
693+{
694+ struct net_device *dev = (struct net_device *)data;
695+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
696+ struct registry_priv *pregpriv = &padapter->registrypriv;
697+ char tmp[32];
698+ s32 mode = 0;
699+
700+ if (count < 1)
701+ return -EFAULT;
702+
703+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
704+ if (pregpriv) {
705+ pregpriv->ampdu_enable = mode;
706+ pr_info("ampdu_enable=%d\n", mode);
707+ }
708+ }
709+ return count;
710+}
711+
712+int proc_get_two_path_rssi(char *page, char **start,
713+ off_t offset, int count,
714+ int *eof, void *data)
715+{
716+ struct net_device *dev = data;
717+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
718+
719+ int len = 0;
720+
721+ if (padapter)
722+ len += snprintf(page + len, count - len,
723+ "%d %d\n",
724+ padapter->recvpriv.RxRssi[0],
725+ padapter->recvpriv.RxRssi[1]
726+ );
727+
728+ *eof = 1;
729+ return len;
730+}
731+
732+int proc_get_rx_stbc(char *page, char **start,
733+ off_t offset, int count,
734+ int *eof, void *data)
735+{
736+ struct net_device *dev = data;
737+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
738+ struct registry_priv *pregpriv = &padapter->registrypriv;
739+
740+ int len = 0;
741+
742+ if (pregpriv)
743+ len += snprintf(page + len, count - len,
744+ "%d\n",
745+ pregpriv->rx_stbc
746+ );
747+
748+ *eof = 1;
749+ return len;
750+}
751+
752+int proc_set_rx_stbc(struct file *file, const char __user *buffer,
753+ unsigned long count, void *data)
754+{
755+ struct net_device *dev = (struct net_device *)data;
756+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
757+ struct registry_priv *pregpriv = &padapter->registrypriv;
758+ char tmp[32];
759+ u32 mode = 0;
760+
761+ if (count < 1)
762+ return -EFAULT;
763+
764+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
765+ if (pregpriv) {
766+ pregpriv->rx_stbc = mode;
767+ printk("rx_stbc=%d\n", mode);
768+ }
769+ }
770+ return count;
771+}
772+
773+int proc_get_rssi_disp(char *page, char **start,
774+ off_t offset, int count,
775+ int *eof, void *data)
776+{
777+ *eof = 1;
778+ return 0;
779+}
780+
781+int proc_set_rssi_disp(struct file *file, const char __user *buffer,
782+ unsigned long count, void *data)
783+{
784+ struct net_device *dev = (struct net_device *)data;
785+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
786+ char tmp[32];
787+ u32 enable = 0;
788+
789+ if (count < 1) {
790+ DBG_88E("argument size is less than 1\n");
791+ return -EFAULT;
792+ }
793+
794+ if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
795+ int num = sscanf(tmp, "%x", &enable);
796+
797+ if (num != 1) {
798+ DBG_88E("invalid set_rssi_disp parameter!\n");
799+ return count;
800+ }
801+
802+ if (enable) {
803+ DBG_88E("Turn On Rx RSSI Display Function\n");
804+ padapter->bRxRSSIDisplay = enable;
805+ } else {
806+ DBG_88E("Turn Off Rx RSSI Display Function\n");
807+ padapter->bRxRSSIDisplay = 0;
808+ }
809+ }
810+ return count;
811+}
812+
813+#ifdef CONFIG_88EU_AP_MODE
814+
815+int proc_get_all_sta_info(char *page, char **start,
816+ off_t offset, int count,
817+ int *eof, void *data)
818+{
819+ struct sta_info *psta;
820+ struct net_device *dev = data;
821+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
822+ struct sta_priv *pstapriv = &padapter->stapriv;
823+ int i, j;
824+ struct list_head *plist, *phead;
825+ struct recv_reorder_ctrl *preorder_ctrl;
826+ int len = 0;
827+
828+ len += snprintf(page + len, count - len, "sta_dz_bitmap=0x%x, tim_bitmap=0x%x\n", pstapriv->sta_dz_bitmap, pstapriv->tim_bitmap);
829+
830+ spin_lock_bh(&pstapriv->sta_hash_lock);
831+
832+ for (i = 0; i < NUM_STA; i++) {
833+ phead = &pstapriv->sta_hash[i];
834+ plist = phead->next;
835+
836+ while (phead != plist) {
837+ psta = container_of(plist, struct sta_info, hash_list);
838+
839+ plist = plist->next;
840+
841+ len += snprintf(page + len, count - len, "sta's macaddr: %pM\n", psta->hwaddr);
842+ len += snprintf(page + len, count - len, "rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
843+ len += snprintf(page + len, count - len, "state=0x%x, aid=%d, macid=%d, raid=%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
844+ len += snprintf(page + len, count - len, "qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
845+ len += snprintf(page + len, count - len, "bwmode=%d, ch_offset=%d, sgi=%d\n", psta->htpriv.bwmode, psta->htpriv.ch_offset, psta->htpriv.sgi);
846+ len += snprintf(page + len, count - len, "ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
847+ len += snprintf(page + len, count - len, "agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
848+ len += snprintf(page + len, count - len, "sleepq_len=%d\n", psta->sleepq_len);
849+ len += snprintf(page + len, count - len, "capability=0x%x\n", psta->capability);
850+ len += snprintf(page + len, count - len, "flags=0x%x\n", psta->flags);
851+ len += snprintf(page + len, count - len, "wpa_psk=0x%x\n", psta->wpa_psk);
852+ len += snprintf(page + len, count - len, "wpa2_group_cipher=0x%x\n", psta->wpa2_group_cipher);
853+ len += snprintf(page + len, count - len, "wpa2_pairwise_cipher=0x%x\n", psta->wpa2_pairwise_cipher);
854+ len += snprintf(page + len, count - len, "qos_info=0x%x\n", psta->qos_info);
855+ len += snprintf(page + len, count - len, "dot118021XPrivacy=0x%x\n", psta->dot118021XPrivacy);
856+
857+ for (j = 0; j < 16; j++) {
858+ preorder_ctrl = &psta->recvreorder_ctrl[j];
859+ if (preorder_ctrl->enable)
860+ len += snprintf(page + len, count - len, "tid=%d, indicate_seq=%d\n", j, preorder_ctrl->indicate_seq);
861+ }
862+ }
863+ }
864+ spin_unlock_bh(&pstapriv->sta_hash_lock);
865+
866+ *eof = 1;
867+ return len;
868+}
869+#endif
870+
871+int proc_get_best_channel(char *page, char **start,
872+ off_t offset, int count,
873+ int *eof, void *data)
874+{
875+ struct net_device *dev = data;
876+ struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
877+ struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
878+ int len = 0;
879+ u32 i, best_channel_24G = 1, index_24G = 0;
880+
881+ for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
882+ if (pmlmeext->channel_set[i].ChannelNum == 1)
883+ index_24G = i;
884+ }
885+
886+ for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
887+ /* 2.4G */
888+ if (pmlmeext->channel_set[i].ChannelNum == 6) {
889+ if (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_24G].rx_count) {
890+ index_24G = i;
891+ best_channel_24G = pmlmeext->channel_set[i].ChannelNum;
892+ }
893+ }
894+
895+ /* debug */
896+ len += snprintf(page + len, count - len, "The rx cnt of channel %3d = %d\n",
897+ pmlmeext->channel_set[i].ChannelNum, pmlmeext->channel_set[i].rx_count);
898+ }
899+
900+ len += snprintf(page + len, count - len, "best_channel_24G = %d\n", best_channel_24G);
901+
902+ *eof = 1;
903+ return len;
904+}
drivers/staging/r8188eu/core/rtw_efuse.c+848−0
@@ -0,0 +1,848 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2011 Realtek Corporation. */
3+
4+#define _RTW_EFUSE_C_
5+
6+#include "../include/osdep_service.h"
7+#include "../include/drv_types.h"
8+#include "../include/rtw_efuse.h"
9+
10+/*------------------------Define local variable------------------------------*/
11+u8 fakeEfuseBank;
12+u32 fakeEfuseUsedBytes;
13+u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE] = {0};
14+u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN] = {0};
15+u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN] = {0};
16+
17+u32 BTEfuseUsedBytes;
18+u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
19+u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN] = {0};
20+u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN] = {0};
21+
22+u32 fakeBTEfuseUsedBytes;
23+u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
24+u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN] = {0};
25+u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN] = {0};
26+/*------------------------Define local variable------------------------------*/
27+
28+/* */
29+#define REG_EFUSE_CTRL 0x0030
30+#define EFUSE_CTRL REG_EFUSE_CTRL /* E-Fuse Control. */
31+/* */
32+static bool Efuse_Read1ByteFromFakeContent(struct adapter *pAdapter,
33+ u16 Offset,
34+ u8 *Value)
35+{
36+ if (Offset >= EFUSE_MAX_HW_SIZE)
37+ return false;
38+ if (fakeEfuseBank == 0)
39+ *Value = fakeEfuseContent[Offset];
40+ else
41+ *Value = fakeBTEfuseContent[fakeEfuseBank - 1][Offset];
42+ return true;
43+}
44+
45+static bool
46+Efuse_Write1ByteToFakeContent(
47+ struct adapter *pAdapter,
48+ u16 Offset,
49+ u8 Value)
50+{
51+ if (Offset >= EFUSE_MAX_HW_SIZE)
52+ return false;
53+ if (fakeEfuseBank == 0) {
54+ fakeEfuseContent[Offset] = Value;
55+ } else {
56+ fakeBTEfuseContent[fakeEfuseBank - 1][Offset] = Value;
57+ }
58+ return true;
59+}
60+
61+/*-----------------------------------------------------------------------------
62+ * Function: Efuse_PowerSwitch
63+ *
64+ * Overview: When we want to enable write operation, we should change to
65+ * pwr on state. When we stop write, we should switch to 500k mode
66+ * and disable LDO 2.5V.
67+ *
68+ * Input: NONE
69+ *
70+ * Output: NONE
71+ *
72+ * Return: NONE
73+ *
74+ * Revised History:
75+ * When Who Remark
76+ * 11/17/2008 MHC Create Version 0.
77+ *
78+ *---------------------------------------------------------------------------*/
79+void
80+Efuse_PowerSwitch(
81+ struct adapter *pAdapter,
82+ u8 write,
83+ u8 PwrState)
84+{
85+ pAdapter->HalFunc.EfusePowerSwitch(pAdapter, write, PwrState);
86+}
87+
88+/*-----------------------------------------------------------------------------
89+ * Function: efuse_GetCurrentSize
90+ *
91+ * Overview: Get current efuse size!!!
92+ *
93+ * Input: NONE
94+ *
95+ * Output: NONE
96+ *
97+ * Return: NONE
98+ *
99+ * Revised History:
100+ * When Who Remark
101+ * 11/16/2008 MHC Create Version 0.
102+ *
103+ *---------------------------------------------------------------------------*/
104+u16
105+Efuse_GetCurrentSize(
106+ struct adapter *pAdapter,
107+ u8 efuseType,
108+ bool pseudo)
109+{
110+ u16 ret = 0;
111+
112+ ret = pAdapter->HalFunc.EfuseGetCurrentSize(pAdapter, efuseType, pseudo);
113+
114+ return ret;
115+}
116+
117+/* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */
118+u8
119+Efuse_CalculateWordCnts(u8 word_en)
120+{
121+ u8 word_cnts = 0;
122+ if (!(word_en & BIT(0)))
123+ word_cnts++; /* 0 : write enable */
124+ if (!(word_en & BIT(1)))
125+ word_cnts++;
126+ if (!(word_en & BIT(2)))
127+ word_cnts++;
128+ if (!(word_en & BIT(3)))
129+ word_cnts++;
130+ return word_cnts;
131+}
132+
133+/* */
134+/* Description: */
135+/* Execute E-Fuse read byte operation. */
136+/* Referred from SD1 Richard. */
137+/* */
138+/* Assumption: */
139+/* 1. Boot from E-Fuse and successfully auto-load. */
140+/* 2. PASSIVE_LEVEL (USB interface) */
141+/* */
142+/* Created by Roger, 2008.10.21. */
143+/* */
144+void
145+ReadEFuseByte(
146+ struct adapter *Adapter,
147+ u16 _offset,
148+ u8 *pbuf,
149+ bool pseudo)
150+{
151+ u32 value32;
152+ u8 readbyte;
153+ u16 retry;
154+
155+ if (pseudo) {
156+ Efuse_Read1ByteFromFakeContent(Adapter, _offset, pbuf);
157+ return;
158+ }
159+
160+ /* Write Address */
161+ rtw_write8(Adapter, EFUSE_CTRL + 1, (_offset & 0xff));
162+ readbyte = rtw_read8(Adapter, EFUSE_CTRL + 2);
163+ rtw_write8(Adapter, EFUSE_CTRL + 2, ((_offset >> 8) & 0x03) | (readbyte & 0xfc));
164+
165+ /* Write bit 32 0 */
166+ readbyte = rtw_read8(Adapter, EFUSE_CTRL + 3);
167+ rtw_write8(Adapter, EFUSE_CTRL + 3, (readbyte & 0x7f));
168+
169+ /* Check bit 32 read-ready */
170+ retry = 0;
171+ value32 = rtw_read32(Adapter, EFUSE_CTRL);
172+ while (!(((value32 >> 24) & 0xff) & 0x80) && (retry < 10000)) {
173+ value32 = rtw_read32(Adapter, EFUSE_CTRL);
174+ retry++;
175+ }
176+
177+ /* 20100205 Joseph: Add delay suggested by SD1 Victor. */
178+ /* This fix the problem that Efuse read error in high temperature condition. */
179+ /* Designer says that there shall be some delay after ready bit is set, or the */
180+ /* result will always stay on last data we read. */
181+ udelay(50);
182+ value32 = rtw_read32(Adapter, EFUSE_CTRL);
183+
184+ *pbuf = (u8)(value32 & 0xff);
185+}
186+
187+/* */
188+/* Description: */
189+/* 1. Execute E-Fuse read byte operation according as map offset and */
190+/* save to E-Fuse table. */
191+/* 2. Referred from SD1 Richard. */
192+/* */
193+/* Assumption: */
194+/* 1. Boot from E-Fuse and successfully auto-load. */
195+/* 2. PASSIVE_LEVEL (USB interface) */
196+/* */
197+/* Created by Roger, 2008.10.21. */
198+/* */
199+/* 2008/12/12 MH 1. Reorganize code flow and reserve bytes. and add description. */
200+/* 2. Add efuse utilization collect. */
201+/* 2008/12/22 MH Read Efuse must check if we write section 1 data again!!! Sec1 */
202+/* write addr must be after sec5. */
203+/* */
204+
205+static void efuse_ReadEFuse(struct adapter *Adapter, u8 efuseType, u16 _offset, u16 _size_byte, u8 *pbuf, bool pseudo)
206+{
207+ Adapter->HalFunc.ReadEFuse(Adapter, efuseType, _offset, _size_byte, pbuf, pseudo);
208+}
209+
210+void EFUSE_GetEfuseDefinition(struct adapter *pAdapter, u8 efuseType, u8 type, void *pOut, bool pseudo
211+ )
212+{
213+ pAdapter->HalFunc.EFUSEGetEfuseDefinition(pAdapter, efuseType, type, pOut, pseudo);
214+}
215+
216+/*-----------------------------------------------------------------------------
217+ * Function: EFUSE_Read1Byte
218+ *
219+ * Overview: Copy from WMAC fot EFUSE read 1 byte.
220+ *
221+ * Input: NONE
222+ *
223+ * Output: NONE
224+ *
225+ * Return: NONE
226+ *
227+ * Revised History:
228+ * When Who Remark
229+ * 09/23/2008 MHC Copy from WMAC.
230+ *
231+ *---------------------------------------------------------------------------*/
232+u8 EFUSE_Read1Byte(struct adapter *Adapter, u16 Address)
233+{
234+ u8 data;
235+ u8 Bytetemp = {0x00};
236+ u8 temp = {0x00};
237+ u32 k = 0;
238+ u16 contentLen = 0;
239+
240+ EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&contentLen, false);
241+
242+ if (Address < contentLen) { /* E-fuse 512Byte */
243+ /* Write E-fuse Register address bit0~7 */
244+ temp = Address & 0xFF;
245+ rtw_write8(Adapter, EFUSE_CTRL + 1, temp);
246+ Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 2);
247+ /* Write E-fuse Register address bit8~9 */
248+ temp = ((Address >> 8) & 0x03) | (Bytetemp & 0xFC);
249+ rtw_write8(Adapter, EFUSE_CTRL + 2, temp);
250+
251+ /* Write 0x30[31]= 0 */
252+ Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 3);
253+ temp = Bytetemp & 0x7F;
254+ rtw_write8(Adapter, EFUSE_CTRL + 3, temp);
255+
256+ /* Wait Write-ready (0x30[31]= 1) */
257+ Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 3);
258+ while (!(Bytetemp & 0x80)) {
259+ Bytetemp = rtw_read8(Adapter, EFUSE_CTRL + 3);
260+ k++;
261+ if (k == 1000) {
262+ k = 0;
263+ break;
264+ }
265+ }
266+ data = rtw_read8(Adapter, EFUSE_CTRL);
267+ return data;
268+ } else {
269+ return 0xFF;
270+ }
271+
272+} /* EFUSE_Read1Byte */
273+
274+/* 11/16/2008 MH Read one byte from real Efuse. */
275+u8 efuse_OneByteRead(struct adapter *pAdapter, u16 addr, u8 *data, bool pseudo)
276+{
277+ u8 tmpidx = 0;
278+ u8 result;
279+
280+ if (pseudo) {
281+ result = Efuse_Read1ByteFromFakeContent(pAdapter, addr, data);
282+ return result;
283+ }
284+ /* -----------------e-fuse reg ctrl --------------------------------- */
285+ /* address */
286+ rtw_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
287+ rtw_write8(pAdapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
288+ (rtw_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC));
289+
290+ rtw_write8(pAdapter, EFUSE_CTRL + 3, 0x72);/* read cmd */
291+
292+ while (!(0x80 & rtw_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 100))
293+ tmpidx++;
294+ if (tmpidx < 100) {
295+ *data = rtw_read8(pAdapter, EFUSE_CTRL);
296+ result = true;
297+ } else {
298+ *data = 0xff;
299+ result = false;
300+ }
301+ return result;
302+}
303+
304+/* 11/16/2008 MH Write one byte to reald Efuse. */
305+u8 efuse_OneByteWrite(struct adapter *pAdapter, u16 addr, u8 data, bool pseudo)
306+{
307+ u8 tmpidx = 0;
308+ u8 result;
309+
310+ if (pseudo) {
311+ result = Efuse_Write1ByteToFakeContent(pAdapter, addr, data);
312+ return result;
313+ }
314+
315+ /* -----------------e-fuse reg ctrl --------------------------------- */
316+ /* address */
317+ rtw_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
318+ rtw_write8(pAdapter, EFUSE_CTRL + 2,
319+ (rtw_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC) |
320+ (u8)((addr >> 8) & 0x03));
321+ rtw_write8(pAdapter, EFUSE_CTRL, data);/* data */
322+
323+ rtw_write8(pAdapter, EFUSE_CTRL + 3, 0xF2);/* write cmd */
324+
325+ while ((0x80 & rtw_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 100))
326+ tmpidx++;
327+
328+ if (tmpidx < 100)
329+ result = true;
330+ else
331+ result = false;
332+
333+ return result;
334+}
335+
336+int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data, bool pseudo)
337+{
338+ int ret = 0;
339+
340+ ret = pAdapter->HalFunc.Efuse_PgPacketRead(pAdapter, offset, data, pseudo);
341+
342+ return ret;
343+}
344+
345+int Efuse_PgPacketWrite(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *data, bool pseudo)
346+{
347+ int ret;
348+
349+ ret = pAdapter->HalFunc.Efuse_PgPacketWrite(pAdapter, offset, word_en, data, pseudo);
350+
351+ return ret;
352+}
353+
354+static int Efuse_PgPacketWrite_BT(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *data, bool pseudo)
355+{
356+ int ret;
357+
358+ ret = pAdapter->HalFunc.Efuse_PgPacketWrite_BT(pAdapter, offset, word_en, data, pseudo);
359+
360+ return ret;
361+}
362+
363+/*-----------------------------------------------------------------------------
364+ * Function: efuse_WordEnableDataRead
365+ *
366+ * Overview: Read allowed word in current efuse section data.
367+ *
368+ * Input: NONE
369+ *
370+ * Output: NONE
371+ *
372+ * Return: NONE
373+ *
374+ * Revised History:
375+ * When Who Remark
376+ * 11/16/2008 MHC Create Version 0.
377+ * 11/21/2008 MHC Fix Write bug when we only enable late word.
378+ *
379+ *---------------------------------------------------------------------------*/
380+void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata)
381+{
382+ if (!(word_en & BIT(0))) {
383+ targetdata[0] = sourdata[0];
384+ targetdata[1] = sourdata[1];
385+ }
386+ if (!(word_en & BIT(1))) {
387+ targetdata[2] = sourdata[2];
388+ targetdata[3] = sourdata[3];
389+ }
390+ if (!(word_en & BIT(2))) {
391+ targetdata[4] = sourdata[4];
392+ targetdata[5] = sourdata[5];
393+ }
394+ if (!(word_en & BIT(3))) {
395+ targetdata[6] = sourdata[6];
396+ targetdata[7] = sourdata[7];
397+ }
398+}
399+
400+u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_en, u8 *data, bool pseudo)
401+{
402+ u8 ret = 0;
403+
404+ ret = pAdapter->HalFunc.Efuse_WordEnableDataWrite(pAdapter, efuse_addr, word_en, data, pseudo);
405+
406+ return ret;
407+}
408+
409+static u8 efuse_read8(struct adapter *padapter, u16 address, u8 *value)
410+{
411+ return efuse_OneByteRead(padapter, address, value, false);
412+}
413+
414+static u8 efuse_write8(struct adapter *padapter, u16 address, u8 *value)
415+{
416+ return efuse_OneByteWrite(padapter, address, *value, false);
417+}
418+
419+/*
420+ * read/wirte raw efuse data
421+ */
422+u8 rtw_efuse_access(struct adapter *padapter, u8 write, u16 start_addr, u16 cnts, u8 *data)
423+{
424+ int i = 0;
425+ u16 real_content_len = 0, max_available_size = 0;
426+ u8 res = _FAIL;
427+ u8 (*rw8)(struct adapter *, u16, u8*);
428+
429+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&real_content_len, false);
430+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
431+
432+ if (start_addr > real_content_len)
433+ return _FAIL;
434+
435+ if (write) {
436+ if ((start_addr + cnts) > max_available_size)
437+ return _FAIL;
438+ rw8 = &efuse_write8;
439+ } else {
440+ rw8 = &efuse_read8;
441+ }
442+
443+ Efuse_PowerSwitch(padapter, write, true);
444+
445+ /* e-fuse one byte read / write */
446+ for (i = 0; i < cnts; i++) {
447+ if (start_addr >= real_content_len) {
448+ res = _FAIL;
449+ break;
450+ }
451+
452+ res = rw8(padapter, start_addr++, data++);
453+ if (_FAIL == res)
454+ break;
455+ }
456+
457+ Efuse_PowerSwitch(padapter, write, false);
458+
459+ return res;
460+}
461+/* */
462+u16 efuse_GetMaxSize(struct adapter *padapter)
463+{
464+ u16 max_size;
465+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_size, false);
466+ return max_size;
467+}
468+/* */
469+u8 efuse_GetCurrentSize(struct adapter *padapter, u16 *size)
470+{
471+ Efuse_PowerSwitch(padapter, false, true);
472+ *size = Efuse_GetCurrentSize(padapter, EFUSE_WIFI, false);
473+ Efuse_PowerSwitch(padapter, false, false);
474+
475+ return _SUCCESS;
476+}
477+/* */
478+u8 rtw_efuse_map_read(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
479+{
480+ u16 mapLen = 0;
481+
482+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
483+
484+ if ((addr + cnts) > mapLen)
485+ return _FAIL;
486+
487+ Efuse_PowerSwitch(padapter, false, true);
488+
489+ efuse_ReadEFuse(padapter, EFUSE_WIFI, addr, cnts, data, false);
490+
491+ Efuse_PowerSwitch(padapter, false, false);
492+
493+ return _SUCCESS;
494+}
495+
496+u8 rtw_BT_efuse_map_read(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
497+{
498+ u16 mapLen = 0;
499+
500+ EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
501+
502+ if ((addr + cnts) > mapLen)
503+ return _FAIL;
504+
505+ Efuse_PowerSwitch(padapter, false, true);
506+
507+ efuse_ReadEFuse(padapter, EFUSE_BT, addr, cnts, data, false);
508+
509+ Efuse_PowerSwitch(padapter, false, false);
510+
511+ return _SUCCESS;
512+}
513+/* */
514+u8 rtw_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
515+{
516+ u8 offset, word_en;
517+ u8 *map;
518+ u8 newdata[PGPKT_DATA_SIZE + 1];
519+ s32 i, idx;
520+ u8 ret = _SUCCESS;
521+ u16 mapLen = 0;
522+
523+ EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
524+
525+ if ((addr + cnts) > mapLen)
526+ return _FAIL;
527+
528+ map = kzalloc(mapLen, GFP_KERNEL);
529+ if (!map)
530+ return _FAIL;
531+
532+ ret = rtw_efuse_map_read(padapter, 0, mapLen, map);
533+ if (ret == _FAIL)
534+ goto exit;
535+
536+ Efuse_PowerSwitch(padapter, true, true);
537+
538+ offset = (addr >> 3);
539+ word_en = 0xF;
540+ memset(newdata, 0xFF, PGPKT_DATA_SIZE + 1);
541+ i = addr & 0x7; /* index of one package */
542+ idx = 0; /* data index */
543+
544+ if (i & 0x1) {
545+ /* odd start */
546+ if (data[idx] != map[addr + idx]) {
547+ word_en &= ~BIT(i >> 1);
548+ newdata[i - 1] = map[addr + idx - 1];
549+ newdata[i] = data[idx];
550+ }
551+ i++;
552+ idx++;
553+ }
554+ do {
555+ for (; i < PGPKT_DATA_SIZE; i += 2) {
556+ if (cnts == idx)
557+ break;
558+ if ((cnts - idx) == 1) {
559+ if (data[idx] != map[addr + idx]) {
560+ word_en &= ~BIT(i >> 1);
561+ newdata[i] = data[idx];
562+ newdata[i + 1] = map[addr + idx + 1];
563+ }
564+ idx++;
565+ break;
566+ } else {
567+ if ((data[idx] != map[addr + idx]) ||
568+ (data[idx + 1] != map[addr + idx + 1])) {
569+ word_en &= ~BIT(i >> 1);
570+ newdata[i] = data[idx];
571+ newdata[i + 1] = data[idx + 1];
572+ }
573+ idx += 2;
574+ }
575+ if (idx == cnts)
576+ break;
577+ }
578+
579+ if (word_en != 0xF) {
580+ ret = Efuse_PgPacketWrite(padapter, offset, word_en, newdata, false);
581+ DBG_88E("offset=%x\n", offset);
582+ DBG_88E("word_en=%x\n", word_en);
583+
584+ for (i = 0; i < PGPKT_DATA_SIZE; i++)
585+ DBG_88E("data=%x \t", newdata[i]);
586+ if (ret == _FAIL)
587+ break;
588+ }
589+
590+ if (idx == cnts)
591+ break;
592+
593+ offset++;
594+ i = 0;
595+ word_en = 0xF;
596+ memset(newdata, 0xFF, PGPKT_DATA_SIZE);
597+ } while (1);
598+
599+ Efuse_PowerSwitch(padapter, true, false);
600+exit:
601+ kfree(map);
602+ return ret;
603+}
604+
605+/* */
606+u8 rtw_BT_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
607+{
608+ u8 offset, word_en;
609+ u8 *map;
610+ u8 newdata[PGPKT_DATA_SIZE + 1];
611+ s32 i, idx;
612+ u8 ret = _SUCCESS;
613+ u16 mapLen = 0;
614+
615+ EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, false);
616+
617+ if ((addr + cnts) > mapLen)
618+ return _FAIL;
619+
620+ map = kzalloc(mapLen, GFP_KERNEL);
621+ if (!map)
622+ return _FAIL;
623+
624+ ret = rtw_BT_efuse_map_read(padapter, 0, mapLen, map);
625+ if (ret == _FAIL)
626+ goto exit;
627+
628+ Efuse_PowerSwitch(padapter, true, true);
629+
630+ offset = (addr >> 3);
631+ word_en = 0xF;
632+ memset(newdata, 0xFF, PGPKT_DATA_SIZE + 1);
633+ i = addr & 0x7; /* index of one package */
634+ idx = 0; /* data index */
635+
636+ if (i & 0x1) {
637+ /* odd start */
638+ if (data[idx] != map[addr + idx]) {
639+ word_en &= ~BIT(i >> 1);
640+ newdata[i - 1] = map[addr + idx - 1];
641+ newdata[i] = data[idx];
642+ }
643+ i++;
644+ idx++;
645+ }
646+ do {
647+ for (; i < PGPKT_DATA_SIZE; i += 2) {
648+ if (cnts == idx)
649+ break;
650+ if ((cnts - idx) == 1) {
651+ if (data[idx] != map[addr + idx]) {
652+ word_en &= ~BIT(i >> 1);
653+ newdata[i] = data[idx];
654+ newdata[i + 1] = map[addr + idx + 1];
655+ }
656+ idx++;
657+ break;
658+ } else {
659+ if ((data[idx] != map[addr + idx]) ||
660+ (data[idx + 1] != map[addr + idx + 1])) {
661+ word_en &= ~BIT(i >> 1);
662+ newdata[i] = data[idx];
663+ newdata[i + 1] = data[idx + 1];
664+ }
665+ idx += 2;
666+ }
667+ if (idx == cnts)
668+ break;
669+ }
670+
671+ if (word_en != 0xF) {
672+ DBG_88E("%s: offset=%#X\n", __func__, offset);
673+ DBG_88E("%s: word_en=%#X\n", __func__, word_en);
674+ DBG_88E("%s: data=", __func__);
675+ for (i = 0; i < PGPKT_DATA_SIZE; i++)
676+ DBG_88E("0x%02X ", newdata[i]);
677+ DBG_88E("\n");
678+
679+ ret = Efuse_PgPacketWrite_BT(padapter, offset, word_en, newdata, false);
680+ if (ret == _FAIL)
681+ break;
682+ }
683+
684+ if (idx == cnts)
685+ break;
686+
687+ offset++;
688+ i = 0;
689+ word_en = 0xF;
690+ memset(newdata, 0xFF, PGPKT_DATA_SIZE);
691+ } while (1);
692+
693+ Efuse_PowerSwitch(padapter, true, false);
694+
695+exit:
696+
697+ kfree(map);
698+
699+ return ret;
700+}
701+
702+/*-----------------------------------------------------------------------------
703+ * Function: efuse_ShadowRead1Byte
704+ * efuse_ShadowRead2Byte
705+ * efuse_ShadowRead4Byte
706+ *
707+ * Overview: Read from efuse init map by one/two/four bytes !!!!!
708+ *
709+ * Input: NONE
710+ *
711+ * Output: NONE
712+ *
713+ * Return: NONE
714+ *
715+ * Revised History:
716+ * When Who Remark
717+ * 11/12/2008 MHC Create Version 0.
718+ *
719+ *---------------------------------------------------------------------------*/
720+static void
721+efuse_ShadowRead1Byte(
722+ struct adapter *pAdapter,
723+ u16 Offset,
724+ u8 *Value)
725+{
726+ struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
727+
728+ *Value = pEEPROM->efuse_eeprom_data[Offset];
729+
730+} /* EFUSE_ShadowRead1Byte */
731+
732+/* Read Two Bytes */
733+static void
734+efuse_ShadowRead2Byte(
735+ struct adapter *pAdapter,
736+ u16 Offset,
737+ u16 *Value)
738+{
739+ struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
740+
741+ *Value = pEEPROM->efuse_eeprom_data[Offset];
742+ *Value |= pEEPROM->efuse_eeprom_data[Offset + 1] << 8;
743+
744+} /* EFUSE_ShadowRead2Byte */
745+
746+/* Read Four Bytes */
747+static void
748+efuse_ShadowRead4Byte(
749+ struct adapter *pAdapter,
750+ u16 Offset,
751+ u32 *Value)
752+{
753+ struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
754+
755+ *Value = pEEPROM->efuse_eeprom_data[Offset];
756+ *Value |= pEEPROM->efuse_eeprom_data[Offset + 1] << 8;
757+ *Value |= pEEPROM->efuse_eeprom_data[Offset + 2] << 16;
758+ *Value |= pEEPROM->efuse_eeprom_data[Offset + 3] << 24;
759+
760+} /* efuse_ShadowRead4Byte */
761+
762+/*-----------------------------------------------------------------------------
763+ * Function: Efuse_ReadAllMap
764+ *
765+ * Overview: Read All Efuse content
766+ *
767+ * Input: NONE
768+ *
769+ * Output: NONE
770+ *
771+ * Return: NONE
772+ *
773+ * Revised History:
774+ * When Who Remark
775+ * 11/11/2008 MHC Create Version 0.
776+ *
777+ *---------------------------------------------------------------------------*/
778+static void Efuse_ReadAllMap(struct adapter *pAdapter, u8 efuseType, u8 *Efuse, bool pseudo)
779+{
780+ u16 mapLen = 0;
781+
782+ Efuse_PowerSwitch(pAdapter, false, true);
783+
784+ EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, pseudo);
785+
786+ efuse_ReadEFuse(pAdapter, efuseType, 0, mapLen, Efuse, pseudo);
787+
788+ Efuse_PowerSwitch(pAdapter, false, false);
789+}
790+
791+/*-----------------------------------------------------------------------------
792+ * Function: EFUSE_ShadowMapUpdate
793+ *
794+ * Overview: Transfer current EFUSE content to shadow init and modify map.
795+ *
796+ * Input: NONE
797+ *
798+ * Output: NONE
799+ *
800+ * Return: NONE
801+ *
802+ * Revised History:
803+ * When Who Remark
804+ * 11/13/2008 MHC Create Version 0.
805+ *
806+ *---------------------------------------------------------------------------*/
807+void EFUSE_ShadowMapUpdate(
808+ struct adapter *pAdapter,
809+ u8 efuseType,
810+ bool pseudo)
811+{
812+ struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
813+ u16 mapLen = 0;
814+
815+ EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, pseudo);
816+
817+ if (pEEPROM->bautoload_fail_flag)
818+ memset(pEEPROM->efuse_eeprom_data, 0xFF, mapLen);
819+ else
820+ Efuse_ReadAllMap(pAdapter, efuseType, pEEPROM->efuse_eeprom_data, pseudo);
821+} /* EFUSE_ShadowMapUpdate */
822+
823+/*-----------------------------------------------------------------------------
824+ * Function: EFUSE_ShadowRead
825+ *
826+ * Overview: Read from efuse init map !!!!!
827+ *
828+ * Input: NONE
829+ *
830+ * Output: NONE
831+ *
832+ * Return: NONE
833+ *
834+ * Revised History:
835+ * When Who Remark
836+ * 11/12/2008 MHC Create Version 0.
837+ *
838+ *---------------------------------------------------------------------------*/
839+void EFUSE_ShadowRead(struct adapter *pAdapter, u8 Type, u16 Offset, u32 *Value)
840+{
841+ if (Type == 1)
842+ efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
843+ else if (Type == 2)
844+ efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
845+ else if (Type == 4)
846+ efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
847+
848+} /* EFUSE_ShadowRead */
drivers/staging/r8188eu/core/rtw_ieee80211.c+1539−0
@@ -0,0 +1,1539 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2011 Realtek Corporation. */
3+
4+#define _IEEE80211_C
5+
6+#include "../include/drv_types.h"
7+#include "../include/ieee80211.h"
8+#include "../include/wifi.h"
9+#include "../include/osdep_service.h"
10+#include "../include/wlan_bssdef.h"
11+#include "../include/usb_osintf.h"
12+
13+u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
14+u16 RTW_WPA_VERSION = 1;
15+u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };
16+u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };
17+u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };
18+u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };
19+u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };
20+u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };
21+u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };
22+u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };
23+u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };
24+
25+u16 RSN_VERSION_BSD = 1;
26+u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 };
27+u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 };
28+u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };
29+u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };
30+u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };
31+u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };
32+u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };
33+u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };
34+/* */
35+/* for adhoc-master to generate ie and provide supported-rate to fw */
36+/* */
37+
38+static u8 WIFI_CCKRATES[] = {
39+ (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
40+ (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
41+ (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
42+ (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)
43+ };
44+
45+static u8 WIFI_OFDMRATES[] = {
46+ (IEEE80211_OFDM_RATE_6MB),
47+ (IEEE80211_OFDM_RATE_9MB),
48+ (IEEE80211_OFDM_RATE_12MB),
49+ (IEEE80211_OFDM_RATE_18MB),
50+ (IEEE80211_OFDM_RATE_24MB),
51+ IEEE80211_OFDM_RATE_36MB,
52+ IEEE80211_OFDM_RATE_48MB,
53+ IEEE80211_OFDM_RATE_54MB
54+ };
55+
56+int rtw_get_bit_value_from_ieee_value(u8 val)
57+{
58+ unsigned char dot11_rate_table[] = {
59+ 2, 4, 11, 22, 12, 18, 24, 36, 48,
60+ 72, 96, 108, 0}; /* last element must be zero!! */
61+
62+ int i = 0;
63+ while (dot11_rate_table[i] != 0) {
64+ if (dot11_rate_table[i] == val)
65+ return BIT(i);
66+ i++;
67+ }
68+ return 0;
69+}
70+
71+uint rtw_is_cckrates_included(u8 *rate)
72+{
73+ u32 i = 0;
74+
75+ while (rate[i] != 0) {
76+ if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
77+ (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
78+ return true;
79+ i++;
80+ }
81+ return false;
82+}
83+
84+uint rtw_is_cckratesonly_included(u8 *rate)
85+{
86+ u32 i = 0;
87+
88+ while (rate[i] != 0) {
89+ if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
90+ (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
91+ return false;
92+ i++;
93+ }
94+
95+ return true;
96+}
97+
98+int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
99+{
100+ if (channel > 14) {
101+ return WIRELESS_INVALID;
102+ } else { /* could be pure B, pure G, or B/G */
103+ if (rtw_is_cckratesonly_included(rate))
104+ return WIRELESS_11B;
105+ else if (rtw_is_cckrates_included(rate))
106+ return WIRELESS_11BG;
107+ else
108+ return WIRELESS_11G;
109+ }
110+}
111+
112+u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
113+ unsigned int *frlen)
114+{
115+ memcpy((void *)pbuf, (void *)source, len);
116+ *frlen = *frlen + len;
117+ return pbuf + len;
118+}
119+
120+/* rtw_set_ie will update frame length */
121+u8 *rtw_set_ie
122+(
123+ u8 *pbuf,
124+ int index,
125+ uint len,
126+ u8 *source,
127+ uint *frlen /* frame length */
128+)
129+{
130+
131+ *pbuf = (u8)index;
132+
133+ *(pbuf + 1) = (u8)len;
134+
135+ if (len > 0)
136+ memcpy((void *)(pbuf + 2), (void *)source, len);
137+
138+ *frlen = *frlen + (len + 2);
139+
140+ return pbuf + len + 2;
141+}
142+
143+inline u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode,
144+ u8 new_ch, u8 ch_switch_cnt)
145+{
146+ u8 ie_data[3];
147+
148+ ie_data[0] = ch_switch_mode;
149+ ie_data[1] = new_ch;
150+ ie_data[2] = ch_switch_cnt;
151+ return rtw_set_ie(buf, WLAN_EID_CHANNEL_SWITCH, 3, ie_data, buf_len);
152+}
153+
154+inline u8 secondary_ch_offset_to_hal_ch_offset(u8 ch_offset)
155+{
156+ if (ch_offset == SCN)
157+ return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
158+ else if (ch_offset == SCA)
159+ return HAL_PRIME_CHNL_OFFSET_UPPER;
160+ else if (ch_offset == SCB)
161+ return HAL_PRIME_CHNL_OFFSET_LOWER;
162+
163+ return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
164+}
165+
166+inline u8 hal_ch_offset_to_secondary_ch_offset(u8 ch_offset)
167+{
168+ if (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
169+ return SCN;
170+ else if (ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
171+ return SCB;
172+ else if (ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
173+ return SCA;
174+
175+ return SCN;
176+}
177+
178+inline u8 *rtw_set_ie_secondary_ch_offset(u8 *buf, u32 *buf_len, u8 secondary_ch_offset)
179+{
180+ return rtw_set_ie(buf, WLAN_EID_SECONDARY_CHANNEL_OFFSET, 1, &secondary_ch_offset, buf_len);
181+}
182+
183+inline u8 *rtw_set_ie_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl,
184+ u8 flags, u16 reason, u16 precedence)
185+{
186+ u8 ie_data[6];
187+
188+ ie_data[0] = ttl;
189+ ie_data[1] = flags;
190+ *(u16 *)(ie_data + 2) = cpu_to_le16(reason);
191+ *(u16 *)(ie_data + 4) = cpu_to_le16(precedence);
192+
193+ return rtw_set_ie(buf, 0x118, 6, ie_data, buf_len);
194+}
195+
196+/*----------------------------------------------------------------------------
197+index: the information element id index, limit is the limit for search
198+-----------------------------------------------------------------------------*/
199+u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit)
200+{
201+ int tmp, i;
202+ u8 *p;
203+
204+ if (limit < 1) {
205+
206+ return NULL;
207+ }
208+
209+ p = pbuf;
210+ i = 0;
211+ *len = 0;
212+ while (1) {
213+ if (*p == index) {
214+ *len = *(p + 1);
215+ return p;
216+ } else {
217+ tmp = *(p + 1);
218+ p += (tmp + 2);
219+ i += (tmp + 2);
220+ }
221+ if (i >= limit)
222+ break;
223+ }
224+
225+ return NULL;
226+}
227+
228+/**
229+ * rtw_get_ie_ex - Search specific IE from a series of IEs
230+ * @in_ie: Address of IEs to search
231+ * @in_len: Length limit from in_ie
232+ * @eid: Element ID to match
233+ * @oui: OUI to match
234+ * @oui_len: OUI length
235+ * @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE
236+ * @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE
237+ *
238+ * Returns: The address of the specific IE found, or NULL
239+ */
240+u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen)
241+{
242+ uint cnt;
243+ u8 *target_ie = NULL;
244+
245+ if (ielen)
246+ *ielen = 0;
247+
248+ if (!in_ie || in_len <= 0)
249+ return target_ie;
250+
251+ cnt = 0;
252+
253+ while (cnt < in_len) {
254+ if (eid == in_ie[cnt] && (!oui || !memcmp(&in_ie[cnt + 2], oui, oui_len))) {
255+ target_ie = &in_ie[cnt];
256+
257+ if (ie)
258+ memcpy(ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
259+
260+ if (ielen)
261+ *ielen = in_ie[cnt + 1] + 2;
262+
263+ break;
264+ } else {
265+ cnt += in_ie[cnt + 1] + 2; /* goto next */
266+ }
267+ }
268+ return target_ie;
269+}
270+
271+/**
272+ * rtw_ies_remove_ie - Find matching IEs and remove
273+ * @ies: Address of IEs to search
274+ * @ies_len: Pointer of length of ies, will update to new length
275+ * @offset: The offset to start scarch
276+ * @eid: Element ID to match
277+ * @oui: OUI to match
278+ * @oui_len: OUI length
279+ *
280+ * Returns: _SUCCESS: ies is updated, _FAIL: not updated
281+ */
282+int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len)
283+{
284+ int ret = _FAIL;
285+ u8 *target_ie;
286+ u32 target_ielen;
287+ u8 *start;
288+ uint search_len;
289+
290+ if (!ies || !ies_len || *ies_len <= offset)
291+ goto exit;
292+
293+ start = ies + offset;
294+ search_len = *ies_len - offset;
295+
296+ while (1) {
297+ target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen);
298+ if (target_ie && target_ielen) {
299+ u8 buf[MAX_IE_SZ] = {0};
300+ u8 *remain_ies = target_ie + target_ielen;
301+ uint remain_len = search_len - (remain_ies - start);
302+
303+ memcpy(buf, remain_ies, remain_len);
304+ memcpy(target_ie, buf, remain_len);
305+ *ies_len = *ies_len - target_ielen;
306+ ret = _SUCCESS;
307+
308+ start = target_ie;
309+ search_len = remain_len;
310+ } else {
311+ break;
312+ }
313+ }
314+exit:
315+ return ret;
316+}
317+
318+void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
319+{
320+
321+ memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
322+
323+ switch (mode) {
324+ case WIRELESS_11B:
325+ memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
326+ break;
327+ case WIRELESS_11G:
328+ memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
329+ break;
330+ case WIRELESS_11BG:
331+ case WIRELESS_11G_24N:
332+ case WIRELESS_11_24N:
333+ case WIRELESS_11BG_24N:
334+ memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
335+ memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
336+ break;
337+ }
338+
339+}
340+
341+uint rtw_get_rateset_len(u8 *rateset)
342+{
343+ uint i = 0;
344+
345+ while (1) {
346+ if ((rateset[i]) == 0)
347+ break;
348+ if (i > 12)
349+ break;
350+ i++;
351+ }
352+
353+ return i;
354+}
355+
356+int rtw_generate_ie(struct registry_priv *pregistrypriv)
357+{
358+ u8 wireless_mode;
359+ int sz = 0, rateLen;
360+ struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
361+ u8 *ie = pdev_network->IEs;
362+
363+ /* timestamp will be inserted by hardware */
364+ sz += 8;
365+ ie += sz;
366+
367+ /* beacon interval : 2bytes */
368+ *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);/* BCN_INTERVAL; */
369+ sz += 2;
370+ ie += 2;
371+
372+ /* capability info */
373+ *(u16 *)ie = 0;
374+
375+ *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
376+
377+ if (pregistrypriv->preamble == PREAMBLE_SHORT)
378+ *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
379+
380+ if (pdev_network->Privacy)
381+ *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
382+
383+ sz += 2;
384+ ie += 2;
385+
386+ /* SSID */
387+ ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);
388+
389+ /* supported rates */
390+ wireless_mode = pregistrypriv->wireless_mode;
391+
392+ rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode);
393+
394+ rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
395+
396+ if (rateLen > 8) {
397+ ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
398+ /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
399+ } else {
400+ ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
401+ }
402+
403+ /* DS parameter set */
404+ ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&pdev_network->Configuration.DSConfig, &sz);
405+
406+ /* IBSS Parameter Set */
407+
408+ ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&pdev_network->Configuration.ATIMWindow, &sz);
409+
410+ if (rateLen > 8)
411+ ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
412+
413+ return sz;
414+}
415+
416+unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
417+{
418+ int len;
419+ u16 val16;
420+ __le16 le_tmp;
421+ unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
422+ u8 *pbuf = pie;
423+ int limit_new = limit;
424+
425+ while (1) {
426+ pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
427+
428+ if (pbuf) {
429+ /* check if oui matches... */
430+ if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)))
431+ goto check_next_ie;
432+
433+ /* check version... */
434+ memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
435+
436+ val16 = le16_to_cpu(le_tmp);
437+ if (val16 != 0x0001)
438+ goto check_next_ie;
439+ *wpa_ie_len = *(pbuf + 1);
440+ return pbuf;
441+ } else {
442+ *wpa_ie_len = 0;
443+ return NULL;
444+ }
445+
446+check_next_ie:
447+ limit_new = limit - (pbuf - pie) - 2 - len;
448+ if (limit_new <= 0)
449+ break;
450+ pbuf += (2 + len);
451+ }
452+ *wpa_ie_len = 0;
453+ return NULL;
454+}
455+
456+unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
457+{
458+
459+ return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
460+}
461+
462+int rtw_get_wpa_cipher_suite(u8 *s)
463+{
464+ if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
465+ return WPA_CIPHER_NONE;
466+ if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
467+ return WPA_CIPHER_WEP40;
468+ if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
469+ return WPA_CIPHER_TKIP;
470+ if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
471+ return WPA_CIPHER_CCMP;
472+ if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
473+ return WPA_CIPHER_WEP104;
474+
475+ return 0;
476+}
477+
478+int rtw_get_wpa2_cipher_suite(u8 *s)
479+{
480+ if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
481+ return WPA_CIPHER_NONE;
482+ if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
483+ return WPA_CIPHER_WEP40;
484+ if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
485+ return WPA_CIPHER_TKIP;
486+ if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
487+ return WPA_CIPHER_CCMP;
488+ if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
489+ return WPA_CIPHER_WEP104;
490+
491+ return 0;
492+}
493+
494+int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
495+{
496+ int i, ret = _SUCCESS;
497+ int left, count;
498+ u8 *pos;
499+ u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
500+
501+ if (wpa_ie_len <= 0) {
502+ /* No WPA IE - fail silently */
503+ return _FAIL;
504+ }
505+
506+ if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
507+ (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
508+ return _FAIL;
509+
510+ pos = wpa_ie;
511+
512+ pos += 8;
513+ left = wpa_ie_len - 8;
514+
515+ /* group_cipher */
516+ if (left >= WPA_SELECTOR_LEN) {
517+ *group_cipher = rtw_get_wpa_cipher_suite(pos);
518+ pos += WPA_SELECTOR_LEN;
519+ left -= WPA_SELECTOR_LEN;
520+ } else if (left > 0) {
521+ return _FAIL;
522+ }
523+
524+ /* pairwise_cipher */
525+ if (left >= 2) {
526+ count = get_unaligned_le16(pos);
527+ pos += 2;
528+ left -= 2;
529+
530+ if (count == 0 || left < count * WPA_SELECTOR_LEN)
531+ return _FAIL;
532+
533+ for (i = 0; i < count; i++) {
534+ *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
535+
536+ pos += WPA_SELECTOR_LEN;
537+ left -= WPA_SELECTOR_LEN;
538+ }
539+ } else if (left == 1) {
540+ return _FAIL;
541+ }
542+
543+ if (is_8021x) {
544+ if (left >= 6) {
545+ pos += 2;
546+ if (!memcmp(pos, SUITE_1X, 4))
547+ *is_8021x = 1;
548+ }
549+ }
550+
551+ return ret;
552+}
553+
554+int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
555+{
556+ int i, ret = _SUCCESS;
557+ int left, count;
558+ u8 *pos;
559+ u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
560+
561+ if (rsn_ie_len <= 0) {
562+ /* No RSN IE - fail silently */
563+ return _FAIL;
564+ }
565+
566+ if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
567+ return _FAIL;
568+
569+ pos = rsn_ie;
570+ pos += 4;
571+ left = rsn_ie_len - 4;
572+
573+ /* group_cipher */
574+ if (left >= RSN_SELECTOR_LEN) {
575+ *group_cipher = rtw_get_wpa2_cipher_suite(pos);
576+
577+ pos += RSN_SELECTOR_LEN;
578+ left -= RSN_SELECTOR_LEN;
579+
580+ } else if (left > 0) {
581+ return _FAIL;
582+ }
583+
584+ /* pairwise_cipher */
585+ if (left >= 2) {
586+ count = get_unaligned_le16(pos);
587+ pos += 2;
588+ left -= 2;
589+
590+ if (count == 0 || left < count * RSN_SELECTOR_LEN)
591+ return _FAIL;
592+
593+ for (i = 0; i < count; i++) {
594+ *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
595+
596+ pos += RSN_SELECTOR_LEN;
597+ left -= RSN_SELECTOR_LEN;
598+ }
599+
600+ } else if (left == 1) {
601+ return _FAIL;
602+ }
603+
604+ if (is_8021x) {
605+ if (left >= 6) {
606+ pos += 2;
607+ if (!memcmp(pos, SUITE_1X, 4))
608+ *is_8021x = 1;
609+ }
610+ }
611+ return ret;
612+}
613+
614+int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
615+{
616+ u8 authmode;
617+ u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
618+ uint cnt;
619+
620+ /* Search required WPA or WPA2 IE and copy to sec_ie[] */
621+
622+ cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
623+
624+ while (cnt < in_len) {
625+ authmode = in_ie[cnt];
626+
627+ if ((authmode == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
628+ if (wpa_ie)
629+ memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
630+
631+ *wpa_len = in_ie[cnt + 1] + 2;
632+ cnt += in_ie[cnt + 1] + 2; /* get next */
633+ } else {
634+ if (authmode == _WPA2_IE_ID_) {
635+ if (rsn_ie)
636+ memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
637+
638+ *rsn_len = in_ie[cnt + 1] + 2;
639+ cnt += in_ie[cnt + 1] + 2; /* get next */
640+ } else {
641+ cnt += in_ie[cnt + 1] + 2; /* get next */
642+ }
643+ }
644+ }
645+
646+ return *rsn_len + *wpa_len;
647+}
648+
649+u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
650+{
651+ u8 match = false;
652+ u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
653+
654+ if (!ie_ptr)
655+ return match;
656+
657+ eid = ie_ptr[0];
658+
659+ if ((eid == _WPA_IE_ID_) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
660+ *wps_ielen = ie_ptr[1] + 2;
661+ match = true;
662+ }
663+ return match;
664+}
665+
666+/**
667+ * rtw_get_wps_ie - Search WPS IE from a series of IEs
668+ * @in_ie: Address of IEs to search
669+ * @in_len: Length limit from in_ie
670+ * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
671+ * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
672+ *
673+ * Returns: The address of the WPS IE found, or NULL
674+ */
675+u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
676+{
677+ uint cnt;
678+ u8 *wpsie_ptr = NULL;
679+ u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
680+
681+ if (wps_ielen)
682+ *wps_ielen = 0;
683+
684+ if (!in_ie || in_len <= 0)
685+ return wpsie_ptr;
686+
687+ cnt = 0;
688+
689+ while (cnt < in_len) {
690+ eid = in_ie[cnt];
691+
692+ if ((eid == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
693+ wpsie_ptr = &in_ie[cnt];
694+
695+ if (wps_ie)
696+ memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
697+
698+ if (wps_ielen)
699+ *wps_ielen = in_ie[cnt + 1] + 2;
700+
701+ cnt += in_ie[cnt + 1] + 2;
702+
703+ break;
704+ } else {
705+ cnt += in_ie[cnt + 1] + 2; /* goto next */
706+ }
707+ }
708+ return wpsie_ptr;
709+}
710+
711+/**
712+ * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
713+ * @wps_ie: Address of WPS IE to search
714+ * @wps_ielen: Length limit from wps_ie
715+ * @target_attr_id: The attribute ID of WPS attribute to search
716+ * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
717+ * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
718+ *
719+ * Returns: the address of the specific WPS attribute found, or NULL
720+ */
721+u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
722+{
723+ u8 *attr_ptr = NULL;
724+ u8 *target_attr_ptr = NULL;
725+ u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
726+
727+ if (len_attr)
728+ *len_attr = 0;
729+
730+ if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
731+ (memcmp(wps_ie + 2, wps_oui, 4)))
732+ return attr_ptr;
733+
734+ /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
735+ attr_ptr = wps_ie + 6; /* goto first attr */
736+
737+ while (attr_ptr - wps_ie < wps_ielen) {
738+ /* 4 = 2(Attribute ID) + 2(Length) */
739+ u16 attr_id = RTW_GET_BE16(attr_ptr);
740+ u16 attr_data_len = RTW_GET_BE16(attr_ptr + 2);
741+ u16 attr_len = attr_data_len + 4;
742+
743+ if (attr_id == target_attr_id) {
744+ target_attr_ptr = attr_ptr;
745+ if (buf_attr)
746+ memcpy(buf_attr, attr_ptr, attr_len);
747+ if (len_attr)
748+ *len_attr = attr_len;
749+ break;
750+ } else {
751+ attr_ptr += attr_len; /* goto next */
752+ }
753+ }
754+ return target_attr_ptr;
755+}
756+
757+/**
758+ * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
759+ * @wps_ie: Address of WPS IE to search
760+ * @wps_ielen: Length limit from wps_ie
761+ * @target_attr_id: The attribute ID of WPS attribute to search
762+ * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
763+ * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
764+ *
765+ * Returns: the address of the specific WPS attribute content found, or NULL
766+ */
767+u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
768+{
769+ u8 *attr_ptr;
770+ u32 attr_len;
771+
772+ if (len_content)
773+ *len_content = 0;
774+
775+ attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
776+
777+ if (attr_ptr && attr_len) {
778+ if (buf_content)
779+ memcpy(buf_content, attr_ptr + 4, attr_len - 4);
780+
781+ if (len_content)
782+ *len_content = attr_len - 4;
783+
784+ return attr_ptr + 4;
785+ }
786+
787+ return NULL;
788+}
789+
790+static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
791+ struct rtw_ieee802_11_elems *elems,
792+ int show_errors)
793+{
794+ unsigned int oui;
795+
796+ /* first 3 bytes in vendor specific information element are the IEEE
797+ * OUI of the vendor. The following byte is used a vendor specific
798+ * sub-type. */
799+ if (elen < 4) {
800+ if (show_errors) {
801+ DBG_88E("short vendor specific information element ignored (len=%lu)\n",
802+ (unsigned long)elen);
803+ }
804+ return -1;
805+ }
806+
807+ oui = RTW_GET_BE24(pos);
808+ switch (oui) {
809+ case OUI_MICROSOFT:
810+ /* Microsoft/Wi-Fi information elements are further typed and
811+ * subtyped */
812+ switch (pos[3]) {
813+ case 1:
814+ /* Microsoft OUI (00:50:F2) with OUI Type 1:
815+ * real WPA information element */
816+ elems->wpa_ie = pos;
817+ elems->wpa_ie_len = elen;
818+ break;
819+ case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
820+ if (elen < 5) {
821+ DBG_88E("short WME information element ignored (len=%lu)\n",
822+ (unsigned long)elen);
823+ return -1;
824+ }
825+ switch (pos[4]) {
826+ case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
827+ case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
828+ elems->wme = pos;
829+ elems->wme_len = elen;
830+ break;
831+ case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
832+ elems->wme_tspec = pos;
833+ elems->wme_tspec_len = elen;
834+ break;
835+ default:
836+ DBG_88E("unknown WME information element ignored (subtype=%d len=%lu)\n",
837+ pos[4], (unsigned long)elen);
838+ return -1;
839+ }
840+ break;
841+ case 4:
842+ /* Wi-Fi Protected Setup (WPS) IE */
843+ elems->wps_ie = pos;
844+ elems->wps_ie_len = elen;
845+ break;
846+ default:
847+ DBG_88E("Unknown Microsoft information element ignored (type=%d len=%lu)\n",
848+ pos[3], (unsigned long)elen);
849+ return -1;
850+ }
851+ break;
852+
853+ case OUI_BROADCOM:
854+ switch (pos[3]) {
855+ case VENDOR_HT_CAPAB_OUI_TYPE:
856+ elems->vendor_ht_cap = pos;
857+ elems->vendor_ht_cap_len = elen;
858+ break;
859+ default:
860+ DBG_88E("Unknown Broadcom information element ignored (type=%d len=%lu)\n",
861+ pos[3], (unsigned long)elen);
862+ return -1;
863+ }
864+ break;
865+ default:
866+ DBG_88E("unknown vendor specific information element ignored (vendor OUI %02x:%02x:%02x len=%lu)\n",
867+ pos[0], pos[1], pos[2], (unsigned long)elen);
868+ return -1;
869+ }
870+ return 0;
871+}
872+
873+/**
874+ * ieee802_11_parse_elems - Parse information elements in management frames
875+ * @start: Pointer to the start of IEs
876+ * @len: Length of IE buffer in octets
877+ * @elems: Data structure for parsed elements
878+ * @show_errors: Whether to show parsing errors in debug log
879+ * Returns: Parsing result
880+ */
881+enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
882+ struct rtw_ieee802_11_elems *elems,
883+ int show_errors)
884+{
885+ uint left = len;
886+ u8 *pos = start;
887+ int unknown = 0;
888+
889+ memset(elems, 0, sizeof(*elems));
890+
891+ while (left >= 2) {
892+ u8 id, elen;
893+
894+ id = *pos++;
895+ elen = *pos++;
896+ left -= 2;
897+
898+ if (elen > left) {
899+ if (show_errors) {
900+ DBG_88E("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
901+ id, elen, (unsigned long)left);
902+ }
903+ return ParseFailed;
904+ }
905+
906+ switch (id) {
907+ case WLAN_EID_SSID:
908+ elems->ssid = pos;
909+ elems->ssid_len = elen;
910+ break;
911+ case WLAN_EID_SUPP_RATES:
912+ elems->supp_rates = pos;
913+ elems->supp_rates_len = elen;
914+ break;
915+ case WLAN_EID_FH_PARAMS:
916+ elems->fh_params = pos;
917+ elems->fh_params_len = elen;
918+ break;
919+ case WLAN_EID_DS_PARAMS:
920+ elems->ds_params = pos;
921+ elems->ds_params_len = elen;
922+ break;
923+ case WLAN_EID_CF_PARAMS:
924+ elems->cf_params = pos;
925+ elems->cf_params_len = elen;
926+ break;
927+ case WLAN_EID_TIM:
928+ elems->tim = pos;
929+ elems->tim_len = elen;
930+ break;
931+ case WLAN_EID_IBSS_PARAMS:
932+ elems->ibss_params = pos;
933+ elems->ibss_params_len = elen;
934+ break;
935+ case WLAN_EID_CHALLENGE:
936+ elems->challenge = pos;
937+ elems->challenge_len = elen;
938+ break;
939+ case WLAN_EID_ERP_INFO:
940+ elems->erp_info = pos;
941+ elems->erp_info_len = elen;
942+ break;
943+ case WLAN_EID_EXT_SUPP_RATES:
944+ elems->ext_supp_rates = pos;
945+ elems->ext_supp_rates_len = elen;
946+ break;
947+ case WLAN_EID_VENDOR_SPECIFIC:
948+ if (rtw_ieee802_11_parse_vendor_specific(pos, elen, elems, show_errors))
949+ unknown++;
950+ break;
951+ case WLAN_EID_RSN:
952+ elems->rsn_ie = pos;
953+ elems->rsn_ie_len = elen;
954+ break;
955+ case WLAN_EID_PWR_CAPABILITY:
956+ elems->power_cap = pos;
957+ elems->power_cap_len = elen;
958+ break;
959+ case WLAN_EID_SUPPORTED_CHANNELS:
960+ elems->supp_channels = pos;
961+ elems->supp_channels_len = elen;
962+ break;
963+ case WLAN_EID_MOBILITY_DOMAIN:
964+ elems->mdie = pos;
965+ elems->mdie_len = elen;
966+ break;
967+ case WLAN_EID_FAST_BSS_TRANSITION:
968+ elems->ftie = pos;
969+ elems->ftie_len = elen;
970+ break;
971+ case WLAN_EID_TIMEOUT_INTERVAL:
972+ elems->timeout_int = pos;
973+ elems->timeout_int_len = elen;
974+ break;
975+ case WLAN_EID_HT_CAP:
976+ elems->ht_capabilities = pos;
977+ elems->ht_capabilities_len = elen;
978+ break;
979+ case WLAN_EID_HT_OPERATION:
980+ elems->ht_operation = pos;
981+ elems->ht_operation_len = elen;
982+ break;
983+ default:
984+ unknown++;
985+ if (!show_errors)
986+ break;
987+ DBG_88E("IEEE 802.11 element parse ignored unknown element (id=%d elen=%d)\n",
988+ id, elen);
989+ break;
990+ }
991+ left -= elen;
992+ pos += elen;
993+ }
994+ if (left)
995+ return ParseFailed;
996+ return unknown ? ParseUnknown : ParseOK;
997+}
998+
999+u8 key_char2num(u8 ch)
1000+{
1001+ if ((ch >= '0') && (ch <= '9'))
1002+ return ch - '0';
1003+ else if ((ch >= 'a') && (ch <= 'f'))
1004+ return ch - 'a' + 10;
1005+ else if ((ch >= 'A') && (ch <= 'F'))
1006+ return ch - 'A' + 10;
1007+ else
1008+ return 0xff;
1009+}
1010+
1011+u8 str_2char2num(u8 hch, u8 lch)
1012+{
1013+ return (key_char2num(hch) * 10) + key_char2num(lch);
1014+}
1015+
1016+u8 key_2char2num(u8 hch, u8 lch)
1017+{
1018+ return (key_char2num(hch) << 4) | key_char2num(lch);
1019+}
1020+
1021+void rtw_macaddr_cfg(u8 *mac_addr)
1022+{
1023+ u8 mac[ETH_ALEN];
1024+ if (!mac_addr)
1025+ return;
1026+
1027+ if (rtw_initmac) { /* Users specify the mac address */
1028+ int jj, kk;
1029+
1030+ for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
1031+ mac[jj] = key_2char2num(rtw_initmac[kk], rtw_initmac[kk + 1]);
1032+ memcpy(mac_addr, mac, ETH_ALEN);
1033+ } else { /* Use the mac address stored in the Efuse */
1034+ memcpy(mac, mac_addr, ETH_ALEN);
1035+ }
1036+
1037+ if (((mac[0] == 0xff) && (mac[1] == 0xff) && (mac[2] == 0xff) &&
1038+ (mac[3] == 0xff) && (mac[4] == 0xff) && (mac[5] == 0xff)) ||
1039+ ((mac[0] == 0x0) && (mac[1] == 0x0) && (mac[2] == 0x0) &&
1040+ (mac[3] == 0x0) && (mac[4] == 0x0) && (mac[5] == 0x0))) {
1041+ mac[0] = 0x00;
1042+ mac[1] = 0xe0;
1043+ mac[2] = 0x4c;
1044+ mac[3] = 0x87;
1045+ mac[4] = 0x00;
1046+ mac[5] = 0x00;
1047+ /* use default mac addresss */
1048+ memcpy(mac_addr, mac, ETH_ALEN);
1049+ DBG_88E("MAC Address from efuse error, assign default one !!!\n");
1050+ }
1051+
1052+ DBG_88E("rtw_macaddr_cfg MAC Address = %pM\n", (mac_addr));
1053+}
1054+
1055+void dump_ies(u8 *buf, u32 buf_len)
1056+{
1057+ u8 *pos = (u8 *)buf;
1058+ u8 id, len;
1059+
1060+ while (pos - buf <= buf_len) {
1061+ id = *pos;
1062+ len = *(pos + 1);
1063+
1064+ DBG_88E("%s ID:%u, LEN:%u\n", __func__, id, len);
1065+ #ifdef CONFIG_88EU_P2P
1066+ dump_p2p_ie(pos, len);
1067+ #endif
1068+ dump_wps_ie(pos, len);
1069+
1070+ pos += (2 + len);
1071+ }
1072+}
1073+
1074+void dump_wps_ie(u8 *ie, u32 ie_len)
1075+{
1076+ u8 *pos = (u8 *)ie;
1077+ u16 id;
1078+ u16 len;
1079+ u8 *wps_ie;
1080+ uint wps_ielen;
1081+
1082+ wps_ie = rtw_get_wps_ie(ie, ie_len, NULL, &wps_ielen);
1083+ if (wps_ie != ie || wps_ielen == 0)
1084+ return;
1085+
1086+ pos += 6;
1087+ while (pos - ie < ie_len) {
1088+ id = RTW_GET_BE16(pos);
1089+ len = RTW_GET_BE16(pos + 2);
1090+ DBG_88E("%s ID:0x%04x, LEN:%u\n", __func__, id, len);
1091+ pos += (4 + len);
1092+ }
1093+}
1094+
1095+#ifdef CONFIG_88EU_P2P
1096+void dump_p2p_ie(u8 *ie, u32 ie_len)
1097+{
1098+ u8 *pos = (u8 *)ie;
1099+ u8 id;
1100+ u16 len;
1101+ u8 *p2p_ie;
1102+ uint p2p_ielen;
1103+
1104+ p2p_ie = rtw_get_p2p_ie(ie, ie_len, NULL, &p2p_ielen);
1105+ if (p2p_ie != ie || p2p_ielen == 0)
1106+ return;
1107+
1108+ pos += 6;
1109+ while (pos - ie < ie_len) {
1110+ id = *pos;
1111+ len = get_unaligned_le16(pos + 1);
1112+ DBG_88E("%s ID:%u, LEN:%u\n", __func__, id, len);
1113+ pos += (3 + len);
1114+ }
1115+}
1116+
1117+/**
1118+ * rtw_get_p2p_ie - Search P2P IE from a series of IEs
1119+ * @in_ie: Address of IEs to search
1120+ * @in_len: Length limit from in_ie
1121+ * @p2p_ie: If not NULL and P2P IE is found, P2P IE will be copied to the buf starting from p2p_ie
1122+ * @p2p_ielen: If not NULL and P2P IE is found, will set to the length of the entire P2P IE
1123+ *
1124+ * Returns: The address of the P2P IE found, or NULL
1125+ */
1126+u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)
1127+{
1128+ uint cnt = 0;
1129+ u8 *p2p_ie_ptr;
1130+ u8 eid, p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
1131+
1132+ if (p2p_ielen)
1133+ *p2p_ielen = 0;
1134+
1135+ while (cnt < in_len) {
1136+ eid = in_ie[cnt];
1137+ if ((in_len < 0) || (cnt > MAX_IE_SZ)) {
1138+ dump_stack();
1139+ return NULL;
1140+ }
1141+ if ((eid == _VENDOR_SPECIFIC_IE_) && !memcmp(&in_ie[cnt + 2], p2p_oui, 4)) {
1142+ p2p_ie_ptr = in_ie + cnt;
1143+
1144+ if (p2p_ie)
1145+ memcpy(p2p_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
1146+ if (p2p_ielen)
1147+ *p2p_ielen = in_ie[cnt + 1] + 2;
1148+ return p2p_ie_ptr;
1149+ } else {
1150+ cnt += in_ie[cnt + 1] + 2; /* goto next */
1151+ }
1152+ }
1153+ return NULL;
1154+}
1155+
1156+/**
1157+ * rtw_get_p2p_attr - Search a specific P2P attribute from a given P2P IE
1158+ * @p2p_ie: Address of P2P IE to search
1159+ * @p2p_ielen: Length limit from p2p_ie
1160+ * @target_attr_id: The attribute ID of P2P attribute to search
1161+ * @buf_attr: If not NULL and the P2P attribute is found, P2P attribute will be copied to the buf starting from buf_attr
1162+ * @len_attr: If not NULL and the P2P attribute is found, will set to the length of the entire P2P attribute
1163+ *
1164+ * Returns: the address of the specific WPS attribute found, or NULL
1165+ */
1166+u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id, u8 *buf_attr, u32 *len_attr)
1167+{
1168+ u8 *attr_ptr = NULL;
1169+ u8 *target_attr_ptr = NULL;
1170+ u8 p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
1171+
1172+ if (len_attr)
1173+ *len_attr = 0;
1174+
1175+ if (!p2p_ie || (p2p_ie[0] != _VENDOR_SPECIFIC_IE_) ||
1176+ memcmp(p2p_ie + 2, p2p_oui, 4))
1177+ return attr_ptr;
1178+
1179+ /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
1180+ attr_ptr = p2p_ie + 6; /* goto first attr */
1181+
1182+ while (attr_ptr - p2p_ie < p2p_ielen) {
1183+ /* 3 = 1(Attribute ID) + 2(Length) */
1184+ u8 attr_id = *attr_ptr;
1185+ u16 attr_data_len = get_unaligned_le16(attr_ptr + 1);
1186+ u16 attr_len = attr_data_len + 3;
1187+
1188+ if (attr_id == target_attr_id) {
1189+ target_attr_ptr = attr_ptr;
1190+
1191+ if (buf_attr)
1192+ memcpy(buf_attr, attr_ptr, attr_len);
1193+ if (len_attr)
1194+ *len_attr = attr_len;
1195+ break;
1196+ } else {
1197+ attr_ptr += attr_len; /* goto next */
1198+ }
1199+ }
1200+ return target_attr_ptr;
1201+}
1202+
1203+/**
1204+ * rtw_get_p2p_attr_content - Search a specific P2P attribute content from a given P2P IE
1205+ * @p2p_ie: Address of P2P IE to search
1206+ * @p2p_ielen: Length limit from p2p_ie
1207+ * @target_attr_id: The attribute ID of P2P attribute to search
1208+ * @buf_content: If not NULL and the P2P attribute is found, P2P attribute content will be copied to the buf starting from buf_content
1209+ * @len_content: If not NULL and the P2P attribute is found, will set to the length of the P2P attribute content
1210+ *
1211+ * Returns: the address of the specific P2P attribute content found, or NULL
1212+ */
1213+u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id, u8 *buf_content, uint *len_content)
1214+{
1215+ u8 *attr_ptr;
1216+ u32 attr_len;
1217+
1218+ if (len_content)
1219+ *len_content = 0;
1220+
1221+ attr_ptr = rtw_get_p2p_attr(p2p_ie, p2p_ielen, target_attr_id, NULL, &attr_len);
1222+
1223+ if (attr_ptr && attr_len) {
1224+ if (buf_content)
1225+ memcpy(buf_content, attr_ptr + 3, attr_len - 3);
1226+
1227+ if (len_content)
1228+ *len_content = attr_len - 3;
1229+
1230+ return attr_ptr + 3;
1231+ }
1232+
1233+ return NULL;
1234+}
1235+
1236+u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr)
1237+{
1238+ u32 a_len;
1239+
1240+ *pbuf = attr_id;
1241+
1242+ /* u16*)(pbuf + 1) = cpu_to_le16(attr_len); */
1243+ RTW_PUT_LE16(pbuf + 1, attr_len);
1244+
1245+ if (pdata_attr)
1246+ memcpy(pbuf + 3, pdata_attr, attr_len);
1247+
1248+ a_len = attr_len + 3;
1249+
1250+ return a_len;
1251+}
1252+
1253+static uint rtw_p2p_attr_remove(u8 *ie, uint ielen_ori, u8 attr_id)
1254+{
1255+ u8 *target_attr;
1256+ u32 target_attr_len;
1257+ uint ielen = ielen_ori;
1258+
1259+ while (1) {
1260+ target_attr = rtw_get_p2p_attr(ie, ielen, attr_id, NULL, &target_attr_len);
1261+ if (target_attr && target_attr_len) {
1262+ u8 *next_attr = target_attr + target_attr_len;
1263+ uint remain_len = ielen - (next_attr - ie);
1264+
1265+ memset(target_attr, 0, target_attr_len);
1266+ memcpy(target_attr, next_attr, remain_len);
1267+ memset(target_attr + remain_len, 0, target_attr_len);
1268+ *(ie + 1) -= target_attr_len;
1269+ ielen -= target_attr_len;
1270+ } else {
1271+ break;
1272+ }
1273+ }
1274+ return ielen;
1275+}
1276+
1277+void rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex *bss_ex, u8 attr_id)
1278+{
1279+ u8 *p2p_ie;
1280+ uint p2p_ielen, p2p_ielen_ori;
1281+
1282+ p2p_ie = rtw_get_p2p_ie(bss_ex->IEs + _FIXED_IE_LENGTH_, bss_ex->IELength - _FIXED_IE_LENGTH_, NULL, &p2p_ielen_ori);
1283+ if (p2p_ie) {
1284+ p2p_ielen = rtw_p2p_attr_remove(p2p_ie, p2p_ielen_ori, attr_id);
1285+ if (p2p_ielen != p2p_ielen_ori) {
1286+ u8 *next_ie_ori = p2p_ie + p2p_ielen_ori;
1287+ u8 *next_ie = p2p_ie + p2p_ielen;
1288+ uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);
1289+
1290+ memcpy(next_ie, next_ie_ori, remain_len);
1291+ memset(next_ie + remain_len, 0, p2p_ielen_ori - p2p_ielen);
1292+ bss_ex->IELength -= p2p_ielen_ori - p2p_ielen;
1293+ }
1294+ }
1295+}
1296+
1297+#endif /* CONFIG_88EU_P2P */
1298+
1299+/* Baron adds to avoid FreeBSD warning */
1300+int ieee80211_is_empty_essid(const char *essid, int essid_len)
1301+{
1302+ /* Single white space is for Linksys APs */
1303+ if (essid_len == 1 && essid[0] == ' ')
1304+ return 1;
1305+
1306+ /* Otherwise, if the entire essid is 0, we assume it is hidden */
1307+ while (essid_len) {
1308+ essid_len--;
1309+ if (essid[essid_len] != '\0')
1310+ return 0;
1311+ }
1312+
1313+ return 1;
1314+}
1315+
1316+int ieee80211_get_hdrlen(u16 fc)
1317+{
1318+ int hdrlen = 24;
1319+
1320+ switch (WLAN_FC_GET_TYPE(fc)) {
1321+ case RTW_IEEE80211_FTYPE_DATA:
1322+ if (fc & RTW_IEEE80211_STYPE_QOS_DATA)
1323+ hdrlen += 2;
1324+ if ((fc & RTW_IEEE80211_FCTL_FROMDS) && (fc & RTW_IEEE80211_FCTL_TODS))
1325+ hdrlen += 6; /* Addr4 */
1326+ break;
1327+ case RTW_IEEE80211_FTYPE_CTL:
1328+ switch (WLAN_FC_GET_STYPE(fc)) {
1329+ case RTW_IEEE80211_STYPE_CTS:
1330+ case RTW_IEEE80211_STYPE_ACK:
1331+ hdrlen = 10;
1332+ break;
1333+ default:
1334+ hdrlen = 16;
1335+ break;
1336+ }
1337+ break;
1338+ }
1339+
1340+ return hdrlen;
1341+}
1342+
1343+static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1344+{
1345+ u32 wpa_ielen;
1346+ unsigned char *pbuf;
1347+ int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1348+ int ret = _FAIL;
1349+ pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1350+
1351+ if (pbuf && (wpa_ielen > 0)) {
1352+ if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
1353+ pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1354+ pnetwork->BcnInfo.group_cipher = group_cipher;
1355+ pnetwork->BcnInfo.is_8021x = is8021x;
1356+ ret = _SUCCESS;
1357+ }
1358+ } else {
1359+ pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1360+
1361+ if (pbuf && (wpa_ielen > 0)) {
1362+ if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
1363+ pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1364+ pnetwork->BcnInfo.group_cipher = group_cipher;
1365+ pnetwork->BcnInfo.is_8021x = is8021x;
1366+ ret = _SUCCESS;
1367+ }
1368+ }
1369+ }
1370+
1371+ return ret;
1372+}
1373+
1374+void rtw_get_bcn_info(struct wlan_network *pnetwork)
1375+{
1376+ unsigned short cap = 0;
1377+ u8 bencrypt = 0;
1378+ __le16 le_tmp;
1379+ u16 wpa_len = 0, rsn_len = 0;
1380+ struct HT_info_element *pht_info = NULL;
1381+ struct ieee80211_ht_cap *pht_cap = NULL;
1382+ unsigned int len;
1383+ unsigned char *p;
1384+
1385+ memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
1386+ cap = le16_to_cpu(le_tmp);
1387+ if (cap & WLAN_CAPABILITY_PRIVACY) {
1388+ bencrypt = 1;
1389+ pnetwork->network.Privacy = 1;
1390+ } else {
1391+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1392+ }
1393+ rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &rsn_len, NULL, &wpa_len);
1394+
1395+ if (rsn_len > 0) {
1396+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1397+ } else if (wpa_len > 0) {
1398+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1399+ } else {
1400+ if (bencrypt)
1401+ pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1402+ }
1403+ rtw_get_cipher_info(pnetwork);
1404+
1405+ /* get bwmode and ch_offset */
1406+ /* parsing HT_CAP_IE */
1407+ p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1408+ if (p && len > 0) {
1409+ pht_cap = (struct ieee80211_ht_cap *)(p + 2);
1410+ pnetwork->BcnInfo.ht_cap_info = le16_to_cpu(pht_cap->cap_info);
1411+ } else {
1412+ pnetwork->BcnInfo.ht_cap_info = 0;
1413+ }
1414+ /* parsing HT_INFO_IE */
1415+ p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1416+ if (p && len > 0) {
1417+ pht_info = (struct HT_info_element *)(p + 2);
1418+ pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
1419+ } else {
1420+ pnetwork->BcnInfo.ht_info_infos_0 = 0;
1421+ }
1422+}
1423+
1424+/* show MCS rate, unit: 100Kbps */
1425+u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate)
1426+{
1427+ u16 max_rate = 0;
1428+
1429+ if (rf_type == RF_1T1R) {
1430+ if (MCS_rate[0] & BIT(7))
1431+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1432+ else if (MCS_rate[0] & BIT(6))
1433+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1434+ else if (MCS_rate[0] & BIT(5))
1435+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1436+ else if (MCS_rate[0] & BIT(4))
1437+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1438+ else if (MCS_rate[0] & BIT(3))
1439+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1440+ else if (MCS_rate[0] & BIT(2))
1441+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1442+ else if (MCS_rate[0] & BIT(1))
1443+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1444+ else if (MCS_rate[0] & BIT(0))
1445+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);
1446+ } else {
1447+ if (MCS_rate[1]) {
1448+ if (MCS_rate[1] & BIT(7))
1449+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 3000 : 2700) : ((short_GI_20) ? 1444 : 1300);
1450+ else if (MCS_rate[1] & BIT(6))
1451+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 2700 : 2430) : ((short_GI_20) ? 1300 : 1170);
1452+ else if (MCS_rate[1] & BIT(5))
1453+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 2400 : 2160) : ((short_GI_20) ? 1156 : 1040);
1454+ else if (MCS_rate[1] & BIT(4))
1455+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1800 : 1620) : ((short_GI_20) ? 867 : 780);
1456+ else if (MCS_rate[1] & BIT(3))
1457+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1458+ else if (MCS_rate[1] & BIT(2))
1459+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1460+ else if (MCS_rate[1] & BIT(1))
1461+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1462+ else if (MCS_rate[1] & BIT(0))
1463+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1464+ } else {
1465+ if (MCS_rate[0] & BIT(7))
1466+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1467+ else if (MCS_rate[0] & BIT(6))
1468+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1469+ else if (MCS_rate[0] & BIT(5))
1470+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1471+ else if (MCS_rate[0] & BIT(4))
1472+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1473+ else if (MCS_rate[0] & BIT(3))
1474+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1475+ else if (MCS_rate[0] & BIT(2))
1476+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1477+ else if (MCS_rate[0] & BIT(1))
1478+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1479+ else if (MCS_rate[0] & BIT(0))
1480+ max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);
1481+ }
1482+ }
1483+ return max_rate;
1484+}
1485+
1486+int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action)
1487+{
1488+ const u8 *frame_body = frame + sizeof(struct rtw_ieee80211_hdr_3addr);
1489+ u16 fc;
1490+ u8 c, a = 0;
1491+
1492+ fc = le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)frame)->frame_ctl);
1493+
1494+ if ((fc & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE)) !=
1495+ (RTW_IEEE80211_FTYPE_MGMT | RTW_IEEE80211_STYPE_ACTION))
1496+ return false;
1497+
1498+ c = frame_body[0];
1499+
1500+ switch (c) {
1501+ case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */
1502+ break;
1503+ default:
1504+ a = frame_body[1];
1505+ }
1506+
1507+ if (category)
1508+ *category = c;
1509+ if (action)
1510+ *action = a;
1511+
1512+ return true;
1513+}
1514+
1515+static const char *_action_public_str[] = {
1516+ "ACT_PUB_BSSCOEXIST",
1517+ "ACT_PUB_DSE_ENABLE",
1518+ "ACT_PUB_DSE_DEENABLE",
1519+ "ACT_PUB_DSE_REG_LOCATION",
1520+ "ACT_PUB_EXT_CHL_SWITCH",
1521+ "ACT_PUB_DSE_MSR_REQ",
1522+ "ACT_PUB_DSE_MSR_RPRT",
1523+ "ACT_PUB_MP",
1524+ "ACT_PUB_DSE_PWR_CONSTRAINT",
1525+ "ACT_PUB_VENDOR",
1526+ "ACT_PUB_GAS_INITIAL_REQ",
1527+ "ACT_PUB_GAS_INITIAL_RSP",
1528+ "ACT_PUB_GAS_COMEBACK_REQ",
1529+ "ACT_PUB_GAS_COMEBACK_RSP",
1530+ "ACT_PUB_TDLS_DISCOVERY_RSP",
1531+ "ACT_PUB_LOCATION_TRACK",
1532+ "ACT_PUB_RSVD",
1533+};
1534+
1535+const char *action_public_str(u8 action)
1536+{
1537+ action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
1538+ return _action_public_str[action];
1539+}
drivers/staging/r8188eu/core/rtw_io.c+299−0
@@ -0,0 +1,299 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2011 Realtek Corporation. */
3+
4+/*
5+
6+The purpose of rtw_io.c
7+
8+a. provides the API
9+
10+b. provides the protocol engine
11+
12+c. provides the software interface between caller and the hardware interface
13+
14+Compiler Flag Option:
15+
16+USB:
17+ a. USE_ASYNC_IRP: Both sync/async operations are provided.
18+
19+Only sync read/rtw_write_mem operations are provided.
20+
21+jackson@realtek.com.tw
22+
23+*/
24+
25+#define _RTW_IO_C_
26+#include "../include/osdep_service.h"
27+#include "../include/drv_types.h"
28+#include "../include/rtw_io.h"
29+#include "../include/osdep_intf.h"
30+#include "../include/usb_ops.h"
31+
32+#define rtw_le16_to_cpu(val) le16_to_cpu(val)
33+#define rtw_le32_to_cpu(val) le32_to_cpu(val)
34+#define rtw_cpu_to_le16(val) cpu_to_le16(val)
35+#define rtw_cpu_to_le32(val) cpu_to_le32(val)
36+
37+u8 _rtw_read8(struct adapter *adapter, u32 addr)
38+{
39+ u8 r_val;
40+ struct io_priv *pio_priv = &adapter->iopriv;
41+ struct intf_hdl *pintfhdl = &pio_priv->intf;
42+ u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
43+
44+
45+ _read8 = pintfhdl->io_ops._read8;
46+ r_val = _read8(pintfhdl, addr);
47+
48+ return r_val;
49+}
50+
51+u16 _rtw_read16(struct adapter *adapter, u32 addr)
52+{
53+ u16 r_val;
54+ struct io_priv *pio_priv = &adapter->iopriv;
55+ struct intf_hdl *pintfhdl = &pio_priv->intf;
56+ u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
57+
58+ _read16 = pintfhdl->io_ops._read16;
59+
60+ r_val = _read16(pintfhdl, addr);
61+
62+ return r_val;
63+}
64+
65+u32 _rtw_read32(struct adapter *adapter, u32 addr)
66+{
67+ u32 r_val;
68+ struct io_priv *pio_priv = &adapter->iopriv;
69+ struct intf_hdl *pintfhdl = &pio_priv->intf;
70+ u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
71+
72+ _read32 = pintfhdl->io_ops._read32;
73+
74+ r_val = _read32(pintfhdl, addr);
75+
76+ return r_val;
77+}
78+
79+int _rtw_write8(struct adapter *adapter, u32 addr, u8 val)
80+{
81+ struct io_priv *pio_priv = &adapter->iopriv;
82+ struct intf_hdl *pintfhdl = &pio_priv->intf;
83+ int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
84+ int ret;
85+
86+ _write8 = pintfhdl->io_ops._write8;
87+
88+ ret = _write8(pintfhdl, addr, val);
89+
90+
91+ return RTW_STATUS_CODE(ret);
92+}
93+
94+int _rtw_write16(struct adapter *adapter, u32 addr, u16 val)
95+{
96+ struct io_priv *pio_priv = &adapter->iopriv;
97+ struct intf_hdl *pintfhdl = &pio_priv->intf;
98+ int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
99+ int ret;
100+
101+ _write16 = pintfhdl->io_ops._write16;
102+
103+ ret = _write16(pintfhdl, addr, val);
104+
105+
106+ return RTW_STATUS_CODE(ret);
107+}
108+int _rtw_write32(struct adapter *adapter, u32 addr, u32 val)
109+{
110+ struct io_priv *pio_priv = &adapter->iopriv;
111+ struct intf_hdl *pintfhdl = &pio_priv->intf;
112+ int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
113+ int ret;
114+
115+ _write32 = pintfhdl->io_ops._write32;
116+
117+ ret = _write32(pintfhdl, addr, val);
118+
119+
120+ return RTW_STATUS_CODE(ret);
121+}
122+
123+int _rtw_writeN(struct adapter *adapter, u32 addr, u32 length, u8 *pdata)
124+{
125+ struct io_priv *pio_priv = &adapter->iopriv;
126+ struct intf_hdl *pintfhdl = (struct intf_hdl *)(&pio_priv->intf);
127+ int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
128+ int ret;
129+
130+ _writeN = pintfhdl->io_ops._writeN;
131+
132+ ret = _writeN(pintfhdl, addr, length, pdata);
133+
134+
135+ return RTW_STATUS_CODE(ret);
136+}
137+int _rtw_write8_async(struct adapter *adapter, u32 addr, u8 val)
138+{
139+ struct io_priv *pio_priv = &adapter->iopriv;
140+ struct intf_hdl *pintfhdl = &pio_priv->intf;
141+ int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
142+ int ret;
143+
144+ _write8_async = pintfhdl->io_ops._write8_async;
145+
146+ ret = _write8_async(pintfhdl, addr, val);
147+
148+
149+ return RTW_STATUS_CODE(ret);
150+}
151+
152+int _rtw_write16_async(struct adapter *adapter, u32 addr, u16 val)
153+{
154+ struct io_priv *pio_priv = &adapter->iopriv;
155+ struct intf_hdl *pintfhdl = &pio_priv->intf;
156+ int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
157+ int ret;
158+
159+ _write16_async = pintfhdl->io_ops._write16_async;
160+ ret = _write16_async(pintfhdl, addr, val);
161+
162+ return RTW_STATUS_CODE(ret);
163+}
164+
165+int _rtw_write32_async(struct adapter *adapter, u32 addr, u32 val)
166+{
167+ struct io_priv *pio_priv = &adapter->iopriv;
168+ struct intf_hdl *pintfhdl = &pio_priv->intf;
169+ int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
170+ int ret;
171+
172+ _write32_async = pintfhdl->io_ops._write32_async;
173+ ret = _write32_async(pintfhdl, addr, val);
174+
175+ return RTW_STATUS_CODE(ret);
176+}
177+
178+void _rtw_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
179+{
180+ void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
181+ struct io_priv *pio_priv = &adapter->iopriv;
182+ struct intf_hdl *pintfhdl = &pio_priv->intf;
183+
184+
185+ if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
186+ return;
187+ _read_mem = pintfhdl->io_ops._read_mem;
188+ _read_mem(pintfhdl, addr, cnt, pmem);
189+
190+}
191+
192+void _rtw_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
193+{
194+ void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
195+ struct io_priv *pio_priv = &adapter->iopriv;
196+ struct intf_hdl *pintfhdl = &pio_priv->intf;
197+
198+
199+
200+ _write_mem = pintfhdl->io_ops._write_mem;
201+
202+ _write_mem(pintfhdl, addr, cnt, pmem);
203+
204+
205+}
206+
207+void _rtw_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
208+{
209+ u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
210+ struct io_priv *pio_priv = &adapter->iopriv;
211+ struct intf_hdl *pintfhdl = &pio_priv->intf;
212+
213+
214+
215+ if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
216+ return;
217+
218+ _read_port = pintfhdl->io_ops._read_port;
219+
220+ _read_port(pintfhdl, addr, cnt, pmem);
221+
222+
223+}
224+
225+void _rtw_read_port_cancel(struct adapter *adapter)
226+{
227+ void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
228+ struct io_priv *pio_priv = &adapter->iopriv;
229+ struct intf_hdl *pintfhdl = &pio_priv->intf;
230+
231+ _read_port_cancel = pintfhdl->io_ops._read_port_cancel;
232+
233+ if (_read_port_cancel)
234+ _read_port_cancel(pintfhdl);
235+}
236+
237+u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
238+{
239+ u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
240+ struct io_priv *pio_priv = &adapter->iopriv;
241+ struct intf_hdl *pintfhdl = &pio_priv->intf;
242+ u32 ret = _SUCCESS;
243+
244+
245+
246+ _write_port = pintfhdl->io_ops._write_port;
247+
248+ ret = _write_port(pintfhdl, addr, cnt, pmem);
249+
250+
251+
252+ return ret;
253+}
254+
255+u32 _rtw_write_port_and_wait(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem, int timeout_ms)
256+{
257+ int ret = _SUCCESS;
258+ struct xmit_buf *pxmitbuf = (struct xmit_buf *)pmem;
259+ struct submit_ctx sctx;
260+
261+ rtw_sctx_init(&sctx, timeout_ms);
262+ pxmitbuf->sctx = &sctx;
263+
264+ ret = _rtw_write_port(adapter, addr, cnt, pmem);
265+
266+ if (ret == _SUCCESS)
267+ ret = rtw_sctx_wait(&sctx);
268+
269+ return ret;
270+}
271+
272+void _rtw_write_port_cancel(struct adapter *adapter)
273+{
274+ void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
275+ struct io_priv *pio_priv = &adapter->iopriv;
276+ struct intf_hdl *pintfhdl = &pio_priv->intf;
277+
278+ _write_port_cancel = pintfhdl->io_ops._write_port_cancel;
279+
280+ if (_write_port_cancel)
281+ _write_port_cancel(pintfhdl);
282+}
283+
284+int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct _io_ops *pops))
285+{
286+ struct io_priv *piopriv = &padapter->iopriv;
287+ struct intf_hdl *pintf = &piopriv->intf;
288+
289+ if (!set_intf_ops)
290+ return _FAIL;
291+
292+ piopriv->padapter = padapter;
293+ pintf->padapter = padapter;
294+ pintf->pintf_dev = adapter_to_dvobj(padapter);
295+
296+ set_intf_ops(&pintf->io_ops);
297+
298+ return _SUCCESS;
299+}
drivers/staging/r8188eu/core/rtw_ioctl_set.c+891−0
@@ -0,0 +1,891 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2012 Realtek Corporation. */
3+
4+#define _RTW_IOCTL_SET_C_
5+
6+#include "../include/osdep_service.h"
7+#include "../include/drv_types.h"
8+#include "../include/rtw_ioctl_set.h"
9+#include "../include/hal_intf.h"
10+
11+#include "../include/usb_osintf.h"
12+#include "../include/usb_ops.h"
13+
14+extern void indicate_wx_scan_complete_event(struct adapter *padapter);
15+
16+u8 rtw_validate_ssid(struct ndis_802_11_ssid *ssid)
17+{
18+ u8 i;
19+ u8 ret = true;
20+
21+ if (ssid->SsidLength > 32) {
22+ ret = false;
23+ goto exit;
24+ }
25+
26+ for (i = 0; i < ssid->SsidLength; i++) {
27+ /* wifi, printable ascii code must be supported */
28+ if (!((ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e))) {
29+ ret = false;
30+ break;
31+ }
32+ }
33+
34+exit:
35+
36+ return ret;
37+}
38+
39+u8 rtw_do_join(struct adapter *padapter)
40+{
41+ struct list_head *plist, *phead;
42+ u8 *pibss = NULL;
43+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
44+ struct __queue *queue = &pmlmepriv->scanned_queue;
45+ u8 ret = _SUCCESS;
46+
47+ spin_lock_bh(&pmlmepriv->scanned_queue.lock);
48+ phead = get_list_head(queue);
49+ plist = phead->next;
50+
51+ pmlmepriv->cur_network.join_res = -2;
52+
53+ set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
54+
55+ pmlmepriv->pscanned = plist;
56+
57+ pmlmepriv->to_join = true;
58+
59+ if (list_empty(&queue->queue)) {
60+ spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
61+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
62+
63+ /* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
64+ /* we try to issue sitesurvey firstly */
65+
66+ if (!pmlmepriv->LinkDetectInfo.bBusyTraffic ||
67+ pmlmepriv->to_roaming > 0) {
68+ /* submit site_survey_cmd */
69+ ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
70+ if (_SUCCESS != ret)
71+ pmlmepriv->to_join = false;
72+ } else {
73+ pmlmepriv->to_join = false;
74+ ret = _FAIL;
75+ }
76+
77+ goto exit;
78+ } else {
79+ int select_ret;
80+
81+ spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
82+ select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
83+ if (select_ret == _SUCCESS) {
84+ pmlmepriv->to_join = false;
85+ _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
86+ } else {
87+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
88+ /* submit createbss_cmd to change to a ADHOC_MASTER */
89+
90+ /* pmlmepriv->lock has been acquired by caller... */
91+ struct wlan_bssid_ex *pdev_network = &padapter->registrypriv.dev_network;
92+
93+ pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
94+
95+ pibss = padapter->registrypriv.dev_network.MacAddress;
96+
97+ memset(&pdev_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
98+ memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid));
99+
100+ rtw_update_registrypriv_dev_network(padapter);
101+
102+ rtw_generate_random_ibss(pibss);
103+
104+ if (rtw_createbss_cmd(padapter) != _SUCCESS) {
105+ ret = false;
106+ goto exit;
107+ }
108+ pmlmepriv->to_join = false;
109+ } else {
110+ /* can't associate ; reset under-linking */
111+ _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
112+
113+ /* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */
114+ /* we try to issue sitesurvey firstly */
115+ if (!pmlmepriv->LinkDetectInfo.bBusyTraffic ||
116+ pmlmepriv->to_roaming > 0) {
117+ ret = rtw_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid, 1, NULL, 0);
118+ if (_SUCCESS != ret)
119+ pmlmepriv->to_join = false;
120+ } else {
121+ ret = _FAIL;
122+ pmlmepriv->to_join = false;
123+ }
124+ }
125+ }
126+ }
127+
128+exit:
129+
130+ return ret;
131+}
132+
133+u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
134+{
135+ u8 status = _SUCCESS;
136+ u32 cur_time = 0;
137+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
138+
139+ DBG_88E_LEVEL(_drv_info_, "set bssid:%pM\n", bssid);
140+
141+ if ((bssid[0] == 0x00 && bssid[1] == 0x00 && bssid[2] == 0x00 &&
142+ bssid[3] == 0x00 && bssid[4] == 0x00 && bssid[5] == 0x00) ||
143+ (bssid[0] == 0xFF && bssid[1] == 0xFF && bssid[2] == 0xFF &&
144+ bssid[3] == 0xFF && bssid[4] == 0xFF && bssid[5] == 0xFF)) {
145+ status = _FAIL;
146+ goto exit;
147+ }
148+
149+ spin_lock_bh(&pmlmepriv->lock);
150+
151+ DBG_88E("Set BSSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
152+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
153+ goto handle_tkip_countermeasure;
154+ else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
155+ goto release_mlme_lock;
156+
157+ if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
158+ if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN)) {
159+ if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE))
160+ goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
161+ } else {
162+ rtw_disassoc_cmd(padapter, 0, true);
163+
164+ if (check_fwstate(pmlmepriv, _FW_LINKED))
165+ rtw_indicate_disconnect(padapter);
166+
167+ rtw_free_assoc_resources(padapter, 1);
168+
169+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
170+ _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
171+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
172+ }
173+ }
174+ }
175+
176+handle_tkip_countermeasure:
177+ /* should we add something here...? */
178+
179+ if (padapter->securitypriv.btkip_countermeasure) {
180+ cur_time = jiffies;
181+
182+ if ((cur_time - padapter->securitypriv.btkip_countermeasure_time) > 60 * HZ) {
183+ padapter->securitypriv.btkip_countermeasure = false;
184+ padapter->securitypriv.btkip_countermeasure_time = 0;
185+ } else {
186+ status = _FAIL;
187+ goto release_mlme_lock;
188+ }
189+ }
190+
191+ memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
192+ pmlmepriv->assoc_by_bssid = true;
193+
194+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
195+ pmlmepriv->to_join = true;
196+ else
197+ status = rtw_do_join(padapter);
198+
199+release_mlme_lock:
200+ spin_unlock_bh(&pmlmepriv->lock);
201+
202+exit:
203+ return status;
204+}
205+
206+u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid)
207+{
208+ u8 status = _SUCCESS;
209+ u32 cur_time = 0;
210+
211+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
212+ struct wlan_network *pnetwork = &pmlmepriv->cur_network;
213+
214+ DBG_88E_LEVEL(_drv_info_, "set ssid [%s] fw_state=0x%08x\n",
215+ ssid->Ssid, get_fwstate(pmlmepriv));
216+
217+ if (!padapter->hw_init_completed) {
218+ status = _FAIL;
219+ goto exit;
220+ }
221+
222+ spin_lock_bh(&pmlmepriv->lock);
223+
224+ DBG_88E("Set SSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
225+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
226+ goto handle_tkip_countermeasure;
227+ } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
228+ goto release_mlme_lock;
229+ }
230+
231+ if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
232+ if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
233+ (!memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength))) {
234+ if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
235+ if (!rtw_is_same_ibss(padapter, pnetwork)) {
236+ /* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
237+ rtw_disassoc_cmd(padapter, 0, true);
238+
239+ if (check_fwstate(pmlmepriv, _FW_LINKED))
240+ rtw_indicate_disconnect(padapter);
241+
242+ rtw_free_assoc_resources(padapter, 1);
243+
244+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
245+ _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
246+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
247+ }
248+ } else {
249+ goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
250+ }
251+ } else {
252+ rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 1);
253+ }
254+ } else {
255+ rtw_disassoc_cmd(padapter, 0, true);
256+
257+ if (check_fwstate(pmlmepriv, _FW_LINKED))
258+ rtw_indicate_disconnect(padapter);
259+
260+ rtw_free_assoc_resources(padapter, 1);
261+
262+ if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
263+ _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
264+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
265+ }
266+ }
267+ }
268+
269+handle_tkip_countermeasure:
270+
271+ if (padapter->securitypriv.btkip_countermeasure) {
272+ cur_time = jiffies;
273+
274+ if ((cur_time - padapter->securitypriv.btkip_countermeasure_time) > 60 * HZ) {
275+ padapter->securitypriv.btkip_countermeasure = false;
276+ padapter->securitypriv.btkip_countermeasure_time = 0;
277+ } else {
278+ status = _FAIL;
279+ goto release_mlme_lock;
280+ }
281+ }
282+
283+ memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid));
284+ pmlmepriv->assoc_by_bssid = false;
285+
286+ if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
287+ pmlmepriv->to_join = true;
288+ } else {
289+ status = rtw_do_join(padapter);
290+ }
291+
292+release_mlme_lock:
293+ spin_unlock_bh(&pmlmepriv->lock);
294+
295+exit:
296+ return status;
297+}
298+
299+u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter,
300+ enum ndis_802_11_network_infra networktype)
301+{
302+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
303+ struct wlan_network *cur_network = &pmlmepriv->cur_network;
304+ enum ndis_802_11_network_infra *pold_state = &cur_network->network.InfrastructureMode;
305+
306+ if (*pold_state != networktype) {
307+ spin_lock_bh(&pmlmepriv->lock);
308+
309+ /* DBG_88E("change mode, old_mode =%d, new_mode =%d, fw_state = 0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv)); */
310+
311+ if (*pold_state == Ndis802_11APMode) {
312+ /* change to other mode from Ndis802_11APMode */
313+ cur_network->join_res = -1;
314+
315+#ifdef CONFIG_88EU_AP_MODE
316+ stop_ap_mode(padapter);
317+#endif
318+ }
319+
320+ if ((check_fwstate(pmlmepriv, _FW_LINKED)) ||
321+ (*pold_state == Ndis802_11IBSS))
322+ rtw_disassoc_cmd(padapter, 0, true);
323+
324+ if ((check_fwstate(pmlmepriv, _FW_LINKED)) ||
325+ (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
326+ rtw_free_assoc_resources(padapter, 1);
327+
328+ if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
329+ if (check_fwstate(pmlmepriv, _FW_LINKED))
330+ rtw_indicate_disconnect(padapter); /* will clr Linked_state; before this function, we must have chked whether issue dis-assoc_cmd or not */
331+ }
332+
333+ *pold_state = networktype;
334+
335+ _clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
336+
337+ switch (networktype) {
338+ case Ndis802_11IBSS:
339+ set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
340+ break;
341+ case Ndis802_11Infrastructure:
342+ set_fwstate(pmlmepriv, WIFI_STATION_STATE);
343+ break;
344+ case Ndis802_11APMode:
345+ set_fwstate(pmlmepriv, WIFI_AP_STATE);
346+#ifdef CONFIG_88EU_AP_MODE
347+ start_ap_mode(padapter);
348+#endif
349+ break;
350+ case Ndis802_11AutoUnknown:
351+ case Ndis802_11InfrastructureMax:
352+ break;
353+ }
354+ spin_unlock_bh(&pmlmepriv->lock);
355+ }
356+
357+ return true;
358+}
359+
360+u8 rtw_set_802_11_disassociate(struct adapter *padapter)
361+{
362+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
363+
364+ spin_lock_bh(&pmlmepriv->lock);
365+
366+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
367+ rtw_disassoc_cmd(padapter, 0, true);
368+ rtw_indicate_disconnect(padapter);
369+ rtw_free_assoc_resources(padapter, 1);
370+ rtw_pwr_wakeup(padapter);
371+ }
372+
373+ spin_unlock_bh(&pmlmepriv->lock);
374+
375+ return true;
376+}
377+
378+u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct ndis_802_11_ssid *pssid, int ssid_max_num)
379+{
380+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
381+ u8 res = true;
382+
383+ if (!padapter) {
384+ res = false;
385+ goto exit;
386+ }
387+ if (!padapter->hw_init_completed) {
388+ res = false;
389+ goto exit;
390+ }
391+
392+ if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) ||
393+ (pmlmepriv->LinkDetectInfo.bBusyTraffic)) {
394+ /* Scan or linking is in progress, do nothing. */
395+ res = true;
396+ } else {
397+ if (rtw_is_scan_deny(padapter)) {
398+ DBG_88E(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
399+ indicate_wx_scan_complete_event(padapter);
400+ return _SUCCESS;
401+ }
402+
403+ spin_lock_bh(&pmlmepriv->lock);
404+
405+ res = rtw_sitesurvey_cmd(padapter, pssid, ssid_max_num, NULL, 0);
406+
407+ spin_unlock_bh(&pmlmepriv->lock);
408+ }
409+exit:
410+
411+ return res;
412+}
413+
414+u8 rtw_set_802_11_authentication_mode(struct adapter *padapter, enum ndis_802_11_auth_mode authmode)
415+{
416+ struct security_priv *psecuritypriv = &padapter->securitypriv;
417+ int res;
418+ u8 ret;
419+
420+ psecuritypriv->ndisauthtype = authmode;
421+
422+ if (psecuritypriv->ndisauthtype > 3)
423+ psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
424+
425+ res = rtw_set_auth(padapter, psecuritypriv);
426+
427+ if (res == _SUCCESS)
428+ ret = true;
429+ else
430+ ret = false;
431+
432+ return ret;
433+}
434+
435+u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
436+{
437+ int keyid, res;
438+ struct security_priv *psecuritypriv = &padapter->securitypriv;
439+ u8 ret = _SUCCESS;
440+
441+ keyid = wep->KeyIndex & 0x3fffffff;
442+
443+ if (keyid >= 4) {
444+ ret = false;
445+ goto exit;
446+ }
447+
448+ switch (wep->KeyLength) {
449+ case 5:
450+ psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
451+ break;
452+ case 13:
453+ psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
454+ break;
455+ default:
456+ psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
457+ break;
458+ }
459+
460+ memcpy(&psecuritypriv->dot11DefKey[keyid].skey[0], &wep->KeyMaterial, wep->KeyLength);
461+
462+ psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
463+
464+ psecuritypriv->dot11PrivacyKeyIndex = keyid;
465+
466+ res = rtw_set_key(padapter, psecuritypriv, keyid, 1);
467+
468+ if (res == _FAIL)
469+ ret = false;
470+exit:
471+
472+ return ret;
473+}
474+
475+u8 rtw_set_802_11_remove_wep(struct adapter *padapter, u32 keyindex)
476+{
477+ u8 ret = _SUCCESS;
478+
479+ if (keyindex >= 0x80000000 || !padapter) {
480+ ret = false;
481+ goto exit;
482+ } else {
483+ int res;
484+ struct security_priv *psecuritypriv = &padapter->securitypriv;
485+ if (keyindex < 4) {
486+ memset(&psecuritypriv->dot11DefKey[keyindex], 0, 16);
487+ res = rtw_set_key(padapter, psecuritypriv, keyindex, 0);
488+ psecuritypriv->dot11DefKeylen[keyindex] = 0;
489+ if (res == _FAIL)
490+ ret = _FAIL;
491+ } else {
492+ ret = _FAIL;
493+ }
494+ }
495+exit:
496+
497+ return ret;
498+}
499+
500+u8 rtw_set_802_11_add_key(struct adapter *padapter, struct ndis_802_11_key *key)
501+{
502+ uint encryptionalgo;
503+ u8 *pbssid;
504+ struct sta_info *stainfo;
505+ u8 bgroup = false;
506+ u8 bgrouptkey = false;/* can be removed later */
507+ u8 ret = _SUCCESS;
508+
509+ if (((key->KeyIndex & 0x80000000) == 0) && ((key->KeyIndex & 0x40000000) > 0)) {
510+ /* It is invalid to clear bit 31 and set bit 30. If the miniport driver encounters this combination, */
511+ /* it must fail the request and return NDIS_STATUS_INVALID_DATA. */
512+ ret = _FAIL;
513+ goto exit;
514+ }
515+
516+ if (key->KeyIndex & 0x40000000) {
517+ /* Pairwise key */
518+
519+ pbssid = get_bssid(&padapter->mlmepriv);
520+ stainfo = rtw_get_stainfo(&padapter->stapriv, pbssid);
521+
522+ if (stainfo && padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
523+ encryptionalgo = stainfo->dot118021XPrivacy;
524+ else
525+ encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
526+
527+ if (key->KeyIndex & 0x000000FF) {
528+ /* The key index is specified in the lower 8 bits by values of zero to 255. */
529+ /* The key index should be set to zero for a Pairwise key, and the driver should fail with */
530+ /* NDIS_STATUS_INVALID_DATA if the lower 8 bits is not zero */
531+ ret = _FAIL;
532+ goto exit;
533+ }
534+
535+ /* check BSSID */
536+ if (is_broadcast_ether_addr(key->BSSID)) {
537+ ret = false;
538+ goto exit;
539+ }
540+
541+ /* Check key length for TKIP. */
542+ if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
543+ ret = _FAIL;
544+ goto exit;
545+ }
546+
547+ /* Check key length for AES. */
548+ if ((encryptionalgo == _AES_) && (key->KeyLength != 16)) {
549+ /* For our supplicant, EAPPkt9x.vxd, cannot differentiate TKIP and AES case. */
550+ if (key->KeyLength == 32) {
551+ key->KeyLength = 16;
552+ } else {
553+ ret = _FAIL;
554+ goto exit;
555+ }
556+ }
557+
558+ /* Check key length for WEP. For NDTEST, 2005.01.27, by rcnjko. */
559+ if ((encryptionalgo == _WEP40_ || encryptionalgo == _WEP104_) &&
560+ (key->KeyLength != 5 && key->KeyLength != 13)) {
561+ ret = _FAIL;
562+ goto exit;
563+ }
564+
565+ bgroup = false;
566+ } else {
567+ /* Group key - KeyIndex(BIT(30) == 0) */
568+ /* when add wep key through add key and didn't assigned encryption type before */
569+ if ((padapter->securitypriv.ndisauthtype <= 3) &&
570+ (padapter->securitypriv.dot118021XGrpPrivacy == 0)) {
571+ switch (key->KeyLength) {
572+ case 5:
573+ padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
574+ break;
575+ case 13:
576+ padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
577+ break;
578+ default:
579+ padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
580+ break;
581+ }
582+
583+ encryptionalgo = padapter->securitypriv.dot11PrivacyAlgrthm;
584+ } else {
585+ encryptionalgo = padapter->securitypriv.dot118021XGrpPrivacy;
586+ }
587+
588+ if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE) && !is_broadcast_ether_addr(key->BSSID)) {
589+ ret = _FAIL;
590+ goto exit;
591+ }
592+
593+ /* Check key length for TKIP */
594+ if ((encryptionalgo == _TKIP_) && (key->KeyLength != 32)) {
595+ ret = _FAIL;
596+ goto exit;
597+ } else if (encryptionalgo == _AES_ && (key->KeyLength != 16 && key->KeyLength != 32)) {
598+ /* Check key length for AES */
599+ /* For NDTEST, we allow keylen = 32 in this case. 2005.01.27, by rcnjko. */
600+ ret = _FAIL;
601+ goto exit;
602+ }
603+
604+ /* Change the key length for EAPPkt9x.vxd. Added by Annie, 2005-11-03. */
605+ if ((encryptionalgo == _AES_) && (key->KeyLength == 32))
606+ key->KeyLength = 16;
607+
608+ if (key->KeyIndex & 0x8000000) {/* error ??? 0x8000_0000 */
609+ bgrouptkey = true;
610+ }
611+
612+ if ((check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE)) &&
613+ (check_fwstate(&padapter->mlmepriv, _FW_LINKED)))
614+ bgrouptkey = true;
615+ bgroup = true;
616+ }
617+
618+ /* If WEP encryption algorithm, just call rtw_set_802_11_add_wep(). */
619+ if ((padapter->securitypriv.dot11AuthAlgrthm != dot11AuthAlgrthm_8021X) &&
620+ (encryptionalgo == _WEP40_ || encryptionalgo == _WEP104_)) {
621+ u32 keyindex;
622+ u32 len = FIELD_OFFSET(struct ndis_802_11_key, KeyMaterial) + key->KeyLength;
623+ struct ndis_802_11_wep *wep = &padapter->securitypriv.ndiswep;
624+
625+ wep->Length = len;
626+ keyindex = key->KeyIndex & 0x7fffffff;
627+ wep->KeyIndex = keyindex;
628+ wep->KeyLength = key->KeyLength;
629+
630+ memcpy(wep->KeyMaterial, key->KeyMaterial, key->KeyLength);
631+ memcpy(&padapter->securitypriv.dot11DefKey[keyindex].skey[0], key->KeyMaterial, key->KeyLength);
632+
633+ padapter->securitypriv.dot11DefKeylen[keyindex] = key->KeyLength;
634+ padapter->securitypriv.dot11PrivacyKeyIndex = keyindex;
635+
636+ ret = rtw_set_802_11_add_wep(padapter, wep);
637+ goto exit;
638+ }
639+ if (key->KeyIndex & 0x20000000) {
640+ /* SetRSC */
641+ if (bgroup) {
642+ unsigned long long keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
643+ memcpy(&padapter->securitypriv.dot11Grprxpn, &keysrc, 8);
644+ } else {
645+ unsigned long long keysrc = key->KeyRSC & 0x00FFFFFFFFFFFFULL;
646+ memcpy(&padapter->securitypriv.dot11Grptxpn, &keysrc, 8);
647+ }
648+ }
649+
650+ /* Indicate this key idx is used for TX */
651+ /* Save the key in KeyMaterial */
652+ if (bgroup) { /* Group transmit key */
653+ int res;
654+
655+ if (bgrouptkey)
656+ padapter->securitypriv.dot118021XGrpKeyid = (u8)key->KeyIndex;
657+ if ((key->KeyIndex & 0x3) == 0) {
658+ ret = _FAIL;
659+ goto exit;
660+ }
661+ memset(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
662+ memset(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
663+ memset(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], 0, 16);
664+
665+ if ((key->KeyIndex & 0x10000000)) {
666+ memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
667+ memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
668+ } else {
669+ memcpy(&padapter->securitypriv.dot118021XGrptxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 24, 8);
670+ memcpy(&padapter->securitypriv.dot118021XGrprxmickey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial + 16, 8);
671+ }
672+
673+ /* set group key by index */
674+ memcpy(&padapter->securitypriv.dot118021XGrpKey[(u8)((key->KeyIndex) & 0x03)], key->KeyMaterial, key->KeyLength);
675+
676+ key->KeyIndex = key->KeyIndex & 0x03;
677+
678+ padapter->securitypriv.binstallGrpkey = true;
679+
680+ padapter->securitypriv.bcheck_grpkey = false;
681+
682+ res = rtw_set_key(padapter, &padapter->securitypriv, key->KeyIndex, 1);
683+
684+ if (res == _FAIL)
685+ ret = _FAIL;
686+
687+ goto exit;
688+
689+ } else { /* Pairwise Key */
690+ u8 res;
691+
692+ pbssid = get_bssid(&padapter->mlmepriv);
693+ stainfo = rtw_get_stainfo(&padapter->stapriv, pbssid);
694+
695+ if (stainfo) {
696+ memset(&stainfo->dot118021x_UncstKey, 0, 16);/* clear keybuffer */
697+
698+ memcpy(&stainfo->dot118021x_UncstKey, key->KeyMaterial, 16);
699+
700+ if (encryptionalgo == _TKIP_) {
701+ padapter->securitypriv.busetkipkey = false;
702+
703+ /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */
704+
705+ /* if TKIP, save the Receive/Transmit MIC key in KeyMaterial[128-255] */
706+ if ((key->KeyIndex & 0x10000000)) {
707+ memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 16, 8);
708+ memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 24, 8);
709+
710+ } else {
711+ memcpy(&stainfo->dot11tkiptxmickey, key->KeyMaterial + 24, 8);
712+ memcpy(&stainfo->dot11tkiprxmickey, key->KeyMaterial + 16, 8);
713+ }
714+ }
715+
716+ /* Set key to CAM through H2C command */
717+ if (bgrouptkey) /* never go to here */
718+ res = rtw_setstakey_cmd(padapter, (unsigned char *)stainfo, false);
719+ else
720+ res = rtw_setstakey_cmd(padapter, (unsigned char *)stainfo, true);
721+ if (!res)
722+ ret = _FAIL;
723+ }
724+ }
725+exit:
726+
727+ return ret;
728+}
729+
730+u8 rtw_set_802_11_remove_key(struct adapter *padapter, struct ndis_802_11_remove_key *key)
731+{
732+ u8 *pbssid;
733+ struct sta_info *stainfo;
734+ u8 bgroup = (key->KeyIndex & 0x4000000) > 0 ? false : true;
735+ u8 keyIndex = (u8)key->KeyIndex & 0x03;
736+ u8 ret = _SUCCESS;
737+
738+ if ((key->KeyIndex & 0xbffffffc) > 0) {
739+ ret = _FAIL;
740+ goto exit;
741+ }
742+
743+ if (bgroup) {
744+ /* clear group key by index */
745+
746+ memset(&padapter->securitypriv.dot118021XGrpKey[keyIndex], 0, 16);
747+
748+ /* \todo Send a H2C Command to Firmware for removing this Key in CAM Entry. */
749+ } else {
750+ pbssid = get_bssid(&padapter->mlmepriv);
751+ stainfo = rtw_get_stainfo(&padapter->stapriv, pbssid);
752+ if (stainfo) {
753+ /* clear key by BSSID */
754+ memset(&stainfo->dot118021x_UncstKey, 0, 16);
755+
756+ /* \todo Send a H2C Command to Firmware for disable this Key in CAM Entry. */
757+ } else {
758+ ret = _FAIL;
759+ goto exit;
760+ }
761+ }
762+exit:
763+
764+ return ret;
765+}
766+
767+/*
768+* rtw_get_cur_max_rate -
769+* @adapter: pointer to struct adapter structure
770+*
771+* Return 0 or 100Kbps
772+*/
773+u16 rtw_get_cur_max_rate(struct adapter *adapter)
774+{
775+ int i = 0;
776+ u8 *p;
777+ u16 rate = 0, max_rate = 0;
778+ struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
779+ struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
780+ struct registry_priv *pregistrypriv = &adapter->registrypriv;
781+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
782+ struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
783+ struct ieee80211_ht_cap *pht_capie;
784+ u8 rf_type = 0;
785+ u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0;
786+ u16 mcs_rate = 0;
787+ u32 ht_ielen = 0;
788+
789+ if (adapter->registrypriv.mp_mode == 1) {
790+ if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
791+ return 0;
792+ }
793+
794+ if ((!check_fwstate(pmlmepriv, _FW_LINKED)) &&
795+ (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
796+ return 0;
797+
798+ if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N)) {
799+ p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength - 12);
800+ if (p && ht_ielen > 0) {
801+ pht_capie = (struct ieee80211_ht_cap *)(p + 2);
802+
803+ memcpy(&mcs_rate, pht_capie->mcs.rx_mask, 2);
804+
805+ /* cur_bwmod is updated by beacon, pmlmeinfo is updated by association response */
806+ bw_40MHz = (pmlmeext->cur_bwmode && (HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH & pmlmeinfo->HT_info.infos[0])) ? 1 : 0;
807+
808+ short_GI_20 = (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & IEEE80211_HT_CAP_SGI_20) ? 1 : 0;
809+ short_GI_40 = (le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info) & IEEE80211_HT_CAP_SGI_40) ? 1 : 0;
810+
811+ rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
812+ max_rate = rtw_mcs_rate(
813+ rf_type,
814+ bw_40MHz & (pregistrypriv->cbw40_enable),
815+ short_GI_20,
816+ short_GI_40,
817+ pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate
818+ );
819+ }
820+ } else {
821+ while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
822+ rate = pcur_bss->SupportedRates[i] & 0x7F;
823+ if (rate > max_rate)
824+ max_rate = rate;
825+ i++;
826+ }
827+
828+ max_rate *= 5;
829+ }
830+
831+ return max_rate;
832+}
833+
834+/*
835+* rtw_set_scan_mode -
836+* @adapter: pointer to struct adapter structure
837+* @scan_mode:
838+*
839+* Return _SUCCESS or _FAIL
840+*/
841+int rtw_set_scan_mode(struct adapter *adapter, enum rt_scan_type scan_mode)
842+{
843+ if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
844+ return _FAIL;
845+
846+ adapter->mlmepriv.scan_mode = scan_mode;
847+
848+ return _SUCCESS;
849+}
850+
851+/*
852+* rtw_set_channel_plan -
853+* @adapter: pointer to struct adapter structure
854+* @channel_plan:
855+*
856+* Return _SUCCESS or _FAIL
857+*/
858+int rtw_set_channel_plan(struct adapter *adapter, u8 channel_plan)
859+{
860+ /* handle by cmd_thread to sync with scan operation */
861+ return rtw_set_chplan_cmd(adapter, channel_plan, 1);
862+}
863+
864+/*
865+* rtw_set_country -
866+* @adapter: pointer to struct adapter structure
867+* @country_code: string of country code
868+*
869+* Return _SUCCESS or _FAIL
870+*/
871+int rtw_set_country(struct adapter *adapter, const char *country_code)
872+{
873+ int channel_plan = RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G;
874+
875+ DBG_88E("%s country_code:%s\n", __func__, country_code);
876+
877+ /* TODO: should have a table to match country code and RT_CHANNEL_DOMAIN */
878+ /* TODO: should consider 2-character and 3-character country code */
879+ if (0 == strcmp(country_code, "US"))
880+ channel_plan = RT_CHANNEL_DOMAIN_FCC;
881+ else if (0 == strcmp(country_code, "EU"))
882+ channel_plan = RT_CHANNEL_DOMAIN_ETSI;
883+ else if (0 == strcmp(country_code, "JP"))
884+ channel_plan = RT_CHANNEL_DOMAIN_MKK;
885+ else if (0 == strcmp(country_code, "CN"))
886+ channel_plan = RT_CHANNEL_DOMAIN_CHINA;
887+ else
888+ DBG_88E("%s unknown country_code:%s\n", __func__, country_code);
889+
890+ return rtw_set_channel_plan(adapter, channel_plan);
891+}
drivers/staging/r8188eu/core/rtw_iol.c+192−0
@@ -0,0 +1,192 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2011 Realtek Corporation. */
3+
4+#include "../include/rtw_iol.h"
5+
6+struct xmit_frame *rtw_IOL_accquire_xmit_frame(struct adapter *adapter)
7+{
8+ struct xmit_frame *xmit_frame;
9+ struct xmit_buf *xmitbuf;
10+ struct pkt_attrib *pattrib;
11+ struct xmit_priv *pxmitpriv = &adapter->xmitpriv;
12+
13+ xmit_frame = rtw_alloc_xmitframe(pxmitpriv);
14+ if (!xmit_frame) {
15+ DBG_88E("%s rtw_alloc_xmitframe return null\n", __func__);
16+ goto exit;
17+ }
18+
19+ xmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
20+ if (!xmitbuf) {
21+ DBG_88E("%s rtw_alloc_xmitbuf return null\n", __func__);
22+ rtw_free_xmitframe(pxmitpriv, xmit_frame);
23+ xmit_frame = NULL;
24+ goto exit;
25+ }
26+
27+ xmit_frame->frame_tag = MGNT_FRAMETAG;
28+ xmit_frame->pxmitbuf = xmitbuf;
29+ xmit_frame->buf_addr = xmitbuf->pbuf;
30+ xmitbuf->priv_data = xmit_frame;
31+
32+ pattrib = &xmit_frame->attrib;
33+ update_mgntframe_attrib(adapter, pattrib);
34+ pattrib->qsel = 0x10;/* Beacon */
35+ pattrib->subtype = WIFI_BEACON;
36+ pattrib->pktlen = 0;
37+ pattrib->last_txcmdsz = 0;
38+exit:
39+ return xmit_frame;
40+}
41+
42+int rtw_IOL_append_cmds(struct xmit_frame *xmit_frame, u8 *IOL_cmds, u32 cmd_len)
43+{
44+ struct pkt_attrib *pattrib = &xmit_frame->attrib;
45+ u16 buf_offset;
46+ u32 ori_len;
47+
48+ buf_offset = TXDESC_OFFSET;
49+ ori_len = buf_offset + pattrib->pktlen;
50+
51+ /* check if the io_buf can accommodate new cmds */
52+ if (ori_len + cmd_len + 8 > MAX_XMITBUF_SZ) {
53+ DBG_88E("%s %u is large than MAX_XMITBUF_SZ:%u, can't accommodate new cmds\n",
54+ __func__, ori_len + cmd_len + 8, MAX_XMITBUF_SZ);
55+ return _FAIL;
56+ }
57+
58+ memcpy(xmit_frame->buf_addr + buf_offset + pattrib->pktlen, IOL_cmds, cmd_len);
59+ pattrib->pktlen += cmd_len;
60+ pattrib->last_txcmdsz += cmd_len;
61+
62+ return _SUCCESS;
63+}
64+
65+bool rtw_IOL_applied(struct adapter *adapter)
66+{
67+ if (1 == adapter->registrypriv.fw_iol)
68+ return true;
69+
70+ if ((2 == adapter->registrypriv.fw_iol) && (!adapter_to_dvobj(adapter)->ishighspeed))
71+ return true;
72+ return false;
73+}
74+
75+int rtw_IOL_exec_cmds_sync(struct adapter *adapter, struct xmit_frame *xmit_frame, u32 max_wating_ms, u32 bndy_cnt)
76+{
77+ return rtw_hal_iol_cmd(adapter, xmit_frame, max_wating_ms, bndy_cnt);
78+}
79+
80+int rtw_IOL_append_LLT_cmd(struct xmit_frame *xmit_frame, u8 page_boundary)
81+{
82+ return _SUCCESS;
83+}
84+
85+int _rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value, u8 mask)
86+{
87+ struct ioreg_cfg cmd = {8, IOREG_CMD_WB_REG, 0x0, 0x0, 0x0};
88+
89+ cmd.address = cpu_to_le16(addr);
90+ cmd.data = cpu_to_le32(value);
91+
92+ if (mask != 0xFF) {
93+ cmd.length = 12;
94+ cmd.mask = cpu_to_le32(mask);
95+ }
96+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
97+}
98+
99+int _rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value, u16 mask)
100+{
101+ struct ioreg_cfg cmd = {8, IOREG_CMD_WW_REG, 0x0, 0x0, 0x0};
102+
103+ cmd.address = cpu_to_le16(addr);
104+ cmd.data = cpu_to_le32(value);
105+
106+ if (mask != 0xFFFF) {
107+ cmd.length = 12;
108+ cmd.mask = cpu_to_le32(mask);
109+ }
110+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
111+}
112+
113+int _rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value, u32 mask)
114+{
115+ struct ioreg_cfg cmd = {8, IOREG_CMD_WD_REG, 0x0, 0x0, 0x0};
116+
117+ cmd.address = cpu_to_le16(addr);
118+ cmd.data = cpu_to_le32(value);
119+
120+ if (mask != 0xFFFFFFFF) {
121+ cmd.length = 12;
122+ cmd.mask = cpu_to_le32(mask);
123+ }
124+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
125+}
126+
127+int _rtw_IOL_append_WRF_cmd(struct xmit_frame *xmit_frame, u8 rf_path, u16 addr, u32 value, u32 mask)
128+{
129+ struct ioreg_cfg cmd = {8, IOREG_CMD_W_RF, 0x0, 0x0, 0x0};
130+
131+ cmd.address = cpu_to_le16((rf_path << 8) | ((addr) & 0xFF));
132+ cmd.data = cpu_to_le32(value);
133+
134+ if (mask != 0x000FFFFF) {
135+ cmd.length = 12;
136+ cmd.mask = cpu_to_le32(mask);
137+ }
138+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
139+}
140+
141+int rtw_IOL_append_DELAY_US_cmd(struct xmit_frame *xmit_frame, u16 us)
142+{
143+ struct ioreg_cfg cmd = {4, IOREG_CMD_DELAY_US, 0x0, 0x0, 0x0};
144+ cmd.address = cpu_to_le16(us);
145+
146+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
147+}
148+
149+int rtw_IOL_append_DELAY_MS_cmd(struct xmit_frame *xmit_frame, u16 ms)
150+{
151+ struct ioreg_cfg cmd = {4, IOREG_CMD_DELAY_US, 0x0, 0x0, 0x0};
152+
153+ cmd.address = cpu_to_le16(ms);
154+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
155+}
156+
157+int rtw_IOL_append_END_cmd(struct xmit_frame *xmit_frame)
158+{
159+ struct ioreg_cfg cmd = {4, IOREG_CMD_END, cpu_to_le16(0xFFFF), cpu_to_le32(0xFF), 0x0};
160+
161+ return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
162+}
163+
164+u8 rtw_IOL_cmd_boundary_handle(struct xmit_frame *pxmit_frame)
165+{
166+ u8 is_cmd_bndy = false;
167+ if (((pxmit_frame->attrib.pktlen + 32) % 256) + 8 >= 256) {
168+ rtw_IOL_append_END_cmd(pxmit_frame);
169+ pxmit_frame->attrib.pktlen = ((((pxmit_frame->attrib.pktlen + 32) / 256) + 1) * 256);
170+
171+ pxmit_frame->attrib.last_txcmdsz = pxmit_frame->attrib.pktlen;
172+ is_cmd_bndy = true;
173+ }
174+ return is_cmd_bndy;
175+}
176+
177+void rtw_IOL_cmd_buf_dump(struct adapter *Adapter, int buf_len, u8 *pbuf)
178+{
179+ int i;
180+ int j = 1;
181+
182+ pr_info("###### %s ######\n", __func__);
183+ for (i = 0; i < buf_len; i++) {
184+ printk("%02x-", *(pbuf + i));
185+
186+ if (j % 32 == 0)
187+ printk("\n");
188+ j++;
189+ }
190+ printk("\n");
191+ pr_info("=============ioreg_cmd len=%d===============\n", buf_len);
192+}
drivers/staging/r8188eu/core/rtw_led.c+1612−0
@@ -0,0 +1,1612 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/* Copyright(c) 2007 - 2012 Realtek Corporation. */
3+
4+#include "../include/drv_types.h"
5+#include "../include/rtw_led.h"
6+
7+/* */
8+/* Description: */
9+/* Callback function of LED BlinkTimer, */
10+/* it just schedules to corresponding BlinkWorkItem/led_blink_hdl */
11+/* */
12+void BlinkTimerCallback(struct timer_list *t)
13+{
14+ struct LED_871x *pLed = from_timer(pLed, t, BlinkTimer);
15+ struct adapter *padapter = pLed->padapter;
16+
17+ if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
18+ return;
19+
20+ _set_workitem(&pLed->BlinkWorkItem);
21+}
22+
23+/* */
24+/* Description: */
25+/* Callback function of LED BlinkWorkItem. */
26+/* We dispatch acture LED blink action according to LedStrategy. */
27+/* */
28+void BlinkWorkItemCallback(struct work_struct *work)
29+{
30+ struct LED_871x *pLed = container_of(work, struct LED_871x, BlinkWorkItem);
31+ BlinkHandler(pLed);
32+}
33+
34+/* */
35+/* Description: */
36+/* Reset status of LED_871x object. */
37+/* */
38+void ResetLedStatus(struct LED_871x *pLed)
39+{
40+ pLed->CurrLedState = RTW_LED_OFF; /* Current LED state. */
41+ pLed->bLedOn = false; /* true if LED is ON, false if LED is OFF. */
42+
43+ pLed->bLedBlinkInProgress = false; /* true if it is blinking, false o.w.. */
44+ pLed->bLedWPSBlinkInProgress = false;
45+
46+ pLed->BlinkTimes = 0; /* Number of times to toggle led state for blinking. */
47+ pLed->BlinkingLedState = LED_UNKNOWN; /* Next state for blinking, either RTW_LED_ON or RTW_LED_OFF are. */
48+
49+ pLed->bLedNoLinkBlinkInProgress = false;
50+ pLed->bLedLinkBlinkInProgress = false;
51+ pLed->bLedStartToLinkBlinkInProgress = false;
52+ pLed->bLedScanBlinkInProgress = false;
53+}
54+
55+/*Description: */
56+/* Initialize an LED_871x object. */
57+void InitLed871x(struct adapter *padapter, struct LED_871x *pLed, enum LED_PIN_871x LedPin)
58+{
59+ pLed->padapter = padapter;
60+ pLed->LedPin = LedPin;
61+
62+ ResetLedStatus(pLed);
63+
64+ timer_setup(&pLed->BlinkTimer, BlinkTimerCallback, 0);
65+ _init_workitem(&pLed->BlinkWorkItem, BlinkWorkItemCallback, pLed);
66+}
67+
68+/* */
69+/* Description: */
70+/* DeInitialize an LED_871x object. */
71+/* */
72+void DeInitLed871x(struct LED_871x *pLed)
73+{
74+ _cancel_workitem_sync(&pLed->BlinkWorkItem);
75+ _cancel_timer_ex(&pLed->BlinkTimer);
76+ ResetLedStatus(pLed);
77+}
78+
79+/* */
80+/* Description: */
81+/* Implementation of LED blinking behavior. */
82+/* It toggle off LED and schedule corresponding timer if necessary. */
83+/* */
84+
85+static void SwLedBlink(struct LED_871x *pLed)
86+{
87+ struct adapter *padapter = pLed->padapter;
88+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
89+ u8 bStopBlinking = false;
90+
91+ /* Change LED according to BlinkingLedState specified. */
92+ if (pLed->BlinkingLedState == RTW_LED_ON)
93+ SwLedOn(padapter, pLed);
94+ else
95+ SwLedOff(padapter, pLed);
96+
97+ /* Determine if we shall change LED state again. */
98+ pLed->BlinkTimes--;
99+ switch (pLed->CurrLedState) {
100+ case LED_BLINK_NORMAL:
101+ if (pLed->BlinkTimes == 0)
102+ bStopBlinking = true;
103+ break;
104+ case LED_BLINK_StartToBlink:
105+ if (check_fwstate(pmlmepriv, _FW_LINKED) && check_fwstate(pmlmepriv, WIFI_STATION_STATE))
106+ bStopBlinking = true;
107+ if (check_fwstate(pmlmepriv, _FW_LINKED) &&
108+ (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
109+ check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
110+ bStopBlinking = true;
111+ else if (pLed->BlinkTimes == 0)
112+ bStopBlinking = true;
113+ break;
114+ case LED_BLINK_WPS:
115+ if (pLed->BlinkTimes == 0)
116+ bStopBlinking = true;
117+ break;
118+ default:
119+ bStopBlinking = true;
120+ break;
121+ }
122+
123+ if (bStopBlinking) {
124+ if (check_fwstate(pmlmepriv, _FW_LINKED) && !pLed->bLedOn) {
125+ SwLedOn(padapter, pLed);
126+ } else if (check_fwstate(pmlmepriv, _FW_LINKED) && pLed->bLedOn) {
127+ SwLedOff(padapter, pLed);
128+ }
129+ pLed->BlinkTimes = 0;
130+ pLed->bLedBlinkInProgress = false;
131+ } else {
132+ /* Assign LED state to toggle. */
133+ if (pLed->BlinkingLedState == RTW_LED_ON)
134+ pLed->BlinkingLedState = RTW_LED_OFF;
135+ else
136+ pLed->BlinkingLedState = RTW_LED_ON;
137+
138+ /* Schedule a timer to toggle LED state. */
139+ switch (pLed->CurrLedState) {
140+ case LED_BLINK_NORMAL:
141+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
142+ break;
143+ case LED_BLINK_SLOWLY:
144+ case LED_BLINK_StartToBlink:
145+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SLOWLY_INTERVAL);
146+ break;
147+ case LED_BLINK_WPS:
148+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LONG_INTERVAL);
149+ break;
150+ default:
151+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SLOWLY_INTERVAL);
152+ break;
153+ }
154+ }
155+}
156+
157+static void SwLedBlink1(struct LED_871x *pLed)
158+{
159+ struct adapter *padapter = pLed->padapter;
160+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
161+ u8 bStopBlinking = false;
162+
163+ /* Change LED according to BlinkingLedState specified. */
164+ if (pLed->BlinkingLedState == RTW_LED_ON)
165+ SwLedOn(padapter, pLed);
166+ else
167+ SwLedOff(padapter, pLed);
168+
169+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
170+ SwLedOff(padapter, pLed);
171+ ResetLedStatus(pLed);
172+ return;
173+ }
174+
175+ switch (pLed->CurrLedState) {
176+ case LED_BLINK_SLOWLY:
177+ if (pLed->bLedOn)
178+ pLed->BlinkingLedState = RTW_LED_OFF;
179+ else
180+ pLed->BlinkingLedState = RTW_LED_ON;
181+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
182+ break;
183+ case LED_BLINK_NORMAL:
184+ if (pLed->bLedOn)
185+ pLed->BlinkingLedState = RTW_LED_OFF;
186+ else
187+ pLed->BlinkingLedState = RTW_LED_ON;
188+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LINK_INTERVAL_ALPHA);
189+ break;
190+ case LED_BLINK_SCAN:
191+ pLed->BlinkTimes--;
192+ if (pLed->BlinkTimes == 0)
193+ bStopBlinking = true;
194+ if (bStopBlinking) {
195+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
196+ pLed->bLedLinkBlinkInProgress = true;
197+ pLed->CurrLedState = LED_BLINK_NORMAL;
198+ if (pLed->bLedOn)
199+ pLed->BlinkingLedState = RTW_LED_OFF;
200+ else
201+ pLed->BlinkingLedState = RTW_LED_ON;
202+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LINK_INTERVAL_ALPHA);
203+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
204+ pLed->bLedNoLinkBlinkInProgress = true;
205+ pLed->CurrLedState = LED_BLINK_SLOWLY;
206+ if (pLed->bLedOn)
207+ pLed->BlinkingLedState = RTW_LED_OFF;
208+ else
209+ pLed->BlinkingLedState = RTW_LED_ON;
210+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
211+ }
212+ pLed->bLedScanBlinkInProgress = false;
213+ } else {
214+ if (pLed->bLedOn)
215+ pLed->BlinkingLedState = RTW_LED_OFF;
216+ else
217+ pLed->BlinkingLedState = RTW_LED_ON;
218+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
219+ }
220+ break;
221+ case LED_BLINK_TXRX:
222+ pLed->BlinkTimes--;
223+ if (pLed->BlinkTimes == 0)
224+ bStopBlinking = true;
225+ if (bStopBlinking) {
226+ if (check_fwstate(pmlmepriv, _FW_LINKED)) {
227+ pLed->bLedLinkBlinkInProgress = true;
228+ pLed->CurrLedState = LED_BLINK_NORMAL;
229+ if (pLed->bLedOn)
230+ pLed->BlinkingLedState = RTW_LED_OFF;
231+ else
232+ pLed->BlinkingLedState = RTW_LED_ON;
233+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LINK_INTERVAL_ALPHA);
234+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
235+ pLed->bLedNoLinkBlinkInProgress = true;
236+ pLed->CurrLedState = LED_BLINK_SLOWLY;
237+ if (pLed->bLedOn)
238+ pLed->BlinkingLedState = RTW_LED_OFF;
239+ else
240+ pLed->BlinkingLedState = RTW_LED_ON;
241+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
242+ }
243+ pLed->BlinkTimes = 0;
244+ pLed->bLedBlinkInProgress = false;
245+ } else {
246+ if (pLed->bLedOn)
247+ pLed->BlinkingLedState = RTW_LED_OFF;
248+ else
249+ pLed->BlinkingLedState = RTW_LED_ON;
250+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
251+ }
252+ break;
253+ case LED_BLINK_WPS:
254+ if (pLed->bLedOn)
255+ pLed->BlinkingLedState = RTW_LED_OFF;
256+ else
257+ pLed->BlinkingLedState = RTW_LED_ON;
258+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
259+ break;
260+ case LED_BLINK_WPS_STOP: /* WPS success */
261+ if (pLed->BlinkingLedState == RTW_LED_ON)
262+ bStopBlinking = false;
263+ else
264+ bStopBlinking = true;
265+
266+ if (bStopBlinking) {
267+ pLed->bLedLinkBlinkInProgress = true;
268+ pLed->CurrLedState = LED_BLINK_NORMAL;
269+ if (pLed->bLedOn)
270+ pLed->BlinkingLedState = RTW_LED_OFF;
271+ else
272+ pLed->BlinkingLedState = RTW_LED_ON;
273+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LINK_INTERVAL_ALPHA);
274+
275+ pLed->bLedWPSBlinkInProgress = false;
276+ } else {
277+ pLed->BlinkingLedState = RTW_LED_OFF;
278+ _set_timer(&pLed->BlinkTimer, LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
279+ }
280+ break;
281+ default:
282+ break;
283+ }
284+}
285+
286+static void SwLedBlink2(struct LED_871x *pLed)
287+{
288+ struct adapter *padapter = pLed->padapter;
289+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
290+ u8 bStopBlinking = false;
291+
292+ /* Change LED according to BlinkingLedState specified. */
293+ if (pLed->BlinkingLedState == RTW_LED_ON)
294+ SwLedOn(padapter, pLed);
295+ else
296+ SwLedOff(padapter, pLed);
297+
298+ switch (pLed->CurrLedState) {
299+ case LED_BLINK_SCAN:
300+ pLed->BlinkTimes--;
301+ if (pLed->BlinkTimes == 0)
302+ bStopBlinking = true;
303+ if (bStopBlinking) {
304+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
305+ SwLedOff(padapter, pLed);
306+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
307+ pLed->CurrLedState = RTW_LED_ON;
308+ pLed->BlinkingLedState = RTW_LED_ON;
309+ SwLedOn(padapter, pLed);
310+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
311+ pLed->CurrLedState = RTW_LED_OFF;
312+ pLed->BlinkingLedState = RTW_LED_OFF;
313+ SwLedOff(padapter, pLed);
314+ }
315+ pLed->bLedScanBlinkInProgress = false;
316+ } else {
317+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
318+ SwLedOff(padapter, pLed);
319+ } else {
320+ if (pLed->bLedOn)
321+ pLed->BlinkingLedState = RTW_LED_OFF;
322+ else
323+ pLed->BlinkingLedState = RTW_LED_ON;
324+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
325+ }
326+ }
327+ break;
328+ case LED_BLINK_TXRX:
329+ pLed->BlinkTimes--;
330+ if (pLed->BlinkTimes == 0)
331+ bStopBlinking = true;
332+ if (bStopBlinking) {
333+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
334+ SwLedOff(padapter, pLed);
335+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
336+ pLed->CurrLedState = RTW_LED_ON;
337+ pLed->BlinkingLedState = RTW_LED_ON;
338+ SwLedOn(padapter, pLed);
339+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
340+ pLed->CurrLedState = RTW_LED_OFF;
341+ pLed->BlinkingLedState = RTW_LED_OFF;
342+ SwLedOff(padapter, pLed);
343+ }
344+ pLed->bLedBlinkInProgress = false;
345+ } else {
346+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
347+ SwLedOff(padapter, pLed);
348+ } else {
349+ if (pLed->bLedOn)
350+ pLed->BlinkingLedState = RTW_LED_OFF;
351+ else
352+ pLed->BlinkingLedState = RTW_LED_ON;
353+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
354+ }
355+ }
356+ break;
357+ default:
358+ break;
359+ }
360+}
361+
362+static void SwLedBlink3(struct LED_871x *pLed)
363+{
364+ struct adapter *padapter = pLed->padapter;
365+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
366+ u8 bStopBlinking = false;
367+
368+ /* Change LED according to BlinkingLedState specified. */
369+ if (pLed->BlinkingLedState == RTW_LED_ON) {
370+ SwLedOn(padapter, pLed);
371+ } else {
372+ if (pLed->CurrLedState != LED_BLINK_WPS_STOP)
373+ SwLedOff(padapter, pLed);
374+ }
375+
376+ switch (pLed->CurrLedState) {
377+ case LED_BLINK_SCAN:
378+ pLed->BlinkTimes--;
379+ if (pLed->BlinkTimes == 0)
380+ bStopBlinking = true;
381+ if (bStopBlinking) {
382+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
383+ SwLedOff(padapter, pLed);
384+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
385+ pLed->CurrLedState = RTW_LED_ON;
386+ pLed->BlinkingLedState = RTW_LED_ON;
387+ if (!pLed->bLedOn)
388+ SwLedOn(padapter, pLed);
389+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
390+ pLed->CurrLedState = RTW_LED_OFF;
391+ pLed->BlinkingLedState = RTW_LED_OFF;
392+ if (pLed->bLedOn)
393+ SwLedOff(padapter, pLed);
394+ }
395+ pLed->bLedScanBlinkInProgress = false;
396+ } else {
397+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
398+ SwLedOff(padapter, pLed);
399+ } else {
400+ if (pLed->bLedOn)
401+ pLed->BlinkingLedState = RTW_LED_OFF;
402+ else
403+ pLed->BlinkingLedState = RTW_LED_ON;
404+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
405+ }
406+ }
407+ break;
408+ case LED_BLINK_TXRX:
409+ pLed->BlinkTimes--;
410+ if (pLed->BlinkTimes == 0)
411+ bStopBlinking = true;
412+ if (bStopBlinking) {
413+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
414+ SwLedOff(padapter, pLed);
415+ } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
416+ pLed->CurrLedState = RTW_LED_ON;
417+ pLed->BlinkingLedState = RTW_LED_ON;
418+ if (!pLed->bLedOn)
419+ SwLedOn(padapter, pLed);
420+ } else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
421+ pLed->CurrLedState = RTW_LED_OFF;
422+ pLed->BlinkingLedState = RTW_LED_OFF;
423+
424+ if (pLed->bLedOn)
425+ SwLedOff(padapter, pLed);
426+ }
427+ pLed->bLedBlinkInProgress = false;
428+ } else {
429+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
430+ SwLedOff(padapter, pLed);
431+ } else {
432+ if (pLed->bLedOn)
433+ pLed->BlinkingLedState = RTW_LED_OFF;
434+ else
435+ pLed->BlinkingLedState = RTW_LED_ON;
436+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
437+ }
438+ }
439+ break;
440+ case LED_BLINK_WPS:
441+ if (pLed->bLedOn)
442+ pLed->BlinkingLedState = RTW_LED_OFF;
443+ else
444+ pLed->BlinkingLedState = RTW_LED_ON;
445+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
446+ break;
447+ case LED_BLINK_WPS_STOP: /* WPS success */
448+ if (pLed->BlinkingLedState == RTW_LED_ON) {
449+ pLed->BlinkingLedState = RTW_LED_OFF;
450+ _set_timer(&pLed->BlinkTimer, LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
451+ bStopBlinking = false;
452+ } else {
453+ bStopBlinking = true;
454+ }
455+ if (bStopBlinking) {
456+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
457+ SwLedOff(padapter, pLed);
458+ } else {
459+ pLed->CurrLedState = RTW_LED_ON;
460+ pLed->BlinkingLedState = RTW_LED_ON;
461+ SwLedOn(padapter, pLed);
462+ }
463+ pLed->bLedWPSBlinkInProgress = false;
464+ }
465+ break;
466+ default:
467+ break;
468+ }
469+}
470+
471+static void SwLedBlink4(struct LED_871x *pLed)
472+{
473+ struct adapter *padapter = pLed->padapter;
474+ struct led_priv *ledpriv = &padapter->ledpriv;
475+ struct LED_871x *pLed1 = &ledpriv->SwLed1;
476+ u8 bStopBlinking = false;
477+
478+ /* Change LED according to BlinkingLedState specified. */
479+ if (pLed->BlinkingLedState == RTW_LED_ON)
480+ SwLedOn(padapter, pLed);
481+ else
482+ SwLedOff(padapter, pLed);
483+
484+ if (!pLed1->bLedWPSBlinkInProgress && pLed1->BlinkingLedState == LED_UNKNOWN) {
485+ pLed1->BlinkingLedState = RTW_LED_OFF;
486+ pLed1->CurrLedState = RTW_LED_OFF;
487+ SwLedOff(padapter, pLed1);
488+ }
489+
490+ switch (pLed->CurrLedState) {
491+ case LED_BLINK_SLOWLY:
492+ if (pLed->bLedOn)
493+ pLed->BlinkingLedState = RTW_LED_OFF;
494+ else
495+ pLed->BlinkingLedState = RTW_LED_ON;
496+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
497+ break;
498+ case LED_BLINK_StartToBlink:
499+ if (pLed->bLedOn) {
500+ pLed->BlinkingLedState = RTW_LED_OFF;
501+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SLOWLY_INTERVAL);
502+ } else {
503+ pLed->BlinkingLedState = RTW_LED_ON;
504+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
505+ }
506+ break;
507+ case LED_BLINK_SCAN:
508+ pLed->BlinkTimes--;
509+ if (pLed->BlinkTimes == 0)
510+ bStopBlinking = false;
511+ if (bStopBlinking) {
512+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
513+ SwLedOff(padapter, pLed);
514+ } else {
515+ pLed->bLedNoLinkBlinkInProgress = false;
516+ pLed->CurrLedState = LED_BLINK_SLOWLY;
517+ if (pLed->bLedOn)
518+ pLed->BlinkingLedState = RTW_LED_OFF;
519+ else
520+ pLed->BlinkingLedState = RTW_LED_ON;
521+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
522+ }
523+ pLed->bLedScanBlinkInProgress = false;
524+ } else {
525+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
526+ SwLedOff(padapter, pLed);
527+ } else {
528+ if (pLed->bLedOn)
529+ pLed->BlinkingLedState = RTW_LED_OFF;
530+ else
531+ pLed->BlinkingLedState = RTW_LED_ON;
532+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
533+ }
534+ }
535+ break;
536+ case LED_BLINK_TXRX:
537+ pLed->BlinkTimes--;
538+ if (pLed->BlinkTimes == 0)
539+ bStopBlinking = true;
540+ if (bStopBlinking) {
541+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
542+ SwLedOff(padapter, pLed);
543+ } else {
544+ pLed->bLedNoLinkBlinkInProgress = true;
545+ pLed->CurrLedState = LED_BLINK_SLOWLY;
546+ if (pLed->bLedOn)
547+ pLed->BlinkingLedState = RTW_LED_OFF;
548+ else
549+ pLed->BlinkingLedState = RTW_LED_ON;
550+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
551+ }
552+ pLed->bLedBlinkInProgress = false;
553+ } else {
554+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
555+ SwLedOff(padapter, pLed);
556+ } else {
557+ if (pLed->bLedOn)
558+ pLed->BlinkingLedState = RTW_LED_OFF;
559+ else
560+ pLed->BlinkingLedState = RTW_LED_ON;
561+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
562+ }
563+ }
564+ break;
565+ case LED_BLINK_WPS:
566+ if (pLed->bLedOn) {
567+ pLed->BlinkingLedState = RTW_LED_OFF;
568+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SLOWLY_INTERVAL);
569+ } else {
570+ pLed->BlinkingLedState = RTW_LED_ON;
571+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
572+ }
573+ break;
574+ case LED_BLINK_WPS_STOP: /* WPS authentication fail */
575+ if (pLed->bLedOn)
576+ pLed->BlinkingLedState = RTW_LED_OFF;
577+ else
578+ pLed->BlinkingLedState = RTW_LED_ON;
579+
580+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
581+ break;
582+ case LED_BLINK_WPS_STOP_OVERLAP: /* WPS session overlap */
583+ pLed->BlinkTimes--;
584+ if (pLed->BlinkTimes == 0) {
585+ if (pLed->bLedOn)
586+ pLed->BlinkTimes = 1;
587+ else
588+ bStopBlinking = true;
589+ }
590+
591+ if (bStopBlinking) {
592+ pLed->BlinkTimes = 10;
593+ pLed->BlinkingLedState = RTW_LED_ON;
594+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LINK_INTERVAL_ALPHA);
595+ } else {
596+ if (pLed->bLedOn)
597+ pLed->BlinkingLedState = RTW_LED_OFF;
598+ else
599+ pLed->BlinkingLedState = RTW_LED_ON;
600+
601+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
602+ }
603+ break;
604+ default:
605+ break;
606+ }
607+}
608+
609+static void SwLedBlink5(struct LED_871x *pLed)
610+{
611+ struct adapter *padapter = pLed->padapter;
612+ u8 bStopBlinking = false;
613+
614+ /* Change LED according to BlinkingLedState specified. */
615+ if (pLed->BlinkingLedState == RTW_LED_ON)
616+ SwLedOn(padapter, pLed);
617+ else
618+ SwLedOff(padapter, pLed);
619+
620+ switch (pLed->CurrLedState) {
621+ case LED_BLINK_SCAN:
622+ pLed->BlinkTimes--;
623+ if (pLed->BlinkTimes == 0)
624+ bStopBlinking = true;
625+
626+ if (bStopBlinking) {
627+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
628+ pLed->CurrLedState = RTW_LED_OFF;
629+ pLed->BlinkingLedState = RTW_LED_OFF;
630+ if (pLed->bLedOn)
631+ SwLedOff(padapter, pLed);
632+ } else {
633+ pLed->CurrLedState = RTW_LED_ON;
634+ pLed->BlinkingLedState = RTW_LED_ON;
635+ if (!pLed->bLedOn)
636+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
637+ }
638+
639+ pLed->bLedScanBlinkInProgress = false;
640+ } else {
641+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
642+ SwLedOff(padapter, pLed);
643+ } else {
644+ if (pLed->bLedOn)
645+ pLed->BlinkingLedState = RTW_LED_OFF;
646+ else
647+ pLed->BlinkingLedState = RTW_LED_ON;
648+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
649+ }
650+ }
651+ break;
652+ case LED_BLINK_TXRX:
653+ pLed->BlinkTimes--;
654+ if (pLed->BlinkTimes == 0)
655+ bStopBlinking = true;
656+
657+ if (bStopBlinking) {
658+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
659+ pLed->CurrLedState = RTW_LED_OFF;
660+ pLed->BlinkingLedState = RTW_LED_OFF;
661+ if (pLed->bLedOn)
662+ SwLedOff(padapter, pLed);
663+ } else {
664+ pLed->CurrLedState = RTW_LED_ON;
665+ pLed->BlinkingLedState = RTW_LED_ON;
666+ if (!pLed->bLedOn)
667+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
668+ }
669+
670+ pLed->bLedBlinkInProgress = false;
671+ } else {
672+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
673+ SwLedOff(padapter, pLed);
674+ } else {
675+ if (pLed->bLedOn)
676+ pLed->BlinkingLedState = RTW_LED_OFF;
677+ else
678+ pLed->BlinkingLedState = RTW_LED_ON;
679+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
680+ }
681+ }
682+ break;
683+
684+ default:
685+ break;
686+ }
687+}
688+
689+static void SwLedBlink6(struct LED_871x *pLed)
690+{
691+ struct adapter *padapter = pLed->padapter;
692+
693+ /* Change LED according to BlinkingLedState specified. */
694+ if (pLed->BlinkingLedState == RTW_LED_ON)
695+ SwLedOn(padapter, pLed);
696+ else
697+ SwLedOff(padapter, pLed);
698+}
699+
700+ /* ALPHA, added by chiyoko, 20090106 */
701+static void SwLedControlMode1(struct adapter *padapter, enum LED_CTL_MODE LedAction)
702+{
703+ struct led_priv *ledpriv = &padapter->ledpriv;
704+ struct LED_871x *pLed = &ledpriv->SwLed0;
705+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
706+
707+ switch (LedAction) {
708+ case LED_CTL_POWER_ON:
709+ case LED_CTL_START_TO_LINK:
710+ case LED_CTL_NO_LINK:
711+ if (!pLed->bLedNoLinkBlinkInProgress) {
712+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
713+ return;
714+ if (pLed->bLedLinkBlinkInProgress) {
715+ _cancel_timer_ex(&pLed->BlinkTimer);
716+ pLed->bLedLinkBlinkInProgress = false;
717+ }
718+ if (pLed->bLedBlinkInProgress) {
719+ _cancel_timer_ex(&pLed->BlinkTimer);
720+ pLed->bLedBlinkInProgress = false;
721+ }
722+
723+ pLed->bLedNoLinkBlinkInProgress = true;
724+ pLed->CurrLedState = LED_BLINK_SLOWLY;
725+ if (pLed->bLedOn)
726+ pLed->BlinkingLedState = RTW_LED_OFF;
727+ else
728+ pLed->BlinkingLedState = RTW_LED_ON;
729+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
730+ }
731+ break;
732+ case LED_CTL_LINK:
733+ if (!pLed->bLedLinkBlinkInProgress) {
734+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
735+ return;
736+ if (pLed->bLedNoLinkBlinkInProgress) {
737+ _cancel_timer_ex(&pLed->BlinkTimer);
738+ pLed->bLedNoLinkBlinkInProgress = false;
739+ }
740+ if (pLed->bLedBlinkInProgress) {
741+ _cancel_timer_ex(&pLed->BlinkTimer);
742+ pLed->bLedBlinkInProgress = false;
743+ }
744+ pLed->bLedLinkBlinkInProgress = true;
745+ pLed->CurrLedState = LED_BLINK_NORMAL;
746+ if (pLed->bLedOn)
747+ pLed->BlinkingLedState = RTW_LED_OFF;
748+ else
749+ pLed->BlinkingLedState = RTW_LED_ON;
750+ _set_timer(&pLed->BlinkTimer, LED_BLINK_LINK_INTERVAL_ALPHA);
751+ }
752+ break;
753+ case LED_CTL_SITE_SURVEY:
754+ if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
755+ ;
756+ } else if (!pLed->bLedScanBlinkInProgress) {
757+ if (IS_LED_WPS_BLINKING(pLed))
758+ return;
759+ if (pLed->bLedNoLinkBlinkInProgress) {
760+ _cancel_timer_ex(&pLed->BlinkTimer);
761+ pLed->bLedNoLinkBlinkInProgress = false;
762+ }
763+ if (pLed->bLedLinkBlinkInProgress) {
764+ _cancel_timer_ex(&pLed->BlinkTimer);
765+ pLed->bLedLinkBlinkInProgress = false;
766+ }
767+ if (pLed->bLedBlinkInProgress) {
768+ _cancel_timer_ex(&pLed->BlinkTimer);
769+ pLed->bLedBlinkInProgress = false;
770+ }
771+ pLed->bLedScanBlinkInProgress = true;
772+ pLed->CurrLedState = LED_BLINK_SCAN;
773+ pLed->BlinkTimes = 24;
774+ if (pLed->bLedOn)
775+ pLed->BlinkingLedState = RTW_LED_OFF;
776+ else
777+ pLed->BlinkingLedState = RTW_LED_ON;
778+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
779+ }
780+ break;
781+ case LED_CTL_TX:
782+ case LED_CTL_RX:
783+ if (!pLed->bLedBlinkInProgress) {
784+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
785+ return;
786+ if (pLed->bLedNoLinkBlinkInProgress) {
787+ _cancel_timer_ex(&pLed->BlinkTimer);
788+ pLed->bLedNoLinkBlinkInProgress = false;
789+ }
790+ if (pLed->bLedLinkBlinkInProgress) {
791+ _cancel_timer_ex(&pLed->BlinkTimer);
792+ pLed->bLedLinkBlinkInProgress = false;
793+ }
794+ pLed->bLedBlinkInProgress = true;
795+ pLed->CurrLedState = LED_BLINK_TXRX;
796+ pLed->BlinkTimes = 2;
797+ if (pLed->bLedOn)
798+ pLed->BlinkingLedState = RTW_LED_OFF;
799+ else
800+ pLed->BlinkingLedState = RTW_LED_ON;
801+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
802+ }
803+ break;
804+ case LED_CTL_START_WPS: /* wait until xinpin finish */
805+ case LED_CTL_START_WPS_BOTTON:
806+ if (!pLed->bLedWPSBlinkInProgress) {
807+ if (pLed->bLedNoLinkBlinkInProgress) {
808+ _cancel_timer_ex(&pLed->BlinkTimer);
809+ pLed->bLedNoLinkBlinkInProgress = false;
810+ }
811+ if (pLed->bLedLinkBlinkInProgress) {
812+ _cancel_timer_ex(&pLed->BlinkTimer);
813+ pLed->bLedLinkBlinkInProgress = false;
814+ }
815+ if (pLed->bLedBlinkInProgress) {
816+ _cancel_timer_ex(&pLed->BlinkTimer);
817+ pLed->bLedBlinkInProgress = false;
818+ }
819+ if (pLed->bLedScanBlinkInProgress) {
820+ _cancel_timer_ex(&pLed->BlinkTimer);
821+ pLed->bLedScanBlinkInProgress = false;
822+ }
823+ pLed->bLedWPSBlinkInProgress = true;
824+ pLed->CurrLedState = LED_BLINK_WPS;
825+ if (pLed->bLedOn)
826+ pLed->BlinkingLedState = RTW_LED_OFF;
827+ else
828+ pLed->BlinkingLedState = RTW_LED_ON;
829+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
830+ }
831+ break;
832+ case LED_CTL_STOP_WPS:
833+ if (pLed->bLedNoLinkBlinkInProgress) {
834+ _cancel_timer_ex(&pLed->BlinkTimer);
835+ pLed->bLedNoLinkBlinkInProgress = false;
836+ }
837+ if (pLed->bLedLinkBlinkInProgress) {
838+ _cancel_timer_ex(&pLed->BlinkTimer);
839+ pLed->bLedLinkBlinkInProgress = false;
840+ }
841+ if (pLed->bLedBlinkInProgress) {
842+ _cancel_timer_ex(&pLed->BlinkTimer);
843+ pLed->bLedBlinkInProgress = false;
844+ }
845+ if (pLed->bLedScanBlinkInProgress) {
846+ _cancel_timer_ex(&pLed->BlinkTimer);
847+ pLed->bLedScanBlinkInProgress = false;
848+ }
849+ if (pLed->bLedWPSBlinkInProgress)
850+ _cancel_timer_ex(&pLed->BlinkTimer);
851+ else
852+ pLed->bLedWPSBlinkInProgress = true;
853+ pLed->CurrLedState = LED_BLINK_WPS_STOP;
854+ if (pLed->bLedOn) {
855+ pLed->BlinkingLedState = RTW_LED_OFF;
856+ _set_timer(&pLed->BlinkTimer, LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
857+ } else {
858+ pLed->BlinkingLedState = RTW_LED_ON;
859+ _set_timer(&pLed->BlinkTimer, 0);
860+ }
861+ break;
862+ case LED_CTL_STOP_WPS_FAIL:
863+ if (pLed->bLedWPSBlinkInProgress) {
864+ _cancel_timer_ex(&pLed->BlinkTimer);
865+ pLed->bLedWPSBlinkInProgress = false;
866+ }
867+ pLed->bLedNoLinkBlinkInProgress = true;
868+ pLed->CurrLedState = LED_BLINK_SLOWLY;
869+ if (pLed->bLedOn)
870+ pLed->BlinkingLedState = RTW_LED_OFF;
871+ else
872+ pLed->BlinkingLedState = RTW_LED_ON;
873+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
874+ break;
875+ case LED_CTL_POWER_OFF:
876+ pLed->CurrLedState = RTW_LED_OFF;
877+ pLed->BlinkingLedState = RTW_LED_OFF;
878+ if (pLed->bLedNoLinkBlinkInProgress) {
879+ _cancel_timer_ex(&pLed->BlinkTimer);
880+ pLed->bLedNoLinkBlinkInProgress = false;
881+ }
882+ if (pLed->bLedLinkBlinkInProgress) {
883+ _cancel_timer_ex(&pLed->BlinkTimer);
884+ pLed->bLedLinkBlinkInProgress = false;
885+ }
886+ if (pLed->bLedBlinkInProgress) {
887+ _cancel_timer_ex(&pLed->BlinkTimer);
888+ pLed->bLedBlinkInProgress = false;
889+ }
890+ if (pLed->bLedWPSBlinkInProgress) {
891+ _cancel_timer_ex(&pLed->BlinkTimer);
892+ pLed->bLedWPSBlinkInProgress = false;
893+ }
894+ if (pLed->bLedScanBlinkInProgress) {
895+ _cancel_timer_ex(&pLed->BlinkTimer);
896+ pLed->bLedScanBlinkInProgress = false;
897+ }
898+ SwLedOff(padapter, pLed);
899+ break;
900+ default:
901+ break;
902+ }
903+}
904+
905+ /* Arcadyan/Sitecom , added by chiyoko, 20090216 */
906+static void SwLedControlMode2(struct adapter *padapter, enum LED_CTL_MODE LedAction)
907+{
908+ struct led_priv *ledpriv = &padapter->ledpriv;
909+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
910+ struct LED_871x *pLed = &ledpriv->SwLed0;
911+
912+ switch (LedAction) {
913+ case LED_CTL_SITE_SURVEY:
914+ if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
915+ } else if (!pLed->bLedScanBlinkInProgress) {
916+ if (IS_LED_WPS_BLINKING(pLed))
917+ return;
918+
919+ if (pLed->bLedBlinkInProgress) {
920+ _cancel_timer_ex(&pLed->BlinkTimer);
921+ pLed->bLedBlinkInProgress = false;
922+ }
923+ pLed->bLedScanBlinkInProgress = true;
924+ pLed->CurrLedState = LED_BLINK_SCAN;
925+ pLed->BlinkTimes = 24;
926+ if (pLed->bLedOn)
927+ pLed->BlinkingLedState = RTW_LED_OFF;
928+ else
929+ pLed->BlinkingLedState = RTW_LED_ON;
930+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
931+ }
932+ break;
933+ case LED_CTL_TX:
934+ case LED_CTL_RX:
935+ if ((!pLed->bLedBlinkInProgress) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
936+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
937+ return;
938+ pLed->bLedBlinkInProgress = true;
939+ pLed->CurrLedState = LED_BLINK_TXRX;
940+ pLed->BlinkTimes = 2;
941+ if (pLed->bLedOn)
942+ pLed->BlinkingLedState = RTW_LED_OFF;
943+ else
944+ pLed->BlinkingLedState = RTW_LED_ON;
945+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
946+ }
947+ break;
948+ case LED_CTL_LINK:
949+ pLed->CurrLedState = RTW_LED_ON;
950+ pLed->BlinkingLedState = RTW_LED_ON;
951+ if (pLed->bLedBlinkInProgress) {
952+ _cancel_timer_ex(&pLed->BlinkTimer);
953+ pLed->bLedBlinkInProgress = false;
954+ }
955+ if (pLed->bLedScanBlinkInProgress) {
956+ _cancel_timer_ex(&pLed->BlinkTimer);
957+ pLed->bLedScanBlinkInProgress = false;
958+ }
959+ _set_timer(&pLed->BlinkTimer, 0);
960+ break;
961+ case LED_CTL_START_WPS: /* wait until xinpin finish */
962+ case LED_CTL_START_WPS_BOTTON:
963+ if (!pLed->bLedWPSBlinkInProgress) {
964+ if (pLed->bLedBlinkInProgress) {
965+ _cancel_timer_ex(&pLed->BlinkTimer);
966+ pLed->bLedBlinkInProgress = false;
967+ }
968+ if (pLed->bLedScanBlinkInProgress) {
969+ _cancel_timer_ex(&pLed->BlinkTimer);
970+ pLed->bLedScanBlinkInProgress = false;
971+ }
972+ pLed->bLedWPSBlinkInProgress = true;
973+ pLed->CurrLedState = RTW_LED_ON;
974+ pLed->BlinkingLedState = RTW_LED_ON;
975+ _set_timer(&pLed->BlinkTimer, 0);
976+ }
977+ break;
978+ case LED_CTL_STOP_WPS:
979+ pLed->bLedWPSBlinkInProgress = false;
980+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
981+ SwLedOff(padapter, pLed);
982+ } else {
983+ pLed->CurrLedState = RTW_LED_ON;
984+ pLed->BlinkingLedState = RTW_LED_ON;
985+ _set_timer(&pLed->BlinkTimer, 0);
986+ }
987+ break;
988+ case LED_CTL_STOP_WPS_FAIL:
989+ pLed->bLedWPSBlinkInProgress = false;
990+ if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
991+ SwLedOff(padapter, pLed);
992+ } else {
993+ pLed->CurrLedState = RTW_LED_OFF;
994+ pLed->BlinkingLedState = RTW_LED_OFF;
995+ _set_timer(&pLed->BlinkTimer, 0);
996+ }
997+ break;
998+ case LED_CTL_START_TO_LINK:
999+ case LED_CTL_NO_LINK:
1000+ if (!IS_LED_BLINKING(pLed)) {
1001+ pLed->CurrLedState = RTW_LED_OFF;
1002+ pLed->BlinkingLedState = RTW_LED_OFF;
1003+ _set_timer(&pLed->BlinkTimer, 0);
1004+ }
1005+ break;
1006+ case LED_CTL_POWER_OFF:
1007+ pLed->CurrLedState = RTW_LED_OFF;
1008+ pLed->BlinkingLedState = RTW_LED_OFF;
1009+ if (pLed->bLedBlinkInProgress) {
1010+ _cancel_timer_ex(&pLed->BlinkTimer);
1011+ pLed->bLedBlinkInProgress = false;
1012+ }
1013+ if (pLed->bLedScanBlinkInProgress) {
1014+ _cancel_timer_ex(&pLed->BlinkTimer);
1015+ pLed->bLedScanBlinkInProgress = false;
1016+ }
1017+ if (pLed->bLedWPSBlinkInProgress) {
1018+ _cancel_timer_ex(&pLed->BlinkTimer);
1019+ pLed->bLedWPSBlinkInProgress = false;
1020+ }
1021+
1022+ _set_timer(&pLed->BlinkTimer, 0);
1023+ break;
1024+ default:
1025+ break;
1026+ }
1027+}
1028+
1029+ /* COREGA, added by chiyoko, 20090316 */
1030+ static void SwLedControlMode3(struct adapter *padapter, enum LED_CTL_MODE LedAction)
1031+{
1032+ struct led_priv *ledpriv = &padapter->ledpriv;
1033+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1034+ struct LED_871x *pLed = &ledpriv->SwLed0;
1035+
1036+ switch (LedAction) {
1037+ case LED_CTL_SITE_SURVEY:
1038+ if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
1039+ } else if (!pLed->bLedScanBlinkInProgress) {
1040+ if (IS_LED_WPS_BLINKING(pLed))
1041+ return;
1042+
1043+ if (pLed->bLedBlinkInProgress) {
1044+ _cancel_timer_ex(&pLed->BlinkTimer);
1045+ pLed->bLedBlinkInProgress = false;
1046+ }
1047+ pLed->bLedScanBlinkInProgress = true;
1048+ pLed->CurrLedState = LED_BLINK_SCAN;
1049+ pLed->BlinkTimes = 24;
1050+ if (pLed->bLedOn)
1051+ pLed->BlinkingLedState = RTW_LED_OFF;
1052+ else
1053+ pLed->BlinkingLedState = RTW_LED_ON;
1054+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
1055+ }
1056+ break;
1057+ case LED_CTL_TX:
1058+ case LED_CTL_RX:
1059+ if ((!pLed->bLedBlinkInProgress) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
1060+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
1061+ return;
1062+ pLed->bLedBlinkInProgress = true;
1063+ pLed->CurrLedState = LED_BLINK_TXRX;
1064+ pLed->BlinkTimes = 2;
1065+ if (pLed->bLedOn)
1066+ pLed->BlinkingLedState = RTW_LED_OFF;
1067+ else
1068+ pLed->BlinkingLedState = RTW_LED_ON;
1069+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
1070+ }
1071+ break;
1072+ case LED_CTL_LINK:
1073+ if (IS_LED_WPS_BLINKING(pLed))
1074+ return;
1075+ pLed->CurrLedState = RTW_LED_ON;
1076+ pLed->BlinkingLedState = RTW_LED_ON;
1077+ if (pLed->bLedBlinkInProgress) {
1078+ _cancel_timer_ex(&pLed->BlinkTimer);
1079+ pLed->bLedBlinkInProgress = false;
1080+ }
1081+ if (pLed->bLedScanBlinkInProgress) {
1082+ _cancel_timer_ex(&pLed->BlinkTimer);
1083+ pLed->bLedScanBlinkInProgress = false;
1084+ }
1085+
1086+ _set_timer(&pLed->BlinkTimer, 0);
1087+ break;
1088+ case LED_CTL_START_WPS: /* wait until xinpin finish */
1089+ case LED_CTL_START_WPS_BOTTON:
1090+ if (!pLed->bLedWPSBlinkInProgress) {
1091+ if (pLed->bLedBlinkInProgress) {
1092+ _cancel_timer_ex(&pLed->BlinkTimer);
1093+ pLed->bLedBlinkInProgress = false;
1094+ }
1095+ if (pLed->bLedScanBlinkInProgress) {
1096+ _cancel_timer_ex(&pLed->BlinkTimer);
1097+ pLed->bLedScanBlinkInProgress = false;
1098+ }
1099+ pLed->bLedWPSBlinkInProgress = true;
1100+ pLed->CurrLedState = LED_BLINK_WPS;
1101+ if (pLed->bLedOn)
1102+ pLed->BlinkingLedState = RTW_LED_OFF;
1103+ else
1104+ pLed->BlinkingLedState = RTW_LED_ON;
1105+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
1106+ }
1107+ break;
1108+ case LED_CTL_STOP_WPS:
1109+ if (pLed->bLedWPSBlinkInProgress) {
1110+ _cancel_timer_ex(&pLed->BlinkTimer);
1111+ pLed->bLedWPSBlinkInProgress = false;
1112+ } else {
1113+ pLed->bLedWPSBlinkInProgress = true;
1114+ }
1115+
1116+ pLed->CurrLedState = LED_BLINK_WPS_STOP;
1117+ if (pLed->bLedOn) {
1118+ pLed->BlinkingLedState = RTW_LED_OFF;
1119+ _set_timer(&pLed->BlinkTimer, LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA);
1120+ } else {
1121+ pLed->BlinkingLedState = RTW_LED_ON;
1122+ _set_timer(&pLed->BlinkTimer, 0);
1123+ }
1124+ break;
1125+ case LED_CTL_STOP_WPS_FAIL:
1126+ if (pLed->bLedWPSBlinkInProgress) {
1127+ _cancel_timer_ex(&pLed->BlinkTimer);
1128+ pLed->bLedWPSBlinkInProgress = false;
1129+ }
1130+ pLed->CurrLedState = RTW_LED_OFF;
1131+ pLed->BlinkingLedState = RTW_LED_OFF;
1132+ _set_timer(&pLed->BlinkTimer, 0);
1133+ break;
1134+ case LED_CTL_START_TO_LINK:
1135+ case LED_CTL_NO_LINK:
1136+ if (!IS_LED_BLINKING(pLed)) {
1137+ pLed->CurrLedState = RTW_LED_OFF;
1138+ pLed->BlinkingLedState = RTW_LED_OFF;
1139+ _set_timer(&pLed->BlinkTimer, 0);
1140+ }
1141+ break;
1142+ case LED_CTL_POWER_OFF:
1143+ pLed->CurrLedState = RTW_LED_OFF;
1144+ pLed->BlinkingLedState = RTW_LED_OFF;
1145+ if (pLed->bLedBlinkInProgress) {
1146+ _cancel_timer_ex(&pLed->BlinkTimer);
1147+ pLed->bLedBlinkInProgress = false;
1148+ }
1149+ if (pLed->bLedScanBlinkInProgress) {
1150+ _cancel_timer_ex(&pLed->BlinkTimer);
1151+ pLed->bLedScanBlinkInProgress = false;
1152+ }
1153+ if (pLed->bLedWPSBlinkInProgress) {
1154+ _cancel_timer_ex(&pLed->BlinkTimer);
1155+ pLed->bLedWPSBlinkInProgress = false;
1156+ }
1157+
1158+ _set_timer(&pLed->BlinkTimer, 0);
1159+ break;
1160+ default:
1161+ break;
1162+ }
1163+}
1164+
1165+ /* Edimax-Belkin, added by chiyoko, 20090413 */
1166+static void SwLedControlMode4(struct adapter *padapter, enum LED_CTL_MODE LedAction)
1167+{
1168+ struct led_priv *ledpriv = &padapter->ledpriv;
1169+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1170+ struct LED_871x *pLed = &ledpriv->SwLed0;
1171+ struct LED_871x *pLed1 = &ledpriv->SwLed1;
1172+
1173+ switch (LedAction) {
1174+ case LED_CTL_START_TO_LINK:
1175+ if (pLed1->bLedWPSBlinkInProgress) {
1176+ pLed1->bLedWPSBlinkInProgress = false;
1177+ _cancel_timer_ex(&pLed1->BlinkTimer);
1178+
1179+ pLed1->BlinkingLedState = RTW_LED_OFF;
1180+ pLed1->CurrLedState = RTW_LED_OFF;
1181+
1182+ if (pLed1->bLedOn)
1183+ _set_timer(&pLed->BlinkTimer, 0);
1184+ }
1185+
1186+ if (!pLed->bLedStartToLinkBlinkInProgress) {
1187+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
1188+ return;
1189+ if (pLed->bLedBlinkInProgress) {
1190+ _cancel_timer_ex(&pLed->BlinkTimer);
1191+ pLed->bLedBlinkInProgress = false;
1192+ }
1193+ if (pLed->bLedNoLinkBlinkInProgress) {
1194+ _cancel_timer_ex(&pLed->BlinkTimer);
1195+ pLed->bLedNoLinkBlinkInProgress = false;
1196+ }
1197+
1198+ pLed->bLedStartToLinkBlinkInProgress = true;
1199+ pLed->CurrLedState = LED_BLINK_StartToBlink;
1200+ if (pLed->bLedOn) {
1201+ pLed->BlinkingLedState = RTW_LED_OFF;
1202+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SLOWLY_INTERVAL);
1203+ } else {
1204+ pLed->BlinkingLedState = RTW_LED_ON;
1205+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
1206+ }
1207+ }
1208+ break;
1209+ case LED_CTL_LINK:
1210+ case LED_CTL_NO_LINK:
1211+ /* LED1 settings */
1212+ if (LedAction == LED_CTL_LINK) {
1213+ if (pLed1->bLedWPSBlinkInProgress) {
1214+ pLed1->bLedWPSBlinkInProgress = false;
1215+ _cancel_timer_ex(&pLed1->BlinkTimer);
1216+
1217+ pLed1->BlinkingLedState = RTW_LED_OFF;
1218+ pLed1->CurrLedState = RTW_LED_OFF;
1219+
1220+ if (pLed1->bLedOn)
1221+ _set_timer(&pLed->BlinkTimer, 0);
1222+ }
1223+ }
1224+
1225+ if (!pLed->bLedNoLinkBlinkInProgress) {
1226+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
1227+ return;
1228+ if (pLed->bLedBlinkInProgress) {
1229+ _cancel_timer_ex(&pLed->BlinkTimer);
1230+ pLed->bLedBlinkInProgress = false;
1231+ }
1232+
1233+ pLed->bLedNoLinkBlinkInProgress = true;
1234+ pLed->CurrLedState = LED_BLINK_SLOWLY;
1235+ if (pLed->bLedOn)
1236+ pLed->BlinkingLedState = RTW_LED_OFF;
1237+ else
1238+ pLed->BlinkingLedState = RTW_LED_ON;
1239+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
1240+ }
1241+ break;
1242+ case LED_CTL_SITE_SURVEY:
1243+ if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
1244+ } else if (!pLed->bLedScanBlinkInProgress) {
1245+ if (IS_LED_WPS_BLINKING(pLed))
1246+ return;
1247+
1248+ if (pLed->bLedNoLinkBlinkInProgress) {
1249+ _cancel_timer_ex(&pLed->BlinkTimer);
1250+ pLed->bLedNoLinkBlinkInProgress = false;
1251+ }
1252+ if (pLed->bLedBlinkInProgress) {
1253+ _cancel_timer_ex(&pLed->BlinkTimer);
1254+ pLed->bLedBlinkInProgress = false;
1255+ }
1256+ pLed->bLedScanBlinkInProgress = true;
1257+ pLed->CurrLedState = LED_BLINK_SCAN;
1258+ pLed->BlinkTimes = 24;
1259+ if (pLed->bLedOn)
1260+ pLed->BlinkingLedState = RTW_LED_OFF;
1261+ else
1262+ pLed->BlinkingLedState = RTW_LED_ON;
1263+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
1264+ }
1265+ break;
1266+ case LED_CTL_TX:
1267+ case LED_CTL_RX:
1268+ if (!pLed->bLedBlinkInProgress) {
1269+ if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed))
1270+ return;
1271+ if (pLed->bLedNoLinkBlinkInProgress) {
1272+ _cancel_timer_ex(&pLed->BlinkTimer);
1273+ pLed->bLedNoLinkBlinkInProgress = false;
1274+ }
1275+ pLed->bLedBlinkInProgress = true;
1276+ pLed->CurrLedState = LED_BLINK_TXRX;
1277+ pLed->BlinkTimes = 2;
1278+ if (pLed->bLedOn)
1279+ pLed->BlinkingLedState = RTW_LED_OFF;
1280+ else
1281+ pLed->BlinkingLedState = RTW_LED_ON;
1282+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
1283+ }
1284+ break;
1285+ case LED_CTL_START_WPS: /* wait until xinpin finish */
1286+ case LED_CTL_START_WPS_BOTTON:
1287+ if (pLed1->bLedWPSBlinkInProgress) {
1288+ pLed1->bLedWPSBlinkInProgress = false;
1289+ _cancel_timer_ex(&pLed1->BlinkTimer);
1290+
1291+ pLed1->BlinkingLedState = RTW_LED_OFF;
1292+ pLed1->CurrLedState = RTW_LED_OFF;
1293+
1294+ if (pLed1->bLedOn)
1295+ _set_timer(&pLed->BlinkTimer, 0);
1296+ }
1297+
1298+ if (!pLed->bLedWPSBlinkInProgress) {
1299+ if (pLed->bLedNoLinkBlinkInProgress) {
1300+ _cancel_timer_ex(&pLed->BlinkTimer);
1301+ pLed->bLedNoLinkBlinkInProgress = false;
1302+ }
1303+ if (pLed->bLedBlinkInProgress) {
1304+ _cancel_timer_ex(&pLed->BlinkTimer);
1305+ pLed->bLedBlinkInProgress = false;
1306+ }
1307+ if (pLed->bLedScanBlinkInProgress) {
1308+ _cancel_timer_ex(&pLed->BlinkTimer);
1309+ pLed->bLedScanBlinkInProgress = false;
1310+ }
1311+ pLed->bLedWPSBlinkInProgress = true;
1312+ pLed->CurrLedState = LED_BLINK_WPS;
1313+ if (pLed->bLedOn) {
1314+ pLed->BlinkingLedState = RTW_LED_OFF;
1315+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SLOWLY_INTERVAL);
1316+ } else {
1317+ pLed->BlinkingLedState = RTW_LED_ON;
1318+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
1319+ }
1320+ }
1321+ break;
1322+ case LED_CTL_STOP_WPS: /* WPS connect success */
1323+ if (pLed->bLedWPSBlinkInProgress) {
1324+ _cancel_timer_ex(&pLed->BlinkTimer);
1325+ pLed->bLedWPSBlinkInProgress = false;
1326+ }
1327+
1328+ pLed->bLedNoLinkBlinkInProgress = true;
1329+ pLed->CurrLedState = LED_BLINK_SLOWLY;
1330+ if (pLed->bLedOn)
1331+ pLed->BlinkingLedState = RTW_LED_OFF;
1332+ else
1333+ pLed->BlinkingLedState = RTW_LED_ON;
1334+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
1335+
1336+ break;
1337+ case LED_CTL_STOP_WPS_FAIL: /* WPS authentication fail */
1338+ if (pLed->bLedWPSBlinkInProgress) {
1339+ _cancel_timer_ex(&pLed->BlinkTimer);
1340+ pLed->bLedWPSBlinkInProgress = false;
1341+ }
1342+ pLed->bLedNoLinkBlinkInProgress = true;
1343+ pLed->CurrLedState = LED_BLINK_SLOWLY;
1344+ if (pLed->bLedOn)
1345+ pLed->BlinkingLedState = RTW_LED_OFF;
1346+ else
1347+ pLed->BlinkingLedState = RTW_LED_ON;
1348+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
1349+
1350+ /* LED1 settings */
1351+ if (pLed1->bLedWPSBlinkInProgress)
1352+ _cancel_timer_ex(&pLed1->BlinkTimer);
1353+ else
1354+ pLed1->bLedWPSBlinkInProgress = true;
1355+ pLed1->CurrLedState = LED_BLINK_WPS_STOP;
1356+ if (pLed1->bLedOn)
1357+ pLed1->BlinkingLedState = RTW_LED_OFF;
1358+ else
1359+ pLed1->BlinkingLedState = RTW_LED_ON;
1360+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
1361+ break;
1362+ case LED_CTL_STOP_WPS_FAIL_OVERLAP: /* WPS session overlap */
1363+ if (pLed->bLedWPSBlinkInProgress) {
1364+ _cancel_timer_ex(&pLed->BlinkTimer);
1365+ pLed->bLedWPSBlinkInProgress = false;
1366+ }
1367+ pLed->bLedNoLinkBlinkInProgress = true;
1368+ pLed->CurrLedState = LED_BLINK_SLOWLY;
1369+ if (pLed->bLedOn)
1370+ pLed->BlinkingLedState = RTW_LED_OFF;
1371+ else
1372+ pLed->BlinkingLedState = RTW_LED_ON;
1373+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NO_LINK_INTERVAL_ALPHA);
1374+
1375+ /* LED1 settings */
1376+ if (pLed1->bLedWPSBlinkInProgress)
1377+ _cancel_timer_ex(&pLed1->BlinkTimer);
1378+ else
1379+ pLed1->bLedWPSBlinkInProgress = true;
1380+ pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
1381+ pLed1->BlinkTimes = 10;
1382+ if (pLed1->bLedOn)
1383+ pLed1->BlinkingLedState = RTW_LED_OFF;
1384+ else
1385+ pLed1->BlinkingLedState = RTW_LED_ON;
1386+ _set_timer(&pLed->BlinkTimer, LED_BLINK_NORMAL_INTERVAL);
1387+ break;
1388+ case LED_CTL_POWER_OFF:
1389+ pLed->CurrLedState = RTW_LED_OFF;
1390+ pLed->BlinkingLedState = RTW_LED_OFF;
1391+
1392+ if (pLed->bLedNoLinkBlinkInProgress) {
1393+ _cancel_timer_ex(&pLed->BlinkTimer);
1394+ pLed->bLedNoLinkBlinkInProgress = false;
1395+ }
1396+ if (pLed->bLedLinkBlinkInProgress) {
1397+ _cancel_timer_ex(&pLed->BlinkTimer);
1398+ pLed->bLedLinkBlinkInProgress = false;
1399+ }
1400+ if (pLed->bLedBlinkInProgress) {
1401+ _cancel_timer_ex(&pLed->BlinkTimer);
1402+ pLed->bLedBlinkInProgress = false;
1403+ }
1404+ if (pLed->bLedWPSBlinkInProgress) {
1405+ _cancel_timer_ex(&pLed->BlinkTimer);
1406+ pLed->bLedWPSBlinkInProgress = false;
1407+ }
1408+ if (pLed->bLedScanBlinkInProgress) {
1409+ _cancel_timer_ex(&pLed->BlinkTimer);
1410+ pLed->bLedScanBlinkInProgress = false;
1411+ }
1412+ if (pLed->bLedStartToLinkBlinkInProgress) {
1413+ _cancel_timer_ex(&pLed->BlinkTimer);
1414+ pLed->bLedStartToLinkBlinkInProgress = false;
1415+ }
1416+ if (pLed1->bLedWPSBlinkInProgress) {
1417+ _cancel_timer_ex(&pLed1->BlinkTimer);
1418+ pLed1->bLedWPSBlinkInProgress = false;
1419+ }
1420+ pLed1->BlinkingLedState = LED_UNKNOWN;
1421+ SwLedOff(padapter, pLed);
1422+ SwLedOff(padapter, pLed1);
1423+ break;
1424+ default:
1425+ break;
1426+ }
1427+}
1428+
1429+ /* Sercomm-Belkin, added by chiyoko, 20090415 */
1430+static void
1431+SwLedControlMode5(
1432+ struct adapter *padapter,
1433+ enum LED_CTL_MODE LedAction
1434+)
1435+{
1436+ struct led_priv *ledpriv = &padapter->ledpriv;
1437+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1438+ struct LED_871x *pLed = &ledpriv->SwLed0;
1439+
1440+ switch (LedAction) {
1441+ case LED_CTL_POWER_ON:
1442+ case LED_CTL_NO_LINK:
1443+ case LED_CTL_LINK: /* solid blue */
1444+ pLed->CurrLedState = RTW_LED_ON;
1445+ pLed->BlinkingLedState = RTW_LED_ON;
1446+
1447+ _set_timer(&pLed->BlinkTimer, 0);
1448+ break;
1449+ case LED_CTL_SITE_SURVEY:
1450+ if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) {
1451+ } else if (!pLed->bLedScanBlinkInProgress) {
1452+ if (pLed->bLedBlinkInProgress) {
1453+ _cancel_timer_ex(&pLed->BlinkTimer);
1454+ pLed->bLedBlinkInProgress = false;
1455+ }
1456+ pLed->bLedScanBlinkInProgress = true;
1457+ pLed->CurrLedState = LED_BLINK_SCAN;
1458+ pLed->BlinkTimes = 24;
1459+ if (pLed->bLedOn)
1460+ pLed->BlinkingLedState = RTW_LED_OFF;
1461+ else
1462+ pLed->BlinkingLedState = RTW_LED_ON;
1463+ _set_timer(&pLed->BlinkTimer, LED_BLINK_SCAN_INTERVAL_ALPHA);
1464+ }
1465+ break;
1466+ case LED_CTL_TX:
1467+ case LED_CTL_RX:
1468+ if (!pLed->bLedBlinkInProgress) {
1469+ if (pLed->CurrLedState == LED_BLINK_SCAN)
1470+ return;
1471+ pLed->bLedBlinkInProgress = true;
1472+ pLed->CurrLedState = LED_BLINK_TXRX;
1473+ pLed->BlinkTimes = 2;
1474+ if (pLed->bLedOn)
1475+ pLed->BlinkingLedState = RTW_LED_OFF;
1476+ else
1477+ pLed->BlinkingLedState = RTW_LED_ON;
1478+ _set_timer(&pLed->BlinkTimer, LED_BLINK_FASTER_INTERVAL_ALPHA);
1479+ }
1480+ break;
1481+ case LED_CTL_POWER_OFF:
1482+ pLed->CurrLedState = RTW_LED_OFF;
1483+ pLed->BlinkingLedState = RTW_LED_OFF;
1484+
1485+ if (pLed->bLedBlinkInProgress) {
1486+ _cancel_timer_ex(&pLed->BlinkTimer);
1487+ pLed->bLedBlinkInProgress = false;
1488+ }
1489+ SwLedOff(padapter, pLed);
1490+ break;
1491+ default:
1492+ break;
1493+ }
1494+}
1495+
1496+ /* WNC-Corega, added by chiyoko, 20090902 */
1497+static void
1498+SwLedControlMode6(
1499+ struct adapter *padapter,
1500+ enum LED_CTL_MODE LedAction
1501+)
1502+{
1503+ struct led_priv *ledpriv = &padapter->ledpriv;
1504+ struct LED_871x *pLed0 = &ledpriv->SwLed0;
1505+
1506+ switch (LedAction) {
1507+ case LED_CTL_POWER_ON:
1508+ case LED_CTL_LINK:
1509+ case LED_CTL_NO_LINK:
1510+ _cancel_timer_ex(&pLed0->BlinkTimer);
1511+ pLed0->CurrLedState = RTW_LED_ON;
1512+ pLed0->BlinkingLedState = RTW_LED_ON;
1513+ _set_timer(&pLed0->BlinkTimer, 0);
1514+ break;
1515+ case LED_CTL_POWER_OFF:
1516+ SwLedOff(padapter, pLed0);
1517+ break;
1518+ default:
1519+ break;
1520+ }
1521+}
1522+
1523+/* */
1524+/* Description: */
1525+/* Handler function of LED Blinking. */
1526+/* We dispatch acture LED blink action according to LedStrategy. */
1527+/* */
1528+void BlinkHandler(struct LED_871x *pLed)
1529+{
1530+ struct adapter *padapter = pLed->padapter;
1531+ struct led_priv *ledpriv = &padapter->ledpriv;
1532+
1533+ if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
1534+ return;
1535+
1536+ switch (ledpriv->LedStrategy) {
1537+ case SW_LED_MODE0:
1538+ SwLedBlink(pLed);
1539+ break;
1540+ case SW_LED_MODE1:
1541+ SwLedBlink1(pLed);
1542+ break;
1543+ case SW_LED_MODE2:
1544+ SwLedBlink2(pLed);
1545+ break;
1546+ case SW_LED_MODE3:
1547+ SwLedBlink3(pLed);
1548+ break;
1549+ case SW_LED_MODE4:
1550+ SwLedBlink4(pLed);
1551+ break;
1552+ case SW_LED_MODE5:
1553+ SwLedBlink5(pLed);
1554+ break;
1555+ case SW_LED_MODE6:
1556+ SwLedBlink6(pLed);
1557+ break;
1558+ default:
1559+ break;
1560+ }
1561+}
1562+
1563+void LedControl8188eu(struct adapter *padapter, enum LED_CTL_MODE LedAction)
1564+{
1565+ struct led_priv *ledpriv = &padapter->ledpriv;
1566+ struct registry_priv *registry_par;
1567+
1568+ if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped) ||
1569+ (!padapter->hw_init_completed))
1570+ return;
1571+
1572+ if (!ledpriv->bRegUseLed)
1573+ return;
1574+
1575+ registry_par = &padapter->registrypriv;
1576+ if (!registry_par->led_enable)
1577+ return;
1578+
1579+ if ((padapter->pwrctrlpriv.rf_pwrstate != rf_on &&
1580+ padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) &&
1581+ (LedAction == LED_CTL_TX || LedAction == LED_CTL_RX ||
1582+ LedAction == LED_CTL_SITE_SURVEY ||
1583+ LedAction == LED_CTL_LINK ||
1584+ LedAction == LED_CTL_NO_LINK ||
1585+ LedAction == LED_CTL_POWER_ON))
1586+ return;
1587+
1588+ switch (ledpriv->LedStrategy) {
1589+ case SW_LED_MODE0:
1590+ break;
1591+ case SW_LED_MODE1:
1592+ SwLedControlMode1(padapter, LedAction);
1593+ break;
1594+ case SW_LED_MODE2:
1595+ SwLedControlMode2(padapter, LedAction);
1596+ break;
1597+ case SW_LED_MODE3:
1598+ SwLedControlMode3(padapter, LedAction);
1599+ break;
1600+ case SW_LED_MODE4:
1601+ SwLedControlMode4(padapter, LedAction);
1602+ break;
1603+ case SW_LED_MODE5:
1604+ SwLedControlMode5(padapter, LedAction);
1605+ break;
1606+ case SW_LED_MODE6:
1607+ SwLedControlMode6(padapter, LedAction);
1608+ break;
1609+ default:
1610+ break;
1611+ }
1612+}
drivers/staging/r8188eu/core/rtw_mlme.crenamed from drivers/staging/rtl8188eu/core/rtw_mlme.c+713−401
@@ -1,50 +1,61 @@
11 // SPDX-License-Identifier: GPL-2.0
2−/******************************************************************************
3− *
4− * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5− *
6− ******************************************************************************/
7−#define _RTW_MLME_C_
2+/* Copyright(c) 2007 - 2011 Realtek Corporation. */
83
9−#include <linux/ieee80211.h>
4+#define _RTW_MLME_C_
105
11−#include <osdep_service.h>
12−#include <drv_types.h>
13−#include <recv_osdep.h>
14−#include <xmit_osdep.h>
15−#include <hal_intf.h>
16−#include <mlme_osdep.h>
17−#include <sta_info.h>
18−#include <wifi.h>
19−#include <wlan_bssdef.h>
20−#include <rtw_ioctl_set.h>
21−#include <linux/vmalloc.h>
22−#include <linux/etherdevice.h>
6+#include "../include/osdep_service.h"
7+#include "../include/drv_types.h"
8+#include "../include/recv_osdep.h"
9+#include "../include/xmit_osdep.h"
10+#include "../include/hal_intf.h"
11+#include "../include/mlme_osdep.h"
12+#include "../include/sta_info.h"
13+#include "../include/wifi.h"
14+#include "../include/wlan_bssdef.h"
15+#include "../include/rtw_ioctl_set.h"
16+#include "../include/usb_osintf.h"
17+
18+extern unsigned char MCS_rate_2R[16];
19+extern unsigned char MCS_rate_1R[16];
20+
21+void rtw_set_roaming(struct adapter *adapter, u8 to_roaming)
22+{
23+ if (to_roaming == 0)
24+ adapter->mlmepriv.to_join = false;
25+ adapter->mlmepriv.to_roaming = to_roaming;
26+}
2327
24−extern const u8 MCS_rate_1R[16];
28+u8 rtw_to_roaming(struct adapter *adapter)
29+{
30+ return adapter->mlmepriv.to_roaming;
31+}
2532
26−int rtw_init_mlme_priv(struct adapter *padapter)
33+int _rtw_init_mlme_priv(struct adapter *padapter)
2734 {
28− int i;
29− u8 *pbuf;
30− struct wlan_network *pnetwork;
31− struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
32− int res = _SUCCESS;
35+ int i;
36+ u8 *pbuf;
37+ struct wlan_network *pnetwork;
38+ struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
39+ int res = _SUCCESS;
3340
3441 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
3542
43+ pmlmepriv->nic_hdl = (u8 *)padapter;
44+
3645 pmlmepriv->pscanned = NULL;
3746 pmlmepriv->fw_state = 0;
3847 pmlmepriv->cur_network.network.InfrastructureMode = Ndis802_11AutoUnknown;
39− pmlmepriv->scan_mode = SCAN_ACTIVE;/* 1: active, 0: passive. Maybe someday we should rename this variable to "active_mode" (Jeff) */
48+ pmlmepriv->scan_mode = SCAN_ACTIVE;/* 1: active, 0: pasive. Maybe someday we should rename this varable to "active_mode" (Jeff) */
4049
4150 spin_lock_init(&pmlmepriv->lock);
4251 _rtw_init_queue(&pmlmepriv->free_bss_pool);
4352 _rtw_init_queue(&pmlmepriv->scanned_queue);
4453
54+ set_scanned_network_val(pmlmepriv, 0);
55+
4556 memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid));
4657
47− pbuf = vzalloc(array_size(MAX_BSS_CNT, sizeof(struct wlan_network)));
58+ pbuf = vzalloc(MAX_BSS_CNT * (sizeof(struct wlan_network)));
4859
4960 if (!pbuf) {
5061 res = _FAIL;
@@ -69,9 +80,14 @@ int rtw_init_mlme_priv(struct adapter *padapter) · 18 unmodified lines
6980 rtw_init_mlme_timer(padapter);
7081
7182 exit:
83+
7284 return res;
7385 }
7486
87+static void rtw_mfree_mlme_priv_lock(struct mlme_priv *pmlmepriv)
88+{
89+}
90+
7591 #if defined(CONFIG_88EU_AP_MODE)
7692 static void rtw_free_mlme_ie_data(u8 **ppie, u32 *plen)
7793 {
@@ -82,12 +98,18 @@ static void rtw_free_mlme_ie_data(u8 **ppie, u32 *plen) · 4 unmodified lines
8298
8399 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv)
84100 {
85− rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
86− rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
101+ kfree(pmlmepriv->assoc_req);
102+ kfree(pmlmepriv->assoc_rsp);
87103 rtw_free_mlme_ie_data(&pmlmepriv->wps_beacon_ie, &pmlmepriv->wps_beacon_ie_len);
88104 rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_req_ie, &pmlmepriv->wps_probe_req_ie_len);
89105 rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_resp_ie, &pmlmepriv->wps_probe_resp_ie_len);
90106 rtw_free_mlme_ie_data(&pmlmepriv->wps_assoc_resp_ie, &pmlmepriv->wps_assoc_resp_ie_len);
107+
108+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_beacon_ie, &pmlmepriv->p2p_beacon_ie_len);
109+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_req_ie, &pmlmepriv->p2p_probe_req_ie_len);
110+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_resp_ie, &pmlmepriv->p2p_probe_resp_ie_len);
111+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_go_probe_resp_ie, &pmlmepriv->p2p_go_probe_resp_ie_len);
112+ rtw_free_mlme_ie_data(&pmlmepriv->p2p_assoc_req_ie, &pmlmepriv->p2p_assoc_req_ie_len);
91113 }
92114 #else
93115 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv)
@@ -95,25 +117,70 @@ void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv) · 1 unmodified line
95117 }
96118 #endif
97119
98−void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
120+void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
99121 {
122+
123+ rtw_free_mlme_priv_ie_data(pmlmepriv);
124+
100125 if (pmlmepriv) {
101− rtw_free_mlme_priv_ie_data(pmlmepriv);
126+ rtw_mfree_mlme_priv_lock(pmlmepriv);
127+
102128 vfree(pmlmepriv->free_bss_buf);
103129 }
130+
131+}
132+
133+int _rtw_enqueue_network(struct __queue *queue, struct wlan_network *pnetwork)
134+{
135+
136+ if (!pnetwork)
137+ goto exit;
138+
139+ spin_lock_bh(&queue->lock);
140+
141+ list_add_tail(&pnetwork->list, &queue->queue);
142+
143+ spin_unlock_bh(&queue->lock);
144+
145+exit:
146+
147+ return _SUCCESS;
104148 }
105149
106−struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv)
107− /* _queue *free_queue) */
150+struct wlan_network *_rtw_dequeue_network(struct __queue *queue)
108151 {
109152 struct wlan_network *pnetwork;
153+
154+ spin_lock_bh(&queue->lock);
155+
156+ if (list_empty(&queue->queue)) {
157+ pnetwork = NULL;
158+ } else {
159+ pnetwork = container_of((&queue->queue)->next, struct wlan_network, list);
160+
161+ list_del_init(&pnetwork->list);
162+ }
163+
164+ spin_unlock_bh(&queue->lock);
165+
166+ return pnetwork;
167+}
168+
169+struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv)/* _queue *free_queue) */
170+{
171+ struct wlan_network *pnetwork;
110172 struct __queue *free_queue = &pmlmepriv->free_bss_pool;
173+ struct list_head *plist = NULL;
111174
112175 spin_lock_bh(&free_queue->lock);
113− pnetwork = list_first_entry_or_null(&free_queue->queue,
114− struct wlan_network, list);
115− if (!pnetwork)
176+
177+ if (list_empty(&free_queue->queue)) {
178+ pnetwork = NULL;
116179 goto exit;
180+ }
181+ plist = (&free_queue->queue)->next;
182+
183+ pnetwork = container_of(plist, struct wlan_network, list);
117184
118185 list_del_init(&pnetwork->list);
119186
@@ -123,16 +190,17 @@ struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv) · 3 unmodified lines
123190 pnetwork->aid = 0;
124191 pnetwork->join_res = 0;
125192
193+ pmlmepriv->num_of_scanned++;
194+
126195 exit:
127196 spin_unlock_bh(&free_queue->lock);
128197
129198 return pnetwork;
130199 }
131200
132−static void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall)
201+void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall)
133202 {
134− unsigned long curr_time;
135− u32 delta_time;
203+ u32 curr_time, delta_time;
136204 u32 lifetime = SCANQUEUE_LIFETIME;
137205 struct __queue *free_queue = &pmlmepriv->free_bss_pool;
138206
@@ -153,11 +221,11 @@ static void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network * · 14 unmodified lines
153221 spin_lock_bh(&free_queue->lock);
154222 list_del_init(&pnetwork->list);
155223 list_add_tail(&pnetwork->list, &free_queue->queue);
224+ pmlmepriv->num_of_scanned--;
156225 spin_unlock_bh(&free_queue->lock);
157226 }
158227
159−static void rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
160− struct wlan_network *pnetwork)
228+void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork)
161229 {
162230 struct __queue *free_queue = &pmlmepriv->free_bss_pool;
163231
@@ -167,48 +235,61 @@ static void rtw_free_network_nolock(struct mlme_priv *pmlmepriv, · 3 unmodified lines
167235 return;
168236 list_del_init(&pnetwork->list);
169237 list_add_tail(&pnetwork->list, get_list_head(free_queue));
238+ pmlmepriv->num_of_scanned--;
170239 }
171240
172241 /*
173− * return the wlan_network with the matching addr
174− *
175− * Shall be called under atomic context... to avoid possible racing condition...
176− */
177−struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr)
242+ return the wlan_network with the matching addr
243+
244+ Shall be calle under atomic context... to avoid possible racing condition...
245+*/
246+struct wlan_network *_rtw_find_network(struct __queue *scanned_queue, u8 *addr)
178247 {
179248 struct list_head *phead, *plist;
180− struct wlan_network *pnetwork = NULL;
249+ struct wlan_network *pnetwork = NULL;
250+ u8 zero_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
181251
182− if (is_zero_ether_addr(addr)) {
252+ if (!memcmp(zero_addr, addr, ETH_ALEN)) {
183253 pnetwork = NULL;
184254 goto exit;
185255 }
186256 phead = get_list_head(scanned_queue);
187− list_for_each(plist, phead) {
188− pnetwork = list_entry(plist, struct wlan_network, list);
257+ plist = phead->next;
258+
259+ while (plist != phead) {
260+ pnetwork = container_of(plist, struct wlan_network, list);
189261 if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
190262 break;
263+ plist = plist->next;
191264 }
192265 if (plist == phead)
193266 pnetwork = NULL;
194267 exit:
268+
195269 return pnetwork;
196270 }
197271
198−void rtw_free_network_queue(struct adapter *padapter, u8 isfreeall)
272+void _rtw_free_network_queue(struct adapter *padapter, u8 isfreeall)
199273 {
200− struct list_head *phead;
201− struct wlan_network *pnetwork, *temp;
274+ struct list_head *phead, *plist;
275+ struct wlan_network *pnetwork;
202276 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
203277 struct __queue *scanned_queue = &pmlmepriv->scanned_queue;
204278
205279 spin_lock_bh(&scanned_queue->lock);
206280
207281 phead = get_list_head(scanned_queue);
208− list_for_each_entry_safe(pnetwork, temp, phead, list)
209− _rtw_free_network(pmlmepriv, pnetwork, isfreeall);
282+ plist = phead->next;
283+
284+ while (phead != plist) {
285+ pnetwork = container_of(plist, struct wlan_network, list);
286+
287+ plist = plist->next;
210288
289+ _rtw_free_network(pmlmepriv, pnetwork, isfreeall);
290+ }
211291 spin_unlock_bh(&scanned_queue->lock);
292+
212293 }
213294
214295 int rtw_if_up(struct adapter *padapter)
@@ -220,12 +301,13 @@ int rtw_if_up(struct adapter *padapter) · 5 unmodified lines
220301 res = false;
221302 else
222303 res = true;
304+
223305 return res;
224306 }
225307
226308 void rtw_generate_random_ibss(u8 *pibss)
227309 {
228− unsigned long curtime = jiffies;
310+ u32 curtime = jiffies;
229311
230312 pibss[0] = 0x02; /* in ad-hoc mode bit1 must set to 1 */
231313 pibss[1] = 0x11;
@@ -242,18 +324,73 @@ u8 *rtw_get_capability_from_ie(u8 *ie) · 10 unmodified lines
242324
243325 u16 rtw_get_capability(struct wlan_bssid_ex *bss)
244326 {
245− __le16 val;
327+ __le16 val;
246328
247− memcpy((u8 *)&val, rtw_get_capability_from_ie(bss->ies), 2);
329+ memcpy((u8 *)&val, rtw_get_capability_from_ie(bss->IEs), 2);
248330
249331 return le16_to_cpu(val);
250332 }
251333
334+u8 *rtw_get_timestampe_from_ie(u8 *ie)
335+{
336+ return ie + 0;
337+}
338+
252339 u8 *rtw_get_beacon_interval_from_ie(u8 *ie)
253340 {
254341 return ie + 8;
255342 }
256343
344+int rtw_init_mlme_priv(struct adapter *padapter)/* struct mlme_priv *pmlmepriv) */
345+{
346+ int res;
347+
348+ res = _rtw_init_mlme_priv(padapter);/* (pmlmepriv); */
349+
350+ return res;
351+}
352+
353+void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
354+{
355+ _rtw_free_mlme_priv(pmlmepriv);
356+}
357+
358+static struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv)
359+{
360+ struct wlan_network *pnetwork;
361+
362+ pnetwork = _rtw_alloc_network(pmlmepriv);
363+
364+ return pnetwork;
365+}
366+
367+static void rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
368+ struct wlan_network *pnetwork)
369+{
370+
371+ _rtw_free_network_nolock(pmlmepriv, pnetwork);
372+
373+}
374+
375+void rtw_free_network_queue(struct adapter *dev, u8 isfreeall)
376+{
377+
378+ _rtw_free_network_queue(dev, isfreeall);
379+
380+}
381+
382+/*
383+ return the wlan_network with the matching addr
384+
385+ Shall be calle under atomic context... to avoid possible racing condition...
386+*/
387+struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr)
388+{
389+ struct wlan_network *pnetwork = _rtw_find_network(scanned_queue, addr);
390+
391+ return pnetwork;
392+}
393+
257394 int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork)
258395 {
259396 int ret = true;
@@ -272,8 +409,8 @@ int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork) · 12 unmodified lines
272409
273410 static int is_same_ess(struct wlan_bssid_ex *a, struct wlan_bssid_ex *b)
274411 {
275− return (a->ssid.ssid_length == b->ssid.ssid_length) &&
276− !memcmp(a->ssid.ssid, b->ssid.ssid, a->ssid.ssid_length);
412+ return (a->Ssid.SsidLength == b->Ssid.SsidLength) &&
413+ !memcmp(a->Ssid.Ssid, b->Ssid.Ssid, a->Ssid.SsidLength);
277414 }
278415
279416 int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst)
@@ -281,42 +418,50 @@ int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst) · 1 unmodified line
281418 u16 s_cap, d_cap;
282419 __le16 le_scap, le_dcap;
283420
284− memcpy((u8 *)&le_scap, rtw_get_capability_from_ie(src->ies), 2);
285− memcpy((u8 *)&le_dcap, rtw_get_capability_from_ie(dst->ies), 2);
421+ memcpy((u8 *)&le_scap, rtw_get_capability_from_ie(src->IEs), 2);
422+ memcpy((u8 *)&le_dcap, rtw_get_capability_from_ie(dst->IEs), 2);
286423
287424 s_cap = le16_to_cpu(le_scap);
288425 d_cap = le16_to_cpu(le_dcap);
289426
290− return ((src->ssid.ssid_length == dst->ssid.ssid_length) &&
291− (!memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN)) &&
292− (!memcmp(src->ssid.ssid, dst->ssid.ssid, src->ssid.ssid_length)) &&
427+ return ((src->Ssid.SsidLength == dst->Ssid.SsidLength) &&
428+ ((!memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN))) &&
429+ ((!memcmp(src->Ssid.Ssid, dst->Ssid.Ssid, src->Ssid.SsidLength))) &&
293430 ((s_cap & WLAN_CAPABILITY_IBSS) ==
294431 (d_cap & WLAN_CAPABILITY_IBSS)) &&
295− ((s_cap & WLAN_CAPABILITY_ESS) ==
296− (d_cap & WLAN_CAPABILITY_ESS)));
432+ ((s_cap & WLAN_CAPABILITY_BSS) ==
433+ (d_cap & WLAN_CAPABILITY_BSS)));
297434 }
298435
299−struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue)
436+struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue)
300437 {
301438 struct list_head *plist, *phead;
302− struct wlan_network *pwlan = NULL;
303− struct wlan_network *oldest = NULL;
439+ struct wlan_network *pwlan = NULL;
440+ struct wlan_network *oldest = NULL;
304441
305442 phead = get_list_head(scanned_queue);
306443
307− for (plist = phead->next; plist != phead; plist = plist->next) {
444+ plist = phead->next;
445+
446+ while (1) {
447+ if (phead == plist)
448+ break;
449+
308450 pwlan = container_of(plist, struct wlan_network, list);
309451
310452 if (!pwlan->fixed) {
311453 if (!oldest || time_after(oldest->last_scanned, pwlan->last_scanned))
312454 oldest = pwlan;
313455 }
456+
457+ plist = plist->next;
314458 }
459+
315460 return oldest;
316461 }
317462
318463 void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
319− struct adapter *padapter, bool update_ie)
464+ struct adapter *padapter, bool update_ie)
320465 {
321466 long rssi_ori = dst->Rssi;
322467 u8 sq_smp = src->PhyInfo.SignalQuality;
@@ -327,82 +472,86 @@ void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src, · 4 unmodified lines
327472 rtw_hal_antdiv_rssi_compared(padapter, dst, src); /* this will update src.Rssi, need consider again */
328473
329474 /* The rule below is 1/5 for sample value, 4/5 for history value */
330− if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) &&
331− is_same_network(&padapter->mlmepriv.cur_network.network, src)) {
475+ if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) && is_same_network(&padapter->mlmepriv.cur_network.network, src)) {
332476 /* Take the recvpriv's value for the connected AP*/
333477 ss_final = padapter->recvpriv.signal_strength;
334478 sq_final = padapter->recvpriv.signal_qual;
335479 /* the rssi value here is undecorated, and will be used for antenna diversity */
336480 if (sq_smp != 101) /* from the right channel */
337− rssi_final = (src->Rssi + dst->Rssi * 4) / 5;
481+ rssi_final = dst->Rssi; //(src->Rssi+dst->Rssi*4)/5;
338482 else
339483 rssi_final = rssi_ori;
340484 } else {
341− if (sq_smp != 101) { /* from the right channel */
342− ss_final = ((u32)(src->PhyInfo.SignalStrength) + (u32)(dst->PhyInfo.SignalStrength) * 4) / 5;
343− sq_final = ((u32)(src->PhyInfo.SignalQuality) + (u32)(dst->PhyInfo.SignalQuality) * 4) / 5;
344− rssi_final = (src->Rssi + dst->Rssi * 4) / 5;
345− } else {
346− /* bss info not receiving from the right channel, use the original RX signal infos */
347− ss_final = dst->PhyInfo.SignalStrength;
348− sq_final = dst->PhyInfo.SignalQuality;
349− rssi_final = dst->Rssi;
350− }
485+// if (sq_smp != 101) { /* from the right channel */
486+ ss_final = (u32)dst->PhyInfo.SignalStrength; //((u32)(src->PhyInfo.SignalStrength)+(u32)(dst->PhyInfo.SignalStrength)*4)/5;
487+ sq_final = (u32)dst->PhyInfo.SignalQuality; //((u32)(src->PhyInfo.SignalQuality)+(u32)(dst->PhyInfo.SignalQuality)*4)/5;
488+ rssi_final = dst->Rssi; //(src->Rssi+dst->Rssi*4)/5;
489+// } else {
490+// /* bss info not receiving from the right channel, use the original RX signal infos */
491+// ss_final = dst->PhyInfo.SignalStrength;
492+// sq_final = dst->PhyInfo.SignalQuality;
493+// rssi_final = dst->Rssi;
494+// }
351495 }
352− if (update_ie)
496+ if (update_ie) {
497+ dst->Reserved[0] = src->Reserved[0];
498+ dst->Reserved[1] = src->Reserved[1];
353499 memcpy((u8 *)dst, (u8 *)src, get_wlan_bssid_ex_sz(src));
500+ }
354501 dst->PhyInfo.SignalStrength = ss_final;
355502 dst->PhyInfo.SignalQuality = sq_final;
356503 dst->Rssi = rssi_final;
504+
357505 }
358506
359507 static void update_current_network(struct adapter *adapter, struct wlan_bssid_ex *pnetwork)
360508 {
361− struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
509+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
362510
363511 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
364512 is_same_network(&pmlmepriv->cur_network.network, pnetwork)) {
365513 update_network(&pmlmepriv->cur_network.network, pnetwork, adapter, true);
366− rtw_update_protection(adapter, (pmlmepriv->cur_network.network.ies) + sizeof(struct ndis_802_11_fixed_ie),
367− pmlmepriv->cur_network.network.ie_length);
514+ rtw_update_protection(adapter, (pmlmepriv->cur_network.network.IEs) + sizeof(struct ndis_802_11_fixed_ie),
515+ pmlmepriv->cur_network.network.IELength);
368516 }
517+
369518 }
370519
371520 /*
372− * Caller must hold pmlmepriv->lock first.
373− */
521+Caller must hold pmlmepriv->lock first.
522+*/
374523 void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *target)
375524 {
376525 struct list_head *plist, *phead;
377− u32 bssid_ex_sz;
378− struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
379− struct __queue *queue = &pmlmepriv->scanned_queue;
380− struct wlan_network *pnetwork = NULL;
381− struct wlan_network *oldest = NULL;
526+ u32 bssid_ex_sz;
527+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
528+ struct __queue *queue = &pmlmepriv->scanned_queue;
529+ struct wlan_network *pnetwork = NULL;
530+ struct wlan_network *oldest = NULL;
382531
383532 spin_lock_bh(&queue->lock);
384533 phead = get_list_head(queue);
385− list_for_each(plist, phead) {
386− pnetwork = list_entry(plist, struct wlan_network, list);
534+ plist = phead->next;
535+
536+ while (phead != plist) {
537+ pnetwork = container_of(plist, struct wlan_network, list);
387538
388539 if (is_same_network(&pnetwork->network, target))
389540 break;
390541 if ((oldest == ((struct wlan_network *)0)) ||
391542 time_after(oldest->last_scanned, pnetwork->last_scanned))
392543 oldest = pnetwork;
544+ plist = plist->next;
393545 }
394546 /* If we didn't find a match, then get a new network slot to initialize
395− * with this beacon's information
396− */
547+ * with this beacon's information */
397548 if (phead == plist) {
398549 if (list_empty(&pmlmepriv->free_bss_pool.queue)) {
399550 /* If there are no more slots, expire the oldest */
400551 pnetwork = oldest;
401552
402− rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA,
403− &target->PhyInfo.Optimum_antenna);
404− memcpy(&pnetwork->network, target,
405− get_wlan_bssid_ex_sz(target));
553+ rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &target->PhyInfo.Optimum_antenna);
554+ memcpy(&pnetwork->network, target, get_wlan_bssid_ex_sz(target));
406555 /* variable initialize */
407556 pnetwork->fixed = false;
408557 pnetwork->last_scanned = jiffies;
@@ -424,8 +573,7 @@ void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *t · 15 unmodified lines
424573
425574 bssid_ex_sz = get_wlan_bssid_ex_sz(target);
426575 target->Length = bssid_ex_sz;
427− rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA,
428− &target->PhyInfo.Optimum_antenna);
576+ rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &target->PhyInfo.Optimum_antenna);
429577 memcpy(&pnetwork->network, target, bssid_ex_sz);
430578
431579 pnetwork->last_scanned = jiffies;
@@ -436,40 +584,47 @@ void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *t · 4 unmodified lines
436584 list_add_tail(&pnetwork->list, &queue->queue);
437585 }
438586 } else {
439− /* we have an entry and we are going to update it. But this
440− * entry may be already expired. In this case we do the same
441− * as we found a new net and call the new_net handler
587+ /* we have an entry and we are going to update it. But this entry may
588+ * be already expired. In this case we do the same as we found a new
589+ * net and call the new_net handler
442590 */
443591 bool update_ie = true;
444592
445593 pnetwork->last_scanned = jiffies;
446594
447595 /* target.Reserved[0]== 1, means that scanned network is a bcn frame. */
448− if ((pnetwork->network.ie_length > target->ie_length) && (target->Reserved[0] == 1))
596+ /* probe resp(3) > beacon(1) > probe req(2) */
597+ if ((target->Reserved[0] != 2) &&
598+ (target->Reserved[0] >= pnetwork->network.Reserved[0]))
599+ update_ie = true;
600+ else
449601 update_ie = false;
450−
451602 update_network(&pnetwork->network, target, adapter, update_ie);
452603 }
453604
454605 exit:
455606 spin_unlock_bh(&queue->lock);
607+
456608 }
457609
458610 static void rtw_add_network(struct adapter *adapter,
459611 struct wlan_bssid_ex *pnetwork)
460612 {
613+
614+#if defined(CONFIG_88EU_P2P)
615+ rtw_wlan_bssid_ex_remove_p2p_attr(pnetwork, P2P_ATTR_GROUP_INFO);
616+#endif
461617 update_current_network(adapter, pnetwork);
462618 rtw_update_scanned_network(adapter, pnetwork);
619+
463620 }
464621
465−/*
466− * select the desired network based on the capability of the (i)bss.
467− * check items: (1) security
468− * (2) network_type
469− * (3) WMM
470− * (4) HT
471− * (5) others
472− */
622+/* select the desired network based on the capability of the (i)bss. */
623+/* check items: (1) security */
624+/* (2) network_type */
625+/* (3) WMM */
626+/* (4) HT */
627+/* (5) others */
473628 static int rtw_is_desired_network(struct adapter *adapter, struct wlan_network *pnetwork)
474629 {
475630 struct security_priv *psecuritypriv = &adapter->securitypriv;
@@ -486,18 +641,33 @@ static int rtw_is_desired_network(struct adapter *adapter, struct wlan_network * · 10 unmodified lines
486641 privacy = pnetwork->network.Privacy;
487642
488643 if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) {
489− if (rtw_get_wps_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, pnetwork->network.ie_length - _FIXED_IE_LENGTH_, NULL, &wps_ielen))
644+ if (rtw_get_wps_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, pnetwork->network.IELength - _FIXED_IE_LENGTH_, NULL, &wps_ielen))
490645 return true;
491646 else
492647 return false;
493648 }
494649 if (adapter->registrypriv.wifi_spec == 1) { /* for correct flow of 8021X to do.... */
650+ u8 *p = NULL;
651+ uint ie_len = 0;
652+
495653 if ((desired_encmode == Ndis802_11EncryptionDisabled) && (privacy != 0))
496654 bselected = false;
655+ if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK) {
656+ p = rtw_get_ie(pnetwork->network.IEs + _BEACON_IE_OFFSET_,
657+ _RSN_IE_2_, &ie_len,
658+ (pnetwork->network.IELength -
659+ _BEACON_IE_OFFSET_));
660+ if (p && ie_len > 0)
661+ bselected = true;
662+ else
663+ bselected = false;
664+ }
497665 }
498666
499− if ((desired_encmode != Ndis802_11EncryptionDisabled) && (privacy == 0))
667+ if ((desired_encmode != Ndis802_11EncryptionDisabled) && (privacy == 0)) {
668+ DBG_88E("desired_encmode: %d, privacy: %d\n", desired_encmode, privacy);
500669 bselected = false;
670+ }
501671
502672 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
503673 if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
@@ -511,7 +681,7 @@ void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf) · 7 unmodified lines
511681 {
512682 u32 len;
513683 struct wlan_bssid_ex *pnetwork;
514− struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
684+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
515685
516686 pnetwork = (struct wlan_bssid_ex *)pbuf;
517687
@@ -525,11 +695,11 @@ void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf) · 7 unmodified lines
525695 if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, pnetwork->MacAddress, ETH_ALEN)) {
526696 struct wlan_network *ibss_wlan = NULL;
527697
528− memcpy(pmlmepriv->cur_network.network.ies, pnetwork->ies, 8);
698+ memcpy(pmlmepriv->cur_network.network.IEs, pnetwork->IEs, 8);
529699 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
530700 ibss_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->MacAddress);
531701 if (ibss_wlan) {
532− memcpy(ibss_wlan->network.ies, pnetwork->ies, 8);
702+ memcpy(ibss_wlan->network.IEs, pnetwork->IEs, 8);
533703 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
534704 goto exit;
535705 }
@@ -539,18 +709,20 @@ void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf) · 3 unmodified lines
539709
540710 /* lock pmlmepriv->lock when you accessing network_q */
541711 if (!check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
542− if (pnetwork->ssid.ssid[0] == 0)
543− pnetwork->ssid.ssid_length = 0;
712+ if (pnetwork->Ssid.Ssid[0] == 0)
713+ pnetwork->Ssid.SsidLength = 0;
544714 rtw_add_network(adapter, pnetwork);
545715 }
546716
547717 exit:
718+
548719 spin_unlock_bh(&pmlmepriv->lock);
549720 }
550721
551722 void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf)
552723 {
553− struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
724+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
725+ u8 timer_cancelled = 0;
554726
555727 spin_lock_bh(&pmlmepriv->lock);
556728
@@ -561,10 +733,17 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf) · 4 unmodified lines
561733 }
562734
563735 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
564− del_timer_sync(&pmlmepriv->scan_to_timer);
736+ timer_cancelled = 1;
737+
565738 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
566739 }
567740
741+ spin_unlock_bh(&pmlmepriv->lock);
742+
743+ if (timer_cancelled)
744+ _cancel_timer(&pmlmepriv->scan_to_timer, &timer_cancelled);
745+
746+ spin_lock_bh(&pmlmepriv->lock);
568747 rtw_set_signal_stat_timer(&adapter->recvpriv);
569748
570749 if (pmlmepriv->to_join) {
@@ -573,15 +752,15 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf) · 2 unmodified lines
573752 set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
574753
575754 if (rtw_select_and_join_from_scanned_queue(pmlmepriv) == _SUCCESS) {
576− mod_timer(&pmlmepriv->assoc_timer,
577− jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
755+ _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
578756 } else {
579− struct wlan_bssid_ex *pdev_network = &adapter->registrypriv.dev_network;
757+ struct wlan_bssid_ex *pdev_network = &adapter->registrypriv.dev_network;
580758 u8 *pibss = adapter->registrypriv.dev_network.MacAddress;
581759
582760 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
583761
584− memcpy(&pdev_network->ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid));
762+ memset(&pdev_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
763+ memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid));
585764
586765 rtw_update_registrypriv_dev_network(adapter);
587766 rtw_generate_random_ibss(pibss);
@@ -594,26 +773,28 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf) · 6 unmodified lines
594773 }
595774 } else {
596775 int s_ret;
597−
598776 set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
599777 pmlmepriv->to_join = false;
600778 s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
601− if (s_ret == _SUCCESS) {
602− mod_timer(&pmlmepriv->assoc_timer,
603− jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
779+ if (_SUCCESS == s_ret) {
780+ _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
604781 } else if (s_ret == 2) { /* there is no need to wait for join */
605782 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
606783 rtw_indicate_connect(adapter);
607784 } else {
608− if (pmlmepriv->to_roaming != 0) {
785+ DBG_88E("try_to_join, but select scanning queue fail, to_roaming:%d\n",
786+ pmlmepriv->to_roaming);
787+ if (rtw_to_roaming(adapter) != 0) {
609788 if (--pmlmepriv->to_roaming == 0 ||
610− rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, 1, NULL, 0) != _SUCCESS) {
611− pmlmepriv->to_roaming = 0;
612− rtw_free_assoc_resources(adapter);
789+ _SUCCESS != rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)) {
790+ rtw_set_roaming(adapter, 0);
791+ rtw_free_assoc_resources(adapter, 1);
613792 rtw_indicate_disconnect(adapter);
614793 } else {
615794 pmlmepriv->to_join = true;
616795 }
796+ } else {
797+ rtw_indicate_disconnect(adapter);
617798 }
618799 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
619800 }
@@ -624,6 +805,9 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf) · 4 unmodified lines
624805
625806 spin_unlock_bh(&pmlmepriv->lock);
626807
808+ if (check_fwstate(pmlmepriv, _FW_LINKED))
809+ p2p_ps_wk_cmd(adapter, P2P_PS_SCAN_DONE, 0);
810+
627811 rtw_os_xmit_schedule(adapter);
628812 }
629813
@@ -652,6 +836,7 @@ static void free_scanqueue(struct mlme_priv *pmlmepriv) · 22 unmodified lines
652836 list_del_init(plist);
653837 list_add_tail(plist, &free_queue->queue);
654838 plist = ptemp;
839+ pmlmepriv->num_of_scanned--;
655840 }
656841
657842 spin_unlock_bh(&free_queue->lock);
@@ -659,25 +844,13 @@ static void free_scanqueue(struct mlme_priv *pmlmepriv) · 1 unmodified line
659844 }
660845
661846 /*
662− * rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock
663− */
664−void rtw_free_assoc_resources(struct adapter *adapter)
665−{
666− struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
667−
668− spin_lock_bh(&pmlmepriv->scanned_queue.lock);
669− rtw_free_assoc_resources_locked(adapter);
670− spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
671−}
672−
673−/*
674− * rtw_free_assoc_resources_locked: the caller has to lock pmlmepriv->lock
675− */
676−void rtw_free_assoc_resources_locked(struct adapter *adapter)
847+*rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock
848+*/
849+void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue)
677850 {
678851 struct wlan_network *pwlan = NULL;
679− struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
680− struct sta_priv *pstapriv = &adapter->stapriv;
852+ struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
853+ struct sta_priv *pstapriv = &adapter->stapriv;
681854 struct wlan_network *tgt_network = &pmlmepriv->cur_network;
682855
683856 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_AP_STATE)) {
@@ -703,6 +876,9 @@ void rtw_free_assoc_resources_locked(struct adapter *adapter) · 19 unmodified lines
703876 rtw_init_bcmc_stainfo(adapter);
704877 }
705878
879+ if (lock_scanned_queue)
880+ spin_lock_bh(&pmlmepriv->scanned_queue.lock);
881+
706882 pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.MacAddress);
707883 if (pwlan)
708884 pwlan->fixed = false;
@@ -710,22 +886,25 @@ void rtw_free_assoc_resources_locked(struct adapter *adapter) · 1 unmodified line
710886 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) && (adapter->stapriv.asoc_sta_count == 1)))
711887 rtw_free_network_nolock(pmlmepriv, pwlan);
712888
889+ if (lock_scanned_queue)
890+ spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
713891 pmlmepriv->key_mask = 0;
892+
714893 }
715894
716895 /*
717− * rtw_indicate_connect: the caller has to lock pmlmepriv->lock
718− */
896+*rtw_indicate_connect: the caller has to lock pmlmepriv->lock
897+*/
719898 void rtw_indicate_connect(struct adapter *padapter)

1237 more lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_mlme_ext.c+8327−0

This diff is large: its 8328 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_mp.c+935−0

This diff is large: its 936 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_mp_ioctl.c+1170−0

This diff is large: its 1171 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_p2p.c+1997−0

This diff is large: its 1998 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_pwrctrl.crenamed from drivers/staging/rtl8188eu/core/rtw_pwrctrl.c+189−165

This diff is large: its 662 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_recv.crenamed from drivers/staging/rtl8188eu/core/rtw_recv.c+567−321

This diff is large: its 1825 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_rf.crenamed from drivers/staging/rtl8188eu/core/rtw_rf.c+24−10

This diff is large: its 52 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_security.c+1656−0

This diff is large: its 1657 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_sreset.c+62−0

This diff is large: its 63 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_sta_mgt.crenamed from drivers/staging/rtl8188eu/core/rtw_sta_mgt.c+150−121

This diff is large: its 466 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_wlan_util.crenamed from drivers/staging/rtl8188eu/core/rtw_wlan_util.c+605−335

This diff is large: its 1579 lines aren’t shown here.

drivers/staging/r8188eu/core/rtw_xmit.crenamed from drivers/staging/rtl8188eu/core/rtw_xmit.c+576−264

This diff is large: its 1677 lines aren’t shown here.

drivers/staging/r8188eu/hal/Hal8188EPwrSeq.c+69−0

This diff is large: its 70 lines aren’t shown here.

drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.crenamed from drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c+83−65

This diff is large: its 346 lines aren’t shown here.

drivers/staging/r8188eu/hal/HalHWImg8188E_BB.crenamed from drivers/staging/rtl8188eu/hal/bb_cfg.c+247−226

This diff is large: its 530 lines aren’t shown here.

drivers/staging/r8188eu/hal/HalHWImg8188E_MAC.c+213−0

This diff is large: its 214 lines aren’t shown here.

drivers/staging/r8188eu/hal/HalHWImg8188E_RF.c+250−0

This diff is large: its 251 lines aren’t shown here.

drivers/staging/r8188eu/hal/HalPhyRf_8188e.c+1264−0

This diff is large: its 1265 lines aren’t shown here.

drivers/staging/r8188eu/hal/HalPwrSeqCmd.c+95−0

This diff is large: its 96 lines aren’t shown here.

drivers/staging/r8188eu/hal/hal_com.crenamed from drivers/staging/rtl8188eu/hal/hal_com.c+131−58

This diff is large: its 272 lines aren’t shown here.

drivers/staging/r8188eu/hal/hal_intf.c+441−0

This diff is large: its 442 lines aren’t shown here.

drivers/staging/r8188eu/hal/odm.c+1968−0

This diff is large: its 1969 lines aren’t shown here.

drivers/staging/r8188eu/hal/odm_HWConfig.c+567−0

This diff is large: its 568 lines aren’t shown here.

drivers/staging/r8188eu/hal/odm_RTL8188E.c+337−0

This diff is large: its 338 lines aren’t shown here.

drivers/staging/r8188eu/hal/odm_RegConfig8188E.c+98−0

This diff is large: its 99 lines aren’t shown here.

drivers/staging/r8188eu/hal/odm_debug.c+6−0

This diff is large: its 7 lines aren’t shown here.

drivers/staging/r8188eu/hal/odm_interface.c+178−0

This diff is large: its 179 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_cmd.crenamed from drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c+284−138

This diff is large: its 774 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_dm.c+238−0

This diff is large: its 239 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_hal_init.c+2304−0

This diff is large: its 2305 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_mp.c+798−0

This diff is large: its 799 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_phycfg.c+1105−0

This diff is large: its 1106 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_rf6052.c+550−0

This diff is large: its 551 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_rxdesc.crenamed from drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c+18−25

This diff is large: its 112 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_sreset.c+64−0

This diff is large: its 65 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188e_xmit.crenamed from drivers/staging/rtl8188eu/hal/rtl8188e_xmit.c+5−8

This diff is large: its 20 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188eu_led.c+94−0

This diff is large: its 95 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188eu_recv.c+117−0

This diff is large: its 118 lines aren’t shown here.

drivers/staging/r8188eu/hal/rtl8188eu_xmit.crenamed from drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c+119−85

This diff is large: its 407 lines aren’t shown here.

drivers/staging/r8188eu/hal/usb_halinit.crenamed from drivers/staging/rtl8188eu/hal/usb_halinit.c+785−393

This diff is large: its 2274 lines aren’t shown here.

drivers/staging/r8188eu/hal/usb_ops_linux.c+562−0

This diff is large: its 563 lines aren’t shown here.

drivers/staging/r8188eu/include/Hal8188EPhyCfg.hrenamed from drivers/staging/rtl8188eu/include/hal8188e_phy_cfg.h+107−33

This diff is large: its 229 lines aren’t shown here.

drivers/staging/r8188eu/include/Hal8188EPhyReg.h+1072−0

This diff is large: its 1073 lines aren’t shown here.

drivers/staging/r8188eu/include/Hal8188EPwrSeq.h+155−0

This diff is large: its 156 lines aren’t shown here.

drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h+64−0

This diff is large: its 65 lines aren’t shown here.

drivers/staging/r8188eu/include/HalHWImg8188E_BB.h+27−0

This diff is large: its 28 lines aren’t shown here.

drivers/staging/r8188eu/include/HalHWImg8188E_FW.h+16−0

This diff is large: its 17 lines aren’t shown here.

drivers/staging/r8188eu/include/HalHWImg8188E_MAC.h+13−0

This diff is large: its 14 lines aren’t shown here.

drivers/staging/r8188eu/include/HalHWImg8188E_RF.h+13−0

This diff is large: its 14 lines aren’t shown here.

drivers/staging/r8188eu/include/HalPhyRf_8188e.h+41−0

This diff is large: its 42 lines aren’t shown here.

drivers/staging/r8188eu/include/HalPwrSeqCmd.h+110−0

This diff is large: its 111 lines aren’t shown here.

drivers/staging/r8188eu/include/HalVerDef.h+149−0

This diff is large: its 150 lines aren’t shown here.

drivers/staging/r8188eu/include/basic_types.hrenamed from drivers/staging/rtl8188eu/include/basic_types.h+45−56

This diff is large: its 139 lines aren’t shown here.

drivers/staging/r8188eu/include/drv_types.h+323−0

This diff is large: its 324 lines aren’t shown here.

drivers/staging/r8188eu/include/hal_com.hrenamed from drivers/staging/rtl8188eu/include/hal_com.h+17−11

This diff is large: its 49 lines aren’t shown here.

drivers/staging/r8188eu/include/hal_intf.h+411−0

This diff is large: its 412 lines aren’t shown here.

drivers/staging/r8188eu/include/ieee80211.hrenamed from drivers/staging/rtl8188eu/include/ieee80211.h+582−98

This diff is large: its 904 lines aren’t shown here.

drivers/staging/r8188eu/include/ieee80211_ext.h+271−0

This diff is large: its 272 lines aren’t shown here.

drivers/staging/r8188eu/include/ioctl_cfg80211.h+91−0

This diff is large: its 92 lines aren’t shown here.

drivers/staging/r8188eu/include/mlme_osdep.hrenamed from drivers/staging/rtl8188eu/include/mlme_osdep.h+6−8

This diff is large: its 25 lines aren’t shown here.

drivers/staging/r8188eu/include/mp_custom_oid.h+333−0

This diff is large: its 334 lines aren’t shown here.

drivers/staging/r8188eu/include/odm.hrenamed from drivers/staging/rtl8188eu/include/odm.h+161−66

This diff is large: its 474 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_HWConfig.hrenamed from drivers/staging/rtl8188eu/include/odm_hwconfig.h+26−11

This diff is large: its 54 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_RTL8188E.h+36−0

This diff is large: its 37 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_RegConfig8188E.h+27−0

This diff is large: its 28 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_RegDefine11AC.h+29−0

This diff is large: its 30 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_RegDefine11N.h+143−0

This diff is large: its 144 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_interface.h+147−0

This diff is large: its 148 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_precomp.hrenamed from drivers/staging/rtl8188eu/include/odm_precomp.h+29−16

This diff is large: its 87 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_reg.h+89−0

This diff is large: its 90 lines aren’t shown here.

drivers/staging/r8188eu/include/odm_types.h+45−0

This diff is large: its 46 lines aren’t shown here.

drivers/staging/r8188eu/include/osdep_intf.h+64−0

This diff is large: its 65 lines aren’t shown here.

drivers/staging/r8188eu/include/osdep_service.h+315−0

This diff is large: its 316 lines aren’t shown here.

drivers/staging/r8188eu/include/recv_osdep.h+37−0

This diff is large: its 38 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_cmd.hrenamed from drivers/staging/rtl8188eu/include/rtl8188e_cmd.h+42−6

This diff is large: its 77 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_dm.hrenamed from drivers/staging/rtl8188eu/include/rtl8188e_dm.h+14−7

This diff is large: its 41 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_hal.hrenamed from drivers/staging/rtl8188eu/include/rtl8188e_hal.h+171−52

This diff is large: its 420 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_led.h+18−0

This diff is large: its 19 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_recv.hrenamed from drivers/staging/rtl8188eu/include/rtl8188e_recv.h+11−11

This diff is large: its 33 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_rf.h+19−0

This diff is large: its 20 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_spec.hrenamed from drivers/staging/rtl8188eu/include/rtl8188e_spec.h+359−98

This diff is large: its 741 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_sreset.h+15−0

This diff is large: its 16 lines aren’t shown here.

drivers/staging/r8188eu/include/rtl8188e_xmit.hrenamed from drivers/staging/rtl8188eu/include/rtl8188e_xmit.h+22−29

This diff is large: its 91 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_ap.hrenamed from drivers/staging/rtl8188eu/include/rtw_ap.h+10−8

This diff is large: its 45 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_br_ext.h+49−0

This diff is large: its 50 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_cmd.h+975−0

This diff is large: its 976 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_debug.h+231−0

This diff is large: its 232 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_eeprom.hrenamed from drivers/staging/rtl8188eu/include/rtw_eeprom.h+16−16

This diff is large: its 74 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_efuse.h+134−0

This diff is large: its 135 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_event.h+97−0

This diff is large: its 98 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_ht.h+28−0

This diff is large: its 29 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_io.h+367−0

This diff is large: its 368 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_ioctl.hrenamed from drivers/staging/rtl8188eu/include/rtw_ioctl.h+21−14

This diff is large: its 61 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_ioctl_rtl.h+63−0

This diff is large: its 64 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_ioctl_set.h+33−0

This diff is large: its 34 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_iol.h+68−0

This diff is large: its 69 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_led.h+181−0

This diff is large: its 182 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_mlme.h+632−0

This diff is large: its 633 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_mlme_ext.hrenamed from drivers/staging/rtl8188eu/include/rtw_mlme_ext.h+266−89

This diff is large: its 556 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_mp.h+474−0

This diff is large: its 475 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_mp_ioctl.h+242−0

This diff is large: its 243 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_mp_phy_regdef.h+1063−0

This diff is large: its 1064 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_p2p.h+119−0

This diff is large: its 120 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_pwrctrl.hrenamed from drivers/staging/rtl8188eu/include/rtw_pwrctrl.h+48−27

This diff is large: its 150 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_recv.h+413−0

This diff is large: its 414 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_rf.hrenamed from drivers/staging/rtl8188eu/include/rtw_rf.h+23−14

This diff is large: its 84 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_security.hrenamed from drivers/staging/rtl8188eu/include/rtw_security.h+134−34

This diff is large: its 233 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_sreset.h+34−0

This diff is large: its 35 lines aren’t shown here.

drivers/staging/r8188eu/include/rtw_xmit.hrenamed from drivers/staging/rtl8188eu/include/rtw_xmit.h+43−28

This diff is large: its 193 lines aren’t shown here.

drivers/staging/r8188eu/include/sta_info.hrenamed from drivers/staging/rtl8188eu/include/sta_info.h+35−26

This diff is large: its 115 lines aren’t shown here.

drivers/staging/r8188eu/include/usb_ops.h+72−0

This diff is large: its 73 lines aren’t shown here.

drivers/staging/r8188eu/include/usb_ops_linux.h+39−0

This diff is large: its 40 lines aren’t shown here.

drivers/staging/r8188eu/include/usb_osintf.h+29−0

This diff is large: its 30 lines aren’t shown here.

drivers/staging/r8188eu/include/usb_vendor_req.h+35−0

This diff is large: its 36 lines aren’t shown here.

drivers/staging/r8188eu/include/wifi.h+1029−0

This diff is large: its 1030 lines aren’t shown here.

drivers/staging/r8188eu/include/wlan_bssdef.hrenamed from drivers/staging/rtl8188eu/include/wlan_bssdef.h+118−31

This diff is large: its 245 lines aren’t shown here.

drivers/staging/r8188eu/include/xmit_osdep.h+51−0

This diff is large: its 52 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/ioctl_linux.c+6649−0

This diff is large: its 6650 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/mlme_linux.c+216−0

This diff is large: its 217 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/os_intfs.c+1199−0

This diff is large: its 1200 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/osdep_service.c+343−0

This diff is large: its 344 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/recv_linux.crenamed from drivers/staging/rtl8188eu/os_dep/recv_linux.c+102−26

This diff is large: its 191 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/usb_intf.c+781−0

This diff is large: its 782 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/usb_ops_linux.c+253−0

This diff is large: its 254 lines aren’t shown here.

drivers/staging/r8188eu/os_dep/xmit_linux.crenamed from drivers/staging/rtl8188eu/os_dep/xmit_linux.c+96−34

This diff is large: its 224 lines aren’t shown here.

drivers/staging/rtl8188eu/Makefile+0−56

This diff is large: its 57 lines aren’t shown here.

drivers/staging/rtl8188eu/TODO+0−14

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_cmd.c+0−1219

This diff is large: its 1220 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_efuse.c+0−876

This diff is large: its 877 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_ieee80211.c+0−992

This diff is large: its 993 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_ioctl_set.c+0−512

This diff is large: its 513 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_iol.c+0−19

This diff is large: its 20 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_led.c+0−460

This diff is large: its 461 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_mlme_ext.c+0−5172

This diff is large: its 5173 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_security.c+0−869

This diff is large: its 870 lines aren’t shown here.

drivers/staging/rtl8188eu/core/rtw_sreset.c+0−21

This diff is large: its 22 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/fw.c+0−202

This diff is large: its 203 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/hal_intf.c+0−60

This diff is large: its 61 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/mac_cfg.c+0−120

This diff is large: its 121 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/odm.c+0−966

This diff is large: its 967 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/odm_hwconfig.c+0−397

This diff is large: its 398 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/odm_rtl8188e.c+0−335

This diff is large: its 336 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/phy.c+0−1276

This diff is large: its 1277 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/pwrseq.c+0−88

This diff is large: its 89 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/pwrseqcmd.c+0−80

This diff is large: its 81 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/rf.c+0−289

This diff is large: its 290 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/rf_cfg.c+0−247

This diff is large: its 248 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/rtl8188e_dm.c+0−217

This diff is large: its 218 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c+0−523

This diff is large: its 524 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/rtl8188eu_led.c+0−55

This diff is large: its 56 lines aren’t shown here.

drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c+0−83

This diff is large: its 84 lines aren’t shown here.

drivers/staging/rtl8188eu/include/HalVerDef.h+0−37

This diff is large: its 38 lines aren’t shown here.

drivers/staging/rtl8188eu/include/drv_types.h+0−176

This diff is large: its 177 lines aren’t shown here.

drivers/staging/rtl8188eu/include/fw.h+0−44

This diff is large: its 45 lines aren’t shown here.

drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h+0−201

This diff is large: its 202 lines aren’t shown here.

drivers/staging/rtl8188eu/include/hal8188e_rate_adaptive.h+0−74

This diff is large: its 75 lines aren’t shown here.

drivers/staging/rtl8188eu/include/hal_intf.h+0−223

This diff is large: its 224 lines aren’t shown here.

drivers/staging/rtl8188eu/include/mon.h+0−28

This diff is large: its 29 lines aren’t shown here.

drivers/staging/rtl8188eu/include/odm_rtl8188e.h+0−39

This diff is large: its 40 lines aren’t shown here.

drivers/staging/rtl8188eu/include/odm_types.h+0−24

This diff is large: its 25 lines aren’t shown here.

drivers/staging/rtl8188eu/include/osdep_intf.h+0−37

This diff is large: its 38 lines aren’t shown here.

drivers/staging/rtl8188eu/include/osdep_service.h+0−81

This diff is large: its 82 lines aren’t shown here.

drivers/staging/rtl8188eu/include/phy.h+0−26

This diff is large: its 27 lines aren’t shown here.

drivers/staging/rtl8188eu/include/phydm_reg.h+0−22

This diff is large: its 23 lines aren’t shown here.

drivers/staging/rtl8188eu/include/phydm_regdefine11n.h+0−53

This diff is large: its 54 lines aren’t shown here.

drivers/staging/rtl8188eu/include/pwrseq.h+0−242

This diff is large: its 243 lines aren’t shown here.

drivers/staging/rtl8188eu/include/pwrseqcmd.h+0−52

This diff is large: its 53 lines aren’t shown here.

drivers/staging/rtl8188eu/include/recv_osdep.h+0−26

This diff is large: its 27 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rf.h+0−12

This diff is large: its 13 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_android.h+0−51

This diff is large: its 52 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_cmd.h+0−361

This diff is large: its 362 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_efuse.h+0−67

This diff is large: its 68 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_event.h+0−81

This diff is large: its 82 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_ht.h+0−26

This diff is large: its 27 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_ioctl_set.h+0−28

This diff is large: its 29 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_iol.h+0−14

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_led.h+0−98

This diff is large: its 99 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_mlme.h+0−355

This diff is large: its 356 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_recv.h+0−262

This diff is large: its 263 lines aren’t shown here.

drivers/staging/rtl8188eu/include/rtw_sreset.h+0−30

This diff is large: its 31 lines aren’t shown here.

drivers/staging/rtl8188eu/include/usb_ops_linux.h+0−26

This diff is large: its 27 lines aren’t shown here.

drivers/staging/rtl8188eu/include/wifi.h+0−355

This diff is large: its 356 lines aren’t shown here.

drivers/staging/rtl8188eu/include/xmit_osdep.h+0−32

This diff is large: its 33 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/ioctl_linux.c+0−2777

This diff is large: its 2778 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/mlme_linux.c+0−167

This diff is large: its 168 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/mon.c+0−183

This diff is large: its 184 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/os_intfs.c+0−658

This diff is large: its 659 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/osdep_service.c+0−63

This diff is large: its 64 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/rtw_android.c+0−231

This diff is large: its 232 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/usb_intf.c+0−485

This diff is large: its 486 lines aren’t shown here.

drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c+0−644

This diff is large: its 645 lines aren’t shown here.

drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8192e/rtl8192e/rtl_core.c+0−5

This diff is large: its 26 lines aren’t shown here.

drivers/staging/rtl8192e/rtllib_crypt_ccmp.c+3−1

This diff is large: its 11 lines aren’t shown here.

drivers/staging/rtl8192e/rtllib_rx.c+17−40

This diff is large: its 82 lines aren’t shown here.

drivers/staging/rtl8192e/rtllib_softmac.c+2−1

This diff is large: its 10 lines aren’t shown here.

drivers/staging/rtl8192e/rtllib_softmac_wx.c+7−11

This diff is large: its 26 lines aren’t shown here.

drivers/staging/rtl8192u/ieee80211/ieee80211.h+2−2

This diff is large: its 18 lines aren’t shown here.

drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c+3−1

This diff is large: its 11 lines aren’t shown here.

drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c+14−35

This diff is large: its 77 lines aren’t shown here.

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c+2−1

This diff is large: its 10 lines aren’t shown here.

drivers/staging/rtl8192u/r8192U_core.c+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8192u/r819xU_phy.c+44−48

This diff is large: its 190 lines aren’t shown here.

drivers/staging/rtl8712/hal_init.c+0−1

This diff is large: its 7 lines aren’t shown here.

drivers/staging/rtl8712/os_intfs.c+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8712/osdep_service.h+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8712/wifi.h+0−48

This diff is large: its 74 lines aren’t shown here.

drivers/staging/rtl8723bs/Kconfig+1−2

This diff is large: its 10 lines aren’t shown here.

drivers/staging/rtl8723bs/Makefile+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_ap.c+65−70

This diff is large: its 436 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_cmd.c+27−27

This diff is large: its 147 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_debug.c+4−15

This diff is large: its 34 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_ieee80211.c+58−96

This diff is large: its 283 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_io.c+2−11

This diff is large: its 45 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_ioctl_set.c+16−87

This diff is large: its 199 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_mlme.c+116−147

This diff is large: its 670 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c+147−150

This diff is large: its 861 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_recv.c+3−3

This diff is large: its 27 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_rf.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_security.c+18−18

This diff is large: its 102 lines aren’t shown here.

drivers/staging/rtl8723bs/core/rtw_wlan_util.c+58−89

This diff is large: its 410 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c+0−464

This diff is large: its 478 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.h+0−1

This diff is large: its 5 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c+0−414

This diff is large: its 435 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.h+0−1

This diff is large: its 5 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h+0−8

This diff is large: its 35 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c+8−9

This diff is large: its 35 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c+1−85

This diff is large: its 100 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalPhyRf.c+26−41

This diff is large: its 149 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c+82−109

This diff is large: its 439 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/Mp_Precomp.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/hal_btcoex.c+2−109

This diff is large: its 177 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/hal_com.c+6−166

This diff is large: its 239 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/hal_com_phycfg.c+64−383

This diff is large: its 686 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/hal_sdio.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm.c+12−44

This diff is large: its 109 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm.h+0−25

This diff is large: its 63 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_CfoTracking.c+17−19

This diff is large: its 65 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_CfoTracking.h+1−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_DIG.c+1−4

This diff is large: its 19 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_HWConfig.c+175−168

This diff is large: its 446 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_HWConfig.h+4−25

This diff is large: its 55 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_NoiseMonitor.c+10−13

This diff is large: its 62 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_RTL8723B.c+0−36

This diff is large: its 37 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_RTL8723B.h+0−14

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.c+3−4

This diff is large: its 35 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h+3−8

This diff is large: its 25 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_RegDefine11N.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_precomp.h+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/odm_reg.h+0−4

This diff is large: its 20 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c+11−12

This diff is large: its 76 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723b_dm.c+0−12

This diff is large: its 31 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c+18−66

This diff is large: its 149 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c+21−31

This diff is large: its 116 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c+5−16

This diff is large: its 64 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c+1−2

This diff is large: its 17 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/hal/sdio_halinit.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8723bs/include/Hal8192CPhyReg.h+0−4

This diff is large: its 25 lines aren’t shown here.

drivers/staging/rtl8723bs/include/HalVerDef.h+0−18

This diff is large: its 42 lines aren’t shown here.

drivers/staging/rtl8723bs/include/drv_types.h+0−9

This diff is large: its 36 lines aren’t shown here.

drivers/staging/rtl8723bs/include/ethernet.h+0−14

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_btcoex.h+0−3

This diff is large: its 16 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_com.h+1−34

This diff is large: its 49 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_com_phycfg.h+4−16

This diff is large: its 49 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_com_reg.h+0−19

This diff is large: its 33 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_data.h+7−17

This diff is large: its 60 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_pg.h+3−5

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8723bs/include/hal_phy.h+1−2

This diff is large: its 10 lines aren’t shown here.

drivers/staging/rtl8723bs/include/ieee80211.h+5−37

This diff is large: its 65 lines aren’t shown here.

drivers/staging/rtl8723bs/include/osdep_intf.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8723bs/include/osdep_service.h+0−4

This diff is large: its 11 lines aren’t shown here.

drivers/staging/rtl8723bs/include/rtl8723b_xmit.h+0−8

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8723bs/include/rtw_ioctl_set.h+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rtl8723bs/include/rtw_mlme.h+3−3

This diff is large: its 13 lines aren’t shown here.

drivers/staging/rtl8723bs/include/rtw_recv.h+2−0

This diff is large: its 9 lines aren’t shown here.

drivers/staging/rtl8723bs/include/rtw_rf.h+0−10

This diff is large: its 17 lines aren’t shown here.

drivers/staging/rtl8723bs/include/wifi.h+0−8

This diff is large: its 15 lines aren’t shown here.

drivers/staging/rtl8723bs/include/wlan_bssdef.h+36−56

This diff is large: its 164 lines aren’t shown here.

drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c+105−68

This diff is large: its 430 lines aren’t shown here.

drivers/staging/rtl8723bs/os_dep/ioctl_linux.c+63−3226

This diff is large: its 3416 lines aren’t shown here.

drivers/staging/rtl8723bs/os_dep/mlme_linux.c+0−4

This diff is large: its 25 lines aren’t shown here.

drivers/staging/rtl8723bs/os_dep/os_intfs.c+4−28

This diff is large: its 109 lines aren’t shown here.

drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/rts5208/rtsx_scsi.c+3−7

This diff is large: its 26 lines aren’t shown here.

drivers/staging/sm750fb/sm750.c+26−26

This diff is large: its 150 lines aren’t shown here.

drivers/staging/sm750fb/sm750.h+6−6

This diff is large: its 26 lines aren’t shown here.

drivers/staging/sm750fb/sm750_cursor.c+2−2

This diff is large: its 18 lines aren’t shown here.

drivers/staging/sm750fb/sm750_hw.c+31−31

This diff is large: its 174 lines aren’t shown here.

drivers/staging/vc04_services/Kconfig+24−4

This diff is large: its 36 lines aren’t shown here.

drivers/staging/vc04_services/Makefile+4−1

This diff is large: its 15 lines aren’t shown here.

drivers/staging/vc04_services/bcm2835-audio/bcm2835.h+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c+0−564

This diff is large: its 565 lines aren’t shown here.

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c+715−1615

This diff is large: its 2488 lines aren’t shown here.

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h+82−0

This diff is large: its 104 lines aren’t shown here.

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c+1440−0

This diff is large: its 1441 lines aren’t shown here.

drivers/staging/vt6655/baseband.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/baseband.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/card.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/vt6655/card.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/channel.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/channel.h+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/vt6655/desc.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/device.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/device_cfg.h+1−5

This diff is large: its 26 lines aren’t shown here.

drivers/staging/vt6655/device_main.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/dpc.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/dpc.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/key.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/key.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/mac.c+0−3

This diff is large: its 17 lines aren’t shown here.

drivers/staging/vt6655/mac.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/power.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/power.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/rf.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/rf.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/rxtx.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/rxtx.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/srom.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/srom.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/tmacro.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6655/upc.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/baseband.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/baseband.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/card.c+0−1

This diff is large: its 8 lines aren’t shown here.

drivers/staging/vt6656/card.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/channel.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/channel.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/desc.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/device.h+0−4

This diff is large: its 18 lines aren’t shown here.

drivers/staging/vt6656/key.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/key.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/mac.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/mac.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/main_usb.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/power.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/power.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/rf.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/rf.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/rxtx.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/rxtx.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/usbpipe.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/usbpipe.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/wcmd.c+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/vt6656/wcmd.h+0−2

This diff is large: its 9 lines aren’t shown here.

drivers/staging/wlan-ng/hfa384x.h+3−16

This diff is large: its 40 lines aren’t shown here.

drivers/staging/wlan-ng/hfa384x_usb.c+6−7

This diff is large: its 55 lines aren’t shown here.

drivers/staging/wlan-ng/p80211conv.c+24−24

This diff is large: its 103 lines aren’t shown here.

drivers/staging/wlan-ng/p80211conv.h+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/wlan-ng/p80211hdr.h+8−22

This diff is large: its 37 lines aren’t shown here.

drivers/staging/wlan-ng/p80211mgmt.h+12−12

This diff is large: its 108 lines aren’t shown here.

drivers/staging/wlan-ng/p80211netdev.c+6−6

This diff is large: its 34 lines aren’t shown here.

drivers/staging/wlan-ng/p80211netdev.h+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/staging/wlan-ng/prism2fw.c+4−4

This diff is large: its 36 lines aren’t shown here.

drivers/staging/wlan-ng/prism2mib.c+10−0

This diff is large: its 29 lines aren’t shown here.

drivers/staging/wlan-ng/prism2sta.c+3−3

This diff is large: its 27 lines aren’t shown here.

include/dt-bindings/iio/adc/ingenic,adc.h+1−0

This diff is large: its 7 lines aren’t shown here.

include/linux/counter.h+16−16

This diff is large: its 65 lines aren’t shown here.

include/linux/mfd/hi6421-spmi-pmic.h+0−5

This diff is large: its 12 lines aren’t shown here.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t