Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: rt5640: Add RL6231 class device shared support for RT5640, RT5645 and RT5651

The patch adds the RL6231 class device shared support for RT5640, RT5645 and
RT5651. The function of the DMIC clock calculation can be shared by RL6231
shared support.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Oder Chiou and committed by
Mark Brown
49ef7925 15f78ea6

+107 -50
+9
sound/soc/codecs/Kconfig
··· 392 392 select SND_SOC_PCM512x 393 393 select REGMAP_SPI 394 394 395 + config SND_SOC_RL6231 396 + tristate 397 + default y if SND_SOC_RT5640=y 398 + default y if SND_SOC_RT5645=y 399 + default y if SND_SOC_RT5651=y 400 + default m if SND_SOC_RT5640=m 401 + default m if SND_SOC_RT5645=m 402 + default m if SND_SOC_RT5651=m 403 + 395 404 config SND_SOC_RT5631 396 405 tristate 397 406
+2
sound/soc/codecs/Makefile
··· 58 58 snd-soc-pcm512x-objs := pcm512x.o 59 59 snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o 60 60 snd-soc-pcm512x-spi-objs := pcm512x-spi.o 61 + snd-soc-rl6231-objs := rl6231.o 61 62 snd-soc-rt5631-objs := rt5631.o 62 63 snd-soc-rt5640-objs := rt5640.o 63 64 snd-soc-rt5645-objs := rt5645.o ··· 212 211 obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o 213 212 obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o 214 213 obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o 214 + obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o 215 215 obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 216 216 obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o 217 217 obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o
+67
sound/soc/codecs/rl6231.c
··· 1 + /* 2 + * rl6231.c - RL6231 class device shared support 3 + * 4 + * Copyright 2014 Realtek Semiconductor Corp. 5 + * 6 + * Author: Oder Chiou <oder_chiou@realtek.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + */ 12 + 13 + #include <linux/module.h> 14 + #include <linux/moduleparam.h> 15 + #include <linux/init.h> 16 + #include <linux/delay.h> 17 + #include <linux/pm.h> 18 + #include <linux/gpio.h> 19 + #include <linux/i2c.h> 20 + #include <linux/regmap.h> 21 + #include <linux/of.h> 22 + #include <linux/of_gpio.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/spi/spi.h> 25 + #include <linux/acpi.h> 26 + #include <sound/core.h> 27 + #include <sound/pcm.h> 28 + #include <sound/pcm_params.h> 29 + #include <sound/soc.h> 30 + #include <sound/soc-dapm.h> 31 + #include <sound/initval.h> 32 + #include <sound/tlv.h> 33 + 34 + #include "rl6231.h" 35 + 36 + /** 37 + * rl6231_calc_dmic_clk - Calculate the parameter of dmic. 38 + * 39 + * @rate: base clock rate. 40 + * 41 + * Choose dmic clock between 1MHz and 3MHz. 42 + * It is better for clock to approximate 3MHz. 43 + */ 44 + int rl6231_calc_dmic_clk(int rate) 45 + { 46 + int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; 47 + int i, red, bound, temp; 48 + 49 + red = 3000000 * 12; 50 + for (i = 0; i < ARRAY_SIZE(div); i++) { 51 + bound = div[i] * 3000000; 52 + if (rate > bound) 53 + continue; 54 + temp = bound - rate; 55 + if (temp < red) { 56 + red = temp; 57 + idx = i; 58 + } 59 + } 60 + 61 + return idx; 62 + } 63 + EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); 64 + 65 + MODULE_DESCRIPTION("RL6231 class device shared support"); 66 + MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>"); 67 + MODULE_LICENSE("GPL v2");
+18
sound/soc/codecs/rl6231.h
··· 1 + /* 2 + * rl6231.h - RL6231 class device shared support 3 + * 4 + * Copyright 2014 Realtek Semiconductor Corp. 5 + * 6 + * Author: Oder Chiou <oder_chiou@realtek.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + */ 12 + 13 + #ifndef __RL6231_H__ 14 + #define __RL6231_H__ 15 + 16 + int rl6231_calc_dmic_clk(int rate); 17 + 18 + #endif /* __RL6231_H__ */
+4 -17
sound/soc/codecs/rt5640.c
··· 30 30 #include <sound/initval.h> 31 31 #include <sound/tlv.h> 32 32 33 + #include "rl6231.h" 33 34 #include "rt5640.h" 34 35 35 36 #define RT5640_DEVICE_ID 0x6231 ··· 453 452 * @kcontrol: The kcontrol of this widget. 454 453 * @event: Event id. 455 454 * 456 - * Choose dmic clock between 1MHz and 3MHz. 457 - * It is better for clock to approximate 3MHz. 458 455 */ 459 456 static int set_dmic_clk(struct snd_soc_dapm_widget *w, 460 457 struct snd_kcontrol *kcontrol, int event) 461 458 { 462 459 struct snd_soc_codec *codec = w->codec; 463 460 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 464 - int div[] = {2, 3, 4, 6, 8, 12}; 465 - int idx = -EINVAL, i; 466 - int rate, red, bound, temp; 461 + int idx = -EINVAL; 467 462 468 - rate = rt5640->sysclk; 469 - red = 3000000 * 12; 470 - for (i = 0; i < ARRAY_SIZE(div); i++) { 471 - bound = div[i] * 3000000; 472 - if (rate > bound) 473 - continue; 474 - temp = bound - rate; 475 - if (temp < red) { 476 - red = temp; 477 - idx = i; 478 - } 479 - } 463 + idx = rl6231_calc_dmic_clk(rt5640->sysclk); 464 + 480 465 if (idx < 0) 481 466 dev_err(codec->dev, "Failed to set DMIC clock\n"); 482 467 else
+3 -17
sound/soc/codecs/rt5645.c
··· 26 26 #include <sound/initval.h> 27 27 #include <sound/tlv.h> 28 28 29 + #include "rl6231.h" 29 30 #include "rt5645.h" 30 31 31 32 #define RT5645_DEVICE_ID 0x6308 ··· 520 519 * @kcontrol: The kcontrol of this widget. 521 520 * @event: Event id. 522 521 * 523 - * Choose dmic clock between 1MHz and 3MHz. 524 - * It is better for clock to approximate 3MHz. 525 522 */ 526 523 static int set_dmic_clk(struct snd_soc_dapm_widget *w, 527 524 struct snd_kcontrol *kcontrol, int event) 528 525 { 529 526 struct snd_soc_codec *codec = w->codec; 530 527 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 531 - int div[] = {2, 3, 4, 6, 8, 12}; 532 - int idx = -EINVAL, i; 533 - int rate, red, bound, temp; 528 + int idx = -EINVAL; 534 529 535 - rate = rt5645->sysclk; 536 - red = 3000000 * 12; 537 - for (i = 0; i < ARRAY_SIZE(div); i++) { 538 - bound = div[i] * 3000000; 539 - if (rate > bound) 540 - continue; 541 - temp = bound - rate; 542 - if (temp < red) { 543 - red = temp; 544 - idx = i; 545 - } 546 - } 530 + idx = rl6231_calc_dmic_clk(rt5645->sysclk); 547 531 548 532 if (idx < 0) 549 533 dev_err(codec->dev, "Failed to set DMIC clock\n");
+4 -16
sound/soc/codecs/rt5651.c
··· 26 26 #include <sound/initval.h> 27 27 #include <sound/tlv.h> 28 28 29 + #include "rl6231.h" 29 30 #include "rt5651.h" 30 31 31 32 #define RT5651_DEVICE_ID_VALUE 0x6281 ··· 372 371 * @kcontrol: The kcontrol of this widget. 373 372 * @event: Event id. 374 373 * 375 - * Choose dmic clock between 1MHz and 3MHz. 376 - * It is better for clock to approximate 3MHz. 377 374 */ 378 375 static int set_dmic_clk(struct snd_soc_dapm_widget *w, 379 376 struct snd_kcontrol *kcontrol, int event) 380 377 { 381 378 struct snd_soc_codec *codec = w->codec; 382 379 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 383 - int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; 384 - int i, rate, red, bound, temp; 380 + int idx = -EINVAL; 385 381 386 - rate = rt5651->sysclk; 387 - red = 3000000 * 12; 388 - for (i = 0; i < ARRAY_SIZE(div); i++) { 389 - bound = div[i] * 3000000; 390 - if (rate > bound) 391 - continue; 392 - temp = bound - rate; 393 - if (temp < red) { 394 - red = temp; 395 - idx = i; 396 - } 397 - } 382 + idx = rl6231_calc_dmic_clk(rt5651->sysclk); 383 + 398 384 if (idx < 0) 399 385 dev_err(codec->dev, "Failed to set DMIC clock\n"); 400 386 else