aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMichal Nazarewicz <mina86@mina86.com>2013-12-08 10:35:09 -0500
committerMark Brown <broonie@linaro.org>2013-12-09 13:12:54 -0500
commit48c3fc93803a27bb9d2c79d718cf142974f080c8 (patch)
tree2dc231b0ad36511d418efb0f7b053a7e6b441936 /drivers
parent6ce4eac1f600b34f2f7f58f9cd8f0503d79e42ae (diff)
spi: tegra114: use u32 for 32-bit register values
Previously used “unsigned long” may lead to confusion should the code be compiled for 64-bit machine. This commit also removes some unused fields of the tegra_spi_data structure as well as removes duplicated #defines. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Tested-by: Stephen Warren <swarren@nvidia.com> Acked-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/spi-tegra114.c98
1 files changed, 34 insertions, 64 deletions
diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c
index aaecfb3ebf58..47b93cc4bd19 100644
--- a/drivers/spi/spi-tegra114.c
+++ b/drivers/spi/spi-tegra114.c
@@ -54,11 +54,8 @@
54#define SPI_CS_SS_VAL (1 << 20) 54#define SPI_CS_SS_VAL (1 << 20)
55#define SPI_CS_SW_HW (1 << 21) 55#define SPI_CS_SW_HW (1 << 21)
56/* SPI_CS_POL_INACTIVE bits are default high */ 56/* SPI_CS_POL_INACTIVE bits are default high */
57#define SPI_CS_POL_INACTIVE 22 57 /* n from 0 to 3 */
58#define SPI_CS_POL_INACTIVE_0 (1 << 22) 58#define SPI_CS_POL_INACTIVE(n) (1 << (22 + (n)))
59#define SPI_CS_POL_INACTIVE_1 (1 << 23)
60#define SPI_CS_POL_INACTIVE_2 (1 << 24)
61#define SPI_CS_POL_INACTIVE_3 (1 << 25)
62#define SPI_CS_POL_INACTIVE_MASK (0xF << 22) 59#define SPI_CS_POL_INACTIVE_MASK (0xF << 22)
63 60
64#define SPI_CS_SEL_0 (0 << 26) 61#define SPI_CS_SEL_0 (0 << 26)
@@ -165,9 +162,6 @@
165#define MAX_HOLD_CYCLES 16 162#define MAX_HOLD_CYCLES 16
166#define SPI_DEFAULT_SPEED 25000000 163#define SPI_DEFAULT_SPEED 25000000
167 164
168#define MAX_CHIP_SELECT 4
169#define SPI_FIFO_DEPTH 64
170
171struct tegra_spi_data { 165struct tegra_spi_data {
172 struct device *dev; 166 struct device *dev;
173 struct spi_master *master; 167 struct spi_master *master;
@@ -184,7 +178,6 @@ struct tegra_spi_data {
184 struct spi_device *cur_spi; 178 struct spi_device *cur_spi;
185 struct spi_device *cs_control; 179 struct spi_device *cs_control;
186 unsigned cur_pos; 180 unsigned cur_pos;
187 unsigned cur_len;
188 unsigned words_per_32bit; 181 unsigned words_per_32bit;
189 unsigned bytes_per_word; 182 unsigned bytes_per_word;
190 unsigned curr_dma_words; 183 unsigned curr_dma_words;
@@ -204,12 +197,10 @@ struct tegra_spi_data {
204 u32 rx_status; 197 u32 rx_status;
205 u32 status_reg; 198 u32 status_reg;
206 bool is_packed; 199 bool is_packed;
207 unsigned long packed_size;
208 200
209 u32 command1_reg; 201 u32 command1_reg;
210 u32 dma_control_reg; 202 u32 dma_control_reg;
211 u32 def_command1_reg; 203 u32 def_command1_reg;
212 u32 spi_cs_timing;
213 204
214 struct completion xfer_completion; 205 struct completion xfer_completion;
215 struct spi_transfer *curr_xfer; 206 struct spi_transfer *curr_xfer;
@@ -227,14 +218,14 @@ struct tegra_spi_data {
227static int tegra_spi_runtime_suspend(struct device *dev); 218static int tegra_spi_runtime_suspend(struct device *dev);
228static int tegra_spi_runtime_resume(struct device *dev); 219static int tegra_spi_runtime_resume(struct device *dev);
229 220
230static inline unsigned long tegra_spi_readl(struct tegra_spi_data *tspi, 221static inline u32 tegra_spi_readl(struct tegra_spi_data *tspi,
231 unsigned long reg) 222 unsigned long reg)
232{ 223{
233 return readl(tspi->base + reg); 224 return readl(tspi->base + reg);
234} 225}
235 226
236static inline void tegra_spi_writel(struct tegra_spi_data *tspi, 227static inline void tegra_spi_writel(struct tegra_spi_data *tspi,
237 unsigned long val, unsigned long reg) 228 u32 val, unsigned long reg)
238{ 229{
239 writel(val, tspi->base + reg); 230 writel(val, tspi->base + reg);
240 231
@@ -245,7 +236,7 @@ static inline void tegra_spi_writel(struct tegra_spi_data *tspi,
245 236
246static void tegra_spi_clear_status(struct tegra_spi_data *tspi) 237static void tegra_spi_clear_status(struct tegra_spi_data *tspi)
247{ 238{
248 unsigned long val; 239 u32 val;
249 240
250 /* Write 1 to clear status register */ 241 /* Write 1 to clear status register */
251 val = tegra_spi_readl(tspi, SPI_TRANS_STATUS); 242 val = tegra_spi_readl(tspi, SPI_TRANS_STATUS);
@@ -296,10 +287,9 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf(
296{ 287{
297 unsigned nbytes; 288 unsigned nbytes;
298 unsigned tx_empty_count; 289 unsigned tx_empty_count;
299 unsigned long fifo_status; 290 u32 fifo_status;
300 unsigned max_n_32bit; 291 unsigned max_n_32bit;
301 unsigned i, count; 292 unsigned i, count;
302 unsigned long x;
303 unsigned int written_words; 293 unsigned int written_words;
304 unsigned fifo_words_left; 294 unsigned fifo_words_left;
305 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos; 295 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
@@ -313,9 +303,9 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf(
313 nbytes = written_words * tspi->bytes_per_word; 303 nbytes = written_words * tspi->bytes_per_word;
314 max_n_32bit = DIV_ROUND_UP(nbytes, 4); 304 max_n_32bit = DIV_ROUND_UP(nbytes, 4);
315 for (count = 0; count < max_n_32bit; count++) { 305 for (count = 0; count < max_n_32bit; count++) {
316 x = 0; 306 u32 x = 0;
317 for (i = 0; (i < 4) && nbytes; i++, nbytes--) 307 for (i = 0; (i < 4) && nbytes; i++, nbytes--)
318 x |= (*tx_buf++) << (i*8); 308 x |= (u32)(*tx_buf++) << (i * 8);
319 tegra_spi_writel(tspi, x, SPI_TX_FIFO); 309 tegra_spi_writel(tspi, x, SPI_TX_FIFO);
320 } 310 }
321 } else { 311 } else {
@@ -323,10 +313,10 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf(
323 written_words = max_n_32bit; 313 written_words = max_n_32bit;
324 nbytes = written_words * tspi->bytes_per_word; 314 nbytes = written_words * tspi->bytes_per_word;
325 for (count = 0; count < max_n_32bit; count++) { 315 for (count = 0; count < max_n_32bit; count++) {
326 x = 0; 316 u32 x = 0;
327 for (i = 0; nbytes && (i < tspi->bytes_per_word); 317 for (i = 0; nbytes && (i < tspi->bytes_per_word);
328 i++, nbytes--) 318 i++, nbytes--)
329 x |= ((*tx_buf++) << i*8); 319 x |= (u32)(*tx_buf++) << (i * 8);
330 tegra_spi_writel(tspi, x, SPI_TX_FIFO); 320 tegra_spi_writel(tspi, x, SPI_TX_FIFO);
331 } 321 }
332 } 322 }
@@ -338,9 +328,8 @@ static unsigned int tegra_spi_read_rx_fifo_to_client_rxbuf(
338 struct tegra_spi_data *tspi, struct spi_transfer *t) 328 struct tegra_spi_data *tspi, struct spi_transfer *t)
339{ 329{
340 unsigned rx_full_count; 330 unsigned rx_full_count;
341 unsigned long fifo_status; 331 u32 fifo_status;
342 unsigned i, count; 332 unsigned i, count;
343 unsigned long x;
344 unsigned int read_words = 0; 333 unsigned int read_words = 0;
345 unsigned len; 334 unsigned len;
346 u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_rx_pos; 335 u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_rx_pos;
@@ -350,20 +339,16 @@ static unsigned int tegra_spi_read_rx_fifo_to_client_rxbuf(
350 if (tspi->is_packed) { 339 if (tspi->is_packed) {
351 len = tspi->curr_dma_words * tspi->bytes_per_word; 340 len = tspi->curr_dma_words * tspi->bytes_per_word;
352 for (count = 0; count < rx_full_count; count++) { 341 for (count = 0; count < rx_full_count; count++) {
353 x = tegra_spi_readl(tspi, SPI_RX_FIFO); 342 u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO);
354 for (i = 0; len && (i < 4); i++, len--) 343 for (i = 0; len && (i < 4); i++, len--)
355 *rx_buf++ = (x >> i*8) & 0xFF; 344 *rx_buf++ = (x >> i*8) & 0xFF;
356 } 345 }
357 tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word; 346 tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word;
358 read_words += tspi->curr_dma_words; 347 read_words += tspi->curr_dma_words;
359 } else { 348 } else {
360 unsigned int rx_mask; 349 u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
361 unsigned int bits_per_word = t->bits_per_word;
362
363 rx_mask = (1 << bits_per_word) - 1;
364 for (count = 0; count < rx_full_count; count++) { 350 for (count = 0; count < rx_full_count; count++) {
365 x = tegra_spi_readl(tspi, SPI_RX_FIFO); 351 u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO) & rx_mask;
366 x &= rx_mask;
367 for (i = 0; (i < tspi->bytes_per_word); i++) 352 for (i = 0; (i < tspi->bytes_per_word); i++)
368 *rx_buf++ = (x >> (i*8)) & 0xFF; 353 *rx_buf++ = (x >> (i*8)) & 0xFF;
369 } 354 }
@@ -376,27 +361,24 @@ static unsigned int tegra_spi_read_rx_fifo_to_client_rxbuf(
376static void tegra_spi_copy_client_txbuf_to_spi_txbuf( 361static void tegra_spi_copy_client_txbuf_to_spi_txbuf(
377 struct tegra_spi_data *tspi, struct spi_transfer *t) 362 struct tegra_spi_data *tspi, struct spi_transfer *t)
378{ 363{
379 unsigned len;
380
381 /* Make the dma buffer to read by cpu */ 364 /* Make the dma buffer to read by cpu */
382 dma_sync_single_for_cpu(tspi->dev, tspi->tx_dma_phys, 365 dma_sync_single_for_cpu(tspi->dev, tspi->tx_dma_phys,
383 tspi->dma_buf_size, DMA_TO_DEVICE); 366 tspi->dma_buf_size, DMA_TO_DEVICE);
384 367
385 if (tspi->is_packed) { 368 if (tspi->is_packed) {
386 len = tspi->curr_dma_words * tspi->bytes_per_word; 369 unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
387 memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len); 370 memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len);
388 } else { 371 } else {
389 unsigned int i; 372 unsigned int i;
390 unsigned int count; 373 unsigned int count;
391 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos; 374 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
392 unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word; 375 unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word;
393 unsigned int x;
394 376
395 for (count = 0; count < tspi->curr_dma_words; count++) { 377 for (count = 0; count < tspi->curr_dma_words; count++) {
396 x = 0; 378 u32 x = 0;
397 for (i = 0; consume && (i < tspi->bytes_per_word); 379 for (i = 0; consume && (i < tspi->bytes_per_word);
398 i++, consume--) 380 i++, consume--)
399 x |= ((*tx_buf++) << i * 8); 381 x |= (u32)(*tx_buf++) << (i * 8);
400 tspi->tx_dma_buf[count] = x; 382 tspi->tx_dma_buf[count] = x;
401 } 383 }
402 } 384 }
@@ -410,27 +392,21 @@ static void tegra_spi_copy_client_txbuf_to_spi_txbuf(
410static void tegra_spi_copy_spi_rxbuf_to_client_rxbuf( 392static void tegra_spi_copy_spi_rxbuf_to_client_rxbuf(
411 struct tegra_spi_data *tspi, struct spi_transfer *t) 393 struct tegra_spi_data *tspi, struct spi_transfer *t)
412{ 394{
413 unsigned len;
414
415 /* Make the dma buffer to read by cpu */ 395 /* Make the dma buffer to read by cpu */
416 dma_sync_single_for_cpu(tspi->dev, tspi->rx_dma_phys, 396 dma_sync_single_for_cpu(tspi->dev, tspi->rx_dma_phys,
417 tspi->dma_buf_size, DMA_FROM_DEVICE); 397 tspi->dma_buf_size, DMA_FROM_DEVICE);
418 398
419 if (tspi->is_packed) { 399 if (tspi->is_packed) {
420 len = tspi->curr_dma_words * tspi->bytes_per_word; 400 unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
421 memcpy(t->rx_buf + tspi->cur_rx_pos, tspi->rx_dma_buf, len); 401 memcpy(t->rx_buf + tspi->cur_rx_pos, tspi->rx_dma_buf, len);
422 } else { 402 } else {
423 unsigned int i; 403 unsigned int i;
424 unsigned int count; 404 unsigned int count;
425 unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos; 405 unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos;
426 unsigned int x; 406 u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
427 unsigned int rx_mask;
428 unsigned int bits_per_word = t->bits_per_word;
429 407
430 rx_mask = (1 << bits_per_word) - 1;
431 for (count = 0; count < tspi->curr_dma_words; count++) { 408 for (count = 0; count < tspi->curr_dma_words; count++) {
432 x = tspi->rx_dma_buf[count]; 409 u32 x = tspi->rx_dma_buf[count] & rx_mask;
433 x &= rx_mask;
434 for (i = 0; (i < tspi->bytes_per_word); i++) 410 for (i = 0; (i < tspi->bytes_per_word); i++)
435 *rx_buf++ = (x >> (i*8)) & 0xFF; 411 *rx_buf++ = (x >> (i*8)) & 0xFF;
436 } 412 }
@@ -490,16 +466,16 @@ static int tegra_spi_start_rx_dma(struct tegra_spi_data *tspi, int len)
490static int tegra_spi_start_dma_based_transfer( 466static int tegra_spi_start_dma_based_transfer(
491 struct tegra_spi_data *tspi, struct spi_transfer *t) 467 struct tegra_spi_data *tspi, struct spi_transfer *t)
492{ 468{
493 unsigned long val; 469 u32 val;
494 unsigned int len; 470 unsigned int len;
495 int ret = 0; 471 int ret = 0;
496 unsigned long status; 472 u32 status;
497 473
498 /* Make sure that Rx and Tx fifo are empty */ 474 /* Make sure that Rx and Tx fifo are empty */
499 status = tegra_spi_readl(tspi, SPI_FIFO_STATUS); 475 status = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
500 if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) { 476 if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) {
501 dev_err(tspi->dev, 477 dev_err(tspi->dev, "Rx/Tx fifo are not empty status 0x%08x\n",
502 "Rx/Tx fifo are not empty status 0x%08lx\n", status); 478 (unsigned)status);
503 return -EIO; 479 return -EIO;
504 } 480 }
505 481
@@ -564,7 +540,7 @@ static int tegra_spi_start_dma_based_transfer(
564static int tegra_spi_start_cpu_based_transfer( 540static int tegra_spi_start_cpu_based_transfer(
565 struct tegra_spi_data *tspi, struct spi_transfer *t) 541 struct tegra_spi_data *tspi, struct spi_transfer *t)
566{ 542{
567 unsigned long val; 543 u32 val;
568 unsigned cur_words; 544 unsigned cur_words;
569 545
570 if (tspi->cur_direction & DATA_DIR_TX) 546 if (tspi->cur_direction & DATA_DIR_TX)
@@ -677,13 +653,13 @@ static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi,
677 dma_release_channel(dma_chan); 653 dma_release_channel(dma_chan);
678} 654}
679 655
680static unsigned long tegra_spi_setup_transfer_one(struct spi_device *spi, 656static u32 tegra_spi_setup_transfer_one(struct spi_device *spi,
681 struct spi_transfer *t, bool is_first_of_msg) 657 struct spi_transfer *t, bool is_first_of_msg)
682{ 658{
683 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); 659 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
684 u32 speed = t->speed_hz; 660 u32 speed = t->speed_hz;
685 u8 bits_per_word = t->bits_per_word; 661 u8 bits_per_word = t->bits_per_word;
686 unsigned long command1; 662 u32 command1;
687 int req_mode; 663 int req_mode;
688 664
689 if (speed != tspi->cur_speed) { 665 if (speed != tspi->cur_speed) {
@@ -738,7 +714,7 @@ static unsigned long tegra_spi_setup_transfer_one(struct spi_device *spi,
738} 714}
739 715
740static int tegra_spi_start_transfer_one(struct spi_device *spi, 716static int tegra_spi_start_transfer_one(struct spi_device *spi,
741 struct spi_transfer *t, unsigned long command1) 717 struct spi_transfer *t, u32 command1)
742{ 718{
743 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); 719 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
744 unsigned total_fifo_words; 720 unsigned total_fifo_words;
@@ -763,8 +739,8 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi,
763 tegra_spi_writel(tspi, command1, SPI_COMMAND1); 739 tegra_spi_writel(tspi, command1, SPI_COMMAND1);
764 tspi->command1_reg = command1; 740 tspi->command1_reg = command1;
765 741
766 dev_dbg(tspi->dev, "The def 0x%x and written 0x%lx\n", 742 dev_dbg(tspi->dev, "The def 0x%x and written 0x%x\n",
767 tspi->def_command1_reg, command1); 743 tspi->def_command1_reg, (unsigned)command1);
768 744
769 if (total_fifo_words > SPI_FIFO_DEPTH) 745 if (total_fifo_words > SPI_FIFO_DEPTH)
770 ret = tegra_spi_start_dma_based_transfer(tspi, t); 746 ret = tegra_spi_start_dma_based_transfer(tspi, t);
@@ -776,15 +752,9 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi,
776static int tegra_spi_setup(struct spi_device *spi) 752static int tegra_spi_setup(struct spi_device *spi)
777{ 753{
778 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); 754 struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
779 unsigned long val; 755 u32 val;
780 unsigned long flags; 756 unsigned long flags;
781 int ret; 757 int ret;
782 unsigned int cs_pol_bit[MAX_CHIP_SELECT] = {
783 SPI_CS_POL_INACTIVE_0,
784 SPI_CS_POL_INACTIVE_1,
785 SPI_CS_POL_INACTIVE_2,
786 SPI_CS_POL_INACTIVE_3,
787 };
788 758
789 dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n", 759 dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n",
790 spi->bits_per_word, 760 spi->bits_per_word,
@@ -806,9 +776,9 @@ static int tegra_spi_setup(struct spi_device *spi)
806 spin_lock_irqsave(&tspi->lock, flags); 776 spin_lock_irqsave(&tspi->lock, flags);
807 val = tspi->def_command1_reg; 777 val = tspi->def_command1_reg;
808 if (spi->mode & SPI_CS_HIGH) 778 if (spi->mode & SPI_CS_HIGH)
809 val &= ~cs_pol_bit[spi->chip_select]; 779 val &= ~SPI_CS_POL_INACTIVE(spi->chip_select);
810 else 780 else
811 val |= cs_pol_bit[spi->chip_select]; 781 val |= SPI_CS_POL_INACTIVE(spi->chip_select);
812 tspi->def_command1_reg = val; 782 tspi->def_command1_reg = val;
813 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); 783 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
814 spin_unlock_irqrestore(&tspi->lock, flags); 784 spin_unlock_irqrestore(&tspi->lock, flags);
@@ -842,7 +812,7 @@ static int tegra_spi_transfer_one_message(struct spi_master *master,
842 msg->actual_length = 0; 812 msg->actual_length = 0;
843 813
844 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 814 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
845 unsigned long cmd1; 815 u32 cmd1;
846 816
847 reinit_completion(&tspi->xfer_completion); 817 reinit_completion(&tspi->xfer_completion);
848 818