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