smiapp.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/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. #define SMIAPP_COMPRESSED_BASE 8
  123. #define SMIAPP_COMPRESSED_MAX 12
  124. #define SMIAPP_NR_OF_COMPRESSED (SMIAPP_COMPRESSED_MAX - \
  125. SMIAPP_COMPRESSED_BASE + 1)
  126. struct smiapp_binning_subtype {
  127. u8 horizontal:4;
  128. u8 vertical:4;
  129. } __packed;
  130. struct smiapp_subdev {
  131. struct v4l2_subdev sd;
  132. struct media_pad pads[2];
  133. struct v4l2_rect sink_fmt;
  134. struct v4l2_rect crop[2];
  135. struct v4l2_rect compose; /* compose on sink */
  136. unsigned short sink_pad;
  137. unsigned short source_pad;
  138. int npads;
  139. struct smiapp_sensor *sensor;
  140. struct v4l2_ctrl_handler ctrl_handler;
  141. };
  142. /*
  143. * struct smiapp_sensor - Main device structure
  144. */
  145. struct smiapp_sensor {
  146. /*
  147. * "mutex" is used to serialise access to all fields here
  148. * except v4l2_ctrls at the end of the struct. "mutex" is also
  149. * used to serialise access to file handle specific
  150. * information. The exception to this rule is the power_mutex
  151. * below.
  152. */
  153. struct mutex mutex;
  154. /*
  155. * power_mutex is used to serialise power management related
  156. * activities. Acquiring "mutex" at that time isn't necessary
  157. * since there are no other users anyway.
  158. */
  159. struct mutex power_mutex;
  160. struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
  161. u32 ssds_used;
  162. struct smiapp_subdev *src;
  163. struct smiapp_subdev *binner;
  164. struct smiapp_subdev *scaler;
  165. struct smiapp_subdev *pixel_array;
  166. struct smiapp_platform_data *platform_data;
  167. struct regulator *vana;
  168. struct clk *ext_clk;
  169. u32 limits[SMIAPP_LIMIT_LAST];
  170. u8 nbinning_subtypes;
  171. struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
  172. u32 mbus_frame_fmts;
  173. const struct smiapp_csi_data_format *csi_format;
  174. const struct smiapp_csi_data_format *internal_csi_format;
  175. u32 default_mbus_frame_fmts;
  176. int default_pixel_order;
  177. u8 binning_horizontal;
  178. u8 binning_vertical;
  179. u8 scale_m;
  180. u8 scaling_mode;
  181. u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
  182. u8 frame_skip;
  183. int power_count;
  184. bool streaming;
  185. bool dev_init_done;
  186. u8 *nvm; /* nvm memory buffer */
  187. unsigned int nvm_size; /* bytes */
  188. struct smiapp_module_info minfo;
  189. struct smiapp_pll pll;
  190. /* Is a default format supported for a given BPP? */
  191. unsigned long valid_link_freqs[SMIAPP_NR_OF_COMPRESSED];
  192. /* Pixel array controls */
  193. struct v4l2_ctrl *analog_gain;
  194. struct v4l2_ctrl *exposure;
  195. struct v4l2_ctrl *hflip;
  196. struct v4l2_ctrl *vflip;
  197. struct v4l2_ctrl *vblank;
  198. struct v4l2_ctrl *hblank;
  199. struct v4l2_ctrl *pixel_rate_parray;
  200. /* src controls */
  201. struct v4l2_ctrl *link_freq;
  202. struct v4l2_ctrl *pixel_rate_csi;
  203. /* test pattern colour components */
  204. struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS];
  205. };
  206. #define to_smiapp_subdev(_sd) \
  207. container_of(_sd, struct smiapp_subdev, sd)
  208. #define to_smiapp_sensor(_sd) \
  209. (to_smiapp_subdev(_sd)->sensor)
  210. #endif /* __SMIAPP_PRIV_H_ */