power.c 50 KB

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