mixer.h 11 KB

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