diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-12-13 23:31:14 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-20 08:58:20 -0500 |
commit | bfea3abb804f5ab97c5da3da7c6386664531d698 (patch) | |
tree | 5372a412482dc02f5c11ed0a11a2ec4a2307257e /sound/soc/codecs/wm8993.c | |
parent | d0ad0af0432f7b4fe439a6a46e7a31f8dd5d3d55 (diff) |
ASoC: Move WM8993 resource acquisition and device reset to bus probe
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8993.c')
-rw-r--r-- | sound/soc/codecs/wm8993.c | 89 |
1 files changed, 49 insertions, 40 deletions
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c index 53213020caf7..e7ae9fda3f5b 100644 --- a/sound/soc/codecs/wm8993.c +++ b/sound/soc/codecs/wm8993.c | |||
@@ -1511,7 +1511,7 @@ static int wm8993_probe(struct snd_soc_codec *codec) | |||
1511 | { | 1511 | { |
1512 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); | 1512 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
1513 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 1513 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
1514 | int ret, i, val; | 1514 | int ret; |
1515 | 1515 | ||
1516 | wm8993->hubs_data.hp_startup_mode = 1; | 1516 | wm8993->hubs_data.hp_startup_mode = 1; |
1517 | wm8993->hubs_data.dcs_codes_l = -2; | 1517 | wm8993->hubs_data.dcs_codes_l = -2; |
@@ -1525,36 +1525,6 @@ static int wm8993_probe(struct snd_soc_codec *codec) | |||
1525 | return ret; | 1525 | return ret; |
1526 | } | 1526 | } |
1527 | 1527 | ||
1528 | for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++) | ||
1529 | wm8993->supplies[i].supply = wm8993_supply_names[i]; | ||
1530 | |||
1531 | ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8993->supplies), | ||
1532 | wm8993->supplies); | ||
1533 | if (ret != 0) { | ||
1534 | dev_err(codec->dev, "Failed to request supplies: %d\n", ret); | ||
1535 | return ret; | ||
1536 | } | ||
1537 | |||
1538 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), | ||
1539 | wm8993->supplies); | ||
1540 | if (ret != 0) { | ||
1541 | dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); | ||
1542 | goto err_get; | ||
1543 | } | ||
1544 | |||
1545 | val = snd_soc_read(codec, WM8993_SOFTWARE_RESET); | ||
1546 | if (val != 0x8993) { | ||
1547 | dev_err(codec->dev, "Invalid ID register value %x\n", val); | ||
1548 | ret = -EINVAL; | ||
1549 | goto err_enable; | ||
1550 | } | ||
1551 | |||
1552 | ret = snd_soc_write(codec, WM8993_SOFTWARE_RESET, 0xffff); | ||
1553 | if (ret != 0) | ||
1554 | goto err_enable; | ||
1555 | |||
1556 | regcache_cache_only(wm8993->regmap, true); | ||
1557 | |||
1558 | /* By default we're using the output mixers */ | 1528 | /* By default we're using the output mixers */ |
1559 | wm8993->class_w_users = 2; | 1529 | wm8993->class_w_users = 2; |
1560 | 1530 | ||
@@ -1583,7 +1553,7 @@ static int wm8993_probe(struct snd_soc_codec *codec) | |||
1583 | 1553 | ||
1584 | ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1554 | ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1585 | if (ret != 0) | 1555 | if (ret != 0) |
1586 | goto err_enable; | 1556 | return ret; |
1587 | 1557 | ||
1588 | snd_soc_add_controls(codec, wm8993_snd_controls, | 1558 | snd_soc_add_controls(codec, wm8993_snd_controls, |
1589 | ARRAY_SIZE(wm8993_snd_controls)); | 1559 | ARRAY_SIZE(wm8993_snd_controls)); |
@@ -1605,11 +1575,6 @@ static int wm8993_probe(struct snd_soc_codec *codec) | |||
1605 | 1575 | ||
1606 | return 0; | 1576 | return 0; |
1607 | 1577 | ||
1608 | err_enable: | ||
1609 | regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1610 | err_get: | ||
1611 | regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1612 | return ret; | ||
1613 | } | 1578 | } |
1614 | 1579 | ||
1615 | static int wm8993_remove(struct snd_soc_codec *codec) | 1580 | static int wm8993_remove(struct snd_soc_codec *codec) |
@@ -1698,7 +1663,8 @@ static __devinit int wm8993_i2c_probe(struct i2c_client *i2c, | |||
1698 | const struct i2c_device_id *id) | 1663 | const struct i2c_device_id *id) |
1699 | { | 1664 | { |
1700 | struct wm8993_priv *wm8993; | 1665 | struct wm8993_priv *wm8993; |
1701 | int ret; | 1666 | unsigned int reg; |
1667 | int ret, i; | ||
1702 | 1668 | ||
1703 | wm8993 = devm_kzalloc(&i2c->dev, sizeof(struct wm8993_priv), | 1669 | wm8993 = devm_kzalloc(&i2c->dev, sizeof(struct wm8993_priv), |
1704 | GFP_KERNEL); | 1670 | GFP_KERNEL); |
@@ -1714,15 +1680,56 @@ static __devinit int wm8993_i2c_probe(struct i2c_client *i2c, | |||
1714 | 1680 | ||
1715 | i2c_set_clientdata(i2c, wm8993); | 1681 | i2c_set_clientdata(i2c, wm8993); |
1716 | 1682 | ||
1683 | for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++) | ||
1684 | wm8993->supplies[i].supply = wm8993_supply_names[i]; | ||
1685 | |||
1686 | ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8993->supplies), | ||
1687 | wm8993->supplies); | ||
1688 | if (ret != 0) { | ||
1689 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); | ||
1690 | goto err; | ||
1691 | } | ||
1692 | |||
1693 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), | ||
1694 | wm8993->supplies); | ||
1695 | if (ret != 0) { | ||
1696 | dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); | ||
1697 | goto err_get; | ||
1698 | } | ||
1699 | |||
1700 | ret = regmap_read(wm8993->regmap, WM8993_SOFTWARE_RESET, ®); | ||
1701 | if (ret != 0) { | ||
1702 | dev_err(&i2c->dev, "Failed to read chip ID: %d\n", ret); | ||
1703 | goto err_enable; | ||
1704 | } | ||
1705 | |||
1706 | if (reg != 0x8993) { | ||
1707 | dev_err(&i2c->dev, "Invalid ID register value %x\n", reg); | ||
1708 | ret = -EINVAL; | ||
1709 | goto err_enable; | ||
1710 | } | ||
1711 | |||
1712 | ret = regmap_write(wm8993->regmap, WM8993_SOFTWARE_RESET, 0xffff); | ||
1713 | if (ret != 0) | ||
1714 | goto err_enable; | ||
1715 | |||
1716 | regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1717 | |||
1718 | regcache_cache_only(wm8993->regmap, true); | ||
1719 | |||
1717 | ret = snd_soc_register_codec(&i2c->dev, | 1720 | ret = snd_soc_register_codec(&i2c->dev, |
1718 | &soc_codec_dev_wm8993, &wm8993_dai, 1); | 1721 | &soc_codec_dev_wm8993, &wm8993_dai, 1); |
1719 | if (ret != 0) { | 1722 | if (ret != 0) { |
1720 | dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); | 1723 | dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); |
1721 | goto err; | 1724 | goto err_enable; |
1722 | } | 1725 | } |
1723 | 1726 | ||
1724 | return ret; | 1727 | return 0; |
1725 | 1728 | ||
1729 | err_enable: | ||
1730 | regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1731 | err_get: | ||
1732 | regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1726 | err: | 1733 | err: |
1727 | regmap_exit(wm8993->regmap); | 1734 | regmap_exit(wm8993->regmap); |
1728 | return ret; | 1735 | return ret; |
@@ -1734,6 +1741,8 @@ static __devexit int wm8993_i2c_remove(struct i2c_client *client) | |||
1734 | 1741 | ||
1735 | snd_soc_unregister_codec(&client->dev); | 1742 | snd_soc_unregister_codec(&client->dev); |
1736 | regmap_exit(wm8993->regmap); | 1743 | regmap_exit(wm8993->regmap); |
1744 | regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1745 | regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); | ||
1737 | 1746 | ||
1738 | return 0; | 1747 | return 0; |
1739 | } | 1748 | } |