power.c 44 KB

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