18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Driver for the Conexant CX23885 PCIe bridge
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2006 Steven Toth <stoth@linuxtv.org>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "cx23885.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci#include <linux/delay.h>
138c2ecf20Sopenharmony_ci#include <asm/io.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <media/v4l2-common.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic unsigned int i2c_debug;
188c2ecf20Sopenharmony_cimodule_param(i2c_debug, int, 0644);
198c2ecf20Sopenharmony_ciMODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic unsigned int i2c_scan;
228c2ecf20Sopenharmony_cimodule_param(i2c_scan, int, 0444);
238c2ecf20Sopenharmony_ciMODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define dprintk(level, fmt, arg...)\
268c2ecf20Sopenharmony_ci	do { if (i2c_debug >= level)\
278c2ecf20Sopenharmony_ci		printk(KERN_DEBUG pr_fmt("%s: i2c:" fmt), \
288c2ecf20Sopenharmony_ci			__func__, ##arg); \
298c2ecf20Sopenharmony_ci	} while (0)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define I2C_WAIT_DELAY 32
328c2ecf20Sopenharmony_ci#define I2C_WAIT_RETRY 64
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define I2C_EXTEND  (1 << 3)
358c2ecf20Sopenharmony_ci#define I2C_NOSTOP  (1 << 4)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	struct cx23885_i2c *bus = i2c_adap->algo_data;
408c2ecf20Sopenharmony_ci	struct cx23885_dev *dev = bus->dev;
418c2ecf20Sopenharmony_ci	return cx_read(bus->reg_stat) & 0x01;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline int i2c_is_busy(struct i2c_adapter *i2c_adap)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	struct cx23885_i2c *bus = i2c_adap->algo_data;
478c2ecf20Sopenharmony_ci	struct cx23885_dev *dev = bus->dev;
488c2ecf20Sopenharmony_ci	return cx_read(bus->reg_stat) & 0x02 ? 1 : 0;
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic int i2c_wait_done(struct i2c_adapter *i2c_adap)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	int count;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	for (count = 0; count < I2C_WAIT_RETRY; count++) {
568c2ecf20Sopenharmony_ci		if (!i2c_is_busy(i2c_adap))
578c2ecf20Sopenharmony_ci			break;
588c2ecf20Sopenharmony_ci		udelay(I2C_WAIT_DELAY);
598c2ecf20Sopenharmony_ci	}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	if (I2C_WAIT_RETRY == count)
628c2ecf20Sopenharmony_ci		return 0;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	return 1;
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic int i2c_sendbytes(struct i2c_adapter *i2c_adap,
688c2ecf20Sopenharmony_ci			 const struct i2c_msg *msg, int joined_rlen)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	struct cx23885_i2c *bus = i2c_adap->algo_data;
718c2ecf20Sopenharmony_ci	struct cx23885_dev *dev = bus->dev;
728c2ecf20Sopenharmony_ci	u32 wdata, addr, ctrl;
738c2ecf20Sopenharmony_ci	int retval, cnt;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	if (joined_rlen)
768c2ecf20Sopenharmony_ci		dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__,
778c2ecf20Sopenharmony_ci			msg->len, joined_rlen);
788c2ecf20Sopenharmony_ci	else
798c2ecf20Sopenharmony_ci		dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	/* Deal with i2c probe functions with zero payload */
828c2ecf20Sopenharmony_ci	if (msg->len == 0) {
838c2ecf20Sopenharmony_ci		cx_write(bus->reg_addr, msg->addr << 25);
848c2ecf20Sopenharmony_ci		cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2));
858c2ecf20Sopenharmony_ci		if (!i2c_wait_done(i2c_adap))
868c2ecf20Sopenharmony_ci			return -EIO;
878c2ecf20Sopenharmony_ci		if (!i2c_slave_did_ack(i2c_adap))
888c2ecf20Sopenharmony_ci			return -ENXIO;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci		dprintk(1, "%s() returns 0\n", __func__);
918c2ecf20Sopenharmony_ci		return 0;
928c2ecf20Sopenharmony_ci	}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	/* dev, reg + first byte */
968c2ecf20Sopenharmony_ci	addr = (msg->addr << 25) | msg->buf[0];
978c2ecf20Sopenharmony_ci	wdata = msg->buf[0];
988c2ecf20Sopenharmony_ci	ctrl = bus->i2c_period | (1 << 12) | (1 << 2);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	if (msg->len > 1)
1018c2ecf20Sopenharmony_ci		ctrl |= I2C_NOSTOP | I2C_EXTEND;
1028c2ecf20Sopenharmony_ci	else if (joined_rlen)
1038c2ecf20Sopenharmony_ci		ctrl |= I2C_NOSTOP;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	cx_write(bus->reg_addr, addr);
1068c2ecf20Sopenharmony_ci	cx_write(bus->reg_wdata, wdata);
1078c2ecf20Sopenharmony_ci	cx_write(bus->reg_ctrl, ctrl);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	if (!i2c_wait_done(i2c_adap))
1108c2ecf20Sopenharmony_ci		goto eio;
1118c2ecf20Sopenharmony_ci	if (i2c_debug) {
1128c2ecf20Sopenharmony_ci		printk(KERN_DEBUG " <W %02x %02x", msg->addr << 1, msg->buf[0]);
1138c2ecf20Sopenharmony_ci		if (!(ctrl & I2C_NOSTOP))
1148c2ecf20Sopenharmony_ci			pr_cont(" >\n");
1158c2ecf20Sopenharmony_ci	}
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	for (cnt = 1; cnt < msg->len; cnt++) {
1188c2ecf20Sopenharmony_ci		/* following bytes */
1198c2ecf20Sopenharmony_ci		wdata = msg->buf[cnt];
1208c2ecf20Sopenharmony_ci		ctrl = bus->i2c_period | (1 << 12) | (1 << 2);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci		if (cnt < msg->len - 1)
1238c2ecf20Sopenharmony_ci			ctrl |= I2C_NOSTOP | I2C_EXTEND;
1248c2ecf20Sopenharmony_ci		else if (joined_rlen)
1258c2ecf20Sopenharmony_ci			ctrl |= I2C_NOSTOP;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci		cx_write(bus->reg_addr, addr);
1288c2ecf20Sopenharmony_ci		cx_write(bus->reg_wdata, wdata);
1298c2ecf20Sopenharmony_ci		cx_write(bus->reg_ctrl, ctrl);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci		if (!i2c_wait_done(i2c_adap))
1328c2ecf20Sopenharmony_ci			goto eio;
1338c2ecf20Sopenharmony_ci		if (i2c_debug) {
1348c2ecf20Sopenharmony_ci			pr_cont(" %02x", msg->buf[cnt]);
1358c2ecf20Sopenharmony_ci			if (!(ctrl & I2C_NOSTOP))
1368c2ecf20Sopenharmony_ci				pr_cont(" >\n");
1378c2ecf20Sopenharmony_ci		}
1388c2ecf20Sopenharmony_ci	}
1398c2ecf20Sopenharmony_ci	return msg->len;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci eio:
1428c2ecf20Sopenharmony_ci	retval = -EIO;
1438c2ecf20Sopenharmony_ci	if (i2c_debug)
1448c2ecf20Sopenharmony_ci		pr_err(" ERR: %d\n", retval);
1458c2ecf20Sopenharmony_ci	return retval;
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic int i2c_readbytes(struct i2c_adapter *i2c_adap,
1498c2ecf20Sopenharmony_ci			 const struct i2c_msg *msg, int joined)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	struct cx23885_i2c *bus = i2c_adap->algo_data;
1528c2ecf20Sopenharmony_ci	struct cx23885_dev *dev = bus->dev;
1538c2ecf20Sopenharmony_ci	u32 ctrl, cnt;
1548c2ecf20Sopenharmony_ci	int retval;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	if (i2c_debug && !joined)
1588c2ecf20Sopenharmony_ci		dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	/* Deal with i2c probe functions with zero payload */
1618c2ecf20Sopenharmony_ci	if (msg->len == 0) {
1628c2ecf20Sopenharmony_ci		cx_write(bus->reg_addr, msg->addr << 25);
1638c2ecf20Sopenharmony_ci		cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2) | 1);
1648c2ecf20Sopenharmony_ci		if (!i2c_wait_done(i2c_adap))
1658c2ecf20Sopenharmony_ci			return -EIO;
1668c2ecf20Sopenharmony_ci		if (!i2c_slave_did_ack(i2c_adap))
1678c2ecf20Sopenharmony_ci			return -ENXIO;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci		dprintk(1, "%s() returns 0\n", __func__);
1718c2ecf20Sopenharmony_ci		return 0;
1728c2ecf20Sopenharmony_ci	}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	if (i2c_debug) {
1758c2ecf20Sopenharmony_ci		if (joined)
1768c2ecf20Sopenharmony_ci			dprintk(1, " R");
1778c2ecf20Sopenharmony_ci		else
1788c2ecf20Sopenharmony_ci			dprintk(1, " <R %02x", (msg->addr << 1) + 1);
1798c2ecf20Sopenharmony_ci	}
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < msg->len; cnt++) {
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci		ctrl = bus->i2c_period | (1 << 12) | (1 << 2) | 1;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci		if (cnt < msg->len - 1)
1868c2ecf20Sopenharmony_ci			ctrl |= I2C_NOSTOP | I2C_EXTEND;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci		cx_write(bus->reg_addr, msg->addr << 25);
1898c2ecf20Sopenharmony_ci		cx_write(bus->reg_ctrl, ctrl);
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci		if (!i2c_wait_done(i2c_adap))
1928c2ecf20Sopenharmony_ci			goto eio;
1938c2ecf20Sopenharmony_ci		msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff;
1948c2ecf20Sopenharmony_ci		if (i2c_debug) {
1958c2ecf20Sopenharmony_ci			dprintk(1, " %02x", msg->buf[cnt]);
1968c2ecf20Sopenharmony_ci			if (!(ctrl & I2C_NOSTOP))
1978c2ecf20Sopenharmony_ci				dprintk(1, " >\n");
1988c2ecf20Sopenharmony_ci		}
1998c2ecf20Sopenharmony_ci	}
2008c2ecf20Sopenharmony_ci	return msg->len;
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci eio:
2038c2ecf20Sopenharmony_ci	retval = -EIO;
2048c2ecf20Sopenharmony_ci	if (i2c_debug)
2058c2ecf20Sopenharmony_ci		pr_err(" ERR: %d\n", retval);
2068c2ecf20Sopenharmony_ci	return retval;
2078c2ecf20Sopenharmony_ci}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistatic int i2c_xfer(struct i2c_adapter *i2c_adap,
2108c2ecf20Sopenharmony_ci		    struct i2c_msg *msgs, int num)
2118c2ecf20Sopenharmony_ci{
2128c2ecf20Sopenharmony_ci	int i, retval = 0;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	dprintk(1, "%s(num = %d)\n", __func__, num);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	for (i = 0 ; i < num; i++) {
2178c2ecf20Sopenharmony_ci		dprintk(1, "%s(num = %d) addr = 0x%02x  len = 0x%x\n",
2188c2ecf20Sopenharmony_ci			__func__, num, msgs[i].addr, msgs[i].len);
2198c2ecf20Sopenharmony_ci		if (msgs[i].flags & I2C_M_RD) {
2208c2ecf20Sopenharmony_ci			/* read */
2218c2ecf20Sopenharmony_ci			retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
2228c2ecf20Sopenharmony_ci		} else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
2238c2ecf20Sopenharmony_ci			   msgs[i].addr == msgs[i + 1].addr) {
2248c2ecf20Sopenharmony_ci			/* write then read from same address */
2258c2ecf20Sopenharmony_ci			retval = i2c_sendbytes(i2c_adap, &msgs[i],
2268c2ecf20Sopenharmony_ci					       msgs[i + 1].len);
2278c2ecf20Sopenharmony_ci			if (retval < 0)
2288c2ecf20Sopenharmony_ci				goto err;
2298c2ecf20Sopenharmony_ci			i++;
2308c2ecf20Sopenharmony_ci			retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
2318c2ecf20Sopenharmony_ci		} else {
2328c2ecf20Sopenharmony_ci			/* write */
2338c2ecf20Sopenharmony_ci			retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
2348c2ecf20Sopenharmony_ci		}
2358c2ecf20Sopenharmony_ci		if (retval < 0)
2368c2ecf20Sopenharmony_ci			goto err;
2378c2ecf20Sopenharmony_ci	}
2388c2ecf20Sopenharmony_ci	return num;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci err:
2418c2ecf20Sopenharmony_ci	return retval;
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistatic u32 cx23885_functionality(struct i2c_adapter *adap)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic const struct i2c_algorithm cx23885_i2c_algo_template = {
2508c2ecf20Sopenharmony_ci	.master_xfer	= i2c_xfer,
2518c2ecf20Sopenharmony_ci	.functionality	= cx23885_functionality,
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------- */
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_cistatic const struct i2c_adapter cx23885_i2c_adap_template = {
2578c2ecf20Sopenharmony_ci	.name              = "cx23885",
2588c2ecf20Sopenharmony_ci	.owner             = THIS_MODULE,
2598c2ecf20Sopenharmony_ci	.algo              = &cx23885_i2c_algo_template,
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic const struct i2c_client cx23885_i2c_client_template = {
2638c2ecf20Sopenharmony_ci	.name	= "cx23885 internal",
2648c2ecf20Sopenharmony_ci};
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistatic char *i2c_devs[128] = {
2678c2ecf20Sopenharmony_ci	[0x10 >> 1] = "tda10048",
2688c2ecf20Sopenharmony_ci	[0x12 >> 1] = "dib7000pc",
2698c2ecf20Sopenharmony_ci	[0x1c >> 1] = "lgdt3303",
2708c2ecf20Sopenharmony_ci	[0x80 >> 1] = "cs3308",
2718c2ecf20Sopenharmony_ci	[0x82 >> 1] = "cs3308",
2728c2ecf20Sopenharmony_ci	[0x86 >> 1] = "tda9887",
2738c2ecf20Sopenharmony_ci	[0x32 >> 1] = "cx24227",
2748c2ecf20Sopenharmony_ci	[0x88 >> 1] = "cx25837",
2758c2ecf20Sopenharmony_ci	[0x84 >> 1] = "tda8295",
2768c2ecf20Sopenharmony_ci	[0x98 >> 1] = "flatiron",
2778c2ecf20Sopenharmony_ci	[0xa0 >> 1] = "eeprom",
2788c2ecf20Sopenharmony_ci	[0xc0 >> 1] = "tuner/mt2131/tda8275",
2798c2ecf20Sopenharmony_ci	[0xc2 >> 1] = "tuner/mt2131/tda8275/xc5000/xc3028",
2808c2ecf20Sopenharmony_ci	[0xc8 >> 1] = "tuner/xc3028L",
2818c2ecf20Sopenharmony_ci};
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_cistatic void do_i2c_scan(char *name, struct i2c_client *c)
2848c2ecf20Sopenharmony_ci{
2858c2ecf20Sopenharmony_ci	unsigned char buf;
2868c2ecf20Sopenharmony_ci	int i, rc;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	for (i = 0; i < 128; i++) {
2898c2ecf20Sopenharmony_ci		c->addr = i;
2908c2ecf20Sopenharmony_ci		rc = i2c_master_recv(c, &buf, 0);
2918c2ecf20Sopenharmony_ci		if (rc < 0)
2928c2ecf20Sopenharmony_ci			continue;
2938c2ecf20Sopenharmony_ci		pr_info("%s: i2c scan: found device @ 0x%04x  [%s]\n",
2948c2ecf20Sopenharmony_ci		       name, i, i2c_devs[i] ? i2c_devs[i] : "???");
2958c2ecf20Sopenharmony_ci	}
2968c2ecf20Sopenharmony_ci}
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci/* init + register i2c adapter */
2998c2ecf20Sopenharmony_ciint cx23885_i2c_register(struct cx23885_i2c *bus)
3008c2ecf20Sopenharmony_ci{
3018c2ecf20Sopenharmony_ci	struct cx23885_dev *dev = bus->dev;
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	dprintk(1, "%s(bus = %d)\n", __func__, bus->nr);
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	bus->i2c_adap = cx23885_i2c_adap_template;
3068c2ecf20Sopenharmony_ci	bus->i2c_client = cx23885_i2c_client_template;
3078c2ecf20Sopenharmony_ci	bus->i2c_adap.dev.parent = &dev->pci->dev;
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci	strscpy(bus->i2c_adap.name, bus->dev->name,
3108c2ecf20Sopenharmony_ci		sizeof(bus->i2c_adap.name));
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	bus->i2c_adap.algo_data = bus;
3138c2ecf20Sopenharmony_ci	i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
3148c2ecf20Sopenharmony_ci	i2c_add_adapter(&bus->i2c_adap);
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	bus->i2c_client.adapter = &bus->i2c_adap;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	if (0 == bus->i2c_rc) {
3198c2ecf20Sopenharmony_ci		dprintk(1, "%s: i2c bus %d registered\n", dev->name, bus->nr);
3208c2ecf20Sopenharmony_ci		if (i2c_scan) {
3218c2ecf20Sopenharmony_ci			pr_info("%s: scan bus %d:\n",
3228c2ecf20Sopenharmony_ci					dev->name, bus->nr);
3238c2ecf20Sopenharmony_ci			do_i2c_scan(dev->name, &bus->i2c_client);
3248c2ecf20Sopenharmony_ci		}
3258c2ecf20Sopenharmony_ci	} else
3268c2ecf20Sopenharmony_ci		pr_warn("%s: i2c bus %d register FAILED\n",
3278c2ecf20Sopenharmony_ci			dev->name, bus->nr);
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	/* Instantiate the IR receiver device, if present */
3308c2ecf20Sopenharmony_ci	if (0 == bus->i2c_rc) {
3318c2ecf20Sopenharmony_ci		struct i2c_board_info info;
3328c2ecf20Sopenharmony_ci		static const unsigned short addr_list[] = {
3338c2ecf20Sopenharmony_ci			0x6b, I2C_CLIENT_END
3348c2ecf20Sopenharmony_ci		};
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci		memset(&info, 0, sizeof(struct i2c_board_info));
3378c2ecf20Sopenharmony_ci		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
3388c2ecf20Sopenharmony_ci		/* Use quick read command for probe, some IR chips don't
3398c2ecf20Sopenharmony_ci		 * support writes */
3408c2ecf20Sopenharmony_ci		i2c_new_scanned_device(&bus->i2c_adap, &info, addr_list,
3418c2ecf20Sopenharmony_ci				       i2c_probe_func_quick_read);
3428c2ecf20Sopenharmony_ci	}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	return bus->i2c_rc;
3458c2ecf20Sopenharmony_ci}
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ciint cx23885_i2c_unregister(struct cx23885_i2c *bus)
3488c2ecf20Sopenharmony_ci{
3498c2ecf20Sopenharmony_ci	i2c_del_adapter(&bus->i2c_adap);
3508c2ecf20Sopenharmony_ci	return 0;
3518c2ecf20Sopenharmony_ci}
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_civoid cx23885_av_clk(struct cx23885_dev *dev, int enable)
3548c2ecf20Sopenharmony_ci{
3558c2ecf20Sopenharmony_ci	/* write 0 to bus 2 addr 0x144 via i2x_xfer() */
3568c2ecf20Sopenharmony_ci	char buffer[3];
3578c2ecf20Sopenharmony_ci	struct i2c_msg msg;
3588c2ecf20Sopenharmony_ci	dprintk(1, "%s(enabled = %d)\n", __func__, enable);
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	/* Register 0x144 */
3618c2ecf20Sopenharmony_ci	buffer[0] = 0x01;
3628c2ecf20Sopenharmony_ci	buffer[1] = 0x44;
3638c2ecf20Sopenharmony_ci	if (enable == 1)
3648c2ecf20Sopenharmony_ci		buffer[2] = 0x05;
3658c2ecf20Sopenharmony_ci	else
3668c2ecf20Sopenharmony_ci		buffer[2] = 0x00;
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	msg.addr = 0x44;
3698c2ecf20Sopenharmony_ci	msg.flags = I2C_M_TEN;
3708c2ecf20Sopenharmony_ci	msg.len = 3;
3718c2ecf20Sopenharmony_ci	msg.buf = buffer;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	i2c_xfer(&dev->i2c_bus[2].i2c_adap, &msg, 1);
3748c2ecf20Sopenharmony_ci}
375