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,
  137. (struct work_struct *)event_work);
  138. } else {
  139. DRM_ERROR("the SFR is set illegally\n");
  140. }
  141. return IRQ_HANDLED;
  142. }
  143. static void rotator_align_size(struct rot_context *rot, u32 fmt, u32 *hsize,
  144. u32 *vsize)
  145. {
  146. struct rot_limit_table *limit_tbl = rot->limit_tbl;
  147. struct rot_limit *limit;
  148. u32 mask, val;
  149. /* Get size limit */
  150. if (fmt == ROT_CONTROL_FMT_RGB888)
  151. limit = &limit_tbl->rgb888;
  152. else
  153. limit = &limit_tbl->ycbcr420_2p;
  154. /* Get mask for rounding to nearest aligned val */
  155. mask = ~((1 << limit->align) - 1);
  156. /* Set aligned width */
  157. val = ROT_ALIGN(*hsize, limit->align, mask);
  158. if (val < limit->min_w)
  159. *hsize = ROT_MIN(limit->min_w, mask);
  160. else if (val > limit->max_w)
  161. *hsize = ROT_MAX(limit->max_w, mask);
  162. else
  163. *hsize = val;
  164. /* Set aligned height */
  165. val = ROT_ALIGN(*vsize, limit->align, mask);
  166. if (val < limit->min_h)
  167. *vsize = ROT_MIN(limit->min_h, mask);
  168. else if (val > limit->max_h)
  169. *vsize = ROT_MAX(limit->max_h, mask);
  170. else
  171. *vsize = val;
  172. }
  173. static int rotator_src_set_fmt(struct device *dev, u32 fmt)
  174. {
  175. struct rot_context *rot = dev_get_drvdata(dev);
  176. u32 val;
  177. val = rot_read(ROT_CONTROL);
  178. val &= ~ROT_CONTROL_FMT_MASK;
  179. switch (fmt) {
  180. case DRM_FORMAT_NV12:
  181. val |= ROT_CONTROL_FMT_YCBCR420_2P;
  182. break;
  183. case DRM_FORMAT_XRGB8888:
  184. val |= ROT_CONTROL_FMT_RGB888;
  185. break;
  186. default:
  187. DRM_ERROR("invalid image format\n");
  188. return -EINVAL;
  189. }
  190. rot_write(val, ROT_CONTROL);
  191. return 0;
  192. }
  193. static inline bool rotator_check_reg_fmt(u32 fmt)
  194. {
  195. if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) ||
  196. (fmt == ROT_CONTROL_FMT_RGB888))
  197. return true;
  198. return false;
  199. }
  200. static int rotator_src_set_size(struct device *dev, int swap,
  201. struct drm_exynos_pos *pos,
  202. struct drm_exynos_sz *sz)
  203. {
  204. struct rot_context *rot = dev_get_drvdata(dev);
  205. u32 fmt, hsize, vsize;
  206. u32 val;
  207. /* Get format */
  208. fmt = rotator_reg_get_fmt(rot);
  209. if (!rotator_check_reg_fmt(fmt)) {
  210. DRM_ERROR("invalid format.\n");
  211. return -EINVAL;
  212. }
  213. /* Align buffer size */
  214. hsize = sz->hsize;
  215. vsize = sz->vsize;
  216. rotator_align_size(rot, fmt, &hsize, &vsize);
  217. /* Set buffer size configuration */
  218. val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
  219. rot_write(val, ROT_SRC_BUF_SIZE);
  220. /* Set crop image position configuration */
  221. val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
  222. rot_write(val, ROT_SRC_CROP_POS);
  223. val = ROT_SRC_CROP_SIZE_H(pos->h) | ROT_SRC_CROP_SIZE_W(pos->w);
  224. rot_write(val, ROT_SRC_CROP_SIZE);
  225. return 0;
  226. }
  227. static int rotator_src_set_addr(struct device *dev,
  228. struct drm_exynos_ipp_buf_info *buf_info,
  229. u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
  230. {
  231. struct rot_context *rot = dev_get_drvdata(dev);
  232. dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
  233. u32 val, fmt, hsize, vsize;
  234. int i;
  235. /* Set current buf_id */
  236. rot->cur_buf_id[EXYNOS_DRM_OPS_SRC] = buf_id;
  237. switch (buf_type) {
  238. case IPP_BUF_ENQUEUE:
  239. /* Set address configuration */
  240. for_each_ipp_planar(i)
  241. addr[i] = buf_info->base[i];
  242. /* Get format */
  243. fmt = rotator_reg_get_fmt(rot);
  244. if (!rotator_check_reg_fmt(fmt)) {
  245. DRM_ERROR("invalid format.\n");
  246. return -EINVAL;
  247. }
  248. /* Re-set cb planar for NV12 format */
  249. if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
  250. !addr[EXYNOS_DRM_PLANAR_CB]) {
  251. val = rot_read(ROT_SRC_BUF_SIZE);
  252. hsize = ROT_GET_BUF_SIZE_W(val);
  253. vsize = ROT_GET_BUF_SIZE_H(val);
  254. /* Set cb planar */
  255. addr[EXYNOS_DRM_PLANAR_CB] =
  256. addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
  257. }
  258. for_each_ipp_planar(i)
  259. rot_write(addr[i], ROT_SRC_BUF_ADDR(i));
  260. break;
  261. case IPP_BUF_DEQUEUE:
  262. for_each_ipp_planar(i)
  263. rot_write(0x0, ROT_SRC_BUF_ADDR(i));
  264. break;
  265. default:
  266. /* Nothing to do */
  267. break;
  268. }
  269. return 0;
  270. }
  271. static int rotator_dst_set_transf(struct device *dev,
  272. enum drm_exynos_degree degree,
  273. enum drm_exynos_flip flip, bool *swap)
  274. {
  275. struct rot_context *rot = dev_get_drvdata(dev);
  276. u32 val;
  277. /* Set transform configuration */
  278. val = rot_read(ROT_CONTROL);
  279. val &= ~ROT_CONTROL_FLIP_MASK;
  280. switch (flip) {
  281. case EXYNOS_DRM_FLIP_VERTICAL:
  282. val |= ROT_CONTROL_FLIP_VERTICAL;
  283. break;
  284. case EXYNOS_DRM_FLIP_HORIZONTAL:
  285. val |= ROT_CONTROL_FLIP_HORIZONTAL;
  286. break;
  287. default:
  288. /* Flip None */
  289. break;
  290. }
  291. val &= ~ROT_CONTROL_ROT_MASK;
  292. switch (degree) {
  293. case EXYNOS_DRM_DEGREE_90:
  294. val |= ROT_CONTROL_ROT_90;
  295. break;
  296. case EXYNOS_DRM_DEGREE_180:
  297. val |= ROT_CONTROL_ROT_180;
  298. break;
  299. case EXYNOS_DRM_DEGREE_270:
  300. val |= ROT_CONTROL_ROT_270;
  301. break;
  302. default:
  303. /* Rotation 0 Degree */
  304. break;
  305. }
  306. rot_write(val, ROT_CONTROL);
  307. /* Check degree for setting buffer size swap */
  308. if ((degree == EXYNOS_DRM_DEGREE_90) ||
  309. (degree == EXYNOS_DRM_DEGREE_270))
  310. *swap = true;
  311. else
  312. *swap = false;
  313. return 0;
  314. }
  315. static int rotator_dst_set_size(struct device *dev, int swap,
  316. struct drm_exynos_pos *pos,
  317. struct drm_exynos_sz *sz)
  318. {
  319. struct rot_context *rot = dev_get_drvdata(dev);
  320. u32 val, fmt, hsize, vsize;
  321. /* Get format */
  322. fmt = rotator_reg_get_fmt(rot);
  323. if (!rotator_check_reg_fmt(fmt)) {
  324. DRM_ERROR("invalid format.\n");
  325. return -EINVAL;
  326. }
  327. /* Align buffer size */
  328. hsize = sz->hsize;
  329. vsize = sz->vsize;
  330. rotator_align_size(rot, fmt, &hsize, &vsize);
  331. /* Set buffer size configuration */
  332. val = ROT_SET_BUF_SIZE_H(vsize) | ROT_SET_BUF_SIZE_W(hsize);
  333. rot_write(val, ROT_DST_BUF_SIZE);
  334. /* Set crop image position configuration */
  335. val = ROT_CROP_POS_Y(pos->y) | ROT_CROP_POS_X(pos->x);
  336. rot_write(val, ROT_DST_CROP_POS);
  337. return 0;
  338. }
  339. static int rotator_dst_set_addr(struct device *dev,
  340. struct drm_exynos_ipp_buf_info *buf_info,
  341. u32 buf_id, enum drm_exynos_ipp_buf_type buf_type)
  342. {
  343. struct rot_context *rot = dev_get_drvdata(dev);
  344. dma_addr_t addr[EXYNOS_DRM_PLANAR_MAX];
  345. u32 val, fmt, hsize, vsize;
  346. int i;
  347. /* Set current buf_id */
  348. rot->cur_buf_id[EXYNOS_DRM_OPS_DST] = buf_id;
  349. switch (buf_type) {
  350. case IPP_BUF_ENQUEUE:
  351. /* Set address configuration */
  352. for_each_ipp_planar(i)
  353. addr[i] = buf_info->base[i];
  354. /* Get format */
  355. fmt = rotator_reg_get_fmt(rot);
  356. if (!rotator_check_reg_fmt(fmt)) {
  357. DRM_ERROR("invalid format.\n");
  358. return -EINVAL;
  359. }
  360. /* Re-set cb planar for NV12 format */
  361. if ((fmt == ROT_CONTROL_FMT_YCBCR420_2P) &&
  362. !addr[EXYNOS_DRM_PLANAR_CB]) {
  363. /* Get buf size */
  364. val = rot_read(ROT_DST_BUF_SIZE);
  365. hsize = ROT_GET_BUF_SIZE_W(val);
  366. vsize = ROT_GET_BUF_SIZE_H(val);
  367. /* Set cb planar */
  368. addr[EXYNOS_DRM_PLANAR_CB] =
  369. addr[EXYNOS_DRM_PLANAR_Y] + hsize * vsize;
  370. }
  371. for_each_ipp_planar(i)
  372. rot_write(addr[i], ROT_DST_BUF_ADDR(i));
  373. break;
  374. case IPP_BUF_DEQUEUE:
  375. for_each_ipp_planar(i)
  376. rot_write(0x0, ROT_DST_BUF_ADDR(i));
  377. break;
  378. default:
  379. /* Nothing to do */
  380. break;
  381. }
  382. return 0;
  383. }
  384. static struct exynos_drm_ipp_ops rot_src_ops = {
  385. .set_fmt = rotator_src_set_fmt,
  386. .set_size = rotator_src_set_size,
  387. .set_addr = rotator_src_set_addr,
  388. };
  389. static struct exynos_drm_ipp_ops rot_dst_ops = {
  390. .set_transf = rotator_dst_set_transf,
  391. .set_size = rotator_dst_set_size,
  392. .set_addr = rotator_dst_set_addr,
  393. };
  394. static int rotator_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
  395. {
  396. struct drm_exynos_ipp_prop_list *prop_list = &ippdrv->prop_list;
  397. prop_list->version = 1;
  398. prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
  399. (1 << EXYNOS_DRM_FLIP_HORIZONTAL);
  400. prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
  401. (1 << EXYNOS_DRM_DEGREE_90) |
  402. (1 << EXYNOS_DRM_DEGREE_180) |
  403. (1 << EXYNOS_DRM_DEGREE_270);
  404. prop_list->csc = 0;
  405. prop_list->crop = 0;
  406. prop_list->scale = 0;
  407. return 0;
  408. }
  409. static inline bool rotator_check_drm_fmt(u32 fmt)
  410. {
  411. switch (fmt) {
  412. case DRM_FORMAT_XRGB8888:
  413. case DRM_FORMAT_NV12:
  414. return true;
  415. default:
  416. DRM_DEBUG_KMS("not support format\n");
  417. return false;
  418. }
  419. }
  420. static inline bool rotator_check_drm_flip(enum drm_exynos_flip flip)
  421. {
  422. switch (flip) {
  423. case EXYNOS_DRM_FLIP_NONE:
  424. case EXYNOS_DRM_FLIP_VERTICAL:
  425. case EXYNOS_DRM_FLIP_HORIZONTAL:
  426. case EXYNOS_DRM_FLIP_BOTH:
  427. return true;
  428. default:
  429. DRM_DEBUG_KMS("invalid flip\n");
  430. return false;
  431. }
  432. }
  433. static int rotator_ippdrv_check_property(struct device *dev,
  434. struct drm_exynos_ipp_property *property)
  435. {
  436. struct drm_exynos_ipp_config *src_config =
  437. &property->config[EXYNOS_DRM_OPS_SRC];
  438. struct drm_exynos_ipp_config *dst_config =
  439. &property->config[EXYNOS_DRM_OPS_DST];
  440. struct drm_exynos_pos *src_pos = &src_config->pos;
  441. struct drm_exynos_pos *dst_pos = &dst_config->pos;
  442. struct drm_exynos_sz *src_sz = &src_config->sz;
  443. struct drm_exynos_sz *dst_sz = &dst_config->sz;
  444. bool swap = false;
  445. /* Check format configuration */
  446. if (src_config->fmt != dst_config->fmt) {
  447. DRM_DEBUG_KMS("not support csc feature\n");
  448. return -EINVAL;
  449. }
  450. if (!rotator_check_drm_fmt(dst_config->fmt)) {
  451. DRM_DEBUG_KMS("invalid format\n");
  452. return -EINVAL;
  453. }
  454. /* Check transform configuration */
  455. if (src_config->degree != EXYNOS_DRM_DEGREE_0) {
  456. DRM_DEBUG_KMS("not support source-side rotation\n");
  457. return -EINVAL;
  458. }
  459. switch (dst_config->degree) {
  460. case EXYNOS_DRM_DEGREE_90:
  461. case EXYNOS_DRM_DEGREE_270:
  462. swap = true;
  463. case EXYNOS_DRM_DEGREE_0:
  464. case EXYNOS_DRM_DEGREE_180:
  465. /* No problem */
  466. break;
  467. default:
  468. DRM_DEBUG_KMS("invalid degree\n");
  469. return -EINVAL;
  470. }
  471. if (src_config->flip != EXYNOS_DRM_FLIP_NONE) {
  472. DRM_DEBUG_KMS("not support source-side flip\n");
  473. return -EINVAL;
  474. }
  475. if (!rotator_check_drm_flip(dst_config->flip)) {
  476. DRM_DEBUG_KMS("invalid flip\n");
  477. return -EINVAL;
  478. }
  479. /* Check size configuration */
  480. if ((src_pos->x + src_pos->w > src_sz->hsize) ||
  481. (src_pos->y + src_pos->h > src_sz->vsize)) {
  482. DRM_DEBUG_KMS("out of source buffer bound\n");
  483. return -EINVAL;
  484. }
  485. if (swap) {
  486. if ((dst_pos->x + dst_pos->h > dst_sz->vsize) ||
  487. (dst_pos->y + dst_pos->w > dst_sz->hsize)) {
  488. DRM_DEBUG_KMS("out of destination buffer bound\n");
  489. return -EINVAL;
  490. }
  491. if ((src_pos->w != dst_pos->h) || (src_pos->h != dst_pos->w)) {
  492. DRM_DEBUG_KMS("not support scale feature\n");
  493. return -EINVAL;
  494. }
  495. } else {
  496. if ((dst_pos->x + dst_pos->w > dst_sz->hsize) ||
  497. (dst_pos->y + dst_pos->h > dst_sz->vsize)) {
  498. DRM_DEBUG_KMS("out of destination buffer bound\n");
  499. return -EINVAL;
  500. }
  501. if ((src_pos->w != dst_pos->w) || (src_pos->h != dst_pos->h)) {
  502. DRM_DEBUG_KMS("not support scale feature\n");
  503. return -EINVAL;
  504. }
  505. }
  506. return 0;
  507. }
  508. static int rotator_ippdrv_start(struct device *dev, enum drm_exynos_ipp_cmd cmd)
  509. {
  510. struct rot_context *rot = dev_get_drvdata(dev);
  511. u32 val;
  512. if (rot->suspended) {
  513. DRM_ERROR("suspended state\n");
  514. return -EPERM;
  515. }
  516. if (cmd != IPP_CMD_M2M) {
  517. DRM_ERROR("not support cmd: %d\n", cmd);
  518. return -EINVAL;
  519. }
  520. /* Set interrupt enable */
  521. rotator_reg_set_irq(rot, true);
  522. val = rot_read(ROT_CONTROL);
  523. val |= ROT_CONTROL_START;
  524. rot_write(val, ROT_CONTROL);
  525. return 0;
  526. }
  527. static struct rot_limit_table rot_limit_tbl_4210 = {
  528. .ycbcr420_2p = {
  529. .min_w = 32,
  530. .min_h = 32,
  531. .max_w = SZ_64K,
  532. .max_h = SZ_64K,
  533. .align = 3,
  534. },
  535. .rgb888 = {
  536. .min_w = 8,
  537. .min_h = 8,
  538. .max_w = SZ_16K,
  539. .max_h = SZ_16K,
  540. .align = 2,
  541. },
  542. };
  543. static struct rot_limit_table rot_limit_tbl_4x12 = {
  544. .ycbcr420_2p = {
  545. .min_w = 32,
  546. .min_h = 32,
  547. .max_w = SZ_32K,
  548. .max_h = SZ_32K,
  549. .align = 3,
  550. },
  551. .rgb888 = {
  552. .min_w = 8,
  553. .min_h = 8,
  554. .max_w = SZ_8K,
  555. .max_h = SZ_8K,
  556. .align = 2,
  557. },
  558. };
  559. static struct rot_limit_table rot_limit_tbl_5250 = {
  560. .ycbcr420_2p = {
  561. .min_w = 32,
  562. .min_h = 32,
  563. .max_w = SZ_32K,
  564. .max_h = SZ_32K,
  565. .align = 3,
  566. },
  567. .rgb888 = {
  568. .min_w = 8,
  569. .min_h = 8,
  570. .max_w = SZ_8K,
  571. .max_h = SZ_8K,
  572. .align = 1,
  573. },
  574. };
  575. static const struct of_device_id exynos_rotator_match[] = {
  576. {
  577. .compatible = "samsung,exynos4210-rotator",
  578. .data = &rot_limit_tbl_4210,
  579. },
  580. {
  581. .compatible = "samsung,exynos4212-rotator",
  582. .data = &rot_limit_tbl_4x12,
  583. },
  584. {
  585. .compatible = "samsung,exynos5250-rotator",
  586. .data = &rot_limit_tbl_5250,
  587. },
  588. {},
  589. };
  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. static int rotator_clk_crtl(struct rot_context *rot, bool enable)
  665. {
  666. if (enable) {
  667. clk_enable(rot->clock);
  668. rot->suspended = false;
  669. } else {
  670. clk_disable(rot->clock);
  671. rot->suspended = true;
  672. }
  673. return 0;
  674. }
  675. #ifdef CONFIG_PM_SLEEP
  676. static int rotator_suspend(struct device *dev)
  677. {
  678. struct rot_context *rot = dev_get_drvdata(dev);
  679. if (pm_runtime_suspended(dev))
  680. return 0;
  681. return rotator_clk_crtl(rot, false);
  682. }
  683. static int rotator_resume(struct device *dev)
  684. {
  685. struct rot_context *rot = dev_get_drvdata(dev);
  686. if (!pm_runtime_suspended(dev))
  687. return rotator_clk_crtl(rot, true);
  688. return 0;
  689. }
  690. #endif
  691. #ifdef CONFIG_PM_RUNTIME
  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. };