linux/drivers/i2c/busses/i2c-mt65xx.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2014 MediaTek Inc.
 * Author: Xudong Chen <[email protected]>
 */

#include <linux/clk.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include <linux/sched.h>
#include <linux/slab.h>

#define I2C_RS_TRANSFER
#define I2C_ARB_LOST
#define I2C_HS_NACKERR
#define I2C_ACKERR
#define I2C_TRANSAC_COMP
#define I2C_TRANSAC_START
#define I2C_RS_MUL_CNFG
#define I2C_RS_MUL_TRIG
#define I2C_DCM_DISABLE
#define I2C_IO_CONFIG_OPEN_DRAIN
#define I2C_IO_CONFIG_PUSH_PULL
#define I2C_SOFT_RST
#define I2C_HANDSHAKE_RST
#define I2C_FIFO_ADDR_CLR
#define I2C_DELAY_LEN
#define I2C_ST_START_CON
#define I2C_FS_START_CON
#define I2C_TIME_CLR_VALUE
#define I2C_TIME_DEFAULT_VALUE
#define I2C_WRRD_TRANAC_VALUE
#define I2C_RD_TRANAC_VALUE
#define I2C_SCL_MIS_COMP_VALUE
#define I2C_CHN_CLR_FLAG
#define I2C_RELIABILITY
#define I2C_DMAACK_ENABLE

#define I2C_DMA_CON_TX
#define I2C_DMA_CON_RX
#define I2C_DMA_ASYNC_MODE
#define I2C_DMA_SKIP_CONFIG
#define I2C_DMA_DIR_CHANGE
#define I2C_DMA_START_EN
#define I2C_DMA_INT_FLAG_NONE
#define I2C_DMA_CLR_FLAG
#define I2C_DMA_WARM_RST
#define I2C_DMA_HARD_RST
#define I2C_DMA_HANDSHAKE_RST

#define MAX_SAMPLE_CNT_DIV
#define MAX_STEP_CNT_DIV
#define MAX_CLOCK_DIV_8BITS
#define MAX_CLOCK_DIV_5BITS
#define MAX_HS_STEP_CNT_DIV
#define I2C_STANDARD_MODE_BUFFER
#define I2C_FAST_MODE_BUFFER
#define I2C_FAST_MODE_PLUS_BUFFER

#define I2C_CONTROL_RS
#define I2C_CONTROL_DMA_EN
#define I2C_CONTROL_CLK_EXT_EN
#define I2C_CONTROL_DIR_CHANGE
#define I2C_CONTROL_ACKERR_DET_EN
#define I2C_CONTROL_TRANSFER_LEN_CHANGE
#define I2C_CONTROL_DMAACK_EN
#define I2C_CONTROL_ASYNC_MODE
#define I2C_CONTROL_WRAPPER

#define I2C_DRV_NAME

/**
 * enum i2c_mt65xx_clks - Clocks enumeration for MT65XX I2C
 *
 * @I2C_MT65XX_CLK_MAIN: main clock for i2c bus
 * @I2C_MT65XX_CLK_DMA:  DMA clock for i2c via DMA
 * @I2C_MT65XX_CLK_PMIC: PMIC clock for i2c from PMIC
 * @I2C_MT65XX_CLK_ARB:  Arbitrator clock for i2c
 * @I2C_MT65XX_CLK_MAX:  Number of supported clocks
 */
enum i2c_mt65xx_clks {};

static const char * const i2c_mt65xx_clk_ids[I2C_MT65XX_CLK_MAX] =;

enum DMA_REGS_OFFSET {};

enum i2c_trans_st_rs {};

enum mtk_trans_op {};

enum I2C_REGS_OFFSET {};

static const u16 mt_i2c_regs_v1[] =;

static const u16 mt_i2c_regs_v2[] =;

static const u16 mt_i2c_regs_v3[] =;

struct mtk_i2c_compatible {};

struct mtk_i2c_ac_timing {};

struct mtk_i2c {};

/**
 * struct i2c_spec_values:
 * @min_low_ns: min LOW period of the SCL clock
 * @min_su_sta_ns: min set-up time for a repeated START condition
 * @max_hd_dat_ns: max data hold time
 * @min_su_dat_ns: min data set-up time
 */
