• Home
  • Raw
  • Download

Lines Matching +full:ctrl +full:- +full:len

4  * Copyright (C) Guenter Roeck <linux@roeck-us.net>
45 u8 ctrl; member
59 static int sc18is602_wait_ready(struct sc18is602 *hw, int len) in sc18is602_wait_ready() argument
62 int usecs = 1000000 * len / hw->speed + 1; in sc18is602_wait_ready()
66 err = i2c_master_recv(hw->client, dummy, 1); in sc18is602_wait_ready()
71 return -ETIMEDOUT; in sc18is602_wait_ready()
77 unsigned int len = t->len; in sc18is602_txrx() local
80 if (hw->tlen == 0) { in sc18is602_txrx()
82 hw->buffer[0] = 1 << msg->spi->chip_select; in sc18is602_txrx()
83 hw->tlen = 1; in sc18is602_txrx()
84 hw->rindex = 0; in sc18is602_txrx()
91 if (t->tx_buf) { in sc18is602_txrx()
92 memcpy(&hw->buffer[hw->tlen], t->tx_buf, len); in sc18is602_txrx()
93 hw->tlen += len; in sc18is602_txrx()
94 if (t->rx_buf) in sc18is602_txrx()
97 hw->rindex = hw->tlen - 1; in sc18is602_txrx()
98 } else if (t->rx_buf) { in sc18is602_txrx()
100 * For receive-only transfers we still need to perform a dummy in sc18is602_txrx()
105 hw->rindex = hw->tlen - 1; in sc18is602_txrx()
106 memset(&hw->buffer[hw->tlen], 0, len); in sc18is602_txrx()
107 hw->tlen += len; in sc18is602_txrx()
111 if (do_transfer && hw->tlen > 1) { in sc18is602_txrx()
115 ret = i2c_master_send(hw->client, hw->buffer, hw->tlen); in sc18is602_txrx()
118 if (ret != hw->tlen) in sc18is602_txrx()
119 return -EIO; in sc18is602_txrx()
121 if (t->rx_buf) { in sc18is602_txrx()
122 int rlen = hw->rindex + len; in sc18is602_txrx()
124 ret = sc18is602_wait_ready(hw, hw->tlen); in sc18is602_txrx()
127 ret = i2c_master_recv(hw->client, hw->buffer, rlen); in sc18is602_txrx()
131 return -EIO; in sc18is602_txrx()
132 memcpy(t->rx_buf, &hw->buffer[hw->rindex], len); in sc18is602_txrx()
134 hw->tlen = 0; in sc18is602_txrx()
136 return len; in sc18is602_txrx()
141 u8 ctrl = 0; in sc18is602_setup_transfer() local
145 ctrl |= SC18IS602_MODE_CPHA; in sc18is602_setup_transfer()
147 ctrl |= SC18IS602_MODE_CPOL; in sc18is602_setup_transfer()
149 ctrl |= SC18IS602_MODE_LSB_FIRST; in sc18is602_setup_transfer()
152 if (hz >= hw->freq / 4) { in sc18is602_setup_transfer()
153 ctrl |= SC18IS602_MODE_CLOCK_DIV_4; in sc18is602_setup_transfer()
154 hw->speed = hw->freq / 4; in sc18is602_setup_transfer()
155 } else if (hz >= hw->freq / 16) { in sc18is602_setup_transfer()
156 ctrl |= SC18IS602_MODE_CLOCK_DIV_16; in sc18is602_setup_transfer()
157 hw->speed = hw->freq / 16; in sc18is602_setup_transfer()
158 } else if (hz >= hw->freq / 64) { in sc18is602_setup_transfer()
159 ctrl |= SC18IS602_MODE_CLOCK_DIV_64; in sc18is602_setup_transfer()
160 hw->speed = hw->freq / 64; in sc18is602_setup_transfer()
162 ctrl |= SC18IS602_MODE_CLOCK_DIV_128; in sc18is602_setup_transfer()
163 hw->speed = hw->freq / 128; in sc18is602_setup_transfer()
168 * value of 0xff for hw->ctrl ensures that the correct mode will be set in sc18is602_setup_transfer()
171 if (ctrl == hw->ctrl) in sc18is602_setup_transfer()
174 ret = i2c_smbus_write_byte_data(hw->client, 0xf0, ctrl); in sc18is602_setup_transfer()
178 hw->ctrl = ctrl; in sc18is602_setup_transfer()
186 if (t && t->len + tlen > SC18IS602_BUFSIZ) in sc18is602_check_transfer()
187 return -EINVAL; in sc18is602_check_transfer()
196 struct spi_device *spi = m->spi; in sc18is602_transfer_one()
200 hw->tlen = 0; in sc18is602_transfer_one()
201 list_for_each_entry(t, &m->transfers, transfer_list) { in sc18is602_transfer_one()
204 status = sc18is602_check_transfer(spi, t, hw->tlen); in sc18is602_transfer_one()
208 status = sc18is602_setup_transfer(hw, t->speed_hz, spi->mode); in sc18is602_transfer_one()
212 do_transfer = t->cs_change || list_is_last(&t->transfer_list, in sc18is602_transfer_one()
213 &m->transfers); in sc18is602_transfer_one()
215 if (t->len) { in sc18is602_transfer_one()
219 m->actual_length += status; in sc18is602_transfer_one()
223 if (t->delay_usecs) in sc18is602_transfer_one()
224 udelay(t->delay_usecs); in sc18is602_transfer_one()
226 m->status = status; in sc18is602_transfer_one()
234 struct sc18is602 *hw = spi_master_get_devdata(spi->master); in sc18is602_setup()
237 if (hw->id == sc18is602 && spi->chip_select == 2) in sc18is602_setup()
238 return -ENXIO; in sc18is602_setup()
246 struct device *dev = &client->dev; in sc18is602_probe()
247 struct device_node *np = dev->of_node; in sc18is602_probe()
253 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | in sc18is602_probe()
255 return -EINVAL; in sc18is602_probe()
259 return -ENOMEM; in sc18is602_probe()
265 hw->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in sc18is602_probe()
266 if (IS_ERR(hw->reset)) in sc18is602_probe()
267 return PTR_ERR(hw->reset); in sc18is602_probe()
268 gpiod_set_value_cansleep(hw->reset, 0); in sc18is602_probe()
270 hw->master = master; in sc18is602_probe()
271 hw->client = client; in sc18is602_probe()
272 hw->dev = dev; in sc18is602_probe()
273 hw->ctrl = 0xff; in sc18is602_probe()
275 if (client->dev.of_node) in sc18is602_probe()
276 hw->id = (enum chips)of_device_get_match_data(&client->dev); in sc18is602_probe()
278 hw->id = id->driver_data; in sc18is602_probe()
280 switch (hw->id) { in sc18is602_probe()
283 master->num_chipselect = 4; in sc18is602_probe()
284 hw->freq = SC18IS602_CLOCK; in sc18is602_probe()
287 master->num_chipselect = 2; in sc18is602_probe()
289 hw->freq = pdata->clock_frequency; in sc18is602_probe()
292 int len; in sc18is602_probe() local
294 val = of_get_property(np, "clock-frequency", &len); in sc18is602_probe()
295 if (val && len >= sizeof(__be32)) in sc18is602_probe()
296 hw->freq = be32_to_cpup(val); in sc18is602_probe()
298 if (!hw->freq) in sc18is602_probe()
299 hw->freq = SC18IS602_CLOCK; in sc18is602_probe()
302 master->bus_num = np ? -1 : client->adapter->nr; in sc18is602_probe()
303 master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST; in sc18is602_probe()
304 master->bits_per_word_mask = SPI_BPW_MASK(8); in sc18is602_probe()
305 master->setup = sc18is602_setup; in sc18is602_probe()
306 master->transfer_one_message = sc18is602_transfer_one; in sc18is602_probe()
307 master->dev.of_node = np; in sc18is602_probe()
308 master->min_speed_hz = hw->freq / 128; in sc18is602_probe()
309 master->max_speed_hz = hw->freq / 4; in sc18is602_probe()