rcar-vin.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Driver for Renesas R-Car VIN
  3. *
  4. * Copyright (C) 2016 Renesas Electronics Corp.
  5. * Copyright (C) 2011-2013 Renesas Solutions Corp.
  6. * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
  7. * Copyright (C) 2008 Magnus Damm
  8. *
  9. * Based on the soc-camera rcar_vin driver
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. #ifndef __RCAR_VIN__
  17. #define __RCAR_VIN__
  18. #include <media/v4l2-async.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/v4l2-dev.h>
  21. #include <media/v4l2-device.h>
  22. #include <media/videobuf2-v4l2.h>
  23. /* Number of HW buffers */
  24. #define HW_BUFFER_NUM 3
  25. /* Address alignment mask for HW buffers */
  26. #define HW_BUFFER_MASK 0x7f
  27. enum chip_id {
  28. RCAR_H1,
  29. RCAR_M1,
  30. RCAR_GEN2,
  31. };
  32. /**
  33. * STOPPED - No operation in progress
  34. * RUNNING - Operation in progress have buffers
  35. * STALLED - No operation in progress have no buffers
  36. * STOPPING - Stopping operation
  37. */
  38. enum rvin_dma_state {
  39. STOPPED = 0,
  40. RUNNING,
  41. STALLED,
  42. STOPPING,
  43. };
  44. /**
  45. * struct rvin_source_fmt - Source information
  46. * @width: Width from source
  47. * @height: Height from source
  48. */
  49. struct rvin_source_fmt {
  50. u32 width;
  51. u32 height;
  52. };
  53. /**
  54. * struct rvin_video_format - Data format stored in memory
  55. * @fourcc: Pixelformat
  56. * @bpp: Bytes per pixel
  57. */
  58. struct rvin_video_format {
  59. u32 fourcc;
  60. u8 bpp;
  61. };
  62. /**
  63. * struct rvin_graph_entity - Video endpoint from async framework
  64. * @asd: sub-device descriptor for async framework
  65. * @subdev: subdevice matched using async framework
  66. * @code: Media bus format from source
  67. * @mbus_cfg: Media bus format from DT
  68. * @source_pad: source pad of remote subdevice
  69. * @sink_pad: sink pad of remote subdevice
  70. */
  71. struct rvin_graph_entity {
  72. struct v4l2_async_subdev asd;
  73. struct v4l2_subdev *subdev;
  74. u32 code;
  75. struct v4l2_mbus_config mbus_cfg;
  76. unsigned int source_pad;
  77. unsigned int sink_pad;
  78. };
  79. /**
  80. * struct rvin_dev - Renesas VIN device structure
  81. * @dev: (OF) device
  82. * @base: device I/O register space remapped to virtual memory
  83. * @chip: type of VIN chip
  84. *
  85. * @vdev: V4L2 video device associated with VIN
  86. * @v4l2_dev: V4L2 device
  87. * @ctrl_handler: V4L2 control handler
  88. * @notifier: V4L2 asynchronous subdevs notifier
  89. * @digital: entity in the DT for local digital subdevice
  90. *
  91. * @lock: protects @queue
  92. * @queue: vb2 buffers queue
  93. *
  94. * @qlock: protects @queue_buf, @buf_list, @continuous, @sequence
  95. * @state
  96. * @queue_buf: Keeps track of buffers given to HW slot
  97. * @buf_list: list of queued buffers
  98. * @continuous: tracks if active operation is continuous or single mode
  99. * @sequence: V4L2 buffers sequence number
  100. * @state: keeps track of operation state
  101. *
  102. * @source: active format from the video source
  103. * @format: active V4L2 pixel format
  104. *
  105. * @crop: active cropping
  106. * @compose: active composing
  107. */
  108. struct rvin_dev {
  109. struct device *dev;
  110. void __iomem *base;
  111. enum chip_id chip;
  112. struct video_device vdev;
  113. struct v4l2_device v4l2_dev;
  114. struct v4l2_ctrl_handler ctrl_handler;
  115. struct v4l2_async_notifier notifier;
  116. struct rvin_graph_entity digital;
  117. struct mutex lock;
  118. struct vb2_queue queue;
  119. spinlock_t qlock;
  120. struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
  121. struct list_head buf_list;
  122. bool continuous;
  123. unsigned int sequence;
  124. enum rvin_dma_state state;
  125. struct rvin_source_fmt source;
  126. struct v4l2_pix_format format;
  127. struct v4l2_rect crop;
  128. struct v4l2_rect compose;
  129. };
  130. #define vin_to_source(vin) vin->digital.subdev
  131. /* Debug */
  132. #define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)
  133. #define vin_info(d, fmt, arg...) dev_info(d->dev, fmt, ##arg)
  134. #define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
  135. #define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg)
  136. int rvin_dma_probe(struct rvin_dev *vin, int irq);
  137. void rvin_dma_remove(struct rvin_dev *vin);
  138. int rvin_v4l2_probe(struct rvin_dev *vin);
  139. void rvin_v4l2_remove(struct rvin_dev *vin);
  140. const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
  141. /* Cropping, composing and scaling */
  142. void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
  143. u32 width, u32 height);
  144. void rvin_crop_scale_comp(struct rvin_dev *vin);
  145. #endif