wm8990.c (9d7548d4ca3c52ecb58f098a32b0756cdf8f96ee) wm8990.c (e5d3fd38f93755c5ab1e04b8e40196135f576355)
1/*
2 * wm8990.c -- WM8990 ALSA Soc Audio driver
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * lg@opensource.wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 1463 unchanged lines hidden (view full) ---

1472#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1473
1474/*
1475 * WM891 2 wire address is determined by GPIO5
1476 * state during powerup.
1477 * low = 0x34
1478 * high = 0x36
1479 */
1/*
2 * wm8990.c -- WM8990 ALSA Soc Audio driver
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * lg@opensource.wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it

--- 1463 unchanged lines hidden (view full) ---

1472#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1473
1474/*
1475 * WM891 2 wire address is determined by GPIO5
1476 * state during powerup.
1477 * low = 0x34
1478 * high = 0x36
1479 */
1480static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
1481
1480
1482/* Magic definition of all other variables and things */
1483I2C_CLIENT_INSMOD;
1484
1485static struct i2c_driver wm8990_i2c_driver;
1486static struct i2c_client client_template;
1487
1488static int wm8990_codec_probe(struct i2c_adapter *adap, int addr, int kind)
1481static int wm8990_i2c_probe(struct i2c_client *i2c,
1482 const struct i2c_device_id *id)
1489{
1490 struct snd_soc_device *socdev = wm8990_socdev;
1483{
1484 struct snd_soc_device *socdev = wm8990_socdev;
1491 struct wm8990_setup_data *setup = socdev->codec_data;
1492 struct snd_soc_codec *codec = socdev->codec;
1485 struct snd_soc_codec *codec = socdev->codec;
1493 struct i2c_client *i2c;
1494 int ret;
1495
1486 int ret;
1487
1496 if (addr != setup->i2c_address)
1497 return -ENODEV;
1498
1499 client_template.adapter = adap;
1500 client_template.addr = addr;
1501
1502 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
1503 if (i2c == NULL)
1504 return -ENOMEM;
1505
1506 i2c_set_clientdata(i2c, codec);
1507 codec->control_data = i2c;
1508
1488 i2c_set_clientdata(i2c, codec);
1489 codec->control_data = i2c;
1490
1509 ret = i2c_attach_client(i2c);
1510 if (ret < 0) {
1511 pr_err("failed to attach codec at addr %x\n", addr);
1512 goto err;
1513 }
1514
1515 ret = wm8990_init(socdev);
1491 ret = wm8990_init(socdev);
1516 if (ret < 0) {
1492 if (ret < 0)
1517 pr_err("failed to initialise WM8990\n");
1493 pr_err("failed to initialise WM8990\n");
1518 goto err;
1519 }
1520 return ret;
1521
1494
1522err:
1523 kfree(i2c);
1524 return ret;
1525}
1526
1495 return ret;
1496}
1497
1527static int wm8990_i2c_detach(struct i2c_client *client)
1498static int wm8990_i2c_remove(struct i2c_client *client)
1528{
1529 struct snd_soc_codec *codec = i2c_get_clientdata(client);
1499{
1500 struct snd_soc_codec *codec = i2c_get_clientdata(client);
1530 i2c_detach_client(client);
1531 kfree(codec->reg_cache);
1501 kfree(codec->reg_cache);
1532 kfree(client);
1533 return 0;
1534}
1535
1502 return 0;
1503}
1504
1536static int wm8990_i2c_attach(struct i2c_adapter *adap)
1537{
1538 return i2c_probe(adap, &addr_data, wm8990_codec_probe);
1539}
1505static const struct i2c_device_id wm8990_i2c_id[] = {
1506 { "wm8990", 0 },
1507 { }
1508};
1509MODULE_DEVICE_TABLE(i2c, wm8990_i2c_id);
1540
1541static struct i2c_driver wm8990_i2c_driver = {
1542 .driver = {
1543 .name = "WM8990 I2C Codec",
1544 .owner = THIS_MODULE,
1545 },
1510
1511static struct i2c_driver wm8990_i2c_driver = {
1512 .driver = {
1513 .name = "WM8990 I2C Codec",
1514 .owner = THIS_MODULE,
1515 },
1546 .attach_adapter = wm8990_i2c_attach,
1547 .detach_client = wm8990_i2c_detach,
1548 .command = NULL,
1516 .probe = wm8990_i2c_probe,
1517 .remove = wm8990_i2c_remove,
1518 .id_table = wm8990_i2c_id,
1549};
1550
1519};
1520
1551static struct i2c_client client_template = {
1552 .name = "WM8990",
1553 .driver = &wm8990_i2c_driver,
1554};
1521static int wm8990_add_i2c_device(struct platform_device *pdev,
1522 const struct wm8990_setup_data *setup)
1523{
1524 struct i2c_board_info info;
1525 struct i2c_adapter *adapter;
1526 struct i2c_client *client;
1527 int ret;
1528
1529 ret = i2c_add_driver(&wm8990_i2c_driver);
1530 if (ret != 0) {
1531 dev_err(&pdev->dev, "can't add i2c driver\n");
1532 return ret;
1533 }
1534
1535 memset(&info, 0, sizeof(struct i2c_board_info));
1536 info.addr = setup->i2c_address;
1537 strlcpy(info.type, "wm8990", I2C_NAME_SIZE);
1538
1539 adapter = i2c_get_adapter(setup->i2c_bus);
1540 if (!adapter) {
1541 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
1542 setup->i2c_bus);
1543 goto err_driver;
1544 }
1545
1546 client = i2c_new_device(adapter, &info);
1547 i2c_put_adapter(adapter);
1548 if (!client) {
1549 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
1550 (unsigned int)info.addr);
1551 goto err_driver;
1552 }
1553
1554 return 0;
1555
1556err_driver:
1557 i2c_del_driver(&wm8990_i2c_driver);
1558 return -ENODEV;
1559}
1555#endif
1556
1557static int wm8990_probe(struct platform_device *pdev)
1558{
1559 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1560 struct wm8990_setup_data *setup;
1561 struct snd_soc_codec *codec;
1562 struct wm8990_priv *wm8990;

--- 16 unchanged lines hidden (view full) ---

1579 socdev->codec = codec;
1580 mutex_init(&codec->mutex);
1581 INIT_LIST_HEAD(&codec->dapm_widgets);
1582 INIT_LIST_HEAD(&codec->dapm_paths);
1583 wm8990_socdev = socdev;
1584
1585#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1586 if (setup->i2c_address) {
1560#endif
1561
1562static int wm8990_probe(struct platform_device *pdev)
1563{
1564 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1565 struct wm8990_setup_data *setup;
1566 struct snd_soc_codec *codec;
1567 struct wm8990_priv *wm8990;

--- 16 unchanged lines hidden (view full) ---

1584 socdev->codec = codec;
1585 mutex_init(&codec->mutex);
1586 INIT_LIST_HEAD(&codec->dapm_widgets);
1587 INIT_LIST_HEAD(&codec->dapm_paths);
1588 wm8990_socdev = socdev;
1589
1590#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1591 if (setup->i2c_address) {
1587 normal_i2c[0] = setup->i2c_address;
1588 codec->hw_write = (hw_write_t)i2c_master_send;
1592 codec->hw_write = (hw_write_t)i2c_master_send;
1589 ret = i2c_add_driver(&wm8990_i2c_driver);
1590 if (ret != 0)
1591 printk(KERN_ERR "can't add i2c driver");
1593 ret = wm8990_add_i2c_device(pdev, setup);
1592 }
1593#else
1594 /* Add other interfaces here */
1595#endif
1596
1597 if (ret != 0) {
1598 kfree(codec->private_data);
1599 kfree(codec);

--- 7 unchanged lines hidden (view full) ---

1607 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1608 struct snd_soc_codec *codec = socdev->codec;
1609
1610 if (codec->control_data)
1611 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1612 snd_soc_free_pcms(socdev);
1613 snd_soc_dapm_free(socdev);
1614#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1594 }
1595#else
1596 /* Add other interfaces here */
1597#endif
1598
1599 if (ret != 0) {
1600 kfree(codec->private_data);
1601 kfree(codec);

--- 7 unchanged lines hidden (view full) ---

1609 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1610 struct snd_soc_codec *codec = socdev->codec;
1611
1612 if (codec->control_data)
1613 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
1614 snd_soc_free_pcms(socdev);
1615 snd_soc_dapm_free(socdev);
1616#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1617 i2c_unregister_device(codec->control_data);
1615 i2c_del_driver(&wm8990_i2c_driver);
1616#endif
1617 kfree(codec->private_data);
1618 kfree(codec);
1619
1620 return 0;
1621}
1622
1623struct snd_soc_codec_device soc_codec_dev_wm8990 = {
1624 .probe = wm8990_probe,
1625 .remove = wm8990_remove,
1626 .suspend = wm8990_suspend,
1627 .resume = wm8990_resume,
1628};
1629EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990);
1630
1631MODULE_DESCRIPTION("ASoC WM8990 driver");
1632MODULE_AUTHOR("Liam Girdwood");
1633MODULE_LICENSE("GPL");
1618 i2c_del_driver(&wm8990_i2c_driver);
1619#endif
1620 kfree(codec->private_data);
1621 kfree(codec);
1622
1623 return 0;
1624}
1625
1626struct snd_soc_codec_device soc_codec_dev_wm8990 = {
1627 .probe = wm8990_probe,
1628 .remove = wm8990_remove,
1629 .suspend = wm8990_suspend,
1630 .resume = wm8990_resume,
1631};
1632EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990);
1633
1634MODULE_DESCRIPTION("ASoC WM8990 driver");
1635MODULE_AUTHOR("Liam Girdwood");
1636MODULE_LICENSE("GPL");