21 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/i2c.h>
33 #define SC18IS602_BUFSIZ 200
34 #define SC18IS602_CLOCK 7372000
36 #define SC18IS602_MODE_CPHA BIT(2)
37 #define SC18IS602_MODE_CPOL BIT(3)
38 #define SC18IS602_MODE_LSB_FIRST BIT(5)
39 #define SC18IS602_MODE_CLOCK_DIV_4 0x0
40 #define SC18IS602_MODE_CLOCK_DIV_16 0x1
41 #define SC18IS602_MODE_CLOCK_DIV_64 0x2
42 #define SC18IS602_MODE_CLOCK_DIV_128 0x3
59 static int sc18is602_wait_ready(
struct sc18is602 *
hw,
int len)
65 for (i = 0; i < 10; i++) {
82 hw->
buffer[0] = 1 << msg->
spi->chip_select;
111 if (do_transfer && hw->
tlen > 1) {
122 int rlen = hw->
rindex + len;
124 ret = sc18is602_wait_ready(hw, hw->
tlen);
152 if (hz >= hw->
freq / 4) {
155 }
else if (hz >= hw->
freq / 16) {
158 }
else if (hz >= hw->
freq / 64) {
171 if (ctrl == hw->
ctrl)
207 static int sc18is602_transfer_one(
struct spi_master *master,
210 struct sc18is602 *hw = spi_master_get_devdata(master);
226 status = sc18is602_check_transfer(spi, t, hw->
tlen);
230 status = sc18is602_setup_transfer(hw, hz, spi->
mode);
238 status = sc18is602_txrx(hw, m, t, do_transfer);
255 static int sc18is602_setup(
struct spi_device *spi)
260 if (spi->
mode & ~(SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST))
263 return sc18is602_check_transfer(spi,
NULL, 0);
284 hw = spi_master_get_devdata(master);
285 i2c_set_clientdata(client, hw);
292 hw->
id =
id->driver_data;
309 if (val && len >=
sizeof(
__be32))
318 master->
setup = sc18is602_setup;
320 master->
dev.of_node = np;
329 spi_master_put(master);
333 static int sc18is602_remove(
struct i2c_client *client)
335 struct sc18is602 *hw = i2c_get_clientdata(client);
355 .probe = sc18is602_probe,
356 .remove = sc18is602_remove,
357 .id_table = sc18is602_id,