soc_camera.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 module *owner;
  42. /* soc_camera.c private count. Only accessed with video_lock held */
  43. int use_count;
  44. };
  45. struct soc_camera_file {
  46. struct soc_camera_device *icd;
  47. struct videobuf_queue vb_vidq;
  48. };
  49. struct soc_camera_host {
  50. struct list_head list;
  51. struct device dev;
  52. unsigned char nr; /* Host number */
  53. void *priv;
  54. char *drv_name;
  55. struct soc_camera_host_ops *ops;
  56. };
  57. struct soc_camera_host_ops {
  58. struct module *owner;
  59. int (*add)(struct soc_camera_device *);
  60. void (*remove)(struct soc_camera_device *);
  61. int (*suspend)(struct soc_camera_device *, pm_message_t state);
  62. int (*resume)(struct soc_camera_device *);
  63. int (*set_fmt_cap)(struct soc_camera_device *, __u32,
  64. struct v4l2_rect *);
  65. int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
  66. void (*init_videobuf)(struct videobuf_queue *,
  67. struct soc_camera_device *);
  68. int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
  69. int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
  70. int (*try_bus_param)(struct soc_camera_device *, __u32);
  71. int (*set_bus_param)(struct soc_camera_device *, __u32);
  72. unsigned int (*poll)(struct file *, poll_table *);
  73. };
  74. struct soc_camera_link {
  75. /* Camera bus id, used to match a camera and a bus */
  76. int bus_id;
  77. /* GPIO number to switch between 8 and 10 bit modes */
  78. unsigned int gpio;
  79. };
  80. static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
  81. {
  82. return container_of(dev, struct soc_camera_device, dev);
  83. }
  84. static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
  85. {
  86. return container_of(dev, struct soc_camera_host, dev);
  87. }
  88. extern int soc_camera_host_register(struct soc_camera_host *ici);
  89. extern void soc_camera_host_unregister(struct soc_camera_host *ici);
  90. extern int soc_camera_device_register(struct soc_camera_device *icd);
  91. extern void soc_camera_device_unregister(struct soc_camera_device *icd);
  92. extern int soc_camera_video_start(struct soc_camera_device *icd);
  93. extern void soc_camera_video_stop(struct soc_camera_device *icd);
  94. struct soc_camera_data_format {
  95. char *name;
  96. unsigned int depth;
  97. __u32 fourcc;
  98. enum v4l2_colorspace colorspace;
  99. };
  100. struct soc_camera_ops {
  101. struct module *owner;
  102. int (*probe)(struct soc_camera_device *);
  103. void (*remove)(struct soc_camera_device *);
  104. int (*suspend)(struct soc_camera_device *, pm_message_t state);
  105. int (*resume)(struct soc_camera_device *);
  106. int (*init)(struct soc_camera_device *);
  107. int (*release)(struct soc_camera_device *);
  108. int (*start_capture)(struct soc_camera_device *);
  109. int (*stop_capture)(struct soc_camera_device *);
  110. int (*set_fmt_cap)(struct soc_camera_device *, __u32,
  111. struct v4l2_rect *);
  112. int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
  113. unsigned long (*query_bus_param)(struct soc_camera_device *);
  114. int (*set_bus_param)(struct soc_camera_device *, unsigned long);
  115. int (*get_chip_id)(struct soc_camera_device *,
  116. struct v4l2_chip_ident *);
  117. #ifdef CONFIG_VIDEO_ADV_DEBUG
  118. int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
  119. int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
  120. #endif
  121. int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
  122. int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
  123. const struct v4l2_queryctrl *controls;
  124. int num_controls;
  125. };
  126. static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
  127. struct soc_camera_ops *ops, int id)
  128. {
  129. int i;
  130. for (i = 0; i < ops->num_controls; i++)
  131. if (ops->controls[i].id == id)
  132. return &ops->controls[i];
  133. return NULL;
  134. }
  135. #define SOCAM_MASTER (1 << 0)
  136. #define SOCAM_SLAVE (1 << 1)
  137. #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
  138. #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
  139. #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
  140. #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
  141. #define SOCAM_DATAWIDTH_8 (1 << 6)
  142. #define SOCAM_DATAWIDTH_9 (1 << 7)
  143. #define SOCAM_DATAWIDTH_10 (1 << 8)
  144. #define SOCAM_DATAWIDTH_16 (1 << 9)
  145. #define SOCAM_PCLK_SAMPLE_RISING (1 << 10)
  146. #define SOCAM_PCLK_SAMPLE_FALLING (1 << 11)
  147. #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
  148. SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16)
  149. static inline unsigned long soc_camera_bus_param_compatible(
  150. unsigned long camera_flags, unsigned long bus_flags)
  151. {
  152. unsigned long common_flags, hsync, vsync, pclk;
  153. common_flags = camera_flags & bus_flags;
  154. hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
  155. vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
  156. pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
  157. return (!hsync || !vsync || !pclk) ? 0 : common_flags;
  158. }
  159. #endif