Skip to content

Commit 923dc37

Browse files
henryrovxiaoxiang781216
authored andcommitted
risc-v/bl808: Add I2C driver
This change implements a driver with support for all four I2C blocks on the BL808.
1 parent 41c0fc0 commit 923dc37

File tree

13 files changed

+1234
-10
lines changed

13 files changed

+1234
-10
lines changed

Documentation/platforms/risc-v/bl808/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ DMA No
4848
EMAC No
4949
GPADC Yes
5050
GPIO Yes
51-
I2C No
51+
I2C Yes
5252
I2S No
5353
PWM No
5454
SPI Yes

arch/risc-v/include/bl808/irq.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
/* D0 IRQs ******************************************************************/
5555

5656
#define BL808_IRQ_UART3 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + 4)
57+
#define BL808_IRQ_I2C2 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + 5)
58+
#define BL808_IRQ_I2C3 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + 6)
5759
#define BL808_IRQ_SPI1 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + 7)
5860
#define BL808_IRQ_D0_IPC (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + 38)
5961
#define BL808_IRQ_TIMER1_CH0 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + 61)
@@ -68,8 +70,10 @@
6870
#define BL808_IRQ_UART0 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 28)
6971
#define BL808_IRQ_UART1 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 29)
7072
#define BL808_IRQ_UART2 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 30)
73+
#define BL808_IRQ_I2C0 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 32)
7174
#define BL808_IRQ_TIMER0_CH0 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 36)
7275
#define BL808_IRQ_TIMER0_CH1 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 37)
7376
#define BL808_IRQ_WDT0 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 38)
77+
#define BL808_IRQ_I2C1 (RISCV_IRQ_SEXT + BL808_IRQ_NUM_BASE + BL808_M0_IRQ_OFFSET + 39)
7478

7579
#endif /* __ARCH_RISCV_INCLUDE_BL808_IRQ_H */

arch/risc-v/src/bl808/Kconfig

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,98 @@ config BL808_GPADC_SCAN_ORD11
106106

107107
endmenu
108108

109+
menuconfig BL808_I2C0
110+
bool "I2C 0"
111+
default n
112+
select I2C
113+
select I2C_DRIVER
114+
select ARCH_HAVE_I2CRESET
115+
116+
if BL808_I2C0
117+
118+
comment "Refer to datasheet for valid pin assignments"
119+
120+
config BL808_I2C0_SCL
121+
int "SCL Pin"
122+
default 6
123+
range 0 45
124+
125+
config BL808_I2C0_SDA
126+
int "SDA Pin"
127+
default 7
128+
range 0 45
129+
130+
endif
131+
132+
menuconfig BL808_I2C1
133+
bool "I2C 1"
134+
default n
135+
select I2C
136+
select I2C_DRIVER
137+
select ARCH_HAVE_I2CRESET
138+
139+
if BL808_I2C1
140+
141+
comment "Refer to datasheet for valid pin assignments"
142+
143+
config BL808_I2C1_SCL
144+
int "SCL Pin"
145+
default 6
146+
range 0 45
147+
148+
config BL808_I2C1_SDA
149+
int "SDA Pin"
150+
default 7
151+
range 0 45
152+
153+
endif
154+
155+
menuconfig BL808_I2C2
156+
bool "I2C 2"
157+
default n
158+
select I2C
159+
select I2C_DRIVER
160+
select ARCH_HAVE_I2CRESET
161+
162+
if BL808_I2C2
163+
164+
comment "Refer to datasheet for valid pin assignments"
165+
166+
config BL808_I2C2_SCL
167+
int "SCL Pin"
168+
default 6
169+
range 0 45
170+
171+
config BL808_I2C2_SDA
172+
int "SDA Pin"
173+
default 7
174+
range 0 45
175+
176+
endif
177+
178+
menuconfig BL808_I2C3
179+
bool "I2C 3"
180+
default n
181+
select I2C
182+
select I2C_DRIVER
183+
select ARCH_HAVE_I2CRESET
184+
185+
if BL808_I2C3
186+
187+
comment "Refer to datasheet for valid pin assignments"
188+
189+
config BL808_I2C3_SCL
190+
int "SCL Pin"
191+
default 6
192+
range 0 45
193+
194+
config BL808_I2C3_SDA
195+
int "SDA Pin"
196+
default 7
197+
range 0 45
198+
199+
endif
200+
109201
config BL808_UART0
110202
bool "UART 0"
111203
default n

arch/risc-v/src/bl808/Make.defs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ CHIP_CSRCS = bl808_start.c bl808_irq_dispatch.c bl808_irq.c
3131
CHIP_CSRCS += bl808_timerisr.c bl808_allocateheap.c
3232
CHIP_CSRCS += bl808_gpio.c bl808_mm_init.c bl808_pgalloc.c bl808_serial.c
3333
CHIP_CSRCS += bl808_gpadc.c bl808_spi.c bl808_timer.c bl808_wdt.c
34+
CHIP_CSRCS += bl808_i2c.c

arch/risc-v/src/bl808/bl808_gpio.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858

5959
#define GPIO_MODE_SHIFT (10) /* Bit 10: Port Mode */
6060
#define GPIO_MODE_MASK (1 << GPIO_MODE_SHIFT)
61-
# define GPIO_INPUT (1 << GPIO_MODE_SHIFT) /* Input Enable */
62-
# define GPIO_OUTPUT (0 << GPIO_MODE_SHIFT) /* Output Enable */
61+
#define GPIO_INPUT (1 << GPIO_MODE_SHIFT) /* Input Enable */
62+
#define GPIO_OUTPUT (0 << GPIO_MODE_SHIFT) /* Output Enable */
6363

6464
/* Input/Output pull-ups/downs:
6565
*
@@ -116,13 +116,16 @@
116116
#define GPIO_FUNC_SDH (0 << GPIO_FUNC_SHIFT) /* SDH */
117117
#define GPIO_FUNC_SPI0 (1 << GPIO_FUNC_SHIFT) /* SPI0 */
118118
#define GPIO_FUNC_FLASH (2 << GPIO_FUNC_SHIFT) /* Flash */
119+
#define GPIO_FUNC_I2C0 (5 << GPIO_FUNC_SHIFT) /* I2C0 */
119120
#define GPIO_FUNC_I2C1 (6 << GPIO_FUNC_SHIFT) /* I2C1 */
120121
#define GPIO_FUNC_UART (7 << GPIO_FUNC_SHIFT) /* UART */
121122
#define GPIO_FUNC_CAM (9 << GPIO_FUNC_SHIFT) /* CSI */
122123
#define GPIO_FUNC_ANA (10 << GPIO_FUNC_SHIFT) /* Analog */
123124
#define GPIO_FUNC_SWGPIO (11 << GPIO_FUNC_SHIFT) /* Software GPIO */
124125
#define GPIO_FUNC_PWM0 (16 << GPIO_FUNC_SHIFT) /* PWM0 */
125126
#define GPIO_FUNC_SPI1 (18 << GPIO_FUNC_SHIFT) /* SPI1 */
127+
#define GPIO_FUNC_I2C2 (19 << GPIO_FUNC_SHIFT) /* I2C2 */
128+
#define GPIO_FUNC_I2C3 (20 << GPIO_FUNC_SHIFT) /* I2C3 */
126129
#define GPIO_FUNC_JTAG_D0 (27 << GPIO_FUNC_SHIFT) /* JTAG */
127130

128131
/****************************************************************************

0 commit comments

Comments
 (0)