blob: 4d34362b626cd7439db3a82d77bb96dccd72e090 [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
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -070036#include <mach/msm_subsystem_map.h>
37#include <mach/iommu_domains.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#define DRIVER_NAME "msm_rotator"
40
41#define MSM_ROTATOR_BASE (msm_rotator_dev->io_base)
42#define MSM_ROTATOR_INTR_ENABLE (MSM_ROTATOR_BASE+0x0020)
43#define MSM_ROTATOR_INTR_STATUS (MSM_ROTATOR_BASE+0x0024)
44#define MSM_ROTATOR_INTR_CLEAR (MSM_ROTATOR_BASE+0x0028)
45#define MSM_ROTATOR_START (MSM_ROTATOR_BASE+0x0030)
46#define MSM_ROTATOR_MAX_BURST_SIZE (MSM_ROTATOR_BASE+0x0050)
47#define MSM_ROTATOR_HW_VERSION (MSM_ROTATOR_BASE+0x0070)
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -070048#define MSM_ROTATOR_SW_RESET (MSM_ROTATOR_BASE+0x0074)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049#define MSM_ROTATOR_SRC_SIZE (MSM_ROTATOR_BASE+0x1108)
50#define MSM_ROTATOR_SRCP0_ADDR (MSM_ROTATOR_BASE+0x110c)
51#define MSM_ROTATOR_SRCP1_ADDR (MSM_ROTATOR_BASE+0x1110)
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -070052#define MSM_ROTATOR_SRCP2_ADDR (MSM_ROTATOR_BASE+0x1114)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053#define MSM_ROTATOR_SRC_YSTRIDE1 (MSM_ROTATOR_BASE+0x111c)
54#define MSM_ROTATOR_SRC_YSTRIDE2 (MSM_ROTATOR_BASE+0x1120)
55#define MSM_ROTATOR_SRC_FORMAT (MSM_ROTATOR_BASE+0x1124)
56#define MSM_ROTATOR_SRC_UNPACK_PATTERN1 (MSM_ROTATOR_BASE+0x1128)
57#define MSM_ROTATOR_SUB_BLOCK_CFG (MSM_ROTATOR_BASE+0x1138)
58#define MSM_ROTATOR_OUT_PACK_PATTERN1 (MSM_ROTATOR_BASE+0x1154)
59#define MSM_ROTATOR_OUTP0_ADDR (MSM_ROTATOR_BASE+0x1168)
60#define MSM_ROTATOR_OUTP1_ADDR (MSM_ROTATOR_BASE+0x116c)
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -070061#define MSM_ROTATOR_OUTP2_ADDR (MSM_ROTATOR_BASE+0x1170)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062#define MSM_ROTATOR_OUT_YSTRIDE1 (MSM_ROTATOR_BASE+0x1178)
63#define MSM_ROTATOR_OUT_YSTRIDE2 (MSM_ROTATOR_BASE+0x117c)
64#define MSM_ROTATOR_SRC_XY (MSM_ROTATOR_BASE+0x1200)
65#define MSM_ROTATOR_SRC_IMAGE_SIZE (MSM_ROTATOR_BASE+0x1208)
66
67#define MSM_ROTATOR_MAX_ROT 0x07
68#define MSM_ROTATOR_MAX_H 0x1fff
69#define MSM_ROTATOR_MAX_W 0x1fff
70
71/* from lsb to msb */
72#define GET_PACK_PATTERN(a, x, y, z, bit) \
73 (((a)<<((bit)*3))|((x)<<((bit)*2))|((y)<<(bit))|(z))
74#define CLR_G 0x0
75#define CLR_B 0x1
76#define CLR_R 0x2
77#define CLR_ALPHA 0x3
78
79#define CLR_Y CLR_G
80#define CLR_CB CLR_B
81#define CLR_CR CLR_R
82
83#define ROTATIONS_TO_BITMASK(r) ((((r) & MDP_ROT_90) ? 1 : 0) | \
84 (((r) & MDP_FLIP_LR) ? 2 : 0) | \
85 (((r) & MDP_FLIP_UD) ? 4 : 0))
86
87#define IMEM_NO_OWNER -1;
88
89#define MAX_SESSIONS 16
90#define INVALID_SESSION -1
91#define VERSION_KEY_MASK 0xFFFFFF00
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -070092#define MAX_DOWNSCALE_RATIO 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093
Mayank Chopra012a8e72012-04-11 10:41:13 +053094#define ROTATOR_REVISION_V0 0
95#define ROTATOR_REVISION_V1 1
96#define ROTATOR_REVISION_V2 2
97#define ROTATOR_REVISION_NONE 0xffffffff
98
99uint32_t rotator_hw_revision;
Olav Hauganef95ae32012-05-15 09:50:30 -0700100static char rot_iommu_split_domain;
Mayank Chopra012a8e72012-04-11 10:41:13 +0530101
102/*
103 * rotator_hw_revision:
104 * 0 == 7x30
105 * 1 == 8x60
106 * 2 == 8960
107 *
108 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109struct tile_parm {
110 unsigned int width; /* tile's width */
111 unsigned int height; /* tile's height */
112 unsigned int row_tile_w; /* tiles per row's width */
113 unsigned int row_tile_h; /* tiles per row's height */
114};
115
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700116struct msm_rotator_mem_planes {
117 unsigned int num_planes;
118 unsigned int plane_size[4];
119 unsigned int total_size;
120};
121
122#define checkoffset(offset, size, max_size) \
123 ((size) > (max_size) || (offset) > ((max_size) - (size)))
124
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -0700125struct msm_rotator_fd_info {
126 int pid;
127 int ref_cnt;
128 struct list_head list;
129};
130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131struct msm_rotator_dev {
132 void __iomem *io_base;
133 int irq;
134 struct msm_rotator_img_info *img_info[MAX_SESSIONS];
135 struct clk *core_clk;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -0700136 struct msm_rotator_fd_info *fd_info[MAX_SESSIONS];
137 struct list_head fd_list;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138 struct clk *pclk;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 int rot_clk_state;
140 struct regulator *regulator;
141 struct delayed_work rot_clk_work;
142 struct clk *imem_clk;
143 int imem_clk_state;
144 struct delayed_work imem_clk_work;
145 struct platform_device *pdev;
146 struct cdev cdev;
147 struct device *device;
148 struct class *class;
149 dev_t dev_num;
150 int processing;
151 int last_session_idx;
152 struct mutex rotator_lock;
153 struct mutex imem_lock;
154 int imem_owner;
155 wait_queue_head_t wq;
Naseer Ahmed18018602011-10-25 13:32:58 -0700156 struct ion_client *client;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -0800157 #ifdef CONFIG_MSM_BUS_SCALING
158 uint32_t bus_client_handle;
159 #endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160};
161
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162#define COMPONENT_5BITS 1
163#define COMPONENT_6BITS 2
164#define COMPONENT_8BITS 3
165
166static struct msm_rotator_dev *msm_rotator_dev;
167
168enum {
169 CLK_EN,
170 CLK_DIS,
171 CLK_SUSPEND,
172};
173
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700174int msm_rotator_iommu_map_buf(int mem_id, int domain,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700175 unsigned long *start, unsigned long *len,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700176 struct ion_handle **pihdl, unsigned int secure)
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700177{
178 if (!msm_rotator_dev->client)
179 return -EINVAL;
180
Laura Abbottb14ed962012-01-30 14:18:08 -0800181 *pihdl = ion_import_dma_buf(msm_rotator_dev->client, mem_id);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700182 if (IS_ERR_OR_NULL(*pihdl)) {
Laura Abbottb14ed962012-01-30 14:18:08 -0800183 pr_err("ion_import_dma_buf() failed\n");
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700184 return PTR_ERR(*pihdl);
185 }
Laura Abbottb14ed962012-01-30 14:18:08 -0800186 pr_debug("%s(): ion_hdl %p, ion_fd %d\n", __func__, *pihdl,
187 ion_share_dma_buf(msm_rotator_dev->client, *pihdl));
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700188
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700189 if (rot_iommu_split_domain) {
190 if (secure) {
191 if (ion_phys(msm_rotator_dev->client,
192 *pihdl, start, (unsigned *)len)) {
193 pr_err("%s:%d: ion_phys map failed\n",
194 __func__, __LINE__);
195 return -ENOMEM;
196 }
197 } else {
198 if (ion_map_iommu(msm_rotator_dev->client,
199 *pihdl, domain, GEN_POOL,
200 SZ_4K, 0, start, len, 0,
201 ION_IOMMU_UNMAP_DELAYED)) {
202 pr_err("ion_map_iommu() failed\n");
203 return -EINVAL;
204 }
205 }
206 } else {
207 if (ion_map_iommu(msm_rotator_dev->client,
208 *pihdl, ROTATOR_SRC_DOMAIN, GEN_POOL,
209 SZ_4K, 0, start, len, 0, ION_IOMMU_UNMAP_DELAYED)) {
210 pr_err("ion_map_iommu() failed\n");
211 return -EINVAL;
212 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700213 }
214
215 pr_debug("%s(): mem_id %d, start 0x%lx, len 0x%lx\n",
216 __func__, mem_id, *start, *len);
217 return 0;
218}
219
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700220int msm_rotator_imem_allocate(int requestor)
221{
222 int rc = 0;
223
224#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
225 switch (requestor) {
226 case ROTATOR_REQUEST:
227 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
228 msm_rotator_dev->imem_owner = ROTATOR_REQUEST;
229 rc = 1;
230 } else
231 rc = 0;
232 break;
233 case JPEG_REQUEST:
234 mutex_lock(&msm_rotator_dev->imem_lock);
235 msm_rotator_dev->imem_owner = JPEG_REQUEST;
236 rc = 1;
237 break;
238 default:
239 rc = 0;
240 }
241#else
242 if (requestor == JPEG_REQUEST)
243 rc = 1;
244#endif
245 if (rc == 1) {
246 cancel_delayed_work(&msm_rotator_dev->imem_clk_work);
247 if (msm_rotator_dev->imem_clk_state != CLK_EN
248 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700249 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250 msm_rotator_dev->imem_clk_state = CLK_EN;
251 }
252 }
253
254 return rc;
255}
256EXPORT_SYMBOL(msm_rotator_imem_allocate);
257
258void msm_rotator_imem_free(int requestor)
259{
260#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
261 if (msm_rotator_dev->imem_owner == requestor) {
262 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
263 mutex_unlock(&msm_rotator_dev->imem_lock);
264 }
265#else
266 if (requestor == JPEG_REQUEST)
267 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
268#endif
269}
270EXPORT_SYMBOL(msm_rotator_imem_free);
271
272static void msm_rotator_imem_clk_work_f(struct work_struct *work)
273{
274#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
275 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
276 if (msm_rotator_dev->imem_clk_state == CLK_EN
277 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700278 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700279 msm_rotator_dev->imem_clk_state = CLK_DIS;
280 } else if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND)
281 msm_rotator_dev->imem_clk_state = CLK_DIS;
282 mutex_unlock(&msm_rotator_dev->imem_lock);
283 }
284#endif
285}
286
287/* enable clocks needed by rotator block */
288static void enable_rot_clks(void)
289{
290 if (msm_rotator_dev->regulator)
291 regulator_enable(msm_rotator_dev->regulator);
292 if (msm_rotator_dev->core_clk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700293 clk_prepare_enable(msm_rotator_dev->core_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700294 if (msm_rotator_dev->pclk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700295 clk_prepare_enable(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700296}
297
298/* disable clocks needed by rotator block */
299static void disable_rot_clks(void)
300{
301 if (msm_rotator_dev->core_clk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700302 clk_disable_unprepare(msm_rotator_dev->core_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700303 if (msm_rotator_dev->pclk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700304 clk_disable_unprepare(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700305 if (msm_rotator_dev->regulator)
306 regulator_disable(msm_rotator_dev->regulator);
307}
308
309static void msm_rotator_rot_clk_work_f(struct work_struct *work)
310{
311 if (mutex_trylock(&msm_rotator_dev->rotator_lock)) {
312 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
313 disable_rot_clks();
314 msm_rotator_dev->rot_clk_state = CLK_DIS;
315 } else if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND)
316 msm_rotator_dev->rot_clk_state = CLK_DIS;
317 mutex_unlock(&msm_rotator_dev->rotator_lock);
318 }
319}
320
321static irqreturn_t msm_rotator_isr(int irq, void *dev_id)
322{
323 if (msm_rotator_dev->processing) {
324 msm_rotator_dev->processing = 0;
325 wake_up(&msm_rotator_dev->wq);
326 } else
327 printk(KERN_WARNING "%s: unexpected interrupt\n", DRIVER_NAME);
328
329 return IRQ_HANDLED;
330}
331
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700332static unsigned int tile_size(unsigned int src_width,
333 unsigned int src_height,
334 const struct tile_parm *tp)
335{
336 unsigned int tile_w, tile_h;
337 unsigned int row_num_w, row_num_h;
338 tile_w = tp->width * tp->row_tile_w;
339 tile_h = tp->height * tp->row_tile_h;
340 row_num_w = (src_width + tile_w - 1) / tile_w;
341 row_num_h = (src_height + tile_h - 1) / tile_h;
342 return ((row_num_w * row_num_h * tile_w * tile_h) + 8191) & ~8191;
343}
344
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700345static int get_bpp(int format)
346{
347 switch (format) {
348 case MDP_RGB_565:
349 case MDP_BGR_565:
350 return 2;
351
352 case MDP_XRGB_8888:
353 case MDP_ARGB_8888:
354 case MDP_RGBA_8888:
355 case MDP_BGRA_8888:
356 case MDP_RGBX_8888:
357 return 4;
358
359 case MDP_Y_CBCR_H2V2:
360 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700361 case MDP_Y_CB_CR_H2V2:
362 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530363 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700364 case MDP_Y_CRCB_H2V2_TILE:
365 case MDP_Y_CBCR_H2V2_TILE:
366 return 1;
367
368 case MDP_RGB_888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -0700369 case MDP_YCBCR_H1V1:
370 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700371 return 3;
372
373 case MDP_YCRYCB_H2V1:
374 return 2;/* YCrYCb interleave */
375
376 case MDP_Y_CRCB_H2V1:
377 case MDP_Y_CBCR_H2V1:
378 return 1;
379
380 default:
381 return -1;
382 }
383
384}
385
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700386static int msm_rotator_get_plane_sizes(uint32_t format, uint32_t w, uint32_t h,
387 struct msm_rotator_mem_planes *p)
388{
389 /*
390 * each row of samsung tile consists of two tiles in height
391 * and two tiles in width which means width should align to
392 * 64 x 2 bytes and height should align to 32 x 2 bytes.
393 * video decoder generate two tiles in width and one tile
394 * in height which ends up height align to 32 X 1 bytes.
395 */
396 const struct tile_parm tile = {64, 32, 2, 1};
397 int i;
398
399 if (p == NULL)
400 return -EINVAL;
401
402 if ((w > MSM_ROTATOR_MAX_W) || (h > MSM_ROTATOR_MAX_H))
403 return -ERANGE;
404
405 memset(p, 0, sizeof(*p));
406
407 switch (format) {
408 case MDP_XRGB_8888:
409 case MDP_ARGB_8888:
410 case MDP_RGBA_8888:
411 case MDP_BGRA_8888:
412 case MDP_RGBX_8888:
413 case MDP_RGB_888:
414 case MDP_RGB_565:
415 case MDP_BGR_565:
416 case MDP_YCRYCB_H2V1:
Kyong Hwa Baeebf19192012-05-09 16:31:05 -0700417 case MDP_YCBCR_H1V1:
418 case MDP_YCRCB_H1V1:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700419 p->num_planes = 1;
420 p->plane_size[0] = w * h * get_bpp(format);
421 break;
422 case MDP_Y_CRCB_H2V1:
423 case MDP_Y_CBCR_H2V1:
424 p->num_planes = 2;
425 p->plane_size[0] = w * h;
426 p->plane_size[1] = w * h;
427 break;
428 case MDP_Y_CBCR_H2V2:
429 case MDP_Y_CRCB_H2V2:
430 p->num_planes = 2;
431 p->plane_size[0] = w * h;
432 p->plane_size[1] = w * h / 2;
433 break;
434 case MDP_Y_CRCB_H2V2_TILE:
435 case MDP_Y_CBCR_H2V2_TILE:
436 p->num_planes = 2;
437 p->plane_size[0] = tile_size(w, h, &tile);
438 p->plane_size[1] = tile_size(w, h/2, &tile);
439 break;
440 case MDP_Y_CB_CR_H2V2:
441 case MDP_Y_CR_CB_H2V2:
442 p->num_planes = 3;
443 p->plane_size[0] = w * h;
444 p->plane_size[1] = (w / 2) * (h / 2);
445 p->plane_size[2] = (w / 2) * (h / 2);
446 break;
447 case MDP_Y_CR_CB_GH2V2:
448 p->num_planes = 3;
449 p->plane_size[0] = ALIGN(w, 16) * h;
450 p->plane_size[1] = ALIGN(w / 2, 16) * (h / 2);
451 p->plane_size[2] = ALIGN(w / 2, 16) * (h / 2);
452 break;
453 default:
454 return -EINVAL;
455 }
456
457 for (i = 0; i < p->num_planes; i++)
458 p->total_size += p->plane_size[i];
459
460 return 0;
461}
462
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463static int msm_rotator_ycxcx_h2v1(struct msm_rotator_img_info *info,
464 unsigned int in_paddr,
465 unsigned int out_paddr,
466 unsigned int use_imem,
467 int new_session,
468 unsigned int in_chroma_paddr,
469 unsigned int out_chroma_paddr)
470{
471 int bpp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472
473 if (info->src.format != info->dst.format)
474 return -EINVAL;
475
476 bpp = get_bpp(info->src.format);
477 if (bpp < 0)
478 return -ENOTTY;
479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700481 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700482 iowrite32(out_paddr +
483 ((info->dst_y * info->dst.width) + info->dst_x),
484 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700485 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700486 ((info->dst_y * info->dst.width) + info->dst_x),
487 MSM_ROTATOR_OUTP1_ADDR);
488
489 if (new_session) {
490 iowrite32(info->src.width |
491 info->src.width << 16,
492 MSM_ROTATOR_SRC_YSTRIDE1);
493 if (info->rotations & MDP_ROT_90)
494 iowrite32(info->dst.width |
495 info->dst.width*2 << 16,
496 MSM_ROTATOR_OUT_YSTRIDE1);
497 else
498 iowrite32(info->dst.width |
499 info->dst.width << 16,
500 MSM_ROTATOR_OUT_YSTRIDE1);
501 if (info->src.format == MDP_Y_CBCR_H2V1) {
502 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
503 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
504 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
505 MSM_ROTATOR_OUT_PACK_PATTERN1);
506 } else {
507 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
508 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
509 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
510 MSM_ROTATOR_OUT_PACK_PATTERN1);
511 }
512 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
513 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700514 1 << 8 | /* ROT_EN */
515 info->downscale_ratio << 2 | /* downscale v ratio */
516 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700517 MSM_ROTATOR_SUB_BLOCK_CFG);
518 iowrite32(0 << 29 | /* frame format 0 = linear */
519 (use_imem ? 0 : 1) << 22 | /* tile size */
520 2 << 19 | /* fetch planes 2 = pseudo */
521 0 << 18 | /* unpack align */
522 1 << 17 | /* unpack tight */
523 1 << 13 | /* unpack count 0=1 component */
524 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
525 0 << 8 | /* has alpha */
526 0 << 6 | /* alpha bits 3=8bits */
527 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
528 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
529 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
530 MSM_ROTATOR_SRC_FORMAT);
531 }
532
533 return 0;
534}
535
536static int msm_rotator_ycxcx_h2v2(struct msm_rotator_img_info *info,
537 unsigned int in_paddr,
538 unsigned int out_paddr,
539 unsigned int use_imem,
540 int new_session,
541 unsigned int in_chroma_paddr,
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700542 unsigned int out_chroma_paddr,
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700543 unsigned int in_chroma2_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544{
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700545 uint32_t dst_format;
546 int is_tile = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700547
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700548 switch (info->src.format) {
549 case MDP_Y_CRCB_H2V2_TILE:
550 is_tile = 1;
551 case MDP_Y_CR_CB_H2V2:
552 case MDP_Y_CR_CB_GH2V2:
553 case MDP_Y_CRCB_H2V2:
554 dst_format = MDP_Y_CRCB_H2V2;
555 break;
556 case MDP_Y_CBCR_H2V2_TILE:
557 is_tile = 1;
558 case MDP_Y_CB_CR_H2V2:
559 case MDP_Y_CBCR_H2V2:
560 dst_format = MDP_Y_CBCR_H2V2;
561 break;
562 default:
563 return -EINVAL;
564 }
565 if (info->dst.format != dst_format)
566 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700567
Adrian Salido-Moreno19caf152012-01-03 18:46:25 -0800568 /* rotator expects YCbCr for planar input format */
Mayank Chopra012a8e72012-04-11 10:41:13 +0530569 if ((info->src.format == MDP_Y_CR_CB_H2V2 ||
570 info->src.format == MDP_Y_CR_CB_GH2V2) &&
571 rotator_hw_revision < ROTATOR_REVISION_V2)
Adrian Salido-Moreno19caf152012-01-03 18:46:25 -0800572 swap(in_chroma_paddr, in_chroma2_paddr);
573
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700575 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
576 iowrite32(in_chroma2_paddr, MSM_ROTATOR_SRCP2_ADDR);
577
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700578 iowrite32(out_paddr +
579 ((info->dst_y * info->dst.width) + info->dst_x),
580 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700581 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 ((info->dst_y * info->dst.width)/2 + info->dst_x),
583 MSM_ROTATOR_OUTP1_ADDR);
584
585 if (new_session) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700586 if (in_chroma2_paddr) {
587 if (info->src.format == MDP_Y_CR_CB_GH2V2) {
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530588 iowrite32(ALIGN(info->src.width, 16) |
589 ALIGN((info->src.width / 2), 16) << 16,
590 MSM_ROTATOR_SRC_YSTRIDE1);
591 iowrite32(ALIGN((info->src.width / 2), 16),
592 MSM_ROTATOR_SRC_YSTRIDE2);
593 } else {
594 iowrite32(info->src.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700595 (info->src.width / 2) << 16,
596 MSM_ROTATOR_SRC_YSTRIDE1);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530597 iowrite32((info->src.width / 2),
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700598 MSM_ROTATOR_SRC_YSTRIDE2);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530599 }
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700600 } else {
601 iowrite32(info->src.width |
602 info->src.width << 16,
603 MSM_ROTATOR_SRC_YSTRIDE1);
604 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700605 iowrite32(info->dst.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700606 info->dst.width << 16,
607 MSM_ROTATOR_OUT_YSTRIDE1);
608
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700609 if (dst_format == MDP_Y_CBCR_H2V2) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
611 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
612 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
613 MSM_ROTATOR_OUT_PACK_PATTERN1);
614 } else {
615 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
616 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
617 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
618 MSM_ROTATOR_OUT_PACK_PATTERN1);
619 }
620 iowrite32((3 << 18) | /* chroma sampling 3=4:2:0 */
621 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700622 1 << 8 | /* ROT_EN */
623 info->downscale_ratio << 2 | /* downscale v ratio */
624 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700625 MSM_ROTATOR_SUB_BLOCK_CFG);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700626
627 iowrite32((is_tile ? 2 : 0) << 29 | /* frame format */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700628 (use_imem ? 0 : 1) << 22 | /* tile size */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700629 (in_chroma2_paddr ? 1 : 2) << 19 | /* fetch planes */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700630 0 << 18 | /* unpack align */
631 1 << 17 | /* unpack tight */
632 1 << 13 | /* unpack count 0=1 component */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700633 0 << 9 | /* src Bpp 0=1 byte ... */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634 0 << 8 | /* has alpha */
635 0 << 6 | /* alpha bits 3=8bits */
636 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
637 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
638 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
639 MSM_ROTATOR_SRC_FORMAT);
640 }
641 return 0;
642}
643
644static int msm_rotator_ycrycb(struct msm_rotator_img_info *info,
645 unsigned int in_paddr,
646 unsigned int out_paddr,
647 unsigned int use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +0530648 int new_session,
649 unsigned int out_chroma_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650{
651 int bpp;
Mayank Chopra732dcd62012-01-09 20:53:39 +0530652 uint32_t dst_format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700653
Mayank Chopra732dcd62012-01-09 20:53:39 +0530654 if (info->src.format == MDP_YCRYCB_H2V1)
655 dst_format = MDP_Y_CRCB_H2V1;
656 else
657 return -EINVAL;
658
659 if (info->dst.format != dst_format)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700660 return -EINVAL;
661
662 bpp = get_bpp(info->src.format);
663 if (bpp < 0)
664 return -ENOTTY;
665
666 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
667 iowrite32(out_paddr +
668 ((info->dst_y * info->dst.width) + info->dst_x),
669 MSM_ROTATOR_OUTP0_ADDR);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530670 iowrite32(out_chroma_paddr +
671 ((info->dst_y * info->dst.width)/2 + info->dst_x),
672 MSM_ROTATOR_OUTP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700673
674 if (new_session) {
Mayank Chopra732dcd62012-01-09 20:53:39 +0530675 iowrite32(info->src.width * bpp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676 MSM_ROTATOR_SRC_YSTRIDE1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530677 if (info->rotations & MDP_ROT_90)
678 iowrite32(info->dst.width |
679 (info->dst.width*2) << 16,
680 MSM_ROTATOR_OUT_YSTRIDE1);
681 else
682 iowrite32(info->dst.width |
683 (info->dst.width) << 16,
684 MSM_ROTATOR_OUT_YSTRIDE1);
685
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
687 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530688 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700689 MSM_ROTATOR_OUT_PACK_PATTERN1);
690 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
691 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700692 1 << 8 | /* ROT_EN */
693 info->downscale_ratio << 2 | /* downscale v ratio */
694 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695 MSM_ROTATOR_SUB_BLOCK_CFG);
696 iowrite32(0 << 29 | /* frame format 0 = linear */
697 (use_imem ? 0 : 1) << 22 | /* tile size */
698 0 << 19 | /* fetch planes 0=interleaved */
699 0 << 18 | /* unpack align */
700 1 << 17 | /* unpack tight */
701 3 << 13 | /* unpack count 0=1 component */
702 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
703 0 << 8 | /* has alpha */
704 0 << 6 | /* alpha bits 3=8bits */
705 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
706 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
707 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
708 MSM_ROTATOR_SRC_FORMAT);
709 }
710
711 return 0;
712}
713
714static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
715 unsigned int in_paddr,
716 unsigned int out_paddr,
717 unsigned int use_imem,
718 int new_session)
719{
720 int bpp, abits, rbits, gbits, bbits;
721
722 if (info->src.format != info->dst.format)
723 return -EINVAL;
724
725 bpp = get_bpp(info->src.format);
726 if (bpp < 0)
727 return -ENOTTY;
728
729 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
730 iowrite32(out_paddr +
731 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
732 MSM_ROTATOR_OUTP0_ADDR);
733
734 if (new_session) {
735 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
736 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
737 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
738 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700739 1 << 8 | /* ROT_EN */
740 info->downscale_ratio << 2 | /* downscale v ratio */
741 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700742 MSM_ROTATOR_SUB_BLOCK_CFG);
743 switch (info->src.format) {
744 case MDP_RGB_565:
745 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
746 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
747 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
748 MSM_ROTATOR_OUT_PACK_PATTERN1);
749 abits = 0;
750 rbits = COMPONENT_5BITS;
751 gbits = COMPONENT_6BITS;
752 bbits = COMPONENT_5BITS;
753 break;
754
755 case MDP_BGR_565:
756 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
757 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
758 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
759 MSM_ROTATOR_OUT_PACK_PATTERN1);
760 abits = 0;
761 rbits = COMPONENT_5BITS;
762 gbits = COMPONENT_6BITS;
763 bbits = COMPONENT_5BITS;
764 break;
765
766 case MDP_RGB_888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -0700767 case MDP_YCBCR_H1V1:
768 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700769 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
770 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
771 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
772 MSM_ROTATOR_OUT_PACK_PATTERN1);
773 abits = 0;
774 rbits = COMPONENT_8BITS;
775 gbits = COMPONENT_8BITS;
776 bbits = COMPONENT_8BITS;
777 break;
778
779 case MDP_ARGB_8888:
780 case MDP_RGBA_8888:
781 case MDP_XRGB_8888:
782 case MDP_RGBX_8888:
783 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
784 CLR_B, 8),
785 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
786 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
787 CLR_B, 8),
788 MSM_ROTATOR_OUT_PACK_PATTERN1);
789 abits = COMPONENT_8BITS;
790 rbits = COMPONENT_8BITS;
791 gbits = COMPONENT_8BITS;
792 bbits = COMPONENT_8BITS;
793 break;
794
795 case MDP_BGRA_8888:
796 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
797 CLR_R, 8),
798 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
799 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
800 CLR_R, 8),
801 MSM_ROTATOR_OUT_PACK_PATTERN1);
802 abits = COMPONENT_8BITS;
803 rbits = COMPONENT_8BITS;
804 gbits = COMPONENT_8BITS;
805 bbits = COMPONENT_8BITS;
806 break;
807
808 default:
809 return -EINVAL;
810 }
811 iowrite32(0 << 29 | /* frame format 0 = linear */
812 (use_imem ? 0 : 1) << 22 | /* tile size */
813 0 << 19 | /* fetch planes 0=interleaved */
814 0 << 18 | /* unpack align */
815 1 << 17 | /* unpack tight */
816 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
817 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
818 (abits ? 1 : 0) << 8 | /* has alpha */
819 abits << 6 | /* alpha bits 3=8bits */
820 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
821 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
822 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
823 MSM_ROTATOR_SRC_FORMAT);
824 }
825
826 return 0;
827}
828
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700829static int get_img(struct msmfb_data *fbd, int domain,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700830 unsigned long *start, unsigned long *len, struct file **p_file,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700831 int *p_need, struct ion_handle **p_ihdl, unsigned int secure)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700832{
833 int ret = 0;
834#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700835 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700836 int put_needed, fb_num;
837#endif
838#ifdef CONFIG_ANDROID_PMEM
839 unsigned long vstart;
840#endif
841
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800842 *p_need = 0;
843
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700845 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
846 file = fget_light(fbd->memory_id, &put_needed);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700847 if (file == NULL) {
848 pr_err("fget_light returned NULL\n");
Naseer Ahmed18018602011-10-25 13:32:58 -0700849 return -EINVAL;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700850 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851
Naseer Ahmed18018602011-10-25 13:32:58 -0700852 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
853 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700854 if (get_fb_phys_info(start, len, fb_num,
855 ROTATOR_SUBSYSTEM_ID)) {
856 pr_err("get_fb_phys_info() failed\n");
Naseer Ahmed18018602011-10-25 13:32:58 -0700857 ret = -1;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700858 } else {
Naseer Ahmed18018602011-10-25 13:32:58 -0700859 *p_file = file;
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800860 *p_need = put_needed;
861 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700862 } else {
863 pr_err("invalid FB_MAJOR failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864 ret = -1;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700865 }
Naseer Ahmed18018602011-10-25 13:32:58 -0700866 if (ret)
867 fput_light(file, put_needed);
868 return ret;
869 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700871
872#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700873 return msm_rotator_iommu_map_buf(fbd->memory_id, domain, start,
874 len, p_ihdl, secure);
Naseer Ahmed18018602011-10-25 13:32:58 -0700875#endif
876#ifdef CONFIG_ANDROID_PMEM
877 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
878 return 0;
879 else
880 return -ENOMEM;
881#endif
882
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700883}
884
Olav Hauganef95ae32012-05-15 09:50:30 -0700885static void put_img(struct file *p_file, struct ion_handle *p_ihdl,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700886 int domain, unsigned int secure)
Naseer Ahmed18018602011-10-25 13:32:58 -0700887{
888#ifdef CONFIG_ANDROID_PMEM
889 if (p_file != NULL)
890 put_pmem_file(p_file);
891#endif
Olav Hauganef95ae32012-05-15 09:50:30 -0700892
Naseer Ahmed18018602011-10-25 13:32:58 -0700893#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700894 if (!IS_ERR_OR_NULL(p_ihdl)) {
895 pr_debug("%s(): p_ihdl %p\n", __func__, p_ihdl);
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700896 if (rot_iommu_split_domain) {
897 if (!secure)
898 ion_unmap_iommu(msm_rotator_dev->client,
899 p_ihdl, domain, GEN_POOL);
900 } else {
901 ion_unmap_iommu(msm_rotator_dev->client,
902 p_ihdl, ROTATOR_SRC_DOMAIN, GEN_POOL);
903 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700904
Naseer Ahmed18018602011-10-25 13:32:58 -0700905 ion_free(msm_rotator_dev->client, p_ihdl);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700906 }
Naseer Ahmed18018602011-10-25 13:32:58 -0700907#endif
908}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909static int msm_rotator_do_rotate(unsigned long arg)
910{
Naseer Ahmed18018602011-10-25 13:32:58 -0700911 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912 struct msm_rotator_data_info info;
913 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700914 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700915 int use_imem = 0, rc = 0, s;
916 struct file *srcp0_file = NULL, *dstp0_file = NULL;
917 struct file *srcp1_file = NULL, *dstp1_file = NULL;
918 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
919 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800920 int ps0_need, p_need;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700922 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700923 struct msm_rotator_img_info *img_info;
924 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700925
926 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
927 return -EFAULT;
928
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700929 mutex_lock(&msm_rotator_dev->rotator_lock);
930 for (s = 0; s < MAX_SESSIONS; s++)
931 if ((msm_rotator_dev->img_info[s] != NULL) &&
932 (info.session_id ==
933 (unsigned int)msm_rotator_dev->img_info[s]
934 ))
935 break;
936
937 if (s == MAX_SESSIONS) {
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -0700938 pr_err("%s() : Attempt to use invalid session_id %d\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700939 __func__, s);
940 rc = -EINVAL;
941 goto do_rotate_unlock_mutex;
942 }
943
944 if (msm_rotator_dev->img_info[s]->enable == 0) {
945 dev_dbg(msm_rotator_dev->device,
946 "%s() : Session_id %d not enabled \n",
947 __func__, s);
948 rc = -EINVAL;
949 goto do_rotate_unlock_mutex;
950 }
951
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700952 img_info = msm_rotator_dev->img_info[s];
953 if (msm_rotator_get_plane_sizes(img_info->src.format,
954 img_info->src.width,
955 img_info->src.height,
956 &src_planes)) {
957 pr_err("%s: invalid src format\n", __func__);
958 rc = -EINVAL;
959 goto do_rotate_unlock_mutex;
960 }
961 if (msm_rotator_get_plane_sizes(img_info->dst.format,
962 img_info->dst.width,
963 img_info->dst.height,
964 &dst_planes)) {
965 pr_err("%s: invalid dst format\n", __func__);
966 rc = -EINVAL;
967 goto do_rotate_unlock_mutex;
968 }
969
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700970 rc = get_img(&info.src, ROTATOR_SRC_DOMAIN, (unsigned long *)&in_paddr,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700971 (unsigned long *)&src_len, &srcp0_file, &ps0_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700972 &srcp0_ihdl, 0);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700973 if (rc) {
974 pr_err("%s: in get_img() failed id=0x%08x\n",
975 DRIVER_NAME, info.src.memory_id);
976 goto do_rotate_unlock_mutex;
977 }
978
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700979 rc = get_img(&info.dst, ROTATOR_DST_DOMAIN, (unsigned long *)&out_paddr,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700980 (unsigned long *)&dst_len, &dstp0_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700981 &dstp0_ihdl, img_info->secure);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700982 if (rc) {
983 pr_err("%s: out get_img() failed id=0x%08x\n",
984 DRIVER_NAME, info.dst.memory_id);
985 goto do_rotate_unlock_mutex;
986 }
987
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988 format = msm_rotator_dev->img_info[s]->src.format;
989 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700990 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
991 (src_planes.num_planes == 2)) {
992 if (checkoffset(info.src.offset,
993 src_planes.plane_size[0],
994 src_len)) {
995 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
996 __func__, src_len, info.src.offset);
997 rc = -ERANGE;
998 goto do_rotate_unlock_mutex;
999 }
1000 if (checkoffset(info.dst.offset,
1001 dst_planes.plane_size[0],
1002 dst_len)) {
1003 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
1004 __func__, dst_len, info.dst.offset);
1005 rc = -ERANGE;
1006 goto do_rotate_unlock_mutex;
1007 }
1008
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001009 rc = get_img(&info.src_chroma, ROTATOR_SRC_DOMAIN,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001010 (unsigned long *)&in_chroma_paddr,
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001011 (unsigned long *)&src_len, &srcp1_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001012 &srcp1_ihdl, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001013 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001014 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001015 DRIVER_NAME, info.src_chroma.memory_id);
1016 goto do_rotate_unlock_mutex;
1017 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001018
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001019 rc = get_img(&info.dst_chroma, ROTATOR_DST_DOMAIN,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001020 (unsigned long *)&out_chroma_paddr,
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001021 (unsigned long *)&dst_len, &dstp1_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001022 &dstp1_ihdl, img_info->secure);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001023 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001024 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001026 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001027 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001028
1029 if (checkoffset(info.src_chroma.offset,
1030 src_planes.plane_size[1],
1031 src_len)) {
1032 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
1033 __func__, src_len, info.src_chroma.offset);
1034 rc = -ERANGE;
1035 goto do_rotate_unlock_mutex;
1036 }
1037
1038 if (checkoffset(info.dst_chroma.offset,
1039 src_planes.plane_size[1],
1040 dst_len)) {
1041 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
1042 __func__, dst_len, info.dst_chroma.offset);
1043 rc = -ERANGE;
1044 goto do_rotate_unlock_mutex;
1045 }
1046
1047 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001048 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001049 } else {
1050 if (checkoffset(info.src.offset,
1051 src_planes.total_size,
1052 src_len)) {
1053 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
1054 __func__, src_len, info.src.offset);
1055 rc = -ERANGE;
1056 goto do_rotate_unlock_mutex;
1057 }
1058 if (checkoffset(info.dst.offset,
1059 dst_planes.total_size,
1060 dst_len)) {
1061 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
1062 __func__, dst_len, info.dst.offset);
1063 rc = -ERANGE;
1064 goto do_rotate_unlock_mutex;
1065 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001066 }
1067
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001068 in_paddr += info.src.offset;
1069 out_paddr += info.dst.offset;
1070
1071 if (!in_chroma_paddr && src_planes.num_planes >= 2)
1072 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
1073 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
1074 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
1075 if (src_planes.num_planes >= 3)
1076 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
1077
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001078 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
1079 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
1080 enable_rot_clks();
1081 msm_rotator_dev->rot_clk_state = CLK_EN;
1082 }
1083 enable_irq(msm_rotator_dev->irq);
1084
1085#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1086 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
1087#else
1088 use_imem = 0;
1089#endif
1090 /*
1091 * workaround for a hardware bug. rotator hardware hangs when we
1092 * use write burst beat size 16 on 128X128 tile fetch mode. As a
1093 * temporary fix use 0x42 for BURST_SIZE when imem used.
1094 */
1095 if (use_imem)
1096 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
1097
1098 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
1099 << 16) |
1100 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
1101 MSM_ROTATOR_SRC_SIZE);
1102 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
1103 << 16) |
1104 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
1105 MSM_ROTATOR_SRC_XY);
1106 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
1107 << 16) |
1108 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
1109 MSM_ROTATOR_SRC_IMAGE_SIZE);
1110
1111 switch (format) {
1112 case MDP_RGB_565:
1113 case MDP_BGR_565:
1114 case MDP_RGB_888:
1115 case MDP_ARGB_8888:
1116 case MDP_RGBA_8888:
1117 case MDP_XRGB_8888:
1118 case MDP_BGRA_8888:
1119 case MDP_RGBX_8888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -07001120 case MDP_YCBCR_H1V1:
1121 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001122 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
1123 in_paddr, out_paddr,
1124 use_imem,
1125 msm_rotator_dev->last_session_idx
1126 != s);
1127 break;
1128 case MDP_Y_CBCR_H2V2:
1129 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001130 case MDP_Y_CB_CR_H2V2:
1131 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301132 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001133 case MDP_Y_CRCB_H2V2_TILE:
1134 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001135 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1136 in_paddr, out_paddr, use_imem,
1137 msm_rotator_dev->last_session_idx
1138 != s,
1139 in_chroma_paddr,
1140 out_chroma_paddr,
1141 in_chroma2_paddr);
1142 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001143 case MDP_Y_CBCR_H2V1:
1144 case MDP_Y_CRCB_H2V1:
1145 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1146 in_paddr, out_paddr, use_imem,
1147 msm_rotator_dev->last_session_idx
1148 != s,
1149 in_chroma_paddr,
1150 out_chroma_paddr);
1151 break;
1152 case MDP_YCRYCB_H2V1:
1153 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1154 in_paddr, out_paddr, use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +05301155 msm_rotator_dev->last_session_idx != s,
1156 out_chroma_paddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001157 break;
1158 default:
1159 rc = -EINVAL;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001160 pr_err("%s(): Unsupported format %u\n", __func__, format);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001161 goto do_rotate_exit;
1162 }
1163
1164 if (rc != 0) {
1165 msm_rotator_dev->last_session_idx = INVALID_SESSION;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001166 pr_err("%s(): Invalid session error\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001167 goto do_rotate_exit;
1168 }
1169
1170 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1171
1172 msm_rotator_dev->processing = 1;
1173 iowrite32(0x1, MSM_ROTATOR_START);
1174
1175 wait_event(msm_rotator_dev->wq,
1176 (msm_rotator_dev->processing == 0));
1177 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001178 if ((status & 0x03) != 0x01) {
1179 pr_err("%s(): AXI Bus Error, issuing SW_RESET\n", __func__);
1180 iowrite32(0x1, MSM_ROTATOR_SW_RESET);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001181 rc = -EFAULT;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001182 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1184 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1185
1186do_rotate_exit:
1187 disable_irq(msm_rotator_dev->irq);
1188#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1189 msm_rotator_imem_free(ROTATOR_REQUEST);
1190#endif
1191 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001192do_rotate_unlock_mutex:
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001193 put_img(dstp1_file, dstp1_ihdl, ROTATOR_DST_DOMAIN,
1194 msm_rotator_dev->img_info[s]->secure);
1195 put_img(srcp1_file, srcp1_ihdl, ROTATOR_SRC_DOMAIN, 0);
1196 put_img(dstp0_file, dstp0_ihdl, ROTATOR_DST_DOMAIN,
1197 msm_rotator_dev->img_info[s]->secure);
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001198
1199 /* only source may use frame buffer */
1200 if (info.src.flags & MDP_MEMORY_ID_TYPE_FB)
1201 fput_light(srcp0_file, ps0_need);
1202 else
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001203 put_img(srcp0_file, srcp0_ihdl, ROTATOR_SRC_DOMAIN, 0);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001204 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1206 __func__, rc);
1207 return rc;
1208}
1209
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001210static void msm_rotator_set_perf_level(u32 wh, u32 is_rgb)
1211{
1212 u32 perf_level;
1213
1214 if (is_rgb)
1215 perf_level = 1;
1216 else if (wh <= (640 * 480))
1217 perf_level = 2;
1218 else if (wh <= (736 * 1280))
1219 perf_level = 3;
1220 else
1221 perf_level = 4;
1222
1223#ifdef CONFIG_MSM_BUS_SCALING
1224 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1225 perf_level);
1226#endif
1227
1228}
1229
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001230static int msm_rotator_start(unsigned long arg,
1231 struct msm_rotator_fd_info *fd_info)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001232{
1233 struct msm_rotator_img_info info;
1234 int rc = 0;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001235 int s, is_rgb = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001236 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001237 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238
1239 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1240 return -EFAULT;
1241
1242 if ((info.rotations > MSM_ROTATOR_MAX_ROT) ||
1243 (info.src.height > MSM_ROTATOR_MAX_H) ||
1244 (info.src.width > MSM_ROTATOR_MAX_W) ||
1245 (info.dst.height > MSM_ROTATOR_MAX_H) ||
1246 (info.dst.width > MSM_ROTATOR_MAX_W) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001247 (info.downscale_ratio > MAX_DOWNSCALE_RATIO)) {
1248 pr_err("%s: Invalid parameters\n", __func__);
1249 return -EINVAL;
1250 }
1251
1252 if (info.rotations & MDP_ROT_90) {
1253 dst_w = info.src_rect.h >> info.downscale_ratio;
1254 dst_h = info.src_rect.w >> info.downscale_ratio;
1255 } else {
1256 dst_w = info.src_rect.w >> info.downscale_ratio;
1257 dst_h = info.src_rect.h >> info.downscale_ratio;
1258 }
1259
1260 if (checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001261 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1262 checkoffset(info.dst_x, dst_w, info.dst.width) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001263 checkoffset(info.dst_y, dst_h, info.dst.height)) {
1264 pr_err("%s: Invalid src or dst rect\n", __func__);
1265 return -ERANGE;
1266 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001267
1268 switch (info.src.format) {
1269 case MDP_RGB_565:
1270 case MDP_BGR_565:
1271 case MDP_RGB_888:
1272 case MDP_ARGB_8888:
1273 case MDP_RGBA_8888:
1274 case MDP_XRGB_8888:
1275 case MDP_RGBX_8888:
1276 case MDP_BGRA_8888:
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001277 is_rgb = 1;
Mayank Chopra012a8e72012-04-11 10:41:13 +05301278 info.dst.format = info.src.format;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001279 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001280 case MDP_Y_CBCR_H2V2:
1281 case MDP_Y_CRCB_H2V2:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301282 case MDP_Y_CBCR_H2V1:
1283 case MDP_Y_CRCB_H2V1:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -07001284 case MDP_YCBCR_H1V1:
1285 case MDP_YCRCB_H1V1:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301286 info.dst.format = info.src.format;
1287 break;
1288 case MDP_YCRYCB_H2V1:
1289 info.dst.format = MDP_Y_CRCB_H2V1;
1290 break;
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001291 case MDP_Y_CB_CR_H2V2:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301292 case MDP_Y_CBCR_H2V2_TILE:
1293 info.dst.format = MDP_Y_CBCR_H2V2;
1294 break;
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001295 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301296 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001297 case MDP_Y_CRCB_H2V2_TILE:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301298 info.dst.format = MDP_Y_CRCB_H2V2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001299 break;
1300 default:
1301 return -EINVAL;
1302 }
1303
1304 mutex_lock(&msm_rotator_dev->rotator_lock);
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001305
1306 msm_rotator_set_perf_level((info.src.width*info.src.height), is_rgb);
1307
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001308 for (s = 0; s < MAX_SESSIONS; s++) {
1309 if ((msm_rotator_dev->img_info[s] != NULL) &&
1310 (info.session_id ==
1311 (unsigned int)msm_rotator_dev->img_info[s]
1312 )) {
1313 *(msm_rotator_dev->img_info[s]) = info;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001314 msm_rotator_dev->fd_info[s] = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315
1316 if (msm_rotator_dev->last_session_idx == s)
1317 msm_rotator_dev->last_session_idx =
1318 INVALID_SESSION;
1319 break;
1320 }
1321
1322 if ((msm_rotator_dev->img_info[s] == NULL) &&
1323 (first_free_index ==
1324 INVALID_SESSION))
1325 first_free_index = s;
1326 }
1327
1328 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1329 /* allocate a session id */
1330 msm_rotator_dev->img_info[first_free_index] =
1331 kzalloc(sizeof(struct msm_rotator_img_info),
1332 GFP_KERNEL);
1333 if (!msm_rotator_dev->img_info[first_free_index]) {
1334 printk(KERN_ERR "%s : unable to alloc mem\n",
1335 __func__);
1336 rc = -ENOMEM;
1337 goto rotator_start_exit;
1338 }
1339 info.session_id = (unsigned int)
1340 msm_rotator_dev->img_info[first_free_index];
1341 *(msm_rotator_dev->img_info[first_free_index]) = info;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001342 msm_rotator_dev->fd_info[first_free_index] = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001343 } else if (s == MAX_SESSIONS) {
1344 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1345 __func__);
1346 rc = -EBUSY;
1347 }
1348
Adrian Salido-Morenoc5639952012-04-20 19:07:58 -07001349 if (rc == 0 && copy_to_user((void __user *)arg, &info, sizeof(info)))
1350 rc = -EFAULT;
1351
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001352rotator_start_exit:
1353 mutex_unlock(&msm_rotator_dev->rotator_lock);
1354
1355 return rc;
1356}
1357
1358static int msm_rotator_finish(unsigned long arg)
1359{
1360 int rc = 0;
1361 int s;
1362 unsigned int session_id;
1363
1364 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1365 return -EFAULT;
1366
1367 mutex_lock(&msm_rotator_dev->rotator_lock);
1368 for (s = 0; s < MAX_SESSIONS; s++) {
1369 if ((msm_rotator_dev->img_info[s] != NULL) &&
1370 (session_id ==
1371 (unsigned int)msm_rotator_dev->img_info[s])) {
1372 if (msm_rotator_dev->last_session_idx == s)
1373 msm_rotator_dev->last_session_idx =
1374 INVALID_SESSION;
1375 kfree(msm_rotator_dev->img_info[s]);
1376 msm_rotator_dev->img_info[s] = NULL;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001377 msm_rotator_dev->fd_info[s] = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001378 break;
1379 }
1380 }
1381
1382 if (s == MAX_SESSIONS)
1383 rc = -EINVAL;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001384#ifdef CONFIG_MSM_BUS_SCALING
1385 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1386 0);
1387#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001388 mutex_unlock(&msm_rotator_dev->rotator_lock);
1389 return rc;
1390}
1391
1392static int
1393msm_rotator_open(struct inode *inode, struct file *filp)
1394{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001395 struct msm_rotator_fd_info *tmp, *fd_info = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001396 int i;
1397
1398 if (filp->private_data)
1399 return -EBUSY;
1400
1401 mutex_lock(&msm_rotator_dev->rotator_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001402 for (i = 0; i < MAX_SESSIONS; i++) {
1403 if (msm_rotator_dev->fd_info[i] == NULL)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001404 break;
1405 }
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001406
1407 if (i == MAX_SESSIONS) {
1408 mutex_unlock(&msm_rotator_dev->rotator_lock);
1409 return -EBUSY;
1410 }
1411
1412 list_for_each_entry(tmp, &msm_rotator_dev->fd_list, list) {
1413 if (tmp->pid == current->pid) {
1414 fd_info = tmp;
1415 break;
1416 }
1417 }
1418
1419 if (!fd_info) {
1420 fd_info = kzalloc(sizeof(*fd_info), GFP_KERNEL);
1421 if (!fd_info) {
1422 mutex_unlock(&msm_rotator_dev->rotator_lock);
1423 pr_err("%s: insufficient memory to alloc resources\n",
1424 __func__);
1425 return -ENOMEM;
1426 }
1427 list_add(&fd_info->list, &msm_rotator_dev->fd_list);
1428 fd_info->pid = current->pid;
1429 }
1430 fd_info->ref_cnt++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001431 mutex_unlock(&msm_rotator_dev->rotator_lock);
1432
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001433 filp->private_data = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001434
1435 return 0;
1436}
1437
1438static int
1439msm_rotator_close(struct inode *inode, struct file *filp)
1440{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001441 struct msm_rotator_fd_info *fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001442 int s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001443
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001444 fd_info = (struct msm_rotator_fd_info *)filp->private_data;
1445
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001446 mutex_lock(&msm_rotator_dev->rotator_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001447 if (--fd_info->ref_cnt > 0) {
1448 mutex_unlock(&msm_rotator_dev->rotator_lock);
1449 return 0;
1450 }
1451
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001452 for (s = 0; s < MAX_SESSIONS; s++) {
1453 if (msm_rotator_dev->img_info[s] != NULL &&
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001454 msm_rotator_dev->fd_info[s] == fd_info) {
1455 pr_debug("%s: freeing rotator session %p (pid %d)\n",
1456 __func__, msm_rotator_dev->img_info[s],
1457 fd_info->pid);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001458 kfree(msm_rotator_dev->img_info[s]);
1459 msm_rotator_dev->img_info[s] = NULL;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001460 msm_rotator_dev->fd_info[s] = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001461 if (msm_rotator_dev->last_session_idx == s)
1462 msm_rotator_dev->last_session_idx =
1463 INVALID_SESSION;
1464 }
1465 }
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001466 list_del(&fd_info->list);
1467 kfree(fd_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001468 mutex_unlock(&msm_rotator_dev->rotator_lock);
1469
1470 return 0;
1471}
1472
1473static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1474 unsigned long arg)
1475{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001476 struct msm_rotator_fd_info *fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001477
1478 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1479 return -ENOTTY;
1480
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001481 fd_info = (struct msm_rotator_fd_info *)file->private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001482
1483 switch (cmd) {
1484 case MSM_ROTATOR_IOCTL_START:
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001485 return msm_rotator_start(arg, fd_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001486 case MSM_ROTATOR_IOCTL_ROTATE:
1487 return msm_rotator_do_rotate(arg);
1488 case MSM_ROTATOR_IOCTL_FINISH:
1489 return msm_rotator_finish(arg);
1490
1491 default:
1492 dev_dbg(msm_rotator_dev->device,
1493 "unexpected IOCTL %d\n", cmd);
1494 return -ENOTTY;
1495 }
1496}
1497
1498static const struct file_operations msm_rotator_fops = {
1499 .owner = THIS_MODULE,
1500 .open = msm_rotator_open,
1501 .release = msm_rotator_close,
1502 .unlocked_ioctl = msm_rotator_ioctl,
1503};
1504
1505static int __devinit msm_rotator_probe(struct platform_device *pdev)
1506{
1507 int rc = 0;
1508 struct resource *res;
1509 struct msm_rotator_platform_data *pdata = NULL;
1510 int i, number_of_clks;
1511 uint32_t ver;
1512
1513 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1514 if (!msm_rotator_dev) {
1515 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1516 __func__);
1517 return -ENOMEM;
1518 }
1519 for (i = 0; i < MAX_SESSIONS; i++)
1520 msm_rotator_dev->img_info[i] = NULL;
1521 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1522
1523 pdata = pdev->dev.platform_data;
1524 number_of_clks = pdata->number_of_clocks;
Olav Hauganef95ae32012-05-15 09:50:30 -07001525 rot_iommu_split_domain = pdata->rot_iommu_split_domain;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001526
1527 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1528 mutex_init(&msm_rotator_dev->imem_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001529 INIT_LIST_HEAD(&msm_rotator_dev->fd_list);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001530 msm_rotator_dev->imem_clk_state = CLK_DIS;
1531 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1532 msm_rotator_imem_clk_work_f);
1533 msm_rotator_dev->imem_clk = NULL;
1534 msm_rotator_dev->pdev = pdev;
1535
1536 msm_rotator_dev->core_clk = NULL;
1537 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001538
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001539#ifdef CONFIG_MSM_BUS_SCALING
1540 if (!msm_rotator_dev->bus_client_handle && pdata &&
1541 pdata->bus_scale_table) {
1542 msm_rotator_dev->bus_client_handle =
1543 msm_bus_scale_register_client(
1544 pdata->bus_scale_table);
1545 if (!msm_rotator_dev->bus_client_handle) {
1546 pr_err("%s not able to get bus scale handle\n",
1547 __func__);
1548 }
1549 }
1550#endif
1551
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001552 for (i = 0; i < number_of_clks; i++) {
1553 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1554 msm_rotator_dev->imem_clk =
1555 clk_get(&msm_rotator_dev->pdev->dev,
1556 pdata->rotator_clks[i].clk_name);
1557 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1558 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1559 msm_rotator_dev->imem_clk = NULL;
1560 printk(KERN_ERR "%s: cannot get imem_clk "
1561 "rc=%d\n", DRIVER_NAME, rc);
1562 goto error_imem_clk;
1563 }
1564 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001565 clk_set_rate(msm_rotator_dev->imem_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001566 pdata->rotator_clks[i].clk_rate);
1567 }
1568 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1569 msm_rotator_dev->pclk =
1570 clk_get(&msm_rotator_dev->pdev->dev,
1571 pdata->rotator_clks[i].clk_name);
1572 if (IS_ERR(msm_rotator_dev->pclk)) {
1573 rc = PTR_ERR(msm_rotator_dev->pclk);
1574 msm_rotator_dev->pclk = NULL;
1575 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1576 DRIVER_NAME, rc);
1577 goto error_pclk;
1578 }
1579
1580 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001581 clk_set_rate(msm_rotator_dev->pclk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001582 pdata->rotator_clks[i].clk_rate);
1583 }
1584
1585 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1586 msm_rotator_dev->core_clk =
1587 clk_get(&msm_rotator_dev->pdev->dev,
1588 pdata->rotator_clks[i].clk_name);
1589 if (IS_ERR(msm_rotator_dev->core_clk)) {
1590 rc = PTR_ERR(msm_rotator_dev->core_clk);
1591 msm_rotator_dev->core_clk = NULL;
1592 printk(KERN_ERR "%s: cannot get core clk "
1593 "rc=%d\n", DRIVER_NAME, rc);
1594 goto error_core_clk;
1595 }
1596
1597 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001598 clk_set_rate(msm_rotator_dev->core_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001599 pdata->rotator_clks[i].clk_rate);
1600 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001601 }
1602
Matt Wagantall316f2fc2012-05-03 20:41:42 -07001603 msm_rotator_dev->regulator = regulator_get(&msm_rotator_dev->pdev->dev,
1604 "vdd");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001605 if (IS_ERR(msm_rotator_dev->regulator))
1606 msm_rotator_dev->regulator = NULL;
1607
1608 msm_rotator_dev->rot_clk_state = CLK_DIS;
1609 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1610 msm_rotator_rot_clk_work_f);
1611
1612 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001613#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1614 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1615#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001616 platform_set_drvdata(pdev, msm_rotator_dev);
1617
1618
1619 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1620 if (!res) {
1621 printk(KERN_ALERT
1622 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1623 rc = -ENODEV;
1624 goto error_get_resource;
1625 }
1626 msm_rotator_dev->io_base = ioremap(res->start,
1627 resource_size(res));
1628
1629#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1630 if (msm_rotator_dev->imem_clk)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001631 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001632#endif
1633 enable_rot_clks();
1634 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1635 disable_rot_clks();
1636
1637#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1638 if (msm_rotator_dev->imem_clk)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001639 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001640#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001641 if (ver != pdata->hardware_version_number)
Mayank Chopra012a8e72012-04-11 10:41:13 +05301642 pr_debug("%s: invalid HW version ver 0x%x\n",
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -07001643 DRIVER_NAME, ver);
Naseer Ahmed18018602011-10-25 13:32:58 -07001644
Mayank Chopra012a8e72012-04-11 10:41:13 +05301645 rotator_hw_revision = ver;
1646 rotator_hw_revision >>= 16; /* bit 31:16 */
1647 rotator_hw_revision &= 0xff;
1648
1649 pr_info("%s: rotator_hw_revision=%x\n",
1650 __func__, rotator_hw_revision);
1651
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001652 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1653 if (msm_rotator_dev->irq < 0) {
1654 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1655 DRIVER_NAME);
1656 rc = -ENODEV;
1657 goto error_get_irq;
1658 }
1659 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1660 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1661 if (rc) {
1662 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1663 goto error_get_irq;
1664 }
1665 /* we enable the IRQ when we need it in the ioctl */
1666 disable_irq(msm_rotator_dev->irq);
1667
1668 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1669 if (rc < 0) {
1670 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1671 __func__, rc);
1672 goto error_get_irq;
1673 }
1674
1675 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1676 if (IS_ERR(msm_rotator_dev->class)) {
1677 rc = PTR_ERR(msm_rotator_dev->class);
1678 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1679 DRIVER_NAME, rc);
1680 goto error_class_create;
1681 }
1682
1683 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1684 msm_rotator_dev->dev_num, NULL,
1685 DRIVER_NAME);
1686 if (IS_ERR(msm_rotator_dev->device)) {
1687 rc = PTR_ERR(msm_rotator_dev->device);
1688 printk(KERN_ERR "%s: device_create failed %d\n",
1689 DRIVER_NAME, rc);
1690 goto error_class_device_create;
1691 }
1692
1693 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1694 rc = cdev_add(&msm_rotator_dev->cdev,
1695 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1696 1);
1697 if (rc < 0) {
1698 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1699 goto error_cdev_add;
1700 }
1701
1702 init_waitqueue_head(&msm_rotator_dev->wq);
1703
1704 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1705 return rc;
1706
1707error_cdev_add:
1708 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1709error_class_device_create:
1710 class_destroy(msm_rotator_dev->class);
1711error_class_create:
1712 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1713error_get_irq:
1714 iounmap(msm_rotator_dev->io_base);
1715error_get_resource:
1716 mutex_destroy(&msm_rotator_dev->rotator_lock);
1717 if (msm_rotator_dev->regulator)
1718 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001719 clk_put(msm_rotator_dev->core_clk);
1720error_core_clk:
1721 clk_put(msm_rotator_dev->pclk);
1722error_pclk:
1723 if (msm_rotator_dev->imem_clk)
1724 clk_put(msm_rotator_dev->imem_clk);
1725error_imem_clk:
1726 mutex_destroy(&msm_rotator_dev->imem_lock);
1727 kfree(msm_rotator_dev);
1728 return rc;
1729}
1730
1731static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1732{
1733 int i;
1734
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001735#ifdef CONFIG_MSM_BUS_SCALING
1736 msm_bus_scale_unregister_client(msm_rotator_dev->bus_client_handle);
1737#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001738 free_irq(msm_rotator_dev->irq, NULL);
1739 mutex_destroy(&msm_rotator_dev->rotator_lock);
1740 cdev_del(&msm_rotator_dev->cdev);
1741 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1742 class_destroy(msm_rotator_dev->class);
1743 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1744 iounmap(msm_rotator_dev->io_base);
1745 if (msm_rotator_dev->imem_clk) {
1746 if (msm_rotator_dev->imem_clk_state == CLK_EN)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001747 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001748 clk_put(msm_rotator_dev->imem_clk);
1749 msm_rotator_dev->imem_clk = NULL;
1750 }
1751 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1752 disable_rot_clks();
1753 clk_put(msm_rotator_dev->core_clk);
1754 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001755 if (msm_rotator_dev->regulator)
1756 regulator_put(msm_rotator_dev->regulator);
1757 msm_rotator_dev->core_clk = NULL;
1758 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001759 mutex_destroy(&msm_rotator_dev->imem_lock);
1760 for (i = 0; i < MAX_SESSIONS; i++)
1761 if (msm_rotator_dev->img_info[i] != NULL)
1762 kfree(msm_rotator_dev->img_info[i]);
1763 kfree(msm_rotator_dev);
1764 return 0;
1765}
1766
1767#ifdef CONFIG_PM
1768static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1769{
1770 mutex_lock(&msm_rotator_dev->imem_lock);
1771 if (msm_rotator_dev->imem_clk_state == CLK_EN
1772 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001773 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001774 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1775 }
1776 mutex_unlock(&msm_rotator_dev->imem_lock);
1777 mutex_lock(&msm_rotator_dev->rotator_lock);
1778 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1779 disable_rot_clks();
1780 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1781 }
1782 mutex_unlock(&msm_rotator_dev->rotator_lock);
1783 return 0;
1784}
1785
1786static int msm_rotator_resume(struct platform_device *dev)
1787{
1788 mutex_lock(&msm_rotator_dev->imem_lock);
1789 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1790 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001791 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001792 msm_rotator_dev->imem_clk_state = CLK_EN;
1793 }
1794 mutex_unlock(&msm_rotator_dev->imem_lock);
1795 mutex_lock(&msm_rotator_dev->rotator_lock);
1796 if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND) {
1797 enable_rot_clks();
1798 msm_rotator_dev->rot_clk_state = CLK_EN;
1799 }
1800 mutex_unlock(&msm_rotator_dev->rotator_lock);
1801 return 0;
1802}
1803#endif
1804
1805static struct platform_driver msm_rotator_platform_driver = {
1806 .probe = msm_rotator_probe,
1807 .remove = __devexit_p(msm_rotator_remove),
1808#ifdef CONFIG_PM
1809 .suspend = msm_rotator_suspend,
1810 .resume = msm_rotator_resume,
1811#endif
1812 .driver = {
1813 .owner = THIS_MODULE,
1814 .name = DRIVER_NAME
1815 }
1816};
1817
1818static int __init msm_rotator_init(void)
1819{
1820 return platform_driver_register(&msm_rotator_platform_driver);
1821}
1822
1823static void __exit msm_rotator_exit(void)
1824{
1825 return platform_driver_unregister(&msm_rotator_platform_driver);
1826}
1827
1828module_init(msm_rotator_init);
1829module_exit(msm_rotator_exit);
1830
1831MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1832MODULE_VERSION("1.0");
1833MODULE_LICENSE("GPL v2");