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