soc_camera.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * camera image capture (abstract) bus driver header
  3. *
  4. * Copyright (C) 2006, Sascha Hauer, Pengutronix
  5. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef SOC_CAMERA_H
  12. #define SOC_CAMERA_H
  13. #include <linux/videodev2.h>
  14. #include <media/videobuf-dma-sg.h>
  15. struct soc_camera_device {
  16. struct list_head list;
  17. struct device dev;
  18. struct device *control;
  19. unsigned short width; /* Current window */
  20. unsigned short height; /* sizes */
  21. unsigned short x_min; /* Camera capabilities */
  22. unsigned short y_min;
  23. unsigned short x_current; /* Current window location */
  24. unsigned short y_current;
  25. unsigned short width_min;
  26. unsigned short width_max;
  27. unsigned short height_min;
  28. unsigned short height_max;
  29. unsigned short y_skip_top; /* Lines to skip at the top */
  30. unsigned short gain;
  31. unsigned short exposure;
  32. unsigned char iface; /* Host number */
  33. unsigned char devnum; /* Device number per host */
  34. unsigned char cached_datawidth; /* See comment in .c */
  35. struct soc_camera_ops *ops;
  36. struct video_device *vdev;
  37. const struct soc_camera_data_format *current_fmt;
  38. int (*probe)(struct soc_camera_device *icd);
  39. void (*remove)(struct soc_camera_device *icd);
  40. struct module *owner;
  41. };
  42. struct soc_camera_file {
  43. struct soc_camera_device *icd;
  44. struct videobuf_queue vb_vidq;
  45. };
  46. struct soc_camera_host {
  47. struct list_head list;
  48. struct device dev;
  49. unsigned char nr; /* Host number */
  50. size_t msize;
  51. struct videobuf_queue_ops *vbq_ops;
  52. struct module *owner;
  53. void *priv;
  54. char *drv_name;
  55. int (*add)(struct soc_camera_device *);
  56. void (*remove)(struct soc_camera_device *);
  57. int (*set_capture_format)(struct soc_camera_device *, __u32,
  58. struct v4l2_rect *);
  59. int (*try_fmt_cap)(struct soc_camera_host *, struct v4l2_format *);
  60. int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
  61. int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
  62. unsigned int (*poll)(struct file *, poll_table *);
  63. };
  64. struct soc_camera_link {
  65. /* Camera bus id, used to match a camera and a bus */
  66. int bus_id;
  67. /* GPIO number to switch between 8 and 10 bit modes */
  68. unsigned int gpio;
  69. };
  70. static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
  71. {
  72. return container_of(dev, struct soc_camera_device, dev);
  73. }
  74. static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
  75. {
  76. return container_of(dev, struct soc_camera_host, dev);
  77. }
  78. extern int soc_camera_host_register(struct soc_camera_host *ici,
  79. struct module *owner);
  80. extern void soc_camera_host_unregister(struct soc_camera_host *ici);
  81. extern int soc_camera_device_register(struct soc_camera_device *icd);
  82. extern void soc_camera_device_unregister(struct soc_camera_device *icd);
  83. extern int soc_camera_video_start(struct soc_camera_device *icd);
  84. extern void soc_camera_video_stop(struct soc_camera_device *icd);
  85. struct soc_camera_data_format {
  86. char *name;
  87. unsigned int depth;
  88. __u32 fourcc;
  89. enum v4l2_colorspace colorspace;
  90. };
  91. struct soc_camera_ops {
  92. struct module *owner;
  93. int (*init)(struct soc_camera_device *);
  94. int (*release)(struct soc_camera_device *);
  95. int (*start_capture)(struct soc_camera_device *);
  96. int (*stop_capture)(struct soc_camera_device *);
  97. int (*set_capture_format)(struct soc_camera_device *, __u32,
  98. struct v4l2_rect *, unsigned int);
  99. int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
  100. int (*get_chip_id)(struct soc_camera_device *,
  101. struct v4l2_chip_ident *);
  102. #ifdef CONFIG_VIDEO_ADV_DEBUG
  103. int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
  104. int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
  105. #endif
  106. const struct soc_camera_data_format *formats;
  107. int num_formats;
  108. int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
  109. int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
  110. const struct v4l2_queryctrl *controls;
  111. int num_controls;
  112. unsigned int(*get_datawidth)(struct soc_camera_device *icd);
  113. };
  114. static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
  115. struct soc_camera_ops *ops, int id)
  116. {
  117. int i;
  118. for (i = 0; i < ops->num_controls; i++)
  119. if (ops->controls[i].id == id)
  120. return &ops->controls[i];
  121. return NULL;
  122. }
  123. #define IS_MASTER (1<<0)
  124. #define IS_HSYNC_ACTIVE_HIGH (1<<1)
  125. #define IS_VSYNC_ACTIVE_HIGH (1<<2)
  126. #define IS_DATAWIDTH_8 (1<<3)
  127. #define IS_DATAWIDTH_9 (1<<4)
  128. #define IS_DATAWIDTH_10 (1<<5)
  129. #define IS_PCLK_SAMPLE_RISING (1<<6)
  130. #endif