├── README.md ├── .gitignore ├── rpi-es9018k2m-dac-overlay.dts ├── PKGBUILD ├── Makefile ├── Makefile.archLinux ├── es9018k2m.h ├── rpi-es9018k2m-dac.c ├── es9018k2m.c └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # SabreBerry32 2 | Takazine's DAC Board Driver for Raspberry Pi 3 | 4 | SabreBerry32 DAC board information 5 | http://nw-electric.way-nifty.com/blog/sabreberry32.html 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | -------------------------------------------------------------------------------- /rpi-es9018k2m-dac-overlay.dts: -------------------------------------------------------------------------------- 1 | // Definitions for ES9018K2M-DAC 2 | /dts-v1/; 3 | /plugin/; 4 | 5 | / { 6 | compatible = "brcm,bcm2708"; 7 | 8 | fragment@0 { 9 | target = <&sound>; 10 | frag0: __overlay__ { 11 | compatible = "nobody,es9018k2m-dac"; 12 | i2s-controller = <&i2s>; 13 | status = "okay"; 14 | }; 15 | }; 16 | 17 | fragment@1 { 18 | target = <&i2s>; 19 | __overlay__ { 20 | status = "okay"; 21 | }; 22 | }; 23 | 24 | fragment@2 { 25 | target = <&i2c1>; 26 | __overlay__ { 27 | #address-cells = <1>; 28 | #size-cells = <0>; 29 | status = "okay"; 30 | 31 | sabre9018q2c@48 { 32 | #sound-dai-cells = <0>; 33 | compatible = "ess,es9018k2m"; 34 | reg = <0x48>; 35 | status = "okay"; 36 | }; 37 | }; 38 | }; 39 | 40 | __overrides__ { 41 | slave = <&frag0>,"nobody,slave?"; 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | pkgname=ALASabreBerry 2 | pkgver=4.4.7 3 | pkgrel=1 4 | pkgdesc="ES9018Q2C Kernel Modules For Raspberry" 5 | arch=('armv6h' 'armv7h') 6 | license=('GPL') 7 | depends=('linux-raspberrypi') 8 | makedepends=('gcc' 'linux-raspberrypi-headers') 9 | source=("git+https://github.com/SatoruKawase/SabreBerry32.git" 10 | "Makefile.archlinux.patch" 11 | ) 12 | md5sums=('SKIP' 13 | 'd6665658780b0a75aaf2ddc376f81083' 14 | ) 15 | 16 | 17 | prepare() { 18 | cd "${srcdir}/SabreBerry32" 19 | echo $(pwd) 20 | patch -N -i ../Makefile.archlinux.patch 21 | make -f Makefile.archLinux clean 22 | } 23 | 24 | build() { 25 | cd "${srcdir}/SabreBerry32" 26 | echo $(pwd) 27 | make -f Makefile.archLinux 28 | make -f Makefile.archLinux dtbs 29 | } 30 | 31 | package() { 32 | cd "${srcdir}/SabreBerry32" 33 | echo $(pwd) 34 | make -f Makefile.archLinux DESTDIR=${pkgdir} modules_install 35 | make -f Makefile.archLinux DESTDIR=${pkgdir} install_dtb 36 | } 37 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | KERNEL_SRC = /lib/modules/$(shell uname -r)/source 2 | BUILD_DIR := $(shell pwd) 3 | DTC_DIR = /lib/modules/$(shell uname -r)/build/scripts/dtc/ 4 | VERBOSE = 0 5 | 6 | OBJS = rpi-es9018k2m-dac.o es9018k2m.o 7 | 8 | obj-m := $(OBJS) 9 | 10 | all: 11 | make -C $(KERNEL_SRC) SUBDIRS=$(BUILD_DIR) KBUILD_VERBOSE=$(VERBOSE) modules 12 | 13 | clean: 14 | make -C $(KERNEL_SRC) SUBDIRS=$(BUILD_DIR) clean 15 | rm -f sabreberry32-overlay.dtb 16 | 17 | dtbs: 18 | $(DTC_DIR)/dtc -@ -I dts -O dtb -o sabreberry32-overlay.dtb sabreberry32-overlay.dts 19 | 20 | modules_install: 21 | cp sabre9018q2c.ko /lib/modules/$(shell uname -r)/kernel/sound/soc/codecs/ 22 | cp sabreberry32.ko /lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/ 23 | depmod -a 24 | 25 | modules_remove: 26 | rm /lib/modules/$(shell uname -r)/kernel/sound/soc/codecs/sabre9018q2c.ko 27 | rm /lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/sabreberry32.ko 28 | depmod -a 29 | 30 | install: 31 | modprobe sabre9018q2c 32 | modprobe sabreberry32 33 | 34 | remove: 35 | modprobe -r sabreberry32 36 | modprobe -r sabre9018q2c 37 | 38 | install_dtb: 39 | cp sabreberry32-overlay.dtb /boot/overlays/ 40 | 41 | remove_dtb: 42 | rm /boot/overlays/sabreberry32-overlay.dtb 43 | -------------------------------------------------------------------------------- /Makefile.archLinux: -------------------------------------------------------------------------------- 1 | ARCHDIR=4.4.7-1-ARCH 2 | KERNEL_SRC = /lib/modules/$(ARCHDIR)/build 3 | BUILD_DIR := $(shell pwd) 4 | DTC_DIR = /lib/modules/$(ARCHDIR)/build/scripts/dtc/ 5 | VERBOSE = 1 6 | 7 | OBJS = rpi-es9018k2m-dac.o es9018k2m.o 8 | 9 | obj-m := $(OBJS) 10 | 11 | all: 12 | make -C $(KERNEL_SRC) SUBDIRS=$(BUILD_DIR) KBUILD_VERBOSE=$(VERBOSE) modules 13 | 14 | clean: 15 | make -C $(KERNEL_SRC) SUBDIRS=$(BUILD_DIR) clean 16 | rm -f rpi-es9018k2m-dac-overlay.dtb 17 | 18 | dtbs: 19 | $(DTC_DIR)/dtc -@ -I dts -O dtb -o rpi-es9018k2m-dac-overlay.dtb rpi-es9018k2m-dac-overlay.dts 20 | 21 | modules_install: 22 | gzip rpi-es9018k2m-dac.ko 23 | gzip es9018k2m.ko 24 | mkdir -p $(DESTDIR)/lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/ 25 | cp rpi-es9018k2m-dac.ko.gz $(DESTDIR)/lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/ 26 | cp es9018k2m.ko.gz $(DESTDIR)/lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/ 27 | 28 | modules_remove: 29 | rm $(DESTDIR)/lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/rpi-es9018k2m-dac.ko.gz 30 | rm $(DESTDIR)/lib/modules/$(shell uname -r)/kernel/sound/soc/bcm/es9018k2m.ko.gz 31 | 32 | install_dtb: 33 | mkdir -p $(DESTDIR)/boot/overlays/ 34 | cp rpi-es9018k2m-dac-overlay.dtb $(DESTDIR)/boot/overlays/ 35 | 36 | remove_dtb: 37 | rm /boot/overlays/rpi-es9018k2m-dac-overlay.dtb 38 | 39 | -------------------------------------------------------------------------------- /es9018k2m.h: -------------------------------------------------------------------------------- 1 | /* 2 | * es9018k2m.h -- es9018k2m Soc Audio driver 3 | * 4 | * Copyright 2005 Openedhand Ltd. 5 | * 6 | * Author: Richard Purdie 7 | * 8 | * Based on es9018k2m.h 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License version 2 as 12 | * published by the Free Software Foundation. 13 | */ 14 | 15 | #ifndef _ES9018K2M_H 16 | #define _ES9018K2M_H 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /* ES9018K2M register space */ 25 | 26 | #define ES9018K2M_SYSTEM_SETTING 0x00 27 | #define ES9018K2M_INPUT_CONFIG 0x01 28 | #define ES9018K2M_AUTOMUTE_TIME 0x04 29 | #define ES9018K2M_AUTOMUTE_LEVEL 0x05 30 | #define ES9018K2M_DEEMPHASIS 0x06 31 | #define ES9018K2M_GENERAL_SET 0x07 32 | #define ES9018K2M_GPIO_CONFIG 0x08 33 | #define ES9018K2M_W_MODE_CONTROL 0x09 34 | #define ES9018K2M_V_MODE_CONTROL 0x0A 35 | #define ES9018K2M_CHANNEL_MAP 0x0B 36 | #define ES9018K2M_DPLL 0x0C 37 | #define ES9018K2M_THD_COMPENSATION 0x0D 38 | #define ES9018K2M_SOFT_START 0x0E 39 | #define ES9018K2M_VOLUME1 0x0F 40 | #define ES9018K2M_VOLUME2 0x10 41 | #define ES9018K2M_MASTERTRIM0 0x11 42 | #define ES9018K2M_MASTERTRIM1 0x12 43 | #define ES9018K2M_MASTERTRIM2 0x13 44 | #define ES9018K2M_MASTERTRIM3 0x14 45 | #define ES9018K2M_INPUT_SELECT 0x15 46 | #define ES9018K2M_2_HARMONIC_COMPENSATION_0 0x16 47 | #define ES9018K2M_2_HARMONIC_COMPENSATION_1 0x17 48 | #define ES9018K2M_3_HARMONIC_COMPENSATION_0 0x18 49 | #define ES9018K2M_3_HARMONIC_COMPENSATION_1 0x19 50 | //#for V version 51 | #define ES9018K2M_program_FIR_ADDR 0x1A 52 | #define ES9018K2M_program_FIR_DATA1 0x1B 53 | #define ES9018K2M_program_FIR_DATA2 0x1C 54 | #define ES9018K2M_program_FIR_DATAC 0x1D 55 | #define ES9018K2M_program_FIR_CONTROL 0x1E 56 | 57 | #define ES9018K2M_CACHEREGNUM 0x1E 58 | 59 | #define ES9018K2M_SYSCLK_MCLK 1 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /rpi-es9018k2m-dac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ASoC Driver for RPi-DAC. 3 | * 4 | * Author: Florian Meier 5 | * Copyright 2013 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * version 2 as published by the Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "es9018k2m.h" 27 | 28 | 29 | static int snd_rpi_es9018k2m_dac_init(struct snd_soc_pcm_runtime *rtd) 30 | { 31 | return 0; 32 | } 33 | 34 | static int snd_rpi_es9018k2m_dac_hw_params(struct snd_pcm_substream *substream, 35 | struct snd_pcm_hw_params *params) 36 | { 37 | struct snd_soc_pcm_runtime *rtd = substream->private_data; 38 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 39 | 40 | int bclk_ratio = snd_pcm_format_physical_width( 41 | params_format(params)) * params_channels(params); 42 | return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio); 43 | } 44 | 45 | /* machine stream operations */ 46 | static struct snd_soc_ops snd_rpi_es9018k2m_dac_ops = { 47 | .hw_params = snd_rpi_es9018k2m_dac_hw_params, 48 | }; 49 | 50 | static struct snd_soc_dai_link snd_rpi_es9018k2m_dac_dai[] = { 51 | { 52 | .name = "RPi-ES9018K2M-DAC", 53 | .stream_name = "RPi-DAC ES9018K2M HiFi", 54 | .cpu_dai_name = "bcm2708-i2s.0", 55 | .codec_dai_name = "es9018k2m-hifi", 56 | .platform_name = "bcm2708-i2s.0", 57 | .codec_name = "es9018k2m-codec", 58 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 59 | SND_SOC_DAIFMT_CBS_CFS, 60 | .ops = &snd_rpi_es9018k2m_dac_ops, 61 | .init = snd_rpi_es9018k2m_dac_init, 62 | }, 63 | }; 64 | 65 | /* audio machine driver */ 66 | static struct snd_soc_card snd_rpi_es9018k2m_dac = { 67 | .name = "snd_rpi_es9018k2m_dac", 68 | .owner = THIS_MODULE, 69 | .dai_link = snd_rpi_es9018k2m_dac_dai, 70 | .num_links = ARRAY_SIZE(snd_rpi_es9018k2m_dac_dai), 71 | }; 72 | 73 | static int snd_rpi_es9018k2m_dac_probe(struct platform_device *pdev) 74 | { 75 | int ret = 0; 76 | 77 | snd_rpi_es9018k2m_dac.dev = &pdev->dev; 78 | 79 | if (pdev->dev.of_node) { 80 | struct device_node *i2s_node; 81 | struct snd_soc_dai_link *dai = &snd_rpi_es9018k2m_dac_dai[0]; 82 | i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0); 83 | 84 | if (i2s_node) { 85 | dai->cpu_dai_name = NULL; 86 | dai->cpu_of_node = i2s_node; 87 | dai->platform_name = NULL; 88 | dai->platform_of_node = i2s_node; 89 | } 90 | } 91 | 92 | ret = snd_soc_register_card(&snd_rpi_es9018k2m_dac); 93 | if (ret) 94 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); 95 | 96 | return ret; 97 | } 98 | 99 | static int snd_rpi_es9018k2m_dac_remove(struct platform_device *pdev) 100 | { 101 | return snd_soc_unregister_card(&snd_rpi_es9018k2m_dac); 102 | } 103 | 104 | static const struct of_device_id snd_rpi_es9018k2m_dac_of_match[] = { 105 | { .compatible = "nobody,es9018k2m-dac", }, 106 | {}, 107 | }; 108 | MODULE_DEVICE_TABLE(of, snd_rpi_es9018k2m_dac_of_match); 109 | 110 | static struct platform_driver snd_rpi_es9018k2m_dac_driver = { 111 | .driver = { 112 | .name = "snd-rpi-es9018k2m-dac", 113 | .owner = THIS_MODULE, 114 | .of_match_table = snd_rpi_es9018k2m_dac_of_match, 115 | }, 116 | .probe = snd_rpi_es9018k2m_dac_probe, 117 | .remove = snd_rpi_es9018k2m_dac_remove, 118 | }; 119 | 120 | module_platform_driver(snd_rpi_es9018k2m_dac_driver); 121 | 122 | MODULE_AUTHOR("Florian Meier "); 123 | MODULE_DESCRIPTION("ASoC Driver for RPi-ES9018K2M-DAC"); 124 | MODULE_LICENSE("GPL v2"); 125 | -------------------------------------------------------------------------------- /es9018k2m.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Driver for the ESS SABRE9018Q2C 3 | * 4 | * Author: Satoru Kawase, Takahito Nishiara 5 | * Copyright 2016 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * version 2 as published by the Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | */ 16 | 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "es9018k2m.h" 27 | 28 | 29 | /* SABRE9018Q2C Codec Private Data */ 30 | struct es9018k2m_priv { 31 | struct regmap *regmap; 32 | unsigned int fmt; 33 | }; 34 | 35 | 36 | /* SABRE9018Q2C Default Register Value */ 37 | static const struct reg_default es9018k2m_reg_defaults[] = { 38 | { 0, 0x00 }, 39 | { 1, 0x8c }, 40 | { 4, 0x00 }, 41 | { 5, 0x68 }, 42 | { 6, 0x42 }, 43 | { 7, 0x80 }, 44 | { 8, 0x10 }, 45 | { 9, 0x00 }, 46 | { 10,0x05 }, 47 | { 11,0x02 }, 48 | { 12,0x5a }, 49 | { 13,0x40 }, 50 | { 14,0x8a }, 51 | { 15,0x00 }, 52 | { 16,0x00 }, 53 | { 17,0xff }, 54 | { 18,0xff }, 55 | { 19,0xff }, 56 | { 20,0x7f }, 57 | { 21,0x00 }, 58 | { 26,0x00 }, 59 | { 27,0x00 }, 60 | { 28,0x00 }, 61 | { 29,0x00 }, 62 | { 30,0x00 }, 63 | }; 64 | 65 | 66 | static bool es9018k2m_writeable(struct device *dev, unsigned int reg) 67 | { 68 | if(reg > ES9018K2M_CACHEREGNUM) 69 | return 0; 70 | else if(reg == 0x2 || reg == 0x3) 71 | return 0; 72 | else 73 | return 1; 74 | } 75 | 76 | static bool es9018k2m_readable(struct device *dev, unsigned int reg) 77 | { 78 | if(reg <= ES9018K2M_CACHEREGNUM && reg != 2 && reg !=3) 79 | return 1; 80 | else if(65 <= reg && reg <= 69) 81 | return 1; 82 | else if(70 <= reg && reg <= 93) 83 | return 1; 84 | else 85 | return 0; 86 | } 87 | 88 | static bool es9018k2m_volatile(struct device *dev, unsigned int reg) 89 | { 90 | return false; 91 | } 92 | 93 | 94 | /* Volume Scale */ 95 | static const DECLARE_TLV_DB_SCALE(volume_tlv, -12750, 50, 1); 96 | 97 | /* Control */ 98 | static const struct snd_kcontrol_new es9018k2m_controls[] = { 99 | SOC_DOUBLE_R_TLV("Master Playback Volume", ES9018K2M_VOLUME1, ES9018K2M_VOLUME2, 100 | 0, 255, 0, volume_tlv), 101 | }; 102 | 103 | 104 | static const uint32_t es9018k2m_dai_rates_master[] = { 105 | 44100, 48000, 88200, 96000, 176400, 192000 106 | }; 107 | 108 | static const struct snd_pcm_hw_constraint_list constraints_master = { 109 | .list = es9018k2m_dai_rates_master, 110 | .count = ARRAY_SIZE(es9018k2m_dai_rates_master), 111 | }; 112 | 113 | static const uint32_t es9018k2m_dai_rates_slave[] = { 114 | 8000, 11025, 16000, 22050, 32000, 115 | 44100, 48000, 64000, 88200, 96000, 176400, 192000 116 | }; 117 | 118 | static const struct snd_pcm_hw_constraint_list constraints_slave = { 119 | .list = es9018k2m_dai_rates_slave, 120 | .count = ARRAY_SIZE(es9018k2m_dai_rates_slave), 121 | }; 122 | 123 | static int es9018k2m_dai_startup_master( 124 | struct snd_pcm_substream *substream, struct snd_soc_dai *dai) 125 | { 126 | struct snd_soc_codec *codec = dai->codec; 127 | int ret; 128 | 129 | ret = snd_pcm_hw_constraint_list(substream->runtime, 130 | 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_master); 131 | if (ret != 0) { 132 | dev_err(codec->dev, "Failed to setup rates constraints: %d\n", ret); 133 | return ret; 134 | } 135 | 136 | ret = snd_pcm_hw_constraint_mask64(substream->runtime, 137 | SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_FMTBIT_S32_LE); 138 | if (ret != 0) { 139 | dev_err(codec->dev, "Failed to setup format constraints: %d\n", ret); 140 | } 141 | 142 | return ret; 143 | } 144 | 145 | static int es9018k2m_dai_startup_slave( 146 | struct snd_pcm_substream *substream, struct snd_soc_dai *dai) 147 | { 148 | struct snd_soc_codec *codec = dai->codec; 149 | int ret; 150 | 151 | ret = snd_pcm_hw_constraint_list(substream->runtime, 152 | 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_slave); 153 | if (ret != 0) { 154 | dev_err(codec->dev, "Failed to setup rates constraints: %d\n", ret); 155 | } 156 | 157 | return ret; 158 | } 159 | 160 | static int es9018k2m_dai_startup( 161 | struct snd_pcm_substream *substream, struct snd_soc_dai *dai) 162 | { 163 | struct snd_soc_codec *codec = dai->codec; 164 | struct es9018k2m_priv *es9018k2m 165 | = snd_soc_codec_get_drvdata(codec); 166 | 167 | switch (es9018k2m->fmt & SND_SOC_DAIFMT_MASTER_MASK) { 168 | case SND_SOC_DAIFMT_CBM_CFM: 169 | return es9018k2m_dai_startup_master(substream, dai); 170 | 171 | case SND_SOC_DAIFMT_CBS_CFS: 172 | return es9018k2m_dai_startup_slave(substream, dai); 173 | 174 | default: 175 | return (-EINVAL); 176 | } 177 | } 178 | 179 | static int es9018k2m_hw_params( 180 | struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, 181 | struct snd_soc_dai *dai) 182 | { 183 | struct snd_soc_codec *codec = dai->codec; 184 | 185 | uint8_t iface = snd_soc_read(codec, ES9018K2M_INPUT_CONFIG) & 0x3f; 186 | 187 | switch (params_format(params)) { 188 | case SNDRV_PCM_FORMAT_S16_LE: 189 | iface |= 0x0; 190 | break; 191 | case SNDRV_PCM_FORMAT_S24_LE: 192 | iface |= 0x40; 193 | break; 194 | case SNDRV_PCM_FORMAT_S32_LE: 195 | iface |= 0x80; 196 | break; 197 | default: 198 | return -EINVAL; 199 | } 200 | 201 | snd_soc_write(codec, ES9018K2M_INPUT_CONFIG, iface); 202 | printk(KERN_DEBUG "ess9018k2m: %s reg=0x%x value=0x%x,0x%x #####end\n",__func__,ES9018K2M_INPUT_CONFIG,iface,snd_soc_read(codec, ES9018K2M_INPUT_CONFIG)); 203 | 204 | return 0; 205 | } 206 | 207 | 208 | static const struct snd_soc_dai_ops es9018k2m_dai_ops = { 209 | .startup = es9018k2m_dai_startup, 210 | .hw_params = es9018k2m_hw_params, 211 | }; 212 | 213 | 214 | #define ES9018K2M_RATES (SNDRV_PCM_RATE_8000_44100 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |SNDRV_PCM_RATE_96000|\ 215 | SNDRV_PCM_RATE_176400| SNDRV_PCM_RATE_192000) 216 | 217 | #define ES9018K2M_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ 218 | SNDRV_PCM_FMTBIT_S32_LE) 219 | 220 | static struct snd_soc_dai_driver es9018k2m_dai = { 221 | .name = "es9018k2m-dai", 222 | .playback = { 223 | .stream_name = "Playback", 224 | .channels_min = 1, 225 | .channels_max = 2, 226 | .rates = ES9018K2M_RATES, 227 | .formats = ES9018K2M_FORMATS, 228 | }, 229 | .ops = &es9018k2m_dai_ops, 230 | }; 231 | 232 | static struct snd_soc_codec_driver es9018k2m_codec_driver = { 233 | .controls = es9018k2m_controls, 234 | .num_controls = ARRAY_SIZE(es9018k2m_controls), 235 | }; 236 | 237 | 238 | static const struct regmap_config es9018k2m_regmap = { 239 | .reg_bits = 8, 240 | .val_bits = 8, 241 | .max_register = 93, 242 | 243 | .reg_defaults = es9018k2m_reg_defaults, 244 | .num_reg_defaults = ARRAY_SIZE(es9018k2m_reg_defaults), 245 | 246 | .writeable_reg = es9018k2m_writeable, 247 | .readable_reg = es9018k2m_readable, 248 | .volatile_reg = es9018k2m_volatile, 249 | 250 | .cache_type = REGCACHE_RBTREE, 251 | }; 252 | 253 | 254 | bool es9018k2m_check_chip_id(struct snd_soc_codec *codec) 255 | { 256 | /* 257 | unsigned int value; 258 | 259 | value = snd_soc_read(codec, SABRE9018Q2C_REG_64); 260 | 261 | if (((value & 0x1C) >> 2) != 0) { 262 | return false; 263 | } 264 | */ 265 | return true; 266 | } 267 | EXPORT_SYMBOL_GPL(es9018k2m_check_chip_id); 268 | 269 | 270 | static int es9018k2m_probe(struct device *dev, struct regmap *regmap) 271 | { 272 | struct es9018k2m_priv *es9018k2m; 273 | int ret; 274 | 275 | es9018k2m = devm_kzalloc(dev, sizeof(*es9018k2m), GFP_KERNEL); 276 | if (!es9018k2m) { 277 | dev_err(dev, "devm_kzalloc"); 278 | return (-ENOMEM); 279 | } 280 | 281 | es9018k2m->regmap = regmap; 282 | 283 | dev_set_drvdata(dev, es9018k2m); 284 | 285 | ret = snd_soc_register_codec(dev, 286 | &es9018k2m_codec_driver, &es9018k2m_dai, 1); 287 | if (ret != 0) { 288 | dev_err(dev, "Failed to register CODEC: %d\n", ret); 289 | return ret; 290 | } 291 | 292 | return 0; 293 | } 294 | 295 | static void es9018k2m_remove(struct device *dev) 296 | { 297 | snd_soc_unregister_codec(dev); 298 | } 299 | 300 | 301 | static int es9018k2m_i2c_probe( 302 | struct i2c_client *i2c, const struct i2c_device_id *id) 303 | { 304 | struct regmap *regmap; 305 | 306 | regmap = devm_regmap_init_i2c(i2c, &es9018k2m_regmap); 307 | if (IS_ERR(regmap)) { 308 | return PTR_ERR(regmap); 309 | } 310 | 311 | return es9018k2m_probe(&i2c->dev, regmap); 312 | } 313 | 314 | static int es9018k2m_i2c_remove(struct i2c_client *i2c) 315 | { 316 | es9018k2m_remove(&i2c->dev); 317 | 318 | return 0; 319 | } 320 | 321 | 322 | static const struct i2c_device_id es9018k2m_i2c_id[] = { 323 | { "es9018k2m", }, 324 | { } 325 | }; 326 | MODULE_DEVICE_TABLE(i2c, es9018k2m_i2c_id); 327 | 328 | static const struct of_device_id es9018k2m_of_match[] = { 329 | { .compatible = "ess,es9018k2m", }, 330 | { } 331 | }; 332 | MODULE_DEVICE_TABLE(of, es9018k2m_of_match); 333 | 334 | static struct i2c_driver es9018k2m_i2c_driver = { 335 | .driver = { 336 | .name = "es9018k2m-i2c", 337 | .owner = THIS_MODULE, 338 | .of_match_table = of_match_ptr(es9018k2m_of_match), 339 | }, 340 | .probe = es9018k2m_i2c_probe, 341 | .remove = es9018k2m_i2c_remove, 342 | .id_table = es9018k2m_i2c_id, 343 | }; 344 | module_i2c_driver(es9018k2m_i2c_driver); 345 | 346 | 347 | MODULE_DESCRIPTION("ASoC SABRE9018Q2C codec driver"); 348 | MODULE_AUTHOR("Satoru Kawase "); 349 | MODULE_LICENSE("GPL"); 350 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------