linux/drivers/media/pci/ivtv/ivtv-i2c.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
    I2C functions
    Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
    Copyright (C) 2005-2007  Hans Verkuil <[email protected]>

 */

/*
    This file includes an i2c implementation that was reverse engineered
    from the Hauppauge windows driver.  Older ivtv versions used i2c-algo-bit,
    which whilst fine under most circumstances, had trouble with the Zilog
    CPU on the PVR-150 which handles IR functions (occasional inability to
    communicate with the chip until it was reset) and also with the i2c
    bus being completely unreachable when multiple PVR cards were present.

    The implementation is very similar to i2c-algo-bit, but there are enough
    subtle differences that the two are hard to merge.  The general strategy
    employed by i2c-algo-bit is to use udelay() to implement the timing
    when putting out bits on the scl/sda lines.  The general strategy taken
    here is to poll the lines for state changes (see ivtv_waitscl and
    ivtv_waitsda).  In addition there are small delays at various locations
    which poll the SCL line 5 times (ivtv_scldelay).  I would guess that
    since this is memory mapped I/O that the length of those delays is tied
    to the PCI bus clock.  There is some extra code to do with recovery
    and retries.  Since it is not known what causes the actual i2c problems
    in the first place, the only goal if one was to attempt to use
    i2c-algo-bit would be to try to make it follow the same code path.
    This would be a lot of work, and I'm also not convinced that it would
    provide a generic benefit to i2c-algo-bit.  Therefore consider this
    an engineering solution -- not pretty, but it works.

    Some more general comments about what we are doing:

    The i2c bus is a 2 wire serial bus, with clock (SCL) and data (SDA)
    lines.  To communicate on the bus (as a master, we don't act as a slave),
    we first initiate a start condition (ivtv_start).  We then write the
    address of the device that we want to communicate with, along with a flag
    that indicates whether this is a read or a write.  The slave then issues
    an ACK signal (ivtv_ack), which tells us that it is ready for reading /
    writing.  We then proceed with reading or writing (ivtv_read/ivtv_write),
    and finally issue a stop condition (ivtv_stop) to make the bus available
    to other masters.

    There is an additional form of transaction where a write may be
    immediately followed by a read.  In this case, there is no intervening
    stop condition.  (Only the msp3400 chip uses this method of data transfer).
 */

#include "ivtv-driver.h"
#include "ivtv-cards.h"
#include "ivtv-gpio.h"
#include "ivtv-i2c.h"
#include <media/drv-intf/cx25840.h>

/* i2c implementation for cx23415/6 chip, ivtv project.
 * Author: Kevin Thayer (nufan_wfk at yahoo.com)
 */
/* i2c stuff */
#define IVTV_REG_I2C_SETSCL_OFFSET
#define IVTV_REG_I2C_SETSDA_OFFSET
#define IVTV_REG_I2C_GETSCL_OFFSET
#define IVTV_REG_I2C_GETSDA_OFFSET

#define IVTV_CS53L32A_I2C_ADDR
#define IVTV_M52790_I2C_ADDR
#define IVTV_CX25840_I2C_ADDR
#define IVTV_SAA7115_I2C_ADDR
#define IVTV_SAA7127_I2C_ADDR
#define IVTV_SAA717x_I2C_ADDR
#define IVTV_MSP3400_I2C_ADDR
#define IVTV_HAUPPAUGE_I2C_ADDR
#define IVTV_WM8739_I2C_ADDR
#define IVTV_WM8775_I2C_ADDR
#define IVTV_TEA5767_I2C_ADDR
#define IVTV_UPD64031A_I2C_ADDR
#define IVTV_UPD64083_I2C_ADDR
#define IVTV_VP27SMPX_I2C_ADDR
#define IVTV_M52790_I2C_ADDR
#define IVTV_AVERMEDIA_IR_RX_I2C_ADDR
#define IVTV_HAUP_EXT_IR_RX_I2C_ADDR
#define IVTV_HAUP_INT_IR_RX_I2C_ADDR
#define IVTV_Z8F0811_IR_TX_I2C_ADDR
#define IVTV_Z8F0811_IR_RX_I2C_ADDR
#define IVTV_ADAPTEC_IR_ADDR

