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;
47 new_baseclock
= 564480000;
55 if (data
->soc
== TEGRA_ASOC_UTILS_SOC_TEGRA20
)
56 new_baseclock
= 73728000;
58 new_baseclock
= 552960000;
64 clk_change
= ((new_baseclock
!= data
->set_baseclock
) ||
65 (mclk
!= data
->set_mclk
));
69 data
->set_baseclock
= 0;
72 clk_disable_unprepare(data
->clk_cdev1
);
73 clk_disable_unprepare(data
->clk_pll_a_out0
);
74 clk_disable_unprepare(data
->clk_pll_a
);
76 err
= clk_set_rate(data
->clk_pll_a
, new_baseclock
);
78 dev_err(data
->dev
, "Can't set pll_a rate: %d\n", err
);
82 err
= clk_set_rate(data
->clk_pll_a_out0
, mclk
);
84 dev_err(data
->dev
, "Can't set pll_a_out0 rate: %d\n", err
);
88 /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
90 err
= clk_prepare_enable(data
->clk_pll_a
);
92 dev_err(data
->dev
, "Can't enable pll_a: %d\n", err
);
96 err
= clk_prepare_enable(data
->clk_pll_a_out0
);
98 dev_err(data
->dev
, "Can't enable pll_a_out0: %d\n", err
);
102 err
= clk_prepare_enable(data
->clk_cdev1
);
104 dev_err(data
->dev
, "Can't enable cdev1: %d\n", err
);
108 data
->set_baseclock
= new_baseclock
;
109 data
->set_mclk
= mclk
;
113 EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate
);
115 int tegra_asoc_utils_init(struct tegra_asoc_utils_data
*data
,
122 if (of_machine_is_compatible("nvidia,tegra20"))
123 data
->soc
= TEGRA_ASOC_UTILS_SOC_TEGRA20
;
124 else if (of_machine_is_compatible("nvidia,tegra30"))
125 data
->soc
= TEGRA_ASOC_UTILS_SOC_TEGRA30
;
126 else if (!dev
->of_node
)
127 /* non-DT is always Tegra20 */
128 data
->soc
= TEGRA_ASOC_UTILS_SOC_TEGRA20
;
130 /* DT boot, but unknown SoC */
133 data
->clk_pll_a
= clk_get_sys(NULL
, "pll_a");
134 if (IS_ERR(data
->clk_pll_a
)) {
135 dev_err(data
->dev
, "Can't retrieve clk pll_a\n");
136 ret
= PTR_ERR(data
->clk_pll_a
);
140 data
->clk_pll_a_out0
= clk_get_sys(NULL
, "pll_a_out0");
141 if (IS_ERR(data
->clk_pll_a_out0
)) {
142 dev_err(data
->dev
, "Can't retrieve clk pll_a_out0\n");
143 ret
= PTR_ERR(data
->clk_pll_a_out0
);
147 if (data
->soc
== TEGRA_ASOC_UTILS_SOC_TEGRA20
)
148 data
->clk_cdev1
= clk_get_sys(NULL
, "cdev1");
150 data
->clk_cdev1
= clk_get_sys("extern1", NULL
);
151 if (IS_ERR(data
->clk_cdev1
)) {
152 dev_err(data
->dev
, "Can't retrieve clk cdev1\n");
153 ret
= PTR_ERR(data
->clk_cdev1
);
154 goto err_put_pll_a_out0
;
157 ret
= tegra_asoc_utils_set_rate(data
, 44100, 256 * 44100);
164 clk_put(data
->clk_cdev1
);
166 clk_put(data
->clk_pll_a_out0
);
168 clk_put(data
->clk_pll_a
);
172 EXPORT_SYMBOL_GPL(tegra_asoc_utils_init
);
174 void tegra_asoc_utils_fini(struct tegra_asoc_utils_data
*data
)
176 clk_put(data
->clk_cdev1
);
177 clk_put(data
->clk_pll_a_out0
);
178 clk_put(data
->clk_pll_a
);
180 EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini
);
182 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
183 MODULE_DESCRIPTION("Tegra ASoC utility code");
184 MODULE_LICENSE("GPL");