mixer.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * Samsung TV Mixer driver
  3. *
  4. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  5. *
  6. * Tomasz Stanislawski, <t.stanislaws@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published
  10. * by the Free Software Foundiation. either version 2 of the License,
  11. * or (at your option) any later version
  12. */
  13. #ifndef SAMSUNG_MIXER_H
  14. #define SAMSUNG_MIXER_H
  15. #ifdef CONFIG_VIDEO_SAMSUNG_S5P_MIXER_DEBUG
  16. #define DEBUG
  17. #endif
  18. #include <linux/fb.h>
  19. #include <linux/irqreturn.h>
  20. #include <linux/kernel.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/wait.h>
  23. #include <media/v4l2-device.h>
  24. #include <media/videobuf2-v4l2.h>
  25. #include "regs-mixer.h"
  26. /** maximum number of output interfaces */
  27. #define MXR_MAX_OUTPUTS 2
  28. /** maximum number of input interfaces (layers) */
  29. #define MXR_MAX_LAYERS 3
  30. #define MXR_DRIVER_NAME "s5p-mixer"
  31. /** maximal number of planes for every layer */
  32. #define MXR_MAX_PLANES 2
  33. #define MXR_ENABLE 1
  34. #define MXR_DISABLE 0
  35. /** description of a macroblock for packed formats */
  36. struct mxr_block {
  37. /** vertical number of pixels in macroblock */
  38. unsigned int width;
  39. /** horizontal number of pixels in macroblock */
  40. unsigned int height;
  41. /** size of block in bytes */
  42. unsigned int size;
  43. };
  44. /** description of supported format */
  45. struct mxr_format {
  46. /** format name/mnemonic */
  47. const char *name;
  48. /** fourcc identifier */
  49. u32 fourcc;
  50. /** colorspace identifier */
  51. enum v4l2_colorspace colorspace;
  52. /** number of planes in image data */
  53. int num_planes;
  54. /** description of block for each plane */
  55. struct mxr_block plane[MXR_MAX_PLANES];
  56. /** number of subframes in image data */
  57. int num_subframes;
  58. /** specifies to which subframe belong given plane */
  59. int plane2subframe[MXR_MAX_PLANES];
  60. /** internal code, driver dependent */
  61. unsigned long cookie;
  62. };
  63. /** description of crop configuration for image */
  64. struct mxr_crop {
  65. /** width of layer in pixels */
  66. unsigned int full_width;
  67. /** height of layer in pixels */
  68. unsigned int full_height;
  69. /** horizontal offset of first pixel to be displayed */
  70. unsigned int x_offset;
  71. /** vertical offset of first pixel to be displayed */
  72. unsigned int y_offset;
  73. /** width of displayed data in pixels */
  74. unsigned int width;
  75. /** height of displayed data in pixels */
  76. unsigned int height;
  77. /** indicate which fields are present in buffer */
  78. unsigned int field;
  79. };
  80. /** stages of geometry operations */
  81. enum mxr_geometry_stage {
  82. MXR_GEOMETRY_SINK,
  83. MXR_GEOMETRY_COMPOSE,
  84. MXR_GEOMETRY_CROP,
  85. MXR_GEOMETRY_SOURCE,
  86. };
  87. /* flag indicating that offset should be 0 */
  88. #define MXR_NO_OFFSET 0x80000000
  89. /** description of transformation from source to destination image */
  90. struct mxr_geometry {
  91. /** cropping for source image */
  92. struct mxr_crop src;
  93. /** cropping for destination image */
  94. struct mxr_crop dst;
  95. /** layer-dependant description of horizontal scaling */
  96. unsigned int x_ratio;
  97. /** layer-dependant description of vertical scaling */
  98. unsigned int y_ratio;
  99. };
  100. /** instance of a buffer */
  101. struct mxr_buffer {
  102. /** common v4l buffer stuff -- must be first */
  103. struct vb2_v4l2_buffer vb;
  104. /** node for layer's lists */
  105. struct list_head list;
  106. };
  107. /** internal states of layer */
  108. enum mxr_layer_state {
  109. /** layers is not shown */
  110. MXR_LAYER_IDLE = 0,
  111. /** layer is shown */
  112. MXR_LAYER_STREAMING,
  113. /** state before STREAMOFF is finished */
  114. MXR_LAYER_STREAMING_FINISH,
  115. };
  116. /** forward declarations */
  117. struct mxr_device;
  118. struct mxr_layer;
  119. /** callback for layers operation */
  120. struct mxr_layer_ops {
  121. /* TODO: try to port it to subdev API */
  122. /** handler for resource release function */
  123. void (*release)(struct mxr_layer *);
  124. /** setting buffer to HW */
  125. void (*buffer_set)(struct mxr_layer *, struct mxr_buffer *);
  126. /** setting format and geometry in HW */
  127. void (*format_set)(struct mxr_layer *);
  128. /** streaming stop/start */
  129. void (*stream_set)(struct mxr_layer *, int);
  130. /** adjusting geometry */
  131. void (*fix_geometry)(struct mxr_layer *,
  132. enum mxr_geometry_stage, unsigned long);
  133. };
  134. /** layer instance, a single window and content displayed on output */
  135. struct mxr_layer {
  136. /** parent mixer device */
  137. struct mxr_device *mdev;
  138. /** layer index (unique identifier) */
  139. int idx;
  140. /** callbacks for layer methods */
  141. struct mxr_layer_ops ops;
  142. /** format array */
  143. const struct mxr_format **fmt_array;
  144. /** size of format array */
  145. unsigned long fmt_array_size;
  146. /** lock for protection of list and state fields */
  147. spinlock_t enq_slock;
  148. /** list for enqueued buffers */
  149. struct list_head enq_list;
  150. /** buffer currently owned by hardware in temporary registers */
  151. struct mxr_buffer *update_buf;
  152. /** buffer currently owned by hardware in shadow registers */
  153. struct mxr_buffer *shadow_buf;
  154. /** state of layer IDLE/STREAMING */
  155. enum mxr_layer_state state;
  156. /** mutex for protection of fields below */
  157. struct mutex mutex;
  158. /** handler for video node */
  159. struct video_device vfd;
  160. /** queue for output buffers */
  161. struct vb2_queue vb_queue;
  162. /** current image format */
  163. const struct mxr_format *fmt;
  164. /** current geometry of image */
  165. struct mxr_geometry geo;
  166. };
  167. /** description of mixers output interface */
  168. struct mxr_output {
  169. /** name of output */
  170. char name[32];
  171. /** output subdev */
  172. struct v4l2_subdev *sd;
  173. /** cookie used for configuration of registers */
  174. int cookie;
  175. };
  176. /** specify source of output subdevs */
  177. struct mxr_output_conf {
  178. /** name of output (connector) */
  179. char *output_name;
  180. /** name of module that generates output subdev */
  181. char *module_name;
  182. /** cookie need for mixer HW */
  183. int cookie;
  184. };
  185. struct clk;
  186. struct regulator;
  187. /** auxiliary resources used my mixer */
  188. struct mxr_resources {
  189. /** interrupt index */
  190. int irq;
  191. /** pointer to Mixer registers */
  192. void __iomem *mxr_regs;
  193. /** pointer to Video Processor registers */
  194. void __iomem *vp_regs;
  195. /** other resources, should used under mxr_device.mutex */
  196. struct clk *mixer;
  197. struct clk *vp;
  198. struct clk *sclk_mixer;
  199. struct clk *sclk_hdmi;
  200. struct clk *sclk_dac;
  201. };
  202. /* event flags used */
  203. enum mxr_devide_flags {
  204. MXR_EVENT_VSYNC = 0,
  205. MXR_EVENT_TOP = 1,
  206. };
  207. /** drivers instance */
  208. struct mxr_device {
  209. /** master device */
  210. struct device *dev;
  211. /** state of each layer */
  212. struct mxr_layer *layer[MXR_MAX_LAYERS];
  213. /** state of each output */
  214. struct mxr_output *output[MXR_MAX_OUTPUTS];
  215. /** number of registered outputs */
  216. int output_cnt;
  217. /* video resources */
  218. /** V4L2 device */
  219. struct v4l2_device v4l2_dev;
  220. /** context of allocator */
  221. void *alloc_ctx;
  222. /** event wait queue */
  223. wait_queue_head_t event_queue;
  224. /** state flags */
  225. unsigned long event_flags;
  226. /** spinlock for protection of registers */
  227. spinlock_t reg_slock;
  228. /** mutex for protection of fields below */
  229. struct mutex mutex;
  230. /** number of entities depndant on output configuration */
  231. int n_output;
  232. /** number of users that do streaming */
  233. int n_streamer;
  234. /** index of current output */
  235. int current_output;
  236. /** auxiliary resources used my mixer */
  237. struct mxr_resources res;
  238. };
  239. /** transform device structure into mixer device */
  240. static inline struct mxr_device *to_mdev(struct device *dev)
  241. {
  242. struct v4l2_device *vdev = dev_get_drvdata(dev);
  243. return container_of(vdev, struct mxr_device, v4l2_dev);
  244. }
  245. /** get current output data, should be called under mdev's mutex */
  246. static inline struct mxr_output *to_output(struct mxr_device *mdev)
  247. {
  248. return mdev->output[mdev->current_output];
  249. }
  250. /** get current output subdev, should be called under mdev's mutex */
  251. static inline struct v4l2_subdev *to_outsd(struct mxr_device *mdev)
  252. {
  253. struct mxr_output *out = to_output(mdev);
  254. return out ? out->sd : NULL;
  255. }
  256. /** forward declaration for mixer platform data */
  257. struct mxr_platform_data;
  258. /** acquiring common video resources */
  259. int mxr_acquire_video(struct mxr_device *mdev,
  260. struct mxr_output_conf *output_cont, int output_count);
  261. /** releasing common video resources */
  262. void mxr_release_video(struct mxr_device *mdev);
  263. struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx);
  264. struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx);
  265. struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
  266. int idx, char *name, struct mxr_layer_ops *ops);
  267. void mxr_base_layer_release(struct mxr_layer *layer);
  268. void mxr_layer_release(struct mxr_layer *layer);
  269. int mxr_base_layer_register(struct mxr_layer *layer);
  270. void mxr_base_layer_unregister(struct mxr_layer *layer);
  271. unsigned long mxr_get_plane_size(const struct mxr_block *blk,
  272. unsigned int width, unsigned int height);
  273. /** adds new consumer for mixer's power */
  274. int __must_check mxr_power_get(struct mxr_device *mdev);
  275. /** removes consumer for mixer's power */
  276. void mxr_power_put(struct mxr_device *mdev);
  277. /** add new client for output configuration */
  278. void mxr_output_get(struct mxr_device *mdev);
  279. /** removes new client for output configuration */
  280. void mxr_output_put(struct mxr_device *mdev);
  281. /** add new client for streaming */
  282. void mxr_streamer_get(struct mxr_device *mdev);
  283. /** removes new client for streaming */
  284. void mxr_streamer_put(struct mxr_device *mdev);
  285. /** returns format of data delivared to current output */
  286. void mxr_get_mbus_fmt(struct mxr_device *mdev,
  287. struct v4l2_mbus_framefmt *mbus_fmt);
  288. /* Debug */
  289. #define mxr_err(mdev, fmt, ...) dev_err(mdev->dev, fmt, ##__VA_ARGS__)
  290. #define mxr_warn(mdev, fmt, ...) dev_warn(mdev->dev, fmt, ##__VA_ARGS__)
  291. #define mxr_info(mdev, fmt, ...) dev_info(mdev->dev, fmt, ##__VA_ARGS__)
  292. #ifdef CONFIG_VIDEO_SAMSUNG_S5P_MIXER_DEBUG
  293. #define mxr_dbg(mdev, fmt, ...) dev_dbg(mdev->dev, fmt, ##__VA_ARGS__)
  294. #else
  295. #define mxr_dbg(mdev, fmt, ...) do { (void) mdev; } while (0)
  296. #endif
  297. /* accessing Mixer's and Video Processor's registers */
  298. void mxr_vsync_set_update(struct mxr_device *mdev, int en);
  299. void mxr_reg_reset(struct mxr_device *mdev);
  300. irqreturn_t mxr_irq_handler(int irq, void *dev_data);
  301. void mxr_reg_s_output(struct mxr_device *mdev, int cookie);
  302. void mxr_reg_streamon(struct mxr_device *mdev);
  303. void mxr_reg_streamoff(struct mxr_device *mdev);
  304. int mxr_reg_wait4vsync(struct mxr_device *mdev);
  305. void mxr_reg_set_mbus_fmt(struct mxr_device *mdev,
  306. struct v4l2_mbus_framefmt *fmt);
  307. void mxr_reg_graph_layer_stream(struct mxr_device *mdev, int idx, int en);
  308. void mxr_reg_graph_buffer(struct mxr_device *mdev, int idx, dma_addr_t addr);
  309. void mxr_reg_graph_format(struct mxr_device *mdev, int idx,
  310. const struct mxr_format *fmt, const struct mxr_geometry *geo);
  311. void mxr_reg_vp_layer_stream(struct mxr_device *mdev, int en);
  312. void mxr_reg_vp_buffer(struct mxr_device *mdev,
  313. dma_addr_t luma_addr[2], dma_addr_t chroma_addr[2]);
  314. void mxr_reg_vp_format(struct mxr_device *mdev,
  315. const struct mxr_format *fmt, const struct mxr_geometry *geo);
  316. void mxr_reg_dump(struct mxr_device *mdev);
  317. #endif /* SAMSUNG_MIXER_H */