drivers/media/usb/hdpvr/hdpvr-i2c.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/hdpvr/hdpvr-i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/hdpvr/hdpvr-i2c.c- Extension
.c- Size
- 4635 bytes
- Lines
- 193
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/slab.hlinux/export.hhdpvr.h
Detected Declarations
function Copyrightfunction hdpvr_i2c_readfunction hdpvr_i2c_writefunction hdpvr_transferfunction hdpvr_functionalityfunction hdpvr_activate_irfunction hdpvr_register_i2c_adapter
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Hauppauge HD PVR USB driver
*
* Copyright (C) 2008 Janne Grunau (j@jannau.net)
*
* IR device registration code is
* Copyright (C) 2010 Andy Walls <awalls@md.metrocast.net>
*/
#if IS_ENABLED(CONFIG_I2C)
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/export.h>
#include "hdpvr.h"
#define CTRL_READ_REQUEST 0xb8
#define CTRL_WRITE_REQUEST 0x38
#define REQTYPE_I2C_READ 0xb1
#define REQTYPE_I2C_WRITE 0xb0
#define REQTYPE_I2C_WRITE_STATT 0xd0
#define Z8F0811_IR_TX_I2C_ADDR 0x70
#define Z8F0811_IR_RX_I2C_ADDR 0x71
struct i2c_client *hdpvr_register_ir_i2c(struct hdpvr_device *dev)
{
struct IR_i2c_init_data *init_data = &dev->ir_i2c_init_data;
struct i2c_board_info info = {
I2C_BOARD_INFO("ir_z8f0811_hdpvr", Z8F0811_IR_RX_I2C_ADDR),
};
/* Our default information for ir-kbd-i2c.c to use */
init_data->ir_codes = RC_MAP_HAUPPAUGE;
init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
init_data->type = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_RC6_MCE |
RC_PROTO_BIT_RC6_6A_32;
init_data->name = "HD-PVR";
init_data->polling_interval = 405; /* ms, duplicated from Windows */
info.platform_data = init_data;
return i2c_new_client_device(&dev->i2c_adapter, &info);
}
static int hdpvr_i2c_read(struct hdpvr_device *dev, int bus,
unsigned char addr, char *wdata, int wlen,
char *data, int len)
{
int ret;
if ((len > sizeof(dev->i2c_buf)) || (wlen > sizeof(dev->i2c_buf)))
return -EINVAL;
if (wlen) {
memcpy(dev->i2c_buf, wdata, wlen);
ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
REQTYPE_I2C_WRITE, CTRL_WRITE_REQUEST,
(bus << 8) | addr, 0, dev->i2c_buf,
wlen, 1000);
if (ret < 0)
return ret;
}
ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
REQTYPE_I2C_READ, CTRL_READ_REQUEST,
(bus << 8) | addr, 0, dev->i2c_buf, len, 1000);
if (ret == len) {
memcpy(data, dev->i2c_buf, len);
ret = 0;
} else if (ret >= 0)
ret = -EIO;
return ret;
}
static int hdpvr_i2c_write(struct hdpvr_device *dev, int bus,
unsigned char addr, char *data, int len)
{
int ret;
if (len > sizeof(dev->i2c_buf))
return -EINVAL;
memcpy(dev->i2c_buf, data, len);
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/slab.h`, `linux/export.h`, `hdpvr.h`.
- Detected declarations: `function Copyright`, `function hdpvr_i2c_read`, `function hdpvr_i2c_write`, `function hdpvr_transfer`, `function hdpvr_functionality`, `function hdpvr_activate_ir`, `function hdpvr_register_i2c_adapter`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.