vsp1_drv.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * vsp1_drv.c -- R-Car VSP1 Driver
  4. *
  5. * Copyright (C) 2013-2015 Renesas Electronics Corporation
  6. *
  7. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/delay.h>
  11. #include <linux/device.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_device.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/videodev2.h>
  19. #include <media/rcar-fcp.h>
  20. #include <media/v4l2-subdev.h>
  21. #include "vsp1.h"
  22. #include "vsp1_brx.h"
  23. #include "vsp1_clu.h"
  24. #include "vsp1_dl.h"
  25. #include "vsp1_drm.h"
  26. #include "vsp1_hgo.h"
  27. #include "vsp1_hgt.h"
  28. #include "vsp1_hsit.h"
  29. #include "vsp1_lif.h"
  30. #include "vsp1_lut.h"
  31. #include "vsp1_pipe.h"
  32. #include "vsp1_rwpf.h"
  33. #include "vsp1_sru.h"
  34. #include "vsp1_uds.h"
  35. #include "vsp1_uif.h"
  36. #include "vsp1_video.h"
  37. /* -----------------------------------------------------------------------------
  38. * Interrupt Handling
  39. */
  40. static irqreturn_t vsp1_irq_handler(int irq, void *data)
  41. {
  42. u32 mask = VI6_WFP_IRQ_STA_DFE | VI6_WFP_IRQ_STA_FRE;
  43. struct vsp1_device *vsp1 = data;
  44. irqreturn_t ret = IRQ_NONE;
  45. unsigned int i;
  46. u32 status;
  47. for (i = 0; i < vsp1->info->wpf_count; ++i) {
  48. struct vsp1_rwpf *wpf = vsp1->wpf[i];
  49. if (wpf == NULL)
  50. continue;
  51. status = vsp1_read(vsp1, VI6_WPF_IRQ_STA(i));
  52. vsp1_write(vsp1, VI6_WPF_IRQ_STA(i), ~status & mask);
  53. if (status & VI6_WFP_IRQ_STA_DFE) {
  54. vsp1_pipeline_frame_end(wpf->entity.pipe);
  55. ret = IRQ_HANDLED;
  56. }
  57. }
  58. return ret;
  59. }
  60. /* -----------------------------------------------------------------------------
  61. * Entities
  62. */
  63. /*
  64. * vsp1_create_sink_links - Create links from all sources to the given sink
  65. *
  66. * This function creates media links from all valid sources to the given sink
  67. * pad. Links that would be invalid according to the VSP1 hardware capabilities
  68. * are skipped. Those include all links
  69. *
  70. * - from a UDS to a UDS (UDS entities can't be chained)
  71. * - from an entity to itself (no loops are allowed)
  72. *
  73. * Furthermore, the BRS can't be connected to histogram generators, but no
  74. * special check is currently needed as all VSP instances that include a BRS
  75. * have no histogram generator.
  76. */
  77. static int vsp1_create_sink_links(struct vsp1_device *vsp1,
  78. struct vsp1_entity *sink)
  79. {
  80. struct media_entity *entity = &sink->subdev.entity;
  81. struct vsp1_entity *source;
  82. unsigned int pad;
  83. int ret;
  84. list_for_each_entry(source, &vsp1->entities, list_dev) {
  85. u32 flags;
  86. if (source->type == sink->type)
  87. continue;
  88. if (source->type == VSP1_ENTITY_HGO ||
  89. source->type == VSP1_ENTITY_HGT ||
  90. source->type == VSP1_ENTITY_LIF ||
  91. source->type == VSP1_ENTITY_WPF)
  92. continue;
  93. flags = source->type == VSP1_ENTITY_RPF &&
  94. sink->type == VSP1_ENTITY_WPF &&
  95. source->index == sink->index
  96. ? MEDIA_LNK_FL_ENABLED : 0;
  97. for (pad = 0; pad < entity->num_pads; ++pad) {
  98. if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
  99. continue;
  100. ret = media_create_pad_link(&source->subdev.entity,
  101. source->source_pad,
  102. entity, pad, flags);
  103. if (ret < 0)
  104. return ret;
  105. if (flags & MEDIA_LNK_FL_ENABLED)
  106. source->sink = sink;
  107. }
  108. }
  109. return 0;
  110. }
  111. static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
  112. {
  113. struct vsp1_entity *entity;
  114. unsigned int i;
  115. int ret;
  116. list_for_each_entry(entity, &vsp1->entities, list_dev) {
  117. if (entity->type == VSP1_ENTITY_LIF ||
  118. entity->type == VSP1_ENTITY_RPF)
  119. continue;
  120. ret = vsp1_create_sink_links(vsp1, entity);
  121. if (ret < 0)
  122. return ret;
  123. }
  124. if (vsp1->hgo) {
  125. ret = media_create_pad_link(&vsp1->hgo->histo.entity.subdev.entity,
  126. HISTO_PAD_SOURCE,
  127. &vsp1->hgo->histo.video.entity, 0,
  128. MEDIA_LNK_FL_ENABLED |
  129. MEDIA_LNK_FL_IMMUTABLE);
  130. if (ret < 0)
  131. return ret;
  132. }
  133. if (vsp1->hgt) {
  134. ret = media_create_pad_link(&vsp1->hgt->histo.entity.subdev.entity,
  135. HISTO_PAD_SOURCE,
  136. &vsp1->hgt->histo.video.entity, 0,
  137. MEDIA_LNK_FL_ENABLED |
  138. MEDIA_LNK_FL_IMMUTABLE);
  139. if (ret < 0)
  140. return ret;
  141. }
  142. for (i = 0; i < vsp1->info->lif_count; ++i) {
  143. if (!vsp1->lif[i])
  144. continue;
  145. ret = media_create_pad_link(&vsp1->wpf[i]->entity.subdev.entity,
  146. RWPF_PAD_SOURCE,
  147. &vsp1->lif[i]->entity.subdev.entity,
  148. LIF_PAD_SINK, 0);
  149. if (ret < 0)
  150. return ret;
  151. }
  152. for (i = 0; i < vsp1->info->rpf_count; ++i) {
  153. struct vsp1_rwpf *rpf = vsp1->rpf[i];
  154. ret = media_create_pad_link(&rpf->video->video.entity, 0,
  155. &rpf->entity.subdev.entity,
  156. RWPF_PAD_SINK,
  157. MEDIA_LNK_FL_ENABLED |
  158. MEDIA_LNK_FL_IMMUTABLE);
  159. if (ret < 0)
  160. return ret;
  161. }
  162. for (i = 0; i < vsp1->info->wpf_count; ++i) {
  163. /*
  164. * Connect the video device to the WPF. All connections are
  165. * immutable.
  166. */
  167. struct vsp1_rwpf *wpf = vsp1->wpf[i];
  168. ret = media_create_pad_link(&wpf->entity.subdev.entity,
  169. RWPF_PAD_SOURCE,
  170. &wpf->video->video.entity, 0,
  171. MEDIA_LNK_FL_IMMUTABLE |
  172. MEDIA_LNK_FL_ENABLED);
  173. if (ret < 0)
  174. return ret;
  175. }
  176. return 0;
  177. }
  178. static void vsp1_destroy_entities(struct vsp1_device *vsp1)
  179. {
  180. struct vsp1_entity *entity, *_entity;
  181. struct vsp1_video *video, *_video;
  182. list_for_each_entry_safe(entity, _entity, &vsp1->entities, list_dev) {
  183. list_del(&entity->list_dev);
  184. vsp1_entity_destroy(entity);
  185. }
  186. list_for_each_entry_safe(video, _video, &vsp1->videos, list) {
  187. list_del(&video->list);
  188. vsp1_video_cleanup(video);
  189. }
  190. v4l2_device_unregister(&vsp1->v4l2_dev);
  191. if (vsp1->info->uapi)
  192. media_device_unregister(&vsp1->media_dev);
  193. media_device_cleanup(&vsp1->media_dev);
  194. if (!vsp1->info->uapi)
  195. vsp1_drm_cleanup(vsp1);
  196. }
  197. static int vsp1_create_entities(struct vsp1_device *vsp1)
  198. {
  199. struct media_device *mdev = &vsp1->media_dev;
  200. struct v4l2_device *vdev = &vsp1->v4l2_dev;
  201. struct vsp1_entity *entity;
  202. unsigned int i;
  203. int ret;
  204. mdev->dev = vsp1->dev;
  205. mdev->hw_revision = vsp1->version;
  206. strlcpy(mdev->model, vsp1->info->model, sizeof(mdev->model));
  207. snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
  208. dev_name(mdev->dev));
  209. media_device_init(mdev);
  210. vsp1->media_ops.link_setup = vsp1_entity_link_setup;
  211. /*
  212. * Don't perform link validation when the userspace API is disabled as
  213. * the pipeline is configured internally by the driver in that case, and
  214. * its configuration can thus be trusted.
  215. */
  216. if (vsp1->info->uapi)
  217. vsp1->media_ops.link_validate = v4l2_subdev_link_validate;
  218. vdev->mdev = mdev;
  219. ret = v4l2_device_register(vsp1->dev, vdev);
  220. if (ret < 0) {
  221. dev_err(vsp1->dev, "V4L2 device registration failed (%d)\n",
  222. ret);
  223. goto done;
  224. }
  225. /* Instantiate all the entities. */
  226. if (vsp1_feature(vsp1, VSP1_HAS_BRS)) {
  227. vsp1->brs = vsp1_brx_create(vsp1, VSP1_ENTITY_BRS);
  228. if (IS_ERR(vsp1->brs)) {
  229. ret = PTR_ERR(vsp1->brs);
  230. goto done;
  231. }
  232. list_add_tail(&vsp1->brs->entity.list_dev, &vsp1->entities);
  233. }
  234. if (vsp1_feature(vsp1, VSP1_HAS_BRU)) {
  235. vsp1->bru = vsp1_brx_create(vsp1, VSP1_ENTITY_BRU);
  236. if (IS_ERR(vsp1->bru)) {
  237. ret = PTR_ERR(vsp1->bru);
  238. goto done;
  239. }
  240. list_add_tail(&vsp1->bru->entity.list_dev, &vsp1->entities);
  241. }
  242. if (vsp1_feature(vsp1, VSP1_HAS_CLU)) {
  243. vsp1->clu = vsp1_clu_create(vsp1);
  244. if (IS_ERR(vsp1->clu)) {
  245. ret = PTR_ERR(vsp1->clu);
  246. goto done;
  247. }
  248. list_add_tail(&vsp1->clu->entity.list_dev, &vsp1->entities);
  249. }
  250. vsp1->hsi = vsp1_hsit_create(vsp1, true);
  251. if (IS_ERR(vsp1->hsi)) {
  252. ret = PTR_ERR(vsp1->hsi);
  253. goto done;
  254. }
  255. list_add_tail(&vsp1->hsi->entity.list_dev, &vsp1->entities);
  256. vsp1->hst = vsp1_hsit_create(vsp1, false);
  257. if (IS_ERR(vsp1->hst)) {
  258. ret = PTR_ERR(vsp1->hst);
  259. goto done;
  260. }
  261. list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
  262. if (vsp1_feature(vsp1, VSP1_HAS_HGO) && vsp1->info->uapi) {
  263. vsp1->hgo = vsp1_hgo_create(vsp1);
  264. if (IS_ERR(vsp1->hgo)) {
  265. ret = PTR_ERR(vsp1->hgo);
  266. goto done;
  267. }
  268. list_add_tail(&vsp1->hgo->histo.entity.list_dev,
  269. &vsp1->entities);
  270. }
  271. if (vsp1_feature(vsp1, VSP1_HAS_HGT) && vsp1->info->uapi) {
  272. vsp1->hgt = vsp1_hgt_create(vsp1);
  273. if (IS_ERR(vsp1->hgt)) {
  274. ret = PTR_ERR(vsp1->hgt);
  275. goto done;
  276. }
  277. list_add_tail(&vsp1->hgt->histo.entity.list_dev,
  278. &vsp1->entities);
  279. }
  280. /*
  281. * The LIFs are only supported when used in conjunction with the DU, in
  282. * which case the userspace API is disabled. If the userspace API is
  283. * enabled skip the LIFs, even when present.
  284. */
  285. if (!vsp1->info->uapi) {
  286. for (i = 0; i < vsp1->info->lif_count; ++i) {
  287. struct vsp1_lif *lif;
  288. lif = vsp1_lif_create(vsp1, i);
  289. if (IS_ERR(lif)) {
  290. ret = PTR_ERR(lif);
  291. goto done;
  292. }
  293. vsp1->lif[i] = lif;
  294. list_add_tail(&lif->entity.list_dev, &vsp1->entities);
  295. }
  296. }
  297. if (vsp1_feature(vsp1, VSP1_HAS_LUT)) {
  298. vsp1->lut = vsp1_lut_create(vsp1);
  299. if (IS_ERR(vsp1->lut)) {
  300. ret = PTR_ERR(vsp1->lut);
  301. goto done;
  302. }
  303. list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
  304. }
  305. for (i = 0; i < vsp1->info->rpf_count; ++i) {
  306. struct vsp1_rwpf *rpf;
  307. rpf = vsp1_rpf_create(vsp1, i);
  308. if (IS_ERR(rpf)) {
  309. ret = PTR_ERR(rpf);
  310. goto done;
  311. }
  312. vsp1->rpf[i] = rpf;
  313. list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
  314. if (vsp1->info->uapi) {
  315. struct vsp1_video *video = vsp1_video_create(vsp1, rpf);
  316. if (IS_ERR(video)) {
  317. ret = PTR_ERR(video);
  318. goto done;
  319. }
  320. list_add_tail(&video->list, &vsp1->videos);
  321. }
  322. }
  323. if (vsp1_feature(vsp1, VSP1_HAS_SRU)) {
  324. vsp1->sru = vsp1_sru_create(vsp1);
  325. if (IS_ERR(vsp1->sru)) {
  326. ret = PTR_ERR(vsp1->sru);
  327. goto done;
  328. }
  329. list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
  330. }
  331. for (i = 0; i < vsp1->info->uds_count; ++i) {
  332. struct vsp1_uds *uds;
  333. uds = vsp1_uds_create(vsp1, i);
  334. if (IS_ERR(uds)) {
  335. ret = PTR_ERR(uds);
  336. goto done;
  337. }
  338. vsp1->uds[i] = uds;
  339. list_add_tail(&uds->entity.list_dev, &vsp1->entities);
  340. }
  341. for (i = 0; i < vsp1->info->uif_count; ++i) {
  342. struct vsp1_uif *uif;
  343. uif = vsp1_uif_create(vsp1, i);
  344. if (IS_ERR(uif)) {
  345. ret = PTR_ERR(uif);
  346. goto done;
  347. }
  348. vsp1->uif[i] = uif;
  349. list_add_tail(&uif->entity.list_dev, &vsp1->entities);
  350. }
  351. for (i = 0; i < vsp1->info->wpf_count; ++i) {
  352. struct vsp1_rwpf *wpf;
  353. wpf = vsp1_wpf_create(vsp1, i);
  354. if (IS_ERR(wpf)) {
  355. ret = PTR_ERR(wpf);
  356. goto done;
  357. }
  358. vsp1->wpf[i] = wpf;
  359. list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
  360. if (vsp1->info->uapi) {
  361. struct vsp1_video *video = vsp1_video_create(vsp1, wpf);
  362. if (IS_ERR(video)) {
  363. ret = PTR_ERR(video);
  364. goto done;
  365. }
  366. list_add_tail(&video->list, &vsp1->videos);
  367. }
  368. }
  369. /* Register all subdevs. */
  370. list_for_each_entry(entity, &vsp1->entities, list_dev) {
  371. ret = v4l2_device_register_subdev(&vsp1->v4l2_dev,
  372. &entity->subdev);
  373. if (ret < 0)
  374. goto done;
  375. }
  376. /*
  377. * Create links and register subdev nodes if the userspace API is
  378. * enabled or initialize the DRM pipeline otherwise.
  379. */
  380. if (vsp1->info->uapi) {
  381. ret = vsp1_uapi_create_links(vsp1);
  382. if (ret < 0)
  383. goto done;
  384. ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
  385. if (ret < 0)
  386. goto done;
  387. ret = media_device_register(mdev);
  388. } else {
  389. ret = vsp1_drm_init(vsp1);
  390. }
  391. done:
  392. if (ret < 0)
  393. vsp1_destroy_entities(vsp1);
  394. return ret;
  395. }
  396. int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
  397. {
  398. unsigned int timeout;
  399. u32 status;
  400. status = vsp1_read(vsp1, VI6_STATUS);
  401. if (!(status & VI6_STATUS_SYS_ACT(index)))
  402. return 0;
  403. vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(index));
  404. for (timeout = 10; timeout > 0; --timeout) {
  405. status = vsp1_read(vsp1, VI6_STATUS);
  406. if (!(status & VI6_STATUS_SYS_ACT(index)))
  407. break;
  408. usleep_range(1000, 2000);
  409. }
  410. if (!timeout) {
  411. dev_err(vsp1->dev, "failed to reset wpf.%u\n", index);
  412. return -ETIMEDOUT;
  413. }
  414. return 0;
  415. }
  416. static int vsp1_device_init(struct vsp1_device *vsp1)
  417. {
  418. unsigned int i;
  419. int ret;
  420. /* Reset any channel that might be running. */
  421. for (i = 0; i < vsp1->info->wpf_count; ++i) {
  422. ret = vsp1_reset_wpf(vsp1, i);
  423. if (ret < 0)
  424. return ret;
  425. }
  426. vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
  427. (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
  428. for (i = 0; i < vsp1->info->rpf_count; ++i)
  429. vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
  430. for (i = 0; i < vsp1->info->uds_count; ++i)
  431. vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
  432. for (i = 0; i < vsp1->info->uif_count; ++i)
  433. vsp1_write(vsp1, VI6_DPR_UIF_ROUTE(i), VI6_DPR_NODE_UNUSED);
  434. vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
  435. vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
  436. vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
  437. vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
  438. vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
  439. vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
  440. if (vsp1_feature(vsp1, VSP1_HAS_BRS))
  441. vsp1_write(vsp1, VI6_DPR_ILV_BRS_ROUTE, VI6_DPR_NODE_UNUSED);
  442. vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
  443. (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
  444. vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
  445. (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
  446. vsp1_dlm_setup(vsp1);
  447. return 0;
  448. }
  449. /*
  450. * vsp1_device_get - Acquire the VSP1 device
  451. *
  452. * Make sure the device is not suspended and initialize it if needed.
  453. *
  454. * Return 0 on success or a negative error code otherwise.
  455. */
  456. int vsp1_device_get(struct vsp1_device *vsp1)
  457. {
  458. int ret;
  459. ret = pm_runtime_get_sync(vsp1->dev);
  460. if (ret < 0) {
  461. pm_runtime_put_noidle(vsp1->dev);
  462. return ret;
  463. }
  464. return 0;
  465. }
  466. /*
  467. * vsp1_device_put - Release the VSP1 device
  468. *
  469. * Decrement the VSP1 reference count and cleanup the device if the last
  470. * reference is released.
  471. */
  472. void vsp1_device_put(struct vsp1_device *vsp1)
  473. {
  474. pm_runtime_put_sync(vsp1->dev);
  475. }
  476. /* -----------------------------------------------------------------------------
  477. * Power Management
  478. */
  479. static int __maybe_unused vsp1_pm_suspend(struct device *dev)
  480. {
  481. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  482. /*
  483. * When used as part of a display pipeline, the VSP is stopped and
  484. * restarted explicitly by the DU.
  485. */
  486. if (!vsp1->drm)
  487. vsp1_video_suspend(vsp1);
  488. pm_runtime_force_suspend(vsp1->dev);
  489. return 0;
  490. }
  491. static int __maybe_unused vsp1_pm_resume(struct device *dev)
  492. {
  493. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  494. pm_runtime_force_resume(vsp1->dev);
  495. /*
  496. * When used as part of a display pipeline, the VSP is stopped and
  497. * restarted explicitly by the DU.
  498. */
  499. if (!vsp1->drm)
  500. vsp1_video_resume(vsp1);
  501. return 0;
  502. }
  503. static int __maybe_unused vsp1_pm_runtime_suspend(struct device *dev)
  504. {
  505. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  506. rcar_fcp_disable(vsp1->fcp);
  507. return 0;
  508. }
  509. static int __maybe_unused vsp1_pm_runtime_resume(struct device *dev)
  510. {
  511. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  512. int ret;
  513. if (vsp1->info) {
  514. ret = vsp1_device_init(vsp1);
  515. if (ret < 0)
  516. return ret;
  517. }
  518. return rcar_fcp_enable(vsp1->fcp);
  519. }
  520. static const struct dev_pm_ops vsp1_pm_ops = {
  521. SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
  522. SET_RUNTIME_PM_OPS(vsp1_pm_runtime_suspend, vsp1_pm_runtime_resume, NULL)
  523. };
  524. /* -----------------------------------------------------------------------------
  525. * Platform Driver
  526. */
  527. static const struct vsp1_device_info vsp1_device_infos[] = {
  528. {
  529. .version = VI6_IP_VERSION_MODEL_VSPS_H2,
  530. .model = "VSP1-S",
  531. .gen = 2,
  532. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  533. | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
  534. | VSP1_HAS_WPF_VFLIP,
  535. .rpf_count = 5,
  536. .uds_count = 3,
  537. .wpf_count = 4,
  538. .num_bru_inputs = 4,
  539. .uapi = true,
  540. }, {
  541. .version = VI6_IP_VERSION_MODEL_VSPR_H2,
  542. .model = "VSP1-R",
  543. .gen = 2,
  544. .features = VSP1_HAS_BRU | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
  545. .rpf_count = 5,
  546. .uds_count = 3,
  547. .wpf_count = 4,
  548. .num_bru_inputs = 4,
  549. .uapi = true,
  550. }, {
  551. .version = VI6_IP_VERSION_MODEL_VSPD_GEN2,
  552. .model = "VSP1-D",
  553. .gen = 2,
  554. .features = VSP1_HAS_BRU | VSP1_HAS_HGO | VSP1_HAS_LUT,
  555. .lif_count = 1,
  556. .rpf_count = 4,
  557. .uds_count = 1,
  558. .wpf_count = 1,
  559. .num_bru_inputs = 4,
  560. .uapi = true,
  561. }, {
  562. .version = VI6_IP_VERSION_MODEL_VSPS_M2,
  563. .model = "VSP1-S",
  564. .gen = 2,
  565. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  566. | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
  567. | VSP1_HAS_WPF_VFLIP,
  568. .rpf_count = 5,
  569. .uds_count = 1,
  570. .wpf_count = 4,
  571. .num_bru_inputs = 4,
  572. .uapi = true,
  573. }, {
  574. .version = VI6_IP_VERSION_MODEL_VSPS_V2H,
  575. .model = "VSP1V-S",
  576. .gen = 2,
  577. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT
  578. | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
  579. .rpf_count = 4,
  580. .uds_count = 1,
  581. .wpf_count = 4,
  582. .num_bru_inputs = 4,
  583. .uapi = true,
  584. }, {
  585. .version = VI6_IP_VERSION_MODEL_VSPD_V2H,
  586. .model = "VSP1V-D",
  587. .gen = 2,
  588. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT,
  589. .lif_count = 1,
  590. .rpf_count = 4,
  591. .uds_count = 1,
  592. .wpf_count = 1,
  593. .num_bru_inputs = 4,
  594. .uapi = true,
  595. }, {
  596. .version = VI6_IP_VERSION_MODEL_VSPI_GEN3,
  597. .model = "VSP2-I",
  598. .gen = 3,
  599. .features = VSP1_HAS_CLU | VSP1_HAS_HGO | VSP1_HAS_HGT
  600. | VSP1_HAS_LUT | VSP1_HAS_SRU | VSP1_HAS_WPF_HFLIP
  601. | VSP1_HAS_WPF_VFLIP,
  602. .rpf_count = 1,
  603. .uds_count = 1,
  604. .wpf_count = 1,
  605. .uapi = true,
  606. }, {
  607. .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3,
  608. .model = "VSP2-BD",
  609. .gen = 3,
  610. .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP,
  611. .rpf_count = 5,
  612. .wpf_count = 1,
  613. .num_bru_inputs = 5,
  614. .uapi = true,
  615. }, {
  616. .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3,
  617. .model = "VSP2-BC",
  618. .gen = 3,
  619. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  620. | VSP1_HAS_LUT | VSP1_HAS_WPF_VFLIP,
  621. .rpf_count = 5,
  622. .wpf_count = 1,
  623. .num_bru_inputs = 5,
  624. .uapi = true,
  625. }, {
  626. .version = VI6_IP_VERSION_MODEL_VSPBS_GEN3,
  627. .model = "VSP2-BS",
  628. .gen = 3,
  629. .features = VSP1_HAS_BRS | VSP1_HAS_WPF_VFLIP,
  630. .rpf_count = 2,
  631. .wpf_count = 1,
  632. .uapi = true,
  633. }, {
  634. .version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
  635. .model = "VSP2-D",
  636. .gen = 3,
  637. .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP | VSP1_HAS_EXT_DL,
  638. .lif_count = 1,
  639. .rpf_count = 5,
  640. .uif_count = 1,
  641. .wpf_count = 2,
  642. .num_bru_inputs = 5,
  643. }, {
  644. .version = VI6_IP_VERSION_MODEL_VSPD_V3,
  645. .model = "VSP2-D",
  646. .gen = 3,
  647. .features = VSP1_HAS_BRS | VSP1_HAS_BRU,
  648. .lif_count = 1,
  649. .rpf_count = 5,
  650. .uif_count = 1,
  651. .wpf_count = 1,
  652. .num_bru_inputs = 5,
  653. }, {
  654. .version = VI6_IP_VERSION_MODEL_VSPDL_GEN3,
  655. .model = "VSP2-DL",
  656. .gen = 3,
  657. .features = VSP1_HAS_BRS | VSP1_HAS_BRU | VSP1_HAS_EXT_DL,
  658. .lif_count = 2,
  659. .rpf_count = 5,
  660. .uif_count = 2,
  661. .wpf_count = 2,
  662. .num_bru_inputs = 5,
  663. },
  664. };
  665. static int vsp1_probe(struct platform_device *pdev)
  666. {
  667. struct vsp1_device *vsp1;
  668. struct device_node *fcp_node;
  669. struct resource *irq;
  670. struct resource *io;
  671. unsigned int i;
  672. int ret;
  673. vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
  674. if (vsp1 == NULL)
  675. return -ENOMEM;
  676. vsp1->dev = &pdev->dev;
  677. INIT_LIST_HEAD(&vsp1->entities);
  678. INIT_LIST_HEAD(&vsp1->videos);
  679. platform_set_drvdata(pdev, vsp1);
  680. /* I/O and IRQ resources (clock managed by the clock PM domain) */
  681. io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  682. vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
  683. if (IS_ERR(vsp1->mmio))
  684. return PTR_ERR(vsp1->mmio);
  685. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  686. if (!irq) {
  687. dev_err(&pdev->dev, "missing IRQ\n");
  688. return -EINVAL;
  689. }
  690. ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
  691. IRQF_SHARED, dev_name(&pdev->dev), vsp1);
  692. if (ret < 0) {
  693. dev_err(&pdev->dev, "failed to request IRQ\n");
  694. return ret;
  695. }
  696. /* FCP (optional) */
  697. fcp_node = of_parse_phandle(pdev->dev.of_node, "renesas,fcp", 0);
  698. if (fcp_node) {
  699. vsp1->fcp = rcar_fcp_get(fcp_node);
  700. of_node_put(fcp_node);
  701. if (IS_ERR(vsp1->fcp)) {
  702. dev_dbg(&pdev->dev, "FCP not found (%ld)\n",
  703. PTR_ERR(vsp1->fcp));
  704. return PTR_ERR(vsp1->fcp);
  705. }
  706. /*
  707. * When the FCP is present, it handles all bus master accesses
  708. * for the VSP and must thus be used in place of the VSP device
  709. * to map DMA buffers.
  710. */
  711. vsp1->bus_master = rcar_fcp_get_device(vsp1->fcp);
  712. } else {
  713. vsp1->bus_master = vsp1->dev;
  714. }
  715. /* Configure device parameters based on the version register. */
  716. pm_runtime_enable(&pdev->dev);
  717. ret = vsp1_device_get(vsp1);
  718. if (ret < 0)
  719. goto done;
  720. vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
  721. vsp1_device_put(vsp1);
  722. for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
  723. if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
  724. vsp1_device_infos[i].version) {
  725. vsp1->info = &vsp1_device_infos[i];
  726. break;
  727. }
  728. }
  729. if (!vsp1->info) {
  730. dev_err(&pdev->dev, "unsupported IP version 0x%08x\n",
  731. vsp1->version);
  732. ret = -ENXIO;
  733. goto done;
  734. }
  735. dev_dbg(&pdev->dev, "IP version 0x%08x\n", vsp1->version);
  736. /* Instanciate entities */
  737. ret = vsp1_create_entities(vsp1);
  738. if (ret < 0) {
  739. dev_err(&pdev->dev, "failed to create entities\n");
  740. goto done;
  741. }
  742. done:
  743. if (ret) {
  744. pm_runtime_disable(&pdev->dev);
  745. rcar_fcp_put(vsp1->fcp);
  746. }
  747. return ret;
  748. }
  749. static int vsp1_remove(struct platform_device *pdev)
  750. {
  751. struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
  752. vsp1_destroy_entities(vsp1);
  753. rcar_fcp_put(vsp1->fcp);
  754. pm_runtime_disable(&pdev->dev);
  755. return 0;
  756. }
  757. static const struct of_device_id vsp1_of_match[] = {
  758. { .compatible = "renesas,vsp1" },
  759. { .compatible = "renesas,vsp2" },
  760. { },
  761. };
  762. MODULE_DEVICE_TABLE(of, vsp1_of_match);
  763. static struct platform_driver vsp1_platform_driver = {
  764. .probe = vsp1_probe,
  765. .remove = vsp1_remove,
  766. .driver = {
  767. .name = "vsp1",
  768. .pm = &vsp1_pm_ops,
  769. .of_match_table = vsp1_of_match,
  770. },
  771. };
  772. module_platform_driver(vsp1_platform_driver);
  773. MODULE_ALIAS("vsp1");
  774. MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
  775. MODULE_DESCRIPTION("Renesas VSP1 Driver");
  776. MODULE_LICENSE("GPL");