blob: 6f3b79b9620b9e37b72d4bed9d42fdbc1a64f5c7 [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:
Mayank Chopra797bdb72012-03-03 06:29:40 +0530424 case MDP_Y_CRCB_H1V2:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700425 p->num_planes = 2;
426 p->plane_size[0] = w * h;
427 p->plane_size[1] = w * h;
428 break;
429 case MDP_Y_CBCR_H2V2:
430 case MDP_Y_CRCB_H2V2:
431 p->num_planes = 2;
432 p->plane_size[0] = w * h;
433 p->plane_size[1] = w * h / 2;
434 break;
435 case MDP_Y_CRCB_H2V2_TILE:
436 case MDP_Y_CBCR_H2V2_TILE:
437 p->num_planes = 2;
438 p->plane_size[0] = tile_size(w, h, &tile);
439 p->plane_size[1] = tile_size(w, h/2, &tile);
440 break;
441 case MDP_Y_CB_CR_H2V2:
442 case MDP_Y_CR_CB_H2V2:
443 p->num_planes = 3;
444 p->plane_size[0] = w * h;
445 p->plane_size[1] = (w / 2) * (h / 2);
446 p->plane_size[2] = (w / 2) * (h / 2);
447 break;
448 case MDP_Y_CR_CB_GH2V2:
449 p->num_planes = 3;
450 p->plane_size[0] = ALIGN(w, 16) * h;
451 p->plane_size[1] = ALIGN(w / 2, 16) * (h / 2);
452 p->plane_size[2] = ALIGN(w / 2, 16) * (h / 2);
453 break;
454 default:
455 return -EINVAL;
456 }
457
458 for (i = 0; i < p->num_planes; i++)
459 p->total_size += p->plane_size[i];
460
461 return 0;
462}
463
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700464static int msm_rotator_ycxcx_h2v1(struct msm_rotator_img_info *info,
465 unsigned int in_paddr,
466 unsigned int out_paddr,
467 unsigned int use_imem,
468 int new_session,
469 unsigned int in_chroma_paddr,
470 unsigned int out_chroma_paddr)
471{
472 int bpp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473
474 if (info->src.format != info->dst.format)
475 return -EINVAL;
476
477 bpp = get_bpp(info->src.format);
478 if (bpp < 0)
479 return -ENOTTY;
480
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700481 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700482 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483 iowrite32(out_paddr +
484 ((info->dst_y * info->dst.width) + info->dst_x),
485 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700486 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 ((info->dst_y * info->dst.width) + info->dst_x),
488 MSM_ROTATOR_OUTP1_ADDR);
489
490 if (new_session) {
491 iowrite32(info->src.width |
492 info->src.width << 16,
493 MSM_ROTATOR_SRC_YSTRIDE1);
494 if (info->rotations & MDP_ROT_90)
495 iowrite32(info->dst.width |
496 info->dst.width*2 << 16,
497 MSM_ROTATOR_OUT_YSTRIDE1);
498 else
499 iowrite32(info->dst.width |
500 info->dst.width << 16,
501 MSM_ROTATOR_OUT_YSTRIDE1);
502 if (info->src.format == MDP_Y_CBCR_H2V1) {
503 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
504 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
505 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
506 MSM_ROTATOR_OUT_PACK_PATTERN1);
507 } else {
508 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
509 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
510 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
511 MSM_ROTATOR_OUT_PACK_PATTERN1);
512 }
513 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
514 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700515 1 << 8 | /* ROT_EN */
516 info->downscale_ratio << 2 | /* downscale v ratio */
517 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700518 MSM_ROTATOR_SUB_BLOCK_CFG);
519 iowrite32(0 << 29 | /* frame format 0 = linear */
520 (use_imem ? 0 : 1) << 22 | /* tile size */
521 2 << 19 | /* fetch planes 2 = pseudo */
522 0 << 18 | /* unpack align */
523 1 << 17 | /* unpack tight */
524 1 << 13 | /* unpack count 0=1 component */
525 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
526 0 << 8 | /* has alpha */
527 0 << 6 | /* alpha bits 3=8bits */
528 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
529 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
530 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
531 MSM_ROTATOR_SRC_FORMAT);
532 }
533
534 return 0;
535}
536
537static int msm_rotator_ycxcx_h2v2(struct msm_rotator_img_info *info,
538 unsigned int in_paddr,
539 unsigned int out_paddr,
540 unsigned int use_imem,
541 int new_session,
542 unsigned int in_chroma_paddr,
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700543 unsigned int out_chroma_paddr,
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700544 unsigned int in_chroma2_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700545{
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700546 uint32_t dst_format;
547 int is_tile = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700548
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700549 switch (info->src.format) {
550 case MDP_Y_CRCB_H2V2_TILE:
551 is_tile = 1;
552 case MDP_Y_CR_CB_H2V2:
553 case MDP_Y_CR_CB_GH2V2:
554 case MDP_Y_CRCB_H2V2:
555 dst_format = MDP_Y_CRCB_H2V2;
556 break;
557 case MDP_Y_CBCR_H2V2_TILE:
558 is_tile = 1;
559 case MDP_Y_CB_CR_H2V2:
560 case MDP_Y_CBCR_H2V2:
561 dst_format = MDP_Y_CBCR_H2V2;
562 break;
563 default:
564 return -EINVAL;
565 }
566 if (info->dst.format != dst_format)
567 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700568
Adrian Salido-Moreno19caf152012-01-03 18:46:25 -0800569 /* rotator expects YCbCr for planar input format */
Mayank Chopra012a8e72012-04-11 10:41:13 +0530570 if ((info->src.format == MDP_Y_CR_CB_H2V2 ||
571 info->src.format == MDP_Y_CR_CB_GH2V2) &&
572 rotator_hw_revision < ROTATOR_REVISION_V2)
Adrian Salido-Moreno19caf152012-01-03 18:46:25 -0800573 swap(in_chroma_paddr, in_chroma2_paddr);
574
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700576 iowrite32(in_chroma_paddr, MSM_ROTATOR_SRCP1_ADDR);
577 iowrite32(in_chroma2_paddr, MSM_ROTATOR_SRCP2_ADDR);
578
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700579 iowrite32(out_paddr +
580 ((info->dst_y * info->dst.width) + info->dst_x),
581 MSM_ROTATOR_OUTP0_ADDR);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700582 iowrite32(out_chroma_paddr +
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 ((info->dst_y * info->dst.width)/2 + info->dst_x),
584 MSM_ROTATOR_OUTP1_ADDR);
585
586 if (new_session) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700587 if (in_chroma2_paddr) {
588 if (info->src.format == MDP_Y_CR_CB_GH2V2) {
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530589 iowrite32(ALIGN(info->src.width, 16) |
590 ALIGN((info->src.width / 2), 16) << 16,
591 MSM_ROTATOR_SRC_YSTRIDE1);
592 iowrite32(ALIGN((info->src.width / 2), 16),
593 MSM_ROTATOR_SRC_YSTRIDE2);
594 } else {
595 iowrite32(info->src.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700596 (info->src.width / 2) << 16,
597 MSM_ROTATOR_SRC_YSTRIDE1);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530598 iowrite32((info->src.width / 2),
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700599 MSM_ROTATOR_SRC_YSTRIDE2);
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530600 }
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700601 } else {
602 iowrite32(info->src.width |
603 info->src.width << 16,
604 MSM_ROTATOR_SRC_YSTRIDE1);
605 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700606 iowrite32(info->dst.width |
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700607 info->dst.width << 16,
608 MSM_ROTATOR_OUT_YSTRIDE1);
609
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700610 if (dst_format == MDP_Y_CBCR_H2V2) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700611 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
612 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
613 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CB, CLR_CR, 8),
614 MSM_ROTATOR_OUT_PACK_PATTERN1);
615 } else {
616 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
617 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
618 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
619 MSM_ROTATOR_OUT_PACK_PATTERN1);
620 }
621 iowrite32((3 << 18) | /* chroma sampling 3=4:2:0 */
622 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700623 1 << 8 | /* ROT_EN */
624 info->downscale_ratio << 2 | /* downscale v ratio */
625 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700626 MSM_ROTATOR_SUB_BLOCK_CFG);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700627
628 iowrite32((is_tile ? 2 : 0) << 29 | /* frame format */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700629 (use_imem ? 0 : 1) << 22 | /* tile size */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700630 (in_chroma2_paddr ? 1 : 2) << 19 | /* fetch planes */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700631 0 << 18 | /* unpack align */
632 1 << 17 | /* unpack tight */
633 1 << 13 | /* unpack count 0=1 component */
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700634 0 << 9 | /* src Bpp 0=1 byte ... */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635 0 << 8 | /* has alpha */
636 0 << 6 | /* alpha bits 3=8bits */
637 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
638 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
639 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
640 MSM_ROTATOR_SRC_FORMAT);
641 }
642 return 0;
643}
644
645static int msm_rotator_ycrycb(struct msm_rotator_img_info *info,
646 unsigned int in_paddr,
647 unsigned int out_paddr,
648 unsigned int use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +0530649 int new_session,
650 unsigned int out_chroma_paddr)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700651{
652 int bpp;
Mayank Chopra732dcd62012-01-09 20:53:39 +0530653 uint32_t dst_format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700654
Mayank Chopra797bdb72012-03-03 06:29:40 +0530655 if (info->src.format == MDP_YCRYCB_H2V1) {
656 if (info->rotations & MDP_ROT_90)
657 dst_format = MDP_Y_CRCB_H1V2;
658 else
659 dst_format = MDP_Y_CRCB_H2V1;
660 } else
Mayank Chopra732dcd62012-01-09 20:53:39 +0530661 return -EINVAL;
662
663 if (info->dst.format != dst_format)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700664 return -EINVAL;
665
666 bpp = get_bpp(info->src.format);
667 if (bpp < 0)
668 return -ENOTTY;
669
670 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
671 iowrite32(out_paddr +
672 ((info->dst_y * info->dst.width) + info->dst_x),
673 MSM_ROTATOR_OUTP0_ADDR);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530674 iowrite32(out_chroma_paddr +
675 ((info->dst_y * info->dst.width)/2 + info->dst_x),
676 MSM_ROTATOR_OUTP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700677
678 if (new_session) {
Mayank Chopra732dcd62012-01-09 20:53:39 +0530679 iowrite32(info->src.width * bpp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680 MSM_ROTATOR_SRC_YSTRIDE1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530681 if (info->rotations & MDP_ROT_90)
682 iowrite32(info->dst.width |
683 (info->dst.width*2) << 16,
684 MSM_ROTATOR_OUT_YSTRIDE1);
685 else
686 iowrite32(info->dst.width |
687 (info->dst.width) << 16,
688 MSM_ROTATOR_OUT_YSTRIDE1);
689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
691 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530692 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700693 MSM_ROTATOR_OUT_PACK_PATTERN1);
694 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
695 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700696 1 << 8 | /* ROT_EN */
697 info->downscale_ratio << 2 | /* downscale v ratio */
698 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700699 MSM_ROTATOR_SUB_BLOCK_CFG);
700 iowrite32(0 << 29 | /* frame format 0 = linear */
701 (use_imem ? 0 : 1) << 22 | /* tile size */
702 0 << 19 | /* fetch planes 0=interleaved */
703 0 << 18 | /* unpack align */
704 1 << 17 | /* unpack tight */
705 3 << 13 | /* unpack count 0=1 component */
706 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
707 0 << 8 | /* has alpha */
708 0 << 6 | /* alpha bits 3=8bits */
709 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
710 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
711 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
712 MSM_ROTATOR_SRC_FORMAT);
713 }
714
715 return 0;
716}
717
718static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
719 unsigned int in_paddr,
720 unsigned int out_paddr,
721 unsigned int use_imem,
722 int new_session)
723{
724 int bpp, abits, rbits, gbits, bbits;
725
726 if (info->src.format != info->dst.format)
727 return -EINVAL;
728
729 bpp = get_bpp(info->src.format);
730 if (bpp < 0)
731 return -ENOTTY;
732
733 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
734 iowrite32(out_paddr +
735 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
736 MSM_ROTATOR_OUTP0_ADDR);
737
738 if (new_session) {
739 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
740 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
741 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
742 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700743 1 << 8 | /* ROT_EN */
744 info->downscale_ratio << 2 | /* downscale v ratio */
745 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 MSM_ROTATOR_SUB_BLOCK_CFG);
747 switch (info->src.format) {
748 case MDP_RGB_565:
749 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
750 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
751 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
752 MSM_ROTATOR_OUT_PACK_PATTERN1);
753 abits = 0;
754 rbits = COMPONENT_5BITS;
755 gbits = COMPONENT_6BITS;
756 bbits = COMPONENT_5BITS;
757 break;
758
759 case MDP_BGR_565:
760 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
761 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
762 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
763 MSM_ROTATOR_OUT_PACK_PATTERN1);
764 abits = 0;
765 rbits = COMPONENT_5BITS;
766 gbits = COMPONENT_6BITS;
767 bbits = COMPONENT_5BITS;
768 break;
769
770 case MDP_RGB_888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -0700771 case MDP_YCBCR_H1V1:
772 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700773 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
774 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
775 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
776 MSM_ROTATOR_OUT_PACK_PATTERN1);
777 abits = 0;
778 rbits = COMPONENT_8BITS;
779 gbits = COMPONENT_8BITS;
780 bbits = COMPONENT_8BITS;
781 break;
782
783 case MDP_ARGB_8888:
784 case MDP_RGBA_8888:
785 case MDP_XRGB_8888:
786 case MDP_RGBX_8888:
787 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
788 CLR_B, 8),
789 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
790 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
791 CLR_B, 8),
792 MSM_ROTATOR_OUT_PACK_PATTERN1);
793 abits = COMPONENT_8BITS;
794 rbits = COMPONENT_8BITS;
795 gbits = COMPONENT_8BITS;
796 bbits = COMPONENT_8BITS;
797 break;
798
799 case MDP_BGRA_8888:
800 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
801 CLR_R, 8),
802 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
803 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
804 CLR_R, 8),
805 MSM_ROTATOR_OUT_PACK_PATTERN1);
806 abits = COMPONENT_8BITS;
807 rbits = COMPONENT_8BITS;
808 gbits = COMPONENT_8BITS;
809 bbits = COMPONENT_8BITS;
810 break;
811
812 default:
813 return -EINVAL;
814 }
815 iowrite32(0 << 29 | /* frame format 0 = linear */
816 (use_imem ? 0 : 1) << 22 | /* tile size */
817 0 << 19 | /* fetch planes 0=interleaved */
818 0 << 18 | /* unpack align */
819 1 << 17 | /* unpack tight */
820 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
821 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
822 (abits ? 1 : 0) << 8 | /* has alpha */
823 abits << 6 | /* alpha bits 3=8bits */
824 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
825 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
826 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
827 MSM_ROTATOR_SRC_FORMAT);
828 }
829
830 return 0;
831}
832
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700833static int get_img(struct msmfb_data *fbd, int domain,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700834 unsigned long *start, unsigned long *len, struct file **p_file,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700835 int *p_need, struct ion_handle **p_ihdl, unsigned int secure)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700836{
837 int ret = 0;
838#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700839 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700840 int put_needed, fb_num;
841#endif
842#ifdef CONFIG_ANDROID_PMEM
843 unsigned long vstart;
844#endif
845
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800846 *p_need = 0;
847
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700848#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700849 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
850 file = fget_light(fbd->memory_id, &put_needed);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700851 if (file == NULL) {
852 pr_err("fget_light returned NULL\n");
Naseer Ahmed18018602011-10-25 13:32:58 -0700853 return -EINVAL;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700854 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855
Naseer Ahmed18018602011-10-25 13:32:58 -0700856 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
857 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700858 if (get_fb_phys_info(start, len, fb_num,
859 ROTATOR_SUBSYSTEM_ID)) {
860 pr_err("get_fb_phys_info() failed\n");
Naseer Ahmed18018602011-10-25 13:32:58 -0700861 ret = -1;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700862 } else {
Naseer Ahmed18018602011-10-25 13:32:58 -0700863 *p_file = file;
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800864 *p_need = put_needed;
865 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700866 } else {
867 pr_err("invalid FB_MAJOR failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 ret = -1;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700869 }
Naseer Ahmed18018602011-10-25 13:32:58 -0700870 if (ret)
871 fput_light(file, put_needed);
872 return ret;
873 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700875
876#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700877 return msm_rotator_iommu_map_buf(fbd->memory_id, domain, start,
878 len, p_ihdl, secure);
Naseer Ahmed18018602011-10-25 13:32:58 -0700879#endif
880#ifdef CONFIG_ANDROID_PMEM
881 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
882 return 0;
883 else
884 return -ENOMEM;
885#endif
886
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700887}
888
Olav Hauganef95ae32012-05-15 09:50:30 -0700889static void put_img(struct file *p_file, struct ion_handle *p_ihdl,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700890 int domain, unsigned int secure)
Naseer Ahmed18018602011-10-25 13:32:58 -0700891{
892#ifdef CONFIG_ANDROID_PMEM
893 if (p_file != NULL)
894 put_pmem_file(p_file);
895#endif
Olav Hauganef95ae32012-05-15 09:50:30 -0700896
Naseer Ahmed18018602011-10-25 13:32:58 -0700897#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700898 if (!IS_ERR_OR_NULL(p_ihdl)) {
899 pr_debug("%s(): p_ihdl %p\n", __func__, p_ihdl);
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700900 if (rot_iommu_split_domain) {
901 if (!secure)
902 ion_unmap_iommu(msm_rotator_dev->client,
903 p_ihdl, domain, GEN_POOL);
904 } else {
905 ion_unmap_iommu(msm_rotator_dev->client,
906 p_ihdl, ROTATOR_SRC_DOMAIN, GEN_POOL);
907 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700908
Naseer Ahmed18018602011-10-25 13:32:58 -0700909 ion_free(msm_rotator_dev->client, p_ihdl);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700910 }
Naseer Ahmed18018602011-10-25 13:32:58 -0700911#endif
912}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913static int msm_rotator_do_rotate(unsigned long arg)
914{
Naseer Ahmed18018602011-10-25 13:32:58 -0700915 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916 struct msm_rotator_data_info info;
917 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700918 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700919 int use_imem = 0, rc = 0, s;
920 struct file *srcp0_file = NULL, *dstp0_file = NULL;
921 struct file *srcp1_file = NULL, *dstp1_file = NULL;
922 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
923 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800924 int ps0_need, p_need;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700925 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700926 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700927 struct msm_rotator_img_info *img_info;
928 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700929
930 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
931 return -EFAULT;
932
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700933 mutex_lock(&msm_rotator_dev->rotator_lock);
934 for (s = 0; s < MAX_SESSIONS; s++)
935 if ((msm_rotator_dev->img_info[s] != NULL) &&
936 (info.session_id ==
937 (unsigned int)msm_rotator_dev->img_info[s]
938 ))
939 break;
940
941 if (s == MAX_SESSIONS) {
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -0700942 pr_err("%s() : Attempt to use invalid session_id %d\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700943 __func__, s);
944 rc = -EINVAL;
945 goto do_rotate_unlock_mutex;
946 }
947
948 if (msm_rotator_dev->img_info[s]->enable == 0) {
949 dev_dbg(msm_rotator_dev->device,
950 "%s() : Session_id %d not enabled \n",
951 __func__, s);
952 rc = -EINVAL;
953 goto do_rotate_unlock_mutex;
954 }
955
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700956 img_info = msm_rotator_dev->img_info[s];
957 if (msm_rotator_get_plane_sizes(img_info->src.format,
958 img_info->src.width,
959 img_info->src.height,
960 &src_planes)) {
961 pr_err("%s: invalid src format\n", __func__);
962 rc = -EINVAL;
963 goto do_rotate_unlock_mutex;
964 }
965 if (msm_rotator_get_plane_sizes(img_info->dst.format,
966 img_info->dst.width,
967 img_info->dst.height,
968 &dst_planes)) {
969 pr_err("%s: invalid dst format\n", __func__);
970 rc = -EINVAL;
971 goto do_rotate_unlock_mutex;
972 }
973
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700974 rc = get_img(&info.src, ROTATOR_SRC_DOMAIN, (unsigned long *)&in_paddr,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700975 (unsigned long *)&src_len, &srcp0_file, &ps0_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700976 &srcp0_ihdl, 0);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700977 if (rc) {
978 pr_err("%s: in get_img() failed id=0x%08x\n",
979 DRIVER_NAME, info.src.memory_id);
980 goto do_rotate_unlock_mutex;
981 }
982
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700983 rc = get_img(&info.dst, ROTATOR_DST_DOMAIN, (unsigned long *)&out_paddr,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700984 (unsigned long *)&dst_len, &dstp0_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700985 &dstp0_ihdl, img_info->secure);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700986 if (rc) {
987 pr_err("%s: out get_img() failed id=0x%08x\n",
988 DRIVER_NAME, info.dst.memory_id);
989 goto do_rotate_unlock_mutex;
990 }
991
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700992 format = msm_rotator_dev->img_info[s]->src.format;
993 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700994 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
995 (src_planes.num_planes == 2)) {
996 if (checkoffset(info.src.offset,
997 src_planes.plane_size[0],
998 src_len)) {
999 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
1000 __func__, src_len, info.src.offset);
1001 rc = -ERANGE;
1002 goto do_rotate_unlock_mutex;
1003 }
1004 if (checkoffset(info.dst.offset,
1005 dst_planes.plane_size[0],
1006 dst_len)) {
1007 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
1008 __func__, dst_len, info.dst.offset);
1009 rc = -ERANGE;
1010 goto do_rotate_unlock_mutex;
1011 }
1012
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001013 rc = get_img(&info.src_chroma, ROTATOR_SRC_DOMAIN,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001014 (unsigned long *)&in_chroma_paddr,
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001015 (unsigned long *)&src_len, &srcp1_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001016 &srcp1_ihdl, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001017 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001018 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001019 DRIVER_NAME, info.src_chroma.memory_id);
1020 goto do_rotate_unlock_mutex;
1021 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001022
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001023 rc = get_img(&info.dst_chroma, ROTATOR_DST_DOMAIN,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001024 (unsigned long *)&out_chroma_paddr,
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001025 (unsigned long *)&dst_len, &dstp1_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001026 &dstp1_ihdl, img_info->secure);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001027 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001028 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001029 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001030 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001031 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001032
1033 if (checkoffset(info.src_chroma.offset,
1034 src_planes.plane_size[1],
1035 src_len)) {
1036 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
1037 __func__, src_len, info.src_chroma.offset);
1038 rc = -ERANGE;
1039 goto do_rotate_unlock_mutex;
1040 }
1041
1042 if (checkoffset(info.dst_chroma.offset,
1043 src_planes.plane_size[1],
1044 dst_len)) {
1045 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
1046 __func__, dst_len, info.dst_chroma.offset);
1047 rc = -ERANGE;
1048 goto do_rotate_unlock_mutex;
1049 }
1050
1051 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001052 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001053 } else {
1054 if (checkoffset(info.src.offset,
1055 src_planes.total_size,
1056 src_len)) {
1057 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
1058 __func__, src_len, info.src.offset);
1059 rc = -ERANGE;
1060 goto do_rotate_unlock_mutex;
1061 }
1062 if (checkoffset(info.dst.offset,
1063 dst_planes.total_size,
1064 dst_len)) {
1065 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
1066 __func__, dst_len, info.dst.offset);
1067 rc = -ERANGE;
1068 goto do_rotate_unlock_mutex;
1069 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001070 }
1071
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001072 in_paddr += info.src.offset;
1073 out_paddr += info.dst.offset;
1074
1075 if (!in_chroma_paddr && src_planes.num_planes >= 2)
1076 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
1077 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
1078 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
1079 if (src_planes.num_planes >= 3)
1080 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
1081
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001082 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
1083 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
1084 enable_rot_clks();
1085 msm_rotator_dev->rot_clk_state = CLK_EN;
1086 }
1087 enable_irq(msm_rotator_dev->irq);
1088
1089#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1090 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
1091#else
1092 use_imem = 0;
1093#endif
1094 /*
1095 * workaround for a hardware bug. rotator hardware hangs when we
1096 * use write burst beat size 16 on 128X128 tile fetch mode. As a
1097 * temporary fix use 0x42 for BURST_SIZE when imem used.
1098 */
1099 if (use_imem)
1100 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
1101
1102 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
1103 << 16) |
1104 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
1105 MSM_ROTATOR_SRC_SIZE);
1106 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
1107 << 16) |
1108 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
1109 MSM_ROTATOR_SRC_XY);
1110 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
1111 << 16) |
1112 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
1113 MSM_ROTATOR_SRC_IMAGE_SIZE);
1114
1115 switch (format) {
1116 case MDP_RGB_565:
1117 case MDP_BGR_565:
1118 case MDP_RGB_888:
1119 case MDP_ARGB_8888:
1120 case MDP_RGBA_8888:
1121 case MDP_XRGB_8888:
1122 case MDP_BGRA_8888:
1123 case MDP_RGBX_8888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -07001124 case MDP_YCBCR_H1V1:
1125 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001126 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
1127 in_paddr, out_paddr,
1128 use_imem,
1129 msm_rotator_dev->last_session_idx
1130 != s);
1131 break;
1132 case MDP_Y_CBCR_H2V2:
1133 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001134 case MDP_Y_CB_CR_H2V2:
1135 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301136 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001137 case MDP_Y_CRCB_H2V2_TILE:
1138 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001139 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1140 in_paddr, out_paddr, use_imem,
1141 msm_rotator_dev->last_session_idx
1142 != s,
1143 in_chroma_paddr,
1144 out_chroma_paddr,
1145 in_chroma2_paddr);
1146 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001147 case MDP_Y_CBCR_H2V1:
1148 case MDP_Y_CRCB_H2V1:
1149 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1150 in_paddr, out_paddr, use_imem,
1151 msm_rotator_dev->last_session_idx
1152 != s,
1153 in_chroma_paddr,
1154 out_chroma_paddr);
1155 break;
1156 case MDP_YCRYCB_H2V1:
1157 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1158 in_paddr, out_paddr, use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +05301159 msm_rotator_dev->last_session_idx != s,
1160 out_chroma_paddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001161 break;
1162 default:
1163 rc = -EINVAL;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001164 pr_err("%s(): Unsupported format %u\n", __func__, format);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001165 goto do_rotate_exit;
1166 }
1167
1168 if (rc != 0) {
1169 msm_rotator_dev->last_session_idx = INVALID_SESSION;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001170 pr_err("%s(): Invalid session error\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001171 goto do_rotate_exit;
1172 }
1173
1174 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1175
1176 msm_rotator_dev->processing = 1;
1177 iowrite32(0x1, MSM_ROTATOR_START);
1178
1179 wait_event(msm_rotator_dev->wq,
1180 (msm_rotator_dev->processing == 0));
1181 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001182 if ((status & 0x03) != 0x01) {
1183 pr_err("%s(): AXI Bus Error, issuing SW_RESET\n", __func__);
1184 iowrite32(0x1, MSM_ROTATOR_SW_RESET);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001185 rc = -EFAULT;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001186 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001187 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1188 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1189
1190do_rotate_exit:
1191 disable_irq(msm_rotator_dev->irq);
1192#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1193 msm_rotator_imem_free(ROTATOR_REQUEST);
1194#endif
1195 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001196do_rotate_unlock_mutex:
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001197 put_img(dstp1_file, dstp1_ihdl, ROTATOR_DST_DOMAIN,
1198 msm_rotator_dev->img_info[s]->secure);
1199 put_img(srcp1_file, srcp1_ihdl, ROTATOR_SRC_DOMAIN, 0);
1200 put_img(dstp0_file, dstp0_ihdl, ROTATOR_DST_DOMAIN,
1201 msm_rotator_dev->img_info[s]->secure);
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001202
1203 /* only source may use frame buffer */
1204 if (info.src.flags & MDP_MEMORY_ID_TYPE_FB)
1205 fput_light(srcp0_file, ps0_need);
1206 else
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001207 put_img(srcp0_file, srcp0_ihdl, ROTATOR_SRC_DOMAIN, 0);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001208 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001209 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1210 __func__, rc);
1211 return rc;
1212}
1213
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001214static void msm_rotator_set_perf_level(u32 wh, u32 is_rgb)
1215{
1216 u32 perf_level;
1217
1218 if (is_rgb)
1219 perf_level = 1;
1220 else if (wh <= (640 * 480))
1221 perf_level = 2;
1222 else if (wh <= (736 * 1280))
1223 perf_level = 3;
1224 else
1225 perf_level = 4;
1226
1227#ifdef CONFIG_MSM_BUS_SCALING
1228 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1229 perf_level);
1230#endif
1231
1232}
1233
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001234static int msm_rotator_start(unsigned long arg,
1235 struct msm_rotator_fd_info *fd_info)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001236{
1237 struct msm_rotator_img_info info;
1238 int rc = 0;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001239 int s, is_rgb = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001240 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001241 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001242
1243 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1244 return -EFAULT;
1245
1246 if ((info.rotations > MSM_ROTATOR_MAX_ROT) ||
1247 (info.src.height > MSM_ROTATOR_MAX_H) ||
1248 (info.src.width > MSM_ROTATOR_MAX_W) ||
1249 (info.dst.height > MSM_ROTATOR_MAX_H) ||
1250 (info.dst.width > MSM_ROTATOR_MAX_W) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001251 (info.downscale_ratio > MAX_DOWNSCALE_RATIO)) {
1252 pr_err("%s: Invalid parameters\n", __func__);
1253 return -EINVAL;
1254 }
1255
1256 if (info.rotations & MDP_ROT_90) {
1257 dst_w = info.src_rect.h >> info.downscale_ratio;
1258 dst_h = info.src_rect.w >> info.downscale_ratio;
1259 } else {
1260 dst_w = info.src_rect.w >> info.downscale_ratio;
1261 dst_h = info.src_rect.h >> info.downscale_ratio;
1262 }
1263
1264 if (checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001265 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1266 checkoffset(info.dst_x, dst_w, info.dst.width) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001267 checkoffset(info.dst_y, dst_h, info.dst.height)) {
1268 pr_err("%s: Invalid src or dst rect\n", __func__);
1269 return -ERANGE;
1270 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001271
1272 switch (info.src.format) {
1273 case MDP_RGB_565:
1274 case MDP_BGR_565:
1275 case MDP_RGB_888:
1276 case MDP_ARGB_8888:
1277 case MDP_RGBA_8888:
1278 case MDP_XRGB_8888:
1279 case MDP_RGBX_8888:
1280 case MDP_BGRA_8888:
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001281 is_rgb = 1;
Mayank Chopra012a8e72012-04-11 10:41:13 +05301282 info.dst.format = info.src.format;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001283 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001284 case MDP_Y_CBCR_H2V2:
1285 case MDP_Y_CRCB_H2V2:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301286 case MDP_Y_CBCR_H2V1:
1287 case MDP_Y_CRCB_H2V1:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -07001288 case MDP_YCBCR_H1V1:
1289 case MDP_YCRCB_H1V1:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301290 info.dst.format = info.src.format;
1291 break;
1292 case MDP_YCRYCB_H2V1:
Mayank Chopra797bdb72012-03-03 06:29:40 +05301293 if (info.rotations & MDP_ROT_90)
1294 info.dst.format = MDP_Y_CRCB_H1V2;
1295 else
1296 info.dst.format = MDP_Y_CRCB_H2V1;
Mayank Chopra012a8e72012-04-11 10:41:13 +05301297 break;
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001298 case MDP_Y_CB_CR_H2V2:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301299 case MDP_Y_CBCR_H2V2_TILE:
1300 info.dst.format = MDP_Y_CBCR_H2V2;
1301 break;
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001302 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301303 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001304 case MDP_Y_CRCB_H2V2_TILE:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301305 info.dst.format = MDP_Y_CRCB_H2V2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001306 break;
1307 default:
1308 return -EINVAL;
1309 }
1310
1311 mutex_lock(&msm_rotator_dev->rotator_lock);
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001312
1313 msm_rotator_set_perf_level((info.src.width*info.src.height), is_rgb);
1314
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315 for (s = 0; s < MAX_SESSIONS; s++) {
1316 if ((msm_rotator_dev->img_info[s] != NULL) &&
1317 (info.session_id ==
1318 (unsigned int)msm_rotator_dev->img_info[s]
1319 )) {
1320 *(msm_rotator_dev->img_info[s]) = info;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001321 msm_rotator_dev->fd_info[s] = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001322
1323 if (msm_rotator_dev->last_session_idx == s)
1324 msm_rotator_dev->last_session_idx =
1325 INVALID_SESSION;
1326 break;
1327 }
1328
1329 if ((msm_rotator_dev->img_info[s] == NULL) &&
1330 (first_free_index ==
1331 INVALID_SESSION))
1332 first_free_index = s;
1333 }
1334
1335 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1336 /* allocate a session id */
1337 msm_rotator_dev->img_info[first_free_index] =
1338 kzalloc(sizeof(struct msm_rotator_img_info),
1339 GFP_KERNEL);
1340 if (!msm_rotator_dev->img_info[first_free_index]) {
1341 printk(KERN_ERR "%s : unable to alloc mem\n",
1342 __func__);
1343 rc = -ENOMEM;
1344 goto rotator_start_exit;
1345 }
1346 info.session_id = (unsigned int)
1347 msm_rotator_dev->img_info[first_free_index];
1348 *(msm_rotator_dev->img_info[first_free_index]) = info;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001349 msm_rotator_dev->fd_info[first_free_index] = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350 } else if (s == MAX_SESSIONS) {
1351 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1352 __func__);
1353 rc = -EBUSY;
1354 }
1355
Adrian Salido-Morenoc5639952012-04-20 19:07:58 -07001356 if (rc == 0 && copy_to_user((void __user *)arg, &info, sizeof(info)))
1357 rc = -EFAULT;
1358
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001359rotator_start_exit:
1360 mutex_unlock(&msm_rotator_dev->rotator_lock);
1361
1362 return rc;
1363}
1364
1365static int msm_rotator_finish(unsigned long arg)
1366{
1367 int rc = 0;
1368 int s;
1369 unsigned int session_id;
1370
1371 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1372 return -EFAULT;
1373
1374 mutex_lock(&msm_rotator_dev->rotator_lock);
1375 for (s = 0; s < MAX_SESSIONS; s++) {
1376 if ((msm_rotator_dev->img_info[s] != NULL) &&
1377 (session_id ==
1378 (unsigned int)msm_rotator_dev->img_info[s])) {
1379 if (msm_rotator_dev->last_session_idx == s)
1380 msm_rotator_dev->last_session_idx =
1381 INVALID_SESSION;
1382 kfree(msm_rotator_dev->img_info[s]);
1383 msm_rotator_dev->img_info[s] = NULL;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001384 msm_rotator_dev->fd_info[s] = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001385 break;
1386 }
1387 }
1388
1389 if (s == MAX_SESSIONS)
1390 rc = -EINVAL;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001391#ifdef CONFIG_MSM_BUS_SCALING
1392 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1393 0);
1394#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001395 mutex_unlock(&msm_rotator_dev->rotator_lock);
1396 return rc;
1397}
1398
1399static int
1400msm_rotator_open(struct inode *inode, struct file *filp)
1401{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001402 struct msm_rotator_fd_info *tmp, *fd_info = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001403 int i;
1404
1405 if (filp->private_data)
1406 return -EBUSY;
1407
1408 mutex_lock(&msm_rotator_dev->rotator_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001409 for (i = 0; i < MAX_SESSIONS; i++) {
1410 if (msm_rotator_dev->fd_info[i] == NULL)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001411 break;
1412 }
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001413
1414 if (i == MAX_SESSIONS) {
1415 mutex_unlock(&msm_rotator_dev->rotator_lock);
1416 return -EBUSY;
1417 }
1418
1419 list_for_each_entry(tmp, &msm_rotator_dev->fd_list, list) {
1420 if (tmp->pid == current->pid) {
1421 fd_info = tmp;
1422 break;
1423 }
1424 }
1425
1426 if (!fd_info) {
1427 fd_info = kzalloc(sizeof(*fd_info), GFP_KERNEL);
1428 if (!fd_info) {
1429 mutex_unlock(&msm_rotator_dev->rotator_lock);
1430 pr_err("%s: insufficient memory to alloc resources\n",
1431 __func__);
1432 return -ENOMEM;
1433 }
1434 list_add(&fd_info->list, &msm_rotator_dev->fd_list);
1435 fd_info->pid = current->pid;
1436 }
1437 fd_info->ref_cnt++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001438 mutex_unlock(&msm_rotator_dev->rotator_lock);
1439
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001440 filp->private_data = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001441
1442 return 0;
1443}
1444
1445static int
1446msm_rotator_close(struct inode *inode, struct file *filp)
1447{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001448 struct msm_rotator_fd_info *fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001449 int s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001450
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001451 fd_info = (struct msm_rotator_fd_info *)filp->private_data;
1452
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001453 mutex_lock(&msm_rotator_dev->rotator_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001454 if (--fd_info->ref_cnt > 0) {
1455 mutex_unlock(&msm_rotator_dev->rotator_lock);
1456 return 0;
1457 }
1458
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001459 for (s = 0; s < MAX_SESSIONS; s++) {
1460 if (msm_rotator_dev->img_info[s] != NULL &&
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001461 msm_rotator_dev->fd_info[s] == fd_info) {
1462 pr_debug("%s: freeing rotator session %p (pid %d)\n",
1463 __func__, msm_rotator_dev->img_info[s],
1464 fd_info->pid);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001465 kfree(msm_rotator_dev->img_info[s]);
1466 msm_rotator_dev->img_info[s] = NULL;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001467 msm_rotator_dev->fd_info[s] = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001468 if (msm_rotator_dev->last_session_idx == s)
1469 msm_rotator_dev->last_session_idx =
1470 INVALID_SESSION;
1471 }
1472 }
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001473 list_del(&fd_info->list);
1474 kfree(fd_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001475 mutex_unlock(&msm_rotator_dev->rotator_lock);
1476
1477 return 0;
1478}
1479
1480static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1481 unsigned long arg)
1482{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001483 struct msm_rotator_fd_info *fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001484
1485 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1486 return -ENOTTY;
1487
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001488 fd_info = (struct msm_rotator_fd_info *)file->private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001489
1490 switch (cmd) {
1491 case MSM_ROTATOR_IOCTL_START:
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001492 return msm_rotator_start(arg, fd_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001493 case MSM_ROTATOR_IOCTL_ROTATE:
1494 return msm_rotator_do_rotate(arg);
1495 case MSM_ROTATOR_IOCTL_FINISH:
1496 return msm_rotator_finish(arg);
1497
1498 default:
1499 dev_dbg(msm_rotator_dev->device,
1500 "unexpected IOCTL %d\n", cmd);
1501 return -ENOTTY;
1502 }
1503}
1504
1505static const struct file_operations msm_rotator_fops = {
1506 .owner = THIS_MODULE,
1507 .open = msm_rotator_open,
1508 .release = msm_rotator_close,
1509 .unlocked_ioctl = msm_rotator_ioctl,
1510};
1511
1512static int __devinit msm_rotator_probe(struct platform_device *pdev)
1513{
1514 int rc = 0;
1515 struct resource *res;
1516 struct msm_rotator_platform_data *pdata = NULL;
1517 int i, number_of_clks;
1518 uint32_t ver;
1519
1520 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1521 if (!msm_rotator_dev) {
1522 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1523 __func__);
1524 return -ENOMEM;
1525 }
1526 for (i = 0; i < MAX_SESSIONS; i++)
1527 msm_rotator_dev->img_info[i] = NULL;
1528 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1529
1530 pdata = pdev->dev.platform_data;
1531 number_of_clks = pdata->number_of_clocks;
Olav Hauganef95ae32012-05-15 09:50:30 -07001532 rot_iommu_split_domain = pdata->rot_iommu_split_domain;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001533
1534 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1535 mutex_init(&msm_rotator_dev->imem_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001536 INIT_LIST_HEAD(&msm_rotator_dev->fd_list);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001537 msm_rotator_dev->imem_clk_state = CLK_DIS;
1538 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1539 msm_rotator_imem_clk_work_f);
1540 msm_rotator_dev->imem_clk = NULL;
1541 msm_rotator_dev->pdev = pdev;
1542
1543 msm_rotator_dev->core_clk = NULL;
1544 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001545
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001546#ifdef CONFIG_MSM_BUS_SCALING
1547 if (!msm_rotator_dev->bus_client_handle && pdata &&
1548 pdata->bus_scale_table) {
1549 msm_rotator_dev->bus_client_handle =
1550 msm_bus_scale_register_client(
1551 pdata->bus_scale_table);
1552 if (!msm_rotator_dev->bus_client_handle) {
1553 pr_err("%s not able to get bus scale handle\n",
1554 __func__);
1555 }
1556 }
1557#endif
1558
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001559 for (i = 0; i < number_of_clks; i++) {
1560 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1561 msm_rotator_dev->imem_clk =
1562 clk_get(&msm_rotator_dev->pdev->dev,
1563 pdata->rotator_clks[i].clk_name);
1564 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1565 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1566 msm_rotator_dev->imem_clk = NULL;
1567 printk(KERN_ERR "%s: cannot get imem_clk "
1568 "rc=%d\n", DRIVER_NAME, rc);
1569 goto error_imem_clk;
1570 }
1571 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001572 clk_set_rate(msm_rotator_dev->imem_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001573 pdata->rotator_clks[i].clk_rate);
1574 }
1575 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1576 msm_rotator_dev->pclk =
1577 clk_get(&msm_rotator_dev->pdev->dev,
1578 pdata->rotator_clks[i].clk_name);
1579 if (IS_ERR(msm_rotator_dev->pclk)) {
1580 rc = PTR_ERR(msm_rotator_dev->pclk);
1581 msm_rotator_dev->pclk = NULL;
1582 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1583 DRIVER_NAME, rc);
1584 goto error_pclk;
1585 }
1586
1587 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001588 clk_set_rate(msm_rotator_dev->pclk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001589 pdata->rotator_clks[i].clk_rate);
1590 }
1591
1592 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1593 msm_rotator_dev->core_clk =
1594 clk_get(&msm_rotator_dev->pdev->dev,
1595 pdata->rotator_clks[i].clk_name);
1596 if (IS_ERR(msm_rotator_dev->core_clk)) {
1597 rc = PTR_ERR(msm_rotator_dev->core_clk);
1598 msm_rotator_dev->core_clk = NULL;
1599 printk(KERN_ERR "%s: cannot get core clk "
1600 "rc=%d\n", DRIVER_NAME, rc);
1601 goto error_core_clk;
1602 }
1603
1604 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001605 clk_set_rate(msm_rotator_dev->core_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001606 pdata->rotator_clks[i].clk_rate);
1607 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001608 }
1609
Matt Wagantall316f2fc2012-05-03 20:41:42 -07001610 msm_rotator_dev->regulator = regulator_get(&msm_rotator_dev->pdev->dev,
1611 "vdd");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001612 if (IS_ERR(msm_rotator_dev->regulator))
1613 msm_rotator_dev->regulator = NULL;
1614
1615 msm_rotator_dev->rot_clk_state = CLK_DIS;
1616 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1617 msm_rotator_rot_clk_work_f);
1618
1619 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001620#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1621 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1622#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001623 platform_set_drvdata(pdev, msm_rotator_dev);
1624
1625
1626 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1627 if (!res) {
1628 printk(KERN_ALERT
1629 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1630 rc = -ENODEV;
1631 goto error_get_resource;
1632 }
1633 msm_rotator_dev->io_base = ioremap(res->start,
1634 resource_size(res));
1635
1636#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1637 if (msm_rotator_dev->imem_clk)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001638 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001639#endif
1640 enable_rot_clks();
1641 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1642 disable_rot_clks();
1643
1644#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1645 if (msm_rotator_dev->imem_clk)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001646 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001647#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001648 if (ver != pdata->hardware_version_number)
Mayank Chopra012a8e72012-04-11 10:41:13 +05301649 pr_debug("%s: invalid HW version ver 0x%x\n",
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -07001650 DRIVER_NAME, ver);
Naseer Ahmed18018602011-10-25 13:32:58 -07001651
Mayank Chopra012a8e72012-04-11 10:41:13 +05301652 rotator_hw_revision = ver;
1653 rotator_hw_revision >>= 16; /* bit 31:16 */
1654 rotator_hw_revision &= 0xff;
1655
1656 pr_info("%s: rotator_hw_revision=%x\n",
1657 __func__, rotator_hw_revision);
1658
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001659 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1660 if (msm_rotator_dev->irq < 0) {
1661 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1662 DRIVER_NAME);
1663 rc = -ENODEV;
1664 goto error_get_irq;
1665 }
1666 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1667 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1668 if (rc) {
1669 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1670 goto error_get_irq;
1671 }
1672 /* we enable the IRQ when we need it in the ioctl */
1673 disable_irq(msm_rotator_dev->irq);
1674
1675 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1676 if (rc < 0) {
1677 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1678 __func__, rc);
1679 goto error_get_irq;
1680 }
1681
1682 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1683 if (IS_ERR(msm_rotator_dev->class)) {
1684 rc = PTR_ERR(msm_rotator_dev->class);
1685 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1686 DRIVER_NAME, rc);
1687 goto error_class_create;
1688 }
1689
1690 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1691 msm_rotator_dev->dev_num, NULL,
1692 DRIVER_NAME);
1693 if (IS_ERR(msm_rotator_dev->device)) {
1694 rc = PTR_ERR(msm_rotator_dev->device);
1695 printk(KERN_ERR "%s: device_create failed %d\n",
1696 DRIVER_NAME, rc);
1697 goto error_class_device_create;
1698 }
1699
1700 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1701 rc = cdev_add(&msm_rotator_dev->cdev,
1702 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1703 1);
1704 if (rc < 0) {
1705 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1706 goto error_cdev_add;
1707 }
1708
1709 init_waitqueue_head(&msm_rotator_dev->wq);
1710
1711 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1712 return rc;
1713
1714error_cdev_add:
1715 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1716error_class_device_create:
1717 class_destroy(msm_rotator_dev->class);
1718error_class_create:
1719 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1720error_get_irq:
1721 iounmap(msm_rotator_dev->io_base);
1722error_get_resource:
1723 mutex_destroy(&msm_rotator_dev->rotator_lock);
1724 if (msm_rotator_dev->regulator)
1725 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001726 clk_put(msm_rotator_dev->core_clk);
1727error_core_clk:
1728 clk_put(msm_rotator_dev->pclk);
1729error_pclk:
1730 if (msm_rotator_dev->imem_clk)
1731 clk_put(msm_rotator_dev->imem_clk);
1732error_imem_clk:
1733 mutex_destroy(&msm_rotator_dev->imem_lock);
1734 kfree(msm_rotator_dev);
1735 return rc;
1736}
1737
1738static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1739{
1740 int i;
1741
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001742#ifdef CONFIG_MSM_BUS_SCALING
1743 msm_bus_scale_unregister_client(msm_rotator_dev->bus_client_handle);
1744#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001745 free_irq(msm_rotator_dev->irq, NULL);
1746 mutex_destroy(&msm_rotator_dev->rotator_lock);
1747 cdev_del(&msm_rotator_dev->cdev);
1748 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1749 class_destroy(msm_rotator_dev->class);
1750 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1751 iounmap(msm_rotator_dev->io_base);
1752 if (msm_rotator_dev->imem_clk) {
1753 if (msm_rotator_dev->imem_clk_state == CLK_EN)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001754 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001755 clk_put(msm_rotator_dev->imem_clk);
1756 msm_rotator_dev->imem_clk = NULL;
1757 }
1758 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1759 disable_rot_clks();
1760 clk_put(msm_rotator_dev->core_clk);
1761 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001762 if (msm_rotator_dev->regulator)
1763 regulator_put(msm_rotator_dev->regulator);
1764 msm_rotator_dev->core_clk = NULL;
1765 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001766 mutex_destroy(&msm_rotator_dev->imem_lock);
1767 for (i = 0; i < MAX_SESSIONS; i++)
1768 if (msm_rotator_dev->img_info[i] != NULL)
1769 kfree(msm_rotator_dev->img_info[i]);
1770 kfree(msm_rotator_dev);
1771 return 0;
1772}
1773
1774#ifdef CONFIG_PM
1775static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1776{
1777 mutex_lock(&msm_rotator_dev->imem_lock);
1778 if (msm_rotator_dev->imem_clk_state == CLK_EN
1779 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001780 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001781 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1782 }
1783 mutex_unlock(&msm_rotator_dev->imem_lock);
1784 mutex_lock(&msm_rotator_dev->rotator_lock);
1785 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1786 disable_rot_clks();
1787 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1788 }
1789 mutex_unlock(&msm_rotator_dev->rotator_lock);
1790 return 0;
1791}
1792
1793static int msm_rotator_resume(struct platform_device *dev)
1794{
1795 mutex_lock(&msm_rotator_dev->imem_lock);
1796 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1797 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001798 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001799 msm_rotator_dev->imem_clk_state = CLK_EN;
1800 }
1801 mutex_unlock(&msm_rotator_dev->imem_lock);
1802 mutex_lock(&msm_rotator_dev->rotator_lock);
1803 if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND) {
1804 enable_rot_clks();
1805 msm_rotator_dev->rot_clk_state = CLK_EN;
1806 }
1807 mutex_unlock(&msm_rotator_dev->rotator_lock);
1808 return 0;
1809}
1810#endif
1811
1812static struct platform_driver msm_rotator_platform_driver = {
1813 .probe = msm_rotator_probe,
1814 .remove = __devexit_p(msm_rotator_remove),
1815#ifdef CONFIG_PM
1816 .suspend = msm_rotator_suspend,
1817 .resume = msm_rotator_resume,
1818#endif
1819 .driver = {
1820 .owner = THIS_MODULE,
1821 .name = DRIVER_NAME
1822 }
1823};
1824
1825static int __init msm_rotator_init(void)
1826{
1827 return platform_driver_register(&msm_rotator_platform_driver);
1828}
1829
1830static void __exit msm_rotator_exit(void)
1831{
1832 return platform_driver_unregister(&msm_rotator_platform_driver);
1833}
1834
1835module_init(msm_rotator_init);
1836module_exit(msm_rotator_exit);
1837
1838MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1839MODULE_VERSION("1.0");
1840MODULE_LICENSE("GPL v2");