aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Risolia <luca.risolia@studio.unibo.it>2007-05-02 09:04:03 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-05-09 09:12:38 -0400
commit480b55c26e2f6408e86f22a69fcecc29e019e819 (patch)
tree5df75439da6c7105f54f00aa76d9bdc20ffedd7f
parentb3785596e3964656b9901f4eff73bf40b654d425 (diff)
V4L/DVB (5585): SN9C1xx driver updates
* Default color improvements to the OV7660 @ Fix sn9c102_write_reg() @ Fix sn9c102_i2c_try_raw_read() @ Fix MI-0343 + Add support for pair MI0360+SN9C120 + Add more USB ids Signed-off-by: Luca Risolia <luca.risolia@studio.unibo.it> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r--Documentation/video4linux/sn9c102.txt18
-rw-r--r--drivers/media/video/sn9c102/sn9c102.h2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c91
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h4
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131d.c6
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131r.c8
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0343.c51
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0360.c220
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7630.c25
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7660.c63
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas106b.c14
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bcb.c48
-rw-r--r--drivers/media/video/sn9c102/sn9c102_sensor.h33
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110c1b.c2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110d.c2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5130d1b.c2
16 files changed, 355 insertions, 234 deletions
diff --git a/Documentation/video4linux/sn9c102.txt b/Documentation/video4linux/sn9c102.txt
index 5fe0ad7dfc20..279717c96f63 100644
--- a/Documentation/video4linux/sn9c102.txt
+++ b/Documentation/video4linux/sn9c102.txt
@@ -355,6 +355,9 @@ devices assembling the SN9C1xx PC camera controllers:
355 355
356Vendor ID Product ID 356Vendor ID Product ID
357--------- ---------- 357--------- ----------
3580x0458 0x7025
3590x045e 0x00f5
3600x045e 0x00f7
3580x0471 0x0327 3610x0471 0x0327
3590x0471 0x0328 3620x0471 0x0328
3600x0c45 0x6001 3630x0c45 0x6001
@@ -432,7 +435,7 @@ Image sensor / SN9C1xx bridge | SN9C10[12] SN9C103 SN9C105 SN9C120
432HV7131D Hynix Semiconductor | Yes No No No 435HV7131D Hynix Semiconductor | Yes No No No
433HV7131R Hynix Semiconductor | No Yes Yes Yes 436HV7131R Hynix Semiconductor | No Yes Yes Yes
434MI-0343 Micron Technology | Yes No No No 437MI-0343 Micron Technology | Yes No No No
435MI-0360 Micron Technology | No Yes No No 438MI-0360 Micron Technology | No Yes Yes Yes
436OV7630 OmniVision Technologies | Yes Yes No No 439OV7630 OmniVision Technologies | Yes Yes No No
437OV7660 OmniVision Technologies | No No Yes Yes 440OV7660 OmniVision Technologies | No No Yes Yes
438PAS106B PixArt Imaging | Yes No No No 441PAS106B PixArt Imaging | Yes No No No
@@ -478,13 +481,12 @@ scaling factor is restored to 1.
478This driver supports two different video formats: the first one is the "8-bit 481This driver supports two different video formats: the first one is the "8-bit
479Sequential Bayer" format and can be used to obtain uncompressed video data 482Sequential Bayer" format and can be used to obtain uncompressed video data
480from the device through the current I/O method, while the second one provides 483from the device through the current I/O method, while the second one provides
481"raw" compressed video data (without frame headers not related to the 484either "raw" compressed video data (without frame headers not related to the
482compressed data). The compression quality may vary from 0 to 1 and can be 485compressed data) or standard JPEG (with frame headers). The compression quality
483selected or queried thanks to the VIDIOC_S_JPEGCOMP and VIDIOC_G_JPEGCOMP V4L2 486may vary from 0 to 1 and can be selected or queried thanks to the
484ioctl's. For maximum flexibility, both the default active video format and the 487VIDIOC_S_JPEGCOMP and VIDIOC_G_JPEGCOMP V4L2 ioctl's. For maximum flexibility,
485default compression quality depend on how the image sensor being used is 488both the default active video format and the default compression quality
486initialized (as described in the documentation of the API for the image sensors 489depend on how the image sensor being used is initialized.
487supplied by this driver).
488 490
489 491
49011. Video frame formats [1] 49211. Video frame formats [1]
diff --git a/drivers/media/video/sn9c102/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 680e74634527..11fcb49f5b99 100644
--- a/drivers/media/video/sn9c102/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -141,7 +141,7 @@ sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
141 141
142void 142void
143sn9c102_attach_sensor(struct sn9c102_device* cam, 143sn9c102_attach_sensor(struct sn9c102_device* cam,
144 struct sn9c102_sensor* sensor) 144 const struct sn9c102_sensor* sensor)
145{ 145{
146 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor)); 146 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
147} 147}
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 89f83354de3b..74a204f8ebc8 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -48,8 +48,8 @@
48#define SN9C102_MODULE_AUTHOR "(C) 2004-2007 Luca Risolia" 48#define SN9C102_MODULE_AUTHOR "(C) 2004-2007 Luca Risolia"
49#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 49#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
50#define SN9C102_MODULE_LICENSE "GPL" 50#define SN9C102_MODULE_LICENSE "GPL"
51#define SN9C102_MODULE_VERSION "1:1.39" 51#define SN9C102_MODULE_VERSION "1:1.44"
52#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 39) 52#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 44)
53 53
54/*****************************************************************************/ 54/*****************************************************************************/
55 55
@@ -209,38 +209,41 @@ static void sn9c102_queue_unusedframes(struct sn9c102_device* cam)
209} 209}
210 210
211/*****************************************************************************/ 211/*****************************************************************************/
212
212/* 213/*
213 * Write a sequence of count value/register pairs. Returns -1 after the 214 Write a sequence of count value/register pairs. Returns -1 after the first
214 * first failed write, or 0 for no errors. 215 failed write, or 0 for no errors.
215 */ 216*/
216int sn9c102_write_regs(struct sn9c102_device* cam, const u8 valreg[][2], 217int sn9c102_write_regs(struct sn9c102_device* cam, const u8 valreg[][2],
217 int count) 218 int count)
218{ 219{
219 struct usb_device* udev = cam->usbdev; 220 struct usb_device* udev = cam->usbdev;
220 u8* value = cam->control_buffer; /* Needed for DMA'able memory */ 221 u8* buff = cam->control_buffer;
221 int i, res; 222 int i, res;
222 223
223 for (i = 0; i < count; i++) { 224 for (i = 0; i < count; i++) {
224 u8 index = valreg[i][1]; 225 u8 index = valreg[i][1];
225 226
226 /* 227 /*
227 * index is a u8, so it must be <256 and can't be out of range. 228 index is a u8, so it must be <256 and can't be out of range.
228 * If we put in a check anyway, gcc annoys us with a warning 229 If we put in a check anyway, gcc annoys us with a warning
229 * that our check is useless. People get all uppity when they 230 hat our check is useless. People get all uppity when they
230 * see warnings in the kernel compile. 231 see warnings in the kernel compile.
231 */ 232 */
232 233
233 *value = valreg[i][0]; 234 *buff = valreg[i][0];
234 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 235
235 0x08, 0x41, index, 0, 236 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08,
236 value, 1, SN9C102_CTRL_TIMEOUT); 237 0x41, index, 0, buff, 1,
238 SN9C102_CTRL_TIMEOUT);
239
237 if (res < 0) { 240 if (res < 0) {
238 DBG(3, "Failed to write a register (value 0x%02X, " 241 DBG(3, "Failed to write a register (value 0x%02X, "
239 "index 0x%02X, error %d)", *value, index, res); 242 "index 0x%02X, error %d)", *buff, index, res);
240 return -1; 243 return -1;
241 } 244 }
242 245
243 cam->reg[index] = *value; 246 cam->reg[index] = *buff;
244 } 247 }
245 248
246 return 0; 249 return 0;
@@ -272,8 +275,8 @@ int sn9c102_write_reg(struct sn9c102_device* cam, u8 value, u16 index)
272} 275}
273 276
274 277
275/* NOTE: reading some registers always returns 0 */ 278/* NOTE: with the SN9C10[123] reading some registers always returns 0 */
276static int sn9c102_read_reg(struct sn9c102_device* cam, u16 index) 279int sn9c102_read_reg(struct sn9c102_device* cam, u16 index)
277{ 280{
278 struct usb_device* udev = cam->usbdev; 281 struct usb_device* udev = cam->usbdev;
279 u8* buff = cam->control_buffer; 282 u8* buff = cam->control_buffer;
@@ -299,7 +302,8 @@ int sn9c102_pread_reg(struct sn9c102_device* cam, u16 index)
299 302
300 303
301static int 304static int
302sn9c102_i2c_wait(struct sn9c102_device* cam, struct sn9c102_sensor* sensor) 305sn9c102_i2c_wait(struct sn9c102_device* cam,
306 const struct sn9c102_sensor* sensor)
303{ 307{
304 int i, r; 308 int i, r;
305 309
@@ -320,7 +324,7 @@ sn9c102_i2c_wait(struct sn9c102_device* cam, struct sn9c102_sensor* sensor)
320 324
321static int 325static int
322sn9c102_i2c_detect_read_error(struct sn9c102_device* cam, 326sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
323 struct sn9c102_sensor* sensor) 327 const struct sn9c102_sensor* sensor)
324{ 328{
325 int r , err = 0; 329 int r , err = 0;
326 330
@@ -342,7 +346,7 @@ sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
342 346
343static int 347static int
344sn9c102_i2c_detect_write_error(struct sn9c102_device* cam, 348sn9c102_i2c_detect_write_error(struct sn9c102_device* cam,
345 struct sn9c102_sensor* sensor) 349 const struct sn9c102_sensor* sensor)
346{ 350{
347 int r; 351 int r;
348 r = sn9c102_read_reg(cam, 0x08); 352 r = sn9c102_read_reg(cam, 0x08);
@@ -352,12 +356,12 @@ sn9c102_i2c_detect_write_error(struct sn9c102_device* cam,
352 356
353int 357int
354sn9c102_i2c_try_raw_read(struct sn9c102_device* cam, 358sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
355 struct sn9c102_sensor* sensor, u8 data0, u8 data1, 359 const struct sn9c102_sensor* sensor, u8 data0,
356 u8 n, u8 buffer[]) 360 u8 data1, u8 n, u8 buffer[])
357{ 361{
358 struct usb_device* udev = cam->usbdev; 362 struct usb_device* udev = cam->usbdev;
359 u8* data = cam->control_buffer; 363 u8* data = cam->control_buffer;
360 int err = 0, res; 364 int i = 0, err = 0, res;
361 365
362 /* Write cycle */ 366 /* Write cycle */
363 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) | 367 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) |
@@ -402,7 +406,8 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
402 } 406 }
403 407
404 if (buffer) 408 if (buffer)
405 memcpy(buffer, data, sizeof(buffer)); 409 for (i = 0; i < n && i < 5; i++)
410 buffer[n-i-1] = data[4-i];
406 411
407 return (int)data[4]; 412 return (int)data[4];
408} 413}
@@ -410,7 +415,7 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
410 415
411int 416int
412sn9c102_i2c_try_raw_write(struct sn9c102_device* cam, 417sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
413 struct sn9c102_sensor* sensor, u8 n, u8 data0, 418 const struct sn9c102_sensor* sensor, u8 n, u8 data0,
414 u8 data1, u8 data2, u8 data3, u8 data4, u8 data5) 419 u8 data1, u8 data2, u8 data3, u8 data4, u8 data5)
415{ 420{
416 struct usb_device* udev = cam->usbdev; 421 struct usb_device* udev = cam->usbdev;
@@ -449,7 +454,7 @@ sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
449 454
450int 455int
451sn9c102_i2c_try_read(struct sn9c102_device* cam, 456sn9c102_i2c_try_read(struct sn9c102_device* cam,
452 struct sn9c102_sensor* sensor, u8 address) 457 const struct sn9c102_sensor* sensor, u8 address)
453{ 458{
454 return sn9c102_i2c_try_raw_read(cam, sensor, sensor->i2c_slave_id, 459 return sn9c102_i2c_try_raw_read(cam, sensor, sensor->i2c_slave_id,
455 address, 1, NULL); 460 address, 1, NULL);
@@ -458,7 +463,7 @@ sn9c102_i2c_try_read(struct sn9c102_device* cam,
458 463
459int 464int
460sn9c102_i2c_try_write(struct sn9c102_device* cam, 465sn9c102_i2c_try_write(struct sn9c102_device* cam,
461 struct sn9c102_sensor* sensor, u8 address, u8 value) 466 const struct sn9c102_sensor* sensor, u8 address, u8 value)
462{ 467{
463 return sn9c102_i2c_try_raw_write(cam, sensor, 3, 468 return sn9c102_i2c_try_raw_write(cam, sensor, 3,
464 sensor->i2c_slave_id, address, 469 sensor->i2c_slave_id, address,
@@ -657,16 +662,6 @@ sn9c102_write_jpegheader(struct sn9c102_device* cam, struct sn9c102_frame_t* f)
657} 662}
658 663
659 664
660static void
661sn9c102_write_eoimarker(struct sn9c102_device* cam, struct sn9c102_frame_t* f)
662{
663 static const u8 eoi_marker[2] = {0xff, 0xd9};
664
665 memcpy(f->bufmem + f->buf.bytesused, eoi_marker, sizeof(eoi_marker));
666 f->buf.bytesused += sizeof(eoi_marker);
667}
668
669
670static void sn9c102_urb_complete(struct urb *urb) 665static void sn9c102_urb_complete(struct urb *urb)
671{ 666{
672 struct sn9c102_device* cam = urb->context; 667 struct sn9c102_device* cam = urb->context;
@@ -3181,14 +3176,14 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
3181 3176
3182static const struct file_operations sn9c102_fops = { 3177static const struct file_operations sn9c102_fops = {
3183 .owner = THIS_MODULE, 3178 .owner = THIS_MODULE,
3184 .open = sn9c102_open, 3179 .open = sn9c102_open,
3185 .release = sn9c102_release, 3180 .release = sn9c102_release,
3186 .ioctl = sn9c102_ioctl, 3181 .ioctl = sn9c102_ioctl,
3187 .compat_ioctl = v4l_compat_ioctl32, 3182 .compat_ioctl = v4l_compat_ioctl32,
3188 .read = sn9c102_read, 3183 .read = sn9c102_read,
3189 .poll = sn9c102_poll, 3184 .poll = sn9c102_poll,
3190 .mmap = sn9c102_mmap, 3185 .mmap = sn9c102_mmap,
3191 .llseek = no_llseek, 3186 .llseek = no_llseek,
3192}; 3187};
3193 3188
3194/*****************************************************************************/ 3189/*****************************************************************************/
@@ -3251,7 +3246,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3251 break; 3246 break;
3252 } 3247 }
3253 3248
3254 for (i = 0; sn9c102_sensor_table[i]; i++) { 3249 for (i = 0; i < ARRAY_SIZE(sn9c102_sensor_table); i++) {
3255 err = sn9c102_sensor_table[i](cam); 3250 err = sn9c102_sensor_table[i](cam);
3256 if (!err) 3251 if (!err)
3257 break; 3252 break;
@@ -3262,7 +3257,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3262 DBG(3, "Support for %s maintained by %s", 3257 DBG(3, "Support for %s maintained by %s",
3263 cam->sensor.name, cam->sensor.maintainer); 3258 cam->sensor.name, cam->sensor.maintainer);
3264 } else { 3259 } else {
3265 DBG(1, "No supported image sensor detected"); 3260 DBG(1, "No supported image sensor detected for this bridge");
3266 err = -ENODEV; 3261 err = -ENODEV;
3267 goto fail; 3262 goto fail;
3268 } 3263 }
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index f49bd8c5b86e..916054faf9be 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -86,6 +86,8 @@ static const struct usb_device_id sn9c102_id_table[] = {
86 { SN9C102_USB_DEVICE(0x0c45, 0x60bc, BRIDGE_SN9C103), }, 86 { SN9C102_USB_DEVICE(0x0c45, 0x60bc, BRIDGE_SN9C103), },
87 { SN9C102_USB_DEVICE(0x0c45, 0x60be, BRIDGE_SN9C103), }, 87 { SN9C102_USB_DEVICE(0x0c45, 0x60be, BRIDGE_SN9C103), },
88 /* SN9C105 */ 88 /* SN9C105 */
89 { SN9C102_USB_DEVICE(0x045e, 0x00f5, BRIDGE_SN9C105), },
90 { SN9C102_USB_DEVICE(0x045e, 0x00f7, BRIDGE_SN9C105), },
89 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), }, 91 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), },
90 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), }, 92 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), },
91 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), }, 93 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), },
@@ -100,6 +102,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
100 { SN9C102_USB_DEVICE(0x0c45, 0x60fc, BRIDGE_SN9C105), }, 102 { SN9C102_USB_DEVICE(0x0c45, 0x60fc, BRIDGE_SN9C105), },
101 { SN9C102_USB_DEVICE(0x0c45, 0x60fe, BRIDGE_SN9C105), }, 103 { SN9C102_USB_DEVICE(0x0c45, 0x60fe, BRIDGE_SN9C105), },
102 /* SN9C120 */ 104 /* SN9C120 */
105 { SN9C102_USB_DEVICE(0x0458, 0x7025, BRIDGE_SN9C120), },
103 { SN9C102_USB_DEVICE(0x0c45, 0x6102, BRIDGE_SN9C120), }, 106 { SN9C102_USB_DEVICE(0x0c45, 0x6102, BRIDGE_SN9C120), },
104 { SN9C102_USB_DEVICE(0x0c45, 0x6108, BRIDGE_SN9C120), }, 107 { SN9C102_USB_DEVICE(0x0c45, 0x6108, BRIDGE_SN9C120), },
105 { SN9C102_USB_DEVICE(0x0c45, 0x610f, BRIDGE_SN9C120), }, 108 { SN9C102_USB_DEVICE(0x0c45, 0x610f, BRIDGE_SN9C120), },
@@ -148,7 +151,6 @@ static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = {
148 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ 151 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
149 &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */ 152 &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */
150 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ 153 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
151 NULL,
152}; 154};
153 155
154#endif /* _SN9C102_DEVTABLE_H_ */ 156#endif /* _SN9C102_DEVTABLE_H_ */
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131d.c b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
index 28a861aed044..eaf9ad0dc8a6 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131d.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
@@ -144,7 +144,7 @@ static int hv7131d_set_pix_format(struct sn9c102_device* cam,
144} 144}
145 145
146 146
147static struct sn9c102_sensor hv7131d = { 147static const struct sn9c102_sensor hv7131d = {
148 .name = "HV7131D", 148 .name = "HV7131D",
149 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 149 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
150 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 150 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
@@ -248,12 +248,10 @@ int sn9c102_probe_hv7131d(struct sn9c102_device* cam)
248 248
249 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01}, 249 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
250 {0x28, 0x17}); 250 {0x28, 0x17});
251 if (err)
252 return -EIO;
253 251
254 r0 = sn9c102_i2c_try_read(cam, &hv7131d, 0x00); 252 r0 = sn9c102_i2c_try_read(cam, &hv7131d, 0x00);
255 r1 = sn9c102_i2c_try_read(cam, &hv7131d, 0x01); 253 r1 = sn9c102_i2c_try_read(cam, &hv7131d, 0x01);
256 if (r0 < 0 || r1 < 0) 254 if (err || r0 < 0 || r1 < 0)
257 return -EIO; 255 return -EIO;
258 256
259 if (r0 != 0x00 || r1 != 0x04) 257 if (r0 != 0x00 || r1 != 0x04)
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131r.c b/drivers/media/video/sn9c102/sn9c102_hv7131r.c
index 5a495baa5f95..0fc401223cfc 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131r.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131r.c
@@ -44,7 +44,6 @@ static int hv7131r_init(struct sn9c102_device* cam)
44 {0xb0, 0x2b}, {0xc0, 0x2c}, 44 {0xb0, 0x2b}, {0xc0, 0x2c},
45 {0xd0, 0x2d}, {0xe0, 0x2e}, 45 {0xd0, 0x2d}, {0xe0, 0x2e},
46 {0xf0, 0x2f}, {0xff, 0x30}); 46 {0xf0, 0x2f}, {0xff, 0x30});
47
48 break; 47 break;
49 case BRIDGE_SN9C105: 48 case BRIDGE_SN9C105:
50 case BRIDGE_SN9C120: 49 case BRIDGE_SN9C120:
@@ -254,7 +253,7 @@ static int hv7131r_set_pix_format(struct sn9c102_device* cam,
254} 253}
255 254
256 255
257static struct sn9c102_sensor hv7131r = { 256static const struct sn9c102_sensor hv7131r = {
258 .name = "HV7131R", 257 .name = "HV7131R",
259 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 258 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
260 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120, 259 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120,
@@ -350,11 +349,8 @@ int sn9c102_probe_hv7131r(struct sn9c102_device* cam)
350 {0x34, 0x01}, {0x20, 0x17}, 349 {0x34, 0x01}, {0x20, 0x17},
351 {0x34, 0x01}, {0x46, 0x01}); 350 {0x34, 0x01}, {0x46, 0x01});
352 351
353 if (err)
354 return -EIO;
355
356 devid = sn9c102_i2c_try_read(cam, &hv7131r, 0x00); 352 devid = sn9c102_i2c_try_read(cam, &hv7131r, 0x00);
357 if (devid < 0) 353 if (err || devid < 0)
358 return -EIO; 354 return -EIO;
359 355
360 if (devid != 0x02) 356 if (devid != 0x02)
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0343.c b/drivers/media/video/sn9c102/sn9c102_mi0343.c
index 9200845d011b..00b134ca0a3d 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0343.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0343.c
@@ -55,45 +55,45 @@ static int mi0343_get_ctrl(struct sn9c102_device* cam,
55 struct v4l2_control* ctrl) 55 struct v4l2_control* ctrl)
56{ 56{
57 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 57 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
58 u8 data[5+1]; 58 u8 data[2];
59 59
60 switch (ctrl->id) { 60 switch (ctrl->id) {
61 case V4L2_CID_EXPOSURE: 61 case V4L2_CID_EXPOSURE:
62 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 62 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 2,
63 2+1, data) < 0) 63 data) < 0)
64 return -EIO; 64 return -EIO;
65 ctrl->value = data[2]; 65 ctrl->value = data[0];
66 return 0; 66 return 0;
67 case V4L2_CID_GAIN: 67 case V4L2_CID_GAIN:
68 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 68 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 2,
69 2+1, data) < 0) 69 data) < 0)
70 return -EIO; 70 return -EIO;
71 break; 71 break;
72 case V4L2_CID_HFLIP: 72 case V4L2_CID_HFLIP:
73 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 73 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
74 2+1, data) < 0) 74 data) < 0)
75 return -EIO; 75 return -EIO;
76 ctrl->value = data[3] & 0x20 ? 1 : 0; 76 ctrl->value = data[1] & 0x20 ? 1 : 0;
77 return 0; 77 return 0;
78 case V4L2_CID_VFLIP: 78 case V4L2_CID_VFLIP:
79 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 79 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
80 2+1, data) < 0) 80 data) < 0)
81 return -EIO; 81 return -EIO;
82 ctrl->value = data[3] & 0x80 ? 1 : 0; 82 ctrl->value = data[1] & 0x80 ? 1 : 0;
83 return 0; 83 return 0;
84 case V4L2_CID_RED_BALANCE: 84 case V4L2_CID_RED_BALANCE:
85 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 85 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 2,
86 2+1, data) < 0) 86 data) < 0)
87 return -EIO; 87 return -EIO;
88 break; 88 break;
89 case V4L2_CID_BLUE_BALANCE: 89 case V4L2_CID_BLUE_BALANCE:
90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 2,
91 2+1, data) < 0) 91 data) < 0)
92 return -EIO; 92 return -EIO;
93 break; 93 break;
94 case SN9C102_V4L2_CID_GREEN_BALANCE: 94 case SN9C102_V4L2_CID_GREEN_BALANCE:
95 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 95 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 2,
96 2+1, data) < 0) 96 data) < 0)
97 return -EIO; 97 return -EIO;
98 break; 98 break;
99 default: 99 default:
@@ -105,7 +105,7 @@ static int mi0343_get_ctrl(struct sn9c102_device* cam,
105 case V4L2_CID_RED_BALANCE: 105 case V4L2_CID_RED_BALANCE:
106 case V4L2_CID_BLUE_BALANCE: 106 case V4L2_CID_BLUE_BALANCE:
107 case SN9C102_V4L2_CID_GREEN_BALANCE: 107 case SN9C102_V4L2_CID_GREEN_BALANCE:
108 ctrl->value = data[3] | (data[2] << 8); 108 ctrl->value = data[1] | (data[0] << 8);
109 if (ctrl->value >= 0x10 && ctrl->value <= 0x3f) 109 if (ctrl->value >= 0x10 && ctrl->value <= 0x3f)
110 ctrl->value -= 0x10; 110 ctrl->value -= 0x10;
111 else if (ctrl->value >= 0x60 && ctrl->value <= 0x7f) 111 else if (ctrl->value >= 0x60 && ctrl->value <= 0x7f)
@@ -223,7 +223,7 @@ static int mi0343_set_pix_format(struct sn9c102_device* cam,
223} 223}
224 224
225 225
226static struct sn9c102_sensor mi0343 = { 226static const struct sn9c102_sensor mi0343 = {
227 .name = "MI-0343", 227 .name = "MI-0343",
228 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 228 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
229 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 229 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
@@ -332,20 +332,17 @@ static struct sn9c102_sensor mi0343 = {
332 332
333int sn9c102_probe_mi0343(struct sn9c102_device* cam) 333int sn9c102_probe_mi0343(struct sn9c102_device* cam)
334{ 334{
335 u8 data[5+1]; 335 u8 data[2];
336 int err = 0;
337
338 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
339 {0x28, 0x17});
340 336
341 if (err) 337 if (sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
338 {0x28, 0x17}))
342 return -EIO; 339 return -EIO;
343 340
344 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 0x00, 341 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 0x00,
345 2, data) < 0) 342 2, data) < 0)
346 return -EIO; 343 return -EIO;
347 344
348 if (data[4] != 0x32 || data[3] != 0xe3) 345 if (data[1] != 0x42 || data[0] != 0xe3)
349 return -ENODEV; 346 return -ENODEV;
350 347
351 sn9c102_attach_sensor(cam, &mi0343); 348 sn9c102_attach_sensor(cam, &mi0343);
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0360.c b/drivers/media/video/sn9c102/sn9c102_mi0360.c
index 64698acb0b15..f8d81d82e8d5 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0360.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0360.c
@@ -27,20 +27,105 @@ static int mi0360_init(struct sn9c102_device* cam)
27 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 27 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
28 int err = 0; 28 int err = 0;
29 29
30 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11}, 30 switch (sn9c102_get_bridge(cam)) {
31 {0x0a, 0x14}, {0x40, 0x01}, 31 case BRIDGE_SN9C103:
32 {0x20, 0x17}, {0x07, 0x18}, 32 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11},
33 {0xa0, 0x19}, {0x02, 0x1c}, 33 {0x0a, 0x14}, {0x40, 0x01},
34 {0x03, 0x1d}, {0x0f, 0x1e}, 34 {0x20, 0x17}, {0x07, 0x18},
35 {0x0c, 0x1f}, {0x00, 0x20}, 35 {0xa0, 0x19}, {0x02, 0x1c},
36 {0x10, 0x21}, {0x20, 0x22}, 36 {0x03, 0x1d}, {0x0f, 0x1e},
37 {0x30, 0x23}, {0x40, 0x24}, 37 {0x0c, 0x1f}, {0x00, 0x20},
38 {0x50, 0x25}, {0x60, 0x26}, 38 {0x10, 0x21}, {0x20, 0x22},
39 {0x70, 0x27}, {0x80, 0x28}, 39 {0x30, 0x23}, {0x40, 0x24},
40 {0x90, 0x29}, {0xa0, 0x2a}, 40 {0x50, 0x25}, {0x60, 0x26},
41 {0xb0, 0x2b}, {0xc0, 0x2c}, 41 {0x70, 0x27}, {0x80, 0x28},
42 {0xd0, 0x2d}, {0xe0, 0x2e}, 42 {0x90, 0x29}, {0xa0, 0x2a},
43 {0xf0, 0x2f}, {0xff, 0x30}); 43 {0xb0, 0x2b}, {0xc0, 0x2c},
44 {0xd0, 0x2d}, {0xe0, 0x2e},
45 {0xf0, 0x2f}, {0xff, 0x30});
46 break;
47 case BRIDGE_SN9C105:
48 case BRIDGE_SN9C120:
49 err = sn9c102_write_const_regs(cam, {0x44, 0x01}, {0x40, 0x02},
50 {0x00, 0x03}, {0x1a, 0x04},
51 {0x50, 0x05}, {0x20, 0x06},
52 {0x10, 0x07}, {0x03, 0x10},
53 {0x08, 0x14}, {0xa2, 0x17},
54 {0x47, 0x18}, {0x00, 0x19},
55 {0x1d, 0x1a}, {0x10, 0x1b},
56 {0x02, 0x1c}, {0x03, 0x1d},
57 {0x0f, 0x1e}, {0x0c, 0x1f},
58 {0x00, 0x20}, {0x29, 0x21},
59 {0x40, 0x22}, {0x54, 0x23},
60 {0x66, 0x24}, {0x76, 0x25},
61 {0x85, 0x26}, {0x94, 0x27},
62 {0xa1, 0x28}, {0xae, 0x29},
63 {0xbb, 0x2a}, {0xc7, 0x2b},
64 {0xd3, 0x2c}, {0xde, 0x2d},
65 {0xea, 0x2e}, {0xf4, 0x2f},
66 {0xff, 0x30}, {0x00, 0x3F},
67 {0xC7, 0x40}, {0x01, 0x41},
68 {0x44, 0x42}, {0x00, 0x43},
69 {0x44, 0x44}, {0x00, 0x45},
70 {0x44, 0x46}, {0x00, 0x47},
71 {0xC7, 0x48}, {0x01, 0x49},
72 {0xC7, 0x4A}, {0x01, 0x4B},
73 {0xC7, 0x4C}, {0x01, 0x4D},
74 {0x44, 0x4E}, {0x00, 0x4F},
75 {0x44, 0x50}, {0x00, 0x51},
76 {0x44, 0x52}, {0x00, 0x53},
77 {0xC7, 0x54}, {0x01, 0x55},
78 {0xC7, 0x56}, {0x01, 0x57},
79 {0xC7, 0x58}, {0x01, 0x59},
80 {0x44, 0x5A}, {0x00, 0x5B},
81 {0x44, 0x5C}, {0x00, 0x5D},
82 {0x44, 0x5E}, {0x00, 0x5F},
83 {0xC7, 0x60}, {0x01, 0x61},
84 {0xC7, 0x62}, {0x01, 0x63},
85 {0xC7, 0x64}, {0x01, 0x65},
86 {0x44, 0x66}, {0x00, 0x67},
87 {0x44, 0x68}, {0x00, 0x69},
88 {0x44, 0x6A}, {0x00, 0x6B},
89 {0xC7, 0x6C}, {0x01, 0x6D},
90 {0xC7, 0x6E}, {0x01, 0x6F},
91 {0xC7, 0x70}, {0x01, 0x71},
92 {0x44, 0x72}, {0x00, 0x73},
93 {0x44, 0x74}, {0x00, 0x75},
94 {0x44, 0x76}, {0x00, 0x77},
95 {0xC7, 0x78}, {0x01, 0x79},
96 {0xC7, 0x7A}, {0x01, 0x7B},
97 {0xC7, 0x7C}, {0x01, 0x7D},
98 {0x44, 0x7E}, {0x00, 0x7F},
99 {0x14, 0x84}, {0x00, 0x85},
100 {0x27, 0x86}, {0x00, 0x87},
101 {0x07, 0x88}, {0x00, 0x89},
102 {0xEC, 0x8A}, {0x0f, 0x8B},
103 {0xD8, 0x8C}, {0x0f, 0x8D},
104 {0x3D, 0x8E}, {0x00, 0x8F},
105 {0x3D, 0x90}, {0x00, 0x91},
106 {0xCD, 0x92}, {0x0f, 0x93},
107 {0xf7, 0x94}, {0x0f, 0x95},
108 {0x0C, 0x96}, {0x00, 0x97},
109 {0x00, 0x98}, {0x66, 0x99},
110 {0x05, 0x9A}, {0x00, 0x9B},
111 {0x04, 0x9C}, {0x00, 0x9D},
112 {0x08, 0x9E}, {0x00, 0x9F},
113 {0x2D, 0xC0}, {0x2D, 0xC1},
114 {0x3A, 0xC2}, {0x05, 0xC3},
115 {0x04, 0xC4}, {0x3F, 0xC5},
116 {0x00, 0xC6}, {0x00, 0xC7},
117 {0x50, 0xC8}, {0x3C, 0xC9},
118 {0x28, 0xCA}, {0xD8, 0xCB},
119 {0x14, 0xCC}, {0xEC, 0xCD},
120 {0x32, 0xCE}, {0xDD, 0xCF},
121 {0x32, 0xD0}, {0xDD, 0xD1},
122 {0x6A, 0xD2}, {0x50, 0xD3},
123 {0x00, 0xD4}, {0x00, 0xD5},
124 {0x00, 0xD6});
125 break;
126 default:
127 break;
128 }
44 129
45 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d, 130 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d,
46 0x00, 0x01, 0, 0); 131 0x00, 0x01, 0, 0);
@@ -65,50 +150,50 @@ static int mi0360_get_ctrl(struct sn9c102_device* cam,
65 struct v4l2_control* ctrl) 150 struct v4l2_control* ctrl)
66{ 151{
67 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 152 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
68 u8 data[5+1]; 153 u8 data[2];
69 154
70 switch (ctrl->id) { 155 switch (ctrl->id) {
71 case V4L2_CID_EXPOSURE: 156 case V4L2_CID_EXPOSURE:
72 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 157 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 2,
73 2+1, data) < 0) 158 data) < 0)
74 return -EIO; 159 return -EIO;
75 ctrl->value = data[2]; 160 ctrl->value = data[0];
76 return 0; 161 return 0;
77 case V4L2_CID_GAIN: 162 case V4L2_CID_GAIN:
78 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 163 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 2,
79 2+1, data) < 0) 164 data) < 0)
80 return -EIO; 165 return -EIO;
81 ctrl->value = data[3]; 166 ctrl->value = data[1];
82 return 0; 167 return 0;
83 case V4L2_CID_RED_BALANCE: 168 case V4L2_CID_RED_BALANCE:
84 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 169 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 2,
85 2+1, data) < 0) 170 data) < 0)
86 return -EIO; 171 return -EIO;
87 ctrl->value = data[3]; 172 ctrl->value = data[1];
88 return 0; 173 return 0;
89 case V4L2_CID_BLUE_BALANCE: 174 case V4L2_CID_BLUE_BALANCE:
90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 175 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 2,
91 2+1, data) < 0) 176 data) < 0)
92 return -EIO; 177 return -EIO;
93 ctrl->value = data[3]; 178 ctrl->value = data[1];
94 return 0; 179 return 0;
95 case SN9C102_V4L2_CID_GREEN_BALANCE: 180 case SN9C102_V4L2_CID_GREEN_BALANCE:
96 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 181 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 2,
97 2+1, data) < 0) 182 data) < 0)
98 return -EIO; 183 return -EIO;
99 ctrl->value = data[3]; 184 ctrl->value = data[1];
100 return 0; 185 return 0;
101 case V4L2_CID_HFLIP: 186 case V4L2_CID_HFLIP:
102 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 187 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
103 2+1, data) < 0) 188 data) < 0)
104 return -EIO; 189 return -EIO;
105 ctrl->value = data[3] & 0x20 ? 1 : 0; 190 ctrl->value = data[1] & 0x20 ? 1 : 0;
106 return 0; 191 return 0;
107 case V4L2_CID_VFLIP: 192 case V4L2_CID_VFLIP:
108 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 193 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
109 2+1, data) < 0) 194 data) < 0)
110 return -EIO; 195 return -EIO;
111 ctrl->value = data[3] & 0x80 ? 1 : 0; 196 ctrl->value = data[1] & 0x80 ? 1 : 0;
112 return 0; 197 return 0;
113 default: 198 default:
114 return -EINVAL; 199 return -EINVAL;
@@ -178,8 +263,19 @@ static int mi0360_set_crop(struct sn9c102_device* cam,
178{ 263{
179 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 264 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
180 int err = 0; 265 int err = 0;
181 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0, 266 u8 h_start = 0, v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
182 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1; 267
268 switch (sn9c102_get_bridge(cam)) {
269 case BRIDGE_SN9C103:
270 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0;
271 break;
272 case BRIDGE_SN9C105:
273 case BRIDGE_SN9C120:
274 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 1;
275 break;
276 default:
277 break;
278 }
183 279
184 err += sn9c102_write_reg(cam, h_start, 0x12); 280 err += sn9c102_write_reg(cam, h_start, 0x12);
185 err += sn9c102_write_reg(cam, v_start, 0x13); 281 err += sn9c102_write_reg(cam, v_start, 0x13);
@@ -194,24 +290,30 @@ static int mi0360_set_pix_format(struct sn9c102_device* cam,
194 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 290 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
195 int err = 0; 291 int err = 0;
196 292
197 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) { 293 if (pix->pixelformat == V4L2_PIX_FMT_SBGGR8) {
198 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
199 0x0a, 0x00, 0x02, 0, 0);
200 err += sn9c102_write_reg(cam, 0x20, 0x19);
201 } else {
202 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 294 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
203 0x0a, 0x00, 0x05, 0, 0); 295 0x0a, 0x00, 0x05, 0, 0);
204 err += sn9c102_write_reg(cam, 0x60, 0x19); 296 err += sn9c102_write_reg(cam, 0x60, 0x19);
297 if (sn9c102_get_bridge(cam) == BRIDGE_SN9C105 ||
298 sn9c102_get_bridge(cam) == BRIDGE_SN9C120)
299 err += sn9c102_write_reg(cam, 0xa6, 0x17);
300 } else {
301 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
302 0x0a, 0x00, 0x02, 0, 0);
303 err += sn9c102_write_reg(cam, 0x20, 0x19);
304 if (sn9c102_get_bridge(cam) == BRIDGE_SN9C105 ||
305 sn9c102_get_bridge(cam) == BRIDGE_SN9C120)
306 err += sn9c102_write_reg(cam, 0xa2, 0x17);
205 } 307 }
206 308
207 return err; 309 return err;
208} 310}
209 311
210 312
211static struct sn9c102_sensor mi0360 = { 313static const struct sn9c102_sensor mi0360 = {
212 .name = "MI-0360", 314 .name = "MI-0360",
213 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 315 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
214 .supported_bridge = BRIDGE_SN9C103, 316 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120,
215 .frequency = SN9C102_I2C_100KHZ, 317 .frequency = SN9C102_I2C_100KHZ,
216 .interface = SN9C102_I2C_2WIRES, 318 .interface = SN9C102_I2C_2WIRES,
217 .i2c_slave_id = 0x5d, 319 .i2c_slave_id = 0x5d,
@@ -317,19 +419,31 @@ static struct sn9c102_sensor mi0360 = {
317 419
318int sn9c102_probe_mi0360(struct sn9c102_device* cam) 420int sn9c102_probe_mi0360(struct sn9c102_device* cam)
319{ 421{
320 u8 data[5+1];
321 int err;
322 422
323 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01}, 423 u8 data[2];
324 {0x28, 0x17}); 424
325 if (err) 425 switch (sn9c102_get_bridge(cam)) {
326 return -EIO; 426 case BRIDGE_SN9C103:
427 if (sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
428 {0x28, 0x17}))
429 return -EIO;
430 break;
431 case BRIDGE_SN9C105:
432 case BRIDGE_SN9C120:
433 if (sn9c102_write_const_regs(cam, {0x01, 0xf1}, {0x00, 0xf1},
434 {0x01, 0x01}, {0x00, 0x01},
435 {0x28, 0x17}))
436 return -EIO;
437 break;
438 default:
439 break;
440 }
327 441
328 if (sn9c102_i2c_try_raw_read(cam, &mi0360, mi0360.i2c_slave_id, 0x00, 442 if (sn9c102_i2c_try_raw_read(cam, &mi0360, mi0360.i2c_slave_id, 0x00,
329 2+1, data) < 0) 443 2, data) < 0)
330 return -EIO; 444 return -EIO;
331 445
332 if (data[2] != 0x82 || data[3] != 0x43) 446 if (data[0] != 0x82 || data[1] != 0x43)
333 return -ENODEV; 447 return -ENODEV;
334 448
335 sn9c102_attach_sensor(cam, &mi0360); 449 sn9c102_attach_sensor(cam, &mi0360);
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7630.c b/drivers/media/video/sn9c102/sn9c102_ov7630.c
index 31b6080b0615..e6832347894f 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7630.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7630.c
@@ -29,9 +29,8 @@ static int ov7630_init(struct sn9c102_device* cam)
29 switch (sn9c102_get_bridge(cam)) { 29 switch (sn9c102_get_bridge(cam)) {
30 case BRIDGE_SN9C101: 30 case BRIDGE_SN9C101:
31 case BRIDGE_SN9C102: 31 case BRIDGE_SN9C102:
32 err = sn9c102_write_const_regs(cam, {0x00, 0x14}, 32 err = sn9c102_write_const_regs(cam, {0x00, 0x14}, {0x60, 0x17},
33 {0x60, 0x17}, {0x0f, 0x18}, 33 {0x0f, 0x18}, {0x50, 0x19});
34 {0x50, 0x19});
35 34
36 err += sn9c102_i2c_write(cam, 0x12, 0x8d); 35 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
37 err += sn9c102_i2c_write(cam, 0x12, 0x0d); 36 err += sn9c102_i2c_write(cam, 0x12, 0x0d);
@@ -61,7 +60,6 @@ static int ov7630_init(struct sn9c102_device* cam)
61 err += sn9c102_i2c_write(cam, 0x71, 0x00); 60 err += sn9c102_i2c_write(cam, 0x71, 0x00);
62 err += sn9c102_i2c_write(cam, 0x74, 0x21); 61 err += sn9c102_i2c_write(cam, 0x74, 0x21);
63 err += sn9c102_i2c_write(cam, 0x7d, 0xf7); 62 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
64
65 break; 63 break;
66 case BRIDGE_SN9C103: 64 case BRIDGE_SN9C103:
67 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, {0x00, 0x03}, 65 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, {0x00, 0x03},
@@ -253,7 +251,7 @@ static int ov7630_set_pix_format(struct sn9c102_device* cam,
253} 251}
254 252
255 253
256static struct sn9c102_sensor ov7630 = { 254static const struct sn9c102_sensor ov7630 = {
257 .name = "OV7630", 255 .name = "OV7630",
258 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 256 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
259 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103, 257 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
@@ -408,19 +406,16 @@ int sn9c102_probe_ov7630(struct sn9c102_device* cam)
408 switch (sn9c102_get_bridge(cam)) { 406 switch (sn9c102_get_bridge(cam)) {
409 case BRIDGE_SN9C101: 407 case BRIDGE_SN9C101:
410 case BRIDGE_SN9C102: 408 case BRIDGE_SN9C102:
411 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, 409 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
412 {0x00, 0x01}, {0x28, 0x17}); 410 {0x28, 0x17});
413
414 break; 411 break;
415 case BRIDGE_SN9C103: /* do _not_ change anything! */ 412 case BRIDGE_SN9C103: /* do _not_ change anything! */
416 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, 413 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, {0x42, 0x01},
417 {0x42, 0x01}, {0x28, 0x17}, 414 {0x28, 0x17}, {0x44, 0x02});
418 {0x44, 0x02});
419 pid = sn9c102_i2c_try_read(cam, &ov7630, 0x0a); 415 pid = sn9c102_i2c_try_read(cam, &ov7630, 0x0a);
420 if (err || pid < 0) { /* try a different initialization */ 416 if (err || pid < 0) /* try a different initialization */
421 err = sn9c102_write_reg(cam, 0x01, 0x01); 417 err += sn9c102_write_const_regs(cam, {0x01, 0x01},
422 err += sn9c102_write_reg(cam, 0x00, 0x01); 418 {0x00, 0x01});
423 }
424 break; 419 break;
425 default: 420 default:
426 break; 421 break;
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7660.c b/drivers/media/video/sn9c102/sn9c102_ov7660.c
index c898e948fe8d..4b6474048a72 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7660.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7660.c
@@ -104,8 +104,8 @@ static int ov7660_init(struct sn9c102_device* cam)
104 err += sn9c102_i2c_write(cam, 0x12, 0x80); 104 err += sn9c102_i2c_write(cam, 0x12, 0x80);
105 err += sn9c102_i2c_write(cam, 0x11, 0x09); 105 err += sn9c102_i2c_write(cam, 0x11, 0x09);
106 err += sn9c102_i2c_write(cam, 0x00, 0x0A); 106 err += sn9c102_i2c_write(cam, 0x00, 0x0A);
107 err += sn9c102_i2c_write(cam, 0x01, 0x78); 107 err += sn9c102_i2c_write(cam, 0x01, 0x80);
108 err += sn9c102_i2c_write(cam, 0x02, 0x90); 108 err += sn9c102_i2c_write(cam, 0x02, 0x80);
109 err += sn9c102_i2c_write(cam, 0x03, 0x00); 109 err += sn9c102_i2c_write(cam, 0x03, 0x00);
110 err += sn9c102_i2c_write(cam, 0x04, 0x00); 110 err += sn9c102_i2c_write(cam, 0x04, 0x00);
111 err += sn9c102_i2c_write(cam, 0x05, 0x08); 111 err += sn9c102_i2c_write(cam, 0x05, 0x08);
@@ -122,7 +122,7 @@ static int ov7660_init(struct sn9c102_device* cam)
122 err += sn9c102_i2c_write(cam, 0x10, 0x20); 122 err += sn9c102_i2c_write(cam, 0x10, 0x20);
123 err += sn9c102_i2c_write(cam, 0x11, 0x03); 123 err += sn9c102_i2c_write(cam, 0x11, 0x03);
124 err += sn9c102_i2c_write(cam, 0x12, 0x05); 124 err += sn9c102_i2c_write(cam, 0x12, 0x05);
125 err += sn9c102_i2c_write(cam, 0x13, 0xF8); 125 err += sn9c102_i2c_write(cam, 0x13, 0xC7);
126 err += sn9c102_i2c_write(cam, 0x14, 0x2C); 126 err += sn9c102_i2c_write(cam, 0x14, 0x2C);
127 err += sn9c102_i2c_write(cam, 0x15, 0x00); 127 err += sn9c102_i2c_write(cam, 0x15, 0x00);
128 err += sn9c102_i2c_write(cam, 0x16, 0x02); 128 err += sn9c102_i2c_write(cam, 0x16, 0x02);
@@ -162,7 +162,7 @@ static int ov7660_init(struct sn9c102_device* cam)
162 err += sn9c102_i2c_write(cam, 0x38, 0x02); 162 err += sn9c102_i2c_write(cam, 0x38, 0x02);
163 err += sn9c102_i2c_write(cam, 0x39, 0x43); 163 err += sn9c102_i2c_write(cam, 0x39, 0x43);
164 err += sn9c102_i2c_write(cam, 0x3A, 0x00); 164 err += sn9c102_i2c_write(cam, 0x3A, 0x00);
165 err += sn9c102_i2c_write(cam, 0x3B, 0x02); 165 err += sn9c102_i2c_write(cam, 0x3B, 0x0A);
166 err += sn9c102_i2c_write(cam, 0x3C, 0x6C); 166 err += sn9c102_i2c_write(cam, 0x3C, 0x6C);
167 err += sn9c102_i2c_write(cam, 0x3D, 0x99); 167 err += sn9c102_i2c_write(cam, 0x3D, 0x99);
168 err += sn9c102_i2c_write(cam, 0x3E, 0x0E); 168 err += sn9c102_i2c_write(cam, 0x3E, 0x0E);
@@ -281,25 +281,34 @@ static int ov7660_get_ctrl(struct sn9c102_device* cam,
281 return -EIO; 281 return -EIO;
282 break; 282 break;
283 case V4L2_CID_DO_WHITE_BALANCE: 283 case V4L2_CID_DO_WHITE_BALANCE:
284 ctrl->value = sn9c102_pread_reg(cam, 0x02); 284 if ((ctrl->value = sn9c102_read_reg(cam, 0x02)) < 0)
285 return -EIO;
285 ctrl->value = (ctrl->value & 0x04) ? 1 : 0; 286 ctrl->value = (ctrl->value & 0x04) ? 1 : 0;
286 break; 287 break;
287 case V4L2_CID_RED_BALANCE: 288 case V4L2_CID_RED_BALANCE:
288 ctrl->value = sn9c102_pread_reg(cam, 0x05); 289 if ((ctrl->value = sn9c102_read_reg(cam, 0x05)) < 0)
290 return -EIO;
289 ctrl->value &= 0x7f; 291 ctrl->value &= 0x7f;
290 break; 292 break;
291 case V4L2_CID_BLUE_BALANCE: 293 case V4L2_CID_BLUE_BALANCE:
292 ctrl->value = sn9c102_pread_reg(cam, 0x06); 294 if ((ctrl->value = sn9c102_read_reg(cam, 0x06)) < 0)
295 return -EIO;
293 ctrl->value &= 0x7f; 296 ctrl->value &= 0x7f;
294 break; 297 break;
295 case SN9C102_V4L2_CID_GREEN_BALANCE: 298 case SN9C102_V4L2_CID_GREEN_BALANCE:
296 ctrl->value = sn9c102_pread_reg(cam, 0x07); 299 if ((ctrl->value = sn9c102_read_reg(cam, 0x07)) < 0)
300 return -EIO;
297 ctrl->value &= 0x7f; 301 ctrl->value &= 0x7f;
298 break; 302 break;
303 case SN9C102_V4L2_CID_BAND_FILTER:
304 if ((ctrl->value = sn9c102_i2c_read(cam, 0x3b)) < 0)
305 return -EIO;
306 ctrl->value &= 0x08;
307 break;
299 case V4L2_CID_GAIN: 308 case V4L2_CID_GAIN:
300 if ((ctrl->value = sn9c102_i2c_read(cam, 0x00)) < 0) 309 if ((ctrl->value = sn9c102_i2c_read(cam, 0x00)) < 0)
301 return -EIO; 310 return -EIO;
302 ctrl->value &= 0x7f; 311 ctrl->value &= 0x1f;
303 break; 312 break;
304 case V4L2_CID_AUTOGAIN: 313 case V4L2_CID_AUTOGAIN:
305 if ((ctrl->value = sn9c102_i2c_read(cam, 0x13)) < 0) 314 if ((ctrl->value = sn9c102_i2c_read(cam, 0x13)) < 0)
@@ -335,12 +344,15 @@ static int ov7660_set_ctrl(struct sn9c102_device* cam,
335 case SN9C102_V4L2_CID_GREEN_BALANCE: 344 case SN9C102_V4L2_CID_GREEN_BALANCE:
336 err += sn9c102_write_reg(cam, ctrl->value, 0x07); 345 err += sn9c102_write_reg(cam, ctrl->value, 0x07);
337 break; 346 break;
347 case SN9C102_V4L2_CID_BAND_FILTER:
348 err += sn9c102_i2c_write(cam, ctrl->value << 3, 0x3b);
349 break;
338 case V4L2_CID_GAIN: 350 case V4L2_CID_GAIN:
339 err += sn9c102_i2c_write(cam, 0x00, ctrl->value); 351 err += sn9c102_i2c_write(cam, 0x00, 0x60 + ctrl->value);
340 break; 352 break;
341 case V4L2_CID_AUTOGAIN: 353 case V4L2_CID_AUTOGAIN:
342 err += sn9c102_i2c_write(cam, 0x13, 0xf0 | ctrl->value | 354 err += sn9c102_i2c_write(cam, 0x13, 0xc0 |
343 (ctrl->value << 1)); 355 (ctrl->value * 0x07));
344 break; 356 break;
345 default: 357 default:
346 return -EINVAL; 358 return -EINVAL;
@@ -386,7 +398,7 @@ static int ov7660_set_pix_format(struct sn9c102_device* cam,
386} 398}
387 399
388 400
389static struct sn9c102_sensor ov7660 = { 401static const struct sn9c102_sensor ov7660 = {
390 .name = "OV7660", 402 .name = "OV7660",
391 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 403 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
392 .supported_bridge = BRIDGE_SN9C105 | BRIDGE_SN9C120, 404 .supported_bridge = BRIDGE_SN9C105 | BRIDGE_SN9C120,
@@ -401,9 +413,9 @@ static struct sn9c102_sensor ov7660 = {
401 .type = V4L2_CTRL_TYPE_INTEGER, 413 .type = V4L2_CTRL_TYPE_INTEGER,
402 .name = "global gain", 414 .name = "global gain",
403 .minimum = 0x00, 415 .minimum = 0x00,
404 .maximum = 0x7f, 416 .maximum = 0x1f,
405 .step = 0x01, 417 .step = 0x01,
406 .default_value = 0x0a, 418 .default_value = 0x09,
407 .flags = 0, 419 .flags = 0,
408 }, 420 },
409 { 421 {
@@ -413,7 +425,7 @@ static struct sn9c102_sensor ov7660 = {
413 .minimum = 0x00, 425 .minimum = 0x00,
414 .maximum = 0xff, 426 .maximum = 0xff,
415 .step = 0x01, 427 .step = 0x01,
416 .default_value = 0x50, 428 .default_value = 0x27,
417 .flags = 0, 429 .flags = 0,
418 }, 430 },
419 { 431 {
@@ -433,7 +445,7 @@ static struct sn9c102_sensor ov7660 = {
433 .minimum = 0x00, 445 .minimum = 0x00,
434 .maximum = 0x7f, 446 .maximum = 0x7f,
435 .step = 0x01, 447 .step = 0x01,
436 .default_value = 0x1f, 448 .default_value = 0x14,
437 .flags = 0, 449 .flags = 0,
438 }, 450 },
439 { 451 {
@@ -443,7 +455,7 @@ static struct sn9c102_sensor ov7660 = {
443 .minimum = 0x00, 455 .minimum = 0x00,
444 .maximum = 0x7f, 456 .maximum = 0x7f,
445 .step = 0x01, 457 .step = 0x01,
446 .default_value = 0x1e, 458 .default_value = 0x14,
447 .flags = 0, 459 .flags = 0,
448 }, 460 },
449 { 461 {
@@ -453,7 +465,7 @@ static struct sn9c102_sensor ov7660 = {
453 .minimum = 0x00, 465 .minimum = 0x00,
454 .maximum = 0x01, 466 .maximum = 0x01,
455 .step = 0x01, 467 .step = 0x01,
456 .default_value = 0x00, 468 .default_value = 0x01,
457 .flags = 0, 469 .flags = 0,
458 }, 470 },
459 { 471 {
@@ -463,7 +475,17 @@ static struct sn9c102_sensor ov7660 = {
463 .minimum = 0x00, 475 .minimum = 0x00,
464 .maximum = 0x7f, 476 .maximum = 0x7f,
465 .step = 0x01, 477 .step = 0x01,
466 .default_value = 0x20, 478 .default_value = 0x14,
479 .flags = 0,
480 },
481 {
482 .id = SN9C102_V4L2_CID_BAND_FILTER,
483 .type = V4L2_CTRL_TYPE_BOOLEAN,
484 .name = "band filter",
485 .minimum = 0x00,
486 .maximum = 0x01,
487 .step = 0x01,
488 .default_value = 0x00,
467 .flags = 0, 489 .flags = 0,
468 }, 490 },
469 }, 491 },
@@ -508,6 +530,7 @@ int sn9c102_probe_ov7660(struct sn9c102_device* cam)
508 return -EIO; 530 return -EIO;
509 if (pid != 0x76 || ver != 0x60) 531 if (pid != 0x76 || ver != 0x60)
510 return -ENODEV; 532 return -ENODEV;
533
511 sn9c102_attach_sensor(cam, &ov7660); 534 sn9c102_attach_sensor(cam, &ov7660);
512 535
513 return 0; 536 return 0;
diff --git a/drivers/media/video/sn9c102/sn9c102_pas106b.c b/drivers/media/video/sn9c102/sn9c102_pas106b.c
index 67151964801f..360f2a848bc0 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas106b.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas106b.c
@@ -163,7 +163,7 @@ static int pas106b_set_pix_format(struct sn9c102_device* cam,
163} 163}
164 164
165 165
166static struct sn9c102_sensor pas106b = { 166static const struct sn9c102_sensor pas106b = {
167 .name = "PAS106B", 167 .name = "PAS106B",
168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
169 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 169 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
@@ -273,23 +273,21 @@ static struct sn9c102_sensor pas106b = {
273 273
274int sn9c102_probe_pas106b(struct sn9c102_device* cam) 274int sn9c102_probe_pas106b(struct sn9c102_device* cam)
275{ 275{
276 int r0 = 0, r1 = 0, err; 276 int r0 = 0, r1 = 0;
277 unsigned int pid = 0; 277 unsigned int pid = 0;
278 278
279 /* 279 /*
280 Minimal initialization to enable the I2C communication 280 Minimal initialization to enable the I2C communication
281 NOTE: do NOT change the values! 281 NOTE: do NOT change the values!
282 */ 282 */
283 err = sn9c102_write_const_regs(cam, 283 if (sn9c102_write_const_regs(cam,
284 {0x01, 0x01}, /* sensor power down */ 284 {0x01, 0x01}, /* sensor power down */
285 {0x00, 0x01}, /* sensor power on */ 285 {0x00, 0x01}, /* sensor power on */
286 {0x28, 0x17});/* sensor clock 24 MHz */ 286 {0x28, 0x17})) /* sensor clock at 24 MHz */
287 if (err)
288 return -EIO; 287 return -EIO;
289 288
290 r0 = sn9c102_i2c_try_read(cam, &pas106b, 0x00); 289 r0 = sn9c102_i2c_try_read(cam, &pas106b, 0x00);
291 r1 = sn9c102_i2c_try_read(cam, &pas106b, 0x01); 290 r1 = sn9c102_i2c_try_read(cam, &pas106b, 0x01);
292
293 if (r0 < 0 || r1 < 0) 291 if (r0 < 0 || r1 < 0)
294 return -EIO; 292 return -EIO;
295 293
diff --git a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
index c1b8d6b63b47..ca4a1506ed3d 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
@@ -35,29 +35,28 @@ static int pas202bcb_init(struct sn9c102_device* cam)
35 switch (sn9c102_get_bridge(cam)) { 35 switch (sn9c102_get_bridge(cam)) {
36 case BRIDGE_SN9C101: 36 case BRIDGE_SN9C101:
37 case BRIDGE_SN9C102: 37 case BRIDGE_SN9C102:
38 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, 38 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11},
39 {0x00, 0x11}, {0x00, 0x14}, 39 {0x00, 0x14}, {0x20, 0x17},
40 {0x20, 0x17}, {0x30, 0x19}, 40 {0x30, 0x19}, {0x09, 0x18});
41 {0x09, 0x18});
42 break; 41 break;
43 case BRIDGE_SN9C103: 42 case BRIDGE_SN9C103:
44 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, 43 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, {0x00, 0x03},
45 {0x00, 0x03}, {0x1a, 0x04}, 44 {0x1a, 0x04}, {0x20, 0x05},
46 {0x20, 0x05}, {0x20, 0x06}, 45 {0x20, 0x06}, {0x20, 0x07},
47 {0x20, 0x07}, {0x00, 0x10}, 46 {0x00, 0x10}, {0x00, 0x11},
48 {0x00, 0x11}, {0x00, 0x14}, 47 {0x00, 0x14}, {0x20, 0x17},
49 {0x20, 0x17}, {0x30, 0x19}, 48 {0x30, 0x19}, {0x09, 0x18},
50 {0x09, 0x18}, {0x02, 0x1c}, 49 {0x02, 0x1c}, {0x03, 0x1d},
51 {0x03, 0x1d}, {0x0f, 0x1e}, 50 {0x0f, 0x1e}, {0x0c, 0x1f},
52 {0x0c, 0x1f}, {0x00, 0x20}, 51 {0x00, 0x20}, {0x10, 0x21},
53 {0x10, 0x21}, {0x20, 0x22}, 52 {0x20, 0x22}, {0x30, 0x23},
54 {0x30, 0x23}, {0x40, 0x24}, 53 {0x40, 0x24}, {0x50, 0x25},
55 {0x50, 0x25}, {0x60, 0x26}, 54 {0x60, 0x26}, {0x70, 0x27},
56 {0x70, 0x27}, {0x80, 0x28}, 55 {0x80, 0x28}, {0x90, 0x29},
57 {0x90, 0x29}, {0xa0, 0x2a}, 56 {0xa0, 0x2a}, {0xb0, 0x2b},
58 {0xb0, 0x2b}, {0xc0, 0x2c}, 57 {0xc0, 0x2c}, {0xd0, 0x2d},
59 {0xd0, 0x2d}, {0xe0, 0x2e}, 58 {0xe0, 0x2e}, {0xf0, 0x2f},
60 {0xf0, 0x2f}, {0xff, 0x30}); 59 {0xff, 0x30});
61 break; 60 break;
62 default: 61 default:
63 break; 62 break;
@@ -197,7 +196,7 @@ static int pas202bcb_set_crop(struct sn9c102_device* cam,
197} 196}
198 197
199 198
200static struct sn9c102_sensor pas202bcb = { 199static const struct sn9c102_sensor pas202bcb = {
201 .name = "PAS202BCB", 200 .name = "PAS202BCB",
202 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 201 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
203 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103, 202 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
@@ -313,9 +312,8 @@ int sn9c102_probe_pas202bcb(struct sn9c102_device* cam)
313 {0x28, 0x17});/* clock 24 MHz */ 312 {0x28, 0x17});/* clock 24 MHz */
314 break; 313 break;
315 case BRIDGE_SN9C103: /* do _not_ change anything! */ 314 case BRIDGE_SN9C103: /* do _not_ change anything! */
316 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, 315 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, {0x44, 0x01},
317 {0x44, 0x01}, {0x44, 0x02}, 316 {0x44, 0x02}, {0x29, 0x17});
318 {0x29, 0x17});
319 break; 317 break;
320 default: 318 default:
321 break; 319 break;
diff --git a/drivers/media/video/sn9c102/sn9c102_sensor.h b/drivers/media/video/sn9c102/sn9c102_sensor.h
index 1bbf64c897a2..2d7d786b8430 100644
--- a/drivers/media/video/sn9c102/sn9c102_sensor.h
+++ b/drivers/media/video/sn9c102/sn9c102_sensor.h
@@ -22,7 +22,7 @@
22#define _SN9C102_SENSOR_H_ 22#define _SN9C102_SENSOR_H_
23 23
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include <linux/videodev.h> 25#include <linux/videodev2.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/stddef.h> 27#include <linux/stddef.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
@@ -74,7 +74,7 @@ sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id);
74/* Attach a probed sensor to the camera. */ 74/* Attach a probed sensor to the camera. */
75extern void 75extern void
76sn9c102_attach_sensor(struct sn9c102_device* cam, 76sn9c102_attach_sensor(struct sn9c102_device* cam,
77 struct sn9c102_sensor* sensor); 77 const struct sn9c102_sensor* sensor);
78 78
79/* 79/*
80 Read/write routines: they always return -1 on error, 0 or the read value 80 Read/write routines: they always return -1 on error, 0 or the read value
@@ -85,10 +85,11 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
85*/ 85*/
86 86
87/* The "try" I2C I/O versions are used when probing the sensor */ 87/* The "try" I2C I/O versions are used when probing the sensor */
88extern int sn9c102_i2c_try_write(struct sn9c102_device*,struct sn9c102_sensor*, 88extern int sn9c102_i2c_try_write(struct sn9c102_device*,
89 u8 address, u8 value); 89 const struct sn9c102_sensor*, u8 address,
90extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*, 90 u8 value);
91 u8 address); 91extern int sn9c102_i2c_try_read(struct sn9c102_device*,
92 const struct sn9c102_sensor*, u8 address);
92 93
93/* 94/*
94 These must be used if and only if the sensor doesn't implement the standard 95 These must be used if and only if the sensor doesn't implement the standard
@@ -102,29 +103,31 @@ extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
102 byte. 103 byte.
103*/ 104*/
104extern int sn9c102_i2c_try_raw_write(struct sn9c102_device* cam, 105extern int sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
105 struct sn9c102_sensor* sensor, u8 n, 106 const struct sn9c102_sensor* sensor, u8 n,
106 u8 data0, u8 data1, u8 data2, u8 data3, 107 u8 data0, u8 data1, u8 data2, u8 data3,
107 u8 data4, u8 data5); 108 u8 data4, u8 data5);
108extern int sn9c102_i2c_try_raw_read(struct sn9c102_device* cam, 109extern int sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
109 struct sn9c102_sensor* sensor, u8 data0, 110 const struct sn9c102_sensor* sensor,
110 u8 data1, u8 n, u8 buffer[]); 111 u8 data0, u8 data1, u8 n, u8 buffer[]);
111 112
112/* To be used after the sensor struct has been attached to the camera struct */ 113/* To be used after the sensor struct has been attached to the camera struct */
113extern int sn9c102_i2c_write(struct sn9c102_device*, u8 address, u8 value); 114extern int sn9c102_i2c_write(struct sn9c102_device*, u8 address, u8 value);
114extern int sn9c102_i2c_read(struct sn9c102_device*, u8 address); 115extern int sn9c102_i2c_read(struct sn9c102_device*, u8 address);
115 116
116/* I/O on registers in the bridge. Could be used by the sensor methods too */ 117/* I/O on registers in the bridge. Could be used by the sensor methods too */
118extern int sn9c102_read_reg(struct sn9c102_device*, u16 index);
117extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index); 119extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index);
118extern int sn9c102_write_reg(struct sn9c102_device*, u8 value, u16 index); 120extern int sn9c102_write_reg(struct sn9c102_device*, u8 value, u16 index);
119extern int sn9c102_write_regs(struct sn9c102_device*, const u8 valreg[][2], 121extern int sn9c102_write_regs(struct sn9c102_device*, const u8 valreg[][2],
120 int count); 122 int count);
121/* 123/*
122 * Write multiple registers with constant values. For example: 124 Write multiple registers with constant values. For example:
123 * sn9c102_write_const_regs(cam, {0x00, 0x14}, {0x60, 0x17}, {0x0f, 0x18}); 125 sn9c102_write_const_regs(cam, {0x00, 0x14}, {0x60, 0x17}, {0x0f, 0x18});
124 */ 126 Register adresses must be < 256.
125#define sn9c102_write_const_regs(device, data...) \ 127*/
126 ({ const static u8 _data[][2] = {data}; \ 128#define sn9c102_write_const_regs(sn9c102_device, data...) \
127 sn9c102_write_regs(device, _data, ARRAY_SIZE(_data)); }) 129 ({ const static u8 _valreg[][2] = {data}; \
130 sn9c102_write_regs(sn9c102_device, _valreg, ARRAY_SIZE(_valreg)); })
128 131
129/*****************************************************************************/ 132/*****************************************************************************/
130 133
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
index 0e7ec8662c70..e7d2de2bace1 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
@@ -88,7 +88,7 @@ static int tas5110c1b_set_pix_format(struct sn9c102_device* cam,
88} 88}
89 89
90 90
91static struct sn9c102_sensor tas5110c1b = { 91static const struct sn9c102_sensor tas5110c1b = {
92 .name = "TAS5110C1B", 92 .name = "TAS5110C1B",
93 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 93 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
94 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 94 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110d.c b/drivers/media/video/sn9c102/sn9c102_tas5110d.c
index 83a39e8b5e71..d32fdbccdc5e 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110d.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110d.c
@@ -68,7 +68,7 @@ static int tas5110d_set_pix_format(struct sn9c102_device* cam,
68} 68}
69 69
70 70
71static struct sn9c102_sensor tas5110d = { 71static const struct sn9c102_sensor tas5110d = {
72 .name = "TAS5110D", 72 .name = "TAS5110D",
73 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 73 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
74 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 74 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
index 50406503fc40..56fb1d575a8a 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
@@ -89,7 +89,7 @@ static int tas5130d1b_set_pix_format(struct sn9c102_device* cam,
89} 89}
90 90
91 91
92static struct sn9c102_sensor tas5130d1b = { 92static const struct sn9c102_sensor tas5130d1b = {
93 .name = "TAS5130D1B", 93 .name = "TAS5130D1B",
94 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 94 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
95 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 95 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,