diff options
author | Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | 2011-05-23 07:46:18 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-05-24 06:41:36 -0400 |
commit | 4f56cde17e3373219b56d2e9a91dbcd0ad228af7 (patch) | |
tree | 2c5e5cf8f7060a5847f1b9b13ebeafad46fdce84 /sound/soc/sh/fsi.c | |
parent | 0ffe296addcfb8414ebad3d399859f9bf8f955d2 (diff) |
ASoC: sh: fsi: add fsi_set_master_clk
Current FSI driver is using set_rate call back function which is for
master mode.
By this patch, it is used from fsi_set_master_clk.
This patch is preparation of cleanup suspend/resume patch.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Liam Girdwood <lrg@ti.com>
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 | 164 |
1 files changed, 87 insertions, 77 deletions
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 702588577f59..83f6fdce75ee 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c | |||
@@ -558,6 +558,82 @@ static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) | |||
558 | /* | 558 | /* |
559 | * clock function | 559 | * clock function |
560 | */ | 560 | */ |
561 | static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, | ||
562 | long rate, int enable) | ||
563 | { | ||
564 | struct fsi_master *master = fsi_get_master(fsi); | ||
565 | set_rate_func set_rate = fsi_get_info_set_rate(master); | ||
566 | int fsi_ver = master->core->ver; | ||
567 | int ret; | ||
568 | |||
569 | ret = set_rate(dev, fsi_is_port_a(fsi), rate, enable); | ||
570 | if (ret < 0) /* error */ | ||
571 | return ret; | ||
572 | |||
573 | if (!enable) | ||
574 | return 0; | ||
575 | |||
576 | if (ret > 0) { | ||
577 | u32 data = 0; | ||
578 | |||
579 | switch (ret & SH_FSI_ACKMD_MASK) { | ||
580 | default: | ||
581 | /* FALL THROUGH */ | ||
582 | case SH_FSI_ACKMD_512: | ||
583 | data |= (0x0 << 12); | ||
584 | break; | ||
585 | case SH_FSI_ACKMD_256: | ||
586 | data |= (0x1 << 12); | ||
587 | break; | ||
588 | case SH_FSI_ACKMD_128: | ||
589 | data |= (0x2 << 12); | ||
590 | break; | ||
591 | case SH_FSI_ACKMD_64: | ||
592 | data |= (0x3 << 12); | ||
593 | break; | ||
594 | case SH_FSI_ACKMD_32: | ||
595 | if (fsi_ver < 2) | ||
596 | dev_err(dev, "unsupported ACKMD\n"); | ||
597 | else | ||
598 | data |= (0x4 << 12); | ||
599 | break; | ||
600 | } | ||
601 | |||
602 | switch (ret & SH_FSI_BPFMD_MASK) { | ||
603 | default: | ||
604 | /* FALL THROUGH */ | ||
605 | case SH_FSI_BPFMD_32: | ||
606 | data |= (0x0 << 8); | ||
607 | break; | ||
608 | case SH_FSI_BPFMD_64: | ||
609 | data |= (0x1 << 8); | ||
610 | break; | ||
611 | case SH_FSI_BPFMD_128: | ||
612 | data |= (0x2 << 8); | ||
613 | break; | ||
614 | case SH_FSI_BPFMD_256: | ||
615 | data |= (0x3 << 8); | ||
616 | break; | ||
617 | case SH_FSI_BPFMD_512: | ||
618 | data |= (0x4 << 8); | ||
619 | break; | ||
620 | case SH_FSI_BPFMD_16: | ||
621 | if (fsi_ver < 2) | ||
622 | dev_err(dev, "unsupported ACKMD\n"); | ||
623 | else | ||
624 | data |= (0x7 << 8); | ||
625 | break; | ||
626 | } | ||
627 | |||
628 | fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data); | ||
629 | udelay(10); | ||
630 | ret = 0; | ||
631 | } | ||
632 | |||
633 | return ret; | ||
634 | |||
635 | } | ||
636 | |||
561 | #define fsi_module_init(m, d) __fsi_module_clk_ctrl(m, d, 1) | 637 | #define fsi_module_init(m, d) __fsi_module_clk_ctrl(m, d, 1) |
562 | #define fsi_module_kill(m, d) __fsi_module_clk_ctrl(m, d, 0) | 638 | #define fsi_module_kill(m, d) __fsi_module_clk_ctrl(m, d, 0) |
563 | static void __fsi_module_clk_ctrl(struct fsi_master *master, | 639 | static void __fsi_module_clk_ctrl(struct fsi_master *master, |
@@ -826,13 +902,11 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream, | |||
826 | { | 902 | { |
827 | struct fsi_priv *fsi = fsi_get_priv(substream); | 903 | struct fsi_priv *fsi = fsi_get_priv(substream); |
828 | int is_play = fsi_is_play(substream); | 904 | int is_play = fsi_is_play(substream); |
829 | struct fsi_master *master = fsi_get_master(fsi); | ||
830 | set_rate_func set_rate = fsi_get_info_set_rate(master); | ||
831 | 905 | ||
832 | fsi_irq_disable(fsi, is_play); | 906 | fsi_irq_disable(fsi, is_play); |
833 | 907 | ||
834 | if (fsi_is_clk_master(fsi)) | 908 | if (fsi_is_clk_master(fsi)) |
835 | set_rate(dai->dev, fsi_is_port_a(fsi), fsi->rate, 0); | 909 | fsi_set_master_clk(dai->dev, fsi, fsi->rate, 0); |
836 | 910 | ||
837 | fsi->rate = 0; | 911 | fsi->rate = 0; |
838 | 912 | ||
@@ -960,79 +1034,19 @@ static int fsi_dai_hw_params(struct snd_pcm_substream *substream, | |||
960 | struct snd_soc_dai *dai) | 1034 | struct snd_soc_dai *dai) |
961 | { | 1035 | { |
962 | struct fsi_priv *fsi = fsi_get_priv(substream); | 1036 | struct fsi_priv *fsi = fsi_get_priv(substream); |
963 | struct fsi_master *master = fsi_get_master(fsi); | ||
964 | set_rate_func set_rate = fsi_get_info_set_rate(master); | ||
965 | int fsi_ver = master->core->ver; | ||
966 | long rate = params_rate(params); | 1037 | long rate = params_rate(params); |
967 | int ret; | 1038 | int ret; |
968 | 1039 | ||
969 | if (!fsi_is_clk_master(fsi)) | 1040 | if (!fsi_is_clk_master(fsi)) |
970 | return 0; | 1041 | return 0; |
971 | 1042 | ||
972 | ret = set_rate(dai->dev, fsi_is_port_a(fsi), rate, 1); | 1043 | ret = fsi_set_master_clk(dai->dev, fsi, rate, 1); |
973 | if (ret < 0) /* error */ | 1044 | if (ret < 0) |
974 | return ret; | 1045 | return ret; |
975 | 1046 | ||
976 | fsi->rate = rate; | 1047 | fsi->rate = rate; |
977 | if (ret > 0) { | ||
978 | u32 data = 0; | ||
979 | |||
980 | switch (ret & SH_FSI_ACKMD_MASK) { | ||
981 | default: | ||
982 | /* FALL THROUGH */ | ||
983 | case SH_FSI_ACKMD_512: | ||
984 | data |= (0x0 << 12); | ||
985 | break; | ||
986 | case SH_FSI_ACKMD_256: | ||
987 | data |= (0x1 << 12); | ||
988 | break; | ||
989 | case SH_FSI_ACKMD_128: | ||
990 | data |= (0x2 << 12); | ||
991 | break; | ||
992 | case SH_FSI_ACKMD_64: | ||
993 | data |= (0x3 << 12); | ||
994 | break; | ||
995 | case SH_FSI_ACKMD_32: | ||
996 | if (fsi_ver < 2) | ||
997 | dev_err(dai->dev, "unsupported ACKMD\n"); | ||
998 | else | ||
999 | data |= (0x4 << 12); | ||
1000 | break; | ||
1001 | } | ||
1002 | |||
1003 | switch (ret & SH_FSI_BPFMD_MASK) { | ||
1004 | default: | ||
1005 | /* FALL THROUGH */ | ||
1006 | case SH_FSI_BPFMD_32: | ||
1007 | data |= (0x0 << 8); | ||
1008 | break; | ||
1009 | case SH_FSI_BPFMD_64: | ||
1010 | data |= (0x1 << 8); | ||
1011 | break; | ||
1012 | case SH_FSI_BPFMD_128: | ||
1013 | data |= (0x2 << 8); | ||
1014 | break; | ||
1015 | case SH_FSI_BPFMD_256: | ||
1016 | data |= (0x3 << 8); | ||
1017 | break; | ||
1018 | case SH_FSI_BPFMD_512: | ||
1019 | data |= (0x4 << 8); | ||
1020 | break; | ||
1021 | case SH_FSI_BPFMD_16: | ||
1022 | if (fsi_ver < 2) | ||
1023 | dev_err(dai->dev, "unsupported ACKMD\n"); | ||
1024 | else | ||
1025 | data |= (0x7 << 8); | ||
1026 | break; | ||
1027 | } | ||
1028 | |||
1029 | fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data); | ||
1030 | udelay(10); | ||
1031 | ret = 0; | ||
1032 | } | ||
1033 | 1048 | ||
1034 | return ret; | 1049 | return ret; |
1035 | |||
1036 | } | 1050 | } |
1037 | 1051 | ||
1038 | static struct snd_soc_dai_ops fsi_dai_ops = { | 1052 | static struct snd_soc_dai_ops fsi_dai_ops = { |
@@ -1301,8 +1315,7 @@ static int fsi_remove(struct platform_device *pdev) | |||
1301 | } | 1315 | } |
1302 | 1316 | ||
1303 | static void __fsi_suspend(struct fsi_priv *fsi, | 1317 | static void __fsi_suspend(struct fsi_priv *fsi, |
1304 | struct device *dev, | 1318 | struct device *dev) |
1305 | set_rate_func set_rate) | ||
1306 | { | 1319 | { |
1307 | fsi->saved_do_fmt = fsi_reg_read(fsi, DO_FMT); | 1320 | fsi->saved_do_fmt = fsi_reg_read(fsi, DO_FMT); |
1308 | fsi->saved_di_fmt = fsi_reg_read(fsi, DI_FMT); | 1321 | fsi->saved_di_fmt = fsi_reg_read(fsi, DI_FMT); |
@@ -1311,12 +1324,11 @@ static void __fsi_suspend(struct fsi_priv *fsi, | |||
1311 | fsi->saved_out_sel = fsi_reg_read(fsi, OUT_SEL); | 1324 | fsi->saved_out_sel = fsi_reg_read(fsi, OUT_SEL); |
1312 | 1325 | ||
1313 | if (fsi_is_clk_master(fsi)) | 1326 | if (fsi_is_clk_master(fsi)) |
1314 | set_rate(dev, fsi_is_port_a(fsi), fsi->rate, 0); | 1327 | fsi_set_master_clk(dev, fsi, fsi->rate, 0); |
1315 | } | 1328 | } |
1316 | 1329 | ||
1317 | static void __fsi_resume(struct fsi_priv *fsi, | 1330 | static void __fsi_resume(struct fsi_priv *fsi, |
1318 | struct device *dev, | 1331 | struct device *dev) |
1319 | set_rate_func set_rate) | ||
1320 | { | 1332 | { |
1321 | fsi_reg_write(fsi, DO_FMT, fsi->saved_do_fmt); | 1333 | fsi_reg_write(fsi, DO_FMT, fsi->saved_do_fmt); |
1322 | fsi_reg_write(fsi, DI_FMT, fsi->saved_di_fmt); | 1334 | fsi_reg_write(fsi, DI_FMT, fsi->saved_di_fmt); |
@@ -1325,18 +1337,17 @@ static void __fsi_resume(struct fsi_priv *fsi, | |||
1325 | fsi_reg_write(fsi, OUT_SEL, fsi->saved_out_sel); | 1337 | fsi_reg_write(fsi, OUT_SEL, fsi->saved_out_sel); |
1326 | 1338 | ||
1327 | if (fsi_is_clk_master(fsi)) | 1339 | if (fsi_is_clk_master(fsi)) |
1328 | set_rate(dev, fsi_is_port_a(fsi), fsi->rate, 1); | 1340 | fsi_set_master_clk(dev, fsi, fsi->rate, 1); |
1329 | } | 1341 | } |
1330 | 1342 | ||
1331 | static int fsi_suspend(struct device *dev) | 1343 | static int fsi_suspend(struct device *dev) |
1332 | { | 1344 | { |
1333 | struct fsi_master *master = dev_get_drvdata(dev); | 1345 | struct fsi_master *master = dev_get_drvdata(dev); |
1334 | set_rate_func set_rate = fsi_get_info_set_rate(master); | ||
1335 | 1346 | ||
1336 | pm_runtime_get_sync(dev); | 1347 | pm_runtime_get_sync(dev); |
1337 | 1348 | ||
1338 | __fsi_suspend(&master->fsia, dev, set_rate); | 1349 | __fsi_suspend(&master->fsia, dev); |
1339 | __fsi_suspend(&master->fsib, dev, set_rate); | 1350 | __fsi_suspend(&master->fsib, dev); |
1340 | 1351 | ||
1341 | master->saved_a_mclk = fsi_core_read(master, a_mclk); | 1352 | master->saved_a_mclk = fsi_core_read(master, a_mclk); |
1342 | master->saved_b_mclk = fsi_core_read(master, b_mclk); | 1353 | master->saved_b_mclk = fsi_core_read(master, b_mclk); |
@@ -1355,7 +1366,6 @@ static int fsi_suspend(struct device *dev) | |||
1355 | static int fsi_resume(struct device *dev) | 1366 | static int fsi_resume(struct device *dev) |
1356 | { | 1367 | { |
1357 | struct fsi_master *master = dev_get_drvdata(dev); | 1368 | struct fsi_master *master = dev_get_drvdata(dev); |
1358 | set_rate_func set_rate = fsi_get_info_set_rate(master); | ||
1359 | 1369 | ||
1360 | pm_runtime_get_sync(dev); | 1370 | pm_runtime_get_sync(dev); |
1361 | 1371 | ||
@@ -1368,8 +1378,8 @@ static int fsi_resume(struct device *dev) | |||
1368 | fsi_core_mask_set(master, iemsk, 0xffff, master->saved_iemsk); | 1378 | fsi_core_mask_set(master, iemsk, 0xffff, master->saved_iemsk); |
1369 | fsi_core_mask_set(master, imsk, 0xffff, master->saved_imsk); | 1379 | fsi_core_mask_set(master, imsk, 0xffff, master->saved_imsk); |
1370 | 1380 | ||
1371 | __fsi_resume(&master->fsia, dev, set_rate); | 1381 | __fsi_resume(&master->fsia, dev); |
1372 | __fsi_resume(&master->fsib, dev, set_rate); | 1382 | __fsi_resume(&master->fsib, dev); |
1373 | 1383 | ||
1374 | pm_runtime_put_sync(dev); | 1384 | pm_runtime_put_sync(dev); |
1375 | 1385 | ||