Loading sound/soc/codecs/cs43130.c +116 −99 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/i2c.h> #include <linux/of.h> #include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <sound/core.h> Loading Loading @@ -238,7 +238,7 @@ static int cs43130_pll_config(struct snd_soc_component *component) struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); const struct cs43130_pll_params *pll_entry; dev_dbg(component->dev, "cs43130->mclk = %u, cs43130->mclk_int = %u\n", dev_dbg(cs43130->dev, "cs43130->mclk = %u, cs43130->mclk_int = %u\n", cs43130->mclk, cs43130->mclk_int); pll_entry = cs43130_get_pll_table(cs43130->mclk, cs43130->mclk_int); Loading Loading @@ -303,7 +303,7 @@ static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int cs43130->mclk = freq_in; break; default: dev_err(component->dev, dev_err(cs43130->dev, "unsupported pll input reference clock:%d\n", freq_in); return -EINVAL; } Loading @@ -316,13 +316,13 @@ static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int cs43130->mclk_int = freq_out; break; default: dev_err(component->dev, dev_err(cs43130->dev, "unsupported pll output ref clock: %u\n", freq_out); return -EINVAL; } ret = cs43130_pll_config(component); dev_dbg(component->dev, "cs43130->pll_bypass = %d", cs43130->pll_bypass); dev_dbg(cs43130->dev, "cs43130->pll_bypass = %d", cs43130->pll_bypass); return ret; } Loading @@ -346,7 +346,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, mclk_int_decoded = CS43130_MCLK_24P5; break; default: dev_err(component->dev, "Invalid MCLK INT freq: %u\n", cs43130->mclk_int); dev_err(cs43130->dev, "Invalid MCLK INT freq: %u\n", cs43130->mclk_int); return -EINVAL; } Loading @@ -370,7 +370,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_XTAL_RDY_INT_MASK, 1 << CS43130_XTAL_RDY_INT_SHIFT); if (ret == 0) { dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for XTAL_READY interrupt\n"); return -ETIMEDOUT; } } Loading Loading @@ -406,7 +406,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_XTAL_RDY_INT_MASK, 1 << CS43130_XTAL_RDY_INT_SHIFT); if (ret == 0) { dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for XTAL_READY interrupt\n"); return -ETIMEDOUT; } } Loading @@ -422,7 +422,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_PLL_RDY_INT_MASK, 1 << CS43130_PLL_RDY_INT_SHIFT); if (ret == 0) { dev_err(component->dev, "Timeout waiting for PLL_READY interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for PLL_READY interrupt\n"); return -ETIMEDOUT; } Loading Loading @@ -453,7 +453,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, 1 << CS43130_PDN_PLL_SHIFT); break; default: dev_err(component->dev, "Invalid MCLK source value\n"); dev_err(cs43130->dev, "Invalid MCLK source value\n"); return -EINVAL; } Loading Loading @@ -578,7 +578,7 @@ static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk, break; case SND_SOC_DAIFMT_LEFT_J: hi_size = bitwidth_sclk; frm_delay = 2; frm_delay = 0; frm_phase = 1; break; case SND_SOC_DAIFMT_DSP_A: Loading Loading @@ -804,7 +804,7 @@ static int cs43130_dsd_hw_params(struct snd_pcm_substream *substream, dsd_speed = 1; break; default: dev_err(component->dev, "Rate(%u) not supported\n", dev_err(cs43130->dev, "Rate(%u) not supported\n", params_rate(params)); return -EINVAL; } Loading Loading @@ -875,7 +875,7 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, dsd_speed = 1; break; default: dev_err(component->dev, "Rate(%u) not supported\n", dev_err(cs43130->dev, "Rate(%u) not supported\n", params_rate(params)); return -EINVAL; } Loading @@ -892,7 +892,7 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val); break; default: dev_err(component->dev, "Invalid DAI (%d)\n", dai->id); dev_err(cs43130->dev, "Invalid DAI (%d)\n", dai->id); return -EINVAL; } Loading @@ -916,21 +916,21 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, if (!sclk) { /* at this point, SCLK must be set */ dev_err(component->dev, "SCLK freq is not set\n"); dev_err(cs43130->dev, "SCLK freq is not set\n"); return -EINVAL; } bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params); if (bitwidth_sclk < bitwidth_dai) { dev_err(component->dev, "Format not supported: SCLK freq is too low\n"); dev_err(cs43130->dev, "Format not supported: SCLK freq is too low\n"); return -EINVAL; } dev_dbg(component->dev, dev_dbg(cs43130->dev, "sclk = %u, fs = %d, bitwidth_dai = %u\n", sclk, params_rate(params), bitwidth_dai); dev_dbg(component->dev, dev_dbg(cs43130->dev, "bitwidth_sclk = %u, num_ch = %u\n", bitwidth_sclk, params_channels(params)); Loading Loading @@ -1189,7 +1189,7 @@ static int cs43130_dsd_event(struct snd_soc_dapm_widget *w, } break; default: dev_err(component->dev, "Invalid event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid event = 0x%x\n", event); return -EINVAL; } return 0; Loading Loading @@ -1246,7 +1246,7 @@ static int cs43130_pcm_event(struct snd_soc_dapm_widget *w, } break; default: dev_err(component->dev, "Invalid event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid event = 0x%x\n", event); return -EINVAL; } return 0; Loading Loading @@ -1322,7 +1322,7 @@ static int cs43130_dac_event(struct snd_soc_dapm_widget *w, } break; default: dev_err(component->dev, "Invalid DAC event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid DAC event = 0x%x\n", event); return -EINVAL; } return 0; Loading Loading @@ -1360,13 +1360,21 @@ static int cs43130_hpin_event(struct snd_soc_dapm_widget *w, ARRAY_SIZE(hpin_postpmu_seq)); break; default: dev_err(component->dev, "Invalid HPIN event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid HPIN event = 0x%x\n", event); return -EINVAL; } return 0; } static const char * const bypass_mux_text[] = { "Internal", "Alternative", }; static SOC_ENUM_SINGLE_DECL(bypass_enum, SND_SOC_NOPM, 0, bypass_mux_text); static const struct snd_kcontrol_new bypass_ctrl = SOC_DAPM_ENUM("Switch", bypass_enum); static const struct snd_soc_dapm_widget digital_hp_widgets[] = { SND_SOC_DAPM_MUX("Bypass Switch", SND_SOC_NOPM, 0, 0, &bypass_ctrl), SND_SOC_DAPM_OUTPUT("HPOUTA"), SND_SOC_DAPM_OUTPUT("HPOUTB"), Loading Loading @@ -1419,13 +1427,13 @@ static const struct snd_soc_dapm_route digital_hp_routes[] = { {"DSD", NULL, "XSPIN DSD"}, {"HiFi DAC", NULL, "ASPIN PCM"}, {"HiFi DAC", NULL, "DSD"}, {"HPOUTA", NULL, "HiFi DAC"}, {"HPOUTB", NULL, "HiFi DAC"}, {"Bypass Switch", "Internal", "HiFi DAC"}, {"HPOUTA", NULL, "Bypass Switch"}, {"HPOUTB", NULL, "Bypass Switch"}, }; static const struct snd_soc_dapm_route analog_hp_routes[] = { {"HPOUTA", NULL, "Analog Playback"}, {"HPOUTB", NULL, "Analog Playback"}, {"Bypass Switch", "Alternative", "Analog Playback"}, }; static struct snd_soc_dapm_route all_hp_routes[ Loading Loading @@ -1479,7 +1487,7 @@ static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM; break; default: dev_err(component->dev, "unsupported mode\n"); dev_err(cs43130->dev, "unsupported mode\n"); return -EINVAL; } Loading @@ -1497,12 +1505,12 @@ static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_DSP_B; break; default: dev_err(component->dev, dev_err(cs43130->dev, "unsupported audio format\n"); return -EINVAL; } dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n", dev_dbg(cs43130->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n", codec_dai->id, cs43130->dais[codec_dai->id].dai_mode, cs43130->dais[codec_dai->id].dai_format); Loading @@ -1523,11 +1531,11 @@ static int cs43130_dsd_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM; break; default: dev_err(component->dev, "Unsupported DAI format.\n"); dev_err(cs43130->dev, "Unsupported DAI format.\n"); return -EINVAL; } dev_dbg(component->dev, "dai_mode = 0x%x\n", dev_dbg(cs43130->dev, "dai_mode = 0x%x\n", cs43130->dais[codec_dai->id].dai_mode); return 0; Loading @@ -1540,7 +1548,7 @@ static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai, struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); cs43130->dais[codec_dai->id].sclk = freq; dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id, dev_dbg(cs43130->dev, "dai_id = %d, sclk = %u\n", codec_dai->id, cs43130->dais[codec_dai->id].sclk); return 0; Loading Loading @@ -1630,7 +1638,7 @@ static int cs43130_component_set_sysclk(struct snd_soc_component *component, { struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n", dev_dbg(cs43130->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n", clk_id, source, freq, dir); switch (freq) { Loading @@ -1639,14 +1647,14 @@ static int cs43130_component_set_sysclk(struct snd_soc_component *component, cs43130->mclk = freq; break; default: dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq); dev_err(cs43130->dev, "Invalid MCLK INT freq: %u\n", freq); return -EINVAL; } if (source == CS43130_MCLK_SRC_EXT) { cs43130->pll_bypass = true; } else { dev_err(component->dev, "Invalid MCLK source\n"); dev_err(cs43130->dev, "Invalid MCLK source\n"); return -EINVAL; } Loading Loading @@ -1682,7 +1690,7 @@ static ssize_t hpload_dc_r_show(struct device *dev, return cs43130_show_dc(dev, buf, HP_RIGHT); } static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = { static const u16 cs43130_ac_freq[CS43130_AC_FREQ] = { 24, 43, 93, Loading Loading @@ -1933,7 +1941,6 @@ static int cs43130_update_hpload(unsigned int msk, int ac_idx, unsigned int reg; u32 addr; u16 impedance; struct snd_soc_component *component = cs43130->component; switch (msk) { case CS43130_HPLOAD_DC_INT: Loading Loading @@ -1963,7 +1970,7 @@ static int cs43130_update_hpload(unsigned int msk, int ac_idx, else cs43130->hpload_dc[HP_RIGHT] = impedance; dev_dbg(component->dev, "HP DC impedance (Ch %u): %u\n", !left_ch, dev_dbg(cs43130->dev, "HP DC impedance (Ch %u): %u\n", !left_ch, impedance); } else { if (left_ch) Loading @@ -1971,7 +1978,7 @@ static int cs43130_update_hpload(unsigned int msk, int ac_idx, else cs43130->hpload_ac[ac_idx][HP_RIGHT] = impedance; dev_dbg(component->dev, "HP AC (%u Hz) impedance (Ch %u): %u\n", dev_dbg(cs43130->dev, "HP AC (%u Hz) impedance (Ch %u): %u\n", cs43130->ac_freq[ac_idx], !left_ch, impedance); } Loading @@ -1985,7 +1992,6 @@ static int cs43130_hpload_proc(struct cs43130_private *cs43130, int ret; unsigned int msk; u16 ac_reg_val; struct snd_soc_component *component = cs43130->component; reinit_completion(&cs43130->hpload_evt); Loading @@ -2008,17 +2014,17 @@ static int cs43130_hpload_proc(struct cs43130_private *cs43130, msecs_to_jiffies(1000)); regmap_read(cs43130->regmap, CS43130_INT_MASK_4, &msk); if (!ret) { dev_err(component->dev, "Timeout waiting for HPLOAD interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for HPLOAD interrupt\n"); return -1; } dev_dbg(component->dev, "HP load stat: %x, INT_MASK_4: %x\n", dev_dbg(cs43130->dev, "HP load stat: %x, INT_MASK_4: %x\n", cs43130->hpload_stat, msk); if ((cs43130->hpload_stat & (CS43130_HPLOAD_NO_DC_INT | CS43130_HPLOAD_UNPLUG_INT | CS43130_HPLOAD_OOR_INT)) || !(cs43130->hpload_stat & rslt_msk)) { dev_dbg(component->dev, "HP load measure failed\n"); dev_dbg(cs43130->dev, "HP load measure failed\n"); return -1; } Loading Loading @@ -2129,9 +2135,9 @@ static void cs43130_imp_meas(struct work_struct *wk) snd_soc_jack_report(&cs43130->jack, CS43130_JACK_HEADPHONE, CS43130_JACK_MASK); dev_dbg(component->dev, "Set HP output control. DC threshold\n"); dev_dbg(cs43130->dev, "Set HP output control. DC threshold\n"); for (i = 0; i < CS43130_DC_THRESHOLD; i++) dev_dbg(component->dev, "DC threshold[%d]: %u.\n", i, dev_dbg(cs43130->dev, "DC threshold[%d]: %u.\n", i, cs43130->dc_threshold[i]); cs43130_set_hv(cs43130->regmap, cs43130->hpload_dc[HP_LEFT], Loading Loading @@ -2165,7 +2171,6 @@ static void cs43130_imp_meas(struct work_struct *wk) static irqreturn_t cs43130_irq_thread(int irq, void *data) { struct cs43130_private *cs43130 = (struct cs43130_private *)data; struct snd_soc_component *component = cs43130->component; unsigned int stickies[CS43130_NUM_INT]; unsigned int irq_occurrence = 0; unsigned int masks[CS43130_NUM_INT]; Loading @@ -2183,8 +2188,6 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) for (j = 0; j < 8; j++) irq_occurrence += (stickies[i] >> j) & 1; } dev_dbg(component->dev, "number of interrupts occurred (%u)\n", irq_occurrence); if (!irq_occurrence) return IRQ_NONE; Loading @@ -2201,7 +2204,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_NO_DC_INT) { cs43130->hpload_stat = stickies[3]; dev_err(component->dev, dev_err(cs43130->dev, "DC load has not completed before AC load (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); Loading @@ -2210,7 +2213,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_UNPLUG_INT) { cs43130->hpload_stat = stickies[3]; dev_err(component->dev, "HP unplugged during measurement (%x)\n", dev_err(cs43130->dev, "HP unplugged during measurement (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2218,7 +2221,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_OOR_INT) { cs43130->hpload_stat = stickies[3]; dev_err(component->dev, "HP load out of range (%x)\n", dev_err(cs43130->dev, "HP load out of range (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2226,7 +2229,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_AC_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP AC load measurement done (%x)\n", dev_dbg(cs43130->dev, "HP AC load measurement done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2234,7 +2237,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_DC_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP DC load measurement done (%x)\n", dev_dbg(cs43130->dev, "HP DC load measurement done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2242,7 +2245,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_ON_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP load state machine on done (%x)\n", dev_dbg(cs43130->dev, "HP load state machine on done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2250,19 +2253,19 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_OFF_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP load state machine off done (%x)\n", dev_dbg(cs43130->dev, "HP load state machine off done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; } if (stickies[0] & CS43130_XTAL_ERR_INT) { dev_err(component->dev, "Crystal err: clock is not running\n"); dev_err(cs43130->dev, "Crystal err: clock is not running\n"); return IRQ_HANDLED; } if (stickies[0] & CS43130_HP_UNPLUG_INT) { dev_dbg(component->dev, "HP unplugged\n"); dev_dbg(cs43130->dev, "HP unplugged\n"); cs43130->hpload_done = false; snd_soc_jack_report(&cs43130->jack, 0, CS43130_JACK_MASK); return IRQ_HANDLED; Loading @@ -2271,7 +2274,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[0] & CS43130_HP_PLUG_INT) { if (cs43130->dc_meas && !cs43130->hpload_done && !work_busy(&cs43130->work)) { dev_dbg(component->dev, "HP load queue work\n"); dev_dbg(cs43130->dev, "HP load queue work\n"); queue_work(cs43130->wq, &cs43130->work); } Loading Loading @@ -2303,19 +2306,19 @@ static int cs43130_probe(struct snd_soc_component *component) ret = snd_soc_card_jack_new(card, "Headphone", CS43130_JACK_MASK, &cs43130->jack); if (ret < 0) { dev_err(component->dev, "Cannot create jack\n"); dev_err(cs43130->dev, "Cannot create jack\n"); return ret; } cs43130->hpload_done = false; if (cs43130->dc_meas) { ret = sysfs_create_groups(&component->dev->kobj, hpload_groups); ret = sysfs_create_groups(&cs43130->dev->kobj, hpload_groups); if (ret) return ret; cs43130->wq = create_singlethread_workqueue("cs43130_hp"); if (!cs43130->wq) { sysfs_remove_groups(&component->dev->kobj, hpload_groups); sysfs_remove_groups(&cs43130->dev->kobj, hpload_groups); return -ENOMEM; } INIT_WORK(&cs43130->work, cs43130_imp_meas); Loading Loading @@ -2362,19 +2365,17 @@ static const struct regmap_config cs43130_regmap = { .use_single_write = true, }; static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = { static const u16 cs43130_dc_threshold[CS43130_DC_THRESHOLD] = { 50, 120, }; static int cs43130_handle_device_data(struct i2c_client *i2c_client, struct cs43130_private *cs43130) static int cs43130_handle_device_data(struct cs43130_private *cs43130) { struct device_node *np = i2c_client->dev.of_node; unsigned int val; int i; if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) { if (device_property_read_u32(cs43130->dev, "cirrus,xtal-ibias", &val) < 0) { /* Crystal is unused. System clock is used for external MCLK */ cs43130->xtal_ibias = CS43130_XTAL_UNUSED; return 0; Loading @@ -2391,23 +2392,23 @@ static int cs43130_handle_device_data(struct i2c_client *i2c_client, cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA; break; default: dev_err(&i2c_client->dev, dev_err(cs43130->dev, "Invalid cirrus,xtal-ibias value: %d\n", val); return -EINVAL; } cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure"); cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure"); cs43130->dc_meas = device_property_read_bool(cs43130->dev, "cirrus,dc-measure"); cs43130->ac_meas = device_property_read_bool(cs43130->dev, "cirrus,ac-measure"); if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq, CS43130_AC_FREQ) < 0) { if (!device_property_read_u16_array(cs43130->dev, "cirrus,ac-freq", cs43130->ac_freq, CS43130_AC_FREQ)) { for (i = 0; i < CS43130_AC_FREQ; i++) cs43130->ac_freq[i] = cs43130_ac_freq[i]; } if (of_property_read_u16_array(np, "cirrus,dc-threshold", if (!device_property_read_u16_array(cs43130->dev, "cirrus,dc-threshold", cs43130->dc_threshold, CS43130_DC_THRESHOLD) < 0) { CS43130_DC_THRESHOLD)) { for (i = 0; i < CS43130_DC_THRESHOLD; i++) cs43130->dc_threshold[i] = cs43130_dc_threshold[i]; } Loading @@ -2426,6 +2427,8 @@ static int cs43130_i2c_probe(struct i2c_client *client) if (!cs43130) return -ENOMEM; cs43130->dev = &client->dev; i2c_set_clientdata(client, cs43130); cs43130->regmap = devm_regmap_init_i2c(client, &cs43130_regmap); Loading @@ -2434,29 +2437,30 @@ static int cs43130_i2c_probe(struct i2c_client *client) return ret; } if (client->dev.of_node) { ret = cs43130_handle_device_data(client, cs43130); if (dev_fwnode(cs43130->dev)) { ret = cs43130_handle_device_data(cs43130); if (ret != 0) return ret; } for (i = 0; i < ARRAY_SIZE(cs43130->supplies); i++) cs43130->supplies[i].supply = cs43130_supply_names[i]; ret = devm_regulator_bulk_get(&client->dev, ret = devm_regulator_bulk_get(cs43130->dev, ARRAY_SIZE(cs43130->supplies), cs43130->supplies); if (ret != 0) { dev_err(&client->dev, "Failed to request supplies: %d\n", ret); dev_err(cs43130->dev, "Failed to request supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(cs43130->supplies), cs43130->supplies); if (ret != 0) { dev_err(&client->dev, "Failed to enable supplies: %d\n", ret); dev_err(cs43130->dev, "Failed to enable supplies: %d\n", ret); return ret; } cs43130->reset_gpio = devm_gpiod_get_optional(&client->dev, cs43130->reset_gpio = devm_gpiod_get_optional(cs43130->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(cs43130->reset_gpio)) { ret = PTR_ERR(cs43130->reset_gpio); Loading @@ -2470,7 +2474,7 @@ static int cs43130_i2c_probe(struct i2c_client *client) devid = cirrus_read_device_id(cs43130->regmap, CS43130_DEVID_AB); if (devid < 0) { ret = devid; dev_err(&client->dev, "Failed to read device ID: %d\n", ret); dev_err(cs43130->dev, "Failed to read device ID: %d\n", ret); goto err; } Loading @@ -2481,7 +2485,7 @@ static int cs43130_i2c_probe(struct i2c_client *client) case CS43198_CHIP_ID: break; default: dev_err(&client->dev, dev_err(cs43130->dev, "CS43130 Device ID %X. Expected ID %X, %X, %X or %X\n", devid, CS43130_CHIP_ID, CS4399_CHIP_ID, CS43131_CHIP_ID, CS43198_CHIP_ID); Loading @@ -2492,11 +2496,11 @@ static int cs43130_i2c_probe(struct i2c_client *client) cs43130->dev_id = devid; ret = regmap_read(cs43130->regmap, CS43130_REV_ID, ®); if (ret < 0) { dev_err(&client->dev, "Get Revision ID failed\n"); dev_err(cs43130->dev, "Get Revision ID failed\n"); goto err; } dev_info(&client->dev, dev_info(cs43130->dev, "Cirrus Logic CS43130 (%x), Revision: %02X\n", devid, reg & 0xFF); Loading @@ -2506,21 +2510,21 @@ static int cs43130_i2c_probe(struct i2c_client *client) init_completion(&cs43130->pll_rdy); init_completion(&cs43130->hpload_evt); ret = devm_request_threaded_irq(&client->dev, client->irq, ret = devm_request_threaded_irq(cs43130->dev, client->irq, NULL, cs43130_irq_thread, IRQF_ONESHOT | IRQF_TRIGGER_LOW, "cs43130", cs43130); if (ret != 0) { dev_err(&client->dev, "Failed to request IRQ: %d\n", ret); dev_err(cs43130->dev, "Failed to request IRQ: %d\n", ret); goto err; } cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO; pm_runtime_set_autosuspend_delay(&client->dev, 100); pm_runtime_use_autosuspend(&client->dev); pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(cs43130->dev, 100); pm_runtime_use_autosuspend(cs43130->dev); pm_runtime_set_active(cs43130->dev); pm_runtime_enable(cs43130->dev); switch (cs43130->dev_id) { case CS43130_CHIP_ID: Loading Loading @@ -2556,11 +2560,11 @@ static int cs43130_i2c_probe(struct i2c_client *client) break; } ret = devm_snd_soc_register_component(&client->dev, ret = devm_snd_soc_register_component(cs43130->dev, &soc_component_dev_cs43130, cs43130_dai, ARRAY_SIZE(cs43130_dai)); if (ret < 0) { dev_err(&client->dev, dev_err(cs43130->dev, "snd_soc_register_component failed with ret = %d\n", ret); goto err; } Loading Loading @@ -2598,15 +2602,15 @@ static void cs43130_i2c_remove(struct i2c_client *client) cancel_work_sync(&cs43130->work); flush_workqueue(cs43130->wq); device_remove_file(&client->dev, &dev_attr_hpload_dc_l); device_remove_file(&client->dev, &dev_attr_hpload_dc_r); device_remove_file(&client->dev, &dev_attr_hpload_ac_l); device_remove_file(&client->dev, &dev_attr_hpload_ac_r); device_remove_file(cs43130->dev, &dev_attr_hpload_dc_l); device_remove_file(cs43130->dev, &dev_attr_hpload_dc_r); device_remove_file(cs43130->dev, &dev_attr_hpload_ac_l); device_remove_file(cs43130->dev, &dev_attr_hpload_ac_r); } gpiod_set_value_cansleep(cs43130->reset_gpio, 0); pm_runtime_disable(&client->dev); pm_runtime_disable(cs43130->dev); regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies); } Loading Loading @@ -2669,6 +2673,7 @@ static const struct dev_pm_ops cs43130_runtime_pm = { NULL) }; #if IS_ENABLED(CONFIG_OF) static const struct of_device_id cs43130_of_match[] = { {.compatible = "cirrus,cs43130",}, {.compatible = "cirrus,cs4399",}, Loading @@ -2678,6 +2683,17 @@ static const struct of_device_id cs43130_of_match[] = { }; MODULE_DEVICE_TABLE(of, cs43130_of_match); #endif #if IS_ENABLED(CONFIG_ACPI) static const struct acpi_device_id cs43130_acpi_match[] = { { "CSC4399", 0 }, {} }; MODULE_DEVICE_TABLE(acpi, cs43130_acpi_match); #endif static const struct i2c_device_id cs43130_i2c_id[] = { {"cs43130", 0}, Loading @@ -2692,7 +2708,8 @@ MODULE_DEVICE_TABLE(i2c, cs43130_i2c_id); static struct i2c_driver cs43130_i2c_driver = { .driver = { .name = "cs43130", .of_match_table = cs43130_of_match, .of_match_table = of_match_ptr(cs43130_of_match), .acpi_match_table = ACPI_PTR(cs43130_acpi_match), .pm = &cs43130_runtime_pm, }, .id_table = cs43130_i2c_id, Loading sound/soc/codecs/cs43130.h +1 −0 Original line number Diff line number Diff line Loading @@ -500,6 +500,7 @@ struct cs43130_dai { }; struct cs43130_private { struct device *dev; struct snd_soc_component *component; struct regmap *regmap; struct regulator_bulk_data supplies[CS43130_NUM_SUPPLIES]; Loading Loading
sound/soc/codecs/cs43130.c +116 −99 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/i2c.h> #include <linux/of.h> #include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <sound/core.h> Loading Loading @@ -238,7 +238,7 @@ static int cs43130_pll_config(struct snd_soc_component *component) struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); const struct cs43130_pll_params *pll_entry; dev_dbg(component->dev, "cs43130->mclk = %u, cs43130->mclk_int = %u\n", dev_dbg(cs43130->dev, "cs43130->mclk = %u, cs43130->mclk_int = %u\n", cs43130->mclk, cs43130->mclk_int); pll_entry = cs43130_get_pll_table(cs43130->mclk, cs43130->mclk_int); Loading Loading @@ -303,7 +303,7 @@ static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int cs43130->mclk = freq_in; break; default: dev_err(component->dev, dev_err(cs43130->dev, "unsupported pll input reference clock:%d\n", freq_in); return -EINVAL; } Loading @@ -316,13 +316,13 @@ static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int cs43130->mclk_int = freq_out; break; default: dev_err(component->dev, dev_err(cs43130->dev, "unsupported pll output ref clock: %u\n", freq_out); return -EINVAL; } ret = cs43130_pll_config(component); dev_dbg(component->dev, "cs43130->pll_bypass = %d", cs43130->pll_bypass); dev_dbg(cs43130->dev, "cs43130->pll_bypass = %d", cs43130->pll_bypass); return ret; } Loading @@ -346,7 +346,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, mclk_int_decoded = CS43130_MCLK_24P5; break; default: dev_err(component->dev, "Invalid MCLK INT freq: %u\n", cs43130->mclk_int); dev_err(cs43130->dev, "Invalid MCLK INT freq: %u\n", cs43130->mclk_int); return -EINVAL; } Loading @@ -370,7 +370,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_XTAL_RDY_INT_MASK, 1 << CS43130_XTAL_RDY_INT_SHIFT); if (ret == 0) { dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for XTAL_READY interrupt\n"); return -ETIMEDOUT; } } Loading Loading @@ -406,7 +406,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_XTAL_RDY_INT_MASK, 1 << CS43130_XTAL_RDY_INT_SHIFT); if (ret == 0) { dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for XTAL_READY interrupt\n"); return -ETIMEDOUT; } } Loading @@ -422,7 +422,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, CS43130_PLL_RDY_INT_MASK, 1 << CS43130_PLL_RDY_INT_SHIFT); if (ret == 0) { dev_err(component->dev, "Timeout waiting for PLL_READY interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for PLL_READY interrupt\n"); return -ETIMEDOUT; } Loading Loading @@ -453,7 +453,7 @@ static int cs43130_change_clksrc(struct snd_soc_component *component, 1 << CS43130_PDN_PLL_SHIFT); break; default: dev_err(component->dev, "Invalid MCLK source value\n"); dev_err(cs43130->dev, "Invalid MCLK source value\n"); return -EINVAL; } Loading Loading @@ -578,7 +578,7 @@ static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk, break; case SND_SOC_DAIFMT_LEFT_J: hi_size = bitwidth_sclk; frm_delay = 2; frm_delay = 0; frm_phase = 1; break; case SND_SOC_DAIFMT_DSP_A: Loading Loading @@ -804,7 +804,7 @@ static int cs43130_dsd_hw_params(struct snd_pcm_substream *substream, dsd_speed = 1; break; default: dev_err(component->dev, "Rate(%u) not supported\n", dev_err(cs43130->dev, "Rate(%u) not supported\n", params_rate(params)); return -EINVAL; } Loading Loading @@ -875,7 +875,7 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, dsd_speed = 1; break; default: dev_err(component->dev, "Rate(%u) not supported\n", dev_err(cs43130->dev, "Rate(%u) not supported\n", params_rate(params)); return -EINVAL; } Loading @@ -892,7 +892,7 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val); break; default: dev_err(component->dev, "Invalid DAI (%d)\n", dai->id); dev_err(cs43130->dev, "Invalid DAI (%d)\n", dai->id); return -EINVAL; } Loading @@ -916,21 +916,21 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream, if (!sclk) { /* at this point, SCLK must be set */ dev_err(component->dev, "SCLK freq is not set\n"); dev_err(cs43130->dev, "SCLK freq is not set\n"); return -EINVAL; } bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params); if (bitwidth_sclk < bitwidth_dai) { dev_err(component->dev, "Format not supported: SCLK freq is too low\n"); dev_err(cs43130->dev, "Format not supported: SCLK freq is too low\n"); return -EINVAL; } dev_dbg(component->dev, dev_dbg(cs43130->dev, "sclk = %u, fs = %d, bitwidth_dai = %u\n", sclk, params_rate(params), bitwidth_dai); dev_dbg(component->dev, dev_dbg(cs43130->dev, "bitwidth_sclk = %u, num_ch = %u\n", bitwidth_sclk, params_channels(params)); Loading Loading @@ -1189,7 +1189,7 @@ static int cs43130_dsd_event(struct snd_soc_dapm_widget *w, } break; default: dev_err(component->dev, "Invalid event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid event = 0x%x\n", event); return -EINVAL; } return 0; Loading Loading @@ -1246,7 +1246,7 @@ static int cs43130_pcm_event(struct snd_soc_dapm_widget *w, } break; default: dev_err(component->dev, "Invalid event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid event = 0x%x\n", event); return -EINVAL; } return 0; Loading Loading @@ -1322,7 +1322,7 @@ static int cs43130_dac_event(struct snd_soc_dapm_widget *w, } break; default: dev_err(component->dev, "Invalid DAC event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid DAC event = 0x%x\n", event); return -EINVAL; } return 0; Loading Loading @@ -1360,13 +1360,21 @@ static int cs43130_hpin_event(struct snd_soc_dapm_widget *w, ARRAY_SIZE(hpin_postpmu_seq)); break; default: dev_err(component->dev, "Invalid HPIN event = 0x%x\n", event); dev_err(cs43130->dev, "Invalid HPIN event = 0x%x\n", event); return -EINVAL; } return 0; } static const char * const bypass_mux_text[] = { "Internal", "Alternative", }; static SOC_ENUM_SINGLE_DECL(bypass_enum, SND_SOC_NOPM, 0, bypass_mux_text); static const struct snd_kcontrol_new bypass_ctrl = SOC_DAPM_ENUM("Switch", bypass_enum); static const struct snd_soc_dapm_widget digital_hp_widgets[] = { SND_SOC_DAPM_MUX("Bypass Switch", SND_SOC_NOPM, 0, 0, &bypass_ctrl), SND_SOC_DAPM_OUTPUT("HPOUTA"), SND_SOC_DAPM_OUTPUT("HPOUTB"), Loading Loading @@ -1419,13 +1427,13 @@ static const struct snd_soc_dapm_route digital_hp_routes[] = { {"DSD", NULL, "XSPIN DSD"}, {"HiFi DAC", NULL, "ASPIN PCM"}, {"HiFi DAC", NULL, "DSD"}, {"HPOUTA", NULL, "HiFi DAC"}, {"HPOUTB", NULL, "HiFi DAC"}, {"Bypass Switch", "Internal", "HiFi DAC"}, {"HPOUTA", NULL, "Bypass Switch"}, {"HPOUTB", NULL, "Bypass Switch"}, }; static const struct snd_soc_dapm_route analog_hp_routes[] = { {"HPOUTA", NULL, "Analog Playback"}, {"HPOUTB", NULL, "Analog Playback"}, {"Bypass Switch", "Alternative", "Analog Playback"}, }; static struct snd_soc_dapm_route all_hp_routes[ Loading Loading @@ -1479,7 +1487,7 @@ static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM; break; default: dev_err(component->dev, "unsupported mode\n"); dev_err(cs43130->dev, "unsupported mode\n"); return -EINVAL; } Loading @@ -1497,12 +1505,12 @@ static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_DSP_B; break; default: dev_err(component->dev, dev_err(cs43130->dev, "unsupported audio format\n"); return -EINVAL; } dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n", dev_dbg(cs43130->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n", codec_dai->id, cs43130->dais[codec_dai->id].dai_mode, cs43130->dais[codec_dai->id].dai_format); Loading @@ -1523,11 +1531,11 @@ static int cs43130_dsd_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM; break; default: dev_err(component->dev, "Unsupported DAI format.\n"); dev_err(cs43130->dev, "Unsupported DAI format.\n"); return -EINVAL; } dev_dbg(component->dev, "dai_mode = 0x%x\n", dev_dbg(cs43130->dev, "dai_mode = 0x%x\n", cs43130->dais[codec_dai->id].dai_mode); return 0; Loading @@ -1540,7 +1548,7 @@ static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai, struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); cs43130->dais[codec_dai->id].sclk = freq; dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id, dev_dbg(cs43130->dev, "dai_id = %d, sclk = %u\n", codec_dai->id, cs43130->dais[codec_dai->id].sclk); return 0; Loading Loading @@ -1630,7 +1638,7 @@ static int cs43130_component_set_sysclk(struct snd_soc_component *component, { struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component); dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n", dev_dbg(cs43130->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n", clk_id, source, freq, dir); switch (freq) { Loading @@ -1639,14 +1647,14 @@ static int cs43130_component_set_sysclk(struct snd_soc_component *component, cs43130->mclk = freq; break; default: dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq); dev_err(cs43130->dev, "Invalid MCLK INT freq: %u\n", freq); return -EINVAL; } if (source == CS43130_MCLK_SRC_EXT) { cs43130->pll_bypass = true; } else { dev_err(component->dev, "Invalid MCLK source\n"); dev_err(cs43130->dev, "Invalid MCLK source\n"); return -EINVAL; } Loading Loading @@ -1682,7 +1690,7 @@ static ssize_t hpload_dc_r_show(struct device *dev, return cs43130_show_dc(dev, buf, HP_RIGHT); } static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = { static const u16 cs43130_ac_freq[CS43130_AC_FREQ] = { 24, 43, 93, Loading Loading @@ -1933,7 +1941,6 @@ static int cs43130_update_hpload(unsigned int msk, int ac_idx, unsigned int reg; u32 addr; u16 impedance; struct snd_soc_component *component = cs43130->component; switch (msk) { case CS43130_HPLOAD_DC_INT: Loading Loading @@ -1963,7 +1970,7 @@ static int cs43130_update_hpload(unsigned int msk, int ac_idx, else cs43130->hpload_dc[HP_RIGHT] = impedance; dev_dbg(component->dev, "HP DC impedance (Ch %u): %u\n", !left_ch, dev_dbg(cs43130->dev, "HP DC impedance (Ch %u): %u\n", !left_ch, impedance); } else { if (left_ch) Loading @@ -1971,7 +1978,7 @@ static int cs43130_update_hpload(unsigned int msk, int ac_idx, else cs43130->hpload_ac[ac_idx][HP_RIGHT] = impedance; dev_dbg(component->dev, "HP AC (%u Hz) impedance (Ch %u): %u\n", dev_dbg(cs43130->dev, "HP AC (%u Hz) impedance (Ch %u): %u\n", cs43130->ac_freq[ac_idx], !left_ch, impedance); } Loading @@ -1985,7 +1992,6 @@ static int cs43130_hpload_proc(struct cs43130_private *cs43130, int ret; unsigned int msk; u16 ac_reg_val; struct snd_soc_component *component = cs43130->component; reinit_completion(&cs43130->hpload_evt); Loading @@ -2008,17 +2014,17 @@ static int cs43130_hpload_proc(struct cs43130_private *cs43130, msecs_to_jiffies(1000)); regmap_read(cs43130->regmap, CS43130_INT_MASK_4, &msk); if (!ret) { dev_err(component->dev, "Timeout waiting for HPLOAD interrupt\n"); dev_err(cs43130->dev, "Timeout waiting for HPLOAD interrupt\n"); return -1; } dev_dbg(component->dev, "HP load stat: %x, INT_MASK_4: %x\n", dev_dbg(cs43130->dev, "HP load stat: %x, INT_MASK_4: %x\n", cs43130->hpload_stat, msk); if ((cs43130->hpload_stat & (CS43130_HPLOAD_NO_DC_INT | CS43130_HPLOAD_UNPLUG_INT | CS43130_HPLOAD_OOR_INT)) || !(cs43130->hpload_stat & rslt_msk)) { dev_dbg(component->dev, "HP load measure failed\n"); dev_dbg(cs43130->dev, "HP load measure failed\n"); return -1; } Loading Loading @@ -2129,9 +2135,9 @@ static void cs43130_imp_meas(struct work_struct *wk) snd_soc_jack_report(&cs43130->jack, CS43130_JACK_HEADPHONE, CS43130_JACK_MASK); dev_dbg(component->dev, "Set HP output control. DC threshold\n"); dev_dbg(cs43130->dev, "Set HP output control. DC threshold\n"); for (i = 0; i < CS43130_DC_THRESHOLD; i++) dev_dbg(component->dev, "DC threshold[%d]: %u.\n", i, dev_dbg(cs43130->dev, "DC threshold[%d]: %u.\n", i, cs43130->dc_threshold[i]); cs43130_set_hv(cs43130->regmap, cs43130->hpload_dc[HP_LEFT], Loading Loading @@ -2165,7 +2171,6 @@ static void cs43130_imp_meas(struct work_struct *wk) static irqreturn_t cs43130_irq_thread(int irq, void *data) { struct cs43130_private *cs43130 = (struct cs43130_private *)data; struct snd_soc_component *component = cs43130->component; unsigned int stickies[CS43130_NUM_INT]; unsigned int irq_occurrence = 0; unsigned int masks[CS43130_NUM_INT]; Loading @@ -2183,8 +2188,6 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) for (j = 0; j < 8; j++) irq_occurrence += (stickies[i] >> j) & 1; } dev_dbg(component->dev, "number of interrupts occurred (%u)\n", irq_occurrence); if (!irq_occurrence) return IRQ_NONE; Loading @@ -2201,7 +2204,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_NO_DC_INT) { cs43130->hpload_stat = stickies[3]; dev_err(component->dev, dev_err(cs43130->dev, "DC load has not completed before AC load (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); Loading @@ -2210,7 +2213,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_UNPLUG_INT) { cs43130->hpload_stat = stickies[3]; dev_err(component->dev, "HP unplugged during measurement (%x)\n", dev_err(cs43130->dev, "HP unplugged during measurement (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2218,7 +2221,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_OOR_INT) { cs43130->hpload_stat = stickies[3]; dev_err(component->dev, "HP load out of range (%x)\n", dev_err(cs43130->dev, "HP load out of range (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2226,7 +2229,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_AC_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP AC load measurement done (%x)\n", dev_dbg(cs43130->dev, "HP AC load measurement done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2234,7 +2237,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_DC_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP DC load measurement done (%x)\n", dev_dbg(cs43130->dev, "HP DC load measurement done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2242,7 +2245,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_ON_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP load state machine on done (%x)\n", dev_dbg(cs43130->dev, "HP load state machine on done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; Loading @@ -2250,19 +2253,19 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[3] & CS43130_HPLOAD_OFF_INT) { cs43130->hpload_stat = stickies[3]; dev_dbg(component->dev, "HP load state machine off done (%x)\n", dev_dbg(cs43130->dev, "HP load state machine off done (%x)\n", cs43130->hpload_stat); complete(&cs43130->hpload_evt); return IRQ_HANDLED; } if (stickies[0] & CS43130_XTAL_ERR_INT) { dev_err(component->dev, "Crystal err: clock is not running\n"); dev_err(cs43130->dev, "Crystal err: clock is not running\n"); return IRQ_HANDLED; } if (stickies[0] & CS43130_HP_UNPLUG_INT) { dev_dbg(component->dev, "HP unplugged\n"); dev_dbg(cs43130->dev, "HP unplugged\n"); cs43130->hpload_done = false; snd_soc_jack_report(&cs43130->jack, 0, CS43130_JACK_MASK); return IRQ_HANDLED; Loading @@ -2271,7 +2274,7 @@ static irqreturn_t cs43130_irq_thread(int irq, void *data) if (stickies[0] & CS43130_HP_PLUG_INT) { if (cs43130->dc_meas && !cs43130->hpload_done && !work_busy(&cs43130->work)) { dev_dbg(component->dev, "HP load queue work\n"); dev_dbg(cs43130->dev, "HP load queue work\n"); queue_work(cs43130->wq, &cs43130->work); } Loading Loading @@ -2303,19 +2306,19 @@ static int cs43130_probe(struct snd_soc_component *component) ret = snd_soc_card_jack_new(card, "Headphone", CS43130_JACK_MASK, &cs43130->jack); if (ret < 0) { dev_err(component->dev, "Cannot create jack\n"); dev_err(cs43130->dev, "Cannot create jack\n"); return ret; } cs43130->hpload_done = false; if (cs43130->dc_meas) { ret = sysfs_create_groups(&component->dev->kobj, hpload_groups); ret = sysfs_create_groups(&cs43130->dev->kobj, hpload_groups); if (ret) return ret; cs43130->wq = create_singlethread_workqueue("cs43130_hp"); if (!cs43130->wq) { sysfs_remove_groups(&component->dev->kobj, hpload_groups); sysfs_remove_groups(&cs43130->dev->kobj, hpload_groups); return -ENOMEM; } INIT_WORK(&cs43130->work, cs43130_imp_meas); Loading Loading @@ -2362,19 +2365,17 @@ static const struct regmap_config cs43130_regmap = { .use_single_write = true, }; static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = { static const u16 cs43130_dc_threshold[CS43130_DC_THRESHOLD] = { 50, 120, }; static int cs43130_handle_device_data(struct i2c_client *i2c_client, struct cs43130_private *cs43130) static int cs43130_handle_device_data(struct cs43130_private *cs43130) { struct device_node *np = i2c_client->dev.of_node; unsigned int val; int i; if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) { if (device_property_read_u32(cs43130->dev, "cirrus,xtal-ibias", &val) < 0) { /* Crystal is unused. System clock is used for external MCLK */ cs43130->xtal_ibias = CS43130_XTAL_UNUSED; return 0; Loading @@ -2391,23 +2392,23 @@ static int cs43130_handle_device_data(struct i2c_client *i2c_client, cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA; break; default: dev_err(&i2c_client->dev, dev_err(cs43130->dev, "Invalid cirrus,xtal-ibias value: %d\n", val); return -EINVAL; } cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure"); cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure"); cs43130->dc_meas = device_property_read_bool(cs43130->dev, "cirrus,dc-measure"); cs43130->ac_meas = device_property_read_bool(cs43130->dev, "cirrus,ac-measure"); if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq, CS43130_AC_FREQ) < 0) { if (!device_property_read_u16_array(cs43130->dev, "cirrus,ac-freq", cs43130->ac_freq, CS43130_AC_FREQ)) { for (i = 0; i < CS43130_AC_FREQ; i++) cs43130->ac_freq[i] = cs43130_ac_freq[i]; } if (of_property_read_u16_array(np, "cirrus,dc-threshold", if (!device_property_read_u16_array(cs43130->dev, "cirrus,dc-threshold", cs43130->dc_threshold, CS43130_DC_THRESHOLD) < 0) { CS43130_DC_THRESHOLD)) { for (i = 0; i < CS43130_DC_THRESHOLD; i++) cs43130->dc_threshold[i] = cs43130_dc_threshold[i]; } Loading @@ -2426,6 +2427,8 @@ static int cs43130_i2c_probe(struct i2c_client *client) if (!cs43130) return -ENOMEM; cs43130->dev = &client->dev; i2c_set_clientdata(client, cs43130); cs43130->regmap = devm_regmap_init_i2c(client, &cs43130_regmap); Loading @@ -2434,29 +2437,30 @@ static int cs43130_i2c_probe(struct i2c_client *client) return ret; } if (client->dev.of_node) { ret = cs43130_handle_device_data(client, cs43130); if (dev_fwnode(cs43130->dev)) { ret = cs43130_handle_device_data(cs43130); if (ret != 0) return ret; } for (i = 0; i < ARRAY_SIZE(cs43130->supplies); i++) cs43130->supplies[i].supply = cs43130_supply_names[i]; ret = devm_regulator_bulk_get(&client->dev, ret = devm_regulator_bulk_get(cs43130->dev, ARRAY_SIZE(cs43130->supplies), cs43130->supplies); if (ret != 0) { dev_err(&client->dev, "Failed to request supplies: %d\n", ret); dev_err(cs43130->dev, "Failed to request supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(cs43130->supplies), cs43130->supplies); if (ret != 0) { dev_err(&client->dev, "Failed to enable supplies: %d\n", ret); dev_err(cs43130->dev, "Failed to enable supplies: %d\n", ret); return ret; } cs43130->reset_gpio = devm_gpiod_get_optional(&client->dev, cs43130->reset_gpio = devm_gpiod_get_optional(cs43130->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(cs43130->reset_gpio)) { ret = PTR_ERR(cs43130->reset_gpio); Loading @@ -2470,7 +2474,7 @@ static int cs43130_i2c_probe(struct i2c_client *client) devid = cirrus_read_device_id(cs43130->regmap, CS43130_DEVID_AB); if (devid < 0) { ret = devid; dev_err(&client->dev, "Failed to read device ID: %d\n", ret); dev_err(cs43130->dev, "Failed to read device ID: %d\n", ret); goto err; } Loading @@ -2481,7 +2485,7 @@ static int cs43130_i2c_probe(struct i2c_client *client) case CS43198_CHIP_ID: break; default: dev_err(&client->dev, dev_err(cs43130->dev, "CS43130 Device ID %X. Expected ID %X, %X, %X or %X\n", devid, CS43130_CHIP_ID, CS4399_CHIP_ID, CS43131_CHIP_ID, CS43198_CHIP_ID); Loading @@ -2492,11 +2496,11 @@ static int cs43130_i2c_probe(struct i2c_client *client) cs43130->dev_id = devid; ret = regmap_read(cs43130->regmap, CS43130_REV_ID, ®); if (ret < 0) { dev_err(&client->dev, "Get Revision ID failed\n"); dev_err(cs43130->dev, "Get Revision ID failed\n"); goto err; } dev_info(&client->dev, dev_info(cs43130->dev, "Cirrus Logic CS43130 (%x), Revision: %02X\n", devid, reg & 0xFF); Loading @@ -2506,21 +2510,21 @@ static int cs43130_i2c_probe(struct i2c_client *client) init_completion(&cs43130->pll_rdy); init_completion(&cs43130->hpload_evt); ret = devm_request_threaded_irq(&client->dev, client->irq, ret = devm_request_threaded_irq(cs43130->dev, client->irq, NULL, cs43130_irq_thread, IRQF_ONESHOT | IRQF_TRIGGER_LOW, "cs43130", cs43130); if (ret != 0) { dev_err(&client->dev, "Failed to request IRQ: %d\n", ret); dev_err(cs43130->dev, "Failed to request IRQ: %d\n", ret); goto err; } cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO; pm_runtime_set_autosuspend_delay(&client->dev, 100); pm_runtime_use_autosuspend(&client->dev); pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_set_autosuspend_delay(cs43130->dev, 100); pm_runtime_use_autosuspend(cs43130->dev); pm_runtime_set_active(cs43130->dev); pm_runtime_enable(cs43130->dev); switch (cs43130->dev_id) { case CS43130_CHIP_ID: Loading Loading @@ -2556,11 +2560,11 @@ static int cs43130_i2c_probe(struct i2c_client *client) break; } ret = devm_snd_soc_register_component(&client->dev, ret = devm_snd_soc_register_component(cs43130->dev, &soc_component_dev_cs43130, cs43130_dai, ARRAY_SIZE(cs43130_dai)); if (ret < 0) { dev_err(&client->dev, dev_err(cs43130->dev, "snd_soc_register_component failed with ret = %d\n", ret); goto err; } Loading Loading @@ -2598,15 +2602,15 @@ static void cs43130_i2c_remove(struct i2c_client *client) cancel_work_sync(&cs43130->work); flush_workqueue(cs43130->wq); device_remove_file(&client->dev, &dev_attr_hpload_dc_l); device_remove_file(&client->dev, &dev_attr_hpload_dc_r); device_remove_file(&client->dev, &dev_attr_hpload_ac_l); device_remove_file(&client->dev, &dev_attr_hpload_ac_r); device_remove_file(cs43130->dev, &dev_attr_hpload_dc_l); device_remove_file(cs43130->dev, &dev_attr_hpload_dc_r); device_remove_file(cs43130->dev, &dev_attr_hpload_ac_l); device_remove_file(cs43130->dev, &dev_attr_hpload_ac_r); } gpiod_set_value_cansleep(cs43130->reset_gpio, 0); pm_runtime_disable(&client->dev); pm_runtime_disable(cs43130->dev); regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies); } Loading Loading @@ -2669,6 +2673,7 @@ static const struct dev_pm_ops cs43130_runtime_pm = { NULL) }; #if IS_ENABLED(CONFIG_OF) static const struct of_device_id cs43130_of_match[] = { {.compatible = "cirrus,cs43130",}, {.compatible = "cirrus,cs4399",}, Loading @@ -2678,6 +2683,17 @@ static const struct of_device_id cs43130_of_match[] = { }; MODULE_DEVICE_TABLE(of, cs43130_of_match); #endif #if IS_ENABLED(CONFIG_ACPI) static const struct acpi_device_id cs43130_acpi_match[] = { { "CSC4399", 0 }, {} }; MODULE_DEVICE_TABLE(acpi, cs43130_acpi_match); #endif static const struct i2c_device_id cs43130_i2c_id[] = { {"cs43130", 0}, Loading @@ -2692,7 +2708,8 @@ MODULE_DEVICE_TABLE(i2c, cs43130_i2c_id); static struct i2c_driver cs43130_i2c_driver = { .driver = { .name = "cs43130", .of_match_table = cs43130_of_match, .of_match_table = of_match_ptr(cs43130_of_match), .acpi_match_table = ACPI_PTR(cs43130_acpi_match), .pm = &cs43130_runtime_pm, }, .id_table = cs43130_i2c_id, Loading
sound/soc/codecs/cs43130.h +1 −0 Original line number Diff line number Diff line Loading @@ -500,6 +500,7 @@ struct cs43130_dai { }; struct cs43130_private { struct device *dev; struct snd_soc_component *component; struct regmap *regmap; struct regulator_bulk_data supplies[CS43130_NUM_SUPPLIES]; Loading