1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <console/console.h>
4 #include <device/i2c_simple.h>
10 static qup_config_t blsp1_qup0_config
= {
11 QUP_MINICORE_I2C_MASTER
,
18 static qup_config_t blsp1_qup1_config
= {
19 QUP_MINICORE_I2C_MASTER
,
26 static qup_config_t blsp1_qup2_config
= {
27 QUP_MINICORE_I2C_MASTER
,
34 static qup_config_t blsp1_qup3_config
= {
35 QUP_MINICORE_I2C_MASTER
,
42 static int i2c_read(uint32_t gsbi_id
, uint8_t slave
,
43 uint8_t *data
, int data_len
)
46 qup_return_t qup_ret
= 0;
48 memset(&obj
, 0, sizeof(obj
));
49 obj
.protocol
= QUP_MINICORE_I2C_MASTER
;
50 obj
.p
.iic
.addr
= slave
;
51 obj
.p
.iic
.data_len
= data_len
;
52 obj
.p
.iic
.data
= data
;
53 qup_ret
= qup_recv_data(gsbi_id
, &obj
);
55 if (qup_ret
!= QUP_SUCCESS
)
61 static int i2c_write(uint32_t gsbi_id
, uint8_t slave
,
62 uint8_t *data
, int data_len
, uint8_t stop_seq
)
65 qup_return_t qup_ret
= 0;
67 memset(&obj
, 0, sizeof(obj
));
68 obj
.protocol
= QUP_MINICORE_I2C_MASTER
;
69 obj
.p
.iic
.addr
= slave
;
70 obj
.p
.iic
.data_len
= data_len
;
71 obj
.p
.iic
.data
= data
;
72 qup_ret
= qup_send_data(gsbi_id
, &obj
, stop_seq
);
74 if (qup_ret
!= QUP_SUCCESS
)
80 static int i2c_init(blsp_qup_id_t id
)
82 qup_config_t
*qup_config
;
86 qup_config
= &blsp1_qup0_config
;
89 qup_config
= &blsp1_qup1_config
;
92 qup_config
= &blsp1_qup2_config
;
95 qup_config
= &blsp1_qup3_config
;
98 printk(BIOS_ERR
, "QUP configuration not defined for BLSP%d.\n",
103 if (qup_config
->initialized
)
106 if (blsp_i2c_init(id
)) {
107 printk(BIOS_ERR
, "failed to initialize blsp\n");
111 if (qup_init(id
, qup_config
)) {
112 printk(BIOS_ERR
, "failed to initialize qup\n");
116 if (qup_reset_i2c_master_status(id
)) {
117 printk(BIOS_ERR
, "failed to reset i2c master status\n");
121 qup_config
->initialized
= 1;
125 int platform_i2c_transfer(unsigned int bus
, struct i2c_msg
*segments
,
128 struct i2c_msg
*seg
= segments
;
134 while (!ret
&& seg_count
--) {
135 if (seg
->flags
& I2C_M_RD
)
136 ret
= i2c_read(bus
, seg
->slave
, seg
->buf
, seg
->len
);
138 ret
= i2c_write(bus
, seg
->slave
, seg
->buf
, seg
->len
,
139 (seg_count
? 0 : 1));
144 qup_set_state(bus
, QUP_STATE_RESET
);