Skip to content

Commit 908d984

Browse files
Qii Wangwsakernel
authored andcommitted
i2c: mediatek: Add access to more than 8GB dram in i2c driver
Newer MTK chip support more than 8GB of dram. Replace support_33bits with more general dma_max_support and remove mtk_i2c_set_4g_mode. Reviewed-by: Yingjoe Chen <[email protected]> Signed-off-by: Qii Wang <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 8426fe7 commit 908d984

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

drivers/i2c/busses/i2c-mt65xx.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#define I2C_DMA_INT_FLAG_NONE 0x0000
5656
#define I2C_DMA_CLR_FLAG 0x0000
5757
#define I2C_DMA_HARD_RST 0x0002
58-
#define I2C_DMA_4G_MODE 0x0001
5958

6059
#define MAX_SAMPLE_CNT_DIV 8
6160
#define MAX_STEP_CNT_DIV 64
@@ -204,11 +203,11 @@ struct mtk_i2c_compatible {
204203
unsigned char dcm: 1;
205204
unsigned char auto_restart: 1;
206205
unsigned char aux_len_reg: 1;
207-
unsigned char support_33bits: 1;
208206
unsigned char timing_adjust: 1;
209207
unsigned char dma_sync: 1;
210208
unsigned char ltiming_adjust: 1;
211209
unsigned char apdma_sync: 1;
210+
unsigned char max_dma_support;
212211
};
213212

214213
struct mtk_i2c_ac_timing {
@@ -311,11 +310,11 @@ static const struct mtk_i2c_compatible mt2712_compat = {
311310
.dcm = 1,
312311
.auto_restart = 1,
313312
.aux_len_reg = 1,
314-
.support_33bits = 1,
315313
.timing_adjust = 1,
316314
.dma_sync = 0,
317315
.ltiming_adjust = 0,
318316
.apdma_sync = 0,
317+
.max_dma_support = 33,
319318
};
320319

321320
static const struct mtk_i2c_compatible mt6577_compat = {
@@ -325,11 +324,11 @@ static const struct mtk_i2c_compatible mt6577_compat = {
325324
.dcm = 1,
326325
.auto_restart = 0,
327326
.aux_len_reg = 0,
328-
.support_33bits = 0,
329327
.timing_adjust = 0,
330328
.dma_sync = 0,
331329
.ltiming_adjust = 0,
332330
.apdma_sync = 0,
331+
.max_dma_support = 32,
333332
};
334333

335334
static const struct mtk_i2c_compatible mt6589_compat = {
@@ -339,11 +338,11 @@ static const struct mtk_i2c_compatible mt6589_compat = {
339338
.dcm = 0,
340339
.auto_restart = 0,
341340
.aux_len_reg = 0,
342-
.support_33bits = 0,
343341
.timing_adjust = 0,
344342
.dma_sync = 0,
345343
.ltiming_adjust = 0,
346344
.apdma_sync = 0,
345+
.max_dma_support = 32,
347346
};
348347

349348
static const struct mtk_i2c_compatible mt7622_compat = {
@@ -353,11 +352,11 @@ static const struct mtk_i2c_compatible mt7622_compat = {
353352
.dcm = 1,
354353
.auto_restart = 1,
355354
.aux_len_reg = 1,
356-
.support_33bits = 0,
357355
.timing_adjust = 0,
358356
.dma_sync = 0,
359357
.ltiming_adjust = 0,
360358
.apdma_sync = 0,
359+
.max_dma_support = 32,
361360
};
362361

363362
static const struct mtk_i2c_compatible mt8173_compat = {
@@ -366,11 +365,11 @@ static const struct mtk_i2c_compatible mt8173_compat = {
366365
.dcm = 1,
367366
.auto_restart = 1,
368367
.aux_len_reg = 1,
369-
.support_33bits = 1,
370368
.timing_adjust = 0,
371369
.dma_sync = 0,
372370
.ltiming_adjust = 0,
373371
.apdma_sync = 0,
372+
.max_dma_support = 33,
374373
};
375374

376375
static const struct mtk_i2c_compatible mt8183_compat = {
@@ -380,11 +379,11 @@ static const struct mtk_i2c_compatible mt8183_compat = {
380379
.dcm = 0,
381380
.auto_restart = 1,
382381
.aux_len_reg = 1,
383-
.support_33bits = 1,
384382
.timing_adjust = 1,
385383
.dma_sync = 1,
386384
.ltiming_adjust = 1,
387385
.apdma_sync = 0,
386+
.max_dma_support = 33,
388387
};
389388

390389
static const struct of_device_id mtk_i2c_of_match[] = {
@@ -796,11 +795,6 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
796795
return 0;
797796
}
798797

799-
static inline u32 mtk_i2c_set_4g_mode(dma_addr_t addr)
800-
{
801-
return (addr & BIT_ULL(32)) ? I2C_DMA_4G_MODE : I2C_DMA_CLR_FLAG;
802-
}
803-
804798
static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
805799
int num, int left_num)
806800
{
@@ -885,8 +879,8 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
885879
return -ENOMEM;
886880
}
887881

888-
if (i2c->dev_comp->support_33bits) {
889-
reg_4g_mode = mtk_i2c_set_4g_mode(rpaddr);
882+
if (i2c->dev_comp->max_dma_support > 32) {
883+
reg_4g_mode = upper_32_bits(rpaddr);
890884
writel(reg_4g_mode, i2c->pdmabase + OFFSET_RX_4G_MODE);
891885
}
892886

@@ -908,8 +902,8 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
908902
return -ENOMEM;
909903
}
910904

911-
if (i2c->dev_comp->support_33bits) {
912-
reg_4g_mode = mtk_i2c_set_4g_mode(wpaddr);
905+
if (i2c->dev_comp->max_dma_support > 32) {
906+
reg_4g_mode = upper_32_bits(wpaddr);
913907
writel(reg_4g_mode, i2c->pdmabase + OFFSET_TX_4G_MODE);
914908
}
915909

@@ -954,11 +948,11 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
954948
return -ENOMEM;
955949
}
956950

957-
if (i2c->dev_comp->support_33bits) {
958-
reg_4g_mode = mtk_i2c_set_4g_mode(wpaddr);
951+
if (i2c->dev_comp->max_dma_support > 32) {
952+
reg_4g_mode = upper_32_bits(wpaddr);
959953
writel(reg_4g_mode, i2c->pdmabase + OFFSET_TX_4G_MODE);
960954

961-
reg_4g_mode = mtk_i2c_set_4g_mode(rpaddr);
955+
reg_4g_mode = upper_32_bits(rpaddr);
962956
writel(reg_4g_mode, i2c->pdmabase + OFFSET_RX_4G_MODE);
963957
}
964958

@@ -1232,8 +1226,9 @@ static int mtk_i2c_probe(struct platform_device *pdev)
12321226
return -EINVAL;
12331227
}
12341228

1235-
if (i2c->dev_comp->support_33bits) {
1236-
ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(33));
1229+
if (i2c->dev_comp->max_dma_support > 32) {
1230+
ret = dma_set_mask(&pdev->dev,
1231+
DMA_BIT_MASK(i2c->dev_comp->max_dma_support));
12371232
if (ret) {
12381233
dev_err(&pdev->dev, "dma_set_mask return error.\n");
12391234
return ret;

0 commit comments

Comments
 (0)