blob: d6fb9378a57ac3672a8f651999a5f8ffa0a07e60 [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
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -070085#define MAX_DOWNSCALE_RATIO 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086
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) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700432 1 << 8 | /* ROT_EN */
433 info->downscale_ratio << 2 | /* downscale v ratio */
434 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700435 MSM_ROTATOR_SUB_BLOCK_CFG);
436 iowrite32(0 << 29 | /* frame format 0 = linear */
437 (use_imem ? 0 : 1) << 22 | /* tile size */
438 2 << 19 | /* fetch planes 2 = pseudo */
439 0 << 18 | /* unpack align */
440 1 << 17 | /* unpack tight */
441 1 << 13 | /* unpack count 0=1 component */
442 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
443 0 << 8 | /* has alpha */
444 0 << 6 | /* alpha bits 3=8bits */
445 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
446 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
447 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
448 MSM_ROTATOR_SRC_FORMAT);
449 }
450
451 return 0;
452}
453
454static int msm_rotator_ycxcx_h2v2(struct msm_rotator_img_info *info,
455 unsigned int in_paddr,
456 unsigned int out_paddr,
457 unsigned int use_imem,
458 int new_session,
459 unsigned int in_chroma_paddr,
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700460 unsigned int out_chroma_paddr,
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700461 unsigned int in_chroma2_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700462{
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700463 uint32_t dst_format;
464 int is_tile = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700466 switch (info->src.format) {
467 case MDP_Y_CRCB_H2V2_TILE:
468 is_tile = 1;
469 case MDP_Y_CR_CB_H2V2:
470 case MDP_Y_CR_CB_GH2V2:
471 case MDP_Y_CRCB_H2V2:
472 dst_format = MDP_Y_CRCB_H2V2;
473 break;
474 case MDP_Y_CBCR_H2V2_TILE:
475 is_tile = 1;
476 case MDP_Y_CB_CR_H2V2:
477 case MDP_Y_CBCR_H2V2:
478 dst_format = MDP_Y_CBCR_H2V2;
479 break;
480 default:
481 return -EINVAL;
482 }
483 if (info->dst.format != dst_format)
484 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485
486 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700487 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
488 iowrite32(in_chroma2_paddr, MSM_ROTATOR_SRCP2_ADDR);
489
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700490 iowrite32(out_paddr +
491 ((info->dst_y * info->dst.width) + info->dst_x),
492 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700493 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700494 ((info->dst_y * info->dst.width)/2 + info->dst_x),
495 MSM_ROTATOR_OUTP1_ADDR);
496
497 if (new_session) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700498 if (in_chroma2_paddr) {
499 if (info->src.format == MDP_Y_CR_CB_GH2V2) {
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530500 iowrite32(ALIGN(info->src.width, 16) |
501 ALIGN((info->src.width / 2), 16) << 16,
502 MSM_ROTATOR_SRC_YSTRIDE1);
503 iowrite32(ALIGN((info->src.width / 2), 16),
504 MSM_ROTATOR_SRC_YSTRIDE2);
505 } else {
506 iowrite32(info->src.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700507 (info->src.width / 2) << 16,
508 MSM_ROTATOR_SRC_YSTRIDE1);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530509 iowrite32((info->src.width / 2),
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700510 MSM_ROTATOR_SRC_YSTRIDE2);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530511 }
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700512 } else {
513 iowrite32(info->src.width |
514 info->src.width << 16,
515 MSM_ROTATOR_SRC_YSTRIDE1);
516 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700517 iowrite32(info->dst.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700518 info->dst.width << 16,
519 MSM_ROTATOR_OUT_YSTRIDE1);
520
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700521 if (dst_format == MDP_Y_CBCR_H2V2) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700522 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
523 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
524 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
525 MSM_ROTATOR_OUT_PACK_PATTERN1);
526 } else {
527 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
528 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
529 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
530 MSM_ROTATOR_OUT_PACK_PATTERN1);
531 }
532 iowrite32((3 << 18) | /* chroma sampling 3=4:2:0 */
533 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700534 1 << 8 | /* ROT_EN */
535 info->downscale_ratio << 2 | /* downscale v ratio */
536 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537 MSM_ROTATOR_SUB_BLOCK_CFG);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700538
539 iowrite32((is_tile ? 2 : 0) << 29 | /* frame format */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700540 (use_imem ? 0 : 1) << 22 | /* tile size */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700541 (in_chroma2_paddr ? 1 : 2) << 19 | /* fetch planes */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700542 0 << 18 | /* unpack align */
543 1 << 17 | /* unpack tight */
544 1 << 13 | /* unpack count 0=1 component */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700545 0 << 9 | /* src Bpp 0=1 byte ... */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700546 0 << 8 | /* has alpha */
547 0 << 6 | /* alpha bits 3=8bits */
548 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
549 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
550 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
551 MSM_ROTATOR_SRC_FORMAT);
552 }
553 return 0;
554}
555
556static int msm_rotator_ycrycb(struct msm_rotator_img_info *info,
557 unsigned int in_paddr,
558 unsigned int out_paddr,
559 unsigned int use_imem,
560 int new_session)
561{
562 int bpp;
563
564 if (info->src.format != info->dst.format)
565 return -EINVAL;
566
567 bpp = get_bpp(info->src.format);
568 if (bpp < 0)
569 return -ENOTTY;
570
571 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
572 iowrite32(out_paddr +
573 ((info->dst_y * info->dst.width) + info->dst_x),
574 MSM_ROTATOR_OUTP0_ADDR);
575
576 if (new_session) {
577 iowrite32(info->src.width,
578 MSM_ROTATOR_SRC_YSTRIDE1);
579 iowrite32(info->dst.width,
580 MSM_ROTATOR_OUT_YSTRIDE1);
581 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
582 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
583 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
584 MSM_ROTATOR_OUT_PACK_PATTERN1);
585 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
586 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700587 1 << 8 | /* ROT_EN */
588 info->downscale_ratio << 2 | /* downscale v ratio */
589 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700590 MSM_ROTATOR_SUB_BLOCK_CFG);
591 iowrite32(0 << 29 | /* frame format 0 = linear */
592 (use_imem ? 0 : 1) << 22 | /* tile size */
593 0 << 19 | /* fetch planes 0=interleaved */
594 0 << 18 | /* unpack align */
595 1 << 17 | /* unpack tight */
596 3 << 13 | /* unpack count 0=1 component */
597 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
598 0 << 8 | /* has alpha */
599 0 << 6 | /* alpha bits 3=8bits */
600 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
601 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
602 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
603 MSM_ROTATOR_SRC_FORMAT);
604 }
605
606 return 0;
607}
608
609static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
610 unsigned int in_paddr,
611 unsigned int out_paddr,
612 unsigned int use_imem,
613 int new_session)
614{
615 int bpp, abits, rbits, gbits, bbits;
616
617 if (info->src.format != info->dst.format)
618 return -EINVAL;
619
620 bpp = get_bpp(info->src.format);
621 if (bpp < 0)
622 return -ENOTTY;
623
624 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
625 iowrite32(out_paddr +
626 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
627 MSM_ROTATOR_OUTP0_ADDR);
628
629 if (new_session) {
630 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
631 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
632 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
633 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700634 1 << 8 | /* ROT_EN */
635 info->downscale_ratio << 2 | /* downscale v ratio */
636 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700637 MSM_ROTATOR_SUB_BLOCK_CFG);
638 switch (info->src.format) {
639 case MDP_RGB_565:
640 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
641 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
642 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
643 MSM_ROTATOR_OUT_PACK_PATTERN1);
644 abits = 0;
645 rbits = COMPONENT_5BITS;
646 gbits = COMPONENT_6BITS;
647 bbits = COMPONENT_5BITS;
648 break;
649
650 case MDP_BGR_565:
651 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
652 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
653 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
654 MSM_ROTATOR_OUT_PACK_PATTERN1);
655 abits = 0;
656 rbits = COMPONENT_5BITS;
657 gbits = COMPONENT_6BITS;
658 bbits = COMPONENT_5BITS;
659 break;
660
661 case MDP_RGB_888:
662 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
663 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
664 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
665 MSM_ROTATOR_OUT_PACK_PATTERN1);
666 abits = 0;
667 rbits = COMPONENT_8BITS;
668 gbits = COMPONENT_8BITS;
669 bbits = COMPONENT_8BITS;
670 break;
671
672 case MDP_ARGB_8888:
673 case MDP_RGBA_8888:
674 case MDP_XRGB_8888:
675 case MDP_RGBX_8888:
676 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
677 CLR_B, 8),
678 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
679 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
680 CLR_B, 8),
681 MSM_ROTATOR_OUT_PACK_PATTERN1);
682 abits = COMPONENT_8BITS;
683 rbits = COMPONENT_8BITS;
684 gbits = COMPONENT_8BITS;
685 bbits = COMPONENT_8BITS;
686 break;
687
688 case MDP_BGRA_8888:
689 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
690 CLR_R, 8),
691 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
692 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
693 CLR_R, 8),
694 MSM_ROTATOR_OUT_PACK_PATTERN1);
695 abits = COMPONENT_8BITS;
696 rbits = COMPONENT_8BITS;
697 gbits = COMPONENT_8BITS;
698 bbits = COMPONENT_8BITS;
699 break;
700
701 default:
702 return -EINVAL;
703 }
704 iowrite32(0 << 29 | /* frame format 0 = linear */
705 (use_imem ? 0 : 1) << 22 | /* tile size */
706 0 << 19 | /* fetch planes 0=interleaved */
707 0 << 18 | /* unpack align */
708 1 << 17 | /* unpack tight */
709 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
710 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
711 (abits ? 1 : 0) << 8 | /* has alpha */
712 abits << 6 | /* alpha bits 3=8bits */
713 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
714 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
715 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
716 MSM_ROTATOR_SRC_FORMAT);
717 }
718
719 return 0;
720}
721
Naseer Ahmed18018602011-10-25 13:32:58 -0700722static int get_img(struct msmfb_data *fbd, unsigned long *start,
723 unsigned long *len, struct file **p_file, struct ion_handle **p_ihdl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724{
725 int ret = 0;
726#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700727 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700728 int put_needed, fb_num;
729#endif
730#ifdef CONFIG_ANDROID_PMEM
731 unsigned long vstart;
732#endif
733
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700735 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
736 file = fget_light(fbd->memory_id, &put_needed);
737 if (file == NULL)
738 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700739
Naseer Ahmed18018602011-10-25 13:32:58 -0700740 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
741 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
742 if (get_fb_phys_info(start, len, fb_num))
743 ret = -1;
744 else
745 *p_file = file;
746 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700747 ret = -1;
Naseer Ahmed18018602011-10-25 13:32:58 -0700748 if (ret)
749 fput_light(file, put_needed);
750 return ret;
751 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700752#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700753
754#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
755 *p_ihdl = ion_import_fd(msm_rotator_dev->client,
756 fbd->memory_id);
757 if (IS_ERR_OR_NULL(*p_ihdl))
758 return PTR_ERR(*p_ihdl);
759 if (!ion_phys(msm_rotator_dev->client, *p_ihdl, start,
760 (size_t *) len))
761 return 0;
762 else
763 return -ENOMEM;
764#endif
765#ifdef CONFIG_ANDROID_PMEM
766 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
767 return 0;
768 else
769 return -ENOMEM;
770#endif
771
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700772}
773
Naseer Ahmed18018602011-10-25 13:32:58 -0700774static void put_img(struct file *p_file, struct ion_handle *p_ihdl)
775{
776#ifdef CONFIG_ANDROID_PMEM
777 if (p_file != NULL)
778 put_pmem_file(p_file);
779#endif
780#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
781 if (!IS_ERR_OR_NULL(p_ihdl))
782 ion_free(msm_rotator_dev->client, p_ihdl);
783#endif
784}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700785static int msm_rotator_do_rotate(unsigned long arg)
786{
Naseer Ahmed18018602011-10-25 13:32:58 -0700787 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700788 struct msm_rotator_data_info info;
789 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700790 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700791 int use_imem = 0, rc = 0, s;
792 struct file *srcp0_file = NULL, *dstp0_file = NULL;
793 struct file *srcp1_file = NULL, *dstp1_file = NULL;
794 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
795 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700796 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700797 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700798 struct msm_rotator_img_info *img_info;
799 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800
801 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
802 return -EFAULT;
803
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700804 mutex_lock(&msm_rotator_dev->rotator_lock);
805 for (s = 0; s < MAX_SESSIONS; s++)
806 if ((msm_rotator_dev->img_info[s] != NULL) &&
807 (info.session_id ==
808 (unsigned int)msm_rotator_dev->img_info[s]
809 ))
810 break;
811
812 if (s == MAX_SESSIONS) {
813 dev_dbg(msm_rotator_dev->device,
814 "%s() : Attempt to use invalid session_id %d\n",
815 __func__, s);
816 rc = -EINVAL;
817 goto do_rotate_unlock_mutex;
818 }
819
820 if (msm_rotator_dev->img_info[s]->enable == 0) {
821 dev_dbg(msm_rotator_dev->device,
822 "%s() : Session_id %d not enabled \n",
823 __func__, s);
824 rc = -EINVAL;
825 goto do_rotate_unlock_mutex;
826 }
827
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700828 img_info = msm_rotator_dev->img_info[s];
829 if (msm_rotator_get_plane_sizes(img_info->src.format,
830 img_info->src.width,
831 img_info->src.height,
832 &src_planes)) {
833 pr_err("%s: invalid src format\n", __func__);
834 rc = -EINVAL;
835 goto do_rotate_unlock_mutex;
836 }
837 if (msm_rotator_get_plane_sizes(img_info->dst.format,
838 img_info->dst.width,
839 img_info->dst.height,
840 &dst_planes)) {
841 pr_err("%s: invalid dst format\n", __func__);
842 rc = -EINVAL;
843 goto do_rotate_unlock_mutex;
844 }
845
Naseer Ahmed18018602011-10-25 13:32:58 -0700846 rc = get_img(&info.src, (unsigned long *)&in_paddr,
847 (unsigned long *)&src_len, &srcp0_file, &srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700848 if (rc) {
849 pr_err("%s: in get_img() failed id=0x%08x\n",
850 DRIVER_NAME, info.src.memory_id);
851 goto do_rotate_unlock_mutex;
852 }
853
Naseer Ahmed18018602011-10-25 13:32:58 -0700854 rc = get_img(&info.dst, (unsigned long *)&out_paddr,
855 (unsigned long *)&dst_len, &dstp0_file, &dstp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700856 if (rc) {
857 pr_err("%s: out get_img() failed id=0x%08x\n",
858 DRIVER_NAME, info.dst.memory_id);
859 goto do_rotate_unlock_mutex;
860 }
861
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 format = msm_rotator_dev->img_info[s]->src.format;
863 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700864 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
865 (src_planes.num_planes == 2)) {
866 if (checkoffset(info.src.offset,
867 src_planes.plane_size[0],
868 src_len)) {
869 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
870 __func__, src_len, info.src.offset);
871 rc = -ERANGE;
872 goto do_rotate_unlock_mutex;
873 }
874 if (checkoffset(info.dst.offset,
875 dst_planes.plane_size[0],
876 dst_len)) {
877 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
878 __func__, dst_len, info.dst.offset);
879 rc = -ERANGE;
880 goto do_rotate_unlock_mutex;
881 }
882
Naseer Ahmed18018602011-10-25 13:32:58 -0700883 rc = get_img(&info.src_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700884 (unsigned long *)&in_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700885 (unsigned long *)&src_len, &srcp1_file,
886 &srcp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700888 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889 DRIVER_NAME, info.src_chroma.memory_id);
890 goto do_rotate_unlock_mutex;
891 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700892
Naseer Ahmed18018602011-10-25 13:32:58 -0700893 rc = get_img(&info.dst_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700894 (unsigned long *)&out_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700895 (unsigned long *)&dst_len, &dstp1_file,
896 &dstp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700898 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700900 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700902
903 if (checkoffset(info.src_chroma.offset,
904 src_planes.plane_size[1],
905 src_len)) {
906 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
907 __func__, src_len, info.src_chroma.offset);
908 rc = -ERANGE;
909 goto do_rotate_unlock_mutex;
910 }
911
912 if (checkoffset(info.dst_chroma.offset,
913 src_planes.plane_size[1],
914 dst_len)) {
915 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
916 __func__, dst_len, info.dst_chroma.offset);
917 rc = -ERANGE;
918 goto do_rotate_unlock_mutex;
919 }
920
921 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700923 } else {
924 if (checkoffset(info.src.offset,
925 src_planes.total_size,
926 src_len)) {
927 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
928 __func__, src_len, info.src.offset);
929 rc = -ERANGE;
930 goto do_rotate_unlock_mutex;
931 }
932 if (checkoffset(info.dst.offset,
933 dst_planes.total_size,
934 dst_len)) {
935 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
936 __func__, dst_len, info.dst.offset);
937 rc = -ERANGE;
938 goto do_rotate_unlock_mutex;
939 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700940 }
941
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700942 in_paddr += info.src.offset;
943 out_paddr += info.dst.offset;
944
945 if (!in_chroma_paddr && src_planes.num_planes >= 2)
946 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
947 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
948 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
949 if (src_planes.num_planes >= 3)
950 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
951
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700952 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
953 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
954 enable_rot_clks();
955 msm_rotator_dev->rot_clk_state = CLK_EN;
956 }
957 enable_irq(msm_rotator_dev->irq);
958
959#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
960 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
961#else
962 use_imem = 0;
963#endif
964 /*
965 * workaround for a hardware bug. rotator hardware hangs when we
966 * use write burst beat size 16 on 128X128 tile fetch mode. As a
967 * temporary fix use 0x42 for BURST_SIZE when imem used.
968 */
969 if (use_imem)
970 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
971
972 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
973 << 16) |
974 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
975 MSM_ROTATOR_SRC_SIZE);
976 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
977 << 16) |
978 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
979 MSM_ROTATOR_SRC_XY);
980 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
981 << 16) |
982 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
983 MSM_ROTATOR_SRC_IMAGE_SIZE);
984
985 switch (format) {
986 case MDP_RGB_565:
987 case MDP_BGR_565:
988 case MDP_RGB_888:
989 case MDP_ARGB_8888:
990 case MDP_RGBA_8888:
991 case MDP_XRGB_8888:
992 case MDP_BGRA_8888:
993 case MDP_RGBX_8888:
994 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
995 in_paddr, out_paddr,
996 use_imem,
997 msm_rotator_dev->last_session_idx
998 != s);
999 break;
1000 case MDP_Y_CBCR_H2V2:
1001 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001002 case MDP_Y_CB_CR_H2V2:
1003 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301004 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001005 case MDP_Y_CRCB_H2V2_TILE:
1006 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001007 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1008 in_paddr, out_paddr, use_imem,
1009 msm_rotator_dev->last_session_idx
1010 != s,
1011 in_chroma_paddr,
1012 out_chroma_paddr,
1013 in_chroma2_paddr);
1014 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001015 case MDP_Y_CBCR_H2V1:
1016 case MDP_Y_CRCB_H2V1:
1017 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1018 in_paddr, out_paddr, use_imem,
1019 msm_rotator_dev->last_session_idx
1020 != s,
1021 in_chroma_paddr,
1022 out_chroma_paddr);
1023 break;
1024 case MDP_YCRYCB_H2V1:
1025 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1026 in_paddr, out_paddr, use_imem,
1027 msm_rotator_dev->last_session_idx != s);
1028 break;
1029 default:
1030 rc = -EINVAL;
1031 goto do_rotate_exit;
1032 }
1033
1034 if (rc != 0) {
1035 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1036 goto do_rotate_exit;
1037 }
1038
1039 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1040
1041 msm_rotator_dev->processing = 1;
1042 iowrite32(0x1, MSM_ROTATOR_START);
1043
1044 wait_event(msm_rotator_dev->wq,
1045 (msm_rotator_dev->processing == 0));
1046 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
1047 if ((status & 0x03) != 0x01)
1048 rc = -EFAULT;
1049 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1050 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1051
1052do_rotate_exit:
1053 disable_irq(msm_rotator_dev->irq);
1054#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1055 msm_rotator_imem_free(ROTATOR_REQUEST);
1056#endif
1057 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001058do_rotate_unlock_mutex:
Naseer Ahmed18018602011-10-25 13:32:58 -07001059 put_img(dstp1_file, dstp1_ihdl);
1060 put_img(srcp1_file, srcp1_ihdl);
1061 put_img(dstp0_file, dstp0_ihdl);
1062 put_img(srcp0_file, srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001063 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001064 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1065 __func__, rc);
1066 return rc;
1067}
1068
1069static int msm_rotator_start(unsigned long arg, int pid)
1070{
1071 struct msm_rotator_img_info info;
1072 int rc = 0;
1073 int s;
1074 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001075 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001076
1077 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1078 return -EFAULT;
1079
1080 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-Moreno67273e52011-10-21 19:04:18 -07001085 (info.downscale_ratio > MAX_DOWNSCALE_RATIO)) {
1086 pr_err("%s: Invalid parameters\n", __func__);
1087 return -EINVAL;
1088 }
1089
1090 if (info.rotations & MDP_ROT_90) {
1091 dst_w = info.src_rect.h >> info.downscale_ratio;
1092 dst_h = info.src_rect.w >> info.downscale_ratio;
1093 } else {
1094 dst_w = info.src_rect.w >> info.downscale_ratio;
1095 dst_h = info.src_rect.h >> info.downscale_ratio;
1096 }
1097
1098 if (checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001099 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1100 checkoffset(info.dst_x, dst_w, info.dst.width) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001101 checkoffset(info.dst_y, dst_h, info.dst.height)) {
1102 pr_err("%s: Invalid src or dst rect\n", __func__);
1103 return -ERANGE;
1104 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001105
1106 switch (info.src.format) {
1107 case MDP_RGB_565:
1108 case MDP_BGR_565:
1109 case MDP_RGB_888:
1110 case MDP_ARGB_8888:
1111 case MDP_RGBA_8888:
1112 case MDP_XRGB_8888:
1113 case MDP_RGBX_8888:
1114 case MDP_BGRA_8888:
1115 case MDP_Y_CBCR_H2V2:
1116 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001117 case MDP_Y_CB_CR_H2V2:
1118 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301119 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001120 case MDP_Y_CBCR_H2V1:
1121 case MDP_Y_CRCB_H2V1:
1122 case MDP_YCRYCB_H2V1:
1123 case MDP_Y_CRCB_H2V2_TILE:
1124 case MDP_Y_CBCR_H2V2_TILE:
1125 break;
1126 default:
1127 return -EINVAL;
1128 }
1129
1130 switch (info.dst.format) {
1131 case MDP_RGB_565:
1132 case MDP_BGR_565:
1133 case MDP_RGB_888:
1134 case MDP_ARGB_8888:
1135 case MDP_RGBA_8888:
1136 case MDP_XRGB_8888:
1137 case MDP_RGBX_8888:
1138 case MDP_BGRA_8888:
1139 case MDP_Y_CBCR_H2V2:
1140 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001141 case MDP_Y_CB_CR_H2V2:
1142 case MDP_Y_CR_CB_H2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001143 case MDP_Y_CBCR_H2V1:
1144 case MDP_Y_CRCB_H2V1:
1145 case MDP_YCRYCB_H2V1:
1146 break;
1147 default:
1148 return -EINVAL;
1149 }
1150
1151 mutex_lock(&msm_rotator_dev->rotator_lock);
1152 for (s = 0; s < MAX_SESSIONS; s++) {
1153 if ((msm_rotator_dev->img_info[s] != NULL) &&
1154 (info.session_id ==
1155 (unsigned int)msm_rotator_dev->img_info[s]
1156 )) {
1157 *(msm_rotator_dev->img_info[s]) = info;
1158 msm_rotator_dev->pid_list[s] = pid;
1159
1160 if (msm_rotator_dev->last_session_idx == s)
1161 msm_rotator_dev->last_session_idx =
1162 INVALID_SESSION;
1163 break;
1164 }
1165
1166 if ((msm_rotator_dev->img_info[s] == NULL) &&
1167 (first_free_index ==
1168 INVALID_SESSION))
1169 first_free_index = s;
1170 }
1171
1172 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1173 /* allocate a session id */
1174 msm_rotator_dev->img_info[first_free_index] =
1175 kzalloc(sizeof(struct msm_rotator_img_info),
1176 GFP_KERNEL);
1177 if (!msm_rotator_dev->img_info[first_free_index]) {
1178 printk(KERN_ERR "%s : unable to alloc mem\n",
1179 __func__);
1180 rc = -ENOMEM;
1181 goto rotator_start_exit;
1182 }
1183 info.session_id = (unsigned int)
1184 msm_rotator_dev->img_info[first_free_index];
1185 *(msm_rotator_dev->img_info[first_free_index]) = info;
1186 msm_rotator_dev->pid_list[first_free_index] = pid;
1187
1188 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1189 rc = -EFAULT;
1190 } else if (s == MAX_SESSIONS) {
1191 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1192 __func__);
1193 rc = -EBUSY;
1194 }
1195
1196rotator_start_exit:
1197 mutex_unlock(&msm_rotator_dev->rotator_lock);
1198
1199 return rc;
1200}
1201
1202static int msm_rotator_finish(unsigned long arg)
1203{
1204 int rc = 0;
1205 int s;
1206 unsigned int session_id;
1207
1208 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1209 return -EFAULT;
1210
1211 mutex_lock(&msm_rotator_dev->rotator_lock);
1212 for (s = 0; s < MAX_SESSIONS; s++) {
1213 if ((msm_rotator_dev->img_info[s] != NULL) &&
1214 (session_id ==
1215 (unsigned int)msm_rotator_dev->img_info[s])) {
1216 if (msm_rotator_dev->last_session_idx == s)
1217 msm_rotator_dev->last_session_idx =
1218 INVALID_SESSION;
1219 kfree(msm_rotator_dev->img_info[s]);
1220 msm_rotator_dev->img_info[s] = NULL;
1221 msm_rotator_dev->pid_list[s] = 0;
1222 break;
1223 }
1224 }
1225
1226 if (s == MAX_SESSIONS)
1227 rc = -EINVAL;
1228 mutex_unlock(&msm_rotator_dev->rotator_lock);
1229 return rc;
1230}
1231
1232static int
1233msm_rotator_open(struct inode *inode, struct file *filp)
1234{
1235 int *id;
1236 int i;
1237
1238 if (filp->private_data)
1239 return -EBUSY;
1240
1241 mutex_lock(&msm_rotator_dev->rotator_lock);
1242 id = &msm_rotator_dev->pid_list[0];
1243 for (i = 0; i < MAX_SESSIONS; i++, id++) {
1244 if (*id == 0)
1245 break;
1246 }
1247 mutex_unlock(&msm_rotator_dev->rotator_lock);
1248
1249 if (i == MAX_SESSIONS)
1250 return -EBUSY;
1251
kuogee hsieh7a46d592011-09-09 10:27:23 -07001252 filp->private_data = (void *)current->pid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001253
1254 return 0;
1255}
1256
1257static int
1258msm_rotator_close(struct inode *inode, struct file *filp)
1259{
1260 int s;
1261 int pid;
1262
1263 pid = (int)filp->private_data;
1264 mutex_lock(&msm_rotator_dev->rotator_lock);
1265 for (s = 0; s < MAX_SESSIONS; s++) {
1266 if (msm_rotator_dev->img_info[s] != NULL &&
1267 msm_rotator_dev->pid_list[s] == pid) {
1268 kfree(msm_rotator_dev->img_info[s]);
1269 msm_rotator_dev->img_info[s] = NULL;
1270 if (msm_rotator_dev->last_session_idx == s)
1271 msm_rotator_dev->last_session_idx =
1272 INVALID_SESSION;
1273 }
1274 }
1275 mutex_unlock(&msm_rotator_dev->rotator_lock);
1276
1277 return 0;
1278}
1279
1280static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1281 unsigned long arg)
1282{
1283 int pid;
1284
1285 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1286 return -ENOTTY;
1287
1288 pid = (int)file->private_data;
1289
1290 switch (cmd) {
1291 case MSM_ROTATOR_IOCTL_START:
1292 return msm_rotator_start(arg, pid);
1293 case MSM_ROTATOR_IOCTL_ROTATE:
1294 return msm_rotator_do_rotate(arg);
1295 case MSM_ROTATOR_IOCTL_FINISH:
1296 return msm_rotator_finish(arg);
1297
1298 default:
1299 dev_dbg(msm_rotator_dev->device,
1300 "unexpected IOCTL %d\n", cmd);
1301 return -ENOTTY;
1302 }
1303}
1304
1305static const struct file_operations msm_rotator_fops = {
1306 .owner = THIS_MODULE,
1307 .open = msm_rotator_open,
1308 .release = msm_rotator_close,
1309 .unlocked_ioctl = msm_rotator_ioctl,
1310};
1311
1312static int __devinit msm_rotator_probe(struct platform_device *pdev)
1313{
1314 int rc = 0;
1315 struct resource *res;
1316 struct msm_rotator_platform_data *pdata = NULL;
1317 int i, number_of_clks;
1318 uint32_t ver;
1319
1320 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1321 if (!msm_rotator_dev) {
1322 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1323 __func__);
1324 return -ENOMEM;
1325 }
1326 for (i = 0; i < MAX_SESSIONS; i++)
1327 msm_rotator_dev->img_info[i] = NULL;
1328 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1329
1330 pdata = pdev->dev.platform_data;
1331 number_of_clks = pdata->number_of_clocks;
1332
1333 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1334 mutex_init(&msm_rotator_dev->imem_lock);
1335 msm_rotator_dev->imem_clk_state = CLK_DIS;
1336 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1337 msm_rotator_imem_clk_work_f);
1338 msm_rotator_dev->imem_clk = NULL;
1339 msm_rotator_dev->pdev = pdev;
1340
1341 msm_rotator_dev->core_clk = NULL;
1342 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001343
1344 for (i = 0; i < number_of_clks; i++) {
1345 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1346 msm_rotator_dev->imem_clk =
1347 clk_get(&msm_rotator_dev->pdev->dev,
1348 pdata->rotator_clks[i].clk_name);
1349 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1350 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1351 msm_rotator_dev->imem_clk = NULL;
1352 printk(KERN_ERR "%s: cannot get imem_clk "
1353 "rc=%d\n", DRIVER_NAME, rc);
1354 goto error_imem_clk;
1355 }
1356 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001357 clk_set_rate(msm_rotator_dev->imem_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001358 pdata->rotator_clks[i].clk_rate);
1359 }
1360 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1361 msm_rotator_dev->pclk =
1362 clk_get(&msm_rotator_dev->pdev->dev,
1363 pdata->rotator_clks[i].clk_name);
1364 if (IS_ERR(msm_rotator_dev->pclk)) {
1365 rc = PTR_ERR(msm_rotator_dev->pclk);
1366 msm_rotator_dev->pclk = NULL;
1367 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1368 DRIVER_NAME, rc);
1369 goto error_pclk;
1370 }
1371
1372 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001373 clk_set_rate(msm_rotator_dev->pclk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001374 pdata->rotator_clks[i].clk_rate);
1375 }
1376
1377 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1378 msm_rotator_dev->core_clk =
1379 clk_get(&msm_rotator_dev->pdev->dev,
1380 pdata->rotator_clks[i].clk_name);
1381 if (IS_ERR(msm_rotator_dev->core_clk)) {
1382 rc = PTR_ERR(msm_rotator_dev->core_clk);
1383 msm_rotator_dev->core_clk = NULL;
1384 printk(KERN_ERR "%s: cannot get core clk "
1385 "rc=%d\n", DRIVER_NAME, rc);
1386 goto error_core_clk;
1387 }
1388
1389 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001390 clk_set_rate(msm_rotator_dev->core_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001391 pdata->rotator_clks[i].clk_rate);
1392 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001393 }
1394
1395 msm_rotator_dev->regulator = regulator_get(NULL, pdata->regulator_name);
1396 if (IS_ERR(msm_rotator_dev->regulator))
1397 msm_rotator_dev->regulator = NULL;
1398
1399 msm_rotator_dev->rot_clk_state = CLK_DIS;
1400 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1401 msm_rotator_rot_clk_work_f);
1402
1403 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001404#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1405 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1406#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001407 platform_set_drvdata(pdev, msm_rotator_dev);
1408
1409
1410 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1411 if (!res) {
1412 printk(KERN_ALERT
1413 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1414 rc = -ENODEV;
1415 goto error_get_resource;
1416 }
1417 msm_rotator_dev->io_base = ioremap(res->start,
1418 resource_size(res));
1419
1420#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1421 if (msm_rotator_dev->imem_clk)
1422 clk_enable(msm_rotator_dev->imem_clk);
1423#endif
1424 enable_rot_clks();
1425 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1426 disable_rot_clks();
1427
1428#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1429 if (msm_rotator_dev->imem_clk)
1430 clk_disable(msm_rotator_dev->imem_clk);
1431#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001432 if (ver != pdata->hardware_version_number)
Nagamalleswararao Ganjibcdea002011-09-13 15:43:47 -07001433 pr_info("%s: invalid HW version\n", DRIVER_NAME);
Naseer Ahmed18018602011-10-25 13:32:58 -07001434
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001435 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1436 if (msm_rotator_dev->irq < 0) {
1437 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1438 DRIVER_NAME);
1439 rc = -ENODEV;
1440 goto error_get_irq;
1441 }
1442 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1443 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1444 if (rc) {
1445 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1446 goto error_get_irq;
1447 }
1448 /* we enable the IRQ when we need it in the ioctl */
1449 disable_irq(msm_rotator_dev->irq);
1450
1451 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1452 if (rc < 0) {
1453 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1454 __func__, rc);
1455 goto error_get_irq;
1456 }
1457
1458 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1459 if (IS_ERR(msm_rotator_dev->class)) {
1460 rc = PTR_ERR(msm_rotator_dev->class);
1461 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1462 DRIVER_NAME, rc);
1463 goto error_class_create;
1464 }
1465
1466 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1467 msm_rotator_dev->dev_num, NULL,
1468 DRIVER_NAME);
1469 if (IS_ERR(msm_rotator_dev->device)) {
1470 rc = PTR_ERR(msm_rotator_dev->device);
1471 printk(KERN_ERR "%s: device_create failed %d\n",
1472 DRIVER_NAME, rc);
1473 goto error_class_device_create;
1474 }
1475
1476 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1477 rc = cdev_add(&msm_rotator_dev->cdev,
1478 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1479 1);
1480 if (rc < 0) {
1481 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1482 goto error_cdev_add;
1483 }
1484
1485 init_waitqueue_head(&msm_rotator_dev->wq);
1486
1487 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1488 return rc;
1489
1490error_cdev_add:
1491 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1492error_class_device_create:
1493 class_destroy(msm_rotator_dev->class);
1494error_class_create:
1495 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1496error_get_irq:
1497 iounmap(msm_rotator_dev->io_base);
1498error_get_resource:
1499 mutex_destroy(&msm_rotator_dev->rotator_lock);
1500 if (msm_rotator_dev->regulator)
1501 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001502 clk_put(msm_rotator_dev->core_clk);
1503error_core_clk:
1504 clk_put(msm_rotator_dev->pclk);
1505error_pclk:
1506 if (msm_rotator_dev->imem_clk)
1507 clk_put(msm_rotator_dev->imem_clk);
1508error_imem_clk:
1509 mutex_destroy(&msm_rotator_dev->imem_lock);
1510 kfree(msm_rotator_dev);
1511 return rc;
1512}
1513
1514static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1515{
1516 int i;
1517
1518 free_irq(msm_rotator_dev->irq, NULL);
1519 mutex_destroy(&msm_rotator_dev->rotator_lock);
1520 cdev_del(&msm_rotator_dev->cdev);
1521 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1522 class_destroy(msm_rotator_dev->class);
1523 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1524 iounmap(msm_rotator_dev->io_base);
1525 if (msm_rotator_dev->imem_clk) {
1526 if (msm_rotator_dev->imem_clk_state == CLK_EN)
1527 clk_disable(msm_rotator_dev->imem_clk);
1528 clk_put(msm_rotator_dev->imem_clk);
1529 msm_rotator_dev->imem_clk = NULL;
1530 }
1531 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1532 disable_rot_clks();
1533 clk_put(msm_rotator_dev->core_clk);
1534 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001535 if (msm_rotator_dev->regulator)
1536 regulator_put(msm_rotator_dev->regulator);
1537 msm_rotator_dev->core_clk = NULL;
1538 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001539 mutex_destroy(&msm_rotator_dev->imem_lock);
1540 for (i = 0; i < MAX_SESSIONS; i++)
1541 if (msm_rotator_dev->img_info[i] != NULL)
1542 kfree(msm_rotator_dev->img_info[i]);
1543 kfree(msm_rotator_dev);
1544 return 0;
1545}
1546
1547#ifdef CONFIG_PM
1548static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1549{
1550 mutex_lock(&msm_rotator_dev->imem_lock);
1551 if (msm_rotator_dev->imem_clk_state == CLK_EN
1552 && msm_rotator_dev->imem_clk) {
1553 clk_disable(msm_rotator_dev->imem_clk);
1554 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1555 }
1556 mutex_unlock(&msm_rotator_dev->imem_lock);
1557 mutex_lock(&msm_rotator_dev->rotator_lock);
1558 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1559 disable_rot_clks();
1560 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1561 }
1562 mutex_unlock(&msm_rotator_dev->rotator_lock);
1563 return 0;
1564}
1565
1566static int msm_rotator_resume(struct platform_device *dev)
1567{
1568 mutex_lock(&msm_rotator_dev->imem_lock);
1569 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1570 && msm_rotator_dev->imem_clk) {
1571 clk_enable(msm_rotator_dev->imem_clk);
1572 msm_rotator_dev->imem_clk_state = CLK_EN;
1573 }
1574 mutex_unlock(&msm_rotator_dev->imem_lock);
1575 mutex_lock(&msm_rotator_dev->rotator_lock);
1576 if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND) {
1577 enable_rot_clks();
1578 msm_rotator_dev->rot_clk_state = CLK_EN;
1579 }
1580 mutex_unlock(&msm_rotator_dev->rotator_lock);
1581 return 0;
1582}
1583#endif
1584
1585static struct platform_driver msm_rotator_platform_driver = {
1586 .probe = msm_rotator_probe,
1587 .remove = __devexit_p(msm_rotator_remove),
1588#ifdef CONFIG_PM
1589 .suspend = msm_rotator_suspend,
1590 .resume = msm_rotator_resume,
1591#endif
1592 .driver = {
1593 .owner = THIS_MODULE,
1594 .name = DRIVER_NAME
1595 }
1596};
1597
1598static int __init msm_rotator_init(void)
1599{
1600 return platform_driver_register(&msm_rotator_platform_driver);
1601}
1602
1603static void __exit msm_rotator_exit(void)
1604{
1605 return platform_driver_unregister(&msm_rotator_platform_driver);
1606}
1607
1608module_init(msm_rotator_init);
1609module_exit(msm_rotator_exit);
1610
1611MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1612MODULE_VERSION("1.0");
1613MODULE_LICENSE("GPL v2");