11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2ce38815dSXudong Chen /* 3ce38815dSXudong Chen * Copyright (c) 2014 MediaTek Inc. 4ce38815dSXudong Chen * Author: Xudong Chen <xudong.chen@mediatek.com> 5ce38815dSXudong Chen */ 6ce38815dSXudong Chen 7ce38815dSXudong Chen #include <linux/clk.h> 8ce38815dSXudong Chen #include <linux/completion.h> 9ce38815dSXudong Chen #include <linux/delay.h> 10ce38815dSXudong Chen #include <linux/device.h> 11ce38815dSXudong Chen #include <linux/dma-mapping.h> 12ce38815dSXudong Chen #include <linux/err.h> 13ce38815dSXudong Chen #include <linux/errno.h> 14ce38815dSXudong Chen #include <linux/i2c.h> 15ce38815dSXudong Chen #include <linux/init.h> 16ce38815dSXudong Chen #include <linux/interrupt.h> 17ce38815dSXudong Chen #include <linux/io.h> 18ce38815dSXudong Chen #include <linux/kernel.h> 19ce38815dSXudong Chen #include <linux/mm.h> 20ce38815dSXudong Chen #include <linux/module.h> 21ce38815dSXudong Chen #include <linux/of_address.h> 226e29577fSRyder Lee #include <linux/of_device.h> 23ce38815dSXudong Chen #include <linux/of_irq.h> 24ce38815dSXudong Chen #include <linux/platform_device.h> 25ce38815dSXudong Chen #include <linux/scatterlist.h> 26ce38815dSXudong Chen #include <linux/sched.h> 27ce38815dSXudong Chen #include <linux/slab.h> 28ce38815dSXudong Chen 29b2ed11e2SEddie Huang #define I2C_RS_TRANSFER (1 << 4) 30cad6dc5dSQii Wang #define I2C_ARB_LOST (1 << 3) 31ce38815dSXudong Chen #define I2C_HS_NACKERR (1 << 2) 32ce38815dSXudong Chen #define I2C_ACKERR (1 << 1) 33ce38815dSXudong Chen #define I2C_TRANSAC_COMP (1 << 0) 34ce38815dSXudong Chen #define I2C_TRANSAC_START (1 << 0) 35b2ed11e2SEddie Huang #define I2C_RS_MUL_CNFG (1 << 15) 36b2ed11e2SEddie Huang #define I2C_RS_MUL_TRIG (1 << 14) 37ce38815dSXudong Chen #define I2C_DCM_DISABLE 0x0000 38ce38815dSXudong Chen #define I2C_IO_CONFIG_OPEN_DRAIN 0x0003 39ce38815dSXudong Chen #define I2C_IO_CONFIG_PUSH_PULL 0x0000 40ce38815dSXudong Chen #define I2C_SOFT_RST 0x0001 41ce38815dSXudong Chen #define I2C_FIFO_ADDR_CLR 0x0001 42ce38815dSXudong Chen #define I2C_DELAY_LEN 0x0002 43ce38815dSXudong Chen #define I2C_ST_START_CON 0x8001 44ce38815dSXudong Chen #define I2C_FS_START_CON 0x1800 45ce38815dSXudong Chen #define I2C_TIME_CLR_VALUE 0x0000 46ce38815dSXudong Chen #define I2C_TIME_DEFAULT_VALUE 0x0003 47ce38815dSXudong Chen #define I2C_WRRD_TRANAC_VALUE 0x0002 48ce38815dSXudong Chen #define I2C_RD_TRANAC_VALUE 0x0001 49ce38815dSXudong Chen 50ce38815dSXudong Chen #define I2C_DMA_CON_TX 0x0000 51ce38815dSXudong Chen #define I2C_DMA_CON_RX 0x0001 52ce38815dSXudong Chen #define I2C_DMA_START_EN 0x0001 53ce38815dSXudong Chen #define I2C_DMA_INT_FLAG_NONE 0x0000 54ce38815dSXudong Chen #define I2C_DMA_CLR_FLAG 0x0000 55ea89ef1fSEddie Huang #define I2C_DMA_HARD_RST 0x0002 56f4f4fed6SLiguo Zhang #define I2C_DMA_4G_MODE 0x0001 57ce38815dSXudong Chen 585a10e7d7SJun Gao #define I2C_DEFAULT_CLK_DIV 5 59ce38815dSXudong Chen #define MAX_SAMPLE_CNT_DIV 8 60ce38815dSXudong Chen #define MAX_STEP_CNT_DIV 64 61ce38815dSXudong Chen #define MAX_HS_STEP_CNT_DIV 8 62ce38815dSXudong Chen 63ce38815dSXudong Chen #define I2C_CONTROL_RS (0x1 << 1) 64ce38815dSXudong Chen #define I2C_CONTROL_DMA_EN (0x1 << 2) 65ce38815dSXudong Chen #define I2C_CONTROL_CLK_EXT_EN (0x1 << 3) 66ce38815dSXudong Chen #define I2C_CONTROL_DIR_CHANGE (0x1 << 4) 67ce38815dSXudong Chen #define I2C_CONTROL_ACKERR_DET_EN (0x1 << 5) 68ce38815dSXudong Chen #define I2C_CONTROL_TRANSFER_LEN_CHANGE (0x1 << 6) 69a15c91baSQii Wang #define I2C_CONTROL_DMAACK_EN (0x1 << 8) 70a15c91baSQii Wang #define I2C_CONTROL_ASYNC_MODE (0x1 << 9) 71ce38815dSXudong Chen #define I2C_CONTROL_WRAPPER (0x1 << 0) 72ce38815dSXudong Chen 73ce38815dSXudong Chen #define I2C_DRV_NAME "i2c-mt65xx" 74ce38815dSXudong Chen 75ce38815dSXudong Chen enum DMA_REGS_OFFSET { 76ce38815dSXudong Chen OFFSET_INT_FLAG = 0x0, 77ce38815dSXudong Chen OFFSET_INT_EN = 0x04, 78ce38815dSXudong Chen OFFSET_EN = 0x08, 79ea89ef1fSEddie Huang OFFSET_RST = 0x0c, 80ce38815dSXudong Chen OFFSET_CON = 0x18, 81ce38815dSXudong Chen OFFSET_TX_MEM_ADDR = 0x1c, 82ce38815dSXudong Chen OFFSET_RX_MEM_ADDR = 0x20, 83ce38815dSXudong Chen OFFSET_TX_LEN = 0x24, 84ce38815dSXudong Chen OFFSET_RX_LEN = 0x28, 85f4f4fed6SLiguo Zhang OFFSET_TX_4G_MODE = 0x54, 86f4f4fed6SLiguo Zhang OFFSET_RX_4G_MODE = 0x58, 87ce38815dSXudong Chen }; 88ce38815dSXudong Chen 89ce38815dSXudong Chen enum i2c_trans_st_rs { 90ce38815dSXudong Chen I2C_TRANS_STOP = 0, 91ce38815dSXudong Chen I2C_TRANS_REPEATED_START, 92ce38815dSXudong Chen }; 93ce38815dSXudong Chen 94ce38815dSXudong Chen enum mtk_trans_op { 95ce38815dSXudong Chen I2C_MASTER_WR = 1, 96ce38815dSXudong Chen I2C_MASTER_RD, 97ce38815dSXudong Chen I2C_MASTER_WRRD, 98ce38815dSXudong Chen }; 99ce38815dSXudong Chen 100ce38815dSXudong Chen enum I2C_REGS_OFFSET { 101bc6eaf17SQii Wang OFFSET_DATA_PORT, 102bc6eaf17SQii Wang OFFSET_SLAVE_ADDR, 103bc6eaf17SQii Wang OFFSET_INTR_MASK, 104bc6eaf17SQii Wang OFFSET_INTR_STAT, 105bc6eaf17SQii Wang OFFSET_CONTROL, 106bc6eaf17SQii Wang OFFSET_TRANSFER_LEN, 107bc6eaf17SQii Wang OFFSET_TRANSAC_LEN, 108bc6eaf17SQii Wang OFFSET_DELAY_LEN, 109bc6eaf17SQii Wang OFFSET_TIMING, 110bc6eaf17SQii Wang OFFSET_START, 111bc6eaf17SQii Wang OFFSET_EXT_CONF, 112bc6eaf17SQii Wang OFFSET_FIFO_STAT, 113bc6eaf17SQii Wang OFFSET_FIFO_THRESH, 114bc6eaf17SQii Wang OFFSET_FIFO_ADDR_CLR, 115bc6eaf17SQii Wang OFFSET_IO_CONFIG, 116bc6eaf17SQii Wang OFFSET_RSV_DEBUG, 117bc6eaf17SQii Wang OFFSET_HS, 118bc6eaf17SQii Wang OFFSET_SOFTRESET, 119bc6eaf17SQii Wang OFFSET_DCM_EN, 120bc6eaf17SQii Wang OFFSET_PATH_DIR, 121bc6eaf17SQii Wang OFFSET_DEBUGSTAT, 122bc6eaf17SQii Wang OFFSET_DEBUGCTRL, 123bc6eaf17SQii Wang OFFSET_TRANSFER_LEN_AUX, 124bc6eaf17SQii Wang OFFSET_CLOCK_DIV, 12525708278SQii Wang OFFSET_LTIMING, 126bc6eaf17SQii Wang }; 127bc6eaf17SQii Wang 128bc6eaf17SQii Wang static const u16 mt_i2c_regs_v1[] = { 129bc6eaf17SQii Wang [OFFSET_DATA_PORT] = 0x0, 130bc6eaf17SQii Wang [OFFSET_SLAVE_ADDR] = 0x4, 131bc6eaf17SQii Wang [OFFSET_INTR_MASK] = 0x8, 132bc6eaf17SQii Wang [OFFSET_INTR_STAT] = 0xc, 133bc6eaf17SQii Wang [OFFSET_CONTROL] = 0x10, 134bc6eaf17SQii Wang [OFFSET_TRANSFER_LEN] = 0x14, 135bc6eaf17SQii Wang [OFFSET_TRANSAC_LEN] = 0x18, 136bc6eaf17SQii Wang [OFFSET_DELAY_LEN] = 0x1c, 137bc6eaf17SQii Wang [OFFSET_TIMING] = 0x20, 138bc6eaf17SQii Wang [OFFSET_START] = 0x24, 139bc6eaf17SQii Wang [OFFSET_EXT_CONF] = 0x28, 140bc6eaf17SQii Wang [OFFSET_FIFO_STAT] = 0x30, 141bc6eaf17SQii Wang [OFFSET_FIFO_THRESH] = 0x34, 142bc6eaf17SQii Wang [OFFSET_FIFO_ADDR_CLR] = 0x38, 143bc6eaf17SQii Wang [OFFSET_IO_CONFIG] = 0x40, 144bc6eaf17SQii Wang [OFFSET_RSV_DEBUG] = 0x44, 145bc6eaf17SQii Wang [OFFSET_HS] = 0x48, 146bc6eaf17SQii Wang [OFFSET_SOFTRESET] = 0x50, 147bc6eaf17SQii Wang [OFFSET_DCM_EN] = 0x54, 148bc6eaf17SQii Wang [OFFSET_PATH_DIR] = 0x60, 149bc6eaf17SQii Wang [OFFSET_DEBUGSTAT] = 0x64, 150bc6eaf17SQii Wang [OFFSET_DEBUGCTRL] = 0x68, 151bc6eaf17SQii Wang [OFFSET_TRANSFER_LEN_AUX] = 0x6c, 152bc6eaf17SQii Wang [OFFSET_CLOCK_DIV] = 0x70, 153ce38815dSXudong Chen }; 154ce38815dSXudong Chen 15525708278SQii Wang static const u16 mt_i2c_regs_v2[] = { 15625708278SQii Wang [OFFSET_DATA_PORT] = 0x0, 15725708278SQii Wang [OFFSET_SLAVE_ADDR] = 0x4, 15825708278SQii Wang [OFFSET_INTR_MASK] = 0x8, 15925708278SQii Wang [OFFSET_INTR_STAT] = 0xc, 16025708278SQii Wang [OFFSET_CONTROL] = 0x10, 16125708278SQii Wang [OFFSET_TRANSFER_LEN] = 0x14, 16225708278SQii Wang [OFFSET_TRANSAC_LEN] = 0x18, 16325708278SQii Wang [OFFSET_DELAY_LEN] = 0x1c, 16425708278SQii Wang [OFFSET_TIMING] = 0x20, 16525708278SQii Wang [OFFSET_START] = 0x24, 16625708278SQii Wang [OFFSET_EXT_CONF] = 0x28, 16725708278SQii Wang [OFFSET_LTIMING] = 0x2c, 16825708278SQii Wang [OFFSET_HS] = 0x30, 16925708278SQii Wang [OFFSET_IO_CONFIG] = 0x34, 17025708278SQii Wang [OFFSET_FIFO_ADDR_CLR] = 0x38, 17125708278SQii Wang [OFFSET_TRANSFER_LEN_AUX] = 0x44, 17225708278SQii Wang [OFFSET_CLOCK_DIV] = 0x48, 17325708278SQii Wang [OFFSET_SOFTRESET] = 0x50, 17425708278SQii Wang [OFFSET_DEBUGSTAT] = 0xe0, 17525708278SQii Wang [OFFSET_DEBUGCTRL] = 0xe8, 17625708278SQii Wang [OFFSET_FIFO_STAT] = 0xf4, 17725708278SQii Wang [OFFSET_FIFO_THRESH] = 0xf8, 17825708278SQii Wang [OFFSET_DCM_EN] = 0xf88, 17925708278SQii Wang }; 18025708278SQii Wang 181ce38815dSXudong Chen struct mtk_i2c_compatible { 182ce38815dSXudong Chen const struct i2c_adapter_quirks *quirks; 183bc6eaf17SQii Wang const u16 *regs; 184ce38815dSXudong Chen unsigned char pmic_i2c: 1; 185ce38815dSXudong Chen unsigned char dcm: 1; 186b2ed11e2SEddie Huang unsigned char auto_restart: 1; 187173b77e8SLiguo Zhang unsigned char aux_len_reg: 1; 188f4f4fed6SLiguo Zhang unsigned char support_33bits: 1; 1895a10e7d7SJun Gao unsigned char timing_adjust: 1; 190a15c91baSQii Wang unsigned char dma_sync: 1; 19125708278SQii Wang unsigned char ltiming_adjust: 1; 192ce38815dSXudong Chen }; 193ce38815dSXudong Chen 194ce38815dSXudong Chen struct mtk_i2c { 195ce38815dSXudong Chen struct i2c_adapter adap; /* i2c host adapter */ 196ce38815dSXudong Chen struct device *dev; 197ce38815dSXudong Chen struct completion msg_complete; 198ce38815dSXudong Chen 199ce38815dSXudong Chen /* set in i2c probe */ 200ce38815dSXudong Chen void __iomem *base; /* i2c base addr */ 201ce38815dSXudong Chen void __iomem *pdmabase; /* dma base address*/ 202ce38815dSXudong Chen struct clk *clk_main; /* main clock for i2c bus */ 203ce38815dSXudong Chen struct clk *clk_dma; /* DMA clock for i2c via DMA */ 204ce38815dSXudong Chen struct clk *clk_pmic; /* PMIC clock for i2c from PMIC */ 205cad6dc5dSQii Wang struct clk *clk_arb; /* Arbitrator clock for i2c */ 206ce38815dSXudong Chen bool have_pmic; /* can use i2c pins from PMIC */ 207ce38815dSXudong Chen bool use_push_pull; /* IO config push-pull mode */ 208ce38815dSXudong Chen 209ce38815dSXudong Chen u16 irq_stat; /* interrupt status */ 210f2326401SJun Gao unsigned int clk_src_div; 211ce38815dSXudong Chen unsigned int speed_hz; /* The speed in transfer */ 212ce38815dSXudong Chen enum mtk_trans_op op; 213ce38815dSXudong Chen u16 timing_reg; 214ce38815dSXudong Chen u16 high_speed_reg; 21525708278SQii Wang u16 ltiming_reg; 216173b77e8SLiguo Zhang unsigned char auto_restart; 2178378d01fSLiguo Zhang bool ignore_restart_irq; 218ce38815dSXudong Chen const struct mtk_i2c_compatible *dev_comp; 219ce38815dSXudong Chen }; 220ce38815dSXudong Chen 221ce38815dSXudong Chen static const struct i2c_adapter_quirks mt6577_i2c_quirks = { 222ce38815dSXudong Chen .flags = I2C_AQ_COMB_WRITE_THEN_READ, 223ce38815dSXudong Chen .max_num_msgs = 1, 224ce38815dSXudong Chen .max_write_len = 255, 225ce38815dSXudong Chen .max_read_len = 255, 226ce38815dSXudong Chen .max_comb_1st_msg_len = 255, 227ce38815dSXudong Chen .max_comb_2nd_msg_len = 31, 228ce38815dSXudong Chen }; 229ce38815dSXudong Chen 2301304fe09SJun Gao static const struct i2c_adapter_quirks mt7622_i2c_quirks = { 2311304fe09SJun Gao .max_num_msgs = 255, 2321304fe09SJun Gao }; 2331304fe09SJun Gao 234abf4923eSHsin-Yi Wang static const struct i2c_adapter_quirks mt8183_i2c_quirks = { 235abf4923eSHsin-Yi Wang .flags = I2C_AQ_NO_ZERO_LEN, 236abf4923eSHsin-Yi Wang }; 237abf4923eSHsin-Yi Wang 2385a10e7d7SJun Gao static const struct mtk_i2c_compatible mt2712_compat = { 239bc6eaf17SQii Wang .regs = mt_i2c_regs_v1, 2405a10e7d7SJun Gao .pmic_i2c = 0, 2415a10e7d7SJun Gao .dcm = 1, 2425a10e7d7SJun Gao .auto_restart = 1, 2435a10e7d7SJun Gao .aux_len_reg = 1, 2445a10e7d7SJun Gao .support_33bits = 1, 2455a10e7d7SJun Gao .timing_adjust = 1, 246a15c91baSQii Wang .dma_sync = 0, 24725708278SQii Wang .ltiming_adjust = 0, 2485a10e7d7SJun Gao }; 2495a10e7d7SJun Gao 250ce38815dSXudong Chen static const struct mtk_i2c_compatible mt6577_compat = { 251ce38815dSXudong Chen .quirks = &mt6577_i2c_quirks, 252bc6eaf17SQii Wang .regs = mt_i2c_regs_v1, 253ce38815dSXudong Chen .pmic_i2c = 0, 254ce38815dSXudong Chen .dcm = 1, 255b2ed11e2SEddie Huang .auto_restart = 0, 256173b77e8SLiguo Zhang .aux_len_reg = 0, 257f4f4fed6SLiguo Zhang .support_33bits = 0, 2585a10e7d7SJun Gao .timing_adjust = 0, 259a15c91baSQii Wang .dma_sync = 0, 26025708278SQii Wang .ltiming_adjust = 0, 261ce38815dSXudong Chen }; 262ce38815dSXudong Chen 263ce38815dSXudong Chen static const struct mtk_i2c_compatible mt6589_compat = { 264ce38815dSXudong Chen .quirks = &mt6577_i2c_quirks, 265bc6eaf17SQii Wang .regs = mt_i2c_regs_v1, 266ce38815dSXudong Chen .pmic_i2c = 1, 267ce38815dSXudong Chen .dcm = 0, 268b2ed11e2SEddie Huang .auto_restart = 0, 269173b77e8SLiguo Zhang .aux_len_reg = 0, 270f4f4fed6SLiguo Zhang .support_33bits = 0, 2715a10e7d7SJun Gao .timing_adjust = 0, 272a15c91baSQii Wang .dma_sync = 0, 27325708278SQii Wang .ltiming_adjust = 0, 274b2ed11e2SEddie Huang }; 275b2ed11e2SEddie Huang 2761304fe09SJun Gao static const struct mtk_i2c_compatible mt7622_compat = { 2771304fe09SJun Gao .quirks = &mt7622_i2c_quirks, 278bc6eaf17SQii Wang .regs = mt_i2c_regs_v1, 2791304fe09SJun Gao .pmic_i2c = 0, 2801304fe09SJun Gao .dcm = 1, 2811304fe09SJun Gao .auto_restart = 1, 2821304fe09SJun Gao .aux_len_reg = 1, 2831304fe09SJun Gao .support_33bits = 0, 2845a10e7d7SJun Gao .timing_adjust = 0, 285a15c91baSQii Wang .dma_sync = 0, 28625708278SQii Wang .ltiming_adjust = 0, 2871304fe09SJun Gao }; 2881304fe09SJun Gao 289b2ed11e2SEddie Huang static const struct mtk_i2c_compatible mt8173_compat = { 290bc6eaf17SQii Wang .regs = mt_i2c_regs_v1, 291b2ed11e2SEddie Huang .pmic_i2c = 0, 292b2ed11e2SEddie Huang .dcm = 1, 293b2ed11e2SEddie Huang .auto_restart = 1, 294173b77e8SLiguo Zhang .aux_len_reg = 1, 295f4f4fed6SLiguo Zhang .support_33bits = 1, 2965a10e7d7SJun Gao .timing_adjust = 0, 297a15c91baSQii Wang .dma_sync = 0, 29825708278SQii Wang .ltiming_adjust = 0, 29925708278SQii Wang }; 30025708278SQii Wang 30125708278SQii Wang static const struct mtk_i2c_compatible mt8183_compat = { 302abf4923eSHsin-Yi Wang .quirks = &mt8183_i2c_quirks, 30325708278SQii Wang .regs = mt_i2c_regs_v2, 30425708278SQii Wang .pmic_i2c = 0, 30525708278SQii Wang .dcm = 0, 30625708278SQii Wang .auto_restart = 1, 30725708278SQii Wang .aux_len_reg = 1, 30825708278SQii Wang .support_33bits = 1, 30925708278SQii Wang .timing_adjust = 1, 31025708278SQii Wang .dma_sync = 1, 31125708278SQii Wang .ltiming_adjust = 1, 312ce38815dSXudong Chen }; 313ce38815dSXudong Chen 314ce38815dSXudong Chen static const struct of_device_id mtk_i2c_of_match[] = { 3155a10e7d7SJun Gao { .compatible = "mediatek,mt2712-i2c", .data = &mt2712_compat }, 316ce38815dSXudong Chen { .compatible = "mediatek,mt6577-i2c", .data = &mt6577_compat }, 317ce38815dSXudong Chen { .compatible = "mediatek,mt6589-i2c", .data = &mt6589_compat }, 3181304fe09SJun Gao { .compatible = "mediatek,mt7622-i2c", .data = &mt7622_compat }, 319b2ed11e2SEddie Huang { .compatible = "mediatek,mt8173-i2c", .data = &mt8173_compat }, 32025708278SQii Wang { .compatible = "mediatek,mt8183-i2c", .data = &mt8183_compat }, 321ce38815dSXudong Chen {} 322ce38815dSXudong Chen }; 323ce38815dSXudong Chen MODULE_DEVICE_TABLE(of, mtk_i2c_of_match); 324ce38815dSXudong Chen 325bc6eaf17SQii Wang static u16 mtk_i2c_readw(struct mtk_i2c *i2c, enum I2C_REGS_OFFSET reg) 326bc6eaf17SQii Wang { 327bc6eaf17SQii Wang return readw(i2c->base + i2c->dev_comp->regs[reg]); 328bc6eaf17SQii Wang } 329bc6eaf17SQii Wang 330bc6eaf17SQii Wang static void mtk_i2c_writew(struct mtk_i2c *i2c, u16 val, 331bc6eaf17SQii Wang enum I2C_REGS_OFFSET reg) 332bc6eaf17SQii Wang { 333bc6eaf17SQii Wang writew(val, i2c->base + i2c->dev_comp->regs[reg]); 334bc6eaf17SQii Wang } 335bc6eaf17SQii Wang 336ce38815dSXudong Chen static int mtk_i2c_clock_enable(struct mtk_i2c *i2c) 337ce38815dSXudong Chen { 338ce38815dSXudong Chen int ret; 339ce38815dSXudong Chen 340ce38815dSXudong Chen ret = clk_prepare_enable(i2c->clk_dma); 341ce38815dSXudong Chen if (ret) 342ce38815dSXudong Chen return ret; 343ce38815dSXudong Chen 344ce38815dSXudong Chen ret = clk_prepare_enable(i2c->clk_main); 345ce38815dSXudong Chen if (ret) 346ce38815dSXudong Chen goto err_main; 347ce38815dSXudong Chen 348ce38815dSXudong Chen if (i2c->have_pmic) { 349ce38815dSXudong Chen ret = clk_prepare_enable(i2c->clk_pmic); 350ce38815dSXudong Chen if (ret) 351ce38815dSXudong Chen goto err_pmic; 352ce38815dSXudong Chen } 353cad6dc5dSQii Wang 354cad6dc5dSQii Wang if (i2c->clk_arb) { 355cad6dc5dSQii Wang ret = clk_prepare_enable(i2c->clk_arb); 356cad6dc5dSQii Wang if (ret) 357cad6dc5dSQii Wang goto err_arb; 358cad6dc5dSQii Wang } 359cad6dc5dSQii Wang 360ce38815dSXudong Chen return 0; 361ce38815dSXudong Chen 362cad6dc5dSQii Wang err_arb: 363cad6dc5dSQii Wang if (i2c->have_pmic) 364cad6dc5dSQii Wang clk_disable_unprepare(i2c->clk_pmic); 365ce38815dSXudong Chen err_pmic: 366ce38815dSXudong Chen clk_disable_unprepare(i2c->clk_main); 367ce38815dSXudong Chen err_main: 368ce38815dSXudong Chen clk_disable_unprepare(i2c->clk_dma); 369ce38815dSXudong Chen 370ce38815dSXudong Chen return ret; 371ce38815dSXudong Chen } 372ce38815dSXudong Chen 373ce38815dSXudong Chen static void mtk_i2c_clock_disable(struct mtk_i2c *i2c) 374ce38815dSXudong Chen { 375cad6dc5dSQii Wang if (i2c->clk_arb) 376cad6dc5dSQii Wang clk_disable_unprepare(i2c->clk_arb); 377cad6dc5dSQii Wang 378ce38815dSXudong Chen if (i2c->have_pmic) 379ce38815dSXudong Chen clk_disable_unprepare(i2c->clk_pmic); 380ce38815dSXudong Chen 381ce38815dSXudong Chen clk_disable_unprepare(i2c->clk_main); 382ce38815dSXudong Chen clk_disable_unprepare(i2c->clk_dma); 383ce38815dSXudong Chen } 384ce38815dSXudong Chen 385ce38815dSXudong Chen static void mtk_i2c_init_hw(struct mtk_i2c *i2c) 386ce38815dSXudong Chen { 387ce38815dSXudong Chen u16 control_reg; 388ce38815dSXudong Chen 389bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_SOFT_RST, OFFSET_SOFTRESET); 390ce38815dSXudong Chen 391ce38815dSXudong Chen /* Set ioconfig */ 392ce38815dSXudong Chen if (i2c->use_push_pull) 393bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_IO_CONFIG_PUSH_PULL, OFFSET_IO_CONFIG); 394ce38815dSXudong Chen else 395bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_IO_CONFIG_OPEN_DRAIN, OFFSET_IO_CONFIG); 396ce38815dSXudong Chen 397ce38815dSXudong Chen if (i2c->dev_comp->dcm) 398bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_DCM_DISABLE, OFFSET_DCM_EN); 399ce38815dSXudong Chen 4005a10e7d7SJun Gao if (i2c->dev_comp->timing_adjust) 401bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_DEFAULT_CLK_DIV - 1, OFFSET_CLOCK_DIV); 4025a10e7d7SJun Gao 403bc6eaf17SQii Wang mtk_i2c_writew(i2c, i2c->timing_reg, OFFSET_TIMING); 404bc6eaf17SQii Wang mtk_i2c_writew(i2c, i2c->high_speed_reg, OFFSET_HS); 40525708278SQii Wang if (i2c->dev_comp->ltiming_adjust) 40625708278SQii Wang mtk_i2c_writew(i2c, i2c->ltiming_reg, OFFSET_LTIMING); 407ce38815dSXudong Chen 408ce38815dSXudong Chen /* If use i2c pin from PMIC mt6397 side, need set PATH_DIR first */ 409ce38815dSXudong Chen if (i2c->have_pmic) 410bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_CONTROL_WRAPPER, OFFSET_PATH_DIR); 411ce38815dSXudong Chen 412ce38815dSXudong Chen control_reg = I2C_CONTROL_ACKERR_DET_EN | 413ce38815dSXudong Chen I2C_CONTROL_CLK_EXT_EN | I2C_CONTROL_DMA_EN; 414a15c91baSQii Wang if (i2c->dev_comp->dma_sync) 415a15c91baSQii Wang control_reg |= I2C_CONTROL_DMAACK_EN | I2C_CONTROL_ASYNC_MODE; 416a15c91baSQii Wang 417bc6eaf17SQii Wang mtk_i2c_writew(i2c, control_reg, OFFSET_CONTROL); 418bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_DELAY_LEN, OFFSET_DELAY_LEN); 419ea89ef1fSEddie Huang 420ea89ef1fSEddie Huang writel(I2C_DMA_HARD_RST, i2c->pdmabase + OFFSET_RST); 421ea89ef1fSEddie Huang udelay(50); 422ea89ef1fSEddie Huang writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_RST); 423ce38815dSXudong Chen } 424ce38815dSXudong Chen 425ce38815dSXudong Chen /* 426ce38815dSXudong Chen * Calculate i2c port speed 427ce38815dSXudong Chen * 428ce38815dSXudong Chen * Hardware design: 429ce38815dSXudong Chen * i2c_bus_freq = parent_clk / (clock_div * 2 * sample_cnt * step_cnt) 430ce38815dSXudong Chen * clock_div: fixed in hardware, but may be various in different SoCs 431ce38815dSXudong Chen * 432ce38815dSXudong Chen * The calculation want to pick the highest bus frequency that is still 433ce38815dSXudong Chen * less than or equal to i2c->speed_hz. The calculation try to get 434ce38815dSXudong Chen * sample_cnt and step_cn 435ce38815dSXudong Chen */ 436f2326401SJun Gao static int mtk_i2c_calculate_speed(struct mtk_i2c *i2c, unsigned int clk_src, 437f2326401SJun Gao unsigned int target_speed, 438f2326401SJun Gao unsigned int *timing_step_cnt, 439f2326401SJun Gao unsigned int *timing_sample_cnt) 440ce38815dSXudong Chen { 441ce38815dSXudong Chen unsigned int step_cnt; 442ce38815dSXudong Chen unsigned int sample_cnt; 443ce38815dSXudong Chen unsigned int max_step_cnt; 444ce38815dSXudong Chen unsigned int base_sample_cnt = MAX_SAMPLE_CNT_DIV; 445ce38815dSXudong Chen unsigned int base_step_cnt; 446ce38815dSXudong Chen unsigned int opt_div; 447ce38815dSXudong Chen unsigned int best_mul; 448ce38815dSXudong Chen unsigned int cnt_mul; 449ce38815dSXudong Chen 450*90224e64SAndy Shevchenko if (target_speed > I2C_MAX_FAST_MODE_PLUS_FREQ) 451*90224e64SAndy Shevchenko target_speed = I2C_MAX_FAST_MODE_PLUS_FREQ; 452ce38815dSXudong Chen 453*90224e64SAndy Shevchenko if (target_speed > I2C_MAX_FAST_MODE_FREQ) 454ce38815dSXudong Chen max_step_cnt = MAX_HS_STEP_CNT_DIV; 455ce38815dSXudong Chen else 456ce38815dSXudong Chen max_step_cnt = MAX_STEP_CNT_DIV; 457ce38815dSXudong Chen 458ce38815dSXudong Chen base_step_cnt = max_step_cnt; 459ce38815dSXudong Chen /* Find the best combination */ 460ce38815dSXudong Chen opt_div = DIV_ROUND_UP(clk_src >> 1, target_speed); 461ce38815dSXudong Chen best_mul = MAX_SAMPLE_CNT_DIV * max_step_cnt; 462ce38815dSXudong Chen 463ce38815dSXudong Chen /* Search for the best pair (sample_cnt, step_cnt) with 464ce38815dSXudong Chen * 0 < sample_cnt < MAX_SAMPLE_CNT_DIV 465ce38815dSXudong Chen * 0 < step_cnt < max_step_cnt 466ce38815dSXudong Chen * sample_cnt * step_cnt >= opt_div 467ce38815dSXudong Chen * optimizing for sample_cnt * step_cnt being minimal 468ce38815dSXudong Chen */ 469ce38815dSXudong Chen for (sample_cnt = 1; sample_cnt <= MAX_SAMPLE_CNT_DIV; sample_cnt++) { 470ce38815dSXudong Chen step_cnt = DIV_ROUND_UP(opt_div, sample_cnt); 471ce38815dSXudong Chen cnt_mul = step_cnt * sample_cnt; 472ce38815dSXudong Chen if (step_cnt > max_step_cnt) 473ce38815dSXudong Chen continue; 474ce38815dSXudong Chen 475ce38815dSXudong Chen if (cnt_mul < best_mul) { 476ce38815dSXudong Chen best_mul = cnt_mul; 477ce38815dSXudong Chen base_sample_cnt = sample_cnt; 478ce38815dSXudong Chen base_step_cnt = step_cnt; 479ce38815dSXudong Chen if (best_mul == opt_div) 480ce38815dSXudong Chen break; 481ce38815dSXudong Chen } 482ce38815dSXudong Chen } 483ce38815dSXudong Chen 484ce38815dSXudong Chen sample_cnt = base_sample_cnt; 485ce38815dSXudong Chen step_cnt = base_step_cnt; 486ce38815dSXudong Chen 487ce38815dSXudong Chen if ((clk_src / (2 * sample_cnt * step_cnt)) > target_speed) { 488ce38815dSXudong Chen /* In this case, hardware can't support such 489ce38815dSXudong Chen * low i2c_bus_freq 490ce38815dSXudong Chen */ 491ce38815dSXudong Chen dev_dbg(i2c->dev, "Unsupported speed (%uhz)\n", target_speed); 492ce38815dSXudong Chen return -EINVAL; 493ce38815dSXudong Chen } 494ce38815dSXudong Chen 495f2326401SJun Gao *timing_step_cnt = step_cnt - 1; 496f2326401SJun Gao *timing_sample_cnt = sample_cnt - 1; 497f2326401SJun Gao 498f2326401SJun Gao return 0; 499f2326401SJun Gao } 500f2326401SJun Gao 501f2326401SJun Gao static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk) 502f2326401SJun Gao { 503f2326401SJun Gao unsigned int clk_src; 504f2326401SJun Gao unsigned int step_cnt; 505f2326401SJun Gao unsigned int sample_cnt; 50625708278SQii Wang unsigned int l_step_cnt; 50725708278SQii Wang unsigned int l_sample_cnt; 508f2326401SJun Gao unsigned int target_speed; 509f2326401SJun Gao int ret; 510f2326401SJun Gao 511f2326401SJun Gao clk_src = parent_clk / i2c->clk_src_div; 512f2326401SJun Gao target_speed = i2c->speed_hz; 513ce38815dSXudong Chen 514*90224e64SAndy Shevchenko if (target_speed > I2C_MAX_FAST_MODE_FREQ) { 515f2326401SJun Gao /* Set master code speed register */ 516*90224e64SAndy Shevchenko ret = mtk_i2c_calculate_speed(i2c, clk_src, I2C_MAX_FAST_MODE_FREQ, 51725708278SQii Wang &l_step_cnt, &l_sample_cnt); 518f2326401SJun Gao if (ret < 0) 519f2326401SJun Gao return ret; 520f2326401SJun Gao 52125708278SQii Wang i2c->timing_reg = (l_sample_cnt << 8) | l_step_cnt; 522f2326401SJun Gao 523ce38815dSXudong Chen /* Set the high speed mode register */ 524f2326401SJun Gao ret = mtk_i2c_calculate_speed(i2c, clk_src, target_speed, 525f2326401SJun Gao &step_cnt, &sample_cnt); 526f2326401SJun Gao if (ret < 0) 527f2326401SJun Gao return ret; 528f2326401SJun Gao 529ce38815dSXudong Chen i2c->high_speed_reg = I2C_TIME_DEFAULT_VALUE | 530ce38815dSXudong Chen (sample_cnt << 12) | (step_cnt << 8); 53125708278SQii Wang 53225708278SQii Wang if (i2c->dev_comp->ltiming_adjust) 53325708278SQii Wang i2c->ltiming_reg = (l_sample_cnt << 6) | l_step_cnt | 53425708278SQii Wang (sample_cnt << 12) | (step_cnt << 9); 535ce38815dSXudong Chen } else { 536f2326401SJun Gao ret = mtk_i2c_calculate_speed(i2c, clk_src, target_speed, 537f2326401SJun Gao &step_cnt, &sample_cnt); 538f2326401SJun Gao if (ret < 0) 539f2326401SJun Gao return ret; 540f2326401SJun Gao 541f2326401SJun Gao i2c->timing_reg = (sample_cnt << 8) | step_cnt; 542f2326401SJun Gao 543ce38815dSXudong Chen /* Disable the high speed transaction */ 544ce38815dSXudong Chen i2c->high_speed_reg = I2C_TIME_CLR_VALUE; 54525708278SQii Wang 54625708278SQii Wang if (i2c->dev_comp->ltiming_adjust) 54725708278SQii Wang i2c->ltiming_reg = (sample_cnt << 6) | step_cnt; 548ce38815dSXudong Chen } 549ce38815dSXudong Chen 550ce38815dSXudong Chen return 0; 551ce38815dSXudong Chen } 552ce38815dSXudong Chen 553f4f4fed6SLiguo Zhang static inline u32 mtk_i2c_set_4g_mode(dma_addr_t addr) 554f4f4fed6SLiguo Zhang { 555f4f4fed6SLiguo Zhang return (addr & BIT_ULL(32)) ? I2C_DMA_4G_MODE : I2C_DMA_CLR_FLAG; 556f4f4fed6SLiguo Zhang } 557f4f4fed6SLiguo Zhang 558b2ed11e2SEddie Huang static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, 559b2ed11e2SEddie Huang int num, int left_num) 560ce38815dSXudong Chen { 561ce38815dSXudong Chen u16 addr_reg; 562b2ed11e2SEddie Huang u16 start_reg; 563ce38815dSXudong Chen u16 control_reg; 564b2ed11e2SEddie Huang u16 restart_flag = 0; 565f4f4fed6SLiguo Zhang u32 reg_4g_mode; 566fc66b39fSJun Gao u8 *dma_rd_buf = NULL; 567fc66b39fSJun Gao u8 *dma_wr_buf = NULL; 568ce38815dSXudong Chen dma_addr_t rpaddr = 0; 569ce38815dSXudong Chen dma_addr_t wpaddr = 0; 570ce38815dSXudong Chen int ret; 571ce38815dSXudong Chen 572ce38815dSXudong Chen i2c->irq_stat = 0; 573ce38815dSXudong Chen 574173b77e8SLiguo Zhang if (i2c->auto_restart) 575b2ed11e2SEddie Huang restart_flag = I2C_RS_TRANSFER; 576b2ed11e2SEddie Huang 577ce38815dSXudong Chen reinit_completion(&i2c->msg_complete); 578ce38815dSXudong Chen 579bc6eaf17SQii Wang control_reg = mtk_i2c_readw(i2c, OFFSET_CONTROL) & 580ce38815dSXudong Chen ~(I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS); 581*90224e64SAndy Shevchenko if ((i2c->speed_hz > I2C_MAX_FAST_MODE_FREQ) || (left_num >= 1)) 582ce38815dSXudong Chen control_reg |= I2C_CONTROL_RS; 583ce38815dSXudong Chen 584ce38815dSXudong Chen if (i2c->op == I2C_MASTER_WRRD) 585ce38815dSXudong Chen control_reg |= I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS; 586ce38815dSXudong Chen 587bc6eaf17SQii Wang mtk_i2c_writew(i2c, control_reg, OFFSET_CONTROL); 588ce38815dSXudong Chen 589ce38815dSXudong Chen /* set start condition */ 590*90224e64SAndy Shevchenko if (i2c->speed_hz <= I2C_MAX_STANDARD_MODE_FREQ) 591bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_ST_START_CON, OFFSET_EXT_CONF); 592ce38815dSXudong Chen else 593bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_FS_START_CON, OFFSET_EXT_CONF); 594ce38815dSXudong Chen 5950d47ce21SWolfram Sang addr_reg = i2c_8bit_addr_from_msg(msgs); 596bc6eaf17SQii Wang mtk_i2c_writew(i2c, addr_reg, OFFSET_SLAVE_ADDR); 597ce38815dSXudong Chen 598ce38815dSXudong Chen /* Clear interrupt status */ 599bc6eaf17SQii Wang mtk_i2c_writew(i2c, restart_flag | I2C_HS_NACKERR | I2C_ACKERR | 600cad6dc5dSQii Wang I2C_ARB_LOST | I2C_TRANSAC_COMP, OFFSET_INTR_STAT); 601bc6eaf17SQii Wang 602bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_FIFO_ADDR_CLR, OFFSET_FIFO_ADDR_CLR); 603ce38815dSXudong Chen 604ce38815dSXudong Chen /* Enable interrupt */ 605bc6eaf17SQii Wang mtk_i2c_writew(i2c, restart_flag | I2C_HS_NACKERR | I2C_ACKERR | 606cad6dc5dSQii Wang I2C_ARB_LOST | I2C_TRANSAC_COMP, OFFSET_INTR_MASK); 607ce38815dSXudong Chen 608ce38815dSXudong Chen /* Set transfer and transaction len */ 609ce38815dSXudong Chen if (i2c->op == I2C_MASTER_WRRD) { 610173b77e8SLiguo Zhang if (i2c->dev_comp->aux_len_reg) { 611bc6eaf17SQii Wang mtk_i2c_writew(i2c, msgs->len, OFFSET_TRANSFER_LEN); 612bc6eaf17SQii Wang mtk_i2c_writew(i2c, (msgs + 1)->len, 613173b77e8SLiguo Zhang OFFSET_TRANSFER_LEN_AUX); 614173b77e8SLiguo Zhang } else { 615bc6eaf17SQii Wang mtk_i2c_writew(i2c, msgs->len | ((msgs + 1)->len) << 8, 616bc6eaf17SQii Wang OFFSET_TRANSFER_LEN); 617173b77e8SLiguo Zhang } 618bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_WRRD_TRANAC_VALUE, OFFSET_TRANSAC_LEN); 619ce38815dSXudong Chen } else { 620bc6eaf17SQii Wang mtk_i2c_writew(i2c, msgs->len, OFFSET_TRANSFER_LEN); 621bc6eaf17SQii Wang mtk_i2c_writew(i2c, num, OFFSET_TRANSAC_LEN); 622ce38815dSXudong Chen } 623ce38815dSXudong Chen 624ce38815dSXudong Chen /* Prepare buffer data to start transfer */ 625ce38815dSXudong Chen if (i2c->op == I2C_MASTER_RD) { 626ce38815dSXudong Chen writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); 627ce38815dSXudong Chen writel(I2C_DMA_CON_RX, i2c->pdmabase + OFFSET_CON); 628fc66b39fSJun Gao 629bc1a7f75SHsin-Yi Wang dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 1); 630fc66b39fSJun Gao if (!dma_rd_buf) 631ce38815dSXudong Chen return -ENOMEM; 632f4f4fed6SLiguo Zhang 633fc66b39fSJun Gao rpaddr = dma_map_single(i2c->dev, dma_rd_buf, 634fc66b39fSJun Gao msgs->len, DMA_FROM_DEVICE); 635fc66b39fSJun Gao if (dma_mapping_error(i2c->dev, rpaddr)) { 636fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_rd_buf, msgs, false); 637fc66b39fSJun Gao 638fc66b39fSJun Gao return -ENOMEM; 639fc66b39fSJun Gao } 640fc66b39fSJun Gao 641f4f4fed6SLiguo Zhang if (i2c->dev_comp->support_33bits) { 642f4f4fed6SLiguo Zhang reg_4g_mode = mtk_i2c_set_4g_mode(rpaddr); 643f4f4fed6SLiguo Zhang writel(reg_4g_mode, i2c->pdmabase + OFFSET_RX_4G_MODE); 644f4f4fed6SLiguo Zhang } 645f4f4fed6SLiguo Zhang 646ce38815dSXudong Chen writel((u32)rpaddr, i2c->pdmabase + OFFSET_RX_MEM_ADDR); 647ce38815dSXudong Chen writel(msgs->len, i2c->pdmabase + OFFSET_RX_LEN); 648ce38815dSXudong Chen } else if (i2c->op == I2C_MASTER_WR) { 649ce38815dSXudong Chen writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); 650ce38815dSXudong Chen writel(I2C_DMA_CON_TX, i2c->pdmabase + OFFSET_CON); 651fc66b39fSJun Gao 652bc1a7f75SHsin-Yi Wang dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1); 653fc66b39fSJun Gao if (!dma_wr_buf) 654ce38815dSXudong Chen return -ENOMEM; 655f4f4fed6SLiguo Zhang 656fc66b39fSJun Gao wpaddr = dma_map_single(i2c->dev, dma_wr_buf, 657fc66b39fSJun Gao msgs->len, DMA_TO_DEVICE); 658fc66b39fSJun Gao if (dma_mapping_error(i2c->dev, wpaddr)) { 659fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_wr_buf, msgs, false); 660fc66b39fSJun Gao 661fc66b39fSJun Gao return -ENOMEM; 662fc66b39fSJun Gao } 663fc66b39fSJun Gao 664f4f4fed6SLiguo Zhang if (i2c->dev_comp->support_33bits) { 665f4f4fed6SLiguo Zhang reg_4g_mode = mtk_i2c_set_4g_mode(wpaddr); 666f4f4fed6SLiguo Zhang writel(reg_4g_mode, i2c->pdmabase + OFFSET_TX_4G_MODE); 667f4f4fed6SLiguo Zhang } 668f4f4fed6SLiguo Zhang 669ce38815dSXudong Chen writel((u32)wpaddr, i2c->pdmabase + OFFSET_TX_MEM_ADDR); 670ce38815dSXudong Chen writel(msgs->len, i2c->pdmabase + OFFSET_TX_LEN); 671ce38815dSXudong Chen } else { 672ce38815dSXudong Chen writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_INT_FLAG); 673ce38815dSXudong Chen writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_CON); 674fc66b39fSJun Gao 675bc1a7f75SHsin-Yi Wang dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1); 676fc66b39fSJun Gao if (!dma_wr_buf) 677ce38815dSXudong Chen return -ENOMEM; 678fc66b39fSJun Gao 679fc66b39fSJun Gao wpaddr = dma_map_single(i2c->dev, dma_wr_buf, 680fc66b39fSJun Gao msgs->len, DMA_TO_DEVICE); 681fc66b39fSJun Gao if (dma_mapping_error(i2c->dev, wpaddr)) { 682fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_wr_buf, msgs, false); 683fc66b39fSJun Gao 684fc66b39fSJun Gao return -ENOMEM; 685fc66b39fSJun Gao } 686fc66b39fSJun Gao 687bc1a7f75SHsin-Yi Wang dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 1); 688fc66b39fSJun Gao if (!dma_rd_buf) { 689fc66b39fSJun Gao dma_unmap_single(i2c->dev, wpaddr, 690fc66b39fSJun Gao msgs->len, DMA_TO_DEVICE); 691fc66b39fSJun Gao 692fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_wr_buf, msgs, false); 693fc66b39fSJun Gao 694fc66b39fSJun Gao return -ENOMEM; 695fc66b39fSJun Gao } 696fc66b39fSJun Gao 697fc66b39fSJun Gao rpaddr = dma_map_single(i2c->dev, dma_rd_buf, 698ce38815dSXudong Chen (msgs + 1)->len, 699ce38815dSXudong Chen DMA_FROM_DEVICE); 700ce38815dSXudong Chen if (dma_mapping_error(i2c->dev, rpaddr)) { 701ce38815dSXudong Chen dma_unmap_single(i2c->dev, wpaddr, 702ce38815dSXudong Chen msgs->len, DMA_TO_DEVICE); 703fc66b39fSJun Gao 704fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_wr_buf, msgs, false); 705fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_rd_buf, (msgs + 1), false); 706fc66b39fSJun Gao 707ce38815dSXudong Chen return -ENOMEM; 708ce38815dSXudong Chen } 709f4f4fed6SLiguo Zhang 710f4f4fed6SLiguo Zhang if (i2c->dev_comp->support_33bits) { 711f4f4fed6SLiguo Zhang reg_4g_mode = mtk_i2c_set_4g_mode(wpaddr); 712f4f4fed6SLiguo Zhang writel(reg_4g_mode, i2c->pdmabase + OFFSET_TX_4G_MODE); 713f4f4fed6SLiguo Zhang 714f4f4fed6SLiguo Zhang reg_4g_mode = mtk_i2c_set_4g_mode(rpaddr); 715f4f4fed6SLiguo Zhang writel(reg_4g_mode, i2c->pdmabase + OFFSET_RX_4G_MODE); 716f4f4fed6SLiguo Zhang } 717f4f4fed6SLiguo Zhang 718ce38815dSXudong Chen writel((u32)wpaddr, i2c->pdmabase + OFFSET_TX_MEM_ADDR); 719ce38815dSXudong Chen writel((u32)rpaddr, i2c->pdmabase + OFFSET_RX_MEM_ADDR); 720ce38815dSXudong Chen writel(msgs->len, i2c->pdmabase + OFFSET_TX_LEN); 721ce38815dSXudong Chen writel((msgs + 1)->len, i2c->pdmabase + OFFSET_RX_LEN); 722ce38815dSXudong Chen } 723ce38815dSXudong Chen 724ce38815dSXudong Chen writel(I2C_DMA_START_EN, i2c->pdmabase + OFFSET_EN); 725b2ed11e2SEddie Huang 726173b77e8SLiguo Zhang if (!i2c->auto_restart) { 727b2ed11e2SEddie Huang start_reg = I2C_TRANSAC_START; 728b2ed11e2SEddie Huang } else { 729b2ed11e2SEddie Huang start_reg = I2C_TRANSAC_START | I2C_RS_MUL_TRIG; 730b2ed11e2SEddie Huang if (left_num >= 1) 731b2ed11e2SEddie Huang start_reg |= I2C_RS_MUL_CNFG; 732b2ed11e2SEddie Huang } 733bc6eaf17SQii Wang mtk_i2c_writew(i2c, start_reg, OFFSET_START); 734ce38815dSXudong Chen 735ce38815dSXudong Chen ret = wait_for_completion_timeout(&i2c->msg_complete, 736ce38815dSXudong Chen i2c->adap.timeout); 737ce38815dSXudong Chen 738ce38815dSXudong Chen /* Clear interrupt mask */ 739bc6eaf17SQii Wang mtk_i2c_writew(i2c, ~(restart_flag | I2C_HS_NACKERR | I2C_ACKERR | 740cad6dc5dSQii Wang I2C_ARB_LOST | I2C_TRANSAC_COMP), OFFSET_INTR_MASK); 741ce38815dSXudong Chen 742ce38815dSXudong Chen if (i2c->op == I2C_MASTER_WR) { 743ce38815dSXudong Chen dma_unmap_single(i2c->dev, wpaddr, 744ce38815dSXudong Chen msgs->len, DMA_TO_DEVICE); 745fc66b39fSJun Gao 746fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_wr_buf, msgs, true); 747ce38815dSXudong Chen } else if (i2c->op == I2C_MASTER_RD) { 748ce38815dSXudong Chen dma_unmap_single(i2c->dev, rpaddr, 749ce38815dSXudong Chen msgs->len, DMA_FROM_DEVICE); 750fc66b39fSJun Gao 751fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_rd_buf, msgs, true); 752ce38815dSXudong Chen } else { 753ce38815dSXudong Chen dma_unmap_single(i2c->dev, wpaddr, msgs->len, 754ce38815dSXudong Chen DMA_TO_DEVICE); 755ce38815dSXudong Chen dma_unmap_single(i2c->dev, rpaddr, (msgs + 1)->len, 756ce38815dSXudong Chen DMA_FROM_DEVICE); 757fc66b39fSJun Gao 758fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_wr_buf, msgs, true); 759fc66b39fSJun Gao i2c_put_dma_safe_msg_buf(dma_rd_buf, (msgs + 1), true); 760ce38815dSXudong Chen } 761ce38815dSXudong Chen 762ce38815dSXudong Chen if (ret == 0) { 763ce38815dSXudong Chen dev_dbg(i2c->dev, "addr: %x, transfer timeout\n", msgs->addr); 764ce38815dSXudong Chen mtk_i2c_init_hw(i2c); 765ce38815dSXudong Chen return -ETIMEDOUT; 766ce38815dSXudong Chen } 767ce38815dSXudong Chen 768ce38815dSXudong Chen if (i2c->irq_stat & (I2C_HS_NACKERR | I2C_ACKERR)) { 769ce38815dSXudong Chen dev_dbg(i2c->dev, "addr: %x, transfer ACK error\n", msgs->addr); 770ce38815dSXudong Chen mtk_i2c_init_hw(i2c); 771ce38815dSXudong Chen return -ENXIO; 772ce38815dSXudong Chen } 773ce38815dSXudong Chen 774ce38815dSXudong Chen return 0; 775ce38815dSXudong Chen } 776ce38815dSXudong Chen 777ce38815dSXudong Chen static int mtk_i2c_transfer(struct i2c_adapter *adap, 778ce38815dSXudong Chen struct i2c_msg msgs[], int num) 779ce38815dSXudong Chen { 780ce38815dSXudong Chen int ret; 781ce38815dSXudong Chen int left_num = num; 782ce38815dSXudong Chen struct mtk_i2c *i2c = i2c_get_adapdata(adap); 783ce38815dSXudong Chen 784ce38815dSXudong Chen ret = mtk_i2c_clock_enable(i2c); 785ce38815dSXudong Chen if (ret) 786ce38815dSXudong Chen return ret; 787ce38815dSXudong Chen 788173b77e8SLiguo Zhang i2c->auto_restart = i2c->dev_comp->auto_restart; 789173b77e8SLiguo Zhang 790173b77e8SLiguo Zhang /* checking if we can skip restart and optimize using WRRD mode */ 791173b77e8SLiguo Zhang if (i2c->auto_restart && num == 2) { 792173b77e8SLiguo Zhang if (!(msgs[0].flags & I2C_M_RD) && (msgs[1].flags & I2C_M_RD) && 793173b77e8SLiguo Zhang msgs[0].addr == msgs[1].addr) { 794173b77e8SLiguo Zhang i2c->auto_restart = 0; 795173b77e8SLiguo Zhang } 796173b77e8SLiguo Zhang } 797173b77e8SLiguo Zhang 798*90224e64SAndy Shevchenko if (i2c->auto_restart && num >= 2 && i2c->speed_hz > I2C_MAX_FAST_MODE_FREQ) 7998378d01fSLiguo Zhang /* ignore the first restart irq after the master code, 8008378d01fSLiguo Zhang * otherwise the first transfer will be discarded. 8018378d01fSLiguo Zhang */ 8028378d01fSLiguo Zhang i2c->ignore_restart_irq = true; 8038378d01fSLiguo Zhang else 8048378d01fSLiguo Zhang i2c->ignore_restart_irq = false; 8058378d01fSLiguo Zhang 806b2ed11e2SEddie Huang while (left_num--) { 807ce38815dSXudong Chen if (!msgs->buf) { 808ce38815dSXudong Chen dev_dbg(i2c->dev, "data buffer is NULL.\n"); 809ce38815dSXudong Chen ret = -EINVAL; 810ce38815dSXudong Chen goto err_exit; 811ce38815dSXudong Chen } 812ce38815dSXudong Chen 813ce38815dSXudong Chen if (msgs->flags & I2C_M_RD) 814ce38815dSXudong Chen i2c->op = I2C_MASTER_RD; 815ce38815dSXudong Chen else 816ce38815dSXudong Chen i2c->op = I2C_MASTER_WR; 817ce38815dSXudong Chen 818173b77e8SLiguo Zhang if (!i2c->auto_restart) { 819ce38815dSXudong Chen if (num > 1) { 820ce38815dSXudong Chen /* combined two messages into one transaction */ 821ce38815dSXudong Chen i2c->op = I2C_MASTER_WRRD; 822ce38815dSXudong Chen left_num--; 823ce38815dSXudong Chen } 824b2ed11e2SEddie Huang } 825ce38815dSXudong Chen 826ce38815dSXudong Chen /* always use DMA mode. */ 827b2ed11e2SEddie Huang ret = mtk_i2c_do_transfer(i2c, msgs, num, left_num); 828ce38815dSXudong Chen if (ret < 0) 829ce38815dSXudong Chen goto err_exit; 830ce38815dSXudong Chen 831b2ed11e2SEddie Huang msgs++; 832b2ed11e2SEddie Huang } 833ce38815dSXudong Chen /* the return value is number of executed messages */ 834ce38815dSXudong Chen ret = num; 835ce38815dSXudong Chen 836ce38815dSXudong Chen err_exit: 837ce38815dSXudong Chen mtk_i2c_clock_disable(i2c); 838ce38815dSXudong Chen return ret; 839ce38815dSXudong Chen } 840ce38815dSXudong Chen 841ce38815dSXudong Chen static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id) 842ce38815dSXudong Chen { 843ce38815dSXudong Chen struct mtk_i2c *i2c = dev_id; 844b2ed11e2SEddie Huang u16 restart_flag = 0; 84528c0a843SEddie Huang u16 intr_stat; 846b2ed11e2SEddie Huang 847173b77e8SLiguo Zhang if (i2c->auto_restart) 848b2ed11e2SEddie Huang restart_flag = I2C_RS_TRANSFER; 849ce38815dSXudong Chen 850bc6eaf17SQii Wang intr_stat = mtk_i2c_readw(i2c, OFFSET_INTR_STAT); 851bc6eaf17SQii Wang mtk_i2c_writew(i2c, intr_stat, OFFSET_INTR_STAT); 852ce38815dSXudong Chen 85328c0a843SEddie Huang /* 85428c0a843SEddie Huang * when occurs ack error, i2c controller generate two interrupts 85528c0a843SEddie Huang * first is the ack error interrupt, then the complete interrupt 85628c0a843SEddie Huang * i2c->irq_stat need keep the two interrupt value. 85728c0a843SEddie Huang */ 85828c0a843SEddie Huang i2c->irq_stat |= intr_stat; 8598378d01fSLiguo Zhang 8608378d01fSLiguo Zhang if (i2c->ignore_restart_irq && (i2c->irq_stat & restart_flag)) { 8618378d01fSLiguo Zhang i2c->ignore_restart_irq = false; 8628378d01fSLiguo Zhang i2c->irq_stat = 0; 863bc6eaf17SQii Wang mtk_i2c_writew(i2c, I2C_RS_MUL_CNFG | I2C_RS_MUL_TRIG | 864bc6eaf17SQii Wang I2C_TRANSAC_START, OFFSET_START); 8658378d01fSLiguo Zhang } else { 86628c0a843SEddie Huang if (i2c->irq_stat & (I2C_TRANSAC_COMP | restart_flag)) 867ce38815dSXudong Chen complete(&i2c->msg_complete); 8688378d01fSLiguo Zhang } 869ce38815dSXudong Chen 870ce38815dSXudong Chen return IRQ_HANDLED; 871ce38815dSXudong Chen } 872ce38815dSXudong Chen 873ce38815dSXudong Chen static u32 mtk_i2c_functionality(struct i2c_adapter *adap) 874ce38815dSXudong Chen { 87562931ac2SFabien Parent if (i2c_check_quirks(adap, I2C_AQ_NO_ZERO_LEN)) 876abf4923eSHsin-Yi Wang return I2C_FUNC_I2C | 877abf4923eSHsin-Yi Wang (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); 878abf4923eSHsin-Yi Wang else 879ce38815dSXudong Chen return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 880ce38815dSXudong Chen } 881ce38815dSXudong Chen 882ce38815dSXudong Chen static const struct i2c_algorithm mtk_i2c_algorithm = { 883ce38815dSXudong Chen .master_xfer = mtk_i2c_transfer, 884ce38815dSXudong Chen .functionality = mtk_i2c_functionality, 885ce38815dSXudong Chen }; 886ce38815dSXudong Chen 887f2326401SJun Gao static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c) 888ce38815dSXudong Chen { 889ce38815dSXudong Chen int ret; 890ce38815dSXudong Chen 891ce38815dSXudong Chen ret = of_property_read_u32(np, "clock-frequency", &i2c->speed_hz); 892ce38815dSXudong Chen if (ret < 0) 893*90224e64SAndy Shevchenko i2c->speed_hz = I2C_MAX_STANDARD_MODE_FREQ; 894ce38815dSXudong Chen 895f2326401SJun Gao ret = of_property_read_u32(np, "clock-div", &i2c->clk_src_div); 896ce38815dSXudong Chen if (ret < 0) 897ce38815dSXudong Chen return ret; 898ce38815dSXudong Chen 899f2326401SJun Gao if (i2c->clk_src_div == 0) 900ce38815dSXudong Chen return -EINVAL; 901ce38815dSXudong Chen 902ce38815dSXudong Chen i2c->have_pmic = of_property_read_bool(np, "mediatek,have-pmic"); 903ce38815dSXudong Chen i2c->use_push_pull = 904ce38815dSXudong Chen of_property_read_bool(np, "mediatek,use-push-pull"); 905ce38815dSXudong Chen 906ce38815dSXudong Chen return 0; 907ce38815dSXudong Chen } 908ce38815dSXudong Chen 909ce38815dSXudong Chen static int mtk_i2c_probe(struct platform_device *pdev) 910ce38815dSXudong Chen { 911ce38815dSXudong Chen int ret = 0; 912ce38815dSXudong Chen struct mtk_i2c *i2c; 913ce38815dSXudong Chen struct clk *clk; 914ce38815dSXudong Chen struct resource *res; 915ce38815dSXudong Chen int irq; 916ce38815dSXudong Chen 917ce38815dSXudong Chen i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 918ce38815dSXudong Chen if (!i2c) 919ce38815dSXudong Chen return -ENOMEM; 920ce38815dSXudong Chen 921ce38815dSXudong Chen res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 922ce38815dSXudong Chen i2c->base = devm_ioremap_resource(&pdev->dev, res); 923ce38815dSXudong Chen if (IS_ERR(i2c->base)) 924ce38815dSXudong Chen return PTR_ERR(i2c->base); 925ce38815dSXudong Chen 926ce38815dSXudong Chen res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 927ce38815dSXudong Chen i2c->pdmabase = devm_ioremap_resource(&pdev->dev, res); 928ce38815dSXudong Chen if (IS_ERR(i2c->pdmabase)) 929ce38815dSXudong Chen return PTR_ERR(i2c->pdmabase); 930ce38815dSXudong Chen 931ce38815dSXudong Chen irq = platform_get_irq(pdev, 0); 932ce38815dSXudong Chen if (irq <= 0) 933ce38815dSXudong Chen return irq; 934ce38815dSXudong Chen 935ce38815dSXudong Chen init_completion(&i2c->msg_complete); 936ce38815dSXudong Chen 9376e29577fSRyder Lee i2c->dev_comp = of_device_get_match_data(&pdev->dev); 938ce38815dSXudong Chen i2c->adap.dev.of_node = pdev->dev.of_node; 939ce38815dSXudong Chen i2c->dev = &pdev->dev; 940ce38815dSXudong Chen i2c->adap.dev.parent = &pdev->dev; 941ce38815dSXudong Chen i2c->adap.owner = THIS_MODULE; 942ce38815dSXudong Chen i2c->adap.algo = &mtk_i2c_algorithm; 943ce38815dSXudong Chen i2c->adap.quirks = i2c->dev_comp->quirks; 944ce38815dSXudong Chen i2c->adap.timeout = 2 * HZ; 945ce38815dSXudong Chen i2c->adap.retries = 1; 946ce38815dSXudong Chen 9475a10e7d7SJun Gao ret = mtk_i2c_parse_dt(pdev->dev.of_node, i2c); 9485a10e7d7SJun Gao if (ret) 9495a10e7d7SJun Gao return -EINVAL; 9505a10e7d7SJun Gao 9515a10e7d7SJun Gao if (i2c->dev_comp->timing_adjust) 9525a10e7d7SJun Gao i2c->clk_src_div *= I2C_DEFAULT_CLK_DIV; 9535a10e7d7SJun Gao 954ce38815dSXudong Chen if (i2c->have_pmic && !i2c->dev_comp->pmic_i2c) 955ce38815dSXudong Chen return -EINVAL; 956ce38815dSXudong Chen 957ce38815dSXudong Chen i2c->clk_main = devm_clk_get(&pdev->dev, "main"); 958ce38815dSXudong Chen if (IS_ERR(i2c->clk_main)) { 959ce38815dSXudong Chen dev_err(&pdev->dev, "cannot get main clock\n"); 960ce38815dSXudong Chen return PTR_ERR(i2c->clk_main); 961ce38815dSXudong Chen } 962ce38815dSXudong Chen 963ce38815dSXudong Chen i2c->clk_dma = devm_clk_get(&pdev->dev, "dma"); 964ce38815dSXudong Chen if (IS_ERR(i2c->clk_dma)) { 965ce38815dSXudong Chen dev_err(&pdev->dev, "cannot get dma clock\n"); 966ce38815dSXudong Chen return PTR_ERR(i2c->clk_dma); 967ce38815dSXudong Chen } 968ce38815dSXudong Chen 969cad6dc5dSQii Wang i2c->clk_arb = devm_clk_get(&pdev->dev, "arb"); 970cad6dc5dSQii Wang if (IS_ERR(i2c->clk_arb)) 971cad6dc5dSQii Wang i2c->clk_arb = NULL; 972cad6dc5dSQii Wang 973ce38815dSXudong Chen clk = i2c->clk_main; 974ce38815dSXudong Chen if (i2c->have_pmic) { 975ce38815dSXudong Chen i2c->clk_pmic = devm_clk_get(&pdev->dev, "pmic"); 976ce38815dSXudong Chen if (IS_ERR(i2c->clk_pmic)) { 977ce38815dSXudong Chen dev_err(&pdev->dev, "cannot get pmic clock\n"); 978ce38815dSXudong Chen return PTR_ERR(i2c->clk_pmic); 979ce38815dSXudong Chen } 980ce38815dSXudong Chen clk = i2c->clk_pmic; 981ce38815dSXudong Chen } 982ce38815dSXudong Chen 983ce38815dSXudong Chen strlcpy(i2c->adap.name, I2C_DRV_NAME, sizeof(i2c->adap.name)); 984ce38815dSXudong Chen 985f2326401SJun Gao ret = mtk_i2c_set_speed(i2c, clk_get_rate(clk)); 986ce38815dSXudong Chen if (ret) { 987ce38815dSXudong Chen dev_err(&pdev->dev, "Failed to set the speed.\n"); 988ce38815dSXudong Chen return -EINVAL; 989ce38815dSXudong Chen } 990ce38815dSXudong Chen 991f4f4fed6SLiguo Zhang if (i2c->dev_comp->support_33bits) { 992f4f4fed6SLiguo Zhang ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(33)); 993f4f4fed6SLiguo Zhang if (ret) { 994f4f4fed6SLiguo Zhang dev_err(&pdev->dev, "dma_set_mask return error.\n"); 995f4f4fed6SLiguo Zhang return ret; 996f4f4fed6SLiguo Zhang } 997f4f4fed6SLiguo Zhang } 998f4f4fed6SLiguo Zhang 999ce38815dSXudong Chen ret = mtk_i2c_clock_enable(i2c); 1000ce38815dSXudong Chen if (ret) { 1001ce38815dSXudong Chen dev_err(&pdev->dev, "clock enable failed!\n"); 1002ce38815dSXudong Chen return ret; 1003ce38815dSXudong Chen } 1004ce38815dSXudong Chen mtk_i2c_init_hw(i2c); 1005ce38815dSXudong Chen mtk_i2c_clock_disable(i2c); 1006ce38815dSXudong Chen 1007ce38815dSXudong Chen ret = devm_request_irq(&pdev->dev, irq, mtk_i2c_irq, 1008ce38815dSXudong Chen IRQF_TRIGGER_NONE, I2C_DRV_NAME, i2c); 1009ce38815dSXudong Chen if (ret < 0) { 1010ce38815dSXudong Chen dev_err(&pdev->dev, 1011ce38815dSXudong Chen "Request I2C IRQ %d fail\n", irq); 1012ce38815dSXudong Chen return ret; 1013ce38815dSXudong Chen } 1014ce38815dSXudong Chen 1015ce38815dSXudong Chen i2c_set_adapdata(&i2c->adap, i2c); 1016ce38815dSXudong Chen ret = i2c_add_adapter(&i2c->adap); 1017ea734404SWolfram Sang if (ret) 1018ce38815dSXudong Chen return ret; 1019ce38815dSXudong Chen 1020ce38815dSXudong Chen platform_set_drvdata(pdev, i2c); 1021ce38815dSXudong Chen 1022ce38815dSXudong Chen return 0; 1023ce38815dSXudong Chen } 1024ce38815dSXudong Chen 1025ce38815dSXudong Chen static int mtk_i2c_remove(struct platform_device *pdev) 1026ce38815dSXudong Chen { 1027ce38815dSXudong Chen struct mtk_i2c *i2c = platform_get_drvdata(pdev); 1028ce38815dSXudong Chen 1029ce38815dSXudong Chen i2c_del_adapter(&i2c->adap); 1030ce38815dSXudong Chen 1031ce38815dSXudong Chen return 0; 1032ce38815dSXudong Chen } 1033ce38815dSXudong Chen 103409027e08SLiguo Zhang #ifdef CONFIG_PM_SLEEP 103509027e08SLiguo Zhang static int mtk_i2c_resume(struct device *dev) 103609027e08SLiguo Zhang { 1037f6762cedSJun Gao int ret; 103809027e08SLiguo Zhang struct mtk_i2c *i2c = dev_get_drvdata(dev); 103909027e08SLiguo Zhang 1040f6762cedSJun Gao ret = mtk_i2c_clock_enable(i2c); 1041f6762cedSJun Gao if (ret) { 1042f6762cedSJun Gao dev_err(dev, "clock enable failed!\n"); 1043f6762cedSJun Gao return ret; 1044f6762cedSJun Gao } 1045f6762cedSJun Gao 104609027e08SLiguo Zhang mtk_i2c_init_hw(i2c); 104709027e08SLiguo Zhang 1048f6762cedSJun Gao mtk_i2c_clock_disable(i2c); 1049f6762cedSJun Gao 105009027e08SLiguo Zhang return 0; 105109027e08SLiguo Zhang } 105209027e08SLiguo Zhang #endif 105309027e08SLiguo Zhang 105409027e08SLiguo Zhang static const struct dev_pm_ops mtk_i2c_pm = { 105509027e08SLiguo Zhang SET_SYSTEM_SLEEP_PM_OPS(NULL, mtk_i2c_resume) 105609027e08SLiguo Zhang }; 105709027e08SLiguo Zhang 1058ce38815dSXudong Chen static struct platform_driver mtk_i2c_driver = { 1059ce38815dSXudong Chen .probe = mtk_i2c_probe, 1060ce38815dSXudong Chen .remove = mtk_i2c_remove, 1061ce38815dSXudong Chen .driver = { 1062ce38815dSXudong Chen .name = I2C_DRV_NAME, 106309027e08SLiguo Zhang .pm = &mtk_i2c_pm, 1064ce38815dSXudong Chen .of_match_table = of_match_ptr(mtk_i2c_of_match), 1065ce38815dSXudong Chen }, 1066ce38815dSXudong Chen }; 1067ce38815dSXudong Chen 1068ce38815dSXudong Chen module_platform_driver(mtk_i2c_driver); 1069ce38815dSXudong Chen 1070ce38815dSXudong Chen MODULE_LICENSE("GPL v2"); 1071ce38815dSXudong Chen MODULE_DESCRIPTION("MediaTek I2C Bus Driver"); 1072ce38815dSXudong Chen MODULE_AUTHOR("Xudong Chen <xudong.chen@mediatek.com>"); 1073