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 | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 21 | static int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val); |
| 22 | static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val); |
| 23 | static int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val); |
| 24 | static int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val); |
| 25 | static int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val); |
| 26 | static int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val); |
| 27 | static int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val); |
| 28 | static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val); |
Erik Andr?n | b933d58 | 2009-01-13 13:55:52 -0300 | [diff] [blame^] | 29 | static int po1030_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val); |
| 30 | static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val); |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 31 | static int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val); |
| 32 | static int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val); |
| 33 | static int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); |
| 34 | static int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val); |
| 35 | static int po1030_set_auto_white_balance(struct gspca_dev *gspca_dev, |
| 36 | __s32 val); |
| 37 | static int po1030_get_auto_white_balance(struct gspca_dev *gspca_dev, |
| 38 | __s32 *val); |
Erik Andr?n | dd9ce84 | 2009-01-13 13:43:46 -0300 | [diff] [blame] | 39 | static int po1030_set_auto_exposure(struct gspca_dev *gspca_dev, |
| 40 | __s32 val); |
| 41 | static int po1030_get_auto_exposure(struct gspca_dev *gspca_dev, |
| 42 | __s32 *val); |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 43 | |
Erik Andr?n | 74cadfe | 2008-12-30 16:48:42 -0300 | [diff] [blame] | 44 | static struct v4l2_pix_format po1030_modes[] = { |
| 45 | { |
| 46 | 640, |
| 47 | 480, |
| 48 | V4L2_PIX_FMT_SBGGR8, |
| 49 | V4L2_FIELD_NONE, |
| 50 | .sizeimage = 640 * 480, |
| 51 | .bytesperline = 640, |
| 52 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 53 | .priv = 0 |
| 54 | } |
| 55 | }; |
| 56 | |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 57 | const static struct ctrl po1030_ctrls[] = { |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 58 | #define GAIN_IDX 0 |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 59 | { |
| 60 | { |
| 61 | .id = V4L2_CID_GAIN, |
| 62 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 63 | .name = "gain", |
| 64 | .minimum = 0x00, |
| 65 | .maximum = 0x4f, |
| 66 | .step = 0x1, |
| 67 | .default_value = PO1030_GLOBAL_GAIN_DEFAULT, |
| 68 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 69 | }, |
| 70 | .set = po1030_set_gain, |
| 71 | .get = po1030_get_gain |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 72 | }, |
| 73 | #define EXPOSURE_IDX 1 |
| 74 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 75 | { |
| 76 | .id = V4L2_CID_EXPOSURE, |
| 77 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 78 | .name = "exposure", |
| 79 | .minimum = 0x00, |
| 80 | .maximum = 0x02ff, |
| 81 | .step = 0x1, |
| 82 | .default_value = PO1030_EXPOSURE_DEFAULT, |
| 83 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 84 | }, |
| 85 | .set = po1030_set_exposure, |
| 86 | .get = po1030_get_exposure |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 87 | }, |
| 88 | #define RED_BALANCE_IDX 2 |
| 89 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 90 | { |
| 91 | .id = V4L2_CID_RED_BALANCE, |
| 92 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 93 | .name = "red balance", |
| 94 | .minimum = 0x00, |
| 95 | .maximum = 0xff, |
| 96 | .step = 0x1, |
| 97 | .default_value = PO1030_RED_GAIN_DEFAULT, |
| 98 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 99 | }, |
| 100 | .set = po1030_set_red_balance, |
| 101 | .get = po1030_get_red_balance |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 102 | }, |
| 103 | #define BLUE_BALANCE_IDX 3 |
| 104 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 105 | { |
| 106 | .id = V4L2_CID_BLUE_BALANCE, |
| 107 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 108 | .name = "blue balance", |
| 109 | .minimum = 0x00, |
| 110 | .maximum = 0xff, |
| 111 | .step = 0x1, |
| 112 | .default_value = PO1030_BLUE_GAIN_DEFAULT, |
| 113 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 114 | }, |
| 115 | .set = po1030_set_blue_balance, |
| 116 | .get = po1030_get_blue_balance |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 117 | }, |
| 118 | #define HFLIP_IDX 4 |
| 119 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 120 | { |
| 121 | .id = V4L2_CID_HFLIP, |
| 122 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 123 | .name = "horizontal flip", |
| 124 | .minimum = 0, |
| 125 | .maximum = 1, |
| 126 | .step = 1, |
| 127 | .default_value = 0, |
| 128 | }, |
| 129 | .set = po1030_set_hflip, |
| 130 | .get = po1030_get_hflip |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 131 | }, |
| 132 | #define VFLIP_IDX 5 |
| 133 | { |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 134 | { |
| 135 | .id = V4L2_CID_VFLIP, |
| 136 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 137 | .name = "vertical flip", |
| 138 | .minimum = 0, |
| 139 | .maximum = 1, |
| 140 | .step = 1, |
| 141 | .default_value = 0, |
| 142 | }, |
| 143 | .set = po1030_set_vflip, |
| 144 | .get = po1030_get_vflip |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 145 | }, |
| 146 | #define AUTO_WHITE_BALANCE_IDX 6 |
| 147 | { |
| 148 | { |
| 149 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 150 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 151 | .name = "auto white balance", |
| 152 | .minimum = 0, |
| 153 | .maximum = 1, |
| 154 | .step = 1, |
| 155 | .default_value = 0, |
| 156 | }, |
| 157 | .set = po1030_set_auto_white_balance, |
| 158 | .get = po1030_get_auto_white_balance |
Erik Andr?n | dd9ce84 | 2009-01-13 13:43:46 -0300 | [diff] [blame] | 159 | }, |
| 160 | #define AUTO_EXPOSURE_IDX 7 |
| 161 | { |
| 162 | { |
| 163 | .id = V4L2_CID_EXPOSURE_AUTO, |
| 164 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 165 | .name = "auto exposure", |
| 166 | .minimum = 0, |
| 167 | .maximum = 1, |
| 168 | .step = 1, |
| 169 | .default_value = 0, |
| 170 | }, |
| 171 | .set = po1030_set_auto_exposure, |
| 172 | .get = po1030_get_auto_exposure |
| 173 | }, |
Erik Andr?n | b933d58 | 2009-01-13 13:55:52 -0300 | [diff] [blame^] | 174 | #define GREEN_BALANCE_IDX 8 |
| 175 | { |
| 176 | { |
| 177 | .id = M5602_V4L2_CID_GREEN_BALANCE, |
| 178 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 179 | .name = "green balance", |
| 180 | .minimum = 0x00, |
| 181 | .maximum = 0xff, |
| 182 | .step = 0x1, |
| 183 | .default_value = PO1030_GREEN_GAIN_DEFAULT, |
| 184 | .flags = V4L2_CTRL_FLAG_SLIDER |
| 185 | }, |
| 186 | .set = po1030_set_green_balance, |
| 187 | .get = po1030_get_green_balance |
| 188 | }, |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 189 | }; |
| 190 | |
Erik Andrén | 658efb6 | 2008-11-24 14:21:29 -0300 | [diff] [blame] | 191 | static void po1030_dump_registers(struct sd *sd); |
| 192 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 193 | int po1030_probe(struct sd *sd) |
| 194 | { |
Erik Andr?n | 3e5cbad | 2009-01-11 12:52:10 -0300 | [diff] [blame] | 195 | u8 dev_id_h = 0, i; |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 196 | s32 *sensor_settings; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 197 | |
| 198 | if (force_sensor) { |
| 199 | if (force_sensor == PO1030_SENSOR) { |
| 200 | info("Forcing a %s sensor", po1030.name); |
| 201 | goto sensor_found; |
| 202 | } |
| 203 | /* If we want to force another sensor, don't try to probe this |
| 204 | * one */ |
| 205 | return -ENODEV; |
| 206 | } |
| 207 | |
| 208 | info("Probing for a po1030 sensor"); |
| 209 | |
| 210 | /* Run the pre-init to actually probe the unit */ |
| 211 | for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) { |
| 212 | u8 data = preinit_po1030[i][2]; |
| 213 | if (preinit_po1030[i][0] == SENSOR) |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 214 | m5602_write_sensor(sd, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 215 | preinit_po1030[i][1], &data, 1); |
| 216 | else |
| 217 | m5602_write_bridge(sd, preinit_po1030[i][1], data); |
| 218 | } |
| 219 | |
Erik Andr?n | fcb9810 | 2009-01-08 04:04:19 -0300 | [diff] [blame] | 220 | if (m5602_read_sensor(sd, PO1030_DEVID_H, &dev_id_h, 1)) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 221 | return -ENODEV; |
| 222 | |
Erik Andr?n | 3e5cbad | 2009-01-11 12:52:10 -0300 | [diff] [blame] | 223 | if (dev_id_h == 0x30) { |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 224 | info("Detected a po1030 sensor"); |
| 225 | goto sensor_found; |
| 226 | } |
| 227 | return -ENODEV; |
| 228 | |
| 229 | sensor_found: |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 230 | sensor_settings = kmalloc( |
| 231 | ARRAY_SIZE(po1030_ctrls) * sizeof(s32), GFP_KERNEL); |
| 232 | if (!sensor_settings) |
| 233 | return -ENOMEM; |
| 234 | |
Erik Andr?n | 74cadfe | 2008-12-30 16:48:42 -0300 | [diff] [blame] | 235 | sd->gspca_dev.cam.cam_mode = po1030_modes; |
| 236 | sd->gspca_dev.cam.nmodes = ARRAY_SIZE(po1030_modes); |
Erik Andr?n | e17cc08 | 2008-12-30 17:06:55 -0300 | [diff] [blame] | 237 | sd->desc->ctrls = po1030_ctrls; |
Erik Andr?n | e4cc4fc | 2008-12-30 15:27:17 -0300 | [diff] [blame] | 238 | sd->desc->nctrls = ARRAY_SIZE(po1030_ctrls); |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 239 | |
| 240 | for (i = 0; i < ARRAY_SIZE(po1030_ctrls); i++) |
| 241 | sensor_settings[i] = po1030_ctrls[i].qctrl.default_value; |
| 242 | sd->sensor_priv = sensor_settings; |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 243 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 244 | return 0; |
| 245 | } |
| 246 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 247 | int po1030_init(struct sd *sd) |
| 248 | { |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 249 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 250 | int i, err = 0; |
| 251 | |
| 252 | /* Init the sensor */ |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 253 | for (i = 0; i < ARRAY_SIZE(init_po1030) && !err; i++) { |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 254 | u8 data[2] = {0x00, 0x00}; |
| 255 | |
| 256 | switch (init_po1030[i][0]) { |
| 257 | case BRIDGE: |
| 258 | err = m5602_write_bridge(sd, |
| 259 | init_po1030[i][1], |
| 260 | init_po1030[i][2]); |
| 261 | break; |
| 262 | |
| 263 | case SENSOR: |
| 264 | data[0] = init_po1030[i][2]; |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 265 | err = m5602_write_sensor(sd, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 266 | init_po1030[i][1], data, 1); |
| 267 | break; |
| 268 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 269 | default: |
| 270 | info("Invalid stream command, exiting init"); |
| 271 | return -EINVAL; |
| 272 | } |
| 273 | } |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 274 | if (err < 0) |
| 275 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 276 | |
Erik Andr?n | 36e756c | 2009-01-09 13:35:00 -0300 | [diff] [blame] | 277 | if (dump_sensor) |
| 278 | po1030_dump_registers(sd); |
| 279 | |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 280 | err = po1030_set_exposure(&sd->gspca_dev, |
| 281 | sensor_settings[EXPOSURE_IDX]); |
| 282 | if (err < 0) |
| 283 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 284 | |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 285 | err = po1030_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); |
| 286 | if (err < 0) |
| 287 | return err; |
| 288 | |
| 289 | err = po1030_set_hflip(&sd->gspca_dev, sensor_settings[HFLIP_IDX]); |
| 290 | if (err < 0) |
| 291 | return err; |
| 292 | |
| 293 | err = po1030_set_vflip(&sd->gspca_dev, sensor_settings[VFLIP_IDX]); |
| 294 | if (err < 0) |
| 295 | return err; |
| 296 | |
| 297 | err = po1030_set_red_balance(&sd->gspca_dev, |
| 298 | sensor_settings[RED_BALANCE_IDX]); |
| 299 | if (err < 0) |
| 300 | return err; |
| 301 | |
Erik Andr?n | 926d503 | 2009-01-11 15:23:46 -0300 | [diff] [blame] | 302 | err = po1030_set_blue_balance(&sd->gspca_dev, |
Erik Andr?n | cb29e69 | 2009-01-07 18:05:08 -0300 | [diff] [blame] | 303 | sensor_settings[BLUE_BALANCE_IDX]); |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 304 | if (err < 0) |
| 305 | return err; |
| 306 | |
Erik Andr?n | b933d58 | 2009-01-13 13:55:52 -0300 | [diff] [blame^] | 307 | err = po1030_set_green_balance(&sd->gspca_dev, |
| 308 | sensor_settings[GREEN_BALANCE_IDX]); |
| 309 | if (err < 0) |
| 310 | return err; |
| 311 | |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 312 | err = po1030_set_auto_white_balance(&sd->gspca_dev, |
Erik Andr?n | dd9ce84 | 2009-01-13 13:43:46 -0300 | [diff] [blame] | 313 | sensor_settings[AUTO_WHITE_BALANCE_IDX]); |
| 314 | if (err < 0) |
| 315 | return err; |
| 316 | |
| 317 | err = po1030_set_auto_exposure(&sd->gspca_dev, |
| 318 | sensor_settings[AUTO_EXPOSURE_IDX]); |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 319 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 320 | } |
| 321 | |
Erik Andr?n | c996b36 | 2009-01-08 14:15:06 -0300 | [diff] [blame] | 322 | int po1030_start(struct sd *sd) |
| 323 | { |
| 324 | int i, err = 0; |
| 325 | /* Synthesize the vsync/hsync setup */ |
| 326 | for (i = 0; i < ARRAY_SIZE(start_po1030) && !err; i++) { |
| 327 | if (start_po1030[i][0] == BRIDGE) |
| 328 | err = m5602_write_bridge(sd, start_po1030[i][1], |
| 329 | start_po1030[i][2]); |
| 330 | else if (start_po1030[i][0] == SENSOR) { |
| 331 | u8 data = start_po1030[i][2]; |
| 332 | err = m5602_write_sensor(sd, |
| 333 | start_po1030[i][1], &data, 1); |
| 334 | } |
| 335 | } |
| 336 | return err; |
| 337 | } |
| 338 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 339 | static int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 340 | { |
| 341 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 342 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 343 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 344 | *val = sensor_settings[EXPOSURE_IDX]; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 345 | PDEBUG(D_V4L2, "Exposure read as %d", *val); |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 346 | return 0; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 347 | } |
| 348 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 349 | static int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 350 | { |
| 351 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 352 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 353 | u8 i2c_data; |
| 354 | int err; |
| 355 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 356 | sensor_settings[EXPOSURE_IDX] = val; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 357 | PDEBUG(D_V4L2, "Set exposure to %d", val & 0xffff); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 358 | |
| 359 | i2c_data = ((val & 0xff00) >> 8); |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 360 | PDEBUG(D_V4L2, "Set exposure to high byte to 0x%x", |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 361 | i2c_data); |
| 362 | |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 363 | err = m5602_write_sensor(sd, PO1030_INTEGLINES_H, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 364 | &i2c_data, 1); |
| 365 | if (err < 0) |
Erik Andr?n | 051781b | 2008-12-27 12:28:00 -0300 | [diff] [blame] | 366 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 367 | |
| 368 | i2c_data = (val & 0xff); |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 369 | PDEBUG(D_V4L2, "Set exposure to low byte to 0x%x", |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 370 | i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 371 | err = m5602_write_sensor(sd, PO1030_INTEGLINES_M, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 372 | &i2c_data, 1); |
| 373 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 374 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 375 | } |
| 376 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 377 | static int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 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; |
| 381 | |
| 382 | *val = sensor_settings[GAIN_IDX]; |
| 383 | PDEBUG(D_V4L2, "Read global gain %d", *val); |
| 384 | return 0; |
| 385 | } |
| 386 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 387 | static int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val) |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 388 | { |
| 389 | struct sd *sd = (struct sd *) gspca_dev; |
| 390 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 391 | u8 i2c_data; |
| 392 | int err; |
| 393 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 394 | sensor_settings[GAIN_IDX] = val; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 395 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 396 | i2c_data = val & 0xff; |
| 397 | PDEBUG(D_V4L2, "Set global gain to %d", i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 398 | err = m5602_write_sensor(sd, PO1030_GLOBALGAIN, |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 399 | &i2c_data, 1); |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 400 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 401 | } |
| 402 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 403 | static int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 404 | { |
| 405 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 406 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 407 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 408 | *val = sensor_settings[HFLIP_IDX]; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 409 | PDEBUG(D_V4L2, "Read hflip %d", *val); |
| 410 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 411 | return 0; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 412 | } |
| 413 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 414 | static int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val) |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 415 | { |
| 416 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 417 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 418 | u8 i2c_data; |
| 419 | int err; |
| 420 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 421 | sensor_settings[HFLIP_IDX] = val; |
| 422 | |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 423 | PDEBUG(D_V4L2, "Set hflip %d", val); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 424 | err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1); |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 425 | if (err < 0) |
Erik Andr?n | 051781b | 2008-12-27 12:28:00 -0300 | [diff] [blame] | 426 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 427 | |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 428 | i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 429 | |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 430 | err = m5602_write_sensor(sd, PO1030_CONTROL2, |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 431 | &i2c_data, 1); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 432 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 433 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 434 | } |
| 435 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 436 | static int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 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 | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 440 | |
Erik Andr?n | 2742908 | 2009-01-07 17:41:47 -0300 | [diff] [blame] | 441 | *val = sensor_settings[VFLIP_IDX]; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 442 | PDEBUG(D_V4L2, "Read vflip %d", *val); |
| 443 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 444 | return 0; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 445 | } |
| 446 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 447 | static int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val) |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 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 | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 451 | u8 i2c_data; |
| 452 | int err; |
| 453 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 454 | sensor_settings[VFLIP_IDX] = val; |
| 455 | |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 456 | PDEBUG(D_V4L2, "Set vflip %d", val); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 457 | err = m5602_read_sensor(sd, PO1030_CONTROL2, &i2c_data, 1); |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 458 | if (err < 0) |
Erik Andr?n | 051781b | 2008-12-27 12:28:00 -0300 | [diff] [blame] | 459 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 460 | |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 461 | i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 462 | |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 463 | err = m5602_write_sensor(sd, PO1030_CONTROL2, |
Erik Andrén | 1d07b6f | 2008-11-27 14:07:24 -0300 | [diff] [blame] | 464 | &i2c_data, 1); |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 465 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 466 | return err; |
Erik Andren | e2c9749 | 2008-10-16 16:49:17 -0300 | [diff] [blame] | 467 | } |
| 468 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 469 | static int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 470 | { |
| 471 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 472 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 473 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 474 | *val = sensor_settings[RED_BALANCE_IDX]; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 475 | PDEBUG(D_V4L2, "Read red gain %d", *val); |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 476 | return 0; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 477 | } |
| 478 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 479 | static int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 480 | { |
| 481 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 482 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 483 | u8 i2c_data; |
| 484 | int err; |
| 485 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 486 | sensor_settings[RED_BALANCE_IDX] = val; |
| 487 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 488 | i2c_data = val & 0xff; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 489 | PDEBUG(D_V4L2, "Set red gain to %d", i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 490 | err = m5602_write_sensor(sd, PO1030_RED_GAIN, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 491 | &i2c_data, 1); |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 492 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 493 | } |
| 494 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 495 | static int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 496 | { |
| 497 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 498 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 499 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 500 | *val = sensor_settings[BLUE_BALANCE_IDX]; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 501 | PDEBUG(D_V4L2, "Read blue gain %d", *val); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 502 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 503 | return 0; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 504 | } |
| 505 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 506 | static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 507 | { |
| 508 | struct sd *sd = (struct sd *) gspca_dev; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 509 | s32 *sensor_settings = sd->sensor_priv; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 510 | u8 i2c_data; |
| 511 | int err; |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 512 | |
| 513 | sensor_settings[BLUE_BALANCE_IDX] = val; |
| 514 | |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 515 | i2c_data = val & 0xff; |
Erik Andren | 17ea88a | 2008-10-16 16:46:07 -0300 | [diff] [blame] | 516 | PDEBUG(D_V4L2, "Set blue gain to %d", i2c_data); |
Erik Andr?n | bb9460e | 2009-01-07 13:54:13 -0300 | [diff] [blame] | 517 | err = m5602_write_sensor(sd, PO1030_BLUE_GAIN, |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 518 | &i2c_data, 1); |
| 519 | |
Erik Andrén | 7b9f246 | 2008-11-20 03:59:02 -0300 | [diff] [blame] | 520 | return err; |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 521 | } |
| 522 | |
Erik Andr?n | b933d58 | 2009-01-13 13:55:52 -0300 | [diff] [blame^] | 523 | static int po1030_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val) |
| 524 | { |
| 525 | struct sd *sd = (struct sd *) gspca_dev; |
| 526 | s32 *sensor_settings = sd->sensor_priv; |
| 527 | |
| 528 | *val = sensor_settings[GREEN_BALANCE_IDX]; |
| 529 | PDEBUG(D_V4L2, "Read green gain %d", *val); |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val) |
| 535 | { |
| 536 | struct sd *sd = (struct sd *) gspca_dev; |
| 537 | s32 *sensor_settings = sd->sensor_priv; |
| 538 | u8 i2c_data; |
| 539 | int err; |
| 540 | |
| 541 | sensor_settings[GREEN_BALANCE_IDX] = val; |
| 542 | i2c_data = val & 0xff; |
| 543 | PDEBUG(D_V4L2, "Set green gain to %d", i2c_data); |
| 544 | |
| 545 | err = m5602_write_sensor(sd, PO1030_GREEN_1_GAIN, |
| 546 | &i2c_data, 1); |
| 547 | if (err < 0) |
| 548 | return err; |
| 549 | |
| 550 | return m5602_write_sensor(sd, PO1030_GREEN_2_GAIN, |
| 551 | &i2c_data, 1); |
| 552 | } |
| 553 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 554 | static int po1030_get_auto_white_balance(struct gspca_dev *gspca_dev, |
| 555 | __s32 *val) |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 556 | { |
| 557 | struct sd *sd = (struct sd *) gspca_dev; |
| 558 | s32 *sensor_settings = sd->sensor_priv; |
| 559 | |
| 560 | *val = sensor_settings[AUTO_WHITE_BALANCE_IDX]; |
| 561 | PDEBUG(D_V4L2, "Auto white balancing is %d", *val); |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
Erik Andr?n | cf811d5 | 2009-04-03 02:49:10 -0300 | [diff] [blame] | 566 | static int po1030_set_auto_white_balance(struct gspca_dev *gspca_dev, |
| 567 | __s32 val) |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 568 | { |
| 569 | struct sd *sd = (struct sd *) gspca_dev; |
| 570 | s32 *sensor_settings = sd->sensor_priv; |
| 571 | u8 i2c_data; |
| 572 | int err; |
| 573 | |
| 574 | sensor_settings[AUTO_WHITE_BALANCE_IDX] = val; |
| 575 | |
| 576 | err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); |
| 577 | if (err < 0) |
| 578 | return err; |
| 579 | |
Erik Andr?n | dd9ce84 | 2009-01-13 13:43:46 -0300 | [diff] [blame] | 580 | PDEBUG(D_V4L2, "Set auto white balance to %d", val); |
Erik Andr?n | 3b9ae65 | 2009-01-08 03:53:50 -0300 | [diff] [blame] | 581 | i2c_data = (i2c_data & 0xfe) | (val & 0x01); |
| 582 | err = m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); |
| 583 | return err; |
| 584 | } |
| 585 | |
Erik Andr?n | dd9ce84 | 2009-01-13 13:43:46 -0300 | [diff] [blame] | 586 | static int po1030_get_auto_exposure(struct gspca_dev *gspca_dev, |
| 587 | __s32 *val) |
| 588 | { |
| 589 | struct sd *sd = (struct sd *) gspca_dev; |
| 590 | s32 *sensor_settings = sd->sensor_priv; |
| 591 | |
| 592 | *val = sensor_settings[AUTO_EXPOSURE_IDX]; |
| 593 | PDEBUG(D_V4L2, "Auto exposure is %d", *val); |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | static int po1030_set_auto_exposure(struct gspca_dev *gspca_dev, |
| 598 | __s32 val) |
| 599 | { |
| 600 | struct sd *sd = (struct sd *) gspca_dev; |
| 601 | s32 *sensor_settings = sd->sensor_priv; |
| 602 | u8 i2c_data; |
| 603 | int err; |
| 604 | |
| 605 | sensor_settings[AUTO_EXPOSURE_IDX] = val; |
| 606 | err = m5602_read_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); |
| 607 | if (err < 0) |
| 608 | return err; |
| 609 | |
| 610 | PDEBUG(D_V4L2, "Set auto exposure to %d", val); |
| 611 | i2c_data = (i2c_data & 0xfd) | ((val & 0x01) << 1); |
| 612 | return m5602_write_sensor(sd, PO1030_AUTOCTRL1, &i2c_data, 1); |
| 613 | } |
| 614 | |
Erik Andr?n | 05d7d9c | 2009-01-06 06:39:11 -0300 | [diff] [blame] | 615 | void po1030_disconnect(struct sd *sd) |
| 616 | { |
| 617 | sd->sensor = NULL; |
| 618 | kfree(sd->sensor_priv); |
| 619 | } |
| 620 | |
Erik Andrén | 658efb6 | 2008-11-24 14:21:29 -0300 | [diff] [blame] | 621 | static void po1030_dump_registers(struct sd *sd) |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 622 | { |
| 623 | int address; |
| 624 | u8 value = 0; |
| 625 | |
| 626 | info("Dumping the po1030 sensor core registers"); |
| 627 | for (address = 0; address < 0x7f; address++) { |
Erik Andrén | c061c97 | 2008-11-27 13:46:39 -0300 | [diff] [blame] | 628 | m5602_read_sensor(sd, address, &value, 1); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 629 | info("register 0x%x contains 0x%x", |
| 630 | address, value); |
| 631 | } |
| 632 | |
| 633 | info("po1030 register state dump complete"); |
| 634 | |
| 635 | info("Probing for which registers that are read/write"); |
| 636 | for (address = 0; address < 0xff; address++) { |
| 637 | u8 old_value, ctrl_value; |
| 638 | u8 test_value[2] = {0xff, 0xff}; |
| 639 | |
Erik Andrén | c061c97 | 2008-11-27 13:46:39 -0300 | [diff] [blame] | 640 | m5602_read_sensor(sd, address, &old_value, 1); |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 641 | m5602_write_sensor(sd, address, test_value, 1); |
Erik Andrén | c061c97 | 2008-11-27 13:46:39 -0300 | [diff] [blame] | 642 | m5602_read_sensor(sd, address, &ctrl_value, 1); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 643 | |
| 644 | if (ctrl_value == test_value[0]) |
| 645 | info("register 0x%x is writeable", address); |
| 646 | else |
| 647 | info("register 0x%x is read only", address); |
| 648 | |
| 649 | /* Restore original value */ |
Erik Andrén | 6dc4cff | 2008-11-26 04:08:10 -0300 | [diff] [blame] | 650 | m5602_write_sensor(sd, address, &old_value, 1); |
Erik Andren | c109f81 | 2008-10-01 04:51:53 -0300 | [diff] [blame] | 651 | } |
| 652 | } |