/* This array should match the IVTV_HW_ defines */
static const u8 hw_addrs[IVTV_HW_MAX_BITS] =;

/* This array should match the IVTV_HW_ defines */
static const char * const hw_devicenames[IVTV_HW_MAX_BITS] =;

static int get_key_adaptec(struct IR_i2c *ir, enum rc_proto *protocol,
			   u32 *scancode, u8 *toggle)
{}

static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
{}

/* Instantiate the IR receiver device using probing -- undesirable */
void ivtv_i2c_new_ir_legacy(struct ivtv *itv)
{}

int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
{}

struct v4l2_subdev *ivtv_find_hw(struct ivtv *itv, u32 hw)
{}

/* Set the serial clock line to the desired state */
static void ivtv_setscl(struct ivtv *itv, int state)
{}

/* Set the serial data line to the desired state */
static void ivtv_setsda(struct ivtv *itv, int state)
{}

/* Read the serial clock line */
static int ivtv_getscl(struct ivtv *itv)
{}

/* Read the serial data line */
static int ivtv_getsda(struct ivtv *itv)
{}

/* Implement a short delay by polling the serial clock line */
static void ivtv_scldelay(struct ivtv *itv)
{}

/* Wait for the serial clock line to become set to a specific value */
static int ivtv_waitscl(struct ivtv *itv, int val)
{}

/* Wait for the serial data line to become set to a specific value */
static int ivtv_waitsda(struct ivtv *itv, int val)
{}

/* Wait for the slave to issue an ACK */
static int ivtv_ack(struct ivtv *itv)
{}

/* Write a single byte to the i2c bus and wait for the slave to ACK */
static int ivtv_sendbyte(struct ivtv *itv, unsigned char byte)
{}

/* Read a byte from the i2c bus and send a NACK if applicable (i.e. for the
   final byte) */
static int ivtv_readbyte(struct ivtv *itv, unsigned char *byte, int nack)
{}

/* Issue a start condition on the i2c bus to alert slaves to prepare for
   an address write */
static int ivtv_start(struct ivtv *itv)
{}

/* Issue a stop condition on the i2c bus to release it */
static int ivtv_stop(struct ivtv *itv)
{}

/* Write a message to the given i2c slave.  do_stop may be 0 to prevent
   issuing the i2c stop condition (when following with a read) */
static int ivtv_write(struct ivtv *itv, unsigned char addr, unsigned char *data, u32 len, int do_stop)
{}

/* Read data from the given i2c slave.  A stop condition is always issued. */
static int ivtv_read(struct ivtv *itv, unsigned char addr, unsigned char *data, u32 len)
{}

/* Kernel i2c transfer implementation.  Takes a number of messages to be read
   or written.  If a read follows a write, this will occur without an
   intervening stop condition */
static int ivtv_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
{}

/* Kernel i2c capabilities */
static u32 ivtv_functionality(struct i2c_adapter *adap)
{}

static const struct i2c_algorithm ivtv_algo =;

/* template for our-bit banger */
static const struct i2c_adapter ivtv_i2c_adap_hw_template =;

static void ivtv_setscl_old(void *data, int state)
{}

static void ivtv_setsda_old(void *data, int state)
{}

static int ivtv_getscl_old(void *data)
{}

static int ivtv_getsda_old(void *data)
{}

/* template for i2c-bit-algo */
static const struct i2c_adapter ivtv_i2c_adap_template =;

#define IVTV_ALGO_BIT_TIMEOUT

static const struct i2c_algo_bit_data ivtv_i2c_algo_template =;

static const struct i2c_client ivtv_i2c_client_template =;

/* init + register i2c adapter */
int init_ivtv_i2c(struct ivtv *itv)
{}

void exit_ivtv_i2c(struct ivtv *itv)
{}