blob: 729ac1008d336f6ce24b3d3103397518cab828d5 [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>
Mitchel Humpherys9faf7e12012-09-06 10:33:12 -070031#include <linux/msm_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 }
taeyol.kim69400442012-08-03 19:15:10 -0700186 pr_debug("%s(): ion_hdl %p, ion_fd %d\n", __func__, *pihdl, mem_id);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700187
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700188 if (rot_iommu_split_domain) {
189 if (secure) {
190 if (ion_phys(msm_rotator_dev->client,
191 *pihdl, start, (unsigned *)len)) {
192 pr_err("%s:%d: ion_phys map failed\n",
193 __func__, __LINE__);
194 return -ENOMEM;
195 }
196 } else {
197 if (ion_map_iommu(msm_rotator_dev->client,
198 *pihdl, domain, GEN_POOL,
199 SZ_4K, 0, start, len, 0,
200 ION_IOMMU_UNMAP_DELAYED)) {
201 pr_err("ion_map_iommu() failed\n");
202 return -EINVAL;
203 }
204 }
205 } else {
206 if (ion_map_iommu(msm_rotator_dev->client,
207 *pihdl, ROTATOR_SRC_DOMAIN, GEN_POOL,
208 SZ_4K, 0, start, len, 0, ION_IOMMU_UNMAP_DELAYED)) {
209 pr_err("ion_map_iommu() failed\n");
210 return -EINVAL;
211 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700212 }
213
214 pr_debug("%s(): mem_id %d, start 0x%lx, len 0x%lx\n",
215 __func__, mem_id, *start, *len);
216 return 0;
217}
218
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219int msm_rotator_imem_allocate(int requestor)
220{
221 int rc = 0;
222
223#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
224 switch (requestor) {
225 case ROTATOR_REQUEST:
226 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
227 msm_rotator_dev->imem_owner = ROTATOR_REQUEST;
228 rc = 1;
229 } else
230 rc = 0;
231 break;
232 case JPEG_REQUEST:
233 mutex_lock(&msm_rotator_dev->imem_lock);
234 msm_rotator_dev->imem_owner = JPEG_REQUEST;
235 rc = 1;
236 break;
237 default:
238 rc = 0;
239 }
240#else
241 if (requestor == JPEG_REQUEST)
242 rc = 1;
243#endif
244 if (rc == 1) {
245 cancel_delayed_work(&msm_rotator_dev->imem_clk_work);
246 if (msm_rotator_dev->imem_clk_state != CLK_EN
247 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700248 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700249 msm_rotator_dev->imem_clk_state = CLK_EN;
250 }
251 }
252
253 return rc;
254}
255EXPORT_SYMBOL(msm_rotator_imem_allocate);
256
257void msm_rotator_imem_free(int requestor)
258{
259#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
260 if (msm_rotator_dev->imem_owner == requestor) {
261 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
262 mutex_unlock(&msm_rotator_dev->imem_lock);
263 }
264#else
265 if (requestor == JPEG_REQUEST)
266 schedule_delayed_work(&msm_rotator_dev->imem_clk_work, HZ);
267#endif
268}
269EXPORT_SYMBOL(msm_rotator_imem_free);
270
271static void msm_rotator_imem_clk_work_f(struct work_struct *work)
272{
273#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
274 if (mutex_trylock(&msm_rotator_dev->imem_lock)) {
275 if (msm_rotator_dev->imem_clk_state == CLK_EN
276 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700277 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700278 msm_rotator_dev->imem_clk_state = CLK_DIS;
279 } else if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND)
280 msm_rotator_dev->imem_clk_state = CLK_DIS;
281 mutex_unlock(&msm_rotator_dev->imem_lock);
282 }
283#endif
284}
285
286/* enable clocks needed by rotator block */
287static void enable_rot_clks(void)
288{
289 if (msm_rotator_dev->regulator)
290 regulator_enable(msm_rotator_dev->regulator);
291 if (msm_rotator_dev->core_clk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700292 clk_prepare_enable(msm_rotator_dev->core_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 if (msm_rotator_dev->pclk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700294 clk_prepare_enable(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295}
296
297/* disable clocks needed by rotator block */
298static void disable_rot_clks(void)
299{
300 if (msm_rotator_dev->core_clk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700301 clk_disable_unprepare(msm_rotator_dev->core_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700302 if (msm_rotator_dev->pclk != NULL)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -0700303 clk_disable_unprepare(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700304 if (msm_rotator_dev->regulator)
305 regulator_disable(msm_rotator_dev->regulator);
306}
307
308static void msm_rotator_rot_clk_work_f(struct work_struct *work)
309{
310 if (mutex_trylock(&msm_rotator_dev->rotator_lock)) {
311 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
312 disable_rot_clks();
313 msm_rotator_dev->rot_clk_state = CLK_DIS;
314 } else if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND)
315 msm_rotator_dev->rot_clk_state = CLK_DIS;
316 mutex_unlock(&msm_rotator_dev->rotator_lock);
317 }
318}
319
320static irqreturn_t msm_rotator_isr(int irq, void *dev_id)
321{
322 if (msm_rotator_dev->processing) {
323 msm_rotator_dev->processing = 0;
324 wake_up(&msm_rotator_dev->wq);
325 } else
326 printk(KERN_WARNING "%s: unexpected interrupt\n", DRIVER_NAME);
327
328 return IRQ_HANDLED;
329}
330
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700331static unsigned int tile_size(unsigned int src_width,
332 unsigned int src_height,
333 const struct tile_parm *tp)
334{
335 unsigned int tile_w, tile_h;
336 unsigned int row_num_w, row_num_h;
337 tile_w = tp->width * tp->row_tile_w;
338 tile_h = tp->height * tp->row_tile_h;
339 row_num_w = (src_width + tile_w - 1) / tile_w;
340 row_num_h = (src_height + tile_h - 1) / tile_h;
341 return ((row_num_w * row_num_h * tile_w * tile_h) + 8191) & ~8191;
342}
343
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700344static int get_bpp(int format)
345{
346 switch (format) {
347 case MDP_RGB_565:
348 case MDP_BGR_565:
349 return 2;
350
351 case MDP_XRGB_8888:
352 case MDP_ARGB_8888:
353 case MDP_RGBA_8888:
354 case MDP_BGRA_8888:
355 case MDP_RGBX_8888:
356 return 4;
357
358 case MDP_Y_CBCR_H2V2:
359 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -0700360 case MDP_Y_CB_CR_H2V2:
361 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +0530362 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700363 case MDP_Y_CRCB_H2V2_TILE:
364 case MDP_Y_CBCR_H2V2_TILE:
365 return 1;
366
367 case MDP_RGB_888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -0700368 case MDP_YCBCR_H1V1:
369 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700370 return 3;
371
372 case MDP_YCRYCB_H2V1:
373 return 2;/* YCrYCb interleave */
374
375 case MDP_Y_CRCB_H2V1:
376 case MDP_Y_CBCR_H2V1:
377 return 1;
378
379 default:
380 return -1;
381 }
382
383}
384
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700385static int msm_rotator_get_plane_sizes(uint32_t format, uint32_t w, uint32_t h,
386 struct msm_rotator_mem_planes *p)
387{
388 /*
389 * each row of samsung tile consists of two tiles in height
390 * and two tiles in width which means width should align to
391 * 64 x 2 bytes and height should align to 32 x 2 bytes.
392 * video decoder generate two tiles in width and one tile
393 * in height which ends up height align to 32 X 1 bytes.
394 */
395 const struct tile_parm tile = {64, 32, 2, 1};
396 int i;
397
398 if (p == NULL)
399 return -EINVAL;
400
401 if ((w > MSM_ROTATOR_MAX_W) || (h > MSM_ROTATOR_MAX_H))
402 return -ERANGE;
403
404 memset(p, 0, sizeof(*p));
405
406 switch (format) {
407 case MDP_XRGB_8888:
408 case MDP_ARGB_8888:
409 case MDP_RGBA_8888:
410 case MDP_BGRA_8888:
411 case MDP_RGBX_8888:
412 case MDP_RGB_888:
413 case MDP_RGB_565:
414 case MDP_BGR_565:
415 case MDP_YCRYCB_H2V1:
Kyong Hwa Baeebf19192012-05-09 16:31:05 -0700416 case MDP_YCBCR_H1V1:
417 case MDP_YCRCB_H1V1:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700418 p->num_planes = 1;
419 p->plane_size[0] = w * h * get_bpp(format);
420 break;
421 case MDP_Y_CRCB_H2V1:
422 case MDP_Y_CBCR_H2V1:
Mayank Chopra797bdb72012-03-03 06:29:40 +0530423 case MDP_Y_CRCB_H1V2:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700424 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 Chopra797bdb72012-03-03 06:29:40 +0530654 if (info->src.format == MDP_YCRYCB_H2V1) {
655 if (info->rotations & MDP_ROT_90)
656 dst_format = MDP_Y_CRCB_H1V2;
657 else
658 dst_format = MDP_Y_CRCB_H2V1;
659 } else
Mayank Chopra732dcd62012-01-09 20:53:39 +0530660 return -EINVAL;
661
662 if (info->dst.format != dst_format)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700663 return -EINVAL;
664
665 bpp = get_bpp(info->src.format);
666 if (bpp < 0)
667 return -ENOTTY;
668
669 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
670 iowrite32(out_paddr +
671 ((info->dst_y * info->dst.width) + info->dst_x),
672 MSM_ROTATOR_OUTP0_ADDR);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530673 iowrite32(out_chroma_paddr +
674 ((info->dst_y * info->dst.width)/2 + info->dst_x),
675 MSM_ROTATOR_OUTP1_ADDR);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676
677 if (new_session) {
Mayank Chopra732dcd62012-01-09 20:53:39 +0530678 iowrite32(info->src.width * bpp,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700679 MSM_ROTATOR_SRC_YSTRIDE1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530680 if (info->rotations & MDP_ROT_90)
681 iowrite32(info->dst.width |
682 (info->dst.width*2) << 16,
683 MSM_ROTATOR_OUT_YSTRIDE1);
684 else
685 iowrite32(info->dst.width |
686 (info->dst.width) << 16,
687 MSM_ROTATOR_OUT_YSTRIDE1);
688
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700689 iowrite32(GET_PACK_PATTERN(CLR_Y, CLR_CR, CLR_Y, CLR_CB, 8),
690 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
Mayank Chopra732dcd62012-01-09 20:53:39 +0530691 iowrite32(GET_PACK_PATTERN(0, 0, CLR_CR, CLR_CB, 8),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700692 MSM_ROTATOR_OUT_PACK_PATTERN1);
693 iowrite32((1 << 18) | /* chroma sampling 1=H2V1 */
694 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700695 1 << 8 | /* ROT_EN */
696 info->downscale_ratio << 2 | /* downscale v ratio */
697 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 MSM_ROTATOR_SUB_BLOCK_CFG);
699 iowrite32(0 << 29 | /* frame format 0 = linear */
700 (use_imem ? 0 : 1) << 22 | /* tile size */
701 0 << 19 | /* fetch planes 0=interleaved */
702 0 << 18 | /* unpack align */
703 1 << 17 | /* unpack tight */
704 3 << 13 | /* unpack count 0=1 component */
705 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
706 0 << 8 | /* has alpha */
707 0 << 6 | /* alpha bits 3=8bits */
708 3 << 4 | /* R/Cr bits 1=5 2=6 3=8 */
709 3 << 2 | /* B/Cb bits 1=5 2=6 3=8 */
710 3 << 0, /* G/Y bits 1=5 2=6 3=8 */
711 MSM_ROTATOR_SRC_FORMAT);
712 }
713
714 return 0;
715}
716
717static int msm_rotator_rgb_types(struct msm_rotator_img_info *info,
718 unsigned int in_paddr,
719 unsigned int out_paddr,
720 unsigned int use_imem,
721 int new_session)
722{
723 int bpp, abits, rbits, gbits, bbits;
724
725 if (info->src.format != info->dst.format)
726 return -EINVAL;
727
728 bpp = get_bpp(info->src.format);
729 if (bpp < 0)
730 return -ENOTTY;
731
732 iowrite32(in_paddr, MSM_ROTATOR_SRCP0_ADDR);
733 iowrite32(out_paddr +
734 ((info->dst_y * info->dst.width) + info->dst_x) * bpp,
735 MSM_ROTATOR_OUTP0_ADDR);
736
737 if (new_session) {
738 iowrite32(info->src.width * bpp, MSM_ROTATOR_SRC_YSTRIDE1);
739 iowrite32(info->dst.width * bpp, MSM_ROTATOR_OUT_YSTRIDE1);
740 iowrite32((0 << 18) | /* chroma sampling 0=rgb */
741 (ROTATIONS_TO_BITMASK(info->rotations) << 9) |
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -0700742 1 << 8 | /* ROT_EN */
743 info->downscale_ratio << 2 | /* downscale v ratio */
744 info->downscale_ratio, /* downscale h ratio */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700745 MSM_ROTATOR_SUB_BLOCK_CFG);
746 switch (info->src.format) {
747 case MDP_RGB_565:
748 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
749 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
750 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
751 MSM_ROTATOR_OUT_PACK_PATTERN1);
752 abits = 0;
753 rbits = COMPONENT_5BITS;
754 gbits = COMPONENT_6BITS;
755 bbits = COMPONENT_5BITS;
756 break;
757
758 case MDP_BGR_565:
759 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
760 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
761 iowrite32(GET_PACK_PATTERN(0, CLR_B, CLR_G, CLR_R, 8),
762 MSM_ROTATOR_OUT_PACK_PATTERN1);
763 abits = 0;
764 rbits = COMPONENT_5BITS;
765 gbits = COMPONENT_6BITS;
766 bbits = COMPONENT_5BITS;
767 break;
768
769 case MDP_RGB_888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -0700770 case MDP_YCBCR_H1V1:
771 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700772 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
773 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
774 iowrite32(GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 8),
775 MSM_ROTATOR_OUT_PACK_PATTERN1);
776 abits = 0;
777 rbits = COMPONENT_8BITS;
778 gbits = COMPONENT_8BITS;
779 bbits = COMPONENT_8BITS;
780 break;
781
782 case MDP_ARGB_8888:
783 case MDP_RGBA_8888:
784 case MDP_XRGB_8888:
785 case MDP_RGBX_8888:
786 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
787 CLR_B, 8),
788 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
789 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_R, CLR_G,
790 CLR_B, 8),
791 MSM_ROTATOR_OUT_PACK_PATTERN1);
792 abits = COMPONENT_8BITS;
793 rbits = COMPONENT_8BITS;
794 gbits = COMPONENT_8BITS;
795 bbits = COMPONENT_8BITS;
796 break;
797
798 case MDP_BGRA_8888:
799 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
800 CLR_R, 8),
801 MSM_ROTATOR_SRC_UNPACK_PATTERN1);
802 iowrite32(GET_PACK_PATTERN(CLR_ALPHA, CLR_B, CLR_G,
803 CLR_R, 8),
804 MSM_ROTATOR_OUT_PACK_PATTERN1);
805 abits = COMPONENT_8BITS;
806 rbits = COMPONENT_8BITS;
807 gbits = COMPONENT_8BITS;
808 bbits = COMPONENT_8BITS;
809 break;
810
811 default:
812 return -EINVAL;
813 }
814 iowrite32(0 << 29 | /* frame format 0 = linear */
815 (use_imem ? 0 : 1) << 22 | /* tile size */
816 0 << 19 | /* fetch planes 0=interleaved */
817 0 << 18 | /* unpack align */
818 1 << 17 | /* unpack tight */
819 (abits ? 3 : 2) << 13 | /* unpack count 0=1 comp */
820 (bpp-1) << 9 | /* src Bpp 0=1 byte ... */
821 (abits ? 1 : 0) << 8 | /* has alpha */
822 abits << 6 | /* alpha bits 3=8bits */
823 rbits << 4 | /* R/Cr bits 1=5 2=6 3=8 */
824 bbits << 2 | /* B/Cb bits 1=5 2=6 3=8 */
825 gbits << 0, /* G/Y bits 1=5 2=6 3=8 */
826 MSM_ROTATOR_SRC_FORMAT);
827 }
828
829 return 0;
830}
831
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700832static int get_img(struct msmfb_data *fbd, int domain,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700833 unsigned long *start, unsigned long *len, struct file **p_file,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700834 int *p_need, struct ion_handle **p_ihdl, unsigned int secure)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700835{
836 int ret = 0;
837#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700838 struct file *file = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700839 int put_needed, fb_num;
840#endif
841#ifdef CONFIG_ANDROID_PMEM
842 unsigned long vstart;
843#endif
844
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800845 *p_need = 0;
846
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847#ifdef CONFIG_FB
Naseer Ahmed18018602011-10-25 13:32:58 -0700848 if (fbd->flags & MDP_MEMORY_ID_TYPE_FB) {
849 file = fget_light(fbd->memory_id, &put_needed);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700850 if (file == NULL) {
851 pr_err("fget_light returned NULL\n");
Naseer Ahmed18018602011-10-25 13:32:58 -0700852 return -EINVAL;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700853 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700854
Naseer Ahmed18018602011-10-25 13:32:58 -0700855 if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
856 fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700857 if (get_fb_phys_info(start, len, fb_num,
858 ROTATOR_SUBSYSTEM_ID)) {
859 pr_err("get_fb_phys_info() failed\n");
Naseer Ahmed18018602011-10-25 13:32:58 -0700860 ret = -1;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700861 } else {
Naseer Ahmed18018602011-10-25 13:32:58 -0700862 *p_file = file;
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800863 *p_need = put_needed;
864 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700865 } else {
866 pr_err("invalid FB_MAJOR failed\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867 ret = -1;
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700868 }
Naseer Ahmed18018602011-10-25 13:32:58 -0700869 if (ret)
870 fput_light(file, put_needed);
871 return ret;
872 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700873#endif
Naseer Ahmed18018602011-10-25 13:32:58 -0700874
875#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700876 return msm_rotator_iommu_map_buf(fbd->memory_id, domain, start,
877 len, p_ihdl, secure);
Naseer Ahmed18018602011-10-25 13:32:58 -0700878#endif
879#ifdef CONFIG_ANDROID_PMEM
880 if (!get_pmem_file(fbd->memory_id, start, &vstart, len, p_file))
881 return 0;
882 else
883 return -ENOMEM;
884#endif
885
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700886}
887
Olav Hauganef95ae32012-05-15 09:50:30 -0700888static void put_img(struct file *p_file, struct ion_handle *p_ihdl,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700889 int domain, unsigned int secure)
Naseer Ahmed18018602011-10-25 13:32:58 -0700890{
891#ifdef CONFIG_ANDROID_PMEM
892 if (p_file != NULL)
893 put_pmem_file(p_file);
894#endif
Olav Hauganef95ae32012-05-15 09:50:30 -0700895
Naseer Ahmed18018602011-10-25 13:32:58 -0700896#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700897 if (!IS_ERR_OR_NULL(p_ihdl)) {
898 pr_debug("%s(): p_ihdl %p\n", __func__, p_ihdl);
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700899 if (rot_iommu_split_domain) {
900 if (!secure)
901 ion_unmap_iommu(msm_rotator_dev->client,
902 p_ihdl, domain, GEN_POOL);
903 } else {
904 ion_unmap_iommu(msm_rotator_dev->client,
905 p_ihdl, ROTATOR_SRC_DOMAIN, GEN_POOL);
906 }
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700907
Naseer Ahmed18018602011-10-25 13:32:58 -0700908 ion_free(msm_rotator_dev->client, p_ihdl);
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700909 }
Naseer Ahmed18018602011-10-25 13:32:58 -0700910#endif
911}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912static int msm_rotator_do_rotate(unsigned long arg)
913{
Naseer Ahmed18018602011-10-25 13:32:58 -0700914 unsigned int status, format;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915 struct msm_rotator_data_info info;
916 unsigned int in_paddr, out_paddr;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700917 unsigned long src_len, dst_len;
Naseer Ahmed18018602011-10-25 13:32:58 -0700918 int use_imem = 0, rc = 0, s;
919 struct file *srcp0_file = NULL, *dstp0_file = NULL;
920 struct file *srcp1_file = NULL, *dstp1_file = NULL;
921 struct ion_handle *srcp0_ihdl = NULL, *dstp0_ihdl = NULL;
922 struct ion_handle *srcp1_ihdl = NULL, *dstp1_ihdl = NULL;
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -0800923 int ps0_need, p_need;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 unsigned int in_chroma_paddr = 0, out_chroma_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700925 unsigned int in_chroma2_paddr = 0;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700926 struct msm_rotator_img_info *img_info;
927 struct msm_rotator_mem_planes src_planes, dst_planes;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928
929 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
930 return -EFAULT;
931
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 mutex_lock(&msm_rotator_dev->rotator_lock);
933 for (s = 0; s < MAX_SESSIONS; s++)
934 if ((msm_rotator_dev->img_info[s] != NULL) &&
935 (info.session_id ==
936 (unsigned int)msm_rotator_dev->img_info[s]
937 ))
938 break;
939
940 if (s == MAX_SESSIONS) {
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -0700941 pr_err("%s() : Attempt to use invalid session_id %d\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700942 __func__, s);
943 rc = -EINVAL;
944 goto do_rotate_unlock_mutex;
945 }
946
947 if (msm_rotator_dev->img_info[s]->enable == 0) {
948 dev_dbg(msm_rotator_dev->device,
949 "%s() : Session_id %d not enabled \n",
950 __func__, s);
951 rc = -EINVAL;
952 goto do_rotate_unlock_mutex;
953 }
954
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700955 img_info = msm_rotator_dev->img_info[s];
956 if (msm_rotator_get_plane_sizes(img_info->src.format,
957 img_info->src.width,
958 img_info->src.height,
959 &src_planes)) {
960 pr_err("%s: invalid src format\n", __func__);
961 rc = -EINVAL;
962 goto do_rotate_unlock_mutex;
963 }
964 if (msm_rotator_get_plane_sizes(img_info->dst.format,
965 img_info->dst.width,
966 img_info->dst.height,
967 &dst_planes)) {
968 pr_err("%s: invalid dst format\n", __func__);
969 rc = -EINVAL;
970 goto do_rotate_unlock_mutex;
971 }
972
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700973 rc = get_img(&info.src, ROTATOR_SRC_DOMAIN, (unsigned long *)&in_paddr,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700974 (unsigned long *)&src_len, &srcp0_file, &ps0_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700975 &srcp0_ihdl, 0);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700976 if (rc) {
977 pr_err("%s: in get_img() failed id=0x%08x\n",
978 DRIVER_NAME, info.src.memory_id);
979 goto do_rotate_unlock_mutex;
980 }
981
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700982 rc = get_img(&info.dst, ROTATOR_DST_DOMAIN, (unsigned long *)&out_paddr,
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -0700983 (unsigned long *)&dst_len, &dstp0_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -0700984 &dstp0_ihdl, img_info->secure);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700985 if (rc) {
986 pr_err("%s: out get_img() failed id=0x%08x\n",
987 DRIVER_NAME, info.dst.memory_id);
988 goto do_rotate_unlock_mutex;
989 }
990
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700991 format = msm_rotator_dev->img_info[s]->src.format;
992 if (((info.version_key & VERSION_KEY_MASK) == 0xA5B4C300) &&
Adrian Salido-Moreno88411862011-09-20 18:54:03 -0700993 ((info.version_key & ~VERSION_KEY_MASK) > 0) &&
994 (src_planes.num_planes == 2)) {
995 if (checkoffset(info.src.offset,
996 src_planes.plane_size[0],
997 src_len)) {
998 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
999 __func__, src_len, info.src.offset);
1000 rc = -ERANGE;
1001 goto do_rotate_unlock_mutex;
1002 }
1003 if (checkoffset(info.dst.offset,
1004 dst_planes.plane_size[0],
1005 dst_len)) {
1006 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
1007 __func__, dst_len, info.dst.offset);
1008 rc = -ERANGE;
1009 goto do_rotate_unlock_mutex;
1010 }
1011
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001012 rc = get_img(&info.src_chroma, ROTATOR_SRC_DOMAIN,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001013 (unsigned long *)&in_chroma_paddr,
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001014 (unsigned long *)&src_len, &srcp1_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001015 &srcp1_ihdl, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001017 pr_err("%s: in chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001018 DRIVER_NAME, info.src_chroma.memory_id);
1019 goto do_rotate_unlock_mutex;
1020 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001021
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001022 rc = get_img(&info.dst_chroma, ROTATOR_DST_DOMAIN,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001023 (unsigned long *)&out_chroma_paddr,
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001024 (unsigned long *)&dst_len, &dstp1_file, &p_need,
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001025 &dstp1_ihdl, img_info->secure);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001026 if (rc) {
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001027 pr_err("%s: out chroma get_img() failed id=0x%08x\n",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001028 DRIVER_NAME, info.dst_chroma.memory_id);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001029 goto do_rotate_unlock_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001030 }
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001031
1032 if (checkoffset(info.src_chroma.offset,
1033 src_planes.plane_size[1],
1034 src_len)) {
1035 pr_err("%s: invalid chr src buf len=%lu offset=%x\n",
1036 __func__, src_len, info.src_chroma.offset);
1037 rc = -ERANGE;
1038 goto do_rotate_unlock_mutex;
1039 }
1040
1041 if (checkoffset(info.dst_chroma.offset,
1042 src_planes.plane_size[1],
1043 dst_len)) {
1044 pr_err("%s: invalid chr dst buf len=%lu offset=%x\n",
1045 __func__, dst_len, info.dst_chroma.offset);
1046 rc = -ERANGE;
1047 goto do_rotate_unlock_mutex;
1048 }
1049
1050 in_chroma_paddr += info.src_chroma.offset;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001051 out_chroma_paddr += info.dst_chroma.offset;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001052 } else {
1053 if (checkoffset(info.src.offset,
1054 src_planes.total_size,
1055 src_len)) {
1056 pr_err("%s: invalid src buffer (len=%lu offset=%x)\n",
1057 __func__, src_len, info.src.offset);
1058 rc = -ERANGE;
1059 goto do_rotate_unlock_mutex;
1060 }
1061 if (checkoffset(info.dst.offset,
1062 dst_planes.total_size,
1063 dst_len)) {
1064 pr_err("%s: invalid dst buffer (len=%lu offset=%x)\n",
1065 __func__, dst_len, info.dst.offset);
1066 rc = -ERANGE;
1067 goto do_rotate_unlock_mutex;
1068 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001069 }
1070
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001071 in_paddr += info.src.offset;
1072 out_paddr += info.dst.offset;
1073
1074 if (!in_chroma_paddr && src_planes.num_planes >= 2)
1075 in_chroma_paddr = in_paddr + src_planes.plane_size[0];
1076 if (!out_chroma_paddr && dst_planes.num_planes >= 2)
1077 out_chroma_paddr = out_paddr + dst_planes.plane_size[0];
1078 if (src_planes.num_planes >= 3)
1079 in_chroma2_paddr = in_chroma_paddr + src_planes.plane_size[1];
1080
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001081 cancel_delayed_work(&msm_rotator_dev->rot_clk_work);
1082 if (msm_rotator_dev->rot_clk_state != CLK_EN) {
1083 enable_rot_clks();
1084 msm_rotator_dev->rot_clk_state = CLK_EN;
1085 }
1086 enable_irq(msm_rotator_dev->irq);
1087
1088#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1089 use_imem = msm_rotator_imem_allocate(ROTATOR_REQUEST);
1090#else
1091 use_imem = 0;
1092#endif
1093 /*
1094 * workaround for a hardware bug. rotator hardware hangs when we
1095 * use write burst beat size 16 on 128X128 tile fetch mode. As a
1096 * temporary fix use 0x42 for BURST_SIZE when imem used.
1097 */
1098 if (use_imem)
1099 iowrite32(0x42, MSM_ROTATOR_MAX_BURST_SIZE);
1100
1101 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.h & 0x1fff)
1102 << 16) |
1103 (msm_rotator_dev->img_info[s]->src_rect.w & 0x1fff),
1104 MSM_ROTATOR_SRC_SIZE);
1105 iowrite32(((msm_rotator_dev->img_info[s]->src_rect.y & 0x1fff)
1106 << 16) |
1107 (msm_rotator_dev->img_info[s]->src_rect.x & 0x1fff),
1108 MSM_ROTATOR_SRC_XY);
1109 iowrite32(((msm_rotator_dev->img_info[s]->src.height & 0x1fff)
1110 << 16) |
1111 (msm_rotator_dev->img_info[s]->src.width & 0x1fff),
1112 MSM_ROTATOR_SRC_IMAGE_SIZE);
1113
1114 switch (format) {
1115 case MDP_RGB_565:
1116 case MDP_BGR_565:
1117 case MDP_RGB_888:
1118 case MDP_ARGB_8888:
1119 case MDP_RGBA_8888:
1120 case MDP_XRGB_8888:
1121 case MDP_BGRA_8888:
1122 case MDP_RGBX_8888:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -07001123 case MDP_YCBCR_H1V1:
1124 case MDP_YCRCB_H1V1:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001125 rc = msm_rotator_rgb_types(msm_rotator_dev->img_info[s],
1126 in_paddr, out_paddr,
1127 use_imem,
1128 msm_rotator_dev->last_session_idx
1129 != s);
1130 break;
1131 case MDP_Y_CBCR_H2V2:
1132 case MDP_Y_CRCB_H2V2:
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001133 case MDP_Y_CB_CR_H2V2:
1134 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301135 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001136 case MDP_Y_CRCB_H2V2_TILE:
1137 case MDP_Y_CBCR_H2V2_TILE:
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001138 rc = msm_rotator_ycxcx_h2v2(msm_rotator_dev->img_info[s],
1139 in_paddr, out_paddr, use_imem,
1140 msm_rotator_dev->last_session_idx
1141 != s,
1142 in_chroma_paddr,
1143 out_chroma_paddr,
1144 in_chroma2_paddr);
1145 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001146 case MDP_Y_CBCR_H2V1:
1147 case MDP_Y_CRCB_H2V1:
1148 rc = msm_rotator_ycxcx_h2v1(msm_rotator_dev->img_info[s],
1149 in_paddr, out_paddr, use_imem,
1150 msm_rotator_dev->last_session_idx
1151 != s,
1152 in_chroma_paddr,
1153 out_chroma_paddr);
1154 break;
1155 case MDP_YCRYCB_H2V1:
1156 rc = msm_rotator_ycrycb(msm_rotator_dev->img_info[s],
1157 in_paddr, out_paddr, use_imem,
Mayank Chopra732dcd62012-01-09 20:53:39 +05301158 msm_rotator_dev->last_session_idx != s,
1159 out_chroma_paddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001160 break;
1161 default:
1162 rc = -EINVAL;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001163 pr_err("%s(): Unsupported format %u\n", __func__, format);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001164 goto do_rotate_exit;
1165 }
1166
1167 if (rc != 0) {
1168 msm_rotator_dev->last_session_idx = INVALID_SESSION;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001169 pr_err("%s(): Invalid session error\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001170 goto do_rotate_exit;
1171 }
1172
1173 iowrite32(3, MSM_ROTATOR_INTR_ENABLE);
1174
1175 msm_rotator_dev->processing = 1;
1176 iowrite32(0x1, MSM_ROTATOR_START);
1177
1178 wait_event(msm_rotator_dev->wq,
1179 (msm_rotator_dev->processing == 0));
1180 status = (unsigned char)ioread32(MSM_ROTATOR_INTR_STATUS);
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001181 if ((status & 0x03) != 0x01) {
1182 pr_err("%s(): AXI Bus Error, issuing SW_RESET\n", __func__);
1183 iowrite32(0x1, MSM_ROTATOR_SW_RESET);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001184 rc = -EFAULT;
Ravishangar Kalyanam30cf3eb2012-04-13 18:10:26 -07001185 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001186 iowrite32(0, MSM_ROTATOR_INTR_ENABLE);
1187 iowrite32(3, MSM_ROTATOR_INTR_CLEAR);
1188
1189do_rotate_exit:
1190 disable_irq(msm_rotator_dev->irq);
1191#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1192 msm_rotator_imem_free(ROTATOR_REQUEST);
1193#endif
1194 schedule_delayed_work(&msm_rotator_dev->rot_clk_work, HZ);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001195do_rotate_unlock_mutex:
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001196 put_img(dstp1_file, dstp1_ihdl, ROTATOR_DST_DOMAIN,
1197 msm_rotator_dev->img_info[s]->secure);
1198 put_img(srcp1_file, srcp1_ihdl, ROTATOR_SRC_DOMAIN, 0);
1199 put_img(dstp0_file, dstp0_ihdl, ROTATOR_DST_DOMAIN,
1200 msm_rotator_dev->img_info[s]->secure);
Kuogee Hsiehbeaa9352012-02-24 16:59:26 -08001201
1202 /* only source may use frame buffer */
1203 if (info.src.flags & MDP_MEMORY_ID_TYPE_FB)
1204 fput_light(srcp0_file, ps0_need);
1205 else
Ravishangar Kalyanam1eca3522012-05-31 18:02:24 -07001206 put_img(srcp0_file, srcp0_ihdl, ROTATOR_SRC_DOMAIN, 0);
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001207 mutex_unlock(&msm_rotator_dev->rotator_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001208 dev_dbg(msm_rotator_dev->device, "%s() returning rc = %d\n",
1209 __func__, rc);
1210 return rc;
1211}
1212
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001213static void msm_rotator_set_perf_level(u32 wh, u32 is_rgb)
1214{
1215 u32 perf_level;
1216
1217 if (is_rgb)
1218 perf_level = 1;
1219 else if (wh <= (640 * 480))
1220 perf_level = 2;
1221 else if (wh <= (736 * 1280))
1222 perf_level = 3;
1223 else
1224 perf_level = 4;
1225
1226#ifdef CONFIG_MSM_BUS_SCALING
1227 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1228 perf_level);
1229#endif
1230
1231}
1232
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001233static int msm_rotator_start(unsigned long arg,
1234 struct msm_rotator_fd_info *fd_info)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001235{
1236 struct msm_rotator_img_info info;
1237 int rc = 0;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001238 int s, is_rgb = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001239 int first_free_index = INVALID_SESSION;
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001240 unsigned int dst_w, dst_h;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001241
1242 if (copy_from_user(&info, (void __user *)arg, sizeof(info)))
1243 return -EFAULT;
1244
1245 if ((info.rotations > MSM_ROTATOR_MAX_ROT) ||
1246 (info.src.height > MSM_ROTATOR_MAX_H) ||
1247 (info.src.width > MSM_ROTATOR_MAX_W) ||
1248 (info.dst.height > MSM_ROTATOR_MAX_H) ||
1249 (info.dst.width > MSM_ROTATOR_MAX_W) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001250 (info.downscale_ratio > MAX_DOWNSCALE_RATIO)) {
1251 pr_err("%s: Invalid parameters\n", __func__);
1252 return -EINVAL;
1253 }
1254
1255 if (info.rotations & MDP_ROT_90) {
1256 dst_w = info.src_rect.h >> info.downscale_ratio;
1257 dst_h = info.src_rect.w >> info.downscale_ratio;
1258 } else {
1259 dst_w = info.src_rect.w >> info.downscale_ratio;
1260 dst_h = info.src_rect.h >> info.downscale_ratio;
1261 }
1262
1263 if (checkoffset(info.src_rect.x, info.src_rect.w, info.src.width) ||
Adrian Salido-Moreno88411862011-09-20 18:54:03 -07001264 checkoffset(info.src_rect.y, info.src_rect.h, info.src.height) ||
1265 checkoffset(info.dst_x, dst_w, info.dst.width) ||
Adrian Salido-Moreno67273e52011-10-21 19:04:18 -07001266 checkoffset(info.dst_y, dst_h, info.dst.height)) {
1267 pr_err("%s: Invalid src or dst rect\n", __func__);
1268 return -ERANGE;
1269 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001270
1271 switch (info.src.format) {
1272 case MDP_RGB_565:
1273 case MDP_BGR_565:
1274 case MDP_RGB_888:
1275 case MDP_ARGB_8888:
1276 case MDP_RGBA_8888:
1277 case MDP_XRGB_8888:
1278 case MDP_RGBX_8888:
1279 case MDP_BGRA_8888:
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001280 is_rgb = 1;
Mayank Chopra012a8e72012-04-11 10:41:13 +05301281 info.dst.format = info.src.format;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001282 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001283 case MDP_Y_CBCR_H2V2:
1284 case MDP_Y_CRCB_H2V2:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301285 case MDP_Y_CBCR_H2V1:
1286 case MDP_Y_CRCB_H2V1:
Adrian Salido-Morenoeeb06c72011-08-15 10:41:35 -07001287 case MDP_YCBCR_H1V1:
1288 case MDP_YCRCB_H1V1:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301289 info.dst.format = info.src.format;
1290 break;
1291 case MDP_YCRYCB_H2V1:
Mayank Chopra797bdb72012-03-03 06:29:40 +05301292 if (info.rotations & MDP_ROT_90)
1293 info.dst.format = MDP_Y_CRCB_H1V2;
1294 else
1295 info.dst.format = MDP_Y_CRCB_H2V1;
Mayank Chopra012a8e72012-04-11 10:41:13 +05301296 break;
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001297 case MDP_Y_CB_CR_H2V2:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301298 case MDP_Y_CBCR_H2V2_TILE:
1299 info.dst.format = MDP_Y_CBCR_H2V2;
1300 break;
Adrian Salido-Moreno0644f342011-07-08 12:05:01 -07001301 case MDP_Y_CR_CB_H2V2:
Pradeep Jilagam9b4a6be2011-10-03 17:19:20 +05301302 case MDP_Y_CR_CB_GH2V2:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001303 case MDP_Y_CRCB_H2V2_TILE:
Mayank Chopra012a8e72012-04-11 10:41:13 +05301304 info.dst.format = MDP_Y_CRCB_H2V2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305 break;
1306 default:
1307 return -EINVAL;
1308 }
1309
1310 mutex_lock(&msm_rotator_dev->rotator_lock);
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001311
1312 msm_rotator_set_perf_level((info.src.width*info.src.height), is_rgb);
1313
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001314 for (s = 0; s < MAX_SESSIONS; s++) {
1315 if ((msm_rotator_dev->img_info[s] != NULL) &&
1316 (info.session_id ==
1317 (unsigned int)msm_rotator_dev->img_info[s]
1318 )) {
1319 *(msm_rotator_dev->img_info[s]) = info;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001320 msm_rotator_dev->fd_info[s] = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001321
1322 if (msm_rotator_dev->last_session_idx == s)
1323 msm_rotator_dev->last_session_idx =
1324 INVALID_SESSION;
1325 break;
1326 }
1327
1328 if ((msm_rotator_dev->img_info[s] == NULL) &&
1329 (first_free_index ==
1330 INVALID_SESSION))
1331 first_free_index = s;
1332 }
1333
1334 if ((s == MAX_SESSIONS) && (first_free_index != INVALID_SESSION)) {
1335 /* allocate a session id */
1336 msm_rotator_dev->img_info[first_free_index] =
1337 kzalloc(sizeof(struct msm_rotator_img_info),
1338 GFP_KERNEL);
1339 if (!msm_rotator_dev->img_info[first_free_index]) {
1340 printk(KERN_ERR "%s : unable to alloc mem\n",
1341 __func__);
1342 rc = -ENOMEM;
1343 goto rotator_start_exit;
1344 }
1345 info.session_id = (unsigned int)
1346 msm_rotator_dev->img_info[first_free_index];
1347 *(msm_rotator_dev->img_info[first_free_index]) = info;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001348 msm_rotator_dev->fd_info[first_free_index] = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001349 } else if (s == MAX_SESSIONS) {
1350 dev_dbg(msm_rotator_dev->device, "%s: all sessions in use\n",
1351 __func__);
1352 rc = -EBUSY;
1353 }
1354
Adrian Salido-Morenoc5639952012-04-20 19:07:58 -07001355 if (rc == 0 && copy_to_user((void __user *)arg, &info, sizeof(info)))
1356 rc = -EFAULT;
1357
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001358rotator_start_exit:
1359 mutex_unlock(&msm_rotator_dev->rotator_lock);
1360
1361 return rc;
1362}
1363
1364static int msm_rotator_finish(unsigned long arg)
1365{
1366 int rc = 0;
1367 int s;
1368 unsigned int session_id;
1369
1370 if (copy_from_user(&session_id, (void __user *)arg, sizeof(s)))
1371 return -EFAULT;
1372
1373 mutex_lock(&msm_rotator_dev->rotator_lock);
1374 for (s = 0; s < MAX_SESSIONS; s++) {
1375 if ((msm_rotator_dev->img_info[s] != NULL) &&
1376 (session_id ==
1377 (unsigned int)msm_rotator_dev->img_info[s])) {
1378 if (msm_rotator_dev->last_session_idx == s)
1379 msm_rotator_dev->last_session_idx =
1380 INVALID_SESSION;
1381 kfree(msm_rotator_dev->img_info[s]);
1382 msm_rotator_dev->img_info[s] = NULL;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001383 msm_rotator_dev->fd_info[s] = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001384 break;
1385 }
1386 }
1387
1388 if (s == MAX_SESSIONS)
1389 rc = -EINVAL;
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001390#ifdef CONFIG_MSM_BUS_SCALING
1391 msm_bus_scale_client_update_request(msm_rotator_dev->bus_client_handle,
1392 0);
1393#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001394 mutex_unlock(&msm_rotator_dev->rotator_lock);
1395 return rc;
1396}
1397
1398static int
1399msm_rotator_open(struct inode *inode, struct file *filp)
1400{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001401 struct msm_rotator_fd_info *tmp, *fd_info = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001402 int i;
1403
1404 if (filp->private_data)
1405 return -EBUSY;
1406
1407 mutex_lock(&msm_rotator_dev->rotator_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001408 for (i = 0; i < MAX_SESSIONS; i++) {
1409 if (msm_rotator_dev->fd_info[i] == NULL)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001410 break;
1411 }
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001412
1413 if (i == MAX_SESSIONS) {
1414 mutex_unlock(&msm_rotator_dev->rotator_lock);
1415 return -EBUSY;
1416 }
1417
1418 list_for_each_entry(tmp, &msm_rotator_dev->fd_list, list) {
1419 if (tmp->pid == current->pid) {
1420 fd_info = tmp;
1421 break;
1422 }
1423 }
1424
1425 if (!fd_info) {
1426 fd_info = kzalloc(sizeof(*fd_info), GFP_KERNEL);
1427 if (!fd_info) {
1428 mutex_unlock(&msm_rotator_dev->rotator_lock);
1429 pr_err("%s: insufficient memory to alloc resources\n",
1430 __func__);
1431 return -ENOMEM;
1432 }
1433 list_add(&fd_info->list, &msm_rotator_dev->fd_list);
1434 fd_info->pid = current->pid;
1435 }
1436 fd_info->ref_cnt++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001437 mutex_unlock(&msm_rotator_dev->rotator_lock);
1438
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001439 filp->private_data = fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001440
1441 return 0;
1442}
1443
1444static int
1445msm_rotator_close(struct inode *inode, struct file *filp)
1446{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001447 struct msm_rotator_fd_info *fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001448 int s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001449
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001450 fd_info = (struct msm_rotator_fd_info *)filp->private_data;
1451
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001452 mutex_lock(&msm_rotator_dev->rotator_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001453 if (--fd_info->ref_cnt > 0) {
1454 mutex_unlock(&msm_rotator_dev->rotator_lock);
1455 return 0;
1456 }
1457
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001458 for (s = 0; s < MAX_SESSIONS; s++) {
1459 if (msm_rotator_dev->img_info[s] != NULL &&
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001460 msm_rotator_dev->fd_info[s] == fd_info) {
1461 pr_debug("%s: freeing rotator session %p (pid %d)\n",
1462 __func__, msm_rotator_dev->img_info[s],
1463 fd_info->pid);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001464 kfree(msm_rotator_dev->img_info[s]);
1465 msm_rotator_dev->img_info[s] = NULL;
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001466 msm_rotator_dev->fd_info[s] = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001467 if (msm_rotator_dev->last_session_idx == s)
1468 msm_rotator_dev->last_session_idx =
1469 INVALID_SESSION;
1470 }
1471 }
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001472 list_del(&fd_info->list);
1473 kfree(fd_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001474 mutex_unlock(&msm_rotator_dev->rotator_lock);
1475
1476 return 0;
1477}
1478
1479static long msm_rotator_ioctl(struct file *file, unsigned cmd,
1480 unsigned long arg)
1481{
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001482 struct msm_rotator_fd_info *fd_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001483
1484 if (_IOC_TYPE(cmd) != MSM_ROTATOR_IOCTL_MAGIC)
1485 return -ENOTTY;
1486
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001487 fd_info = (struct msm_rotator_fd_info *)file->private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001488
1489 switch (cmd) {
1490 case MSM_ROTATOR_IOCTL_START:
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001491 return msm_rotator_start(arg, fd_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001492 case MSM_ROTATOR_IOCTL_ROTATE:
1493 return msm_rotator_do_rotate(arg);
1494 case MSM_ROTATOR_IOCTL_FINISH:
1495 return msm_rotator_finish(arg);
1496
1497 default:
1498 dev_dbg(msm_rotator_dev->device,
1499 "unexpected IOCTL %d\n", cmd);
1500 return -ENOTTY;
1501 }
1502}
1503
1504static const struct file_operations msm_rotator_fops = {
1505 .owner = THIS_MODULE,
1506 .open = msm_rotator_open,
1507 .release = msm_rotator_close,
1508 .unlocked_ioctl = msm_rotator_ioctl,
1509};
1510
1511static int __devinit msm_rotator_probe(struct platform_device *pdev)
1512{
1513 int rc = 0;
1514 struct resource *res;
1515 struct msm_rotator_platform_data *pdata = NULL;
1516 int i, number_of_clks;
1517 uint32_t ver;
1518
1519 msm_rotator_dev = kzalloc(sizeof(struct msm_rotator_dev), GFP_KERNEL);
1520 if (!msm_rotator_dev) {
1521 printk(KERN_ERR "%s Unable to allocate memory for struct\n",
1522 __func__);
1523 return -ENOMEM;
1524 }
1525 for (i = 0; i < MAX_SESSIONS; i++)
1526 msm_rotator_dev->img_info[i] = NULL;
1527 msm_rotator_dev->last_session_idx = INVALID_SESSION;
1528
1529 pdata = pdev->dev.platform_data;
1530 number_of_clks = pdata->number_of_clocks;
Olav Hauganef95ae32012-05-15 09:50:30 -07001531 rot_iommu_split_domain = pdata->rot_iommu_split_domain;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001532
1533 msm_rotator_dev->imem_owner = IMEM_NO_OWNER;
1534 mutex_init(&msm_rotator_dev->imem_lock);
Adrian Salido-Moreno5737db12012-04-02 15:22:08 -07001535 INIT_LIST_HEAD(&msm_rotator_dev->fd_list);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001536 msm_rotator_dev->imem_clk_state = CLK_DIS;
1537 INIT_DELAYED_WORK(&msm_rotator_dev->imem_clk_work,
1538 msm_rotator_imem_clk_work_f);
1539 msm_rotator_dev->imem_clk = NULL;
1540 msm_rotator_dev->pdev = pdev;
1541
1542 msm_rotator_dev->core_clk = NULL;
1543 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001544
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001545#ifdef CONFIG_MSM_BUS_SCALING
1546 if (!msm_rotator_dev->bus_client_handle && pdata &&
1547 pdata->bus_scale_table) {
1548 msm_rotator_dev->bus_client_handle =
1549 msm_bus_scale_register_client(
1550 pdata->bus_scale_table);
1551 if (!msm_rotator_dev->bus_client_handle) {
1552 pr_err("%s not able to get bus scale handle\n",
1553 __func__);
1554 }
1555 }
1556#endif
1557
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001558 for (i = 0; i < number_of_clks; i++) {
1559 if (pdata->rotator_clks[i].clk_type == ROTATOR_IMEM_CLK) {
1560 msm_rotator_dev->imem_clk =
1561 clk_get(&msm_rotator_dev->pdev->dev,
1562 pdata->rotator_clks[i].clk_name);
1563 if (IS_ERR(msm_rotator_dev->imem_clk)) {
1564 rc = PTR_ERR(msm_rotator_dev->imem_clk);
1565 msm_rotator_dev->imem_clk = NULL;
1566 printk(KERN_ERR "%s: cannot get imem_clk "
1567 "rc=%d\n", DRIVER_NAME, rc);
1568 goto error_imem_clk;
1569 }
1570 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001571 clk_set_rate(msm_rotator_dev->imem_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001572 pdata->rotator_clks[i].clk_rate);
1573 }
1574 if (pdata->rotator_clks[i].clk_type == ROTATOR_PCLK) {
1575 msm_rotator_dev->pclk =
1576 clk_get(&msm_rotator_dev->pdev->dev,
1577 pdata->rotator_clks[i].clk_name);
1578 if (IS_ERR(msm_rotator_dev->pclk)) {
1579 rc = PTR_ERR(msm_rotator_dev->pclk);
1580 msm_rotator_dev->pclk = NULL;
1581 printk(KERN_ERR "%s: cannot get pclk rc=%d\n",
1582 DRIVER_NAME, rc);
1583 goto error_pclk;
1584 }
1585
1586 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001587 clk_set_rate(msm_rotator_dev->pclk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001588 pdata->rotator_clks[i].clk_rate);
1589 }
1590
1591 if (pdata->rotator_clks[i].clk_type == ROTATOR_CORE_CLK) {
1592 msm_rotator_dev->core_clk =
1593 clk_get(&msm_rotator_dev->pdev->dev,
1594 pdata->rotator_clks[i].clk_name);
1595 if (IS_ERR(msm_rotator_dev->core_clk)) {
1596 rc = PTR_ERR(msm_rotator_dev->core_clk);
1597 msm_rotator_dev->core_clk = NULL;
1598 printk(KERN_ERR "%s: cannot get core clk "
1599 "rc=%d\n", DRIVER_NAME, rc);
1600 goto error_core_clk;
1601 }
1602
1603 if (pdata->rotator_clks[i].clk_rate)
Matt Wagantall754f2472011-11-08 15:44:00 -08001604 clk_set_rate(msm_rotator_dev->core_clk,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001605 pdata->rotator_clks[i].clk_rate);
1606 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001607 }
1608
Matt Wagantall316f2fc2012-05-03 20:41:42 -07001609 msm_rotator_dev->regulator = regulator_get(&msm_rotator_dev->pdev->dev,
1610 "vdd");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001611 if (IS_ERR(msm_rotator_dev->regulator))
1612 msm_rotator_dev->regulator = NULL;
1613
1614 msm_rotator_dev->rot_clk_state = CLK_DIS;
1615 INIT_DELAYED_WORK(&msm_rotator_dev->rot_clk_work,
1616 msm_rotator_rot_clk_work_f);
1617
1618 mutex_init(&msm_rotator_dev->rotator_lock);
Naseer Ahmed18018602011-10-25 13:32:58 -07001619#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
1620 msm_rotator_dev->client = msm_ion_client_create(-1, pdev->name);
1621#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001622 platform_set_drvdata(pdev, msm_rotator_dev);
1623
1624
1625 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1626 if (!res) {
1627 printk(KERN_ALERT
1628 "%s: could not get IORESOURCE_MEM\n", DRIVER_NAME);
1629 rc = -ENODEV;
1630 goto error_get_resource;
1631 }
1632 msm_rotator_dev->io_base = ioremap(res->start,
1633 resource_size(res));
1634
1635#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1636 if (msm_rotator_dev->imem_clk)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001637 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001638#endif
1639 enable_rot_clks();
1640 ver = ioread32(MSM_ROTATOR_HW_VERSION);
1641 disable_rot_clks();
1642
1643#ifdef CONFIG_MSM_ROTATOR_USE_IMEM
1644 if (msm_rotator_dev->imem_clk)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001645 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001646#endif
Naseer Ahmed18018602011-10-25 13:32:58 -07001647 if (ver != pdata->hardware_version_number)
Mayank Chopra012a8e72012-04-11 10:41:13 +05301648 pr_debug("%s: invalid HW version ver 0x%x\n",
Ravishangar Kalyanam6bc448a2012-03-14 11:31:52 -07001649 DRIVER_NAME, ver);
Naseer Ahmed18018602011-10-25 13:32:58 -07001650
Mayank Chopra012a8e72012-04-11 10:41:13 +05301651 rotator_hw_revision = ver;
1652 rotator_hw_revision >>= 16; /* bit 31:16 */
1653 rotator_hw_revision &= 0xff;
1654
1655 pr_info("%s: rotator_hw_revision=%x\n",
1656 __func__, rotator_hw_revision);
1657
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001658 msm_rotator_dev->irq = platform_get_irq(pdev, 0);
1659 if (msm_rotator_dev->irq < 0) {
1660 printk(KERN_ALERT "%s: could not get IORESOURCE_IRQ\n",
1661 DRIVER_NAME);
1662 rc = -ENODEV;
1663 goto error_get_irq;
1664 }
1665 rc = request_irq(msm_rotator_dev->irq, msm_rotator_isr,
1666 IRQF_TRIGGER_RISING, DRIVER_NAME, NULL);
1667 if (rc) {
1668 printk(KERN_ERR "%s: request_irq() failed\n", DRIVER_NAME);
1669 goto error_get_irq;
1670 }
1671 /* we enable the IRQ when we need it in the ioctl */
1672 disable_irq(msm_rotator_dev->irq);
1673
1674 rc = alloc_chrdev_region(&msm_rotator_dev->dev_num, 0, 1, DRIVER_NAME);
1675 if (rc < 0) {
1676 printk(KERN_ERR "%s: alloc_chrdev_region Failed rc = %d\n",
1677 __func__, rc);
1678 goto error_get_irq;
1679 }
1680
1681 msm_rotator_dev->class = class_create(THIS_MODULE, DRIVER_NAME);
1682 if (IS_ERR(msm_rotator_dev->class)) {
1683 rc = PTR_ERR(msm_rotator_dev->class);
1684 printk(KERN_ERR "%s: couldn't create class rc = %d\n",
1685 DRIVER_NAME, rc);
1686 goto error_class_create;
1687 }
1688
1689 msm_rotator_dev->device = device_create(msm_rotator_dev->class, NULL,
1690 msm_rotator_dev->dev_num, NULL,
1691 DRIVER_NAME);
1692 if (IS_ERR(msm_rotator_dev->device)) {
1693 rc = PTR_ERR(msm_rotator_dev->device);
1694 printk(KERN_ERR "%s: device_create failed %d\n",
1695 DRIVER_NAME, rc);
1696 goto error_class_device_create;
1697 }
1698
1699 cdev_init(&msm_rotator_dev->cdev, &msm_rotator_fops);
1700 rc = cdev_add(&msm_rotator_dev->cdev,
1701 MKDEV(MAJOR(msm_rotator_dev->dev_num), 0),
1702 1);
1703 if (rc < 0) {
1704 printk(KERN_ERR "%s: cdev_add failed %d\n", __func__, rc);
1705 goto error_cdev_add;
1706 }
1707
1708 init_waitqueue_head(&msm_rotator_dev->wq);
1709
1710 dev_dbg(msm_rotator_dev->device, "probe successful\n");
1711 return rc;
1712
1713error_cdev_add:
1714 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1715error_class_device_create:
1716 class_destroy(msm_rotator_dev->class);
1717error_class_create:
1718 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1719error_get_irq:
1720 iounmap(msm_rotator_dev->io_base);
1721error_get_resource:
1722 mutex_destroy(&msm_rotator_dev->rotator_lock);
1723 if (msm_rotator_dev->regulator)
1724 regulator_put(msm_rotator_dev->regulator);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001725 clk_put(msm_rotator_dev->core_clk);
1726error_core_clk:
1727 clk_put(msm_rotator_dev->pclk);
1728error_pclk:
1729 if (msm_rotator_dev->imem_clk)
1730 clk_put(msm_rotator_dev->imem_clk);
1731error_imem_clk:
1732 mutex_destroy(&msm_rotator_dev->imem_lock);
1733 kfree(msm_rotator_dev);
1734 return rc;
1735}
1736
1737static int __devexit msm_rotator_remove(struct platform_device *plat_dev)
1738{
1739 int i;
1740
Nagamalleswararao Ganjie1a9f872011-11-06 23:13:32 -08001741#ifdef CONFIG_MSM_BUS_SCALING
1742 msm_bus_scale_unregister_client(msm_rotator_dev->bus_client_handle);
1743#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001744 free_irq(msm_rotator_dev->irq, NULL);
1745 mutex_destroy(&msm_rotator_dev->rotator_lock);
1746 cdev_del(&msm_rotator_dev->cdev);
1747 device_destroy(msm_rotator_dev->class, msm_rotator_dev->dev_num);
1748 class_destroy(msm_rotator_dev->class);
1749 unregister_chrdev_region(msm_rotator_dev->dev_num, 1);
1750 iounmap(msm_rotator_dev->io_base);
1751 if (msm_rotator_dev->imem_clk) {
1752 if (msm_rotator_dev->imem_clk_state == CLK_EN)
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001753 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001754 clk_put(msm_rotator_dev->imem_clk);
1755 msm_rotator_dev->imem_clk = NULL;
1756 }
1757 if (msm_rotator_dev->rot_clk_state == CLK_EN)
1758 disable_rot_clks();
1759 clk_put(msm_rotator_dev->core_clk);
1760 clk_put(msm_rotator_dev->pclk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001761 if (msm_rotator_dev->regulator)
1762 regulator_put(msm_rotator_dev->regulator);
1763 msm_rotator_dev->core_clk = NULL;
1764 msm_rotator_dev->pclk = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001765 mutex_destroy(&msm_rotator_dev->imem_lock);
1766 for (i = 0; i < MAX_SESSIONS; i++)
1767 if (msm_rotator_dev->img_info[i] != NULL)
1768 kfree(msm_rotator_dev->img_info[i]);
1769 kfree(msm_rotator_dev);
1770 return 0;
1771}
1772
1773#ifdef CONFIG_PM
1774static int msm_rotator_suspend(struct platform_device *dev, pm_message_t state)
1775{
1776 mutex_lock(&msm_rotator_dev->imem_lock);
1777 if (msm_rotator_dev->imem_clk_state == CLK_EN
1778 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001779 clk_disable_unprepare(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001780 msm_rotator_dev->imem_clk_state = CLK_SUSPEND;
1781 }
1782 mutex_unlock(&msm_rotator_dev->imem_lock);
1783 mutex_lock(&msm_rotator_dev->rotator_lock);
1784 if (msm_rotator_dev->rot_clk_state == CLK_EN) {
1785 disable_rot_clks();
1786 msm_rotator_dev->rot_clk_state = CLK_SUSPEND;
1787 }
1788 mutex_unlock(&msm_rotator_dev->rotator_lock);
1789 return 0;
1790}
1791
1792static int msm_rotator_resume(struct platform_device *dev)
1793{
1794 mutex_lock(&msm_rotator_dev->imem_lock);
1795 if (msm_rotator_dev->imem_clk_state == CLK_SUSPEND
1796 && msm_rotator_dev->imem_clk) {
Ravishangar Kalyanamd16485d2012-03-21 16:51:26 -07001797 clk_prepare_enable(msm_rotator_dev->imem_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001798 msm_rotator_dev->imem_clk_state = CLK_EN;
1799 }
1800 mutex_unlock(&msm_rotator_dev->imem_lock);
1801 mutex_lock(&msm_rotator_dev->rotator_lock);
1802 if (msm_rotator_dev->rot_clk_state == CLK_SUSPEND) {
1803 enable_rot_clks();
1804 msm_rotator_dev->rot_clk_state = CLK_EN;
1805 }
1806 mutex_unlock(&msm_rotator_dev->rotator_lock);
1807 return 0;
1808}
1809#endif
1810
1811static struct platform_driver msm_rotator_platform_driver = {
1812 .probe = msm_rotator_probe,
1813 .remove = __devexit_p(msm_rotator_remove),
1814#ifdef CONFIG_PM
1815 .suspend = msm_rotator_suspend,
1816 .resume = msm_rotator_resume,
1817#endif
1818 .driver = {
1819 .owner = THIS_MODULE,
1820 .name = DRIVER_NAME
1821 }
1822};
1823
1824static int __init msm_rotator_init(void)
1825{
1826 return platform_driver_register(&msm_rotator_platform_driver);
1827}
1828
1829static void __exit msm_rotator_exit(void)
1830{
1831 return platform_driver_unregister(&msm_rotator_platform_driver);
1832}
1833
1834module_init(msm_rotator_init);
1835module_exit(msm_rotator_exit);
1836
1837MODULE_DESCRIPTION("MSM Offline Image Rotator driver");
1838MODULE_VERSION("1.0");
1839MODULE_LICENSE("GPL v2");