10 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <linux/i2c.h>
16 #include <asm/unaligned.h>
18 #define SPI_XCOMM_SETTINGS_LEN_OFFSET 10
19 #define SPI_XCOMM_SETTINGS_3WIRE BIT(6)
20 #define SPI_XCOMM_SETTINGS_CS_HIGH BIT(5)
21 #define SPI_XCOMM_SETTINGS_SAMPLE_END BIT(4)
22 #define SPI_XCOMM_SETTINGS_CPHA BIT(3)
23 #define SPI_XCOMM_SETTINGS_CPOL BIT(2)
24 #define SPI_XCOMM_SETTINGS_CLOCK_DIV_MASK 0x3
25 #define SPI_XCOMM_SETTINGS_CLOCK_DIV_64 0x2
26 #define SPI_XCOMM_SETTINGS_CLOCK_DIV_16 0x1
27 #define SPI_XCOMM_SETTINGS_CLOCK_DIV_4 0x0
29 #define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03
30 #define SPI_XCOMM_CMD_WRITE 0x04
32 #define SPI_XCOMM_CLOCK 48000000
54 put_unaligned_be16(settings, &buf[1]);
55 put_unaligned_be16(spi_xcomm->
chipselect, &buf[3]);
67 chipselect |=
BIT(cs);
69 chipselect &= ~
BIT(cs);
74 static int spi_xcomm_setup_transfer(
struct spi_xcomm *spi_xcomm,
88 else if (divider >= 16)
114 static int spi_xcomm_txrx_bufs(
struct spi_xcomm *spi_xcomm,
126 else if (ret != t->
len + 1)
132 else if (ret != t->
len)
139 static int spi_xcomm_transfer_one(
struct spi_master *master,
142 struct spi_xcomm *spi_xcomm = spi_master_get_devdata(master);
143 unsigned int settings = spi_xcomm->
settings;
145 unsigned cs_change = 0;
147 bool is_first =
true;
153 spi_xcomm_chipselect(spi_xcomm, spi,
true);
162 status = spi_xcomm_setup_transfer(spi_xcomm, spi, t, &settings);
169 if (cs_change ^ is_last)
176 status = spi_xcomm_sync_config(spi_xcomm, t->
len);
179 }
else if (settings != spi_xcomm->
settings || is_first) {
181 status = spi_xcomm_sync_config(spi_xcomm, 0);
187 status = spi_xcomm_txrx_bufs(spi_xcomm, spi, t);
203 if (status != 0 || !cs_change)
204 spi_xcomm_chipselect(spi_xcomm, spi,
false);
212 static int spi_xcomm_setup(
struct spi_device *spi)
223 struct spi_xcomm *spi_xcomm;
231 spi_xcomm = spi_master_get_devdata(master);
232 spi_xcomm->
i2c = i2c;
237 master->
setup = spi_xcomm_setup;
239 master->
dev.of_node = i2c->
dev.of_node;
240 i2c_set_clientdata(i2c, master);
244 spi_master_put(master);
251 struct spi_master *master = i2c_get_clientdata(i2c);
268 .id_table = spi_xcomm_ids,
269 .probe = spi_xcomm_probe,