diff options
author | Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | 2010-09-17 00:48:45 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-09-20 15:44:24 -0400 |
commit | 5bfb9ad0840b15d9c45d25a05e4ff9ae5eb80508 (patch) | |
tree | 36c6a383f73de86adf2d409be3003584311a297d /sound/soc/sh/fsi.c | |
parent | 5250a5031ee5733c10c7cb371206ed3784918adc (diff) |
ASoC: fsi: modify variable name to easy to understand
Current FSI driver is using
data-length / width / number / offset for variables.
But it was a very confusing name.
This patch rename them to easy to understand,
and add new functions for it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/sh/fsi.c')
-rw-r--r-- | sound/soc/sh/fsi.c | 173 |
1 files changed, 96 insertions, 77 deletions
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 363b37a603cb..3448170debe4 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c | |||
@@ -102,6 +102,15 @@ | |||
102 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) | 102 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
103 | 103 | ||
104 | /* | 104 | /* |
105 | * FSI driver use below type name for variable | ||
106 | * | ||
107 | * xxx_len : data length | ||
108 | * xxx_width : data width | ||
109 | * xxx_offset : data offset | ||
110 | * xxx_num : number of data | ||
111 | */ | ||
112 | |||
113 | /* | ||
105 | * struct | 114 | * struct |
106 | */ | 115 | */ |
107 | 116 | ||
@@ -110,13 +119,13 @@ struct fsi_priv { | |||
110 | struct snd_pcm_substream *substream; | 119 | struct snd_pcm_substream *substream; |
111 | struct fsi_master *master; | 120 | struct fsi_master *master; |
112 | 121 | ||
113 | int fifo_max; | 122 | int fifo_max_num; |
114 | int chan; | 123 | int chan_num; |
115 | 124 | ||
116 | int byte_offset; | 125 | int buff_offset; |
126 | int buff_len; | ||
117 | int period_len; | 127 | int period_len; |
118 | int buffer_len; | 128 | int period_num; |
119 | int periods; | ||
120 | 129 | ||
121 | u32 mst_ctrl; | 130 | u32 mst_ctrl; |
122 | }; | 131 | }; |
@@ -320,32 +329,43 @@ static void fsi_stream_push(struct fsi_priv *fsi, | |||
320 | u32 period_len) | 329 | u32 period_len) |
321 | { | 330 | { |
322 | fsi->substream = substream; | 331 | fsi->substream = substream; |
323 | fsi->buffer_len = buffer_len; | 332 | fsi->buff_len = buffer_len; |
333 | fsi->buff_offset = 0; | ||
324 | fsi->period_len = period_len; | 334 | fsi->period_len = period_len; |
325 | fsi->byte_offset = 0; | 335 | fsi->period_num = 0; |
326 | fsi->periods = 0; | ||
327 | } | 336 | } |
328 | 337 | ||
329 | static void fsi_stream_pop(struct fsi_priv *fsi) | 338 | static void fsi_stream_pop(struct fsi_priv *fsi) |
330 | { | 339 | { |
331 | fsi->substream = NULL; | 340 | fsi->substream = NULL; |
332 | fsi->buffer_len = 0; | 341 | fsi->buff_len = 0; |
342 | fsi->buff_offset = 0; | ||
333 | fsi->period_len = 0; | 343 | fsi->period_len = 0; |
334 | fsi->byte_offset = 0; | 344 | fsi->period_num = 0; |
335 | fsi->periods = 0; | ||
336 | } | 345 | } |
337 | 346 | ||
338 | static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play) | 347 | static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play) |
339 | { | 348 | { |
340 | u32 status; | 349 | u32 status; |
341 | u32 reg = is_play ? DOFF_ST : DIFF_ST; | 350 | u32 reg = is_play ? DOFF_ST : DIFF_ST; |
342 | int residue; | 351 | int data_num; |
343 | 352 | ||
344 | status = fsi_reg_read(fsi, reg); | 353 | status = fsi_reg_read(fsi, reg); |
345 | residue = 0x1ff & (status >> 8); | 354 | data_num = 0x1ff & (status >> 8); |
346 | residue *= fsi->chan; | 355 | data_num *= fsi->chan_num; |
356 | |||
357 | return data_num; | ||
358 | } | ||
347 | 359 | ||
348 | return residue; | 360 | static int fsi_len2num(int len, int width) |
361 | { | ||
362 | return len / width; | ||
363 | } | ||
364 | |||
365 | #define fsi_num2offset(a, b) fsi_num2len(a, b) | ||
366 | static int fsi_num2len(int num, int width) | ||
367 | { | ||
368 | return num * width; | ||
349 | } | 369 | } |
350 | 370 | ||
351 | /* | 371 | /* |
@@ -354,50 +374,50 @@ static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play) | |||
354 | 374 | ||
355 | static u8 *fsi_dma_get_area(struct fsi_priv *fsi) | 375 | static u8 *fsi_dma_get_area(struct fsi_priv *fsi) |
356 | { | 376 | { |
357 | return fsi->substream->runtime->dma_area + fsi->byte_offset; | 377 | return fsi->substream->runtime->dma_area + fsi->buff_offset; |
358 | } | 378 | } |
359 | 379 | ||
360 | static void fsi_dma_soft_push16(struct fsi_priv *fsi, int size) | 380 | static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num) |
361 | { | 381 | { |
362 | u16 *start; | 382 | u16 *start; |
363 | int i; | 383 | int i; |
364 | 384 | ||
365 | start = (u16 *)fsi_dma_get_area(fsi); | 385 | start = (u16 *)fsi_dma_get_area(fsi); |
366 | 386 | ||
367 | for (i = 0; i < size; i++) | 387 | for (i = 0; i < num; i++) |
368 | fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8)); | 388 | fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8)); |
369 | } | 389 | } |
370 | 390 | ||
371 | static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int size) | 391 | static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num) |
372 | { | 392 | { |
373 | u16 *start; | 393 | u16 *start; |
374 | int i; | 394 | int i; |
375 | 395 | ||
376 | start = (u16 *)fsi_dma_get_area(fsi); | 396 | start = (u16 *)fsi_dma_get_area(fsi); |
377 | 397 | ||
378 | for (i = 0; i < size; i++) | 398 | for (i = 0; i < num; i++) |
379 | *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8); | 399 | *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8); |
380 | } | 400 | } |
381 | 401 | ||
382 | static void fsi_dma_soft_push32(struct fsi_priv *fsi, int size) | 402 | static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num) |
383 | { | 403 | { |
384 | u32 *start; | 404 | u32 *start; |
385 | int i; | 405 | int i; |
386 | 406 | ||
387 | start = (u32 *)fsi_dma_get_area(fsi); | 407 | start = (u32 *)fsi_dma_get_area(fsi); |
388 | 408 | ||
389 | for (i = 0; i < size; i++) | 409 | for (i = 0; i < num; i++) |
390 | fsi_reg_write(fsi, DODT, *(start + i)); | 410 | fsi_reg_write(fsi, DODT, *(start + i)); |
391 | } | 411 | } |
392 | 412 | ||
393 | static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int size) | 413 | static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num) |
394 | { | 414 | { |
395 | u32 *start; | 415 | u32 *start; |
396 | int i; | 416 | int i; |
397 | 417 | ||
398 | start = (u32 *)fsi_dma_get_area(fsi); | 418 | start = (u32 *)fsi_dma_get_area(fsi); |
399 | 419 | ||
400 | for (i = 0; i < size; i++) | 420 | for (i = 0; i < num; i++) |
401 | *(start + i) = fsi_reg_read(fsi, DIDT); | 421 | *(start + i) = fsi_reg_read(fsi, DIDT); |
402 | } | 422 | } |
403 | 423 | ||
@@ -492,8 +512,8 @@ static void fsi_fifo_init(struct fsi_priv *fsi, | |||
492 | shift = fsi_master_read(master, FIFO_SZ); | 512 | shift = fsi_master_read(master, FIFO_SZ); |
493 | shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT; | 513 | shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT; |
494 | shift &= OUT_SZ_MASK; | 514 | shift &= OUT_SZ_MASK; |
495 | fsi->fifo_max = 256 << shift; | 515 | fsi->fifo_max_num = 256 << shift; |
496 | dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max); | 516 | dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max_num); |
497 | 517 | ||
498 | /* | 518 | /* |
499 | * The maximum number of sample data varies depending | 519 | * The maximum number of sample data varies depending |
@@ -514,9 +534,10 @@ static void fsi_fifo_init(struct fsi_priv *fsi, | |||
514 | * 7 channels: 32 ( 32 x 7 = 224) | 534 | * 7 channels: 32 ( 32 x 7 = 224) |
515 | * 8 channels: 32 ( 32 x 8 = 256) | 535 | * 8 channels: 32 ( 32 x 8 = 256) |
516 | */ | 536 | */ |
517 | for (i = 1; i < fsi->chan; i <<= 1) | 537 | for (i = 1; i < fsi->chan_num; i <<= 1) |
518 | fsi->fifo_max >>= 1; | 538 | fsi->fifo_max_num >>= 1; |
519 | dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max); | 539 | dev_dbg(dai->dev, "%d channel %d store\n", |
540 | fsi->chan_num, fsi->fifo_max_num); | ||
520 | 541 | ||
521 | ctrl = is_play ? DOFF_CTL : DIFF_CTL; | 542 | ctrl = is_play ? DOFF_CTL : DIFF_CTL; |
522 | 543 | ||
@@ -545,9 +566,9 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup) | |||
545 | struct snd_pcm_runtime *runtime; | 566 | struct snd_pcm_runtime *runtime; |
546 | struct snd_pcm_substream *substream = NULL; | 567 | struct snd_pcm_substream *substream = NULL; |
547 | u32 status; | 568 | u32 status; |
548 | int send; | 569 | int push_num; |
549 | int fifo_free; | 570 | int push_num_max; |
550 | int width; | 571 | int ch_width; |
551 | int over_period; | 572 | int over_period; |
552 | 573 | ||
553 | if (!fsi || | 574 | if (!fsi || |
@@ -562,41 +583,40 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup) | |||
562 | /* FSI FIFO has limit. | 583 | /* FSI FIFO has limit. |
563 | * So, this driver can not send periods data at a time | 584 | * So, this driver can not send periods data at a time |
564 | */ | 585 | */ |
565 | if (fsi->byte_offset >= | 586 | if (fsi->buff_offset >= |
566 | fsi->period_len * (fsi->periods + 1)) { | 587 | fsi_num2offset(fsi->period_num + 1, fsi->period_len)) { |
567 | 588 | ||
568 | over_period = 1; | 589 | over_period = 1; |
569 | fsi->periods = (fsi->periods + 1) % runtime->periods; | 590 | fsi->period_num = (fsi->period_num + 1) % runtime->periods; |
570 | 591 | ||
571 | if (0 == fsi->periods) | 592 | if (0 == fsi->period_num) |
572 | fsi->byte_offset = 0; | 593 | fsi->buff_offset = 0; |
573 | } | 594 | } |
574 | 595 | ||
575 | /* get 1 channel data width */ | 596 | /* get 1 channel data width */ |
576 | width = frames_to_bytes(runtime, 1) / fsi->chan; | 597 | ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num; |
577 | 598 | ||
578 | /* get send size for alsa */ | 599 | /* number of push data */ |
579 | send = (fsi->buffer_len - fsi->byte_offset) / width; | 600 | push_num = fsi_len2num(fsi->buff_len - fsi->buff_offset, ch_width); |
580 | 601 | ||
581 | /* get FIFO free size */ | 602 | /* max number of push data */ |
582 | fifo_free = (fsi->fifo_max * fsi->chan) - fsi_get_fifo_residue(fsi, 1); | 603 | push_num_max = (fsi->fifo_max_num * fsi->chan_num) - |
604 | fsi_get_fifo_data_num(fsi, 1); | ||
583 | 605 | ||
584 | /* size check */ | 606 | push_num = min(push_num, push_num_max); |
585 | if (fifo_free < send) | ||
586 | send = fifo_free; | ||
587 | 607 | ||
588 | switch (width) { | 608 | switch (ch_width) { |
589 | case 2: | 609 | case 2: |
590 | fsi_dma_soft_push16(fsi, send); | 610 | fsi_dma_soft_push16(fsi, push_num); |
591 | break; | 611 | break; |
592 | case 4: | 612 | case 4: |
593 | fsi_dma_soft_push32(fsi, send); | 613 | fsi_dma_soft_push32(fsi, push_num); |
594 | break; | 614 | break; |
595 | default: | 615 | default: |
596 | return -EINVAL; | 616 | return -EINVAL; |
597 | } | 617 | } |
598 | 618 | ||
599 | fsi->byte_offset += send * width; | 619 | fsi->buff_offset += fsi_num2offset(push_num, ch_width); |
600 | 620 | ||
601 | status = fsi_reg_read(fsi, DOFF_ST); | 621 | status = fsi_reg_read(fsi, DOFF_ST); |
602 | if (!startup) { | 622 | if (!startup) { |
@@ -622,9 +642,9 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup) | |||
622 | struct snd_pcm_runtime *runtime; | 642 | struct snd_pcm_runtime *runtime; |
623 | struct snd_pcm_substream *substream = NULL; | 643 | struct snd_pcm_substream *substream = NULL; |
624 | u32 status; | 644 | u32 status; |
625 | int free; | 645 | int pop_num; |
626 | int fifo_fill; | 646 | int pop_num_max; |
627 | int width; | 647 | int ch_width; |
628 | int over_period; | 648 | int over_period; |
629 | 649 | ||
630 | if (!fsi || | 650 | if (!fsi || |
@@ -639,40 +659,39 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup) | |||
639 | /* FSI FIFO has limit. | 659 | /* FSI FIFO has limit. |
640 | * So, this driver can not send periods data at a time | 660 | * So, this driver can not send periods data at a time |
641 | */ | 661 | */ |
642 | if (fsi->byte_offset >= | 662 | if (fsi->buff_offset >= |
643 | fsi->period_len * (fsi->periods + 1)) { | 663 | fsi_num2offset(fsi->period_num + 1, fsi->period_len)) { |
644 | 664 | ||
645 | over_period = 1; | 665 | over_period = 1; |
646 | fsi->periods = (fsi->periods + 1) % runtime->periods; | 666 | fsi->period_num = (fsi->period_num + 1) % runtime->periods; |
647 | 667 | ||
648 | if (0 == fsi->periods) | 668 | if (0 == fsi->period_num) |
649 | fsi->byte_offset = 0; | 669 | fsi->buff_offset = 0; |
650 | } | 670 | } |
651 | 671 | ||
652 | /* get 1 channel data width */ | 672 | /* get 1 channel data width */ |
653 | width = frames_to_bytes(runtime, 1) / fsi->chan; | 673 | ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num; |
654 | 674 | ||
655 | /* get free space for alsa */ | 675 | /* get free space for alsa */ |
656 | free = (fsi->buffer_len - fsi->byte_offset) / width; | 676 | pop_num_max = fsi_len2num(fsi->buff_len - fsi->buff_offset, ch_width); |
657 | 677 | ||
658 | /* get recv size */ | 678 | /* get recv size */ |
659 | fifo_fill = fsi_get_fifo_residue(fsi, 0); | 679 | pop_num = fsi_get_fifo_data_num(fsi, 0); |
660 | 680 | ||
661 | if (free < fifo_fill) | 681 | pop_num = min(pop_num_max, pop_num); |
662 | fifo_fill = free; | ||
663 | 682 | ||
664 | switch (width) { | 683 | switch (ch_width) { |
665 | case 2: | 684 | case 2: |
666 | fsi_dma_soft_pop16(fsi, fifo_fill); | 685 | fsi_dma_soft_pop16(fsi, pop_num); |
667 | break; | 686 | break; |
668 | case 4: | 687 | case 4: |
669 | fsi_dma_soft_pop32(fsi, fifo_fill); | 688 | fsi_dma_soft_pop32(fsi, pop_num); |
670 | break; | 689 | break; |
671 | default: | 690 | default: |
672 | return -EINVAL; | 691 | return -EINVAL; |
673 | } | 692 | } |
674 | 693 | ||
675 | fsi->byte_offset += fifo_fill * width; | 694 | fsi->buff_offset += fsi_num2offset(pop_num, ch_width); |
676 | 695 | ||
677 | status = fsi_reg_read(fsi, DIFF_ST); | 696 | status = fsi_reg_read(fsi, DIFF_ST); |
678 | if (!startup) { | 697 | if (!startup) { |
@@ -763,29 +782,29 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, | |||
763 | switch (fmt) { | 782 | switch (fmt) { |
764 | case SH_FSI_FMT_MONO: | 783 | case SH_FSI_FMT_MONO: |
765 | data = CR_MONO; | 784 | data = CR_MONO; |
766 | fsi->chan = 1; | 785 | fsi->chan_num = 1; |
767 | break; | 786 | break; |
768 | case SH_FSI_FMT_MONO_DELAY: | 787 | case SH_FSI_FMT_MONO_DELAY: |
769 | data = CR_MONO_D; | 788 | data = CR_MONO_D; |
770 | fsi->chan = 1; | 789 | fsi->chan_num = 1; |
771 | break; | 790 | break; |
772 | case SH_FSI_FMT_PCM: | 791 | case SH_FSI_FMT_PCM: |
773 | data = CR_PCM; | 792 | data = CR_PCM; |
774 | fsi->chan = 2; | 793 | fsi->chan_num = 2; |
775 | break; | 794 | break; |
776 | case SH_FSI_FMT_I2S: | 795 | case SH_FSI_FMT_I2S: |
777 | data = CR_I2S; | 796 | data = CR_I2S; |
778 | fsi->chan = 2; | 797 | fsi->chan_num = 2; |
779 | break; | 798 | break; |
780 | case SH_FSI_FMT_TDM: | 799 | case SH_FSI_FMT_TDM: |
781 | fsi->chan = is_play ? | 800 | fsi->chan_num = is_play ? |
782 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); | 801 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); |
783 | data = CR_TDM | (fsi->chan - 1); | 802 | data = CR_TDM | (fsi->chan_num - 1); |
784 | break; | 803 | break; |
785 | case SH_FSI_FMT_TDM_DELAY: | 804 | case SH_FSI_FMT_TDM_DELAY: |
786 | fsi->chan = is_play ? | 805 | fsi->chan_num = is_play ? |
787 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); | 806 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); |
788 | data = CR_TDM_D | (fsi->chan - 1); | 807 | data = CR_TDM_D | (fsi->chan_num - 1); |
789 | break; | 808 | break; |
790 | case SH_FSI_FMT_SPDIF: | 809 | case SH_FSI_FMT_SPDIF: |
791 | if (master->core->ver < 2) { | 810 | if (master->core->ver < 2) { |
@@ -793,7 +812,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, | |||
793 | return -EINVAL; | 812 | return -EINVAL; |
794 | } | 813 | } |
795 | data = CR_SPDIF; | 814 | data = CR_SPDIF; |
796 | fsi->chan = 2; | 815 | fsi->chan_num = 2; |
797 | fsi_spdif_clk_ctrl(fsi, 1); | 816 | fsi_spdif_clk_ctrl(fsi, 1); |
798 | fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010); | 817 | fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010); |
799 | break; | 818 | break; |
@@ -992,7 +1011,7 @@ static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) | |||
992 | struct fsi_priv *fsi = fsi_get_priv(substream); | 1011 | struct fsi_priv *fsi = fsi_get_priv(substream); |
993 | long location; | 1012 | long location; |
994 | 1013 | ||
995 | location = (fsi->byte_offset - 1); | 1014 | location = (fsi->buff_offset - 1); |
996 | if (location < 0) | 1015 | if (location < 0) |
997 | location = 0; | 1016 | location = 0; |
998 | 1017 | ||