From d375d0abcd625cd09cd90a252ad22a1085452e3c Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 25 Jun 2015 21:41:43 +0800 Subject: ASoC: cs42xx8: Move the code checking *regmap argument earlier Slightly improve the readability by moving the code checking *regmap argument earlier. Also move the assignment of of_id close to the place testing it. Signed-off-by: Axel Lin Acked-by: Brian Austin Signed-off-by: Mark Brown diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c index e1d4686..ab39514 100644 --- a/sound/soc/codecs/cs42xx8.c +++ b/sound/soc/codecs/cs42xx8.c @@ -435,16 +435,24 @@ EXPORT_SYMBOL_GPL(cs42xx8_of_match); int cs42xx8_probe(struct device *dev, struct regmap *regmap) { - const struct of_device_id *of_id = of_match_device(cs42xx8_of_match, dev); + const struct of_device_id *of_id; struct cs42xx8_priv *cs42xx8; int ret, val, i; + if (IS_ERR(regmap)) { + ret = PTR_ERR(regmap); + dev_err(dev, "failed to allocate regmap: %d\n", ret); + return ret; + } + cs42xx8 = devm_kzalloc(dev, sizeof(*cs42xx8), GFP_KERNEL); if (cs42xx8 == NULL) return -ENOMEM; + cs42xx8->regmap = regmap; dev_set_drvdata(dev, cs42xx8); + of_id = of_match_device(cs42xx8_of_match, dev); if (of_id) cs42xx8->drvdata = of_id->data; @@ -482,13 +490,6 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap) /* Make sure hardware reset done */ msleep(5); - cs42xx8->regmap = regmap; - if (IS_ERR(cs42xx8->regmap)) { - ret = PTR_ERR(cs42xx8->regmap); - dev_err(dev, "failed to allocate regmap: %d\n", ret); - goto err_enable; - } - /* * We haven't marked the chip revision as volatile due to * sharing a register with the right input volume; explicitly -- cgit v0.10.2 From 5e4cb7b60833b0124a9f71dbc5118144ca79c3c4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 25 Jun 2015 21:44:13 +0800 Subject: ASoC: cs42xx8: Setup of_match_table Setup of_match_table and since cs42xx8_of_match is exported and used in cs42xx8-i2c.c, it cannot be static. Signed-off-by: Axel Lin Acked-by: Brian Austin Signed-off-by: Mark Brown diff --git a/sound/soc/codecs/cs42xx8-i2c.c b/sound/soc/codecs/cs42xx8-i2c.c index 657dce2..5a71c9e 100644 --- a/sound/soc/codecs/cs42xx8-i2c.c +++ b/sound/soc/codecs/cs42xx8-i2c.c @@ -20,7 +20,7 @@ static int cs42xx8_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { - u32 ret = cs42xx8_probe(&i2c->dev, + int ret = cs42xx8_probe(&i2c->dev, devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config)); if (ret) return ret; @@ -51,6 +51,7 @@ static struct i2c_driver cs42xx8_i2c_driver = { .name = "cs42xx8", .owner = THIS_MODULE, .pm = &cs42xx8_pm, + .of_match_table = cs42xx8_of_match, }, .probe = cs42xx8_i2c_probe, .remove = cs42xx8_i2c_remove, diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c index ab39514..d562e1b 100644 --- a/sound/soc/codecs/cs42xx8.c +++ b/sound/soc/codecs/cs42xx8.c @@ -425,7 +425,7 @@ const struct cs42xx8_driver_data cs42888_data = { }; EXPORT_SYMBOL_GPL(cs42888_data); -static const struct of_device_id cs42xx8_of_match[] = { +const struct of_device_id cs42xx8_of_match[] = { { .compatible = "cirrus,cs42448", .data = &cs42448_data, }, { .compatible = "cirrus,cs42888", .data = &cs42888_data, }, { /* sentinel */ } diff --git a/sound/soc/codecs/cs42xx8.h b/sound/soc/codecs/cs42xx8.h index b2c10e5..d36c61b 100644 --- a/sound/soc/codecs/cs42xx8.h +++ b/sound/soc/codecs/cs42xx8.h @@ -22,6 +22,7 @@ extern const struct dev_pm_ops cs42xx8_pm; extern const struct cs42xx8_driver_data cs42448_data; extern const struct cs42xx8_driver_data cs42888_data; extern const struct regmap_config cs42xx8_regmap_config; +extern const struct of_device_id cs42xx8_of_match[]; int cs42xx8_probe(struct device *dev, struct regmap *regmap); /* CS42888 register map */ -- cgit v0.10.2 From c4a99a4b4f6ef56e9c8182920680b84a7129ca80 Mon Sep 17 00:00:00 2001 From: "Fang, Yang A" Date: Tue, 7 Jul 2015 14:21:47 -0700 Subject: ASoC: ts3a227e: do not report jack status when there is i2c read err After suspend -> resume the ts3a227e_interrupt sometimes comes before i2c controller resume is called .regmap_read will return incorrect status and report a wrong jack status.This patch will disable irq on suspend and enable irq again on the resume to make sure interrupt is coming after TI resumes. Also We should return if there is read err,the interrupt will come again since it is level triggered and we are not yet clear the interrupt. In addtion,cht_bsw_max98090_ti machine driver registered additional notifier base on jack event which will program the audio codec.there will be codec timeout err if such event occurs prior to i2c controller is resumed. Signed-off-by: Fang, Yang A Signed-off-by: Mark Brown diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c index 12232d7..ffc6f30 100644 --- a/sound/soc/codecs/ts3a227e.c +++ b/sound/soc/codecs/ts3a227e.c @@ -23,11 +23,13 @@ #include "ts3a227e.h" struct ts3a227e { + struct device *dev; struct regmap *regmap; struct snd_soc_jack *jack; bool plugged; bool mic_present; unsigned int buttons_held; + int irq; }; /* Button values to be reported on the jack */ @@ -189,16 +191,28 @@ static irqreturn_t ts3a227e_interrupt(int irq, void *data) struct ts3a227e *ts3a227e = (struct ts3a227e *)data; struct regmap *regmap = ts3a227e->regmap; unsigned int int_reg, kp_int_reg, acc_reg, i; + struct device *dev = ts3a227e->dev; + int ret; /* Check for plug/unplug. */ - regmap_read(regmap, TS3A227E_REG_INTERRUPT, &int_reg); + ret = regmap_read(regmap, TS3A227E_REG_INTERRUPT, &int_reg); + if (ret) { + dev_err(dev, "failed to clear interrupt ret=%d\n", ret); + return IRQ_NONE; + } + if (int_reg & (DETECTION_COMPLETE_EVENT | INS_REM_EVENT)) { regmap_read(regmap, TS3A227E_REG_ACCESSORY_STATUS, &acc_reg); ts3a227e_new_jack_state(ts3a227e, acc_reg); } /* Report any key events. */ - regmap_read(regmap, TS3A227E_REG_KP_INTERRUPT, &kp_int_reg); + ret = regmap_read(regmap, TS3A227E_REG_KP_INTERRUPT, &kp_int_reg); + if (ret) { + dev_err(dev, "failed to clear key interrupt ret=%d\n", ret); + return IRQ_NONE; + } + for (i = 0; i < TS3A227E_NUM_BUTTONS; i++) { if (kp_int_reg & PRESS_MASK(i)) ts3a227e->buttons_held |= (1 << i); @@ -283,6 +297,8 @@ static int ts3a227e_i2c_probe(struct i2c_client *i2c, return -ENOMEM; i2c_set_clientdata(i2c, ts3a227e); + ts3a227e->dev = dev; + ts3a227e->irq = i2c->irq; ts3a227e->regmap = devm_regmap_init_i2c(i2c, &ts3a227e_regmap_config); if (IS_ERR(ts3a227e->regmap)) @@ -320,6 +336,32 @@ static int ts3a227e_i2c_probe(struct i2c_client *i2c, return 0; } +#ifdef CONFIG_PM_SLEEP +static int ts3a227e_suspend(struct device *dev) +{ + struct ts3a227e *ts3a227e = dev_get_drvdata(dev); + + dev_dbg(ts3a227e->dev, "suspend disable irq\n"); + disable_irq(ts3a227e->irq); + + return 0; +} + +static int ts3a227e_resume(struct device *dev) +{ + struct ts3a227e *ts3a227e = dev_get_drvdata(dev); + + dev_dbg(ts3a227e->dev, "resume enable irq\n"); + enable_irq(ts3a227e->irq); + + return 0; +} +#endif + +static const struct dev_pm_ops ts3a227e_pm = { + SET_SYSTEM_SLEEP_PM_OPS(ts3a227e_suspend, ts3a227e_resume) +}; + static const struct i2c_device_id ts3a227e_i2c_ids[] = { { "ts3a227e", 0 }, { } @@ -336,6 +378,7 @@ static struct i2c_driver ts3a227e_driver = { .driver = { .name = "ts3a227e", .owner = THIS_MODULE, + .pm = &ts3a227e_pm, .of_match_table = of_match_ptr(ts3a227e_of_match), }, .probe = ts3a227e_i2c_probe, -- cgit v0.10.2