vsp1_drv.c 20 KB

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