omap_remoteproc.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  1. /*
  2. * OMAP Remote Processor driver
  3. *
  4. * Copyright (C) 2011-2016 Texas Instruments Incorporated - http://www.ti.com/
  5. * Copyright (C) 2011 Google, Inc.
  6. *
  7. * Ohad Ben-Cohen <ohad@wizery.com>
  8. * Brian Swetland <swetland@google.com>
  9. * Fernando Guzman Lugo <fernando.lugo@ti.com>
  10. * Mark Grosen <mgrosen@ti.com>
  11. * Suman Anna <s-anna@ti.com>
  12. * Hari Kanigeri <h-kanigeri2@ti.com>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * version 2 as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/err.h>
  26. #include <linux/io.h>
  27. #include <linux/of_device.h>
  28. #include <linux/of_address.h>
  29. #include <linux/of_reserved_mem.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/remoteproc.h>
  34. #include <linux/mailbox_client.h>
  35. #include <linux/omap-mailbox.h>
  36. #include <linux/omap-iommu.h>
  37. #include <linux/regmap.h>
  38. #include <linux/mfd/syscon.h>
  39. #include <linux/pm_runtime.h>
  40. #include <linux/platform_data/remoteproc-omap.h>
  41. #include "omap_remoteproc.h"
  42. #include "remoteproc_internal.h"
  43. #define OMAP_RPROC_DSP_LOCAL_MEM_OFFSET (0x00800000)
  44. #define OMAP_RPROC_IPU_L2RAM_DEV_ADDR (0x20000000)
  45. /* default auto-suspend delay (ms) */
  46. #define DEFAULT_AUTOSUSPEND_DELAY 10000
  47. /**
  48. * struct omap_rproc_boot_data - boot data structure for the DSP omap rprocs
  49. * @syscon: regmap handle for the system control configuration module
  50. * @boot_reg: boot register offset within the @syscon regmap
  51. * @boot_reg_shift: bit-field shift required for the boot address value in
  52. * @boot_reg
  53. */
  54. struct omap_rproc_boot_data {
  55. struct regmap *syscon;
  56. unsigned int boot_reg;
  57. unsigned int boot_reg_shift;
  58. };
  59. /**
  60. * struct omap_rproc_mem - internal memory structure
  61. * @cpu_addr: MPU virtual address of the memory region
  62. * @bus_addr: bus address used to access the memory region
  63. * @dev_addr: device address of the memory region from DSP view
  64. * @size: size of the memory region
  65. */
  66. struct omap_rproc_mem {
  67. void __iomem *cpu_addr;
  68. phys_addr_t bus_addr;
  69. u32 dev_addr;
  70. size_t size;
  71. };
  72. /**
  73. * struct omap_rproc_timers_info - timers for the omap rproc
  74. * @odt: timer pointer
  75. * @irq: timer irq
  76. */
  77. struct omap_rproc_timers_info {
  78. struct omap_dm_timer *odt;
  79. int irq;
  80. };
  81. /**
  82. * struct omap_rproc - omap remote processor state
  83. * @mbox: mailbox channel handle
  84. * @client: mailbox client to request the mailbox channel
  85. * @boot_data: boot data structure for setting processor boot address
  86. * @mem: internal memory regions data
  87. * @num_mems: number of internal memory regions
  88. * @num_timers: number of rproc timer(s)
  89. * @num_wd_timers: number of rproc watchdog timers
  90. * @timers: timer(s) info used by rproc
  91. * @autosuspend_delay: auto-suspend delay value to be used for runtime pm
  92. * @need_resume: if true a resume is needed in the system resume callback
  93. * @rproc: rproc handle
  94. * @pm_comp: completion primitive to sync for suspend response
  95. * @standby_addr: kernel address of the register having module standby status
  96. * @suspend_acked: state machine flag to store the suspend request ack
  97. */
  98. struct omap_rproc {
  99. struct mbox_chan *mbox;
  100. struct mbox_client client;
  101. struct omap_rproc_boot_data *boot_data;
  102. struct omap_rproc_mem *mem;
  103. int num_mems;
  104. int num_timers;
  105. int num_wd_timers;
  106. struct omap_rproc_timers_info *timers;
  107. int autosuspend_delay;
  108. bool need_resume;
  109. struct rproc *rproc;
  110. struct completion pm_comp;
  111. void __iomem *standby_addr;
  112. bool suspend_acked;
  113. };
  114. /**
  115. * struct omap_rproc_dev_data - device data for the omap remote processor
  116. * @device_name: device name of the remote processor
  117. * @fw_name: firmware name to use
  118. * @autosuspend_delay: custom auto-suspend delay value in milliseconds
  119. */
  120. struct omap_rproc_dev_data {
  121. const char *device_name;
  122. const char *fw_name;
  123. int autosuspend_delay;
  124. };
  125. /**
  126. * omap_rproc_watchdog_isr - Watchdog ISR handler for remoteproc device
  127. * @irq: IRQ number associated with a watchdog timer
  128. * @data: IRQ handler data
  129. *
  130. * This ISR routine executes the required necessary low-level code to
  131. * acknowledge a watchdog timer interrupt. There can be multiple watchdog
  132. * timers associated with a rproc (like IPUs which have 2 watchdog timers,
  133. * one per Cortex M3/M4 core), so a lookup has to be performed to identify
  134. * the timer to acknowledge its interrupt.
  135. *
  136. * The function also invokes rproc_report_crash to report the watchdog event
  137. * to the remoteproc driver core, to trigger a recovery.
  138. *
  139. * Return: IRQ_HANDLED or IRQ_NONE
  140. */
  141. static irqreturn_t omap_rproc_watchdog_isr(int irq, void *data)
  142. {
  143. struct platform_device *pdev = data;
  144. struct rproc *rproc = platform_get_drvdata(pdev);
  145. struct omap_rproc *oproc = rproc->priv;
  146. struct device *dev = &pdev->dev;
  147. struct omap_rproc_pdata *pdata = dev->platform_data;
  148. struct omap_rproc_timer_ops *timer_ops = pdata->timer_ops;
  149. struct omap_rproc_timers_info *timers = oproc->timers;
  150. struct omap_dm_timer *timer = NULL;
  151. int num_timers = oproc->num_timers + oproc->num_wd_timers;
  152. int i;
  153. for (i = oproc->num_timers; i < num_timers; i++) {
  154. if (timers[i].irq > 0 && irq == timers[i].irq) {
  155. timer = timers[i].odt;
  156. break;
  157. }
  158. }
  159. if (!timer) {
  160. dev_err(dev, "invalid timer\n");
  161. return IRQ_NONE;
  162. }
  163. timer_ops->ack_timer_irq(timer);
  164. rproc_report_crash(rproc, RPROC_WATCHDOG);
  165. return IRQ_HANDLED;
  166. }
  167. /**
  168. * omap_rproc_enable_timers - enable the timers for a remoteproc
  169. * @pdev - the remoteproc platform device
  170. * @configure - boolean flag used to acquire and configure the timer handle
  171. *
  172. * This function is used primarily to enable the timers associated with
  173. * a remoteproc. The configure flag is provided to allow the remoteproc
  174. * driver core to either acquire and start a timer (during device
  175. * initialization) or to just start a timer (during a resume operation).
  176. */
  177. static int
  178. omap_rproc_enable_timers(struct platform_device *pdev, bool configure)
  179. {
  180. int i;
  181. int ret = 0;
  182. struct rproc *rproc = platform_get_drvdata(pdev);
  183. struct omap_rproc *oproc = rproc->priv;
  184. struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
  185. struct omap_rproc_timer_ops *timer_ops = pdata->timer_ops;
  186. struct omap_rproc_timers_info *timers = oproc->timers;
  187. struct device *dev = &pdev->dev;
  188. struct device_node *np = NULL;
  189. int num_timers = oproc->num_timers + oproc->num_wd_timers;
  190. if (num_timers <= 0)
  191. return 0;
  192. if (!configure)
  193. goto start_timers;
  194. for (i = 0; i < num_timers; i++) {
  195. if (i < oproc->num_timers)
  196. np = of_parse_phandle(dev->of_node, "timers", i);
  197. else
  198. np = of_parse_phandle(dev->of_node, "watchdog-timers",
  199. (i - oproc->num_timers));
  200. if (!np) {
  201. ret = -ENXIO;
  202. dev_err(dev, "device node lookup for timer at index %d failed: %d\n",
  203. i < oproc->num_timers ? i :
  204. i - oproc->num_timers, ret);
  205. goto free_timers;
  206. }
  207. timers[i].irq = -1;
  208. timers[i].odt = timer_ops->request_timer(np);
  209. of_node_put(np);
  210. if (IS_ERR(timers[i].odt)) {
  211. dev_err(dev, "request for timer %p failed: %ld\n", np,
  212. PTR_ERR(timers[i].odt));
  213. ret = -EBUSY;
  214. goto free_timers;
  215. }
  216. if (i >= oproc->num_timers) {
  217. timers[i].irq = timer_ops->get_timer_irq(timers[i].odt);
  218. if (timers[i].irq < 0) {
  219. dev_err(dev, "get_irq for timer %p failed: %d\n",
  220. np, timers[i].irq);
  221. ret = -EBUSY;
  222. goto free_timers;
  223. }
  224. ret = request_irq(timers[i].irq,
  225. omap_rproc_watchdog_isr, IRQF_SHARED,
  226. "rproc-wdt", pdev);
  227. if (ret) {
  228. dev_err(&pdev->dev, "error requesting irq for timer %p\n",
  229. np);
  230. timer_ops->release_timer(timers[i].odt);
  231. timers[i].odt = NULL;
  232. timers[i].irq = -1;
  233. goto free_timers;
  234. }
  235. }
  236. }
  237. start_timers:
  238. for (i = 0; i < num_timers; i++)
  239. timer_ops->start_timer(timers[i].odt);
  240. return 0;
  241. free_timers:
  242. while (i--) {
  243. if (i >= oproc->num_timers)
  244. free_irq(timers[i].irq, pdev);
  245. timer_ops->release_timer(timers[i].odt);
  246. timers[i].odt = NULL;
  247. timers[i].irq = -1;
  248. }
  249. return ret;
  250. }
  251. /**
  252. * omap_rproc_disable_timers - disable the timers for a remoteproc
  253. * @pdev - the remoteproc platform device
  254. * @configure - boolean flag used to release the timer handle
  255. *
  256. * This function is used primarily to disable the timers associated with
  257. * a remoteproc. The configure flag is provided to allow the remoteproc
  258. * driver core to either stop and release a timer (during device shutdown)
  259. * or to just stop a timer (during a suspend operation).
  260. */
  261. static int
  262. omap_rproc_disable_timers(struct platform_device *pdev, bool configure)
  263. {
  264. int i;
  265. struct rproc *rproc = platform_get_drvdata(pdev);
  266. struct omap_rproc *oproc = rproc->priv;
  267. struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
  268. struct omap_rproc_timer_ops *timer_ops = pdata->timer_ops;
  269. struct omap_rproc_timers_info *timers = oproc->timers;
  270. int num_timers = oproc->num_timers + oproc->num_wd_timers;
  271. if (num_timers <= 0)
  272. return 0;
  273. for (i = 0; i < num_timers; i++) {
  274. timer_ops->stop_timer(timers[i].odt);
  275. if (configure) {
  276. if (i >= oproc->num_timers)
  277. free_irq(timers[i].irq, pdev);
  278. timer_ops->release_timer(timers[i].odt);
  279. timers[i].odt = NULL;
  280. timers[i].irq = -1;
  281. }
  282. }
  283. return 0;
  284. }
  285. /**
  286. * omap_rproc_mbox_callback() - inbound mailbox message handler
  287. * @client: mailbox client pointer used for requesting the mailbox channel
  288. * @data: mailbox payload
  289. *
  290. * This handler is invoked by omap's mailbox driver whenever a mailbox
  291. * message is received. Usually, the mailbox payload simply contains
  292. * the index of the virtqueue that is kicked by the remote processor,
  293. * and we let remoteproc core handle it.
  294. *
  295. * In addition to virtqueue indices, we also have some out-of-band values
  296. * that indicates different events. Those values are deliberately very
  297. * big so they don't coincide with virtqueue indices.
  298. */
  299. static void omap_rproc_mbox_callback(struct mbox_client *client, void *data)
  300. {
  301. struct omap_rproc *oproc = container_of(client, struct omap_rproc,
  302. client);
  303. struct device *dev = oproc->rproc->dev.parent;
  304. const char *name = oproc->rproc->name;
  305. u32 msg = (u32)data;
  306. dev_dbg(dev, "mbox msg: 0x%x\n", msg);
  307. switch (msg) {
  308. case RP_MBOX_CRASH:
  309. /*
  310. * remoteproc detected an exception, notify the rproc core.
  311. * The remoteproc core will handle the recovery.
  312. */
  313. dev_err(dev, "omap rproc %s crashed\n", name);
  314. rproc_report_crash(oproc->rproc, RPROC_FATAL_ERROR);
  315. break;
  316. case RP_MBOX_ECHO_REPLY:
  317. dev_info(dev, "received echo reply from %s\n", name);
  318. break;
  319. case RP_MBOX_SUSPEND_ACK:
  320. case RP_MBOX_SUSPEND_CANCEL:
  321. oproc->suspend_acked = msg == RP_MBOX_SUSPEND_ACK;
  322. complete(&oproc->pm_comp);
  323. break;
  324. default:
  325. if (msg >= RP_MBOX_END_MSG) {
  326. dev_err(dev, "dropping unknown message 0x%x", msg);
  327. return;
  328. }
  329. /* msg contains the index of the triggered vring */
  330. if (rproc_vq_interrupt(oproc->rproc, msg) == IRQ_NONE)
  331. dev_dbg(dev, "no message was found in vqid %d\n", msg);
  332. }
  333. }
  334. /* kick a virtqueue */
  335. static void omap_rproc_kick(struct rproc *rproc, int vqid)
  336. {
  337. struct omap_rproc *oproc = rproc->priv;
  338. struct device *dev = rproc->dev.parent;
  339. int ret;
  340. /* wake up the rproc before kicking it */
  341. ret = pm_runtime_get_sync(dev);
  342. if (WARN_ON(ret < 0)) {
  343. dev_err(dev, "pm_runtime_get_sync() failed during kick, ret = %d\n",
  344. ret);
  345. pm_runtime_put_noidle(dev);
  346. return;
  347. }
  348. /* send the index of the triggered virtqueue in the mailbox payload */
  349. ret = mbox_send_message(oproc->mbox, (void *)vqid);
  350. if (ret < 0)
  351. dev_err(dev, "failed to send mailbox message, status = %d\n",
  352. ret);
  353. pm_runtime_mark_last_busy(dev);
  354. pm_runtime_put_autosuspend(dev);
  355. }
  356. /**
  357. * omap_rproc_write_dsp_boot_addr - set boot address for a DSP remote processor
  358. * @rproc: handle of a remote processor
  359. *
  360. * Set boot address for a supported DSP remote processor.
  361. */
  362. static int omap_rproc_write_dsp_boot_addr(struct rproc *rproc)
  363. {
  364. struct device *dev = rproc->dev.parent;
  365. struct omap_rproc *oproc = rproc->priv;
  366. struct omap_rproc_boot_data *bdata = oproc->boot_data;
  367. u32 offset = bdata->boot_reg;
  368. unsigned int value = rproc->bootaddr;
  369. unsigned int mask = ~(SZ_1K - 1);
  370. if (value & (SZ_1K - 1)) {
  371. dev_err(dev, "invalid boot address 0x%x, must be aligned on a 1KB boundary\n",
  372. value);
  373. return -EINVAL;
  374. }
  375. value >>= bdata->boot_reg_shift;
  376. mask >>= bdata->boot_reg_shift;
  377. regmap_update_bits(bdata->syscon, offset, mask, value);
  378. return 0;
  379. }
  380. /*
  381. * Power up the remote processor.
  382. *
  383. * This function will be invoked only after the firmware for this rproc
  384. * was loaded, parsed successfully, and all of its resource requirements
  385. * were met.
  386. */
  387. static int omap_rproc_start(struct rproc *rproc)
  388. {
  389. struct omap_rproc *oproc = rproc->priv;
  390. struct device *dev = rproc->dev.parent;
  391. struct platform_device *pdev = to_platform_device(dev);
  392. struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
  393. int ret;
  394. struct mbox_client *client = &oproc->client;
  395. if (oproc->boot_data) {
  396. ret = omap_rproc_write_dsp_boot_addr(rproc);
  397. if (ret)
  398. return ret;
  399. }
  400. client->dev = dev;
  401. client->tx_done = NULL;
  402. client->rx_callback = omap_rproc_mbox_callback;
  403. client->tx_block = false;
  404. client->knows_txdone = false;
  405. oproc->mbox = mbox_request_channel(client, 0);
  406. if (IS_ERR(oproc->mbox)) {
  407. ret = -EBUSY;
  408. dev_err(dev, "mbox_request_channel failed: %ld\n",
  409. PTR_ERR(oproc->mbox));
  410. return ret;
  411. }
  412. /*
  413. * Ping the remote processor. this is only for sanity-sake;
  414. * there is no functional effect whatsoever.
  415. *
  416. * Note that the reply will _not_ arrive immediately: this message
  417. * will wait in the mailbox fifo until the remote processor is booted.
  418. */
  419. ret = mbox_send_message(oproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
  420. if (ret < 0) {
  421. dev_err(dev, "mbox_send_message failed: %d\n", ret);
  422. goto put_mbox;
  423. }
  424. ret = omap_rproc_enable_timers(pdev, true);
  425. if (ret) {
  426. dev_err(dev, "omap_rproc_enable_timers failed: %d\n", ret);
  427. goto put_mbox;
  428. }
  429. ret = pdata->device_enable(pdev);
  430. if (ret) {
  431. dev_err(dev, "omap_device_enable failed: %d\n", ret);
  432. goto reset_timers;
  433. }
  434. /*
  435. * remote processor is up, so update the runtime pm status and
  436. * enable the auto-suspend. The device usage count is incremented
  437. * manually for balancing it for auto-suspend
  438. */
  439. pm_runtime_set_active(dev);
  440. pm_runtime_set_autosuspend_delay(dev, oproc->autosuspend_delay);
  441. pm_runtime_use_autosuspend(dev);
  442. pm_runtime_get_noresume(dev);
  443. pm_runtime_enable(dev);
  444. pm_runtime_mark_last_busy(dev);
  445. pm_runtime_put_autosuspend(dev);
  446. return 0;
  447. reset_timers:
  448. omap_rproc_disable_timers(pdev, true);
  449. put_mbox:
  450. mbox_free_channel(oproc->mbox);
  451. return ret;
  452. }
  453. /* power off the remote processor */
  454. static int omap_rproc_stop(struct rproc *rproc)
  455. {
  456. struct device *dev = rproc->dev.parent;
  457. struct platform_device *pdev = to_platform_device(dev);
  458. struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
  459. struct omap_rproc *oproc = rproc->priv;
  460. int ret;
  461. /*
  462. * cancel any possible scheduled runtime suspend by incrementing
  463. * the device usage count, and resuming the device. The remoteproc
  464. * also needs to be woken up if suspended, to avoid the remoteproc
  465. * OS to continue to remember any context that it has saved, and
  466. * avoid potential issues in misindentifying a subsequent device
  467. * reboot as a power restore boot
  468. */
  469. ret = pm_runtime_get_sync(dev);
  470. if (ret < 0) {
  471. pm_runtime_put_noidle(dev);
  472. return ret;
  473. }
  474. ret = pdata->device_shutdown(pdev);
  475. if (ret)
  476. goto out;
  477. ret = omap_rproc_disable_timers(pdev, true);
  478. if (ret)
  479. goto enable_device;
  480. mbox_free_channel(oproc->mbox);
  481. /*
  482. * update the runtime pm states and status now that the remoteproc
  483. * has stopped
  484. */
  485. pm_runtime_disable(dev);
  486. pm_runtime_dont_use_autosuspend(dev);
  487. pm_runtime_put_noidle(dev);
  488. pm_runtime_set_suspended(dev);
  489. return 0;
  490. enable_device:
  491. pdata->device_enable(pdev);
  492. out:
  493. /* schedule the next auto-suspend */
  494. pm_runtime_mark_last_busy(dev);
  495. pm_runtime_put_autosuspend(dev);
  496. return ret;
  497. }
  498. /*
  499. * Internal Memory translation helper
  500. *
  501. * Custom function implementing the rproc .da_to_va ops to provide address
  502. * translation (device address to kernel virtual address) for internal RAMs
  503. * present in a DSP or IPU device). The translated addresses can be used
  504. * either by the remoteproc core for loading, or by any rpmsg bus drivers.
  505. */
  506. static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, int len,
  507. u32 flags)
  508. {
  509. struct omap_rproc *oproc = rproc->priv;
  510. void *va = NULL;
  511. int i;
  512. u32 offset;
  513. if (len <= 0)
  514. return NULL;
  515. if (!oproc->num_mems)
  516. return NULL;
  517. for (i = 0; i < oproc->num_mems; i++) {
  518. if (da >= oproc->mem[i].dev_addr && da + len <=
  519. oproc->mem[i].dev_addr + oproc->mem[i].size) {
  520. offset = da - oproc->mem[i].dev_addr;
  521. /* __force to make sparse happy with type conversion */
  522. va = (__force void *)(oproc->mem[i].cpu_addr + offset);
  523. break;
  524. }
  525. }
  526. return va;
  527. }
  528. static const struct rproc_ops omap_rproc_ops = {
  529. .start = omap_rproc_start,
  530. .stop = omap_rproc_stop,
  531. .kick = omap_rproc_kick,
  532. .da_to_va = omap_rproc_da_to_va,
  533. };
  534. #ifdef CONFIG_PM
  535. static bool _is_rproc_in_standby(struct omap_rproc *oproc)
  536. {
  537. static int standby_mask = (1 << 18);
  538. return readl(oproc->standby_addr) & standby_mask;
  539. }
  540. /* 1 sec is long enough time to let the remoteproc side suspend the device */
  541. #define DEF_SUSPEND_TIMEOUT 1000
  542. static int _omap_rproc_suspend(struct rproc *rproc, bool auto_suspend)
  543. {
  544. struct device *dev = rproc->dev.parent;
  545. struct platform_device *pdev = to_platform_device(dev);
  546. struct omap_rproc_pdata *pdata = dev_get_platdata(dev);
  547. struct omap_rproc *oproc = rproc->priv;
  548. unsigned long to = msecs_to_jiffies(DEF_SUSPEND_TIMEOUT);
  549. unsigned long ta = jiffies + to;
  550. u32 suspend_msg = auto_suspend ?
  551. RP_MBOX_SUSPEND_AUTO : RP_MBOX_SUSPEND_SYSTEM;
  552. int ret;
  553. reinit_completion(&oproc->pm_comp);
  554. oproc->suspend_acked = false;
  555. ret = mbox_send_message(oproc->mbox, (void *)suspend_msg);
  556. if (ret < 0) {
  557. dev_err(dev, "PM mbox_send_message failed: %d\n", ret);
  558. return ret;
  559. }
  560. ret = wait_for_completion_timeout(&oproc->pm_comp, to);
  561. if (!oproc->suspend_acked)
  562. return -EBUSY;
  563. /*
  564. * The remoteproc side is returning the ACK message before saving the
  565. * context, because the context saving is performed within a SYS/BIOS
  566. * function, and it cannot have any inter-dependencies against the IPC
  567. * layer. Also, as the SYS/BIOS needs to preserve properly the processor
  568. * register set, sending this ACK or signalling the completion of the
  569. * context save through a shared memory variable can never be the
  570. * absolute last thing to be executed on the remoteproc side, and the
  571. * MPU cannot use the ACK message as a sync point to put the remoteproc
  572. * into reset. The only way to ensure that the remote processor has
  573. * completed saving the context is to check that the module has reached
  574. * STANDBY state (after saving the context, the SYS/BIOS executes the
  575. * appropriate target-specific WFI instruction causing the module to
  576. * enter STANDBY).
  577. */
  578. while (!_is_rproc_in_standby(oproc)) {
  579. if (time_after(jiffies, ta))
  580. return -ETIME;
  581. schedule();
  582. }
  583. ret = pdata->device_shutdown(pdev);
  584. if (ret)
  585. return ret;
  586. ret = omap_rproc_disable_timers(pdev, false);
  587. if (ret) {
  588. dev_err(dev, "disabling timers during suspend failed %d\n",
  589. ret);
  590. goto enable_device;
  591. }
  592. /*
  593. * IOMMUs would have to be disabled specifically for runtime suspend.
  594. * They are handled automatically through System PM callbacks for
  595. * regular system suspend
  596. */
  597. if (auto_suspend) {
  598. ret = omap_iommu_domain_deactivate(rproc->domain);
  599. if (ret) {
  600. dev_err(dev, "iommu domain deactivate failed %d\n",
  601. ret);
  602. goto enable_timers;
  603. }
  604. }
  605. return 0;
  606. enable_timers:
  607. /* ignore errors on re-enabling code */
  608. omap_rproc_enable_timers(pdev, false);
  609. enable_device:
  610. pdata->device_enable(pdev);
  611. return ret;
  612. }
  613. static int _omap_rproc_resume(struct rproc *rproc, bool auto_suspend)
  614. {
  615. struct device *dev = rproc->dev.parent;
  616. struct platform_device *pdev = to_platform_device(dev);
  617. struct omap_rproc_pdata *pdata = dev_get_platdata(dev);
  618. struct omap_rproc *oproc = rproc->priv;
  619. int ret;
  620. /*
  621. * IOMMUs would have to be enabled specifically for runtime resume.
  622. * They would have been already enabled automatically through System
  623. * PM callbacks for regular system resume
  624. */
  625. if (auto_suspend) {
  626. ret = omap_iommu_domain_activate(rproc->domain);
  627. if (ret) {
  628. dev_err(dev, "omap_iommu activate failed %d\n", ret);
  629. goto out;
  630. }
  631. }
  632. /* boot address could be lost after suspend, so restore it */
  633. if (oproc->boot_data) {
  634. ret = omap_rproc_write_dsp_boot_addr(rproc);
  635. if (ret) {
  636. dev_err(dev, "boot address restore failed %d\n", ret);
  637. goto suspend_iommu;
  638. }
  639. }
  640. ret = omap_rproc_enable_timers(pdev, false);
  641. if (ret) {
  642. dev_err(dev, "enabling timers during resume failed %d\n",
  643. ret);
  644. goto suspend_iommu;
  645. }
  646. ret = pdata->device_enable(pdev);
  647. if (ret)
  648. goto disable_timers;
  649. return 0;
  650. disable_timers:
  651. omap_rproc_disable_timers(pdev, false);
  652. suspend_iommu:
  653. if (auto_suspend)
  654. omap_iommu_domain_deactivate(rproc->domain);
  655. out:
  656. return ret;
  657. }
  658. #ifdef CONFIG_PM_SLEEP
  659. static int omap_rproc_suspend(struct device *dev)
  660. {
  661. struct platform_device *pdev = to_platform_device(dev);
  662. struct rproc *rproc = platform_get_drvdata(pdev);
  663. struct omap_rproc *oproc = rproc->priv;
  664. int ret = 0;
  665. mutex_lock(&rproc->lock);
  666. if (rproc->state == RPROC_OFFLINE)
  667. goto out;
  668. if (rproc->state == RPROC_SUSPENDED)
  669. goto out;
  670. if (rproc->state != RPROC_RUNNING) {
  671. ret = -EBUSY;
  672. goto out;
  673. }
  674. ret = _omap_rproc_suspend(rproc, false);
  675. if (ret) {
  676. dev_err(dev, "suspend failed %d\n", ret);
  677. goto out;
  678. }
  679. /*
  680. * remoteproc is running at the time of system suspend, so remember
  681. * it so as to wake it up during system resume
  682. */
  683. oproc->need_resume = 1;
  684. rproc->state = RPROC_SUSPENDED;
  685. /*
  686. * update the runtime pm status to be suspended, without decrementing
  687. * the device usage count
  688. */
  689. pm_runtime_disable(dev);
  690. pm_runtime_set_suspended(dev);
  691. out:
  692. mutex_unlock(&rproc->lock);
  693. return ret;
  694. }
  695. static int omap_rproc_resume(struct device *dev)
  696. {
  697. struct platform_device *pdev = to_platform_device(dev);
  698. struct rproc *rproc = platform_get_drvdata(pdev);
  699. struct omap_rproc *oproc = rproc->priv;
  700. int ret = 0;
  701. mutex_lock(&rproc->lock);
  702. if (rproc->state == RPROC_OFFLINE)
  703. goto out;
  704. if (rproc->state != RPROC_SUSPENDED) {
  705. ret = -EBUSY;
  706. goto out;
  707. }
  708. /*
  709. * remoteproc was auto-suspended at the time of system suspend,
  710. * so no need to wake-up the processor (leave it in suspended
  711. * state, will be woken up during a subsequent runtime_resume)
  712. */
  713. if (!oproc->need_resume)
  714. goto out;
  715. ret = _omap_rproc_resume(rproc, false);
  716. if (ret) {
  717. dev_err(dev, "resume failed %d\n", ret);
  718. goto out;
  719. }
  720. oproc->need_resume = false;
  721. rproc->state = RPROC_RUNNING;
  722. /*
  723. * update the runtime pm status to be active, without incrementing
  724. * the device usage count
  725. */
  726. pm_runtime_set_active(dev);
  727. pm_runtime_enable(dev);
  728. pm_runtime_mark_last_busy(dev);
  729. out:
  730. mutex_unlock(&rproc->lock);
  731. return ret;
  732. }
  733. #endif /* CONFIG_PM_SLEEP */
  734. static int omap_rproc_runtime_suspend(struct device *dev)
  735. {
  736. struct rproc *rproc = dev_get_drvdata(dev);
  737. struct omap_rproc *oproc = rproc->priv;
  738. int ret;
  739. if (rproc->state == RPROC_CRASHED) {
  740. dev_dbg(dev, "rproc cannot be runtime suspended when crashed!\n");
  741. return -EBUSY;
  742. }
  743. if (WARN_ON(rproc->state != RPROC_RUNNING)) {
  744. dev_err(dev, "rproc cannot be runtime suspended when not running!\n");
  745. return -EBUSY;
  746. }
  747. /*
  748. * do not even attempt suspend if the remote processor is not
  749. * idled for runtime auto-suspend
  750. */
  751. if (!_is_rproc_in_standby(oproc))
  752. return -EBUSY;
  753. ret = _omap_rproc_suspend(rproc, true);
  754. if (ret)
  755. goto abort;
  756. rproc->state = RPROC_SUSPENDED;
  757. return 0;
  758. abort:
  759. pm_runtime_mark_last_busy(dev);
  760. return ret;
  761. }
  762. static int omap_rproc_runtime_resume(struct device *dev)
  763. {
  764. struct rproc *rproc = dev_get_drvdata(dev);
  765. int ret;
  766. if (WARN_ON(rproc->state != RPROC_SUSPENDED)) {
  767. dev_err(dev, "rproc cannot be runtime resumed if not suspended!\n");
  768. return -EBUSY;
  769. }
  770. ret = _omap_rproc_resume(rproc, true);
  771. if (ret) {
  772. dev_err(dev, "runtime resume failed %d\n", ret);
  773. return ret;
  774. }
  775. rproc->state = RPROC_RUNNING;
  776. return 0;
  777. }
  778. #endif /* CONFIG_PM */
  779. static const struct omap_rproc_dev_data omap4_dsp_dev_data = {
  780. .device_name = "dsp",
  781. .fw_name = "omap4-dsp-fw.xe64T",
  782. };
  783. static const struct omap_rproc_dev_data omap4_ipu_dev_data = {
  784. .device_name = "ipu",
  785. .fw_name = "omap4-ipu-fw.xem3",
  786. };
  787. static const struct omap_rproc_dev_data omap5_dsp_dev_data = {
  788. .device_name = "dsp",
  789. .fw_name = "omap5-dsp-fw.xe64T",
  790. };
  791. static const struct omap_rproc_dev_data omap5_ipu_dev_data = {
  792. .device_name = "ipu",
  793. .fw_name = "omap5-ipu-fw.xem4",
  794. };
  795. static const struct omap_rproc_dev_data dra7_rproc_dev_data[] = {
  796. {
  797. .device_name = "40800000.dsp",
  798. .fw_name = "dra7-dsp1-fw.xe66",
  799. },
  800. {
  801. .device_name = "41000000.dsp",
  802. .fw_name = "dra7-dsp2-fw.xe66",
  803. },
  804. {
  805. .device_name = "55020000.ipu",
  806. .fw_name = "dra7-ipu2-fw.xem4",
  807. },
  808. {
  809. .device_name = "58820000.ipu",
  810. .fw_name = "dra7-ipu1-fw.xem4",
  811. },
  812. {
  813. /* sentinel */
  814. },
  815. };
  816. static const struct of_device_id omap_rproc_of_match[] = {
  817. {
  818. .compatible = "ti,omap4-dsp",
  819. .data = &omap4_dsp_dev_data,
  820. },
  821. {
  822. .compatible = "ti,omap4-ipu",
  823. .data = &omap4_ipu_dev_data,
  824. },
  825. {
  826. .compatible = "ti,omap5-dsp",
  827. .data = &omap5_dsp_dev_data,
  828. },
  829. {
  830. .compatible = "ti,omap5-ipu",
  831. .data = &omap5_ipu_dev_data,
  832. },
  833. {
  834. .compatible = "ti,dra7-dsp",
  835. .data = dra7_rproc_dev_data,
  836. },
  837. {
  838. .compatible = "ti,dra7-ipu",
  839. .data = dra7_rproc_dev_data,
  840. },
  841. {
  842. /* end */
  843. },
  844. };
  845. MODULE_DEVICE_TABLE(of, omap_rproc_of_match);
  846. static int omap_rproc_get_autosuspend_delay(struct platform_device *pdev)
  847. {
  848. struct device_node *np = pdev->dev.of_node;
  849. const struct omap_rproc_dev_data *data;
  850. const struct of_device_id *match;
  851. int delay = -EINVAL;
  852. match = of_match_device(omap_rproc_of_match, &pdev->dev);
  853. if (!match)
  854. return -ENODEV;
  855. data = match->data;
  856. if (!of_device_is_compatible(np, "ti,dra7-dsp") &&
  857. !of_device_is_compatible(np, "ti,dra7-ipu")) {
  858. delay = data->autosuspend_delay;
  859. goto out;
  860. }
  861. for (; data && data->device_name; data++) {
  862. if (!strcmp(dev_name(&pdev->dev), data->device_name)) {
  863. delay = data->autosuspend_delay;
  864. break;
  865. }
  866. }
  867. out:
  868. return (delay > 0) ? delay : DEFAULT_AUTOSUSPEND_DELAY;
  869. }
  870. static const char *omap_rproc_get_firmware(struct platform_device *pdev)
  871. {
  872. struct device_node *np = pdev->dev.of_node;
  873. const struct omap_rproc_dev_data *data;
  874. const struct of_device_id *match;
  875. match = of_match_device(omap_rproc_of_match, &pdev->dev);
  876. if (!match)
  877. return ERR_PTR(-ENODEV);
  878. data = match->data;
  879. if (!of_device_is_compatible(np, "ti,dra7-dsp") &&
  880. !of_device_is_compatible(np, "ti,dra7-ipu"))
  881. return data->fw_name;
  882. for (; data && data->device_name; data++) {
  883. if (!strcmp(dev_name(&pdev->dev), data->device_name))
  884. return data->fw_name;
  885. }
  886. return NULL;
  887. }
  888. static int omap_rproc_get_boot_data(struct platform_device *pdev,
  889. struct rproc *rproc)
  890. {
  891. struct device_node *np = pdev->dev.of_node;
  892. struct omap_rproc *oproc = rproc->priv;
  893. int ret;
  894. if (!of_device_is_compatible(np, "ti,omap4-dsp") &&
  895. !of_device_is_compatible(np, "ti,omap5-dsp") &&
  896. !of_device_is_compatible(np, "ti,dra7-dsp"))
  897. return 0;
  898. oproc->boot_data = devm_kzalloc(&pdev->dev, sizeof(*oproc->boot_data),
  899. GFP_KERNEL);
  900. if (!oproc->boot_data)
  901. return -ENOMEM;
  902. if (!of_property_read_bool(np, "syscon-bootreg")) {
  903. dev_err(&pdev->dev, "syscon-bootreg property is missing\n");
  904. return -EINVAL;
  905. }
  906. oproc->boot_data->syscon =
  907. syscon_regmap_lookup_by_phandle(np, "syscon-bootreg");
  908. if (IS_ERR(oproc->boot_data->syscon)) {
  909. ret = PTR_ERR(oproc->boot_data->syscon);
  910. return ret;
  911. }
  912. if (of_property_read_u32_index(np, "syscon-bootreg", 1,
  913. &oproc->boot_data->boot_reg)) {
  914. dev_err(&pdev->dev, "couldn't get the boot register\n");
  915. return -EINVAL;
  916. }
  917. if (of_device_is_compatible(np, "ti,dra7-dsp"))
  918. oproc->boot_data->boot_reg_shift = 10;
  919. return 0;
  920. }
  921. static int omap_rproc_of_get_internal_memories(struct platform_device *pdev,
  922. struct rproc *rproc)
  923. {
  924. static const char * const ipu_mem_names[] = {"l2ram"};
  925. static const char * const dra7_dsp_mem_names[] = {"l2ram", "l1pram",
  926. "l1dram"};
  927. struct device_node *np = pdev->dev.of_node;
  928. struct omap_rproc *oproc = rproc->priv;
  929. struct device *dev = &pdev->dev;
  930. const char * const *mem_names;
  931. struct resource *res;
  932. int num_mems;
  933. const __be32 *addrp;
  934. u32 l4_offset = 0;
  935. u64 size;
  936. int i;
  937. /* OMAP4 and OMAP5 DSPs does not have support for flat SRAM */
  938. if (of_device_is_compatible(np, "ti,omap4-dsp") ||
  939. of_device_is_compatible(np, "ti,omap5-dsp"))
  940. return 0;
  941. /* DRA7 DSPs have two additional SRAMs at L1 level */
  942. if (of_device_is_compatible(np, "ti,dra7-dsp")) {
  943. mem_names = dra7_dsp_mem_names;
  944. num_mems = ARRAY_SIZE(dra7_dsp_mem_names);
  945. } else {
  946. mem_names = ipu_mem_names;
  947. num_mems = ARRAY_SIZE(ipu_mem_names);
  948. }
  949. oproc->mem = devm_kcalloc(dev, num_mems, sizeof(*oproc->mem),
  950. GFP_KERNEL);
  951. if (!oproc->mem)
  952. return -ENOMEM;
  953. for (i = 0; i < num_mems; i++) {
  954. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  955. mem_names[i]);
  956. oproc->mem[i].cpu_addr = devm_ioremap_resource(dev, res);
  957. if (IS_ERR(oproc->mem[i].cpu_addr)) {
  958. dev_err(dev, "failed to parse and map %s memory\n",
  959. mem_names[i]);
  960. return PTR_ERR(oproc->mem[i].cpu_addr);
  961. }
  962. oproc->mem[i].bus_addr = res->start;
  963. /*
  964. * The DSPs have the internal memories starting at a fixed
  965. * offset of 0x800000 from address 0, and this corresponds to
  966. * L2RAM. The L3 address view has the L2RAM bus address as the
  967. * starting address for the IP, so the L2RAM memory region needs
  968. * to be processed first, and the device addresses for each
  969. * memory region can be computed using the relative offset
  970. * from this base address.
  971. */
  972. if (of_device_is_compatible(np, "ti,dra7-dsp") &&
  973. !strcmp(mem_names[i], "l2ram")) {
  974. addrp = of_get_address(dev->of_node, i, &size, NULL);
  975. l4_offset = be32_to_cpu(*addrp);
  976. }
  977. oproc->mem[i].dev_addr =
  978. of_device_is_compatible(np, "ti,dra7-dsp") ?
  979. res->start - l4_offset +
  980. OMAP_RPROC_DSP_LOCAL_MEM_OFFSET :
  981. OMAP_RPROC_IPU_L2RAM_DEV_ADDR;
  982. oproc->mem[i].size = resource_size(res);
  983. }
  984. oproc->num_mems = num_mems;
  985. return 0;
  986. }
  987. static int omap_rproc_probe(struct platform_device *pdev)
  988. {
  989. struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
  990. struct device_node *np = pdev->dev.of_node;
  991. struct omap_rproc_timer_ops *timer_ops;
  992. struct omap_rproc *oproc;
  993. struct rproc *rproc;
  994. const char *firmware;
  995. u32 standby_addr = 0;
  996. int num_timers;
  997. int ret;
  998. if (!np) {
  999. dev_err(&pdev->dev, "only DT-based devices are supported\n");
  1000. return -ENODEV;
  1001. }
  1002. /*
  1003. * self-manage the ordering dependencies between omap_device_enable/idle
  1004. * and omap_device_assert/deassert_hardreset API during runtime suspend
  1005. * and resume, rather than relying on the order in omap_device layer.
  1006. */
  1007. if (pdev->dev.pm_domain) {
  1008. dev_dbg(&pdev->dev, "device pm_domain is being reset for this remoteproc device\n");
  1009. pdev->dev.pm_domain = NULL;
  1010. }
  1011. if (!pdata || !pdata->device_enable || !pdata->device_shutdown) {
  1012. dev_err(&pdev->dev, "platform data is either missing or incomplete\n");
  1013. return -ENODEV;
  1014. }
  1015. firmware = omap_rproc_get_firmware(pdev);
  1016. if (IS_ERR(firmware))
  1017. return PTR_ERR(firmware);
  1018. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  1019. if (ret) {
  1020. dev_err(&pdev->dev, "dma_set_coherent_mask: %d\n", ret);
  1021. return ret;
  1022. }
  1023. rproc = rproc_alloc(&pdev->dev, dev_name(&pdev->dev), &omap_rproc_ops,
  1024. firmware, sizeof(*oproc));
  1025. if (!rproc)
  1026. return -ENOMEM;
  1027. oproc = rproc->priv;
  1028. oproc->rproc = rproc;
  1029. /* All existing OMAP IPU and DSP processors have an MMU */
  1030. rproc->has_iommu = true;
  1031. ret = omap_rproc_of_get_internal_memories(pdev, rproc);
  1032. if (ret)
  1033. goto free_rproc;
  1034. ret = omap_rproc_get_boot_data(pdev, rproc);
  1035. if (ret)
  1036. goto free_rproc;
  1037. timer_ops = pdata->timer_ops;
  1038. /*
  1039. * Timer nodes are directly used in client nodes as phandles, so
  1040. * retrieve the count using NULL as cells-name.
  1041. * XXX: Use the much simpler of_property_count_elems_of_size
  1042. * if available
  1043. */
  1044. oproc->num_timers = of_count_phandle_with_args(np, "timers", NULL);
  1045. if (oproc->num_timers <= 0) {
  1046. dev_dbg(&pdev->dev, "device does not have timers, status = %d\n",
  1047. oproc->num_timers);
  1048. oproc->num_timers = 0;
  1049. } else {
  1050. if (!timer_ops || !timer_ops->request_timer ||
  1051. !timer_ops->release_timer || !timer_ops->start_timer ||
  1052. !timer_ops->stop_timer) {
  1053. dev_err(&pdev->dev, "device does not have required timer ops\n");
  1054. ret = -ENODEV;
  1055. goto free_rproc;
  1056. }
  1057. }
  1058. #ifdef CONFIG_OMAP_REMOTEPROC_WATCHDOG
  1059. oproc->num_wd_timers = of_count_phandle_with_args(np, "watchdog-timers",
  1060. NULL);
  1061. if (oproc->num_wd_timers <= 0) {
  1062. dev_dbg(&pdev->dev, "device does not have watchdog timers, status = %d\n",
  1063. oproc->num_wd_timers);
  1064. oproc->num_wd_timers = 0;
  1065. } else {
  1066. if (!timer_ops || !timer_ops->request_timer ||
  1067. !timer_ops->release_timer || !timer_ops->start_timer ||
  1068. !timer_ops->stop_timer || !timer_ops->get_timer_irq ||
  1069. !timer_ops->ack_timer_irq) {
  1070. dev_err(&pdev->dev, "device does not have required watchdog timer ops\n");
  1071. ret = -ENODEV;
  1072. goto free_rproc;
  1073. }
  1074. }
  1075. #endif
  1076. if (oproc->num_timers || oproc->num_wd_timers) {
  1077. num_timers = oproc->num_timers + oproc->num_wd_timers;
  1078. oproc->timers = devm_kzalloc(&pdev->dev, sizeof(*oproc->timers)
  1079. * num_timers, GFP_KERNEL);
  1080. if (!oproc->timers) {
  1081. ret = -ENOMEM;
  1082. goto free_rproc;
  1083. }
  1084. dev_dbg(&pdev->dev, "device has %d tick timers and %d watchdog timers\n",
  1085. oproc->num_timers, oproc->num_wd_timers);
  1086. }
  1087. init_completion(&oproc->pm_comp);
  1088. oproc->autosuspend_delay = omap_rproc_get_autosuspend_delay(pdev);
  1089. if (oproc->autosuspend_delay < 0) {
  1090. ret = oproc->autosuspend_delay;
  1091. goto free_rproc;
  1092. }
  1093. ret = of_property_read_u32(np, "ti,rproc-standby-info", &standby_addr);
  1094. if (ret || !standby_addr) {
  1095. ret = !standby_addr ? -EINVAL : ret;
  1096. goto free_rproc;
  1097. }
  1098. oproc->standby_addr = devm_ioremap(&pdev->dev, standby_addr,
  1099. sizeof(u32));
  1100. if (!oproc->standby_addr) {
  1101. ret = -ENOMEM;
  1102. goto free_rproc;
  1103. }
  1104. ret = of_reserved_mem_device_init(&pdev->dev);
  1105. if (ret) {
  1106. dev_err(&pdev->dev, "device does not have specific CMA pool\n");
  1107. goto free_rproc;
  1108. }
  1109. platform_set_drvdata(pdev, rproc);
  1110. ret = rproc_add(rproc);
  1111. if (ret)
  1112. goto release_mem;
  1113. if (rproc_get_alias_id(rproc) < 0)
  1114. dev_warn(&pdev->dev, "device does not have an alias id\n");
  1115. return 0;
  1116. release_mem:
  1117. of_reserved_mem_device_release(&pdev->dev);
  1118. free_rproc:
  1119. rproc_free(rproc);
  1120. return ret;
  1121. }
  1122. static int omap_rproc_remove(struct platform_device *pdev)
  1123. {
  1124. struct rproc *rproc = platform_get_drvdata(pdev);
  1125. rproc_del(rproc);
  1126. rproc_free(rproc);
  1127. of_reserved_mem_device_release(&pdev->dev);
  1128. return 0;
  1129. }
  1130. static const struct dev_pm_ops omap_rproc_pm_ops = {
  1131. SET_SYSTEM_SLEEP_PM_OPS(omap_rproc_suspend, omap_rproc_resume)
  1132. SET_RUNTIME_PM_OPS(omap_rproc_runtime_suspend,
  1133. omap_rproc_runtime_resume, NULL)
  1134. };
  1135. static struct platform_driver omap_rproc_driver = {
  1136. .probe = omap_rproc_probe,
  1137. .remove = omap_rproc_remove,
  1138. .driver = {
  1139. .name = "omap-rproc",
  1140. .pm = &omap_rproc_pm_ops,
  1141. .of_match_table = omap_rproc_of_match,
  1142. },
  1143. };
  1144. module_platform_driver(omap_rproc_driver);
  1145. MODULE_LICENSE("GPL v2");
  1146. MODULE_DESCRIPTION("OMAP Remote Processor control driver");