Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1 | /* |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 2 | * Driver for MT9M111/MT9M112 CMOS Image Sensor from Micron |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/videodev2.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/i2c.h> |
| 13 | #include <linux/log2.h> |
| 14 | #include <linux/gpio.h> |
| 15 | #include <linux/delay.h> |
| 16 | |
| 17 | #include <media/v4l2-common.h> |
| 18 | #include <media/v4l2-chip-ident.h> |
| 19 | #include <media/soc_camera.h> |
| 20 | |
| 21 | /* |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 22 | * mt9m111 and mt9m112 i2c address is 0x5d or 0x48 (depending on SAddr pin) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 23 | * The platform has to define i2c_board_info and call i2c_register_board_info() |
| 24 | */ |
| 25 | |
| 26 | /* mt9m111: Sensor register addresses */ |
| 27 | #define MT9M111_CHIP_VERSION 0x000 |
| 28 | #define MT9M111_ROW_START 0x001 |
| 29 | #define MT9M111_COLUMN_START 0x002 |
| 30 | #define MT9M111_WINDOW_HEIGHT 0x003 |
| 31 | #define MT9M111_WINDOW_WIDTH 0x004 |
| 32 | #define MT9M111_HORIZONTAL_BLANKING_B 0x005 |
| 33 | #define MT9M111_VERTICAL_BLANKING_B 0x006 |
| 34 | #define MT9M111_HORIZONTAL_BLANKING_A 0x007 |
| 35 | #define MT9M111_VERTICAL_BLANKING_A 0x008 |
| 36 | #define MT9M111_SHUTTER_WIDTH 0x009 |
| 37 | #define MT9M111_ROW_SPEED 0x00a |
| 38 | #define MT9M111_EXTRA_DELAY 0x00b |
| 39 | #define MT9M111_SHUTTER_DELAY 0x00c |
| 40 | #define MT9M111_RESET 0x00d |
| 41 | #define MT9M111_READ_MODE_B 0x020 |
| 42 | #define MT9M111_READ_MODE_A 0x021 |
| 43 | #define MT9M111_FLASH_CONTROL 0x023 |
| 44 | #define MT9M111_GREEN1_GAIN 0x02b |
| 45 | #define MT9M111_BLUE_GAIN 0x02c |
| 46 | #define MT9M111_RED_GAIN 0x02d |
| 47 | #define MT9M111_GREEN2_GAIN 0x02e |
| 48 | #define MT9M111_GLOBAL_GAIN 0x02f |
| 49 | #define MT9M111_CONTEXT_CONTROL 0x0c8 |
| 50 | #define MT9M111_PAGE_MAP 0x0f0 |
| 51 | #define MT9M111_BYTE_WISE_ADDR 0x0f1 |
| 52 | |
| 53 | #define MT9M111_RESET_SYNC_CHANGES (1 << 15) |
| 54 | #define MT9M111_RESET_RESTART_BAD_FRAME (1 << 9) |
| 55 | #define MT9M111_RESET_SHOW_BAD_FRAMES (1 << 8) |
| 56 | #define MT9M111_RESET_RESET_SOC (1 << 5) |
| 57 | #define MT9M111_RESET_OUTPUT_DISABLE (1 << 4) |
| 58 | #define MT9M111_RESET_CHIP_ENABLE (1 << 3) |
| 59 | #define MT9M111_RESET_ANALOG_STANDBY (1 << 2) |
| 60 | #define MT9M111_RESET_RESTART_FRAME (1 << 1) |
| 61 | #define MT9M111_RESET_RESET_MODE (1 << 0) |
| 62 | |
| 63 | #define MT9M111_RMB_MIRROR_COLS (1 << 1) |
| 64 | #define MT9M111_RMB_MIRROR_ROWS (1 << 0) |
| 65 | #define MT9M111_CTXT_CTRL_RESTART (1 << 15) |
| 66 | #define MT9M111_CTXT_CTRL_DEFECTCOR_B (1 << 12) |
| 67 | #define MT9M111_CTXT_CTRL_RESIZE_B (1 << 10) |
| 68 | #define MT9M111_CTXT_CTRL_CTRL2_B (1 << 9) |
| 69 | #define MT9M111_CTXT_CTRL_GAMMA_B (1 << 8) |
| 70 | #define MT9M111_CTXT_CTRL_XENON_EN (1 << 7) |
| 71 | #define MT9M111_CTXT_CTRL_READ_MODE_B (1 << 3) |
| 72 | #define MT9M111_CTXT_CTRL_LED_FLASH_EN (1 << 2) |
| 73 | #define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1 << 1) |
| 74 | #define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1 << 0) |
| 75 | /* |
| 76 | * mt9m111: Colorpipe register addresses (0x100..0x1ff) |
| 77 | */ |
| 78 | #define MT9M111_OPER_MODE_CTRL 0x106 |
| 79 | #define MT9M111_OUTPUT_FORMAT_CTRL 0x108 |
| 80 | #define MT9M111_REDUCER_XZOOM_B 0x1a0 |
| 81 | #define MT9M111_REDUCER_XSIZE_B 0x1a1 |
| 82 | #define MT9M111_REDUCER_YZOOM_B 0x1a3 |
| 83 | #define MT9M111_REDUCER_YSIZE_B 0x1a4 |
| 84 | #define MT9M111_REDUCER_XZOOM_A 0x1a6 |
| 85 | #define MT9M111_REDUCER_XSIZE_A 0x1a7 |
| 86 | #define MT9M111_REDUCER_YZOOM_A 0x1a9 |
| 87 | #define MT9M111_REDUCER_YSIZE_A 0x1aa |
| 88 | |
| 89 | #define MT9M111_OUTPUT_FORMAT_CTRL2_A 0x13a |
| 90 | #define MT9M111_OUTPUT_FORMAT_CTRL2_B 0x19b |
| 91 | |
| 92 | #define MT9M111_OPMODE_AUTOEXPO_EN (1 << 14) |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 93 | #define MT9M111_OPMODE_AUTOWHITEBAL_EN (1 << 1) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 94 | |
| 95 | #define MT9M111_OUTFMT_PROCESSED_BAYER (1 << 14) |
| 96 | #define MT9M111_OUTFMT_BYPASS_IFP (1 << 10) |
| 97 | #define MT9M111_OUTFMT_INV_PIX_CLOCK (1 << 9) |
| 98 | #define MT9M111_OUTFMT_RGB (1 << 8) |
| 99 | #define MT9M111_OUTFMT_RGB565 (0x0 << 6) |
| 100 | #define MT9M111_OUTFMT_RGB555 (0x1 << 6) |
| 101 | #define MT9M111_OUTFMT_RGB444x (0x2 << 6) |
| 102 | #define MT9M111_OUTFMT_RGBx444 (0x3 << 6) |
| 103 | #define MT9M111_OUTFMT_TST_RAMP_OFF (0x0 << 4) |
| 104 | #define MT9M111_OUTFMT_TST_RAMP_COL (0x1 << 4) |
| 105 | #define MT9M111_OUTFMT_TST_RAMP_ROW (0x2 << 4) |
| 106 | #define MT9M111_OUTFMT_TST_RAMP_FRAME (0x3 << 4) |
| 107 | #define MT9M111_OUTFMT_SHIFT_3_UP (1 << 3) |
| 108 | #define MT9M111_OUTFMT_AVG_CHROMA (1 << 2) |
| 109 | #define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1 << 1) |
| 110 | #define MT9M111_OUTFMT_SWAP_RGB_EVEN (1 << 1) |
| 111 | #define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1 << 0) |
| 112 | /* |
| 113 | * mt9m111: Camera control register addresses (0x200..0x2ff not implemented) |
| 114 | */ |
| 115 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 116 | #define reg_read(reg) mt9m111_reg_read(client, MT9M111_##reg) |
| 117 | #define reg_write(reg, val) mt9m111_reg_write(client, MT9M111_##reg, (val)) |
| 118 | #define reg_set(reg, val) mt9m111_reg_set(client, MT9M111_##reg, (val)) |
| 119 | #define reg_clear(reg, val) mt9m111_reg_clear(client, MT9M111_##reg, (val)) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 120 | |
| 121 | #define MT9M111_MIN_DARK_ROWS 8 |
| 122 | #define MT9M111_MIN_DARK_COLS 24 |
| 123 | #define MT9M111_MAX_HEIGHT 1024 |
| 124 | #define MT9M111_MAX_WIDTH 1280 |
| 125 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 126 | /* MT9M111 has only one fixed colorspace per pixelcode */ |
| 127 | struct mt9m111_datafmt { |
| 128 | enum v4l2_mbus_pixelcode code; |
| 129 | enum v4l2_colorspace colorspace; |
| 130 | }; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 131 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 132 | /* Find a data format by a pixel code in an array */ |
| 133 | static const struct mt9m111_datafmt *mt9m111_find_datafmt( |
| 134 | enum v4l2_mbus_pixelcode code, const struct mt9m111_datafmt *fmt, |
| 135 | int n) |
| 136 | { |
| 137 | int i; |
| 138 | for (i = 0; i < n; i++) |
| 139 | if (fmt[i].code == code) |
| 140 | return fmt + i; |
| 141 | |
| 142 | return NULL; |
| 143 | } |
| 144 | |
| 145 | static const struct mt9m111_datafmt mt9m111_colour_fmts[] = { |
| 146 | {V4L2_MBUS_FMT_YUYV8_2X8_LE, V4L2_COLORSPACE_JPEG}, |
| 147 | {V4L2_MBUS_FMT_YVYU8_2X8_LE, V4L2_COLORSPACE_JPEG}, |
| 148 | {V4L2_MBUS_FMT_YUYV8_2X8_BE, V4L2_COLORSPACE_JPEG}, |
| 149 | {V4L2_MBUS_FMT_YVYU8_2X8_BE, V4L2_COLORSPACE_JPEG}, |
| 150 | {V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB}, |
| 151 | {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB}, |
| 152 | {V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB}, |
| 153 | {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB}, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | enum mt9m111_context { |
| 157 | HIGHPOWER = 0, |
| 158 | LOWPOWER, |
| 159 | }; |
| 160 | |
| 161 | struct mt9m111 { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 162 | struct v4l2_subdev subdev; |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 163 | int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */ |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 164 | enum mt9m111_context context; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 165 | struct v4l2_rect rect; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 166 | const struct mt9m111_datafmt *fmt; |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 167 | unsigned int gain; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 168 | unsigned char autoexposure; |
| 169 | unsigned char datawidth; |
| 170 | unsigned int powered:1; |
| 171 | unsigned int hflip:1; |
| 172 | unsigned int vflip:1; |
| 173 | unsigned int swap_rgb_even_odd:1; |
| 174 | unsigned int swap_rgb_red_blue:1; |
| 175 | unsigned int swap_yuv_y_chromas:1; |
| 176 | unsigned int swap_yuv_cb_cr:1; |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 177 | unsigned int autowhitebalance:1; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 178 | }; |
| 179 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 180 | static struct mt9m111 *to_mt9m111(const struct i2c_client *client) |
| 181 | { |
| 182 | return container_of(i2c_get_clientdata(client), struct mt9m111, subdev); |
| 183 | } |
| 184 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 185 | static int reg_page_map_set(struct i2c_client *client, const u16 reg) |
| 186 | { |
| 187 | int ret; |
| 188 | u16 page; |
| 189 | static int lastpage = -1; /* PageMap cache value */ |
| 190 | |
| 191 | page = (reg >> 8); |
| 192 | if (page == lastpage) |
| 193 | return 0; |
| 194 | if (page > 2) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | ret = i2c_smbus_write_word_data(client, MT9M111_PAGE_MAP, swab16(page)); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 198 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 199 | lastpage = page; |
| 200 | return ret; |
| 201 | } |
| 202 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 203 | static int mt9m111_reg_read(struct i2c_client *client, const u16 reg) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 204 | { |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 205 | int ret; |
| 206 | |
| 207 | ret = reg_page_map_set(client, reg); |
| 208 | if (!ret) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 209 | ret = swab16(i2c_smbus_read_word_data(client, reg & 0xff)); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 210 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 211 | dev_dbg(&client->dev, "read reg.%03x -> %04x\n", reg, ret); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 212 | return ret; |
| 213 | } |
| 214 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 215 | static int mt9m111_reg_write(struct i2c_client *client, const u16 reg, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 216 | const u16 data) |
| 217 | { |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 218 | int ret; |
| 219 | |
| 220 | ret = reg_page_map_set(client, reg); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 221 | if (!ret) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 222 | ret = i2c_smbus_write_word_data(client, reg & 0xff, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 223 | swab16(data)); |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 224 | dev_dbg(&client->dev, "write reg.%03x = %04x -> %d\n", reg, data, ret); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 225 | return ret; |
| 226 | } |
| 227 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 228 | static int mt9m111_reg_set(struct i2c_client *client, const u16 reg, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 229 | const u16 data) |
| 230 | { |
| 231 | int ret; |
| 232 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 233 | ret = mt9m111_reg_read(client, reg); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 234 | if (ret >= 0) |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 235 | ret = mt9m111_reg_write(client, reg, ret | data); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 236 | return ret; |
| 237 | } |
| 238 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 239 | static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 240 | const u16 data) |
| 241 | { |
| 242 | int ret; |
| 243 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 244 | ret = mt9m111_reg_read(client, reg); |
| 245 | return mt9m111_reg_write(client, reg, ret & ~data); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 246 | } |
| 247 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 248 | static int mt9m111_set_context(struct i2c_client *client, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 249 | enum mt9m111_context ctxt) |
| 250 | { |
| 251 | int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B |
| 252 | | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B |
| 253 | | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B |
| 254 | | MT9M111_CTXT_CTRL_VBLANK_SEL_B |
| 255 | | MT9M111_CTXT_CTRL_HBLANK_SEL_B; |
| 256 | int valA = MT9M111_CTXT_CTRL_RESTART; |
| 257 | |
| 258 | if (ctxt == HIGHPOWER) |
| 259 | return reg_write(CONTEXT_CONTROL, valB); |
| 260 | else |
| 261 | return reg_write(CONTEXT_CONTROL, valA); |
| 262 | } |
| 263 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 264 | static int mt9m111_setup_rect(struct i2c_client *client, |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 265 | struct v4l2_rect *rect) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 266 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 267 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 268 | int ret, is_raw_format; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 269 | int width = rect->width; |
| 270 | int height = rect->height; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 271 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 272 | if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 || |
| 273 | mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 274 | is_raw_format = 1; |
| 275 | else |
| 276 | is_raw_format = 0; |
| 277 | |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 278 | ret = reg_write(COLUMN_START, rect->left); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 279 | if (!ret) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 280 | ret = reg_write(ROW_START, rect->top); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 281 | |
| 282 | if (is_raw_format) { |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 283 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 284 | ret = reg_write(WINDOW_WIDTH, width); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 285 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 286 | ret = reg_write(WINDOW_HEIGHT, height); |
| 287 | } else { |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 288 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 289 | ret = reg_write(REDUCER_XZOOM_B, MT9M111_MAX_WIDTH); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 290 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 291 | ret = reg_write(REDUCER_YZOOM_B, MT9M111_MAX_HEIGHT); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 292 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 293 | ret = reg_write(REDUCER_XSIZE_B, width); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 294 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 295 | ret = reg_write(REDUCER_YSIZE_B, height); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 296 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 297 | ret = reg_write(REDUCER_XZOOM_A, MT9M111_MAX_WIDTH); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 298 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 299 | ret = reg_write(REDUCER_YZOOM_A, MT9M111_MAX_HEIGHT); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 300 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 301 | ret = reg_write(REDUCER_XSIZE_A, width); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 302 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 303 | ret = reg_write(REDUCER_YSIZE_A, height); |
| 304 | } |
| 305 | |
| 306 | return ret; |
| 307 | } |
| 308 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 309 | static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 310 | { |
| 311 | int ret; |
| 312 | |
| 313 | ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 314 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 315 | ret = reg_write(OUTPUT_FORMAT_CTRL2_B, outfmt); |
| 316 | return ret; |
| 317 | } |
| 318 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 319 | static int mt9m111_setfmt_bayer8(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 320 | { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 321 | return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER | |
| 322 | MT9M111_OUTFMT_RGB); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 323 | } |
| 324 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 325 | static int mt9m111_setfmt_bayer10(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 326 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 327 | return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 328 | } |
| 329 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 330 | static int mt9m111_setfmt_rgb565(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 331 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 332 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 333 | int val = 0; |
| 334 | |
| 335 | if (mt9m111->swap_rgb_red_blue) |
| 336 | val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; |
| 337 | if (mt9m111->swap_rgb_even_odd) |
| 338 | val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; |
| 339 | val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565; |
| 340 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 341 | return mt9m111_setup_pixfmt(client, val); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 342 | } |
| 343 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 344 | static int mt9m111_setfmt_rgb555(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 345 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 346 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 347 | int val = 0; |
| 348 | |
| 349 | if (mt9m111->swap_rgb_red_blue) |
| 350 | val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; |
| 351 | if (mt9m111->swap_rgb_even_odd) |
| 352 | val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; |
| 353 | val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555; |
| 354 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 355 | return mt9m111_setup_pixfmt(client, val); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 356 | } |
| 357 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 358 | static int mt9m111_setfmt_yuv(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 359 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 360 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 361 | int val = 0; |
| 362 | |
| 363 | if (mt9m111->swap_yuv_cb_cr) |
| 364 | val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; |
| 365 | if (mt9m111->swap_yuv_y_chromas) |
| 366 | val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y; |
| 367 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 368 | return mt9m111_setup_pixfmt(client, val); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 369 | } |
| 370 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 371 | static int mt9m111_enable(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 372 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 373 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 374 | int ret; |
| 375 | |
| 376 | ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 377 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 378 | mt9m111->powered = 1; |
| 379 | return ret; |
| 380 | } |
| 381 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 382 | static int mt9m111_reset(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 383 | { |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 384 | int ret; |
| 385 | |
| 386 | ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 387 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 388 | ret = reg_set(RESET, MT9M111_RESET_RESET_SOC); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 389 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 390 | ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE |
| 391 | | MT9M111_RESET_RESET_SOC); |
Antonio Ospite | afb1368 | 2009-02-23 12:13:24 -0300 | [diff] [blame] | 392 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 393 | return ret; |
| 394 | } |
| 395 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 396 | static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd) |
| 397 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 398 | struct soc_camera_link *icl = to_soc_camera_link(icd); |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 399 | unsigned long flags = SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 400 | SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | |
Guennadi Liakhovetski | 2d9329f | 2009-02-23 12:12:58 -0300 | [diff] [blame] | 401 | SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8; |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 402 | |
| 403 | return soc_camera_apply_sensor_flags(icl, flags); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f) |
| 407 | { |
| 408 | return 0; |
| 409 | } |
| 410 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 411 | static int mt9m111_make_rect(struct i2c_client *client, |
| 412 | struct v4l2_rect *rect) |
| 413 | { |
| 414 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
| 415 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 416 | if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 || |
| 417 | mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 418 | /* Bayer format - even size lengths */ |
| 419 | rect->width = ALIGN(rect->width, 2); |
| 420 | rect->height = ALIGN(rect->height, 2); |
| 421 | /* Let the user play with the starting pixel */ |
| 422 | } |
| 423 | |
| 424 | /* FIXME: the datasheet doesn't specify minimum sizes */ |
| 425 | soc_camera_limit_side(&rect->left, &rect->width, |
| 426 | MT9M111_MIN_DARK_COLS, 2, MT9M111_MAX_WIDTH); |
| 427 | |
| 428 | soc_camera_limit_side(&rect->top, &rect->height, |
| 429 | MT9M111_MIN_DARK_ROWS, 2, MT9M111_MAX_HEIGHT); |
| 430 | |
| 431 | return mt9m111_setup_rect(client, rect); |
| 432 | } |
| 433 | |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 434 | static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 435 | { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 436 | struct v4l2_rect rect = a->c; |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 437 | struct i2c_client *client = sd->priv; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 438 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 439 | int ret; |
| 440 | |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 441 | dev_dbg(&client->dev, "%s left=%d, top=%d, width=%d, height=%d\n", |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 442 | __func__, rect.left, rect.top, rect.width, rect.height); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 443 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 444 | ret = mt9m111_make_rect(client, &rect); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 445 | if (!ret) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 446 | mt9m111->rect = rect; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 447 | return ret; |
| 448 | } |
| 449 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 450 | static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
| 451 | { |
| 452 | struct i2c_client *client = sd->priv; |
| 453 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
| 454 | |
| 455 | a->c = mt9m111->rect; |
| 456 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) |
| 462 | { |
| 463 | a->bounds.left = MT9M111_MIN_DARK_COLS; |
| 464 | a->bounds.top = MT9M111_MIN_DARK_ROWS; |
| 465 | a->bounds.width = MT9M111_MAX_WIDTH; |
| 466 | a->bounds.height = MT9M111_MAX_HEIGHT; |
| 467 | a->defrect = a->bounds; |
| 468 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 469 | a->pixelaspect.numerator = 1; |
| 470 | a->pixelaspect.denominator = 1; |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 475 | static int mt9m111_g_fmt(struct v4l2_subdev *sd, |
| 476 | struct v4l2_mbus_framefmt *mf) |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 477 | { |
| 478 | struct i2c_client *client = sd->priv; |
| 479 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 480 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 481 | mf->width = mt9m111->rect.width; |
| 482 | mf->height = mt9m111->rect.height; |
| 483 | mf->code = mt9m111->fmt->code; |
| 484 | mf->field = V4L2_FIELD_NONE; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 489 | static int mt9m111_set_pixfmt(struct i2c_client *client, |
| 490 | enum v4l2_mbus_pixelcode code) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 491 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 492 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 493 | int ret; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 494 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 495 | switch (code) { |
| 496 | case V4L2_MBUS_FMT_SBGGR8_1X8: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 497 | ret = mt9m111_setfmt_bayer8(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 498 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 499 | case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 500 | ret = mt9m111_setfmt_bayer10(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 501 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 502 | case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 503 | ret = mt9m111_setfmt_rgb555(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 504 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 505 | case V4L2_MBUS_FMT_RGB565_2X8_LE: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 506 | ret = mt9m111_setfmt_rgb565(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 507 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 508 | case V4L2_MBUS_FMT_YUYV8_2X8_BE: |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 509 | mt9m111->swap_yuv_y_chromas = 0; |
| 510 | mt9m111->swap_yuv_cb_cr = 0; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 511 | ret = mt9m111_setfmt_yuv(client); |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 512 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 513 | case V4L2_MBUS_FMT_YVYU8_2X8_BE: |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 514 | mt9m111->swap_yuv_y_chromas = 0; |
| 515 | mt9m111->swap_yuv_cb_cr = 1; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 516 | ret = mt9m111_setfmt_yuv(client); |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 517 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 518 | case V4L2_MBUS_FMT_YUYV8_2X8_LE: |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 519 | mt9m111->swap_yuv_y_chromas = 1; |
| 520 | mt9m111->swap_yuv_cb_cr = 0; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 521 | ret = mt9m111_setfmt_yuv(client); |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 522 | break; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 523 | case V4L2_MBUS_FMT_YVYU8_2X8_LE: |
Robert Jarzmik | 88f4b89 | 2008-12-17 14:05:31 -0300 | [diff] [blame] | 524 | mt9m111->swap_yuv_y_chromas = 1; |
| 525 | mt9m111->swap_yuv_cb_cr = 1; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 526 | ret = mt9m111_setfmt_yuv(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 527 | break; |
| 528 | default: |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 529 | dev_err(&client->dev, "Pixel format not handled : %x\n", |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 530 | code); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 531 | ret = -EINVAL; |
| 532 | } |
| 533 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 534 | return ret; |
| 535 | } |
| 536 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 537 | static int mt9m111_s_fmt(struct v4l2_subdev *sd, |
| 538 | struct v4l2_mbus_framefmt *mf) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 539 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 540 | struct i2c_client *client = sd->priv; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 541 | const struct mt9m111_datafmt *fmt; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 542 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 543 | struct v4l2_rect rect = { |
| 544 | .left = mt9m111->rect.left, |
| 545 | .top = mt9m111->rect.top, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 546 | .width = mf->width, |
| 547 | .height = mf->height, |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 548 | }; |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 549 | int ret; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 550 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 551 | fmt = mt9m111_find_datafmt(mf->code, mt9m111_colour_fmts, |
| 552 | ARRAY_SIZE(mt9m111_colour_fmts)); |
| 553 | if (!fmt) |
| 554 | return -EINVAL; |
| 555 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 556 | dev_dbg(&client->dev, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 557 | "%s code=%x left=%d, top=%d, width=%d, height=%d\n", __func__, |
| 558 | mf->code, rect.left, rect.top, rect.width, rect.height); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 559 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 560 | ret = mt9m111_make_rect(client, &rect); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 561 | if (!ret) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 562 | ret = mt9m111_set_pixfmt(client, mf->code); |
| 563 | if (!ret) { |
| 564 | mt9m111->rect = rect; |
| 565 | mt9m111->fmt = fmt; |
| 566 | mf->colorspace = fmt->colorspace; |
| 567 | } |
| 568 | |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 569 | return ret; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 570 | } |
| 571 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 572 | static int mt9m111_try_fmt(struct v4l2_subdev *sd, |
| 573 | struct v4l2_mbus_framefmt *mf) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 574 | { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 575 | struct i2c_client *client = sd->priv; |
| 576 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
| 577 | const struct mt9m111_datafmt *fmt; |
| 578 | bool bayer = mf->code == V4L2_MBUS_FMT_SBGGR8_1X8 || |
| 579 | mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE; |
| 580 | |
| 581 | fmt = mt9m111_find_datafmt(mf->code, mt9m111_colour_fmts, |
| 582 | ARRAY_SIZE(mt9m111_colour_fmts)); |
| 583 | if (!fmt) { |
| 584 | fmt = mt9m111->fmt; |
| 585 | mf->code = fmt->code; |
| 586 | } |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 587 | |
| 588 | /* |
| 589 | * With Bayer format enforce even side lengths, but let the user play |
| 590 | * with the starting pixel |
| 591 | */ |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 592 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 593 | if (mf->height > MT9M111_MAX_HEIGHT) |
| 594 | mf->height = MT9M111_MAX_HEIGHT; |
| 595 | else if (mf->height < 2) |
| 596 | mf->height = 2; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 597 | else if (bayer) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 598 | mf->height = ALIGN(mf->height, 2); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 599 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 600 | if (mf->width > MT9M111_MAX_WIDTH) |
| 601 | mf->width = MT9M111_MAX_WIDTH; |
| 602 | else if (mf->width < 2) |
| 603 | mf->width = 2; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 604 | else if (bayer) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 605 | mf->width = ALIGN(mf->width, 2); |
| 606 | |
| 607 | mf->colorspace = fmt->colorspace; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 612 | static int mt9m111_g_chip_ident(struct v4l2_subdev *sd, |
| 613 | struct v4l2_dbg_chip_ident *id) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 614 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 615 | struct i2c_client *client = sd->priv; |
| 616 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 617 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 618 | if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 619 | return -EINVAL; |
| 620 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 621 | if (id->match.addr != client->addr) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 622 | return -ENODEV; |
| 623 | |
| 624 | id->ident = mt9m111->model; |
| 625 | id->revision = 0; |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 631 | static int mt9m111_g_register(struct v4l2_subdev *sd, |
| 632 | struct v4l2_dbg_register *reg) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 633 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 634 | struct i2c_client *client = sd->priv; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 635 | int val; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 636 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 637 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 638 | return -EINVAL; |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 639 | if (reg->match.addr != client->addr) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 640 | return -ENODEV; |
| 641 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 642 | val = mt9m111_reg_read(client, reg->reg); |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 643 | reg->size = 2; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 644 | reg->val = (u64)val; |
| 645 | |
| 646 | if (reg->val > 0xffff) |
| 647 | return -EIO; |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 652 | static int mt9m111_s_register(struct v4l2_subdev *sd, |
| 653 | struct v4l2_dbg_register *reg) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 654 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 655 | struct i2c_client *client = sd->priv; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 656 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 657 | if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 658 | return -EINVAL; |
| 659 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 660 | if (reg->match.addr != client->addr) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 661 | return -ENODEV; |
| 662 | |
Guennadi Liakhovetski | 9538e1c | 2009-04-24 12:57:01 -0300 | [diff] [blame] | 663 | if (mt9m111_reg_write(client, reg->reg, reg->val) < 0) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 664 | return -EIO; |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | #endif |
| 669 | |
| 670 | static const struct v4l2_queryctrl mt9m111_controls[] = { |
| 671 | { |
| 672 | .id = V4L2_CID_VFLIP, |
| 673 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 674 | .name = "Flip Verticaly", |
| 675 | .minimum = 0, |
| 676 | .maximum = 1, |
| 677 | .step = 1, |
| 678 | .default_value = 0, |
| 679 | }, { |
| 680 | .id = V4L2_CID_HFLIP, |
| 681 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 682 | .name = "Flip Horizontaly", |
| 683 | .minimum = 0, |
| 684 | .maximum = 1, |
| 685 | .step = 1, |
| 686 | .default_value = 0, |
| 687 | }, { /* gain = 1/32*val (=>gain=1 if val==32) */ |
| 688 | .id = V4L2_CID_GAIN, |
| 689 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 690 | .name = "Gain", |
| 691 | .minimum = 0, |
| 692 | .maximum = 63 * 2 * 2, |
| 693 | .step = 1, |
| 694 | .default_value = 32, |
| 695 | .flags = V4L2_CTRL_FLAG_SLIDER, |
| 696 | }, { |
| 697 | .id = V4L2_CID_EXPOSURE_AUTO, |
| 698 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 699 | .name = "Auto Exposure", |
| 700 | .minimum = 0, |
| 701 | .maximum = 1, |
| 702 | .step = 1, |
| 703 | .default_value = 1, |
| 704 | } |
| 705 | }; |
| 706 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 707 | static int mt9m111_resume(struct soc_camera_device *icd); |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 708 | static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 709 | |
| 710 | static struct soc_camera_ops mt9m111_ops = { |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 711 | .suspend = mt9m111_suspend, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 712 | .resume = mt9m111_resume, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 713 | .query_bus_param = mt9m111_query_bus_param, |
| 714 | .set_bus_param = mt9m111_set_bus_param, |
| 715 | .controls = mt9m111_controls, |
| 716 | .num_controls = ARRAY_SIZE(mt9m111_controls), |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 717 | }; |
| 718 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 719 | static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 720 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 721 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 722 | int ret; |
| 723 | |
| 724 | if (mt9m111->context == HIGHPOWER) { |
| 725 | if (flip) |
| 726 | ret = reg_set(READ_MODE_B, mask); |
| 727 | else |
| 728 | ret = reg_clear(READ_MODE_B, mask); |
| 729 | } else { |
| 730 | if (flip) |
| 731 | ret = reg_set(READ_MODE_A, mask); |
| 732 | else |
| 733 | ret = reg_clear(READ_MODE_A, mask); |
| 734 | } |
| 735 | |
| 736 | return ret; |
| 737 | } |
| 738 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 739 | static int mt9m111_get_global_gain(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 740 | { |
roel kluin | 0f28b79 | 2008-12-17 14:01:07 -0300 | [diff] [blame] | 741 | int data; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 742 | |
| 743 | data = reg_read(GLOBAL_GAIN); |
| 744 | if (data >= 0) |
roel kluin | 0f28b79 | 2008-12-17 14:01:07 -0300 | [diff] [blame] | 745 | return (data & 0x2f) * (1 << ((data >> 10) & 1)) * |
| 746 | (1 << ((data >> 9) & 1)); |
| 747 | return data; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 748 | } |
roel kluin | 0f28b79 | 2008-12-17 14:01:07 -0300 | [diff] [blame] | 749 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 750 | static int mt9m111_set_global_gain(struct i2c_client *client, int gain) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 751 | { |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 752 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 753 | u16 val; |
| 754 | |
| 755 | if (gain > 63 * 2 * 2) |
| 756 | return -EINVAL; |
| 757 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 758 | mt9m111->gain = gain; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 759 | if ((gain >= 64 * 2) && (gain < 63 * 2 * 2)) |
| 760 | val = (1 << 10) | (1 << 9) | (gain / 4); |
| 761 | else if ((gain >= 64) && (gain < 64 * 2)) |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 762 | val = (1 << 9) | (gain / 2); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 763 | else |
| 764 | val = gain; |
| 765 | |
| 766 | return reg_write(GLOBAL_GAIN, val); |
| 767 | } |
| 768 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 769 | static int mt9m111_set_autoexposure(struct i2c_client *client, int on) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 770 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 771 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 772 | int ret; |
| 773 | |
| 774 | if (on) |
| 775 | ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); |
| 776 | else |
| 777 | ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); |
| 778 | |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 779 | if (!ret) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 780 | mt9m111->autoexposure = on; |
| 781 | |
| 782 | return ret; |
| 783 | } |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 784 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 785 | static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on) |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 786 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 787 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 788 | int ret; |
| 789 | |
| 790 | if (on) |
| 791 | ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN); |
| 792 | else |
| 793 | ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN); |
| 794 | |
| 795 | if (!ret) |
| 796 | mt9m111->autowhitebalance = on; |
| 797 | |
| 798 | return ret; |
| 799 | } |
| 800 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 801 | static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 802 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 803 | struct i2c_client *client = sd->priv; |
| 804 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 805 | int data; |
| 806 | |
| 807 | switch (ctrl->id) { |
| 808 | case V4L2_CID_VFLIP: |
| 809 | if (mt9m111->context == HIGHPOWER) |
| 810 | data = reg_read(READ_MODE_B); |
| 811 | else |
| 812 | data = reg_read(READ_MODE_A); |
| 813 | |
| 814 | if (data < 0) |
| 815 | return -EIO; |
| 816 | ctrl->value = !!(data & MT9M111_RMB_MIRROR_ROWS); |
| 817 | break; |
| 818 | case V4L2_CID_HFLIP: |
| 819 | if (mt9m111->context == HIGHPOWER) |
| 820 | data = reg_read(READ_MODE_B); |
| 821 | else |
| 822 | data = reg_read(READ_MODE_A); |
| 823 | |
| 824 | if (data < 0) |
| 825 | return -EIO; |
| 826 | ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS); |
| 827 | break; |
| 828 | case V4L2_CID_GAIN: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 829 | data = mt9m111_get_global_gain(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 830 | if (data < 0) |
| 831 | return data; |
| 832 | ctrl->value = data; |
| 833 | break; |
| 834 | case V4L2_CID_EXPOSURE_AUTO: |
| 835 | ctrl->value = mt9m111->autoexposure; |
| 836 | break; |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 837 | case V4L2_CID_AUTO_WHITE_BALANCE: |
| 838 | ctrl->value = mt9m111->autowhitebalance; |
| 839 | break; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 840 | } |
| 841 | return 0; |
| 842 | } |
| 843 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 844 | static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 845 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 846 | struct i2c_client *client = sd->priv; |
| 847 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 848 | const struct v4l2_queryctrl *qctrl; |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 849 | int ret; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 850 | |
| 851 | qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 852 | if (!qctrl) |
| 853 | return -EINVAL; |
| 854 | |
| 855 | switch (ctrl->id) { |
| 856 | case V4L2_CID_VFLIP: |
| 857 | mt9m111->vflip = ctrl->value; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 858 | ret = mt9m111_set_flip(client, ctrl->value, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 859 | MT9M111_RMB_MIRROR_ROWS); |
| 860 | break; |
| 861 | case V4L2_CID_HFLIP: |
| 862 | mt9m111->hflip = ctrl->value; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 863 | ret = mt9m111_set_flip(client, ctrl->value, |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 864 | MT9M111_RMB_MIRROR_COLS); |
| 865 | break; |
| 866 | case V4L2_CID_GAIN: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 867 | ret = mt9m111_set_global_gain(client, ctrl->value); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 868 | break; |
| 869 | case V4L2_CID_EXPOSURE_AUTO: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 870 | ret = mt9m111_set_autoexposure(client, ctrl->value); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 871 | break; |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 872 | case V4L2_CID_AUTO_WHITE_BALANCE: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 873 | ret = mt9m111_set_autowhitebalance(client, ctrl->value); |
Robert Jarzmik | 39bf372 | 2008-12-18 11:29:05 -0300 | [diff] [blame] | 874 | break; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 875 | default: |
| 876 | ret = -EINVAL; |
| 877 | } |
| 878 | |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 879 | return ret; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 880 | } |
| 881 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 882 | static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state) |
| 883 | { |
| 884 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
| 885 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
| 886 | |
| 887 | mt9m111->gain = mt9m111_get_global_gain(client); |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 892 | static int mt9m111_restore_state(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 893 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 894 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 895 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 896 | mt9m111_set_context(client, mt9m111->context); |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 897 | mt9m111_set_pixfmt(client, mt9m111->fmt->code); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 898 | mt9m111_setup_rect(client, &mt9m111->rect); |
| 899 | mt9m111_set_flip(client, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); |
| 900 | mt9m111_set_flip(client, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS); |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 901 | mt9m111_set_global_gain(client, mt9m111->gain); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 902 | mt9m111_set_autoexposure(client, mt9m111->autoexposure); |
| 903 | mt9m111_set_autowhitebalance(client, mt9m111->autowhitebalance); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | static int mt9m111_resume(struct soc_camera_device *icd) |
| 908 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 909 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 910 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 911 | int ret = 0; |
| 912 | |
| 913 | if (mt9m111->powered) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 914 | ret = mt9m111_enable(client); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 915 | if (!ret) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 916 | ret = mt9m111_reset(client); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 917 | if (!ret) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 918 | ret = mt9m111_restore_state(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 919 | } |
| 920 | return ret; |
| 921 | } |
| 922 | |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 923 | static int mt9m111_init(struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 924 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 925 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 926 | int ret; |
| 927 | |
| 928 | mt9m111->context = HIGHPOWER; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 929 | ret = mt9m111_enable(client); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 930 | if (!ret) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 931 | ret = mt9m111_reset(client); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 932 | if (!ret) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 933 | ret = mt9m111_set_context(client, mt9m111->context); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 934 | if (!ret) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 935 | ret = mt9m111_set_autoexposure(client, mt9m111->autoexposure); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 936 | if (ret) |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 937 | dev_err(&client->dev, "mt9m11x init failed: %d\n", ret); |
Guennadi Liakhovetski | 506c629 | 2008-08-14 12:03:49 -0300 | [diff] [blame] | 938 | return ret; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 939 | } |
| 940 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 941 | /* |
| 942 | * Interface active, can use i2c. If it fails, it can indeed mean, that |
| 943 | * this wasn't our capture interface, so, we wait for the right one |
| 944 | */ |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 945 | static int mt9m111_video_probe(struct soc_camera_device *icd, |
| 946 | struct i2c_client *client) |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 947 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 948 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 949 | s32 data; |
| 950 | int ret; |
| 951 | |
| 952 | /* |
| 953 | * We must have a parent by now. And it cannot be a wrong one. |
| 954 | * So this entire test is completely redundant. |
| 955 | */ |
| 956 | if (!icd->dev.parent || |
| 957 | to_soc_camera_host(icd->dev.parent)->nr != icd->iface) |
| 958 | return -ENODEV; |
| 959 | |
Guennadi Liakhovetski | a4c56fd | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 960 | mt9m111->autoexposure = 1; |
| 961 | mt9m111->autowhitebalance = 1; |
| 962 | |
| 963 | mt9m111->swap_rgb_even_odd = 1; |
| 964 | mt9m111->swap_rgb_red_blue = 1; |
| 965 | |
| 966 | ret = mt9m111_init(client); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 967 | if (ret) |
| 968 | goto ei2c; |
| 969 | |
| 970 | data = reg_read(CHIP_VERSION); |
| 971 | |
| 972 | switch (data) { |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 973 | case 0x143a: /* MT9M111 */ |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 974 | mt9m111->model = V4L2_IDENT_MT9M111; |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 975 | break; |
| 976 | case 0x148c: /* MT9M112 */ |
| 977 | mt9m111->model = V4L2_IDENT_MT9M112; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 978 | break; |
| 979 | default: |
| 980 | ret = -ENODEV; |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 981 | dev_err(&client->dev, |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 982 | "No MT9M11x chip detected, register read %x\n", data); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 983 | goto ei2c; |
| 984 | } |
| 985 | |
Guennadi Liakhovetski | 85f8be6 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 986 | dev_info(&client->dev, "Detected a MT9M11x chip ID %x\n", data); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 987 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 988 | ei2c: |
| 989 | return ret; |
| 990 | } |
| 991 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 992 | static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = { |
| 993 | .g_ctrl = mt9m111_g_ctrl, |
| 994 | .s_ctrl = mt9m111_s_ctrl, |
| 995 | .g_chip_ident = mt9m111_g_chip_ident, |
| 996 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 997 | .g_register = mt9m111_g_register, |
| 998 | .s_register = mt9m111_s_register, |
| 999 | #endif |
| 1000 | }; |
| 1001 | |
Hans Verkuil | 3805f20 | 2010-05-08 17:55:00 -0300 | [diff] [blame] | 1002 | static int mt9m111_enum_fmt(struct v4l2_subdev *sd, unsigned int index, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1003 | enum v4l2_mbus_pixelcode *code) |
| 1004 | { |
Hans Verkuil | 3805f20 | 2010-05-08 17:55:00 -0300 | [diff] [blame] | 1005 | if (index >= ARRAY_SIZE(mt9m111_colour_fmts)) |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1006 | return -EINVAL; |
| 1007 | |
| 1008 | *code = mt9m111_colour_fmts[index].code; |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1012 | static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1013 | .s_mbus_fmt = mt9m111_s_fmt, |
| 1014 | .g_mbus_fmt = mt9m111_g_fmt, |
| 1015 | .try_mbus_fmt = mt9m111_try_fmt, |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 1016 | .s_crop = mt9m111_s_crop, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1017 | .g_crop = mt9m111_g_crop, |
| 1018 | .cropcap = mt9m111_cropcap, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1019 | .enum_mbus_fmt = mt9m111_enum_fmt, |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1020 | }; |
| 1021 | |
| 1022 | static struct v4l2_subdev_ops mt9m111_subdev_ops = { |
| 1023 | .core = &mt9m111_subdev_core_ops, |
| 1024 | .video = &mt9m111_subdev_video_ops, |
| 1025 | }; |
| 1026 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1027 | static int mt9m111_probe(struct i2c_client *client, |
| 1028 | const struct i2c_device_id *did) |
| 1029 | { |
| 1030 | struct mt9m111 *mt9m111; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1031 | struct soc_camera_device *icd = client->dev.platform_data; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1032 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1033 | struct soc_camera_link *icl; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1034 | int ret; |
| 1035 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1036 | if (!icd) { |
| 1037 | dev_err(&client->dev, "MT9M11x: missing soc-camera data!\n"); |
| 1038 | return -EINVAL; |
| 1039 | } |
| 1040 | |
| 1041 | icl = to_soc_camera_link(icd); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1042 | if (!icl) { |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 1043 | dev_err(&client->dev, "MT9M11x driver needs platform data\n"); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1044 | return -EINVAL; |
| 1045 | } |
| 1046 | |
| 1047 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) { |
| 1048 | dev_warn(&adapter->dev, |
| 1049 | "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n"); |
| 1050 | return -EIO; |
| 1051 | } |
| 1052 | |
| 1053 | mt9m111 = kzalloc(sizeof(struct mt9m111), GFP_KERNEL); |
| 1054 | if (!mt9m111) |
| 1055 | return -ENOMEM; |
| 1056 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1057 | v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1058 | |
| 1059 | /* Second stage probe - when a capture adapter is there */ |
Guennadi Liakhovetski | a0705b0 | 2009-08-25 11:46:17 -0300 | [diff] [blame] | 1060 | icd->ops = &mt9m111_ops; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1061 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1062 | mt9m111->rect.left = MT9M111_MIN_DARK_COLS; |
| 1063 | mt9m111->rect.top = MT9M111_MIN_DARK_ROWS; |
| 1064 | mt9m111->rect.width = MT9M111_MAX_WIDTH; |
| 1065 | mt9m111->rect.height = MT9M111_MAX_HEIGHT; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1066 | mt9m111->fmt = &mt9m111_colour_fmts[0]; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1067 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1068 | ret = mt9m111_video_probe(icd, client); |
| 1069 | if (ret) { |
| 1070 | icd->ops = NULL; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1071 | kfree(mt9m111); |
| 1072 | } |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1073 | |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1074 | return ret; |
| 1075 | } |
| 1076 | |
| 1077 | static int mt9m111_remove(struct i2c_client *client) |
| 1078 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1079 | struct mt9m111 *mt9m111 = to_mt9m111(client); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1080 | struct soc_camera_device *icd = client->dev.platform_data; |
| 1081 | |
| 1082 | icd->ops = NULL; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1083 | client->driver = NULL; |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1084 | kfree(mt9m111); |
| 1085 | |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | static const struct i2c_device_id mt9m111_id[] = { |
| 1090 | { "mt9m111", 0 }, |
| 1091 | { } |
| 1092 | }; |
| 1093 | MODULE_DEVICE_TABLE(i2c, mt9m111_id); |
| 1094 | |
| 1095 | static struct i2c_driver mt9m111_i2c_driver = { |
| 1096 | .driver = { |
| 1097 | .name = "mt9m111", |
| 1098 | }, |
| 1099 | .probe = mt9m111_probe, |
| 1100 | .remove = mt9m111_remove, |
| 1101 | .id_table = mt9m111_id, |
| 1102 | }; |
| 1103 | |
| 1104 | static int __init mt9m111_mod_init(void) |
| 1105 | { |
| 1106 | return i2c_add_driver(&mt9m111_i2c_driver); |
| 1107 | } |
| 1108 | |
| 1109 | static void __exit mt9m111_mod_exit(void) |
| 1110 | { |
| 1111 | i2c_del_driver(&mt9m111_i2c_driver); |
| 1112 | } |
| 1113 | |
| 1114 | module_init(mt9m111_mod_init); |
| 1115 | module_exit(mt9m111_mod_exit); |
| 1116 | |
Mike Rapoport | d7f83a5 | 2008-12-18 11:44:15 -0300 | [diff] [blame] | 1117 | MODULE_DESCRIPTION("Micron MT9M111/MT9M112 Camera driver"); |
Robert Jarzmik | 77110ab | 2008-08-14 12:02:51 -0300 | [diff] [blame] | 1118 | MODULE_AUTHOR("Robert Jarzmik"); |
| 1119 | MODULE_LICENSE("GPL"); |