2 * tegra_asoc_utils.c - Harmony machine ASoC driver
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - 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/err.h>
25 #include <linux/kernel.h>
27 #include "tegra_asoc_utils.h"
29 #define PREFIX "ASoC Tegra: "
31 static struct clk *clk_pll_a;
32 static struct clk *clk_pll_a_out0;
33 static struct clk *clk_cdev1;
35 static int set_baseclock, set_mclk;
37 int tegra_asoc_utils_set_rate(int srate, int mclk, int *mclk_change)
47 new_baseclock = 56448000;
55 new_baseclock = 73728000;
61 *mclk_change = ((new_baseclock != set_baseclock) ||
69 clk_disable(clk_cdev1);
70 clk_disable(clk_pll_a_out0);
71 clk_disable(clk_pll_a);
73 err = clk_set_rate(clk_pll_a, new_baseclock);
75 pr_err(PREFIX "Can't set pll_a rate: %d\n", err);
79 err = clk_set_rate(clk_pll_a_out0, mclk);
81 pr_err(PREFIX "Can't set pll_a_out0 rate: %d\n", err);
85 /* Don't set cdev1 rate; its locked to pll_a_out0 */
87 err = clk_enable(clk_pll_a);
89 pr_err(PREFIX "Can't enable pll_a: %d\n", err);
93 err = clk_enable(clk_pll_a_out0);
95 pr_err(PREFIX "Can't enable pll_a_out0: %d\n", err);
99 err = clk_enable(clk_cdev1);
101 pr_err(PREFIX "Can't enable cdev1: %d\n", err);
105 set_baseclock = new_baseclock;
111 int tegra_asoc_utils_init(void)
115 clk_pll_a = clk_get_sys(NULL, "pll_a");
116 if (IS_ERR(clk_pll_a)) {
117 pr_err(PREFIX "Can't retrieve clk pll_a\n");
118 ret = PTR_ERR(clk_pll_a);
122 clk_pll_a_out0 = clk_get_sys(NULL, "pll_a_out0");
123 if (IS_ERR(clk_pll_a_out0)) {
124 pr_err(PREFIX "Can't retrieve clk pll_a_out0\n");
125 ret = PTR_ERR(clk_pll_a_out0);
129 clk_cdev1 = clk_get_sys(NULL, "cdev1");
130 if (IS_ERR(clk_cdev1)) {
131 pr_err(PREFIX "Can't retrieve clk cdev1\n");
132 ret = PTR_ERR(clk_cdev1);
133 goto err_put_pll_a_out0;
139 clk_put(clk_pll_a_out0);
146 void tegra_asoc_utils_fini(void)
149 clk_put(clk_pll_a_out0);