mt9m111.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. /*
  2. * Driver for MT9M111/MT9M112/MT9M131 CMOS Image Sensor from Micron/Aptina
  3. *
  4. * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/videodev2.h>
  11. #include <linux/slab.h>
  12. #include <linux/i2c.h>
  13. #include <linux/log2.h>
  14. #include <linux/gpio.h>
  15. #include <linux/delay.h>
  16. #include <linux/v4l2-mediabus.h>
  17. #include <linux/module.h>
  18. #include <media/soc_camera.h>
  19. #include <media/v4l2-common.h>
  20. #include <media/v4l2-ctrls.h>
  21. #include <media/v4l2-chip-ident.h>
  22. /*
  23. * MT9M111, MT9M112 and MT9M131:
  24. * i2c address is 0x48 or 0x5d (depending on SADDR pin)
  25. * The platform has to define i2c_board_info and call i2c_register_board_info()
  26. */
  27. /*
  28. * Sensor core register addresses (0x000..0x0ff)
  29. */
  30. #define MT9M111_CHIP_VERSION 0x000
  31. #define MT9M111_ROW_START 0x001
  32. #define MT9M111_COLUMN_START 0x002
  33. #define MT9M111_WINDOW_HEIGHT 0x003
  34. #define MT9M111_WINDOW_WIDTH 0x004
  35. #define MT9M111_HORIZONTAL_BLANKING_B 0x005
  36. #define MT9M111_VERTICAL_BLANKING_B 0x006
  37. #define MT9M111_HORIZONTAL_BLANKING_A 0x007
  38. #define MT9M111_VERTICAL_BLANKING_A 0x008
  39. #define MT9M111_SHUTTER_WIDTH 0x009
  40. #define MT9M111_ROW_SPEED 0x00a
  41. #define MT9M111_EXTRA_DELAY 0x00b
  42. #define MT9M111_SHUTTER_DELAY 0x00c
  43. #define MT9M111_RESET 0x00d
  44. #define MT9M111_READ_MODE_B 0x020
  45. #define MT9M111_READ_MODE_A 0x021
  46. #define MT9M111_FLASH_CONTROL 0x023
  47. #define MT9M111_GREEN1_GAIN 0x02b
  48. #define MT9M111_BLUE_GAIN 0x02c
  49. #define MT9M111_RED_GAIN 0x02d
  50. #define MT9M111_GREEN2_GAIN 0x02e
  51. #define MT9M111_GLOBAL_GAIN 0x02f
  52. #define MT9M111_CONTEXT_CONTROL 0x0c8
  53. #define MT9M111_PAGE_MAP 0x0f0
  54. #define MT9M111_BYTE_WISE_ADDR 0x0f1
  55. #define MT9M111_RESET_SYNC_CHANGES (1 << 15)
  56. #define MT9M111_RESET_RESTART_BAD_FRAME (1 << 9)
  57. #define MT9M111_RESET_SHOW_BAD_FRAMES (1 << 8)
  58. #define MT9M111_RESET_RESET_SOC (1 << 5)
  59. #define MT9M111_RESET_OUTPUT_DISABLE (1 << 4)
  60. #define MT9M111_RESET_CHIP_ENABLE (1 << 3)
  61. #define MT9M111_RESET_ANALOG_STANDBY (1 << 2)
  62. #define MT9M111_RESET_RESTART_FRAME (1 << 1)
  63. #define MT9M111_RESET_RESET_MODE (1 << 0)
  64. #define MT9M111_RM_FULL_POWER_RD (0 << 10)
  65. #define MT9M111_RM_LOW_POWER_RD (1 << 10)
  66. #define MT9M111_RM_COL_SKIP_4X (1 << 5)
  67. #define MT9M111_RM_ROW_SKIP_4X (1 << 4)
  68. #define MT9M111_RM_COL_SKIP_2X (1 << 3)
  69. #define MT9M111_RM_ROW_SKIP_2X (1 << 2)
  70. #define MT9M111_RMB_MIRROR_COLS (1 << 1)
  71. #define MT9M111_RMB_MIRROR_ROWS (1 << 0)
  72. #define MT9M111_CTXT_CTRL_RESTART (1 << 15)
  73. #define MT9M111_CTXT_CTRL_DEFECTCOR_B (1 << 12)
  74. #define MT9M111_CTXT_CTRL_RESIZE_B (1 << 10)
  75. #define MT9M111_CTXT_CTRL_CTRL2_B (1 << 9)
  76. #define MT9M111_CTXT_CTRL_GAMMA_B (1 << 8)
  77. #define MT9M111_CTXT_CTRL_XENON_EN (1 << 7)
  78. #define MT9M111_CTXT_CTRL_READ_MODE_B (1 << 3)
  79. #define MT9M111_CTXT_CTRL_LED_FLASH_EN (1 << 2)
  80. #define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1 << 1)
  81. #define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1 << 0)
  82. /*
  83. * Colorpipe register addresses (0x100..0x1ff)
  84. */
  85. #define MT9M111_OPER_MODE_CTRL 0x106
  86. #define MT9M111_OUTPUT_FORMAT_CTRL 0x108
  87. #define MT9M111_REDUCER_XZOOM_B 0x1a0
  88. #define MT9M111_REDUCER_XSIZE_B 0x1a1
  89. #define MT9M111_REDUCER_YZOOM_B 0x1a3
  90. #define MT9M111_REDUCER_YSIZE_B 0x1a4
  91. #define MT9M111_REDUCER_XZOOM_A 0x1a6
  92. #define MT9M111_REDUCER_XSIZE_A 0x1a7
  93. #define MT9M111_REDUCER_YZOOM_A 0x1a9
  94. #define MT9M111_REDUCER_YSIZE_A 0x1aa
  95. #define MT9M111_OUTPUT_FORMAT_CTRL2_A 0x13a
  96. #define MT9M111_OUTPUT_FORMAT_CTRL2_B 0x19b
  97. #define MT9M111_OPMODE_AUTOEXPO_EN (1 << 14)
  98. #define MT9M111_OPMODE_AUTOWHITEBAL_EN (1 << 1)
  99. #define MT9M111_OUTFMT_FLIP_BAYER_COL (1 << 9)
  100. #define MT9M111_OUTFMT_FLIP_BAYER_ROW (1 << 8)
  101. #define MT9M111_OUTFMT_PROCESSED_BAYER (1 << 14)
  102. #define MT9M111_OUTFMT_BYPASS_IFP (1 << 10)
  103. #define MT9M111_OUTFMT_INV_PIX_CLOCK (1 << 9)
  104. #define MT9M111_OUTFMT_RGB (1 << 8)
  105. #define MT9M111_OUTFMT_RGB565 (0 << 6)
  106. #define MT9M111_OUTFMT_RGB555 (1 << 6)
  107. #define MT9M111_OUTFMT_RGB444x (2 << 6)
  108. #define MT9M111_OUTFMT_RGBx444 (3 << 6)
  109. #define MT9M111_OUTFMT_TST_RAMP_OFF (0 << 4)
  110. #define MT9M111_OUTFMT_TST_RAMP_COL (1 << 4)
  111. #define MT9M111_OUTFMT_TST_RAMP_ROW (2 << 4)
  112. #define MT9M111_OUTFMT_TST_RAMP_FRAME (3 << 4)
  113. #define MT9M111_OUTFMT_SHIFT_3_UP (1 << 3)
  114. #define MT9M111_OUTFMT_AVG_CHROMA (1 << 2)
  115. #define MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN (1 << 1)
  116. #define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr_RGB_R_B (1 << 0)
  117. /*
  118. * Camera control register addresses (0x200..0x2ff not implemented)
  119. */
  120. #define reg_read(reg) mt9m111_reg_read(client, MT9M111_##reg)
  121. #define reg_write(reg, val) mt9m111_reg_write(client, MT9M111_##reg, (val))
  122. #define reg_set(reg, val) mt9m111_reg_set(client, MT9M111_##reg, (val))
  123. #define reg_clear(reg, val) mt9m111_reg_clear(client, MT9M111_##reg, (val))
  124. #define reg_mask(reg, val, mask) mt9m111_reg_mask(client, MT9M111_##reg, \
  125. (val), (mask))
  126. #define MT9M111_MIN_DARK_ROWS 8
  127. #define MT9M111_MIN_DARK_COLS 26
  128. #define MT9M111_MAX_HEIGHT 1024
  129. #define MT9M111_MAX_WIDTH 1280
  130. struct mt9m111_context {
  131. u16 read_mode;
  132. u16 blanking_h;
  133. u16 blanking_v;
  134. u16 reducer_xzoom;
  135. u16 reducer_yzoom;
  136. u16 reducer_xsize;
  137. u16 reducer_ysize;
  138. u16 output_fmt_ctrl2;
  139. u16 control;
  140. };
  141. static struct mt9m111_context context_a = {
  142. .read_mode = MT9M111_READ_MODE_A,
  143. .blanking_h = MT9M111_HORIZONTAL_BLANKING_A,
  144. .blanking_v = MT9M111_VERTICAL_BLANKING_A,
  145. .reducer_xzoom = MT9M111_REDUCER_XZOOM_A,
  146. .reducer_yzoom = MT9M111_REDUCER_YZOOM_A,
  147. .reducer_xsize = MT9M111_REDUCER_XSIZE_A,
  148. .reducer_ysize = MT9M111_REDUCER_YSIZE_A,
  149. .output_fmt_ctrl2 = MT9M111_OUTPUT_FORMAT_CTRL2_A,
  150. .control = MT9M111_CTXT_CTRL_RESTART,
  151. };
  152. static struct mt9m111_context context_b = {
  153. .read_mode = MT9M111_READ_MODE_B,
  154. .blanking_h = MT9M111_HORIZONTAL_BLANKING_B,
  155. .blanking_v = MT9M111_VERTICAL_BLANKING_B,
  156. .reducer_xzoom = MT9M111_REDUCER_XZOOM_B,
  157. .reducer_yzoom = MT9M111_REDUCER_YZOOM_B,
  158. .reducer_xsize = MT9M111_REDUCER_XSIZE_B,
  159. .reducer_ysize = MT9M111_REDUCER_YSIZE_B,
  160. .output_fmt_ctrl2 = MT9M111_OUTPUT_FORMAT_CTRL2_B,
  161. .control = MT9M111_CTXT_CTRL_RESTART |
  162. MT9M111_CTXT_CTRL_DEFECTCOR_B | MT9M111_CTXT_CTRL_RESIZE_B |
  163. MT9M111_CTXT_CTRL_CTRL2_B | MT9M111_CTXT_CTRL_GAMMA_B |
  164. MT9M111_CTXT_CTRL_READ_MODE_B | MT9M111_CTXT_CTRL_VBLANK_SEL_B |
  165. MT9M111_CTXT_CTRL_HBLANK_SEL_B,
  166. };
  167. /* MT9M111 has only one fixed colorspace per pixelcode */
  168. struct mt9m111_datafmt {
  169. enum v4l2_mbus_pixelcode code;
  170. enum v4l2_colorspace colorspace;
  171. };
  172. static const struct mt9m111_datafmt mt9m111_colour_fmts[] = {
  173. {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG},
  174. {V4L2_MBUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG},
  175. {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
  176. {V4L2_MBUS_FMT_VYUY8_2X8, V4L2_COLORSPACE_JPEG},
  177. {V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
  178. {V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, V4L2_COLORSPACE_SRGB},
  179. {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB},
  180. {V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB},
  181. {V4L2_MBUS_FMT_BGR565_2X8_LE, V4L2_COLORSPACE_SRGB},
  182. {V4L2_MBUS_FMT_BGR565_2X8_BE, V4L2_COLORSPACE_SRGB},
  183. {V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB},
  184. {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
  185. };
  186. struct mt9m111 {
  187. struct v4l2_subdev subdev;
  188. struct v4l2_ctrl_handler hdl;
  189. struct v4l2_ctrl *gain;
  190. int model; /* V4L2_IDENT_MT9M111 or V4L2_IDENT_MT9M112 code
  191. * from v4l2-chip-ident.h */
  192. struct mt9m111_context *ctx;
  193. struct v4l2_rect rect; /* cropping rectangle */
  194. int width; /* output */
  195. int height; /* sizes */
  196. struct mutex power_lock; /* lock to protect power_count */
  197. int power_count;
  198. const struct mt9m111_datafmt *fmt;
  199. int lastpage; /* PageMap cache value */
  200. };
  201. /* Find a data format by a pixel code */
  202. static const struct mt9m111_datafmt *mt9m111_find_datafmt(struct mt9m111 *mt9m111,
  203. enum v4l2_mbus_pixelcode code)
  204. {
  205. int i;
  206. for (i = 0; i < ARRAY_SIZE(mt9m111_colour_fmts); i++)
  207. if (mt9m111_colour_fmts[i].code == code)
  208. return mt9m111_colour_fmts + i;
  209. return mt9m111->fmt;
  210. }
  211. static struct mt9m111 *to_mt9m111(const struct i2c_client *client)
  212. {
  213. return container_of(i2c_get_clientdata(client), struct mt9m111, subdev);
  214. }
  215. static int reg_page_map_set(struct i2c_client *client, const u16 reg)
  216. {
  217. int ret;
  218. u16 page;
  219. struct mt9m111 *mt9m111 = to_mt9m111(client);
  220. page = (reg >> 8);
  221. if (page == mt9m111->lastpage)
  222. return 0;
  223. if (page > 2)
  224. return -EINVAL;
  225. ret = i2c_smbus_write_word_swapped(client, MT9M111_PAGE_MAP, page);
  226. if (!ret)
  227. mt9m111->lastpage = page;
  228. return ret;
  229. }
  230. static int mt9m111_reg_read(struct i2c_client *client, const u16 reg)
  231. {
  232. int ret;
  233. ret = reg_page_map_set(client, reg);
  234. if (!ret)
  235. ret = i2c_smbus_read_word_swapped(client, reg & 0xff);
  236. dev_dbg(&client->dev, "read reg.%03x -> %04x\n", reg, ret);
  237. return ret;
  238. }
  239. static int mt9m111_reg_write(struct i2c_client *client, const u16 reg,
  240. const u16 data)
  241. {
  242. int ret;
  243. ret = reg_page_map_set(client, reg);
  244. if (!ret)
  245. ret = i2c_smbus_write_word_swapped(client, reg & 0xff, data);
  246. dev_dbg(&client->dev, "write reg.%03x = %04x -> %d\n", reg, data, ret);
  247. return ret;
  248. }
  249. static int mt9m111_reg_set(struct i2c_client *client, const u16 reg,
  250. const u16 data)
  251. {
  252. int ret;
  253. ret = mt9m111_reg_read(client, reg);
  254. if (ret >= 0)
  255. ret = mt9m111_reg_write(client, reg, ret | data);
  256. return ret;
  257. }
  258. static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg,
  259. const u16 data)
  260. {
  261. int ret;
  262. ret = mt9m111_reg_read(client, reg);
  263. if (ret >= 0)
  264. ret = mt9m111_reg_write(client, reg, ret & ~data);
  265. return ret;
  266. }
  267. static int mt9m111_reg_mask(struct i2c_client *client, const u16 reg,
  268. const u16 data, const u16 mask)
  269. {
  270. int ret;
  271. ret = mt9m111_reg_read(client, reg);
  272. if (ret >= 0)
  273. ret = mt9m111_reg_write(client, reg, (ret & ~mask) | data);
  274. return ret;
  275. }
  276. static int mt9m111_set_context(struct mt9m111 *mt9m111,
  277. struct mt9m111_context *ctx)
  278. {
  279. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  280. return reg_write(CONTEXT_CONTROL, ctx->control);
  281. }
  282. static int mt9m111_setup_rect_ctx(struct mt9m111 *mt9m111,
  283. struct mt9m111_context *ctx, struct v4l2_rect *rect,
  284. unsigned int width, unsigned int height)
  285. {
  286. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  287. int ret = mt9m111_reg_write(client, ctx->reducer_xzoom, rect->width);
  288. if (!ret)
  289. ret = mt9m111_reg_write(client, ctx->reducer_yzoom, rect->height);
  290. if (!ret)
  291. ret = mt9m111_reg_write(client, ctx->reducer_xsize, width);
  292. if (!ret)
  293. ret = mt9m111_reg_write(client, ctx->reducer_ysize, height);
  294. return ret;
  295. }
  296. static int mt9m111_setup_geometry(struct mt9m111 *mt9m111, struct v4l2_rect *rect,
  297. int width, int height, enum v4l2_mbus_pixelcode code)
  298. {
  299. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  300. int ret;
  301. ret = reg_write(COLUMN_START, rect->left);
  302. if (!ret)
  303. ret = reg_write(ROW_START, rect->top);
  304. if (!ret)
  305. ret = reg_write(WINDOW_WIDTH, rect->width);
  306. if (!ret)
  307. ret = reg_write(WINDOW_HEIGHT, rect->height);
  308. if (code != V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) {
  309. /* IFP in use, down-scaling possible */
  310. if (!ret)
  311. ret = mt9m111_setup_rect_ctx(mt9m111, &context_b,
  312. rect, width, height);
  313. if (!ret)
  314. ret = mt9m111_setup_rect_ctx(mt9m111, &context_a,
  315. rect, width, height);
  316. }
  317. dev_dbg(&client->dev, "%s(%x): %ux%u@%u:%u -> %ux%u = %d\n",
  318. __func__, code, rect->width, rect->height, rect->left, rect->top,
  319. width, height, ret);
  320. return ret;
  321. }
  322. static int mt9m111_enable(struct mt9m111 *mt9m111)
  323. {
  324. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  325. return reg_write(RESET, MT9M111_RESET_CHIP_ENABLE);
  326. }
  327. static int mt9m111_reset(struct mt9m111 *mt9m111)
  328. {
  329. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  330. int ret;
  331. ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
  332. if (!ret)
  333. ret = reg_set(RESET, MT9M111_RESET_RESET_SOC);
  334. if (!ret)
  335. ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE
  336. | MT9M111_RESET_RESET_SOC);
  337. return ret;
  338. }
  339. static int mt9m111_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
  340. {
  341. struct v4l2_rect rect = a->c;
  342. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  343. int width, height;
  344. int ret;
  345. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  346. return -EINVAL;
  347. if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 ||
  348. mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) {
  349. /* Bayer format - even size lengths */
  350. rect.width = ALIGN(rect.width, 2);
  351. rect.height = ALIGN(rect.height, 2);
  352. /* Let the user play with the starting pixel */
  353. }
  354. /* FIXME: the datasheet doesn't specify minimum sizes */
  355. soc_camera_limit_side(&rect.left, &rect.width,
  356. MT9M111_MIN_DARK_COLS, 2, MT9M111_MAX_WIDTH);
  357. soc_camera_limit_side(&rect.top, &rect.height,
  358. MT9M111_MIN_DARK_ROWS, 2, MT9M111_MAX_HEIGHT);
  359. width = min(mt9m111->width, rect.width);
  360. height = min(mt9m111->height, rect.height);
  361. ret = mt9m111_setup_geometry(mt9m111, &rect, width, height, mt9m111->fmt->code);
  362. if (!ret) {
  363. mt9m111->rect = rect;
  364. mt9m111->width = width;
  365. mt9m111->height = height;
  366. }
  367. return ret;
  368. }
  369. static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
  370. {
  371. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  372. a->c = mt9m111->rect;
  373. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  374. return 0;
  375. }
  376. static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
  377. {
  378. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  379. return -EINVAL;
  380. a->bounds.left = MT9M111_MIN_DARK_COLS;
  381. a->bounds.top = MT9M111_MIN_DARK_ROWS;
  382. a->bounds.width = MT9M111_MAX_WIDTH;
  383. a->bounds.height = MT9M111_MAX_HEIGHT;
  384. a->defrect = a->bounds;
  385. a->pixelaspect.numerator = 1;
  386. a->pixelaspect.denominator = 1;
  387. return 0;
  388. }
  389. static int mt9m111_g_fmt(struct v4l2_subdev *sd,
  390. struct v4l2_mbus_framefmt *mf)
  391. {
  392. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  393. mf->width = mt9m111->width;
  394. mf->height = mt9m111->height;
  395. mf->code = mt9m111->fmt->code;
  396. mf->colorspace = mt9m111->fmt->colorspace;
  397. mf->field = V4L2_FIELD_NONE;
  398. return 0;
  399. }
  400. static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111,
  401. enum v4l2_mbus_pixelcode code)
  402. {
  403. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  404. u16 data_outfmt2, mask_outfmt2 = MT9M111_OUTFMT_PROCESSED_BAYER |
  405. MT9M111_OUTFMT_BYPASS_IFP | MT9M111_OUTFMT_RGB |
  406. MT9M111_OUTFMT_RGB565 | MT9M111_OUTFMT_RGB555 |
  407. MT9M111_OUTFMT_RGB444x | MT9M111_OUTFMT_RGBx444 |
  408. MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN |
  409. MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr_RGB_R_B;
  410. int ret;
  411. switch (code) {
  412. case V4L2_MBUS_FMT_SBGGR8_1X8:
  413. data_outfmt2 = MT9M111_OUTFMT_PROCESSED_BAYER |
  414. MT9M111_OUTFMT_RGB;
  415. break;
  416. case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE:
  417. data_outfmt2 = MT9M111_OUTFMT_BYPASS_IFP | MT9M111_OUTFMT_RGB;
  418. break;
  419. case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE:
  420. data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555 |
  421. MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN;
  422. break;
  423. case V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE:
  424. data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
  425. break;
  426. case V4L2_MBUS_FMT_RGB565_2X8_LE:
  427. data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565 |
  428. MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN;
  429. break;
  430. case V4L2_MBUS_FMT_RGB565_2X8_BE:
  431. data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
  432. break;
  433. case V4L2_MBUS_FMT_BGR565_2X8_BE:
  434. data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565 |
  435. MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr_RGB_R_B;
  436. break;
  437. case V4L2_MBUS_FMT_BGR565_2X8_LE:
  438. data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565 |
  439. MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN |
  440. MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr_RGB_R_B;
  441. break;
  442. case V4L2_MBUS_FMT_UYVY8_2X8:
  443. data_outfmt2 = 0;
  444. break;
  445. case V4L2_MBUS_FMT_VYUY8_2X8:
  446. data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr_RGB_R_B;
  447. break;
  448. case V4L2_MBUS_FMT_YUYV8_2X8:
  449. data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN;
  450. break;
  451. case V4L2_MBUS_FMT_YVYU8_2X8:
  452. data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_C_Y_RGB_EVEN |
  453. MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr_RGB_R_B;
  454. break;
  455. default:
  456. dev_err(&client->dev, "Pixel format not handled: %x\n", code);
  457. return -EINVAL;
  458. }
  459. ret = mt9m111_reg_mask(client, context_a.output_fmt_ctrl2,
  460. data_outfmt2, mask_outfmt2);
  461. if (!ret)
  462. ret = mt9m111_reg_mask(client, context_b.output_fmt_ctrl2,
  463. data_outfmt2, mask_outfmt2);
  464. return ret;
  465. }
  466. static int mt9m111_try_fmt(struct v4l2_subdev *sd,
  467. struct v4l2_mbus_framefmt *mf)
  468. {
  469. struct i2c_client *client = v4l2_get_subdevdata(sd);
  470. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  471. const struct mt9m111_datafmt *fmt;
  472. struct v4l2_rect *rect = &mt9m111->rect;
  473. bool bayer;
  474. fmt = mt9m111_find_datafmt(mt9m111, mf->code);
  475. bayer = fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 ||
  476. fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE;
  477. /*
  478. * With Bayer format enforce even side lengths, but let the user play
  479. * with the starting pixel
  480. */
  481. if (bayer) {
  482. rect->width = ALIGN(rect->width, 2);
  483. rect->height = ALIGN(rect->height, 2);
  484. }
  485. if (fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) {
  486. /* IFP bypass mode, no scaling */
  487. mf->width = rect->width;
  488. mf->height = rect->height;
  489. } else {
  490. /* No upscaling */
  491. if (mf->width > rect->width)
  492. mf->width = rect->width;
  493. if (mf->height > rect->height)
  494. mf->height = rect->height;
  495. }
  496. dev_dbg(&client->dev, "%s(): %ux%u, code=%x\n", __func__,
  497. mf->width, mf->height, fmt->code);
  498. mf->code = fmt->code;
  499. mf->colorspace = fmt->colorspace;
  500. return 0;
  501. }
  502. static int mt9m111_s_fmt(struct v4l2_subdev *sd,
  503. struct v4l2_mbus_framefmt *mf)
  504. {
  505. const struct mt9m111_datafmt *fmt;
  506. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  507. struct v4l2_rect *rect = &mt9m111->rect;
  508. int ret;
  509. mt9m111_try_fmt(sd, mf);
  510. fmt = mt9m111_find_datafmt(mt9m111, mf->code);
  511. /* try_fmt() guarantees fmt != NULL && fmt->code == mf->code */
  512. ret = mt9m111_setup_geometry(mt9m111, rect, mf->width, mf->height, mf->code);
  513. if (!ret)
  514. ret = mt9m111_set_pixfmt(mt9m111, mf->code);
  515. if (!ret) {
  516. mt9m111->width = mf->width;
  517. mt9m111->height = mf->height;
  518. mt9m111->fmt = fmt;
  519. }
  520. return ret;
  521. }
  522. static int mt9m111_g_chip_ident(struct v4l2_subdev *sd,
  523. struct v4l2_dbg_chip_ident *id)
  524. {
  525. struct i2c_client *client = v4l2_get_subdevdata(sd);
  526. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  527. if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
  528. return -EINVAL;
  529. if (id->match.addr != client->addr)
  530. return -ENODEV;
  531. id->ident = mt9m111->model;
  532. id->revision = 0;
  533. return 0;
  534. }
  535. #ifdef CONFIG_VIDEO_ADV_DEBUG
  536. static int mt9m111_g_register(struct v4l2_subdev *sd,
  537. struct v4l2_dbg_register *reg)
  538. {
  539. struct i2c_client *client = v4l2_get_subdevdata(sd);
  540. int val;
  541. if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
  542. return -EINVAL;
  543. if (reg->match.addr != client->addr)
  544. return -ENODEV;
  545. val = mt9m111_reg_read(client, reg->reg);
  546. reg->size = 2;
  547. reg->val = (u64)val;
  548. if (reg->val > 0xffff)
  549. return -EIO;
  550. return 0;
  551. }
  552. static int mt9m111_s_register(struct v4l2_subdev *sd,
  553. struct v4l2_dbg_register *reg)
  554. {
  555. struct i2c_client *client = v4l2_get_subdevdata(sd);
  556. if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
  557. return -EINVAL;
  558. if (reg->match.addr != client->addr)
  559. return -ENODEV;
  560. if (mt9m111_reg_write(client, reg->reg, reg->val) < 0)
  561. return -EIO;
  562. return 0;
  563. }
  564. #endif
  565. static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask)
  566. {
  567. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  568. int ret;
  569. if (flip)
  570. ret = mt9m111_reg_set(client, mt9m111->ctx->read_mode, mask);
  571. else
  572. ret = mt9m111_reg_clear(client, mt9m111->ctx->read_mode, mask);
  573. return ret;
  574. }
  575. static int mt9m111_get_global_gain(struct mt9m111 *mt9m111)
  576. {
  577. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  578. int data;
  579. data = reg_read(GLOBAL_GAIN);
  580. if (data >= 0)
  581. return (data & 0x2f) * (1 << ((data >> 10) & 1)) *
  582. (1 << ((data >> 9) & 1));
  583. return data;
  584. }
  585. static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
  586. {
  587. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  588. u16 val;
  589. if (gain > 63 * 2 * 2)
  590. return -EINVAL;
  591. if ((gain >= 64 * 2) && (gain < 63 * 2 * 2))
  592. val = (1 << 10) | (1 << 9) | (gain / 4);
  593. else if ((gain >= 64) && (gain < 64 * 2))
  594. val = (1 << 9) | (gain / 2);
  595. else
  596. val = gain;
  597. return reg_write(GLOBAL_GAIN, val);
  598. }
  599. static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on)
  600. {
  601. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  602. if (on)
  603. return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
  604. return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
  605. }
  606. static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on)
  607. {
  608. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  609. if (on)
  610. return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
  611. return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
  612. }
  613. static int mt9m111_s_ctrl(struct v4l2_ctrl *ctrl)
  614. {
  615. struct mt9m111 *mt9m111 = container_of(ctrl->handler,
  616. struct mt9m111, hdl);
  617. switch (ctrl->id) {
  618. case V4L2_CID_VFLIP:
  619. return mt9m111_set_flip(mt9m111, ctrl->val,
  620. MT9M111_RMB_MIRROR_ROWS);
  621. case V4L2_CID_HFLIP:
  622. return mt9m111_set_flip(mt9m111, ctrl->val,
  623. MT9M111_RMB_MIRROR_COLS);
  624. case V4L2_CID_GAIN:
  625. return mt9m111_set_global_gain(mt9m111, ctrl->val);
  626. case V4L2_CID_EXPOSURE_AUTO:
  627. return mt9m111_set_autoexposure(mt9m111, ctrl->val);
  628. case V4L2_CID_AUTO_WHITE_BALANCE:
  629. return mt9m111_set_autowhitebalance(mt9m111, ctrl->val);
  630. }
  631. return -EINVAL;
  632. }
  633. static int mt9m111_suspend(struct mt9m111 *mt9m111)
  634. {
  635. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  636. int ret;
  637. v4l2_ctrl_s_ctrl(mt9m111->gain, mt9m111_get_global_gain(mt9m111));
  638. ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
  639. if (!ret)
  640. ret = reg_set(RESET, MT9M111_RESET_RESET_SOC |
  641. MT9M111_RESET_OUTPUT_DISABLE |
  642. MT9M111_RESET_ANALOG_STANDBY);
  643. if (!ret)
  644. ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE);
  645. return ret;
  646. }
  647. static void mt9m111_restore_state(struct mt9m111 *mt9m111)
  648. {
  649. mt9m111_set_context(mt9m111, mt9m111->ctx);
  650. mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code);
  651. mt9m111_setup_geometry(mt9m111, &mt9m111->rect,
  652. mt9m111->width, mt9m111->height, mt9m111->fmt->code);
  653. v4l2_ctrl_handler_setup(&mt9m111->hdl);
  654. }
  655. static int mt9m111_resume(struct mt9m111 *mt9m111)
  656. {
  657. int ret = mt9m111_enable(mt9m111);
  658. if (!ret)
  659. ret = mt9m111_reset(mt9m111);
  660. if (!ret)
  661. mt9m111_restore_state(mt9m111);
  662. return ret;
  663. }
  664. static int mt9m111_init(struct mt9m111 *mt9m111)
  665. {
  666. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  667. int ret;
  668. /* Default HIGHPOWER context */
  669. mt9m111->ctx = &context_b;
  670. ret = mt9m111_enable(mt9m111);
  671. if (!ret)
  672. ret = mt9m111_reset(mt9m111);
  673. if (!ret)
  674. ret = mt9m111_set_context(mt9m111, mt9m111->ctx);
  675. if (ret)
  676. dev_err(&client->dev, "mt9m111 init failed: %d\n", ret);
  677. return ret;
  678. }
  679. static int mt9m111_power_on(struct mt9m111 *mt9m111)
  680. {
  681. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  682. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  683. int ret;
  684. ret = soc_camera_power_on(&client->dev, icl);
  685. if (ret < 0)
  686. return ret;
  687. ret = mt9m111_resume(mt9m111);
  688. if (ret < 0) {
  689. dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret);
  690. soc_camera_power_off(&client->dev, icl);
  691. }
  692. return ret;
  693. }
  694. static void mt9m111_power_off(struct mt9m111 *mt9m111)
  695. {
  696. struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
  697. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  698. mt9m111_suspend(mt9m111);
  699. soc_camera_power_off(&client->dev, icl);
  700. }
  701. static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
  702. {
  703. struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
  704. int ret = 0;
  705. mutex_lock(&mt9m111->power_lock);
  706. /*
  707. * If the power count is modified from 0 to != 0 or from != 0 to 0,
  708. * update the power state.
  709. */
  710. if (mt9m111->power_count == !on) {
  711. if (on)
  712. ret = mt9m111_power_on(mt9m111);
  713. else
  714. mt9m111_power_off(mt9m111);
  715. }
  716. if (!ret) {
  717. /* Update the power count. */
  718. mt9m111->power_count += on ? 1 : -1;
  719. WARN_ON(mt9m111->power_count < 0);
  720. }
  721. mutex_unlock(&mt9m111->power_lock);
  722. return ret;
  723. }
  724. static const struct v4l2_ctrl_ops mt9m111_ctrl_ops = {
  725. .s_ctrl = mt9m111_s_ctrl,
  726. };
  727. static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = {
  728. .g_chip_ident = mt9m111_g_chip_ident,
  729. .s_power = mt9m111_s_power,
  730. #ifdef CONFIG_VIDEO_ADV_DEBUG
  731. .g_register = mt9m111_g_register,
  732. .s_register = mt9m111_s_register,
  733. #endif
  734. };
  735. static int mt9m111_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
  736. enum v4l2_mbus_pixelcode *code)
  737. {
  738. if (index >= ARRAY_SIZE(mt9m111_colour_fmts))
  739. return -EINVAL;
  740. *code = mt9m111_colour_fmts[index].code;
  741. return 0;
  742. }
  743. static int mt9m111_g_mbus_config(struct v4l2_subdev *sd,
  744. struct v4l2_mbus_config *cfg)
  745. {
  746. struct i2c_client *client = v4l2_get_subdevdata(sd);
  747. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  748. cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
  749. V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
  750. V4L2_MBUS_DATA_ACTIVE_HIGH;
  751. cfg->type = V4L2_MBUS_PARALLEL;
  752. cfg->flags = soc_camera_apply_board_flags(icl, cfg);
  753. return 0;
  754. }
  755. static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = {
  756. .s_mbus_fmt = mt9m111_s_fmt,
  757. .g_mbus_fmt = mt9m111_g_fmt,
  758. .try_mbus_fmt = mt9m111_try_fmt,
  759. .s_crop = mt9m111_s_crop,
  760. .g_crop = mt9m111_g_crop,
  761. .cropcap = mt9m111_cropcap,
  762. .enum_mbus_fmt = mt9m111_enum_fmt,
  763. .g_mbus_config = mt9m111_g_mbus_config,
  764. };
  765. static struct v4l2_subdev_ops mt9m111_subdev_ops = {
  766. .core = &mt9m111_subdev_core_ops,
  767. .video = &mt9m111_subdev_video_ops,
  768. };
  769. /*
  770. * Interface active, can use i2c. If it fails, it can indeed mean, that
  771. * this wasn't our capture interface, so, we wait for the right one
  772. */
  773. static int mt9m111_video_probe(struct i2c_client *client)
  774. {
  775. struct mt9m111 *mt9m111 = to_mt9m111(client);
  776. s32 data;
  777. int ret;
  778. ret = mt9m111_s_power(&mt9m111->subdev, 1);
  779. if (ret < 0)
  780. return ret;
  781. data = reg_read(CHIP_VERSION);
  782. switch (data) {
  783. case 0x143a: /* MT9M111 or MT9M131 */
  784. mt9m111->model = V4L2_IDENT_MT9M111;
  785. dev_info(&client->dev,
  786. "Detected a MT9M111/MT9M131 chip ID %x\n", data);
  787. break;
  788. case 0x148c: /* MT9M112 */
  789. mt9m111->model = V4L2_IDENT_MT9M112;
  790. dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data);
  791. break;
  792. default:
  793. dev_err(&client->dev,
  794. "No MT9M111/MT9M112/MT9M131 chip detected register read %x\n",
  795. data);
  796. ret = -ENODEV;
  797. goto done;
  798. }
  799. ret = mt9m111_init(mt9m111);
  800. if (ret)
  801. goto done;
  802. ret = v4l2_ctrl_handler_setup(&mt9m111->hdl);
  803. done:
  804. mt9m111_s_power(&mt9m111->subdev, 0);
  805. return ret;
  806. }
  807. static int mt9m111_probe(struct i2c_client *client,
  808. const struct i2c_device_id *did)
  809. {
  810. struct mt9m111 *mt9m111;
  811. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  812. struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
  813. int ret;
  814. if (!icl) {
  815. dev_err(&client->dev, "mt9m111: driver needs platform data\n");
  816. return -EINVAL;
  817. }
  818. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
  819. dev_warn(&adapter->dev,
  820. "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
  821. return -EIO;
  822. }
  823. mt9m111 = kzalloc(sizeof(struct mt9m111), GFP_KERNEL);
  824. if (!mt9m111)
  825. return -ENOMEM;
  826. v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops);
  827. v4l2_ctrl_handler_init(&mt9m111->hdl, 5);
  828. v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
  829. V4L2_CID_VFLIP, 0, 1, 1, 0);
  830. v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
  831. V4L2_CID_HFLIP, 0, 1, 1, 0);
  832. v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
  833. V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
  834. mt9m111->gain = v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
  835. V4L2_CID_GAIN, 0, 63 * 2 * 2, 1, 32);
  836. v4l2_ctrl_new_std_menu(&mt9m111->hdl,
  837. &mt9m111_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
  838. V4L2_EXPOSURE_AUTO);
  839. mt9m111->subdev.ctrl_handler = &mt9m111->hdl;
  840. if (mt9m111->hdl.error) {
  841. int err = mt9m111->hdl.error;
  842. kfree(mt9m111);
  843. return err;
  844. }
  845. /* Second stage probe - when a capture adapter is there */
  846. mt9m111->rect.left = MT9M111_MIN_DARK_COLS;
  847. mt9m111->rect.top = MT9M111_MIN_DARK_ROWS;
  848. mt9m111->rect.width = MT9M111_MAX_WIDTH;
  849. mt9m111->rect.height = MT9M111_MAX_HEIGHT;
  850. mt9m111->fmt = &mt9m111_colour_fmts[0];
  851. mt9m111->lastpage = -1;
  852. mutex_init(&mt9m111->power_lock);
  853. ret = mt9m111_video_probe(client);
  854. if (ret) {
  855. v4l2_ctrl_handler_free(&mt9m111->hdl);
  856. kfree(mt9m111);
  857. }
  858. return ret;
  859. }
  860. static int mt9m111_remove(struct i2c_client *client)
  861. {
  862. struct mt9m111 *mt9m111 = to_mt9m111(client);
  863. v4l2_device_unregister_subdev(&mt9m111->subdev);
  864. v4l2_ctrl_handler_free(&mt9m111->hdl);
  865. kfree(mt9m111);
  866. return 0;
  867. }
  868. static const struct i2c_device_id mt9m111_id[] = {
  869. { "mt9m111", 0 },
  870. { }
  871. };
  872. MODULE_DEVICE_TABLE(i2c, mt9m111_id);
  873. static struct i2c_driver mt9m111_i2c_driver = {
  874. .driver = {
  875. .name = "mt9m111",
  876. },
  877. .probe = mt9m111_probe,
  878. .remove = mt9m111_remove,
  879. .id_table = mt9m111_id,
  880. };
  881. module_i2c_driver(mt9m111_i2c_driver);
  882. MODULE_DESCRIPTION("Micron/Aptina MT9M111/MT9M112/MT9M131 Camera driver");
  883. MODULE_AUTHOR("Robert Jarzmik");
  884. MODULE_LICENSE("GPL");