fusb302的pd驱动代码
时间: 2023-11-22 21:54:28 浏览: 233
以下是fusb302的PD驱动代码示例,参考自Linux内核的驱动代码(fusb302.c):
```
static int fusb302_pd_send_message(struct fusb302_chip *chip,
enum tcpm_transmit_type type,
uint16_t header, const void *data,
size_t count)
{
int ret;
u8 buf[PDO_MAX_OBJECT_SIZE];
struct pd_message msg = {
.header = header,
.count = count,
.obj = buf,
};
struct tcpm_message tcpm_msg = {
.header = type,
.tx_data = &msg,
};
if (count > PDO_MAX_OBJECT_SIZE) {
dev_err(chip->dev, "message too long\n");
return -EINVAL;
}
memcpy(buf, data, count);
ret = chip->phy_ops->tcpm_transmit(chip, &tcpm_msg);
if (ret < 0)
dev_err(chip->dev, "failed to send message: %d\n", ret);
return ret;
}
```
此代码片段中,`fusb302_pd_send_message()`函数用于向FUSB302发送PD消息。该函数将消息打包为TCPM消息格式并传递给`tcpm_transmit()`函数以进行发送。`tcpm_transmit()`函数是由FUSB302 PHY驱动程序提供的函数,用于将TCPM消息传递给FUSB302芯片进行发送。
阅读全文