smiapp.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * drivers/media/i2c/smiapp/smiapp.h
  3. *
  4. * Generic driver for SMIA/SMIA++ compliant camera modules
  5. *
  6. * Copyright (C) 2010--2012 Nokia Corporation
  7. * Contact: Sakari Ailus <sakari.ailus@iki.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #ifndef __SMIAPP_PRIV_H_
  19. #define __SMIAPP_PRIV_H_
  20. #include <linux/mutex.h>
  21. #include <media/v4l2-ctrls.h>
  22. #include <media/v4l2-subdev.h>
  23. #include <media/i2c/smiapp.h>
  24. #include "smiapp-pll.h"
  25. #include "smiapp-reg.h"
  26. #include "smiapp-regs.h"
  27. #include "smiapp-quirk.h"
  28. /*
  29. * Standard SMIA++ constants
  30. */
  31. #define SMIA_VERSION_1 10
  32. #define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */
  33. #define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */
  34. #define SMIAPP_VERSION_1 10
  35. #define SMIAPP_PROFILE_0 0
  36. #define SMIAPP_PROFILE_1 1
  37. #define SMIAPP_PROFILE_2 2
  38. #define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */
  39. #define SMIAPP_RESET_DELAY_CLOCKS 2400
  40. #define SMIAPP_RESET_DELAY(clk) \
  41. (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
  42. + (clk) / 1000 - 1) / ((clk) / 1000))
  43. #define SMIAPP_COLOUR_COMPONENTS 4
  44. #include "smiapp-limits.h"
  45. struct smiapp_quirk;
  46. #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
  47. struct smiapp_module_ident {
  48. u8 manufacturer_id;
  49. u16 model_id;
  50. u8 revision_number_major;
  51. u8 flags;
  52. char *name;
  53. const struct smiapp_quirk *quirk;
  54. };
  55. struct smiapp_module_info {
  56. u32 manufacturer_id;
  57. u32 model_id;
  58. u32 revision_number_major;
  59. u32 revision_number_minor;
  60. u32 module_year;
  61. u32 module_month;
  62. u32 module_day;
  63. u32 sensor_manufacturer_id;
  64. u32 sensor_model_id;
  65. u32 sensor_revision_number;
  66. u32 sensor_firmware_version;
  67. u32 smia_version;
  68. u32 smiapp_version;
  69. u32 smiapp_profile;
  70. char *name;
  71. const struct smiapp_quirk *quirk;
  72. };
  73. #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
  74. { .manufacturer_id = manufacturer, \
  75. .model_id = model, \
  76. .revision_number_major = rev, \
  77. .flags = fl, \
  78. .name = _name, \
  79. .quirk = _quirk, }
  80. #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
  81. { .manufacturer_id = manufacturer, \
  82. .model_id = model, \
  83. .revision_number_major = rev, \
  84. .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
  85. .name = _name, \
  86. .quirk = _quirk, }
  87. #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
  88. { .manufacturer_id = manufacturer, \
  89. .model_id = model, \
  90. .revision_number_major = rev, \
  91. .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
  92. .name = _name, }
  93. #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
  94. { .manufacturer_id = manufacturer, \
  95. .model_id = model, \
  96. .revision_number_major = rev, \
  97. .flags = 0, \
  98. .name = _name, \
  99. .quirk = _quirk, }
  100. #define SMIAPP_IDENT(manufacturer, model, rev, _name) \
  101. { .manufacturer_id = manufacturer, \
  102. .model_id = model, \
  103. .revision_number_major = rev, \
  104. .flags = 0, \
  105. .name = _name, }
  106. struct smiapp_reg_limits {
  107. u32 addr;
  108. char *what;
  109. };
  110. extern struct smiapp_reg_limits smiapp_reg_limits[];
  111. struct smiapp_csi_data_format {
  112. u32 code;
  113. u8 width;
  114. u8 compressed;
  115. u8 pixel_order;
  116. };
  117. #define SMIAPP_SUBDEVS 3
  118. #define SMIAPP_PA_PAD_SRC 0
  119. #define SMIAPP_PAD_SINK 0
  120. #define SMIAPP_PAD_SRC 1
  121. #define SMIAPP_PADS 2
  122. struct smiapp_binning_subtype {
  123. u8 horizontal:4;
  124. u8 vertical:4;
  125. } __packed;
  126. struct smiapp_subdev {
  127. struct v4l2_subdev sd;
  128. struct media_pad pads[SMIAPP_PADS];
  129. struct v4l2_rect sink_fmt;
  130. struct v4l2_rect crop[SMIAPP_PADS];
  131. struct v4l2_rect compose; /* compose on sink */
  132. unsigned short sink_pad;
  133. unsigned short source_pad;
  134. int npads;
  135. struct smiapp_sensor *sensor;
  136. struct v4l2_ctrl_handler ctrl_handler;
  137. };
  138. /*
  139. * struct smiapp_sensor - Main device structure
  140. */
  141. struct smiapp_sensor {
  142. /*
  143. * "mutex" is used to serialise access to all fields here
  144. * except v4l2_ctrls at the end of the struct. "mutex" is also
  145. * used to serialise access to file handle specific
  146. * information.
  147. */
  148. struct mutex mutex;
  149. struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
  150. u32 ssds_used;
  151. struct smiapp_subdev *src;
  152. struct smiapp_subdev *binner;
  153. struct smiapp_subdev *scaler;
  154. struct smiapp_subdev *pixel_array;
  155. struct smiapp_hwconfig *hwcfg;
  156. struct regulator *vana;
  157. struct clk *ext_clk;
  158. struct gpio_desc *xshutdown;
  159. u32 limits[SMIAPP_LIMIT_LAST];
  160. u8 nbinning_subtypes;
  161. struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
  162. u32 mbus_frame_fmts;
  163. const struct smiapp_csi_data_format *csi_format;
  164. const struct smiapp_csi_data_format *internal_csi_format;
  165. u32 default_mbus_frame_fmts;
  166. int default_pixel_order;
  167. u8 binning_horizontal;
  168. u8 binning_vertical;
  169. u8 scale_m;
  170. u8 scaling_mode;
  171. u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
  172. u8 frame_skip;
  173. u16 embedded_start; /* embedded data start line */
  174. u16 embedded_end;
  175. u16 image_start; /* image data start line */
  176. u16 visible_pixel_start; /* start pixel of the visible image */
  177. bool streaming;
  178. bool dev_init_done;
  179. u8 compressed_min_bpp;
  180. u8 *nvm; /* nvm memory buffer */
  181. unsigned int nvm_size; /* bytes */
  182. struct smiapp_module_info minfo;
  183. struct smiapp_pll pll;
  184. /* Is a default format supported for a given BPP? */
  185. unsigned long *valid_link_freqs;
  186. /* Pixel array controls */
  187. struct v4l2_ctrl *analog_gain;
  188. struct v4l2_ctrl *exposure;
  189. struct v4l2_ctrl *hflip;
  190. struct v4l2_ctrl *vflip;
  191. struct v4l2_ctrl *vblank;
  192. struct v4l2_ctrl *hblank;
  193. struct v4l2_ctrl *pixel_rate_parray;
  194. /* src controls */
  195. struct v4l2_ctrl *link_freq;
  196. struct v4l2_ctrl *pixel_rate_csi;
  197. /* test pattern colour components */
  198. struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS];
  199. };
  200. #define to_smiapp_subdev(_sd) \
  201. container_of(_sd, struct smiapp_subdev, sd)
  202. #define to_smiapp_sensor(_sd) \
  203. (to_smiapp_subdev(_sd)->sensor)
  204. #endif /* __SMIAPP_PRIV_H_ */