blob: 696a7bdca4b52d7bc2c722ee3468b83bfaa7d54f [file] [log] [blame]
Nagamalleswararao Ganjibcdea002011-09-13 15:43:47 -07001/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#include <linux/platform_device.h>
14#include <linux/cdev.h>
15#include <linux/list.h>
16#include <linux/module.h>
17#include <linux/fs.h>
18#include <linux/interrupt.h>
19#include <linux/sched.h>
20#include <linux/uaccess.h>
21#include <linux/clk.h>
22#include <mach/clk.h>
23#include <linux/android_pmem.h>
24#include <linux/msm_rotator.h>
25#include <linux/io.h>
26#include <mach/msm_rotator_imem.h>
27#include <linux/ktime.h>
28#include <linux/workqueue.h>
29#include <linux/file.h>
30#include <linux/major.h>
31#include <linux/regulator/consumer.h>
Naseer Ahmed18018602011-10-25 13:32:58 -070032#include <linux/ion.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033
34#define DRIVER_NAME "msm_rotator"
35
36#define MSM_ROTATOR_BASE (msm_rotator_dev->io_base)
37#define MSM_ROTATOR_INTR_ENABLE (MSM_ROTATOR_BASE+0x0020)
38#define MSM_ROTATOR_INTR_STATUS (MSM_ROTATOR_BASE+0x0024)
39#define MSM_ROTATOR_INTR_CLEAR (MSM_ROTATOR_BASE+0x0028)
40#define MSM_ROTATOR_START (MSM_ROTATOR_BASE+0x0030)
41#define MSM_ROTATOR_MAX_BURST_SIZE (MSM_ROTATOR_BASE+0x0050)
42#define MSM_ROTATOR_HW_VERSION (MSM_ROTATOR_BASE+0x0070)
43#define MSM_ROTATOR_SRC_SIZE (MSM_ROTATOR_BASE+0x1108)
44#define MSM_ROTATOR_SRCP0_ADDR (MSM_ROTATOR_BASE+0x110c)
45#define MSM_ROTATOR_SRCP1_ADDR (MSM_ROTATOR_BASE+0x1110)
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -070046#define MSM_ROTATOR_SRCP2_ADDR (MSM_ROTATOR_BASE+0x1114)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047#define MSM_ROTATOR_SRC_YSTRIDE1 (MSM_ROTATOR_BASE+0x111c)
48#define MSM_ROTATOR_SRC_YSTRIDE2 (MSM_ROTATOR_BASE+0x1120)
49#define MSM_ROTATOR_SRC_FORMAT (MSM_ROTATOR_BASE+0x1124)
50#define MSM_ROTATOR_SRC_UNPACK_PATTERN1 (MSM_ROTATOR_BASE+0x1128)
51#define MSM_ROTATOR_SUB_BLOCK_CFG (MSM_ROTATOR_BASE+0x1138)
52#define MSM_ROTATOR_OUT_PACK_PATTERN1 (MSM_ROTATOR_BASE+0x1154)
53#define MSM_ROTATOR_OUTP0_ADDR (MSM_ROTATOR_BASE+0x1168)
54#define MSM_ROTATOR_OUTP1_ADDR (MSM_ROTATOR_BASE+0x116c)
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -070055#define MSM_ROTATOR_OUTP2_ADDR (MSM_ROTATOR_BASE+0x1170)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056#define MSM_ROTATOR_OUT_YSTRIDE1 (MSM_ROTATOR_BASE+0x1178)
57#define MSM_ROTATOR_OUT_YSTRIDE2 (MSM_ROTATOR_BASE+0x117c)
58#define MSM_ROTATOR_SRC_XY (MSM_ROTATOR_BASE+0x1200)
59#define MSM_ROTATOR_SRC_IMAGE_SIZE (MSM_ROTATOR_BASE+0x1208)
60
61#define MSM_ROTATOR_MAX_ROT 0x07
62#define MSM_ROTATOR_MAX_H 0x1fff
63#define MSM_ROTATOR_MAX_W 0x1fff
64
65/* from lsb to msb */
66#define GET_PACK_PATTERN(a, x, y, z, bit) \
67 (((a)<<((bit)*3))|((x)<<((bit)*2))|((y)<<(bit))|(z))
68#define CLR_G 0x0
69#define CLR_B 0x1
70#define CLR_R 0x2
71#define CLR_ALPHA 0x3
72
73#define CLR_Y CLR_G
74#define CLR_CB CLR_B
75#define CLR_CR CLR_R
76
77#define ROTATIONS_TO_BITMASK(r) ((((r) & MDP_ROT_90) ? 1 : 0) | \
78 (((r) & MDP_FLIP_LR) ? 2 : 0) | \
79 (((r) & MDP_FLIP_UD) ? 4 : 0))
80
81#define IMEM_NO_OWNER -1;
82
83#define MAX_SESSIONS 16
84#define INVALID_SESSION -1
85#define VERSION_KEY_MASK 0xFFFFFF00
86
87struct tile_parm {
88 unsigned int width; /* tile's width */
89 unsigned int height; /* tile's height */
90 unsigned int row_tile_w; /* tiles per row's width */
91 unsigned int row_tile_h; /* tiles per row's height */
92};
93
Adrian Salido-Moreno88411862011-09-20 18:54:03 -070094struct msm_rotator_mem_planes {
95 unsigned int num_planes;
96 unsigned int plane_size[4];
97 unsigned int total_size;
98};
99
100#define checkoffset(offset, size, max_size) \
101 ((size) > (max_size) || (offset) > ((max_size) - (size)))
102
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103struct msm_rotator_dev {
104 void __iomem *io_base;
105 int irq;
106 struct msm_rotator_img_info *img_info[MAX_SESSIONS];
107 struct clk *core_clk;
108 int pid_list[MAX_SESSIONS];
109 struct clk *pclk;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110 int rot_clk_state;
111 struct regulator *regulator;
112 struct delayed_work rot_clk_work;
113 struct clk *imem_clk;
114 int imem_clk_state;
115 struct delayed_work imem_clk_work;
116 struct platform_device *pdev;
117 struct cdev cdev;
118 struct device *device;
119 struct class *class;
120 dev_t dev_num;
121 int processing;
122 int last_session_idx;
123 struct mutex rotator_lock;
124 struct mutex imem_lock;
125 int imem_owner;
126 wait_queue_head_t wq;
Naseer Ahmed18018602011-10-25 13:32:58 -0700127 struct ion_client *client;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128};
129
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130#define COMPONENT_5BITS 1
131#define COMPONENT_6BITS 2
132#define COMPONENT_8BITS 3
133
134static struct msm_rotator_dev *msm_rotator_dev;
135
136enum {
137 CLK_EN,
138 CLK_DIS,
139 CLK_SUSPEND,
140};
141
142int msm_rotator_imem_allocate(int requestor)
143{
144 int rc = 0;
145
146#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
147 switch (requestor) {
148 case ROTATOR_REQUEST:
149 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
150 msm_rotator_dev->imem_owner = ROTATOR_REQUEST;
151 rc = 1;
152 } else
153 rc = 0;
154 break;
155 case JPEG_REQUEST:
156 mutex_lock(&msm_rotator_dev->imem_lock);
157 msm_rotator_dev->imem_owner = JPEG_REQUEST;
158 rc = 1;
159 break;
160 default:
161 rc = 0;
162 }
163#else
164 if (requestor == JPEG_REQUEST)
165 rc = 1;
166#endif
167 if (rc == 1) {
168 cancel_delayed_work(&msm_rotator_dev->imem_clk_work);
169 if (msm_rotator_dev->imem_clk_state != CLK_EN
170 && msm_rotator_dev->imem_clk) {
171 clk_enable(msm_rotator_dev->imem_clk);
172 msm_rotator_dev->imem_clk_state = CLK_EN;
173 }
174 }
175
176 return rc;
177}
178EXPORT_SYMBOL(msm_rotator_imem_allocate);
179
180void msm_rotator_imem_free(int requestor)
181{
182#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
183 if (msm_rotator_dev->imem_owner == requestor) {
184 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
185 mutex_unlock(&msm_rotator_dev->imem_lock);
186 }
187#else
188 if (requestor == JPEG_REQUEST)
189 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
190#endif
191}
192EXPORT_SYMBOL(msm_rotator_imem_free);
193
194static void msm_rotator_imem_clk_work_f(struct work_struct *work)
195{
196#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
197 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
198 if (msm_rotator_dev->imem_clk_state == CLK_EN
199 && msm_rotator_dev->imem_clk) {
200 clk_disable(msm_rotator_dev->imem_clk);
201 msm_rotator_dev->imem_clk_state = CLK_DIS;
202 } else if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND)
203 msm_rotator_dev->imem_clk_state = CLK_DIS;
204 mutex_unlock(&msm_rotator_dev->imem_lock);
205 }
206#endif
207}
208
209/* enable clocks needed by rotator block */
210static void enable_rot_clks(void)
211{
212 if (msm_rotator_dev->regulator)
213 regulator_enable(msm_rotator_dev->regulator);
214 if (msm_rotator_dev->core_clk != NULL)
215 clk_enable(msm_rotator_dev->core_clk);
216 if (msm_rotator_dev->pclk != NULL)
217 clk_enable(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700218}
219
220/* disable clocks needed by rotator block */
221static void disable_rot_clks(void)
222{
223 if (msm_rotator_dev->core_clk != NULL)
224 clk_disable(msm_rotator_dev->core_clk);
225 if (msm_rotator_dev->pclk != NULL)
226 clk_disable(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 if (msm_rotator_dev->regulator)
228 regulator_disable(msm_rotator_dev->regulator);
229}
230
231static void msm_rotator_rot_clk_work_f(struct work_struct *work)
232{
233 if (mutex_trylock(&msm_rotator_dev->rotator_lock)) {
234 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
235 disable_rot_clks();
236 msm_rotator_dev->rot_clk_state = CLK_DIS;
237 } else if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND)
238 msm_rotator_dev->rot_clk_state = CLK_DIS;
239 mutex_unlock(&msm_rotator_dev->rotator_lock);
240 }
241}
242
243static irqreturn_t msm_rotator_isr(int irq, void *dev_id)
244{
245 if (msm_rotator_dev->processing) {
246 msm_rotator_dev->processing = 0;
247 wake_up(&msm_rotator_dev->wq);
248 } else
249 printk(KERN_WARNING "%s: unexpected interrupt\n", DRIVER_NAME);
250
251 return IRQ_HANDLED;
252}
253
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700254static unsigned int tile_size(unsigned int src_width,
255 unsigned int src_height,
256 const struct tile_parm *tp)
257{
258 unsigned int tile_w, tile_h;
259 unsigned int row_num_w, row_num_h;
260 tile_w = tp->width * tp->row_tile_w;
261 tile_h = tp->height * tp->row_tile_h;
262 row_num_w = (src_width + tile_w - 1) / tile_w;
263 row_num_h = (src_height + tile_h - 1) / tile_h;
264 return ((row_num_w * row_num_h * tile_w * tile_h) + 8191) & ~8191;
265}
266
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700267static int get_bpp(int format)
268{
269 switch (format) {
270 case MDP_RGB_565:
271 case MDP_BGR_565:
272 return 2;
273
274 case MDP_XRGB_8888:
275 case MDP_ARGB_8888:
276 case MDP_RGBA_8888:
277 case MDP_BGRA_8888:
278 case MDP_RGBX_8888:
279 return 4;
280
281 case MDP_Y_CBCR_H2V2:
282 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700283 case MDP_Y_CB_CR_H2V2:
284 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530285 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286 case MDP_Y_CRCB_H2V2_TILE:
287 case MDP_Y_CBCR_H2V2_TILE:
288 return 1;
289
290 case MDP_RGB_888:
291 return 3;
292
293 case MDP_YCRYCB_H2V1:
294 return 2;/* YCrYCb interleave */
295
296 case MDP_Y_CRCB_H2V1:
297 case MDP_Y_CBCR_H2V1:
298 return 1;
299
300 default:
301 return -1;
302 }
303
304}
305
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700306static int msm_rotator_get_plane_sizes(uint32_t format, uint32_t w, uint32_t h,
307 struct msm_rotator_mem_planes *p)
308{
309 /*
310 * each row of samsung tile consists of two tiles in height
311 * and two tiles in width which means width should align to
312 * 64 x 2 bytes and height should align to 32 x 2 bytes.
313 * video decoder generate two tiles in width and one tile
314 * in height which ends up height align to 32 X 1 bytes.
315 */
316 const struct tile_parm tile = {64, 32, 2, 1};
317 int i;
318
319 if (p == NULL)
320 return -EINVAL;
321
322 if ((w > MSM_ROTATOR_MAX_W) || (h > MSM_ROTATOR_MAX_H))
323 return -ERANGE;
324
325 memset(p, 0, sizeof(*p));
326
327 switch (format) {
328 case MDP_XRGB_8888:
329 case MDP_ARGB_8888:
330 case MDP_RGBA_8888:
331 case MDP_BGRA_8888:
332 case MDP_RGBX_8888:
333 case MDP_RGB_888:
334 case MDP_RGB_565:
335 case MDP_BGR_565:
336 case MDP_YCRYCB_H2V1:
337 p->num_planes = 1;
338 p->plane_size[0] = w * h * get_bpp(format);
339 break;
340 case MDP_Y_CRCB_H2V1:
341 case MDP_Y_CBCR_H2V1:
342 p->num_planes = 2;
343 p->plane_size[0] = w * h;
344 p->plane_size[1] = w * h;
345 break;
346 case MDP_Y_CBCR_H2V2:
347 case MDP_Y_CRCB_H2V2:
348 p->num_planes = 2;
349 p->plane_size[0] = w * h;
350 p->plane_size[1] = w * h / 2;
351 break;
352 case MDP_Y_CRCB_H2V2_TILE:
353 case MDP_Y_CBCR_H2V2_TILE:
354 p->num_planes = 2;
355 p->plane_size[0] = tile_size(w, h, &tile);
356 p->plane_size[1] = tile_size(w, h/2, &tile);
357 break;
358 case MDP_Y_CB_CR_H2V2:
359 case MDP_Y_CR_CB_H2V2:
360 p->num_planes = 3;
361 p->plane_size[0] = w * h;
362 p->plane_size[1] = (w / 2) * (h / 2);
363 p->plane_size[2] = (w / 2) * (h / 2);
364 break;
365 case MDP_Y_CR_CB_GH2V2:
366 p->num_planes = 3;
367 p->plane_size[0] = ALIGN(w, 16) * h;
368 p->plane_size[1] = ALIGN(w / 2, 16) * (h / 2);
369 p->plane_size[2] = ALIGN(w / 2, 16) * (h / 2);
370 break;
371 default:
372 return -EINVAL;
373 }
374
375 for (i = 0; i < p->num_planes; i++)
376 p->total_size += p->plane_size[i];
377
378 return 0;
379}
380
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700381static int msm_rotator_ycxcx_h2v1(struct msm_rotator_img_info *info,
382 unsigned int in_paddr,
383 unsigned int out_paddr,
384 unsigned int use_imem,
385 int new_session,
386 unsigned int in_chroma_paddr,
387 unsigned int out_chroma_paddr)
388{
389 int bpp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700390
391 if (info->src.format != info->dst.format)
392 return -EINVAL;
393
394 bpp = get_bpp(info->src.format);
395 if (bpp < 0)
396 return -ENOTTY;
397
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700398 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700399 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700400 iowrite32(out_paddr +
401 ((info->dst_y * info->dst.width) + info->dst_x),
402 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700403 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404 ((info->dst_y * info->dst.width) + info->dst_x),
405 MSM_ROTATOR_OUTP1_ADDR);
406
407 if (new_session) {
408 iowrite32(info->src.width |
409 info->src.width << 16,
410 MSM_ROTATOR_SRC_YSTRIDE1);
411 if (info->rotations & MDP_ROT_90)
412 iowrite32(info->dst.width |
413 info->dst.width*2 << 16,
414 MSM_ROTATOR_OUT_YSTRIDE1);
415 else
416 iowrite32(info->dst.width |
417 info->dst.width << 16,
418 MSM_ROTATOR_OUT_YSTRIDE1);
419 if (info->src.format == MDP_Y_CBCR_H2V1) {
420 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
421 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
422 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
423 MSM_ROTATOR_OUT_PACK_PATTERN1);
424 } else {
425 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
426 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
427 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
428 MSM_ROTATOR_OUT_PACK_PATTERN1);
429 }
430 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
431 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
432 1 << 8, /* ROT_EN */
433 MSM_ROTATOR_SUB_BLOCK_CFG);
434 iowrite32(0 << 29 | /* frame format 0 = linear */
435 (use_imem ? 0 : 1) << 22 | /* tile size */
436 2 << 19 | /* fetch planes 2 = pseudo */
437 0 << 18 | /* unpack align */
438 1 << 17 | /* unpack tight */
439 1 << 13 | /* unpack count 0=1 component */
440 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
441 0 << 8 | /* has alpha */
442 0 << 6 | /* alpha bits 3=8bits */
443 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
444 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
445 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
446 MSM_ROTATOR_SRC_FORMAT);
447 }
448
449 return 0;
450}
451
452static int msm_rotator_ycxcx_h2v2(struct msm_rotator_img_info *info,
453 unsigned int in_paddr,
454 unsigned int out_paddr,
455 unsigned int use_imem,
456 int new_session,
457 unsigned int in_chroma_paddr,
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700458 unsigned int out_chroma_paddr,
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700459 unsigned int in_chroma2_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700460{
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700461 uint32_t dst_format;
462 int is_tile = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700464 switch (info->src.format) {
465 case MDP_Y_CRCB_H2V2_TILE:
466 is_tile = 1;
467 case MDP_Y_CR_CB_H2V2:
468 case MDP_Y_CR_CB_GH2V2:
469 case MDP_Y_CRCB_H2V2:
470 dst_format = MDP_Y_CRCB_H2V2;
471 break;
472 case MDP_Y_CBCR_H2V2_TILE:
473 is_tile = 1;
474 case MDP_Y_CB_CR_H2V2:
475 case MDP_Y_CBCR_H2V2:
476 dst_format = MDP_Y_CBCR_H2V2;
477 break;
478 default:
479 return -EINVAL;
480 }
481 if (info->dst.format != dst_format)
482 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483
484 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700485 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
486 iowrite32(in_chroma2_paddr, MSM_ROTATOR_SRCP2_ADDR);
487
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488 iowrite32(out_paddr +
489 ((info->dst_y * info->dst.width) + info->dst_x),
490 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700491 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700492 ((info->dst_y * info->dst.width)/2 + info->dst_x),
493 MSM_ROTATOR_OUTP1_ADDR);
494
495 if (new_session) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700496 if (in_chroma2_paddr) {
497 if (info->src.format == MDP_Y_CR_CB_GH2V2) {
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530498 iowrite32(ALIGN(info->src.width, 16) |
499 ALIGN((info->src.width / 2), 16) << 16,
500 MSM_ROTATOR_SRC_YSTRIDE1);
501 iowrite32(ALIGN((info->src.width / 2), 16),
502 MSM_ROTATOR_SRC_YSTRIDE2);
503 } else {
504 iowrite32(info->src.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700505 (info->src.width / 2) << 16,
506 MSM_ROTATOR_SRC_YSTRIDE1);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530507 iowrite32((info->src.width / 2),
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700508 MSM_ROTATOR_SRC_YSTRIDE2);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530509 }
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700510 } else {
511 iowrite32(info->src.width |
512 info->src.width << 16,
513 MSM_ROTATOR_SRC_YSTRIDE1);
514 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700515 iowrite32(info->dst.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700516 info->dst.width << 16,
517 MSM_ROTATOR_OUT_YSTRIDE1);
518
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700519 if (dst_format == MDP_Y_CBCR_H2V2) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700520 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
521 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
522 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
523 MSM_ROTATOR_OUT_PACK_PATTERN1);
524 } else {
525 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
526 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
527 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
528 MSM_ROTATOR_OUT_PACK_PATTERN1);
529 }
530 iowrite32((3 << 18) | /* chroma sampling 3=4:2:0 */
531 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
532 1 << 8, /* ROT_EN */
533 MSM_ROTATOR_SUB_BLOCK_CFG);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700534
535 iowrite32((is_tile ? 2 : 0) << 29 | /* frame format */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700536 (use_imem ? 0 : 1) << 22 | /* tile size */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700537 (in_chroma2_paddr ? 1 : 2) << 19 | /* fetch planes */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700538 0 << 18 | /* unpack align */
539 1 << 17 | /* unpack tight */
540 1 << 13 | /* unpack count 0=1 component */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700541 0 << 9 | /* src Bpp 0=1 byte ... */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700542 0 << 8 | /* has alpha */
543 0 << 6 | /* alpha bits 3=8bits */
544 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
545 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
546 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
547 MSM_ROTATOR_SRC_FORMAT);
548 }
549 return 0;
550}
551
552static int msm_rotator_ycrycb(struct msm_rotator_img_info *info,
553 unsigned int in_paddr,
554 unsigned int out_paddr,
555 unsigned int use_imem,
556 int new_session)
557{
558 int bpp;
559
560 if (info->src.format != info->dst.format)
561 return -EINVAL;
562
563 bpp = get_bpp(info->src.format);
564 if (bpp < 0)
565 return -ENOTTY;
566
567 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
568 iowrite32(out_paddr +
569 ((info->dst_y * info->dst.width) + info->dst_x),
570 MSM_ROTATOR_OUTP0_ADDR);
571
572 if (new_session) {
573 iowrite32(info->src.width,
574 MSM_ROTATOR_SRC_YSTRIDE1);
575 iowrite32(info->dst.width,
576 MSM_ROTATOR_OUT_YSTRIDE1);
577 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
578 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
579 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
580 MSM_ROTATOR_OUT_PACK_PATTERN1);
581 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
582 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
583 1 << 8, /* ROT_EN */
584 MSM_ROTATOR_SUB_BLOCK_CFG);
585 iowrite32(0 << 29 | /* frame format 0 = linear */
586 (use_imem ? 0 : 1) << 22 | /* tile size */
587 0 << 19 | /* fetch planes 0=interleaved */
588 0 << 18 | /* unpack align */
589 1 << 17 | /* unpack tight */
590 3 << 13 | /* unpack count 0=1 component */
591 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
592 0 << 8 | /* has alpha */
593 0 << 6 | /* alpha bits 3=8bits */
594 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
595 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
596 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
597 MSM_ROTATOR_SRC_FORMAT);
598 }
599
600 return 0;
601}
602
603static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
604 unsigned int in_paddr,
605 unsigned int out_paddr,
606 unsigned int use_imem,
607 int new_session)
608{
609 int bpp, abits, rbits, gbits, bbits;
610
611 if (info->src.format != info->dst.format)
612 return -EINVAL;
613
614 bpp = get_bpp(info->src.format);
615 if (bpp < 0)
616 return -ENOTTY;
617
618 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
619 iowrite32(out_paddr +
620 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
621 MSM_ROTATOR_OUTP0_ADDR);
622
623 if (new_session) {
624 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
625 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
626 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
627 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
628 1 << 8, /* ROT_EN */
629 MSM_ROTATOR_SUB_BLOCK_CFG);
630 switch (info->src.format) {
631 case MDP_RGB_565:
632 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
633 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
634 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
635 MSM_ROTATOR_OUT_PACK_PATTERN1);
636 abits = 0;
637 rbits = COMPONENT_5BITS;
638 gbits = COMPONENT_6BITS;
639 bbits = COMPONENT_5BITS;
640 break;
641
642 case MDP_BGR_565:
643 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
644 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
645 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
646 MSM_ROTATOR_OUT_PACK_PATTERN1);
647 abits = 0;
648 rbits = COMPONENT_5BITS;
649 gbits = COMPONENT_6BITS;
650 bbits = COMPONENT_5BITS;
651 break;
652
653 case MDP_RGB_888:
654 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
655 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
656 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
657 MSM_ROTATOR_OUT_PACK_PATTERN1);
658 abits = 0;
659 rbits = COMPONENT_8BITS;
660 gbits = COMPONENT_8BITS;
661 bbits = COMPONENT_8BITS;
662 break;
663
664 case MDP_ARGB_8888:
665 case MDP_RGBA_8888:
666 case MDP_XRGB_8888:
667 case MDP_RGBX_8888:
668 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
669 CLR_B, 8),
670 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
671 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
672 CLR_B, 8),
673 MSM_ROTATOR_OUT_PACK_PATTERN1);
674 abits = COMPONENT_8BITS;
675 rbits = COMPONENT_8BITS;
676 gbits = COMPONENT_8BITS;
677 bbits = COMPONENT_8BITS;
678 break;
679
680 case MDP_BGRA_8888:
681 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
682 CLR_R, 8),
683 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
684 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
685 CLR_R, 8),
686 MSM_ROTATOR_OUT_PACK_PATTERN1);
687 abits = COMPONENT_8BITS;
688 rbits = COMPONENT_8BITS;
689 gbits = COMPONENT_8BITS;
690 bbits = COMPONENT_8BITS;
691 break;
692
693 default:
694 return -EINVAL;
695 }
696 iowrite32(0 << 29 | /* frame format 0 = linear */
697 (use_imem ? 0 : 1) << 22 | /* tile size */
698 0 << 19 | /* fetch planes 0=interleaved */
699 0 << 18 | /* unpack align */
700 1 << 17 | /* unpack tight */
701 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
702 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
703 (abits ? 1 : 0) << 8 | /* has alpha */
704 abits << 6 | /* alpha bits 3=8bits */
705 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
706 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
707 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
708 MSM_ROTATOR_SRC_FORMAT);
709 }
710
711 return 0;
712}
713
Naseer Ahmed18018602011-10-25 13:32:58 -0700714static int get_img(struct msmfb_data *fbd, unsigned long *start,
715 unsigned long *len, struct file **p_file, struct ion_handle **p_ihdl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716{
717 int ret = 0;
718#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700719 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700720 int put_needed, fb_num;
721#endif
722#ifdef CONFIG_ANDROID_PMEM
723 unsigned long vstart;
724#endif
725
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700727 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
728 file = fget_light(fbd->memory_id, &put_needed);
729 if (file == NULL)
730 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700731
Naseer Ahmed18018602011-10-25 13:32:58 -0700732 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
733 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
734 if (get_fb_phys_info(start, len, fb_num))
735 ret = -1;
736 else
737 *p_file = file;
738 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700739 ret = -1;
Naseer Ahmed18018602011-10-25 13:32:58 -0700740 if (ret)
741 fput_light(file, put_needed);
742 return ret;
743 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700745
746#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
747 *p_ihdl = ion_import_fd(msm_rotator_dev->client,
748 fbd->memory_id);
749 if (IS_ERR_OR_NULL(*p_ihdl))
750 return PTR_ERR(*p_ihdl);
751 if (!ion_phys(msm_rotator_dev->client, *p_ihdl, start,
752 (size_t *) len))
753 return 0;
754 else
755 return -ENOMEM;
756#endif
757#ifdef CONFIG_ANDROID_PMEM
758 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
759 return 0;
760 else
761 return -ENOMEM;
762#endif
763
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700764}
765
Naseer Ahmed18018602011-10-25 13:32:58 -0700766static void put_img(struct file *p_file, struct ion_handle *p_ihdl)
767{
768#ifdef CONFIG_ANDROID_PMEM
769 if (p_file != NULL)
770 put_pmem_file(p_file);
771#endif
772#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
773 if (!IS_ERR_OR_NULL(p_ihdl))
774 ion_free(msm_rotator_dev->client, p_ihdl);
775#endif
776}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700777static int msm_rotator_do_rotate(unsigned long arg)
778{
Naseer Ahmed18018602011-10-25 13:32:58 -0700779 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700780 struct msm_rotator_data_info info;
781 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700782 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700783 int use_imem = 0, rc = 0, s;
784 struct file *srcp0_file = NULL, *dstp0_file = NULL;
785 struct file *srcp1_file = NULL, *dstp1_file = NULL;
786 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
787 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700788 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700789 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700790 struct msm_rotator_img_info *img_info;
791 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700792
793 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
794 return -EFAULT;
795
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700796 mutex_lock(&msm_rotator_dev->rotator_lock);
797 for (s = 0; s < MAX_SESSIONS; s++)
798 if ((msm_rotator_dev->img_info[s] != NULL) &&
799 (info.session_id ==
800 (unsigned int)msm_rotator_dev->img_info[s]
801 ))
802 break;
803
804 if (s == MAX_SESSIONS) {
805 dev_dbg(msm_rotator_dev->device,
806 "%s() : Attempt to use invalid session_id %d\n",
807 __func__, s);
808 rc = -EINVAL;
809 goto do_rotate_unlock_mutex;
810 }
811
812 if (msm_rotator_dev->img_info[s]->enable == 0) {
813 dev_dbg(msm_rotator_dev->device,
814 "%s() : Session_id %d not enabled \n",
815 __func__, s);
816 rc = -EINVAL;
817 goto do_rotate_unlock_mutex;
818 }
819
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700820 img_info = msm_rotator_dev->img_info[s];
821 if (msm_rotator_get_plane_sizes(img_info->src.format,
822 img_info->src.width,
823 img_info->src.height,
824 &src_planes)) {
825 pr_err("%s: invalid src format\n", __func__);
826 rc = -EINVAL;
827 goto do_rotate_unlock_mutex;
828 }
829 if (msm_rotator_get_plane_sizes(img_info->dst.format,
830 img_info->dst.width,
831 img_info->dst.height,
832 &dst_planes)) {
833 pr_err("%s: invalid dst format\n", __func__);
834 rc = -EINVAL;
835 goto do_rotate_unlock_mutex;
836 }
837
Naseer Ahmed18018602011-10-25 13:32:58 -0700838 rc = get_img(&info.src, (unsigned long *)&in_paddr,
839 (unsigned long *)&src_len, &srcp0_file, &srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700840 if (rc) {
841 pr_err("%s: in get_img() failed id=0x%08x\n",
842 DRIVER_NAME, info.src.memory_id);
843 goto do_rotate_unlock_mutex;
844 }
845
Naseer Ahmed18018602011-10-25 13:32:58 -0700846 rc = get_img(&info.dst, (unsigned long *)&out_paddr,
847 (unsigned long *)&dst_len, &dstp0_file, &dstp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700848 if (rc) {
849 pr_err("%s: out get_img() failed id=0x%08x\n",
850 DRIVER_NAME, info.dst.memory_id);
851 goto do_rotate_unlock_mutex;
852 }
853
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700854 format = msm_rotator_dev->img_info[s]->src.format;
855 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700856 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
857 (src_planes.num_planes == 2)) {
858 if (checkoffset(info.src.offset,
859 src_planes.plane_size[0],
860 src_len)) {
861 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
862 __func__, src_len, info.src.offset);
863 rc = -ERANGE;
864 goto do_rotate_unlock_mutex;
865 }
866 if (checkoffset(info.dst.offset,
867 dst_planes.plane_size[0],
868 dst_len)) {
869 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
870 __func__, dst_len, info.dst.offset);
871 rc = -ERANGE;
872 goto do_rotate_unlock_mutex;
873 }
874
Naseer Ahmed18018602011-10-25 13:32:58 -0700875 rc = get_img(&info.src_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700876 (unsigned long *)&in_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700877 (unsigned long *)&src_len, &srcp1_file,
878 &srcp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700880 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700881 DRIVER_NAME, info.src_chroma.memory_id);
882 goto do_rotate_unlock_mutex;
883 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700884
Naseer Ahmed18018602011-10-25 13:32:58 -0700885 rc = get_img(&info.dst_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700886 (unsigned long *)&out_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700887 (unsigned long *)&dst_len, &dstp1_file,
888 &dstp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700890 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700892 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700894
895 if (checkoffset(info.src_chroma.offset,
896 src_planes.plane_size[1],
897 src_len)) {
898 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
899 __func__, src_len, info.src_chroma.offset);
900 rc = -ERANGE;
901 goto do_rotate_unlock_mutex;
902 }
903
904 if (checkoffset(info.dst_chroma.offset,
905 src_planes.plane_size[1],
906 dst_len)) {
907 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
908 __func__, dst_len, info.dst_chroma.offset);
909 rc = -ERANGE;
910 goto do_rotate_unlock_mutex;
911 }
912
913 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700915 } else {
916 if (checkoffset(info.src.offset,
917 src_planes.total_size,
918 src_len)) {
919 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
920 __func__, src_len, info.src.offset);
921 rc = -ERANGE;
922 goto do_rotate_unlock_mutex;
923 }
924 if (checkoffset(info.dst.offset,
925 dst_planes.total_size,
926 dst_len)) {
927 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
928 __func__, dst_len, info.dst.offset);
929 rc = -ERANGE;
930 goto do_rotate_unlock_mutex;
931 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 }
933
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700934 in_paddr += info.src.offset;
935 out_paddr += info.dst.offset;
936
937 if (!in_chroma_paddr && src_planes.num_planes >= 2)
938 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
939 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
940 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
941 if (src_planes.num_planes >= 3)
942 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
943
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700944 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
945 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
946 enable_rot_clks();
947 msm_rotator_dev->rot_clk_state = CLK_EN;
948 }
949 enable_irq(msm_rotator_dev->irq);
950
951#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
952 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
953#else
954 use_imem = 0;
955#endif
956 /*
957 * workaround for a hardware bug. rotator hardware hangs when we
958 * use write burst beat size 16 on 128X128 tile fetch mode. As a
959 * temporary fix use 0x42 for BURST_SIZE when imem used.
960 */
961 if (use_imem)
962 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
963
964 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
965 << 16) |
966 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
967 MSM_ROTATOR_SRC_SIZE);
968 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
969 << 16) |
970 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
971 MSM_ROTATOR_SRC_XY);
972 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
973 << 16) |
974 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
975 MSM_ROTATOR_SRC_IMAGE_SIZE);
976
977 switch (format) {
978 case MDP_RGB_565:
979 case MDP_BGR_565:
980 case MDP_RGB_888:
981 case MDP_ARGB_8888:
982 case MDP_RGBA_8888:
983 case MDP_XRGB_8888:
984 case MDP_BGRA_8888:
985 case MDP_RGBX_8888:
986 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
987 in_paddr, out_paddr,
988 use_imem,
989 msm_rotator_dev->last_session_idx
990 != s);
991 break;
992 case MDP_Y_CBCR_H2V2:
993 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700994 case MDP_Y_CB_CR_H2V2:
995 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530996 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997 case MDP_Y_CRCB_H2V2_TILE:
998 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700999 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1000 in_paddr, out_paddr, use_imem,
1001 msm_rotator_dev->last_session_idx
1002 != s,
1003 in_chroma_paddr,
1004 out_chroma_paddr,
1005 in_chroma2_paddr);
1006 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001007 case MDP_Y_CBCR_H2V1:
1008 case MDP_Y_CRCB_H2V1:
1009 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1010 in_paddr, out_paddr, use_imem,
1011 msm_rotator_dev->last_session_idx
1012 != s,
1013 in_chroma_paddr,
1014 out_chroma_paddr);
1015 break;
1016 case MDP_YCRYCB_H2V1:
1017 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1018 in_paddr, out_paddr, use_imem,
1019 msm_rotator_dev->last_session_idx != s);
1020 break;
1021 default:
1022 rc = -EINVAL;
1023 goto do_rotate_exit;
1024 }
1025
1026 if (rc != 0) {
1027 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1028 goto do_rotate_exit;
1029 }
1030
1031 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1032
1033 msm_rotator_dev->processing = 1;
1034 iowrite32(0x1, MSM_ROTATOR_START);
1035
1036 wait_event(msm_rotator_dev->wq,
1037 (msm_rotator_dev->processing == 0));
1038 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
1039 if ((status & 0x03) != 0x01)
1040 rc = -EFAULT;
1041 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1042 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1043
1044do_rotate_exit:
1045 disable_irq(msm_rotator_dev->irq);
1046#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1047 msm_rotator_imem_free(ROTATOR_REQUEST);
1048#endif
1049 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001050do_rotate_unlock_mutex:
Naseer Ahmed18018602011-10-25 13:32:58 -07001051 put_img(dstp1_file, dstp1_ihdl);
1052 put_img(srcp1_file, srcp1_ihdl);
1053 put_img(dstp0_file, dstp0_ihdl);
1054 put_img(srcp0_file, srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001055 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001056 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1057 __func__, rc);
1058 return rc;
1059}
1060
1061static int msm_rotator_start(unsigned long arg, int pid)
1062{
1063 struct msm_rotator_img_info info;
1064 int rc = 0;
1065 int s;
1066 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001067 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001068
1069 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1070 return -EFAULT;
1071
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001072 if (info.rotations & MDP_ROT_90) {
1073 dst_w = info.src_rect.h;
1074 dst_h = info.src_rect.w;
1075 } else {
1076 dst_w = info.src_rect.w;
1077 dst_h = info.src_rect.h;
1078 }
1079
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001080 if ((info.rotations > MSM_ROTATOR_MAX_ROT) ||
1081 (info.src.height > MSM_ROTATOR_MAX_H) ||
1082 (info.src.width > MSM_ROTATOR_MAX_W) ||
1083 (info.dst.height > MSM_ROTATOR_MAX_H) ||
1084 (info.dst.width > MSM_ROTATOR_MAX_W) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001085 checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
1086 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1087 checkoffset(info.dst_x, dst_w, info.dst.width) ||
1088 checkoffset(info.dst_y, dst_h, info.dst.height))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001089 return -EINVAL;
1090
1091 switch (info.src.format) {
1092 case MDP_RGB_565:
1093 case MDP_BGR_565:
1094 case MDP_RGB_888:
1095 case MDP_ARGB_8888:
1096 case MDP_RGBA_8888:
1097 case MDP_XRGB_8888:
1098 case MDP_RGBX_8888:
1099 case MDP_BGRA_8888:
1100 case MDP_Y_CBCR_H2V2:
1101 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001102 case MDP_Y_CB_CR_H2V2:
1103 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301104 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001105 case MDP_Y_CBCR_H2V1:
1106 case MDP_Y_CRCB_H2V1:
1107 case MDP_YCRYCB_H2V1:
1108 case MDP_Y_CRCB_H2V2_TILE:
1109 case MDP_Y_CBCR_H2V2_TILE:
1110 break;
1111 default:
1112 return -EINVAL;
1113 }
1114
1115 switch (info.dst.format) {
1116 case MDP_RGB_565:
1117 case MDP_BGR_565:
1118 case MDP_RGB_888:
1119 case MDP_ARGB_8888:
1120 case MDP_RGBA_8888:
1121 case MDP_XRGB_8888:
1122 case MDP_RGBX_8888:
1123 case MDP_BGRA_8888:
1124 case MDP_Y_CBCR_H2V2:
1125 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001126 case MDP_Y_CB_CR_H2V2:
1127 case MDP_Y_CR_CB_H2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001128 case MDP_Y_CBCR_H2V1:
1129 case MDP_Y_CRCB_H2V1:
1130 case MDP_YCRYCB_H2V1:
1131 break;
1132 default:
1133 return -EINVAL;
1134 }
1135
1136 mutex_lock(&msm_rotator_dev->rotator_lock);
1137 for (s = 0; s < MAX_SESSIONS; s++) {
1138 if ((msm_rotator_dev->img_info[s] != NULL) &&
1139 (info.session_id ==
1140 (unsigned int)msm_rotator_dev->img_info[s]
1141 )) {
1142 *(msm_rotator_dev->img_info[s]) = info;
1143 msm_rotator_dev->pid_list[s] = pid;
1144
1145 if (msm_rotator_dev->last_session_idx == s)
1146 msm_rotator_dev->last_session_idx =
1147 INVALID_SESSION;
1148 break;
1149 }
1150
1151 if ((msm_rotator_dev->img_info[s] == NULL) &&
1152 (first_free_index ==
1153 INVALID_SESSION))
1154 first_free_index = s;
1155 }
1156
1157 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1158 /* allocate a session id */
1159 msm_rotator_dev->img_info[first_free_index] =
1160 kzalloc(sizeof(struct msm_rotator_img_info),
1161 GFP_KERNEL);
1162 if (!msm_rotator_dev->img_info[first_free_index]) {
1163 printk(KERN_ERR "%s : unable to alloc mem\n",
1164 __func__);
1165 rc = -ENOMEM;
1166 goto rotator_start_exit;
1167 }
1168 info.session_id = (unsigned int)
1169 msm_rotator_dev->img_info[first_free_index];
1170 *(msm_rotator_dev->img_info[first_free_index]) = info;
1171 msm_rotator_dev->pid_list[first_free_index] = pid;
1172
1173 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1174 rc = -EFAULT;
1175 } else if (s == MAX_SESSIONS) {
1176 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1177 __func__);
1178 rc = -EBUSY;
1179 }
1180
1181rotator_start_exit:
1182 mutex_unlock(&msm_rotator_dev->rotator_lock);
1183
1184 return rc;
1185}
1186
1187static int msm_rotator_finish(unsigned long arg)
1188{
1189 int rc = 0;
1190 int s;
1191 unsigned int session_id;
1192
1193 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1194 return -EFAULT;
1195
1196 mutex_lock(&msm_rotator_dev->rotator_lock);
1197 for (s = 0; s < MAX_SESSIONS; s++) {
1198 if ((msm_rotator_dev->img_info[s] != NULL) &&
1199 (session_id ==
1200 (unsigned int)msm_rotator_dev->img_info[s])) {
1201 if (msm_rotator_dev->last_session_idx == s)
1202 msm_rotator_dev->last_session_idx =
1203 INVALID_SESSION;
1204 kfree(msm_rotator_dev->img_info[s]);
1205 msm_rotator_dev->img_info[s] = NULL;
1206 msm_rotator_dev->pid_list[s] = 0;
1207 break;
1208 }
1209 }
1210
1211 if (s == MAX_SESSIONS)
1212 rc = -EINVAL;
1213 mutex_unlock(&msm_rotator_dev->rotator_lock);
1214 return rc;
1215}
1216
1217static int
1218msm_rotator_open(struct inode *inode, struct file *filp)
1219{
1220 int *id;
1221 int i;
1222
1223 if (filp->private_data)
1224 return -EBUSY;
1225
1226 mutex_lock(&msm_rotator_dev->rotator_lock);
1227 id = &msm_rotator_dev->pid_list[0];
1228 for (i = 0; i < MAX_SESSIONS; i++, id++) {
1229 if (*id == 0)
1230 break;
1231 }
1232 mutex_unlock(&msm_rotator_dev->rotator_lock);
1233
1234 if (i == MAX_SESSIONS)
1235 return -EBUSY;
1236
kuogee hsieh7a46d592011-09-09 10:27:23 -07001237 filp->private_data = (void *)current->pid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238
1239 return 0;
1240}
1241
1242static int
1243msm_rotator_close(struct inode *inode, struct file *filp)
1244{
1245 int s;
1246 int pid;
1247
1248 pid = (int)filp->private_data;
1249 mutex_lock(&msm_rotator_dev->rotator_lock);
1250 for (s = 0; s < MAX_SESSIONS; s++) {
1251 if (msm_rotator_dev->img_info[s] != NULL &&
1252 msm_rotator_dev->pid_list[s] == pid) {
1253 kfree(msm_rotator_dev->img_info[s]);
1254 msm_rotator_dev->img_info[s] = NULL;
1255 if (msm_rotator_dev->last_session_idx == s)
1256 msm_rotator_dev->last_session_idx =
1257 INVALID_SESSION;
1258 }
1259 }
1260 mutex_unlock(&msm_rotator_dev->rotator_lock);
1261
1262 return 0;
1263}
1264
1265static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1266 unsigned long arg)
1267{
1268 int pid;
1269
1270 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1271 return -ENOTTY;
1272
1273 pid = (int)file->private_data;
1274
1275 switch (cmd) {
1276 case MSM_ROTATOR_IOCTL_START:
1277 return msm_rotator_start(arg, pid);
1278 case MSM_ROTATOR_IOCTL_ROTATE:
1279 return msm_rotator_do_rotate(arg);
1280 case MSM_ROTATOR_IOCTL_FINISH:
1281 return msm_rotator_finish(arg);
1282
1283 default:
1284 dev_dbg(msm_rotator_dev->device,
1285 "unexpected IOCTL %d\n", cmd);
1286 return -ENOTTY;
1287 }
1288}
1289
1290static const struct file_operations msm_rotator_fops = {
1291 .owner = THIS_MODULE,
1292 .open = msm_rotator_open,
1293 .release = msm_rotator_close,
1294 .unlocked_ioctl = msm_rotator_ioctl,
1295};
1296
1297static int __devinit msm_rotator_probe(struct platform_device *pdev)
1298{
1299 int rc = 0;
1300 struct resource *res;
1301 struct msm_rotator_platform_data *pdata = NULL;
1302 int i, number_of_clks;
1303 uint32_t ver;
1304
1305 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1306 if (!msm_rotator_dev) {
1307 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1308 __func__);
1309 return -ENOMEM;
1310 }
1311 for (i = 0; i < MAX_SESSIONS; i++)
1312 msm_rotator_dev->img_info[i] = NULL;
1313 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1314
1315 pdata = pdev->dev.platform_data;
1316 number_of_clks = pdata->number_of_clocks;
1317
1318 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1319 mutex_init(&msm_rotator_dev->imem_lock);
1320 msm_rotator_dev->imem_clk_state = CLK_DIS;
1321 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1322 msm_rotator_imem_clk_work_f);
1323 msm_rotator_dev->imem_clk = NULL;
1324 msm_rotator_dev->pdev = pdev;
1325
1326 msm_rotator_dev->core_clk = NULL;
1327 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001328
1329 for (i = 0; i < number_of_clks; i++) {
1330 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1331 msm_rotator_dev->imem_clk =
1332 clk_get(&msm_rotator_dev->pdev->dev,
1333 pdata->rotator_clks[i].clk_name);
1334 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1335 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1336 msm_rotator_dev->imem_clk = NULL;
1337 printk(KERN_ERR "%s: cannot get imem_clk "
1338 "rc=%d\n", DRIVER_NAME, rc);
1339 goto error_imem_clk;
1340 }
1341 if (pdata->rotator_clks[i].clk_rate)
1342 clk_set_min_rate(msm_rotator_dev->imem_clk,
1343 pdata->rotator_clks[i].clk_rate);
1344 }
1345 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1346 msm_rotator_dev->pclk =
1347 clk_get(&msm_rotator_dev->pdev->dev,
1348 pdata->rotator_clks[i].clk_name);
1349 if (IS_ERR(msm_rotator_dev->pclk)) {
1350 rc = PTR_ERR(msm_rotator_dev->pclk);
1351 msm_rotator_dev->pclk = NULL;
1352 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1353 DRIVER_NAME, rc);
1354 goto error_pclk;
1355 }
1356
1357 if (pdata->rotator_clks[i].clk_rate)
1358 clk_set_min_rate(msm_rotator_dev->pclk,
1359 pdata->rotator_clks[i].clk_rate);
1360 }
1361
1362 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1363 msm_rotator_dev->core_clk =
1364 clk_get(&msm_rotator_dev->pdev->dev,
1365 pdata->rotator_clks[i].clk_name);
1366 if (IS_ERR(msm_rotator_dev->core_clk)) {
1367 rc = PTR_ERR(msm_rotator_dev->core_clk);
1368 msm_rotator_dev->core_clk = NULL;
1369 printk(KERN_ERR "%s: cannot get core clk "
1370 "rc=%d\n", DRIVER_NAME, rc);
1371 goto error_core_clk;
1372 }
1373
1374 if (pdata->rotator_clks[i].clk_rate)
1375 clk_set_min_rate(msm_rotator_dev->core_clk,
1376 pdata->rotator_clks[i].clk_rate);
1377 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001378 }
1379
1380 msm_rotator_dev->regulator = regulator_get(NULL, pdata->regulator_name);
1381 if (IS_ERR(msm_rotator_dev->regulator))
1382 msm_rotator_dev->regulator = NULL;
1383
1384 msm_rotator_dev->rot_clk_state = CLK_DIS;
1385 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1386 msm_rotator_rot_clk_work_f);
1387
1388 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001389#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1390 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1391#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001392 platform_set_drvdata(pdev, msm_rotator_dev);
1393
1394
1395 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1396 if (!res) {
1397 printk(KERN_ALERT
1398 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1399 rc = -ENODEV;
1400 goto error_get_resource;
1401 }
1402 msm_rotator_dev->io_base = ioremap(res->start,
1403 resource_size(res));
1404
1405#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1406 if (msm_rotator_dev->imem_clk)
1407 clk_enable(msm_rotator_dev->imem_clk);
1408#endif
1409 enable_rot_clks();
1410 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1411 disable_rot_clks();
1412
1413#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1414 if (msm_rotator_dev->imem_clk)
1415 clk_disable(msm_rotator_dev->imem_clk);
1416#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001417 if (ver != pdata->hardware_version_number)
Nagamalleswararao Ganjibcdea002011-09-13 15:43:47 -07001418 pr_info("%s: invalid HW version\n", DRIVER_NAME);
Naseer Ahmed18018602011-10-25 13:32:58 -07001419
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001420 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1421 if (msm_rotator_dev->irq < 0) {
1422 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1423 DRIVER_NAME);
1424 rc = -ENODEV;
1425 goto error_get_irq;
1426 }
1427 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1428 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1429 if (rc) {
1430 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1431 goto error_get_irq;
1432 }
1433 /* we enable the IRQ when we need it in the ioctl */
1434 disable_irq(msm_rotator_dev->irq);
1435
1436 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1437 if (rc < 0) {
1438 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1439 __func__, rc);
1440 goto error_get_irq;
1441 }
1442
1443 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1444 if (IS_ERR(msm_rotator_dev->class)) {
1445 rc = PTR_ERR(msm_rotator_dev->class);
1446 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1447 DRIVER_NAME, rc);
1448 goto error_class_create;
1449 }
1450
1451 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1452 msm_rotator_dev->dev_num, NULL,
1453 DRIVER_NAME);
1454 if (IS_ERR(msm_rotator_dev->device)) {
1455 rc = PTR_ERR(msm_rotator_dev->device);
1456 printk(KERN_ERR "%s: device_create failed %d\n",
1457 DRIVER_NAME, rc);
1458 goto error_class_device_create;
1459 }
1460
1461 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1462 rc = cdev_add(&msm_rotator_dev->cdev,
1463 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1464 1);
1465 if (rc < 0) {
1466 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1467 goto error_cdev_add;
1468 }
1469
1470 init_waitqueue_head(&msm_rotator_dev->wq);
1471
1472 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1473 return rc;
1474
1475error_cdev_add:
1476 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1477error_class_device_create:
1478 class_destroy(msm_rotator_dev->class);
1479error_class_create:
1480 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1481error_get_irq:
1482 iounmap(msm_rotator_dev->io_base);
1483error_get_resource:
1484 mutex_destroy(&msm_rotator_dev->rotator_lock);
1485 if (msm_rotator_dev->regulator)
1486 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001487 clk_put(msm_rotator_dev->core_clk);
1488error_core_clk:
1489 clk_put(msm_rotator_dev->pclk);
1490error_pclk:
1491 if (msm_rotator_dev->imem_clk)
1492 clk_put(msm_rotator_dev->imem_clk);
1493error_imem_clk:
1494 mutex_destroy(&msm_rotator_dev->imem_lock);
1495 kfree(msm_rotator_dev);
1496 return rc;
1497}
1498
1499static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1500{
1501 int i;
1502
1503 free_irq(msm_rotator_dev->irq, NULL);
1504 mutex_destroy(&msm_rotator_dev->rotator_lock);
1505 cdev_del(&msm_rotator_dev->cdev);
1506 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1507 class_destroy(msm_rotator_dev->class);
1508 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1509 iounmap(msm_rotator_dev->io_base);
1510 if (msm_rotator_dev->imem_clk) {
1511 if (msm_rotator_dev->imem_clk_state == CLK_EN)
1512 clk_disable(msm_rotator_dev->imem_clk);
1513 clk_put(msm_rotator_dev->imem_clk);
1514 msm_rotator_dev->imem_clk = NULL;
1515 }
1516 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1517 disable_rot_clks();
1518 clk_put(msm_rotator_dev->core_clk);
1519 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001520 if (msm_rotator_dev->regulator)
1521 regulator_put(msm_rotator_dev->regulator);
1522 msm_rotator_dev->core_clk = NULL;
1523 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001524 mutex_destroy(&msm_rotator_dev->imem_lock);
1525 for (i = 0; i < MAX_SESSIONS; i++)
1526 if (msm_rotator_dev->img_info[i] != NULL)
1527 kfree(msm_rotator_dev->img_info[i]);
1528 kfree(msm_rotator_dev);
1529 return 0;
1530}
1531
1532#ifdef CONFIG_PM
1533static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1534{
1535 mutex_lock(&msm_rotator_dev->imem_lock);
1536 if (msm_rotator_dev->imem_clk_state == CLK_EN
1537 && msm_rotator_dev->imem_clk) {
1538 clk_disable(msm_rotator_dev->imem_clk);
1539 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1540 }
1541 mutex_unlock(&msm_rotator_dev->imem_lock);
1542 mutex_lock(&msm_rotator_dev->rotator_lock);
1543 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1544 disable_rot_clks();
1545 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1546 }
1547 mutex_unlock(&msm_rotator_dev->rotator_lock);
1548 return 0;
1549}
1550
1551static int msm_rotator_resume(struct platform_device *dev)
1552{
1553 mutex_lock(&msm_rotator_dev->imem_lock);
1554 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1555 && msm_rotator_dev->imem_clk) {
1556 clk_enable(msm_rotator_dev->imem_clk);
1557 msm_rotator_dev->imem_clk_state = CLK_EN;
1558 }
1559 mutex_unlock(&msm_rotator_dev->imem_lock);
1560 mutex_lock(&msm_rotator_dev->rotator_lock);
1561 if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND) {
1562 enable_rot_clks();
1563 msm_rotator_dev->rot_clk_state = CLK_EN;
1564 }
1565 mutex_unlock(&msm_rotator_dev->rotator_lock);
1566 return 0;
1567}
1568#endif
1569
1570static struct platform_driver msm_rotator_platform_driver = {
1571 .probe = msm_rotator_probe,
1572 .remove = __devexit_p(msm_rotator_remove),
1573#ifdef CONFIG_PM
1574 .suspend = msm_rotator_suspend,
1575 .resume = msm_rotator_resume,
1576#endif
1577 .driver = {
1578 .owner = THIS_MODULE,
1579 .name = DRIVER_NAME
1580 }
1581};
1582
1583static int __init msm_rotator_init(void)
1584{
1585 return platform_driver_register(&msm_rotator_platform_driver);
1586}
1587
1588static void __exit msm_rotator_exit(void)
1589{
1590 return platform_driver_unregister(&msm_rotator_platform_driver);
1591}
1592
1593module_init(msm_rotator_init);
1594module_exit(msm_rotator_exit);
1595
1596MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1597MODULE_VERSION("1.0");
1598MODULE_LICENSE("GPL v2");