]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/media/video/hdpvr/hdpvr-i2c.c
3 * Hauppauge HD PVR USB driver
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
13 #include <linux/i2c.h>
14 #include <linux/slab.h>
18 #define CTRL_READ_REQUEST 0xb8
19 #define CTRL_WRITE_REQUEST 0x38
21 #define REQTYPE_I2C_READ 0xb1
22 #define REQTYPE_I2C_WRITE 0xb0
23 #define REQTYPE_I2C_WRITE_STATT 0xd0
25 static int hdpvr_i2c_read(struct hdpvr_device
*dev
, unsigned char addr
,
29 char *buf
= kmalloc(len
, GFP_KERNEL
);
33 ret
= usb_control_msg(dev
->udev
,
34 usb_rcvctrlpipe(dev
->udev
, 0),
35 REQTYPE_I2C_READ
, CTRL_READ_REQUEST
,
36 0x100|addr
, 0, buf
, len
, 1000);
39 memcpy(data
, buf
, len
);
49 static int hdpvr_i2c_write(struct hdpvr_device
*dev
, unsigned char addr
,
53 char *buf
= kmalloc(len
, GFP_KERNEL
);
57 memcpy(buf
, data
, len
);
58 ret
= usb_control_msg(dev
->udev
,
59 usb_sndctrlpipe(dev
->udev
, 0),
60 REQTYPE_I2C_WRITE
, CTRL_WRITE_REQUEST
,
61 0x100|addr
, 0, buf
, len
, 1000);
66 ret
= usb_control_msg(dev
->udev
,
67 usb_rcvctrlpipe(dev
->udev
, 0),
68 REQTYPE_I2C_WRITE_STATT
, CTRL_READ_REQUEST
,
81 static int hdpvr_transfer(struct i2c_adapter
*i2c_adapter
, struct i2c_msg
*msgs
,
84 struct hdpvr_device
*dev
= i2c_get_adapdata(i2c_adapter
);
85 int retval
= 0, i
, addr
;
90 mutex_lock(&dev
->i2c_mutex
);
92 for (i
= 0; i
< num
&& !retval
; i
++) {
93 addr
= msgs
[i
].addr
<< 1;
95 if (msgs
[i
].flags
& I2C_M_RD
)
96 retval
= hdpvr_i2c_read(dev
, addr
, msgs
[i
].buf
,
99 retval
= hdpvr_i2c_write(dev
, addr
, msgs
[i
].buf
,
103 mutex_unlock(&dev
->i2c_mutex
);
105 return retval
? retval
: num
;
108 static u32
hdpvr_functionality(struct i2c_adapter
*adapter
)
110 return I2C_FUNC_I2C
| I2C_FUNC_SMBUS_EMUL
;
113 static struct i2c_algorithm hdpvr_algo
= {
114 .master_xfer
= hdpvr_transfer
,
115 .functionality
= hdpvr_functionality
,
118 int hdpvr_register_i2c_adapter(struct hdpvr_device
*dev
)
120 struct i2c_adapter
*i2c_adap
;
121 int retval
= -ENOMEM
;
123 i2c_adap
= kzalloc(sizeof(struct i2c_adapter
), GFP_KERNEL
);
124 if (i2c_adap
== NULL
)
127 strlcpy(i2c_adap
->name
, "Hauppauge HD PVR I2C",
128 sizeof(i2c_adap
->name
));
129 i2c_adap
->algo
= &hdpvr_algo
;
130 i2c_adap
->class = I2C_CLASS_TV_ANALOG
;
131 i2c_adap
->owner
= THIS_MODULE
;
132 i2c_adap
->dev
.parent
= &dev
->udev
->dev
;
134 i2c_set_adapdata(i2c_adap
, dev
);
136 retval
= i2c_add_adapter(i2c_adap
);
139 dev
->i2c_adapter
= i2c_adap
;