#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/errno.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
enum i2c_mode { … };
enum i2c_state_ind { … };
enum i2c_oper { … };
enum i2c_bank { … };
enum i2c_state { … };
#if IS_ENABLED(CONFIG_I2C_SLAVE)
enum i2c_addr { … };
#endif
#define NPCM_I2CSEGCTL …
#define NPCM_I2CSDA …
#define NPCM_I2CST …
#define NPCM_I2CCST …
#define NPCM_I2CCTL1 …
#define NPCM_I2CADDR1 …
#define NPCM_I2CCTL2 …
#define NPCM_I2CADDR2 …
#define NPCM_I2CCTL3 …
#define NPCM_I2CCST2 …
#define NPCM_I2CCST3 …
#define I2C_VER …
#define NPCM_I2CADDR3 …
#define NPCM_I2CADDR7 …
#define NPCM_I2CADDR4 …
#define NPCM_I2CADDR8 …
#define NPCM_I2CADDR5 …
#define NPCM_I2CADDR9 …
#define NPCM_I2CADDR6 …
#define NPCM_I2CADDR10 …
#define NPCM_I2CCTL4 …
#define NPCM_I2CCTL5 …
#define NPCM_I2CSCLLT …
#define NPCM_I2CFIF_CTL …
#define NPCM_I2CSCLHT …
#define NPCM_I2CFIF_CTS …
#define NPCM_I2CTXF_CTL …
#define NPCM_I2CT_OUT …
#define NPCM_I2CPEC …
#define NPCM_I2CTXF_STS …
#define NPCM_I2CRXF_STS …
#define NPCM_I2CRXF_CTL …
#if IS_ENABLED(CONFIG_I2C_SLAVE)
#define I2C_NUM_OWN_ADDR …
#define I2C_NUM_OWN_ADDR_SUPPORTED …
static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = …;
#endif
#define NPCM_I2CST_XMIT …
#define NPCM_I2CST_MASTER …
#define NPCM_I2CST_NMATCH …
#define NPCM_I2CST_STASTR …
#define NPCM_I2CST_NEGACK …
#define NPCM_I2CST_BER …
#define NPCM_I2CST_SDAST …
#define NPCM_I2CST_SLVSTP …
#define NPCM_I2CCST_BUSY …
#define NPCM_I2CCST_BB …
#define NPCM_I2CCST_MATCH …
#define NPCM_I2CCST_GCMATCH …
#define NPCM_I2CCST_TSDA …
#define NPCM_I2CCST_TGSCL …
#define NPCM_I2CCST_MATCHAF …
#define NPCM_I2CCST_ARPMATCH …
#define NPCM_I2CCTL1_START …
#define NPCM_I2CCTL1_STOP …
#define NPCM_I2CCTL1_INTEN …
#define NPCM_I2CCTL1_EOBINTE …
#define NPCM_I2CCTL1_ACK …
#define NPCM_I2CCTL1_GCMEN …
#define NPCM_I2CCTL1_NMINTE …
#define NPCM_I2CCTL1_STASTRE …
#define NPCM_I2CCTL1_RWS …
#define NPCM_I2CADDR_A …
#define NPCM_I2CADDR_SAEN …
#define I2CCTL2_ENABLE …
#define I2CCTL2_SCLFRQ6_0 …
#define I2CCTL3_SCLFRQ8_7 …
#define I2CCTL3_ARPMEN …
#define I2CCTL3_IDL_START …
#define I2CCTL3_400K_MODE …
#define I2CCTL3_BNK_SEL …
#define I2CCTL3_SDA_LVL …
#define I2CCTL3_SCL_LVL …
#define NPCM_I2CCST2_MATCHA1F …
#define NPCM_I2CCST2_MATCHA2F …
#define NPCM_I2CCST2_MATCHA3F …
#define NPCM_I2CCST2_MATCHA4F …
#define NPCM_I2CCST2_MATCHA5F …
#define NPCM_I2CCST2_MATCHA6F …
#define NPCM_I2CCST2_MATCHA7F …
#define NPCM_I2CCST2_INTSTS …
#define NPCM_I2CCST3_MATCHA8F …
#define NPCM_I2CCST3_MATCHA9F …
#define NPCM_I2CCST3_MATCHA10F …
#define NPCM_I2CCST3_EO_BUSY …
#define I2CCTL4_HLDT …
#define I2CCTL4_LVL_WE …
#define I2CCTL5_DBNCT …
#define NPCM_I2CFIF_CTS_RXF_TXE …
#define NPCM_I2CFIF_CTS_RFTE_IE …
#define NPCM_I2CFIF_CTS_CLR_FIFO …
#define NPCM_I2CFIF_CTS_SLVRSTR …
#define NPCM_I2CTXF_CTL_THR_TXIE …
#define NPCM_I2CT_OUT_TO_CKDIV …
#define NPCM_I2CT_OUT_T_OUTIE …
#define NPCM_I2CT_OUT_T_OUTST …
#define NPCM_I2CTXF_STS_TX_THST …
#define NPCM_I2CRXF_STS_RX_THST …
#define NPCM_I2CFIF_CTL_FIFO_EN …
#define NPCM_I2CRXF_CTL_THR_RXIE …
#define MAX_I2C_HW_FIFO_SIZE …
#define I2C_VER_VERSION …
#define I2C_VER_FIFO_EN …
#define DEFAULT_STALL_COUNT …
#define SCLFRQ_0_TO_6 …
#define SCLFRQ_7_TO_8 …
#define I2C_FREQ_MIN_HZ …
#define I2C_FREQ_MAX_HZ …
struct npcm_i2c_data { … };
static const struct npcm_i2c_data npxm7xx_i2c_data = …;
static const struct npcm_i2c_data npxm8xx_i2c_data = …;
struct npcm_i2c { … };
static inline void npcm_i2c_select_bank(struct npcm_i2c *bus,
enum i2c_bank bank)
{ … }
static void npcm_i2c_init_params(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_wr_byte(struct npcm_i2c *bus, u8 data)
{ … }
static inline u8 npcm_i2c_rd_byte(struct npcm_i2c *bus)
{ … }
static int npcm_i2c_get_SCL(struct i2c_adapter *_adap)
{ … }
static int npcm_i2c_get_SDA(struct i2c_adapter *_adap)
{ … }
static inline u16 npcm_i2c_get_index(struct npcm_i2c *bus)
{ … }
static inline bool npcm_i2c_is_quick(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_disable(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_enable(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_eob_int(struct npcm_i2c *bus, bool enable)
{ … }
static inline bool npcm_i2c_tx_fifo_empty(struct npcm_i2c *bus)
{ … }
static inline bool npcm_i2c_rx_fifo_full(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_clear_fifo_int(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_clear_tx_fifo(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_clear_rx_fifo(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_int_enable(struct npcm_i2c *bus, bool enable)
{ … }
static inline void npcm_i2c_master_start(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_master_stop(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_stall_after_start(struct npcm_i2c *bus, bool stall)
{ … }
static inline void npcm_i2c_nack(struct npcm_i2c *bus)
{ … }
static inline void npcm_i2c_clear_master_status(struct npcm_i2c *bus)
{ … }
#if IS_ENABLED(CONFIG_I2C_SLAVE)
static void npcm_i2c_slave_int_enable(struct npcm_i2c *bus, bool enable)
{ … }
static int npcm_i2c_slave_enable(struct npcm_i2c *bus, enum i2c_addr addr_type,
u8 addr, bool enable)
{ … }
#endif
static void npcm_i2c_reset(struct npcm_i2c *bus)
{ … }
static inline bool npcm_i2c_is_master(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_callback(struct npcm_i2c *bus,
enum i2c_state_ind op_status, u16 info)
{ … }
static u8 npcm_i2c_fifo_usage(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_write_to_fifo_master(struct npcm_i2c *bus, u16 max_bytes)
{ … }
static void npcm_i2c_set_fifo(struct npcm_i2c *bus, int nread, int nwrite)
{ … }
static void npcm_i2c_read_fifo(struct npcm_i2c *bus, u8 bytes_in_fifo)
{ … }
static void npcm_i2c_master_abort(struct npcm_i2c *bus)
{ … }
#if IS_ENABLED(CONFIG_I2C_SLAVE)
static u8 npcm_i2c_get_slave_addr(struct npcm_i2c *bus, enum i2c_addr addr_type)
{ … }
static int npcm_i2c_remove_slave_addr(struct npcm_i2c *bus, u8 slave_add)
{ … }
static void npcm_i2c_write_fifo_slave(struct npcm_i2c *bus, u16 max_bytes)
{ … }
static void npcm_i2c_read_fifo_slave(struct npcm_i2c *bus, u8 bytes_in_fifo)
{ … }
static int npcm_i2c_slave_get_wr_buf(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_slave_send_rd_buf(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_slave_receive(struct npcm_i2c *bus, u16 nread,
u8 *read_data)
{ … }
static void npcm_i2c_slave_xmit(struct npcm_i2c *bus, u16 nwrite,
u8 *write_data)
{ … }
static void npcm_i2c_slave_wr_buf_sync(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_slave_rd_wr(struct npcm_i2c *bus)
{ … }
static irqreturn_t npcm_i2c_int_slave_handler(struct npcm_i2c *bus)
{ … }
static int npcm_i2c_reg_slave(struct i2c_client *client)
{ … }
static int npcm_i2c_unreg_slave(struct i2c_client *client)
{ … }
#endif
static void npcm_i2c_master_fifo_read(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_master_handler_write(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_master_handler_read(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_handle_nmatch(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_handle_nack(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_handle_ber(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_handle_eob(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_handle_stall_after_start(struct npcm_i2c *bus)
{ … }
static void npcm_i2c_irq_handle_sda(struct npcm_i2c *bus, u8 i2cst)
{ … }
static int npcm_i2c_int_master_handler(struct npcm_i2c *bus)
{ … }
static int npcm_i2c_recovery_tgclk(struct i2c_adapter *_adap)
{ … }
static void npcm_i2c_recovery_init(struct i2c_adapter *_adap)
{ … }
#define SCLFRQ_MIN …
#define SCLFRQ_MAX …
#define clk_coef(freq, mul) …
static int npcm_i2c_init_clk(struct npcm_i2c *bus, u32 bus_freq_hz)
{ … }
static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
u32 bus_freq_hz)
{ … }
static int __npcm_i2c_init(struct npcm_i2c *bus, struct platform_device *pdev)
{ … }
static irqreturn_t npcm_i2c_bus_irq(int irq, void *dev_id)
{ … }
static bool npcm_i2c_master_start_xmit(struct npcm_i2c *bus,
u8 slave_addr, u16 nwrite, u16 nread,
u8 *write_data, u8 *read_data,
bool use_PEC, bool use_read_block)
{ … }
static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
int num)
{ … }
static u32 npcm_i2c_functionality(struct i2c_adapter *adap)
{ … }
static const struct i2c_adapter_quirks npcm_i2c_quirks = …;
static const struct i2c_algorithm npcm_i2c_algo = …;
static void npcm_i2c_init_debugfs(struct platform_device *pdev,
struct npcm_i2c *bus)
{ … }
static int npcm_i2c_probe_bus(struct platform_device *pdev)
{ … }
static void npcm_i2c_remove_bus(struct platform_device *pdev)
{ … }
static const struct of_device_id npcm_i2c_bus_of_table[] = …;
MODULE_DEVICE_TABLE(of, npcm_i2c_bus_of_table);
static struct platform_driver npcm_i2c_bus_driver = …;
module_platform_driver(…) …;
MODULE_AUTHOR(…) …;
MODULE_AUTHOR(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;