Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * STK1160 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2012 Ezequiel Garcia
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * <elezegarcia--a.t--gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Based on Easycap driver by R.M. Thomas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	Copyright (C) 2010 R.M. Thomas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	<rmthomas--a.t--sciolus.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "stk1160.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "stk1160-reg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static unsigned int i2c_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) module_param(i2c_debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define dprintk_i2c(fmt, args...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (i2c_debug)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		printk(KERN_DEBUG fmt, ##args);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int stk1160_i2c_busy_wait(struct stk1160 *dev, u8 wait_bit_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned long end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u8 flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	/* Wait until read/write finish bit is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	end = jiffies + msecs_to_jiffies(STK1160_I2C_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	while (time_is_after_jiffies(end)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		stk1160_read_reg(dev, STK1160_SICTL+1, &flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		/* read/write done? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		if (flag & wait_bit_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		usleep_range(10 * USEC_PER_MSEC, 20 * USEC_PER_MSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int stk1160_i2c_write_reg(struct stk1160 *dev, u8 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		u8 reg, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/* Set serial device address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	rc = stk1160_write_reg(dev, STK1160_SICTL_SDA, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* Set i2c device register sub-address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	rc = stk1160_write_reg(dev, STK1160_SBUSW_WA, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/* Set i2c device register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	rc = stk1160_write_reg(dev, STK1160_SBUSW_WD, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* Start write now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	rc = stk1160_write_reg(dev, STK1160_SICTL, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	rc = stk1160_i2c_busy_wait(dev, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static int stk1160_i2c_read_reg(struct stk1160 *dev, u8 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		u8 reg, u8 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/* Set serial device address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	rc = stk1160_write_reg(dev, STK1160_SICTL_SDA, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Set i2c device register sub-address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	rc = stk1160_write_reg(dev, STK1160_SBUSR_RA, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* Start read now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	rc = stk1160_write_reg(dev, STK1160_SICTL, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	rc = stk1160_i2c_busy_wait(dev, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	rc = stk1160_read_reg(dev, STK1160_SBUSR_RD, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * stk1160_i2c_check_for_device()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * check if there is a i2c_device at the supplied address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int stk1160_i2c_check_for_device(struct stk1160 *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		unsigned char addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/* Set serial device address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	rc = stk1160_write_reg(dev, STK1160_SICTL_SDA, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* Set device sub-address, we'll chip version reg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	rc = stk1160_write_reg(dev, STK1160_SBUSR_RA, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* Start read now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	rc = stk1160_write_reg(dev, STK1160_SICTL, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	rc = stk1160_i2c_busy_wait(dev, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * stk1160_i2c_xfer()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * the main i2c transfer function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int stk1160_i2c_xfer(struct i2c_adapter *i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			   struct i2c_msg msgs[], int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct stk1160 *dev = i2c_adap->algo_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int addr, rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		addr = msgs[i].addr << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		dprintk_i2c("%s: addr=%x", __func__, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (!msgs[i].len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			/* no len: check only for device presence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			rc = stk1160_i2c_check_for_device(dev, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				dprintk_i2c(" no device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		} else if (msgs[i].flags & I2C_M_RD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			/* read request without preceding register selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			dprintk_i2c(" subaddr not selected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		} else if (i + 1 < num && msgs[i].len <= 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			   (msgs[i + 1].flags & I2C_M_RD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			   msgs[i].addr == msgs[i + 1].addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			if (msgs[i].len != 1 || msgs[i + 1].len != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				dprintk_i2c(" len not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			dprintk_i2c(" subaddr=%x", msgs[i].buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			rc = stk1160_i2c_read_reg(dev, addr, msgs[i].buf[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				msgs[i + 1].buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			dprintk_i2c(" read=%x", *msgs[i + 1].buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			/* consumed two msgs, so we skip one of them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			if (msgs[i].len != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				dprintk_i2c(" len not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			dprintk_i2c(" subaddr=%x write=%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				msgs[i].buf[0],  msgs[i].buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			rc = stk1160_i2c_write_reg(dev, addr, msgs[i].buf[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				msgs[i].buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		dprintk_i2c(" OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	dprintk_i2c(" ERROR: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * functionality(), what da heck is this?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static u32 functionality(struct i2c_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return I2C_FUNC_SMBUS_EMUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static const struct i2c_algorithm algo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	.master_xfer   = stk1160_i2c_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	.functionality = functionality,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static const struct i2c_adapter adap_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	.name = "stk1160",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	.algo = &algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static const struct i2c_client client_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.name = "stk1160 internal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * stk1160_i2c_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * register i2c bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int stk1160_i2c_register(struct stk1160 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	dev->i2c_adap = adap_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	dev->i2c_adap.dev.parent = dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	strscpy(dev->i2c_adap.name, "stk1160", sizeof(dev->i2c_adap.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	dev->i2c_adap.algo_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	rc = i2c_add_adapter(&dev->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		stk1160_err("cannot add i2c adapter (%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	dev->i2c_client = client_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	dev->i2c_client.adapter = &dev->i2c_adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	/* Set i2c clock divider device address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	stk1160_write_reg(dev, STK1160_SICTL_CD,  0x0f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	stk1160_write_reg(dev, STK1160_ASIC + 3,  0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * stk1160_i2c_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * unregister i2c_bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int stk1160_i2c_unregister(struct stk1160 *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	i2c_del_adapter(&dev->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }