1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
4 #include <console/console.h>
5 #include <device/i2c_simple.h>
15 [0]{.scl
= GPIO(0, C
, 0), .sda
= GPIO(0, B
, 7)},
16 [1]{.scl
= GPIO(8, A
, 5), .sda
= GPIO(8, A
, 4)},
17 [2]{.scl
= GPIO(6, B
, 2), .sda
= GPIO(6, B
, 1)},
18 [3]{.scl
= GPIO(2, C
, 0), .sda
= GPIO(2, C
, 1)},
19 [4]{.scl
= GPIO(7, C
, 2), .sda
= GPIO(7, C
, 1)},
20 [5]{.scl
= GPIO(7, C
, 4), .sda
= GPIO(7, C
, 3)},
23 static int get_scl(unsigned int bus
)
25 return gpio_get(pins
[bus
].scl
);
28 static int get_sda(unsigned int bus
)
30 return gpio_get(pins
[bus
].sda
);
33 static void set_scl(unsigned int bus
, int high
)
36 gpio_input_pullup(pins
[bus
].scl
);
38 gpio_output(pins
[bus
].scl
, 0);
41 static void set_sda(unsigned int bus
, int high
)
44 gpio_input_pullup(pins
[bus
].sda
);
46 gpio_output(pins
[bus
].sda
, 0);
49 static struct software_i2c_ops rk_ops
= {
56 void software_i2c_attach(unsigned int bus
)
58 software_i2c
[bus
] = &rk_ops
;
60 /* Mux pins to GPIO function for software I2C emulation. */
63 clrbits32(&rk3288_pmu
->iomux_i2c0scl
, IOMUX_I2C0SCL
);
64 clrbits32(&rk3288_pmu
->iomux_i2c0sda
, IOMUX_I2C0SDA
);
67 write32(&rk3288_grf
->iomux_i2c1
, IOMUX_GPIO(IOMUX_I2C1
));
70 write32(&rk3288_grf
->iomux_i2c2
, IOMUX_GPIO(IOMUX_I2C2
));
73 write32(&rk3288_grf
->iomux_i2c3
, IOMUX_GPIO(IOMUX_I2C3
));
76 write32(&rk3288_grf
->iomux_i2c4
, IOMUX_GPIO(IOMUX_I2C4
));
79 write32(&rk3288_grf
->iomux_i2c5scl
, IOMUX_GPIO(IOMUX_I2C5SCL
));
80 write32(&rk3288_grf
->iomux_i2c5sda
, IOMUX_GPIO(IOMUX_I2C5SDA
));
83 die("Unknown I2C bus number!");
86 /* Initialize bus to idle state. */
91 void software_i2c_detach(unsigned int bus
)
93 software_i2c
[bus
] = NULL
;
95 /* Mux pins back to hardware I2C controller. */
98 setbits32(&rk3288_pmu
->iomux_i2c0scl
, IOMUX_I2C0SCL
);
99 setbits32(&rk3288_pmu
->iomux_i2c0sda
, IOMUX_I2C0SDA
);
102 write32(&rk3288_grf
->iomux_i2c1
, IOMUX_I2C1
);
105 write32(&rk3288_grf
->iomux_i2c2
, IOMUX_I2C2
);
108 write32(&rk3288_grf
->iomux_i2c3
, IOMUX_I2C3
);
111 write32(&rk3288_grf
->iomux_i2c4
, IOMUX_I2C4
);
114 write32(&rk3288_grf
->iomux_i2c5scl
, IOMUX_I2C5SCL
);
115 write32(&rk3288_grf
->iomux_i2c5sda
, IOMUX_I2C5SDA
);
118 die("Unknown I2C bus number!");