power.c 46 KB

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