power.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021 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/regulator/consumer.h>
  15. #if IS_ENABLED(CONFIG_QCOM_COMMAND_DB)
  16. #include <soc/qcom/cmd-db.h>
  17. #endif
  18. #include "main.h"
  19. #include "debug.h"
  20. #include "bus.h"
  21. #if IS_ENABLED(CONFIG_ARCH_QCOM)
  22. static struct cnss_vreg_cfg cnss_vreg_list[] = {
  23. {"vdd-wlan-core", 1300000, 1300000, 0, 0, 0},
  24. {"vdd-wlan-io", 1800000, 1800000, 0, 0, 0},
  25. {"vdd-wlan-xtal-aon", 0, 0, 0, 0, 0},
  26. {"vdd-wlan-xtal", 1800000, 1800000, 0, 2, 0},
  27. {"vdd-wlan", 0, 0, 0, 0, 0},
  28. {"vdd-wlan-ctrl1", 0, 0, 0, 0, 0},
  29. {"vdd-wlan-ctrl2", 0, 0, 0, 0, 0},
  30. {"vdd-wlan-sp2t", 2700000, 2700000, 0, 0, 0},
  31. {"wlan-ant-switch", 1800000, 1800000, 0, 0, 0},
  32. {"wlan-soc-swreg", 1200000, 1200000, 0, 0, 0},
  33. {"vdd-wlan-aon", 950000, 950000, 0, 0, 0},
  34. {"vdd-wlan-dig", 950000, 952000, 0, 0, 0},
  35. {"vdd-wlan-rfa1", 1900000, 1900000, 0, 0, 0},
  36. {"vdd-wlan-rfa2", 1350000, 1350000, 0, 0, 0},
  37. {"alt-sleep-clk", 0, 0, 0, 0, 0},
  38. {"vdd-wlan-en", 0, 0, 0, 10, 0},
  39. };
  40. static struct cnss_clk_cfg cnss_clk_list[] = {
  41. {"rf_clk", 0, 0},
  42. };
  43. #else
  44. static struct cnss_vreg_cfg cnss_vreg_list[] = {
  45. };
  46. static struct cnss_clk_cfg cnss_clk_list[] = {
  47. };
  48. #endif
  49. #define CNSS_VREG_INFO_SIZE ARRAY_SIZE(cnss_vreg_list)
  50. #define CNSS_CLK_INFO_SIZE ARRAY_SIZE(cnss_clk_list)
  51. #define MAX_PROP_SIZE 32
  52. #define BOOTSTRAP_GPIO "qcom,enable-bootstrap-gpio"
  53. #define BOOTSTRAP_ACTIVE "bootstrap_active"
  54. #define WLAN_EN_GPIO "wlan-en-gpio"
  55. #define BT_EN_GPIO "qcom,bt-en-gpio"
  56. #define XO_CLK_GPIO "qcom,xo-clk-gpio"
  57. #define WLAN_EN_ACTIVE "wlan_en_active"
  58. #define WLAN_EN_SLEEP "wlan_en_sleep"
  59. #define BOOTSTRAP_DELAY 1000
  60. #define WLAN_ENABLE_DELAY 1000
  61. #define TCS_CMD_DATA_ADDR_OFFSET 0x4
  62. #define TCS_OFFSET 0xC8
  63. #define TCS_CMD_OFFSET 0x10
  64. #define MAX_TCS_NUM 8
  65. #define MAX_TCS_CMD_NUM 5
  66. #define BT_CXMX_VOLTAGE_MV 950
  67. #define CNSS_MBOX_MSG_MAX_LEN 64
  68. #define CNSS_MBOX_TIMEOUT_MS 1000
  69. /**
  70. * enum cnss_vreg_param: Voltage regulator TCS param
  71. * @CNSS_VREG_VOLTAGE: Provides voltage level to be configured in TCS
  72. * @CNSS_VREG_MODE: Regulator mode
  73. * @CNSS_VREG_TCS_ENABLE: Set Voltage regulator enable config in TCS
  74. */
  75. enum cnss_vreg_param {
  76. CNSS_VREG_VOLTAGE,
  77. CNSS_VREG_MODE,
  78. CNSS_VREG_ENABLE,
  79. };
  80. /**
  81. * enum cnss_tcs_seq: TCS sequence ID for trigger
  82. * CNSS_TCS_UP_SEQ: TCS Sequence based on up trigger / Wake TCS
  83. * CNSS_TCS_DOWN_SEQ: TCS Sequence based on down trigger / Sleep TCS
  84. * CNSS_TCS_ALL_SEQ: Update for both up and down triggers
  85. */
  86. enum cnss_tcs_seq {
  87. CNSS_TCS_UP_SEQ,
  88. CNSS_TCS_DOWN_SEQ,
  89. CNSS_TCS_ALL_SEQ,
  90. };
  91. static int cnss_get_vreg_single(struct cnss_plat_data *plat_priv,
  92. struct cnss_vreg_info *vreg)
  93. {
  94. int ret = 0;
  95. struct device *dev;
  96. struct regulator *reg;
  97. const __be32 *prop;
  98. char prop_name[MAX_PROP_SIZE] = {0};
  99. int len;
  100. dev = &plat_priv->plat_dev->dev;
  101. reg = devm_regulator_get_optional(dev, vreg->cfg.name);
  102. if (IS_ERR(reg)) {
  103. ret = PTR_ERR(reg);
  104. if (ret == -ENODEV)
  105. return ret;
  106. else if (ret == -EPROBE_DEFER)
  107. cnss_pr_info("EPROBE_DEFER for regulator: %s\n",
  108. vreg->cfg.name);
  109. else
  110. cnss_pr_err("Failed to get regulator %s, err = %d\n",
  111. vreg->cfg.name, ret);
  112. return ret;
  113. }
  114. vreg->reg = reg;
  115. snprintf(prop_name, MAX_PROP_SIZE, "qcom,%s-config",
  116. vreg->cfg.name);
  117. prop = of_get_property(dev->of_node, prop_name, &len);
  118. if (!prop || len != (5 * sizeof(__be32))) {
  119. cnss_pr_dbg("Property %s %s, use default\n", prop_name,
  120. prop ? "invalid format" : "doesn't exist");
  121. } else {
  122. vreg->cfg.min_uv = be32_to_cpup(&prop[0]);
  123. vreg->cfg.max_uv = be32_to_cpup(&prop[1]);
  124. vreg->cfg.load_ua = be32_to_cpup(&prop[2]);
  125. vreg->cfg.delay_us = be32_to_cpup(&prop[3]);
  126. vreg->cfg.need_unvote = be32_to_cpup(&prop[4]);
  127. }
  128. cnss_pr_dbg("Got regulator: %s, min_uv: %u, max_uv: %u, load_ua: %u, delay_us: %u, need_unvote: %u\n",
  129. vreg->cfg.name, vreg->cfg.min_uv,
  130. vreg->cfg.max_uv, vreg->cfg.load_ua,
  131. vreg->cfg.delay_us, vreg->cfg.need_unvote);
  132. return 0;
  133. }
  134. static void cnss_put_vreg_single(struct cnss_plat_data *plat_priv,
  135. struct cnss_vreg_info *vreg)
  136. {
  137. struct device *dev = &plat_priv->plat_dev->dev;
  138. cnss_pr_dbg("Put regulator: %s\n", vreg->cfg.name);
  139. devm_regulator_put(vreg->reg);
  140. devm_kfree(dev, vreg);
  141. }
  142. static int cnss_vreg_on_single(struct cnss_vreg_info *vreg)
  143. {
  144. int ret = 0;
  145. if (vreg->enabled) {
  146. cnss_pr_dbg("Regulator %s is already enabled\n",
  147. vreg->cfg.name);
  148. return 0;
  149. }
  150. cnss_pr_dbg("Regulator %s is being enabled\n", vreg->cfg.name);
  151. if (vreg->cfg.min_uv != 0 && vreg->cfg.max_uv != 0) {
  152. ret = regulator_set_voltage(vreg->reg,
  153. vreg->cfg.min_uv,
  154. vreg->cfg.max_uv);
  155. if (ret) {
  156. cnss_pr_err("Failed to set voltage for regulator %s, min_uv: %u, max_uv: %u, err = %d\n",
  157. vreg->cfg.name, vreg->cfg.min_uv,
  158. vreg->cfg.max_uv, ret);
  159. goto out;
  160. }
  161. }
  162. if (vreg->cfg.load_ua) {
  163. ret = regulator_set_load(vreg->reg,
  164. vreg->cfg.load_ua);
  165. if (ret < 0) {
  166. cnss_pr_err("Failed to set load for regulator %s, load: %u, err = %d\n",
  167. vreg->cfg.name, vreg->cfg.load_ua,
  168. ret);
  169. goto out;
  170. }
  171. }
  172. if (vreg->cfg.delay_us)
  173. udelay(vreg->cfg.delay_us);
  174. ret = regulator_enable(vreg->reg);
  175. if (ret) {
  176. cnss_pr_err("Failed to enable regulator %s, err = %d\n",
  177. vreg->cfg.name, ret);
  178. goto out;
  179. }
  180. vreg->enabled = true;
  181. out:
  182. return ret;
  183. }
  184. static int cnss_vreg_unvote_single(struct cnss_vreg_info *vreg)
  185. {
  186. int ret = 0;
  187. if (!vreg->enabled) {
  188. cnss_pr_dbg("Regulator %s is already disabled\n",
  189. vreg->cfg.name);
  190. return 0;
  191. }
  192. cnss_pr_dbg("Removing vote for Regulator %s\n", vreg->cfg.name);
  193. if (vreg->cfg.load_ua) {
  194. ret = regulator_set_load(vreg->reg, 0);
  195. if (ret < 0)
  196. cnss_pr_err("Failed to set load for regulator %s, err = %d\n",
  197. vreg->cfg.name, ret);
  198. }
  199. if (vreg->cfg.min_uv != 0 && vreg->cfg.max_uv != 0) {
  200. ret = regulator_set_voltage(vreg->reg, 0,
  201. vreg->cfg.max_uv);
  202. if (ret)
  203. cnss_pr_err("Failed to set voltage for regulator %s, err = %d\n",
  204. vreg->cfg.name, ret);
  205. }
  206. return ret;
  207. }
  208. static int cnss_vreg_off_single(struct cnss_vreg_info *vreg)
  209. {
  210. int ret = 0;
  211. if (!vreg->enabled) {
  212. cnss_pr_dbg("Regulator %s is already disabled\n",
  213. vreg->cfg.name);
  214. return 0;
  215. }
  216. cnss_pr_dbg("Regulator %s is being disabled\n",
  217. vreg->cfg.name);
  218. ret = regulator_disable(vreg->reg);
  219. if (ret)
  220. cnss_pr_err("Failed to disable regulator %s, err = %d\n",
  221. vreg->cfg.name, ret);
  222. if (vreg->cfg.load_ua) {
  223. ret = regulator_set_load(vreg->reg, 0);
  224. if (ret < 0)
  225. cnss_pr_err("Failed to set load for regulator %s, err = %d\n",
  226. vreg->cfg.name, ret);
  227. }
  228. if (vreg->cfg.min_uv != 0 && vreg->cfg.max_uv != 0) {
  229. ret = regulator_set_voltage(vreg->reg, 0,
  230. vreg->cfg.max_uv);
  231. if (ret)
  232. cnss_pr_err("Failed to set voltage for regulator %s, err = %d\n",
  233. vreg->cfg.name, ret);
  234. }
  235. vreg->enabled = false;
  236. return ret;
  237. }
  238. static struct cnss_vreg_cfg *get_vreg_list(u32 *vreg_list_size,
  239. enum cnss_vreg_type type)
  240. {
  241. switch (type) {
  242. case CNSS_VREG_PRIM:
  243. *vreg_list_size = CNSS_VREG_INFO_SIZE;
  244. return cnss_vreg_list;
  245. default:
  246. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  247. *vreg_list_size = 0;
  248. return NULL;
  249. }
  250. }
  251. static int cnss_get_vreg(struct cnss_plat_data *plat_priv,
  252. struct list_head *vreg_list,
  253. struct cnss_vreg_cfg *vreg_cfg,
  254. u32 vreg_list_size)
  255. {
  256. int ret = 0;
  257. int i;
  258. struct cnss_vreg_info *vreg;
  259. struct device *dev = &plat_priv->plat_dev->dev;
  260. if (!list_empty(vreg_list)) {
  261. cnss_pr_dbg("Vregs have already been updated\n");
  262. return 0;
  263. }
  264. for (i = 0; i < vreg_list_size; i++) {
  265. vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
  266. if (!vreg)
  267. return -ENOMEM;
  268. memcpy(&vreg->cfg, &vreg_cfg[i], sizeof(vreg->cfg));
  269. ret = cnss_get_vreg_single(plat_priv, vreg);
  270. if (ret != 0) {
  271. if (ret == -ENODEV) {
  272. devm_kfree(dev, vreg);
  273. continue;
  274. } else {
  275. devm_kfree(dev, vreg);
  276. return ret;
  277. }
  278. }
  279. list_add_tail(&vreg->list, vreg_list);
  280. }
  281. return 0;
  282. }
  283. static void cnss_put_vreg(struct cnss_plat_data *plat_priv,
  284. struct list_head *vreg_list)
  285. {
  286. struct cnss_vreg_info *vreg;
  287. while (!list_empty(vreg_list)) {
  288. vreg = list_first_entry(vreg_list,
  289. struct cnss_vreg_info, list);
  290. list_del(&vreg->list);
  291. if (IS_ERR_OR_NULL(vreg->reg))
  292. continue;
  293. cnss_put_vreg_single(plat_priv, vreg);
  294. }
  295. }
  296. static int cnss_vreg_on(struct cnss_plat_data *plat_priv,
  297. struct list_head *vreg_list)
  298. {
  299. struct cnss_vreg_info *vreg;
  300. int ret = 0;
  301. list_for_each_entry(vreg, vreg_list, list) {
  302. if (IS_ERR_OR_NULL(vreg->reg))
  303. continue;
  304. ret = cnss_vreg_on_single(vreg);
  305. if (ret)
  306. break;
  307. }
  308. if (!ret)
  309. return 0;
  310. list_for_each_entry_continue_reverse(vreg, vreg_list, list) {
  311. if (IS_ERR_OR_NULL(vreg->reg) || !vreg->enabled)
  312. continue;
  313. cnss_vreg_off_single(vreg);
  314. }
  315. return ret;
  316. }
  317. static int cnss_vreg_off(struct cnss_plat_data *plat_priv,
  318. struct list_head *vreg_list)
  319. {
  320. struct cnss_vreg_info *vreg;
  321. list_for_each_entry_reverse(vreg, vreg_list, list) {
  322. if (IS_ERR_OR_NULL(vreg->reg))
  323. continue;
  324. cnss_vreg_off_single(vreg);
  325. }
  326. return 0;
  327. }
  328. static int cnss_vreg_unvote(struct cnss_plat_data *plat_priv,
  329. struct list_head *vreg_list)
  330. {
  331. struct cnss_vreg_info *vreg;
  332. list_for_each_entry_reverse(vreg, vreg_list, list) {
  333. if (IS_ERR_OR_NULL(vreg->reg))
  334. continue;
  335. if (vreg->cfg.need_unvote)
  336. cnss_vreg_unvote_single(vreg);
  337. }
  338. return 0;
  339. }
  340. int cnss_get_vreg_type(struct cnss_plat_data *plat_priv,
  341. enum cnss_vreg_type type)
  342. {
  343. struct cnss_vreg_cfg *vreg_cfg;
  344. u32 vreg_list_size = 0;
  345. int ret = 0;
  346. vreg_cfg = get_vreg_list(&vreg_list_size, type);
  347. if (!vreg_cfg)
  348. return -EINVAL;
  349. switch (type) {
  350. case CNSS_VREG_PRIM:
  351. ret = cnss_get_vreg(plat_priv, &plat_priv->vreg_list,
  352. vreg_cfg, vreg_list_size);
  353. break;
  354. default:
  355. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  356. return -EINVAL;
  357. }
  358. return ret;
  359. }
  360. void cnss_put_vreg_type(struct cnss_plat_data *plat_priv,
  361. enum cnss_vreg_type type)
  362. {
  363. switch (type) {
  364. case CNSS_VREG_PRIM:
  365. cnss_put_vreg(plat_priv, &plat_priv->vreg_list);
  366. break;
  367. default:
  368. return;
  369. }
  370. }
  371. int cnss_vreg_on_type(struct cnss_plat_data *plat_priv,
  372. enum cnss_vreg_type type)
  373. {
  374. int ret = 0;
  375. switch (type) {
  376. case CNSS_VREG_PRIM:
  377. ret = cnss_vreg_on(plat_priv, &plat_priv->vreg_list);
  378. break;
  379. default:
  380. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  381. return -EINVAL;
  382. }
  383. return ret;
  384. }
  385. int cnss_vreg_off_type(struct cnss_plat_data *plat_priv,
  386. enum cnss_vreg_type type)
  387. {
  388. int ret = 0;
  389. switch (type) {
  390. case CNSS_VREG_PRIM:
  391. ret = cnss_vreg_off(plat_priv, &plat_priv->vreg_list);
  392. break;
  393. default:
  394. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  395. return -EINVAL;
  396. }
  397. return ret;
  398. }
  399. int cnss_vreg_unvote_type(struct cnss_plat_data *plat_priv,
  400. enum cnss_vreg_type type)
  401. {
  402. int ret = 0;
  403. switch (type) {
  404. case CNSS_VREG_PRIM:
  405. ret = cnss_vreg_unvote(plat_priv, &plat_priv->vreg_list);
  406. break;
  407. default:
  408. cnss_pr_err("Unsupported vreg type 0x%x\n", type);
  409. return -EINVAL;
  410. }
  411. return ret;
  412. }
  413. static int cnss_get_clk_single(struct cnss_plat_data *plat_priv,
  414. struct cnss_clk_info *clk_info)
  415. {
  416. struct device *dev = &plat_priv->plat_dev->dev;
  417. struct clk *clk;
  418. int ret;
  419. clk = devm_clk_get(dev, clk_info->cfg.name);
  420. if (IS_ERR(clk)) {
  421. ret = PTR_ERR(clk);
  422. if (clk_info->cfg.required)
  423. cnss_pr_err("Failed to get clock %s, err = %d\n",
  424. clk_info->cfg.name, ret);
  425. else
  426. cnss_pr_dbg("Failed to get optional clock %s, err = %d\n",
  427. clk_info->cfg.name, ret);
  428. return ret;
  429. }
  430. clk_info->clk = clk;
  431. cnss_pr_dbg("Got clock: %s, freq: %u\n",
  432. clk_info->cfg.name, clk_info->cfg.freq);
  433. return 0;
  434. }
  435. static void cnss_put_clk_single(struct cnss_plat_data *plat_priv,
  436. struct cnss_clk_info *clk_info)
  437. {
  438. struct device *dev = &plat_priv->plat_dev->dev;
  439. cnss_pr_dbg("Put clock: %s\n", clk_info->cfg.name);
  440. devm_clk_put(dev, clk_info->clk);
  441. }
  442. static int cnss_clk_on_single(struct cnss_clk_info *clk_info)
  443. {
  444. int ret;
  445. if (clk_info->enabled) {
  446. cnss_pr_dbg("Clock %s is already enabled\n",
  447. clk_info->cfg.name);
  448. return 0;
  449. }
  450. cnss_pr_dbg("Clock %s is being enabled\n", clk_info->cfg.name);
  451. if (clk_info->cfg.freq) {
  452. ret = clk_set_rate(clk_info->clk, clk_info->cfg.freq);
  453. if (ret) {
  454. cnss_pr_err("Failed to set frequency %u for clock %s, err = %d\n",
  455. clk_info->cfg.freq, clk_info->cfg.name,
  456. ret);
  457. return ret;
  458. }
  459. }
  460. ret = clk_prepare_enable(clk_info->clk);
  461. if (ret) {
  462. cnss_pr_err("Failed to enable clock %s, err = %d\n",
  463. clk_info->cfg.name, ret);
  464. return ret;
  465. }
  466. clk_info->enabled = true;
  467. return 0;
  468. }
  469. static int cnss_clk_off_single(struct cnss_clk_info *clk_info)
  470. {
  471. if (!clk_info->enabled) {
  472. cnss_pr_dbg("Clock %s is already disabled\n",
  473. clk_info->cfg.name);
  474. return 0;
  475. }
  476. cnss_pr_dbg("Clock %s is being disabled\n", clk_info->cfg.name);
  477. clk_disable_unprepare(clk_info->clk);
  478. clk_info->enabled = false;
  479. return 0;
  480. }
  481. int cnss_get_clk(struct cnss_plat_data *plat_priv)
  482. {
  483. struct device *dev;
  484. struct list_head *clk_list;
  485. struct cnss_clk_info *clk_info;
  486. int ret, i;
  487. if (!plat_priv)
  488. return -ENODEV;
  489. dev = &plat_priv->plat_dev->dev;
  490. clk_list = &plat_priv->clk_list;
  491. if (!list_empty(clk_list)) {
  492. cnss_pr_dbg("Clocks have already been updated\n");
  493. return 0;
  494. }
  495. for (i = 0; i < CNSS_CLK_INFO_SIZE; i++) {
  496. clk_info = devm_kzalloc(dev, sizeof(*clk_info), GFP_KERNEL);
  497. if (!clk_info) {
  498. ret = -ENOMEM;
  499. goto cleanup;
  500. }
  501. memcpy(&clk_info->cfg, &cnss_clk_list[i],
  502. sizeof(clk_info->cfg));
  503. ret = cnss_get_clk_single(plat_priv, clk_info);
  504. if (ret != 0) {
  505. if (clk_info->cfg.required) {
  506. devm_kfree(dev, clk_info);
  507. goto cleanup;
  508. } else {
  509. devm_kfree(dev, clk_info);
  510. continue;
  511. }
  512. }
  513. list_add_tail(&clk_info->list, clk_list);
  514. }
  515. return 0;
  516. cleanup:
  517. while (!list_empty(clk_list)) {
  518. clk_info = list_first_entry(clk_list, struct cnss_clk_info,
  519. list);
  520. list_del(&clk_info->list);
  521. if (IS_ERR_OR_NULL(clk_info->clk))
  522. continue;
  523. cnss_put_clk_single(plat_priv, clk_info);
  524. devm_kfree(dev, clk_info);
  525. }
  526. return ret;
  527. }
  528. void cnss_put_clk(struct cnss_plat_data *plat_priv)
  529. {
  530. struct device *dev;
  531. struct list_head *clk_list;
  532. struct cnss_clk_info *clk_info;
  533. if (!plat_priv)
  534. return;
  535. dev = &plat_priv->plat_dev->dev;
  536. clk_list = &plat_priv->clk_list;
  537. while (!list_empty(clk_list)) {
  538. clk_info = list_first_entry(clk_list, struct cnss_clk_info,
  539. list);
  540. list_del(&clk_info->list);
  541. if (IS_ERR_OR_NULL(clk_info->clk))
  542. continue;
  543. cnss_put_clk_single(plat_priv, clk_info);
  544. devm_kfree(dev, clk_info);
  545. }
  546. }
  547. static int cnss_clk_on(struct cnss_plat_data *plat_priv,
  548. struct list_head *clk_list)
  549. {
  550. struct cnss_clk_info *clk_info;
  551. int ret = 0;
  552. list_for_each_entry(clk_info, clk_list, list) {
  553. if (IS_ERR_OR_NULL(clk_info->clk))
  554. continue;
  555. ret = cnss_clk_on_single(clk_info);
  556. if (ret)
  557. break;
  558. }
  559. if (!ret)
  560. return 0;
  561. list_for_each_entry_continue_reverse(clk_info, clk_list, list) {
  562. if (IS_ERR_OR_NULL(clk_info->clk))
  563. continue;
  564. cnss_clk_off_single(clk_info);
  565. }
  566. return ret;
  567. }
  568. static int cnss_clk_off(struct cnss_plat_data *plat_priv,
  569. struct list_head *clk_list)
  570. {
  571. struct cnss_clk_info *clk_info;
  572. list_for_each_entry_reverse(clk_info, clk_list, list) {
  573. if (IS_ERR_OR_NULL(clk_info->clk))
  574. continue;
  575. cnss_clk_off_single(clk_info);
  576. }
  577. return 0;
  578. }
  579. int cnss_get_pinctrl(struct cnss_plat_data *plat_priv)
  580. {
  581. int ret = 0;
  582. struct device *dev;
  583. struct cnss_pinctrl_info *pinctrl_info;
  584. dev = &plat_priv->plat_dev->dev;
  585. pinctrl_info = &plat_priv->pinctrl_info;
  586. pinctrl_info->pinctrl = devm_pinctrl_get(dev);
  587. if (IS_ERR_OR_NULL(pinctrl_info->pinctrl)) {
  588. ret = PTR_ERR(pinctrl_info->pinctrl);
  589. cnss_pr_err("Failed to get pinctrl, err = %d\n", ret);
  590. goto out;
  591. }
  592. if (of_find_property(dev->of_node, BOOTSTRAP_GPIO, NULL)) {
  593. pinctrl_info->bootstrap_active =
  594. pinctrl_lookup_state(pinctrl_info->pinctrl,
  595. BOOTSTRAP_ACTIVE);
  596. if (IS_ERR_OR_NULL(pinctrl_info->bootstrap_active)) {
  597. ret = PTR_ERR(pinctrl_info->bootstrap_active);
  598. cnss_pr_err("Failed to get bootstrap active state, err = %d\n",
  599. ret);
  600. goto out;
  601. }
  602. }
  603. if (of_find_property(dev->of_node, WLAN_EN_GPIO, NULL)) {
  604. pinctrl_info->wlan_en_active =
  605. pinctrl_lookup_state(pinctrl_info->pinctrl,
  606. WLAN_EN_ACTIVE);
  607. if (IS_ERR_OR_NULL(pinctrl_info->wlan_en_active)) {
  608. ret = PTR_ERR(pinctrl_info->wlan_en_active);
  609. cnss_pr_err("Failed to get wlan_en active state, err = %d\n",
  610. ret);
  611. goto out;
  612. }
  613. pinctrl_info->wlan_en_sleep =
  614. pinctrl_lookup_state(pinctrl_info->pinctrl,
  615. WLAN_EN_SLEEP);
  616. if (IS_ERR_OR_NULL(pinctrl_info->wlan_en_sleep)) {
  617. ret = PTR_ERR(pinctrl_info->wlan_en_sleep);
  618. cnss_pr_err("Failed to get wlan_en sleep state, err = %d\n",
  619. ret);
  620. goto out;
  621. }
  622. }
  623. /* Added for QCA6490 PMU delayed WLAN_EN_GPIO */
  624. if (of_find_property(dev->of_node, BT_EN_GPIO, NULL)) {
  625. pinctrl_info->bt_en_gpio = of_get_named_gpio(dev->of_node,
  626. BT_EN_GPIO, 0);
  627. cnss_pr_dbg("BT GPIO: %d\n", pinctrl_info->bt_en_gpio);
  628. } else {
  629. pinctrl_info->bt_en_gpio = -EINVAL;
  630. }
  631. /* Added for QCA6490 to minimize XO CLK selection leakage prevention */
  632. if (of_find_property(dev->of_node, XO_CLK_GPIO, NULL)) {
  633. pinctrl_info->xo_clk_gpio = of_get_named_gpio(dev->of_node,
  634. XO_CLK_GPIO, 0);
  635. cnss_pr_dbg("QCA6490 XO_CLK GPIO: %d\n",
  636. pinctrl_info->xo_clk_gpio);
  637. cnss_set_feature_list(plat_priv, BOOTSTRAP_CLOCK_SELECT_V01);
  638. } else {
  639. pinctrl_info->xo_clk_gpio = -EINVAL;
  640. }
  641. return 0;
  642. out:
  643. return ret;
  644. }
  645. #define CNSS_XO_CLK_RETRY_COUNT_MAX 5
  646. static void cnss_set_xo_clk_gpio_state(struct cnss_plat_data *plat_priv,
  647. bool enable)
  648. {
  649. int xo_clk_gpio = plat_priv->pinctrl_info.xo_clk_gpio, retry = 0, ret;
  650. if (xo_clk_gpio < 0 || plat_priv->device_id != QCA6490_DEVICE_ID)
  651. return;
  652. retry_gpio_req:
  653. ret = gpio_request(xo_clk_gpio, "XO_CLK_GPIO");
  654. if (ret) {
  655. if (retry++ < CNSS_XO_CLK_RETRY_COUNT_MAX) {
  656. /* wait for ~(10 - 20) ms */
  657. usleep_range(10000, 20000);
  658. goto retry_gpio_req;
  659. }
  660. }
  661. if (ret) {
  662. cnss_pr_err("QCA6490 XO CLK Gpio request failed\n");
  663. return;
  664. }
  665. if (enable) {
  666. gpio_direction_output(xo_clk_gpio, 1);
  667. /*XO CLK must be asserted for some time before WLAN_EN */
  668. usleep_range(100, 200);
  669. } else {
  670. /* Assert XO CLK ~(2-5)ms before off for valid latch in HW */
  671. usleep_range(2000, 5000);
  672. gpio_direction_output(xo_clk_gpio, 0);
  673. }
  674. gpio_free(xo_clk_gpio);
  675. }
  676. static int cnss_select_pinctrl_state(struct cnss_plat_data *plat_priv,
  677. bool state)
  678. {
  679. int ret = 0;
  680. struct cnss_pinctrl_info *pinctrl_info;
  681. if (!plat_priv) {
  682. cnss_pr_err("plat_priv is NULL!\n");
  683. ret = -ENODEV;
  684. goto out;
  685. }
  686. pinctrl_info = &plat_priv->pinctrl_info;
  687. if (state) {
  688. if (!IS_ERR_OR_NULL(pinctrl_info->bootstrap_active)) {
  689. ret = pinctrl_select_state
  690. (pinctrl_info->pinctrl,
  691. pinctrl_info->bootstrap_active);
  692. if (ret) {
  693. cnss_pr_err("Failed to select bootstrap active state, err = %d\n",
  694. ret);
  695. goto out;
  696. }
  697. udelay(BOOTSTRAP_DELAY);
  698. }
  699. cnss_set_xo_clk_gpio_state(plat_priv, true);
  700. if (!IS_ERR_OR_NULL(pinctrl_info->wlan_en_active)) {
  701. ret = pinctrl_select_state
  702. (pinctrl_info->pinctrl,
  703. pinctrl_info->wlan_en_active);
  704. if (ret) {
  705. cnss_pr_err("Failed to select wlan_en active state, err = %d\n",
  706. ret);
  707. goto out;
  708. }
  709. udelay(WLAN_ENABLE_DELAY);
  710. }
  711. cnss_set_xo_clk_gpio_state(plat_priv, false);
  712. } else {
  713. if (!IS_ERR_OR_NULL(pinctrl_info->wlan_en_sleep)) {
  714. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  715. pinctrl_info->wlan_en_sleep);
  716. if (ret) {
  717. cnss_pr_err("Failed to select wlan_en sleep state, err = %d\n",
  718. ret);
  719. goto out;
  720. }
  721. }
  722. }
  723. cnss_pr_dbg("%s WLAN_EN GPIO successfully\n",
  724. state ? "Assert" : "De-assert");
  725. return 0;
  726. out:
  727. return ret;
  728. }
  729. /**
  730. * cnss_select_pinctrl_enable - select WLAN_GPIO for Active pinctrl status
  731. * @plat_priv: Platform private data structure pointer
  732. *
  733. * For QCA6490, PMU requires minimum 100ms delay between BT_EN_GPIO off and
  734. * WLAN_EN_GPIO on. This is done to avoid power up issues.
  735. *
  736. * Return: Status of pinctrl select operation. 0 - Success.
  737. */
  738. static int cnss_select_pinctrl_enable(struct cnss_plat_data *plat_priv)
  739. {
  740. int ret = 0, bt_en_gpio = plat_priv->pinctrl_info.bt_en_gpio;
  741. u8 wlan_en_state = 0;
  742. if (bt_en_gpio < 0 || plat_priv->device_id != QCA6490_DEVICE_ID)
  743. goto set_wlan_en;
  744. if (gpio_get_value(bt_en_gpio)) {
  745. cnss_pr_dbg("BT_EN_GPIO State: On\n");
  746. ret = cnss_select_pinctrl_state(plat_priv, true);
  747. if (!ret)
  748. return ret;
  749. wlan_en_state = 1;
  750. }
  751. if (!gpio_get_value(bt_en_gpio)) {
  752. cnss_pr_dbg("BT_EN_GPIO State: Off. Delay WLAN_GPIO enable\n");
  753. /* check for BT_EN_GPIO down race during above operation */
  754. if (wlan_en_state) {
  755. cnss_pr_dbg("Reset WLAN_EN as BT got turned off during enable\n");
  756. cnss_select_pinctrl_state(plat_priv, false);
  757. wlan_en_state = 0;
  758. }
  759. /* 100 ms delay for BT_EN and WLAN_EN QCA6490 PMU sequencing */
  760. msleep(100);
  761. }
  762. set_wlan_en:
  763. if (!wlan_en_state)
  764. ret = cnss_select_pinctrl_state(plat_priv, true);
  765. return ret;
  766. }
  767. int cnss_power_on_device(struct cnss_plat_data *plat_priv)
  768. {
  769. int ret = 0;
  770. if (plat_priv->powered_on) {
  771. cnss_pr_dbg("Already powered up");
  772. return 0;
  773. }
  774. ret = cnss_vreg_on_type(plat_priv, CNSS_VREG_PRIM);
  775. if (ret) {
  776. cnss_pr_err("Failed to turn on vreg, err = %d\n", ret);
  777. goto out;
  778. }
  779. ret = cnss_clk_on(plat_priv, &plat_priv->clk_list);
  780. if (ret) {
  781. cnss_pr_err("Failed to turn on clocks, err = %d\n", ret);
  782. goto vreg_off;
  783. }
  784. ret = cnss_select_pinctrl_enable(plat_priv);
  785. if (ret) {
  786. cnss_pr_err("Failed to select pinctrl state, err = %d\n", ret);
  787. goto clk_off;
  788. }
  789. plat_priv->powered_on = true;
  790. return 0;
  791. clk_off:
  792. cnss_clk_off(plat_priv, &plat_priv->clk_list);
  793. vreg_off:
  794. cnss_vreg_off_type(plat_priv, CNSS_VREG_PRIM);
  795. out:
  796. return ret;
  797. }
  798. void cnss_power_off_device(struct cnss_plat_data *plat_priv)
  799. {
  800. if (!plat_priv->powered_on) {
  801. cnss_pr_dbg("Already powered down");
  802. return;
  803. }
  804. cnss_select_pinctrl_state(plat_priv, false);
  805. cnss_clk_off(plat_priv, &plat_priv->clk_list);
  806. cnss_vreg_off_type(plat_priv, CNSS_VREG_PRIM);
  807. plat_priv->powered_on = false;
  808. }
  809. bool cnss_is_device_powered_on(struct cnss_plat_data *plat_priv)
  810. {
  811. return plat_priv->powered_on;
  812. }
  813. void cnss_set_pin_connect_status(struct cnss_plat_data *plat_priv)
  814. {
  815. unsigned long pin_status = 0;
  816. set_bit(CNSS_WLAN_EN, &pin_status);
  817. set_bit(CNSS_PCIE_TXN, &pin_status);
  818. set_bit(CNSS_PCIE_TXP, &pin_status);
  819. set_bit(CNSS_PCIE_RXN, &pin_status);
  820. set_bit(CNSS_PCIE_RXP, &pin_status);
  821. set_bit(CNSS_PCIE_REFCLKN, &pin_status);
  822. set_bit(CNSS_PCIE_REFCLKP, &pin_status);
  823. set_bit(CNSS_PCIE_RST, &pin_status);
  824. plat_priv->pin_result.host_pin_result = pin_status;
  825. }
  826. #if IS_ENABLED(CONFIG_QCOM_COMMAND_DB)
  827. static int cnss_cmd_db_ready(struct cnss_plat_data *plat_priv)
  828. {
  829. return cmd_db_ready();
  830. }
  831. static u32 cnss_cmd_db_read_addr(struct cnss_plat_data *plat_priv,
  832. const char *res_id)
  833. {
  834. return cmd_db_read_addr(res_id);
  835. }
  836. #else
  837. static int cnss_cmd_db_ready(struct cnss_plat_data *plat_priv)
  838. {
  839. return -EOPNOTSUPP;
  840. }
  841. static u32 cnss_cmd_db_read_addr(struct cnss_plat_data *plat_priv,
  842. const char *res_id)
  843. {
  844. return 0;
  845. }
  846. #endif
  847. int cnss_get_tcs_info(struct cnss_plat_data *plat_priv)
  848. {
  849. struct platform_device *plat_dev = plat_priv->plat_dev;
  850. struct resource *res;
  851. resource_size_t addr_len;
  852. void __iomem *tcs_cmd_base_addr;
  853. int ret = 0;
  854. res = platform_get_resource_byname(plat_dev, IORESOURCE_MEM, "tcs_cmd");
  855. if (!res) {
  856. cnss_pr_dbg("TCS CMD address is not present for CPR\n");
  857. goto out;
  858. }
  859. plat_priv->tcs_info.cmd_base_addr = res->start;
  860. addr_len = resource_size(res);
  861. cnss_pr_dbg("TCS CMD base address is %pa with length %pa\n",
  862. &plat_priv->tcs_info.cmd_base_addr, &addr_len);
  863. tcs_cmd_base_addr = devm_ioremap(&plat_dev->dev, res->start, addr_len);
  864. if (!tcs_cmd_base_addr) {
  865. ret = -EINVAL;
  866. cnss_pr_err("Failed to map TCS CMD address, err = %d\n",
  867. ret);
  868. goto out;
  869. }
  870. plat_priv->tcs_info.cmd_base_addr_io = tcs_cmd_base_addr;
  871. return 0;
  872. out:
  873. return ret;
  874. }
  875. int cnss_get_cpr_info(struct cnss_plat_data *plat_priv)
  876. {
  877. struct platform_device *plat_dev = plat_priv->plat_dev;
  878. struct cnss_cpr_info *cpr_info = &plat_priv->cpr_info;
  879. const char *cmd_db_name;
  880. u32 cpr_pmic_addr = 0;
  881. int ret = 0;
  882. if (plat_priv->tcs_info.cmd_base_addr == 0) {
  883. cnss_pr_dbg("TCS CMD not configured\n");
  884. return 0;
  885. }
  886. ret = of_property_read_string(plat_dev->dev.of_node,
  887. "qcom,cmd_db_name", &cmd_db_name);
  888. if (ret) {
  889. cnss_pr_dbg("CommandDB name is not present for CPR\n");
  890. goto out;
  891. }
  892. ret = cnss_cmd_db_ready(plat_priv);
  893. if (ret) {
  894. cnss_pr_err("CommandDB is not ready, err = %d\n", ret);
  895. goto out;
  896. }
  897. cpr_pmic_addr = cnss_cmd_db_read_addr(plat_priv, cmd_db_name);
  898. if (cpr_pmic_addr > 0) {
  899. cpr_info->cpr_pmic_addr = cpr_pmic_addr;
  900. cnss_pr_dbg("Get CPR PMIC address 0x%x from %s\n",
  901. cpr_info->cpr_pmic_addr, cmd_db_name);
  902. } else {
  903. cnss_pr_err("CPR PMIC address is not available for %s\n",
  904. cmd_db_name);
  905. ret = -EINVAL;
  906. goto out;
  907. }
  908. return 0;
  909. out:
  910. return ret;
  911. }
  912. int cnss_aop_mbox_init(struct cnss_plat_data *plat_priv)
  913. {
  914. struct mbox_client *mbox = &plat_priv->mbox_client_data;
  915. struct mbox_chan *chan;
  916. int ret = 0;
  917. mbox->dev = &plat_priv->plat_dev->dev;
  918. mbox->tx_block = true;
  919. mbox->tx_tout = CNSS_MBOX_TIMEOUT_MS;
  920. mbox->knows_txdone = false;
  921. plat_priv->mbox_chan = NULL;
  922. ret = of_property_read_string(plat_priv->plat_dev->dev.of_node,
  923. "qcom,vreg_ol_cpr",
  924. &plat_priv->vreg_ol_cpr);
  925. if (ret)
  926. cnss_pr_dbg("Vreg for OL CPR not configured\n");
  927. ret = of_property_read_string(plat_priv->plat_dev->dev.of_node,
  928. "qcom,vreg_ipa",
  929. &plat_priv->vreg_ipa);
  930. if (ret)
  931. cnss_pr_dbg("Volt regulator for Int Power Amp not configured\n");
  932. if (!plat_priv->vreg_ol_cpr && !plat_priv->vreg_ipa)
  933. return 0;
  934. chan = mbox_request_channel(mbox, 0);
  935. if (IS_ERR(chan)) {
  936. cnss_pr_err("Failed to get mbox channel\n");
  937. return PTR_ERR(chan);
  938. }
  939. plat_priv->mbox_chan = chan;
  940. cnss_pr_dbg("Mbox channel initialized\n");
  941. return 0;
  942. }
  943. #if IS_ENABLED(CONFIG_MSM_QMP)
  944. static int cnss_aop_set_vreg_param(struct cnss_plat_data *plat_priv,
  945. const char *vreg_name,
  946. enum cnss_vreg_param param,
  947. enum cnss_tcs_seq seq, int val)
  948. {
  949. struct qmp_pkt pkt;
  950. char mbox_msg[CNSS_MBOX_MSG_MAX_LEN];
  951. static const char * const vreg_param_str[] = {"v", "m", "e"};
  952. static const char *const tcs_seq_str[] = {"upval", "dwnval", "enable"};
  953. int ret = 0;
  954. if (param > CNSS_VREG_ENABLE || seq > CNSS_TCS_ALL_SEQ || !vreg_name)
  955. return -EINVAL;
  956. snprintf(mbox_msg, CNSS_MBOX_MSG_MAX_LEN,
  957. "{class: wlan_pdc, res: %s.%s, %s: %d}", vreg_name,
  958. vreg_param_str[param], tcs_seq_str[seq], val);
  959. cnss_pr_dbg("Sending AOP Mbox msg: %s\n", mbox_msg);
  960. pkt.size = CNSS_MBOX_MSG_MAX_LEN;
  961. pkt.data = mbox_msg;
  962. ret = mbox_send_message(plat_priv->mbox_chan, &pkt);
  963. if (ret < 0)
  964. cnss_pr_err("Failed to send AOP mbox msg: %s\n", mbox_msg);
  965. else
  966. ret = 0;
  967. return ret;
  968. }
  969. #else
  970. static int cnss_aop_set_vreg_param(struct cnss_plat_data *plat_priv,
  971. const char *vreg_name,
  972. enum cnss_vreg_param param,
  973. enum cnss_tcs_seq seq, int val)
  974. {
  975. return 0;
  976. }
  977. #endif
  978. int cnss_update_cpr_info(struct cnss_plat_data *plat_priv)
  979. {
  980. struct cnss_cpr_info *cpr_info = &plat_priv->cpr_info;
  981. u32 pmic_addr, voltage = 0, voltage_tmp, offset;
  982. void __iomem *tcs_cmd_addr, *tcs_cmd_data_addr;
  983. int i, j;
  984. if (cpr_info->voltage == 0) {
  985. cnss_pr_err("OL CPR Voltage %dm is not valid\n",
  986. cpr_info->voltage);
  987. return -EINVAL;
  988. }
  989. if (!plat_priv->vreg_ol_cpr || !plat_priv->mbox_chan) {
  990. cnss_pr_dbg("Mbox channel / OL CPR Vreg not configured\n");
  991. } else {
  992. return cnss_aop_set_vreg_param(plat_priv,
  993. plat_priv->vreg_ol_cpr,
  994. CNSS_VREG_VOLTAGE,
  995. CNSS_TCS_UP_SEQ,
  996. cpr_info->voltage);
  997. }
  998. if (plat_priv->tcs_info.cmd_base_addr == 0) {
  999. cnss_pr_dbg("TCS CMD not configured for OL CPR update\n");
  1000. return 0;
  1001. }
  1002. if (cpr_info->cpr_pmic_addr == 0) {
  1003. cnss_pr_err("PMIC address 0x%x is not valid\n",
  1004. cpr_info->cpr_pmic_addr);
  1005. return -EINVAL;
  1006. }
  1007. if (cpr_info->tcs_cmd_data_addr_io)
  1008. goto update_cpr;
  1009. for (i = 0; i < MAX_TCS_NUM; i++) {
  1010. for (j = 0; j < MAX_TCS_CMD_NUM; j++) {
  1011. offset = i * TCS_OFFSET + j * TCS_CMD_OFFSET;
  1012. tcs_cmd_addr = plat_priv->tcs_info.cmd_base_addr_io +
  1013. offset;
  1014. pmic_addr = readl_relaxed(tcs_cmd_addr);
  1015. if (pmic_addr == cpr_info->cpr_pmic_addr) {
  1016. tcs_cmd_data_addr = tcs_cmd_addr +
  1017. TCS_CMD_DATA_ADDR_OFFSET;
  1018. voltage_tmp = readl_relaxed(tcs_cmd_data_addr);
  1019. cnss_pr_dbg("Got voltage %dmV from i: %d, j: %d\n",
  1020. voltage_tmp, i, j);
  1021. if (voltage_tmp > voltage) {
  1022. voltage = voltage_tmp;
  1023. cpr_info->tcs_cmd_data_addr =
  1024. plat_priv->tcs_info.cmd_base_addr +
  1025. offset + TCS_CMD_DATA_ADDR_OFFSET;
  1026. cpr_info->tcs_cmd_data_addr_io =
  1027. tcs_cmd_data_addr;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. if (!cpr_info->tcs_cmd_data_addr_io) {
  1033. cnss_pr_err("Failed to find proper TCS CMD data address\n");
  1034. return -EINVAL;
  1035. }
  1036. update_cpr:
  1037. cpr_info->voltage = cpr_info->voltage > BT_CXMX_VOLTAGE_MV ?
  1038. cpr_info->voltage : BT_CXMX_VOLTAGE_MV;
  1039. cnss_pr_dbg("Update TCS CMD data address %pa with voltage %dmV\n",
  1040. &cpr_info->tcs_cmd_data_addr, cpr_info->voltage);
  1041. writel_relaxed(cpr_info->voltage, cpr_info->tcs_cmd_data_addr_io);
  1042. return 0;
  1043. }
  1044. int cnss_enable_int_pow_amp_vreg(struct cnss_plat_data *plat_priv)
  1045. {
  1046. struct platform_device *plat_dev = plat_priv->plat_dev;
  1047. u32 offset, addr_val, data_val;
  1048. void __iomem *tcs_cmd;
  1049. int ret;
  1050. static bool config_done;
  1051. if (plat_priv->device_id != QCA6490_DEVICE_ID)
  1052. return -EINVAL;
  1053. if (config_done) {
  1054. cnss_pr_dbg("IPA Vreg already configured\n");
  1055. return 0;
  1056. }
  1057. if (!plat_priv->vreg_ipa || !plat_priv->mbox_chan) {
  1058. cnss_pr_dbg("Mbox channel / IPA Vreg not configured\n");
  1059. } else {
  1060. ret = cnss_aop_set_vreg_param(plat_priv,
  1061. plat_priv->vreg_ipa,
  1062. CNSS_VREG_ENABLE,
  1063. CNSS_TCS_UP_SEQ, 1);
  1064. if (ret == 0)
  1065. config_done = true;
  1066. return ret;
  1067. }
  1068. if (!plat_priv->tcs_info.cmd_base_addr_io) {
  1069. cnss_pr_err("TCS CMD not configured for IPA Vreg enable\n");
  1070. return -EINVAL;
  1071. }
  1072. ret = of_property_read_u32(plat_dev->dev.of_node,
  1073. "qcom,tcs_offset_int_pow_amp_vreg",
  1074. &offset);
  1075. if (ret) {
  1076. cnss_pr_dbg("Internal Power Amp Vreg not configured\n");
  1077. return -EINVAL;
  1078. }
  1079. tcs_cmd = plat_priv->tcs_info.cmd_base_addr_io + offset;
  1080. addr_val = readl_relaxed(tcs_cmd);
  1081. tcs_cmd += TCS_CMD_DATA_ADDR_OFFSET;
  1082. /* 1 = enable Vreg */
  1083. writel_relaxed(1, tcs_cmd);
  1084. data_val = readl_relaxed(tcs_cmd);
  1085. cnss_pr_dbg("Setup S3E TCS Addr: %x Data: %d\n", addr_val, data_val);
  1086. config_done = true;
  1087. return 0;
  1088. }