power.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/delay.h>
  8. #if IS_ENABLED(CONFIG_MSM_QMP)
  9. #include <linux/mailbox/qmp.h>
  10. #endif
  11. #include <linux/of.h>
  12. #include <linux/of_gpio.h>
  13. #include <linux/pinctrl/consumer.h>
  14. #include <linux/pinctrl/qcom-pinctrl.h>
  15. #include <linux/regulator/consumer.h>
  16. #if IS_ENABLED(CONFIG_QCOM_COMMAND_DB)
  17. #include <soc/qcom/cmd-db.h>
  18. #endif
  19. #include "main.h"
  20. #include "debug.h"
  21. #include "bus.h"
  22. #if IS_ENABLED(CONFIG_ARCH_QCOM)
  23. static struct cnss_vreg_cfg cnss_vreg_list[] = {
  24. {"vdd-wlan-core", 1300000, 1300000, 0, 0, 0},
  25. {"vdd-wlan-io", 1800000, 1800000, 0, 0, 0},
  26. {"vdd-wlan-io12", 1200000, 1200000, 0, 0, 0},
  27. {"vdd-wlan-ant-share", 1800000, 1800000, 0, 0, 0},
  28. {"vdd-wlan-xtal-aon", 0, 0, 0, 0, 0},
  29. {"vdd-wlan-xtal", 1800000, 1800000, 0, 2, 0},
  30. {"vdd-wlan", 0, 0, 0, 0, 0},
  31. {"vdd-wlan-ctrl1", 0, 0, 0, 0, 0},
  32. {"vdd-wlan-ctrl2", 0, 0, 0, 0, 0},
  33. {"vdd-wlan-sp2t", 2700000, 2700000, 0, 0, 0},
  34. {"wlan-ant-switch", 1800000, 1800000, 0, 0, 0},
  35. {"wlan-soc-swreg", 1200000, 1200000, 0, 0, 0},
  36. {"vdd-wlan-aon", 950000, 950000, 0, 0, 0},
  37. {"vdd-wlan-dig", 950000, 952000, 0, 0, 0},
  38. {"vdd-wlan-rfa1", 1900000, 1900000, 0, 0, 0},
  39. {"vdd-wlan-rfa2", 1350000, 1350000, 0, 0, 0},
  40. {"vdd-wlan-rfa3", 1900000, 1900000, 450000, 0, 0},
  41. {"alt-sleep-clk", 0, 0, 0, 0, 0},
  42. {"vdd-wlan-en", 0, 0, 0, 10, 0},
  43. };
  44. static struct cnss_clk_cfg cnss_clk_list[] = {
  45. {"rf_clk", 0, 0},
  46. };
  47. #else
  48. static struct cnss_vreg_cfg cnss_vreg_list[] = {
  49. };
  50. static struct cnss_clk_cfg cnss_clk_list[] = {
  51. };
  52. #endif
  53. #define CNSS_VREG_INFO_SIZE ARRAY_SIZE(cnss_vreg_list)
  54. #define CNSS_CLK_INFO_SIZE ARRAY_SIZE(cnss_clk_list)
  55. #define MAX_PROP_SIZE 32
  56. #define BOOTSTRAP_GPIO "qcom,enable-bootstrap-gpio"
  57. #define BOOTSTRAP_ACTIVE "bootstrap_active"
  58. #define HOST_SOL_GPIO "wlan-host-sol-gpio"
  59. #define DEV_SOL_GPIO "wlan-dev-sol-gpio"
  60. #define SOL_DEFAULT "sol_default"
  61. #define WLAN_EN_GPIO "wlan-en-gpio"
  62. #define BT_EN_GPIO "qcom,bt-en-gpio"
  63. #define XO_CLK_GPIO "qcom,xo-clk-gpio"
  64. #define SW_CTRL_GPIO "qcom,sw-ctrl-gpio"
  65. #define WLAN_SW_CTRL_GPIO "qcom,wlan-sw-ctrl-gpio"
  66. #define WLAN_EN_ACTIVE "wlan_en_active"
  67. #define WLAN_EN_SLEEP "wlan_en_sleep"
  68. #define WLAN_VREGS_PROP "wlan_vregs"
  69. #define BOOTSTRAP_DELAY 1000
  70. #define WLAN_ENABLE_DELAY 1000
  71. #define WLAN_ENABLE_DELAY_ROME 10000
  72. #define TCS_CMD_DATA_ADDR_OFFSET 0x4
  73. #define TCS_OFFSET 0xC8
  74. #define TCS_CMD_OFFSET 0x10
  75. #define MAX_TCS_NUM 8
  76. #define MAX_TCS_CMD_NUM 5
  77. #define BT_CXMX_VOLTAGE_MV 950
  78. #define CNSS_MBOX_MSG_MAX_LEN 64
  79. #define CNSS_MBOX_TIMEOUT_MS 1000
  80. /* Platform HW config */
  81. #define CNSS_PMIC_VOLTAGE_STEP 4
  82. #define CNSS_PMIC_AUTO_HEADROOM 16
  83. #define CNSS_IR_DROP_WAKE 30
  84. #define CNSS_IR_DROP_SLEEP 10
  85. /**
  86. * enum cnss_aop_vreg_param: Voltage regulator TCS param
  87. * @CNSS_VREG_VOLTAGE: Provides voltage level in mV to be configured in TCS
  88. * @CNSS_VREG_MODE: Regulator mode
  89. * @CNSS_VREG_TCS_ENABLE: Set bool Voltage regulator enable config in TCS.
  90. */
  91. enum cnss_aop_vreg_param {
  92. CNSS_VREG_VOLTAGE,
  93. CNSS_VREG_MODE,
  94. CNSS_VREG_ENABLE,
  95. CNSS_VREG_PARAM_MAX
  96. };
  97. /** enum cnss_aop_vreg_param_mode: Voltage modes supported by AOP*/
  98. enum cnss_aop_vreg_param_mode {
  99. CNSS_VREG_RET_MODE = 3,
  100. CNSS_VREG_LPM_MODE = 4,
  101. CNSS_VREG_AUTO_MODE = 6,
  102. CNSS_VREG_NPM_MODE = 7,
  103. CNSS_VREG_MODE_MAX
  104. };
  105. /**
  106. * enum cnss_aop_tcs_seq: TCS sequence ID for trigger
  107. * @CNSS_TCS_UP_SEQ: TCS Sequence based on up trigger / Wake TCS
  108. * @CNSS_TCS_DOWN_SEQ: TCS Sequence based on down trigger / Sleep TCS
  109. * @CNSS_TCS_ENABLE_SEQ: Enable this TCS seq entry
  110. */
  111. enum cnss_aop_tcs_seq_param {
  112. CNSS_TCS_UP_SEQ,
  113. CNSS_TCS_DOWN_SEQ,
  114. CNSS_TCS_ENABLE_SEQ,
  115. CNSS_TCS_SEQ_MAX
  116. };
  117. static int cnss_get_vreg_single(struct cnss_plat_data *plat_priv,
  118. struct cnss_vreg_info *vreg)
  119. {
  120. int ret = 0;
  121. struct device *dev;
  122. struct regulator *reg;
  123. const __be32 *prop;
  124. char prop_name[MAX_PROP_SIZE] = {0};
  125. int len;
  126. struct device_node *dt_node;
  127. dev = &plat_priv->plat_dev->dev;
  128. dt_node = (plat_priv->dev_node ? plat_priv->dev_node : dev->of_node);
  129. reg = devm_regulator_get_optional(dev, vreg->cfg.name);
  130. if (IS_ERR(reg)) {
  131. ret = PTR_ERR(reg);
  132. if (ret == -ENODEV)
  133. return ret;
  134. else if (ret == -EPROBE_DEFER)
  135. cnss_pr_info("EPROBE_DEFER for regulator: %s\n",
  136. vreg->cfg.name);
  137. else
  138. cnss_pr_err("Failed to get regulator %s, err = %d\n",
  139. vreg->cfg.name, ret);
  140. return ret;
  141. }
  142. vreg->reg = reg;
  143. snprintf(prop_name, MAX_PROP_SIZE, "qcom,%s-config",
  144. vreg->cfg.name);
  145. prop = of_get_property(dt_node, prop_name, &len);
  146. if (!prop || len != (5 * sizeof(__be32))) {
  147. cnss_pr_dbg("Property %s %s, use default\n", prop_name,
  148. prop ? "invalid format" : "doesn't exist");
  149. } else {
  150. vreg->cfg.min_uv = be32_to_cpup(&prop[0]);
  151. vreg->cfg.max_uv = be32_to_cpup(&prop[1]);
  152. vreg->cfg.load_ua = be32_to_cpup(&prop[2]);
  153. vreg->cfg.delay_us = be32_to_cpup(&prop[3]);
  154. vreg->cfg.need_unvote = be32_to_cpup(&prop[4]);
  155. }
  156. cnss_pr_dbg("Got regulator: %s, min_uv: %u, max_uv: %u, load_ua: %u, delay_us: %u, need_unvote: %u\n",
  157. vreg->cfg.name, vreg->cfg.min_uv,
  158. vreg->cfg.max_uv, vreg->cfg.load_ua,
  159. vreg->cfg.delay_us, vreg->cfg.need_unvote);
  160. return 0;
  161. }
  162. static void cnss_put_vreg_single(struct cnss_plat_data *plat_priv,
  163. struct cnss_vreg_info *vreg)
  164. {
  165. struct device *dev = &plat_priv->plat_dev->dev;
  166. cnss_pr_dbg("Put regulator: %s\n", vreg->cfg.name);
  167. devm_regulator_put(vreg->reg);
  168. devm_kfree(dev, vreg);
  169. }
  170. static int cnss_vreg_on_single(struct cnss_vreg_info *vreg)
  171. {
  172. int ret = 0;
  173. if (vreg->enabled) {
  174. cnss_pr_dbg("Regulator %s is already enabled\n",
  175. vreg->cfg.name);
  176. return 0;
  177. }
  178. cnss_pr_dbg("Regulator %s is being enabled\n", vreg->cfg.name);
  179. if (vreg->cfg.min_uv != 0 && vreg->cfg.max_uv != 0) {
  180. ret = regulator_set_voltage(vreg->reg,
  181. vreg->cfg.min_uv,
  182. vreg->cfg.max_uv);
  183. if (ret) {
  184. cnss_pr_err("Failed to set voltage for regulator %s, min_uv: %u, max_uv: %u, err = %d\n",
  185. vreg->cfg.name, vreg->cfg.min_uv,
  186. vreg->cfg.max_uv, ret);
  187. goto out;
  188. }
  189. }
  190. if (vreg->cfg.load_ua) {
  191. ret = regulator_set_load(vreg->reg,
  192. vreg->cfg.load_ua);
  193. if (ret < 0) {
  194. cnss_pr_err("Failed to set load for regulator %s, load: %u, err = %d\n",
  195. vreg->cfg.name, vreg->cfg.load_ua,
  196. ret);
  197. goto out;
  198. }
  199. }
  200. if (vreg->cfg.delay_us)
  201. udelay(vreg->cfg.delay_us);
  202. ret = regulator_enable(vreg->reg);
  203. if (ret) {
  204. cnss_pr_err("Failed to enable regulator %s, err = %d\n",
  205. vreg->cfg.name, ret);
  206. goto out;
  207. }
  208. vreg->enabled = true;
  209. out:
  210. return ret;
  211. }
  212. static int cnss_vreg_unvote_single(struct cnss_vreg_info *vreg)
  213. {
  214. int ret = 0;
  215. if (!vreg->enabled) {
  216. cnss_pr_dbg("Regulator %s is already disabled\n",
  217. vreg->cfg.name);
  218. return 0;
  219. }
  220. cnss_pr_dbg("Removing vote for Regulator %s\n", vreg->cfg.name);
  221. if (vreg->cfg.load_ua) {
  222. ret = regulator_set_load(vreg->reg, 0);
  223. if (ret < 0)
  224. cnss_pr_err("Failed to set load for regulator %s, err = %d\n",
  225. vreg->cfg.name, ret);
  226. }
  227. if (vreg->cfg.min_uv != 0 && vreg->cfg.max_uv != 0) {
  228. ret = regulator_set_voltage(vreg->reg, 0,
  229. vreg->cfg.max_uv);
  230. if (ret)
  231. cnss_pr_err("Failed to set voltage for regulator %s, err = %d\n",
  232. vreg->cfg.name, ret);
  233. }
  234. return ret;
  235. }
  236. static int cnss_vreg_off_single(struct cnss_vreg_info *vreg)
  237. {
  238. int ret = 0;
  239. if (!vreg->enabled) {
  240. cnss_pr_dbg("Regulator %s is already disabled\n",
  241. vreg->cfg.name);
  242. return 0;
  243. }
  244. cnss_pr_dbg("Regulator %s is being disabled\n",
  245. vreg->cfg.name);
  246. ret = regulator_disable(vreg->reg);
  247. if (ret)
  248. cnss_pr_err("Failed to disable regulator %s, err = %d\n",
  249. vreg->cfg.name, ret);
  250. if (vreg->cfg.load_ua) {
  251. ret = regulator_set_load(vreg->reg, 0);
  252. if (ret < 0)
  253. cnss_pr_err("Failed to set load for regulator %s, err = %d\n",
  254. vreg->cfg.name, ret);
  255. }
  256. if (vreg->cfg.min_uv != 0 && vreg->cfg.max_uv != 0) {
  257. ret = regulator_set_voltage(vreg->reg, 0,
  258. vreg->cfg.max_uv);
  259. if (ret)
  260. cnss_pr_err("Failed to set voltage for regulator %s, err = %d\n",
  261. vreg->cfg.name, ret);
  262. }
  263. vreg->enabled = false;
  264. return ret;
  265. }
  266. static struct cnss_vreg_cfg *get_vreg_list(u32 *vreg_list_size,
  267. enum cnss_vreg_type type)
  268. {
  269. switch (type) {
  270. case CNSS_VREG_PRIM:
  271. *vreg_list_size = CNSS_VREG_INFO_SIZE;
  272. return cnss_vreg_list;
  273. default:
  274. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  275. *vreg_list_size = 0;
  276. return NULL;
  277. }
  278. }
  279. /*
  280. * For multi-exchg dt node, get the required vregs' names from property
  281. * 'wlan_vregs', which is string array;
  282. *
  283. * if the property is present but no value is set, then no additional wlan
  284. * verg is required.
  285. *
  286. * For non-multi-exchg dt, go through all vregs in the static array
  287. * 'cnss_vreg_list'.
  288. */
  289. static int cnss_get_vreg(struct cnss_plat_data *plat_priv,
  290. struct list_head *vreg_list,
  291. struct cnss_vreg_cfg *vreg_cfg,
  292. u32 vreg_list_size)
  293. {
  294. int ret = 0;
  295. int i;
  296. struct cnss_vreg_info *vreg;
  297. struct device *dev = &plat_priv->plat_dev->dev;
  298. int id_n;
  299. struct device_node *dt_node;
  300. if (!list_empty(vreg_list) &&
  301. (plat_priv->dt_type != CNSS_DTT_MULTIEXCHG)) {
  302. cnss_pr_dbg("Vregs have already been updated\n");
  303. return 0;
  304. }
  305. dt_node = (plat_priv->dev_node ? plat_priv->dev_node : dev->of_node);
  306. if (plat_priv->dt_type == CNSS_DTT_MULTIEXCHG) {
  307. id_n = of_property_count_strings(dt_node,
  308. WLAN_VREGS_PROP);
  309. if (id_n <= 0) {
  310. if (id_n == -ENODATA) {
  311. cnss_pr_dbg("No additional vregs for: %s:%lx\n",
  312. dt_node->name,
  313. plat_priv->device_id);
  314. return 0;
  315. }
  316. cnss_pr_err("property %s is invalid or missed: %s:%lx\n",
  317. WLAN_VREGS_PROP, dt_node->name,
  318. plat_priv->device_id);
  319. return -EINVAL;
  320. }
  321. } else {
  322. id_n = vreg_list_size;
  323. }
  324. for (i = 0; i < id_n; i++) {
  325. vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
  326. if (!vreg)
  327. return -ENOMEM;
  328. if (plat_priv->dt_type == CNSS_DTT_MULTIEXCHG) {
  329. ret = of_property_read_string_index(dt_node,
  330. WLAN_VREGS_PROP, i,
  331. &vreg->cfg.name);
  332. if (ret) {
  333. cnss_pr_err("Failed to read vreg ids\n");
  334. return ret;
  335. }
  336. } else {
  337. memcpy(&vreg->cfg, &vreg_cfg[i], sizeof(vreg->cfg));
  338. }
  339. ret = cnss_get_vreg_single(plat_priv, vreg);
  340. if (ret != 0) {
  341. if (ret == -ENODEV) {
  342. devm_kfree(dev, vreg);
  343. continue;
  344. } else {
  345. devm_kfree(dev, vreg);
  346. return ret;
  347. }
  348. }
  349. list_add_tail(&vreg->list, vreg_list);
  350. }
  351. return 0;
  352. }
  353. static void cnss_put_vreg(struct cnss_plat_data *plat_priv,
  354. struct list_head *vreg_list)
  355. {
  356. struct cnss_vreg_info *vreg;
  357. while (!list_empty(vreg_list)) {
  358. vreg = list_first_entry(vreg_list,
  359. struct cnss_vreg_info, list);
  360. list_del(&vreg->list);
  361. if (IS_ERR_OR_NULL(vreg->reg))
  362. continue;
  363. cnss_put_vreg_single(plat_priv, vreg);
  364. }
  365. }
  366. static int cnss_vreg_on(struct cnss_plat_data *plat_priv,
  367. struct list_head *vreg_list)
  368. {
  369. struct cnss_vreg_info *vreg;
  370. int ret = 0;
  371. list_for_each_entry(vreg, vreg_list, list) {
  372. if (IS_ERR_OR_NULL(vreg->reg))
  373. continue;
  374. ret = cnss_vreg_on_single(vreg);
  375. if (ret)
  376. break;
  377. }
  378. if (!ret)
  379. return 0;
  380. list_for_each_entry_continue_reverse(vreg, vreg_list, list) {
  381. if (IS_ERR_OR_NULL(vreg->reg) || !vreg->enabled)
  382. continue;
  383. cnss_vreg_off_single(vreg);
  384. }
  385. return ret;
  386. }
  387. static int cnss_vreg_off(struct cnss_plat_data *plat_priv,
  388. struct list_head *vreg_list)
  389. {
  390. struct cnss_vreg_info *vreg;
  391. list_for_each_entry_reverse(vreg, vreg_list, list) {
  392. if (IS_ERR_OR_NULL(vreg->reg))
  393. continue;
  394. cnss_vreg_off_single(vreg);
  395. }
  396. return 0;
  397. }
  398. static int cnss_vreg_unvote(struct cnss_plat_data *plat_priv,
  399. struct list_head *vreg_list)
  400. {
  401. struct cnss_vreg_info *vreg;
  402. list_for_each_entry_reverse(vreg, vreg_list, list) {
  403. if (IS_ERR_OR_NULL(vreg->reg))
  404. continue;
  405. if (vreg->cfg.need_unvote)
  406. cnss_vreg_unvote_single(vreg);
  407. }
  408. return 0;
  409. }
  410. int cnss_get_vreg_type(struct cnss_plat_data *plat_priv,
  411. enum cnss_vreg_type type)
  412. {
  413. struct cnss_vreg_cfg *vreg_cfg;
  414. u32 vreg_list_size = 0;
  415. int ret = 0;
  416. vreg_cfg = get_vreg_list(&vreg_list_size, type);
  417. if (!vreg_cfg)
  418. return -EINVAL;
  419. switch (type) {
  420. case CNSS_VREG_PRIM:
  421. ret = cnss_get_vreg(plat_priv, &plat_priv->vreg_list,
  422. vreg_cfg, vreg_list_size);
  423. break;
  424. default:
  425. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  426. return -EINVAL;
  427. }
  428. return ret;
  429. }
  430. void cnss_put_vreg_type(struct cnss_plat_data *plat_priv,
  431. enum cnss_vreg_type type)
  432. {
  433. switch (type) {
  434. case CNSS_VREG_PRIM:
  435. cnss_put_vreg(plat_priv, &plat_priv->vreg_list);
  436. break;
  437. default:
  438. return;
  439. }
  440. }
  441. int cnss_vreg_on_type(struct cnss_plat_data *plat_priv,
  442. enum cnss_vreg_type type)
  443. {
  444. int ret = 0;
  445. switch (type) {
  446. case CNSS_VREG_PRIM:
  447. ret = cnss_vreg_on(plat_priv, &plat_priv->vreg_list);
  448. break;
  449. default:
  450. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  451. return -EINVAL;
  452. }
  453. return ret;
  454. }
  455. int cnss_vreg_off_type(struct cnss_plat_data *plat_priv,
  456. enum cnss_vreg_type type)
  457. {
  458. int ret = 0;
  459. switch (type) {
  460. case CNSS_VREG_PRIM:
  461. ret = cnss_vreg_off(plat_priv, &plat_priv->vreg_list);
  462. break;
  463. default:
  464. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  465. return -EINVAL;
  466. }
  467. return ret;
  468. }
  469. int cnss_vreg_unvote_type(struct cnss_plat_data *plat_priv,
  470. enum cnss_vreg_type type)
  471. {
  472. int ret = 0;
  473. switch (type) {
  474. case CNSS_VREG_PRIM:
  475. ret = cnss_vreg_unvote(plat_priv, &plat_priv->vreg_list);
  476. break;
  477. default:
  478. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  479. return -EINVAL;
  480. }
  481. return ret;
  482. }
  483. static int cnss_get_clk_single(struct cnss_plat_data *plat_priv,
  484. struct cnss_clk_info *clk_info)
  485. {
  486. struct device *dev = &plat_priv->plat_dev->dev;
  487. struct clk *clk;
  488. int ret;
  489. clk = devm_clk_get(dev, clk_info->cfg.name);
  490. if (IS_ERR(clk)) {
  491. ret = PTR_ERR(clk);
  492. if (clk_info->cfg.required)
  493. cnss_pr_err("Failed to get clock %s, err = %d\n",
  494. clk_info->cfg.name, ret);
  495. else
  496. cnss_pr_dbg("Failed to get optional clock %s, err = %d\n",
  497. clk_info->cfg.name, ret);
  498. return ret;
  499. }
  500. clk_info->clk = clk;
  501. cnss_pr_dbg("Got clock: %s, freq: %u\n",
  502. clk_info->cfg.name, clk_info->cfg.freq);
  503. return 0;
  504. }
  505. static void cnss_put_clk_single(struct cnss_plat_data *plat_priv,
  506. struct cnss_clk_info *clk_info)
  507. {
  508. struct device *dev = &plat_priv->plat_dev->dev;
  509. cnss_pr_dbg("Put clock: %s\n", clk_info->cfg.name);
  510. devm_clk_put(dev, clk_info->clk);
  511. }
  512. static int cnss_clk_on_single(struct cnss_clk_info *clk_info)
  513. {
  514. int ret;
  515. if (clk_info->enabled) {
  516. cnss_pr_dbg("Clock %s is already enabled\n",
  517. clk_info->cfg.name);
  518. return 0;
  519. }
  520. cnss_pr_dbg("Clock %s is being enabled\n", clk_info->cfg.name);
  521. if (clk_info->cfg.freq) {
  522. ret = clk_set_rate(clk_info->clk, clk_info->cfg.freq);
  523. if (ret) {
  524. cnss_pr_err("Failed to set frequency %u for clock %s, err = %d\n",
  525. clk_info->cfg.freq, clk_info->cfg.name,
  526. ret);
  527. return ret;
  528. }
  529. }
  530. ret = clk_prepare_enable(clk_info->clk);
  531. if (ret) {
  532. cnss_pr_err("Failed to enable clock %s, err = %d\n",
  533. clk_info->cfg.name, ret);
  534. return ret;
  535. }
  536. clk_info->enabled = true;
  537. return 0;
  538. }
  539. static int cnss_clk_off_single(struct cnss_clk_info *clk_info)
  540. {
  541. if (!clk_info->enabled) {
  542. cnss_pr_dbg("Clock %s is already disabled\n",
  543. clk_info->cfg.name);
  544. return 0;
  545. }
  546. cnss_pr_dbg("Clock %s is being disabled\n", clk_info->cfg.name);
  547. clk_disable_unprepare(clk_info->clk);
  548. clk_info->enabled = false;
  549. return 0;
  550. }
  551. int cnss_get_clk(struct cnss_plat_data *plat_priv)
  552. {
  553. struct device *dev;
  554. struct list_head *clk_list;
  555. struct cnss_clk_info *clk_info;
  556. int ret, i;
  557. if (!plat_priv)
  558. return -ENODEV;
  559. dev = &plat_priv->plat_dev->dev;
  560. clk_list = &plat_priv->clk_list;
  561. if (!list_empty(clk_list)) {
  562. cnss_pr_dbg("Clocks have already been updated\n");
  563. return 0;
  564. }
  565. for (i = 0; i < CNSS_CLK_INFO_SIZE; i++) {
  566. clk_info = devm_kzalloc(dev, sizeof(*clk_info), GFP_KERNEL);
  567. if (!clk_info) {
  568. ret = -ENOMEM;
  569. goto cleanup;
  570. }
  571. memcpy(&clk_info->cfg, &cnss_clk_list[i],
  572. sizeof(clk_info->cfg));
  573. ret = cnss_get_clk_single(plat_priv, clk_info);
  574. if (ret != 0) {
  575. if (clk_info->cfg.required) {
  576. devm_kfree(dev, clk_info);
  577. goto cleanup;
  578. } else {
  579. devm_kfree(dev, clk_info);
  580. continue;
  581. }
  582. }
  583. list_add_tail(&clk_info->list, clk_list);
  584. }
  585. return 0;
  586. cleanup:
  587. while (!list_empty(clk_list)) {
  588. clk_info = list_first_entry(clk_list, struct cnss_clk_info,
  589. list);
  590. list_del(&clk_info->list);
  591. if (IS_ERR_OR_NULL(clk_info->clk))
  592. continue;
  593. cnss_put_clk_single(plat_priv, clk_info);
  594. devm_kfree(dev, clk_info);
  595. }
  596. return ret;
  597. }
  598. void cnss_put_clk(struct cnss_plat_data *plat_priv)
  599. {
  600. struct device *dev;
  601. struct list_head *clk_list;
  602. struct cnss_clk_info *clk_info;
  603. if (!plat_priv)
  604. return;
  605. dev = &plat_priv->plat_dev->dev;
  606. clk_list = &plat_priv->clk_list;
  607. while (!list_empty(clk_list)) {
  608. clk_info = list_first_entry(clk_list, struct cnss_clk_info,
  609. list);
  610. list_del(&clk_info->list);
  611. if (IS_ERR_OR_NULL(clk_info->clk))
  612. continue;
  613. cnss_put_clk_single(plat_priv, clk_info);
  614. devm_kfree(dev, clk_info);
  615. }
  616. }
  617. static int cnss_clk_on(struct cnss_plat_data *plat_priv,
  618. struct list_head *clk_list)
  619. {
  620. struct cnss_clk_info *clk_info;
  621. int ret = 0;
  622. list_for_each_entry(clk_info, clk_list, list) {
  623. if (IS_ERR_OR_NULL(clk_info->clk))
  624. continue;
  625. ret = cnss_clk_on_single(clk_info);
  626. if (ret)
  627. break;
  628. }
  629. if (!ret)
  630. return 0;
  631. list_for_each_entry_continue_reverse(clk_info, clk_list, list) {
  632. if (IS_ERR_OR_NULL(clk_info->clk))
  633. continue;
  634. cnss_clk_off_single(clk_info);
  635. }
  636. return ret;
  637. }
  638. static int cnss_clk_off(struct cnss_plat_data *plat_priv,
  639. struct list_head *clk_list)
  640. {
  641. struct cnss_clk_info *clk_info;
  642. list_for_each_entry_reverse(clk_info, clk_list, list) {
  643. if (IS_ERR_OR_NULL(clk_info->clk))
  644. continue;
  645. cnss_clk_off_single(clk_info);
  646. }
  647. return 0;
  648. }
  649. int cnss_get_pinctrl(struct cnss_plat_data *plat_priv)
  650. {
  651. int ret = 0;
  652. struct device *dev;
  653. struct cnss_pinctrl_info *pinctrl_info;
  654. u32 gpio_id, i;
  655. int gpio_id_n;
  656. dev = &plat_priv->plat_dev->dev;
  657. pinctrl_info = &plat_priv->pinctrl_info;
  658. pinctrl_info->pinctrl = devm_pinctrl_get(dev);
  659. if (IS_ERR_OR_NULL(pinctrl_info->pinctrl)) {
  660. ret = PTR_ERR(pinctrl_info->pinctrl);
  661. cnss_pr_err("Failed to get pinctrl, err = %d\n", ret);
  662. goto out;
  663. }
  664. if (of_find_property(dev->of_node, BOOTSTRAP_GPIO, NULL)) {
  665. pinctrl_info->bootstrap_active =
  666. pinctrl_lookup_state(pinctrl_info->pinctrl,
  667. BOOTSTRAP_ACTIVE);
  668. if (IS_ERR_OR_NULL(pinctrl_info->bootstrap_active)) {
  669. ret = PTR_ERR(pinctrl_info->bootstrap_active);
  670. cnss_pr_err("Failed to get bootstrap active state, err = %d\n",
  671. ret);
  672. goto out;
  673. }
  674. }
  675. if (of_find_property(dev->of_node, HOST_SOL_GPIO, NULL) &&
  676. of_find_property(dev->of_node, DEV_SOL_GPIO, NULL)) {
  677. pinctrl_info->sol_default =
  678. pinctrl_lookup_state(pinctrl_info->pinctrl,
  679. SOL_DEFAULT);
  680. if (IS_ERR_OR_NULL(pinctrl_info->sol_default)) {
  681. ret = PTR_ERR(pinctrl_info->sol_default);
  682. cnss_pr_err("Failed to get sol default state, err = %d\n",
  683. ret);
  684. goto out;
  685. }
  686. cnss_pr_dbg("Got sol default state\n");
  687. }
  688. if (of_find_property(dev->of_node, WLAN_EN_GPIO, NULL)) {
  689. pinctrl_info->wlan_en_gpio = of_get_named_gpio(dev->of_node,
  690. WLAN_EN_GPIO, 0);
  691. cnss_pr_dbg("WLAN_EN GPIO: %d\n", pinctrl_info->wlan_en_gpio);
  692. pinctrl_info->wlan_en_active =
  693. pinctrl_lookup_state(pinctrl_info->pinctrl,
  694. WLAN_EN_ACTIVE);
  695. if (IS_ERR_OR_NULL(pinctrl_info->wlan_en_active)) {
  696. ret = PTR_ERR(pinctrl_info->wlan_en_active);
  697. cnss_pr_err("Failed to get wlan_en active state, err = %d\n",
  698. ret);
  699. goto out;
  700. }
  701. pinctrl_info->wlan_en_sleep =
  702. pinctrl_lookup_state(pinctrl_info->pinctrl,
  703. WLAN_EN_SLEEP);
  704. if (IS_ERR_OR_NULL(pinctrl_info->wlan_en_sleep)) {
  705. ret = PTR_ERR(pinctrl_info->wlan_en_sleep);
  706. cnss_pr_err("Failed to get wlan_en sleep state, err = %d\n",
  707. ret);
  708. goto out;
  709. }
  710. cnss_set_feature_list(plat_priv, CNSS_WLAN_EN_SUPPORT_V01);
  711. } else {
  712. pinctrl_info->wlan_en_gpio = -EINVAL;
  713. }
  714. /* Added for QCA6490 PMU delayed WLAN_EN_GPIO */
  715. if (of_find_property(dev->of_node, BT_EN_GPIO, NULL)) {
  716. pinctrl_info->bt_en_gpio = of_get_named_gpio(dev->of_node,
  717. BT_EN_GPIO, 0);
  718. cnss_pr_dbg("BT GPIO: %d\n", pinctrl_info->bt_en_gpio);
  719. } else {
  720. pinctrl_info->bt_en_gpio = -EINVAL;
  721. }
  722. /* Added for QCA6490 to minimize XO CLK selection leakage prevention */
  723. if (of_find_property(dev->of_node, XO_CLK_GPIO, NULL)) {
  724. pinctrl_info->xo_clk_gpio = of_get_named_gpio(dev->of_node,
  725. XO_CLK_GPIO, 0);
  726. cnss_pr_dbg("QCA6490 XO_CLK GPIO: %d\n",
  727. pinctrl_info->xo_clk_gpio);
  728. cnss_set_feature_list(plat_priv, BOOTSTRAP_CLOCK_SELECT_V01);
  729. } else {
  730. pinctrl_info->xo_clk_gpio = -EINVAL;
  731. }
  732. if (of_find_property(dev->of_node, SW_CTRL_GPIO, NULL)) {
  733. pinctrl_info->sw_ctrl_gpio = of_get_named_gpio(dev->of_node,
  734. SW_CTRL_GPIO,
  735. 0);
  736. cnss_pr_dbg("Switch control GPIO: %d\n",
  737. pinctrl_info->sw_ctrl_gpio);
  738. } else {
  739. pinctrl_info->sw_ctrl_gpio = -EINVAL;
  740. }
  741. /* Find out and configure all those GPIOs which need to be setup
  742. * for interrupt wakeup capable
  743. */
  744. gpio_id_n = of_property_count_u32_elems(dev->of_node, "mpm_wake_set_gpios");
  745. if (gpio_id_n > 0) {
  746. cnss_pr_dbg("Num of GPIOs to be setup for interrupt wakeup capable: %d\n",
  747. gpio_id_n);
  748. for (i = 0; i < gpio_id_n; i++) {
  749. ret = of_property_read_u32_index(dev->of_node,
  750. "mpm_wake_set_gpios",
  751. i, &gpio_id);
  752. if (ret) {
  753. cnss_pr_err("Failed to read gpio_id at index: %d\n", i);
  754. continue;
  755. }
  756. ret = msm_gpio_mpm_wake_set(gpio_id, 1);
  757. if (ret < 0) {
  758. cnss_pr_err("Failed to setup gpio_id: %d as interrupt wakeup capable, ret: %d\n",
  759. ret);
  760. } else {
  761. cnss_pr_dbg("gpio_id: %d successfully setup for interrupt wakeup capable\n",
  762. gpio_id);
  763. }
  764. }
  765. } else {
  766. cnss_pr_dbg("No GPIOs to be setup for interrupt wakeup capable\n");
  767. }
  768. return 0;
  769. out:
  770. return ret;
  771. }
  772. int cnss_get_wlan_sw_ctrl(struct cnss_plat_data *plat_priv)
  773. {
  774. struct device *dev;
  775. struct cnss_pinctrl_info *pinctrl_info;
  776. dev = &plat_priv->plat_dev->dev;
  777. pinctrl_info = &plat_priv->pinctrl_info;
  778. if (of_find_property(dev->of_node, WLAN_SW_CTRL_GPIO, NULL)) {
  779. pinctrl_info->wlan_sw_ctrl_gpio = of_get_named_gpio(dev->of_node,
  780. WLAN_SW_CTRL_GPIO,
  781. 0);
  782. cnss_pr_dbg("WLAN Switch control GPIO: %d\n",
  783. pinctrl_info->wlan_sw_ctrl_gpio);
  784. } else {
  785. pinctrl_info->wlan_sw_ctrl_gpio = -EINVAL;
  786. }
  787. return 0;
  788. }
  789. #define CNSS_XO_CLK_RETRY_COUNT_MAX 5
  790. static void cnss_set_xo_clk_gpio_state(struct cnss_plat_data *plat_priv,
  791. bool enable)
  792. {
  793. int xo_clk_gpio = plat_priv->pinctrl_info.xo_clk_gpio, retry = 0, ret;
  794. if (xo_clk_gpio < 0 || plat_priv->device_id != QCA6490_DEVICE_ID)
  795. return;
  796. retry_gpio_req:
  797. ret = gpio_request(xo_clk_gpio, "XO_CLK_GPIO");
  798. if (ret) {
  799. if (retry++ < CNSS_XO_CLK_RETRY_COUNT_MAX) {
  800. /* wait for ~(10 - 20) ms */
  801. usleep_range(10000, 20000);
  802. goto retry_gpio_req;
  803. }
  804. }
  805. if (ret) {
  806. cnss_pr_err("QCA6490 XO CLK Gpio request failed\n");
  807. return;
  808. }
  809. if (enable) {
  810. gpio_direction_output(xo_clk_gpio, 1);
  811. /*XO CLK must be asserted for some time before WLAN_EN */
  812. usleep_range(100, 200);
  813. } else {
  814. /* Assert XO CLK ~(2-5)ms before off for valid latch in HW */
  815. usleep_range(2000, 5000);
  816. gpio_direction_output(xo_clk_gpio, 0);
  817. }
  818. gpio_free(xo_clk_gpio);
  819. }
  820. static int cnss_select_pinctrl_state(struct cnss_plat_data *plat_priv,
  821. bool state)
  822. {
  823. int ret = 0;
  824. struct cnss_pinctrl_info *pinctrl_info;
  825. if (!plat_priv) {
  826. cnss_pr_err("plat_priv is NULL!\n");
  827. ret = -ENODEV;
  828. goto out;
  829. }
  830. pinctrl_info = &plat_priv->pinctrl_info;
  831. if (state) {
  832. if (!IS_ERR_OR_NULL(pinctrl_info->bootstrap_active)) {
  833. ret = pinctrl_select_state
  834. (pinctrl_info->pinctrl,
  835. pinctrl_info->bootstrap_active);
  836. if (ret) {
  837. cnss_pr_err("Failed to select bootstrap active state, err = %d\n",
  838. ret);
  839. goto out;
  840. }
  841. udelay(BOOTSTRAP_DELAY);
  842. }
  843. if (!IS_ERR_OR_NULL(pinctrl_info->sol_default)) {
  844. ret = pinctrl_select_state
  845. (pinctrl_info->pinctrl,
  846. pinctrl_info->sol_default);
  847. if (ret) {
  848. cnss_pr_err("Failed to select sol default state, err = %d\n",
  849. ret);
  850. goto out;
  851. }
  852. cnss_pr_dbg("Selected sol default state\n");
  853. }
  854. cnss_set_xo_clk_gpio_state(plat_priv, true);
  855. if (!IS_ERR_OR_NULL(pinctrl_info->wlan_en_active)) {
  856. ret = pinctrl_select_state
  857. (pinctrl_info->pinctrl,
  858. pinctrl_info->wlan_en_active);
  859. if (ret) {
  860. cnss_pr_err("Failed to select wlan_en active state, err = %d\n",
  861. ret);
  862. goto out;
  863. }
  864. if (plat_priv->device_id == QCA6174_DEVICE_ID ||
  865. plat_priv->device_id == 0)
  866. udelay(WLAN_ENABLE_DELAY_ROME);
  867. else
  868. udelay(WLAN_ENABLE_DELAY);
  869. cnss_set_xo_clk_gpio_state(plat_priv, false);
  870. } else {
  871. cnss_set_xo_clk_gpio_state(plat_priv, false);
  872. goto out;
  873. }
  874. } else {
  875. if (!IS_ERR_OR_NULL(pinctrl_info->wlan_en_sleep)) {
  876. cnss_wlan_hw_disable_check(plat_priv);
  877. if (test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state)) {
  878. cnss_pr_dbg("Avoid WLAN_EN low. WLAN HW Disbaled");
  879. goto out;
  880. }
  881. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  882. pinctrl_info->wlan_en_sleep);
  883. if (ret) {
  884. cnss_pr_err("Failed to select wlan_en sleep state, err = %d\n",
  885. ret);
  886. goto out;
  887. }
  888. } else {
  889. goto out;
  890. }
  891. }
  892. cnss_pr_dbg("WLAN_EN Value: %d\n", gpio_get_value(pinctrl_info->wlan_en_gpio));
  893. cnss_pr_dbg("%s WLAN_EN GPIO successfully\n",
  894. state ? "Assert" : "De-assert");
  895. return 0;
  896. out:
  897. return ret;
  898. }
  899. /**
  900. * cnss_select_pinctrl_enable - select WLAN_GPIO for Active pinctrl status
  901. * @plat_priv: Platform private data structure pointer
  902. *
  903. * For QCA6490, PMU requires minimum 100ms delay between BT_EN_GPIO off and
  904. * WLAN_EN_GPIO on. This is done to avoid power up issues.
  905. *
  906. * Return: Status of pinctrl select operation. 0 - Success.
  907. */
  908. static int cnss_select_pinctrl_enable(struct cnss_plat_data *plat_priv)
  909. {
  910. int ret = 0, bt_en_gpio = plat_priv->pinctrl_info.bt_en_gpio;
  911. u8 wlan_en_state = 0;
  912. if (bt_en_gpio < 0 || plat_priv->device_id != QCA6490_DEVICE_ID)
  913. goto set_wlan_en;
  914. if (gpio_get_value(bt_en_gpio)) {
  915. cnss_pr_dbg("BT_EN_GPIO State: On\n");
  916. ret = cnss_select_pinctrl_state(plat_priv, true);
  917. if (!ret)
  918. return ret;
  919. wlan_en_state = 1;
  920. }
  921. if (!gpio_get_value(bt_en_gpio)) {
  922. cnss_pr_dbg("BT_EN_GPIO State: Off. Delay WLAN_GPIO enable\n");
  923. /* check for BT_EN_GPIO down race during above operation */
  924. if (wlan_en_state) {
  925. cnss_pr_dbg("Reset WLAN_EN as BT got turned off during enable\n");
  926. cnss_select_pinctrl_state(plat_priv, false);
  927. wlan_en_state = 0;
  928. }
  929. /* 100 ms delay for BT_EN and WLAN_EN QCA6490 PMU sequencing */
  930. msleep(100);
  931. }
  932. set_wlan_en:
  933. if (!wlan_en_state)
  934. ret = cnss_select_pinctrl_state(plat_priv, true);
  935. return ret;
  936. }
  937. int cnss_get_input_gpio_value(struct cnss_plat_data *plat_priv, int gpio_num)
  938. {
  939. int ret;
  940. if (gpio_num < 0)
  941. return -EINVAL;
  942. ret = gpio_direction_input(gpio_num);
  943. if (ret) {
  944. cnss_pr_err("Failed to set direction of GPIO(%d), err = %d",
  945. gpio_num, ret);
  946. return -EINVAL;
  947. }
  948. return gpio_get_value(gpio_num);
  949. }
  950. int cnss_power_on_device(struct cnss_plat_data *plat_priv, bool reset)
  951. {
  952. int ret = 0;
  953. if (plat_priv->powered_on) {
  954. cnss_pr_dbg("Already powered up");
  955. return 0;
  956. }
  957. cnss_wlan_hw_disable_check(plat_priv);
  958. if (test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state)) {
  959. cnss_pr_dbg("Avoid WLAN Power On. WLAN HW Disbaled");
  960. return -EINVAL;
  961. }
  962. ret = cnss_vreg_on_type(plat_priv, CNSS_VREG_PRIM);
  963. if (ret) {
  964. cnss_pr_err("Failed to turn on vreg, err = %d\n", ret);
  965. goto out;
  966. }
  967. ret = cnss_clk_on(plat_priv, &plat_priv->clk_list);
  968. if (ret) {
  969. cnss_pr_err("Failed to turn on clocks, err = %d\n", ret);
  970. goto vreg_off;
  971. }
  972. #ifdef CONFIG_PULLDOWN_WLANEN
  973. if (reset) {
  974. /* The default state of wlan_en maybe not low,
  975. * according to datasheet, we should put wlan_en
  976. * to low first, and trigger high.
  977. * And the default delay for qca6390 is at least 4ms,
  978. * for qcn7605/qca6174, it is 10us. For safe, set 5ms delay
  979. * here.
  980. */
  981. ret = cnss_select_pinctrl_state(plat_priv, false);
  982. if (ret) {
  983. cnss_pr_err("Failed to select pinctrl state, err = %d\n",
  984. ret);
  985. goto clk_off;
  986. }
  987. usleep_range(4000, 5000);
  988. }
  989. #endif
  990. ret = cnss_select_pinctrl_enable(plat_priv);
  991. if (ret) {
  992. cnss_pr_err("Failed to select pinctrl state, err = %d\n", ret);
  993. goto clk_off;
  994. }
  995. plat_priv->powered_on = true;
  996. cnss_enable_dev_sol_irq(plat_priv);
  997. cnss_set_host_sol_value(plat_priv, 0);
  998. return 0;
  999. clk_off:
  1000. cnss_clk_off(plat_priv, &plat_priv->clk_list);
  1001. vreg_off:
  1002. cnss_vreg_off_type(plat_priv, CNSS_VREG_PRIM);
  1003. out:
  1004. return ret;
  1005. }
  1006. void cnss_power_off_device(struct cnss_plat_data *plat_priv)
  1007. {
  1008. if (!plat_priv->powered_on) {
  1009. cnss_pr_dbg("Already powered down");
  1010. return;
  1011. }
  1012. cnss_disable_dev_sol_irq(plat_priv);
  1013. cnss_select_pinctrl_state(plat_priv, false);
  1014. cnss_clk_off(plat_priv, &plat_priv->clk_list);
  1015. cnss_vreg_off_type(plat_priv, CNSS_VREG_PRIM);
  1016. plat_priv->powered_on = false;
  1017. }
  1018. bool cnss_is_device_powered_on(struct cnss_plat_data *plat_priv)
  1019. {
  1020. return plat_priv->powered_on;
  1021. }
  1022. void cnss_set_pin_connect_status(struct cnss_plat_data *plat_priv)
  1023. {
  1024. unsigned long pin_status = 0;
  1025. set_bit(CNSS_WLAN_EN, &pin_status);
  1026. set_bit(CNSS_PCIE_TXN, &pin_status);
  1027. set_bit(CNSS_PCIE_TXP, &pin_status);
  1028. set_bit(CNSS_PCIE_RXN, &pin_status);
  1029. set_bit(CNSS_PCIE_RXP, &pin_status);
  1030. set_bit(CNSS_PCIE_REFCLKN, &pin_status);
  1031. set_bit(CNSS_PCIE_REFCLKP, &pin_status);
  1032. set_bit(CNSS_PCIE_RST, &pin_status);
  1033. plat_priv->pin_result.host_pin_result = pin_status;
  1034. }
  1035. #if IS_ENABLED(CONFIG_QCOM_COMMAND_DB)
  1036. static int cnss_cmd_db_ready(struct cnss_plat_data *plat_priv)
  1037. {
  1038. return cmd_db_ready();
  1039. }
  1040. static u32 cnss_cmd_db_read_addr(struct cnss_plat_data *plat_priv,
  1041. const char *res_id)
  1042. {
  1043. return cmd_db_read_addr(res_id);
  1044. }
  1045. #else
  1046. static int cnss_cmd_db_ready(struct cnss_plat_data *plat_priv)
  1047. {
  1048. return -EOPNOTSUPP;
  1049. }
  1050. static u32 cnss_cmd_db_read_addr(struct cnss_plat_data *plat_priv,
  1051. const char *res_id)
  1052. {
  1053. return 0;
  1054. }
  1055. #endif
  1056. int cnss_get_tcs_info(struct cnss_plat_data *plat_priv)
  1057. {
  1058. struct platform_device *plat_dev = plat_priv->plat_dev;
  1059. struct resource *res;
  1060. resource_size_t addr_len;
  1061. void __iomem *tcs_cmd_base_addr;
  1062. int ret = 0;
  1063. res = platform_get_resource_byname(plat_dev, IORESOURCE_MEM, "tcs_cmd");
  1064. if (!res) {
  1065. cnss_pr_dbg("TCS CMD address is not present for CPR\n");
  1066. goto out;
  1067. }
  1068. plat_priv->tcs_info.cmd_base_addr = res->start;
  1069. addr_len = resource_size(res);
  1070. cnss_pr_dbg("TCS CMD base address is %pa with length %pa\n",
  1071. &plat_priv->tcs_info.cmd_base_addr, &addr_len);
  1072. tcs_cmd_base_addr = devm_ioremap(&plat_dev->dev, res->start, addr_len);
  1073. if (!tcs_cmd_base_addr) {
  1074. ret = -EINVAL;
  1075. cnss_pr_err("Failed to map TCS CMD address, err = %d\n",
  1076. ret);
  1077. goto out;
  1078. }
  1079. plat_priv->tcs_info.cmd_base_addr_io = tcs_cmd_base_addr;
  1080. return 0;
  1081. out:
  1082. return ret;
  1083. }
  1084. int cnss_get_cpr_info(struct cnss_plat_data *plat_priv)
  1085. {
  1086. struct platform_device *plat_dev = plat_priv->plat_dev;
  1087. struct cnss_cpr_info *cpr_info = &plat_priv->cpr_info;
  1088. const char *cmd_db_name;
  1089. u32 cpr_pmic_addr = 0;
  1090. int ret = 0;
  1091. if (plat_priv->tcs_info.cmd_base_addr == 0) {
  1092. cnss_pr_dbg("TCS CMD not configured\n");
  1093. return 0;
  1094. }
  1095. ret = of_property_read_string(plat_dev->dev.of_node,
  1096. "qcom,cmd_db_name", &cmd_db_name);
  1097. if (ret) {
  1098. cnss_pr_dbg("CommandDB name is not present for CPR\n");
  1099. goto out;
  1100. }
  1101. ret = cnss_cmd_db_ready(plat_priv);
  1102. if (ret) {
  1103. cnss_pr_err("CommandDB is not ready, err = %d\n", ret);
  1104. goto out;
  1105. }
  1106. cpr_pmic_addr = cnss_cmd_db_read_addr(plat_priv, cmd_db_name);
  1107. if (cpr_pmic_addr > 0) {
  1108. cpr_info->cpr_pmic_addr = cpr_pmic_addr;
  1109. cnss_pr_dbg("Get CPR PMIC address 0x%x from %s\n",
  1110. cpr_info->cpr_pmic_addr, cmd_db_name);
  1111. } else {
  1112. cnss_pr_err("CPR PMIC address is not available for %s\n",
  1113. cmd_db_name);
  1114. ret = -EINVAL;
  1115. goto out;
  1116. }
  1117. return 0;
  1118. out:
  1119. return ret;
  1120. }
  1121. #if IS_ENABLED(CONFIG_MSM_QMP)
  1122. int cnss_aop_mbox_init(struct cnss_plat_data *plat_priv)
  1123. {
  1124. struct mbox_client *mbox = &plat_priv->mbox_client_data;
  1125. struct mbox_chan *chan;
  1126. int ret;
  1127. plat_priv->mbox_chan = NULL;
  1128. mbox->dev = &plat_priv->plat_dev->dev;
  1129. mbox->tx_block = true;
  1130. mbox->tx_tout = CNSS_MBOX_TIMEOUT_MS;
  1131. mbox->knows_txdone = false;
  1132. chan = mbox_request_channel(mbox, 0);
  1133. if (IS_ERR(chan)) {
  1134. cnss_pr_err("Failed to get mbox channel\n");
  1135. return PTR_ERR(chan);
  1136. }
  1137. plat_priv->mbox_chan = chan;
  1138. cnss_pr_dbg("Mbox channel initialized\n");
  1139. ret = cnss_aop_pdc_reconfig(plat_priv);
  1140. if (ret)
  1141. cnss_pr_err("Failed to reconfig WLAN PDC, err = %d\n", ret);
  1142. return 0;
  1143. }
  1144. /**
  1145. * cnss_aop_send_msg: Sends json message to AOP using QMP
  1146. * @plat_priv: Pointer to cnss platform data
  1147. * @msg: String in json format
  1148. *
  1149. * AOP accepts JSON message to configure WLAN resources. Format as follows:
  1150. * To send VReg config: {class: wlan_pdc, ss: <pdc_name>,
  1151. * res: <VReg_name>.<param>, <seq_param>: <value>}
  1152. * To send PDC Config: {class: wlan_pdc, ss: <pdc_name>, res: pdc,
  1153. * enable: <Value>}
  1154. * QMP returns timeout error if format not correct or AOP operation fails.
  1155. *
  1156. * Return: 0 for success
  1157. */
  1158. int cnss_aop_send_msg(struct cnss_plat_data *plat_priv, char *mbox_msg)
  1159. {
  1160. struct qmp_pkt pkt;
  1161. int ret = 0;
  1162. cnss_pr_dbg("Sending AOP Mbox msg: %s\n", mbox_msg);
  1163. pkt.size = CNSS_MBOX_MSG_MAX_LEN;
  1164. pkt.data = mbox_msg;
  1165. ret = mbox_send_message(plat_priv->mbox_chan, &pkt);
  1166. if (ret < 0)
  1167. cnss_pr_err("Failed to send AOP mbox msg: %s\n", mbox_msg);
  1168. else
  1169. ret = 0;
  1170. return ret;
  1171. }
  1172. /* cnss_pdc_reconfig: Send PDC init table as configured in DT for wlan device */
  1173. int cnss_aop_pdc_reconfig(struct cnss_plat_data *plat_priv)
  1174. {
  1175. u32 i;
  1176. int ret;
  1177. if (plat_priv->pdc_init_table_len <= 0 || !plat_priv->pdc_init_table)
  1178. return 0;
  1179. cnss_pr_dbg("Setting PDC defaults for device ID: %d\n",
  1180. plat_priv->device_id);
  1181. for (i = 0; i < plat_priv->pdc_init_table_len; i++) {
  1182. ret = cnss_aop_send_msg(plat_priv,
  1183. (char *)plat_priv->pdc_init_table[i]);
  1184. if (ret < 0)
  1185. break;
  1186. }
  1187. return ret;
  1188. }
  1189. /* cnss_aop_pdc_name_str: Get PDC name corresponding to VReg from DT Mapiping */
  1190. static const char *cnss_aop_pdc_name_str(struct cnss_plat_data *plat_priv,
  1191. const char *vreg_name)
  1192. {
  1193. u32 i;
  1194. static const char * const aop_pdc_ss_str[] = {"rf", "bb"};
  1195. const char *pdc = aop_pdc_ss_str[0], *vreg_map_name;
  1196. if (plat_priv->vreg_pdc_map_len <= 0 || !plat_priv->vreg_pdc_map)
  1197. goto end;
  1198. for (i = 0; i < plat_priv->vreg_pdc_map_len; i++) {
  1199. vreg_map_name = plat_priv->vreg_pdc_map[i];
  1200. if (strnstr(vreg_map_name, vreg_name, strlen(vreg_map_name))) {
  1201. pdc = plat_priv->vreg_pdc_map[i + 1];
  1202. break;
  1203. }
  1204. }
  1205. end:
  1206. cnss_pr_dbg("%s mapped to %s\n", vreg_name, pdc);
  1207. return pdc;
  1208. }
  1209. static int cnss_aop_set_vreg_param(struct cnss_plat_data *plat_priv,
  1210. const char *vreg_name,
  1211. enum cnss_aop_vreg_param param,
  1212. enum cnss_aop_tcs_seq_param seq_param,
  1213. int val)
  1214. {
  1215. char msg[CNSS_MBOX_MSG_MAX_LEN];
  1216. static const char * const aop_vreg_param_str[] = {
  1217. [CNSS_VREG_VOLTAGE] = "v", [CNSS_VREG_MODE] = "m",
  1218. [CNSS_VREG_ENABLE] = "e",};
  1219. static const char * const aop_tcs_seq_str[] = {
  1220. [CNSS_TCS_UP_SEQ] = "upval", [CNSS_TCS_DOWN_SEQ] = "dwnval",
  1221. [CNSS_TCS_ENABLE_SEQ] = "enable",};
  1222. if (param >= CNSS_VREG_PARAM_MAX || seq_param >= CNSS_TCS_SEQ_MAX ||
  1223. !vreg_name)
  1224. return -EINVAL;
  1225. snprintf(msg, CNSS_MBOX_MSG_MAX_LEN,
  1226. "{class: wlan_pdc, ss: %s, res: %s.%s, %s: %d}",
  1227. cnss_aop_pdc_name_str(plat_priv, vreg_name),
  1228. vreg_name, aop_vreg_param_str[param],
  1229. aop_tcs_seq_str[seq_param], val);
  1230. return cnss_aop_send_msg(plat_priv, msg);
  1231. }
  1232. int cnss_aop_ol_cpr_cfg_setup(struct cnss_plat_data *plat_priv,
  1233. struct wlfw_pmu_cfg_v01 *fw_pmu_cfg)
  1234. {
  1235. const char *pmu_pin, *vreg;
  1236. struct wlfw_pmu_param_v01 *fw_pmu_param;
  1237. u32 fw_pmu_param_len, i, j, plat_vreg_param_len = 0;
  1238. int ret = 0;
  1239. struct platform_vreg_param {
  1240. char vreg[MAX_PROP_SIZE];
  1241. u32 wake_volt;
  1242. u32 sleep_volt;
  1243. } plat_vreg_param[QMI_WLFW_PMU_PARAMS_MAX_V01] = {0};
  1244. static bool config_done;
  1245. if (config_done)
  1246. return 0;
  1247. if (plat_priv->pmu_vreg_map_len <= 0 || !plat_priv->mbox_chan ||
  1248. !plat_priv->pmu_vreg_map) {
  1249. cnss_pr_dbg("Mbox channel / PMU VReg Map not configured\n");
  1250. goto end;
  1251. }
  1252. if (!fw_pmu_cfg)
  1253. return -EINVAL;
  1254. fw_pmu_param = fw_pmu_cfg->pmu_param;
  1255. fw_pmu_param_len = fw_pmu_cfg->pmu_param_len;
  1256. /* Get PMU Pin name to Platfom Vreg Mapping */
  1257. for (i = 0; i < fw_pmu_param_len; i++) {
  1258. cnss_pr_dbg("FW_PMU Data: %s %d %d %d %d\n",
  1259. fw_pmu_param[i].pin_name,
  1260. fw_pmu_param[i].wake_volt_valid,
  1261. fw_pmu_param[i].wake_volt,
  1262. fw_pmu_param[i].sleep_volt_valid,
  1263. fw_pmu_param[i].sleep_volt);
  1264. if (!fw_pmu_param[i].wake_volt_valid &&
  1265. !fw_pmu_param[i].sleep_volt_valid)
  1266. continue;
  1267. vreg = NULL;
  1268. for (j = 0; j < plat_priv->pmu_vreg_map_len; j += 2) {
  1269. pmu_pin = plat_priv->pmu_vreg_map[j];
  1270. if (strnstr(pmu_pin, fw_pmu_param[i].pin_name,
  1271. strlen(pmu_pin))) {
  1272. vreg = plat_priv->pmu_vreg_map[j + 1];
  1273. break;
  1274. }
  1275. }
  1276. if (!vreg) {
  1277. cnss_pr_err("No VREG mapping for %s\n",
  1278. fw_pmu_param[i].pin_name);
  1279. continue;
  1280. } else {
  1281. cnss_pr_dbg("%s mapped to %s\n",
  1282. fw_pmu_param[i].pin_name, vreg);
  1283. }
  1284. for (j = 0; j < QMI_WLFW_PMU_PARAMS_MAX_V01; j++) {
  1285. u32 wake_volt = 0, sleep_volt = 0;
  1286. if (plat_vreg_param[j].vreg[0] == '\0')
  1287. strlcpy(plat_vreg_param[j].vreg, vreg,
  1288. sizeof(plat_vreg_param[j].vreg));
  1289. else if (!strnstr(plat_vreg_param[j].vreg, vreg,
  1290. strlen(plat_vreg_param[j].vreg)))
  1291. continue;
  1292. if (fw_pmu_param[i].wake_volt_valid)
  1293. wake_volt = roundup(fw_pmu_param[i].wake_volt,
  1294. CNSS_PMIC_VOLTAGE_STEP) -
  1295. CNSS_PMIC_AUTO_HEADROOM +
  1296. CNSS_IR_DROP_WAKE;
  1297. if (fw_pmu_param[i].sleep_volt_valid)
  1298. sleep_volt = roundup(fw_pmu_param[i].sleep_volt,
  1299. CNSS_PMIC_VOLTAGE_STEP) -
  1300. CNSS_PMIC_AUTO_HEADROOM +
  1301. CNSS_IR_DROP_SLEEP;
  1302. plat_vreg_param[j].wake_volt =
  1303. (wake_volt > plat_vreg_param[j].wake_volt ?
  1304. wake_volt : plat_vreg_param[j].wake_volt);
  1305. plat_vreg_param[j].sleep_volt =
  1306. (sleep_volt > plat_vreg_param[j].sleep_volt ?
  1307. sleep_volt : plat_vreg_param[j].sleep_volt);
  1308. plat_vreg_param_len = (plat_vreg_param_len > j ?
  1309. plat_vreg_param_len : j);
  1310. cnss_pr_dbg("Plat VReg Data: %s %d %d\n",
  1311. plat_vreg_param[j].vreg,
  1312. plat_vreg_param[j].wake_volt,
  1313. plat_vreg_param[j].sleep_volt);
  1314. break;
  1315. }
  1316. }
  1317. for (i = 0; i <= plat_vreg_param_len; i++) {
  1318. if (plat_vreg_param[i].wake_volt > 0) {
  1319. ret =
  1320. cnss_aop_set_vreg_param(plat_priv,
  1321. plat_vreg_param[i].vreg,
  1322. CNSS_VREG_VOLTAGE,
  1323. CNSS_TCS_UP_SEQ,
  1324. plat_vreg_param[i].wake_volt);
  1325. }
  1326. if (plat_vreg_param[i].sleep_volt > 0) {
  1327. ret =
  1328. cnss_aop_set_vreg_param(plat_priv,
  1329. plat_vreg_param[i].vreg,
  1330. CNSS_VREG_VOLTAGE,
  1331. CNSS_TCS_DOWN_SEQ,
  1332. plat_vreg_param[i].sleep_volt);
  1333. }
  1334. if (ret < 0)
  1335. break;
  1336. }
  1337. end:
  1338. config_done = true;
  1339. return ret;
  1340. }
  1341. #else
  1342. int cnss_aop_mbox_init(struct cnss_plat_data *plat_priv)
  1343. {
  1344. return 0;
  1345. }
  1346. int cnss_aop_send_msg(struct cnss_plat_data *plat_priv, char *msg)
  1347. {
  1348. return 0;
  1349. }
  1350. int cnss_aop_pdc_reconfig(struct cnss_plat_data *plat_priv)
  1351. {
  1352. return 0;
  1353. }
  1354. static int cnss_aop_set_vreg_param(struct cnss_plat_data *plat_priv,
  1355. const char *vreg_name,
  1356. enum cnss_aop_vreg_param param,
  1357. enum cnss_aop_tcs_seq_param seq_param,
  1358. int val)
  1359. {
  1360. return 0;
  1361. }
  1362. int cnss_aop_ol_cpr_cfg_setup(struct cnss_plat_data *plat_priv,
  1363. struct wlfw_pmu_cfg_v01 *fw_pmu_cfg)
  1364. {
  1365. return 0;
  1366. }
  1367. #endif
  1368. void cnss_power_misc_params_init(struct cnss_plat_data *plat_priv)
  1369. {
  1370. struct device *dev = &plat_priv->plat_dev->dev;
  1371. int ret;
  1372. /* common DT Entries */
  1373. plat_priv->pdc_init_table_len =
  1374. of_property_count_strings(dev->of_node,
  1375. "qcom,pdc_init_table");
  1376. if (plat_priv->pdc_init_table_len > 0) {
  1377. plat_priv->pdc_init_table =
  1378. kcalloc(plat_priv->pdc_init_table_len,
  1379. sizeof(char *), GFP_KERNEL);
  1380. ret =
  1381. of_property_read_string_array(dev->of_node,
  1382. "qcom,pdc_init_table",
  1383. plat_priv->pdc_init_table,
  1384. plat_priv->pdc_init_table_len);
  1385. if (ret < 0)
  1386. cnss_pr_err("Failed to get PDC Init Table\n");
  1387. } else {
  1388. cnss_pr_dbg("PDC Init Table not configured\n");
  1389. }
  1390. plat_priv->vreg_pdc_map_len =
  1391. of_property_count_strings(dev->of_node,
  1392. "qcom,vreg_pdc_map");
  1393. if (plat_priv->vreg_pdc_map_len > 0) {
  1394. plat_priv->vreg_pdc_map =
  1395. kcalloc(plat_priv->vreg_pdc_map_len,
  1396. sizeof(char *), GFP_KERNEL);
  1397. ret =
  1398. of_property_read_string_array(dev->of_node,
  1399. "qcom,vreg_pdc_map",
  1400. plat_priv->vreg_pdc_map,
  1401. plat_priv->vreg_pdc_map_len);
  1402. if (ret < 0)
  1403. cnss_pr_err("Failed to get VReg PDC Mapping\n");
  1404. } else {
  1405. cnss_pr_dbg("VReg PDC Mapping not configured\n");
  1406. }
  1407. plat_priv->pmu_vreg_map_len =
  1408. of_property_count_strings(dev->of_node,
  1409. "qcom,pmu_vreg_map");
  1410. if (plat_priv->pmu_vreg_map_len > 0) {
  1411. plat_priv->pmu_vreg_map = kcalloc(plat_priv->pmu_vreg_map_len,
  1412. sizeof(char *), GFP_KERNEL);
  1413. ret =
  1414. of_property_read_string_array(dev->of_node, "qcom,pmu_vreg_map",
  1415. plat_priv->pmu_vreg_map,
  1416. plat_priv->pmu_vreg_map_len);
  1417. if (ret < 0)
  1418. cnss_pr_err("Fail to get PMU VReg Mapping\n");
  1419. } else {
  1420. cnss_pr_dbg("PMU VReg Mapping not configured\n");
  1421. }
  1422. /* Device DT Specific */
  1423. if (plat_priv->device_id == QCA6390_DEVICE_ID ||
  1424. plat_priv->device_id == QCA6490_DEVICE_ID) {
  1425. ret = of_property_read_string(dev->of_node,
  1426. "qcom,vreg_ol_cpr",
  1427. &plat_priv->vreg_ol_cpr);
  1428. if (ret)
  1429. cnss_pr_dbg("VReg for QCA6490 OL CPR not configured\n");
  1430. ret = of_property_read_string(dev->of_node,
  1431. "qcom,vreg_ipa",
  1432. &plat_priv->vreg_ipa);
  1433. if (ret)
  1434. cnss_pr_dbg("VReg for QCA6490 Int Power Amp not configured\n");
  1435. }
  1436. }
  1437. int cnss_update_cpr_info(struct cnss_plat_data *plat_priv)
  1438. {
  1439. struct cnss_cpr_info *cpr_info = &plat_priv->cpr_info;
  1440. u32 pmic_addr, voltage = 0, voltage_tmp, offset;
  1441. void __iomem *tcs_cmd_addr, *tcs_cmd_data_addr;
  1442. int i, j;
  1443. if (cpr_info->voltage == 0) {
  1444. cnss_pr_err("OL CPR Voltage %dm is not valid\n",
  1445. cpr_info->voltage);
  1446. return -EINVAL;
  1447. }
  1448. if (plat_priv->device_id != QCA6490_DEVICE_ID)
  1449. return -EINVAL;
  1450. if (!plat_priv->vreg_ol_cpr || !plat_priv->mbox_chan) {
  1451. cnss_pr_dbg("Mbox channel / OL CPR Vreg not configured\n");
  1452. } else {
  1453. return cnss_aop_set_vreg_param(plat_priv,
  1454. plat_priv->vreg_ol_cpr,
  1455. CNSS_VREG_VOLTAGE,
  1456. CNSS_TCS_DOWN_SEQ,
  1457. cpr_info->voltage);
  1458. }
  1459. if (plat_priv->tcs_info.cmd_base_addr == 0) {
  1460. cnss_pr_dbg("TCS CMD not configured for OL CPR update\n");
  1461. return 0;
  1462. }
  1463. if (cpr_info->cpr_pmic_addr == 0) {
  1464. cnss_pr_err("PMIC address 0x%x is not valid\n",
  1465. cpr_info->cpr_pmic_addr);
  1466. return -EINVAL;
  1467. }
  1468. if (cpr_info->tcs_cmd_data_addr_io)
  1469. goto update_cpr;
  1470. for (i = 0; i < MAX_TCS_NUM; i++) {
  1471. for (j = 0; j < MAX_TCS_CMD_NUM; j++) {
  1472. offset = i * TCS_OFFSET + j * TCS_CMD_OFFSET;
  1473. tcs_cmd_addr = plat_priv->tcs_info.cmd_base_addr_io +
  1474. offset;
  1475. pmic_addr = readl_relaxed(tcs_cmd_addr);
  1476. if (pmic_addr == cpr_info->cpr_pmic_addr) {
  1477. tcs_cmd_data_addr = tcs_cmd_addr +
  1478. TCS_CMD_DATA_ADDR_OFFSET;
  1479. voltage_tmp = readl_relaxed(tcs_cmd_data_addr);
  1480. cnss_pr_dbg("Got voltage %dmV from i: %d, j: %d\n",
  1481. voltage_tmp, i, j);
  1482. if (voltage_tmp > voltage) {
  1483. voltage = voltage_tmp;
  1484. cpr_info->tcs_cmd_data_addr =
  1485. plat_priv->tcs_info.cmd_base_addr +
  1486. offset + TCS_CMD_DATA_ADDR_OFFSET;
  1487. cpr_info->tcs_cmd_data_addr_io =
  1488. tcs_cmd_data_addr;
  1489. }
  1490. }
  1491. }
  1492. }
  1493. if (!cpr_info->tcs_cmd_data_addr_io) {
  1494. cnss_pr_err("Failed to find proper TCS CMD data address\n");
  1495. return -EINVAL;
  1496. }
  1497. update_cpr:
  1498. cpr_info->voltage = cpr_info->voltage > BT_CXMX_VOLTAGE_MV ?
  1499. cpr_info->voltage : BT_CXMX_VOLTAGE_MV;
  1500. cnss_pr_dbg("Update TCS CMD data address %pa with voltage %dmV\n",
  1501. &cpr_info->tcs_cmd_data_addr, cpr_info->voltage);
  1502. writel_relaxed(cpr_info->voltage, cpr_info->tcs_cmd_data_addr_io);
  1503. return 0;
  1504. }
  1505. int cnss_enable_int_pow_amp_vreg(struct cnss_plat_data *plat_priv)
  1506. {
  1507. struct platform_device *plat_dev = plat_priv->plat_dev;
  1508. u32 offset, addr_val, data_val;
  1509. void __iomem *tcs_cmd;
  1510. int ret;
  1511. static bool config_done;
  1512. if (plat_priv->device_id != QCA6490_DEVICE_ID)
  1513. return -EINVAL;
  1514. if (config_done) {
  1515. cnss_pr_dbg("IPA Vreg already configured\n");
  1516. return 0;
  1517. }
  1518. if (!plat_priv->vreg_ipa || !plat_priv->mbox_chan) {
  1519. cnss_pr_dbg("Mbox channel / IPA Vreg not configured\n");
  1520. } else {
  1521. ret = cnss_aop_set_vreg_param(plat_priv,
  1522. plat_priv->vreg_ipa,
  1523. CNSS_VREG_ENABLE,
  1524. CNSS_TCS_UP_SEQ, 1);
  1525. if (ret == 0)
  1526. config_done = true;
  1527. return ret;
  1528. }
  1529. if (!plat_priv->tcs_info.cmd_base_addr_io) {
  1530. cnss_pr_err("TCS CMD not configured for IPA Vreg enable\n");
  1531. return -EINVAL;
  1532. }
  1533. ret = of_property_read_u32(plat_dev->dev.of_node,
  1534. "qcom,tcs_offset_int_pow_amp_vreg",
  1535. &offset);
  1536. if (ret) {
  1537. cnss_pr_dbg("Internal Power Amp Vreg not configured\n");
  1538. return -EINVAL;
  1539. }
  1540. tcs_cmd = plat_priv->tcs_info.cmd_base_addr_io + offset;
  1541. addr_val = readl_relaxed(tcs_cmd);
  1542. tcs_cmd += TCS_CMD_DATA_ADDR_OFFSET;
  1543. /* 1 = enable Vreg */
  1544. writel_relaxed(1, tcs_cmd);
  1545. data_val = readl_relaxed(tcs_cmd);
  1546. cnss_pr_dbg("Setup S3E TCS Addr: %x Data: %d\n", addr_val, data_val);
  1547. config_done = true;
  1548. return 0;
  1549. }
  1550. int cnss_dev_specific_power_on(struct cnss_plat_data *plat_priv)
  1551. {
  1552. int ret;
  1553. if (plat_priv->dt_type != CNSS_DTT_MULTIEXCHG)
  1554. return 0;
  1555. ret = cnss_get_vreg_type(plat_priv, CNSS_VREG_PRIM);
  1556. if (ret)
  1557. return ret;
  1558. plat_priv->powered_on = false;
  1559. return cnss_power_on_device(plat_priv, false);
  1560. }