diff --git a/Makefile b/Makefile index 608e7a3..b9de7f4 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,17 @@ +# +# Peter Yang +# Copyright (c) 2019 Seeed Studio +# +# MIT License +# + +uname_r=$(shell uname -r) + +# If KERNELRELEASE is defined, we've been invoked from the +# kernel build system and can use its language +ifneq ($(KERNELRELEASE),) +# $(warning KERNELVERSION=$(KERNELVERSION)) + snd-soc-wm8960-objs := wm8960.o snd-soc-ac108-objs := ac108.o ac101.o snd-soc-seeed-voicecard-objs := seeed-voicecard.o @@ -14,14 +28,25 @@ endif endif + +else + +DEST := /lib/modules/$(uname_r)/kernel + all: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + make -C /lib/modules/$(uname_r)/build M=$(PWD) modules clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean + make -C /lib/modules/$(uname_r)/build M=$(PWD) clean install: - sudo cp snd-soc-ac108.ko /lib/modules/$(shell uname -r)/kernel/sound/soc/codecs/ - sudo cp snd-soc-wm8960.ko /lib/modules/$(shell uname -r)/kernel/sound/soc/codecs/ - sudo cp snd-soc-seeed-voicecard.ko /lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/ + sudo cp snd-soc-ac108.ko ${DEST}/sound/soc/codecs/ + sudo cp snd-soc-wm8960.ko ${DEST}/sound/soc/codecs/ + sudo cp snd-soc-seeed-voicecard.ko ${DEST}/sound/soc/bcm/ sudo depmod -a + + +.PHONY: all clean install + +endif + diff --git a/ac101.c b/ac101.c index eb212f8..a4bcd62 100644 --- a/ac101.c +++ b/ac101.c @@ -363,7 +363,7 @@ static irqreturn_t audio_hmic_irq(int irq, void *para) static int ac101_switch_probe(struct ac10x_priv *ac10x) { struct i2c_client *i2c = ac10x->i2c101; - int ret; + long ret; ac10x->gpiod_irq = devm_gpiod_get_optional(&i2c->dev, "switch-irq", GPIOD_IN); if (IS_ERR(ac10x->gpiod_irq)) { @@ -376,7 +376,7 @@ static int ac101_switch_probe(struct ac10x_priv *ac10x) { ac10x->irq = gpiod_to_irq(ac10x->gpiod_irq); if (IS_ERR_VALUE(ac10x->irq)) { - pr_info("[ac101] map gpio to irq failed, errno = %d\n", ac10x->irq); + pr_info("[ac101] map gpio to irq failed, errno = %ld\n", ac10x->irq); ac10x->irq = 0; goto _err_irq; } @@ -384,7 +384,7 @@ static int ac101_switch_probe(struct ac10x_priv *ac10x) { /* request irq, set irq type to falling edge trigger */ ret = devm_request_irq(ac10x->codec->dev, ac10x->irq, audio_hmic_irq, IRQF_TRIGGER_FALLING, "SWTICH_EINT", ac10x); if (IS_ERR_VALUE(ret)) { - pr_info("[ac101] request virq %d failed, errno = %d\n", ac10x->irq, ret); + pr_info("[ac101] request virq %ld failed, errno = %ld\n", ac10x->irq, ret); goto _err_irq; } diff --git a/ac108.c b/ac108.c index 9f79735..cd20547 100644 --- a/ac108.c +++ b/ac108.c @@ -1271,6 +1271,12 @@ int ac108_codec_remove(struct snd_soc_codec *codec) { } return ac101_codec_remove(codec); } +#if __NO_SND_SOC_CODEC_DRV +void ac108_codec_remove_void(struct snd_soc_codec *codec) { + ac108_codec_remove(codec); +} +#define ac108_codec_remove ac108_codec_remove_void +#endif int ac108_codec_suspend(struct snd_soc_codec *codec) { struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec); diff --git a/ac10x.h b/ac10x.h index ae371a6..9b83807 100644 --- a/ac10x.h +++ b/ac10x.h @@ -40,6 +40,8 @@ #endif +#include "sound-compatible-4.18.h" + #ifdef CONFIG_AC101_SWITCH_DETECT enum headphone_mode_u { HEADPHONE_IDLE, @@ -78,7 +80,7 @@ struct ac10x_priv { #ifdef CONFIG_AC101_SWITCH_DETECT struct gpio_desc* gpiod_irq; - int irq; + long irq; volatile int irq_cntr; volatile int pullout_cntr; volatile int state; diff --git a/install.sh b/install.sh index 8d93033..380512e 100755 --- a/install.sh +++ b/install.sh @@ -12,7 +12,7 @@ if [ "x${is_Raspberry}" != "xRaspberry" ] ; then fi ver="0.3" - +uname_r=$(uname -r) # we create a dir with this version to ensure that 'dkms remove' won't delete # the sources during kernel updates @@ -35,7 +35,6 @@ fi # locate currently installed kernels (may be different to running kernel if # it's just been updated) kernels=$(ls /lib/modules | sed "s/^/-k /") -uname_r=$(uname -r) function install_module { src=$1 @@ -67,7 +66,7 @@ cp seeed-8mic-voicecard.dtbo /boot/overlays #install alsa plugins # no need this plugin now -# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so +# install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/ rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so #set kernel moduels diff --git a/sound-compatible-4.18.h b/sound-compatible-4.18.h new file mode 100644 index 0000000..dc5a787 --- /dev/null +++ b/sound-compatible-4.18.h @@ -0,0 +1,35 @@ +/* + * (C) Copyright 2017-2018 + * Seeed Technology Co., Ltd. + * + * PeterYang + */ +#ifndef __SOUND_COMPATIBLE_4_18_H__ +#define __SOUND_COMPATIBLE_4_18_H__ + +#include + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) +#define __NO_SND_SOC_CODEC_DRV 1 +#else +#define __NO_SND_SOC_CODEC_DRV 0 +#endif + +#if __NO_SND_SOC_CODEC_DRV +#define codec component +#define snd_soc_codec snd_soc_component +#define snd_soc_codec_driver snd_soc_component_driver +#define snd_soc_codec_get_drvdata snd_soc_component_get_drvdata +#define snd_soc_codec_get_dapm snd_soc_component_get_dapm +#define snd_soc_codec_get_bias_level snd_soc_component_get_bias_level +#define snd_soc_kcontrol_codec snd_soc_kcontrol_component +#define snd_soc_read snd_soc_component_read32 +#define snd_soc_register_codec snd_soc_register_component +#define snd_soc_unregister_codec snd_soc_unregister_component +#define snd_soc_update_bits snd_soc_component_update_bits +#define snd_soc_write snd_soc_component_write +#define snd_soc_add_codec_controls snd_soc_add_component_controls +#endif + +#endif//__SOUND_COMPATIBLE_4_18_H__ + diff --git a/wm8960.c b/wm8960.c index 8f41673..f26f59b 100644 --- a/wm8960.c +++ b/wm8960.c @@ -25,6 +25,7 @@ #include #include #include +#include "sound-compatible-4.18.h" #include "wm8960.h" @@ -507,7 +508,11 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec) * list each time to find the desired power state do so now * and save the result. */ + #if __NO_SND_SOC_CODEC_DRV + list_for_each_entry(w, &codec->card->widgets, list) { + #else list_for_each_entry(w, &codec->component.card->widgets, list) { + #endif if (w->dapm != dapm) continue; if (strcmp(w->name, "LOUT1 PGA") == 0) @@ -1275,7 +1280,13 @@ static int wm8960_probe(struct snd_soc_codec *codec) static const struct snd_soc_codec_driver soc_codec_dev_wm8960 = { .probe = wm8960_probe, .set_bias_level = wm8960_set_bias_level, - .suspend_bias_off = true, + .suspend_bias_off = true, + #if __NO_SND_SOC_CODEC_DRV + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, + #endif }; static const struct regmap_config wm8960_regmap = {