Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gsc-core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd.
3  * http://www.samsung.com
4  *
5  * header file for Samsung EXYNOS5 SoC series G-Scaler driver
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 version 2 as
9  * published by the Free Software Foundation.
10  */
11 
12 #ifndef GSC_CORE_H_
13 #define GSC_CORE_H_
14 
15 #include <linux/delay.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/types.h>
19 #include <linux/videodev2.h>
20 #include <linux/io.h>
21 #include <linux/pm_runtime.h>
22 #include <media/videobuf2-core.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-mem2mem.h>
26 #include <media/v4l2-mediabus.h>
28 
29 #include "gsc-regs.h"
30 
31 #define CONFIG_VB2_GSC_DMA_CONTIG 1
32 #define GSC_MODULE_NAME "exynos-gsc"
33 
34 #define GSC_SHUTDOWN_TIMEOUT ((100*HZ)/1000)
35 #define GSC_MAX_DEVS 4
36 #define GSC_M2M_BUF_NUM 0
37 #define GSC_MAX_CTRL_NUM 10
38 #define GSC_SC_ALIGN_4 4
39 #define GSC_SC_ALIGN_2 2
40 #define DEFAULT_CSC_EQ 1
41 #define DEFAULT_CSC_RANGE 1
42 
43 #define GSC_PARAMS (1 << 0)
44 #define GSC_SRC_FMT (1 << 1)
45 #define GSC_DST_FMT (1 << 2)
46 #define GSC_CTX_M2M (1 << 3)
47 #define GSC_CTX_STOP_REQ (1 << 6)
48 
50  /* for global */
52 
53  /* for m2m node */
59 };
60 
61 enum gsc_irq {
64 };
65 
74  GSC_CAMERA = 0x1,
79 };
80 
82  GSC_RGB = 0x1,
83  GSC_YUV420 = 0x2,
84  GSC_YUV422 = 0x4,
85  GSC_YUV444 = 0x8,
86 };
87 
89  GSC_LSB_Y = 0x10,
91  GSC_CBCR = 0x20,
93 };
94 
95 #define fh_to_ctx(__fh) container_of(__fh, struct gsc_ctx, fh)
96 #define is_rgb(x) (!!((x) & 0x1))
97 #define is_yuv420(x) (!!((x) & 0x2))
98 #define is_yuv422(x) (!!((x) & 0x4))
99 
100 #define gsc_m2m_active(dev) test_bit(ST_M2M_RUN, &(dev)->state)
101 #define gsc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
102 #define gsc_m2m_opened(dev) test_bit(ST_M2M_OPEN, &(dev)->state)
103 
104 #define ctrl_to_ctx(__ctrl) \
105  container_of((__ctrl)->handler, struct gsc_ctx, ctrl_handler)
106 
118 struct gsc_fmt {
120  char *name;
129 };
130 
138  struct vb2_buffer vb;
139  struct list_head list;
140  int idx;
141 };
142 
149 struct gsc_addr {
153 };
154 
155 /* struct gsc_ctrls - the G-Scaler control set
156  * @rotate: rotation degree
157  * @hflip: horizontal flip
158  * @vflip: vertical flip
159  * @global_alpha: the alpha value of current frame
160  */
161 struct gsc_ctrls {
162  struct v4l2_ctrl *rotate;
163  struct v4l2_ctrl *hflip;
164  struct v4l2_ctrl *vflip;
166 };
167 
176 struct gsc_scaler {
182 };
183 
184 struct gsc_dev;
185 
186 struct gsc_ctx;
187 
199 struct gsc_frame {
202  struct v4l2_rect crop;
203  unsigned long payload[VIDEO_MAX_PLANES];
204  struct gsc_addr addr;
205  const struct gsc_fmt *fmt;
208 };
209 
218  struct video_device *vfd;
220  struct gsc_ctx *ctx;
221  int refcnt;
222 };
223 
240 struct gsc_pix_max {
253 };
254 
267 struct gsc_pix_min {
276 };
277 
286 };
287 
291 struct gsc_variant {
302 };
303 
313  unsigned long lclk_frequency;
315 };
316 
332 struct gsc_dev {
334  struct mutex lock;
338  struct clk *clock;
339  void __iomem *regs;
342  struct exynos_platform_gscaler *pdata;
343  unsigned long state;
344  struct vb2_alloc_ctx *alloc_ctx;
346 };
347 
364 struct gsc_ctx {
372  int rotation;
373  unsigned int hflip:1;
374  unsigned int vflip:1;
375  struct gsc_dev *gsc_dev;
377  struct v4l2_fh fh;
380  bool ctrls_rdy;
381 };
382 
383 void gsc_set_prefbuf(struct gsc_dev *gsc, struct gsc_frame *frm);
384 int gsc_register_m2m_device(struct gsc_dev *gsc);
385 void gsc_unregister_m2m_device(struct gsc_dev *gsc);
386 void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state);
387 
388 u32 get_plane_size(struct gsc_frame *fr, unsigned int plane);
389 const struct gsc_fmt *get_format(int index);
390 const struct gsc_fmt *find_fmt(u32 *pixelformat, u32 *mbus_code, u32 index);
391 int gsc_enum_fmt_mplane(struct v4l2_fmtdesc *f);
392 int gsc_try_fmt_mplane(struct gsc_ctx *ctx, struct v4l2_format *f);
393 void gsc_set_frame_size(struct gsc_frame *frame, int width, int height);
394 int gsc_g_fmt_mplane(struct gsc_ctx *ctx, struct v4l2_format *f);
395 void gsc_check_crop_change(u32 tmp_w, u32 tmp_h, u32 *w, u32 *h);
396 int gsc_g_crop(struct gsc_ctx *ctx, struct v4l2_crop *cr);
397 int gsc_try_crop(struct gsc_ctx *ctx, struct v4l2_crop *cr);
399  u32 *ratio);
400 void gsc_get_prescaler_shfactor(u32 hratio, u32 vratio, u32 *sh);
401 void gsc_check_src_scale_info(struct gsc_variant *var,
402  struct gsc_frame *s_frame,
403  u32 *wratio, u32 tx, u32 ty, u32 *hratio);
404 int gsc_check_scaler_ratio(struct gsc_variant *var, int sw, int sh, int dw,
405  int dh, int rot, int out_path);
406 int gsc_set_scaler_info(struct gsc_ctx *ctx);
407 int gsc_ctrls_create(struct gsc_ctx *ctx);
408 void gsc_ctrls_delete(struct gsc_ctx *ctx);
409 int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_buffer *vb,
410  struct gsc_frame *frame, struct gsc_addr *addr);
411 
412 static inline void gsc_ctx_state_lock_set(u32 state, struct gsc_ctx *ctx)
413 {
414  unsigned long flags;
415 
416  spin_lock_irqsave(&ctx->gsc_dev->slock, flags);
417  ctx->state |= state;
418  spin_unlock_irqrestore(&ctx->gsc_dev->slock, flags);
419 }
420 
421 static inline void gsc_ctx_state_lock_clear(u32 state, struct gsc_ctx *ctx)
422 {
423  unsigned long flags;
424 
425  spin_lock_irqsave(&ctx->gsc_dev->slock, flags);
426  ctx->state &= ~state;
427  spin_unlock_irqrestore(&ctx->gsc_dev->slock, flags);
428 }
429 
430 static inline void gsc_hw_enable_control(struct gsc_dev *dev, bool on)
431 {
432  u32 cfg = readl(dev->regs + GSC_ENABLE);
433 
434  if (on)
435  cfg |= GSC_ENABLE_ON;
436  else
437  cfg &= ~GSC_ENABLE_ON;
438 
439  writel(cfg, dev->regs + GSC_ENABLE);
440 }
441 
442 static inline int gsc_hw_get_irq_status(struct gsc_dev *dev)
443 {
444  u32 cfg = readl(dev->regs + GSC_IRQ);
445  if (cfg & GSC_IRQ_STATUS_OR_IRQ)
446  return GSC_IRQ_OVERRUN;
447  else
448  return GSC_IRQ_DONE;
449 
450 }
451 
452 static inline void gsc_hw_clear_irq(struct gsc_dev *dev, int irq)
453 {
454  u32 cfg = readl(dev->regs + GSC_IRQ);
455  if (irq == GSC_IRQ_OVERRUN)
456  cfg |= GSC_IRQ_STATUS_OR_IRQ;
457  else if (irq == GSC_IRQ_DONE)
459  writel(cfg, dev->regs + GSC_IRQ);
460 }
461 
462 static inline void gsc_lock(struct vb2_queue *vq)
463 {
464  struct gsc_ctx *ctx = vb2_get_drv_priv(vq);
465  mutex_lock(&ctx->gsc_dev->lock);
466 }
467 
468 static inline void gsc_unlock(struct vb2_queue *vq)
469 {
470  struct gsc_ctx *ctx = vb2_get_drv_priv(vq);
471  mutex_unlock(&ctx->gsc_dev->lock);
472 }
473 
474 static inline bool gsc_ctx_state_is_set(u32 mask, struct gsc_ctx *ctx)
475 {
476  unsigned long flags;
477  bool ret;
478 
479  spin_lock_irqsave(&ctx->gsc_dev->slock, flags);
480  ret = (ctx->state & mask) == mask;
481  spin_unlock_irqrestore(&ctx->gsc_dev->slock, flags);
482  return ret;
483 }
484 
485 static inline struct gsc_frame *ctx_get_frame(struct gsc_ctx *ctx,
486  enum v4l2_buf_type type)
487 {
488  struct gsc_frame *frame;
489 
490  if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) {
491  frame = &ctx->s_frame;
492  } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
493  frame = &ctx->d_frame;
494  } else {
495  pr_err("Wrong buffer/video queue type (%d)", type);
496  return ERR_PTR(-EINVAL);
497  }
498 
499  return frame;
500 }
501 
502 void gsc_hw_set_sw_reset(struct gsc_dev *dev);
503 int gsc_wait_reset(struct gsc_dev *dev);
504 
505 void gsc_hw_set_frm_done_irq_mask(struct gsc_dev *dev, bool mask);
506 void gsc_hw_set_gsc_irq_enable(struct gsc_dev *dev, bool mask);
507 void gsc_hw_set_input_buf_masking(struct gsc_dev *dev, u32 shift, bool enable);
508 void gsc_hw_set_output_buf_masking(struct gsc_dev *dev, u32 shift, bool enable);
509 void gsc_hw_set_input_addr(struct gsc_dev *dev, struct gsc_addr *addr,
510  int index);
511 void gsc_hw_set_output_addr(struct gsc_dev *dev, struct gsc_addr *addr,
512  int index);
513 void gsc_hw_set_input_path(struct gsc_ctx *ctx);
514 void gsc_hw_set_in_size(struct gsc_ctx *ctx);
515 void gsc_hw_set_in_image_rgb(struct gsc_ctx *ctx);
516 void gsc_hw_set_in_image_format(struct gsc_ctx *ctx);
517 void gsc_hw_set_output_path(struct gsc_ctx *ctx);
518 void gsc_hw_set_out_size(struct gsc_ctx *ctx);
519 void gsc_hw_set_out_image_rgb(struct gsc_ctx *ctx);
520 void gsc_hw_set_out_image_format(struct gsc_ctx *ctx);
521 void gsc_hw_set_prescaler(struct gsc_ctx *ctx);
522 void gsc_hw_set_mainscaler(struct gsc_ctx *ctx);
523 void gsc_hw_set_rotation(struct gsc_ctx *ctx);
524 void gsc_hw_set_global_alpha(struct gsc_ctx *ctx);
525 void gsc_hw_set_sfr_update(struct gsc_ctx *ctx);
526 
527 #endif /* GSC_CORE_H_ */