blob: bd4892535226f3f9adab2ba408b2808d3da42dcf [file] [log] [blame]
Adrian Salido-Moreno19caf152012-01-03 18:46:25 -08001/* Copyright (c) 2009-2012, 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>
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -080032#ifdef CONFIG_MSM_BUS_SCALING
33#include <mach/msm_bus.h>
34#include <mach/msm_bus_board.h>
35#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036
37#define DRIVER_NAME "msm_rotator"
38
39#define MSM_ROTATOR_BASE (msm_rotator_dev->io_base)
40#define MSM_ROTATOR_INTR_ENABLE (MSM_ROTATOR_BASE+0x0020)
41#define MSM_ROTATOR_INTR_STATUS (MSM_ROTATOR_BASE+0x0024)
42#define MSM_ROTATOR_INTR_CLEAR (MSM_ROTATOR_BASE+0x0028)
43#define MSM_ROTATOR_START (MSM_ROTATOR_BASE+0x0030)
44#define MSM_ROTATOR_MAX_BURST_SIZE (MSM_ROTATOR_BASE+0x0050)
45#define MSM_ROTATOR_HW_VERSION (MSM_ROTATOR_BASE+0x0070)
46#define MSM_ROTATOR_SRC_SIZE (MSM_ROTATOR_BASE+0x1108)
47#define MSM_ROTATOR_SRCP0_ADDR (MSM_ROTATOR_BASE+0x110c)
48#define MSM_ROTATOR_SRCP1_ADDR (MSM_ROTATOR_BASE+0x1110)
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -070049#define MSM_ROTATOR_SRCP2_ADDR (MSM_ROTATOR_BASE+0x1114)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050#define MSM_ROTATOR_SRC_YSTRIDE1 (MSM_ROTATOR_BASE+0x111c)
51#define MSM_ROTATOR_SRC_YSTRIDE2 (MSM_ROTATOR_BASE+0x1120)
52#define MSM_ROTATOR_SRC_FORMAT (MSM_ROTATOR_BASE+0x1124)
53#define MSM_ROTATOR_SRC_UNPACK_PATTERN1 (MSM_ROTATOR_BASE+0x1128)
54#define MSM_ROTATOR_SUB_BLOCK_CFG (MSM_ROTATOR_BASE+0x1138)
55#define MSM_ROTATOR_OUT_PACK_PATTERN1 (MSM_ROTATOR_BASE+0x1154)
56#define MSM_ROTATOR_OUTP0_ADDR (MSM_ROTATOR_BASE+0x1168)
57#define MSM_ROTATOR_OUTP1_ADDR (MSM_ROTATOR_BASE+0x116c)
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -070058#define MSM_ROTATOR_OUTP2_ADDR (MSM_ROTATOR_BASE+0x1170)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059#define MSM_ROTATOR_OUT_YSTRIDE1 (MSM_ROTATOR_BASE+0x1178)
60#define MSM_ROTATOR_OUT_YSTRIDE2 (MSM_ROTATOR_BASE+0x117c)
61#define MSM_ROTATOR_SRC_XY (MSM_ROTATOR_BASE+0x1200)
62#define MSM_ROTATOR_SRC_IMAGE_SIZE (MSM_ROTATOR_BASE+0x1208)
63
64#define MSM_ROTATOR_MAX_ROT 0x07
65#define MSM_ROTATOR_MAX_H 0x1fff
66#define MSM_ROTATOR_MAX_W 0x1fff
67
68/* from lsb to msb */
69#define GET_PACK_PATTERN(a, x, y, z, bit) \
70 (((a)<<((bit)*3))|((x)<<((bit)*2))|((y)<<(bit))|(z))
71#define CLR_G 0x0
72#define CLR_B 0x1
73#define CLR_R 0x2
74#define CLR_ALPHA 0x3
75
76#define CLR_Y CLR_G
77#define CLR_CB CLR_B
78#define CLR_CR CLR_R
79
80#define ROTATIONS_TO_BITMASK(r) ((((r) & MDP_ROT_90) ? 1 : 0) | \
81 (((r) & MDP_FLIP_LR) ? 2 : 0) | \
82 (((r) & MDP_FLIP_UD) ? 4 : 0))
83
84#define IMEM_NO_OWNER -1;
85
86#define MAX_SESSIONS 16
87#define INVALID_SESSION -1
88#define VERSION_KEY_MASK 0xFFFFFF00
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -070089#define MAX_DOWNSCALE_RATIO 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090
91struct tile_parm {
92 unsigned int width; /* tile's width */
93 unsigned int height; /* tile's height */
94 unsigned int row_tile_w; /* tiles per row's width */
95 unsigned int row_tile_h; /* tiles per row's height */
96};
97
Adrian Salido-Moreno88411862011-09-20 18:54:03 -070098struct msm_rotator_mem_planes {
99 unsigned int num_planes;
100 unsigned int plane_size[4];
101 unsigned int total_size;
102};
103
104#define checkoffset(offset, size, max_size) \
105 ((size) > (max_size) || (offset) > ((max_size) - (size)))
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct msm_rotator_dev {
108 void __iomem *io_base;
109 int irq;
110 struct msm_rotator_img_info *img_info[MAX_SESSIONS];
111 struct clk *core_clk;
112 int pid_list[MAX_SESSIONS];
113 struct clk *pclk;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114 int rot_clk_state;
115 struct regulator *regulator;
116 struct delayed_work rot_clk_work;
117 struct clk *imem_clk;
118 int imem_clk_state;
119 struct delayed_work imem_clk_work;
120 struct platform_device *pdev;
121 struct cdev cdev;
122 struct device *device;
123 struct class *class;
124 dev_t dev_num;
125 int processing;
126 int last_session_idx;
127 struct mutex rotator_lock;
128 struct mutex imem_lock;
129 int imem_owner;
130 wait_queue_head_t wq;
Naseer Ahmed18018602011-10-25 13:32:58 -0700131 struct ion_client *client;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -0800132 #ifdef CONFIG_MSM_BUS_SCALING
133 uint32_t bus_client_handle;
134 #endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135};
136
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137#define COMPONENT_5BITS 1
138#define COMPONENT_6BITS 2
139#define COMPONENT_8BITS 3
140
141static struct msm_rotator_dev *msm_rotator_dev;
142
143enum {
144 CLK_EN,
145 CLK_DIS,
146 CLK_SUSPEND,
147};
148
149int msm_rotator_imem_allocate(int requestor)
150{
151 int rc = 0;
152
153#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
154 switch (requestor) {
155 case ROTATOR_REQUEST:
156 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
157 msm_rotator_dev->imem_owner = ROTATOR_REQUEST;
158 rc = 1;
159 } else
160 rc = 0;
161 break;
162 case JPEG_REQUEST:
163 mutex_lock(&msm_rotator_dev->imem_lock);
164 msm_rotator_dev->imem_owner = JPEG_REQUEST;
165 rc = 1;
166 break;
167 default:
168 rc = 0;
169 }
170#else
171 if (requestor == JPEG_REQUEST)
172 rc = 1;
173#endif
174 if (rc == 1) {
175 cancel_delayed_work(&msm_rotator_dev->imem_clk_work);
176 if (msm_rotator_dev->imem_clk_state != CLK_EN
177 && msm_rotator_dev->imem_clk) {
178 clk_enable(msm_rotator_dev->imem_clk);
179 msm_rotator_dev->imem_clk_state = CLK_EN;
180 }
181 }
182
183 return rc;
184}
185EXPORT_SYMBOL(msm_rotator_imem_allocate);
186
187void msm_rotator_imem_free(int requestor)
188{
189#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
190 if (msm_rotator_dev->imem_owner == requestor) {
191 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
192 mutex_unlock(&msm_rotator_dev->imem_lock);
193 }
194#else
195 if (requestor == JPEG_REQUEST)
196 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
197#endif
198}
199EXPORT_SYMBOL(msm_rotator_imem_free);
200
201static void msm_rotator_imem_clk_work_f(struct work_struct *work)
202{
203#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
204 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
205 if (msm_rotator_dev->imem_clk_state == CLK_EN
206 && msm_rotator_dev->imem_clk) {
207 clk_disable(msm_rotator_dev->imem_clk);
208 msm_rotator_dev->imem_clk_state = CLK_DIS;
209 } else if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND)
210 msm_rotator_dev->imem_clk_state = CLK_DIS;
211 mutex_unlock(&msm_rotator_dev->imem_lock);
212 }
213#endif
214}
215
216/* enable clocks needed by rotator block */
217static void enable_rot_clks(void)
218{
219 if (msm_rotator_dev->regulator)
220 regulator_enable(msm_rotator_dev->regulator);
221 if (msm_rotator_dev->core_clk != NULL)
222 clk_enable(msm_rotator_dev->core_clk);
223 if (msm_rotator_dev->pclk != NULL)
224 clk_enable(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225}
226
227/* disable clocks needed by rotator block */
228static void disable_rot_clks(void)
229{
230 if (msm_rotator_dev->core_clk != NULL)
231 clk_disable(msm_rotator_dev->core_clk);
232 if (msm_rotator_dev->pclk != NULL)
233 clk_disable(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234 if (msm_rotator_dev->regulator)
235 regulator_disable(msm_rotator_dev->regulator);
236}
237
238static void msm_rotator_rot_clk_work_f(struct work_struct *work)
239{
240 if (mutex_trylock(&msm_rotator_dev->rotator_lock)) {
241 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
242 disable_rot_clks();
243 msm_rotator_dev->rot_clk_state = CLK_DIS;
244 } else if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND)
245 msm_rotator_dev->rot_clk_state = CLK_DIS;
246 mutex_unlock(&msm_rotator_dev->rotator_lock);
247 }
248}
249
250static irqreturn_t msm_rotator_isr(int irq, void *dev_id)
251{
252 if (msm_rotator_dev->processing) {
253 msm_rotator_dev->processing = 0;
254 wake_up(&msm_rotator_dev->wq);
255 } else
256 printk(KERN_WARNING "%s: unexpected interrupt\n", DRIVER_NAME);
257
258 return IRQ_HANDLED;
259}
260
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700261static unsigned int tile_size(unsigned int src_width,
262 unsigned int src_height,
263 const struct tile_parm *tp)
264{
265 unsigned int tile_w, tile_h;
266 unsigned int row_num_w, row_num_h;
267 tile_w = tp->width * tp->row_tile_w;
268 tile_h = tp->height * tp->row_tile_h;
269 row_num_w = (src_width + tile_w - 1) / tile_w;
270 row_num_h = (src_height + tile_h - 1) / tile_h;
271 return ((row_num_w * row_num_h * tile_w * tile_h) + 8191) & ~8191;
272}
273
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700274static int get_bpp(int format)
275{
276 switch (format) {
277 case MDP_RGB_565:
278 case MDP_BGR_565:
279 return 2;
280
281 case MDP_XRGB_8888:
282 case MDP_ARGB_8888:
283 case MDP_RGBA_8888:
284 case MDP_BGRA_8888:
285 case MDP_RGBX_8888:
286 return 4;
287
288 case MDP_Y_CBCR_H2V2:
289 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700290 case MDP_Y_CB_CR_H2V2:
291 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530292 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 case MDP_Y_CRCB_H2V2_TILE:
294 case MDP_Y_CBCR_H2V2_TILE:
295 return 1;
296
297 case MDP_RGB_888:
298 return 3;
299
300 case MDP_YCRYCB_H2V1:
301 return 2;/* YCrYCb interleave */
302
303 case MDP_Y_CRCB_H2V1:
304 case MDP_Y_CBCR_H2V1:
305 return 1;
306
307 default:
308 return -1;
309 }
310
311}
312
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700313static int msm_rotator_get_plane_sizes(uint32_t format, uint32_t w, uint32_t h,
314 struct msm_rotator_mem_planes *p)
315{
316 /*
317 * each row of samsung tile consists of two tiles in height
318 * and two tiles in width which means width should align to
319 * 64 x 2 bytes and height should align to 32 x 2 bytes.
320 * video decoder generate two tiles in width and one tile
321 * in height which ends up height align to 32 X 1 bytes.
322 */
323 const struct tile_parm tile = {64, 32, 2, 1};
324 int i;
325
326 if (p == NULL)
327 return -EINVAL;
328
329 if ((w > MSM_ROTATOR_MAX_W) || (h > MSM_ROTATOR_MAX_H))
330 return -ERANGE;
331
332 memset(p, 0, sizeof(*p));
333
334 switch (format) {
335 case MDP_XRGB_8888:
336 case MDP_ARGB_8888:
337 case MDP_RGBA_8888:
338 case MDP_BGRA_8888:
339 case MDP_RGBX_8888:
340 case MDP_RGB_888:
341 case MDP_RGB_565:
342 case MDP_BGR_565:
343 case MDP_YCRYCB_H2V1:
344 p->num_planes = 1;
345 p->plane_size[0] = w * h * get_bpp(format);
346 break;
347 case MDP_Y_CRCB_H2V1:
348 case MDP_Y_CBCR_H2V1:
349 p->num_planes = 2;
350 p->plane_size[0] = w * h;
351 p->plane_size[1] = w * h;
352 break;
353 case MDP_Y_CBCR_H2V2:
354 case MDP_Y_CRCB_H2V2:
355 p->num_planes = 2;
356 p->plane_size[0] = w * h;
357 p->plane_size[1] = w * h / 2;
358 break;
359 case MDP_Y_CRCB_H2V2_TILE:
360 case MDP_Y_CBCR_H2V2_TILE:
361 p->num_planes = 2;
362 p->plane_size[0] = tile_size(w, h, &tile);
363 p->plane_size[1] = tile_size(w, h/2, &tile);
364 break;
365 case MDP_Y_CB_CR_H2V2:
366 case MDP_Y_CR_CB_H2V2:
367 p->num_planes = 3;
368 p->plane_size[0] = w * h;
369 p->plane_size[1] = (w / 2) * (h / 2);
370 p->plane_size[2] = (w / 2) * (h / 2);
371 break;
372 case MDP_Y_CR_CB_GH2V2:
373 p->num_planes = 3;
374 p->plane_size[0] = ALIGN(w, 16) * h;
375 p->plane_size[1] = ALIGN(w / 2, 16) * (h / 2);
376 p->plane_size[2] = ALIGN(w / 2, 16) * (h / 2);
377 break;
378 default:
379 return -EINVAL;
380 }
381
382 for (i = 0; i < p->num_planes; i++)
383 p->total_size += p->plane_size[i];
384
385 return 0;
386}
387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700388static int msm_rotator_ycxcx_h2v1(struct msm_rotator_img_info *info,
389 unsigned int in_paddr,
390 unsigned int out_paddr,
391 unsigned int use_imem,
392 int new_session,
393 unsigned int in_chroma_paddr,
394 unsigned int out_chroma_paddr)
395{
396 int bpp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700397
398 if (info->src.format != info->dst.format)
399 return -EINVAL;
400
401 bpp = get_bpp(info->src.format);
402 if (bpp < 0)
403 return -ENOTTY;
404
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700405 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700406 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700407 iowrite32(out_paddr +
408 ((info->dst_y * info->dst.width) + info->dst_x),
409 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700410 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700411 ((info->dst_y * info->dst.width) + info->dst_x),
412 MSM_ROTATOR_OUTP1_ADDR);
413
414 if (new_session) {
415 iowrite32(info->src.width |
416 info->src.width << 16,
417 MSM_ROTATOR_SRC_YSTRIDE1);
418 if (info->rotations & MDP_ROT_90)
419 iowrite32(info->dst.width |
420 info->dst.width*2 << 16,
421 MSM_ROTATOR_OUT_YSTRIDE1);
422 else
423 iowrite32(info->dst.width |
424 info->dst.width << 16,
425 MSM_ROTATOR_OUT_YSTRIDE1);
426 if (info->src.format == MDP_Y_CBCR_H2V1) {
427 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
428 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
429 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
430 MSM_ROTATOR_OUT_PACK_PATTERN1);
431 } else {
432 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
433 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
434 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
435 MSM_ROTATOR_OUT_PACK_PATTERN1);
436 }
437 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
438 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700439 1 << 8 | /* ROT_EN */
440 info->downscale_ratio << 2 | /* downscale v ratio */
441 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700442 MSM_ROTATOR_SUB_BLOCK_CFG);
443 iowrite32(0 << 29 | /* frame format 0 = linear */
444 (use_imem ? 0 : 1) << 22 | /* tile size */
445 2 << 19 | /* fetch planes 2 = pseudo */
446 0 << 18 | /* unpack align */
447 1 << 17 | /* unpack tight */
448 1 << 13 | /* unpack count 0=1 component */
449 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
450 0 << 8 | /* has alpha */
451 0 << 6 | /* alpha bits 3=8bits */
452 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
453 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
454 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
455 MSM_ROTATOR_SRC_FORMAT);
456 }
457
458 return 0;
459}
460
461static int msm_rotator_ycxcx_h2v2(struct msm_rotator_img_info *info,
462 unsigned int in_paddr,
463 unsigned int out_paddr,
464 unsigned int use_imem,
465 int new_session,
466 unsigned int in_chroma_paddr,
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700467 unsigned int out_chroma_paddr,
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700468 unsigned int in_chroma2_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700469{
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700470 uint32_t dst_format;
471 int is_tile = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700473 switch (info->src.format) {
474 case MDP_Y_CRCB_H2V2_TILE:
475 is_tile = 1;
476 case MDP_Y_CR_CB_H2V2:
477 case MDP_Y_CR_CB_GH2V2:
478 case MDP_Y_CRCB_H2V2:
479 dst_format = MDP_Y_CRCB_H2V2;
480 break;
481 case MDP_Y_CBCR_H2V2_TILE:
482 is_tile = 1;
483 case MDP_Y_CB_CR_H2V2:
484 case MDP_Y_CBCR_H2V2:
485 dst_format = MDP_Y_CBCR_H2V2;
486 break;
487 default:
488 return -EINVAL;
489 }
490 if (info->dst.format != dst_format)
491 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700492
Adrian Salido-Moreno19caf152012-01-03 18:46:25 -0800493 /* rotator expects YCbCr for planar input format */
494 if (info->src.format == MDP_Y_CR_CB_H2V2 ||
495 info->src.format == MDP_Y_CR_CB_GH2V2)
496 swap(in_chroma_paddr, in_chroma2_paddr);
497
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700498 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700499 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
500 iowrite32(in_chroma2_paddr, MSM_ROTATOR_SRCP2_ADDR);
501
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700502 iowrite32(out_paddr +
503 ((info->dst_y * info->dst.width) + info->dst_x),
504 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700505 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700506 ((info->dst_y * info->dst.width)/2 + info->dst_x),
507 MSM_ROTATOR_OUTP1_ADDR);
508
509 if (new_session) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700510 if (in_chroma2_paddr) {
511 if (info->src.format == MDP_Y_CR_CB_GH2V2) {
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530512 iowrite32(ALIGN(info->src.width, 16) |
513 ALIGN((info->src.width / 2), 16) << 16,
514 MSM_ROTATOR_SRC_YSTRIDE1);
515 iowrite32(ALIGN((info->src.width / 2), 16),
516 MSM_ROTATOR_SRC_YSTRIDE2);
517 } else {
518 iowrite32(info->src.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700519 (info->src.width / 2) << 16,
520 MSM_ROTATOR_SRC_YSTRIDE1);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530521 iowrite32((info->src.width / 2),
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700522 MSM_ROTATOR_SRC_YSTRIDE2);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530523 }
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700524 } else {
525 iowrite32(info->src.width |
526 info->src.width << 16,
527 MSM_ROTATOR_SRC_YSTRIDE1);
528 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700529 iowrite32(info->dst.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700530 info->dst.width << 16,
531 MSM_ROTATOR_OUT_YSTRIDE1);
532
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700533 if (dst_format == MDP_Y_CBCR_H2V2) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700534 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
535 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
536 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
537 MSM_ROTATOR_OUT_PACK_PATTERN1);
538 } else {
539 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
540 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
541 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
542 MSM_ROTATOR_OUT_PACK_PATTERN1);
543 }
544 iowrite32((3 << 18) | /* chroma sampling 3=4:2:0 */
545 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700546 1 << 8 | /* ROT_EN */
547 info->downscale_ratio << 2 | /* downscale v ratio */
548 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700549 MSM_ROTATOR_SUB_BLOCK_CFG);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700550
551 iowrite32((is_tile ? 2 : 0) << 29 | /* frame format */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700552 (use_imem ? 0 : 1) << 22 | /* tile size */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700553 (in_chroma2_paddr ? 1 : 2) << 19 | /* fetch planes */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700554 0 << 18 | /* unpack align */
555 1 << 17 | /* unpack tight */
556 1 << 13 | /* unpack count 0=1 component */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700557 0 << 9 | /* src Bpp 0=1 byte ... */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700558 0 << 8 | /* has alpha */
559 0 << 6 | /* alpha bits 3=8bits */
560 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
561 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
562 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
563 MSM_ROTATOR_SRC_FORMAT);
564 }
565 return 0;
566}
567
568static int msm_rotator_ycrycb(struct msm_rotator_img_info *info,
569 unsigned int in_paddr,
570 unsigned int out_paddr,
571 unsigned int use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +0530572 int new_session,
573 unsigned int out_chroma_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574{
575 int bpp;
Mayank Chopra732dcd62012-01-09 20:53:39 +0530576 uint32_t dst_format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700577
Mayank Chopra732dcd62012-01-09 20:53:39 +0530578 if (info->src.format == MDP_YCRYCB_H2V1)
579 dst_format = MDP_Y_CRCB_H2V1;
580 else
581 return -EINVAL;
582
583 if (info->dst.format != dst_format)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700584 return -EINVAL;
585
586 bpp = get_bpp(info->src.format);
587 if (bpp < 0)
588 return -ENOTTY;
589
590 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
591 iowrite32(out_paddr +
592 ((info->dst_y * info->dst.width) + info->dst_x),
593 MSM_ROTATOR_OUTP0_ADDR);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530594 iowrite32(out_chroma_paddr +
595 ((info->dst_y * info->dst.width)/2 + info->dst_x),
596 MSM_ROTATOR_OUTP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700597
598 if (new_session) {
Mayank Chopra732dcd62012-01-09 20:53:39 +0530599 iowrite32(info->src.width * bpp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700600 MSM_ROTATOR_SRC_YSTRIDE1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530601 if (info->rotations & MDP_ROT_90)
602 iowrite32(info->dst.width |
603 (info->dst.width*2) << 16,
604 MSM_ROTATOR_OUT_YSTRIDE1);
605 else
606 iowrite32(info->dst.width |
607 (info->dst.width) << 16,
608 MSM_ROTATOR_OUT_YSTRIDE1);
609
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
611 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530612 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700613 MSM_ROTATOR_OUT_PACK_PATTERN1);
614 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
615 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700616 1 << 8 | /* ROT_EN */
617 info->downscale_ratio << 2 | /* downscale v ratio */
618 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700619 MSM_ROTATOR_SUB_BLOCK_CFG);
620 iowrite32(0 << 29 | /* frame format 0 = linear */
621 (use_imem ? 0 : 1) << 22 | /* tile size */
622 0 << 19 | /* fetch planes 0=interleaved */
623 0 << 18 | /* unpack align */
624 1 << 17 | /* unpack tight */
625 3 << 13 | /* unpack count 0=1 component */
626 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
627 0 << 8 | /* has alpha */
628 0 << 6 | /* alpha bits 3=8bits */
629 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
630 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
631 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
632 MSM_ROTATOR_SRC_FORMAT);
633 }
634
635 return 0;
636}
637
638static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
639 unsigned int in_paddr,
640 unsigned int out_paddr,
641 unsigned int use_imem,
642 int new_session)
643{
644 int bpp, abits, rbits, gbits, bbits;
645
646 if (info->src.format != info->dst.format)
647 return -EINVAL;
648
649 bpp = get_bpp(info->src.format);
650 if (bpp < 0)
651 return -ENOTTY;
652
653 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
654 iowrite32(out_paddr +
655 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
656 MSM_ROTATOR_OUTP0_ADDR);
657
658 if (new_session) {
659 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
660 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
661 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
662 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700663 1 << 8 | /* ROT_EN */
664 info->downscale_ratio << 2 | /* downscale v ratio */
665 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700666 MSM_ROTATOR_SUB_BLOCK_CFG);
667 switch (info->src.format) {
668 case MDP_RGB_565:
669 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
670 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
671 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
672 MSM_ROTATOR_OUT_PACK_PATTERN1);
673 abits = 0;
674 rbits = COMPONENT_5BITS;
675 gbits = COMPONENT_6BITS;
676 bbits = COMPONENT_5BITS;
677 break;
678
679 case MDP_BGR_565:
680 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
681 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
682 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
683 MSM_ROTATOR_OUT_PACK_PATTERN1);
684 abits = 0;
685 rbits = COMPONENT_5BITS;
686 gbits = COMPONENT_6BITS;
687 bbits = COMPONENT_5BITS;
688 break;
689
690 case MDP_RGB_888:
691 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
692 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
693 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
694 MSM_ROTATOR_OUT_PACK_PATTERN1);
695 abits = 0;
696 rbits = COMPONENT_8BITS;
697 gbits = COMPONENT_8BITS;
698 bbits = COMPONENT_8BITS;
699 break;
700
701 case MDP_ARGB_8888:
702 case MDP_RGBA_8888:
703 case MDP_XRGB_8888:
704 case MDP_RGBX_8888:
705 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
706 CLR_B, 8),
707 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
708 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
709 CLR_B, 8),
710 MSM_ROTATOR_OUT_PACK_PATTERN1);
711 abits = COMPONENT_8BITS;
712 rbits = COMPONENT_8BITS;
713 gbits = COMPONENT_8BITS;
714 bbits = COMPONENT_8BITS;
715 break;
716
717 case MDP_BGRA_8888:
718 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
719 CLR_R, 8),
720 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
721 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
722 CLR_R, 8),
723 MSM_ROTATOR_OUT_PACK_PATTERN1);
724 abits = COMPONENT_8BITS;
725 rbits = COMPONENT_8BITS;
726 gbits = COMPONENT_8BITS;
727 bbits = COMPONENT_8BITS;
728 break;
729
730 default:
731 return -EINVAL;
732 }
733 iowrite32(0 << 29 | /* frame format 0 = linear */
734 (use_imem ? 0 : 1) << 22 | /* tile size */
735 0 << 19 | /* fetch planes 0=interleaved */
736 0 << 18 | /* unpack align */
737 1 << 17 | /* unpack tight */
738 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
739 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
740 (abits ? 1 : 0) << 8 | /* has alpha */
741 abits << 6 | /* alpha bits 3=8bits */
742 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
743 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
744 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
745 MSM_ROTATOR_SRC_FORMAT);
746 }
747
748 return 0;
749}
750
Naseer Ahmed18018602011-10-25 13:32:58 -0700751static int get_img(struct msmfb_data *fbd, unsigned long *start,
752 unsigned long *len, struct file **p_file, struct ion_handle **p_ihdl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700753{
754 int ret = 0;
755#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700756 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757 int put_needed, fb_num;
758#endif
759#ifdef CONFIG_ANDROID_PMEM
760 unsigned long vstart;
761#endif
762
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700763#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700764 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
765 file = fget_light(fbd->memory_id, &put_needed);
766 if (file == NULL)
767 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768
Naseer Ahmed18018602011-10-25 13:32:58 -0700769 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
770 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
771 if (get_fb_phys_info(start, len, fb_num))
772 ret = -1;
773 else
774 *p_file = file;
775 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700776 ret = -1;
Naseer Ahmed18018602011-10-25 13:32:58 -0700777 if (ret)
778 fput_light(file, put_needed);
779 return ret;
780 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700781#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700782
783#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
784 *p_ihdl = ion_import_fd(msm_rotator_dev->client,
785 fbd->memory_id);
786 if (IS_ERR_OR_NULL(*p_ihdl))
787 return PTR_ERR(*p_ihdl);
788 if (!ion_phys(msm_rotator_dev->client, *p_ihdl, start,
789 (size_t *) len))
790 return 0;
791 else
792 return -ENOMEM;
793#endif
794#ifdef CONFIG_ANDROID_PMEM
795 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
796 return 0;
797 else
798 return -ENOMEM;
799#endif
800
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700801}
802
Naseer Ahmed18018602011-10-25 13:32:58 -0700803static void put_img(struct file *p_file, struct ion_handle *p_ihdl)
804{
805#ifdef CONFIG_ANDROID_PMEM
806 if (p_file != NULL)
807 put_pmem_file(p_file);
808#endif
809#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
810 if (!IS_ERR_OR_NULL(p_ihdl))
811 ion_free(msm_rotator_dev->client, p_ihdl);
812#endif
813}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700814static int msm_rotator_do_rotate(unsigned long arg)
815{
Naseer Ahmed18018602011-10-25 13:32:58 -0700816 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700817 struct msm_rotator_data_info info;
818 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700819 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700820 int use_imem = 0, rc = 0, s;
821 struct file *srcp0_file = NULL, *dstp0_file = NULL;
822 struct file *srcp1_file = NULL, *dstp1_file = NULL;
823 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
824 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700825 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700826 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700827 struct msm_rotator_img_info *img_info;
828 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829
830 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
831 return -EFAULT;
832
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 mutex_lock(&msm_rotator_dev->rotator_lock);
834 for (s = 0; s < MAX_SESSIONS; s++)
835 if ((msm_rotator_dev->img_info[s] != NULL) &&
836 (info.session_id ==
837 (unsigned int)msm_rotator_dev->img_info[s]
838 ))
839 break;
840
841 if (s == MAX_SESSIONS) {
842 dev_dbg(msm_rotator_dev->device,
843 "%s() : Attempt to use invalid session_id %d\n",
844 __func__, s);
845 rc = -EINVAL;
846 goto do_rotate_unlock_mutex;
847 }
848
849 if (msm_rotator_dev->img_info[s]->enable == 0) {
850 dev_dbg(msm_rotator_dev->device,
851 "%s() : Session_id %d not enabled \n",
852 __func__, s);
853 rc = -EINVAL;
854 goto do_rotate_unlock_mutex;
855 }
856
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700857 img_info = msm_rotator_dev->img_info[s];
858 if (msm_rotator_get_plane_sizes(img_info->src.format,
859 img_info->src.width,
860 img_info->src.height,
861 &src_planes)) {
862 pr_err("%s: invalid src format\n", __func__);
863 rc = -EINVAL;
864 goto do_rotate_unlock_mutex;
865 }
866 if (msm_rotator_get_plane_sizes(img_info->dst.format,
867 img_info->dst.width,
868 img_info->dst.height,
869 &dst_planes)) {
870 pr_err("%s: invalid dst format\n", __func__);
871 rc = -EINVAL;
872 goto do_rotate_unlock_mutex;
873 }
874
Naseer Ahmed18018602011-10-25 13:32:58 -0700875 rc = get_img(&info.src, (unsigned long *)&in_paddr,
876 (unsigned long *)&src_len, &srcp0_file, &srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700877 if (rc) {
878 pr_err("%s: in get_img() failed id=0x%08x\n",
879 DRIVER_NAME, info.src.memory_id);
880 goto do_rotate_unlock_mutex;
881 }
882
Naseer Ahmed18018602011-10-25 13:32:58 -0700883 rc = get_img(&info.dst, (unsigned long *)&out_paddr,
884 (unsigned long *)&dst_len, &dstp0_file, &dstp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700885 if (rc) {
886 pr_err("%s: out get_img() failed id=0x%08x\n",
887 DRIVER_NAME, info.dst.memory_id);
888 goto do_rotate_unlock_mutex;
889 }
890
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 format = msm_rotator_dev->img_info[s]->src.format;
892 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700893 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
894 (src_planes.num_planes == 2)) {
895 if (checkoffset(info.src.offset,
896 src_planes.plane_size[0],
897 src_len)) {
898 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
899 __func__, src_len, info.src.offset);
900 rc = -ERANGE;
901 goto do_rotate_unlock_mutex;
902 }
903 if (checkoffset(info.dst.offset,
904 dst_planes.plane_size[0],
905 dst_len)) {
906 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
907 __func__, dst_len, info.dst.offset);
908 rc = -ERANGE;
909 goto do_rotate_unlock_mutex;
910 }
911
Naseer Ahmed18018602011-10-25 13:32:58 -0700912 rc = get_img(&info.src_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913 (unsigned long *)&in_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700914 (unsigned long *)&src_len, &srcp1_file,
915 &srcp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700917 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700918 DRIVER_NAME, info.src_chroma.memory_id);
919 goto do_rotate_unlock_mutex;
920 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921
Naseer Ahmed18018602011-10-25 13:32:58 -0700922 rc = get_img(&info.dst_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700923 (unsigned long *)&out_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700924 (unsigned long *)&dst_len, &dstp1_file,
925 &dstp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700927 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700929 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700931
932 if (checkoffset(info.src_chroma.offset,
933 src_planes.plane_size[1],
934 src_len)) {
935 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
936 __func__, src_len, info.src_chroma.offset);
937 rc = -ERANGE;
938 goto do_rotate_unlock_mutex;
939 }
940
941 if (checkoffset(info.dst_chroma.offset,
942 src_planes.plane_size[1],
943 dst_len)) {
944 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
945 __func__, dst_len, info.dst_chroma.offset);
946 rc = -ERANGE;
947 goto do_rotate_unlock_mutex;
948 }
949
950 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700951 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700952 } else {
953 if (checkoffset(info.src.offset,
954 src_planes.total_size,
955 src_len)) {
956 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
957 __func__, src_len, info.src.offset);
958 rc = -ERANGE;
959 goto do_rotate_unlock_mutex;
960 }
961 if (checkoffset(info.dst.offset,
962 dst_planes.total_size,
963 dst_len)) {
964 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
965 __func__, dst_len, info.dst.offset);
966 rc = -ERANGE;
967 goto do_rotate_unlock_mutex;
968 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969 }
970
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700971 in_paddr += info.src.offset;
972 out_paddr += info.dst.offset;
973
974 if (!in_chroma_paddr && src_planes.num_planes >= 2)
975 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
976 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
977 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
978 if (src_planes.num_planes >= 3)
979 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
980
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700981 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
982 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
983 enable_rot_clks();
984 msm_rotator_dev->rot_clk_state = CLK_EN;
985 }
986 enable_irq(msm_rotator_dev->irq);
987
988#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
989 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
990#else
991 use_imem = 0;
992#endif
993 /*
994 * workaround for a hardware bug. rotator hardware hangs when we
995 * use write burst beat size 16 on 128X128 tile fetch mode. As a
996 * temporary fix use 0x42 for BURST_SIZE when imem used.
997 */
998 if (use_imem)
999 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
1000
1001 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
1002 << 16) |
1003 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
1004 MSM_ROTATOR_SRC_SIZE);
1005 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
1006 << 16) |
1007 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
1008 MSM_ROTATOR_SRC_XY);
1009 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
1010 << 16) |
1011 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
1012 MSM_ROTATOR_SRC_IMAGE_SIZE);
1013
1014 switch (format) {
1015 case MDP_RGB_565:
1016 case MDP_BGR_565:
1017 case MDP_RGB_888:
1018 case MDP_ARGB_8888:
1019 case MDP_RGBA_8888:
1020 case MDP_XRGB_8888:
1021 case MDP_BGRA_8888:
1022 case MDP_RGBX_8888:
1023 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
1024 in_paddr, out_paddr,
1025 use_imem,
1026 msm_rotator_dev->last_session_idx
1027 != s);
1028 break;
1029 case MDP_Y_CBCR_H2V2:
1030 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001031 case MDP_Y_CB_CR_H2V2:
1032 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301033 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001034 case MDP_Y_CRCB_H2V2_TILE:
1035 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001036 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1037 in_paddr, out_paddr, use_imem,
1038 msm_rotator_dev->last_session_idx
1039 != s,
1040 in_chroma_paddr,
1041 out_chroma_paddr,
1042 in_chroma2_paddr);
1043 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001044 case MDP_Y_CBCR_H2V1:
1045 case MDP_Y_CRCB_H2V1:
1046 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1047 in_paddr, out_paddr, use_imem,
1048 msm_rotator_dev->last_session_idx
1049 != s,
1050 in_chroma_paddr,
1051 out_chroma_paddr);
1052 break;
1053 case MDP_YCRYCB_H2V1:
1054 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1055 in_paddr, out_paddr, use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +05301056 msm_rotator_dev->last_session_idx != s,
1057 out_chroma_paddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001058 break;
1059 default:
1060 rc = -EINVAL;
1061 goto do_rotate_exit;
1062 }
1063
1064 if (rc != 0) {
1065 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1066 goto do_rotate_exit;
1067 }
1068
1069 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1070
1071 msm_rotator_dev->processing = 1;
1072 iowrite32(0x1, MSM_ROTATOR_START);
1073
1074 wait_event(msm_rotator_dev->wq,
1075 (msm_rotator_dev->processing == 0));
1076 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
1077 if ((status & 0x03) != 0x01)
1078 rc = -EFAULT;
1079 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1080 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1081
1082do_rotate_exit:
1083 disable_irq(msm_rotator_dev->irq);
1084#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1085 msm_rotator_imem_free(ROTATOR_REQUEST);
1086#endif
1087 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001088do_rotate_unlock_mutex:
Naseer Ahmed18018602011-10-25 13:32:58 -07001089 put_img(dstp1_file, dstp1_ihdl);
1090 put_img(srcp1_file, srcp1_ihdl);
1091 put_img(dstp0_file, dstp0_ihdl);
1092 put_img(srcp0_file, srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001093 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001094 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1095 __func__, rc);
1096 return rc;
1097}
1098
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001099static void msm_rotator_set_perf_level(u32 wh, u32 is_rgb)
1100{
1101 u32 perf_level;
1102
1103 if (is_rgb)
1104 perf_level = 1;
1105 else if (wh <= (640 * 480))
1106 perf_level = 2;
1107 else if (wh <= (736 * 1280))
1108 perf_level = 3;
1109 else
1110 perf_level = 4;
1111
1112#ifdef CONFIG_MSM_BUS_SCALING
1113 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1114 perf_level);
1115#endif
1116
1117}
1118
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001119static int msm_rotator_start(unsigned long arg, int pid)
1120{
1121 struct msm_rotator_img_info info;
1122 int rc = 0;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001123 int s, is_rgb = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001124 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001125 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001126
1127 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1128 return -EFAULT;
1129
1130 if ((info.rotations > MSM_ROTATOR_MAX_ROT) ||
1131 (info.src.height > MSM_ROTATOR_MAX_H) ||
1132 (info.src.width > MSM_ROTATOR_MAX_W) ||
1133 (info.dst.height > MSM_ROTATOR_MAX_H) ||
1134 (info.dst.width > MSM_ROTATOR_MAX_W) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001135 (info.downscale_ratio > MAX_DOWNSCALE_RATIO)) {
1136 pr_err("%s: Invalid parameters\n", __func__);
1137 return -EINVAL;
1138 }
1139
1140 if (info.rotations & MDP_ROT_90) {
1141 dst_w = info.src_rect.h >> info.downscale_ratio;
1142 dst_h = info.src_rect.w >> info.downscale_ratio;
1143 } else {
1144 dst_w = info.src_rect.w >> info.downscale_ratio;
1145 dst_h = info.src_rect.h >> info.downscale_ratio;
1146 }
1147
1148 if (checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001149 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1150 checkoffset(info.dst_x, dst_w, info.dst.width) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001151 checkoffset(info.dst_y, dst_h, info.dst.height)) {
1152 pr_err("%s: Invalid src or dst rect\n", __func__);
1153 return -ERANGE;
1154 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001155
1156 switch (info.src.format) {
1157 case MDP_RGB_565:
1158 case MDP_BGR_565:
1159 case MDP_RGB_888:
1160 case MDP_ARGB_8888:
1161 case MDP_RGBA_8888:
1162 case MDP_XRGB_8888:
1163 case MDP_RGBX_8888:
1164 case MDP_BGRA_8888:
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001165 is_rgb = 1;
1166 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001167 case MDP_Y_CBCR_H2V2:
1168 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001169 case MDP_Y_CB_CR_H2V2:
1170 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301171 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001172 case MDP_Y_CBCR_H2V1:
1173 case MDP_Y_CRCB_H2V1:
1174 case MDP_YCRYCB_H2V1:
1175 case MDP_Y_CRCB_H2V2_TILE:
1176 case MDP_Y_CBCR_H2V2_TILE:
1177 break;
1178 default:
1179 return -EINVAL;
1180 }
1181
1182 switch (info.dst.format) {
1183 case MDP_RGB_565:
1184 case MDP_BGR_565:
1185 case MDP_RGB_888:
1186 case MDP_ARGB_8888:
1187 case MDP_RGBA_8888:
1188 case MDP_XRGB_8888:
1189 case MDP_RGBX_8888:
1190 case MDP_BGRA_8888:
1191 case MDP_Y_CBCR_H2V2:
1192 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001193 case MDP_Y_CB_CR_H2V2:
1194 case MDP_Y_CR_CB_H2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195 case MDP_Y_CBCR_H2V1:
1196 case MDP_Y_CRCB_H2V1:
1197 case MDP_YCRYCB_H2V1:
1198 break;
1199 default:
1200 return -EINVAL;
1201 }
1202
1203 mutex_lock(&msm_rotator_dev->rotator_lock);
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001204
1205 msm_rotator_set_perf_level((info.src.width*info.src.height), is_rgb);
1206
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001207 for (s = 0; s < MAX_SESSIONS; s++) {
1208 if ((msm_rotator_dev->img_info[s] != NULL) &&
1209 (info.session_id ==
1210 (unsigned int)msm_rotator_dev->img_info[s]
1211 )) {
1212 *(msm_rotator_dev->img_info[s]) = info;
1213 msm_rotator_dev->pid_list[s] = pid;
1214
1215 if (msm_rotator_dev->last_session_idx == s)
1216 msm_rotator_dev->last_session_idx =
1217 INVALID_SESSION;
1218 break;
1219 }
1220
1221 if ((msm_rotator_dev->img_info[s] == NULL) &&
1222 (first_free_index ==
1223 INVALID_SESSION))
1224 first_free_index = s;
1225 }
1226
1227 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1228 /* allocate a session id */
1229 msm_rotator_dev->img_info[first_free_index] =
1230 kzalloc(sizeof(struct msm_rotator_img_info),
1231 GFP_KERNEL);
1232 if (!msm_rotator_dev->img_info[first_free_index]) {
1233 printk(KERN_ERR "%s : unable to alloc mem\n",
1234 __func__);
1235 rc = -ENOMEM;
1236 goto rotator_start_exit;
1237 }
1238 info.session_id = (unsigned int)
1239 msm_rotator_dev->img_info[first_free_index];
1240 *(msm_rotator_dev->img_info[first_free_index]) = info;
1241 msm_rotator_dev->pid_list[first_free_index] = pid;
1242
1243 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1244 rc = -EFAULT;
1245 } else if (s == MAX_SESSIONS) {
1246 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1247 __func__);
1248 rc = -EBUSY;
1249 }
1250
1251rotator_start_exit:
1252 mutex_unlock(&msm_rotator_dev->rotator_lock);
1253
1254 return rc;
1255}
1256
1257static int msm_rotator_finish(unsigned long arg)
1258{
1259 int rc = 0;
1260 int s;
1261 unsigned int session_id;
1262
1263 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1264 return -EFAULT;
1265
1266 mutex_lock(&msm_rotator_dev->rotator_lock);
1267 for (s = 0; s < MAX_SESSIONS; s++) {
1268 if ((msm_rotator_dev->img_info[s] != NULL) &&
1269 (session_id ==
1270 (unsigned int)msm_rotator_dev->img_info[s])) {
1271 if (msm_rotator_dev->last_session_idx == s)
1272 msm_rotator_dev->last_session_idx =
1273 INVALID_SESSION;
1274 kfree(msm_rotator_dev->img_info[s]);
1275 msm_rotator_dev->img_info[s] = NULL;
1276 msm_rotator_dev->pid_list[s] = 0;
1277 break;
1278 }
1279 }
1280
1281 if (s == MAX_SESSIONS)
1282 rc = -EINVAL;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001283#ifdef CONFIG_MSM_BUS_SCALING
1284 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1285 0);
1286#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001287 mutex_unlock(&msm_rotator_dev->rotator_lock);
1288 return rc;
1289}
1290
1291static int
1292msm_rotator_open(struct inode *inode, struct file *filp)
1293{
1294 int *id;
1295 int i;
1296
1297 if (filp->private_data)
1298 return -EBUSY;
1299
1300 mutex_lock(&msm_rotator_dev->rotator_lock);
1301 id = &msm_rotator_dev->pid_list[0];
1302 for (i = 0; i < MAX_SESSIONS; i++, id++) {
1303 if (*id == 0)
1304 break;
1305 }
1306 mutex_unlock(&msm_rotator_dev->rotator_lock);
1307
1308 if (i == MAX_SESSIONS)
1309 return -EBUSY;
1310
kuogee hsieh7a46d592011-09-09 10:27:23 -07001311 filp->private_data = (void *)current->pid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001312
1313 return 0;
1314}
1315
1316static int
1317msm_rotator_close(struct inode *inode, struct file *filp)
1318{
1319 int s;
1320 int pid;
1321
1322 pid = (int)filp->private_data;
1323 mutex_lock(&msm_rotator_dev->rotator_lock);
1324 for (s = 0; s < MAX_SESSIONS; s++) {
1325 if (msm_rotator_dev->img_info[s] != NULL &&
1326 msm_rotator_dev->pid_list[s] == pid) {
1327 kfree(msm_rotator_dev->img_info[s]);
1328 msm_rotator_dev->img_info[s] = NULL;
1329 if (msm_rotator_dev->last_session_idx == s)
1330 msm_rotator_dev->last_session_idx =
1331 INVALID_SESSION;
1332 }
1333 }
1334 mutex_unlock(&msm_rotator_dev->rotator_lock);
1335
1336 return 0;
1337}
1338
1339static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1340 unsigned long arg)
1341{
1342 int pid;
1343
1344 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1345 return -ENOTTY;
1346
1347 pid = (int)file->private_data;
1348
1349 switch (cmd) {
1350 case MSM_ROTATOR_IOCTL_START:
1351 return msm_rotator_start(arg, pid);
1352 case MSM_ROTATOR_IOCTL_ROTATE:
1353 return msm_rotator_do_rotate(arg);
1354 case MSM_ROTATOR_IOCTL_FINISH:
1355 return msm_rotator_finish(arg);
1356
1357 default:
1358 dev_dbg(msm_rotator_dev->device,
1359 "unexpected IOCTL %d\n", cmd);
1360 return -ENOTTY;
1361 }
1362}
1363
1364static const struct file_operations msm_rotator_fops = {
1365 .owner = THIS_MODULE,
1366 .open = msm_rotator_open,
1367 .release = msm_rotator_close,
1368 .unlocked_ioctl = msm_rotator_ioctl,
1369};
1370
1371static int __devinit msm_rotator_probe(struct platform_device *pdev)
1372{
1373 int rc = 0;
1374 struct resource *res;
1375 struct msm_rotator_platform_data *pdata = NULL;
1376 int i, number_of_clks;
1377 uint32_t ver;
1378
1379 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1380 if (!msm_rotator_dev) {
1381 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1382 __func__);
1383 return -ENOMEM;
1384 }
1385 for (i = 0; i < MAX_SESSIONS; i++)
1386 msm_rotator_dev->img_info[i] = NULL;
1387 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1388
1389 pdata = pdev->dev.platform_data;
1390 number_of_clks = pdata->number_of_clocks;
1391
1392 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1393 mutex_init(&msm_rotator_dev->imem_lock);
1394 msm_rotator_dev->imem_clk_state = CLK_DIS;
1395 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1396 msm_rotator_imem_clk_work_f);
1397 msm_rotator_dev->imem_clk = NULL;
1398 msm_rotator_dev->pdev = pdev;
1399
1400 msm_rotator_dev->core_clk = NULL;
1401 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001402
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001403#ifdef CONFIG_MSM_BUS_SCALING
1404 if (!msm_rotator_dev->bus_client_handle && pdata &&
1405 pdata->bus_scale_table) {
1406 msm_rotator_dev->bus_client_handle =
1407 msm_bus_scale_register_client(
1408 pdata->bus_scale_table);
1409 if (!msm_rotator_dev->bus_client_handle) {
1410 pr_err("%s not able to get bus scale handle\n",
1411 __func__);
1412 }
1413 }
1414#endif
1415
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001416 for (i = 0; i < number_of_clks; i++) {
1417 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1418 msm_rotator_dev->imem_clk =
1419 clk_get(&msm_rotator_dev->pdev->dev,
1420 pdata->rotator_clks[i].clk_name);
1421 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1422 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1423 msm_rotator_dev->imem_clk = NULL;
1424 printk(KERN_ERR "%s: cannot get imem_clk "
1425 "rc=%d\n", DRIVER_NAME, rc);
1426 goto error_imem_clk;
1427 }
1428 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001429 clk_set_rate(msm_rotator_dev->imem_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001430 pdata->rotator_clks[i].clk_rate);
1431 }
1432 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1433 msm_rotator_dev->pclk =
1434 clk_get(&msm_rotator_dev->pdev->dev,
1435 pdata->rotator_clks[i].clk_name);
1436 if (IS_ERR(msm_rotator_dev->pclk)) {
1437 rc = PTR_ERR(msm_rotator_dev->pclk);
1438 msm_rotator_dev->pclk = NULL;
1439 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1440 DRIVER_NAME, rc);
1441 goto error_pclk;
1442 }
1443
1444 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001445 clk_set_rate(msm_rotator_dev->pclk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001446 pdata->rotator_clks[i].clk_rate);
1447 }
1448
1449 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1450 msm_rotator_dev->core_clk =
1451 clk_get(&msm_rotator_dev->pdev->dev,
1452 pdata->rotator_clks[i].clk_name);
1453 if (IS_ERR(msm_rotator_dev->core_clk)) {
1454 rc = PTR_ERR(msm_rotator_dev->core_clk);
1455 msm_rotator_dev->core_clk = NULL;
1456 printk(KERN_ERR "%s: cannot get core clk "
1457 "rc=%d\n", DRIVER_NAME, rc);
1458 goto error_core_clk;
1459 }
1460
1461 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001462 clk_set_rate(msm_rotator_dev->core_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001463 pdata->rotator_clks[i].clk_rate);
1464 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001465 }
1466
1467 msm_rotator_dev->regulator = regulator_get(NULL, pdata->regulator_name);
1468 if (IS_ERR(msm_rotator_dev->regulator))
1469 msm_rotator_dev->regulator = NULL;
1470
1471 msm_rotator_dev->rot_clk_state = CLK_DIS;
1472 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1473 msm_rotator_rot_clk_work_f);
1474
1475 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001476#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1477 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1478#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001479 platform_set_drvdata(pdev, msm_rotator_dev);
1480
1481
1482 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1483 if (!res) {
1484 printk(KERN_ALERT
1485 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1486 rc = -ENODEV;
1487 goto error_get_resource;
1488 }
1489 msm_rotator_dev->io_base = ioremap(res->start,
1490 resource_size(res));
1491
1492#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1493 if (msm_rotator_dev->imem_clk)
1494 clk_enable(msm_rotator_dev->imem_clk);
1495#endif
1496 enable_rot_clks();
1497 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1498 disable_rot_clks();
1499
1500#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1501 if (msm_rotator_dev->imem_clk)
1502 clk_disable(msm_rotator_dev->imem_clk);
1503#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001504 if (ver != pdata->hardware_version_number)
Nagamalleswararao Ganjibcdea002011-09-13 15:43:47 -07001505 pr_info("%s: invalid HW version\n", DRIVER_NAME);
Naseer Ahmed18018602011-10-25 13:32:58 -07001506
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001507 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1508 if (msm_rotator_dev->irq < 0) {
1509 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1510 DRIVER_NAME);
1511 rc = -ENODEV;
1512 goto error_get_irq;
1513 }
1514 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1515 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1516 if (rc) {
1517 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1518 goto error_get_irq;
1519 }
1520 /* we enable the IRQ when we need it in the ioctl */
1521 disable_irq(msm_rotator_dev->irq);
1522
1523 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1524 if (rc < 0) {
1525 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1526 __func__, rc);
1527 goto error_get_irq;
1528 }
1529
1530 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1531 if (IS_ERR(msm_rotator_dev->class)) {
1532 rc = PTR_ERR(msm_rotator_dev->class);
1533 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1534 DRIVER_NAME, rc);
1535 goto error_class_create;
1536 }
1537
1538 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1539 msm_rotator_dev->dev_num, NULL,
1540 DRIVER_NAME);
1541 if (IS_ERR(msm_rotator_dev->device)) {
1542 rc = PTR_ERR(msm_rotator_dev->device);
1543 printk(KERN_ERR "%s: device_create failed %d\n",
1544 DRIVER_NAME, rc);
1545 goto error_class_device_create;
1546 }
1547
1548 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1549 rc = cdev_add(&msm_rotator_dev->cdev,
1550 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1551 1);
1552 if (rc < 0) {
1553 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1554 goto error_cdev_add;
1555 }
1556
1557 init_waitqueue_head(&msm_rotator_dev->wq);
1558
1559 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1560 return rc;
1561
1562error_cdev_add:
1563 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1564error_class_device_create:
1565 class_destroy(msm_rotator_dev->class);
1566error_class_create:
1567 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1568error_get_irq:
1569 iounmap(msm_rotator_dev->io_base);
1570error_get_resource:
1571 mutex_destroy(&msm_rotator_dev->rotator_lock);
1572 if (msm_rotator_dev->regulator)
1573 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001574 clk_put(msm_rotator_dev->core_clk);
1575error_core_clk:
1576 clk_put(msm_rotator_dev->pclk);
1577error_pclk:
1578 if (msm_rotator_dev->imem_clk)
1579 clk_put(msm_rotator_dev->imem_clk);
1580error_imem_clk:
1581 mutex_destroy(&msm_rotator_dev->imem_lock);
1582 kfree(msm_rotator_dev);
1583 return rc;
1584}
1585
1586static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1587{
1588 int i;
1589
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001590#ifdef CONFIG_MSM_BUS_SCALING
1591 msm_bus_scale_unregister_client(msm_rotator_dev->bus_client_handle);
1592#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001593 free_irq(msm_rotator_dev->irq, NULL);
1594 mutex_destroy(&msm_rotator_dev->rotator_lock);
1595 cdev_del(&msm_rotator_dev->cdev);
1596 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1597 class_destroy(msm_rotator_dev->class);
1598 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1599 iounmap(msm_rotator_dev->io_base);
1600 if (msm_rotator_dev->imem_clk) {
1601 if (msm_rotator_dev->imem_clk_state == CLK_EN)
1602 clk_disable(msm_rotator_dev->imem_clk);
1603 clk_put(msm_rotator_dev->imem_clk);
1604 msm_rotator_dev->imem_clk = NULL;
1605 }
1606 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1607 disable_rot_clks();
1608 clk_put(msm_rotator_dev->core_clk);
1609 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001610 if (msm_rotator_dev->regulator)
1611 regulator_put(msm_rotator_dev->regulator);
1612 msm_rotator_dev->core_clk = NULL;
1613 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001614 mutex_destroy(&msm_rotator_dev->imem_lock);
1615 for (i = 0; i < MAX_SESSIONS; i++)
1616 if (msm_rotator_dev->img_info[i] != NULL)
1617 kfree(msm_rotator_dev->img_info[i]);
1618 kfree(msm_rotator_dev);
1619 return 0;
1620}
1621
1622#ifdef CONFIG_PM
1623static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1624{
1625 mutex_lock(&msm_rotator_dev->imem_lock);
1626 if (msm_rotator_dev->imem_clk_state == CLK_EN
1627 && msm_rotator_dev->imem_clk) {
1628 clk_disable(msm_rotator_dev->imem_clk);
1629 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1630 }
1631 mutex_unlock(&msm_rotator_dev->imem_lock);
1632 mutex_lock(&msm_rotator_dev->rotator_lock);
1633 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1634 disable_rot_clks();
1635 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1636 }
1637 mutex_unlock(&msm_rotator_dev->rotator_lock);
1638 return 0;
1639}
1640
1641static int msm_rotator_resume(struct platform_device *dev)
1642{
1643 mutex_lock(&msm_rotator_dev->imem_lock);
1644 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1645 && msm_rotator_dev->imem_clk) {
1646 clk_enable(msm_rotator_dev->imem_clk);
1647 msm_rotator_dev->imem_clk_state = CLK_EN;
1648 }
1649 mutex_unlock(&msm_rotator_dev->imem_lock);
1650 mutex_lock(&msm_rotator_dev->rotator_lock);
1651 if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND) {
1652 enable_rot_clks();
1653 msm_rotator_dev->rot_clk_state = CLK_EN;
1654 }
1655 mutex_unlock(&msm_rotator_dev->rotator_lock);
1656 return 0;
1657}
1658#endif
1659
1660static struct platform_driver msm_rotator_platform_driver = {
1661 .probe = msm_rotator_probe,
1662 .remove = __devexit_p(msm_rotator_remove),
1663#ifdef CONFIG_PM
1664 .suspend = msm_rotator_suspend,
1665 .resume = msm_rotator_resume,
1666#endif
1667 .driver = {
1668 .owner = THIS_MODULE,
1669 .name = DRIVER_NAME
1670 }
1671};
1672
1673static int __init msm_rotator_init(void)
1674{
1675 return platform_driver_register(&msm_rotator_platform_driver);
1676}
1677
1678static void __exit msm_rotator_exit(void)
1679{
1680 return platform_driver_unregister(&msm_rotator_platform_driver);
1681}
1682
1683module_init(msm_rotator_init);
1684module_exit(msm_rotator_exit);
1685
1686MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1687MODULE_VERSION("1.0");
1688MODULE_LICENSE("GPL v2");