mixer.h 10 KB

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