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