blob: 529d9ddef2a47bc8788f3a9e30c3a3f6220b43cc [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,
572 int new_session)
573{
574 int bpp;
575
576 if (info->src.format != info->dst.format)
577 return -EINVAL;
578
579 bpp = get_bpp(info->src.format);
580 if (bpp < 0)
581 return -ENOTTY;
582
583 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
584 iowrite32(out_paddr +
585 ((info->dst_y * info->dst.width) + info->dst_x),
586 MSM_ROTATOR_OUTP0_ADDR);
587
588 if (new_session) {
589 iowrite32(info->src.width,
590 MSM_ROTATOR_SRC_YSTRIDE1);
591 iowrite32(info->dst.width,
592 MSM_ROTATOR_OUT_YSTRIDE1);
593 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
594 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
595 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
596 MSM_ROTATOR_OUT_PACK_PATTERN1);
597 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
598 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700599 1 << 8 | /* ROT_EN */
600 info->downscale_ratio << 2 | /* downscale v ratio */
601 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700602 MSM_ROTATOR_SUB_BLOCK_CFG);
603 iowrite32(0 << 29 | /* frame format 0 = linear */
604 (use_imem ? 0 : 1) << 22 | /* tile size */
605 0 << 19 | /* fetch planes 0=interleaved */
606 0 << 18 | /* unpack align */
607 1 << 17 | /* unpack tight */
608 3 << 13 | /* unpack count 0=1 component */
609 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
610 0 << 8 | /* has alpha */
611 0 << 6 | /* alpha bits 3=8bits */
612 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
613 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
614 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
615 MSM_ROTATOR_SRC_FORMAT);
616 }
617
618 return 0;
619}
620
621static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
622 unsigned int in_paddr,
623 unsigned int out_paddr,
624 unsigned int use_imem,
625 int new_session)
626{
627 int bpp, abits, rbits, gbits, bbits;
628
629 if (info->src.format != info->dst.format)
630 return -EINVAL;
631
632 bpp = get_bpp(info->src.format);
633 if (bpp < 0)
634 return -ENOTTY;
635
636 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
637 iowrite32(out_paddr +
638 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
639 MSM_ROTATOR_OUTP0_ADDR);
640
641 if (new_session) {
642 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
643 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
644 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
645 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700646 1 << 8 | /* ROT_EN */
647 info->downscale_ratio << 2 | /* downscale v ratio */
648 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 MSM_ROTATOR_SUB_BLOCK_CFG);
650 switch (info->src.format) {
651 case MDP_RGB_565:
652 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
653 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
654 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
655 MSM_ROTATOR_OUT_PACK_PATTERN1);
656 abits = 0;
657 rbits = COMPONENT_5BITS;
658 gbits = COMPONENT_6BITS;
659 bbits = COMPONENT_5BITS;
660 break;
661
662 case MDP_BGR_565:
663 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
664 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
665 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
666 MSM_ROTATOR_OUT_PACK_PATTERN1);
667 abits = 0;
668 rbits = COMPONENT_5BITS;
669 gbits = COMPONENT_6BITS;
670 bbits = COMPONENT_5BITS;
671 break;
672
673 case MDP_RGB_888:
674 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
675 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
676 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
677 MSM_ROTATOR_OUT_PACK_PATTERN1);
678 abits = 0;
679 rbits = COMPONENT_8BITS;
680 gbits = COMPONENT_8BITS;
681 bbits = COMPONENT_8BITS;
682 break;
683
684 case MDP_ARGB_8888:
685 case MDP_RGBA_8888:
686 case MDP_XRGB_8888:
687 case MDP_RGBX_8888:
688 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
689 CLR_B, 8),
690 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
691 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
692 CLR_B, 8),
693 MSM_ROTATOR_OUT_PACK_PATTERN1);
694 abits = COMPONENT_8BITS;
695 rbits = COMPONENT_8BITS;
696 gbits = COMPONENT_8BITS;
697 bbits = COMPONENT_8BITS;
698 break;
699
700 case MDP_BGRA_8888:
701 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
702 CLR_R, 8),
703 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
704 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
705 CLR_R, 8),
706 MSM_ROTATOR_OUT_PACK_PATTERN1);
707 abits = COMPONENT_8BITS;
708 rbits = COMPONENT_8BITS;
709 gbits = COMPONENT_8BITS;
710 bbits = COMPONENT_8BITS;
711 break;
712
713 default:
714 return -EINVAL;
715 }
716 iowrite32(0 << 29 | /* frame format 0 = linear */
717 (use_imem ? 0 : 1) << 22 | /* tile size */
718 0 << 19 | /* fetch planes 0=interleaved */
719 0 << 18 | /* unpack align */
720 1 << 17 | /* unpack tight */
721 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
722 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
723 (abits ? 1 : 0) << 8 | /* has alpha */
724 abits << 6 | /* alpha bits 3=8bits */
725 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
726 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
727 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
728 MSM_ROTATOR_SRC_FORMAT);
729 }
730
731 return 0;
732}
733
Naseer Ahmed18018602011-10-25 13:32:58 -0700734static int get_img(struct msmfb_data *fbd, unsigned long *start,
735 unsigned long *len, struct file **p_file, struct ion_handle **p_ihdl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700736{
737 int ret = 0;
738#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700739 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700740 int put_needed, fb_num;
741#endif
742#ifdef CONFIG_ANDROID_PMEM
743 unsigned long vstart;
744#endif
745
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700747 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
748 file = fget_light(fbd->memory_id, &put_needed);
749 if (file == NULL)
750 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700751
Naseer Ahmed18018602011-10-25 13:32:58 -0700752 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
753 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
754 if (get_fb_phys_info(start, len, fb_num))
755 ret = -1;
756 else
757 *p_file = file;
758 } else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700759 ret = -1;
Naseer Ahmed18018602011-10-25 13:32:58 -0700760 if (ret)
761 fput_light(file, put_needed);
762 return ret;
763 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700764#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700765
766#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
767 *p_ihdl = ion_import_fd(msm_rotator_dev->client,
768 fbd->memory_id);
769 if (IS_ERR_OR_NULL(*p_ihdl))
770 return PTR_ERR(*p_ihdl);
771 if (!ion_phys(msm_rotator_dev->client, *p_ihdl, start,
772 (size_t *) len))
773 return 0;
774 else
775 return -ENOMEM;
776#endif
777#ifdef CONFIG_ANDROID_PMEM
778 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
779 return 0;
780 else
781 return -ENOMEM;
782#endif
783
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700784}
785
Naseer Ahmed18018602011-10-25 13:32:58 -0700786static void put_img(struct file *p_file, struct ion_handle *p_ihdl)
787{
788#ifdef CONFIG_ANDROID_PMEM
789 if (p_file != NULL)
790 put_pmem_file(p_file);
791#endif
792#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
793 if (!IS_ERR_OR_NULL(p_ihdl))
794 ion_free(msm_rotator_dev->client, p_ihdl);
795#endif
796}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700797static int msm_rotator_do_rotate(unsigned long arg)
798{
Naseer Ahmed18018602011-10-25 13:32:58 -0700799 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800 struct msm_rotator_data_info info;
801 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700802 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700803 int use_imem = 0, rc = 0, s;
804 struct file *srcp0_file = NULL, *dstp0_file = NULL;
805 struct file *srcp1_file = NULL, *dstp1_file = NULL;
806 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
807 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700808 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700809 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700810 struct msm_rotator_img_info *img_info;
811 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700812
813 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
814 return -EFAULT;
815
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816 mutex_lock(&msm_rotator_dev->rotator_lock);
817 for (s = 0; s < MAX_SESSIONS; s++)
818 if ((msm_rotator_dev->img_info[s] != NULL) &&
819 (info.session_id ==
820 (unsigned int)msm_rotator_dev->img_info[s]
821 ))
822 break;
823
824 if (s == MAX_SESSIONS) {
825 dev_dbg(msm_rotator_dev->device,
826 "%s() : Attempt to use invalid session_id %d\n",
827 __func__, s);
828 rc = -EINVAL;
829 goto do_rotate_unlock_mutex;
830 }
831
832 if (msm_rotator_dev->img_info[s]->enable == 0) {
833 dev_dbg(msm_rotator_dev->device,
834 "%s() : Session_id %d not enabled \n",
835 __func__, s);
836 rc = -EINVAL;
837 goto do_rotate_unlock_mutex;
838 }
839
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700840 img_info = msm_rotator_dev->img_info[s];
841 if (msm_rotator_get_plane_sizes(img_info->src.format,
842 img_info->src.width,
843 img_info->src.height,
844 &src_planes)) {
845 pr_err("%s: invalid src format\n", __func__);
846 rc = -EINVAL;
847 goto do_rotate_unlock_mutex;
848 }
849 if (msm_rotator_get_plane_sizes(img_info->dst.format,
850 img_info->dst.width,
851 img_info->dst.height,
852 &dst_planes)) {
853 pr_err("%s: invalid dst format\n", __func__);
854 rc = -EINVAL;
855 goto do_rotate_unlock_mutex;
856 }
857
Naseer Ahmed18018602011-10-25 13:32:58 -0700858 rc = get_img(&info.src, (unsigned long *)&in_paddr,
859 (unsigned long *)&src_len, &srcp0_file, &srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700860 if (rc) {
861 pr_err("%s: in get_img() failed id=0x%08x\n",
862 DRIVER_NAME, info.src.memory_id);
863 goto do_rotate_unlock_mutex;
864 }
865
Naseer Ahmed18018602011-10-25 13:32:58 -0700866 rc = get_img(&info.dst, (unsigned long *)&out_paddr,
867 (unsigned long *)&dst_len, &dstp0_file, &dstp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700868 if (rc) {
869 pr_err("%s: out get_img() failed id=0x%08x\n",
870 DRIVER_NAME, info.dst.memory_id);
871 goto do_rotate_unlock_mutex;
872 }
873
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 format = msm_rotator_dev->img_info[s]->src.format;
875 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700876 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
877 (src_planes.num_planes == 2)) {
878 if (checkoffset(info.src.offset,
879 src_planes.plane_size[0],
880 src_len)) {
881 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
882 __func__, src_len, info.src.offset);
883 rc = -ERANGE;
884 goto do_rotate_unlock_mutex;
885 }
886 if (checkoffset(info.dst.offset,
887 dst_planes.plane_size[0],
888 dst_len)) {
889 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
890 __func__, dst_len, info.dst.offset);
891 rc = -ERANGE;
892 goto do_rotate_unlock_mutex;
893 }
894
Naseer Ahmed18018602011-10-25 13:32:58 -0700895 rc = get_img(&info.src_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700896 (unsigned long *)&in_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700897 (unsigned long *)&src_len, &srcp1_file,
898 &srcp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700900 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 DRIVER_NAME, info.src_chroma.memory_id);
902 goto do_rotate_unlock_mutex;
903 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904
Naseer Ahmed18018602011-10-25 13:32:58 -0700905 rc = get_img(&info.dst_chroma,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 (unsigned long *)&out_chroma_paddr,
Naseer Ahmed18018602011-10-25 13:32:58 -0700907 (unsigned long *)&dst_len, &dstp1_file,
908 &dstp1_ihdl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700910 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700912 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700914
915 if (checkoffset(info.src_chroma.offset,
916 src_planes.plane_size[1],
917 src_len)) {
918 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
919 __func__, src_len, info.src_chroma.offset);
920 rc = -ERANGE;
921 goto do_rotate_unlock_mutex;
922 }
923
924 if (checkoffset(info.dst_chroma.offset,
925 src_planes.plane_size[1],
926 dst_len)) {
927 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
928 __func__, dst_len, info.dst_chroma.offset);
929 rc = -ERANGE;
930 goto do_rotate_unlock_mutex;
931 }
932
933 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700934 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700935 } else {
936 if (checkoffset(info.src.offset,
937 src_planes.total_size,
938 src_len)) {
939 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
940 __func__, src_len, info.src.offset);
941 rc = -ERANGE;
942 goto do_rotate_unlock_mutex;
943 }
944 if (checkoffset(info.dst.offset,
945 dst_planes.total_size,
946 dst_len)) {
947 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
948 __func__, dst_len, info.dst.offset);
949 rc = -ERANGE;
950 goto do_rotate_unlock_mutex;
951 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700952 }
953
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700954 in_paddr += info.src.offset;
955 out_paddr += info.dst.offset;
956
957 if (!in_chroma_paddr && src_planes.num_planes >= 2)
958 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
959 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
960 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
961 if (src_planes.num_planes >= 3)
962 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
963
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
965 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
966 enable_rot_clks();
967 msm_rotator_dev->rot_clk_state = CLK_EN;
968 }
969 enable_irq(msm_rotator_dev->irq);
970
971#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
972 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
973#else
974 use_imem = 0;
975#endif
976 /*
977 * workaround for a hardware bug. rotator hardware hangs when we
978 * use write burst beat size 16 on 128X128 tile fetch mode. As a
979 * temporary fix use 0x42 for BURST_SIZE when imem used.
980 */
981 if (use_imem)
982 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
983
984 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
985 << 16) |
986 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
987 MSM_ROTATOR_SRC_SIZE);
988 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
989 << 16) |
990 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
991 MSM_ROTATOR_SRC_XY);
992 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
993 << 16) |
994 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
995 MSM_ROTATOR_SRC_IMAGE_SIZE);
996
997 switch (format) {
998 case MDP_RGB_565:
999 case MDP_BGR_565:
1000 case MDP_RGB_888:
1001 case MDP_ARGB_8888:
1002 case MDP_RGBA_8888:
1003 case MDP_XRGB_8888:
1004 case MDP_BGRA_8888:
1005 case MDP_RGBX_8888:
1006 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
1007 in_paddr, out_paddr,
1008 use_imem,
1009 msm_rotator_dev->last_session_idx
1010 != s);
1011 break;
1012 case MDP_Y_CBCR_H2V2:
1013 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001014 case MDP_Y_CB_CR_H2V2:
1015 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301016 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001017 case MDP_Y_CRCB_H2V2_TILE:
1018 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001019 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1020 in_paddr, out_paddr, use_imem,
1021 msm_rotator_dev->last_session_idx
1022 != s,
1023 in_chroma_paddr,
1024 out_chroma_paddr,
1025 in_chroma2_paddr);
1026 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001027 case MDP_Y_CBCR_H2V1:
1028 case MDP_Y_CRCB_H2V1:
1029 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1030 in_paddr, out_paddr, use_imem,
1031 msm_rotator_dev->last_session_idx
1032 != s,
1033 in_chroma_paddr,
1034 out_chroma_paddr);
1035 break;
1036 case MDP_YCRYCB_H2V1:
1037 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1038 in_paddr, out_paddr, use_imem,
1039 msm_rotator_dev->last_session_idx != s);
1040 break;
1041 default:
1042 rc = -EINVAL;
1043 goto do_rotate_exit;
1044 }
1045
1046 if (rc != 0) {
1047 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1048 goto do_rotate_exit;
1049 }
1050
1051 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1052
1053 msm_rotator_dev->processing = 1;
1054 iowrite32(0x1, MSM_ROTATOR_START);
1055
1056 wait_event(msm_rotator_dev->wq,
1057 (msm_rotator_dev->processing == 0));
1058 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
1059 if ((status & 0x03) != 0x01)
1060 rc = -EFAULT;
1061 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1062 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1063
1064do_rotate_exit:
1065 disable_irq(msm_rotator_dev->irq);
1066#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1067 msm_rotator_imem_free(ROTATOR_REQUEST);
1068#endif
1069 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001070do_rotate_unlock_mutex:
Naseer Ahmed18018602011-10-25 13:32:58 -07001071 put_img(dstp1_file, dstp1_ihdl);
1072 put_img(srcp1_file, srcp1_ihdl);
1073 put_img(dstp0_file, dstp0_ihdl);
1074 put_img(srcp0_file, srcp0_ihdl);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001075 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001076 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1077 __func__, rc);
1078 return rc;
1079}
1080
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001081static void msm_rotator_set_perf_level(u32 wh, u32 is_rgb)
1082{
1083 u32 perf_level;
1084
1085 if (is_rgb)
1086 perf_level = 1;
1087 else if (wh <= (640 * 480))
1088 perf_level = 2;
1089 else if (wh <= (736 * 1280))
1090 perf_level = 3;
1091 else
1092 perf_level = 4;
1093
1094#ifdef CONFIG_MSM_BUS_SCALING
1095 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1096 perf_level);
1097#endif
1098
1099}
1100
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001101static int msm_rotator_start(unsigned long arg, int pid)
1102{
1103 struct msm_rotator_img_info info;
1104 int rc = 0;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001105 int s, is_rgb = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001106 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001107 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001108
1109 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1110 return -EFAULT;
1111
1112 if ((info.rotations > MSM_ROTATOR_MAX_ROT) ||
1113 (info.src.height > MSM_ROTATOR_MAX_H) ||
1114 (info.src.width > MSM_ROTATOR_MAX_W) ||
1115 (info.dst.height > MSM_ROTATOR_MAX_H) ||
1116 (info.dst.width > MSM_ROTATOR_MAX_W) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001117 (info.downscale_ratio > MAX_DOWNSCALE_RATIO)) {
1118 pr_err("%s: Invalid parameters\n", __func__);
1119 return -EINVAL;
1120 }
1121
1122 if (info.rotations & MDP_ROT_90) {
1123 dst_w = info.src_rect.h >> info.downscale_ratio;
1124 dst_h = info.src_rect.w >> info.downscale_ratio;
1125 } else {
1126 dst_w = info.src_rect.w >> info.downscale_ratio;
1127 dst_h = info.src_rect.h >> info.downscale_ratio;
1128 }
1129
1130 if (checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001131 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1132 checkoffset(info.dst_x, dst_w, info.dst.width) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001133 checkoffset(info.dst_y, dst_h, info.dst.height)) {
1134 pr_err("%s: Invalid src or dst rect\n", __func__);
1135 return -ERANGE;
1136 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001137
1138 switch (info.src.format) {
1139 case MDP_RGB_565:
1140 case MDP_BGR_565:
1141 case MDP_RGB_888:
1142 case MDP_ARGB_8888:
1143 case MDP_RGBA_8888:
1144 case MDP_XRGB_8888:
1145 case MDP_RGBX_8888:
1146 case MDP_BGRA_8888:
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001147 is_rgb = 1;
1148 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001149 case MDP_Y_CBCR_H2V2:
1150 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001151 case MDP_Y_CB_CR_H2V2:
1152 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301153 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001154 case MDP_Y_CBCR_H2V1:
1155 case MDP_Y_CRCB_H2V1:
1156 case MDP_YCRYCB_H2V1:
1157 case MDP_Y_CRCB_H2V2_TILE:
1158 case MDP_Y_CBCR_H2V2_TILE:
1159 break;
1160 default:
1161 return -EINVAL;
1162 }
1163
1164 switch (info.dst.format) {
1165 case MDP_RGB_565:
1166 case MDP_BGR_565:
1167 case MDP_RGB_888:
1168 case MDP_ARGB_8888:
1169 case MDP_RGBA_8888:
1170 case MDP_XRGB_8888:
1171 case MDP_RGBX_8888:
1172 case MDP_BGRA_8888:
1173 case MDP_Y_CBCR_H2V2:
1174 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001175 case MDP_Y_CB_CR_H2V2:
1176 case MDP_Y_CR_CB_H2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177 case MDP_Y_CBCR_H2V1:
1178 case MDP_Y_CRCB_H2V1:
1179 case MDP_YCRYCB_H2V1:
1180 break;
1181 default:
1182 return -EINVAL;
1183 }
1184
1185 mutex_lock(&msm_rotator_dev->rotator_lock);
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001186
1187 msm_rotator_set_perf_level((info.src.width*info.src.height), is_rgb);
1188
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001189 for (s = 0; s < MAX_SESSIONS; s++) {
1190 if ((msm_rotator_dev->img_info[s] != NULL) &&
1191 (info.session_id ==
1192 (unsigned int)msm_rotator_dev->img_info[s]
1193 )) {
1194 *(msm_rotator_dev->img_info[s]) = info;
1195 msm_rotator_dev->pid_list[s] = pid;
1196
1197 if (msm_rotator_dev->last_session_idx == s)
1198 msm_rotator_dev->last_session_idx =
1199 INVALID_SESSION;
1200 break;
1201 }
1202
1203 if ((msm_rotator_dev->img_info[s] == NULL) &&
1204 (first_free_index ==
1205 INVALID_SESSION))
1206 first_free_index = s;
1207 }
1208
1209 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1210 /* allocate a session id */
1211 msm_rotator_dev->img_info[first_free_index] =
1212 kzalloc(sizeof(struct msm_rotator_img_info),
1213 GFP_KERNEL);
1214 if (!msm_rotator_dev->img_info[first_free_index]) {
1215 printk(KERN_ERR "%s : unable to alloc mem\n",
1216 __func__);
1217 rc = -ENOMEM;
1218 goto rotator_start_exit;
1219 }
1220 info.session_id = (unsigned int)
1221 msm_rotator_dev->img_info[first_free_index];
1222 *(msm_rotator_dev->img_info[first_free_index]) = info;
1223 msm_rotator_dev->pid_list[first_free_index] = pid;
1224
1225 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1226 rc = -EFAULT;
1227 } else if (s == MAX_SESSIONS) {
1228 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1229 __func__);
1230 rc = -EBUSY;
1231 }
1232
1233rotator_start_exit:
1234 mutex_unlock(&msm_rotator_dev->rotator_lock);
1235
1236 return rc;
1237}
1238
1239static int msm_rotator_finish(unsigned long arg)
1240{
1241 int rc = 0;
1242 int s;
1243 unsigned int session_id;
1244
1245 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1246 return -EFAULT;
1247
1248 mutex_lock(&msm_rotator_dev->rotator_lock);
1249 for (s = 0; s < MAX_SESSIONS; s++) {
1250 if ((msm_rotator_dev->img_info[s] != NULL) &&
1251 (session_id ==
1252 (unsigned int)msm_rotator_dev->img_info[s])) {
1253 if (msm_rotator_dev->last_session_idx == s)
1254 msm_rotator_dev->last_session_idx =
1255 INVALID_SESSION;
1256 kfree(msm_rotator_dev->img_info[s]);
1257 msm_rotator_dev->img_info[s] = NULL;
1258 msm_rotator_dev->pid_list[s] = 0;
1259 break;
1260 }
1261 }
1262
1263 if (s == MAX_SESSIONS)
1264 rc = -EINVAL;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001265#ifdef CONFIG_MSM_BUS_SCALING
1266 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1267 0);
1268#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001269 mutex_unlock(&msm_rotator_dev->rotator_lock);
1270 return rc;
1271}
1272
1273static int
1274msm_rotator_open(struct inode *inode, struct file *filp)
1275{
1276 int *id;
1277 int i;
1278
1279 if (filp->private_data)
1280 return -EBUSY;
1281
1282 mutex_lock(&msm_rotator_dev->rotator_lock);
1283 id = &msm_rotator_dev->pid_list[0];
1284 for (i = 0; i < MAX_SESSIONS; i++, id++) {
1285 if (*id == 0)
1286 break;
1287 }
1288 mutex_unlock(&msm_rotator_dev->rotator_lock);
1289
1290 if (i == MAX_SESSIONS)
1291 return -EBUSY;
1292
kuogee hsieh7a46d592011-09-09 10:27:23 -07001293 filp->private_data = (void *)current->pid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001294
1295 return 0;
1296}
1297
1298static int
1299msm_rotator_close(struct inode *inode, struct file *filp)
1300{
1301 int s;
1302 int pid;
1303
1304 pid = (int)filp->private_data;
1305 mutex_lock(&msm_rotator_dev->rotator_lock);
1306 for (s = 0; s < MAX_SESSIONS; s++) {
1307 if (msm_rotator_dev->img_info[s] != NULL &&
1308 msm_rotator_dev->pid_list[s] == pid) {
1309 kfree(msm_rotator_dev->img_info[s]);
1310 msm_rotator_dev->img_info[s] = NULL;
1311 if (msm_rotator_dev->last_session_idx == s)
1312 msm_rotator_dev->last_session_idx =
1313 INVALID_SESSION;
1314 }
1315 }
1316 mutex_unlock(&msm_rotator_dev->rotator_lock);
1317
1318 return 0;
1319}
1320
1321static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1322 unsigned long arg)
1323{
1324 int pid;
1325
1326 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1327 return -ENOTTY;
1328
1329 pid = (int)file->private_data;
1330
1331 switch (cmd) {
1332 case MSM_ROTATOR_IOCTL_START:
1333 return msm_rotator_start(arg, pid);
1334 case MSM_ROTATOR_IOCTL_ROTATE:
1335 return msm_rotator_do_rotate(arg);
1336 case MSM_ROTATOR_IOCTL_FINISH:
1337 return msm_rotator_finish(arg);
1338
1339 default:
1340 dev_dbg(msm_rotator_dev->device,
1341 "unexpected IOCTL %d\n", cmd);
1342 return -ENOTTY;
1343 }
1344}
1345
1346static const struct file_operations msm_rotator_fops = {
1347 .owner = THIS_MODULE,
1348 .open = msm_rotator_open,
1349 .release = msm_rotator_close,
1350 .unlocked_ioctl = msm_rotator_ioctl,
1351};
1352
1353static int __devinit msm_rotator_probe(struct platform_device *pdev)
1354{
1355 int rc = 0;
1356 struct resource *res;
1357 struct msm_rotator_platform_data *pdata = NULL;
1358 int i, number_of_clks;
1359 uint32_t ver;
1360
1361 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1362 if (!msm_rotator_dev) {
1363 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1364 __func__);
1365 return -ENOMEM;
1366 }
1367 for (i = 0; i < MAX_SESSIONS; i++)
1368 msm_rotator_dev->img_info[i] = NULL;
1369 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1370
1371 pdata = pdev->dev.platform_data;
1372 number_of_clks = pdata->number_of_clocks;
1373
1374 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1375 mutex_init(&msm_rotator_dev->imem_lock);
1376 msm_rotator_dev->imem_clk_state = CLK_DIS;
1377 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1378 msm_rotator_imem_clk_work_f);
1379 msm_rotator_dev->imem_clk = NULL;
1380 msm_rotator_dev->pdev = pdev;
1381
1382 msm_rotator_dev->core_clk = NULL;
1383 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001384
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001385#ifdef CONFIG_MSM_BUS_SCALING
1386 if (!msm_rotator_dev->bus_client_handle && pdata &&
1387 pdata->bus_scale_table) {
1388 msm_rotator_dev->bus_client_handle =
1389 msm_bus_scale_register_client(
1390 pdata->bus_scale_table);
1391 if (!msm_rotator_dev->bus_client_handle) {
1392 pr_err("%s not able to get bus scale handle\n",
1393 __func__);
1394 }
1395 }
1396#endif
1397
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001398 for (i = 0; i < number_of_clks; i++) {
1399 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1400 msm_rotator_dev->imem_clk =
1401 clk_get(&msm_rotator_dev->pdev->dev,
1402 pdata->rotator_clks[i].clk_name);
1403 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1404 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1405 msm_rotator_dev->imem_clk = NULL;
1406 printk(KERN_ERR "%s: cannot get imem_clk "
1407 "rc=%d\n", DRIVER_NAME, rc);
1408 goto error_imem_clk;
1409 }
1410 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001411 clk_set_rate(msm_rotator_dev->imem_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001412 pdata->rotator_clks[i].clk_rate);
1413 }
1414 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1415 msm_rotator_dev->pclk =
1416 clk_get(&msm_rotator_dev->pdev->dev,
1417 pdata->rotator_clks[i].clk_name);
1418 if (IS_ERR(msm_rotator_dev->pclk)) {
1419 rc = PTR_ERR(msm_rotator_dev->pclk);
1420 msm_rotator_dev->pclk = NULL;
1421 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1422 DRIVER_NAME, rc);
1423 goto error_pclk;
1424 }
1425
1426 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001427 clk_set_rate(msm_rotator_dev->pclk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001428 pdata->rotator_clks[i].clk_rate);
1429 }
1430
1431 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1432 msm_rotator_dev->core_clk =
1433 clk_get(&msm_rotator_dev->pdev->dev,
1434 pdata->rotator_clks[i].clk_name);
1435 if (IS_ERR(msm_rotator_dev->core_clk)) {
1436 rc = PTR_ERR(msm_rotator_dev->core_clk);
1437 msm_rotator_dev->core_clk = NULL;
1438 printk(KERN_ERR "%s: cannot get core clk "
1439 "rc=%d\n", DRIVER_NAME, rc);
1440 goto error_core_clk;
1441 }
1442
1443 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001444 clk_set_rate(msm_rotator_dev->core_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001445 pdata->rotator_clks[i].clk_rate);
1446 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001447 }
1448
1449 msm_rotator_dev->regulator = regulator_get(NULL, pdata->regulator_name);
1450 if (IS_ERR(msm_rotator_dev->regulator))
1451 msm_rotator_dev->regulator = NULL;
1452
1453 msm_rotator_dev->rot_clk_state = CLK_DIS;
1454 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1455 msm_rotator_rot_clk_work_f);
1456
1457 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001458#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1459 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1460#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001461 platform_set_drvdata(pdev, msm_rotator_dev);
1462
1463
1464 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1465 if (!res) {
1466 printk(KERN_ALERT
1467 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1468 rc = -ENODEV;
1469 goto error_get_resource;
1470 }
1471 msm_rotator_dev->io_base = ioremap(res->start,
1472 resource_size(res));
1473
1474#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1475 if (msm_rotator_dev->imem_clk)
1476 clk_enable(msm_rotator_dev->imem_clk);
1477#endif
1478 enable_rot_clks();
1479 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1480 disable_rot_clks();
1481
1482#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1483 if (msm_rotator_dev->imem_clk)
1484 clk_disable(msm_rotator_dev->imem_clk);
1485#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001486 if (ver != pdata->hardware_version_number)
Nagamalleswararao Ganjibcdea002011-09-13 15:43:47 -07001487 pr_info("%s: invalid HW version\n", DRIVER_NAME);
Naseer Ahmed18018602011-10-25 13:32:58 -07001488
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001489 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1490 if (msm_rotator_dev->irq < 0) {
1491 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1492 DRIVER_NAME);
1493 rc = -ENODEV;
1494 goto error_get_irq;
1495 }
1496 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1497 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1498 if (rc) {
1499 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1500 goto error_get_irq;
1501 }
1502 /* we enable the IRQ when we need it in the ioctl */
1503 disable_irq(msm_rotator_dev->irq);
1504
1505 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1506 if (rc < 0) {
1507 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1508 __func__, rc);
1509 goto error_get_irq;
1510 }
1511
1512 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1513 if (IS_ERR(msm_rotator_dev->class)) {
1514 rc = PTR_ERR(msm_rotator_dev->class);
1515 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1516 DRIVER_NAME, rc);
1517 goto error_class_create;
1518 }
1519
1520 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1521 msm_rotator_dev->dev_num, NULL,
1522 DRIVER_NAME);
1523 if (IS_ERR(msm_rotator_dev->device)) {
1524 rc = PTR_ERR(msm_rotator_dev->device);
1525 printk(KERN_ERR "%s: device_create failed %d\n",
1526 DRIVER_NAME, rc);
1527 goto error_class_device_create;
1528 }
1529
1530 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1531 rc = cdev_add(&msm_rotator_dev->cdev,
1532 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1533 1);
1534 if (rc < 0) {
1535 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1536 goto error_cdev_add;
1537 }
1538
1539 init_waitqueue_head(&msm_rotator_dev->wq);
1540
1541 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1542 return rc;
1543
1544error_cdev_add:
1545 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1546error_class_device_create:
1547 class_destroy(msm_rotator_dev->class);
1548error_class_create:
1549 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1550error_get_irq:
1551 iounmap(msm_rotator_dev->io_base);
1552error_get_resource:
1553 mutex_destroy(&msm_rotator_dev->rotator_lock);
1554 if (msm_rotator_dev->regulator)
1555 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001556 clk_put(msm_rotator_dev->core_clk);
1557error_core_clk:
1558 clk_put(msm_rotator_dev->pclk);
1559error_pclk:
1560 if (msm_rotator_dev->imem_clk)
1561 clk_put(msm_rotator_dev->imem_clk);
1562error_imem_clk:
1563 mutex_destroy(&msm_rotator_dev->imem_lock);
1564 kfree(msm_rotator_dev);
1565 return rc;
1566}
1567
1568static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1569{
1570 int i;
1571
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001572#ifdef CONFIG_MSM_BUS_SCALING
1573 msm_bus_scale_unregister_client(msm_rotator_dev->bus_client_handle);
1574#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001575 free_irq(msm_rotator_dev->irq, NULL);
1576 mutex_destroy(&msm_rotator_dev->rotator_lock);
1577 cdev_del(&msm_rotator_dev->cdev);
1578 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1579 class_destroy(msm_rotator_dev->class);
1580 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1581 iounmap(msm_rotator_dev->io_base);
1582 if (msm_rotator_dev->imem_clk) {
1583 if (msm_rotator_dev->imem_clk_state == CLK_EN)
1584 clk_disable(msm_rotator_dev->imem_clk);
1585 clk_put(msm_rotator_dev->imem_clk);
1586 msm_rotator_dev->imem_clk = NULL;
1587 }
1588 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1589 disable_rot_clks();
1590 clk_put(msm_rotator_dev->core_clk);
1591 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001592 if (msm_rotator_dev->regulator)
1593 regulator_put(msm_rotator_dev->regulator);
1594 msm_rotator_dev->core_clk = NULL;
1595 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001596 mutex_destroy(&msm_rotator_dev->imem_lock);
1597 for (i = 0; i < MAX_SESSIONS; i++)
1598 if (msm_rotator_dev->img_info[i] != NULL)
1599 kfree(msm_rotator_dev->img_info[i]);
1600 kfree(msm_rotator_dev);
1601 return 0;
1602}
1603
1604#ifdef CONFIG_PM
1605static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1606{
1607 mutex_lock(&msm_rotator_dev->imem_lock);
1608 if (msm_rotator_dev->imem_clk_state == CLK_EN
1609 && msm_rotator_dev->imem_clk) {
1610 clk_disable(msm_rotator_dev->imem_clk);
1611 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1612 }
1613 mutex_unlock(&msm_rotator_dev->imem_lock);
1614 mutex_lock(&msm_rotator_dev->rotator_lock);
1615 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1616 disable_rot_clks();
1617 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1618 }
1619 mutex_unlock(&msm_rotator_dev->rotator_lock);
1620 return 0;
1621}
1622
1623static int msm_rotator_resume(struct platform_device *dev)
1624{
1625 mutex_lock(&msm_rotator_dev->imem_lock);
1626 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1627 && msm_rotator_dev->imem_clk) {
1628 clk_enable(msm_rotator_dev->imem_clk);
1629 msm_rotator_dev->imem_clk_state = CLK_EN;
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_SUSPEND) {
1634 enable_rot_clks();
1635 msm_rotator_dev->rot_clk_state = CLK_EN;
1636 }
1637 mutex_unlock(&msm_rotator_dev->rotator_lock);
1638 return 0;
1639}
1640#endif
1641
1642static struct platform_driver msm_rotator_platform_driver = {
1643 .probe = msm_rotator_probe,
1644 .remove = __devexit_p(msm_rotator_remove),
1645#ifdef CONFIG_PM
1646 .suspend = msm_rotator_suspend,
1647 .resume = msm_rotator_resume,
1648#endif
1649 .driver = {
1650 .owner = THIS_MODULE,
1651 .name = DRIVER_NAME
1652 }
1653};
1654
1655static int __init msm_rotator_init(void)
1656{
1657 return platform_driver_register(&msm_rotator_platform_driver);
1658}
1659
1660static void __exit msm_rotator_exit(void)
1661{
1662 return platform_driver_unregister(&msm_rotator_platform_driver);
1663}
1664
1665module_init(msm_rotator_init);
1666module_exit(msm_rotator_exit);
1667
1668MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1669MODULE_VERSION("1.0");
1670MODULE_LICENSE("GPL v2");