drivers/media/usb/dvb-usb/technisat-usb2.c

Source file repositories/reference/linux-study-clean/drivers/media/usb/dvb-usb/technisat-usb2.c

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/dvb-usb/technisat-usb2.c
Extension
.c
Size
20086 bytes
Lines
812
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct technisat_usb2_state {
	struct dvb_usb_device *dev;
	struct delayed_work green_led_work;
	u8 power_state;

	u16 last_scan_code;

	u8 buf[64];
};

/* debug print helpers */
#define deb_info(args...)    dprintk(debug, 0x01, args)
#define deb_eeprom(args...)  dprintk(debug, 0x02, args)
#define deb_i2c(args...)     dprintk(debug, 0x04, args)
#define deb_rc(args...)      dprintk(debug, 0x08, args)

/* vendor requests */
#define SET_IFCLK_TO_EXTERNAL_TSCLK_VENDOR_REQUEST 0xB3
#define SET_FRONT_END_RESET_VENDOR_REQUEST         0xB4
#define GET_VERSION_INFO_VENDOR_REQUEST            0xB5
#define SET_GREEN_LED_VENDOR_REQUEST               0xB6
#define SET_RED_LED_VENDOR_REQUEST                 0xB7
#define GET_IR_DATA_VENDOR_REQUEST                 0xB8
#define SET_LED_TIMER_DIVIDER_VENDOR_REQUEST       0xB9
#define SET_USB_REENUMERATION                      0xBA

/* i2c-access methods */
#define I2C_SPEED_100KHZ_BIT 0x40

#define I2C_STATUS_NAK 7
#define I2C_STATUS_OK 8

static int technisat_usb2_i2c_access(struct usb_device *udev,
		u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
{
	u8 *b;
	int ret, actual_length;

	b = kmalloc(64, GFP_KERNEL);
	if (!b)
		return -ENOMEM;

	deb_i2c("i2c-access: %02x, tx: ", device_addr);
	debug_dump(tx, txlen, deb_i2c);
	deb_i2c(" ");

	if (txlen > 62) {
		err("i2c TX buffer can't exceed 62 bytes (dev 0x%02x)",
				device_addr);
		txlen = 62;
	}
	if (rxlen > 62) {
		err("i2c RX buffer can't exceed 62 bytes (dev 0x%02x)",
				device_addr);
		rxlen = 62;
	}

	b[0] = I2C_SPEED_100KHZ_BIT;
	b[1] = device_addr << 1;

	if (rx != NULL) {
		b[0] |= rxlen;
		b[1] |= 1;
	}

	memcpy(&b[2], tx, txlen);
	ret = usb_bulk_msg(udev,
			usb_sndbulkpipe(udev, 0x01),
			b, 2 + txlen,
			NULL, 1000);

	if (ret < 0) {
		err("i2c-error: out failed %02x = %d", device_addr, ret);
		goto err;
	}

	ret = usb_bulk_msg(udev,
			usb_rcvbulkpipe(udev, 0x01),
			b, 64, &actual_length, 1000);
	if (ret < 0) {
		err("i2c-error: in failed %02x = %d", device_addr, ret);
		goto err;
	}

	if (b[0] != I2C_STATUS_OK) {
		err("i2c-error: %02x = %d", device_addr, b[0]);
		/* handle tuner-i2c-nak */
		if (!(b[0] == I2C_STATUS_NAK &&
				device_addr == 0x60
				/* && device_is_technisat_usb2 */))

Annotation

Implementation Notes