2 * tegra_asoc_utils.c - Harmony machine ASoC driver
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
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.
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.
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
23 #include <linux/clk.h>
24 #include <linux/device.h>
25 #include <linux/err.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include "tegra_asoc_utils.h"
32 int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data
*data
, int srate
,
44 if (data
->soc
== TEGRA_ASOC_UTILS_SOC_TEGRA20
)
45 new_baseclock
= 56448000;
46 else if (data
->soc
== TEGRA_ASOC_UTILS_SOC_TEGRA30
)
47 new_baseclock
= 564480000;
49 new_baseclock
= 282240000;
57 if (data
->soc
== TEGRA_ASOC_UTILS_SOC_TEGRA20
)
58 new_baseclock
= 73728000;
59 else if (data
->soc
== TEGRA_ASOC_UTILS_SOC_TEGRA30
)
60 new_baseclock
= 552960000;
62 new_baseclock
= 368640000;
68 clk_change
= ((new_baseclock
!= data
->set_baseclock
) ||
69 (mclk
!= data
->set_mclk
));
73 data
->set_baseclock
= 0;
76 clk_disable_unprepare(data
->clk_cdev1
);
77 clk_disable_unprepare(data
->clk_pll_a_out0
);
78 clk_disable_unprepare(data
->clk_pll_a
);
80 err
= clk_set_rate(data
->clk_pll_a
, new_baseclock
);
82 dev_err(data
->dev
, "Can't set pll_a rate: %d\n", err
);
86 err
= clk_set_rate(data
->clk_pll_a_out0
, mclk
);
88 dev_err(data
->dev
, "Can't set pll_a_out0 rate: %d\n", err
);
92 /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
94 err
= clk_prepare_enable(data
->clk_pll_a
);
96 dev_err(data
->dev
, "Can't enable pll_a: %d\n", err
);
100 err
= clk_prepare_enable(data
->clk_pll_a_out0
);
102 dev_err(data
->dev
, "Can't enable pll_a_out0: %d\n", err
);
106 err
= clk_prepare_enable(data
->clk_cdev1
);
108 dev_err(data
->dev
, "Can't enable cdev1: %d\n", err
);
112 data
->set_baseclock
= new_baseclock
;
113 data
->set_mclk
= mclk
;
117 EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate
);
119 int tegra_asoc_utils_set_ac97_rate(struct tegra_asoc_utils_data
*data
)
121 const int pll_rate
= 73728000;
122 const int ac97_rate
= 24576000;
125 clk_disable_unprepare(data
->clk_cdev1
);
126 clk_disable_unprepare(data
->clk_pll_a_out0
);
127 clk_disable_unprepare(data
->clk_pll_a
);
130 * AC97 rate is fixed at 24.576MHz and is used for both the host
131 * controller and the external codec
133 err
= clk_set_rate(data
->clk_pll_a
, pll_rate
);
135 dev_err(data
->dev
, "Can't set pll_a rate: %d\n", err
);
139 err
= clk_set_rate(data
->clk_pll_a_out0
, ac97_rate
);
141 dev_err(data
->dev
, "Can't set pll_a_out0 rate: %d\n", err
);
145 /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
147 err
= clk_prepare_enable(data
->clk_pll_a
);
149 dev_err(data
->dev
, "Can't enable pll_a: %d\n", err
);
153 err
= clk_prepare_enable(data
->clk_pll_a_out0
);
155 dev_err(data
->dev
, "Can't enable pll_a_out0: %d\n", err
);
159 err
= clk_prepare_enable(data
->clk_cdev1
);
161 dev_err(data
->dev
, "Can't enable cdev1: %d\n", err
);
165 data
->set_baseclock
= pll_rate
;
166 data
->set_mclk
= ac97_rate
;
170 EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_ac97_rate
);
172 int tegra_asoc_utils_init(struct tegra_asoc_utils_data
*data
,
179 if (of_machine_is_compatible("nvidia,tegra20"))
180 data
->soc
= TEGRA_ASOC_UTILS_SOC_TEGRA20
;
181 else if (of_machine_is_compatible("nvidia,tegra30"))
182 data
->soc
= TEGRA_ASOC_UTILS_SOC_TEGRA30
;
183 else if (of_machine_is_compatible("nvidia,tegra114"))
184 data
->soc
= TEGRA_ASOC_UTILS_SOC_TEGRA114
;
186 dev_err(data
->dev
, "SoC unknown to Tegra ASoC utils\n");
190 data
->clk_pll_a
= clk_get(dev
, "pll_a");
191 if (IS_ERR(data
->clk_pll_a
)) {
192 dev_err(data
->dev
, "Can't retrieve clk pll_a\n");
193 ret
= PTR_ERR(data
->clk_pll_a
);
197 data
->clk_pll_a_out0
= clk_get(dev
, "pll_a_out0");
198 if (IS_ERR(data
->clk_pll_a_out0
)) {
199 dev_err(data
->dev
, "Can't retrieve clk pll_a_out0\n");
200 ret
= PTR_ERR(data
->clk_pll_a_out0
);
204 data
->clk_cdev1
= clk_get(dev
, "mclk");
205 if (IS_ERR(data
->clk_cdev1
)) {
206 dev_err(data
->dev
, "Can't retrieve clk cdev1\n");
207 ret
= PTR_ERR(data
->clk_cdev1
);
208 goto err_put_pll_a_out0
;
211 ret
= tegra_asoc_utils_set_rate(data
, 44100, 256 * 44100);
218 clk_put(data
->clk_cdev1
);
220 clk_put(data
->clk_pll_a_out0
);
222 clk_put(data
->clk_pll_a
);
226 EXPORT_SYMBOL_GPL(tegra_asoc_utils_init
);
228 void tegra_asoc_utils_fini(struct tegra_asoc_utils_data
*data
)
230 clk_put(data
->clk_cdev1
);
231 clk_put(data
->clk_pll_a_out0
);
232 clk_put(data
->clk_pll_a
);
234 EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini
);
236 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
237 MODULE_DESCRIPTION("Tegra ASoC utility code");
238 MODULE_LICENSE("GPL");