ark1668e_vin.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #ifndef _ARK1668_VIDEO_H_
  2. #define _ARK1668_VIDEO_H_
  3. #include <linux/cdev.h>
  4. #include <linux/i2c.h>
  5. #include <linux/soc/arkmicro/ark1668e_lcdc_regs.h>
  6. #include <linux/soc/arkmicro/ark1668e_sys_resgs.h>
  7. #include <linux/soc/arkmicro/ark1668e_itu656_regs.h>
  8. #include <linux/soc/arkmicro/ark_scale.h>
  9. //#include <linux/soc/arkmicro/ark1668e_gpio.h>
  10. #define ITU656_FRAME_NUM 4
  11. #define ITU656_BUFFER_NUM 3
  12. #define ITU656_SCALE_FRAME_NUM 3
  13. #define ITU656_FRAME_NUM_MAX 8
  14. #define ARK_VIN_NAME "ark1668e_vin"
  15. #define PAL 0
  16. #define NTSC 1
  17. #define PAL_WIDTH 720
  18. #define PAL_HEIGHT 288
  19. #define NTSC_WIDTH 720
  20. #define NTSC_HEIGHT 240
  21. #define CVBS_WIDTH PAL_WIDTH
  22. #define CVBS_HEIGHT PAL_HEIGHT
  23. #define START_DISCARD_FRAME 6
  24. #define DISPLAY_WIDTH 1024
  25. #define DISPLAY_HEIGHT 600
  26. #define ITU656_FIELD_SIZE (CVBS_WIDTH*CVBS_HEIGHT*2)
  27. #define ITU656_FRAME_SIZE (ITU656_FIELD_SIZE*2)
  28. #define ITU656_PROGRESSIVE_FRAME_SIZE (1280*720*2)
  29. #define ITU656_PROGRESSIVE_FRAME_SIZE_1080P (1920*1080*3/2)
  30. #define ARK_IOW(num, dtype) _IOW('O', num, dtype)
  31. #define ARK_IOR(num, dtype) _IOR('O', num, dtype)
  32. #define ARK_IOWR(num, dtype) _IOWR('O', num, dtype)
  33. #define ARK_IO(num) _IO('O', num)
  34. //for v4l2 sd
  35. #define VIDIOC_GET_RESOLUTION _IOWR('V', BASE_VIDIOC_PRIVATE + 1, int)
  36. #define VIDIOC_GET_PROGRESSIVE _IOWR('V', BASE_VIDIOC_PRIVATE + 2, int)
  37. #define VIDIOC_GET_CHIPINFO _IOWR('V', BASE_VIDIOC_PRIVATE + 3, int)
  38. #define VIDIOC_ENTER_CARBACK _IOWR('V', BASE_VIDIOC_PRIVATE + 4, int)
  39. #define VIDIOC_EXIT_CARBACK _IOWR('V', BASE_VIDIOC_PRIVATE + 5, int)
  40. #define VIDIOC_GET_ITU601_ENABLE _IOWR('V', BASE_VIDIOC_PRIVATE + 6, int)
  41. #define VIDIOC_SET_AVIN_MODE _IOWR('V', BASE_VIDIOC_PRIVATE + 7, int)
  42. #define VIDIOC_ENABLE_TIME _IOWR('V', BASE_VIDIOC_PRIVATE + 8, int)
  43. #define TVOUT_LAYER 0
  44. #define DISPLAY_LAYER 1
  45. #define TRACK_LAYER 2
  46. #define vin_readl(reg) __raw_readl(g_ark1668e_vin->dvr_dev->context.itu656_base+(reg))
  47. #define vin_writel(reg, val) __raw_writel((val), g_ark1668e_vin->dvr_dev->context.itu656_base+(reg))
  48. #define vin_readl_sys(reg) __raw_readl(g_ark1668e_vin->dvr_dev->context.sys_base+(reg))
  49. #define vin_writel_sys(reg, val) __raw_writel((val), g_ark1668e_vin->dvr_dev->context.sys_base+(reg))
  50. #define vin_readl_dein(reg) __raw_readl(g_ark1668e_vin->dvr_dev->context.deinterlace_base+(reg))
  51. #define vin_writel_dein(reg, val) __raw_writel((val), g_ark1668e_vin->dvr_dev->context.deinterlace_base+(reg))
  52. #define vin_readl_lcd(reg) __raw_readl(g_ark1668e_vin->dvr_dev->context.lcd_base+(reg))
  53. #define vin_writel_lcd(reg, val) __raw_writel((val), g_ark1668e_vin->dvr_dev->context.lcd_base+(reg))
  54. enum vin_framebuf_status{
  55. FRAMEBUF_STATUS_FREE,
  56. FRAMEBUF_STATUS_BUSY,
  57. FRAMEBUF_STATUS_READY,
  58. };
  59. enum {
  60. TYPE_UNKNOWN = -1,
  61. TYPE_CVBS = 0,
  62. TYPE_720P,
  63. TYPE_1080P,
  64. };
  65. enum ark7116_channel {
  66. ARK7116_AV0,
  67. ARK7116_AV1,
  68. ARK7116_AV2,
  69. };
  70. enum itu656_channel {
  71. ITU656_CH0,
  72. ITU656_CH1,
  73. ITU656_CH2,
  74. };
  75. enum dvr_source {
  76. DVR_SOURCE_CAMERA,
  77. DVR_SOURCE_AUX,
  78. DVR_SOURCE_DVD,
  79. };
  80. enum itu656_mirror{
  81. MIRROR_NO = 0,
  82. MIRROR_LEVEL,
  83. MIRROR_VERTICAL,
  84. MIRROR_LEVEL_VERTICAL,
  85. MIRROR_END,
  86. };
  87. enum {
  88. TYPE_UNDEF = -1,
  89. TYPE_ARK7116 = 0,
  90. TYPE_ARK7116H,
  91. TYPE_RN6752,
  92. TYPE_PR2000,
  93. };
  94. struct vin_para{
  95. int xpos;
  96. int ypos;
  97. int width;
  98. int height;
  99. int source;
  100. int tvout;
  101. int hori_mirror;
  102. int vert_mirror;
  103. int left_blank;
  104. int right_blank;
  105. int top_blank;
  106. int bottom_blank;
  107. int progressive;
  108. int itu601en;
  109. };
  110. struct ark_itu656in_context {
  111. int itu656_irq;
  112. int deinterlace_irq;
  113. struct device *dev;
  114. void __iomem *itu656_base;
  115. void __iomem *sys_base;
  116. void __iomem *deinterlace_base;
  117. void __iomem *lcd_base;
  118. };
  119. struct dvr_dev{
  120. char *name;
  121. int work_status;
  122. int channel;
  123. int itu_channel;
  124. int system; //ntsc or pal
  125. int interlace;
  126. int itu601en;
  127. int chip_info;
  128. int discard_frame;
  129. int cur_buffer;
  130. int show_video;
  131. int deinter_status;
  132. int src_width;
  133. int src_height;
  134. int screen_width;
  135. int screen_height;
  136. int screen_xpos;
  137. int screen_ypos;
  138. int carback_exit_status;
  139. u8 *buffer_virtaddr;
  140. unsigned int buffer_size;
  141. unsigned int buffer_phyaddr;
  142. unsigned int scale_buffer_size;
  143. int scale_alloc_width;
  144. int scale_alloc_height;
  145. int *scale_out_yaddr;
  146. int scale_out_yphyaddr;
  147. int scale_in_yphyaddr;
  148. int carback_signal;
  149. int layer_status;
  150. int signal_flag;
  151. int vin_mirror_config;
  152. int vin_buffer_status;
  153. int first_show_flag;
  154. int dev_major, dev_minor;
  155. #ifdef CONFIG_VIDEO_USE_LOCK
  156. struct semaphore vin_sem;
  157. #endif
  158. spinlock_t spin_lock;
  159. struct work_struct scale_work;
  160. struct workqueue_struct *scale_queue;
  161. struct work_struct detect_work;
  162. struct workqueue_struct *detect_queue;
  163. struct cdev cdev;
  164. struct i2c_client *client;
  165. struct vin_para itu656in;
  166. struct vin_para itu656in_back;
  167. struct timer_list timer;
  168. struct timer_list signal_timer;
  169. unsigned int framebuf_phyaddr[ITU656_FRAME_NUM_MAX];
  170. unsigned int framebuf_status[ITU656_FRAME_NUM_MAX];
  171. unsigned int scalebuf_phyaddr[ITU656_SCALE_FRAME_NUM];
  172. unsigned int framebuf_num;
  173. unsigned int scale_framebuf_num;
  174. unsigned int scale_framebuf_index;
  175. unsigned int cur_frame;
  176. unsigned int frame_finish[ITU656_FRAME_NUM_MAX];//store frame id
  177. int frame_finish_count;
  178. wait_queue_head_t frame_finish_waitq;
  179. struct ark_itu656in_context context;
  180. };
  181. struct vin_subdev_entity {
  182. struct v4l2_subdev *sd;
  183. struct v4l2_async_subdev *asd;
  184. struct v4l2_async_notifier notifier;
  185. u32 pfe_cfg0;
  186. struct list_head list;
  187. };
  188. struct vin_buffer {
  189. struct vb2_v4l2_buffer vb;
  190. struct list_head list;
  191. };
  192. struct ark1668e_vin_device {
  193. struct device *dev;
  194. struct v4l2_device v4l2_dev;
  195. struct video_device video_dev;
  196. struct vb2_queue vb2_vidq;
  197. spinlock_t ark_queue_lock;
  198. struct list_head ark_queue;
  199. struct vin_buffer *cur_frm;
  200. unsigned int sequence;
  201. unsigned int vin_status;
  202. unsigned int sd_init;
  203. unsigned int app_channel_set;
  204. bool stop;
  205. bool stream_flag;
  206. int aux_flag;
  207. int aux_status;
  208. struct completion comp;
  209. struct v4l2_format fmt;
  210. struct work_struct awb_work;
  211. struct mutex lock;
  212. struct vin_subdev_entity *current_subdev;
  213. struct list_head subdev_entities;
  214. struct dvr_dev *dvr_dev;
  215. };
  216. struct vin_screen {
  217. unsigned int disp_x;
  218. unsigned int disp_y;
  219. unsigned int disp_width;
  220. unsigned int disp_height;
  221. };
  222. #define ARK_DVR_IOC_MAGIC 'n'
  223. #define VIN_UPDATE_WINDOW _IOWR(ARK_DVR_IOC_MAGIC, 50, struct vin_screen)
  224. #define VIN_START _IO(ARK_DVR_IOC_MAGIC, 51)
  225. #define VIN_STOP _IO(ARK_DVR_IOC_MAGIC, 52)
  226. #define VIN_SWITCH_CHANNEL _IOWR(ARK_DVR_IOC_MAGIC, 53, int)
  227. #define VIN_CONFIG _IOWR(ARK_DVR_IOC_MAGIC, 54, struct vin_para)
  228. #ifdef CONFIG_VIDEO_USE_LOCK
  229. #define VIN_IOCTL_DOWN_IDLE _IO(ARK_DVR_IOC_MAGIC, 55)
  230. #define VIN_IOCTL_UP_IDLE _IO(ARK_DVR_IOC_MAGIC, 56)
  231. #endif
  232. #endif