exynos_drm_rotator.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * YoungJun Cho <yj44.cho@samsung.com>
  5. * Eunchul Kim <chulspro.kim@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundationr
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/err.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <linux/pm_runtime.h>
  18. #include <drm/drmP.h>
  19. #include <drm/exynos_drm.h>
  20. #include "regs-rotator.h"
  21. #include "exynos_drm.h"
  22. #include "exynos_drm_drv.h"
  23. #include "exynos_drm_ipp.h"
  24. /*
  25. * Rotator supports image crop/rotator and input/output DMA operations.
  26. * input DMA reads image data from the memory.
  27. * output DMA writes image data to memory.
  28. *
  29. * M2M operation : supports crop/scale/rotation/csc so on.
  30. * Memory ----> Rotator H/W ----> Memory.
  31. */
  32. /*
  33. * TODO
  34. * 1. check suspend/resume api if needed.
  35. * 2. need to check use case platform_device_id.
  36. * 3. check src/dst size with, height.
  37. * 4. need to add supported list in prop_list.
  38. */
  39. #define get_rot_context(dev) platform_get_drvdata(to_platform_device(dev))
  40. #define get_ctx_from_ippdrv(ippdrv) container_of(ippdrv,\
  41. struct rot_context, ippdrv);
  42. #define rot_read(offset) readl(rot->regs + (offset))
  43. #define rot_write(cfg, offset) writel(cfg, rot->regs + (offset))
  44. enum rot_irq_status {
  45. ROT_IRQ_STATUS_COMPLETE = 8,
  46. ROT_IRQ_STATUS_ILLEGAL = 9,
  47. };
  48. /*
  49. * A structure of limitation.
  50. *
  51. * @min_w: minimum width.
  52. * @min_h: minimum height.
  53. * @max_w: maximum width.
  54. * @max_h: maximum height.
  55. * @align: align size.
  56. */
  57. struct rot_limit {
  58. u32 min_w;
  59. u32 min_h;
  60. u32 max_w;
  61. u32 max_h;
  62. u32 align;
  63. };
  64. /*
  65. * A structure of limitation table.
  66. *
  67. * @ycbcr420_2p: case of YUV.
  68. * @rgb888: case of RGB.
  69. */
  70. struct rot_limit_table {
  71. struct rot_limit ycbcr420_2p;
  72. struct rot_limit rgb888;
  73. };
  74. /*
  75. * A structure of rotator context.
  76. * @ippdrv: prepare initialization using ippdrv.
  77. * @regs_res: register resources.
  78. * @regs: memory mapped io registers.
  79. * @clock: rotator gate clock.
  80. * @limit_tbl: limitation of rotator.
  81. * @irq: irq number.
  82. * @cur_buf_id: current operation buffer id.
  83. * @suspended: suspended state.
  84. */
  85. struct rot_context {
  86. struct exynos_drm_ippdrv ippdrv;
  87. struct resource *regs_res;
  88. void __iomem *regs;
  89. struct clk *clock;
  90. struct rot_limit_table *limit_tbl;
  91. int irq;
  92. int cur_buf_id[EXYNOS_DRM_OPS_MAX];
  93. bool suspended;
  94. };
  95. static void rotator_reg_set_irq(struct rot_context *rot, bool enable)
  96. {
  97. u32 val = rot_read(ROT_CONFIG);
  98. if (enable == true)
  99. val |= ROT_CONFIG_IRQ;
  100. else
  101. val &= ~ROT_CONFIG_IRQ;
  102. rot_write(val, ROT_CONFIG);
  103. }
  104. static u32 rotator_reg_get_fmt(struct rot_context *rot)
  105. {
  106. u32 val = rot_read(ROT_CONTROL);
  107. val &= ROT_CONTROL_FMT_MASK;
  108. return val;
  109. }
  110. static enum rot_irq_status rotator_reg_get_irq_status(struct rot_context *rot)
  111. {
  112. u32 val = rot_read(ROT_STATUS);
  113. val = ROT_STATUS_IRQ(val);
  114. if (val == ROT_STATUS_IRQ_VAL_COMPLETE)
  115. return ROT_IRQ_STATUS_COMPLETE;
  116. return ROT_IRQ_STATUS_ILLEGAL;
  117. }
  118. static irqreturn_t rotator_irq_handler(int irq, void *arg)
  119. {
  120. struct rot_context *rot = arg;
  121. struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
  122. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  123. struct drm_exynos_ipp_event_work *event_work = c_node->event_work;
  124. enum rot_irq_status irq_status;
  125. u32 val;
  126. /* Get execution result */
  127. irq_status = rotator_reg_get_irq_status(rot);
  128. /* clear status */
  129. val = rot_read(ROT_STATUS);
  130. val |= ROT_STATUS_IRQ_PENDING((u32)irq_status);
  131. rot_write(val, ROT_STATUS);
  132. if (irq_status == ROT_IRQ_STATUS_COMPLETE) {
  133. event_work->ippdrv = ippdrv;
  134. event_work->buf_id[EXYNOS_DRM_OPS_DST] =
  135. rot->cur_buf_id[EXYNOS_DRM_OPS_DST];
  136. queue_work(ippdrv->event_workq, &event_work->work);
  137. } else {
  138. DRM_ERROR("the SFR is set illegally\n");
  139. }
  140. return IRQ_HANDLED;
  141. }
  142. static void rotator_align_size(struct rot_context *rot, u32 fmt, u32 *hsize,
  143. u32 *vsize)
  144. {
  145. struct rot_limit_table *limit_tbl = rot->limit_tbl;
  146. struct rot_limit *limit;
  147. u32 mask, val;
  148. /* Get size limit */
  149. if (fmt == ROT_CONTROL_FMT_RGB888)
  150. limit = &limit_tbl->rgb888;
  151. else
  152. limit = &limit_tbl->ycbcr420_2p;
  153. /* Get mask for rounding to nearest aligned val */
  154. mask = ~((1 << limit->align) - 1);
  155. /* Set aligned width */
  156. val = ROT_ALIGN(*hsize, limit->align, mask);
  157. if (val < limit->min_w)
  158. *hsize = ROT_MIN(limit->min_w, mask);
  159. else if (val > limit->max_w)
  160. *hsize = ROT_MAX(limit->max_w, mask);
  161. else
  162. *hsize = val;
  163. /* Set aligned height */
  164. val = ROT_ALIGN(*vsize, limit->align, mask);
  165. if (val < limit->min_h)
  166. *vsize = ROT_MIN(limit->min_h, mask);
  167. else if (val > limit->max_h)
  168. *vsize = ROT_MAX(limit->max_h, mask);
  169. else
  170. *vsize = val;
  171. }
  172. static int rotator_src_set_fmt(struct device *dev, u32 fmt)
  173. {
  174. struct rot_context *rot = dev_get_drvdata(dev);
  175. u32 val;
  176. val = rot_read(ROT_CONTROL);
  177. val &= ~ROT_CONTROL_FMT_MASK;
  178. switch (fmt) {
  179. case DRM_FORMAT_NV12:
  180. val |= ROT_CONTROL_FMT_YCBCR420_2P;
  181. break;
  182. case DRM_FORMAT_XRGB8888:
  183. val |= ROT_CONTROL_FMT_RGB888;
  184. break;
  185. default:
  186. DRM_ERROR("invalid image format\n");
  187. return -EINVAL;
  188. }
  189. rot_write(val, ROT_CONTROL);
  190. return 0;
  191. }
  192. static inline bool rotator_check_reg_fmt(u32 fmt)
  193. {
  194. if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) ||
  195. (fmt == ROT_CONTROL_FMT_RGB888))
  196. return true;
  197. return false;
  198. }
  199. static int rotator_src_set_size(struct device *dev, int swap,
  200. struct drm_exynos_pos *pos,
  201. struct drm_exynos_sz *sz)
  202. {
  203. struct rot_context *rot = dev_get_drvdata(dev);
  204. u32 fmt, hsize, vsize;
  205. u32 val;
  206. /* Get format */
  207. fmt = rotator_reg_get_fmt(rot);
  208. if (!rotator_check_reg_fmt(fmt)) {
  209. DRM_ERROR("invalid format.\n");
  210. return -EINVAL;
  211. }
  212. /* Align buffer size */
  213. hsize = sz->hsize;
  214. vsize = sz->vsize;
  215. rotator_align_size(rot, fmt, &hsize, &vsize);
  216. /* Set buffer size configuration */
  217. val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
  218. rot_write(val, ROT_SRC_BUF_SIZE);
  219. /* Set crop image position configuration */
  220. val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
  221. rot_write(val, ROT_SRC_CROP_POS);
  222. val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
  223. rot_write(val, ROT_SRC_CROP_SIZE);
  224. return 0;
  225. }
  226. static int rotator_src_set_addr(struct device *dev,
  227. struct drm_exynos_ipp_buf_info *buf_info,
  228. u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
  229. {
  230. struct rot_context *rot = dev_get_drvdata(dev);
  231. dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
  232. u32 val, fmt, hsize, vsize;
  233. int i;
  234. /* Set current buf_id */
  235. rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
  236. switch (buf_type) {
  237. case IPP_BUF_ENQUEUE:
  238. /* Set address configuration */
  239. for_each_ipp_planar(i)
  240. addr[i] = buf_info->base[i];
  241. /* Get format */
  242. fmt = rotator_reg_get_fmt(rot);
  243. if (!rotator_check_reg_fmt(fmt)) {
  244. DRM_ERROR("invalid format.\n");
  245. return -EINVAL;
  246. }
  247. /* Re-set cb planar for NV12 format */
  248. if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
  249. !addr[EXYNOS_DRM_PLANAR_CB]) {
  250. val = rot_read(ROT_SRC_BUF_SIZE);
  251. hsize = ROT_GET_BUF_SIZE_W(val);
  252. vsize = ROT_GET_BUF_SIZE_H(val);
  253. /* Set cb planar */
  254. addr[EXYNOS_DRM_PLANAR_CB] =
  255. addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
  256. }
  257. for_each_ipp_planar(i)
  258. rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
  259. break;
  260. case IPP_BUF_DEQUEUE:
  261. for_each_ipp_planar(i)
  262. rot_write(0x0, ROT_SRC_BUF_ADDR(i));
  263. break;
  264. default:
  265. /* Nothing to do */
  266. break;
  267. }
  268. return 0;
  269. }
  270. static int rotator_dst_set_transf(struct device *dev,
  271. enum drm_exynos_degree degree,
  272. enum drm_exynos_flip flip, bool *swap)
  273. {
  274. struct rot_context *rot = dev_get_drvdata(dev);
  275. u32 val;
  276. /* Set transform configuration */
  277. val = rot_read(ROT_CONTROL);
  278. val &= ~ROT_CONTROL_FLIP_MASK;
  279. switch (flip) {
  280. case EXYNOS_DRM_FLIP_VERTICAL:
  281. val |= ROT_CONTROL_FLIP_VERTICAL;
  282. break;
  283. case EXYNOS_DRM_FLIP_HORIZONTAL:
  284. val |= ROT_CONTROL_FLIP_HORIZONTAL;
  285. break;
  286. default:
  287. /* Flip None */
  288. break;
  289. }
  290. val &= ~ROT_CONTROL_ROT_MASK;
  291. switch (degree) {
  292. case EXYNOS_DRM_DEGREE_90:
  293. val |= ROT_CONTROL_ROT_90;
  294. break;
  295. case EXYNOS_DRM_DEGREE_180:
  296. val |= ROT_CONTROL_ROT_180;
  297. break;
  298. case EXYNOS_DRM_DEGREE_270:
  299. val |= ROT_CONTROL_ROT_270;
  300. break;
  301. default:
  302. /* Rotation 0 Degree */
  303. break;
  304. }
  305. rot_write(val, ROT_CONTROL);
  306. /* Check degree for setting buffer size swap */
  307. if ((degree == EXYNOS_DRM_DEGREE_90) ||
  308. (degree == EXYNOS_DRM_DEGREE_270))
  309. *swap = true;
  310. else
  311. *swap = false;
  312. return 0;
  313. }
  314. static int rotator_dst_set_size(struct device *dev, int swap,
  315. struct drm_exynos_pos *pos,
  316. struct drm_exynos_sz *sz)
  317. {
  318. struct rot_context *rot = dev_get_drvdata(dev);
  319. u32 val, fmt, hsize, vsize;
  320. /* Get format */
  321. fmt = rotator_reg_get_fmt(rot);
  322. if (!rotator_check_reg_fmt(fmt)) {
  323. DRM_ERROR("invalid format.\n");
  324. return -EINVAL;
  325. }
  326. /* Align buffer size */
  327. hsize = sz->hsize;
  328. vsize = sz->vsize;
  329. rotator_align_size(rot, fmt, &hsize, &vsize);
  330. /* Set buffer size configuration */
  331. val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
  332. rot_write(val, ROT_DST_BUF_SIZE);
  333. /* Set crop image position configuration */
  334. val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
  335. rot_write(val, ROT_DST_CROP_POS);
  336. return 0;
  337. }
  338. static int rotator_dst_set_addr(struct device *dev,
  339. struct drm_exynos_ipp_buf_info *buf_info,
  340. u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
  341. {
  342. struct rot_context *rot = dev_get_drvdata(dev);
  343. dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
  344. u32 val, fmt, hsize, vsize;
  345. int i;
  346. /* Set current buf_id */
  347. rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
  348. switch (buf_type) {
  349. case IPP_BUF_ENQUEUE:
  350. /* Set address configuration */
  351. for_each_ipp_planar(i)
  352. addr[i] = buf_info->base[i];
  353. /* Get format */
  354. fmt = rotator_reg_get_fmt(rot);
  355. if (!rotator_check_reg_fmt(fmt)) {
  356. DRM_ERROR("invalid format.\n");
  357. return -EINVAL;
  358. }
  359. /* Re-set cb planar for NV12 format */
  360. if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
  361. !addr[EXYNOS_DRM_PLANAR_CB]) {
  362. /* Get buf size */
  363. val = rot_read(ROT_DST_BUF_SIZE);
  364. hsize = ROT_GET_BUF_SIZE_W(val);
  365. vsize = ROT_GET_BUF_SIZE_H(val);
  366. /* Set cb planar */
  367. addr[EXYNOS_DRM_PLANAR_CB] =
  368. addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
  369. }
  370. for_each_ipp_planar(i)
  371. rot_write(addr[i], ROT_DST_BUF_ADDR(i));
  372. break;
  373. case IPP_BUF_DEQUEUE:
  374. for_each_ipp_planar(i)
  375. rot_write(0x0, ROT_DST_BUF_ADDR(i));
  376. break;
  377. default:
  378. /* Nothing to do */
  379. break;
  380. }
  381. return 0;
  382. }
  383. static struct exynos_drm_ipp_ops rot_src_ops = {
  384. .set_fmt = rotator_src_set_fmt,
  385. .set_size = rotator_src_set_size,
  386. .set_addr = rotator_src_set_addr,
  387. };
  388. static struct exynos_drm_ipp_ops rot_dst_ops = {
  389. .set_transf = rotator_dst_set_transf,
  390. .set_size = rotator_dst_set_size,
  391. .set_addr = rotator_dst_set_addr,
  392. };
  393. static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
  394. {
  395. struct drm_exynos_ipp_prop_list *prop_list = &ippdrv->prop_list;
  396. prop_list->version = 1;
  397. prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
  398. (1 << EXYNOS_DRM_FLIP_HORIZONTAL);
  399. prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
  400. (1 << EXYNOS_DRM_DEGREE_90) |
  401. (1 << EXYNOS_DRM_DEGREE_180) |
  402. (1 << EXYNOS_DRM_DEGREE_270);
  403. prop_list->csc = 0;
  404. prop_list->crop = 0;
  405. prop_list->scale = 0;
  406. return 0;
  407. }
  408. static inline bool rotator_check_drm_fmt(u32 fmt)
  409. {
  410. switch (fmt) {
  411. case DRM_FORMAT_XRGB8888:
  412. case DRM_FORMAT_NV12:
  413. return true;
  414. default:
  415. DRM_DEBUG_KMS("not support format\n");
  416. return false;
  417. }
  418. }
  419. static inline bool rotator_check_drm_flip(enum drm_exynos_flip flip)
  420. {
  421. switch (flip) {
  422. case EXYNOS_DRM_FLIP_NONE:
  423. case EXYNOS_DRM_FLIP_VERTICAL:
  424. case EXYNOS_DRM_FLIP_HORIZONTAL:
  425. case EXYNOS_DRM_FLIP_BOTH:
  426. return true;
  427. default:
  428. DRM_DEBUG_KMS("invalid flip\n");
  429. return false;
  430. }
  431. }
  432. static int rotator_ippdrv_check_property(struct device *dev,
  433. struct drm_exynos_ipp_property *property)
  434. {
  435. struct drm_exynos_ipp_config *src_config =
  436. &property->config[EXYNOS_DRM_OPS_SRC];
  437. struct drm_exynos_ipp_config *dst_config =
  438. &property->config[EXYNOS_DRM_OPS_DST];
  439. struct drm_exynos_pos *src_pos = &src_config->pos;
  440. struct drm_exynos_pos *dst_pos = &dst_config->pos;
  441. struct drm_exynos_sz *src_sz = &src_config->sz;
  442. struct drm_exynos_sz *dst_sz = &dst_config->sz;
  443. bool swap = false;
  444. /* Check format configuration */
  445. if (src_config->fmt != dst_config->fmt) {
  446. DRM_DEBUG_KMS("not support csc feature\n");
  447. return -EINVAL;
  448. }
  449. if (!rotator_check_drm_fmt(dst_config->fmt)) {
  450. DRM_DEBUG_KMS("invalid format\n");
  451. return -EINVAL;
  452. }
  453. /* Check transform configuration */
  454. if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
  455. DRM_DEBUG_KMS("not support source-side rotation\n");
  456. return -EINVAL;
  457. }
  458. switch (dst_config->degree) {
  459. case EXYNOS_DRM_DEGREE_90:
  460. case EXYNOS_DRM_DEGREE_270:
  461. swap = true;
  462. case EXYNOS_DRM_DEGREE_0:
  463. case EXYNOS_DRM_DEGREE_180:
  464. /* No problem */
  465. break;
  466. default:
  467. DRM_DEBUG_KMS("invalid degree\n");
  468. return -EINVAL;
  469. }
  470. if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
  471. DRM_DEBUG_KMS("not support source-side flip\n");
  472. return -EINVAL;
  473. }
  474. if (!rotator_check_drm_flip(dst_config->flip)) {
  475. DRM_DEBUG_KMS("invalid flip\n");
  476. return -EINVAL;
  477. }
  478. /* Check size configuration */
  479. if ((src_pos->x + src_pos->w > src_sz->hsize) ||
  480. (src_pos->y + src_pos->h > src_sz->vsize)) {
  481. DRM_DEBUG_KMS("out of source buffer bound\n");
  482. return -EINVAL;
  483. }
  484. if (swap) {
  485. if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
  486. (dst_pos->y + dst_pos->w > dst_sz->hsize)) {
  487. DRM_DEBUG_KMS("out of destination buffer bound\n");
  488. return -EINVAL;
  489. }
  490. if ((src_pos->w != dst_pos->h) || (src_pos->h != dst_pos->w)) {
  491. DRM_DEBUG_KMS("not support scale feature\n");
  492. return -EINVAL;
  493. }
  494. } else {
  495. if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
  496. (dst_pos->y + dst_pos->h > dst_sz->vsize)) {
  497. DRM_DEBUG_KMS("out of destination buffer bound\n");
  498. return -EINVAL;
  499. }
  500. if ((src_pos->w != dst_pos->w) || (src_pos->h != dst_pos->h)) {
  501. DRM_DEBUG_KMS("not support scale feature\n");
  502. return -EINVAL;
  503. }
  504. }
  505. return 0;
  506. }
  507. static int rotator_ippdrv_start(struct device *dev, enum drm_exynos_ipp_cmd cmd)
  508. {
  509. struct rot_context *rot = dev_get_drvdata(dev);
  510. u32 val;
  511. if (rot->suspended) {
  512. DRM_ERROR("suspended state\n");
  513. return -EPERM;
  514. }
  515. if (cmd != IPP_CMD_M2M) {
  516. DRM_ERROR("not support cmd: %d\n", cmd);
  517. return -EINVAL;
  518. }
  519. /* Set interrupt enable */
  520. rotator_reg_set_irq(rot, true);
  521. val = rot_read(ROT_CONTROL);
  522. val |= ROT_CONTROL_START;
  523. rot_write(val, ROT_CONTROL);
  524. return 0;
  525. }
  526. static struct rot_limit_table rot_limit_tbl_4210 = {
  527. .ycbcr420_2p = {
  528. .min_w = 32,
  529. .min_h = 32,
  530. .max_w = SZ_64K,
  531. .max_h = SZ_64K,
  532. .align = 3,
  533. },
  534. .rgb888 = {
  535. .min_w = 8,
  536. .min_h = 8,
  537. .max_w = SZ_16K,
  538. .max_h = SZ_16K,
  539. .align = 2,
  540. },
  541. };
  542. static struct rot_limit_table rot_limit_tbl_4x12 = {
  543. .ycbcr420_2p = {
  544. .min_w = 32,
  545. .min_h = 32,
  546. .max_w = SZ_32K,
  547. .max_h = SZ_32K,
  548. .align = 3,
  549. },
  550. .rgb888 = {
  551. .min_w = 8,
  552. .min_h = 8,
  553. .max_w = SZ_8K,
  554. .max_h = SZ_8K,
  555. .align = 2,
  556. },
  557. };
  558. static struct rot_limit_table rot_limit_tbl_5250 = {
  559. .ycbcr420_2p = {
  560. .min_w = 32,
  561. .min_h = 32,
  562. .max_w = SZ_32K,
  563. .max_h = SZ_32K,
  564. .align = 3,
  565. },
  566. .rgb888 = {
  567. .min_w = 8,
  568. .min_h = 8,
  569. .max_w = SZ_8K,
  570. .max_h = SZ_8K,
  571. .align = 1,
  572. },
  573. };
  574. static const struct of_device_id exynos_rotator_match[] = {
  575. {
  576. .compatible = "samsung,exynos4210-rotator",
  577. .data = &rot_limit_tbl_4210,
  578. },
  579. {
  580. .compatible = "samsung,exynos4212-rotator",
  581. .data = &rot_limit_tbl_4x12,
  582. },
  583. {
  584. .compatible = "samsung,exynos5250-rotator",
  585. .data = &rot_limit_tbl_5250,
  586. },
  587. {},
  588. };
  589. MODULE_DEVICE_TABLE(of, exynos_rotator_match);
  590. static int rotator_probe(struct platform_device *pdev)
  591. {
  592. struct device *dev = &pdev->dev;
  593. struct rot_context *rot;
  594. struct exynos_drm_ippdrv *ippdrv;
  595. const struct of_device_id *match;
  596. int ret;
  597. if (!dev->of_node) {
  598. dev_err(dev, "cannot find of_node.\n");
  599. return -ENODEV;
  600. }
  601. rot = devm_kzalloc(dev, sizeof(*rot), GFP_KERNEL);
  602. if (!rot)
  603. return -ENOMEM;
  604. match = of_match_node(exynos_rotator_match, dev->of_node);
  605. if (!match) {
  606. dev_err(dev, "failed to match node\n");
  607. return -ENODEV;
  608. }
  609. rot->limit_tbl = (struct rot_limit_table *)match->data;
  610. rot->regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  611. rot->regs = devm_ioremap_resource(dev, rot->regs_res);
  612. if (IS_ERR(rot->regs))
  613. return PTR_ERR(rot->regs);
  614. rot->irq = platform_get_irq(pdev, 0);
  615. if (rot->irq < 0) {
  616. dev_err(dev, "failed to get irq\n");
  617. return rot->irq;
  618. }
  619. ret = devm_request_threaded_irq(dev, rot->irq, NULL,
  620. rotator_irq_handler, IRQF_ONESHOT, "drm_rotator", rot);
  621. if (ret < 0) {
  622. dev_err(dev, "failed to request irq\n");
  623. return ret;
  624. }
  625. rot->clock = devm_clk_get(dev, "rotator");
  626. if (IS_ERR(rot->clock)) {
  627. dev_err(dev, "failed to get clock\n");
  628. return PTR_ERR(rot->clock);
  629. }
  630. pm_runtime_enable(dev);
  631. ippdrv = &rot->ippdrv;
  632. ippdrv->dev = dev;
  633. ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &rot_src_ops;
  634. ippdrv->ops[EXYNOS_DRM_OPS_DST] = &rot_dst_ops;
  635. ippdrv->check_property = rotator_ippdrv_check_property;
  636. ippdrv->start = rotator_ippdrv_start;
  637. ret = rotator_init_prop_list(ippdrv);
  638. if (ret < 0) {
  639. dev_err(dev, "failed to init property list.\n");
  640. goto err_ippdrv_register;
  641. }
  642. DRM_DEBUG_KMS("ippdrv[0x%x]\n", (int)ippdrv);
  643. platform_set_drvdata(pdev, rot);
  644. ret = exynos_drm_ippdrv_register(ippdrv);
  645. if (ret < 0) {
  646. dev_err(dev, "failed to register drm rotator device\n");
  647. goto err_ippdrv_register;
  648. }
  649. dev_info(dev, "The exynos rotator is probed successfully\n");
  650. return 0;
  651. err_ippdrv_register:
  652. pm_runtime_disable(dev);
  653. return ret;
  654. }
  655. static int rotator_remove(struct platform_device *pdev)
  656. {
  657. struct device *dev = &pdev->dev;
  658. struct rot_context *rot = dev_get_drvdata(dev);
  659. struct exynos_drm_ippdrv *ippdrv = &rot->ippdrv;
  660. exynos_drm_ippdrv_unregister(ippdrv);
  661. pm_runtime_disable(dev);
  662. return 0;
  663. }
  664. #ifdef CONFIG_PM
  665. static int rotator_clk_crtl(struct rot_context *rot, bool enable)
  666. {
  667. if (enable) {
  668. clk_enable(rot->clock);
  669. rot->suspended = false;
  670. } else {
  671. clk_disable(rot->clock);
  672. rot->suspended = true;
  673. }
  674. return 0;
  675. }
  676. #ifdef CONFIG_PM_SLEEP
  677. static int rotator_suspend(struct device *dev)
  678. {
  679. struct rot_context *rot = dev_get_drvdata(dev);
  680. if (pm_runtime_suspended(dev))
  681. return 0;
  682. return rotator_clk_crtl(rot, false);
  683. }
  684. static int rotator_resume(struct device *dev)
  685. {
  686. struct rot_context *rot = dev_get_drvdata(dev);
  687. if (!pm_runtime_suspended(dev))
  688. return rotator_clk_crtl(rot, true);
  689. return 0;
  690. }
  691. #endif
  692. static int rotator_runtime_suspend(struct device *dev)
  693. {
  694. struct rot_context *rot = dev_get_drvdata(dev);
  695. return rotator_clk_crtl(rot, false);
  696. }
  697. static int rotator_runtime_resume(struct device *dev)
  698. {
  699. struct rot_context *rot = dev_get_drvdata(dev);
  700. return rotator_clk_crtl(rot, true);
  701. }
  702. #endif
  703. static const struct dev_pm_ops rotator_pm_ops = {
  704. SET_SYSTEM_SLEEP_PM_OPS(rotator_suspend, rotator_resume)
  705. SET_RUNTIME_PM_OPS(rotator_runtime_suspend, rotator_runtime_resume,
  706. NULL)
  707. };
  708. struct platform_driver rotator_driver = {
  709. .probe = rotator_probe,
  710. .remove = rotator_remove,
  711. .driver = {
  712. .name = "exynos-rot",
  713. .owner = THIS_MODULE,
  714. .pm = &rotator_pm_ops,
  715. .of_match_table = exynos_rotator_match,
  716. },
  717. };