diff options
author | Stephen Warren <swarren@nvidia.com> | 2011-01-08 00:36:15 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-01-10 17:20:47 -0500 |
commit | a50a399b8ba169816d8afae66bfd42fbb65b1973 (patch) | |
tree | 5e1b7e3bc99e7ccd3c92a247cad7fb37a768f2e4 /sound/soc/tegra | |
parent | 71f78e22146c522b26fc2074fcd9cb81806895b1 (diff) |
ASoC: tegra: Machine utility code
Many portions of Tegra ASoC machine drivers will be similar or identical.
To avoid cut/paste, this file will act as a repository for all that common
code. For now, it solely includes code to reprogram the audio PLL for
44.1KHz- vs. 48KHz-based sample rates.
Signed-Off-By: Stephen Warren <swarren@nvidia.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/tegra')
-rw-r--r-- | sound/soc/tegra/tegra_asoc_utils.c | 154 | ||||
-rw-r--r-- | sound/soc/tegra/tegra_asoc_utils.h | 31 |
2 files changed, 185 insertions, 0 deletions
diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c new file mode 100644 index 000000000000..711ab7ff5ced --- /dev/null +++ b/sound/soc/tegra/tegra_asoc_utils.c | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * tegra_asoc_utils.c - Harmony machine ASoC driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/clk.h> | ||
24 | #include <linux/err.h> | ||
25 | #include <linux/kernel.h> | ||
26 | |||
27 | #include "tegra_asoc_utils.h" | ||
28 | |||
29 | #define PREFIX "ASoC Tegra: " | ||
30 | |||
31 | static struct clk *clk_pll_a; | ||
32 | static struct clk *clk_pll_a_out0; | ||
33 | static struct clk *clk_cdev1; | ||
34 | |||
35 | static int set_baseclock, set_mclk; | ||
36 | |||
37 | int tegra_asoc_utils_set_rate(int srate, int mclk, int *mclk_change) | ||
38 | { | ||
39 | int new_baseclock; | ||
40 | int err; | ||
41 | |||
42 | switch (srate) { | ||
43 | case 11025: | ||
44 | case 22050: | ||
45 | case 44100: | ||
46 | case 88200: | ||
47 | new_baseclock = 56448000; | ||
48 | break; | ||
49 | case 8000: | ||
50 | case 16000: | ||
51 | case 32000: | ||
52 | case 48000: | ||
53 | case 64000: | ||
54 | case 96000: | ||
55 | new_baseclock = 73728000; | ||
56 | break; | ||
57 | default: | ||
58 | return -EINVAL; | ||
59 | } | ||
60 | |||
61 | *mclk_change = ((new_baseclock != set_baseclock) || | ||
62 | (mclk != set_mclk)); | ||
63 | if (!*mclk_change) | ||
64 | return 0; | ||
65 | |||
66 | set_baseclock = 0; | ||
67 | set_mclk = 0; | ||
68 | |||
69 | clk_disable(clk_cdev1); | ||
70 | clk_disable(clk_pll_a_out0); | ||
71 | clk_disable(clk_pll_a); | ||
72 | |||
73 | err = clk_set_rate(clk_pll_a, new_baseclock); | ||
74 | if (err) { | ||
75 | pr_err(PREFIX "Can't set pll_a rate: %d\n", err); | ||
76 | return err; | ||
77 | } | ||
78 | |||
79 | err = clk_set_rate(clk_pll_a_out0, mclk); | ||
80 | if (err) { | ||
81 | pr_err(PREFIX "Can't set pll_a_out0 rate: %d\n", err); | ||
82 | return err; | ||
83 | } | ||
84 | |||
85 | /* Don't set cdev1 rate; its locked to pll_a_out0 */ | ||
86 | |||
87 | err = clk_enable(clk_pll_a); | ||
88 | if (err) { | ||
89 | pr_err(PREFIX "Can't enable pll_a: %d\n", err); | ||
90 | return err; | ||
91 | } | ||
92 | |||
93 | err = clk_enable(clk_pll_a_out0); | ||
94 | if (err) { | ||
95 | pr_err(PREFIX "Can't enable pll_a_out0: %d\n", err); | ||
96 | return err; | ||
97 | } | ||
98 | |||
99 | err = clk_enable(clk_cdev1); | ||
100 | if (err) { | ||
101 | pr_err(PREFIX "Can't enable cdev1: %d\n", err); | ||
102 | return err; | ||
103 | } | ||
104 | |||
105 | set_baseclock = new_baseclock; | ||
106 | set_mclk = mclk; | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | int tegra_asoc_utils_init(void) | ||
112 | { | ||
113 | int ret; | ||
114 | |||
115 | clk_pll_a = clk_get_sys(NULL, "pll_a"); | ||
116 | if (IS_ERR_OR_NULL(clk_pll_a)) { | ||
117 | pr_err(PREFIX "Can't retrieve clk pll_a\n"); | ||
118 | ret = PTR_ERR(clk_pll_a); | ||
119 | goto err; | ||
120 | } | ||
121 | |||
122 | clk_pll_a_out0 = clk_get_sys(NULL, "pll_a_out0"); | ||
123 | if (IS_ERR_OR_NULL(clk_pll_a_out0)) { | ||
124 | pr_err(PREFIX "Can't retrieve clk pll_a_out0\n"); | ||
125 | ret = PTR_ERR(clk_pll_a_out0); | ||
126 | goto err; | ||
127 | } | ||
128 | |||
129 | clk_cdev1 = clk_get_sys(NULL, "cdev1"); | ||
130 | if (IS_ERR_OR_NULL(clk_cdev1)) { | ||
131 | pr_err(PREFIX "Can't retrieve clk cdev1\n"); | ||
132 | ret = PTR_ERR(clk_cdev1); | ||
133 | goto err; | ||
134 | } | ||
135 | |||
136 | return 0; | ||
137 | |||
138 | err: | ||
139 | if (!IS_ERR_OR_NULL(clk_cdev1)) | ||
140 | clk_put(clk_cdev1); | ||
141 | if (!IS_ERR_OR_NULL(clk_pll_a_out0)) | ||
142 | clk_put(clk_pll_a_out0); | ||
143 | if (!IS_ERR_OR_NULL(clk_pll_a)) | ||
144 | clk_put(clk_pll_a); | ||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | void tegra_asoc_utils_fini(void) | ||
149 | { | ||
150 | clk_put(clk_cdev1); | ||
151 | clk_put(clk_pll_a_out0); | ||
152 | clk_put(clk_pll_a); | ||
153 | } | ||
154 | |||
diff --git a/sound/soc/tegra/tegra_asoc_utils.h b/sound/soc/tegra/tegra_asoc_utils.h new file mode 100644 index 000000000000..855f8f6e44ca --- /dev/null +++ b/sound/soc/tegra/tegra_asoc_utils.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * tegra_asoc_utils.h - Definitions for Tegra DAS driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #ifndef __TEGRA_ASOC_UTILS_H__ | ||
24 | #define __TEGRA_ASOC_UTILS_H_ | ||
25 | |||
26 | int tegra_asoc_utils_set_rate(int srate, int mclk_rate, int *mclk_change); | ||
27 | int tegra_asoc_utils_init(void); | ||
28 | void tegra_asoc_utils_fini(void); | ||
29 | |||
30 | #endif | ||
31 | |||