Skip to content

Commit 2570827

Browse files
Qii WangWolfram Sang
authored andcommitted
i2c: mediatek: Add i2c support for MediaTek MT8183
Add i2c compatible for MT8183. Compare to MT2712 i2c controller, MT8183 has different register offsets. Ltiming_reg is added to adjust low width of SCL. Arb clock and dma_sync are needed. Signed-off-by: Qii Wang <qii.wang@mediatek.com> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent a15c91b commit 2570827

1 file changed

Lines changed: 60 additions & 2 deletions

File tree

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

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ enum I2C_REGS_OFFSET {
133133
OFFSET_DEBUGCTRL,
134134
OFFSET_TRANSFER_LEN_AUX,
135135
OFFSET_CLOCK_DIV,
136+
OFFSET_LTIMING,
136137
};
137138

138139
static const u16 mt_i2c_regs_v1[] = {
@@ -162,6 +163,32 @@ static const u16 mt_i2c_regs_v1[] = {
162163
[OFFSET_CLOCK_DIV] = 0x70,
163164
};
164165

166+
static const u16 mt_i2c_regs_v2[] = {
167+
[OFFSET_DATA_PORT] = 0x0,
168+
[OFFSET_SLAVE_ADDR] = 0x4,
169+
[OFFSET_INTR_MASK] = 0x8,
170+
[OFFSET_INTR_STAT] = 0xc,
171+
[OFFSET_CONTROL] = 0x10,
172+
[OFFSET_TRANSFER_LEN] = 0x14,
173+
[OFFSET_TRANSAC_LEN] = 0x18,
174+
[OFFSET_DELAY_LEN] = 0x1c,
175+
[OFFSET_TIMING] = 0x20,
176+
[OFFSET_START] = 0x24,
177+
[OFFSET_EXT_CONF] = 0x28,
178+
[OFFSET_LTIMING] = 0x2c,
179+
[OFFSET_HS] = 0x30,
180+
[OFFSET_IO_CONFIG] = 0x34,
181+
[OFFSET_FIFO_ADDR_CLR] = 0x38,
182+
[OFFSET_TRANSFER_LEN_AUX] = 0x44,
183+
[OFFSET_CLOCK_DIV] = 0x48,
184+
[OFFSET_SOFTRESET] = 0x50,
185+
[OFFSET_DEBUGSTAT] = 0xe0,
186+
[OFFSET_DEBUGCTRL] = 0xe8,
187+
[OFFSET_FIFO_STAT] = 0xf4,
188+
[OFFSET_FIFO_THRESH] = 0xf8,
189+
[OFFSET_DCM_EN] = 0xf88,
190+
};
191+
165192
struct mtk_i2c_compatible {
166193
const struct i2c_adapter_quirks *quirks;
167194
const u16 *regs;
@@ -172,6 +199,7 @@ struct mtk_i2c_compatible {
172199
unsigned char support_33bits: 1;
173200
unsigned char timing_adjust: 1;
174201
unsigned char dma_sync: 1;
202+
unsigned char ltiming_adjust: 1;
175203
};
176204

177205
struct mtk_i2c {
@@ -195,6 +223,7 @@ struct mtk_i2c {
195223
enum mtk_trans_op op;
196224
u16 timing_reg;
197225
u16 high_speed_reg;
226+
u16 ltiming_reg;
198227
unsigned char auto_restart;
199228
bool ignore_restart_irq;
200229
const struct mtk_i2c_compatible *dev_comp;
@@ -222,6 +251,7 @@ static const struct mtk_i2c_compatible mt2712_compat = {
222251
.support_33bits = 1,
223252
.timing_adjust = 1,
224253
.dma_sync = 0,
254+
.ltiming_adjust = 0,
225255
};
226256

227257
static const struct mtk_i2c_compatible mt6577_compat = {
@@ -234,6 +264,7 @@ static const struct mtk_i2c_compatible mt6577_compat = {
234264
.support_33bits = 0,
235265
.timing_adjust = 0,
236266
.dma_sync = 0,
267+
.ltiming_adjust = 0,
237268
};
238269

239270
static const struct mtk_i2c_compatible mt6589_compat = {
@@ -246,6 +277,7 @@ static const struct mtk_i2c_compatible mt6589_compat = {
246277
.support_33bits = 0,
247278
.timing_adjust = 0,
248279
.dma_sync = 0,
280+
.ltiming_adjust = 0,
249281
};
250282

251283
static const struct mtk_i2c_compatible mt7622_compat = {
@@ -258,6 +290,7 @@ static const struct mtk_i2c_compatible mt7622_compat = {
258290
.support_33bits = 0,
259291
.timing_adjust = 0,
260292
.dma_sync = 0,
293+
.ltiming_adjust = 0,
261294
};
262295

263296
static const struct mtk_i2c_compatible mt8173_compat = {
@@ -269,6 +302,19 @@ static const struct mtk_i2c_compatible mt8173_compat = {
269302
.support_33bits = 1,
270303
.timing_adjust = 0,
271304
.dma_sync = 0,
305+
.ltiming_adjust = 0,
306+
};
307+
308+
static const struct mtk_i2c_compatible mt8183_compat = {
309+
.regs = mt_i2c_regs_v2,
310+
.pmic_i2c = 0,
311+
.dcm = 0,
312+
.auto_restart = 1,
313+
.aux_len_reg = 1,
314+
.support_33bits = 1,
315+
.timing_adjust = 1,
316+
.dma_sync = 1,
317+
.ltiming_adjust = 1,
272318
};
273319

274320
static const struct of_device_id mtk_i2c_of_match[] = {
@@ -277,6 +323,7 @@ static const struct of_device_id mtk_i2c_of_match[] = {
277323
{ .compatible = "mediatek,mt6589-i2c", .data = &mt6589_compat },
278324
{ .compatible = "mediatek,mt7622-i2c", .data = &mt7622_compat },
279325
{ .compatible = "mediatek,mt8173-i2c", .data = &mt8173_compat },
326+
{ .compatible = "mediatek,mt8183-i2c", .data = &mt8183_compat },
280327
{}
281328
};
282329
MODULE_DEVICE_TABLE(of, mtk_i2c_of_match);
@@ -361,6 +408,8 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
361408

362409
mtk_i2c_writew(i2c, i2c->timing_reg, OFFSET_TIMING);
363410
mtk_i2c_writew(i2c, i2c->high_speed_reg, OFFSET_HS);
411+
if (i2c->dev_comp->ltiming_adjust)
412+
mtk_i2c_writew(i2c, i2c->ltiming_reg, OFFSET_LTIMING);
364413

365414
/* If use i2c pin from PMIC mt6397 side, need set PATH_DIR first */
366415
if (i2c->have_pmic)
@@ -460,6 +509,8 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
460509
unsigned int clk_src;
461510
unsigned int step_cnt;
462511
unsigned int sample_cnt;
512+
unsigned int l_step_cnt;
513+
unsigned int l_sample_cnt;
463514
unsigned int target_speed;
464515
int ret;
465516

@@ -469,11 +520,11 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
469520
if (target_speed > MAX_FS_MODE_SPEED) {
470521
/* Set master code speed register */
471522
ret = mtk_i2c_calculate_speed(i2c, clk_src, MAX_FS_MODE_SPEED,
472-
&step_cnt, &sample_cnt);
523+
&l_step_cnt, &l_sample_cnt);
473524
if (ret < 0)
474525
return ret;
475526

476-
i2c->timing_reg = (sample_cnt << 8) | step_cnt;
527+
i2c->timing_reg = (l_sample_cnt << 8) | l_step_cnt;
477528

478529
/* Set the high speed mode register */
479530
ret = mtk_i2c_calculate_speed(i2c, clk_src, target_speed,
@@ -483,6 +534,10 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
483534

484535
i2c->high_speed_reg = I2C_TIME_DEFAULT_VALUE |
485536
(sample_cnt << 12) | (step_cnt << 8);
537+
538+
if (i2c->dev_comp->ltiming_adjust)
539+
i2c->ltiming_reg = (l_sample_cnt << 6) | l_step_cnt |
540+
(sample_cnt << 12) | (step_cnt << 9);
486541
} else {
487542
ret = mtk_i2c_calculate_speed(i2c, clk_src, target_speed,
488543
&step_cnt, &sample_cnt);
@@ -493,6 +548,9 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
493548

494549
/* Disable the high speed transaction */
495550
i2c->high_speed_reg = I2C_TIME_CLR_VALUE;
551+
552+
if (i2c->dev_comp->ltiming_adjust)
553+
i2c->ltiming_reg = (sample_cnt << 6) | step_cnt;
496554
}
497555

498556
return 0;

0 commit comments

Comments
 (0)