Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Samsung S5P G2D - 2D Graphics Accelerator Driver |
| 3 | * |
| 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 5 | * Kamil Debski, <k.debski@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the |
| 10 | * License, or (at your option) any later version |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/fs.h> |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 15 | #include <linux/timer.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/clk.h> |
| 19 | #include <linux/interrupt.h> |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 20 | #include <linux/of.h> |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 21 | |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <media/v4l2-mem2mem.h> |
| 24 | #include <media/v4l2-device.h> |
| 25 | #include <media/v4l2-ioctl.h> |
| 26 | #include <media/videobuf2-core.h> |
| 27 | #include <media/videobuf2-dma-contig.h> |
| 28 | |
| 29 | #include "g2d.h" |
| 30 | #include "g2d-regs.h" |
| 31 | |
| 32 | #define fh2ctx(__fh) container_of(__fh, struct g2d_ctx, fh) |
| 33 | |
| 34 | static struct g2d_fmt formats[] = { |
| 35 | { |
| 36 | .name = "XRGB_8888", |
| 37 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 38 | .depth = 32, |
| 39 | .hw = COLOR_MODE(ORDER_XRGB, MODE_XRGB_8888), |
| 40 | }, |
| 41 | { |
| 42 | .name = "RGB_565", |
| 43 | .fourcc = V4L2_PIX_FMT_RGB565X, |
| 44 | .depth = 16, |
| 45 | .hw = COLOR_MODE(ORDER_XRGB, MODE_RGB_565), |
| 46 | }, |
| 47 | { |
| 48 | .name = "XRGB_1555", |
| 49 | .fourcc = V4L2_PIX_FMT_RGB555X, |
| 50 | .depth = 16, |
| 51 | .hw = COLOR_MODE(ORDER_XRGB, MODE_XRGB_1555), |
| 52 | }, |
| 53 | { |
| 54 | .name = "XRGB_4444", |
| 55 | .fourcc = V4L2_PIX_FMT_RGB444, |
| 56 | .depth = 16, |
| 57 | .hw = COLOR_MODE(ORDER_XRGB, MODE_XRGB_4444), |
| 58 | }, |
| 59 | { |
| 60 | .name = "PACKED_RGB_888", |
| 61 | .fourcc = V4L2_PIX_FMT_RGB24, |
| 62 | .depth = 24, |
| 63 | .hw = COLOR_MODE(ORDER_XRGB, MODE_PACKED_RGB_888), |
| 64 | }, |
| 65 | }; |
| 66 | #define NUM_FORMATS ARRAY_SIZE(formats) |
| 67 | |
Sachin Kamat | ec76afe | 2012-05-10 03:35:48 -0300 | [diff] [blame] | 68 | static struct g2d_frame def_frame = { |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 69 | .width = DEFAULT_WIDTH, |
| 70 | .height = DEFAULT_HEIGHT, |
| 71 | .c_width = DEFAULT_WIDTH, |
| 72 | .c_height = DEFAULT_HEIGHT, |
| 73 | .o_width = 0, |
| 74 | .o_height = 0, |
| 75 | .fmt = &formats[0], |
| 76 | .right = DEFAULT_WIDTH, |
| 77 | .bottom = DEFAULT_HEIGHT, |
| 78 | }; |
| 79 | |
Sachin Kamat | ec76afe | 2012-05-10 03:35:48 -0300 | [diff] [blame] | 80 | static struct g2d_fmt *find_fmt(struct v4l2_format *f) |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 81 | { |
| 82 | unsigned int i; |
| 83 | for (i = 0; i < NUM_FORMATS; i++) { |
| 84 | if (formats[i].fourcc == f->fmt.pix.pixelformat) |
| 85 | return &formats[i]; |
| 86 | } |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | static struct g2d_frame *get_frame(struct g2d_ctx *ctx, |
| 92 | enum v4l2_buf_type type) |
| 93 | { |
| 94 | switch (type) { |
| 95 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 96 | return &ctx->in; |
| 97 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 98 | return &ctx->out; |
| 99 | default: |
| 100 | return ERR_PTR(-EINVAL); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static int g2d_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, |
| 105 | unsigned int *nbuffers, unsigned int *nplanes, |
| 106 | unsigned int sizes[], void *alloc_ctxs[]) |
| 107 | { |
| 108 | struct g2d_ctx *ctx = vb2_get_drv_priv(vq); |
| 109 | struct g2d_frame *f = get_frame(ctx, vq->type); |
| 110 | |
| 111 | if (IS_ERR(f)) |
| 112 | return PTR_ERR(f); |
| 113 | |
| 114 | sizes[0] = f->size; |
| 115 | *nplanes = 1; |
| 116 | alloc_ctxs[0] = ctx->dev->alloc_ctx; |
| 117 | |
| 118 | if (*nbuffers == 0) |
| 119 | *nbuffers = 1; |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static int g2d_buf_prepare(struct vb2_buffer *vb) |
| 125 | { |
| 126 | struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
| 127 | struct g2d_frame *f = get_frame(ctx, vb->vb2_queue->type); |
| 128 | |
| 129 | if (IS_ERR(f)) |
| 130 | return PTR_ERR(f); |
| 131 | vb2_set_plane_payload(vb, 0, f->size); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static void g2d_buf_queue(struct vb2_buffer *vb) |
| 136 | { |
| 137 | struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 138 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 139 | } |
| 140 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 141 | static struct vb2_ops g2d_qops = { |
| 142 | .queue_setup = g2d_queue_setup, |
| 143 | .buf_prepare = g2d_buf_prepare, |
| 144 | .buf_queue = g2d_buf_queue, |
| 145 | }; |
| 146 | |
| 147 | static int queue_init(void *priv, struct vb2_queue *src_vq, |
| 148 | struct vb2_queue *dst_vq) |
| 149 | { |
| 150 | struct g2d_ctx *ctx = priv; |
| 151 | int ret; |
| 152 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 153 | src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 154 | src_vq->io_modes = VB2_MMAP | VB2_USERPTR; |
| 155 | src_vq->drv_priv = ctx; |
| 156 | src_vq->ops = &g2d_qops; |
| 157 | src_vq->mem_ops = &vb2_dma_contig_memops; |
| 158 | src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 159 | src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 160 | src_vq->lock = &ctx->dev->mutex; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 161 | |
| 162 | ret = vb2_queue_init(src_vq); |
| 163 | if (ret) |
| 164 | return ret; |
| 165 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 166 | dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 167 | dst_vq->io_modes = VB2_MMAP | VB2_USERPTR; |
| 168 | dst_vq->drv_priv = ctx; |
| 169 | dst_vq->ops = &g2d_qops; |
| 170 | dst_vq->mem_ops = &vb2_dma_contig_memops; |
| 171 | dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 172 | dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 173 | dst_vq->lock = &ctx->dev->mutex; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 174 | |
| 175 | return vb2_queue_init(dst_vq); |
| 176 | } |
| 177 | |
| 178 | static int g2d_s_ctrl(struct v4l2_ctrl *ctrl) |
| 179 | { |
| 180 | struct g2d_ctx *ctx = container_of(ctrl->handler, struct g2d_ctx, |
| 181 | ctrl_handler); |
Kamil Debski | 27dda97 | 2012-02-16 10:52:47 -0300 | [diff] [blame] | 182 | unsigned long flags; |
| 183 | |
| 184 | spin_lock_irqsave(&ctx->dev->ctrl_lock, flags); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 185 | switch (ctrl->id) { |
| 186 | case V4L2_CID_COLORFX: |
| 187 | if (ctrl->val == V4L2_COLORFX_NEGATIVE) |
| 188 | ctx->rop = ROP4_INVERT; |
| 189 | else |
| 190 | ctx->rop = ROP4_COPY; |
Kamil Debski | 7f6cce6 | 2012-01-02 09:19:25 -0300 | [diff] [blame] | 191 | break; |
Sachin Kamat | d0d2832 | 2012-02-16 10:52:16 -0300 | [diff] [blame] | 192 | |
| 193 | case V4L2_CID_HFLIP: |
| 194 | ctx->flip = ctx->ctrl_hflip->val | (ctx->ctrl_vflip->val << 1); |
| 195 | break; |
| 196 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 197 | } |
Kamil Debski | 27dda97 | 2012-02-16 10:52:47 -0300 | [diff] [blame] | 198 | spin_unlock_irqrestore(&ctx->dev->ctrl_lock, flags); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static const struct v4l2_ctrl_ops g2d_ctrl_ops = { |
| 203 | .s_ctrl = g2d_s_ctrl, |
| 204 | }; |
| 205 | |
Sachin Kamat | ec76afe | 2012-05-10 03:35:48 -0300 | [diff] [blame] | 206 | static int g2d_setup_ctrls(struct g2d_ctx *ctx) |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 207 | { |
| 208 | struct g2d_dev *dev = ctx->dev; |
| 209 | |
Sachin Kamat | d0d2832 | 2012-02-16 10:52:16 -0300 | [diff] [blame] | 210 | v4l2_ctrl_handler_init(&ctx->ctrl_handler, 3); |
| 211 | |
| 212 | ctx->ctrl_hflip = v4l2_ctrl_new_std(&ctx->ctrl_handler, &g2d_ctrl_ops, |
| 213 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 214 | |
| 215 | ctx->ctrl_vflip = v4l2_ctrl_new_std(&ctx->ctrl_handler, &g2d_ctrl_ops, |
| 216 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 217 | |
| 218 | v4l2_ctrl_new_std_menu( |
| 219 | &ctx->ctrl_handler, |
| 220 | &g2d_ctrl_ops, |
| 221 | V4L2_CID_COLORFX, |
| 222 | V4L2_COLORFX_NEGATIVE, |
| 223 | ~((1 << V4L2_COLORFX_NONE) | (1 << V4L2_COLORFX_NEGATIVE)), |
| 224 | V4L2_COLORFX_NONE); |
| 225 | |
| 226 | if (ctx->ctrl_handler.error) { |
Sachin Kamat | d0d2832 | 2012-02-16 10:52:16 -0300 | [diff] [blame] | 227 | int err = ctx->ctrl_handler.error; |
| 228 | v4l2_err(&dev->v4l2_dev, "g2d_setup_ctrls failed\n"); |
| 229 | v4l2_ctrl_handler_free(&ctx->ctrl_handler); |
| 230 | return err; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 231 | } |
| 232 | |
Sachin Kamat | d0d2832 | 2012-02-16 10:52:16 -0300 | [diff] [blame] | 233 | v4l2_ctrl_cluster(2, &ctx->ctrl_hflip); |
| 234 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int g2d_open(struct file *file) |
| 239 | { |
| 240 | struct g2d_dev *dev = video_drvdata(file); |
| 241 | struct g2d_ctx *ctx = NULL; |
| 242 | int ret = 0; |
| 243 | |
| 244 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 245 | if (!ctx) |
| 246 | return -ENOMEM; |
| 247 | ctx->dev = dev; |
| 248 | /* Set default formats */ |
| 249 | ctx->in = def_frame; |
| 250 | ctx->out = def_frame; |
| 251 | |
Hans Verkuil | de40cb2 | 2012-06-24 06:58:28 -0300 | [diff] [blame] | 252 | if (mutex_lock_interruptible(&dev->mutex)) { |
| 253 | kfree(ctx); |
| 254 | return -ERESTARTSYS; |
| 255 | } |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 256 | ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); |
| 257 | if (IS_ERR(ctx->fh.m2m_ctx)) { |
| 258 | ret = PTR_ERR(ctx->fh.m2m_ctx); |
Hans Verkuil | de40cb2 | 2012-06-24 06:58:28 -0300 | [diff] [blame] | 259 | mutex_unlock(&dev->mutex); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 260 | kfree(ctx); |
| 261 | return ret; |
| 262 | } |
| 263 | v4l2_fh_init(&ctx->fh, video_devdata(file)); |
| 264 | file->private_data = &ctx->fh; |
| 265 | v4l2_fh_add(&ctx->fh); |
| 266 | |
| 267 | g2d_setup_ctrls(ctx); |
| 268 | |
| 269 | /* Write the default values to the ctx struct */ |
| 270 | v4l2_ctrl_handler_setup(&ctx->ctrl_handler); |
| 271 | |
| 272 | ctx->fh.ctrl_handler = &ctx->ctrl_handler; |
Hans Verkuil | de40cb2 | 2012-06-24 06:58:28 -0300 | [diff] [blame] | 273 | mutex_unlock(&dev->mutex); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 274 | |
| 275 | v4l2_info(&dev->v4l2_dev, "instance opened\n"); |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int g2d_release(struct file *file) |
| 280 | { |
| 281 | struct g2d_dev *dev = video_drvdata(file); |
| 282 | struct g2d_ctx *ctx = fh2ctx(file->private_data); |
| 283 | |
| 284 | v4l2_ctrl_handler_free(&ctx->ctrl_handler); |
| 285 | v4l2_fh_del(&ctx->fh); |
| 286 | v4l2_fh_exit(&ctx->fh); |
| 287 | kfree(ctx); |
| 288 | v4l2_info(&dev->v4l2_dev, "instance closed\n"); |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | static int vidioc_querycap(struct file *file, void *priv, |
| 294 | struct v4l2_capability *cap) |
| 295 | { |
| 296 | strncpy(cap->driver, G2D_NAME, sizeof(cap->driver) - 1); |
| 297 | strncpy(cap->card, G2D_NAME, sizeof(cap->card) - 1); |
| 298 | cap->bus_info[0] = 0; |
Hans Verkuil | 8c17e5e | 2014-11-24 06:37:26 -0300 | [diff] [blame] | 299 | cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING; |
| 300 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int vidioc_enum_fmt(struct file *file, void *prv, struct v4l2_fmtdesc *f) |
| 305 | { |
| 306 | struct g2d_fmt *fmt; |
| 307 | if (f->index >= NUM_FORMATS) |
| 308 | return -EINVAL; |
| 309 | fmt = &formats[f->index]; |
| 310 | f->pixelformat = fmt->fourcc; |
| 311 | strncpy(f->description, fmt->name, sizeof(f->description) - 1); |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static int vidioc_g_fmt(struct file *file, void *prv, struct v4l2_format *f) |
| 316 | { |
| 317 | struct g2d_ctx *ctx = prv; |
| 318 | struct vb2_queue *vq; |
| 319 | struct g2d_frame *frm; |
| 320 | |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 321 | vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 322 | if (!vq) |
| 323 | return -EINVAL; |
| 324 | frm = get_frame(ctx, f->type); |
| 325 | if (IS_ERR(frm)) |
| 326 | return PTR_ERR(frm); |
| 327 | |
| 328 | f->fmt.pix.width = frm->width; |
| 329 | f->fmt.pix.height = frm->height; |
| 330 | f->fmt.pix.field = V4L2_FIELD_NONE; |
| 331 | f->fmt.pix.pixelformat = frm->fmt->fourcc; |
| 332 | f->fmt.pix.bytesperline = (frm->width * frm->fmt->depth) >> 3; |
| 333 | f->fmt.pix.sizeimage = frm->size; |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static int vidioc_try_fmt(struct file *file, void *prv, struct v4l2_format *f) |
| 338 | { |
| 339 | struct g2d_fmt *fmt; |
| 340 | enum v4l2_field *field; |
| 341 | |
| 342 | fmt = find_fmt(f); |
| 343 | if (!fmt) |
| 344 | return -EINVAL; |
| 345 | |
| 346 | field = &f->fmt.pix.field; |
| 347 | if (*field == V4L2_FIELD_ANY) |
| 348 | *field = V4L2_FIELD_NONE; |
| 349 | else if (*field != V4L2_FIELD_NONE) |
| 350 | return -EINVAL; |
| 351 | |
| 352 | if (f->fmt.pix.width > MAX_WIDTH) |
| 353 | f->fmt.pix.width = MAX_WIDTH; |
| 354 | if (f->fmt.pix.height > MAX_HEIGHT) |
| 355 | f->fmt.pix.height = MAX_HEIGHT; |
| 356 | |
| 357 | if (f->fmt.pix.width < 1) |
| 358 | f->fmt.pix.width = 1; |
| 359 | if (f->fmt.pix.height < 1) |
| 360 | f->fmt.pix.height = 1; |
| 361 | |
| 362 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 363 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int vidioc_s_fmt(struct file *file, void *prv, struct v4l2_format *f) |
| 368 | { |
| 369 | struct g2d_ctx *ctx = prv; |
| 370 | struct g2d_dev *dev = ctx->dev; |
| 371 | struct vb2_queue *vq; |
| 372 | struct g2d_frame *frm; |
| 373 | struct g2d_fmt *fmt; |
| 374 | int ret = 0; |
| 375 | |
| 376 | /* Adjust all values accordingly to the hardware capabilities |
| 377 | * and chosen format. */ |
| 378 | ret = vidioc_try_fmt(file, prv, f); |
| 379 | if (ret) |
| 380 | return ret; |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 381 | vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 382 | if (vb2_is_busy(vq)) { |
| 383 | v4l2_err(&dev->v4l2_dev, "queue (%d) bust\n", f->type); |
| 384 | return -EBUSY; |
| 385 | } |
| 386 | frm = get_frame(ctx, f->type); |
| 387 | if (IS_ERR(frm)) |
| 388 | return PTR_ERR(frm); |
| 389 | fmt = find_fmt(f); |
| 390 | if (!fmt) |
| 391 | return -EINVAL; |
| 392 | frm->width = f->fmt.pix.width; |
| 393 | frm->height = f->fmt.pix.height; |
| 394 | frm->size = f->fmt.pix.sizeimage; |
| 395 | /* Reset crop settings */ |
| 396 | frm->o_width = 0; |
| 397 | frm->o_height = 0; |
| 398 | frm->c_width = frm->width; |
| 399 | frm->c_height = frm->height; |
| 400 | frm->right = frm->width; |
| 401 | frm->bottom = frm->height; |
| 402 | frm->fmt = fmt; |
| 403 | frm->stride = f->fmt.pix.bytesperline; |
| 404 | return 0; |
| 405 | } |
| 406 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 407 | static int vidioc_cropcap(struct file *file, void *priv, |
| 408 | struct v4l2_cropcap *cr) |
| 409 | { |
| 410 | struct g2d_ctx *ctx = priv; |
| 411 | struct g2d_frame *f; |
| 412 | |
| 413 | f = get_frame(ctx, cr->type); |
| 414 | if (IS_ERR(f)) |
| 415 | return PTR_ERR(f); |
| 416 | |
| 417 | cr->bounds.left = 0; |
| 418 | cr->bounds.top = 0; |
| 419 | cr->bounds.width = f->width; |
| 420 | cr->bounds.height = f->height; |
| 421 | cr->defrect = cr->bounds; |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static int vidioc_g_crop(struct file *file, void *prv, struct v4l2_crop *cr) |
| 426 | { |
| 427 | struct g2d_ctx *ctx = prv; |
| 428 | struct g2d_frame *f; |
| 429 | |
| 430 | f = get_frame(ctx, cr->type); |
| 431 | if (IS_ERR(f)) |
| 432 | return PTR_ERR(f); |
| 433 | |
| 434 | cr->c.left = f->o_height; |
| 435 | cr->c.top = f->o_width; |
| 436 | cr->c.width = f->c_width; |
| 437 | cr->c.height = f->c_height; |
| 438 | return 0; |
| 439 | } |
| 440 | |
Hans Verkuil | 21ec9c9 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 441 | static int vidioc_try_crop(struct file *file, void *prv, const struct v4l2_crop *cr) |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 442 | { |
| 443 | struct g2d_ctx *ctx = prv; |
| 444 | struct g2d_dev *dev = ctx->dev; |
| 445 | struct g2d_frame *f; |
| 446 | |
| 447 | f = get_frame(ctx, cr->type); |
| 448 | if (IS_ERR(f)) |
| 449 | return PTR_ERR(f); |
| 450 | |
| 451 | if (cr->c.top < 0 || cr->c.left < 0) { |
| 452 | v4l2_err(&dev->v4l2_dev, |
| 453 | "doesn't support negative values for top & left\n"); |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 460 | static int vidioc_s_crop(struct file *file, void *prv, const struct v4l2_crop *cr) |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 461 | { |
| 462 | struct g2d_ctx *ctx = prv; |
| 463 | struct g2d_frame *f; |
| 464 | int ret; |
| 465 | |
| 466 | ret = vidioc_try_crop(file, prv, cr); |
| 467 | if (ret) |
| 468 | return ret; |
| 469 | f = get_frame(ctx, cr->type); |
| 470 | if (IS_ERR(f)) |
| 471 | return PTR_ERR(f); |
| 472 | |
| 473 | f->c_width = cr->c.width; |
| 474 | f->c_height = cr->c.height; |
| 475 | f->o_width = cr->c.left; |
| 476 | f->o_height = cr->c.top; |
| 477 | f->bottom = f->o_height + f->c_height; |
| 478 | f->right = f->o_width + f->c_width; |
| 479 | return 0; |
| 480 | } |
| 481 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 482 | static void job_abort(void *prv) |
| 483 | { |
| 484 | struct g2d_ctx *ctx = prv; |
| 485 | struct g2d_dev *dev = ctx->dev; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 486 | |
Sachin Kamat | 2356877 | 2012-05-10 03:35:47 -0300 | [diff] [blame] | 487 | if (dev->curr == NULL) /* No job currently running */ |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 488 | return; |
| 489 | |
Mauro Carvalho Chehab | dc916aa | 2014-08-26 10:52:56 -0300 | [diff] [blame] | 490 | wait_event_timeout(dev->irq_queue, |
| 491 | dev->curr == NULL, |
| 492 | msecs_to_jiffies(G2D_TIMEOUT)); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static void device_run(void *prv) |
| 496 | { |
| 497 | struct g2d_ctx *ctx = prv; |
| 498 | struct g2d_dev *dev = ctx->dev; |
| 499 | struct vb2_buffer *src, *dst; |
Kamil Debski | 27dda97 | 2012-02-16 10:52:47 -0300 | [diff] [blame] | 500 | unsigned long flags; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 501 | u32 cmd = 0; |
| 502 | |
| 503 | dev->curr = ctx; |
| 504 | |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 505 | src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); |
| 506 | dst = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 507 | |
| 508 | clk_enable(dev->gate); |
| 509 | g2d_reset(dev); |
| 510 | |
Kamil Debski | 27dda97 | 2012-02-16 10:52:47 -0300 | [diff] [blame] | 511 | spin_lock_irqsave(&dev->ctrl_lock, flags); |
| 512 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 513 | g2d_set_src_size(dev, &ctx->in); |
| 514 | g2d_set_src_addr(dev, vb2_dma_contig_plane_dma_addr(src, 0)); |
| 515 | |
| 516 | g2d_set_dst_size(dev, &ctx->out); |
| 517 | g2d_set_dst_addr(dev, vb2_dma_contig_plane_dma_addr(dst, 0)); |
| 518 | |
| 519 | g2d_set_rop4(dev, ctx->rop); |
Sachin Kamat | d0d2832 | 2012-02-16 10:52:16 -0300 | [diff] [blame] | 520 | g2d_set_flip(dev, ctx->flip); |
| 521 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 522 | if (ctx->in.c_width != ctx->out.c_width || |
Sachin Kamat | 62ce272 | 2013-01-17 00:07:18 -0300 | [diff] [blame] | 523 | ctx->in.c_height != ctx->out.c_height) { |
| 524 | if (dev->variant->hw_rev == TYPE_G2D_3X) |
| 525 | cmd |= CMD_V3_ENABLE_STRETCH; |
| 526 | else |
| 527 | g2d_set_v41_stretch(dev, &ctx->in, &ctx->out); |
| 528 | } |
| 529 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 530 | g2d_set_cmd(dev, cmd); |
| 531 | g2d_start(dev); |
Kamil Debski | 27dda97 | 2012-02-16 10:52:47 -0300 | [diff] [blame] | 532 | |
| 533 | spin_unlock_irqrestore(&dev->ctrl_lock, flags); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static irqreturn_t g2d_isr(int irq, void *prv) |
| 537 | { |
| 538 | struct g2d_dev *dev = prv; |
| 539 | struct g2d_ctx *ctx = dev->curr; |
| 540 | struct vb2_buffer *src, *dst; |
| 541 | |
| 542 | g2d_clear_int(dev); |
| 543 | clk_disable(dev->gate); |
| 544 | |
Sachin Kamat | 2356877 | 2012-05-10 03:35:47 -0300 | [diff] [blame] | 545 | BUG_ON(ctx == NULL); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 546 | |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 547 | src = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); |
| 548 | dst = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 549 | |
Sachin Kamat | 2356877 | 2012-05-10 03:35:47 -0300 | [diff] [blame] | 550 | BUG_ON(src == NULL); |
| 551 | BUG_ON(dst == NULL); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 552 | |
Kamil Debski | dc7be295 | 2013-04-24 09:34:03 -0300 | [diff] [blame] | 553 | dst->v4l2_buf.timecode = src->v4l2_buf.timecode; |
| 554 | dst->v4l2_buf.timestamp = src->v4l2_buf.timestamp; |
Sakari Ailus | 309f4d6 | 2014-02-08 14:21:35 -0300 | [diff] [blame] | 555 | dst->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
| 556 | dst->v4l2_buf.flags |= |
| 557 | src->v4l2_buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
Kamil Debski | dc7be295 | 2013-04-24 09:34:03 -0300 | [diff] [blame] | 558 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 559 | v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE); |
| 560 | v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE); |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 561 | v4l2_m2m_job_finish(dev->m2m_dev, ctx->fh.m2m_ctx); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 562 | |
Sachin Kamat | 2356877 | 2012-05-10 03:35:47 -0300 | [diff] [blame] | 563 | dev->curr = NULL; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 564 | wake_up(&dev->irq_queue); |
| 565 | return IRQ_HANDLED; |
| 566 | } |
| 567 | |
| 568 | static const struct v4l2_file_operations g2d_fops = { |
| 569 | .owner = THIS_MODULE, |
| 570 | .open = g2d_open, |
| 571 | .release = g2d_release, |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 572 | .poll = v4l2_m2m_fop_poll, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 573 | .unlocked_ioctl = video_ioctl2, |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 574 | .mmap = v4l2_m2m_fop_mmap, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | static const struct v4l2_ioctl_ops g2d_ioctl_ops = { |
| 578 | .vidioc_querycap = vidioc_querycap, |
| 579 | |
| 580 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt, |
| 581 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt, |
| 582 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt, |
| 583 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt, |
| 584 | |
| 585 | .vidioc_enum_fmt_vid_out = vidioc_enum_fmt, |
| 586 | .vidioc_g_fmt_vid_out = vidioc_g_fmt, |
| 587 | .vidioc_try_fmt_vid_out = vidioc_try_fmt, |
| 588 | .vidioc_s_fmt_vid_out = vidioc_s_fmt, |
| 589 | |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 590 | .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, |
| 591 | .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, |
| 592 | .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, |
| 593 | .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 594 | |
Sylwester Nawrocki | febeaa4 | 2013-08-25 18:13:17 -0300 | [diff] [blame] | 595 | .vidioc_streamon = v4l2_m2m_ioctl_streamon, |
| 596 | .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 597 | |
| 598 | .vidioc_g_crop = vidioc_g_crop, |
| 599 | .vidioc_s_crop = vidioc_s_crop, |
| 600 | .vidioc_cropcap = vidioc_cropcap, |
| 601 | }; |
| 602 | |
| 603 | static struct video_device g2d_videodev = { |
| 604 | .name = G2D_NAME, |
| 605 | .fops = &g2d_fops, |
| 606 | .ioctl_ops = &g2d_ioctl_ops, |
| 607 | .minor = -1, |
| 608 | .release = video_device_release, |
Hans Verkuil | 954f340 | 2012-09-05 06:05:50 -0300 | [diff] [blame] | 609 | .vfl_dir = VFL_DIR_M2M, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 610 | }; |
| 611 | |
| 612 | static struct v4l2_m2m_ops g2d_m2m_ops = { |
| 613 | .device_run = device_run, |
| 614 | .job_abort = job_abort, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 615 | }; |
| 616 | |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 617 | static const struct of_device_id exynos_g2d_match[]; |
| 618 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 619 | static int g2d_probe(struct platform_device *pdev) |
| 620 | { |
| 621 | struct g2d_dev *dev; |
| 622 | struct video_device *vfd; |
| 623 | struct resource *res; |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 624 | const struct of_device_id *of_id; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 625 | int ret = 0; |
| 626 | |
Sachin Kamat | 32fced0 | 2012-05-14 06:31:24 -0300 | [diff] [blame] | 627 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 628 | if (!dev) |
| 629 | return -ENOMEM; |
Sachin Kamat | 32fced0 | 2012-05-14 06:31:24 -0300 | [diff] [blame] | 630 | |
Kamil Debski | 27dda97 | 2012-02-16 10:52:47 -0300 | [diff] [blame] | 631 | spin_lock_init(&dev->ctrl_lock); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 632 | mutex_init(&dev->mutex); |
| 633 | atomic_set(&dev->num_inst, 0); |
| 634 | init_waitqueue_head(&dev->irq_queue); |
| 635 | |
| 636 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 637 | |
Thierry Reding | f23999e | 2013-01-21 06:09:07 -0300 | [diff] [blame] | 638 | dev->regs = devm_ioremap_resource(&pdev->dev, res); |
| 639 | if (IS_ERR(dev->regs)) |
| 640 | return PTR_ERR(dev->regs); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 641 | |
| 642 | dev->clk = clk_get(&pdev->dev, "sclk_fimg2d"); |
Tony Prisk | 15514fb | 2012-12-18 05:28:41 -0300 | [diff] [blame] | 643 | if (IS_ERR(dev->clk)) { |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 644 | dev_err(&pdev->dev, "failed to get g2d clock\n"); |
Sachin Kamat | 32fced0 | 2012-05-14 06:31:24 -0300 | [diff] [blame] | 645 | return -ENXIO; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 646 | } |
| 647 | |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 648 | ret = clk_prepare(dev->clk); |
| 649 | if (ret) { |
| 650 | dev_err(&pdev->dev, "failed to prepare g2d clock\n"); |
| 651 | goto put_clk; |
| 652 | } |
| 653 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 654 | dev->gate = clk_get(&pdev->dev, "fimg2d"); |
Tony Prisk | 15514fb | 2012-12-18 05:28:41 -0300 | [diff] [blame] | 655 | if (IS_ERR(dev->gate)) { |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 656 | dev_err(&pdev->dev, "failed to get g2d clock gate\n"); |
| 657 | ret = -ENXIO; |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 658 | goto unprep_clk; |
| 659 | } |
| 660 | |
| 661 | ret = clk_prepare(dev->gate); |
| 662 | if (ret) { |
| 663 | dev_err(&pdev->dev, "failed to prepare g2d clock gate\n"); |
| 664 | goto put_clk_gate; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 668 | if (!res) { |
| 669 | dev_err(&pdev->dev, "failed to find IRQ\n"); |
| 670 | ret = -ENXIO; |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 671 | goto unprep_clk_gate; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | dev->irq = res->start; |
| 675 | |
Sachin Kamat | 32fced0 | 2012-05-14 06:31:24 -0300 | [diff] [blame] | 676 | ret = devm_request_irq(&pdev->dev, dev->irq, g2d_isr, |
| 677 | 0, pdev->name, dev); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 678 | if (ret) { |
| 679 | dev_err(&pdev->dev, "failed to install IRQ\n"); |
| 680 | goto put_clk_gate; |
| 681 | } |
| 682 | |
| 683 | dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); |
| 684 | if (IS_ERR(dev->alloc_ctx)) { |
| 685 | ret = PTR_ERR(dev->alloc_ctx); |
Sachin Kamat | 32fced0 | 2012-05-14 06:31:24 -0300 | [diff] [blame] | 686 | goto unprep_clk_gate; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); |
| 690 | if (ret) |
| 691 | goto alloc_ctx_cleanup; |
| 692 | vfd = video_device_alloc(); |
| 693 | if (!vfd) { |
| 694 | v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n"); |
| 695 | ret = -ENOMEM; |
| 696 | goto unreg_v4l2_dev; |
| 697 | } |
| 698 | *vfd = g2d_videodev; |
| 699 | vfd->lock = &dev->mutex; |
Sachin Kamat | 8a09a4c | 2013-07-15 02:36:23 -0300 | [diff] [blame] | 700 | vfd->v4l2_dev = &dev->v4l2_dev; |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 701 | ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); |
| 702 | if (ret) { |
| 703 | v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); |
| 704 | goto rel_vdev; |
| 705 | } |
| 706 | video_set_drvdata(vfd, dev); |
| 707 | snprintf(vfd->name, sizeof(vfd->name), "%s", g2d_videodev.name); |
| 708 | dev->vfd = vfd; |
| 709 | v4l2_info(&dev->v4l2_dev, "device registered as /dev/video%d\n", |
| 710 | vfd->num); |
| 711 | platform_set_drvdata(pdev, dev); |
| 712 | dev->m2m_dev = v4l2_m2m_init(&g2d_m2m_ops); |
| 713 | if (IS_ERR(dev->m2m_dev)) { |
| 714 | v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n"); |
| 715 | ret = PTR_ERR(dev->m2m_dev); |
| 716 | goto unreg_video_dev; |
| 717 | } |
| 718 | |
| 719 | def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3; |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 720 | |
| 721 | if (!pdev->dev.of_node) { |
| 722 | dev->variant = g2d_get_drv_data(pdev); |
| 723 | } else { |
| 724 | of_id = of_match_node(exynos_g2d_match, pdev->dev.of_node); |
| 725 | if (!of_id) { |
| 726 | ret = -ENODEV; |
| 727 | goto unreg_video_dev; |
| 728 | } |
| 729 | dev->variant = (struct g2d_variant *)of_id->data; |
| 730 | } |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 731 | |
| 732 | return 0; |
| 733 | |
| 734 | unreg_video_dev: |
| 735 | video_unregister_device(dev->vfd); |
| 736 | rel_vdev: |
| 737 | video_device_release(vfd); |
| 738 | unreg_v4l2_dev: |
| 739 | v4l2_device_unregister(&dev->v4l2_dev); |
| 740 | alloc_ctx_cleanup: |
| 741 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 742 | unprep_clk_gate: |
| 743 | clk_unprepare(dev->gate); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 744 | put_clk_gate: |
| 745 | clk_put(dev->gate); |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 746 | unprep_clk: |
| 747 | clk_unprepare(dev->clk); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 748 | put_clk: |
| 749 | clk_put(dev->clk); |
Sachin Kamat | 32fced0 | 2012-05-14 06:31:24 -0300 | [diff] [blame] | 750 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 751 | return ret; |
| 752 | } |
| 753 | |
| 754 | static int g2d_remove(struct platform_device *pdev) |
| 755 | { |
Jingoo Han | 4e3eff6 | 2013-09-09 02:52:24 -0300 | [diff] [blame] | 756 | struct g2d_dev *dev = platform_get_drvdata(pdev); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 757 | |
| 758 | v4l2_info(&dev->v4l2_dev, "Removing " G2D_NAME); |
| 759 | v4l2_m2m_release(dev->m2m_dev); |
| 760 | video_unregister_device(dev->vfd); |
| 761 | v4l2_device_unregister(&dev->v4l2_dev); |
| 762 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 763 | clk_unprepare(dev->gate); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 764 | clk_put(dev->gate); |
Kamil Debski | 11a37c7 | 2012-02-16 10:51:28 -0300 | [diff] [blame] | 765 | clk_unprepare(dev->clk); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 766 | clk_put(dev->clk); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
Sachin Kamat | 62ce272 | 2013-01-17 00:07:18 -0300 | [diff] [blame] | 770 | static struct g2d_variant g2d_drvdata_v3x = { |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 771 | .hw_rev = TYPE_G2D_3X, /* Revision 3.0 for S5PV210 and Exynos4210 */ |
Sachin Kamat | 62ce272 | 2013-01-17 00:07:18 -0300 | [diff] [blame] | 772 | }; |
| 773 | |
| 774 | static struct g2d_variant g2d_drvdata_v4x = { |
| 775 | .hw_rev = TYPE_G2D_4X, /* Revision 4.1 for Exynos4X12 and Exynos5 */ |
| 776 | }; |
| 777 | |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 778 | static const struct of_device_id exynos_g2d_match[] = { |
| 779 | { |
| 780 | .compatible = "samsung,s5pv210-g2d", |
| 781 | .data = &g2d_drvdata_v3x, |
| 782 | }, { |
| 783 | .compatible = "samsung,exynos4212-g2d", |
| 784 | .data = &g2d_drvdata_v4x, |
| 785 | }, |
| 786 | {}, |
| 787 | }; |
| 788 | MODULE_DEVICE_TABLE(of, exynos_g2d_match); |
| 789 | |
Krzysztof Kozlowski | 6425f64 | 2015-05-01 12:51:03 -0300 | [diff] [blame] | 790 | static const struct platform_device_id g2d_driver_ids[] = { |
Sachin Kamat | 62ce272 | 2013-01-17 00:07:18 -0300 | [diff] [blame] | 791 | { |
| 792 | .name = "s5p-g2d", |
| 793 | .driver_data = (unsigned long)&g2d_drvdata_v3x, |
| 794 | }, { |
| 795 | .name = "s5p-g2d-v4x", |
| 796 | .driver_data = (unsigned long)&g2d_drvdata_v4x, |
| 797 | }, |
| 798 | {}, |
| 799 | }; |
| 800 | MODULE_DEVICE_TABLE(platform, g2d_driver_ids); |
| 801 | |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 802 | static struct platform_driver g2d_pdrv = { |
| 803 | .probe = g2d_probe, |
| 804 | .remove = g2d_remove, |
Sachin Kamat | 62ce272 | 2013-01-17 00:07:18 -0300 | [diff] [blame] | 805 | .id_table = g2d_driver_ids, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 806 | .driver = { |
| 807 | .name = G2D_NAME, |
Sachin Kamat | 5ce60d7 | 2013-02-06 01:29:43 -0300 | [diff] [blame] | 808 | .of_match_table = exynos_g2d_match, |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 809 | }, |
| 810 | }; |
| 811 | |
Axel Lin | 1d6629b | 2012-01-10 03:21:49 -0300 | [diff] [blame] | 812 | module_platform_driver(g2d_pdrv); |
Kamil Debski | 9188473 | 2011-10-06 11:32:12 -0300 | [diff] [blame] | 813 | |
| 814 | MODULE_AUTHOR("Kamil Debski <k.debski@samsung.com>"); |
| 815 | MODULE_DESCRIPTION("S5P G2D 2d graphics accelerator driver"); |
| 816 | MODULE_LICENSE("GPL"); |