src.c (3b7843ff618f63d1776abd71de7eea9130987037) | src.c (43cb6954f8c8a68fdc354226fa045ff43c7e4d39) |
---|---|
1/* 2 * Renesas R-Car SRC support 3 * 4 * Copyright (C) 2013 Renesas Solutions Corp. 5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 8 unchanged lines hidden (view full) --- 17#define OUF_SRCI ((1 << 9) | (1 << 8)) 18 19/* SCU_SYSTEM_STATUS0/1 */ 20#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) 21 22struct rsnd_src { 23 struct rsnd_src_platform_info *info; /* rcar_snd.h */ 24 struct rsnd_mod mod; | 1/* 2 * Renesas R-Car SRC support 3 * 4 * Copyright (C) 2013 Renesas Solutions Corp. 5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 8 unchanged lines hidden (view full) --- 17#define OUF_SRCI ((1 << 9) | (1 << 8)) 18 19/* SCU_SYSTEM_STATUS0/1 */ 20#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) 21 22struct rsnd_src { 23 struct rsnd_src_platform_info *info; /* rcar_snd.h */ 24 struct rsnd_mod mod; |
25 struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ 26 struct rsnd_kctrl_cfg_s sync; /* sync convert */ |
|
25 u32 convert_rate; /* sampling rate convert */ 26 int err; 27}; 28 29#define RSND_SRC_NAME_SIZE 16 30 | 27 u32 convert_rate; /* sampling rate convert */ 28 int err; 29}; 30 31#define RSND_SRC_NAME_SIZE 16 32 |
31#define rsnd_src_convert_rate(s) ((s)->convert_rate) | 33#define rsnd_enable_sync_convert(src) ((src)->sen.val) |
32#define rsnd_src_of_node(priv) \ 33 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") 34 35#define rsnd_mod_to_src(_mod) \ 36 container_of((_mod), struct rsnd_src, mod) 37 38#define for_each_rsnd_src(pos, priv, i) \ 39 for ((i) = 0; \ --- 188 unchanged lines hidden (view full) --- 228 return 0; 229 230 /* disable SSI interrupt if Gen2 */ 231 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000); 232 233 return 0; 234} 235 | 34#define rsnd_src_of_node(priv) \ 35 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") 36 37#define rsnd_mod_to_src(_mod) \ 38 container_of((_mod), struct rsnd_src, mod) 39 40#define for_each_rsnd_src(pos, priv, i) \ 41 for ((i) = 0; \ --- 188 unchanged lines hidden (view full) --- 230 return 0; 231 232 /* disable SSI interrupt if Gen2 */ 233 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000); 234 235 return 0; 236} 237 |
238static u32 rsnd_src_convert_rate(struct rsnd_src *src) 239{ 240 struct rsnd_mod *mod = &src->mod; 241 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 242 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 243 u32 convert_rate; 244 245 if (!runtime) 246 return 0; 247 248 if (!rsnd_enable_sync_convert(src)) 249 return src->convert_rate; 250 251 convert_rate = src->sync.val; 252 253 if (!convert_rate) 254 convert_rate = src->convert_rate; 255 256 if (!convert_rate) 257 convert_rate = runtime->rate; 258 259 return convert_rate; 260} 261 |
|
236unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, 237 struct rsnd_dai_stream *io, 238 struct snd_pcm_runtime *runtime) 239{ 240 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); 241 struct rsnd_src *src; 242 unsigned int rate = 0; 243 --- 84 unchanged lines hidden (view full) --- 328 struct rsnd_priv *priv) 329{ 330 struct rsnd_src *src = rsnd_mod_to_src(mod); 331 332 rsnd_mod_hw_start(mod); 333 334 src->err = 0; 335 | 262unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, 263 struct rsnd_dai_stream *io, 264 struct snd_pcm_runtime *runtime) 265{ 266 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); 267 struct rsnd_src *src; 268 unsigned int rate = 0; 269 --- 84 unchanged lines hidden (view full) --- 354 struct rsnd_priv *priv) 355{ 356 struct rsnd_src *src = rsnd_mod_to_src(mod); 357 358 rsnd_mod_hw_start(mod); 359 360 src->err = 0; 361 |
362 /* reset sync convert_rate */ 363 src->sync.val = 0; 364 |
|
336 /* 337 * Initialize the operation of the SRC internal circuits 338 * see rsnd_src_start() 339 */ 340 rsnd_mod_write(mod, SRC_SRCIR, 1); 341 342 return 0; 343} --- 7 unchanged lines hidden (view full) --- 351 rsnd_mod_hw_stop(mod); 352 353 if (src->err) 354 dev_warn(dev, "%s[%d] under/over flow err = %d\n", 355 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); 356 357 src->convert_rate = 0; 358 | 365 /* 366 * Initialize the operation of the SRC internal circuits 367 * see rsnd_src_start() 368 */ 369 rsnd_mod_write(mod, SRC_SRCIR, 1); 370 371 return 0; 372} --- 7 unchanged lines hidden (view full) --- 380 rsnd_mod_hw_stop(mod); 381 382 if (src->err) 383 dev_warn(dev, "%s[%d] under/over flow err = %d\n", 384 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); 385 386 src->convert_rate = 0; 387 |
388 /* reset sync convert_rate */ 389 src->sync.val = 0; 390 |
|
359 return 0; 360} 361 362static int rsnd_src_start(struct rsnd_mod *mod) 363{ 364 /* 365 * Cancel the initialization and operate the SRC function 366 * see rsnd_src_init() --- 300 unchanged lines hidden (view full) --- 667static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) 668{ 669 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 670 struct device *dev = rsnd_priv_to_dev(priv); 671 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 672 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 673 struct rsnd_src *src = rsnd_mod_to_src(mod); 674 u32 convert_rate = rsnd_src_convert_rate(src); | 391 return 0; 392} 393 394static int rsnd_src_start(struct rsnd_mod *mod) 395{ 396 /* 397 * Cancel the initialization and operate the SRC function 398 * see rsnd_src_init() --- 300 unchanged lines hidden (view full) --- 699static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) 700{ 701 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 702 struct device *dev = rsnd_priv_to_dev(priv); 703 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 704 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 705 struct rsnd_src *src = rsnd_mod_to_src(mod); 706 u32 convert_rate = rsnd_src_convert_rate(src); |
707 u32 cr, route; |
|
675 uint ratio; 676 int ret; 677 678 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ 679 if (!convert_rate) 680 ratio = 0; 681 else if (convert_rate > runtime->rate) 682 ratio = 100 * convert_rate / runtime->rate; --- 4 unchanged lines hidden (view full) --- 687 dev_err(dev, "FSO/FSI ratio error\n"); 688 return -EINVAL; 689 } 690 691 ret = rsnd_src_set_convert_rate(mod); 692 if (ret < 0) 693 return ret; 694 | 708 uint ratio; 709 int ret; 710 711 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ 712 if (!convert_rate) 713 ratio = 0; 714 else if (convert_rate > runtime->rate) 715 ratio = 100 * convert_rate / runtime->rate; --- 4 unchanged lines hidden (view full) --- 720 dev_err(dev, "FSO/FSI ratio error\n"); 721 return -EINVAL; 722 } 723 724 ret = rsnd_src_set_convert_rate(mod); 725 if (ret < 0) 726 return ret; 727 |
695 rsnd_mod_write(mod, SRC_SRCCR, 0x00011110); 696 | 728 cr = 0x00011110; 729 route = 0x0; |
697 if (convert_rate) { | 730 if (convert_rate) { |
698 /* Gen1/Gen2 are not compatible */ 699 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); | 731 route = 0x1; 732 733 if (rsnd_enable_sync_convert(src)) { 734 cr |= 0x1; 735 route |= rsnd_io_is_play(io) ? 736 (0x1 << 24) : (0x1 << 25); 737 } |
700 } 701 | 738 } 739 |
740 rsnd_mod_write(mod, SRC_SRCCR, cr); 741 rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); 742 |
|
702 switch (rsnd_mod_id(mod)) { 703 case 5: 704 case 6: 705 case 7: 706 case 8: 707 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000); 708 break; 709 default: --- 96 unchanged lines hidden (view full) --- 806 807 ret = _rsnd_src_stop_gen2(mod); 808 809 rsnd_dma_stop(rsnd_mod_to_dma(mod)); 810 811 return ret; 812} 813 | 743 switch (rsnd_mod_id(mod)) { 744 case 5: 745 case 6: 746 case 7: 747 case 8: 748 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000); 749 break; 750 default: --- 96 unchanged lines hidden (view full) --- 847 848 ret = _rsnd_src_stop_gen2(mod); 849 850 rsnd_dma_stop(rsnd_mod_to_dma(mod)); 851 852 return ret; 853} 854 |
855static void rsnd_src_reconvert_update(struct rsnd_mod *mod) 856{ 857 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 858 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 859 struct rsnd_src *src = rsnd_mod_to_src(mod); 860 u32 convert_rate = rsnd_src_convert_rate(src); 861 u32 fsrate; 862 863 if (!runtime) 864 return; 865 866 if (!convert_rate) 867 convert_rate = runtime->rate; 868 869 fsrate = 0x0400000 / convert_rate * runtime->rate; 870 871 /* update IFS */ 872 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 873} 874 875static int rsnd_src_pcm_new(struct rsnd_mod *mod, 876 struct snd_soc_pcm_runtime *rtd) 877{ 878 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 879 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 880 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 881 struct rsnd_src *src = rsnd_mod_to_src(mod); 882 int ret; 883 884 /* 885 * enable SRC sync convert if possible 886 */ 887 888 /* 889 * Gen1 is not supported 890 */ 891 if (rsnd_is_gen1(priv)) 892 return 0; 893 894 /* 895 * SRC sync convert needs clock master 896 */ 897 if (!rsnd_rdai_is_clk_master(rdai)) 898 return 0; 899 900 /* 901 * We can't use SRC sync convert 902 * if it has DVC 903 */ 904 if (rsnd_io_to_mod_dvc(io)) 905 return 0; 906 907 /* 908 * enable sync convert 909 */ 910 ret = rsnd_kctrl_new_s(mod, rtd, 911 rsnd_io_is_play(io) ? 912 "SRC Out Rate Switch" : 913 "SRC In Rate Switch", 914 rsnd_src_reconvert_update, 915 &src->sen, 1); 916 if (ret < 0) 917 return ret; 918 919 ret = rsnd_kctrl_new_s(mod, rtd, 920 rsnd_io_is_play(io) ? 921 "SRC Out Rate" : 922 "SRC In Rate", 923 rsnd_src_reconvert_update, 924 &src->sync, 192000); 925 926 return ret; 927} 928 |
|
814static struct rsnd_mod_ops rsnd_src_gen2_ops = { 815 .name = SRC_NAME, 816 .dma_req = rsnd_src_dma_req, 817 .probe = rsnd_src_probe_gen2, 818 .remove = rsnd_src_remove_gen2, 819 .init = rsnd_src_init_gen2, 820 .quit = rsnd_src_quit, 821 .start = rsnd_src_start_gen2, 822 .stop = rsnd_src_stop_gen2, 823 .hw_params = rsnd_src_hw_params, | 929static struct rsnd_mod_ops rsnd_src_gen2_ops = { 930 .name = SRC_NAME, 931 .dma_req = rsnd_src_dma_req, 932 .probe = rsnd_src_probe_gen2, 933 .remove = rsnd_src_remove_gen2, 934 .init = rsnd_src_init_gen2, 935 .quit = rsnd_src_quit, 936 .start = rsnd_src_start_gen2, 937 .stop = rsnd_src_stop_gen2, 938 .hw_params = rsnd_src_hw_params, |
939 .pcm_new = rsnd_src_pcm_new, |
|
824}; 825 826struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) 827{ 828 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) 829 id = 0; 830 831 return &((struct rsnd_src *)(priv->src) + id)->mod; --- 114 unchanged lines hidden --- | 940}; 941 942struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) 943{ 944 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) 945 id = 0; 946 947 return &((struct rsnd_src *)(priv->src) + id)->mod; --- 114 unchanged lines hidden --- |