mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 17:08:10 +00:00
a06b80e830
Add Zhaoxin I2C controller driver. It provides the access to the i2c busses, which connects to the touchpad, eeprom, I2S, etc. Zhaoxin I2C controller has two separate busses, so may accommodate up to two I2C adapters. Those adapters are listed in the ACPI namespace with the IIC1D17 HID, and probed by a platform driver. The driver works with IRQ mode, and supports basic I2C features. Flags I2C_AQ_NO_ZERO_LEN and I2C_AQ_COMB_WRITE_THEN_READ are used to limit the unsupported access. Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
85 lines
2 KiB
C
85 lines
2 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
#ifndef __I2C_VIAI2C_COMMON_H_
|
|
#define __I2C_VIAI2C_COMMON_H_
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/err.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of_irq.h>
|
|
#include <linux/platform_device.h>
|
|
|
|
/* REG_CR Bit fields */
|
|
#define VIAI2C_REG_CR 0x00
|
|
#define VIAI2C_CR_ENABLE BIT(0)
|
|
#define VIAI2C_CR_RX_END BIT(1)
|
|
#define VIAI2C_CR_TX_END BIT(2)
|
|
#define VIAI2C_CR_CPU_RDY BIT(3)
|
|
#define VIAI2C_CR_END_MASK GENMASK(2, 1)
|
|
|
|
/* REG_TCR Bit fields */
|
|
#define VIAI2C_REG_TCR 0x02
|
|
#define VIAI2C_TCR_HS_MODE BIT(13)
|
|
#define VIAI2C_TCR_READ BIT(14)
|
|
#define VIAI2C_TCR_FAST BIT(15)
|
|
#define VIAI2C_TCR_ADDR_MASK GENMASK(6, 0)
|
|
|
|
/* REG_CSR Bit fields */
|
|
#define VIAI2C_REG_CSR 0x04
|
|
#define VIAI2C_CSR_RCV_NOT_ACK BIT(0)
|
|
#define VIAI2C_CSR_RCV_ACK_MASK BIT(0)
|
|
#define VIAI2C_CSR_READY_MASK BIT(1)
|
|
|
|
/* REG_ISR Bit fields */
|
|
#define VIAI2C_REG_ISR 0x06
|
|
#define VIAI2C_ISR_NACK_ADDR BIT(0)
|
|
#define VIAI2C_ISR_BYTE_END BIT(1)
|
|
#define VIAI2C_ISR_SCL_TIMEOUT BIT(2)
|
|
#define VIAI2C_ISR_MASK_ALL GENMASK(2, 0)
|
|
|
|
/* REG_IMR Bit fields */
|
|
#define VIAI2C_REG_IMR 0x08
|
|
#define VIAI2C_IMR_BYTE BIT(1)
|
|
#define VIAI2C_IMR_ENABLE_ALL GENMASK(2, 0)
|
|
|
|
#define VIAI2C_REG_CDR 0x0A
|
|
#define VIAI2C_REG_TR 0x0C
|
|
#define VIAI2C_REG_MCR 0x0E
|
|
|
|
#define VIAI2C_TIMEOUT (msecs_to_jiffies(1000))
|
|
|
|
enum {
|
|
VIAI2C_PLAT_WMT,
|
|
VIAI2C_PLAT_ZHAOXIN
|
|
};
|
|
|
|
enum {
|
|
VIAI2C_BYTE_MODE,
|
|
VIAI2C_FIFO_MODE
|
|
};
|
|
|
|
struct viai2c {
|
|
struct i2c_adapter adapter;
|
|
struct completion complete;
|
|
struct device *dev;
|
|
void __iomem *base;
|
|
struct clk *clk;
|
|
u16 tcr;
|
|
int irq;
|
|
u16 xfered_len;
|
|
struct i2c_msg *msg;
|
|
int ret;
|
|
bool last;
|
|
unsigned int mode;
|
|
unsigned int platform;
|
|
void *pltfm_priv;
|
|
};
|
|
|
|
int viai2c_wait_bus_not_busy(struct viai2c *i2c);
|
|
int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num);
|
|
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat);
|
|
int viai2c_fifo_irq_xfer(struct viai2c *i2c, bool irq);
|
|
|
|
#endif
|