diff options
Diffstat (limited to 'drivers/spi/spi-sc18is602.c')
-rw-r--r-- | drivers/spi/spi-sc18is602.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/drivers/spi/spi-sc18is602.c b/drivers/spi/spi-sc18is602.c index 121c2e1dea36..237f2e7a7179 100644 --- a/drivers/spi/spi-sc18is602.c +++ b/drivers/spi/spi-sc18is602.c | |||
@@ -183,17 +183,9 @@ static int sc18is602_setup_transfer(struct sc18is602 *hw, u32 hz, u8 mode) | |||
183 | static int sc18is602_check_transfer(struct spi_device *spi, | 183 | static int sc18is602_check_transfer(struct spi_device *spi, |
184 | struct spi_transfer *t, int tlen) | 184 | struct spi_transfer *t, int tlen) |
185 | { | 185 | { |
186 | uint32_t hz; | ||
187 | |||
188 | if (t && t->len + tlen > SC18IS602_BUFSIZ) | 186 | if (t && t->len + tlen > SC18IS602_BUFSIZ) |
189 | return -EINVAL; | 187 | return -EINVAL; |
190 | 188 | ||
191 | hz = spi->max_speed_hz; | ||
192 | if (t && t->speed_hz) | ||
193 | hz = t->speed_hz; | ||
194 | if (hz == 0) | ||
195 | return -EINVAL; | ||
196 | |||
197 | return 0; | 189 | return 0; |
198 | } | 190 | } |
199 | 191 | ||
@@ -205,22 +197,15 @@ static int sc18is602_transfer_one(struct spi_master *master, | |||
205 | struct spi_transfer *t; | 197 | struct spi_transfer *t; |
206 | int status = 0; | 198 | int status = 0; |
207 | 199 | ||
208 | /* SC18IS602 does not support CS2 */ | ||
209 | if (hw->id == sc18is602 && spi->chip_select == 2) { | ||
210 | status = -ENXIO; | ||
211 | goto error; | ||
212 | } | ||
213 | |||
214 | hw->tlen = 0; | 200 | hw->tlen = 0; |
215 | list_for_each_entry(t, &m->transfers, transfer_list) { | 201 | list_for_each_entry(t, &m->transfers, transfer_list) { |
216 | u32 hz = t->speed_hz ? : spi->max_speed_hz; | ||
217 | bool do_transfer; | 202 | bool do_transfer; |
218 | 203 | ||
219 | status = sc18is602_check_transfer(spi, t, hw->tlen); | 204 | status = sc18is602_check_transfer(spi, t, hw->tlen); |
220 | if (status < 0) | 205 | if (status < 0) |
221 | break; | 206 | break; |
222 | 207 | ||
223 | status = sc18is602_setup_transfer(hw, hz, spi->mode); | 208 | status = sc18is602_setup_transfer(hw, t->speed_hz, spi->mode); |
224 | if (status < 0) | 209 | if (status < 0) |
225 | break; | 210 | break; |
226 | 211 | ||
@@ -238,7 +223,6 @@ static int sc18is602_transfer_one(struct spi_master *master, | |||
238 | if (t->delay_usecs) | 223 | if (t->delay_usecs) |
239 | udelay(t->delay_usecs); | 224 | udelay(t->delay_usecs); |
240 | } | 225 | } |
241 | error: | ||
242 | m->status = status; | 226 | m->status = status; |
243 | spi_finalize_current_message(master); | 227 | spi_finalize_current_message(master); |
244 | 228 | ||
@@ -247,10 +231,13 @@ error: | |||
247 | 231 | ||
248 | static int sc18is602_setup(struct spi_device *spi) | 232 | static int sc18is602_setup(struct spi_device *spi) |
249 | { | 233 | { |
250 | if (spi->mode & ~(SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST)) | 234 | struct sc18is602 *hw = spi_master_get_devdata(spi->master); |
251 | return -EINVAL; | ||
252 | 235 | ||
253 | return sc18is602_check_transfer(spi, NULL, 0); | 236 | /* SC18IS602 does not support CS2 */ |
237 | if (hw->id == sc18is602 && spi->chip_select == 2) | ||
238 | return -ENXIO; | ||
239 | |||
240 | return 0; | ||
254 | } | 241 | } |
255 | 242 | ||
256 | static int sc18is602_probe(struct i2c_client *client, | 243 | static int sc18is602_probe(struct i2c_client *client, |
@@ -309,6 +296,8 @@ static int sc18is602_probe(struct i2c_client *client, | |||
309 | master->setup = sc18is602_setup; | 296 | master->setup = sc18is602_setup; |
310 | master->transfer_one_message = sc18is602_transfer_one; | 297 | master->transfer_one_message = sc18is602_transfer_one; |
311 | master->dev.of_node = np; | 298 | master->dev.of_node = np; |
299 | master->min_speed_hz = hw->freq / 128; | ||
300 | master->max_speed_hz = hw->freq / 4; | ||
312 | 301 | ||
313 | error = devm_spi_register_master(dev, master); | 302 | error = devm_spi_register_master(dev, master); |
314 | if (error) | 303 | if (error) |