#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/platform_data/i2c-pxa.h>
#include <linux/property.h>
#include <linux/slab.h>
#define IBMR_SDAS …
#define IBMR_SCLS …
#define ICR_START …
#define ICR_STOP …
#define ICR_ACKNAK …
#define ICR_TB …
#define ICR_MA …
#define ICR_SCLE …
#define ICR_IUE …
#define ICR_GCD …
#define ICR_ITEIE …
#define ICR_IRFIE …
#define ICR_BEIE …
#define ICR_SSDIE …
#define ICR_ALDIE …
#define ICR_SADIE …
#define ICR_UR …
#define ICR_FM …
#define ICR_HS …
#define ICR_A3700_FM …
#define ICR_A3700_HS …
#define ICR_GPIOEN …
#define ISR_RWM …
#define ISR_ACKNAK …
#define ISR_UB …
#define ISR_IBB …
#define ISR_SSD …
#define ISR_ALD …
#define ISR_ITE …
#define ISR_IRF …
#define ISR_GCAD …
#define ISR_SAD …
#define ISR_BED …
#define ILCR_SLV_SHIFT …
#define ILCR_SLV_MASK …
#define ILCR_FLV_SHIFT …
#define ILCR_FLV_MASK …
#define ILCR_HLVL_SHIFT …
#define ILCR_HLVL_MASK …
#define ILCR_HLVH_SHIFT …
#define ILCR_HLVH_MASK …
#define IWCR_CNT_SHIFT …
#define IWCR_CNT_MASK …
#define IWCR_HS_CNT1_SHIFT …
#define IWCR_HS_CNT1_MASK …
#define IWCR_HS_CNT2_SHIFT …
#define IWCR_HS_CNT2_MASK …
#define DEF_TIMEOUT …
#define NO_SLAVE …
#define BUS_ERROR …
#define XFER_NAKED …
#define I2C_RETRY …
#define I2C_ICR_INIT …
#define I2C_ISR_INIT …
struct pxa_reg_layout { … };
enum pxa_i2c_types { … };
static struct pxa_reg_layout pxa_reg_layout[] = …;
static const struct of_device_id i2c_pxa_dt_ids[] = …;
MODULE_DEVICE_TABLE(of, i2c_pxa_dt_ids);
static const struct platform_device_id i2c_pxa_id_table[] = …;
MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
struct pxa_i2c { … };
#define _IBMR(i2c) …
#define _IDBR(i2c) …
#define _ICR(i2c) …
#define _ISR(i2c) …
#define _ISAR(i2c) …
#define _ILCR(i2c) …
#define _IWCR(i2c) …
#define I2C_PXA_SLAVE_ADDR …
#ifdef DEBUG
struct bits { … };
#define PXA_BIT(m, s, u) …
static inline void
decode_bits(const char *prefix, const struct bits *bits, int num, u32 val)
{ … }
static const struct bits isr_bits[] = …;
static void decode_ISR(unsigned int val)
{ … }
#ifdef CONFIG_I2C_PXA_SLAVE
static const struct bits icr_bits[] = …;
static void decode_ICR(unsigned int val)
{ … }
#endif
static unsigned int i2c_debug = …;
static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
{ … }
#define show_state(i2c) …
static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
{ … }
#else
#define i2c_debug …
#define show_state …
#define decode_ISR …
#define decode_ICR …
#define i2c_pxa_scream_blue_murder …
#endif
static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
{ … }
static void i2c_pxa_abort(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_set_master(struct pxa_i2c *i2c)
{ … }
#ifdef CONFIG_I2C_PXA_SLAVE
static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
{ … }
static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
{ … }
#else
#define i2c_pxa_set_slave …
#endif
static void i2c_pxa_do_reset(struct pxa_i2c *i2c)
{ … }
static void i2c_pxa_enable(struct pxa_i2c *i2c)
{ … }
static void i2c_pxa_reset(struct pxa_i2c *i2c)
{ … }
#ifdef CONFIG_I2C_PXA_SLAVE
static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
{ … }
static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
{ … }
static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
{ … }
static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_slave_reg(struct i2c_client *slave)
{ … }
static int i2c_pxa_slave_unreg(struct i2c_client *slave)
{ … }
#else
static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
{
if (isr & ISR_BED) {
} else {
writel(0, _IDBR(i2c));
writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
}
}
static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
{
writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
}
static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
{
int timeout;
writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
timeout = 0x10000;
while (1) {
if ((readl(_IBMR(i2c)) & IBMR_SCLS) == IBMR_SCLS)
break;
timeout--;
if (timeout <= 0) {
dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
break;
}
}
writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
}
static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
{
if (i2c->msg)
i2c_pxa_master_complete(i2c, I2C_RETRY);
}
#endif
static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
{ … }
static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c)
{ … }
static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
{ … }
static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
{ … }
static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
{ … }
#define VALID_INT_SOURCE …
static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
{ … }
static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
{ … }
static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c,
struct i2c_msg *msgs, int num,
int (*xfer)(struct pxa_i2c *,
struct i2c_msg *, int num))
{ … }
static int i2c_pxa_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[], int num)
{ … }
static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
{ … }
static const struct i2c_algorithm i2c_pxa_algorithm = …;
static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
struct i2c_msg *msg, int num)
{ … }
static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[], int num)
{ … }
static const struct i2c_algorithm i2c_pxa_pio_algorithm = …;
static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
enum pxa_i2c_types *i2c_types)
{ … }
static int i2c_pxa_probe_pdata(struct platform_device *pdev,
struct pxa_i2c *i2c,
enum pxa_i2c_types *i2c_types)
{ … }
static void i2c_pxa_prepare_recovery(struct i2c_adapter *adap)
{ … }
static void i2c_pxa_unprepare_recovery(struct i2c_adapter *adap)
{ … }
static int i2c_pxa_init_recovery(struct pxa_i2c *i2c)
{ … }
static int i2c_pxa_probe(struct platform_device *dev)
{ … }
static void i2c_pxa_remove(struct platform_device *dev)
{ … }
static int i2c_pxa_suspend_noirq(struct device *dev)
{ … }
static int i2c_pxa_resume_noirq(struct device *dev)
{ … }
static const struct dev_pm_ops i2c_pxa_dev_pm_ops = …;
static struct platform_driver i2c_pxa_driver = …;
static int __init i2c_adap_pxa_init(void)
{ … }
static void __exit i2c_adap_pxa_exit(void)
{ … }
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
subsys_initcall(i2c_adap_pxa_init);
module_exit(i2c_adap_pxa_exit);