soc_camera.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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-core.h>
  15. #include <linux/pm.h>
  16. struct soc_camera_device {
  17. struct list_head list;
  18. struct device dev;
  19. struct device *control;
  20. unsigned short width; /* Current window */
  21. unsigned short height; /* sizes */
  22. unsigned short x_min; /* Camera capabilities */
  23. unsigned short y_min;
  24. unsigned short x_current; /* Current window location */
  25. unsigned short y_current;
  26. unsigned short width_min;
  27. unsigned short width_max;
  28. unsigned short height_min;
  29. unsigned short height_max;
  30. unsigned short y_skip_top; /* Lines to skip at the top */
  31. unsigned short gain;
  32. unsigned short exposure;
  33. unsigned char iface; /* Host number */
  34. unsigned char devnum; /* Device number per host */
  35. unsigned char buswidth; /* See comment in .c */
  36. struct soc_camera_ops *ops;
  37. struct video_device *vdev;
  38. const struct soc_camera_data_format *current_fmt;
  39. const struct soc_camera_data_format *formats;
  40. int num_formats;
  41. struct soc_camera_format_xlate *user_formats;
  42. int num_user_formats;
  43. struct module *owner;
  44. void *host_priv; /* per-device host private data */
  45. /* soc_camera.c private count. Only accessed with video_lock held */
  46. int use_count;
  47. };
  48. struct soc_camera_file {
  49. struct soc_camera_device *icd;
  50. struct videobuf_queue vb_vidq;
  51. };
  52. struct soc_camera_host {
  53. struct list_head list;
  54. struct device dev;
  55. unsigned char nr; /* Host number */
  56. void *priv;
  57. const char *drv_name;
  58. struct soc_camera_host_ops *ops;
  59. };
  60. struct soc_camera_host_ops {
  61. struct module *owner;
  62. int (*add)(struct soc_camera_device *);
  63. void (*remove)(struct soc_camera_device *);
  64. int (*suspend)(struct soc_camera_device *, pm_message_t);
  65. int (*resume)(struct soc_camera_device *);
  66. int (*get_formats)(struct soc_camera_device *, int,
  67. struct soc_camera_format_xlate *);
  68. int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *);
  69. int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *);
  70. void (*init_videobuf)(struct videobuf_queue *,
  71. struct soc_camera_device *);
  72. int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
  73. int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
  74. int (*set_bus_param)(struct soc_camera_device *, __u32);
  75. unsigned int (*poll)(struct file *, poll_table *);
  76. };
  77. #define SOCAM_SENSOR_INVERT_PCLK (1 << 0)
  78. #define SOCAM_SENSOR_INVERT_MCLK (1 << 1)
  79. #define SOCAM_SENSOR_INVERT_HSYNC (1 << 2)
  80. #define SOCAM_SENSOR_INVERT_VSYNC (1 << 3)
  81. #define SOCAM_SENSOR_INVERT_DATA (1 << 4)
  82. struct soc_camera_link {
  83. /* Camera bus id, used to match a camera and a bus */
  84. int bus_id;
  85. /* GPIO number to switch between 8 and 10 bit modes */
  86. unsigned int gpio;
  87. /* Per camera SOCAM_SENSOR_* bus flags */
  88. unsigned long flags;
  89. /* Optional callbacks to power on or off and reset the sensor */
  90. int (*power)(struct device *, int);
  91. int (*reset)(struct device *);
  92. };
  93. static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
  94. {
  95. return container_of(dev, struct soc_camera_device, dev);
  96. }
  97. static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
  98. {
  99. return container_of(dev, struct soc_camera_host, dev);
  100. }
  101. extern int soc_camera_host_register(struct soc_camera_host *ici);
  102. extern void soc_camera_host_unregister(struct soc_camera_host *ici);
  103. extern int soc_camera_device_register(struct soc_camera_device *icd);
  104. extern void soc_camera_device_unregister(struct soc_camera_device *icd);
  105. extern int soc_camera_video_start(struct soc_camera_device *icd);
  106. extern void soc_camera_video_stop(struct soc_camera_device *icd);
  107. extern const struct soc_camera_data_format *soc_camera_format_by_fourcc(
  108. struct soc_camera_device *icd, unsigned int fourcc);
  109. extern const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
  110. struct soc_camera_device *icd, unsigned int fourcc);
  111. struct soc_camera_data_format {
  112. const char *name;
  113. unsigned int depth;
  114. __u32 fourcc;
  115. enum v4l2_colorspace colorspace;
  116. };
  117. /**
  118. * struct soc_camera_format_xlate - match between host and sensor formats
  119. * @cam_fmt: sensor format provided by the sensor
  120. * @host_fmt: host format after host translation from cam_fmt
  121. * @buswidth: bus width for this format
  122. *
  123. * Host and sensor translation structure. Used in table of host and sensor
  124. * formats matchings in soc_camera_device. A host can override the generic list
  125. * generation by implementing get_formats(), and use it for format checks and
  126. * format setup.
  127. */
  128. struct soc_camera_format_xlate {
  129. const struct soc_camera_data_format *cam_fmt;
  130. const struct soc_camera_data_format *host_fmt;
  131. unsigned char buswidth;
  132. };
  133. struct soc_camera_ops {
  134. struct module *owner;
  135. int (*probe)(struct soc_camera_device *);
  136. void (*remove)(struct soc_camera_device *);
  137. int (*suspend)(struct soc_camera_device *, pm_message_t state);
  138. int (*resume)(struct soc_camera_device *);
  139. int (*init)(struct soc_camera_device *);
  140. int (*release)(struct soc_camera_device *);
  141. int (*start_capture)(struct soc_camera_device *);
  142. int (*stop_capture)(struct soc_camera_device *);
  143. int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *);
  144. int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *);
  145. unsigned long (*query_bus_param)(struct soc_camera_device *);
  146. int (*set_bus_param)(struct soc_camera_device *, unsigned long);
  147. int (*get_chip_id)(struct soc_camera_device *,
  148. struct v4l2_chip_ident *);
  149. #ifdef CONFIG_VIDEO_ADV_DEBUG
  150. int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
  151. int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
  152. #endif
  153. int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
  154. int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
  155. const struct v4l2_queryctrl *controls;
  156. int num_controls;
  157. };
  158. static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
  159. struct soc_camera_ops *ops, int id)
  160. {
  161. int i;
  162. for (i = 0; i < ops->num_controls; i++)
  163. if (ops->controls[i].id == id)
  164. return &ops->controls[i];
  165. return NULL;
  166. }
  167. #define SOCAM_MASTER (1 << 0)
  168. #define SOCAM_SLAVE (1 << 1)
  169. #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
  170. #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
  171. #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
  172. #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
  173. #define SOCAM_DATAWIDTH_8 (1 << 6)
  174. #define SOCAM_DATAWIDTH_9 (1 << 7)
  175. #define SOCAM_DATAWIDTH_10 (1 << 8)
  176. #define SOCAM_DATAWIDTH_16 (1 << 9)
  177. #define SOCAM_PCLK_SAMPLE_RISING (1 << 10)
  178. #define SOCAM_PCLK_SAMPLE_FALLING (1 << 11)
  179. #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
  180. SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16)
  181. static inline unsigned long soc_camera_bus_param_compatible(
  182. unsigned long camera_flags, unsigned long bus_flags)
  183. {
  184. unsigned long common_flags, hsync, vsync, pclk;
  185. common_flags = camera_flags & bus_flags;
  186. hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
  187. vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
  188. pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
  189. return (!hsync || !vsync || !pclk) ? 0 : common_flags;
  190. }
  191. extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
  192. unsigned long flags);
  193. #endif