SPI 可以通过组包的方式 发送4次8bit 组成一次32bit
//线传输地址,再传输要传送的值 线传输低位,再传输高位
addr = TCAN4X5X_WRITE_CMD | (*((u16 *)reg) << 8) | val_len >> 2;
txaddr[0] = (addr >> 24) & 0xff;
txaddr[1] = (addr >> 16) & 0xff;
txaddr[2] = (addr >> 8) & 0xff;
txaddr[3] = (addr >> 0) & 0xff;
txval[0] = (*(u32 *)val >> 24) & 0xff;
txval[1] = (*(u32 *)val >> 16) & 0xff;
txval[2] = (*(u32 *)val >> 8) & 0xff;
txval[3] = (*(u32 *)val >> 0) & 0xff;
struct spi_transfer t[8] = {
{
.tx_buf = &txaddr[0],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txaddr[1],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txaddr[2],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txaddr[3],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txval[0],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txval[1],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txval[2],
.len = 1,
.cs_change = 0,
},
{
.tx_buf = &txval[3],
.len = val_len,
},
};
// printk("txbuf:%x %x %x %x %x\n", txaddr, txaddr[0], txaddr[1],
// txaddr[2], txaddr[3]);
// printk("txval:%x %x %x %x %x\n", *(u32 *)val, txval[0], txval[1],
// txval[2], txval[3]);
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
spi_message_add_tail(&t[2], &m);
spi_message_add_tail(&t[3], &m);
spi_message_add_tail(&t[4], &m);
spi_message_add_tail(&t[5], &m);
spi_message_add_tail(&t[6], &m);
spi_message_add_tail(&t[7], &m);