Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for MT9V022 CMOS Image Sensor from Micron |
| 3 | * |
| 4 | * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> |
| 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 | |
| 11 | #include <linux/videodev2.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/i2c.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/log2.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 17 | |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 18 | #include <media/i2c/mt9v022.h> |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 19 | #include <media/soc_camera.h> |
Mauro Carvalho Chehab | d647f0b | 2015-11-13 19:40:07 -0200 | [diff] [blame] | 20 | #include <media/drv-intf/soc_mediabus.h> |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 21 | #include <media/v4l2-subdev.h> |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 22 | #include <media/v4l2-clk.h> |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 23 | #include <media/v4l2-ctrls.h> |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 24 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 25 | /* |
| 26 | * mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c |
Peter Meerwald | 22cf83f | 2012-06-13 10:48:11 -0300 | [diff] [blame] | 27 | * The platform has to define struct i2c_board_info objects and link to them |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 28 | * from struct soc_camera_host_desc |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 29 | */ |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 30 | |
| 31 | static char *sensor_type; |
| 32 | module_param(sensor_type, charp, S_IRUGO); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 33 | MODULE_PARM_DESC(sensor_type, "Sensor type: \"colour\" or \"monochrome\""); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 34 | |
| 35 | /* mt9v022 selected register addresses */ |
| 36 | #define MT9V022_CHIP_VERSION 0x00 |
| 37 | #define MT9V022_COLUMN_START 0x01 |
| 38 | #define MT9V022_ROW_START 0x02 |
| 39 | #define MT9V022_WINDOW_HEIGHT 0x03 |
| 40 | #define MT9V022_WINDOW_WIDTH 0x04 |
| 41 | #define MT9V022_HORIZONTAL_BLANKING 0x05 |
| 42 | #define MT9V022_VERTICAL_BLANKING 0x06 |
| 43 | #define MT9V022_CHIP_CONTROL 0x07 |
| 44 | #define MT9V022_SHUTTER_WIDTH1 0x08 |
| 45 | #define MT9V022_SHUTTER_WIDTH2 0x09 |
| 46 | #define MT9V022_SHUTTER_WIDTH_CTRL 0x0a |
| 47 | #define MT9V022_TOTAL_SHUTTER_WIDTH 0x0b |
| 48 | #define MT9V022_RESET 0x0c |
| 49 | #define MT9V022_READ_MODE 0x0d |
| 50 | #define MT9V022_MONITOR_MODE 0x0e |
| 51 | #define MT9V022_PIXEL_OPERATION_MODE 0x0f |
| 52 | #define MT9V022_LED_OUT_CONTROL 0x1b |
| 53 | #define MT9V022_ADC_MODE_CONTROL 0x1c |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 54 | #define MT9V022_REG32 0x20 |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 55 | #define MT9V022_ANALOG_GAIN 0x35 |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 56 | #define MT9V022_BLACK_LEVEL_CALIB_CTRL 0x47 |
| 57 | #define MT9V022_PIXCLK_FV_LV 0x74 |
| 58 | #define MT9V022_DIGITAL_TEST_PATTERN 0x7f |
| 59 | #define MT9V022_AEC_AGC_ENABLE 0xAF |
| 60 | #define MT9V022_MAX_TOTAL_SHUTTER_WIDTH 0xBD |
| 61 | |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 62 | /* mt9v024 partial list register addresses changes with respect to mt9v022 */ |
| 63 | #define MT9V024_PIXCLK_FV_LV 0x72 |
| 64 | #define MT9V024_MAX_TOTAL_SHUTTER_WIDTH 0xAD |
| 65 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 66 | /* Progressive scan, master, defaults */ |
| 67 | #define MT9V022_CHIP_CONTROL_DEFAULT 0x188 |
| 68 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 69 | #define MT9V022_MAX_WIDTH 752 |
| 70 | #define MT9V022_MAX_HEIGHT 480 |
| 71 | #define MT9V022_MIN_WIDTH 48 |
| 72 | #define MT9V022_MIN_HEIGHT 32 |
| 73 | #define MT9V022_COLUMN_SKIP 1 |
| 74 | #define MT9V022_ROW_SKIP 4 |
| 75 | |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 76 | #define MT9V022_HORIZONTAL_BLANKING_MIN 43 |
| 77 | #define MT9V022_HORIZONTAL_BLANKING_MAX 1023 |
| 78 | #define MT9V022_HORIZONTAL_BLANKING_DEF 94 |
| 79 | #define MT9V022_VERTICAL_BLANKING_MIN 2 |
| 80 | #define MT9V022_VERTICAL_BLANKING_MAX 3000 |
| 81 | #define MT9V022_VERTICAL_BLANKING_DEF 45 |
| 82 | |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 83 | #define is_mt9v022_rev3(id) (id == 0x1313) |
| 84 | #define is_mt9v024(id) (id == 0x1324) |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 85 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 86 | /* MT9V022 has only one fixed colorspace per pixelcode */ |
| 87 | struct mt9v022_datafmt { |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 88 | u32 code; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 89 | enum v4l2_colorspace colorspace; |
| 90 | }; |
| 91 | |
| 92 | /* Find a data format by a pixel code in an array */ |
| 93 | static const struct mt9v022_datafmt *mt9v022_find_datafmt( |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 94 | u32 code, const struct mt9v022_datafmt *fmt, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 95 | int n) |
| 96 | { |
| 97 | int i; |
| 98 | for (i = 0; i < n; i++) |
| 99 | if (fmt[i].code == code) |
| 100 | return fmt + i; |
| 101 | |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | static const struct mt9v022_datafmt mt9v022_colour_fmts[] = { |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 106 | /* |
| 107 | * Order important: first natively supported, |
| 108 | * second supported with a GPIO extender |
| 109 | */ |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 110 | {MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_COLORSPACE_SRGB}, |
| 111 | {MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB}, |
Guennadi Liakhovetski | bb55de3 | 2008-04-22 14:45:13 -0300 | [diff] [blame] | 112 | }; |
| 113 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 114 | static const struct mt9v022_datafmt mt9v022_monochrome_fmts[] = { |
Guennadi Liakhovetski | bb55de3 | 2008-04-22 14:45:13 -0300 | [diff] [blame] | 115 | /* Order important - see above */ |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 116 | {MEDIA_BUS_FMT_Y10_1X10, V4L2_COLORSPACE_JPEG}, |
| 117 | {MEDIA_BUS_FMT_Y8_1X8, V4L2_COLORSPACE_JPEG}, |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 118 | }; |
| 119 | |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 120 | /* only registers with different addresses on different mt9v02x sensors */ |
| 121 | struct mt9v02x_register { |
| 122 | u8 max_total_shutter_width; |
| 123 | u8 pixclk_fv_lv; |
| 124 | }; |
| 125 | |
| 126 | static const struct mt9v02x_register mt9v022_register = { |
| 127 | .max_total_shutter_width = MT9V022_MAX_TOTAL_SHUTTER_WIDTH, |
| 128 | .pixclk_fv_lv = MT9V022_PIXCLK_FV_LV, |
| 129 | }; |
| 130 | |
| 131 | static const struct mt9v02x_register mt9v024_register = { |
| 132 | .max_total_shutter_width = MT9V024_MAX_TOTAL_SHUTTER_WIDTH, |
| 133 | .pixclk_fv_lv = MT9V024_PIXCLK_FV_LV, |
| 134 | }; |
| 135 | |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 136 | enum mt9v022_model { |
| 137 | MT9V022IX7ATM, |
| 138 | MT9V022IX7ATC, |
| 139 | }; |
| 140 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 141 | struct mt9v022 { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 142 | struct v4l2_subdev subdev; |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 143 | struct v4l2_ctrl_handler hdl; |
| 144 | struct { |
| 145 | /* exposure/auto-exposure cluster */ |
| 146 | struct v4l2_ctrl *autoexposure; |
| 147 | struct v4l2_ctrl *exposure; |
| 148 | }; |
| 149 | struct { |
| 150 | /* gain/auto-gain cluster */ |
| 151 | struct v4l2_ctrl *autogain; |
| 152 | struct v4l2_ctrl *gain; |
| 153 | }; |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 154 | struct v4l2_ctrl *hblank; |
| 155 | struct v4l2_ctrl *vblank; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 156 | struct v4l2_rect rect; /* Sensor window */ |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 157 | struct v4l2_clk *clk; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 158 | const struct mt9v022_datafmt *fmt; |
| 159 | const struct mt9v022_datafmt *fmts; |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 160 | const struct mt9v02x_register *reg; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 161 | int num_fmts; |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 162 | enum mt9v022_model model; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 163 | u16 chip_control; |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 164 | u16 chip_version; |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 165 | unsigned short y_skip_top; /* Lines to skip at the top */ |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 166 | }; |
| 167 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 168 | static struct mt9v022 *to_mt9v022(const struct i2c_client *client) |
| 169 | { |
| 170 | return container_of(i2c_get_clientdata(client), struct mt9v022, subdev); |
| 171 | } |
| 172 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 173 | static int reg_read(struct i2c_client *client, const u8 reg) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 174 | { |
Jonathan Cameron | 3f87704 | 2011-10-21 09:30:25 -0300 | [diff] [blame] | 175 | return i2c_smbus_read_word_swapped(client, reg); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 176 | } |
| 177 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 178 | static int reg_write(struct i2c_client *client, const u8 reg, |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 179 | const u16 data) |
| 180 | { |
Jonathan Cameron | 3f87704 | 2011-10-21 09:30:25 -0300 | [diff] [blame] | 181 | return i2c_smbus_write_word_swapped(client, reg, data); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 182 | } |
| 183 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 184 | static int reg_set(struct i2c_client *client, const u8 reg, |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 185 | const u16 data) |
| 186 | { |
| 187 | int ret; |
| 188 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 189 | ret = reg_read(client, reg); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 190 | if (ret < 0) |
| 191 | return ret; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 192 | return reg_write(client, reg, ret | data); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 193 | } |
| 194 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 195 | static int reg_clear(struct i2c_client *client, const u8 reg, |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 196 | const u16 data) |
| 197 | { |
| 198 | int ret; |
| 199 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 200 | ret = reg_read(client, reg); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 201 | if (ret < 0) |
| 202 | return ret; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 203 | return reg_write(client, reg, ret & ~data); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 204 | } |
| 205 | |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 206 | static int mt9v022_init(struct i2c_client *client) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 207 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 208 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 209 | int ret; |
| 210 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 211 | /* |
| 212 | * Almost the default mode: master, parallel, simultaneous, and an |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 213 | * undocumented bit 0x200, which is present in table 7, but not in 8, |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 214 | * plus snapshot mode to disable scan for now |
| 215 | */ |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 216 | mt9v022->chip_control |= 0x10; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 217 | ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 218 | if (!ret) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 219 | ret = reg_write(client, MT9V022_READ_MODE, 0x300); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 220 | |
| 221 | /* All defaults */ |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 222 | if (!ret) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 223 | /* AEC, AGC on */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 224 | ret = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x3); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 225 | if (!ret) |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 226 | ret = reg_write(client, MT9V022_ANALOG_GAIN, 16); |
| 227 | if (!ret) |
| 228 | ret = reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH, 480); |
| 229 | if (!ret) |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 230 | ret = reg_write(client, mt9v022->reg->max_total_shutter_width, 480); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 231 | if (!ret) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 232 | /* default - auto */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 233 | ret = reg_clear(client, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 234 | if (!ret) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 235 | ret = reg_write(client, MT9V022_DIGITAL_TEST_PATTERN, 0); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 236 | if (!ret) |
| 237 | return v4l2_ctrl_handler_setup(&mt9v022->hdl); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 238 | |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 239 | return ret; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 240 | } |
| 241 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 242 | static int mt9v022_s_stream(struct v4l2_subdev *sd, int enable) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 243 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 244 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 245 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Stefan Herbrechtsmeier | 8103466 | 2008-08-14 12:04:11 -0300 | [diff] [blame] | 246 | |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 247 | if (enable) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 248 | /* Switch to master "normal" mode */ |
| 249 | mt9v022->chip_control &= ~0x10; |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 250 | if (is_mt9v022_rev3(mt9v022->chip_version) || |
| 251 | is_mt9v024(mt9v022->chip_version)) { |
| 252 | /* |
| 253 | * Unset snapshot mode specific settings: clear bit 9 |
| 254 | * and bit 2 in reg. 0x20 when in normal mode. |
| 255 | */ |
| 256 | if (reg_clear(client, MT9V022_REG32, 0x204)) |
| 257 | return -EIO; |
| 258 | } |
| 259 | } else { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 260 | /* Switch to snapshot mode */ |
| 261 | mt9v022->chip_control |= 0x10; |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 262 | if (is_mt9v022_rev3(mt9v022->chip_version) || |
| 263 | is_mt9v024(mt9v022->chip_version)) { |
| 264 | /* |
| 265 | * Required settings for snapshot mode: set bit 9 |
| 266 | * (RST enable) and bit 2 (CR enable) in reg. 0x20 |
| 267 | * See TechNote TN0960 or TN-09-225. |
| 268 | */ |
| 269 | if (reg_set(client, MT9V022_REG32, 0x204)) |
| 270 | return -EIO; |
| 271 | } |
| 272 | } |
Stefan Herbrechtsmeier | 8103466 | 2008-08-14 12:04:11 -0300 | [diff] [blame] | 273 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 274 | if (reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control) < 0) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 275 | return -EIO; |
| 276 | return 0; |
| 277 | } |
| 278 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 279 | static int mt9v022_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 280 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 281 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 282 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
| 283 | struct v4l2_rect rect = a->c; |
Andrei Andreyanau | bff7993 | 2013-02-06 11:29:18 -0300 | [diff] [blame] | 284 | int min_row, min_blank; |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 285 | int ret; |
| 286 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 287 | /* Bayer format - even size lengths */ |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 288 | if (mt9v022->fmts == mt9v022_colour_fmts) { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 289 | rect.width = ALIGN(rect.width, 2); |
| 290 | rect.height = ALIGN(rect.height, 2); |
| 291 | /* Let the user play with the starting pixel */ |
| 292 | } |
| 293 | |
| 294 | soc_camera_limit_side(&rect.left, &rect.width, |
| 295 | MT9V022_COLUMN_SKIP, MT9V022_MIN_WIDTH, MT9V022_MAX_WIDTH); |
| 296 | |
| 297 | soc_camera_limit_side(&rect.top, &rect.height, |
| 298 | MT9V022_ROW_SKIP, MT9V022_MIN_HEIGHT, MT9V022_MAX_HEIGHT); |
| 299 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 300 | /* Like in example app. Contradicts the datasheet though */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 301 | ret = reg_read(client, MT9V022_AEC_AGC_ENABLE); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 302 | if (ret >= 0) { |
| 303 | if (ret & 1) /* Autoexposure */ |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 304 | ret = reg_write(client, mt9v022->reg->max_total_shutter_width, |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 305 | rect.height + mt9v022->y_skip_top + 43); |
Anatolij Gustschin | 9bb047c | 2012-09-27 19:04:34 -0300 | [diff] [blame] | 306 | /* |
| 307 | * If autoexposure is off, there is no need to set |
| 308 | * MT9V022_TOTAL_SHUTTER_WIDTH here. Autoexposure can be off |
| 309 | * only if the user has set exposure manually, using the |
| 310 | * V4L2_CID_EXPOSURE_AUTO with the value V4L2_EXPOSURE_MANUAL. |
| 311 | * In this case the register MT9V022_TOTAL_SHUTTER_WIDTH |
| 312 | * already contains the correct value. |
| 313 | */ |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 314 | } |
| 315 | /* Setup frame format: defaults apart from width and height */ |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 316 | if (!ret) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 317 | ret = reg_write(client, MT9V022_COLUMN_START, rect.left); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 318 | if (!ret) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 319 | ret = reg_write(client, MT9V022_ROW_START, rect.top); |
Andrei Andreyanau | bff7993 | 2013-02-06 11:29:18 -0300 | [diff] [blame] | 320 | /* |
| 321 | * mt9v022: min total row time is 660 columns, min blanking is 43 |
| 322 | * mt9v024: min total row time is 690 columns, min blanking is 61 |
| 323 | */ |
| 324 | if (is_mt9v024(mt9v022->chip_version)) { |
| 325 | min_row = 690; |
| 326 | min_blank = 61; |
| 327 | } else { |
| 328 | min_row = 660; |
| 329 | min_blank = 43; |
| 330 | } |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 331 | if (!ret) |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 332 | ret = v4l2_ctrl_s_ctrl(mt9v022->hblank, |
Andrei Andreyanau | bff7993 | 2013-02-06 11:29:18 -0300 | [diff] [blame] | 333 | rect.width > min_row - min_blank ? |
| 334 | min_blank : min_row - rect.width); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 335 | if (!ret) |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 336 | ret = v4l2_ctrl_s_ctrl(mt9v022->vblank, 45); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 337 | if (!ret) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 338 | ret = reg_write(client, MT9V022_WINDOW_WIDTH, rect.width); |
Guennadi Liakhovetski | 1121164 | 2008-08-14 12:03:18 -0300 | [diff] [blame] | 339 | if (!ret) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 340 | ret = reg_write(client, MT9V022_WINDOW_HEIGHT, |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 341 | rect.height + mt9v022->y_skip_top); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 342 | |
| 343 | if (ret < 0) |
| 344 | return ret; |
| 345 | |
Márton Németh | e26b314 | 2010-02-24 17:13:29 -0300 | [diff] [blame] | 346 | dev_dbg(&client->dev, "Frame %dx%d pixel\n", rect.width, rect.height); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 347 | |
| 348 | mt9v022->rect = rect; |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static int mt9v022_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
| 354 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 355 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 356 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
| 357 | |
| 358 | a->c = mt9v022->rect; |
| 359 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static int mt9v022_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) |
| 365 | { |
| 366 | a->bounds.left = MT9V022_COLUMN_SKIP; |
| 367 | a->bounds.top = MT9V022_ROW_SKIP; |
| 368 | a->bounds.width = MT9V022_MAX_WIDTH; |
| 369 | a->bounds.height = MT9V022_MAX_HEIGHT; |
| 370 | a->defrect = a->bounds; |
| 371 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 372 | a->pixelaspect.numerator = 1; |
| 373 | a->pixelaspect.denominator = 1; |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 378 | static int mt9v022_get_fmt(struct v4l2_subdev *sd, |
| 379 | struct v4l2_subdev_pad_config *cfg, |
| 380 | struct v4l2_subdev_format *format) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 381 | { |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 382 | struct v4l2_mbus_framefmt *mf = &format->format; |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 383 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 384 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 385 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 386 | if (format->pad) |
| 387 | return -EINVAL; |
| 388 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 389 | mf->width = mt9v022->rect.width; |
| 390 | mf->height = mt9v022->rect.height; |
| 391 | mf->code = mt9v022->fmt->code; |
| 392 | mf->colorspace = mt9v022->fmt->colorspace; |
| 393 | mf->field = V4L2_FIELD_NONE; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 394 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 398 | static int mt9v022_s_fmt(struct v4l2_subdev *sd, |
| 399 | struct v4l2_mbus_framefmt *mf) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 400 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 401 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 402 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 403 | struct v4l2_crop a = { |
| 404 | .c = { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 405 | .left = mt9v022->rect.left, |
| 406 | .top = mt9v022->rect.top, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 407 | .width = mf->width, |
| 408 | .height = mf->height, |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 409 | }, |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 410 | }; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 411 | int ret; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 412 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 413 | /* |
| 414 | * The caller provides a supported format, as verified per call to |
Hans Verkuil | 717fd5b | 2015-04-09 06:24:36 -0300 | [diff] [blame] | 415 | * .set_fmt(FORMAT_TRY), datawidth is from our supported format list |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 416 | */ |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 417 | switch (mf->code) { |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 418 | case MEDIA_BUS_FMT_Y8_1X8: |
| 419 | case MEDIA_BUS_FMT_Y10_1X10: |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 420 | if (mt9v022->model != MT9V022IX7ATM) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 421 | return -EINVAL; |
| 422 | break; |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 423 | case MEDIA_BUS_FMT_SBGGR8_1X8: |
| 424 | case MEDIA_BUS_FMT_SBGGR10_1X10: |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 425 | if (mt9v022->model != MT9V022IX7ATC) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 426 | return -EINVAL; |
| 427 | break; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 428 | default: |
| 429 | return -EINVAL; |
| 430 | } |
| 431 | |
| 432 | /* No support for scaling on this camera, just crop. */ |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 433 | ret = mt9v022_s_crop(sd, &a); |
| 434 | if (!ret) { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 435 | mf->width = mt9v022->rect.width; |
| 436 | mf->height = mt9v022->rect.height; |
| 437 | mt9v022->fmt = mt9v022_find_datafmt(mf->code, |
| 438 | mt9v022->fmts, mt9v022->num_fmts); |
| 439 | mf->colorspace = mt9v022->fmt->colorspace; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | return ret; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 443 | } |
| 444 | |
Hans Verkuil | 717fd5b | 2015-04-09 06:24:36 -0300 | [diff] [blame] | 445 | static int mt9v022_set_fmt(struct v4l2_subdev *sd, |
| 446 | struct v4l2_subdev_pad_config *cfg, |
| 447 | struct v4l2_subdev_format *format) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 448 | { |
Hans Verkuil | 717fd5b | 2015-04-09 06:24:36 -0300 | [diff] [blame] | 449 | struct v4l2_mbus_framefmt *mf = &format->format; |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 450 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 451 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 452 | const struct mt9v022_datafmt *fmt; |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 453 | int align = mf->code == MEDIA_BUS_FMT_SBGGR8_1X8 || |
| 454 | mf->code == MEDIA_BUS_FMT_SBGGR10_1X10; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 455 | |
Hans Verkuil | 717fd5b | 2015-04-09 06:24:36 -0300 | [diff] [blame] | 456 | if (format->pad) |
| 457 | return -EINVAL; |
| 458 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 459 | v4l_bound_align_image(&mf->width, MT9V022_MIN_WIDTH, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 460 | MT9V022_MAX_WIDTH, align, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 461 | &mf->height, MT9V022_MIN_HEIGHT + mt9v022->y_skip_top, |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 462 | MT9V022_MAX_HEIGHT + mt9v022->y_skip_top, align, 0); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 463 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 464 | fmt = mt9v022_find_datafmt(mf->code, mt9v022->fmts, |
| 465 | mt9v022->num_fmts); |
| 466 | if (!fmt) { |
| 467 | fmt = mt9v022->fmt; |
| 468 | mf->code = fmt->code; |
| 469 | } |
| 470 | |
| 471 | mf->colorspace = fmt->colorspace; |
| 472 | |
Hans Verkuil | 717fd5b | 2015-04-09 06:24:36 -0300 | [diff] [blame] | 473 | if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) |
| 474 | return mt9v022_s_fmt(sd, mf); |
| 475 | cfg->try_fmt = *mf; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 479 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 480 | static int mt9v022_g_register(struct v4l2_subdev *sd, |
| 481 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 482 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 483 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 484 | |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 485 | if (reg->reg > 0xff) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 486 | return -EINVAL; |
| 487 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 488 | reg->size = 2; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 489 | reg->val = reg_read(client, reg->reg); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 490 | |
| 491 | if (reg->val > 0xffff) |
| 492 | return -EIO; |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 497 | static int mt9v022_s_register(struct v4l2_subdev *sd, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 498 | const struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 499 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 500 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 501 | |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 502 | if (reg->reg > 0xff) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 503 | return -EINVAL; |
| 504 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 505 | if (reg_write(client, reg->reg, reg->val) < 0) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 506 | return -EIO; |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | #endif |
| 511 | |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 512 | static int mt9v022_s_power(struct v4l2_subdev *sd, int on) |
| 513 | { |
| 514 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 515 | struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 516 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 517 | |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 518 | return soc_camera_set_power(&client->dev, ssdd, mt9v022->clk, on); |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 519 | } |
| 520 | |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 521 | static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 522 | { |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 523 | struct mt9v022 *mt9v022 = container_of(ctrl->handler, |
| 524 | struct mt9v022, hdl); |
| 525 | struct v4l2_subdev *sd = &mt9v022->subdev; |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 526 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 527 | struct v4l2_ctrl *gain = mt9v022->gain; |
| 528 | struct v4l2_ctrl *exp = mt9v022->exposure; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 529 | unsigned long range; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 530 | int data; |
| 531 | |
| 532 | switch (ctrl->id) { |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 533 | case V4L2_CID_AUTOGAIN: |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 534 | data = reg_read(client, MT9V022_ANALOG_GAIN); |
| 535 | if (data < 0) |
| 536 | return -EIO; |
| 537 | |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 538 | range = gain->maximum - gain->minimum; |
| 539 | gain->val = ((data - 16) * range + 24) / 48 + gain->minimum; |
| 540 | return 0; |
| 541 | case V4L2_CID_EXPOSURE_AUTO: |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 542 | data = reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH); |
| 543 | if (data < 0) |
| 544 | return -EIO; |
| 545 | |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 546 | range = exp->maximum - exp->minimum; |
| 547 | exp->val = ((data - 1) * range + 239) / 479 + exp->minimum; |
| 548 | return 0; |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 549 | case V4L2_CID_HBLANK: |
| 550 | data = reg_read(client, MT9V022_HORIZONTAL_BLANKING); |
| 551 | if (data < 0) |
| 552 | return -EIO; |
| 553 | ctrl->val = data; |
| 554 | return 0; |
| 555 | case V4L2_CID_VBLANK: |
| 556 | data = reg_read(client, MT9V022_VERTICAL_BLANKING); |
| 557 | if (data < 0) |
| 558 | return -EIO; |
| 559 | ctrl->val = data; |
| 560 | return 0; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 561 | } |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 562 | return -EINVAL; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 563 | } |
| 564 | |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 565 | static int mt9v022_s_ctrl(struct v4l2_ctrl *ctrl) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 566 | { |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 567 | struct mt9v022 *mt9v022 = container_of(ctrl->handler, |
| 568 | struct mt9v022, hdl); |
| 569 | struct v4l2_subdev *sd = &mt9v022->subdev; |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 570 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 571 | int data; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 572 | |
| 573 | switch (ctrl->id) { |
| 574 | case V4L2_CID_VFLIP: |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 575 | if (ctrl->val) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 576 | data = reg_set(client, MT9V022_READ_MODE, 0x10); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 577 | else |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 578 | data = reg_clear(client, MT9V022_READ_MODE, 0x10); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 579 | if (data < 0) |
| 580 | return -EIO; |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 581 | return 0; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 582 | case V4L2_CID_HFLIP: |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 583 | if (ctrl->val) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 584 | data = reg_set(client, MT9V022_READ_MODE, 0x20); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 585 | else |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 586 | data = reg_clear(client, MT9V022_READ_MODE, 0x20); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 587 | if (data < 0) |
| 588 | return -EIO; |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 589 | return 0; |
| 590 | case V4L2_CID_AUTOGAIN: |
| 591 | if (ctrl->val) { |
| 592 | if (reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0) |
| 593 | return -EIO; |
| 594 | } else { |
| 595 | struct v4l2_ctrl *gain = mt9v022->gain; |
| 596 | /* mt9v022 has minimum == default */ |
| 597 | unsigned long range = gain->maximum - gain->minimum; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 598 | /* Valid values 16 to 64, 32 to 64 must be even. */ |
Hans Verkuil | 0d5e8c4 | 2014-07-17 12:31:23 -0300 | [diff] [blame] | 599 | unsigned long gain_val = ((gain->val - (s32)gain->minimum) * |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 600 | 48 + range / 2) / range + 16; |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 601 | |
| 602 | if (gain_val >= 32) |
| 603 | gain_val &= ~1; |
| 604 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 605 | /* |
| 606 | * The user wants to set gain manually, hope, she |
| 607 | * knows, what she's doing... Switch AGC off. |
| 608 | */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 609 | if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 610 | return -EIO; |
| 611 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 612 | dev_dbg(&client->dev, "Setting gain from %d to %lu\n", |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 613 | reg_read(client, MT9V022_ANALOG_GAIN), gain_val); |
| 614 | if (reg_write(client, MT9V022_ANALOG_GAIN, gain_val) < 0) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 615 | return -EIO; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 616 | } |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 617 | return 0; |
| 618 | case V4L2_CID_EXPOSURE_AUTO: |
| 619 | if (ctrl->val == V4L2_EXPOSURE_AUTO) { |
| 620 | data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1); |
| 621 | } else { |
| 622 | struct v4l2_ctrl *exp = mt9v022->exposure; |
| 623 | unsigned long range = exp->maximum - exp->minimum; |
Hans Verkuil | 0d5e8c4 | 2014-07-17 12:31:23 -0300 | [diff] [blame] | 624 | unsigned long shutter = ((exp->val - (s32)exp->minimum) * |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 625 | 479 + range / 2) / range + 1; |
| 626 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 627 | /* |
| 628 | * The user wants to set shutter width manually, hope, |
| 629 | * she knows, what she's doing... Switch AEC off. |
| 630 | */ |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 631 | data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1); |
| 632 | if (data < 0) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 633 | return -EIO; |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 634 | dev_dbg(&client->dev, "Shutter width from %d to %lu\n", |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 635 | reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH), |
| 636 | shutter); |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 637 | if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH, |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 638 | shutter) < 0) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 639 | return -EIO; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 640 | } |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 641 | return 0; |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 642 | case V4L2_CID_HBLANK: |
| 643 | if (reg_write(client, MT9V022_HORIZONTAL_BLANKING, |
| 644 | ctrl->val) < 0) |
| 645 | return -EIO; |
| 646 | return 0; |
| 647 | case V4L2_CID_VBLANK: |
| 648 | if (reg_write(client, MT9V022_VERTICAL_BLANKING, |
| 649 | ctrl->val) < 0) |
| 650 | return -EIO; |
| 651 | return 0; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 652 | } |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 653 | return -EINVAL; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 654 | } |
| 655 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 656 | /* |
| 657 | * Interface active, can use i2c. If it fails, it can indeed mean, that |
| 658 | * this wasn't our capture interface, so, we wait for the right one |
| 659 | */ |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 660 | static int mt9v022_video_probe(struct i2c_client *client) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 661 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 662 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 663 | struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 664 | s32 data; |
| 665 | int ret; |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 666 | unsigned long flags; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 667 | |
Laurent Pinchart | 4bbc6d5 | 2012-07-18 10:54:04 -0300 | [diff] [blame] | 668 | ret = mt9v022_s_power(&mt9v022->subdev, 1); |
| 669 | if (ret < 0) |
| 670 | return ret; |
| 671 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 672 | /* Read out the chip version register */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 673 | data = reg_read(client, MT9V022_CHIP_VERSION); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 674 | |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 675 | /* must be 0x1311, 0x1313 or 0x1324 */ |
| 676 | if (data != 0x1311 && data != 0x1313 && data != 0x1324) { |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 677 | ret = -ENODEV; |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 678 | dev_info(&client->dev, "No MT9V022 found, ID register 0x%x\n", |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 679 | data); |
| 680 | goto ei2c; |
| 681 | } |
| 682 | |
Anatolij Gustschin | d0bac76 | 2012-09-27 19:52:42 -0300 | [diff] [blame] | 683 | mt9v022->chip_version = data; |
| 684 | |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 685 | mt9v022->reg = is_mt9v024(data) ? &mt9v024_register : |
| 686 | &mt9v022_register; |
| 687 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 688 | /* Soft reset */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 689 | ret = reg_write(client, MT9V022_RESET, 1); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 690 | if (ret < 0) |
| 691 | goto ei2c; |
| 692 | /* 15 clock cycles */ |
| 693 | udelay(200); |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 694 | if (reg_read(client, MT9V022_RESET)) { |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 695 | dev_err(&client->dev, "Resetting MT9V022 failed!\n"); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 696 | if (ret > 0) |
| 697 | ret = -EIO; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 698 | goto ei2c; |
| 699 | } |
| 700 | |
| 701 | /* Set monochrome or colour sensor type */ |
| 702 | if (sensor_type && (!strcmp("colour", sensor_type) || |
| 703 | !strcmp("color", sensor_type))) { |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 704 | ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11); |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 705 | mt9v022->model = MT9V022IX7ATC; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 706 | mt9v022->fmts = mt9v022_colour_fmts; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 707 | } else { |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 708 | ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 0x11); |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 709 | mt9v022->model = MT9V022IX7ATM; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 710 | mt9v022->fmts = mt9v022_monochrome_fmts; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 711 | } |
| 712 | |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 713 | if (ret < 0) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 714 | goto ei2c; |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 715 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 716 | mt9v022->num_fmts = 0; |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 717 | |
| 718 | /* |
| 719 | * This is a 10bit sensor, so by default we only allow 10bit. |
| 720 | * The platform may support different bus widths due to |
| 721 | * different routing of the data lines. |
| 722 | */ |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 723 | if (ssdd->query_bus_param) |
| 724 | flags = ssdd->query_bus_param(ssdd); |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 725 | else |
| 726 | flags = SOCAM_DATAWIDTH_10; |
| 727 | |
| 728 | if (flags & SOCAM_DATAWIDTH_10) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 729 | mt9v022->num_fmts++; |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 730 | else |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 731 | mt9v022->fmts++; |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 732 | |
| 733 | if (flags & SOCAM_DATAWIDTH_8) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 734 | mt9v022->num_fmts++; |
Sascha Hauer | e958e27 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 735 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 736 | mt9v022->fmt = &mt9v022->fmts[0]; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 737 | |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 738 | dev_info(&client->dev, "Detected a MT9V022 chip ID %x, %s sensor\n", |
Hans Verkuil | 6be89da | 2013-05-29 06:59:50 -0300 | [diff] [blame] | 739 | data, mt9v022->model == MT9V022IX7ATM ? |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 740 | "monochrome" : "colour"); |
| 741 | |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 742 | ret = mt9v022_init(client); |
| 743 | if (ret < 0) |
| 744 | dev_err(&client->dev, "Failed to initialise the camera\n"); |
| 745 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 746 | ei2c: |
Laurent Pinchart | 4bbc6d5 | 2012-07-18 10:54:04 -0300 | [diff] [blame] | 747 | mt9v022_s_power(&mt9v022->subdev, 0); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 748 | return ret; |
| 749 | } |
| 750 | |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 751 | static int mt9v022_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines) |
| 752 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 753 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 754 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
| 755 | |
| 756 | *lines = mt9v022->y_skip_top; |
| 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 761 | static const struct v4l2_ctrl_ops mt9v022_ctrl_ops = { |
| 762 | .g_volatile_ctrl = mt9v022_g_volatile_ctrl, |
| 763 | .s_ctrl = mt9v022_s_ctrl, |
| 764 | }; |
| 765 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 766 | static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 767 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 768 | .g_register = mt9v022_g_register, |
| 769 | .s_register = mt9v022_s_register, |
| 770 | #endif |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 771 | .s_power = mt9v022_s_power, |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 772 | }; |
| 773 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 774 | static int mt9v022_enum_mbus_code(struct v4l2_subdev *sd, |
| 775 | struct v4l2_subdev_pad_config *cfg, |
| 776 | struct v4l2_subdev_mbus_code_enum *code) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 777 | { |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 778 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 779 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
| 780 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 781 | if (code->pad || code->index >= mt9v022->num_fmts) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 782 | return -EINVAL; |
| 783 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 784 | code->code = mt9v022->fmts[code->index].code; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 785 | return 0; |
| 786 | } |
| 787 | |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 788 | static int mt9v022_g_mbus_config(struct v4l2_subdev *sd, |
| 789 | struct v4l2_mbus_config *cfg) |
| 790 | { |
| 791 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 792 | struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 793 | |
| 794 | cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE | |
| 795 | V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | |
| 796 | V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW | |
| 797 | V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | |
| 798 | V4L2_MBUS_DATA_ACTIVE_HIGH; |
| 799 | cfg->type = V4L2_MBUS_PARALLEL; |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 800 | cfg->flags = soc_camera_apply_board_flags(ssdd, cfg); |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | static int mt9v022_s_mbus_config(struct v4l2_subdev *sd, |
| 806 | const struct v4l2_mbus_config *cfg) |
| 807 | { |
| 808 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 809 | struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 810 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 811 | unsigned long flags = soc_camera_apply_board_flags(ssdd, cfg); |
Guennadi Liakhovetski | 443f483 | 2011-09-09 07:06:50 -0300 | [diff] [blame] | 812 | unsigned int bps = soc_mbus_get_fmtdesc(mt9v022->fmt->code)->bits_per_sample; |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 813 | int ret; |
| 814 | u16 pixclk = 0; |
| 815 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 816 | if (ssdd->set_bus_param) { |
| 817 | ret = ssdd->set_bus_param(ssdd, 1 << (bps - 1)); |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 818 | if (ret) |
| 819 | return ret; |
| 820 | } else if (bps != 10) { |
| 821 | /* |
| 822 | * Without board specific bus width settings we only support the |
| 823 | * sensors native bus width |
| 824 | */ |
| 825 | return -EINVAL; |
| 826 | } |
| 827 | |
| 828 | if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) |
| 829 | pixclk |= 0x10; |
| 830 | |
| 831 | if (!(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)) |
| 832 | pixclk |= 0x1; |
| 833 | |
| 834 | if (!(flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)) |
| 835 | pixclk |= 0x2; |
| 836 | |
Alex Gershgorin | c078ac1 | 2012-08-02 12:32:41 -0300 | [diff] [blame] | 837 | ret = reg_write(client, mt9v022->reg->pixclk_fv_lv, pixclk); |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 838 | if (ret < 0) |
| 839 | return ret; |
| 840 | |
| 841 | if (!(flags & V4L2_MBUS_MASTER)) |
| 842 | mt9v022->chip_control &= ~0x8; |
| 843 | |
| 844 | ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control); |
| 845 | if (ret < 0) |
| 846 | return ret; |
| 847 | |
| 848 | dev_dbg(&client->dev, "Calculated pixclk 0x%x, chip control 0x%x\n", |
| 849 | pixclk, mt9v022->chip_control); |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 854 | static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = { |
| 855 | .s_stream = mt9v022_s_stream, |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 856 | .s_crop = mt9v022_s_crop, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 857 | .g_crop = mt9v022_g_crop, |
| 858 | .cropcap = mt9v022_cropcap, |
Guennadi Liakhovetski | e8e2c70 | 2011-07-27 05:53:33 -0300 | [diff] [blame] | 859 | .g_mbus_config = mt9v022_g_mbus_config, |
| 860 | .s_mbus_config = mt9v022_s_mbus_config, |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 861 | }; |
| 862 | |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 863 | static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = { |
| 864 | .g_skip_top_lines = mt9v022_g_skip_top_lines, |
| 865 | }; |
| 866 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 867 | static const struct v4l2_subdev_pad_ops mt9v022_subdev_pad_ops = { |
| 868 | .enum_mbus_code = mt9v022_enum_mbus_code, |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 869 | .get_fmt = mt9v022_get_fmt, |
Hans Verkuil | 717fd5b | 2015-04-09 06:24:36 -0300 | [diff] [blame] | 870 | .set_fmt = mt9v022_set_fmt, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 871 | }; |
| 872 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 873 | static struct v4l2_subdev_ops mt9v022_subdev_ops = { |
| 874 | .core = &mt9v022_subdev_core_ops, |
| 875 | .video = &mt9v022_subdev_video_ops, |
Guennadi Liakhovetski | 3253610 | 2009-12-11 11:14:46 -0300 | [diff] [blame] | 876 | .sensor = &mt9v022_subdev_sensor_ops, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 877 | .pad = &mt9v022_subdev_pad_ops, |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 878 | }; |
| 879 | |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 880 | static int mt9v022_probe(struct i2c_client *client, |
| 881 | const struct i2c_device_id *did) |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 882 | { |
| 883 | struct mt9v022 *mt9v022; |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 884 | struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 885 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
Wei Yongjun | daf16ba | 2012-11-28 23:56:15 -0300 | [diff] [blame] | 886 | struct mt9v022_platform_data *pdata; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 887 | int ret; |
| 888 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 889 | if (!ssdd) { |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 890 | dev_err(&client->dev, "MT9V022 driver needs platform data\n"); |
| 891 | return -EINVAL; |
| 892 | } |
| 893 | |
| 894 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) { |
| 895 | dev_warn(&adapter->dev, |
| 896 | "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n"); |
| 897 | return -EIO; |
| 898 | } |
| 899 | |
Guennadi Liakhovetski | 70e176a | 2012-12-21 10:28:43 -0300 | [diff] [blame] | 900 | mt9v022 = devm_kzalloc(&client->dev, sizeof(struct mt9v022), GFP_KERNEL); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 901 | if (!mt9v022) |
| 902 | return -ENOMEM; |
| 903 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 904 | pdata = ssdd->drv_priv; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 905 | v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 906 | v4l2_ctrl_handler_init(&mt9v022->hdl, 6); |
| 907 | v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 908 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 909 | v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 910 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 911 | mt9v022->autogain = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 912 | V4L2_CID_AUTOGAIN, 0, 1, 1, 1); |
| 913 | mt9v022->gain = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 914 | V4L2_CID_GAIN, 0, 127, 1, 64); |
| 915 | |
| 916 | /* |
| 917 | * Simulated autoexposure. If enabled, we calculate shutter width |
| 918 | * ourselves in the driver based on vertical blanking and frame width |
| 919 | */ |
| 920 | mt9v022->autoexposure = v4l2_ctrl_new_std_menu(&mt9v022->hdl, |
| 921 | &mt9v022_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0, |
| 922 | V4L2_EXPOSURE_AUTO); |
| 923 | mt9v022->exposure = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 924 | V4L2_CID_EXPOSURE, 1, 255, 1, 255); |
| 925 | |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 926 | mt9v022->hblank = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 927 | V4L2_CID_HBLANK, MT9V022_HORIZONTAL_BLANKING_MIN, |
| 928 | MT9V022_HORIZONTAL_BLANKING_MAX, 1, |
| 929 | MT9V022_HORIZONTAL_BLANKING_DEF); |
| 930 | |
| 931 | mt9v022->vblank = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, |
| 932 | V4L2_CID_VBLANK, MT9V022_VERTICAL_BLANKING_MIN, |
| 933 | MT9V022_VERTICAL_BLANKING_MAX, 1, |
| 934 | MT9V022_VERTICAL_BLANKING_DEF); |
| 935 | |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 936 | mt9v022->subdev.ctrl_handler = &mt9v022->hdl; |
| 937 | if (mt9v022->hdl.error) { |
| 938 | int err = mt9v022->hdl.error; |
| 939 | |
Anatolij Gustschin | 6cc1eb7 | 2012-09-27 19:03:45 -0300 | [diff] [blame] | 940 | dev_err(&client->dev, "control initialisation err %d\n", err); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 941 | return err; |
| 942 | } |
| 943 | v4l2_ctrl_auto_cluster(2, &mt9v022->autoexposure, |
| 944 | V4L2_EXPOSURE_MANUAL, true); |
| 945 | v4l2_ctrl_auto_cluster(2, &mt9v022->autogain, 0, true); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 946 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 947 | mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT; |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 948 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 949 | /* |
Anatolij Gustschin | b6f50b4 | 2012-09-27 19:05:27 -0300 | [diff] [blame] | 950 | * On some platforms the first read out line is corrupted. |
| 951 | * Workaround it by skipping if indicated by platform data. |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 952 | */ |
Anatolij Gustschin | b6f50b4 | 2012-09-27 19:05:27 -0300 | [diff] [blame] | 953 | mt9v022->y_skip_top = pdata ? pdata->y_skip_top : 0; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 954 | mt9v022->rect.left = MT9V022_COLUMN_SKIP; |
| 955 | mt9v022->rect.top = MT9V022_ROW_SKIP; |
| 956 | mt9v022->rect.width = MT9V022_MAX_WIDTH; |
| 957 | mt9v022->rect.height = MT9V022_MAX_HEIGHT; |
| 958 | |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 959 | mt9v022->clk = v4l2_clk_get(&client->dev, "mclk"); |
| 960 | if (IS_ERR(mt9v022->clk)) { |
| 961 | ret = PTR_ERR(mt9v022->clk); |
| 962 | goto eclkget; |
| 963 | } |
| 964 | |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 965 | ret = mt9v022_video_probe(client); |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 966 | if (ret) { |
| 967 | v4l2_clk_put(mt9v022->clk); |
| 968 | eclkget: |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 969 | v4l2_ctrl_handler_free(&mt9v022->hdl); |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 970 | } |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 971 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 972 | return ret; |
| 973 | } |
| 974 | |
| 975 | static int mt9v022_remove(struct i2c_client *client) |
| 976 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 977 | struct mt9v022 *mt9v022 = to_mt9v022(client); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 978 | struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 979 | |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame] | 980 | v4l2_clk_put(mt9v022->clk); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 981 | v4l2_device_unregister_subdev(&mt9v022->subdev); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 982 | if (ssdd->free_bus) |
| 983 | ssdd->free_bus(ssdd); |
Hans Verkuil | ab7b50a | 2011-09-07 05:22:39 -0300 | [diff] [blame] | 984 | v4l2_ctrl_handler_free(&mt9v022->hdl); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 985 | |
| 986 | return 0; |
| 987 | } |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 988 | static const struct i2c_device_id mt9v022_id[] = { |
| 989 | { "mt9v022", 0 }, |
| 990 | { } |
| 991 | }; |
| 992 | MODULE_DEVICE_TABLE(i2c, mt9v022_id); |
| 993 | |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 994 | static struct i2c_driver mt9v022_i2c_driver = { |
| 995 | .driver = { |
| 996 | .name = "mt9v022", |
| 997 | }, |
| 998 | .probe = mt9v022_probe, |
| 999 | .remove = mt9v022_remove, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 1000 | .id_table = mt9v022_id, |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 1001 | }; |
| 1002 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 1003 | module_i2c_driver(mt9v022_i2c_driver); |
Guennadi Liakhovetski | 7397bfbe | 2008-04-22 14:42:04 -0300 | [diff] [blame] | 1004 | |
| 1005 | MODULE_DESCRIPTION("Micron MT9V022 Camera driver"); |
| 1006 | MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>"); |
| 1007 | MODULE_LICENSE("GPL"); |