struct i2c_spec_values {};

static const struct i2c_spec_values standard_mode_spec =;

static const struct i2c_spec_values fast_mode_spec =;

static const struct i2c_spec_values fast_mode_plus_spec =;

static const struct i2c_adapter_quirks mt6577_i2c_quirks =;

static const struct i2c_adapter_quirks mt7622_i2c_quirks =;

static const struct i2c_adapter_quirks mt8183_i2c_quirks =;

static const struct mtk_i2c_compatible mt2712_compat =;

static const struct mtk_i2c_compatible mt6577_compat =;

static const struct mtk_i2c_compatible mt6589_compat =;

static const struct mtk_i2c_compatible mt7622_compat =;

static const struct mtk_i2c_compatible mt8168_compat =;

static const struct mtk_i2c_compatible mt7981_compat =;

static const struct mtk_i2c_compatible mt7986_compat =;

static const struct mtk_i2c_compatible mt8173_compat =;

static const struct mtk_i2c_compatible mt8183_compat =;

static const struct mtk_i2c_compatible mt8186_compat =;

static const struct mtk_i2c_compatible mt8188_compat =;

static const struct mtk_i2c_compatible mt8192_compat =;

static const struct of_device_id mtk_i2c_of_match[] =;
MODULE_DEVICE_TABLE(of, mtk_i2c_of_match);

static u16 mtk_i2c_readw(struct mtk_i2c *i2c, enum I2C_REGS_OFFSET reg)
{}

static void mtk_i2c_writew(struct mtk_i2c *i2c, u16 val,
			   enum I2C_REGS_OFFSET reg)
{}

static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
{}

static const struct i2c_spec_values *mtk_i2c_get_spec(unsigned int speed)
{}

static int mtk_i2c_max_step_cnt(unsigned int target_speed)
{}

static int mtk_i2c_get_clk_div_restri(struct mtk_i2c *i2c,
				      unsigned int sample_cnt)
{}

/*
 * Check and Calculate i2c ac-timing
 *
 * Hardware design:
 * sample_ns = (1000000000 * (sample_cnt + 1)) / clk_src
 * xxx_cnt_div =  spec->min_xxx_ns / sample_ns
 *
 * Sample_ns is rounded down for xxx_cnt_div would be greater
 * than the smallest spec.
 * The sda_timing is chosen as the middle value between
 * the largest and smallest.
 */
static int mtk_i2c_check_ac_timing(struct mtk_i2c *i2c,
				   unsigned int clk_src,
				   unsigned int check_speed,
				   unsigned int step_cnt,
				   unsigned int sample_cnt)
{}

/*
 * Calculate i2c port speed
 *
 * Hardware design:
 * i2c_bus_freq = parent_clk / (clock_div * 2 * sample_cnt * step_cnt)
 * clock_div: fixed in hardware, but may be various in different SoCs
 *
 * The calculation want to pick the highest bus frequency that is still
 * less than or equal to i2c->speed_hz. The calculation try to get
 * sample_cnt and step_cn
 */
static int mtk_i2c_calculate_speed(struct mtk_i2c *i2c, unsigned int clk_src,
				   unsigned int target_speed,
				   unsigned int *timing_step_cnt,
				   unsigned int *timing_sample_cnt)
{}

static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
{}

static void i2c_dump_register(struct mtk_i2c *i2c)
{}

static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
			       int num, int left_num)
{}

static int mtk_i2c_transfer(struct i2c_adapter *adap,
			    struct i2c_msg msgs[], int num)
{}

static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id)
{}

static u32 mtk_i2c_functionality(struct i2c_adapter *adap)
{}

static const struct i2c_algorithm mtk_i2c_algorithm =;

static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
{}

static int mtk_i2c_probe(struct platform_device *pdev)
{}

static void mtk_i2c_remove(struct platform_device *pdev)
{}

static int mtk_i2c_suspend_noirq(struct device *dev)
{}

static int mtk_i2c_resume_noirq(struct device *dev)
{}

static const struct dev_pm_ops mtk_i2c_pm =;

static struct platform_driver mtk_i2c_driver =;

module_platform_driver();

MODULE_LICENSE();
MODULE_DESCRIPTION();
MODULE_AUTHOR();