0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/clk.h>
0010 #include <linux/clk-provider.h>
0011 #include <linux/module.h>
0012 #include <linux/of_address.h>
0013 #include <sound/soc.h>
0014
0015 #include "fsl_utils.h"
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
0030 const char *name,
0031 struct snd_soc_dai_link *dai,
0032 unsigned int *dma_channel_id,
0033 unsigned int *dma_id)
0034 {
0035 struct resource res;
0036 struct device_node *dma_channel_np, *dma_np;
0037 const __be32 *iprop;
0038 int ret;
0039
0040 dma_channel_np = of_parse_phandle(ssi_np, name, 0);
0041 if (!dma_channel_np)
0042 return -EINVAL;
0043
0044 if (!of_device_is_compatible(dma_channel_np, "fsl,ssi-dma-channel")) {
0045 of_node_put(dma_channel_np);
0046 return -EINVAL;
0047 }
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 ret = of_address_to_resource(dma_channel_np, 0, &res);
0058 if (ret) {
0059 of_node_put(dma_channel_np);
0060 return ret;
0061 }
0062 snprintf((char *)dai->platforms->name, DAI_NAME_SIZE, "%llx.%pOFn",
0063 (unsigned long long) res.start, dma_channel_np);
0064
0065 iprop = of_get_property(dma_channel_np, "cell-index", NULL);
0066 if (!iprop) {
0067 of_node_put(dma_channel_np);
0068 return -EINVAL;
0069 }
0070 *dma_channel_id = be32_to_cpup(iprop);
0071
0072 dma_np = of_get_parent(dma_channel_np);
0073 iprop = of_get_property(dma_np, "cell-index", NULL);
0074 if (!iprop) {
0075 of_node_put(dma_np);
0076 of_node_put(dma_channel_np);
0077 return -EINVAL;
0078 }
0079 *dma_id = be32_to_cpup(iprop);
0080
0081 of_node_put(dma_np);
0082 of_node_put(dma_channel_np);
0083
0084 return 0;
0085 }
0086 EXPORT_SYMBOL(fsl_asoc_get_dma_channel);
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 void fsl_asoc_get_pll_clocks(struct device *dev, struct clk **pll8k_clk,
0098 struct clk **pll11k_clk)
0099 {
0100 *pll8k_clk = devm_clk_get(dev, "pll8k");
0101 if (IS_ERR(*pll8k_clk))
0102 *pll8k_clk = NULL;
0103
0104 *pll11k_clk = devm_clk_get(dev, "pll11k");
0105 if (IS_ERR(*pll11k_clk))
0106 *pll11k_clk = NULL;
0107 }
0108 EXPORT_SYMBOL(fsl_asoc_get_pll_clocks);
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 void fsl_asoc_reparent_pll_clocks(struct device *dev, struct clk *clk,
0122 struct clk *pll8k_clk,
0123 struct clk *pll11k_clk, u64 ratio)
0124 {
0125 struct clk *p, *pll = NULL, *npll = NULL;
0126 bool reparent = false;
0127 int ret = 0;
0128
0129 if (!clk || !pll8k_clk || !pll11k_clk)
0130 return;
0131
0132 p = clk;
0133 while (p && pll8k_clk && pll11k_clk) {
0134 struct clk *pp = clk_get_parent(p);
0135
0136 if (clk_is_match(pp, pll8k_clk) ||
0137 clk_is_match(pp, pll11k_clk)) {
0138 pll = pp;
0139 break;
0140 }
0141 p = pp;
0142 }
0143
0144 npll = (do_div(ratio, 8000) ? pll11k_clk : pll8k_clk);
0145 reparent = (pll && !clk_is_match(pll, npll));
0146
0147 if (reparent) {
0148 ret = clk_set_parent(p, npll);
0149 if (ret < 0)
0150 dev_warn(dev, "failed to set parent:%d\n", ret);
0151 }
0152 }
0153 EXPORT_SYMBOL(fsl_asoc_reparent_pll_clocks);
0154
0155 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
0156 MODULE_DESCRIPTION("Freescale ASoC utility code");
0157 MODULE_LICENSE("GPL v2");