vsp1_drv.c 19 KB

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