vsp1_drv.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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_brx.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->entity.pipe);
  58. ret = IRQ_HANDLED;
  59. }
  60. }
  61. return ret;
  62. }
  63. /* -----------------------------------------------------------------------------
  64. * Entities
  65. */
  66. /*
  67. * vsp1_create_sink_links - Create links from all sources to the given sink
  68. *
  69. * This function creates media links from all valid sources to the given sink
  70. * pad. Links that would be invalid according to the VSP1 hardware capabilities
  71. * are skipped. Those include all links
  72. *
  73. * - from a UDS to a UDS (UDS entities can't be chained)
  74. * - from an entity to itself (no loops are allowed)
  75. *
  76. * Furthermore, the BRS can't be connected to histogram generators, but no
  77. * special check is currently needed as all VSP instances that include a BRS
  78. * have no histogram generator.
  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_HGO ||
  92. source->type == VSP1_ENTITY_HGT ||
  93. source->type == VSP1_ENTITY_LIF ||
  94. source->type == VSP1_ENTITY_WPF)
  95. continue;
  96. flags = source->type == VSP1_ENTITY_RPF &&
  97. sink->type == VSP1_ENTITY_WPF &&
  98. source->index == sink->index
  99. ? MEDIA_LNK_FL_ENABLED : 0;
  100. for (pad = 0; pad < entity->num_pads; ++pad) {
  101. if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
  102. continue;
  103. ret = media_create_pad_link(&source->subdev.entity,
  104. source->source_pad,
  105. entity, pad, flags);
  106. if (ret < 0)
  107. return ret;
  108. if (flags & MEDIA_LNK_FL_ENABLED)
  109. source->sink = sink;
  110. }
  111. }
  112. return 0;
  113. }
  114. static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
  115. {
  116. struct vsp1_entity *entity;
  117. unsigned int i;
  118. int ret;
  119. list_for_each_entry(entity, &vsp1->entities, list_dev) {
  120. if (entity->type == VSP1_ENTITY_LIF ||
  121. entity->type == VSP1_ENTITY_RPF)
  122. continue;
  123. ret = vsp1_create_sink_links(vsp1, entity);
  124. if (ret < 0)
  125. return ret;
  126. }
  127. if (vsp1->hgo) {
  128. ret = media_create_pad_link(&vsp1->hgo->histo.entity.subdev.entity,
  129. HISTO_PAD_SOURCE,
  130. &vsp1->hgo->histo.video.entity, 0,
  131. MEDIA_LNK_FL_ENABLED |
  132. MEDIA_LNK_FL_IMMUTABLE);
  133. if (ret < 0)
  134. return ret;
  135. }
  136. if (vsp1->hgt) {
  137. ret = media_create_pad_link(&vsp1->hgt->histo.entity.subdev.entity,
  138. HISTO_PAD_SOURCE,
  139. &vsp1->hgt->histo.video.entity, 0,
  140. MEDIA_LNK_FL_ENABLED |
  141. MEDIA_LNK_FL_IMMUTABLE);
  142. if (ret < 0)
  143. return ret;
  144. }
  145. for (i = 0; i < vsp1->info->lif_count; ++i) {
  146. if (!vsp1->lif[i])
  147. continue;
  148. ret = media_create_pad_link(&vsp1->wpf[i]->entity.subdev.entity,
  149. RWPF_PAD_SOURCE,
  150. &vsp1->lif[i]->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_BRS) {
  230. vsp1->brs = vsp1_brx_create(vsp1, VSP1_ENTITY_BRS);
  231. if (IS_ERR(vsp1->brs)) {
  232. ret = PTR_ERR(vsp1->brs);
  233. goto done;
  234. }
  235. list_add_tail(&vsp1->brs->entity.list_dev, &vsp1->entities);
  236. }
  237. if (vsp1->info->features & VSP1_HAS_BRU) {
  238. vsp1->bru = vsp1_brx_create(vsp1, VSP1_ENTITY_BRU);
  239. if (IS_ERR(vsp1->bru)) {
  240. ret = PTR_ERR(vsp1->bru);
  241. goto done;
  242. }
  243. list_add_tail(&vsp1->bru->entity.list_dev, &vsp1->entities);
  244. }
  245. if (vsp1->info->features & VSP1_HAS_CLU) {
  246. vsp1->clu = vsp1_clu_create(vsp1);
  247. if (IS_ERR(vsp1->clu)) {
  248. ret = PTR_ERR(vsp1->clu);
  249. goto done;
  250. }
  251. list_add_tail(&vsp1->clu->entity.list_dev, &vsp1->entities);
  252. }
  253. vsp1->hsi = vsp1_hsit_create(vsp1, true);
  254. if (IS_ERR(vsp1->hsi)) {
  255. ret = PTR_ERR(vsp1->hsi);
  256. goto done;
  257. }
  258. list_add_tail(&vsp1->hsi->entity.list_dev, &vsp1->entities);
  259. vsp1->hst = vsp1_hsit_create(vsp1, false);
  260. if (IS_ERR(vsp1->hst)) {
  261. ret = PTR_ERR(vsp1->hst);
  262. goto done;
  263. }
  264. list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
  265. if (vsp1->info->features & VSP1_HAS_HGO && vsp1->info->uapi) {
  266. vsp1->hgo = vsp1_hgo_create(vsp1);
  267. if (IS_ERR(vsp1->hgo)) {
  268. ret = PTR_ERR(vsp1->hgo);
  269. goto done;
  270. }
  271. list_add_tail(&vsp1->hgo->histo.entity.list_dev,
  272. &vsp1->entities);
  273. }
  274. if (vsp1->info->features & VSP1_HAS_HGT && vsp1->info->uapi) {
  275. vsp1->hgt = vsp1_hgt_create(vsp1);
  276. if (IS_ERR(vsp1->hgt)) {
  277. ret = PTR_ERR(vsp1->hgt);
  278. goto done;
  279. }
  280. list_add_tail(&vsp1->hgt->histo.entity.list_dev,
  281. &vsp1->entities);
  282. }
  283. /*
  284. * The LIFs are only supported when used in conjunction with the DU, in
  285. * which case the userspace API is disabled. If the userspace API is
  286. * enabled skip the LIFs, even when present.
  287. */
  288. if (!vsp1->info->uapi) {
  289. for (i = 0; i < vsp1->info->lif_count; ++i) {
  290. struct vsp1_lif *lif;
  291. lif = vsp1_lif_create(vsp1, i);
  292. if (IS_ERR(lif)) {
  293. ret = PTR_ERR(lif);
  294. goto done;
  295. }
  296. vsp1->lif[i] = lif;
  297. list_add_tail(&lif->entity.list_dev, &vsp1->entities);
  298. }
  299. }
  300. if (vsp1->info->features & VSP1_HAS_LUT) {
  301. vsp1->lut = vsp1_lut_create(vsp1);
  302. if (IS_ERR(vsp1->lut)) {
  303. ret = PTR_ERR(vsp1->lut);
  304. goto done;
  305. }
  306. list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
  307. }
  308. for (i = 0; i < vsp1->info->rpf_count; ++i) {
  309. struct vsp1_rwpf *rpf;
  310. rpf = vsp1_rpf_create(vsp1, i);
  311. if (IS_ERR(rpf)) {
  312. ret = PTR_ERR(rpf);
  313. goto done;
  314. }
  315. vsp1->rpf[i] = rpf;
  316. list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
  317. if (vsp1->info->uapi) {
  318. struct vsp1_video *video = vsp1_video_create(vsp1, rpf);
  319. if (IS_ERR(video)) {
  320. ret = PTR_ERR(video);
  321. goto done;
  322. }
  323. list_add_tail(&video->list, &vsp1->videos);
  324. }
  325. }
  326. if (vsp1->info->features & VSP1_HAS_SRU) {
  327. vsp1->sru = vsp1_sru_create(vsp1);
  328. if (IS_ERR(vsp1->sru)) {
  329. ret = PTR_ERR(vsp1->sru);
  330. goto done;
  331. }
  332. list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
  333. }
  334. for (i = 0; i < vsp1->info->uds_count; ++i) {
  335. struct vsp1_uds *uds;
  336. uds = vsp1_uds_create(vsp1, i);
  337. if (IS_ERR(uds)) {
  338. ret = PTR_ERR(uds);
  339. goto done;
  340. }
  341. vsp1->uds[i] = uds;
  342. list_add_tail(&uds->entity.list_dev, &vsp1->entities);
  343. }
  344. for (i = 0; i < vsp1->info->wpf_count; ++i) {
  345. struct vsp1_rwpf *wpf;
  346. wpf = vsp1_wpf_create(vsp1, i);
  347. if (IS_ERR(wpf)) {
  348. ret = PTR_ERR(wpf);
  349. goto done;
  350. }
  351. vsp1->wpf[i] = wpf;
  352. list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
  353. if (vsp1->info->uapi) {
  354. struct vsp1_video *video = vsp1_video_create(vsp1, wpf);
  355. if (IS_ERR(video)) {
  356. ret = PTR_ERR(video);
  357. goto done;
  358. }
  359. list_add_tail(&video->list, &vsp1->videos);
  360. }
  361. }
  362. /* Register all subdevs. */
  363. list_for_each_entry(entity, &vsp1->entities, list_dev) {
  364. ret = v4l2_device_register_subdev(&vsp1->v4l2_dev,
  365. &entity->subdev);
  366. if (ret < 0)
  367. goto done;
  368. }
  369. /*
  370. * Create links and register subdev nodes if the userspace API is
  371. * enabled or initialize the DRM pipeline otherwise.
  372. */
  373. if (vsp1->info->uapi) {
  374. ret = vsp1_uapi_create_links(vsp1);
  375. if (ret < 0)
  376. goto done;
  377. ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
  378. if (ret < 0)
  379. goto done;
  380. ret = media_device_register(mdev);
  381. } else {
  382. ret = vsp1_drm_init(vsp1);
  383. }
  384. done:
  385. if (ret < 0)
  386. vsp1_destroy_entities(vsp1);
  387. return ret;
  388. }
  389. int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
  390. {
  391. unsigned int timeout;
  392. u32 status;
  393. status = vsp1_read(vsp1, VI6_STATUS);
  394. if (!(status & VI6_STATUS_SYS_ACT(index)))
  395. return 0;
  396. vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(index));
  397. for (timeout = 10; timeout > 0; --timeout) {
  398. status = vsp1_read(vsp1, VI6_STATUS);
  399. if (!(status & VI6_STATUS_SYS_ACT(index)))
  400. break;
  401. usleep_range(1000, 2000);
  402. }
  403. if (!timeout) {
  404. dev_err(vsp1->dev, "failed to reset wpf.%u\n", index);
  405. return -ETIMEDOUT;
  406. }
  407. return 0;
  408. }
  409. static int vsp1_device_init(struct vsp1_device *vsp1)
  410. {
  411. unsigned int i;
  412. int ret;
  413. /* Reset any channel that might be running. */
  414. for (i = 0; i < vsp1->info->wpf_count; ++i) {
  415. ret = vsp1_reset_wpf(vsp1, i);
  416. if (ret < 0)
  417. return ret;
  418. }
  419. vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
  420. (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
  421. for (i = 0; i < vsp1->info->rpf_count; ++i)
  422. vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
  423. for (i = 0; i < vsp1->info->uds_count; ++i)
  424. vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
  425. vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
  426. vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
  427. vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
  428. vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
  429. vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
  430. vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
  431. if (vsp1->info->features & VSP1_HAS_BRS)
  432. vsp1_write(vsp1, VI6_DPR_ILV_BRS_ROUTE, VI6_DPR_NODE_UNUSED);
  433. vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
  434. (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
  435. vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
  436. (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
  437. vsp1_dlm_setup(vsp1);
  438. return 0;
  439. }
  440. /*
  441. * vsp1_device_get - Acquire the VSP1 device
  442. *
  443. * Make sure the device is not suspended and initialize it if needed.
  444. *
  445. * Return 0 on success or a negative error code otherwise.
  446. */
  447. int vsp1_device_get(struct vsp1_device *vsp1)
  448. {
  449. int ret;
  450. ret = pm_runtime_get_sync(vsp1->dev);
  451. return ret < 0 ? ret : 0;
  452. }
  453. /*
  454. * vsp1_device_put - Release the VSP1 device
  455. *
  456. * Decrement the VSP1 reference count and cleanup the device if the last
  457. * reference is released.
  458. */
  459. void vsp1_device_put(struct vsp1_device *vsp1)
  460. {
  461. pm_runtime_put_sync(vsp1->dev);
  462. }
  463. /* -----------------------------------------------------------------------------
  464. * Power Management
  465. */
  466. static int __maybe_unused vsp1_pm_suspend(struct device *dev)
  467. {
  468. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  469. /*
  470. * When used as part of a display pipeline, the VSP is stopped and
  471. * restarted explicitly by the DU.
  472. */
  473. if (!vsp1->drm)
  474. vsp1_pipelines_suspend(vsp1);
  475. pm_runtime_force_suspend(vsp1->dev);
  476. return 0;
  477. }
  478. static int __maybe_unused vsp1_pm_resume(struct device *dev)
  479. {
  480. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  481. pm_runtime_force_resume(vsp1->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_pipelines_resume(vsp1);
  488. return 0;
  489. }
  490. static int __maybe_unused vsp1_pm_runtime_suspend(struct device *dev)
  491. {
  492. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  493. rcar_fcp_disable(vsp1->fcp);
  494. return 0;
  495. }
  496. static int __maybe_unused vsp1_pm_runtime_resume(struct device *dev)
  497. {
  498. struct vsp1_device *vsp1 = dev_get_drvdata(dev);
  499. int ret;
  500. if (vsp1->info) {
  501. ret = vsp1_device_init(vsp1);
  502. if (ret < 0)
  503. return ret;
  504. }
  505. return rcar_fcp_enable(vsp1->fcp);
  506. }
  507. static const struct dev_pm_ops vsp1_pm_ops = {
  508. SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
  509. SET_RUNTIME_PM_OPS(vsp1_pm_runtime_suspend, vsp1_pm_runtime_resume, NULL)
  510. };
  511. /* -----------------------------------------------------------------------------
  512. * Platform Driver
  513. */
  514. static const struct vsp1_device_info vsp1_device_infos[] = {
  515. {
  516. .version = VI6_IP_VERSION_MODEL_VSPS_H2,
  517. .model = "VSP1-S",
  518. .gen = 2,
  519. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  520. | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
  521. | VSP1_HAS_WPF_VFLIP,
  522. .rpf_count = 5,
  523. .uds_count = 3,
  524. .wpf_count = 4,
  525. .num_bru_inputs = 4,
  526. .uapi = true,
  527. }, {
  528. .version = VI6_IP_VERSION_MODEL_VSPR_H2,
  529. .model = "VSP1-R",
  530. .gen = 2,
  531. .features = VSP1_HAS_BRU | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
  532. .rpf_count = 5,
  533. .uds_count = 3,
  534. .wpf_count = 4,
  535. .num_bru_inputs = 4,
  536. .uapi = true,
  537. }, {
  538. .version = VI6_IP_VERSION_MODEL_VSPD_GEN2,
  539. .model = "VSP1-D",
  540. .gen = 2,
  541. .features = VSP1_HAS_BRU | VSP1_HAS_HGO | VSP1_HAS_LUT,
  542. .lif_count = 1,
  543. .rpf_count = 4,
  544. .uds_count = 1,
  545. .wpf_count = 1,
  546. .num_bru_inputs = 4,
  547. .uapi = true,
  548. }, {
  549. .version = VI6_IP_VERSION_MODEL_VSPS_M2,
  550. .model = "VSP1-S",
  551. .gen = 2,
  552. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  553. | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
  554. | VSP1_HAS_WPF_VFLIP,
  555. .rpf_count = 5,
  556. .uds_count = 1,
  557. .wpf_count = 4,
  558. .num_bru_inputs = 4,
  559. .uapi = true,
  560. }, {
  561. .version = VI6_IP_VERSION_MODEL_VSPS_V2H,
  562. .model = "VSP1V-S",
  563. .gen = 2,
  564. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT
  565. | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
  566. .rpf_count = 4,
  567. .uds_count = 1,
  568. .wpf_count = 4,
  569. .num_bru_inputs = 4,
  570. .uapi = true,
  571. }, {
  572. .version = VI6_IP_VERSION_MODEL_VSPD_V2H,
  573. .model = "VSP1V-D",
  574. .gen = 2,
  575. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT,
  576. .lif_count = 1,
  577. .rpf_count = 4,
  578. .uds_count = 1,
  579. .wpf_count = 1,
  580. .num_bru_inputs = 4,
  581. .uapi = true,
  582. }, {
  583. .version = VI6_IP_VERSION_MODEL_VSPI_GEN3,
  584. .model = "VSP2-I",
  585. .gen = 3,
  586. .features = VSP1_HAS_CLU | VSP1_HAS_HGO | VSP1_HAS_HGT
  587. | VSP1_HAS_LUT | VSP1_HAS_SRU | VSP1_HAS_WPF_HFLIP
  588. | VSP1_HAS_WPF_VFLIP,
  589. .rpf_count = 1,
  590. .uds_count = 1,
  591. .wpf_count = 1,
  592. .uapi = true,
  593. }, {
  594. .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3,
  595. .model = "VSP2-BD",
  596. .gen = 3,
  597. .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP,
  598. .rpf_count = 5,
  599. .wpf_count = 1,
  600. .num_bru_inputs = 5,
  601. .uapi = true,
  602. }, {
  603. .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3,
  604. .model = "VSP2-BC",
  605. .gen = 3,
  606. .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
  607. | VSP1_HAS_LUT | VSP1_HAS_WPF_VFLIP,
  608. .rpf_count = 5,
  609. .wpf_count = 1,
  610. .num_bru_inputs = 5,
  611. .uapi = true,
  612. }, {
  613. .version = VI6_IP_VERSION_MODEL_VSPBS_GEN3,
  614. .model = "VSP2-BS",
  615. .gen = 3,
  616. .features = VSP1_HAS_BRS | VSP1_HAS_WPF_VFLIP,
  617. .rpf_count = 2,
  618. .wpf_count = 1,
  619. .uapi = true,
  620. }, {
  621. .version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
  622. .model = "VSP2-D",
  623. .gen = 3,
  624. .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP,
  625. .lif_count = 1,
  626. .rpf_count = 5,
  627. .wpf_count = 2,
  628. .num_bru_inputs = 5,
  629. }, {
  630. .version = VI6_IP_VERSION_MODEL_VSPD_V3,
  631. .model = "VSP2-D",
  632. .gen = 3,
  633. .features = VSP1_HAS_BRS | VSP1_HAS_BRU,
  634. .lif_count = 1,
  635. .rpf_count = 5,
  636. .wpf_count = 1,
  637. .num_bru_inputs = 5,
  638. }, {
  639. .version = VI6_IP_VERSION_MODEL_VSPDL_GEN3,
  640. .model = "VSP2-DL",
  641. .gen = 3,
  642. .features = VSP1_HAS_BRS | VSP1_HAS_BRU,
  643. .lif_count = 2,
  644. .rpf_count = 5,
  645. .wpf_count = 2,
  646. .num_bru_inputs = 5,
  647. },
  648. };
  649. static int vsp1_probe(struct platform_device *pdev)
  650. {
  651. struct vsp1_device *vsp1;
  652. struct device_node *fcp_node;
  653. struct resource *irq;
  654. struct resource *io;
  655. unsigned int i;
  656. int ret;
  657. vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
  658. if (vsp1 == NULL)
  659. return -ENOMEM;
  660. vsp1->dev = &pdev->dev;
  661. INIT_LIST_HEAD(&vsp1->entities);
  662. INIT_LIST_HEAD(&vsp1->videos);
  663. platform_set_drvdata(pdev, vsp1);
  664. /* I/O and IRQ resources (clock managed by the clock PM domain) */
  665. io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  666. vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
  667. if (IS_ERR(vsp1->mmio))
  668. return PTR_ERR(vsp1->mmio);
  669. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  670. if (!irq) {
  671. dev_err(&pdev->dev, "missing IRQ\n");
  672. return -EINVAL;
  673. }
  674. ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
  675. IRQF_SHARED, dev_name(&pdev->dev), vsp1);
  676. if (ret < 0) {
  677. dev_err(&pdev->dev, "failed to request IRQ\n");
  678. return ret;
  679. }
  680. /* FCP (optional) */
  681. fcp_node = of_parse_phandle(pdev->dev.of_node, "renesas,fcp", 0);
  682. if (fcp_node) {
  683. vsp1->fcp = rcar_fcp_get(fcp_node);
  684. of_node_put(fcp_node);
  685. if (IS_ERR(vsp1->fcp)) {
  686. dev_dbg(&pdev->dev, "FCP not found (%ld)\n",
  687. PTR_ERR(vsp1->fcp));
  688. return PTR_ERR(vsp1->fcp);
  689. }
  690. /*
  691. * When the FCP is present, it handles all bus master accesses
  692. * for the VSP and must thus be used in place of the VSP device
  693. * to map DMA buffers.
  694. */
  695. vsp1->bus_master = rcar_fcp_get_device(vsp1->fcp);
  696. } else {
  697. vsp1->bus_master = vsp1->dev;
  698. }
  699. /* Configure device parameters based on the version register. */
  700. pm_runtime_enable(&pdev->dev);
  701. ret = pm_runtime_get_sync(&pdev->dev);
  702. if (ret < 0)
  703. goto done;
  704. vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
  705. pm_runtime_put_sync(&pdev->dev);
  706. for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
  707. if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
  708. vsp1_device_infos[i].version) {
  709. vsp1->info = &vsp1_device_infos[i];
  710. break;
  711. }
  712. }
  713. if (!vsp1->info) {
  714. dev_err(&pdev->dev, "unsupported IP version 0x%08x\n",
  715. vsp1->version);
  716. ret = -ENXIO;
  717. goto done;
  718. }
  719. dev_dbg(&pdev->dev, "IP version 0x%08x\n", vsp1->version);
  720. /* Instanciate entities */
  721. ret = vsp1_create_entities(vsp1);
  722. if (ret < 0) {
  723. dev_err(&pdev->dev, "failed to create entities\n");
  724. goto done;
  725. }
  726. done:
  727. if (ret)
  728. pm_runtime_disable(&pdev->dev);
  729. return ret;
  730. }
  731. static int vsp1_remove(struct platform_device *pdev)
  732. {
  733. struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
  734. vsp1_destroy_entities(vsp1);
  735. rcar_fcp_put(vsp1->fcp);
  736. pm_runtime_disable(&pdev->dev);
  737. return 0;
  738. }
  739. static const struct of_device_id vsp1_of_match[] = {
  740. { .compatible = "renesas,vsp1" },
  741. { .compatible = "renesas,vsp2" },
  742. { },
  743. };
  744. MODULE_DEVICE_TABLE(of, vsp1_of_match);
  745. static struct platform_driver vsp1_platform_driver = {
  746. .probe = vsp1_probe,
  747. .remove = vsp1_remove,
  748. .driver = {
  749. .name = "vsp1",
  750. .pm = &vsp1_pm_ops,
  751. .of_match_table = vsp1_of_match,
  752. },
  753. };
  754. module_platform_driver(vsp1_platform_driver);
  755. MODULE_ALIAS("vsp1");
  756. MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
  757. MODULE_DESCRIPTION("Renesas VSP1 Driver");
  758. MODULE_LICENSE("GPL");