forked from GothAck/hifimems-kmod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of hifimems kernel module & device tree overlay
- Loading branch information
0 parents
commit 5900119
Showing
6 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.o | ||
.hifimems* | ||
*.ko | ||
*.dtbo | ||
*.mod.c | ||
Module* | ||
modules.order | ||
.tmp_versions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
obj-m += hifimems-soundcard.o hifimems-codec.o | ||
SRC := $(shell pwd) | ||
|
||
all: devicetree | ||
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules | ||
|
||
modules_install: devicetree | ||
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install | ||
cp hifimems-soundcard.dtbo /boot/overlays/ | ||
|
||
clean: clean-local | ||
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) clean | ||
|
||
clean-local: | ||
rm hifimems-soundcard.dtbo || true | ||
|
||
hifimems-soundcard.dtbo: | ||
dtc -@ -I dts -O dtb -o hifimems-soundcard.dtbo hifimems-soundcard-overlay.dts | ||
|
||
devicetree: hifimems-soundcard.dtbo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# AoSC Driver Simple I2S Hifiberry and ICS43432 MEMS | ||
|
||
> Use Hifiberry-dac / Adafruit Speaker Bonnet and ICS43432 / SPH0645 I2S MEMS Mic simultaneously | ||
Tested with: | ||
- [Adafruit I2S MEMS Microphone Breakout](https://www.adafruit.com/product/3421) | ||
- [Adafruit I2S 3W Stereo Speaker Bonnet for Raspberry Pi](https://www.adafruit.com/product/3346) | ||
|
||
Based on googlevoicehat-{codec,soundcard}.c by Peter Malkin. | ||
|
||
## Install | ||
|
||
This was installed successfully on Linux 4.9.35+ on a Raspberry Pi Zero W | ||
|
||
```sh | ||
sudo apt-get install raspberrypi-kernel-headers | ||
|
||
git clone https://github.com/GothAck/hifimems-kmod | ||
cd hifimems-kmod | ||
|
||
make KERNEL_SRC=/lib/modules/$(uname -r)/build all | ||
sudo make KERNEL_SRC=/lib/modules/$(uname -r)/build modules_install | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Simple driver for Hifiberry and ICS43432 MEMS microphone compatible hardware | ||
* | ||
* Author: Greg Miell <[email protected]> | ||
* Copyright 2017 | ||
* Based on googlevoicehat-codec.c by Peter Malkin | ||
* | ||
* 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. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
*/ | ||
|
||
#include <linux/device.h> | ||
#include <linux/err.h> | ||
#include <linux/init.h> | ||
#include <linux/kernel.h> | ||
#include <linux/mod_devicetable.h> | ||
#include <linux/module.h> | ||
#include <linux/of.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/version.h> | ||
#include <sound/pcm.h> | ||
#include <sound/soc.h> | ||
#include <sound/soc-dai.h> | ||
#include <sound/soc-dapm.h> | ||
|
||
static int hifimems_codec_probe(struct snd_soc_codec *codec) { | ||
return 0; | ||
} | ||
|
||
static int hifimems_codec_remove(struct snd_soc_codec *codec) { | ||
return 0; | ||
} | ||
|
||
static const struct snd_soc_dapm_widget hifimems_dapm_widgets[] = { | ||
SND_SOC_DAPM_OUTPUT("Speaker"), | ||
}; | ||
|
||
static const struct snd_soc_dapm_route hifimems_dapm_routes[] = { | ||
{"Speaker", NULL, "Playback"}, | ||
}; | ||
|
||
static struct snd_soc_codec_driver hifimems_codec_driver = { | ||
.probe = hifimems_codec_probe, | ||
.remove = hifimems_codec_remove, | ||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) | ||
.component_driver = { | ||
#endif | ||
.dapm_widgets = hifimems_dapm_widgets, | ||
.num_dapm_widgets = ARRAY_SIZE(hifimems_dapm_widgets), | ||
.dapm_routes = hifimems_dapm_routes, | ||
.num_dapm_routes = ARRAY_SIZE(hifimems_dapm_routes), | ||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) | ||
}, | ||
#endif | ||
}; | ||
|
||
static struct snd_soc_dai_driver hifimems_dai = { | ||
.name = "hifimems-hifi", | ||
.capture = {.stream_name = "Capture", | ||
.channels_min = 2, | ||
.channels_max = 2, | ||
.rates = SNDRV_PCM_RATE_48000, | ||
.formats = SNDRV_PCM_FMTBIT_S32_LE}, | ||
.playback = {.stream_name = "Playback", | ||
.channels_min = 2, | ||
.channels_max = 2, | ||
.rates = SNDRV_PCM_RATE_48000, | ||
.formats = SNDRV_PCM_FMTBIT_S32_LE}, | ||
.symmetric_rates = 1}; | ||
|
||
#ifdef CONFIG_OF | ||
static const struct of_device_id hifimems_ids[] = { | ||
{ | ||
.compatible = "hifimems,hifimems", | ||
}, | ||
{}}; | ||
MODULE_DEVICE_TABLE(of, hifimems_ids); | ||
#endif | ||
|
||
static int hifimems_platform_probe(struct platform_device *pdev) { | ||
return snd_soc_register_codec(&pdev->dev, &hifimems_codec_driver, &hifimems_dai, 1); | ||
} | ||
|
||
static int hifimems_platform_remove(struct platform_device *pdev) { | ||
snd_soc_unregister_codec(&pdev->dev); | ||
return 0; | ||
} | ||
|
||
static struct platform_driver hifimems_driver = { | ||
.driver = | ||
{ | ||
.name = "hifimems-codec", .of_match_table = of_match_ptr(hifimems_ids), | ||
}, | ||
.probe = hifimems_platform_probe, | ||
.remove = hifimems_platform_remove, | ||
}; | ||
|
||
module_platform_driver(hifimems_driver); | ||
|
||
MODULE_DESCRIPTION("Simple I2S Hifiberry & ICS43432 MEMS Codec"); | ||
MODULE_AUTHOR("Greg Miell <[email protected]>"); | ||
MODULE_LICENSE("GPL v2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Simple driver for Hifiberry and ICS43432 MEMS microphone compatible hardware | ||
/dts-v1/; | ||
/plugin/; | ||
|
||
/ { | ||
compatible = "brcm,bcm2708"; | ||
|
||
fragment@0 { | ||
target = <&i2s>; | ||
__overlay__ { | ||
status = "okay"; | ||
}; | ||
}; | ||
|
||
fragment@2 { | ||
target-path = "/"; | ||
__overlay__ { | ||
hifimems-codec { | ||
#sound-dai-cells = <0>; | ||
compatible = "hifimems,hifimems"; | ||
status = "okay"; | ||
}; | ||
}; | ||
}; | ||
|
||
fragment@3 { | ||
target = <&sound>; | ||
__overlay__ { | ||
compatible = "hifimems,hifimems-soundcard"; | ||
i2s-controller = <&i2s>; | ||
status = "okay"; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Simple driver for Hifiberry and ICS43432 MEMS microphone compatible hardware | ||
* | ||
* Author: Greg Miell <[email protected]> | ||
* Copyright 2017 | ||
* Based on googlevoicehat-soundcard.c by Peter Malkin | ||
* | ||
* 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. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/platform_device.h> | ||
|
||
#include <sound/core.h> | ||
#include <sound/pcm.h> | ||
#include <sound/pcm_params.h> | ||
#include <sound/soc.h> | ||
#include <sound/jack.h> | ||
|
||
static int snd_rpi_hifimems_soundcard_init(struct snd_soc_pcm_runtime *rtd) | ||
{ | ||
return 0; | ||
} | ||
|
||
static int snd_rpi_hifimems_soundcard_hw_params( | ||
struct snd_pcm_substream *substream, | ||
struct snd_pcm_hw_params *params) | ||
{ | ||
struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
|
||
unsigned int sample_bits = | ||
snd_pcm_format_physical_width(params_format(params)); | ||
|
||
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2); | ||
} | ||
|
||
/* machine stream operations */ | ||
static struct snd_soc_ops snd_rpi_hifimems_soundcard_ops = { | ||
.hw_params = snd_rpi_hifimems_soundcard_hw_params, | ||
}; | ||
|
||
static struct snd_soc_dai_link snd_rpi_hifimems_soundcard_dai[] = { | ||
{ | ||
.name = "I2S Hifiberry & ICS43432", | ||
.stream_name = "I2S Hifiberry & ICS43432 Audio", | ||
.cpu_dai_name = "bcm2708-i2s.0", | ||
.codec_dai_name = "hifimems-hifi", | ||
.platform_name = "bcm2708-i2s.0", | ||
.codec_name = "hifimems-codec", | ||
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
SND_SOC_DAIFMT_CBS_CFS, | ||
.ops = &snd_rpi_hifimems_soundcard_ops, | ||
.init = snd_rpi_hifimems_soundcard_init, | ||
}, | ||
}; | ||
|
||
/* audio machine driver */ | ||
static struct snd_soc_card snd_rpi_hifimems_soundcard = { | ||
.name = "snd_rpi_hifimems_soundcard", | ||
.owner = THIS_MODULE, | ||
.dai_link = snd_rpi_hifimems_soundcard_dai, | ||
.num_links = ARRAY_SIZE(snd_rpi_hifimems_soundcard_dai), | ||
}; | ||
|
||
static int snd_rpi_hifimems_soundcard_probe(struct platform_device *pdev) | ||
{ | ||
int ret = 0; | ||
|
||
snd_rpi_hifimems_soundcard.dev = &pdev->dev; | ||
|
||
if (pdev->dev.of_node) { | ||
struct device_node *i2s_node; | ||
struct snd_soc_dai_link *dai = &snd_rpi_hifimems_soundcard_dai[0]; | ||
i2s_node = of_parse_phandle(pdev->dev.of_node, | ||
"i2s-controller", 0); | ||
|
||
if (i2s_node) { | ||
dai->cpu_dai_name = NULL; | ||
dai->cpu_of_node = i2s_node; | ||
dai->platform_name = NULL; | ||
dai->platform_of_node = i2s_node; | ||
} | ||
} | ||
|
||
ret = snd_soc_register_card(&snd_rpi_hifimems_soundcard); | ||
if (ret) | ||
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); | ||
|
||
return ret; | ||
} | ||
|
||
static int snd_rpi_hifimems_soundcard_remove(struct platform_device *pdev) | ||
{ | ||
return snd_soc_unregister_card(&snd_rpi_hifimems_soundcard); | ||
} | ||
|
||
static const struct of_device_id snd_rpi_hifimems_soundcard_of_match[] = { | ||
{ .compatible = "hifimems,hifimems-soundcard", }, | ||
{}, | ||
}; | ||
MODULE_DEVICE_TABLE(of, snd_rpi_hifimems_soundcard_of_match); | ||
|
||
static struct platform_driver snd_rpi_hifimems_soundcard_driver = { | ||
.driver = { | ||
.name = "snd-hifimems-soundcard", | ||
.owner = THIS_MODULE, | ||
.of_match_table = snd_rpi_hifimems_soundcard_of_match, | ||
}, | ||
.probe = snd_rpi_hifimems_soundcard_probe, | ||
.remove = snd_rpi_hifimems_soundcard_remove, | ||
}; | ||
|
||
module_platform_driver(snd_rpi_hifimems_soundcard_driver); | ||
|
||
MODULE_DESCRIPTION("AoSC Driver Simple I2S Hifiberry and ICS43432 MEMS"); | ||
MODULE_AUTHOR("Greg Miell <[email protected]>"); | ||
MODULE_LICENSE("GPL v2"); |