qcom_q6v5_pil.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. /*
  2. * Qualcomm Peripheral Image Loader
  3. *
  4. * Copyright (C) 2016 Linaro Ltd.
  5. * Copyright (C) 2014 Sony Mobile Communications AB
  6. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk.h>
  18. #include <linux/delay.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/kernel.h>
  22. #include <linux/mfd/syscon.h>
  23. #include <linux/module.h>
  24. #include <linux/of_address.h>
  25. #include <linux/of_device.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/regmap.h>
  28. #include <linux/regulator/consumer.h>
  29. #include <linux/remoteproc.h>
  30. #include <linux/reset.h>
  31. #include <linux/soc/qcom/mdt_loader.h>
  32. #include <linux/iopoll.h>
  33. #include "remoteproc_internal.h"
  34. #include "qcom_common.h"
  35. #include "qcom_q6v5.h"
  36. #include <linux/qcom_scm.h>
  37. #define MPSS_CRASH_REASON_SMEM 421
  38. /* RMB Status Register Values */
  39. #define RMB_PBL_SUCCESS 0x1
  40. #define RMB_MBA_XPU_UNLOCKED 0x1
  41. #define RMB_MBA_XPU_UNLOCKED_SCRIBBLED 0x2
  42. #define RMB_MBA_META_DATA_AUTH_SUCCESS 0x3
  43. #define RMB_MBA_AUTH_COMPLETE 0x4
  44. /* PBL/MBA interface registers */
  45. #define RMB_MBA_IMAGE_REG 0x00
  46. #define RMB_PBL_STATUS_REG 0x04
  47. #define RMB_MBA_COMMAND_REG 0x08
  48. #define RMB_MBA_STATUS_REG 0x0C
  49. #define RMB_PMI_META_DATA_REG 0x10
  50. #define RMB_PMI_CODE_START_REG 0x14
  51. #define RMB_PMI_CODE_LENGTH_REG 0x18
  52. #define RMB_MBA_MSS_STATUS 0x40
  53. #define RMB_MBA_ALT_RESET 0x44
  54. #define RMB_CMD_META_DATA_READY 0x1
  55. #define RMB_CMD_LOAD_READY 0x2
  56. /* QDSP6SS Register Offsets */
  57. #define QDSP6SS_RESET_REG 0x014
  58. #define QDSP6SS_GFMUX_CTL_REG 0x020
  59. #define QDSP6SS_PWR_CTL_REG 0x030
  60. #define QDSP6SS_MEM_PWR_CTL 0x0B0
  61. #define QDSP6SS_STRAP_ACC 0x110
  62. /* AXI Halt Register Offsets */
  63. #define AXI_HALTREQ_REG 0x0
  64. #define AXI_HALTACK_REG 0x4
  65. #define AXI_IDLE_REG 0x8
  66. #define HALT_ACK_TIMEOUT_MS 100
  67. /* QDSP6SS_RESET */
  68. #define Q6SS_STOP_CORE BIT(0)
  69. #define Q6SS_CORE_ARES BIT(1)
  70. #define Q6SS_BUS_ARES_ENABLE BIT(2)
  71. /* QDSP6SS_GFMUX_CTL */
  72. #define Q6SS_CLK_ENABLE BIT(1)
  73. /* QDSP6SS_PWR_CTL */
  74. #define Q6SS_L2DATA_SLP_NRET_N_0 BIT(0)
  75. #define Q6SS_L2DATA_SLP_NRET_N_1 BIT(1)
  76. #define Q6SS_L2DATA_SLP_NRET_N_2 BIT(2)
  77. #define Q6SS_L2TAG_SLP_NRET_N BIT(16)
  78. #define Q6SS_ETB_SLP_NRET_N BIT(17)
  79. #define Q6SS_L2DATA_STBY_N BIT(18)
  80. #define Q6SS_SLP_RET_N BIT(19)
  81. #define Q6SS_CLAMP_IO BIT(20)
  82. #define QDSS_BHS_ON BIT(21)
  83. #define QDSS_LDO_BYP BIT(22)
  84. /* QDSP6v56 parameters */
  85. #define QDSP6v56_LDO_BYP BIT(25)
  86. #define QDSP6v56_BHS_ON BIT(24)
  87. #define QDSP6v56_CLAMP_WL BIT(21)
  88. #define QDSP6v56_CLAMP_QMC_MEM BIT(22)
  89. #define HALT_CHECK_MAX_LOOPS 200
  90. #define QDSP6SS_XO_CBCR 0x0038
  91. #define QDSP6SS_ACC_OVERRIDE_VAL 0x20
  92. /* QDSP6v65 parameters */
  93. #define QDSP6SS_SLEEP 0x3C
  94. #define QDSP6SS_BOOT_CORE_START 0x400
  95. #define QDSP6SS_BOOT_CMD 0x404
  96. #define SLEEP_CHECK_MAX_LOOPS 200
  97. #define BOOT_FSM_TIMEOUT 10000
  98. struct reg_info {
  99. struct regulator *reg;
  100. int uV;
  101. int uA;
  102. };
  103. struct qcom_mss_reg_res {
  104. const char *supply;
  105. int uV;
  106. int uA;
  107. };
  108. struct rproc_hexagon_res {
  109. const char *hexagon_mba_image;
  110. struct qcom_mss_reg_res *proxy_supply;
  111. struct qcom_mss_reg_res *active_supply;
  112. char **proxy_clk_names;
  113. char **reset_clk_names;
  114. char **active_clk_names;
  115. int version;
  116. bool need_mem_protection;
  117. bool has_alt_reset;
  118. };
  119. struct q6v5 {
  120. struct device *dev;
  121. struct rproc *rproc;
  122. void __iomem *reg_base;
  123. void __iomem *rmb_base;
  124. struct regmap *halt_map;
  125. u32 halt_q6;
  126. u32 halt_modem;
  127. u32 halt_nc;
  128. struct reset_control *mss_restart;
  129. struct qcom_q6v5 q6v5;
  130. struct clk *active_clks[8];
  131. struct clk *reset_clks[4];
  132. struct clk *proxy_clks[4];
  133. int active_clk_count;
  134. int reset_clk_count;
  135. int proxy_clk_count;
  136. struct reg_info active_regs[1];
  137. struct reg_info proxy_regs[3];
  138. int active_reg_count;
  139. int proxy_reg_count;
  140. bool running;
  141. phys_addr_t mba_phys;
  142. void *mba_region;
  143. size_t mba_size;
  144. phys_addr_t mpss_phys;
  145. phys_addr_t mpss_reloc;
  146. void *mpss_region;
  147. size_t mpss_size;
  148. struct qcom_rproc_glink glink_subdev;
  149. struct qcom_rproc_subdev smd_subdev;
  150. struct qcom_rproc_ssr ssr_subdev;
  151. struct qcom_sysmon *sysmon;
  152. bool need_mem_protection;
  153. bool has_alt_reset;
  154. int mpss_perm;
  155. int mba_perm;
  156. int version;
  157. };
  158. enum {
  159. MSS_MSM8916,
  160. MSS_MSM8974,
  161. MSS_MSM8996,
  162. MSS_SDM845,
  163. };
  164. static int q6v5_regulator_init(struct device *dev, struct reg_info *regs,
  165. const struct qcom_mss_reg_res *reg_res)
  166. {
  167. int rc;
  168. int i;
  169. if (!reg_res)
  170. return 0;
  171. for (i = 0; reg_res[i].supply; i++) {
  172. regs[i].reg = devm_regulator_get(dev, reg_res[i].supply);
  173. if (IS_ERR(regs[i].reg)) {
  174. rc = PTR_ERR(regs[i].reg);
  175. if (rc != -EPROBE_DEFER)
  176. dev_err(dev, "Failed to get %s\n regulator",
  177. reg_res[i].supply);
  178. return rc;
  179. }
  180. regs[i].uV = reg_res[i].uV;
  181. regs[i].uA = reg_res[i].uA;
  182. }
  183. return i;
  184. }
  185. static int q6v5_regulator_enable(struct q6v5 *qproc,
  186. struct reg_info *regs, int count)
  187. {
  188. int ret;
  189. int i;
  190. for (i = 0; i < count; i++) {
  191. if (regs[i].uV > 0) {
  192. ret = regulator_set_voltage(regs[i].reg,
  193. regs[i].uV, INT_MAX);
  194. if (ret) {
  195. dev_err(qproc->dev,
  196. "Failed to request voltage for %d.\n",
  197. i);
  198. goto err;
  199. }
  200. }
  201. if (regs[i].uA > 0) {
  202. ret = regulator_set_load(regs[i].reg,
  203. regs[i].uA);
  204. if (ret < 0) {
  205. dev_err(qproc->dev,
  206. "Failed to set regulator mode\n");
  207. goto err;
  208. }
  209. }
  210. ret = regulator_enable(regs[i].reg);
  211. if (ret) {
  212. dev_err(qproc->dev, "Regulator enable failed\n");
  213. goto err;
  214. }
  215. }
  216. return 0;
  217. err:
  218. for (; i >= 0; i--) {
  219. if (regs[i].uV > 0)
  220. regulator_set_voltage(regs[i].reg, 0, INT_MAX);
  221. if (regs[i].uA > 0)
  222. regulator_set_load(regs[i].reg, 0);
  223. regulator_disable(regs[i].reg);
  224. }
  225. return ret;
  226. }
  227. static void q6v5_regulator_disable(struct q6v5 *qproc,
  228. struct reg_info *regs, int count)
  229. {
  230. int i;
  231. for (i = 0; i < count; i++) {
  232. if (regs[i].uV > 0)
  233. regulator_set_voltage(regs[i].reg, 0, INT_MAX);
  234. if (regs[i].uA > 0)
  235. regulator_set_load(regs[i].reg, 0);
  236. regulator_disable(regs[i].reg);
  237. }
  238. }
  239. static int q6v5_clk_enable(struct device *dev,
  240. struct clk **clks, int count)
  241. {
  242. int rc;
  243. int i;
  244. for (i = 0; i < count; i++) {
  245. rc = clk_prepare_enable(clks[i]);
  246. if (rc) {
  247. dev_err(dev, "Clock enable failed\n");
  248. goto err;
  249. }
  250. }
  251. return 0;
  252. err:
  253. for (i--; i >= 0; i--)
  254. clk_disable_unprepare(clks[i]);
  255. return rc;
  256. }
  257. static void q6v5_clk_disable(struct device *dev,
  258. struct clk **clks, int count)
  259. {
  260. int i;
  261. for (i = 0; i < count; i++)
  262. clk_disable_unprepare(clks[i]);
  263. }
  264. static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm,
  265. bool remote_owner, phys_addr_t addr,
  266. size_t size)
  267. {
  268. struct qcom_scm_vmperm next;
  269. if (!qproc->need_mem_protection)
  270. return 0;
  271. if (remote_owner && *current_perm == BIT(QCOM_SCM_VMID_MSS_MSA))
  272. return 0;
  273. if (!remote_owner && *current_perm == BIT(QCOM_SCM_VMID_HLOS))
  274. return 0;
  275. next.vmid = remote_owner ? QCOM_SCM_VMID_MSS_MSA : QCOM_SCM_VMID_HLOS;
  276. next.perm = remote_owner ? QCOM_SCM_PERM_RW : QCOM_SCM_PERM_RWX;
  277. return qcom_scm_assign_mem(addr, ALIGN(size, SZ_4K),
  278. current_perm, &next, 1);
  279. }
  280. static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
  281. {
  282. struct q6v5 *qproc = rproc->priv;
  283. memcpy(qproc->mba_region, fw->data, fw->size);
  284. return 0;
  285. }
  286. static int q6v5_reset_assert(struct q6v5 *qproc)
  287. {
  288. if (qproc->has_alt_reset)
  289. return reset_control_reset(qproc->mss_restart);
  290. else
  291. return reset_control_assert(qproc->mss_restart);
  292. }
  293. static int q6v5_reset_deassert(struct q6v5 *qproc)
  294. {
  295. int ret;
  296. if (qproc->has_alt_reset) {
  297. writel(1, qproc->rmb_base + RMB_MBA_ALT_RESET);
  298. ret = reset_control_reset(qproc->mss_restart);
  299. writel(0, qproc->rmb_base + RMB_MBA_ALT_RESET);
  300. } else {
  301. ret = reset_control_deassert(qproc->mss_restart);
  302. }
  303. return ret;
  304. }
  305. static int q6v5_rmb_pbl_wait(struct q6v5 *qproc, int ms)
  306. {
  307. unsigned long timeout;
  308. s32 val;
  309. timeout = jiffies + msecs_to_jiffies(ms);
  310. for (;;) {
  311. val = readl(qproc->rmb_base + RMB_PBL_STATUS_REG);
  312. if (val)
  313. break;
  314. if (time_after(jiffies, timeout))
  315. return -ETIMEDOUT;
  316. msleep(1);
  317. }
  318. return val;
  319. }
  320. static int q6v5_rmb_mba_wait(struct q6v5 *qproc, u32 status, int ms)
  321. {
  322. unsigned long timeout;
  323. s32 val;
  324. timeout = jiffies + msecs_to_jiffies(ms);
  325. for (;;) {
  326. val = readl(qproc->rmb_base + RMB_MBA_STATUS_REG);
  327. if (val < 0)
  328. break;
  329. if (!status && val)
  330. break;
  331. else if (status && val == status)
  332. break;
  333. if (time_after(jiffies, timeout))
  334. return -ETIMEDOUT;
  335. msleep(1);
  336. }
  337. return val;
  338. }
  339. static int q6v5proc_reset(struct q6v5 *qproc)
  340. {
  341. u32 val;
  342. int ret;
  343. int i;
  344. if (qproc->version == MSS_SDM845) {
  345. val = readl(qproc->reg_base + QDSP6SS_SLEEP);
  346. val |= 0x1;
  347. writel(val, qproc->reg_base + QDSP6SS_SLEEP);
  348. ret = readl_poll_timeout(qproc->reg_base + QDSP6SS_SLEEP,
  349. val, !(val & BIT(31)), 1,
  350. SLEEP_CHECK_MAX_LOOPS);
  351. if (ret) {
  352. dev_err(qproc->dev, "QDSP6SS Sleep clock timed out\n");
  353. return -ETIMEDOUT;
  354. }
  355. /* De-assert QDSP6 stop core */
  356. writel(1, qproc->reg_base + QDSP6SS_BOOT_CORE_START);
  357. /* Trigger boot FSM */
  358. writel(1, qproc->reg_base + QDSP6SS_BOOT_CMD);
  359. ret = readl_poll_timeout(qproc->rmb_base + RMB_MBA_MSS_STATUS,
  360. val, (val & BIT(0)) != 0, 10, BOOT_FSM_TIMEOUT);
  361. if (ret) {
  362. dev_err(qproc->dev, "Boot FSM failed to complete.\n");
  363. /* Reset the modem so that boot FSM is in reset state */
  364. q6v5_reset_deassert(qproc);
  365. return ret;
  366. }
  367. goto pbl_wait;
  368. } else if (qproc->version == MSS_MSM8996) {
  369. /* Override the ACC value if required */
  370. writel(QDSP6SS_ACC_OVERRIDE_VAL,
  371. qproc->reg_base + QDSP6SS_STRAP_ACC);
  372. /* Assert resets, stop core */
  373. val = readl(qproc->reg_base + QDSP6SS_RESET_REG);
  374. val |= Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENABLE | Q6SS_STOP_CORE;
  375. writel(val, qproc->reg_base + QDSP6SS_RESET_REG);
  376. /* BHS require xo cbcr to be enabled */
  377. val = readl(qproc->reg_base + QDSP6SS_XO_CBCR);
  378. val |= 0x1;
  379. writel(val, qproc->reg_base + QDSP6SS_XO_CBCR);
  380. /* Read CLKOFF bit to go low indicating CLK is enabled */
  381. ret = readl_poll_timeout(qproc->reg_base + QDSP6SS_XO_CBCR,
  382. val, !(val & BIT(31)), 1,
  383. HALT_CHECK_MAX_LOOPS);
  384. if (ret) {
  385. dev_err(qproc->dev,
  386. "xo cbcr enabling timed out (rc:%d)\n", ret);
  387. return ret;
  388. }
  389. /* Enable power block headswitch and wait for it to stabilize */
  390. val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  391. val |= QDSP6v56_BHS_ON;
  392. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  393. val |= readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  394. udelay(1);
  395. /* Put LDO in bypass mode */
  396. val |= QDSP6v56_LDO_BYP;
  397. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  398. /* Deassert QDSP6 compiler memory clamp */
  399. val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  400. val &= ~QDSP6v56_CLAMP_QMC_MEM;
  401. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  402. /* Deassert memory peripheral sleep and L2 memory standby */
  403. val |= Q6SS_L2DATA_STBY_N | Q6SS_SLP_RET_N;
  404. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  405. /* Turn on L1, L2, ETB and JU memories 1 at a time */
  406. val = readl(qproc->reg_base + QDSP6SS_MEM_PWR_CTL);
  407. for (i = 19; i >= 0; i--) {
  408. val |= BIT(i);
  409. writel(val, qproc->reg_base +
  410. QDSP6SS_MEM_PWR_CTL);
  411. /*
  412. * Read back value to ensure the write is done then
  413. * wait for 1us for both memory peripheral and data
  414. * array to turn on.
  415. */
  416. val |= readl(qproc->reg_base + QDSP6SS_MEM_PWR_CTL);
  417. udelay(1);
  418. }
  419. /* Remove word line clamp */
  420. val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  421. val &= ~QDSP6v56_CLAMP_WL;
  422. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  423. } else {
  424. /* Assert resets, stop core */
  425. val = readl(qproc->reg_base + QDSP6SS_RESET_REG);
  426. val |= Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENABLE | Q6SS_STOP_CORE;
  427. writel(val, qproc->reg_base + QDSP6SS_RESET_REG);
  428. /* Enable power block headswitch and wait for it to stabilize */
  429. val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  430. val |= QDSS_BHS_ON | QDSS_LDO_BYP;
  431. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  432. val |= readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  433. udelay(1);
  434. /*
  435. * Turn on memories. L2 banks should be done individually
  436. * to minimize inrush current.
  437. */
  438. val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  439. val |= Q6SS_SLP_RET_N | Q6SS_L2TAG_SLP_NRET_N |
  440. Q6SS_ETB_SLP_NRET_N | Q6SS_L2DATA_STBY_N;
  441. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  442. val |= Q6SS_L2DATA_SLP_NRET_N_2;
  443. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  444. val |= Q6SS_L2DATA_SLP_NRET_N_1;
  445. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  446. val |= Q6SS_L2DATA_SLP_NRET_N_0;
  447. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  448. }
  449. /* Remove IO clamp */
  450. val &= ~Q6SS_CLAMP_IO;
  451. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  452. /* Bring core out of reset */
  453. val = readl(qproc->reg_base + QDSP6SS_RESET_REG);
  454. val &= ~Q6SS_CORE_ARES;
  455. writel(val, qproc->reg_base + QDSP6SS_RESET_REG);
  456. /* Turn on core clock */
  457. val = readl(qproc->reg_base + QDSP6SS_GFMUX_CTL_REG);
  458. val |= Q6SS_CLK_ENABLE;
  459. writel(val, qproc->reg_base + QDSP6SS_GFMUX_CTL_REG);
  460. /* Start core execution */
  461. val = readl(qproc->reg_base + QDSP6SS_RESET_REG);
  462. val &= ~Q6SS_STOP_CORE;
  463. writel(val, qproc->reg_base + QDSP6SS_RESET_REG);
  464. pbl_wait:
  465. /* Wait for PBL status */
  466. ret = q6v5_rmb_pbl_wait(qproc, 1000);
  467. if (ret == -ETIMEDOUT) {
  468. dev_err(qproc->dev, "PBL boot timed out\n");
  469. } else if (ret != RMB_PBL_SUCCESS) {
  470. dev_err(qproc->dev, "PBL returned unexpected status %d\n", ret);
  471. ret = -EINVAL;
  472. } else {
  473. ret = 0;
  474. }
  475. return ret;
  476. }
  477. static void q6v5proc_halt_axi_port(struct q6v5 *qproc,
  478. struct regmap *halt_map,
  479. u32 offset)
  480. {
  481. unsigned long timeout;
  482. unsigned int val;
  483. int ret;
  484. /* Check if we're already idle */
  485. ret = regmap_read(halt_map, offset + AXI_IDLE_REG, &val);
  486. if (!ret && val)
  487. return;
  488. /* Assert halt request */
  489. regmap_write(halt_map, offset + AXI_HALTREQ_REG, 1);
  490. /* Wait for halt */
  491. timeout = jiffies + msecs_to_jiffies(HALT_ACK_TIMEOUT_MS);
  492. for (;;) {
  493. ret = regmap_read(halt_map, offset + AXI_HALTACK_REG, &val);
  494. if (ret || val || time_after(jiffies, timeout))
  495. break;
  496. msleep(1);
  497. }
  498. ret = regmap_read(halt_map, offset + AXI_IDLE_REG, &val);
  499. if (ret || !val)
  500. dev_err(qproc->dev, "port failed halt\n");
  501. /* Clear halt request (port will remain halted until reset) */
  502. regmap_write(halt_map, offset + AXI_HALTREQ_REG, 0);
  503. }
  504. static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw)
  505. {
  506. unsigned long dma_attrs = DMA_ATTR_FORCE_CONTIGUOUS;
  507. dma_addr_t phys;
  508. int mdata_perm;
  509. int xferop_ret;
  510. void *ptr;
  511. int ret;
  512. ptr = dma_alloc_attrs(qproc->dev, fw->size, &phys, GFP_KERNEL, dma_attrs);
  513. if (!ptr) {
  514. dev_err(qproc->dev, "failed to allocate mdt buffer\n");
  515. return -ENOMEM;
  516. }
  517. memcpy(ptr, fw->data, fw->size);
  518. /* Hypervisor mapping to access metadata by modem */
  519. mdata_perm = BIT(QCOM_SCM_VMID_HLOS);
  520. ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm,
  521. true, phys, fw->size);
  522. if (ret) {
  523. dev_err(qproc->dev,
  524. "assigning Q6 access to metadata failed: %d\n", ret);
  525. ret = -EAGAIN;
  526. goto free_dma_attrs;
  527. }
  528. writel(phys, qproc->rmb_base + RMB_PMI_META_DATA_REG);
  529. writel(RMB_CMD_META_DATA_READY, qproc->rmb_base + RMB_MBA_COMMAND_REG);
  530. ret = q6v5_rmb_mba_wait(qproc, RMB_MBA_META_DATA_AUTH_SUCCESS, 1000);
  531. if (ret == -ETIMEDOUT)
  532. dev_err(qproc->dev, "MPSS header authentication timed out\n");
  533. else if (ret < 0)
  534. dev_err(qproc->dev, "MPSS header authentication failed: %d\n", ret);
  535. /* Metadata authentication done, remove modem access */
  536. xferop_ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm,
  537. false, phys, fw->size);
  538. if (xferop_ret)
  539. dev_warn(qproc->dev,
  540. "mdt buffer not reclaimed system may become unstable\n");
  541. free_dma_attrs:
  542. dma_free_attrs(qproc->dev, fw->size, ptr, phys, dma_attrs);
  543. return ret < 0 ? ret : 0;
  544. }
  545. static bool q6v5_phdr_valid(const struct elf32_phdr *phdr)
  546. {
  547. if (phdr->p_type != PT_LOAD)
  548. return false;
  549. if ((phdr->p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH)
  550. return false;
  551. if (!phdr->p_memsz)
  552. return false;
  553. return true;
  554. }
  555. static int q6v5_mpss_load(struct q6v5 *qproc)
  556. {
  557. const struct elf32_phdr *phdrs;
  558. const struct elf32_phdr *phdr;
  559. const struct firmware *seg_fw;
  560. const struct firmware *fw;
  561. struct elf32_hdr *ehdr;
  562. phys_addr_t mpss_reloc;
  563. phys_addr_t boot_addr;
  564. phys_addr_t min_addr = PHYS_ADDR_MAX;
  565. phys_addr_t max_addr = 0;
  566. bool relocate = false;
  567. char seg_name[10];
  568. ssize_t offset;
  569. size_t size = 0;
  570. void *ptr;
  571. int ret;
  572. int i;
  573. ret = request_firmware(&fw, "modem.mdt", qproc->dev);
  574. if (ret < 0) {
  575. dev_err(qproc->dev, "unable to load modem.mdt\n");
  576. return ret;
  577. }
  578. /* Initialize the RMB validator */
  579. writel(0, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG);
  580. ret = q6v5_mpss_init_image(qproc, fw);
  581. if (ret)
  582. goto release_firmware;
  583. ehdr = (struct elf32_hdr *)fw->data;
  584. phdrs = (struct elf32_phdr *)(ehdr + 1);
  585. for (i = 0; i < ehdr->e_phnum; i++) {
  586. phdr = &phdrs[i];
  587. if (!q6v5_phdr_valid(phdr))
  588. continue;
  589. if (phdr->p_flags & QCOM_MDT_RELOCATABLE)
  590. relocate = true;
  591. if (phdr->p_paddr < min_addr)
  592. min_addr = phdr->p_paddr;
  593. if (phdr->p_paddr + phdr->p_memsz > max_addr)
  594. max_addr = ALIGN(phdr->p_paddr + phdr->p_memsz, SZ_4K);
  595. }
  596. mpss_reloc = relocate ? min_addr : qproc->mpss_phys;
  597. /* Load firmware segments */
  598. for (i = 0; i < ehdr->e_phnum; i++) {
  599. phdr = &phdrs[i];
  600. if (!q6v5_phdr_valid(phdr))
  601. continue;
  602. offset = phdr->p_paddr - mpss_reloc;
  603. if (offset < 0 || offset + phdr->p_memsz > qproc->mpss_size) {
  604. dev_err(qproc->dev, "segment outside memory range\n");
  605. ret = -EINVAL;
  606. goto release_firmware;
  607. }
  608. ptr = qproc->mpss_region + offset;
  609. if (phdr->p_filesz) {
  610. snprintf(seg_name, sizeof(seg_name), "modem.b%02d", i);
  611. ret = request_firmware(&seg_fw, seg_name, qproc->dev);
  612. if (ret) {
  613. dev_err(qproc->dev, "failed to load %s\n", seg_name);
  614. goto release_firmware;
  615. }
  616. memcpy(ptr, seg_fw->data, seg_fw->size);
  617. release_firmware(seg_fw);
  618. }
  619. if (phdr->p_memsz > phdr->p_filesz) {
  620. memset(ptr + phdr->p_filesz, 0,
  621. phdr->p_memsz - phdr->p_filesz);
  622. }
  623. size += phdr->p_memsz;
  624. }
  625. /* Transfer ownership of modem ddr region to q6 */
  626. ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, true,
  627. qproc->mpss_phys, qproc->mpss_size);
  628. if (ret) {
  629. dev_err(qproc->dev,
  630. "assigning Q6 access to mpss memory failed: %d\n", ret);
  631. ret = -EAGAIN;
  632. goto release_firmware;
  633. }
  634. boot_addr = relocate ? qproc->mpss_phys : min_addr;
  635. writel(boot_addr, qproc->rmb_base + RMB_PMI_CODE_START_REG);
  636. writel(RMB_CMD_LOAD_READY, qproc->rmb_base + RMB_MBA_COMMAND_REG);
  637. writel(size, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG);
  638. ret = q6v5_rmb_mba_wait(qproc, RMB_MBA_AUTH_COMPLETE, 10000);
  639. if (ret == -ETIMEDOUT)
  640. dev_err(qproc->dev, "MPSS authentication timed out\n");
  641. else if (ret < 0)
  642. dev_err(qproc->dev, "MPSS authentication failed: %d\n", ret);
  643. release_firmware:
  644. release_firmware(fw);
  645. return ret < 0 ? ret : 0;
  646. }
  647. static int q6v5_start(struct rproc *rproc)
  648. {
  649. struct q6v5 *qproc = (struct q6v5 *)rproc->priv;
  650. int xfermemop_ret;
  651. int ret;
  652. qcom_q6v5_prepare(&qproc->q6v5);
  653. ret = q6v5_regulator_enable(qproc, qproc->proxy_regs,
  654. qproc->proxy_reg_count);
  655. if (ret) {
  656. dev_err(qproc->dev, "failed to enable proxy supplies\n");
  657. goto disable_irqs;
  658. }
  659. ret = q6v5_clk_enable(qproc->dev, qproc->proxy_clks,
  660. qproc->proxy_clk_count);
  661. if (ret) {
  662. dev_err(qproc->dev, "failed to enable proxy clocks\n");
  663. goto disable_proxy_reg;
  664. }
  665. ret = q6v5_regulator_enable(qproc, qproc->active_regs,
  666. qproc->active_reg_count);
  667. if (ret) {
  668. dev_err(qproc->dev, "failed to enable supplies\n");
  669. goto disable_proxy_clk;
  670. }
  671. ret = q6v5_clk_enable(qproc->dev, qproc->reset_clks,
  672. qproc->reset_clk_count);
  673. if (ret) {
  674. dev_err(qproc->dev, "failed to enable reset clocks\n");
  675. goto disable_vdd;
  676. }
  677. ret = q6v5_reset_deassert(qproc);
  678. if (ret) {
  679. dev_err(qproc->dev, "failed to deassert mss restart\n");
  680. goto disable_reset_clks;
  681. }
  682. ret = q6v5_clk_enable(qproc->dev, qproc->active_clks,
  683. qproc->active_clk_count);
  684. if (ret) {
  685. dev_err(qproc->dev, "failed to enable clocks\n");
  686. goto assert_reset;
  687. }
  688. /* Assign MBA image access in DDR to q6 */
  689. ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, true,
  690. qproc->mba_phys, qproc->mba_size);
  691. if (ret) {
  692. dev_err(qproc->dev,
  693. "assigning Q6 access to mba memory failed: %d\n", ret);
  694. goto disable_active_clks;
  695. }
  696. writel(qproc->mba_phys, qproc->rmb_base + RMB_MBA_IMAGE_REG);
  697. ret = q6v5proc_reset(qproc);
  698. if (ret)
  699. goto reclaim_mba;
  700. ret = q6v5_rmb_mba_wait(qproc, 0, 5000);
  701. if (ret == -ETIMEDOUT) {
  702. dev_err(qproc->dev, "MBA boot timed out\n");
  703. goto halt_axi_ports;
  704. } else if (ret != RMB_MBA_XPU_UNLOCKED &&
  705. ret != RMB_MBA_XPU_UNLOCKED_SCRIBBLED) {
  706. dev_err(qproc->dev, "MBA returned unexpected status %d\n", ret);
  707. ret = -EINVAL;
  708. goto halt_axi_ports;
  709. }
  710. dev_info(qproc->dev, "MBA booted, loading mpss\n");
  711. ret = q6v5_mpss_load(qproc);
  712. if (ret)
  713. goto reclaim_mpss;
  714. ret = qcom_q6v5_wait_for_start(&qproc->q6v5, msecs_to_jiffies(5000));
  715. if (ret == -ETIMEDOUT) {
  716. dev_err(qproc->dev, "start timed out\n");
  717. goto reclaim_mpss;
  718. }
  719. xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false,
  720. qproc->mba_phys,
  721. qproc->mba_size);
  722. if (xfermemop_ret)
  723. dev_err(qproc->dev,
  724. "Failed to reclaim mba buffer system may become unstable\n");
  725. qproc->running = true;
  726. return 0;
  727. reclaim_mpss:
  728. xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm,
  729. false, qproc->mpss_phys,
  730. qproc->mpss_size);
  731. WARN_ON(xfermemop_ret);
  732. halt_axi_ports:
  733. q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_q6);
  734. q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_modem);
  735. q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_nc);
  736. reclaim_mba:
  737. xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false,
  738. qproc->mba_phys,
  739. qproc->mba_size);
  740. if (xfermemop_ret) {
  741. dev_err(qproc->dev,
  742. "Failed to reclaim mba buffer, system may become unstable\n");
  743. }
  744. disable_active_clks:
  745. q6v5_clk_disable(qproc->dev, qproc->active_clks,
  746. qproc->active_clk_count);
  747. assert_reset:
  748. q6v5_reset_assert(qproc);
  749. disable_reset_clks:
  750. q6v5_clk_disable(qproc->dev, qproc->reset_clks,
  751. qproc->reset_clk_count);
  752. disable_vdd:
  753. q6v5_regulator_disable(qproc, qproc->active_regs,
  754. qproc->active_reg_count);
  755. disable_proxy_clk:
  756. q6v5_clk_disable(qproc->dev, qproc->proxy_clks,
  757. qproc->proxy_clk_count);
  758. disable_proxy_reg:
  759. q6v5_regulator_disable(qproc, qproc->proxy_regs,
  760. qproc->proxy_reg_count);
  761. disable_irqs:
  762. qcom_q6v5_unprepare(&qproc->q6v5);
  763. return ret;
  764. }
  765. static int q6v5_stop(struct rproc *rproc)
  766. {
  767. struct q6v5 *qproc = (struct q6v5 *)rproc->priv;
  768. int ret;
  769. u32 val;
  770. qproc->running = false;
  771. ret = qcom_q6v5_request_stop(&qproc->q6v5);
  772. if (ret == -ETIMEDOUT)
  773. dev_err(qproc->dev, "timed out on wait\n");
  774. q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_q6);
  775. q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_modem);
  776. q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_nc);
  777. if (qproc->version == MSS_MSM8996) {
  778. /*
  779. * To avoid high MX current during LPASS/MSS restart.
  780. */
  781. val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  782. val |= Q6SS_CLAMP_IO | QDSP6v56_CLAMP_WL |
  783. QDSP6v56_CLAMP_QMC_MEM;
  784. writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG);
  785. }
  786. ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, false,
  787. qproc->mpss_phys, qproc->mpss_size);
  788. WARN_ON(ret);
  789. q6v5_reset_assert(qproc);
  790. ret = qcom_q6v5_unprepare(&qproc->q6v5);
  791. if (ret) {
  792. q6v5_clk_disable(qproc->dev, qproc->proxy_clks,
  793. qproc->proxy_clk_count);
  794. q6v5_regulator_disable(qproc, qproc->proxy_regs,
  795. qproc->proxy_reg_count);
  796. }
  797. q6v5_clk_disable(qproc->dev, qproc->reset_clks,
  798. qproc->reset_clk_count);
  799. q6v5_clk_disable(qproc->dev, qproc->active_clks,
  800. qproc->active_clk_count);
  801. q6v5_regulator_disable(qproc, qproc->active_regs,
  802. qproc->active_reg_count);
  803. return 0;
  804. }
  805. static void *q6v5_da_to_va(struct rproc *rproc, u64 da, int len)
  806. {
  807. struct q6v5 *qproc = rproc->priv;
  808. int offset;
  809. offset = da - qproc->mpss_reloc;
  810. if (offset < 0 || offset + len > qproc->mpss_size)
  811. return NULL;
  812. return qproc->mpss_region + offset;
  813. }
  814. static const struct rproc_ops q6v5_ops = {
  815. .start = q6v5_start,
  816. .stop = q6v5_stop,
  817. .da_to_va = q6v5_da_to_va,
  818. .load = q6v5_load,
  819. };
  820. static void qcom_msa_handover(struct qcom_q6v5 *q6v5)
  821. {
  822. struct q6v5 *qproc = container_of(q6v5, struct q6v5, q6v5);
  823. q6v5_clk_disable(qproc->dev, qproc->proxy_clks,
  824. qproc->proxy_clk_count);
  825. q6v5_regulator_disable(qproc, qproc->proxy_regs,
  826. qproc->proxy_reg_count);
  827. }
  828. static int q6v5_init_mem(struct q6v5 *qproc, struct platform_device *pdev)
  829. {
  830. struct of_phandle_args args;
  831. struct resource *res;
  832. int ret;
  833. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6");
  834. qproc->reg_base = devm_ioremap_resource(&pdev->dev, res);
  835. if (IS_ERR(qproc->reg_base))
  836. return PTR_ERR(qproc->reg_base);
  837. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rmb");
  838. qproc->rmb_base = devm_ioremap_resource(&pdev->dev, res);
  839. if (IS_ERR(qproc->rmb_base))
  840. return PTR_ERR(qproc->rmb_base);
  841. ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
  842. "qcom,halt-regs", 3, 0, &args);
  843. if (ret < 0) {
  844. dev_err(&pdev->dev, "failed to parse qcom,halt-regs\n");
  845. return -EINVAL;
  846. }
  847. qproc->halt_map = syscon_node_to_regmap(args.np);
  848. of_node_put(args.np);
  849. if (IS_ERR(qproc->halt_map))
  850. return PTR_ERR(qproc->halt_map);
  851. qproc->halt_q6 = args.args[0];
  852. qproc->halt_modem = args.args[1];
  853. qproc->halt_nc = args.args[2];
  854. return 0;
  855. }
  856. static int q6v5_init_clocks(struct device *dev, struct clk **clks,
  857. char **clk_names)
  858. {
  859. int i;
  860. if (!clk_names)
  861. return 0;
  862. for (i = 0; clk_names[i]; i++) {
  863. clks[i] = devm_clk_get(dev, clk_names[i]);
  864. if (IS_ERR(clks[i])) {
  865. int rc = PTR_ERR(clks[i]);
  866. if (rc != -EPROBE_DEFER)
  867. dev_err(dev, "Failed to get %s clock\n",
  868. clk_names[i]);
  869. return rc;
  870. }
  871. }
  872. return i;
  873. }
  874. static int q6v5_init_reset(struct q6v5 *qproc)
  875. {
  876. qproc->mss_restart = devm_reset_control_get_exclusive(qproc->dev,
  877. NULL);
  878. if (IS_ERR(qproc->mss_restart)) {
  879. dev_err(qproc->dev, "failed to acquire mss restart\n");
  880. return PTR_ERR(qproc->mss_restart);
  881. }
  882. return 0;
  883. }
  884. static int q6v5_alloc_memory_region(struct q6v5 *qproc)
  885. {
  886. struct device_node *child;
  887. struct device_node *node;
  888. struct resource r;
  889. int ret;
  890. child = of_get_child_by_name(qproc->dev->of_node, "mba");
  891. node = of_parse_phandle(child, "memory-region", 0);
  892. ret = of_address_to_resource(node, 0, &r);
  893. if (ret) {
  894. dev_err(qproc->dev, "unable to resolve mba region\n");
  895. return ret;
  896. }
  897. of_node_put(node);
  898. qproc->mba_phys = r.start;
  899. qproc->mba_size = resource_size(&r);
  900. qproc->mba_region = devm_ioremap_wc(qproc->dev, qproc->mba_phys, qproc->mba_size);
  901. if (!qproc->mba_region) {
  902. dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n",
  903. &r.start, qproc->mba_size);
  904. return -EBUSY;
  905. }
  906. child = of_get_child_by_name(qproc->dev->of_node, "mpss");
  907. node = of_parse_phandle(child, "memory-region", 0);
  908. ret = of_address_to_resource(node, 0, &r);
  909. if (ret) {
  910. dev_err(qproc->dev, "unable to resolve mpss region\n");
  911. return ret;
  912. }
  913. of_node_put(node);
  914. qproc->mpss_phys = qproc->mpss_reloc = r.start;
  915. qproc->mpss_size = resource_size(&r);
  916. qproc->mpss_region = devm_ioremap_wc(qproc->dev, qproc->mpss_phys, qproc->mpss_size);
  917. if (!qproc->mpss_region) {
  918. dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n",
  919. &r.start, qproc->mpss_size);
  920. return -EBUSY;
  921. }
  922. return 0;
  923. }
  924. static int q6v5_probe(struct platform_device *pdev)
  925. {
  926. const struct rproc_hexagon_res *desc;
  927. struct q6v5 *qproc;
  928. struct rproc *rproc;
  929. int ret;
  930. desc = of_device_get_match_data(&pdev->dev);
  931. if (!desc)
  932. return -EINVAL;
  933. if (desc->need_mem_protection && !qcom_scm_is_available())
  934. return -EPROBE_DEFER;
  935. rproc = rproc_alloc(&pdev->dev, pdev->name, &q6v5_ops,
  936. desc->hexagon_mba_image, sizeof(*qproc));
  937. if (!rproc) {
  938. dev_err(&pdev->dev, "failed to allocate rproc\n");
  939. return -ENOMEM;
  940. }
  941. qproc = (struct q6v5 *)rproc->priv;
  942. qproc->dev = &pdev->dev;
  943. qproc->rproc = rproc;
  944. platform_set_drvdata(pdev, qproc);
  945. ret = q6v5_init_mem(qproc, pdev);
  946. if (ret)
  947. goto free_rproc;
  948. ret = q6v5_alloc_memory_region(qproc);
  949. if (ret)
  950. goto free_rproc;
  951. ret = q6v5_init_clocks(&pdev->dev, qproc->proxy_clks,
  952. desc->proxy_clk_names);
  953. if (ret < 0) {
  954. dev_err(&pdev->dev, "Failed to get proxy clocks.\n");
  955. goto free_rproc;
  956. }
  957. qproc->proxy_clk_count = ret;
  958. ret = q6v5_init_clocks(&pdev->dev, qproc->reset_clks,
  959. desc->reset_clk_names);
  960. if (ret < 0) {
  961. dev_err(&pdev->dev, "Failed to get reset clocks.\n");
  962. goto free_rproc;
  963. }
  964. qproc->reset_clk_count = ret;
  965. ret = q6v5_init_clocks(&pdev->dev, qproc->active_clks,
  966. desc->active_clk_names);
  967. if (ret < 0) {
  968. dev_err(&pdev->dev, "Failed to get active clocks.\n");
  969. goto free_rproc;
  970. }
  971. qproc->active_clk_count = ret;
  972. ret = q6v5_regulator_init(&pdev->dev, qproc->proxy_regs,
  973. desc->proxy_supply);
  974. if (ret < 0) {
  975. dev_err(&pdev->dev, "Failed to get proxy regulators.\n");
  976. goto free_rproc;
  977. }
  978. qproc->proxy_reg_count = ret;
  979. ret = q6v5_regulator_init(&pdev->dev, qproc->active_regs,
  980. desc->active_supply);
  981. if (ret < 0) {
  982. dev_err(&pdev->dev, "Failed to get active regulators.\n");
  983. goto free_rproc;
  984. }
  985. qproc->active_reg_count = ret;
  986. ret = q6v5_init_reset(qproc);
  987. if (ret)
  988. goto free_rproc;
  989. qproc->version = desc->version;
  990. qproc->has_alt_reset = desc->has_alt_reset;
  991. qproc->need_mem_protection = desc->need_mem_protection;
  992. ret = qcom_q6v5_init(&qproc->q6v5, pdev, rproc, MPSS_CRASH_REASON_SMEM,
  993. qcom_msa_handover);
  994. if (ret)
  995. goto free_rproc;
  996. qproc->mpss_perm = BIT(QCOM_SCM_VMID_HLOS);
  997. qproc->mba_perm = BIT(QCOM_SCM_VMID_HLOS);
  998. qcom_add_glink_subdev(rproc, &qproc->glink_subdev);
  999. qcom_add_smd_subdev(rproc, &qproc->smd_subdev);
  1000. qcom_add_ssr_subdev(rproc, &qproc->ssr_subdev, "mpss");
  1001. qproc->sysmon = qcom_add_sysmon_subdev(rproc, "modem", 0x12);
  1002. ret = rproc_add(rproc);
  1003. if (ret)
  1004. goto free_rproc;
  1005. return 0;
  1006. free_rproc:
  1007. rproc_free(rproc);
  1008. return ret;
  1009. }
  1010. static int q6v5_remove(struct platform_device *pdev)
  1011. {
  1012. struct q6v5 *qproc = platform_get_drvdata(pdev);
  1013. rproc_del(qproc->rproc);
  1014. qcom_remove_sysmon_subdev(qproc->sysmon);
  1015. qcom_remove_glink_subdev(qproc->rproc, &qproc->glink_subdev);
  1016. qcom_remove_smd_subdev(qproc->rproc, &qproc->smd_subdev);
  1017. qcom_remove_ssr_subdev(qproc->rproc, &qproc->ssr_subdev);
  1018. rproc_free(qproc->rproc);
  1019. return 0;
  1020. }
  1021. static const struct rproc_hexagon_res sdm845_mss = {
  1022. .hexagon_mba_image = "mba.mbn",
  1023. .proxy_clk_names = (char*[]){
  1024. "xo",
  1025. "prng",
  1026. NULL
  1027. },
  1028. .reset_clk_names = (char*[]){
  1029. "iface",
  1030. "snoc_axi",
  1031. NULL
  1032. },
  1033. .active_clk_names = (char*[]){
  1034. "bus",
  1035. "mem",
  1036. "gpll0_mss",
  1037. "mnoc_axi",
  1038. NULL
  1039. },
  1040. .need_mem_protection = true,
  1041. .has_alt_reset = true,
  1042. .version = MSS_SDM845,
  1043. };
  1044. static const struct rproc_hexagon_res msm8996_mss = {
  1045. .hexagon_mba_image = "mba.mbn",
  1046. .proxy_supply = (struct qcom_mss_reg_res[]) {
  1047. {
  1048. .supply = "pll",
  1049. .uA = 100000,
  1050. },
  1051. {}
  1052. },
  1053. .proxy_clk_names = (char*[]){
  1054. "xo",
  1055. "pnoc",
  1056. "qdss",
  1057. NULL
  1058. },
  1059. .active_clk_names = (char*[]){
  1060. "iface",
  1061. "bus",
  1062. "mem",
  1063. "gpll0_mss",
  1064. "snoc_axi",
  1065. "mnoc_axi",
  1066. NULL
  1067. },
  1068. .need_mem_protection = true,
  1069. .has_alt_reset = false,
  1070. .version = MSS_MSM8996,
  1071. };
  1072. static const struct rproc_hexagon_res msm8916_mss = {
  1073. .hexagon_mba_image = "mba.mbn",
  1074. .proxy_supply = (struct qcom_mss_reg_res[]) {
  1075. {
  1076. .supply = "mx",
  1077. .uV = 1050000,
  1078. },
  1079. {
  1080. .supply = "cx",
  1081. .uA = 100000,
  1082. },
  1083. {
  1084. .supply = "pll",
  1085. .uA = 100000,
  1086. },
  1087. {}
  1088. },
  1089. .proxy_clk_names = (char*[]){
  1090. "xo",
  1091. NULL
  1092. },
  1093. .active_clk_names = (char*[]){
  1094. "iface",
  1095. "bus",
  1096. "mem",
  1097. NULL
  1098. },
  1099. .need_mem_protection = false,
  1100. .has_alt_reset = false,
  1101. .version = MSS_MSM8916,
  1102. };
  1103. static const struct rproc_hexagon_res msm8974_mss = {
  1104. .hexagon_mba_image = "mba.b00",
  1105. .proxy_supply = (struct qcom_mss_reg_res[]) {
  1106. {
  1107. .supply = "mx",
  1108. .uV = 1050000,
  1109. },
  1110. {
  1111. .supply = "cx",
  1112. .uA = 100000,
  1113. },
  1114. {
  1115. .supply = "pll",
  1116. .uA = 100000,
  1117. },
  1118. {}
  1119. },
  1120. .active_supply = (struct qcom_mss_reg_res[]) {
  1121. {
  1122. .supply = "mss",
  1123. .uV = 1050000,
  1124. .uA = 100000,
  1125. },
  1126. {}
  1127. },
  1128. .proxy_clk_names = (char*[]){
  1129. "xo",
  1130. NULL
  1131. },
  1132. .active_clk_names = (char*[]){
  1133. "iface",
  1134. "bus",
  1135. "mem",
  1136. NULL
  1137. },
  1138. .need_mem_protection = false,
  1139. .has_alt_reset = false,
  1140. .version = MSS_MSM8974,
  1141. };
  1142. static const struct of_device_id q6v5_of_match[] = {
  1143. { .compatible = "qcom,q6v5-pil", .data = &msm8916_mss},
  1144. { .compatible = "qcom,msm8916-mss-pil", .data = &msm8916_mss},
  1145. { .compatible = "qcom,msm8974-mss-pil", .data = &msm8974_mss},
  1146. { .compatible = "qcom,msm8996-mss-pil", .data = &msm8996_mss},
  1147. { .compatible = "qcom,sdm845-mss-pil", .data = &sdm845_mss},
  1148. { },
  1149. };
  1150. MODULE_DEVICE_TABLE(of, q6v5_of_match);
  1151. static struct platform_driver q6v5_driver = {
  1152. .probe = q6v5_probe,
  1153. .remove = q6v5_remove,
  1154. .driver = {
  1155. .name = "qcom-q6v5-pil",
  1156. .of_match_table = q6v5_of_match,
  1157. },
  1158. };
  1159. module_platform_driver(q6v5_driver);
  1160. MODULE_DESCRIPTION("Peripheral Image Loader for Hexagon");
  1161. MODULE_LICENSE("GPL v2");