mirror of
https://github.com/torvalds/linux.git
synced 2024-12-26 21:02:19 +00:00
7d58d1117e
Issuing register reads as a separate address write and data read transactions means that other I2C activity could occur in between and state could get out of sync. Issue both the write and read in a single transaction so that the i2c layer can prevent other users accessing the bus until we are complete. Signed-off-by: Chris Pascoe <c.pascoe@itee.uq.edu.au> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
90 lines
2.7 KiB
C
90 lines
2.7 KiB
C
/*
|
|
tuner-i2c.h - i2c interface for different tuners
|
|
|
|
Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org)
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#ifndef __TUNER_I2C_H__
|
|
#define __TUNER_I2C_H__
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
struct tuner_i2c_props {
|
|
u8 addr;
|
|
struct i2c_adapter *adap;
|
|
};
|
|
|
|
static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
|
|
{
|
|
struct i2c_msg msg = { .addr = props->addr, .flags = 0,
|
|
.buf = buf, .len = len };
|
|
int ret = i2c_transfer(props->adap, &msg, 1);
|
|
|
|
return (ret == 1) ? len : ret;
|
|
}
|
|
|
|
static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len)
|
|
{
|
|
struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
|
|
.buf = buf, .len = len };
|
|
int ret = i2c_transfer(props->adap, &msg, 1);
|
|
|
|
return (ret == 1) ? len : ret;
|
|
}
|
|
|
|
static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
|
|
char *obuf, int olen,
|
|
char *ibuf, int ilen)
|
|
{
|
|
struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
|
|
.buf = obuf, .len = olen },
|
|
{ .addr = props->addr, .flags = I2C_M_RD,
|
|
.buf = ibuf, .len = ilen } };
|
|
int ret = i2c_transfer(props->adap, msg, 2);
|
|
|
|
return (ret == 2) ? ilen : ret;
|
|
}
|
|
|
|
#ifndef __TUNER_DRIVER_H__
|
|
#define tuner_warn(fmt, arg...) do { \
|
|
printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
|
|
i2c_adapter_id(priv->i2c_props.adap), \
|
|
priv->i2c_props.addr, ##arg); \
|
|
} while (0)
|
|
|
|
#define tuner_info(fmt, arg...) do { \
|
|
printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
|
|
i2c_adapter_id(priv->i2c_props.adap), \
|
|
priv->i2c_props.addr , ##arg); \
|
|
} while (0)
|
|
|
|
#define tuner_err(fmt, arg...) do { \
|
|
printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
|
|
i2c_adapter_id(priv->i2c_props.adap), \
|
|
priv->i2c_props.addr , ##arg); \
|
|
} while (0)
|
|
|
|
#define tuner_dbg(fmt, arg...) do { \
|
|
if ((debug)) \
|
|
printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
|
|
i2c_adapter_id(priv->i2c_props.adap), \
|
|
priv->i2c_props.addr , ##arg); \
|
|
} while (0)
|
|
#endif /* __TUNER_DRIVER_H__ */
|
|
|
|
#endif /* __TUNER_I2C_H__ */
|