smiapp.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #include "smiapp-limits.h"
  50. struct smiapp_quirk;
  51. #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
  52. struct smiapp_module_ident {
  53. u8 manufacturer_id;
  54. u16 model_id;
  55. u8 revision_number_major;
  56. u8 flags;
  57. char *name;
  58. const struct smiapp_quirk *quirk;
  59. };
  60. struct smiapp_module_info {
  61. u32 manufacturer_id;
  62. u32 model_id;
  63. u32 revision_number_major;
  64. u32 revision_number_minor;
  65. u32 module_year;
  66. u32 module_month;
  67. u32 module_day;
  68. u32 sensor_manufacturer_id;
  69. u32 sensor_model_id;
  70. u32 sensor_revision_number;
  71. u32 sensor_firmware_version;
  72. u32 smia_version;
  73. u32 smiapp_version;
  74. u32 smiapp_profile;
  75. char *name;
  76. const struct smiapp_quirk *quirk;
  77. };
  78. #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
  79. { .manufacturer_id = manufacturer, \
  80. .model_id = model, \
  81. .revision_number_major = rev, \
  82. .flags = fl, \
  83. .name = _name, \
  84. .quirk = _quirk, }
  85. #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
  86. { .manufacturer_id = manufacturer, \
  87. .model_id = model, \
  88. .revision_number_major = rev, \
  89. .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
  90. .name = _name, \
  91. .quirk = _quirk, }
  92. #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
  93. { .manufacturer_id = manufacturer, \
  94. .model_id = model, \
  95. .revision_number_major = rev, \
  96. .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
  97. .name = _name, }
  98. #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
  99. { .manufacturer_id = manufacturer, \
  100. .model_id = model, \
  101. .revision_number_major = rev, \
  102. .flags = 0, \
  103. .name = _name, \
  104. .quirk = _quirk, }
  105. #define SMIAPP_IDENT(manufacturer, model, rev, _name) \
  106. { .manufacturer_id = manufacturer, \
  107. .model_id = model, \
  108. .revision_number_major = rev, \
  109. .flags = 0, \
  110. .name = _name, }
  111. struct smiapp_reg_limits {
  112. u32 addr;
  113. char *what;
  114. };
  115. extern struct smiapp_reg_limits smiapp_reg_limits[];
  116. struct smiapp_csi_data_format {
  117. u32 code;
  118. u8 width;
  119. u8 compressed;
  120. u8 pixel_order;
  121. };
  122. #define SMIAPP_SUBDEVS 3
  123. #define SMIAPP_PA_PAD_SRC 0
  124. #define SMIAPP_PAD_SINK 0
  125. #define SMIAPP_PAD_SRC 1
  126. #define SMIAPP_PADS 2
  127. struct smiapp_binning_subtype {
  128. u8 horizontal:4;
  129. u8 vertical:4;
  130. } __packed;
  131. struct smiapp_subdev {
  132. struct v4l2_subdev sd;
  133. struct media_pad pads[2];
  134. struct v4l2_rect sink_fmt;
  135. struct v4l2_rect crop[2];
  136. struct v4l2_rect compose; /* compose on sink */
  137. unsigned short sink_pad;
  138. unsigned short source_pad;
  139. int npads;
  140. struct smiapp_sensor *sensor;
  141. struct v4l2_ctrl_handler ctrl_handler;
  142. };
  143. /*
  144. * struct smiapp_sensor - Main device structure
  145. */
  146. struct smiapp_sensor {
  147. /*
  148. * "mutex" is used to serialise access to all fields here
  149. * except v4l2_ctrls at the end of the struct. "mutex" is also
  150. * used to serialise access to file handle specific
  151. * information. The exception to this rule is the power_mutex
  152. * below.
  153. */
  154. struct mutex mutex;
  155. /*
  156. * power_mutex is used to serialise power management related
  157. * activities. Acquiring "mutex" at that time isn't necessary
  158. * since there are no other users anyway.
  159. */
  160. struct mutex power_mutex;
  161. struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
  162. u32 ssds_used;
  163. struct smiapp_subdev *src;
  164. struct smiapp_subdev *binner;
  165. struct smiapp_subdev *scaler;
  166. struct smiapp_subdev *pixel_array;
  167. struct smiapp_platform_data *platform_data;
  168. struct regulator *vana;
  169. struct clk *ext_clk;
  170. u32 limits[SMIAPP_LIMIT_LAST];
  171. u8 nbinning_subtypes;
  172. struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
  173. u32 mbus_frame_fmts;
  174. const struct smiapp_csi_data_format *csi_format;
  175. const struct smiapp_csi_data_format *internal_csi_format;
  176. u32 default_mbus_frame_fmts;
  177. int default_pixel_order;
  178. u8 binning_horizontal;
  179. u8 binning_vertical;
  180. u8 scale_m;
  181. u8 scaling_mode;
  182. u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
  183. u8 flash_capability;
  184. u8 frame_skip;
  185. int power_count;
  186. bool streaming;
  187. bool dev_init_done;
  188. u8 *nvm; /* nvm memory buffer */
  189. unsigned int nvm_size; /* bytes */
  190. struct smiapp_module_info minfo;
  191. struct smiapp_pll pll;
  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. };
  204. #define to_smiapp_subdev(_sd) \
  205. container_of(_sd, struct smiapp_subdev, sd)
  206. #define to_smiapp_sensor(_sd) \
  207. (to_smiapp_subdev(_sd)->sensor)
  208. #endif /* __SMIAPP_PRIV_H_ */