soc_camera.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 buswidth; /* 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. const struct soc_camera_data_format *formats;
  39. int num_formats;
  40. struct module *owner;
  41. /* soc_camera.c private count. Only accessed with video_lock held */
  42. int use_count;
  43. };
  44. struct soc_camera_file {
  45. struct soc_camera_device *icd;
  46. struct videobuf_queue vb_vidq;
  47. spinlock_t *lock;
  48. };
  49. struct soc_camera_host {
  50. struct list_head list;
  51. struct device dev;
  52. unsigned char nr; /* Host number */
  53. size_t msize;
  54. struct videobuf_queue_ops *vbq_ops;
  55. void *priv;
  56. char *drv_name;
  57. struct soc_camera_host_ops *ops;
  58. };
  59. struct soc_camera_host_ops {
  60. struct module *owner;
  61. int (*add)(struct soc_camera_device *);
  62. void (*remove)(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. int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
  67. int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
  68. int (*try_bus_param)(struct soc_camera_device *, __u32);
  69. int (*set_bus_param)(struct soc_camera_device *, __u32);
  70. unsigned int (*poll)(struct file *, poll_table *);
  71. spinlock_t* (*spinlock_alloc)(struct soc_camera_file *);
  72. void (*spinlock_free)(spinlock_t *);
  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 (*init)(struct soc_camera_device *);
  105. int (*release)(struct soc_camera_device *);
  106. int (*start_capture)(struct soc_camera_device *);
  107. int (*stop_capture)(struct soc_camera_device *);
  108. int (*set_fmt_cap)(struct soc_camera_device *, __u32,
  109. struct v4l2_rect *);
  110. int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
  111. unsigned long (*query_bus_param)(struct soc_camera_device *);
  112. int (*set_bus_param)(struct soc_camera_device *, unsigned long);
  113. int (*get_chip_id)(struct soc_camera_device *,
  114. struct v4l2_chip_ident *);
  115. #ifdef CONFIG_VIDEO_ADV_DEBUG
  116. int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
  117. int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
  118. #endif
  119. int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
  120. int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
  121. const struct v4l2_queryctrl *controls;
  122. int num_controls;
  123. };
  124. static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
  125. struct soc_camera_ops *ops, int id)
  126. {
  127. int i;
  128. for (i = 0; i < ops->num_controls; i++)
  129. if (ops->controls[i].id == id)
  130. return &ops->controls[i];
  131. return NULL;
  132. }
  133. #define SOCAM_MASTER (1 << 0)
  134. #define SOCAM_SLAVE (1 << 1)
  135. #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
  136. #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
  137. #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
  138. #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
  139. #define SOCAM_DATAWIDTH_8 (1 << 6)
  140. #define SOCAM_DATAWIDTH_9 (1 << 7)
  141. #define SOCAM_DATAWIDTH_10 (1 << 8)
  142. #define SOCAM_PCLK_SAMPLE_RISING (1 << 9)
  143. #define SOCAM_PCLK_SAMPLE_FALLING (1 << 10)
  144. #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
  145. SOCAM_DATAWIDTH_10)
  146. static inline unsigned long soc_camera_bus_param_compatible(
  147. unsigned long camera_flags, unsigned long bus_flags)
  148. {
  149. unsigned long common_flags, hsync, vsync, pclk;
  150. common_flags = camera_flags & bus_flags;
  151. hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
  152. vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
  153. pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
  154. return (!hsync || !vsync || !pclk) ? 0 : common_flags;
  155. }
  156. #endif