aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-09-01 11:45:34 -0400
committerJaroslav Kysela <perex@perex.cz>2008-09-09 03:11:10 -0400
commitad4503d8a0636ddae8175bd05b652264c4260e96 (patch)
tree6be9d28d549feef6e75a538b26977c1b36732014 /sound/soc/codecs
parentd280289e799dcdf5913e8935bffe136d7594e26d (diff)
sound: ASoC: Convert wm8753 to a new-style i2c driver
Convert the wm8753 codec driver to the new (standard) i2c device driver binding model. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Ville Syrjala <syrjala@sci.fi> Cc: Frank Mandarino <fmandarino@endrelia.com> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/wm8753.c106
-rw-r--r--sound/soc/codecs/wm8753.h1
2 files changed, 54 insertions, 53 deletions
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index e873414840c8..8c4df44f3345 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -1637,84 +1637,86 @@ static struct snd_soc_device *wm8753_socdev;
1637 * low = 0x1a 1637 * low = 0x1a
1638 * high = 0x1b 1638 * high = 0x1b
1639 */ 1639 */
1640static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
1641 1640
1642/* Magic definition of all other variables and things */ 1641static int wm8753_i2c_probe(struct i2c_client *i2c,
1643I2C_CLIENT_INSMOD; 1642 const struct i2c_device_id *id)
1644
1645static struct i2c_driver wm8753_i2c_driver;
1646static struct i2c_client client_template;
1647
1648static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
1649{ 1643{
1650 struct snd_soc_device *socdev = wm8753_socdev; 1644 struct snd_soc_device *socdev = wm8753_socdev;
1651 struct wm8753_setup_data *setup = socdev->codec_data;
1652 struct snd_soc_codec *codec = socdev->codec; 1645 struct snd_soc_codec *codec = socdev->codec;
1653 struct i2c_client *i2c;
1654 int ret; 1646 int ret;
1655 1647
1656 if (addr != setup->i2c_address)
1657 return -ENODEV;
1658
1659 client_template.adapter = adap;
1660 client_template.addr = addr;
1661
1662 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
1663 if (!i2c)
1664 return -ENOMEM;
1665
1666 i2c_set_clientdata(i2c, codec); 1648 i2c_set_clientdata(i2c, codec);
1667 codec->control_data = i2c; 1649 codec->control_data = i2c;
1668 1650
1669 ret = i2c_attach_client(i2c);
1670 if (ret < 0) {
1671 pr_err("failed to attach codec at addr %x\n", addr);
1672 goto err;
1673 }
1674
1675 ret = wm8753_init(socdev); 1651 ret = wm8753_init(socdev);
1676 if (ret < 0) { 1652 if (ret < 0)
1677 pr_err("failed to initialise WM8753\n"); 1653 pr_err("failed to initialise WM8753\n");
1678 goto err;
1679 }
1680
1681 return ret;
1682 1654
1683err:
1684 kfree(i2c);
1685 return ret; 1655 return ret;
1686} 1656}
1687 1657
1688static int wm8753_i2c_detach(struct i2c_client *client) 1658static int wm8753_i2c_remove(struct i2c_client *client)
1689{ 1659{
1690 struct snd_soc_codec *codec = i2c_get_clientdata(client); 1660 struct snd_soc_codec *codec = i2c_get_clientdata(client);
1691 i2c_detach_client(client);
1692 kfree(codec->reg_cache); 1661 kfree(codec->reg_cache);
1693 kfree(client);
1694 return 0; 1662 return 0;
1695} 1663}
1696 1664
1697static int wm8753_i2c_attach(struct i2c_adapter *adap) 1665static const struct i2c_device_id wm8753_i2c_id[] = {
1698{ 1666 { "wm8753", 0 },
1699 return i2c_probe(adap, &addr_data, wm8753_codec_probe); 1667 { }
1700} 1668};
1669MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
1701 1670
1702/* corgi i2c codec control layer */
1703static struct i2c_driver wm8753_i2c_driver = { 1671static struct i2c_driver wm8753_i2c_driver = {
1704 .driver = { 1672 .driver = {
1705 .name = "WM8753 I2C Codec", 1673 .name = "WM8753 I2C Codec",
1706 .owner = THIS_MODULE, 1674 .owner = THIS_MODULE,
1707 }, 1675 },
1708 .id = I2C_DRIVERID_WM8753, 1676 .probe = wm8753_i2c_probe,
1709 .attach_adapter = wm8753_i2c_attach, 1677 .remove = wm8753_i2c_remove,
1710 .detach_client = wm8753_i2c_detach, 1678 .id_table = wm8753_i2c_id,
1711 .command = NULL,
1712}; 1679};
1713 1680
1714static struct i2c_client client_template = { 1681static int wm8753_add_i2c_device(struct platform_device *pdev,
1715 .name = "WM8753", 1682 const struct wm8753_setup_data *setup)
1716 .driver = &wm8753_i2c_driver, 1683{
1717}; 1684 struct i2c_board_info info;
1685 struct i2c_adapter *adapter;
1686 struct i2c_client *client;
1687 int ret;
1688
1689 ret = i2c_add_driver(&wm8753_i2c_driver);
1690 if (ret != 0) {
1691 dev_err(&pdev->dev, "can't add i2c driver\n");
1692 return ret;
1693 }
1694
1695 memset(&info, 0, sizeof(struct i2c_board_info));
1696 info.addr = setup->i2c_address;
1697 strlcpy(info.type, "wm8753", I2C_NAME_SIZE);
1698
1699 adapter = i2c_get_adapter(setup->i2c_bus);
1700 if (!adapter) {
1701 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
1702 setup->i2c_bus);
1703 goto err_driver;
1704 }
1705
1706 client = i2c_new_device(adapter, &info);
1707 i2c_put_adapter(adapter);
1708 if (!client) {
1709 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
1710 (unsigned int)info.addr);
1711 goto err_driver;
1712 }
1713
1714 return 0;
1715
1716err_driver:
1717 i2c_del_driver(&wm8753_i2c_driver);
1718 return -ENODEV;
1719}
1718#endif 1720#endif
1719 1721
1720static int wm8753_probe(struct platform_device *pdev) 1722static int wm8753_probe(struct platform_device *pdev)
@@ -1748,11 +1750,8 @@ static int wm8753_probe(struct platform_device *pdev)
1748 1750
1749#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1751#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1750 if (setup->i2c_address) { 1752 if (setup->i2c_address) {
1751 normal_i2c[0] = setup->i2c_address;
1752 codec->hw_write = (hw_write_t)i2c_master_send; 1753 codec->hw_write = (hw_write_t)i2c_master_send;
1753 ret = i2c_add_driver(&wm8753_i2c_driver); 1754 ret = wm8753_add_i2c_device(pdev, setup);
1754 if (ret != 0)
1755 printk(KERN_ERR "can't add i2c driver");
1756 } 1755 }
1757#else 1756#else
1758 /* Add other interfaces here */ 1757 /* Add other interfaces here */
@@ -1796,6 +1795,7 @@ static int wm8753_remove(struct platform_device *pdev)
1796 snd_soc_free_pcms(socdev); 1795 snd_soc_free_pcms(socdev);
1797 snd_soc_dapm_free(socdev); 1796 snd_soc_dapm_free(socdev);
1798#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1797#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1798 i2c_unregister_device(codec->control_data);
1799 i2c_del_driver(&wm8753_i2c_driver); 1799 i2c_del_driver(&wm8753_i2c_driver);
1800#endif 1800#endif
1801 kfree(codec->private_data); 1801 kfree(codec->private_data);
diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h
index 44f5f1ff0cc7..7defde069f1d 100644
--- a/sound/soc/codecs/wm8753.h
+++ b/sound/soc/codecs/wm8753.h
@@ -79,6 +79,7 @@
79#define WM8753_ADCTL2 0x3f 79#define WM8753_ADCTL2 0x3f
80 80
81struct wm8753_setup_data { 81struct wm8753_setup_data {
82 int i2c_bus;
82 unsigned short i2c_address; 83 unsigned short i2c_address;
83}; 84};
84 85