Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
410afed
Documentation
arch
block
certs
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
ac97
aoa
arm
atmel
core
drivers
firewire
hda
i2c
isa
mips
oss
parisc
pci
pcmcia
ppc
sh
soc
adi
amd
atmel
au1x
bcm
blackfin
cirrus
codecs
88pm860x-codec.c
88pm860x-codec.h
Kconfig
Makefile
ab8500-codec.c
ab8500-codec.h
ac97.c
ad1836.c
ad1836.h
ad193x-i2c.c
ad193x-spi.c
ad193x.c
ad193x.h
ad1980.c
ad73311.c
ad73311.h
adau-utils.c
adau-utils.h
adau1373.c
adau1373.h
adau1701.c
adau1701.h
adau1761-i2c.c
adau1761-spi.c
adau1761.c
adau1761.h
adau1781-i2c.c
adau1781-spi.c
adau1781.c
adau1781.h
adau17x1.c
adau17x1.h
adau1977-i2c.c
adau1977-spi.c
adau1977.c
adau1977.h
adau7002.c
adav801.c
adav803.c
adav80x.c
adav80x.h
ads117x.c
ak4104.c
ak4535.c
ak4535.h
ak4554.c
ak4613.c
ak4641.c
ak4642.c
ak4671.c
ak4671.h
ak5386.c
alc5623.c
alc5623.h
alc5632.c
alc5632.h
arizona.c
arizona.h
bt-sco.c
cq93vc.c
cs35l32.c
cs35l32.h
cs35l33.c
cs35l33.h
cs35l34.c
cs35l34.h
cs35l35.c
cs35l35.h
cs4265.c
cs4265.h
cs4270.c
cs4271-i2c.c
cs4271-spi.c
cs4271.c
cs4271.h
cs42l42.c
cs42l42.h
cs42l51-i2c.c
cs42l51.c
cs42l51.h
cs42l52.c
cs42l52.h
cs42l56.c
cs42l56.h
cs42l73.c
cs42l73.h
cs42xx8-i2c.c
cs42xx8.c
cs42xx8.h
cs43130.c
cs43130.h
cs4349.c
cs4349.h
cs47l24.c
cs47l24.h
cs53l30.c
cs53l30.h
cx20442.c
cx20442.h
da7210.c
da7213.c
da7213.h
da7218.c
da7218.h
da7219-aad.c
da7219-aad.h
da7219.c
da7219.h
da732x.c
da732x.h
da732x_reg.h
da9055.c
dio2125.c
dmic.c
es7134.c
es8316.c
es8316.h
es8328-i2c.c
es8328-spi.c
es8328.c
es8328.h
gtm601.c
hdac_hdmi.c
hdac_hdmi.h
hdmi-codec.c
ics43432.c
inno_rk3036.c
inno_rk3036.h
isabelle.c
isabelle.h
jz4740.c
l3.c
lm4857.c
lm49453.c
lm49453.h
max9768.c
max98088.c
max98088.h
max98090.c
max98090.h
max98095.c
max98095.h
max98357a.c
max98371.c
max98371.h
max9850.c
max9850.h
max98504.c
max98504.h
max9860.c
max9860.h
max9867.c
max9867.h
max9877.c
max9877.h
max98925.c
max98925.h
max98926.c
max98926.h
max98927.c
max98927.h
mc13783.c
mc13783.h
ml26124.c
ml26124.h
msm8916-wcd-analog.c
msm8916-wcd-digital.c
nau8540.c
nau8540.h
nau8810.c
nau8810.h
nau8824.c
nau8824.h
nau8825.c
nau8825.h
pcm1681.c
pcm179x-i2c.c
pcm179x-spi.c
pcm179x.c
pcm179x.h
pcm3008.c
pcm3008.h
pcm3168a-i2c.c
pcm3168a-spi.c
pcm3168a.c
pcm3168a.h
pcm5102a.c
pcm512x-i2c.c
pcm512x-spi.c
pcm512x.c
pcm512x.h
rl6231.c
rl6231.h
rl6347a.c
rl6347a.h
rt274.c
rt274.h
rt286.c
rt286.h
rt298.c
rt298.h
rt5514-spi.c
rt5514-spi.h
rt5514.c
rt5514.h
rt5616.c
rt5616.h
rt5631.c
rt5631.h
rt5640.c
rt5640.h
rt5645.c
rt5645.h
rt5651.c
rt5651.h
rt5659.c
rt5659.h
rt5660.c
rt5660.h
rt5663.c
rt5663.h
rt5665.c
rt5665.h
rt5670-dsp.h
rt5670.c
rt5670.h
rt5677-spi.c
rt5677-spi.h
rt5677.c
rt5677.h
sgtl5000.c
sgtl5000.h
si476x.c
sigmadsp-i2c.c
sigmadsp-regmap.c
sigmadsp.c
sigmadsp.h
sirf-audio-codec.c
sirf-audio-codec.h
sn95031.c
sn95031.h
spdif_receiver.c
spdif_transmitter.c
ssm2518.c
ssm2518.h
ssm2602-i2c.c
ssm2602-spi.c
ssm2602.c
ssm2602.h
ssm4567.c
sta32x.c
sta32x.h
sta350.c
sta350.h
sta529.c
stac9766.c
sti-sas.c
tas2552.c
tas2552.h
tas5086.c
tas571x.c
tas571x.h
tas5720.c
tas5720.h
tfa9879.c
tfa9879.h
tlv320aic23-i2c.c
tlv320aic23-spi.c
tlv320aic23.c
tlv320aic23.h
tlv320aic26.c
tlv320aic26.h
tlv320aic31xx.c
tlv320aic31xx.h
tlv320aic32x4-i2c.c
tlv320aic32x4-spi.c
tlv320aic32x4.c
tlv320aic32x4.h
tlv320aic3x.c
tlv320aic3x.h
tlv320dac33.c
tlv320dac33.h
tpa6130a2.c
tpa6130a2.h
ts3a227e.c
ts3a227e.h
twl4030.c
twl6040.c
twl6040.h
uda134x.c
uda134x.h
uda1380.c
uda1380.h
wl1273.c
wl1273.h
wm0010.c
wm1250-ev1.c
wm2000.c
wm2000.h
wm2200.c
wm2200.h
wm5100-tables.c
wm5100.c
wm5100.h
wm5102.c
wm5102.h
wm5110.c
wm5110.h
wm8350.c
wm8350.h
wm8400.c
wm8400.h
wm8510.c
wm8510.h
wm8523.c
wm8523.h
wm8524.c
wm8580.c
wm8580.h
wm8711.c
wm8711.h
wm8727.c
wm8728.c
wm8728.h
wm8731.c
wm8731.h
wm8737.c
wm8737.h
wm8741.c
wm8741.h
wm8750.c
wm8750.h
wm8753.c
wm8753.h
wm8770.c
wm8770.h
wm8776.c
wm8776.h
wm8782.c
wm8804-i2c.c
wm8804-spi.c
wm8804.c
wm8804.h
wm8900.c
wm8900.h
wm8903.c
wm8903.h
wm8904.c
wm8904.h
wm8940.c
wm8940.h
wm8955.c
wm8955.h
wm8958-dsp2.c
wm8960.c
wm8960.h
wm8961.c
wm8961.h
wm8962.c
wm8962.h
wm8971.c
wm8971.h
wm8974.c
wm8974.h
wm8978.c
wm8978.h
wm8983.c
wm8983.h
wm8985.c
wm8985.h
wm8988.c
wm8988.h
wm8990.c
wm8990.h
wm8991.c
wm8991.h
wm8993.c
wm8993.h
wm8994.c
wm8994.h
wm8995.c
wm8995.h
wm8996.c
wm8996.h
wm8997.c
wm8997.h
wm8998.c
wm8998.h
wm9081.c
wm9081.h
wm9090.c
wm9090.h
wm9705.c
wm9712.c
wm9713.c
wm9713.h
wm_adsp.c
wm_adsp.h
wm_hubs.c
wm_hubs.h
wmfw.h
zx_aud96p22.c
davinci
dwc
fsl
generic
hisilicon
img
intel
jz4740
kirkwood
mediatek
mxs
nuc900
omap
pxa
qcom
rockchip
samsung
sh
sirf
spear
sti
stm
sunxi
tegra
txx9
ux500
xtensa
zte
Kconfig
Makefile
soc-ac97.c
soc-acpi.c
soc-cache.c
soc-compress.c
soc-core.c
soc-dapm.c
soc-devres.c
soc-generic-dmaengine-pcm.c
soc-io.c
soc-jack.c
soc-ops.c
soc-pcm.c
soc-topology.c
soc-utils.c
sparc
spi
synth
usb
x86
Kconfig
Makefile
ac97_bus.c
last.c
sound_core.c
tools
usr
virt
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
sound
/
soc
/
codecs
/
cs35l32.c
Copy path
Blame
Blame
Latest commit
History
History
590 lines (491 loc) · 14.9 KB
Breadcrumbs
linux
/
sound
/
soc
/
codecs
/
cs35l32.c
Top
File metadata and controls
Code
Blame
590 lines (491 loc) · 14.9 KB
Raw
/* * cs35l32.c -- CS35L32 ALSA SoC audio driver * * Copyright 2014 CirrusLogic, Inc. * * Author: Brian Austin <brian.austin@cirrus.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/kernel.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/i2c.h> #include <linux/gpio.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> #include <linux/gpio/consumer.h> #include <linux/of_device.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 <dt-bindings/sound/cs35l32.h> #include "cs35l32.h" #define CS35L32_NUM_SUPPLIES 2 static const char *const cs35l32_supply_names[CS35L32_NUM_SUPPLIES] = { "VA", "VP", }; struct cs35l32_private { struct regmap *regmap; struct snd_soc_codec *codec; struct regulator_bulk_data supplies[CS35L32_NUM_SUPPLIES]; struct cs35l32_platform_data pdata; struct gpio_desc *reset_gpio; }; static const struct reg_default cs35l32_reg_defaults[] = { { 0x06, 0x04 }, /* Power Ctl 1 */ { 0x07, 0xE8 }, /* Power Ctl 2 */ { 0x08, 0x40 }, /* Clock Ctl */ { 0x09, 0x20 }, /* Low Battery Threshold */ { 0x0A, 0x00 }, /* Voltage Monitor [RO] */ { 0x0B, 0x40 }, /* Conv Peak Curr Protection CTL */ { 0x0C, 0x07 }, /* IMON Scaling */ { 0x0D, 0x03 }, /* Audio/LED Pwr Manager */ { 0x0F, 0x20 }, /* Serial Port Control */ { 0x10, 0x14 }, /* Class D Amp CTL */ { 0x11, 0x00 }, /* Protection Release CTL */ { 0x12, 0xFF }, /* Interrupt Mask 1 */ { 0x13, 0xFF }, /* Interrupt Mask 2 */ { 0x14, 0xFF }, /* Interrupt Mask 3 */ { 0x19, 0x00 }, /* LED Flash Mode Current */ { 0x1A, 0x00 }, /* LED Movie Mode Current */ { 0x1B, 0x20 }, /* LED Flash Timer */ { 0x1C, 0x00 }, /* LED Flash Inhibit Current */ }; static bool cs35l32_readable_register(struct device *dev, unsigned int reg) { switch (reg) { case CS35L32_DEVID_AB ... CS35L32_AUDIO_LED_MNGR: case CS35L32_ADSP_CTL ... CS35L32_FLASH_INHIBIT: return true; default: return false; } } static bool cs35l32_volatile_register(struct device *dev, unsigned int reg) { switch (reg) { case CS35L32_DEVID_AB ... CS35L32_REV_ID: case CS35L32_INT_STATUS_1 ... CS35L32_LED_STATUS: return true; default: return false; } } static bool cs35l32_precious_register(struct device *dev, unsigned int reg) { switch (reg) { case CS35L32_INT_STATUS_1 ... CS35L32_LED_STATUS: return true; default: return false; } } static DECLARE_TLV_DB_SCALE(classd_ctl_tlv, 900, 300, 0); static const struct snd_kcontrol_new imon_ctl = SOC_DAPM_SINGLE("Switch", CS35L32_PWRCTL2, 6, 1, 1); static const struct snd_kcontrol_new vmon_ctl = SOC_DAPM_SINGLE("Switch", CS35L32_PWRCTL2, 7, 1, 1); static const struct snd_kcontrol_new vpmon_ctl = SOC_DAPM_SINGLE("Switch", CS35L32_PWRCTL2, 5, 1, 1); static const struct snd_kcontrol_new cs35l32_snd_controls[] = { SOC_SINGLE_TLV("Speaker Volume", CS35L32_CLASSD_CTL, 3, 0x04, 1, classd_ctl_tlv), SOC_SINGLE("Zero Cross Switch", CS35L32_CLASSD_CTL, 2, 1, 0), SOC_SINGLE("Gain Manager Switch", CS35L32_AUDIO_LED_MNGR, 3, 1, 0), }; static const struct snd_soc_dapm_widget cs35l32_dapm_widgets[] = { SND_SOC_DAPM_SUPPLY("BOOST", CS35L32_PWRCTL1, 2, 1, NULL, 0), SND_SOC_DAPM_OUT_DRV("Speaker", CS35L32_PWRCTL1, 7, 1, NULL, 0), SND_SOC_DAPM_AIF_OUT("SDOUT", NULL, 0, CS35L32_PWRCTL2, 3, 1), SND_SOC_DAPM_INPUT("VP"), SND_SOC_DAPM_INPUT("ISENSE"), SND_SOC_DAPM_INPUT("VSENSE"), SND_SOC_DAPM_SWITCH("VMON ADC", CS35L32_PWRCTL2, 7, 1, &vmon_ctl), SND_SOC_DAPM_SWITCH("IMON ADC", CS35L32_PWRCTL2, 6, 1, &imon_ctl), SND_SOC_DAPM_SWITCH("VPMON ADC", CS35L32_PWRCTL2, 5, 1, &vpmon_ctl), }; static const struct snd_soc_dapm_route cs35l32_audio_map[] = { {"Speaker", NULL, "BOOST"}, {"VMON ADC", NULL, "VSENSE"}, {"IMON ADC", NULL, "ISENSE"}, {"VPMON ADC", NULL, "VP"}, {"SDOUT", "Switch", "VMON ADC"}, {"SDOUT", "Switch", "IMON ADC"}, {"SDOUT", "Switch", "VPMON ADC"}, {"Capture", NULL, "SDOUT"}, }; static int cs35l32_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { struct snd_soc_codec *codec = codec_dai->codec; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBM_CFM: snd_soc_update_bits(codec, CS35L32_ADSP_CTL, CS35L32_ADSP_MASTER_MASK, CS35L32_ADSP_MASTER_MASK); break; case SND_SOC_DAIFMT_CBS_CFS: snd_soc_update_bits(codec, CS35L32_ADSP_CTL, CS35L32_ADSP_MASTER_MASK, 0); break; default: return -EINVAL; } return 0; } static int cs35l32_set_tristate(struct snd_soc_dai *dai, int tristate) { struct snd_soc_codec *codec = dai->codec; return snd_soc_update_bits(codec, CS35L32_PWRCTL2, CS35L32_SDOUT_3ST, tristate << 3); } static const struct snd_soc_dai_ops cs35l32_ops = { .set_fmt = cs35l32_set_dai_fmt, .set_tristate = cs35l32_set_tristate, }; static struct snd_soc_dai_driver cs35l32_dai[] = { { .name = "cs35l32-monitor", .id = 0, .capture = { .stream_name = "Capture", .channels_min = 2, .channels_max = 2, .rates = CS35L32_RATES, .formats = CS35L32_FORMATS, }, .ops = &cs35l32_ops, .symmetric_rates = 1, } }; static int cs35l32_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, int source, unsigned int freq, int dir) { unsigned int val; switch (freq) { case 6000000: val = CS35L32_MCLK_RATIO; break; case 12000000: val = CS35L32_MCLK_DIV2_MASK | CS35L32_MCLK_RATIO; break; case 6144000: val = 0; break; case 12288000: val = CS35L32_MCLK_DIV2_MASK; break; default: return -EINVAL; } return snd_soc_update_bits(codec, CS35L32_CLK_CTL, CS35L32_MCLK_DIV2_MASK | CS35L32_MCLK_RATIO_MASK, val); } static const struct snd_soc_codec_driver soc_codec_dev_cs35l32 = { .set_sysclk = cs35l32_codec_set_sysclk, .component_driver = { .controls = cs35l32_snd_controls, .num_controls = ARRAY_SIZE(cs35l32_snd_controls), .dapm_widgets = cs35l32_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(cs35l32_dapm_widgets), .dapm_routes = cs35l32_audio_map, .num_dapm_routes = ARRAY_SIZE(cs35l32_audio_map), }, }; /* Current and threshold powerup sequence Pg37 in datasheet */ static const struct reg_sequence cs35l32_monitor_patch[] = { { 0x00, 0x99 }, { 0x48, 0x17 }, { 0x49, 0x56 }, { 0x43, 0x01 }, { 0x3B, 0x62 }, { 0x3C, 0x80 }, { 0x00, 0x00 }, }; static const struct regmap_config cs35l32_regmap = { .reg_bits = 8, .val_bits = 8, .max_register = CS35L32_MAX_REGISTER, .reg_defaults = cs35l32_reg_defaults, .num_reg_defaults = ARRAY_SIZE(cs35l32_reg_defaults), .volatile_reg = cs35l32_volatile_register, .readable_reg = cs35l32_readable_register, .precious_reg = cs35l32_precious_register, .cache_type = REGCACHE_RBTREE, }; static int cs35l32_handle_of_data(struct i2c_client *i2c_client, struct cs35l32_platform_data *pdata) { struct device_node *np = i2c_client->dev.of_node; unsigned int val; if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0) pdata->sdout_share = val; if (of_property_read_u32(np, "cirrus,boost-manager", &val)) val = -1u; switch (val) { case CS35L32_BOOST_MGR_AUTO: case CS35L32_BOOST_MGR_AUTO_AUDIO: case CS35L32_BOOST_MGR_BYPASS: case CS35L32_BOOST_MGR_FIXED: pdata->boost_mng = val; break; case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,boost-manager DT value %d\n", val); pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS; } if (of_property_read_u32(np, "cirrus,sdout-datacfg", &val)) val = -1u; switch (val) { case CS35L32_DATA_CFG_LR_VP: case CS35L32_DATA_CFG_LR_STAT: case CS35L32_DATA_CFG_LR: case CS35L32_DATA_CFG_LR_VPSTAT: pdata->sdout_datacfg = val; break; case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,sdout-datacfg DT value %d\n", val); pdata->sdout_datacfg = CS35L32_DATA_CFG_LR; } if (of_property_read_u32(np, "cirrus,battery-threshold", &val)) val = -1u; switch (val) { case CS35L32_BATT_THRESH_3_1V: case CS35L32_BATT_THRESH_3_2V: case CS35L32_BATT_THRESH_3_3V: case CS35L32_BATT_THRESH_3_4V: pdata->batt_thresh = val; break; case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,battery-threshold DT value %d\n", val); pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V; } if (of_property_read_u32(np, "cirrus,battery-recovery", &val)) val = -1u; switch (val) { case CS35L32_BATT_RECOV_3_1V: case CS35L32_BATT_RECOV_3_2V: case CS35L32_BATT_RECOV_3_3V: case CS35L32_BATT_RECOV_3_4V: case CS35L32_BATT_RECOV_3_5V: case CS35L32_BATT_RECOV_3_6V: pdata->batt_recov = val; break; case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,battery-recovery DT value %d\n", val); pdata->batt_recov = CS35L32_BATT_RECOV_3_4V; } return 0; } static int cs35l32_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { struct cs35l32_private *cs35l32; struct cs35l32_platform_data *pdata = dev_get_platdata(&i2c_client->dev); int ret, i; unsigned int devid = 0; unsigned int reg; cs35l32 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l32_private), GFP_KERNEL); if (!cs35l32) return -ENOMEM; i2c_set_clientdata(i2c_client, cs35l32); cs35l32->regmap = devm_regmap_init_i2c(i2c_client, &cs35l32_regmap); if (IS_ERR(cs35l32->regmap)) { ret = PTR_ERR(cs35l32->regmap); dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); return ret; } if (pdata) { cs35l32->pdata = *pdata; } else { pdata = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l32_platform_data), GFP_KERNEL); if (!pdata) return -ENOMEM; if (i2c_client->dev.of_node) { ret = cs35l32_handle_of_data(i2c_client, &cs35l32->pdata); if (ret != 0) return ret; } } for (i = 0; i < ARRAY_SIZE(cs35l32->supplies); i++) cs35l32->supplies[i].supply = cs35l32_supply_names[i]; ret = devm_regulator_bulk_get(&i2c_client->dev, ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to request supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to enable supplies: %d\n", ret); return ret; } /* Reset the Device */ cs35l32->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(cs35l32->reset_gpio)) return PTR_ERR(cs35l32->reset_gpio); gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); /* initialize codec */ ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, ®); devid = (reg & 0xFF) << 12; ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_CD, ®); devid |= (reg & 0xFF) << 4; ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_E, ®); devid |= (reg & 0xF0) >> 4; if (devid != CS35L32_CHIP_ID) { ret = -ENODEV; dev_err(&i2c_client->dev, "CS35L32 Device ID (%X). Expected %X\n", devid, CS35L32_CHIP_ID); return ret; } ret = regmap_read(cs35l32->regmap, CS35L32_REV_ID, ®); if (ret < 0) { dev_err(&i2c_client->dev, "Get Revision ID failed\n"); return ret; } ret = regmap_register_patch(cs35l32->regmap, cs35l32_monitor_patch, ARRAY_SIZE(cs35l32_monitor_patch)); if (ret < 0) { dev_err(&i2c_client->dev, "Failed to apply errata patch\n"); return ret; } dev_info(&i2c_client->dev, "Cirrus Logic CS35L32, Revision: %02X\n", reg & 0xFF); /* Setup VBOOST Management */ if (cs35l32->pdata.boost_mng) regmap_update_bits(cs35l32->regmap, CS35L32_AUDIO_LED_MNGR, CS35L32_BOOST_MASK, cs35l32->pdata.boost_mng); /* Setup ADSP Format Config */ if (cs35l32->pdata.sdout_share) regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, CS35L32_ADSP_SHARE_MASK, cs35l32->pdata.sdout_share << 3); /* Setup ADSP Data Configuration */ if (cs35l32->pdata.sdout_datacfg) regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, CS35L32_ADSP_DATACFG_MASK, cs35l32->pdata.sdout_datacfg << 4); /* Setup Low Battery Recovery */ if (cs35l32->pdata.batt_recov) regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, CS35L32_BATT_REC_MASK, cs35l32->pdata.batt_recov << 1); /* Setup Low Battery Threshold */ if (cs35l32->pdata.batt_thresh) regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, CS35L32_BATT_THRESH_MASK, cs35l32->pdata.batt_thresh << 4); /* Power down the AMP */ regmap_update_bits(cs35l32->regmap, CS35L32_PWRCTL1, CS35L32_PDN_AMP, CS35L32_PDN_AMP); /* Clear MCLK Error Bit since we don't have the clock yet */ ret = regmap_read(cs35l32->regmap, CS35L32_INT_STATUS_1, ®); ret = snd_soc_register_codec(&i2c_client->dev, &soc_codec_dev_cs35l32, cs35l32_dai, ARRAY_SIZE(cs35l32_dai)); if (ret < 0) goto err_disable; return 0; err_disable: regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); return ret; } static int cs35l32_i2c_remove(struct i2c_client *i2c_client) { struct cs35l32_private *cs35l32 = i2c_get_clientdata(i2c_client); snd_soc_unregister_codec(&i2c_client->dev); /* Hold down reset */ gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); return 0; } #ifdef CONFIG_PM static int cs35l32_runtime_suspend(struct device *dev) { struct cs35l32_private *cs35l32 = dev_get_drvdata(dev); regcache_cache_only(cs35l32->regmap, true); regcache_mark_dirty(cs35l32->regmap); /* Hold down reset */ gpiod_set_value_cansleep(cs35l32->reset_gpio, 0); /* remove power */ regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); return 0; } static int cs35l32_runtime_resume(struct device *dev) { struct cs35l32_private *cs35l32 = dev_get_drvdata(dev); int ret; /* Enable power */ ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); if (ret != 0) { dev_err(dev, "Failed to enable supplies: %d\n", ret); return ret; } gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); regcache_cache_only(cs35l32->regmap, false); regcache_sync(cs35l32->regmap); return 0; } #endif static const struct dev_pm_ops cs35l32_runtime_pm = { SET_RUNTIME_PM_OPS(cs35l32_runtime_suspend, cs35l32_runtime_resume, NULL) }; static const struct of_device_id cs35l32_of_match[] = { { .compatible = "cirrus,cs35l32", }, {}, }; MODULE_DEVICE_TABLE(of, cs35l32_of_match); static const struct i2c_device_id cs35l32_id[] = { {"cs35l32", 0}, {} }; MODULE_DEVICE_TABLE(i2c, cs35l32_id); static struct i2c_driver cs35l32_i2c_driver = { .driver = { .name = "cs35l32", .pm = &cs35l32_runtime_pm, .of_match_table = cs35l32_of_match, }, .id_table = cs35l32_id, .probe = cs35l32_i2c_probe, .remove = cs35l32_i2c_remove, }; module_i2c_driver(cs35l32_i2c_driver); MODULE_DESCRIPTION("ASoC CS35L32 driver"); MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>"); MODULE_LICENSE("GPL");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
You can’t perform that action at this time.