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/device.h>
25 #include <linux/err.h>
26 #include <linux/kernel.h>
28 #include "tegra_asoc_utils.h"
30 int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data
*data
, int srate
,
42 new_baseclock
= 56448000;
50 new_baseclock
= 73728000;
56 clk_change
= ((new_baseclock
!= data
->set_baseclock
) ||
57 (mclk
!= data
->set_mclk
));
61 data
->set_baseclock
= 0;
64 clk_disable(data
->clk_cdev1
);
65 clk_disable(data
->clk_pll_a_out0
);
66 clk_disable(data
->clk_pll_a
);
68 err
= clk_set_rate(data
->clk_pll_a
, new_baseclock
);
70 dev_err(data
->dev
, "Can't set pll_a rate: %d\n", err
);
74 err
= clk_set_rate(data
->clk_pll_a_out0
, mclk
);
76 dev_err(data
->dev
, "Can't set pll_a_out0 rate: %d\n", err
);
80 /* Don't set cdev1 rate; its locked to pll_a_out0 */
82 err
= clk_enable(data
->clk_pll_a
);
84 dev_err(data
->dev
, "Can't enable pll_a: %d\n", err
);
88 err
= clk_enable(data
->clk_pll_a_out0
);
90 dev_err(data
->dev
, "Can't enable pll_a_out0: %d\n", err
);
94 err
= clk_enable(data
->clk_cdev1
);
96 dev_err(data
->dev
, "Can't enable cdev1: %d\n", err
);
100 data
->set_baseclock
= new_baseclock
;
101 data
->set_mclk
= mclk
;
105 EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate
);
107 int tegra_asoc_utils_init(struct tegra_asoc_utils_data
*data
,
114 data
->clk_pll_a
= clk_get_sys(NULL
, "pll_a");
115 if (IS_ERR(data
->clk_pll_a
)) {
116 dev_err(data
->dev
, "Can't retrieve clk pll_a\n");
117 ret
= PTR_ERR(data
->clk_pll_a
);
121 data
->clk_pll_a_out0
= clk_get_sys(NULL
, "pll_a_out0");
122 if (IS_ERR(data
->clk_pll_a_out0
)) {
123 dev_err(data
->dev
, "Can't retrieve clk pll_a_out0\n");
124 ret
= PTR_ERR(data
->clk_pll_a_out0
);
128 data
->clk_cdev1
= clk_get_sys(NULL
, "cdev1");
129 if (IS_ERR(data
->clk_cdev1
)) {
130 dev_err(data
->dev
, "Can't retrieve clk cdev1\n");
131 ret
= PTR_ERR(data
->clk_cdev1
);
132 goto err_put_pll_a_out0
;
138 clk_put(data
->clk_pll_a_out0
);
140 clk_put(data
->clk_pll_a
);
144 EXPORT_SYMBOL_GPL(tegra_asoc_utils_init
);
146 void tegra_asoc_utils_fini(struct tegra_asoc_utils_data
*data
)
148 clk_put(data
->clk_cdev1
);
149 clk_put(data
->clk_pll_a_out0
);
150 clk_put(data
->clk_pll_a
);
152 EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini
);
154 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
155 MODULE_DESCRIPTION("Tegra ASoC utility code");
156 MODULE_LICENSE("GPL");