power.c 31 KB

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