Loading include/sound/rt5677.h 0 → 100644 +21 −0 Original line number Diff line number Diff line /* * linux/sound/rt5677.h -- Platform data for RT5677 * * Copyright 2013 Realtek Semiconductor Corp. * Author: Oder Chiou <oder_chiou@realtek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #ifndef __LINUX_SND_RT5677_H #define __LINUX_SND_RT5677_H struct rt5677_platform_data { /* IN1 IN2 can optionally be differential */ bool in1_diff; bool in2_diff; }; #endif sound/soc/codecs/Kconfig +13 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_RT5640 if I2C select SND_SOC_RT5645 if I2C select SND_SOC_RT5651 if I2C select SND_SOC_RT5677 if I2C select SND_SOC_SGTL5000 if I2C select SND_SOC_SI476X if MFD_SI476X_CORE select SND_SOC_SIRF_AUDIO_CODEC Loading Loading @@ -439,6 +440,15 @@ config SND_SOC_PCM512x_SPI select SND_SOC_PCM512x select REGMAP_SPI config SND_SOC_RL6231 tristate default y if SND_SOC_RT5640=y default y if SND_SOC_RT5645=y default y if SND_SOC_RT5651=y default m if SND_SOC_RT5640=m default m if SND_SOC_RT5645=m default m if SND_SOC_RT5651=m config SND_SOC_RT5631 tristate Loading @@ -451,6 +461,9 @@ config SND_SOC_RT5645 config SND_SOC_RT5651 tristate config SND_SOC_RT5677 tristate #Freescale sgtl5000 codec config SND_SOC_SGTL5000 tristate "Freescale SGTL5000 CODEC" Loading sound/soc/codecs/Makefile +4 −0 Original line number Diff line number Diff line Loading @@ -67,10 +67,12 @@ snd-soc-pcm3008-objs := pcm3008.o snd-soc-pcm512x-objs := pcm512x.o snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o snd-soc-pcm512x-spi-objs := pcm512x-spi.o snd-soc-rl6231-objs := rl6231.o snd-soc-rt5631-objs := rt5631.o snd-soc-rt5640-objs := rt5640.o snd-soc-rt5645-objs := rt5645.o snd-soc-rt5651-objs := rt5651.o snd-soc-rt5677-objs := rt5677.o snd-soc-sgtl5000-objs := sgtl5000.o snd-soc-alc5623-objs := alc5623.o snd-soc-alc5632-objs := alc5632.o Loading Loading @@ -230,10 +232,12 @@ obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o obj-$(CONFIG_SND_SOC_RT5651) += snd-soc-rt5651.o obj-$(CONFIG_SND_SOC_RT5677) += snd-soc-rt5677.o obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o obj-$(CONFIG_SND_SOC_SI476X) += snd-soc-si476x.o Loading sound/soc/codecs/rl6231.c 0 → 100644 +152 −0 Original line number Diff line number Diff line /* * rl6231.c - RL6231 class device shared support * * Copyright 2014 Realtek Semiconductor Corp. * * Author: Oder Chiou <oder_chiou@realtek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/gpio.h> #include <linux/i2c.h> #include <linux/regmap.h> #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/platform_device.h> #include <linux/spi/spi.h> #include <linux/acpi.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> #include <sound/soc-dapm.h> #include <sound/initval.h> #include <sound/tlv.h> #include "rl6231.h" /** * rl6231_calc_dmic_clk - Calculate the parameter of dmic. * * @rate: base clock rate. * * Choose dmic clock between 1MHz and 3MHz. * It is better for clock to approximate 3MHz. */ int rl6231_calc_dmic_clk(int rate) { int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; int i, red, bound, temp; red = 3000000 * 12; for (i = 0; i < ARRAY_SIZE(div); i++) { bound = div[i] * 3000000; if (rate > bound) continue; temp = bound - rate; if (temp < red) { red = temp; idx = i; } } return idx; } EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); /** * rl6231_pll_calc - Calcualte PLL M/N/K code. * @freq_in: external clock provided to codec. * @freq_out: target clock which codec works on. * @pll_code: Pointer to structure with M, N, K and bypass flag. * * Calcualte M/N/K code to configure PLL for codec. * * Returns 0 for success or negative error code. */ int rl6231_pll_calc(const unsigned int freq_in, const unsigned int freq_out, struct rl6231_pll_code *pll_code) { int max_n = RL6231_PLL_N_MAX, max_m = RL6231_PLL_M_MAX; int k, red, n_t, pll_out, in_t, out_t; int n = 0, m = 0, m_t = 0; int red_t = abs(freq_out - freq_in); bool bypass = false; if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in) return -EINVAL; k = 100000000 / freq_out - 2; if (k > RL6231_PLL_K_MAX) k = RL6231_PLL_K_MAX; for (n_t = 0; n_t <= max_n; n_t++) { in_t = freq_in / (k + 2); pll_out = freq_out / (n_t + 2); if (in_t < 0) continue; if (in_t == pll_out) { bypass = true; n = n_t; goto code_find; } red = abs(in_t - pll_out); if (red < red_t) { bypass = true; n = n_t; m = m_t; if (red == 0) goto code_find; red_t = red; } for (m_t = 0; m_t <= max_m; m_t++) { out_t = in_t / (m_t + 2); red = abs(out_t - pll_out); if (red < red_t) { bypass = false; n = n_t; m = m_t; if (red == 0) goto code_find; red_t = red; } } } pr_debug("Only get approximation about PLL\n"); code_find: pll_code->m_bp = bypass; pll_code->m_code = m; pll_code->n_code = n; pll_code->k_code = k; return 0; } EXPORT_SYMBOL_GPL(rl6231_pll_calc); int rl6231_get_clk_info(int sclk, int rate) { int i, pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; if (sclk <= 0 || rate <= 0) return -EINVAL; rate = rate << 8; for (i = 0; i < ARRAY_SIZE(pd); i++) if (sclk == rate * pd[i]) return i; return -EINVAL; } EXPORT_SYMBOL_GPL(rl6231_get_clk_info); MODULE_DESCRIPTION("RL6231 class device shared support"); MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>"); MODULE_LICENSE("GPL v2"); sound/soc/codecs/rl6231.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * rl6231.h - RL6231 class device shared support * * Copyright 2014 Realtek Semiconductor Corp. * * Author: Oder Chiou <oder_chiou@realtek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #ifndef __RL6231_H__ #define __RL6231_H__ #define RL6231_PLL_INP_MAX 40000000 #define RL6231_PLL_INP_MIN 256000 #define RL6231_PLL_N_MAX 0x1ff #define RL6231_PLL_K_MAX 0x1f #define RL6231_PLL_M_MAX 0xf struct rl6231_pll_code { bool m_bp; /* Indicates bypass m code or not. */ int m_code; int n_code; int k_code; }; int rl6231_calc_dmic_clk(int rate); int rl6231_pll_calc(const unsigned int freq_in, const unsigned int freq_out, struct rl6231_pll_code *pll_code); int rl6231_get_clk_info(int sclk, int rate); #endif /* __RL6231_H__ */ Loading
include/sound/rt5677.h 0 → 100644 +21 −0 Original line number Diff line number Diff line /* * linux/sound/rt5677.h -- Platform data for RT5677 * * Copyright 2013 Realtek Semiconductor Corp. * Author: Oder Chiou <oder_chiou@realtek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #ifndef __LINUX_SND_RT5677_H #define __LINUX_SND_RT5677_H struct rt5677_platform_data { /* IN1 IN2 can optionally be differential */ bool in1_diff; bool in2_diff; }; #endif
sound/soc/codecs/Kconfig +13 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_RT5640 if I2C select SND_SOC_RT5645 if I2C select SND_SOC_RT5651 if I2C select SND_SOC_RT5677 if I2C select SND_SOC_SGTL5000 if I2C select SND_SOC_SI476X if MFD_SI476X_CORE select SND_SOC_SIRF_AUDIO_CODEC Loading Loading @@ -439,6 +440,15 @@ config SND_SOC_PCM512x_SPI select SND_SOC_PCM512x select REGMAP_SPI config SND_SOC_RL6231 tristate default y if SND_SOC_RT5640=y default y if SND_SOC_RT5645=y default y if SND_SOC_RT5651=y default m if SND_SOC_RT5640=m default m if SND_SOC_RT5645=m default m if SND_SOC_RT5651=m config SND_SOC_RT5631 tristate Loading @@ -451,6 +461,9 @@ config SND_SOC_RT5645 config SND_SOC_RT5651 tristate config SND_SOC_RT5677 tristate #Freescale sgtl5000 codec config SND_SOC_SGTL5000 tristate "Freescale SGTL5000 CODEC" Loading
sound/soc/codecs/Makefile +4 −0 Original line number Diff line number Diff line Loading @@ -67,10 +67,12 @@ snd-soc-pcm3008-objs := pcm3008.o snd-soc-pcm512x-objs := pcm512x.o snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o snd-soc-pcm512x-spi-objs := pcm512x-spi.o snd-soc-rl6231-objs := rl6231.o snd-soc-rt5631-objs := rt5631.o snd-soc-rt5640-objs := rt5640.o snd-soc-rt5645-objs := rt5645.o snd-soc-rt5651-objs := rt5651.o snd-soc-rt5677-objs := rt5677.o snd-soc-sgtl5000-objs := sgtl5000.o snd-soc-alc5623-objs := alc5623.o snd-soc-alc5632-objs := alc5632.o Loading Loading @@ -230,10 +232,12 @@ obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o obj-$(CONFIG_SND_SOC_RT5651) += snd-soc-rt5651.o obj-$(CONFIG_SND_SOC_RT5677) += snd-soc-rt5677.o obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o obj-$(CONFIG_SND_SOC_SI476X) += snd-soc-si476x.o Loading
sound/soc/codecs/rl6231.c 0 → 100644 +152 −0 Original line number Diff line number Diff line /* * rl6231.c - RL6231 class device shared support * * Copyright 2014 Realtek Semiconductor Corp. * * Author: Oder Chiou <oder_chiou@realtek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/gpio.h> #include <linux/i2c.h> #include <linux/regmap.h> #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/platform_device.h> #include <linux/spi/spi.h> #include <linux/acpi.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> #include <sound/soc-dapm.h> #include <sound/initval.h> #include <sound/tlv.h> #include "rl6231.h" /** * rl6231_calc_dmic_clk - Calculate the parameter of dmic. * * @rate: base clock rate. * * Choose dmic clock between 1MHz and 3MHz. * It is better for clock to approximate 3MHz. */ int rl6231_calc_dmic_clk(int rate) { int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; int i, red, bound, temp; red = 3000000 * 12; for (i = 0; i < ARRAY_SIZE(div); i++) { bound = div[i] * 3000000; if (rate > bound) continue; temp = bound - rate; if (temp < red) { red = temp; idx = i; } } return idx; } EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); /** * rl6231_pll_calc - Calcualte PLL M/N/K code. * @freq_in: external clock provided to codec. * @freq_out: target clock which codec works on. * @pll_code: Pointer to structure with M, N, K and bypass flag. * * Calcualte M/N/K code to configure PLL for codec. * * Returns 0 for success or negative error code. */ int rl6231_pll_calc(const unsigned int freq_in, const unsigned int freq_out, struct rl6231_pll_code *pll_code) { int max_n = RL6231_PLL_N_MAX, max_m = RL6231_PLL_M_MAX; int k, red, n_t, pll_out, in_t, out_t; int n = 0, m = 0, m_t = 0; int red_t = abs(freq_out - freq_in); bool bypass = false; if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in) return -EINVAL; k = 100000000 / freq_out - 2; if (k > RL6231_PLL_K_MAX) k = RL6231_PLL_K_MAX; for (n_t = 0; n_t <= max_n; n_t++) { in_t = freq_in / (k + 2); pll_out = freq_out / (n_t + 2); if (in_t < 0) continue; if (in_t == pll_out) { bypass = true; n = n_t; goto code_find; } red = abs(in_t - pll_out); if (red < red_t) { bypass = true; n = n_t; m = m_t; if (red == 0) goto code_find; red_t = red; } for (m_t = 0; m_t <= max_m; m_t++) { out_t = in_t / (m_t + 2); red = abs(out_t - pll_out); if (red < red_t) { bypass = false; n = n_t; m = m_t; if (red == 0) goto code_find; red_t = red; } } } pr_debug("Only get approximation about PLL\n"); code_find: pll_code->m_bp = bypass; pll_code->m_code = m; pll_code->n_code = n; pll_code->k_code = k; return 0; } EXPORT_SYMBOL_GPL(rl6231_pll_calc); int rl6231_get_clk_info(int sclk, int rate) { int i, pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; if (sclk <= 0 || rate <= 0) return -EINVAL; rate = rate << 8; for (i = 0; i < ARRAY_SIZE(pd); i++) if (sclk == rate * pd[i]) return i; return -EINVAL; } EXPORT_SYMBOL_GPL(rl6231_get_clk_info); MODULE_DESCRIPTION("RL6231 class device shared support"); MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>"); MODULE_LICENSE("GPL v2");
sound/soc/codecs/rl6231.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * rl6231.h - RL6231 class device shared support * * Copyright 2014 Realtek Semiconductor Corp. * * Author: Oder Chiou <oder_chiou@realtek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #ifndef __RL6231_H__ #define __RL6231_H__ #define RL6231_PLL_INP_MAX 40000000 #define RL6231_PLL_INP_MIN 256000 #define RL6231_PLL_N_MAX 0x1ff #define RL6231_PLL_K_MAX 0x1f #define RL6231_PLL_M_MAX 0xf struct rl6231_pll_code { bool m_bp; /* Indicates bypass m code or not. */ int m_code; int n_code; int k_code; }; int rl6231_calc_dmic_clk(int rate); int rl6231_pll_calc(const unsigned int freq_in, const unsigned int freq_out, struct rl6231_pll_code *pll_code); int rl6231_get_clk_info(int sclk, int rate); #endif /* __RL6231_H__ */