power.c 45 KB

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