2019-05-20 14:19:02 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2007-08-21 11:24:42 +07:00
|
|
|
/*
|
|
|
|
tuner-i2c.h - i2c interface for different tuners
|
|
|
|
|
|
|
|
Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TUNER_I2C_H__
|
|
|
|
#define __TUNER_I2C_H__
|
|
|
|
|
|
|
|
#include <linux/i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2007-08-21 11:24:42 +07:00
|
|
|
|
|
|
|
struct tuner_i2c_props {
|
|
|
|
u8 addr;
|
|
|
|
struct i2c_adapter *adap;
|
2008-04-23 00:41:52 +07:00
|
|
|
|
|
|
|
/* used for tuner instance management */
|
|
|
|
int count;
|
|
|
|
char *name;
|
2007-08-21 11:24:42 +07:00
|
|
|
};
|
|
|
|
|
2015-06-23 02:16:39 +07:00
|
|
|
static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props,
|
|
|
|
unsigned char *buf, int len)
|
2007-08-21 11:24:42 +07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-06-23 02:16:39 +07:00
|
|
|
static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props,
|
|
|
|
unsigned char *buf, int len)
|
2007-08-21 11:24:42 +07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-19 14:31:58 +07:00
|
|
|
static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
|
2015-06-23 02:16:39 +07:00
|
|
|
unsigned char *obuf, int olen,
|
|
|
|
unsigned char *ibuf, int ilen)
|
2007-11-19 14:31:58 +07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-23 00:41:52 +07:00
|
|
|
/* Callers must declare as a global for the module:
|
|
|
|
*
|
|
|
|
* static LIST_HEAD(hybrid_tuner_instance_list);
|
|
|
|
*
|
|
|
|
* hybrid_tuner_instance_list should be the third argument
|
|
|
|
* passed into hybrid_tuner_request_state().
|
|
|
|
*
|
|
|
|
* state structure must contain the following:
|
|
|
|
*
|
2018-01-04 18:47:28 +07:00
|
|
|
* struct list_head hybrid_tuner_instance_list;
|
2008-04-23 00:41:52 +07:00
|
|
|
* struct tuner_i2c_props i2c_props;
|
|
|
|
*
|
|
|
|
* hybrid_tuner_instance_list (both within state structure and globally)
|
|
|
|
* is only required if the driver is using hybrid_tuner_request_state
|
|
|
|
* and hybrid_tuner_release_state to manage state sharing between
|
|
|
|
* multiple instances of hybrid tuners.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define tuner_printk(kernlvl, i2cprops, fmt, arg...) do { \
|
|
|
|
printk(kernlvl "%s %d-%04x: " fmt, i2cprops.name, \
|
2008-04-23 00:42:05 +07:00
|
|
|
i2cprops.adap ? \
|
|
|
|
i2c_adapter_id(i2cprops.adap) : -1, \
|
2008-04-23 00:41:52 +07:00
|
|
|
i2cprops.addr, ##arg); \
|
2007-11-15 19:35:44 +07:00
|
|
|
} while (0)
|
|
|
|
|
2008-04-23 00:41:52 +07:00
|
|
|
/* TO DO: convert all callers of these macros to pass in
|
|
|
|
* struct tuner_i2c_props, then remove the macro wrappers */
|
|
|
|
|
|
|
|
#define __tuner_warn(i2cprops, fmt, arg...) do { \
|
|
|
|
tuner_printk(KERN_WARNING, i2cprops, fmt, ##arg); \
|
2007-11-15 19:35:44 +07:00
|
|
|
} while (0)
|
|
|
|
|
2008-04-23 00:41:52 +07:00
|
|
|
#define __tuner_info(i2cprops, fmt, arg...) do { \
|
|
|
|
tuner_printk(KERN_INFO, i2cprops, fmt, ##arg); \
|
2007-11-15 19:35:44 +07:00
|
|
|
} while (0)
|
|
|
|
|
2008-04-23 00:41:52 +07:00
|
|
|
#define __tuner_err(i2cprops, fmt, arg...) do { \
|
|
|
|
tuner_printk(KERN_ERR, i2cprops, fmt, ##arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define __tuner_dbg(i2cprops, fmt, arg...) do { \
|
2007-11-15 19:35:44 +07:00
|
|
|
if ((debug)) \
|
2008-04-23 00:41:52 +07:00
|
|
|
tuner_printk(KERN_DEBUG, i2cprops, fmt, ##arg); \
|
2007-11-15 19:35:44 +07:00
|
|
|
} while (0)
|
2007-08-21 11:24:42 +07:00
|
|
|
|
2008-04-23 00:41:52 +07:00
|
|
|
#define tuner_warn(fmt, arg...) __tuner_warn(priv->i2c_props, fmt, ##arg)
|
|
|
|
#define tuner_info(fmt, arg...) __tuner_info(priv->i2c_props, fmt, ##arg)
|
|
|
|
#define tuner_err(fmt, arg...) __tuner_err(priv->i2c_props, fmt, ##arg)
|
|
|
|
#define tuner_dbg(fmt, arg...) __tuner_dbg(priv->i2c_props, fmt, ##arg)
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/* The return value of hybrid_tuner_request_state indicates the number of
|
|
|
|
* instances using this tuner object.
|
|
|
|
*
|
|
|
|
* 0 - no instances, indicates an error - kzalloc must have failed
|
|
|
|
*
|
|
|
|
* 1 - one instance, indicates that the tuner object was created successfully
|
|
|
|
*
|
|
|
|
* 2 (or more) instances, indicates that an existing tuner object was found
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define hybrid_tuner_request_state(type, state, list, i2cadap, i2caddr, devname)\
|
|
|
|
({ \
|
|
|
|
int __ret = 0; \
|
|
|
|
list_for_each_entry(state, &list, hybrid_tuner_instance_list) { \
|
2008-04-23 00:46:04 +07:00
|
|
|
if (((i2cadap) && (state->i2c_props.adap)) && \
|
|
|
|
((i2c_adapter_id(state->i2c_props.adap) == \
|
|
|
|
i2c_adapter_id(i2cadap)) && \
|
|
|
|
(i2caddr == state->i2c_props.addr))) { \
|
2008-04-23 00:41:52 +07:00
|
|
|
__tuner_info(state->i2c_props, \
|
|
|
|
"attaching existing instance\n"); \
|
|
|
|
state->i2c_props.count++; \
|
|
|
|
__ret = state->i2c_props.count; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
if (0 == __ret) { \
|
|
|
|
state = kzalloc(sizeof(type), GFP_KERNEL); \
|
|
|
|
if (NULL == state) \
|
|
|
|
goto __fail; \
|
|
|
|
state->i2c_props.addr = i2caddr; \
|
|
|
|
state->i2c_props.adap = i2cadap; \
|
|
|
|
state->i2c_props.name = devname; \
|
|
|
|
__tuner_info(state->i2c_props, \
|
|
|
|
"creating new instance\n"); \
|
|
|
|
list_add_tail(&state->hybrid_tuner_instance_list, &list);\
|
|
|
|
state->i2c_props.count++; \
|
|
|
|
__ret = state->i2c_props.count; \
|
|
|
|
} \
|
|
|
|
__fail: \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2008-04-23 00:42:00 +07:00
|
|
|
#define hybrid_tuner_release_state(state) \
|
|
|
|
({ \
|
|
|
|
int __ret; \
|
2008-04-23 00:41:52 +07:00
|
|
|
state->i2c_props.count--; \
|
2008-04-23 00:42:00 +07:00
|
|
|
__ret = state->i2c_props.count; \
|
2008-04-23 00:41:52 +07:00
|
|
|
if (!state->i2c_props.count) { \
|
|
|
|
__tuner_info(state->i2c_props, "destroying instance\n");\
|
|
|
|
list_del(&state->hybrid_tuner_instance_list); \
|
|
|
|
kfree(state); \
|
|
|
|
} \
|
2008-04-23 00:42:00 +07:00
|
|
|
__ret; \
|
|
|
|
})
|
2008-04-23 00:41:52 +07:00
|
|
|
|
2008-04-19 06:26:04 +07:00
|
|
|
#define hybrid_tuner_report_instance_count(state) \
|
|
|
|
({ \
|
|
|
|
int __ret = 0; \
|
|
|
|
if (state) \
|
|
|
|
__ret = state->i2c_props.count; \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2007-08-21 11:24:42 +07:00
|
|
|
#endif /* __TUNER_I2C_H__ */
|