Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / drivers / media / video / tuner-i2c.h
1 /*
2     tuner-i2c.h - i2c interface for different tuners
3
4     Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org)
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef __TUNER_I2C_H__
22 #define __TUNER_I2C_H__
23
24 #include <linux/i2c.h>
25
26 struct tuner_i2c_props {
27         u8 addr;
28         struct i2c_adapter *adap;
29 };
30
31 static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
32 {
33         struct i2c_msg msg = { .addr = props->addr, .flags = 0,
34                                .buf = buf, .len = len };
35         int ret = i2c_transfer(props->adap, &msg, 1);
36
37         return (ret == 1) ? len : ret;
38 }
39
40 static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len)
41 {
42         struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
43                                .buf = buf, .len = len };
44         int ret = i2c_transfer(props->adap, &msg, 1);
45
46         return (ret == 1) ? len : ret;
47 }
48
49 static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
50                                            char *obuf, int olen,
51                                            char *ibuf, int ilen)
52 {
53         struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
54                                     .buf = obuf, .len = olen },
55                                   { .addr = props->addr, .flags = I2C_M_RD,
56                                     .buf = ibuf, .len = ilen } };
57         int ret = i2c_transfer(props->adap, msg, 2);
58
59         return (ret == 2) ? ilen : ret;
60 }
61
62 #define tuner_warn(fmt, arg...) do {                                    \
63         printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX,                 \
64                         i2c_adapter_id(priv->i2c_props.adap),           \
65                         priv->i2c_props.addr, ##arg);                   \
66          } while (0)
67
68 #define tuner_info(fmt, arg...) do {                                    \
69         printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX,                    \
70                         i2c_adapter_id(priv->i2c_props.adap),           \
71                         priv->i2c_props.addr , ##arg);                  \
72         } while (0)
73
74 #define tuner_err(fmt, arg...) do {                                     \
75         printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX,                     \
76                         i2c_adapter_id(priv->i2c_props.adap),           \
77                         priv->i2c_props.addr , ##arg);                  \
78         } while (0)
79
80 #define tuner_dbg(fmt, arg...) do {                                     \
81         if ((debug))                                                    \
82                 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX,           \
83                         i2c_adapter_id(priv->i2c_props.adap),           \
84                         priv->i2c_props.addr , ##arg);                  \
85         } while (0)
86
87 #endif /* __TUNER_I2C_H__ */