^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2008 Sensoray Company Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/videodev2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <media/v4l2-common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <media/v4l2-subdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "go7007-priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) MODULE_DESCRIPTION("Sensoray 2250/2251 i2c v4l2 subdev driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Note: this board has two i2c devices: a vpx3226f and a tlv320aic23b.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Due to the unusual way these are accessed on this device we do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * reuse the i2c drivers, but instead they are implemented in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * driver. It would be nice to improve on this, though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define TLV320_ADDRESS 0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define VPX322_ADDR_ANALOGCONTROL1 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define VPX322_ADDR_BRIGHTNESS0 0x0127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define VPX322_ADDR_BRIGHTNESS1 0x0131
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define VPX322_ADDR_CONTRAST0 0x0128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define VPX322_ADDR_CONTRAST1 0x0132
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define VPX322_ADDR_HUE 0x00dc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define VPX322_ADDR_SAT 0x0030
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct go7007_usb_board {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct go7007_board_info main_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct go7007_usb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct go7007_usb_board *board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct mutex i2c_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct usb_device *usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct urb *video_urbs[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct urb *audio_urbs[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct urb *intr_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static unsigned char aud_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 0x1e, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 0x00, 0x17,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 0x02, 0x17,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 0x04, 0xf9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 0x06, 0xf9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 0x08, 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 0x0a, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 0x0c, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 0x0a, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 0x0c, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 0x0e, 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 0x10, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 0x12, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static unsigned char vid_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 0xF2, 0x0f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 0xAA, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 0xF8, 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static u16 vid_regs_fp[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 0x028, 0x067,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 0x120, 0x016,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 0x121, 0xcF2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 0x122, 0x0F2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 0x123, 0x00c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 0x124, 0x2d0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 0x125, 0x2e0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 0x126, 0x004,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 0x128, 0x1E0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 0x12A, 0x016,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 0x12B, 0x0F2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 0x12C, 0x0F2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 0x12D, 0x00c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 0x12E, 0x2d0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 0x12F, 0x2e0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 0x130, 0x004,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 0x132, 0x1E0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 0x140, 0x060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 0x153, 0x00C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 0x154, 0x200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) 0x150, 0x801,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) 0x000, 0x000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* PAL specific values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static u16 vid_regs_fp_pal[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 0x120, 0x017,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 0x121, 0xd22,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 0x122, 0x122,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 0x12A, 0x017,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 0x12B, 0x122,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 0x12C, 0x122,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 0x140, 0x060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 0x000, 0x000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct s2250 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct v4l2_subdev sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct v4l2_ctrl_handler hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) v4l2_std_id std;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int contrast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int saturation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int hue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int reg12b_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int audio_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct i2c_client *audio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static inline struct s2250 *to_state(struct v4l2_subdev *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return container_of(sd, struct s2250, sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int go7007_usb_vendor_request(struct go7007 *go, u16 request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u16 value, u16 index, void *transfer_buffer, int length, int in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct go7007_usb *usb = go->hpi_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int timeout = 5000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return usb_control_msg(usb->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) usb_rcvctrlpipe(usb->usbdev, 0), request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) value, index, transfer_buffer, length, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return usb_control_msg(usb->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) usb_sndctrlpipe(usb->usbdev, 0), request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) value, index, transfer_buffer, length, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* end from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int write_reg(struct i2c_client *client, u8 reg, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct go7007 *go = i2c_get_adapdata(client->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct go7007_usb *usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int dev_addr = client->addr << 1; /* firmware wants 8-bit address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (go == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (go->status == STATUS_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) buf = kzalloc(16, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) usb = go->hpi_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_info(&client->dev, "i2c lock failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) rc = go7007_usb_vendor_request(go, 0x55, dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) (reg<<8 | value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 16, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) mutex_unlock(&usb->i2c_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int write_reg_fp(struct i2c_client *client, u16 addr, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct go7007 *go = i2c_get_adapdata(client->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct go7007_usb *usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct s2250 *dec = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (go == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (go->status == STATUS_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) buf = kzalloc(16, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) memset(buf, 0xcd, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) usb = go->hpi_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) dev_info(&client->dev, "i2c lock failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) rc = go7007_usb_vendor_request(go, 0x57, addr, val, buf, 16, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) mutex_unlock(&usb->i2c_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (buf[0] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) unsigned int subaddr, val_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) subaddr = (buf[4] << 8) + buf[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) val_read = (buf[2] << 8) + buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (val_read != val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) dev_info(&client->dev, "invalid fp write %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) val_read, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (subaddr != addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_info(&client->dev, "invalid fp write addr %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) subaddr, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* save last 12b value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (addr == 0x12b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) dec->reg12b_val = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int read_reg_fp(struct i2c_client *client, u16 addr, u16 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct go7007 *go = i2c_get_adapdata(client->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct go7007_usb *usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (go == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (go->status == STATUS_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) buf = kzalloc(16, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) memset(buf, 0xcd, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) usb = go->hpi_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) dev_info(&client->dev, "i2c lock failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) rc = go7007_usb_vendor_request(go, 0x58, addr, 0, buf, 16, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) mutex_unlock(&usb->i2c_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) *val = (buf[0] << 8) | buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int write_regs(struct i2c_client *client, u8 *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (write_reg(client, regs[i], regs[i+1]) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) dev_info(&client->dev, "failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int write_regs_fp(struct i2c_client *client, u16 *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (write_reg_fp(client, regs[i], regs[i+1]) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) dev_info(&client->dev, "failed fp\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static int s2250_s_video_routing(struct v4l2_subdev *sd, u32 input, u32 output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) u32 config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct s2250 *state = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct i2c_client *client = v4l2_get_subdevdata(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int vidsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) vidsys = (state->std == V4L2_STD_NTSC) ? 0x01 : 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (input == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* composite */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) write_reg_fp(client, 0x20, 0x020 | vidsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) write_reg_fp(client, 0x21, 0x662);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) write_reg_fp(client, 0x140, 0x060);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) } else if (input == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* S-Video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) write_reg_fp(client, 0x20, 0x040 | vidsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) write_reg_fp(client, 0x21, 0x666);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) write_reg_fp(client, 0x140, 0x060);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) state->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int s2250_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct s2250 *state = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct i2c_client *client = v4l2_get_subdevdata(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) u16 vidsource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) vidsource = (state->input == 1) ? 0x040 : 0x020;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (norm & V4L2_STD_625_50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) write_regs_fp(client, vid_regs_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) write_regs_fp(client, vid_regs_fp_pal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) write_reg_fp(client, 0x20, vidsource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) write_regs_fp(client, vid_regs_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) write_reg_fp(client, 0x20, vidsource | 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) state->std = norm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static int s2250_s_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct s2250 *state = container_of(ctrl->handler, struct s2250, hdl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) u16 oldvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) switch (ctrl->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) case V4L2_CID_BRIGHTNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) read_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, &oldvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) write_reg_fp(client, VPX322_ADDR_BRIGHTNESS0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ctrl->val | (oldvalue & ~0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) read_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, &oldvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) write_reg_fp(client, VPX322_ADDR_BRIGHTNESS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ctrl->val | (oldvalue & ~0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) write_reg_fp(client, 0x140, 0x60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) case V4L2_CID_CONTRAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) read_reg_fp(client, VPX322_ADDR_CONTRAST0, &oldvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) write_reg_fp(client, VPX322_ADDR_CONTRAST0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ctrl->val | (oldvalue & ~0x3f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) read_reg_fp(client, VPX322_ADDR_CONTRAST1, &oldvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) write_reg_fp(client, VPX322_ADDR_CONTRAST1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ctrl->val | (oldvalue & ~0x3f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) write_reg_fp(client, 0x140, 0x60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) case V4L2_CID_SATURATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) write_reg_fp(client, VPX322_ADDR_SAT, ctrl->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) case V4L2_CID_HUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) write_reg_fp(client, VPX322_ADDR_HUE, ctrl->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static int s2250_set_fmt(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct v4l2_subdev_format *format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct v4l2_mbus_framefmt *fmt = &format->format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct s2250 *state = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct i2c_client *client = v4l2_get_subdevdata(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (format->pad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (format->which == V4L2_SUBDEV_FORMAT_TRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (fmt->height < 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) write_reg_fp(client, 0x12b, state->reg12b_val | 0x400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) write_reg_fp(client, 0x140, 0x060);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) write_reg_fp(client, 0x12b, state->reg12b_val & ~0x400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) write_reg_fp(client, 0x140, 0x060);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static int s2250_s_audio_routing(struct v4l2_subdev *sd, u32 input, u32 output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) u32 config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct s2250 *state = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) switch (input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) write_reg(state->audio, 0x08, 0x02); /* Line In */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) write_reg(state->audio, 0x08, 0x04); /* Mic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) write_reg(state->audio, 0x08, 0x05); /* Mic Boost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) state->audio_input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static int s2250_log_status(struct v4l2_subdev *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct s2250 *state = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) v4l2_info(sd, "Standard: %s\n", state->std == V4L2_STD_NTSC ? "NTSC" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) state->std == V4L2_STD_PAL ? "PAL" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) state->std == V4L2_STD_SECAM ? "SECAM" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) "unknown");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) v4l2_info(sd, "Input: %s\n", state->input == 0 ? "Composite" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) state->input == 1 ? "S-video" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) "error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) state->audio_input == 1 ? "Mic" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) state->audio_input == 2 ? "Mic Boost" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) "error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return v4l2_ctrl_subdev_log_status(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* --------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static const struct v4l2_ctrl_ops s2250_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) .s_ctrl = s2250_s_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static const struct v4l2_subdev_core_ops s2250_core_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) .log_status = s2250_log_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static const struct v4l2_subdev_audio_ops s2250_audio_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) .s_routing = s2250_s_audio_routing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static const struct v4l2_subdev_video_ops s2250_video_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) .s_std = s2250_s_std,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) .s_routing = s2250_s_video_routing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static const struct v4l2_subdev_pad_ops s2250_pad_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) .set_fmt = s2250_set_fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static const struct v4l2_subdev_ops s2250_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) .core = &s2250_core_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) .audio = &s2250_audio_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .video = &s2250_video_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) .pad = &s2250_pad_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /* --------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int s2250_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct i2c_client *audio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct s2250 *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct v4l2_subdev *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct go7007 *go = i2c_get_adapdata(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct go7007_usb *usb = go->hpi_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) int err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) audio = i2c_new_dummy_device(adapter, TLV320_ADDRESS >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (IS_ERR(audio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return PTR_ERR(audio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) state = kzalloc(sizeof(struct s2250), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (state == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) i2c_unregister_device(audio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) sd = &state->sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) v4l2_i2c_subdev_init(sd, client, &s2250_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) v4l2_info(sd, "initializing %s at address 0x%x on %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) "Sensoray 2250/2251", client->addr, client->adapter->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) v4l2_ctrl_handler_init(&state->hdl, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) V4L2_CID_CONTRAST, 0, 0x3f, 1, 0x32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) V4L2_CID_SATURATION, 0, 4094, 1, 2070);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) V4L2_CID_HUE, -512, 511, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) sd->ctrl_handler = &state->hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (state->hdl.error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) err = state->hdl.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) state->std = V4L2_STD_NTSC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) state->brightness = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) state->contrast = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) state->saturation = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) state->hue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) state->audio = audio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /* initialize the audio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (write_regs(audio, aud_regs) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) dev_err(&client->dev, "error initializing audio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (write_regs(client, vid_regs) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dev_err(&client->dev, "error initializing decoder\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (write_regs_fp(client, vid_regs_fp) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) dev_err(&client->dev, "error initializing decoder\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) /* set default channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* composite */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) write_reg_fp(client, 0x20, 0x020 | 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) write_reg_fp(client, 0x21, 0x662);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) write_reg_fp(client, 0x140, 0x060);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* set default audio input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) state->audio_input = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) write_reg(client, 0x08, 0x02); /* Line In */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (mutex_lock_interruptible(&usb->i2c_lock) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) data = kzalloc(16, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (data != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) int rc = go7007_usb_vendor_request(go, 0x41, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) data, 16, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (rc > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) u8 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) data[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) mask = 1<<5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) data[0] &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) data[1] |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) go7007_usb_vendor_request(go, 0x40, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) (data[1]<<8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) + data[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) data, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) mutex_unlock(&usb->i2c_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) v4l2_info(sd, "initialized successfully\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) i2c_unregister_device(audio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) v4l2_ctrl_handler_free(&state->hdl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static int s2250_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct s2250 *state = to_state(i2c_get_clientdata(client));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) i2c_unregister_device(state->audio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) v4l2_device_unregister_subdev(&state->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) v4l2_ctrl_handler_free(&state->hdl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static const struct i2c_device_id s2250_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) { "s2250", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) MODULE_DEVICE_TABLE(i2c, s2250_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static struct i2c_driver s2250_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) .name = "s2250",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) .probe = s2250_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .remove = s2250_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .id_table = s2250_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) module_i2c_driver(s2250_driver);