aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2016-09-07 16:51:10 -0400
committerMark Brown <broonie@kernel.org>2016-09-12 14:58:45 -0400
commite33a3ade909194ec2ca633a53b428d4dac853f8a (patch)
tree062f7bde9da24321aea7a3ff5c2d1896499b1fde
parent7c159aa8c103b02a8434ae18b22048952c796e6f (diff)
spi: fsl-espi: remove element status from struct fsl_espi_transfer
Use the return values of the functions in the call chain to transport status information instead of using an element in struct fsl_espi_transfer for this. This is more in line with the general approach how to handle status information and is one step further to eventually get rid of struct fsl_espi_transfer completely. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-fsl-espi.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index 8e6ef9b153d7..5f01b6595442 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -42,7 +42,6 @@ struct fsl_espi_transfer {
42 void *rx_buf; 42 void *rx_buf;
43 unsigned len; 43 unsigned len;
44 unsigned actual_length; 44 unsigned actual_length;
45 int status;
46}; 45};
47 46
48/* eSPI Controller mode register definitions */ 47/* eSPI Controller mode register definitions */
@@ -269,14 +268,14 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t)
269 return mpc8xxx_spi->count; 268 return mpc8xxx_spi->count;
270} 269}
271 270
272static void fsl_espi_do_trans(struct spi_message *m, 271static int fsl_espi_do_trans(struct spi_message *m,
273 struct fsl_espi_transfer *tr) 272 struct fsl_espi_transfer *tr)
274{ 273{
275 struct spi_device *spi = m->spi; 274 struct spi_device *spi = m->spi;
276 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master); 275 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
277 struct fsl_espi_transfer *espi_trans = tr; 276 struct fsl_espi_transfer *espi_trans = tr;
278 struct spi_transfer *t, *first, trans; 277 struct spi_transfer *t, *first, trans;
279 int status = 0; 278 int ret = 0;
280 279
281 memset(&trans, 0, sizeof(trans)); 280 memset(&trans, 0, sizeof(trans));
282 281
@@ -285,10 +284,9 @@ static void fsl_espi_do_trans(struct spi_message *m,
285 list_for_each_entry(t, &m->transfers, transfer_list) { 284 list_for_each_entry(t, &m->transfers, transfer_list) {
286 if ((first->bits_per_word != t->bits_per_word) || 285 if ((first->bits_per_word != t->bits_per_word) ||
287 (first->speed_hz != t->speed_hz)) { 286 (first->speed_hz != t->speed_hz)) {
288 espi_trans->status = -EINVAL;
289 dev_err(mspi->dev, 287 dev_err(mspi->dev,
290 "bits_per_word/speed_hz should be same for the same SPI transfer\n"); 288 "bits_per_word/speed_hz should be same for the same SPI transfer\n");
291 return; 289 return -EINVAL;
292 } 290 }
293 291
294 trans.speed_hz = t->speed_hz; 292 trans.speed_hz = t->speed_hz;
@@ -303,52 +301,59 @@ static void fsl_espi_do_trans(struct spi_message *m,
303 fsl_espi_setup_transfer(spi, &trans); 301 fsl_espi_setup_transfer(spi, &trans);
304 302
305 if (trans.len) 303 if (trans.len)
306 status = fsl_espi_bufs(spi, &trans); 304 ret = fsl_espi_bufs(spi, &trans);
307 305
308 if (status) 306 if (ret)
309 status = -EMSGSIZE; 307 ret = -EMSGSIZE;
310 308
311 if (trans.delay_usecs) 309 if (trans.delay_usecs)
312 udelay(trans.delay_usecs); 310 udelay(trans.delay_usecs);
313 311
314 espi_trans->status = status;
315 fsl_espi_setup_transfer(spi, NULL); 312 fsl_espi_setup_transfer(spi, NULL);
313
314 return ret;
316} 315}
317 316
318static void fsl_espi_cmd_trans(struct spi_message *m, 317static int fsl_espi_cmd_trans(struct spi_message *m,
319 struct fsl_espi_transfer *trans, u8 *rx_buff) 318 struct fsl_espi_transfer *trans, u8 *rx_buff)
320{ 319{
321 struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); 320 struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master);
322 struct fsl_espi_transfer *espi_trans = trans; 321 struct fsl_espi_transfer *espi_trans = trans;
322 int ret;
323 323
324 fsl_espi_copy_to_buf(m, mspi); 324 fsl_espi_copy_to_buf(m, mspi);
325 325
326 espi_trans->tx_buf = mspi->local_buf; 326 espi_trans->tx_buf = mspi->local_buf;
327 espi_trans->rx_buf = mspi->local_buf; 327 espi_trans->rx_buf = mspi->local_buf;
328 fsl_espi_do_trans(m, espi_trans); 328 ret = fsl_espi_do_trans(m, espi_trans);
329 329
330 espi_trans->actual_length = espi_trans->len; 330 espi_trans->actual_length = espi_trans->len;
331
332 return ret;
331} 333}
332 334
333static void fsl_espi_rw_trans(struct spi_message *m, 335static int fsl_espi_rw_trans(struct spi_message *m,
334 struct fsl_espi_transfer *trans, u8 *rx_buff) 336 struct fsl_espi_transfer *trans, u8 *rx_buff)
335{ 337{
336 struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); 338 struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master);
337 unsigned int tx_only; 339 unsigned int tx_only;
340 int ret;
338 341
339 tx_only = fsl_espi_copy_to_buf(m, mspi); 342 tx_only = fsl_espi_copy_to_buf(m, mspi);
340 343
341 trans->tx_buf = mspi->local_buf; 344 trans->tx_buf = mspi->local_buf;
342 trans->rx_buf = mspi->local_buf; 345 trans->rx_buf = mspi->local_buf;
343 fsl_espi_do_trans(m, trans); 346 ret = fsl_espi_do_trans(m, trans);
344 347
345 if (!trans->status) { 348 if (!ret) {
346 /* If there is at least one RX byte then copy it to rx_buff */ 349 /* If there is at least one RX byte then copy it to rx_buff */
347 if (trans->len > tx_only) 350 if (trans->len > tx_only)
348 memcpy(rx_buff, trans->rx_buf + tx_only, 351 memcpy(rx_buff, trans->rx_buf + tx_only,
349 trans->len - tx_only); 352 trans->len - tx_only);
350 trans->actual_length += trans->len; 353 trans->actual_length += trans->len;
351 } 354 }
355
356 return ret;
352} 357}
353 358
354static int fsl_espi_do_one_msg(struct spi_master *master, 359static int fsl_espi_do_one_msg(struct spi_master *master,
@@ -358,6 +363,7 @@ static int fsl_espi_do_one_msg(struct spi_master *master,
358 u8 *rx_buf = NULL; 363 u8 *rx_buf = NULL;
359 unsigned int xfer_len = 0; 364 unsigned int xfer_len = 0;
360 struct fsl_espi_transfer espi_trans; 365 struct fsl_espi_transfer espi_trans;
366 int ret;
361 367
362 list_for_each_entry(t, &m->transfers, transfer_list) { 368 list_for_each_entry(t, &m->transfers, transfer_list) {
363 if (t->rx_buf) 369 if (t->rx_buf)
@@ -368,15 +374,14 @@ static int fsl_espi_do_one_msg(struct spi_master *master,
368 374
369 espi_trans.len = xfer_len; 375 espi_trans.len = xfer_len;
370 espi_trans.actual_length = 0; 376 espi_trans.actual_length = 0;
371 espi_trans.status = 0;
372 377
373 if (!rx_buf) 378 if (!rx_buf)
374 fsl_espi_cmd_trans(m, &espi_trans, NULL); 379 ret = fsl_espi_cmd_trans(m, &espi_trans, NULL);
375 else 380 else
376 fsl_espi_rw_trans(m, &espi_trans, rx_buf); 381 ret = fsl_espi_rw_trans(m, &espi_trans, rx_buf);
377 382
378 m->actual_length = espi_trans.actual_length; 383 m->actual_length = espi_trans.actual_length;
379 m->status = espi_trans.status; 384 m->status = ret;
380 spi_finalize_current_message(master); 385 spi_finalize_current_message(master);
381 return 0; 386 return 0;
382} 387}