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