drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / src / soc / mediatek / mt8188 / i2c.c
blobedfe5102022b62e573b4dfd20caa5bf783ce19e7
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
3 /*
4 * This file is created based on MT8188 Functional Specification
5 * Chapter number: 5.11
6 */
8 #include <assert.h>
9 #include <console/console.h>
10 #include <device/i2c_simple.h>
11 #include <device/mmio.h>
12 #include <gpio.h>
13 #include <soc/i2c.h>
15 struct mtk_i2c mtk_i2c_bus_controller[] = {
16 [0] = {
17 .i2c_regs = (void *)(I2C0_BASE),
18 .i2c_dma_regs = (void *)(I2C0_DMA_BASE),
19 .mt_i2c_flag = I2C_APDMA_ASYNC,
21 [1] = {
22 .i2c_regs = (void *)(I2C1_BASE),
23 .i2c_dma_regs = (void *)(I2C1_DMA_BASE),
24 .mt_i2c_flag = I2C_APDMA_ASYNC,
26 [2] = {
27 .i2c_regs = (void *)(I2C2_BASE),
28 .i2c_dma_regs = (void *)(I2C2_DMA_BASE),
29 .mt_i2c_flag = I2C_APDMA_ASYNC,
31 [3] = {
32 .i2c_regs = (void *)(I2C3_BASE),
33 .i2c_dma_regs = (void *)(I2C3_DMA_BASE),
34 .mt_i2c_flag = I2C_APDMA_ASYNC,
36 [4] = {
37 .i2c_regs = (void *)(I2C4_BASE),
38 .i2c_dma_regs = (void *)(I2C4_DMA_BASE),
39 .mt_i2c_flag = I2C_APDMA_ASYNC,
41 [5] = {
42 .i2c_regs = (void *)(I2C5_BASE),
43 .i2c_dma_regs = (void *)(I2C5_DMA_BASE),
44 .mt_i2c_flag = I2C_APDMA_ASYNC,
46 [6] = {
47 .i2c_regs = (void *)(I2C6_BASE),
48 .i2c_dma_regs = (void *)(I2C6_DMA_BASE),
49 .mt_i2c_flag = I2C_APDMA_ASYNC,
53 _Static_assert(ARRAY_SIZE(mtk_i2c_bus_controller) == I2C_BUS_NUMBER,
54 "Wrong size of mtk_i2c_bus_controller");
56 static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
57 [0] = {
58 PAD_FUNC_UP(SDA0, SDA0),
59 PAD_FUNC_UP(SCL0, SCL0),
61 [1] = {
62 PAD_FUNC_UP(SDA1, SDA1),
63 PAD_FUNC_UP(SCL1, SCL1),
65 [2] = {
66 PAD_FUNC_UP(SDA2, SDA2),
67 PAD_FUNC_UP(SCL2, SCL2),
69 [3] = {
70 PAD_FUNC_UP(SDA3, SDA3),
71 PAD_FUNC_UP(SCL3, SCL3),
73 [4] = {
74 PAD_FUNC_UP(SDA4, SDA4),
75 PAD_FUNC_UP(SCL4, SCL4),
77 [5] = {
78 PAD_FUNC_UP(SDA5, SDA5),
79 PAD_FUNC_UP(SCL5, SCL5),
81 [6] = {
82 PAD_FUNC_UP(SDA6, SDA6),
83 PAD_FUNC_UP(SCL6, SCL6),
87 static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
89 assert(bus < I2C_BUS_NUMBER);
91 const struct pad_func *ptr = i2c_funcs[bus];
92 for (size_t i = 0; i < 2; i++) {
93 gpio_set_mode(ptr[i].gpio, ptr[i].func);
94 gpio_set_pull(ptr[i].gpio, GPIO_PULL_ENABLE, ptr[i].select);
98 void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
100 mtk_i2c_speed_init(bus, speed);
101 mtk_i2c_set_gpio_pinmux(bus);
104 void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
106 printk(BIOS_DEBUG, "LTIMING %x\nCLK_DIV %x\n",
107 read32(&regs->ltiming),
108 read32(&regs->clock_div));
111 void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
113 write32(&regs->clock_div, bus_ctrl->ac_timing.inter_clk_div);
114 write32(&regs->timing, bus_ctrl->ac_timing.htiming);
115 write32(&regs->ltiming, bus_ctrl->ac_timing.ltiming);
116 write32(&regs->hs, bus_ctrl->ac_timing.hs);
117 write32(&regs->ext_conf, bus_ctrl->ac_timing.ext);