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>
27 #include <linux/module.h>
29 #include "tegra_asoc_utils.h"
31 int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data
*data
, int srate
,
43 new_baseclock
= 56448000;
51 new_baseclock
= 73728000;
57 clk_change
= ((new_baseclock
!= data
->set_baseclock
) ||
58 (mclk
!= data
->set_mclk
));
62 data
->set_baseclock
= 0;
65 clk_disable(data
->clk_cdev1
);
66 clk_disable(data
->clk_pll_a_out0
);
67 clk_disable(data
->clk_pll_a
);
69 err
= clk_set_rate(data
->clk_pll_a
, new_baseclock
);
71 dev_err(data
->dev
, "Can't set pll_a rate: %d\n", err
);
75 err
= clk_set_rate(data
->clk_pll_a_out0
, mclk
);
77 dev_err(data
->dev
, "Can't set pll_a_out0 rate: %d\n", err
);
81 /* Don't set cdev1 rate; its locked to pll_a_out0 */
83 err
= clk_enable(data
->clk_pll_a
);
85 dev_err(data
->dev
, "Can't enable pll_a: %d\n", err
);
89 err
= clk_enable(data
->clk_pll_a_out0
);
91 dev_err(data
->dev
, "Can't enable pll_a_out0: %d\n", err
);
95 err
= clk_enable(data
->clk_cdev1
);
97 dev_err(data
->dev
, "Can't enable cdev1: %d\n", err
);
101 data
->set_baseclock
= new_baseclock
;
102 data
->set_mclk
= mclk
;
106 EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate
);
108 int tegra_asoc_utils_init(struct tegra_asoc_utils_data
*data
,
115 data
->clk_pll_a
= clk_get_sys(NULL
, "pll_a");
116 if (IS_ERR(data
->clk_pll_a
)) {
117 dev_err(data
->dev
, "Can't retrieve clk pll_a\n");
118 ret
= PTR_ERR(data
->clk_pll_a
);
122 data
->clk_pll_a_out0
= clk_get_sys(NULL
, "pll_a_out0");
123 if (IS_ERR(data
->clk_pll_a_out0
)) {
124 dev_err(data
->dev
, "Can't retrieve clk pll_a_out0\n");
125 ret
= PTR_ERR(data
->clk_pll_a_out0
);
129 data
->clk_cdev1
= clk_get_sys(NULL
, "cdev1");
130 if (IS_ERR(data
->clk_cdev1
)) {
131 dev_err(data
->dev
, "Can't retrieve clk cdev1\n");
132 ret
= PTR_ERR(data
->clk_cdev1
);
133 goto err_put_pll_a_out0
;
139 clk_put(data
->clk_pll_a_out0
);
141 clk_put(data
->clk_pll_a
);
145 EXPORT_SYMBOL_GPL(tegra_asoc_utils_init
);
147 void tegra_asoc_utils_fini(struct tegra_asoc_utils_data
*data
)
149 clk_put(data
->clk_cdev1
);
150 clk_put(data
->clk_pll_a_out0
);
151 clk_put(data
->clk_pll_a
);
153 EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini
);
155 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
156 MODULE_DESCRIPTION("Tegra ASoC utility code");
157 MODULE_LICENSE("GPL");