smiapp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #ifndef __SMIAPP_PRIV_H_
  25. #define __SMIAPP_PRIV_H_
  26. #include <linux/mutex.h>
  27. #include <media/v4l2-ctrls.h>
  28. #include <media/v4l2-subdev.h>
  29. #include <media/smiapp.h>
  30. #include "smiapp-pll.h"
  31. #include "smiapp-reg.h"
  32. #include "smiapp-regs.h"
  33. #include "smiapp-quirk.h"
  34. /*
  35. * Standard SMIA++ constants
  36. */
  37. #define SMIA_VERSION_1 10
  38. #define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */
  39. #define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */
  40. #define SMIAPP_VERSION_1 10
  41. #define SMIAPP_PROFILE_0 0
  42. #define SMIAPP_PROFILE_1 1
  43. #define SMIAPP_PROFILE_2 2
  44. #define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */
  45. #define SMIAPP_RESET_DELAY_CLOCKS 2400
  46. #define SMIAPP_RESET_DELAY(clk) \
  47. (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
  48. + (clk) / 1000 - 1) / ((clk) / 1000))
  49. #define SMIAPP_COLOUR_COMPONENTS 4
  50. #include "smiapp-limits.h"
  51. struct smiapp_quirk;
  52. #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
  53. struct smiapp_module_ident {
  54. u8 manufacturer_id;
  55. u16 model_id;
  56. u8 revision_number_major;
  57. u8 flags;
  58. char *name;
  59. const struct smiapp_quirk *quirk;
  60. };
  61. struct smiapp_module_info {
  62. u32 manufacturer_id;
  63. u32 model_id;
  64. u32 revision_number_major;
  65. u32 revision_number_minor;
  66. u32 module_year;
  67. u32 module_month;
  68. u32 module_day;
  69. u32 sensor_manufacturer_id;
  70. u32 sensor_model_id;
  71. u32 sensor_revision_number;
  72. u32 sensor_firmware_version;
  73. u32 smia_version;
  74. u32 smiapp_version;
  75. u32 smiapp_profile;
  76. char *name;
  77. const struct smiapp_quirk *quirk;
  78. };
  79. #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
  80. { .manufacturer_id = manufacturer, \
  81. .model_id = model, \
  82. .revision_number_major = rev, \
  83. .flags = fl, \
  84. .name = _name, \
  85. .quirk = _quirk, }
  86. #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
  87. { .manufacturer_id = manufacturer, \
  88. .model_id = model, \
  89. .revision_number_major = rev, \
  90. .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
  91. .name = _name, \
  92. .quirk = _quirk, }
  93. #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
  94. { .manufacturer_id = manufacturer, \
  95. .model_id = model, \
  96. .revision_number_major = rev, \
  97. .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
  98. .name = _name, }
  99. #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
  100. { .manufacturer_id = manufacturer, \
  101. .model_id = model, \
  102. .revision_number_major = rev, \
  103. .flags = 0, \
  104. .name = _name, \
  105. .quirk = _quirk, }
  106. #define SMIAPP_IDENT(manufacturer, model, rev, _name) \
  107. { .manufacturer_id = manufacturer, \
  108. .model_id = model, \
  109. .revision_number_major = rev, \
  110. .flags = 0, \
  111. .name = _name, }
  112. struct smiapp_reg_limits {
  113. u32 addr;
  114. char *what;
  115. };
  116. extern struct smiapp_reg_limits smiapp_reg_limits[];
  117. struct smiapp_csi_data_format {
  118. u32 code;
  119. u8 width;
  120. u8 compressed;
  121. u8 pixel_order;
  122. };
  123. #define SMIAPP_SUBDEVS 3
  124. #define SMIAPP_PA_PAD_SRC 0
  125. #define SMIAPP_PAD_SINK 0
  126. #define SMIAPP_PAD_SRC 1
  127. #define SMIAPP_PADS 2
  128. #define SMIAPP_COMPRESSED_BASE 8
  129. #define SMIAPP_COMPRESSED_MAX 12
  130. #define SMIAPP_NR_OF_COMPRESSED (SMIAPP_COMPRESSED_MAX - \
  131. SMIAPP_COMPRESSED_BASE + 1)
  132. struct smiapp_binning_subtype {
  133. u8 horizontal:4;
  134. u8 vertical:4;
  135. } __packed;
  136. struct smiapp_subdev {
  137. struct v4l2_subdev sd;
  138. struct media_pad pads[2];
  139. struct v4l2_rect sink_fmt;
  140. struct v4l2_rect crop[2];
  141. struct v4l2_rect compose; /* compose on sink */
  142. unsigned short sink_pad;
  143. unsigned short source_pad;
  144. int npads;
  145. struct smiapp_sensor *sensor;
  146. struct v4l2_ctrl_handler ctrl_handler;
  147. };
  148. /*
  149. * struct smiapp_sensor - Main device structure
  150. */
  151. struct smiapp_sensor {
  152. /*
  153. * "mutex" is used to serialise access to all fields here
  154. * except v4l2_ctrls at the end of the struct. "mutex" is also
  155. * used to serialise access to file handle specific
  156. * information. The exception to this rule is the power_mutex
  157. * below.
  158. */
  159. struct mutex mutex;
  160. /*
  161. * power_mutex is used to serialise power management related
  162. * activities. Acquiring "mutex" at that time isn't necessary
  163. * since there are no other users anyway.
  164. */
  165. struct mutex power_mutex;
  166. struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
  167. u32 ssds_used;
  168. struct smiapp_subdev *src;
  169. struct smiapp_subdev *binner;
  170. struct smiapp_subdev *scaler;
  171. struct smiapp_subdev *pixel_array;
  172. struct smiapp_platform_data *platform_data;
  173. struct regulator *vana;
  174. struct clk *ext_clk;
  175. u32 limits[SMIAPP_LIMIT_LAST];
  176. u8 nbinning_subtypes;
  177. struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
  178. u32 mbus_frame_fmts;
  179. const struct smiapp_csi_data_format *csi_format;
  180. const struct smiapp_csi_data_format *internal_csi_format;
  181. u32 default_mbus_frame_fmts;
  182. int default_pixel_order;
  183. u8 binning_horizontal;
  184. u8 binning_vertical;
  185. u8 scale_m;
  186. u8 scaling_mode;
  187. u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
  188. u8 flash_capability;
  189. u8 frame_skip;
  190. int power_count;
  191. bool streaming;
  192. bool dev_init_done;
  193. u8 *nvm; /* nvm memory buffer */
  194. unsigned int nvm_size; /* bytes */
  195. struct smiapp_module_info minfo;
  196. struct smiapp_pll pll;
  197. /* Is a default format supported for a given BPP? */
  198. unsigned long valid_link_freqs[SMIAPP_NR_OF_COMPRESSED];
  199. /* Pixel array controls */
  200. struct v4l2_ctrl *analog_gain;
  201. struct v4l2_ctrl *exposure;
  202. struct v4l2_ctrl *hflip;
  203. struct v4l2_ctrl *vflip;
  204. struct v4l2_ctrl *vblank;
  205. struct v4l2_ctrl *hblank;
  206. struct v4l2_ctrl *pixel_rate_parray;
  207. /* src controls */
  208. struct v4l2_ctrl *link_freq;
  209. struct v4l2_ctrl *pixel_rate_csi;
  210. /* test pattern colour components */
  211. struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS];
  212. };
  213. #define to_smiapp_subdev(_sd) \
  214. container_of(_sd, struct smiapp_subdev, sd)
  215. #define to_smiapp_sensor(_sd) \
  216. (to_smiapp_subdev(_sd)->sensor)
  217. #endif /* __SMIAPP_PRIV_H_ */