Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the po1030 sensor |
| 3 | * |
Erik Andren | 0c505e68 | 2008-10-16 16:43:16 -0300 | [diff] [blame] | 4 | * Copyright (c) 2008 Erik Andrén |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 5 | * Copyright (c) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project. |
| 6 | * Copyright (c) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br> |
| 7 | * |
| 8 | * Portions of code to USB interface and ALi driver software, |
| 9 | * Copyright (c) 2006 Willem Duinker |
| 10 | * v4l2 interface modeled after the V4L2 driver |
| 11 | * for SN9C10x PC Camera Controllers |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License as |
| 15 | * published by the Free Software Foundation, version 2. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include "m5602_po1030.h" |
| 20 | |
Erik Andr?n | 74cadfe | 2008-12-30 16:48:42 -0300 | [diff] [blame] | 21 | static struct v4l2_pix_format po1030_modes[] = { |
| 22 | { |
| 23 | 640, |
| 24 | 480, |
| 25 | V4L2_PIX_FMT_SBGGR8, |
| 26 | V4L2_FIELD_NONE, |
| 27 | .sizeimage = 640 * 480, |
| 28 | .bytesperline = 640, |
| 29 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 30 | .priv = 0 |
| 31 | } |
| 32 | }; |
| 33 | |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 34 | const static struct ctrl po1030_ctrls[] = { |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 35 | #define GAIN_IDX 0 |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 36 | { |
| 37 | { |
| 38 | .id = V4L2_CID_GAIN, |
| 39 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 40 | .name = "gain", |
| 41 | .minimum = 0x00, |
| 42 | .maximum = 0x4f, |
| 43 | .step = 0x1, |
| 44 | .default_value = PO1030_GLOBAL_GAIN_DEFAULT, |
| 45 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 46 | }, |
| 47 | .set = po1030_set_gain, |
| 48 | .get = po1030_get_gain |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 49 | }, |
| 50 | #define EXPOSURE_IDX 1 |
| 51 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 52 | { |
| 53 | .id = V4L2_CID_EXPOSURE, |
| 54 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 55 | .name = "exposure", |
| 56 | .minimum = 0x00, |
| 57 | .maximum = 0x02ff, |
| 58 | .step = 0x1, |
| 59 | .default_value = PO1030_EXPOSURE_DEFAULT, |
| 60 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 61 | }, |
| 62 | .set = po1030_set_exposure, |
| 63 | .get = po1030_get_exposure |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 64 | }, |
| 65 | #define RED_BALANCE_IDX 2 |
| 66 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 67 | { |
| 68 | .id = V4L2_CID_RED_BALANCE, |
| 69 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 70 | .name = "red balance", |
| 71 | .minimum = 0x00, |
| 72 | .maximum = 0xff, |
| 73 | .step = 0x1, |
| 74 | .default_value = PO1030_RED_GAIN_DEFAULT, |
| 75 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 76 | }, |
| 77 | .set = po1030_set_red_balance, |
| 78 | .get = po1030_get_red_balance |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 79 | }, |
| 80 | #define BLUE_BALANCE_IDX 3 |
| 81 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 82 | { |
| 83 | .id = V4L2_CID_BLUE_BALANCE, |
| 84 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 85 | .name = "blue balance", |
| 86 | .minimum = 0x00, |
| 87 | .maximum = 0xff, |
| 88 | .step = 0x1, |
| 89 | .default_value = PO1030_BLUE_GAIN_DEFAULT, |
| 90 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 91 | }, |
| 92 | .set = po1030_set_blue_balance, |
| 93 | .get = po1030_get_blue_balance |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 94 | }, |
| 95 | #define HFLIP_IDX 4 |
| 96 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 97 | { |
| 98 | .id = V4L2_CID_HFLIP, |
| 99 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 100 | .name = "horizontal flip", |
| 101 | .minimum = 0, |
| 102 | .maximum = 1, |
| 103 | .step = 1, |
| 104 | .default_value = 0, |
| 105 | }, |
| 106 | .set = po1030_set_hflip, |
| 107 | .get = po1030_get_hflip |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 108 | }, |
| 109 | #define VFLIP_IDX 5 |
| 110 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 111 | { |
| 112 | .id = V4L2_CID_VFLIP, |
| 113 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 114 | .name = "vertical flip", |
| 115 | .minimum = 0, |
| 116 | .maximum = 1, |
| 117 | .step = 1, |
| 118 | .default_value = 0, |
| 119 | }, |
| 120 | .set = po1030_set_vflip, |
| 121 | .get = po1030_get_vflip |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 122 | }, |
| 123 | #define AUTO_WHITE_BALANCE_IDX 6 |
| 124 | { |
| 125 | { |
| 126 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 127 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 128 | .name = "auto white balance", |
| 129 | .minimum = 0, |
| 130 | .maximum = 1, |
| 131 | .step = 1, |
| 132 | .default_value = 0, |
| 133 | }, |
| 134 | .set = po1030_set_auto_white_balance, |
| 135 | .get = po1030_get_auto_white_balance |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 136 | } |
| 137 | }; |
| 138 | |
Erik Andrén | 658efb6 | 2008-11-24 14:21:29 -0300 | [diff] [blame] | 139 | static void po1030_dump_registers(struct sd *sd); |
| 140 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 141 | int po1030_probe(struct sd *sd) |
| 142 | { |
Erik Andr?n | fcb9810 | 2009-01-08 04:04:19 -0300 | [diff] [blame] | 143 | u8 dev_id_h = 0, dev_id_l = 0, i; |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 144 | s32 *sensor_settings; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 145 | |
| 146 | if (force_sensor) { |
| 147 | if (force_sensor == PO1030_SENSOR) { |
| 148 | info("Forcing a %s sensor", po1030.name); |
| 149 | goto sensor_found; |
| 150 | } |
| 151 | /* If we want to force another sensor, don't try to probe this |
| 152 | * one */ |
| 153 | return -ENODEV; |
| 154 | } |
| 155 | |
| 156 | info("Probing for a po1030 sensor"); |
| 157 | |
| 158 | /* Run the pre-init to actually probe the unit */ |
| 159 | for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) { |
| 160 | u8 data = preinit_po1030[i][2]; |
| 161 | if (preinit_po1030[i][0] == SENSOR) |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 162 | m5602_write_sensor(sd, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 163 | preinit_po1030[i][1], &data, 1); |
| 164 | else |
| 165 | m5602_write_bridge(sd, preinit_po1030[i][1], data); |
| 166 | } |
| 167 | |
Erik Andr?n | fcb9810 | 2009-01-08 04:04:19 -0300 | [diff] [blame] | 168 | if (m5602_read_sensor(sd, PO1030_DEVID_H, &dev_id_h, 1)) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 169 | return -ENODEV; |
| 170 | |
Erik Andr?n | fcb9810 | 2009-01-08 04:04:19 -0300 | [diff] [blame] | 171 | if (m5602_read_sensor(sd, PO1030_DEVID_L, &dev_id_l, 1)) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 172 | return -ENODEV; |
| 173 | |
Erik Andr?n | fcb9810 | 2009-01-08 04:04:19 -0300 | [diff] [blame] | 174 | if ((dev_id_h == 0x10) && (dev_id_l == 0x30)) { |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 175 | info("Detected a po1030 sensor"); |
| 176 | goto sensor_found; |
| 177 | } |
| 178 | return -ENODEV; |
| 179 | |
| 180 | sensor_found: |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 181 | sensor_settings = kmalloc( |
| 182 | ARRAY_SIZE(po1030_ctrls) * sizeof(s32), GFP_KERNEL); |
| 183 | if (!sensor_settings) |
| 184 | return -ENOMEM; |
| 185 | |
Erik Andr?n | 74cadfe | 2008-12-30 16:48:42 -0300 | [diff] [blame] | 186 | sd->gspca_dev.cam.cam_mode = po1030_modes; |
| 187 | sd->gspca_dev.cam.nmodes = ARRAY_SIZE(po1030_modes); |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 188 | sd->desc->ctrls = po1030_ctrls; |
Erik Andr?n | e4cc4fc | 2008-12-30 15:27:17 -0300 | [diff] [blame] | 189 | sd->desc->nctrls = ARRAY_SIZE(po1030_ctrls); |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 190 | |
| 191 | for (i = 0; i < ARRAY_SIZE(po1030_ctrls); i++) |
| 192 | sensor_settings[i] = po1030_ctrls[i].qctrl.default_value; |
| 193 | sd->sensor_priv = sensor_settings; |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 194 | |
| 195 | if (dump_sensor) |
| 196 | po1030_dump_registers(sd); |
| 197 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 201 | int po1030_init(struct sd *sd) |
| 202 | { |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 203 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 204 | int i, err = 0; |
| 205 | |
| 206 | /* Init the sensor */ |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 207 | for (i = 0; i < ARRAY_SIZE(init_po1030) && !err; i++) { |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 208 | u8 data[2] = {0x00, 0x00}; |
| 209 | |
| 210 | switch (init_po1030[i][0]) { |
| 211 | case BRIDGE: |
| 212 | err = m5602_write_bridge(sd, |
| 213 | init_po1030[i][1], |
| 214 | init_po1030[i][2]); |
| 215 | break; |
| 216 | |
| 217 | case SENSOR: |
| 218 | data[0] = init_po1030[i][2]; |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 219 | err = m5602_write_sensor(sd, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 220 | init_po1030[i][1], data, 1); |
| 221 | break; |
| 222 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 223 | default: |
| 224 | info("Invalid stream command, exiting init"); |
| 225 | return -EINVAL; |
| 226 | } |
| 227 | } |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 228 | if (err < 0) |
| 229 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 230 | |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 231 | err = po1030_set_exposure(&sd->gspca_dev, |
| 232 | sensor_settings[EXPOSURE_IDX]); |
| 233 | if (err < 0) |
| 234 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 235 | |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 236 | err = po1030_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); |
| 237 | if (err < 0) |
| 238 | return err; |
| 239 | |
| 240 | err = po1030_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]); |
| 241 | if (err < 0) |
| 242 | return err; |
| 243 | |
| 244 | err = po1030_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]); |
| 245 | if (err < 0) |
| 246 | return err; |
| 247 | |
| 248 | err = po1030_set_red_balance(&sd->gspca_dev, |
| 249 | sensor_settings[RED_BALANCE_IDX]); |
| 250 | if (err < 0) |
| 251 | return err; |
| 252 | |
| 253 | err = po1030_set_red_balance(&sd->gspca_dev, |
| 254 | sensor_settings[BLUE_BALANCE_IDX]); |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 255 | if (err < 0) |
| 256 | return err; |
| 257 | |
| 258 | err = po1030_set_auto_white_balance(&sd->gspca_dev, |
| 259 | sensor_settings[AUTO_WHITE_BALANCE_IDX]); |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 260 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 261 | } |
| 262 | |
Erik Andr?n | c996b36 | 2009-01-08 14:15:06 -0300 | [diff] [blame^] | 263 | int po1030_start(struct sd *sd) |
| 264 | { |
| 265 | int i, err = 0; |
| 266 | /* Synthesize the vsync/hsync setup */ |
| 267 | for (i = 0; i < ARRAY_SIZE(start_po1030) && !err; i++) { |
| 268 | if (start_po1030[i][0] == BRIDGE) |
| 269 | err = m5602_write_bridge(sd, start_po1030[i][1], |
| 270 | start_po1030[i][2]); |
| 271 | else if (start_po1030[i][0] == SENSOR) { |
| 272 | u8 data = start_po1030[i][2]; |
| 273 | err = m5602_write_sensor(sd, |
| 274 | start_po1030[i][1], &data, 1); |
| 275 | } |
| 276 | } |
| 277 | return err; |
| 278 | } |
| 279 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 280 | int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) |
| 281 | { |
| 282 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 283 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 284 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 285 | *val = sensor_settings[EXPOSURE_IDX]; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 286 | PDEBUG(D_V4L2, "Exposure read as %d", *val); |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 287 | return 0; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val) |
| 291 | { |
| 292 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 293 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 294 | u8 i2c_data; |
| 295 | int err; |
| 296 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 297 | sensor_settings[EXPOSURE_IDX] = val; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 298 | PDEBUG(D_V4L2, "Set exposure to %d", val & 0xffff); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 299 | |
| 300 | i2c_data = ((val & 0xff00) >> 8); |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 301 | PDEBUG(D_V4L2, "Set exposure to high byte to 0x%x", |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 302 | i2c_data); |
| 303 | |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 304 | err = m5602_write_sensor(sd, PO1030_INTEGLINES_H, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 305 | &i2c_data, 1); |
| 306 | if (err < 0) |
Erik Andr?n | 051781b | 2008-12-27 12:28:00 -0300 | [diff] [blame] | 307 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 308 | |
| 309 | i2c_data = (val & 0xff); |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 310 | PDEBUG(D_V4L2, "Set exposure to low byte to 0x%x", |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 311 | i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 312 | err = m5602_write_sensor(sd, PO1030_INTEGLINES_M, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 313 | &i2c_data, 1); |
| 314 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 315 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val) |
| 319 | { |
| 320 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 321 | s32 *sensor_settings = sd->sensor_priv; |
| 322 | |
| 323 | *val = sensor_settings[GAIN_IDX]; |
| 324 | PDEBUG(D_V4L2, "Read global gain %d", *val); |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val) |
| 329 | { |
| 330 | struct sd *sd = (struct sd *) gspca_dev; |
| 331 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 332 | u8 i2c_data; |
| 333 | int err; |
| 334 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 335 | sensor_settings[GAIN_IDX] = val; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 336 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 337 | i2c_data = val & 0xff; |
| 338 | PDEBUG(D_V4L2, "Set global gain to %d", i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 339 | err = m5602_write_sensor(sd, PO1030_GLOBALGAIN, |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 340 | &i2c_data, 1); |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 341 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 342 | } |
| 343 | |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 344 | int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 345 | { |
| 346 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 347 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 348 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 349 | *val = sensor_settings[HFLIP_IDX]; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 350 | PDEBUG(D_V4L2, "Read hflip %d", *val); |
| 351 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 352 | return 0; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val) |
| 356 | { |
| 357 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 358 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 359 | u8 i2c_data; |
| 360 | int err; |
| 361 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 362 | sensor_settings[HFLIP_IDX] = val; |
| 363 | |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 364 | PDEBUG(D_V4L2, "Set hflip %d", val); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 365 | err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1); |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 366 | if (err < 0) |
Erik Andr?n | 051781b | 2008-12-27 12:28:00 -0300 | [diff] [blame] | 367 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 368 | |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 369 | i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 370 | |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 371 | err = m5602_write_sensor(sd, PO1030_CONTROL2, |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 372 | &i2c_data, 1); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 373 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 374 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 378 | { |
| 379 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 380 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 381 | |
Erik Andr?n | 2742908 | 2009-01-07 17:41:47 -0300 | [diff] [blame] | 382 | *val = sensor_settings[VFLIP_IDX]; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 383 | PDEBUG(D_V4L2, "Read vflip %d", *val); |
| 384 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 385 | return 0; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val) |
| 389 | { |
| 390 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 391 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 392 | u8 i2c_data; |
| 393 | int err; |
| 394 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 395 | sensor_settings[VFLIP_IDX] = val; |
| 396 | |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 397 | PDEBUG(D_V4L2, "Set vflip %d", val); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 398 | err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1); |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 399 | if (err < 0) |
Erik Andr?n | 051781b | 2008-12-27 12:28:00 -0300 | [diff] [blame] | 400 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 401 | |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 402 | i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 403 | |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 404 | err = m5602_write_sensor(sd, PO1030_CONTROL2, |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 405 | &i2c_data, 1); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 406 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 407 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 408 | } |
| 409 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 410 | int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val) |
| 411 | { |
| 412 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 413 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 414 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 415 | *val = sensor_settings[RED_BALANCE_IDX]; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 416 | PDEBUG(D_V4L2, "Read red gain %d", *val); |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 417 | return 0; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) |
| 421 | { |
| 422 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 423 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 424 | u8 i2c_data; |
| 425 | int err; |
| 426 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 427 | sensor_settings[RED_BALANCE_IDX] = val; |
| 428 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 429 | i2c_data = val & 0xff; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 430 | PDEBUG(D_V4L2, "Set red gain to %d", i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 431 | err = m5602_write_sensor(sd, PO1030_RED_GAIN, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 432 | &i2c_data, 1); |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 433 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val) |
| 437 | { |
| 438 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 439 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 440 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 441 | *val = sensor_settings[BLUE_BALANCE_IDX]; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 442 | PDEBUG(D_V4L2, "Read blue gain %d", *val); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 443 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 444 | return 0; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) |
| 448 | { |
| 449 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 450 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 451 | u8 i2c_data; |
| 452 | int err; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 453 | |
| 454 | sensor_settings[BLUE_BALANCE_IDX] = val; |
| 455 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 456 | i2c_data = val & 0xff; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 457 | PDEBUG(D_V4L2, "Set blue gain to %d", i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 458 | err = m5602_write_sensor(sd, PO1030_BLUE_GAIN, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 459 | &i2c_data, 1); |
| 460 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 461 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 462 | } |
| 463 | |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 464 | int po1030_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val) |
| 465 | { |
| 466 | struct sd *sd = (struct sd *) gspca_dev; |
| 467 | s32 *sensor_settings = sd->sensor_priv; |
| 468 | |
| 469 | *val = sensor_settings[AUTO_WHITE_BALANCE_IDX]; |
| 470 | PDEBUG(D_V4L2, "Auto white balancing is %d", *val); |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | int po1030_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val) |
| 476 | { |
| 477 | struct sd *sd = (struct sd *) gspca_dev; |
| 478 | s32 *sensor_settings = sd->sensor_priv; |
| 479 | u8 i2c_data; |
| 480 | int err; |
| 481 | |
| 482 | sensor_settings[AUTO_WHITE_BALANCE_IDX] = val; |
| 483 | |
| 484 | err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); |
| 485 | if (err < 0) |
| 486 | return err; |
| 487 | |
| 488 | i2c_data = (i2c_data & 0xfe) | (val & 0x01); |
| 489 | err = m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); |
| 490 | return err; |
| 491 | } |
| 492 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 493 | void po1030_disconnect(struct sd *sd) |
| 494 | { |
| 495 | sd->sensor = NULL; |
| 496 | kfree(sd->sensor_priv); |
| 497 | } |
| 498 | |
Erik Andrén | 658efb6 | 2008-11-24 14:21:29 -0300 | [diff] [blame] | 499 | static void po1030_dump_registers(struct sd *sd) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 500 | { |
| 501 | int address; |
| 502 | u8 value = 0; |
| 503 | |
| 504 | info("Dumping the po1030 sensor core registers"); |
| 505 | for (address = 0; address < 0x7f; address++) { |
Erik Andrén | c061c97 | 2008-11-27 13:46:39 -0300 | [diff] [blame] | 506 | m5602_read_sensor(sd, address, &value, 1); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 507 | info("register 0x%x contains 0x%x", |
| 508 | address, value); |
| 509 | } |
| 510 | |
| 511 | info("po1030 register state dump complete"); |
| 512 | |
| 513 | info("Probing for which registers that are read/write"); |
| 514 | for (address = 0; address < 0xff; address++) { |
| 515 | u8 old_value, ctrl_value; |
| 516 | u8 test_value[2] = {0xff, 0xff}; |
| 517 | |
Erik Andrén | c061c97 | 2008-11-27 13:46:39 -0300 | [diff] [blame] | 518 | m5602_read_sensor(sd, address, &old_value, 1); |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 519 | m5602_write_sensor(sd, address, test_value, 1); |
Erik Andrén | c061c97 | 2008-11-27 13:46:39 -0300 | [diff] [blame] | 520 | m5602_read_sensor(sd, address, &ctrl_value, 1); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 521 | |
| 522 | if (ctrl_value == test_value[0]) |
| 523 | info("register 0x%x is writeable", address); |
| 524 | else |
| 525 | info("register 0x%x is read only", address); |
| 526 | |
| 527 | /* Restore original value */ |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 528 | m5602_write_sensor(sd, address, &old_value, 1); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 529 | } |
| 530 | } |