Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for MT9T031 CMOS Image Sensor from Micron |
| 3 | * |
| 4 | * Copyright (C) 2008, Guennadi Liakhovetski, DENX Software Engineering <lg@denx.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/log2.h> |
| 15 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 16 | #include <media/v4l2-subdev.h> |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 17 | #include <media/v4l2-chip-ident.h> |
| 18 | #include <media/soc_camera.h> |
| 19 | |
| 20 | /* mt9t031 i2c address 0x5d |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 21 | * The platform has to define i2c_board_info and link to it from |
| 22 | * struct soc_camera_link */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 23 | |
| 24 | /* mt9t031 selected register addresses */ |
| 25 | #define MT9T031_CHIP_VERSION 0x00 |
| 26 | #define MT9T031_ROW_START 0x01 |
| 27 | #define MT9T031_COLUMN_START 0x02 |
| 28 | #define MT9T031_WINDOW_HEIGHT 0x03 |
| 29 | #define MT9T031_WINDOW_WIDTH 0x04 |
| 30 | #define MT9T031_HORIZONTAL_BLANKING 0x05 |
| 31 | #define MT9T031_VERTICAL_BLANKING 0x06 |
| 32 | #define MT9T031_OUTPUT_CONTROL 0x07 |
| 33 | #define MT9T031_SHUTTER_WIDTH_UPPER 0x08 |
| 34 | #define MT9T031_SHUTTER_WIDTH 0x09 |
| 35 | #define MT9T031_PIXEL_CLOCK_CONTROL 0x0a |
| 36 | #define MT9T031_FRAME_RESTART 0x0b |
| 37 | #define MT9T031_SHUTTER_DELAY 0x0c |
| 38 | #define MT9T031_RESET 0x0d |
| 39 | #define MT9T031_READ_MODE_1 0x1e |
| 40 | #define MT9T031_READ_MODE_2 0x20 |
| 41 | #define MT9T031_READ_MODE_3 0x21 |
| 42 | #define MT9T031_ROW_ADDRESS_MODE 0x22 |
| 43 | #define MT9T031_COLUMN_ADDRESS_MODE 0x23 |
| 44 | #define MT9T031_GLOBAL_GAIN 0x35 |
| 45 | #define MT9T031_CHIP_ENABLE 0xF8 |
| 46 | |
| 47 | #define MT9T031_MAX_HEIGHT 1536 |
| 48 | #define MT9T031_MAX_WIDTH 2048 |
| 49 | #define MT9T031_MIN_HEIGHT 2 |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 50 | #define MT9T031_MIN_WIDTH 18 |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 51 | #define MT9T031_HORIZONTAL_BLANK 142 |
| 52 | #define MT9T031_VERTICAL_BLANK 25 |
| 53 | #define MT9T031_COLUMN_SKIP 32 |
| 54 | #define MT9T031_ROW_SKIP 20 |
| 55 | |
| 56 | #define MT9T031_BUS_PARAM (SOCAM_PCLK_SAMPLE_RISING | \ |
| 57 | SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH | \ |
| 58 | SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH | \ |
| 59 | SOCAM_MASTER | SOCAM_DATAWIDTH_10) |
| 60 | |
| 61 | static const struct soc_camera_data_format mt9t031_colour_formats[] = { |
| 62 | { |
| 63 | .name = "Bayer (sRGB) 10 bit", |
| 64 | .depth = 10, |
| 65 | .fourcc = V4L2_PIX_FMT_SGRBG10, |
| 66 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | struct mt9t031 { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 71 | struct v4l2_subdev subdev; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 72 | struct v4l2_rect rect; /* Sensor window */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 73 | int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 74 | u16 xskip; |
| 75 | u16 yskip; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 76 | unsigned int gain; |
| 77 | unsigned int exposure; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 78 | unsigned char autoexposure; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 79 | }; |
| 80 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 81 | static struct mt9t031 *to_mt9t031(const struct i2c_client *client) |
| 82 | { |
| 83 | return container_of(i2c_get_clientdata(client), struct mt9t031, subdev); |
| 84 | } |
| 85 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 86 | static int reg_read(struct i2c_client *client, const u8 reg) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 87 | { |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 88 | s32 data = i2c_smbus_read_word_data(client, reg); |
| 89 | return data < 0 ? data : swab16(data); |
| 90 | } |
| 91 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 92 | static int reg_write(struct i2c_client *client, const u8 reg, |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 93 | const u16 data) |
| 94 | { |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 95 | return i2c_smbus_write_word_data(client, reg, swab16(data)); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 96 | } |
| 97 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 98 | static int reg_set(struct i2c_client *client, const u8 reg, |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 99 | const u16 data) |
| 100 | { |
| 101 | int ret; |
| 102 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 103 | ret = reg_read(client, reg); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 104 | if (ret < 0) |
| 105 | return ret; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 106 | return reg_write(client, reg, ret | data); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 107 | } |
| 108 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 109 | static int reg_clear(struct i2c_client *client, const u8 reg, |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 110 | const u16 data) |
| 111 | { |
| 112 | int ret; |
| 113 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 114 | ret = reg_read(client, reg); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 115 | if (ret < 0) |
| 116 | return ret; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 117 | return reg_write(client, reg, ret & ~data); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 118 | } |
| 119 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 120 | static int set_shutter(struct i2c_client *client, const u32 data) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 121 | { |
| 122 | int ret; |
| 123 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 124 | ret = reg_write(client, MT9T031_SHUTTER_WIDTH_UPPER, data >> 16); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 125 | |
| 126 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 127 | ret = reg_write(client, MT9T031_SHUTTER_WIDTH, data & 0xffff); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 132 | static int get_shutter(struct i2c_client *client, u32 *data) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 133 | { |
| 134 | int ret; |
| 135 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 136 | ret = reg_read(client, MT9T031_SHUTTER_WIDTH_UPPER); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 137 | *data = ret << 16; |
| 138 | |
| 139 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 140 | ret = reg_read(client, MT9T031_SHUTTER_WIDTH); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 141 | *data |= ret & 0xffff; |
| 142 | |
| 143 | return ret < 0 ? ret : 0; |
| 144 | } |
| 145 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 146 | static int mt9t031_idle(struct i2c_client *client) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 147 | { |
| 148 | int ret; |
| 149 | |
| 150 | /* Disable chip output, synchronous option update */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 151 | ret = reg_write(client, MT9T031_RESET, 1); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 152 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 153 | ret = reg_write(client, MT9T031_RESET, 0); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 154 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 155 | ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 156 | |
| 157 | return ret >= 0 ? 0 : -EIO; |
| 158 | } |
| 159 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 160 | static int mt9t031_disable(struct i2c_client *client) |
| 161 | { |
| 162 | /* Disable the chip */ |
| 163 | reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 168 | static int mt9t031_s_stream(struct v4l2_subdev *sd, int enable) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 169 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 170 | struct i2c_client *client = sd->priv; |
| 171 | int ret; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 172 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 173 | if (enable) |
| 174 | /* Switch to master "normal" mode */ |
| 175 | ret = reg_set(client, MT9T031_OUTPUT_CONTROL, 2); |
| 176 | else |
| 177 | /* Stop sensor readout */ |
| 178 | ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 2); |
| 179 | |
| 180 | if (ret < 0) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 181 | return -EIO; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 182 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int mt9t031_set_bus_param(struct soc_camera_device *icd, |
| 187 | unsigned long flags) |
| 188 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 189 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 190 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 191 | /* The caller should have queried our parameters, check anyway */ |
| 192 | if (flags & ~MT9T031_BUS_PARAM) |
| 193 | return -EINVAL; |
| 194 | |
| 195 | if (flags & SOCAM_PCLK_SAMPLE_FALLING) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 196 | reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); |
Philippe Rétornaz | c98afbf | 2009-03-13 09:42:32 -0300 | [diff] [blame] | 197 | else |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 198 | reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static unsigned long mt9t031_query_bus_param(struct soc_camera_device *icd) |
| 204 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 205 | struct soc_camera_link *icl = to_soc_camera_link(icd); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 206 | |
| 207 | return soc_camera_apply_sensor_flags(icl, MT9T031_BUS_PARAM); |
| 208 | } |
| 209 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 210 | /* target must be _even_ */ |
| 211 | static u16 mt9t031_skip(s32 *source, s32 target, s32 max) |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 212 | { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 213 | unsigned int skip; |
| 214 | |
| 215 | if (*source < target + target / 2) { |
| 216 | *source = target; |
| 217 | return 1; |
| 218 | } |
| 219 | |
| 220 | skip = min(max, *source + target / 2) / target; |
| 221 | if (skip > 8) |
| 222 | skip = 8; |
| 223 | *source = target * skip; |
| 224 | |
| 225 | return skip; |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 226 | } |
| 227 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 228 | /* rect is the sensor rectangle, the caller guarantees parameter validity */ |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 229 | static int mt9t031_set_params(struct soc_camera_device *icd, |
| 230 | struct v4l2_rect *rect, u16 xskip, u16 yskip) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 231 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 232 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 233 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 234 | int ret; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 235 | u16 xbin, ybin; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 236 | const u16 hblank = MT9T031_HORIZONTAL_BLANK, |
| 237 | vblank = MT9T031_VERTICAL_BLANK; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 238 | |
| 239 | xbin = min(xskip, (u16)3); |
| 240 | ybin = min(yskip, (u16)3); |
| 241 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 242 | /* |
| 243 | * Could just do roundup(rect->left, [xy]bin * 2); but this is cheaper. |
| 244 | * There is always a valid suitably aligned value. The worst case is |
| 245 | * xbin = 3, width = 2048. Then we will start at 36, the last read out |
| 246 | * pixel will be 2083, which is < 2085 - first black pixel. |
| 247 | * |
| 248 | * MT9T031 datasheet imposes window left border alignment, depending on |
| 249 | * the selected xskip. Failing to conform to this requirement produces |
| 250 | * dark horizontal stripes in the image. However, even obeying to this |
| 251 | * requirement doesn't eliminate the stripes in all configurations. They |
| 252 | * appear "locally reproducibly," but can differ between tests under |
| 253 | * different lighting conditions. |
| 254 | */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 255 | switch (xbin) { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 256 | case 1: |
| 257 | rect->left &= ~1; |
| 258 | break; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 259 | case 2: |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 260 | rect->left &= ~3; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 261 | break; |
| 262 | case 3: |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 263 | rect->left = rect->left > roundup(MT9T031_COLUMN_SKIP, 6) ? |
| 264 | (rect->left / 6) * 6 : roundup(MT9T031_COLUMN_SKIP, 6); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 265 | } |
| 266 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 267 | rect->top &= ~1; |
| 268 | |
| 269 | dev_dbg(&client->dev, "skip %u:%u, rect %ux%u@%u:%u\n", |
| 270 | xskip, yskip, rect->width, rect->height, rect->left, rect->top); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 271 | |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 272 | /* Disable register update, reconfigure atomically */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 273 | ret = reg_set(client, MT9T031_OUTPUT_CONTROL, 1); |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 274 | if (ret < 0) |
| 275 | return ret; |
| 276 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 277 | /* Blanking and start values - default... */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 278 | ret = reg_write(client, MT9T031_HORIZONTAL_BLANKING, hblank); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 279 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 280 | ret = reg_write(client, MT9T031_VERTICAL_BLANKING, vblank); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 281 | |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 282 | if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) { |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 283 | /* Binning, skipping */ |
| 284 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 285 | ret = reg_write(client, MT9T031_COLUMN_ADDRESS_MODE, |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 286 | ((xbin - 1) << 4) | (xskip - 1)); |
| 287 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 288 | ret = reg_write(client, MT9T031_ROW_ADDRESS_MODE, |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 289 | ((ybin - 1) << 4) | (yskip - 1)); |
| 290 | } |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 291 | dev_dbg(&client->dev, "new physical left %u, top %u\n", |
| 292 | rect->left, rect->top); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 293 | |
| 294 | /* The caller provides a supported format, as guaranteed by |
| 295 | * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() */ |
| 296 | if (ret >= 0) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 297 | ret = reg_write(client, MT9T031_COLUMN_START, rect->left); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 298 | if (ret >= 0) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 299 | ret = reg_write(client, MT9T031_ROW_START, rect->top); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 300 | if (ret >= 0) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 301 | ret = reg_write(client, MT9T031_WINDOW_WIDTH, rect->width - 1); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 302 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 303 | ret = reg_write(client, MT9T031_WINDOW_HEIGHT, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 304 | rect->height + icd->y_skip_top - 1); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 305 | if (ret >= 0 && mt9t031->autoexposure) { |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 306 | unsigned int total_h = rect->height + icd->y_skip_top + vblank; |
| 307 | ret = set_shutter(client, total_h); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 308 | if (ret >= 0) { |
| 309 | const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; |
| 310 | const struct v4l2_queryctrl *qctrl = |
| 311 | soc_camera_find_qctrl(icd->ops, |
| 312 | V4L2_CID_EXPOSURE); |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 313 | mt9t031->exposure = (shutter_max / 2 + (total_h - 1) * |
| 314 | (qctrl->maximum - qctrl->minimum)) / |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 315 | shutter_max + qctrl->minimum; |
| 316 | } |
| 317 | } |
| 318 | |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 319 | /* Re-enable register update, commit all changes */ |
| 320 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 321 | ret = reg_clear(client, MT9T031_OUTPUT_CONTROL, 1); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 322 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 323 | if (ret >= 0) { |
| 324 | mt9t031->rect = *rect; |
| 325 | mt9t031->xskip = xskip; |
| 326 | mt9t031->yskip = yskip; |
| 327 | } |
| 328 | |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 329 | return ret < 0 ? ret : 0; |
| 330 | } |
| 331 | |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 332 | static int mt9t031_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 333 | { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 334 | struct v4l2_rect rect = a->c; |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 335 | struct i2c_client *client = sd->priv; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 336 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 337 | struct soc_camera_device *icd = client->dev.platform_data; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 338 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 339 | rect.width = ALIGN(rect.width, 2); |
| 340 | rect.height = ALIGN(rect.height, 2); |
Guennadi Liakhovetski | e330919 | 2009-08-25 11:46:42 -0300 | [diff] [blame] | 341 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 342 | soc_camera_limit_side(&rect.left, &rect.width, |
| 343 | MT9T031_COLUMN_SKIP, MT9T031_MIN_WIDTH, MT9T031_MAX_WIDTH); |
Guennadi Liakhovetski | e330919 | 2009-08-25 11:46:42 -0300 | [diff] [blame] | 344 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 345 | soc_camera_limit_side(&rect.top, &rect.height, |
| 346 | MT9T031_ROW_SKIP, MT9T031_MIN_HEIGHT, MT9T031_MAX_HEIGHT); |
| 347 | |
| 348 | return mt9t031_set_params(icd, &rect, mt9t031->xskip, mt9t031->yskip); |
| 349 | } |
| 350 | |
| 351 | static int mt9t031_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
| 352 | { |
| 353 | struct i2c_client *client = sd->priv; |
| 354 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
| 355 | |
| 356 | a->c = mt9t031->rect; |
| 357 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | static int mt9t031_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) |
| 363 | { |
| 364 | a->bounds.left = MT9T031_COLUMN_SKIP; |
| 365 | a->bounds.top = MT9T031_ROW_SKIP; |
| 366 | a->bounds.width = MT9T031_MAX_WIDTH; |
| 367 | a->bounds.height = MT9T031_MAX_HEIGHT; |
| 368 | a->defrect = a->bounds; |
| 369 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 370 | a->pixelaspect.numerator = 1; |
| 371 | a->pixelaspect.denominator = 1; |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static int mt9t031_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) |
| 377 | { |
| 378 | struct i2c_client *client = sd->priv; |
| 379 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
| 380 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 381 | |
| 382 | pix->width = mt9t031->rect.width / mt9t031->xskip; |
| 383 | pix->height = mt9t031->rect.height / mt9t031->yskip; |
| 384 | pix->pixelformat = V4L2_PIX_FMT_SGRBG10; |
| 385 | pix->field = V4L2_FIELD_NONE; |
| 386 | pix->colorspace = V4L2_COLORSPACE_SRGB; |
| 387 | |
| 388 | return 0; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 389 | } |
| 390 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 391 | static int mt9t031_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 392 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 393 | struct i2c_client *client = sd->priv; |
| 394 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
| 395 | struct soc_camera_device *icd = client->dev.platform_data; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 396 | struct v4l2_pix_format *pix = &f->fmt.pix; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 397 | u16 xskip, yskip; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 398 | struct v4l2_rect rect = mt9t031->rect; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 399 | |
| 400 | /* |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 401 | * try_fmt has put width and height within limits. |
| 402 | * S_FMT: use binning and skipping for scaling |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 403 | */ |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 404 | xskip = mt9t031_skip(&rect.width, pix->width, MT9T031_MAX_WIDTH); |
| 405 | yskip = mt9t031_skip(&rect.height, pix->height, MT9T031_MAX_HEIGHT); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 406 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 407 | /* mt9t031_set_params() doesn't change width and height */ |
| 408 | return mt9t031_set_params(icd, &rect, xskip, yskip); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 409 | } |
| 410 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 411 | /* |
| 412 | * If a user window larger than sensor window is requested, we'll increase the |
| 413 | * sensor window. |
| 414 | */ |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 415 | static int mt9t031_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 416 | { |
| 417 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 418 | |
Trent Piepho | 653dc59 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 419 | v4l_bound_align_image( |
| 420 | &pix->width, MT9T031_MIN_WIDTH, MT9T031_MAX_WIDTH, 1, |
| 421 | &pix->height, MT9T031_MIN_HEIGHT, MT9T031_MAX_HEIGHT, 1, 0); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 426 | static int mt9t031_g_chip_ident(struct v4l2_subdev *sd, |
| 427 | struct v4l2_dbg_chip_ident *id) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 428 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 429 | struct i2c_client *client = sd->priv; |
| 430 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 431 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 432 | if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 433 | return -EINVAL; |
| 434 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 435 | if (id->match.addr != client->addr) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 436 | return -ENODEV; |
| 437 | |
| 438 | id->ident = mt9t031->model; |
| 439 | id->revision = 0; |
| 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 445 | static int mt9t031_g_register(struct v4l2_subdev *sd, |
| 446 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 447 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 448 | struct i2c_client *client = sd->priv; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 449 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 450 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 451 | return -EINVAL; |
| 452 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 453 | if (reg->match.addr != client->addr) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 454 | return -ENODEV; |
| 455 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 456 | reg->val = reg_read(client, reg->reg); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 457 | |
| 458 | if (reg->val > 0xffff) |
| 459 | return -EIO; |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 464 | static int mt9t031_s_register(struct v4l2_subdev *sd, |
| 465 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 466 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 467 | struct i2c_client *client = sd->priv; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 468 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 469 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 470 | return -EINVAL; |
| 471 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 472 | if (reg->match.addr != client->addr) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 473 | return -ENODEV; |
| 474 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 475 | if (reg_write(client, reg->reg, reg->val) < 0) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 476 | return -EIO; |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | #endif |
| 481 | |
| 482 | static const struct v4l2_queryctrl mt9t031_controls[] = { |
| 483 | { |
| 484 | .id = V4L2_CID_VFLIP, |
| 485 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 486 | .name = "Flip Vertically", |
| 487 | .minimum = 0, |
| 488 | .maximum = 1, |
| 489 | .step = 1, |
| 490 | .default_value = 0, |
| 491 | }, { |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 492 | .id = V4L2_CID_HFLIP, |
| 493 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 494 | .name = "Flip Horizontally", |
| 495 | .minimum = 0, |
| 496 | .maximum = 1, |
| 497 | .step = 1, |
| 498 | .default_value = 0, |
| 499 | }, { |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 500 | .id = V4L2_CID_GAIN, |
| 501 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 502 | .name = "Gain", |
| 503 | .minimum = 0, |
| 504 | .maximum = 127, |
| 505 | .step = 1, |
| 506 | .default_value = 64, |
| 507 | .flags = V4L2_CTRL_FLAG_SLIDER, |
| 508 | }, { |
| 509 | .id = V4L2_CID_EXPOSURE, |
| 510 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 511 | .name = "Exposure", |
| 512 | .minimum = 1, |
| 513 | .maximum = 255, |
| 514 | .step = 1, |
| 515 | .default_value = 255, |
| 516 | .flags = V4L2_CTRL_FLAG_SLIDER, |
| 517 | }, { |
| 518 | .id = V4L2_CID_EXPOSURE_AUTO, |
| 519 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 520 | .name = "Automatic Exposure", |
| 521 | .minimum = 0, |
| 522 | .maximum = 1, |
| 523 | .step = 1, |
| 524 | .default_value = 1, |
| 525 | } |
| 526 | }; |
| 527 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 528 | static struct soc_camera_ops mt9t031_ops = { |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 529 | .set_bus_param = mt9t031_set_bus_param, |
| 530 | .query_bus_param = mt9t031_query_bus_param, |
| 531 | .controls = mt9t031_controls, |
| 532 | .num_controls = ARRAY_SIZE(mt9t031_controls), |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 533 | }; |
| 534 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 535 | static int mt9t031_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 536 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 537 | struct i2c_client *client = sd->priv; |
| 538 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 539 | int data; |
| 540 | |
| 541 | switch (ctrl->id) { |
| 542 | case V4L2_CID_VFLIP: |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 543 | data = reg_read(client, MT9T031_READ_MODE_2); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 544 | if (data < 0) |
| 545 | return -EIO; |
| 546 | ctrl->value = !!(data & 0x8000); |
| 547 | break; |
| 548 | case V4L2_CID_HFLIP: |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 549 | data = reg_read(client, MT9T031_READ_MODE_2); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 550 | if (data < 0) |
| 551 | return -EIO; |
| 552 | ctrl->value = !!(data & 0x4000); |
| 553 | break; |
| 554 | case V4L2_CID_EXPOSURE_AUTO: |
| 555 | ctrl->value = mt9t031->autoexposure; |
| 556 | break; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 557 | case V4L2_CID_GAIN: |
| 558 | ctrl->value = mt9t031->gain; |
| 559 | break; |
| 560 | case V4L2_CID_EXPOSURE: |
| 561 | ctrl->value = mt9t031->exposure; |
| 562 | break; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 563 | } |
| 564 | return 0; |
| 565 | } |
| 566 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 567 | static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 568 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 569 | struct i2c_client *client = sd->priv; |
| 570 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
| 571 | struct soc_camera_device *icd = client->dev.platform_data; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 572 | const struct v4l2_queryctrl *qctrl; |
| 573 | int data; |
| 574 | |
| 575 | qctrl = soc_camera_find_qctrl(&mt9t031_ops, ctrl->id); |
| 576 | |
| 577 | if (!qctrl) |
| 578 | return -EINVAL; |
| 579 | |
| 580 | switch (ctrl->id) { |
| 581 | case V4L2_CID_VFLIP: |
| 582 | if (ctrl->value) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 583 | data = reg_set(client, MT9T031_READ_MODE_2, 0x8000); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 584 | else |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 585 | data = reg_clear(client, MT9T031_READ_MODE_2, 0x8000); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 586 | if (data < 0) |
| 587 | return -EIO; |
| 588 | break; |
| 589 | case V4L2_CID_HFLIP: |
| 590 | if (ctrl->value) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 591 | data = reg_set(client, MT9T031_READ_MODE_2, 0x4000); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 592 | else |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 593 | data = reg_clear(client, MT9T031_READ_MODE_2, 0x4000); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 594 | if (data < 0) |
| 595 | return -EIO; |
| 596 | break; |
| 597 | case V4L2_CID_GAIN: |
| 598 | if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum) |
| 599 | return -EINVAL; |
| 600 | /* See Datasheet Table 7, Gain settings. */ |
| 601 | if (ctrl->value <= qctrl->default_value) { |
| 602 | /* Pack it into 0..1 step 0.125, register values 0..8 */ |
| 603 | unsigned long range = qctrl->default_value - qctrl->minimum; |
| 604 | data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; |
| 605 | |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 606 | dev_dbg(&client->dev, "Setting gain %d\n", data); |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 607 | data = reg_write(client, MT9T031_GLOBAL_GAIN, data); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 608 | if (data < 0) |
| 609 | return -EIO; |
| 610 | } else { |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 611 | /* Pack it into 1.125..128 variable step, register values 9..0x7860 */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 612 | /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */ |
| 613 | unsigned long range = qctrl->maximum - qctrl->default_value - 1; |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 614 | /* calculated gain: map 65..127 to 9..1024 step 0.125 */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 615 | unsigned long gain = ((ctrl->value - qctrl->default_value - 1) * |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 616 | 1015 + range / 2) / range + 9; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 617 | |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 618 | if (gain <= 32) /* calculated gain 9..32 -> 9..32 */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 619 | data = gain; |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 620 | else if (gain <= 64) /* calculated gain 33..64 -> 0x51..0x60 */ |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 621 | data = ((gain - 32) * 16 + 16) / 32 + 80; |
| 622 | else |
Guennadi Liakhovetski | 70e1d35 | 2009-02-23 12:13:23 -0300 | [diff] [blame] | 623 | /* calculated gain 65..1024 -> (1..120) << 8 + 0x60 */ |
| 624 | data = (((gain - 64 + 7) * 32) & 0xff00) | 0x60; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 625 | |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 626 | dev_dbg(&client->dev, "Set gain from 0x%x to 0x%x\n", |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 627 | reg_read(client, MT9T031_GLOBAL_GAIN), data); |
| 628 | data = reg_write(client, MT9T031_GLOBAL_GAIN, data); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 629 | if (data < 0) |
| 630 | return -EIO; |
| 631 | } |
| 632 | |
| 633 | /* Success */ |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 634 | mt9t031->gain = ctrl->value; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 635 | break; |
| 636 | case V4L2_CID_EXPOSURE: |
| 637 | /* mt9t031 has maximum == default */ |
| 638 | if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum) |
| 639 | return -EINVAL; |
| 640 | else { |
| 641 | const unsigned long range = qctrl->maximum - qctrl->minimum; |
| 642 | const u32 shutter = ((ctrl->value - qctrl->minimum) * 1048 + |
| 643 | range / 2) / range + 1; |
| 644 | u32 old; |
| 645 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 646 | get_shutter(client, &old); |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 647 | dev_dbg(&client->dev, "Set shutter from %u to %u\n", |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 648 | old, shutter); |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 649 | if (set_shutter(client, shutter) < 0) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 650 | return -EIO; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 651 | mt9t031->exposure = ctrl->value; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 652 | mt9t031->autoexposure = 0; |
| 653 | } |
| 654 | break; |
| 655 | case V4L2_CID_EXPOSURE_AUTO: |
| 656 | if (ctrl->value) { |
| 657 | const u16 vblank = MT9T031_VERTICAL_BLANK; |
| 658 | const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 659 | unsigned int total_h = mt9t031->rect.height + |
| 660 | icd->y_skip_top + vblank; |
| 661 | |
| 662 | if (set_shutter(client, total_h) < 0) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 663 | return -EIO; |
| 664 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 665 | mt9t031->exposure = (shutter_max / 2 + (total_h - 1) * |
| 666 | (qctrl->maximum - qctrl->minimum)) / |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 667 | shutter_max + qctrl->minimum; |
| 668 | mt9t031->autoexposure = 1; |
| 669 | } else |
| 670 | mt9t031->autoexposure = 0; |
| 671 | break; |
| 672 | } |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | /* Interface active, can use i2c. If it fails, it can indeed mean, that |
| 677 | * this wasn't our capture interface, so, we wait for the right one */ |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 678 | static int mt9t031_video_probe(struct i2c_client *client) |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 679 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 680 | struct soc_camera_device *icd = client->dev.platform_data; |
| 681 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 682 | s32 data; |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 683 | int ret; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 684 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 685 | /* Enable the chip */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 686 | data = reg_write(client, MT9T031_CHIP_ENABLE, 1); |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 687 | dev_dbg(&client->dev, "write: %d\n", data); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 688 | |
| 689 | /* Read out the chip version register */ |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 690 | data = reg_read(client, MT9T031_CHIP_VERSION); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 691 | |
| 692 | switch (data) { |
| 693 | case 0x1621: |
| 694 | mt9t031->model = V4L2_IDENT_MT9T031; |
| 695 | icd->formats = mt9t031_colour_formats; |
| 696 | icd->num_formats = ARRAY_SIZE(mt9t031_colour_formats); |
| 697 | break; |
| 698 | default: |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 699 | dev_err(&client->dev, |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 700 | "No MT9T031 chip detected, register read %x\n", data); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 701 | return -ENODEV; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 702 | } |
| 703 | |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 704 | dev_info(&client->dev, "Detected a MT9T031 chip ID %x\n", data); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 705 | |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 706 | ret = mt9t031_idle(client); |
| 707 | if (ret < 0) |
| 708 | dev_err(&client->dev, "Failed to initialise the camera\n"); |
| 709 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 710 | /* mt9t031_idle() has reset the chip to default. */ |
| 711 | mt9t031->exposure = 255; |
| 712 | mt9t031->gain = 64; |
| 713 | |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 714 | return ret; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 715 | } |
| 716 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 717 | static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = { |
| 718 | .g_ctrl = mt9t031_g_ctrl, |
| 719 | .s_ctrl = mt9t031_s_ctrl, |
| 720 | .g_chip_ident = mt9t031_g_chip_ident, |
| 721 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 722 | .g_register = mt9t031_g_register, |
| 723 | .s_register = mt9t031_s_register, |
| 724 | #endif |
| 725 | }; |
| 726 | |
| 727 | static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = { |
| 728 | .s_stream = mt9t031_s_stream, |
| 729 | .s_fmt = mt9t031_s_fmt, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 730 | .g_fmt = mt9t031_g_fmt, |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 731 | .try_fmt = mt9t031_try_fmt, |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 732 | .s_crop = mt9t031_s_crop, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 733 | .g_crop = mt9t031_g_crop, |
| 734 | .cropcap = mt9t031_cropcap, |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 735 | }; |
| 736 | |
| 737 | static struct v4l2_subdev_ops mt9t031_subdev_ops = { |
| 738 | .core = &mt9t031_subdev_core_ops, |
| 739 | .video = &mt9t031_subdev_video_ops, |
| 740 | }; |
| 741 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 742 | static int mt9t031_probe(struct i2c_client *client, |
| 743 | const struct i2c_device_id *did) |
| 744 | { |
| 745 | struct mt9t031 *mt9t031; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 746 | struct soc_camera_device *icd = client->dev.platform_data; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 747 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 748 | struct soc_camera_link *icl; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 749 | int ret; |
| 750 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 751 | if (!icd) { |
| 752 | dev_err(&client->dev, "MT9T031: missing soc-camera data!\n"); |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
| 756 | icl = to_soc_camera_link(icd); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 757 | if (!icl) { |
| 758 | dev_err(&client->dev, "MT9T031 driver needs platform data\n"); |
| 759 | return -EINVAL; |
| 760 | } |
| 761 | |
| 762 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) { |
| 763 | dev_warn(&adapter->dev, |
| 764 | "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n"); |
| 765 | return -EIO; |
| 766 | } |
| 767 | |
| 768 | mt9t031 = kzalloc(sizeof(struct mt9t031), GFP_KERNEL); |
| 769 | if (!mt9t031) |
| 770 | return -ENOMEM; |
| 771 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 772 | v4l2_i2c_subdev_init(&mt9t031->subdev, client, &mt9t031_subdev_ops); |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 773 | |
| 774 | /* Second stage probe - when a capture adapter is there */ |
Guennadi Liakhovetski | a0705b0 | 2009-08-25 11:46:17 -0300 | [diff] [blame] | 775 | icd->ops = &mt9t031_ops; |
Guennadi Liakhovetski | a0705b0 | 2009-08-25 11:46:17 -0300 | [diff] [blame] | 776 | icd->y_skip_top = 0; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 777 | |
| 778 | mt9t031->rect.left = MT9T031_COLUMN_SKIP; |
| 779 | mt9t031->rect.top = MT9T031_ROW_SKIP; |
| 780 | mt9t031->rect.width = MT9T031_MAX_WIDTH; |
| 781 | mt9t031->rect.height = MT9T031_MAX_HEIGHT; |
| 782 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 783 | /* Simulated autoexposure. If enabled, we calculate shutter width |
| 784 | * ourselves in the driver based on vertical blanking and frame width */ |
| 785 | mt9t031->autoexposure = 1; |
| 786 | |
| 787 | mt9t031->xskip = 1; |
| 788 | mt9t031->yskip = 1; |
| 789 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 790 | mt9t031_idle(client); |
| 791 | |
| 792 | ret = mt9t031_video_probe(client); |
| 793 | |
| 794 | mt9t031_disable(client); |
| 795 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 796 | if (ret) { |
| 797 | icd->ops = NULL; |
| 798 | i2c_set_clientdata(client, NULL); |
| 799 | kfree(mt9t031); |
| 800 | } |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 801 | |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | static int mt9t031_remove(struct i2c_client *client) |
| 806 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 807 | struct mt9t031 *mt9t031 = to_mt9t031(client); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 808 | struct soc_camera_device *icd = client->dev.platform_data; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 809 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 810 | icd->ops = NULL; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 811 | i2c_set_clientdata(client, NULL); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 812 | client->driver = NULL; |
Guennadi Liakhovetski | 4e96fd0 | 2008-12-29 06:04:59 -0300 | [diff] [blame] | 813 | kfree(mt9t031); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static const struct i2c_device_id mt9t031_id[] = { |
| 819 | { "mt9t031", 0 }, |
| 820 | { } |
| 821 | }; |
| 822 | MODULE_DEVICE_TABLE(i2c, mt9t031_id); |
| 823 | |
| 824 | static struct i2c_driver mt9t031_i2c_driver = { |
| 825 | .driver = { |
| 826 | .name = "mt9t031", |
| 827 | }, |
| 828 | .probe = mt9t031_probe, |
| 829 | .remove = mt9t031_remove, |
| 830 | .id_table = mt9t031_id, |
| 831 | }; |
| 832 | |
| 833 | static int __init mt9t031_mod_init(void) |
| 834 | { |
| 835 | return i2c_add_driver(&mt9t031_i2c_driver); |
| 836 | } |
| 837 | |
| 838 | static void __exit mt9t031_mod_exit(void) |
| 839 | { |
| 840 | i2c_del_driver(&mt9t031_i2c_driver); |
| 841 | } |
| 842 | |
| 843 | module_init(mt9t031_mod_init); |
| 844 | module_exit(mt9t031_mod_exit); |
| 845 | |
| 846 | MODULE_DESCRIPTION("Micron MT9T031 Camera driver"); |
| 847 | MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>"); |
| 848 | MODULE_LICENSE("GPL v2"); |