vsp1_drv.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. return ret < 0 ? ret : 0;
  461. }
  462. /*
  463. * vsp1_device_put - Release the VSP1 device
  464. *
  465. * Decrement the VSP1 reference count and cleanup the device if the last
  466. * reference is released.
  467. */
  468. void vsp1_device_put(struct vsp1_device *vsp1)
  469. {
  470. pm_runtime_put_sync(vsp1->dev);
  471. }
  472. /* -----------------------------------------------------------------------------
  473. * Power Management
  474. */
  475. static int __maybe_unused vsp1_pm_suspend(struct device *dev)
  476. {
  477. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  478. /*
  479. * When used as part of a display pipeline, the VSP is stopped and
  480. * restarted explicitly by the DU.
  481. */
  482. if (!vsp1->drm)
  483. vsp1_video_suspend(vsp1);
  484. pm_runtime_force_suspend(vsp1->dev);
  485. return 0;
  486. }
  487. static int __maybe_unused vsp1_pm_resume(struct device *dev)
  488. {
  489. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  490. pm_runtime_force_resume(vsp1->dev);
  491. /*
  492. * When used as part of a display pipeline, the VSP is stopped and
  493. * restarted explicitly by the DU.
  494. */
  495. if (!vsp1->drm)
  496. vsp1_video_resume(vsp1);
  497. return 0;
  498. }
  499. static int __maybe_unused vsp1_pm_runtime_suspend(struct device *dev)
  500. {
  501. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  502. rcar_fcp_disable(vsp1->fcp);
  503. return 0;
  504. }
  505. static int __maybe_unused vsp1_pm_runtime_resume(struct device *dev)
  506. {
  507. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  508. int ret;
  509. if (vsp1->info) {
  510. ret = vsp1_device_init(vsp1);
  511. if (ret < 0)
  512. return ret;
  513. }
  514. return rcar_fcp_enable(vsp1->fcp);
  515. }
  516. static const struct dev_pm_ops vsp1_pm_ops = {
  517. SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
  518. SET_RUNTIME_PM_OPS(vsp1_pm_runtime_suspend, vsp1_pm_runtime_resume, NULL)
  519. };
  520. /* -----------------------------------------------------------------------------
  521. * Platform Driver
  522. */
  523. static const struct vsp1_device_info vsp1_device_infos[] = {
  524. {
  525. .version = VI6_IP_VERSION_MODEL_VSPS_H2,
  526. .model = "VSP1-S",
  527. .gen = 2,
  528. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  529. | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
  530. | VSP1_HAS_WPF_VFLIP,
  531. .rpf_count = 5,
  532. .uds_count = 3,
  533. .wpf_count = 4,
  534. .num_bru_inputs = 4,
  535. .uapi = true,
  536. }, {
  537. .version = VI6_IP_VERSION_MODEL_VSPR_H2,
  538. .model = "VSP1-R",
  539. .gen = 2,
  540. .features = VSP1_HAS_BRU | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
  541. .rpf_count = 5,
  542. .uds_count = 3,
  543. .wpf_count = 4,
  544. .num_bru_inputs = 4,
  545. .uapi = true,
  546. }, {
  547. .version = VI6_IP_VERSION_MODEL_VSPD_GEN2,
  548. .model = "VSP1-D",
  549. .gen = 2,
  550. .features = VSP1_HAS_BRU | VSP1_HAS_HGO | VSP1_HAS_LUT,
  551. .lif_count = 1,
  552. .rpf_count = 4,
  553. .uds_count = 1,
  554. .wpf_count = 1,
  555. .num_bru_inputs = 4,
  556. .uapi = true,
  557. }, {
  558. .version = VI6_IP_VERSION_MODEL_VSPS_M2,
  559. .model = "VSP1-S",
  560. .gen = 2,
  561. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  562. | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
  563. | VSP1_HAS_WPF_VFLIP,
  564. .rpf_count = 5,
  565. .uds_count = 1,
  566. .wpf_count = 4,
  567. .num_bru_inputs = 4,
  568. .uapi = true,
  569. }, {
  570. .version = VI6_IP_VERSION_MODEL_VSPS_V2H,
  571. .model = "VSP1V-S",
  572. .gen = 2,
  573. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT
  574. | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
  575. .rpf_count = 4,
  576. .uds_count = 1,
  577. .wpf_count = 4,
  578. .num_bru_inputs = 4,
  579. .uapi = true,
  580. }, {
  581. .version = VI6_IP_VERSION_MODEL_VSPD_V2H,
  582. .model = "VSP1V-D",
  583. .gen = 2,
  584. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT,
  585. .lif_count = 1,
  586. .rpf_count = 4,
  587. .uds_count = 1,
  588. .wpf_count = 1,
  589. .num_bru_inputs = 4,
  590. .uapi = true,
  591. }, {
  592. .version = VI6_IP_VERSION_MODEL_VSPI_GEN3,
  593. .model = "VSP2-I",
  594. .gen = 3,
  595. .features = VSP1_HAS_CLU | VSP1_HAS_HGO | VSP1_HAS_HGT
  596. | VSP1_HAS_LUT | VSP1_HAS_SRU | VSP1_HAS_WPF_HFLIP
  597. | VSP1_HAS_WPF_VFLIP,
  598. .rpf_count = 1,
  599. .uds_count = 1,
  600. .wpf_count = 1,
  601. .uapi = true,
  602. }, {
  603. .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3,
  604. .model = "VSP2-BD",
  605. .gen = 3,
  606. .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP,
  607. .rpf_count = 5,
  608. .wpf_count = 1,
  609. .num_bru_inputs = 5,
  610. .uapi = true,
  611. }, {
  612. .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3,
  613. .model = "VSP2-BC",
  614. .gen = 3,
  615. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  616. | VSP1_HAS_LUT | VSP1_HAS_WPF_VFLIP,
  617. .rpf_count = 5,
  618. .wpf_count = 1,
  619. .num_bru_inputs = 5,
  620. .uapi = true,
  621. }, {
  622. .version = VI6_IP_VERSION_MODEL_VSPBS_GEN3,
  623. .model = "VSP2-BS",
  624. .gen = 3,
  625. .features = VSP1_HAS_BRS | VSP1_HAS_WPF_VFLIP,
  626. .rpf_count = 2,
  627. .wpf_count = 1,
  628. .uapi = true,
  629. }, {
  630. .version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
  631. .model = "VSP2-D",
  632. .gen = 3,
  633. .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP | VSP1_HAS_EXT_DL,
  634. .lif_count = 1,
  635. .rpf_count = 5,
  636. .uif_count = 1,
  637. .wpf_count = 2,
  638. .num_bru_inputs = 5,
  639. }, {
  640. .version = VI6_IP_VERSION_MODEL_VSPD_V3,
  641. .model = "VSP2-D",
  642. .gen = 3,
  643. .features = VSP1_HAS_BRS | VSP1_HAS_BRU,
  644. .lif_count = 1,
  645. .rpf_count = 5,
  646. .uif_count = 1,
  647. .wpf_count = 1,
  648. .num_bru_inputs = 5,
  649. }, {
  650. .version = VI6_IP_VERSION_MODEL_VSPDL_GEN3,
  651. .model = "VSP2-DL",
  652. .gen = 3,
  653. .features = VSP1_HAS_BRS | VSP1_HAS_BRU | VSP1_HAS_EXT_DL,
  654. .lif_count = 2,
  655. .rpf_count = 5,
  656. .uif_count = 2,
  657. .wpf_count = 2,
  658. .num_bru_inputs = 5,
  659. },
  660. };
  661. static int vsp1_probe(struct platform_device *pdev)
  662. {
  663. struct vsp1_device *vsp1;
  664. struct device_node *fcp_node;
  665. struct resource *irq;
  666. struct resource *io;
  667. unsigned int i;
  668. int ret;
  669. vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
  670. if (vsp1 == NULL)
  671. return -ENOMEM;
  672. vsp1->dev = &pdev->dev;
  673. INIT_LIST_HEAD(&vsp1->entities);
  674. INIT_LIST_HEAD(&vsp1->videos);
  675. platform_set_drvdata(pdev, vsp1);
  676. /* I/O and IRQ resources (clock managed by the clock PM domain) */
  677. io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  678. vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
  679. if (IS_ERR(vsp1->mmio))
  680. return PTR_ERR(vsp1->mmio);
  681. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  682. if (!irq) {
  683. dev_err(&pdev->dev, "missing IRQ\n");
  684. return -EINVAL;
  685. }
  686. ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
  687. IRQF_SHARED, dev_name(&pdev->dev), vsp1);
  688. if (ret < 0) {
  689. dev_err(&pdev->dev, "failed to request IRQ\n");
  690. return ret;
  691. }
  692. /* FCP (optional) */
  693. fcp_node = of_parse_phandle(pdev->dev.of_node, "renesas,fcp", 0);
  694. if (fcp_node) {
  695. vsp1->fcp = rcar_fcp_get(fcp_node);
  696. of_node_put(fcp_node);
  697. if (IS_ERR(vsp1->fcp)) {
  698. dev_dbg(&pdev->dev, "FCP not found (%ld)\n",
  699. PTR_ERR(vsp1->fcp));
  700. return PTR_ERR(vsp1->fcp);
  701. }
  702. /*
  703. * When the FCP is present, it handles all bus master accesses
  704. * for the VSP and must thus be used in place of the VSP device
  705. * to map DMA buffers.
  706. */
  707. vsp1->bus_master = rcar_fcp_get_device(vsp1->fcp);
  708. } else {
  709. vsp1->bus_master = vsp1->dev;
  710. }
  711. /* Configure device parameters based on the version register. */
  712. pm_runtime_enable(&pdev->dev);
  713. ret = pm_runtime_get_sync(&pdev->dev);
  714. if (ret < 0)
  715. goto done;
  716. vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
  717. pm_runtime_put_sync(&pdev->dev);
  718. for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
  719. if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
  720. vsp1_device_infos[i].version) {
  721. vsp1->info = &vsp1_device_infos[i];
  722. break;
  723. }
  724. }
  725. if (!vsp1->info) {
  726. dev_err(&pdev->dev, "unsupported IP version 0x%08x\n",
  727. vsp1->version);
  728. ret = -ENXIO;
  729. goto done;
  730. }
  731. dev_dbg(&pdev->dev, "IP version 0x%08x\n", vsp1->version);
  732. /* Instanciate entities */
  733. ret = vsp1_create_entities(vsp1);
  734. if (ret < 0) {
  735. dev_err(&pdev->dev, "failed to create entities\n");
  736. goto done;
  737. }
  738. done:
  739. if (ret)
  740. pm_runtime_disable(&pdev->dev);
  741. return ret;
  742. }
  743. static int vsp1_remove(struct platform_device *pdev)
  744. {
  745. struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
  746. vsp1_destroy_entities(vsp1);
  747. rcar_fcp_put(vsp1->fcp);
  748. pm_runtime_disable(&pdev->dev);
  749. return 0;
  750. }
  751. static const struct of_device_id vsp1_of_match[] = {
  752. { .compatible = "renesas,vsp1" },
  753. { .compatible = "renesas,vsp2" },
  754. { },
  755. };
  756. MODULE_DEVICE_TABLE(of, vsp1_of_match);
  757. static struct platform_driver vsp1_platform_driver = {
  758. .probe = vsp1_probe,
  759. .remove = vsp1_remove,
  760. .driver = {
  761. .name = "vsp1",
  762. .pm = &vsp1_pm_ops,
  763. .of_match_table = vsp1_of_match,
  764. },
  765. };
  766. module_platform_driver(vsp1_platform_driver);
  767. MODULE_ALIAS("vsp1");
  768. MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
  769. MODULE_DESCRIPTION("Renesas VSP1 Driver");
  770. MODULE_LICENSE("GPL");