diff options
Diffstat (limited to 'sound/soc/codecs/wm8990.c')
-rw-r--r-- | sound/soc/codecs/wm8990.c | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index dd995ef448b4..572d22b0880b 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c | |||
@@ -30,7 +30,6 @@ | |||
30 | 30 | ||
31 | #include "wm8990.h" | 31 | #include "wm8990.h" |
32 | 32 | ||
33 | #define AUDIO_NAME "wm8990" | ||
34 | #define WM8990_VERSION "0.2" | 33 | #define WM8990_VERSION "0.2" |
35 | 34 | ||
36 | /* codec private data */ | 35 | /* codec private data */ |
@@ -1477,81 +1476,86 @@ static struct snd_soc_device *wm8990_socdev; | |||
1477 | * low = 0x34 | 1476 | * low = 0x34 |
1478 | * high = 0x36 | 1477 | * high = 0x36 |
1479 | */ | 1478 | */ |
1480 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
1481 | 1479 | ||
1482 | /* Magic definition of all other variables and things */ | 1480 | static int wm8990_i2c_probe(struct i2c_client *i2c, |
1483 | I2C_CLIENT_INSMOD; | 1481 | const struct i2c_device_id *id) |
1484 | |||
1485 | static struct i2c_driver wm8990_i2c_driver; | ||
1486 | static struct i2c_client client_template; | ||
1487 | |||
1488 | static int wm8990_codec_probe(struct i2c_adapter *adap, int addr, int kind) | ||
1489 | { | 1482 | { |
1490 | struct snd_soc_device *socdev = wm8990_socdev; | 1483 | struct snd_soc_device *socdev = wm8990_socdev; |
1491 | struct wm8990_setup_data *setup = socdev->codec_data; | ||
1492 | struct snd_soc_codec *codec = socdev->codec; | 1484 | struct snd_soc_codec *codec = socdev->codec; |
1493 | struct i2c_client *i2c; | ||
1494 | int ret; | 1485 | int ret; |
1495 | 1486 | ||
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); | 1487 | i2c_set_clientdata(i2c, codec); |
1507 | codec->control_data = i2c; | 1488 | codec->control_data = i2c; |
1508 | 1489 | ||
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); | 1490 | ret = wm8990_init(socdev); |
1516 | if (ret < 0) { | 1491 | if (ret < 0) |
1517 | pr_err("failed to initialise WM8990\n"); | 1492 | pr_err("failed to initialise WM8990\n"); |
1518 | goto err; | ||
1519 | } | ||
1520 | return ret; | ||
1521 | 1493 | ||
1522 | err: | ||
1523 | kfree(i2c); | ||
1524 | return ret; | 1494 | return ret; |
1525 | } | 1495 | } |
1526 | 1496 | ||
1527 | static int wm8990_i2c_detach(struct i2c_client *client) | 1497 | static int wm8990_i2c_remove(struct i2c_client *client) |
1528 | { | 1498 | { |
1529 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 1499 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
1530 | i2c_detach_client(client); | ||
1531 | kfree(codec->reg_cache); | 1500 | kfree(codec->reg_cache); |
1532 | kfree(client); | ||
1533 | return 0; | 1501 | return 0; |
1534 | } | 1502 | } |
1535 | 1503 | ||
1536 | static int wm8990_i2c_attach(struct i2c_adapter *adap) | 1504 | static const struct i2c_device_id wm8990_i2c_id[] = { |
1537 | { | 1505 | { "wm8990", 0 }, |
1538 | return i2c_probe(adap, &addr_data, wm8990_codec_probe); | 1506 | { } |
1539 | } | 1507 | }; |
1508 | MODULE_DEVICE_TABLE(i2c, wm8990_i2c_id); | ||
1540 | 1509 | ||
1541 | static struct i2c_driver wm8990_i2c_driver = { | 1510 | static struct i2c_driver wm8990_i2c_driver = { |
1542 | .driver = { | 1511 | .driver = { |
1543 | .name = "WM8990 I2C Codec", | 1512 | .name = "WM8990 I2C Codec", |
1544 | .owner = THIS_MODULE, | 1513 | .owner = THIS_MODULE, |
1545 | }, | 1514 | }, |
1546 | .attach_adapter = wm8990_i2c_attach, | 1515 | .probe = wm8990_i2c_probe, |
1547 | .detach_client = wm8990_i2c_detach, | 1516 | .remove = wm8990_i2c_remove, |
1548 | .command = NULL, | 1517 | .id_table = wm8990_i2c_id, |
1549 | }; | 1518 | }; |
1550 | 1519 | ||
1551 | static struct i2c_client client_template = { | 1520 | static int wm8990_add_i2c_device(struct platform_device *pdev, |
1552 | .name = "WM8990", | 1521 | const struct wm8990_setup_data *setup) |
1553 | .driver = &wm8990_i2c_driver, | 1522 | { |
1554 | }; | 1523 | struct i2c_board_info info; |
1524 | struct i2c_adapter *adapter; | ||
1525 | struct i2c_client *client; | ||
1526 | int ret; | ||
1527 | |||
1528 | ret = i2c_add_driver(&wm8990_i2c_driver); | ||
1529 | if (ret != 0) { | ||
1530 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
1531 | return ret; | ||
1532 | } | ||
1533 | |||
1534 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
1535 | info.addr = setup->i2c_address; | ||
1536 | strlcpy(info.type, "wm8990", I2C_NAME_SIZE); | ||
1537 | |||
1538 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
1539 | if (!adapter) { | ||
1540 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
1541 | setup->i2c_bus); | ||
1542 | goto err_driver; | ||
1543 | } | ||
1544 | |||
1545 | client = i2c_new_device(adapter, &info); | ||
1546 | i2c_put_adapter(adapter); | ||
1547 | if (!client) { | ||
1548 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
1549 | (unsigned int)info.addr); | ||
1550 | goto err_driver; | ||
1551 | } | ||
1552 | |||
1553 | return 0; | ||
1554 | |||
1555 | err_driver: | ||
1556 | i2c_del_driver(&wm8990_i2c_driver); | ||
1557 | return -ENODEV; | ||
1558 | } | ||
1555 | #endif | 1559 | #endif |
1556 | 1560 | ||
1557 | static int wm8990_probe(struct platform_device *pdev) | 1561 | static int wm8990_probe(struct platform_device *pdev) |
@@ -1560,7 +1564,7 @@ static int wm8990_probe(struct platform_device *pdev) | |||
1560 | struct wm8990_setup_data *setup; | 1564 | struct wm8990_setup_data *setup; |
1561 | struct snd_soc_codec *codec; | 1565 | struct snd_soc_codec *codec; |
1562 | struct wm8990_priv *wm8990; | 1566 | struct wm8990_priv *wm8990; |
1563 | int ret = 0; | 1567 | int ret; |
1564 | 1568 | ||
1565 | pr_info("WM8990 Audio Codec %s\n", WM8990_VERSION); | 1569 | pr_info("WM8990 Audio Codec %s\n", WM8990_VERSION); |
1566 | 1570 | ||
@@ -1582,16 +1586,13 @@ static int wm8990_probe(struct platform_device *pdev) | |||
1582 | INIT_LIST_HEAD(&codec->dapm_paths); | 1586 | INIT_LIST_HEAD(&codec->dapm_paths); |
1583 | wm8990_socdev = socdev; | 1587 | wm8990_socdev = socdev; |
1584 | 1588 | ||
1589 | ret = -ENODEV; | ||
1590 | |||
1585 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1591 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1586 | if (setup->i2c_address) { | 1592 | if (setup->i2c_address) { |
1587 | normal_i2c[0] = setup->i2c_address; | ||
1588 | codec->hw_write = (hw_write_t)i2c_master_send; | 1593 | codec->hw_write = (hw_write_t)i2c_master_send; |
1589 | ret = i2c_add_driver(&wm8990_i2c_driver); | 1594 | ret = wm8990_add_i2c_device(pdev, setup); |
1590 | if (ret != 0) | ||
1591 | printk(KERN_ERR "can't add i2c driver"); | ||
1592 | } | 1595 | } |
1593 | #else | ||
1594 | /* Add other interfaces here */ | ||
1595 | #endif | 1596 | #endif |
1596 | 1597 | ||
1597 | if (ret != 0) { | 1598 | if (ret != 0) { |
@@ -1612,6 +1613,7 @@ static int wm8990_remove(struct platform_device *pdev) | |||
1612 | snd_soc_free_pcms(socdev); | 1613 | snd_soc_free_pcms(socdev); |
1613 | snd_soc_dapm_free(socdev); | 1614 | snd_soc_dapm_free(socdev); |
1614 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1615 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1616 | i2c_unregister_device(codec->control_data); | ||
1615 | i2c_del_driver(&wm8990_i2c_driver); | 1617 | i2c_del_driver(&wm8990_i2c_driver); |
1616 | #endif | 1618 | #endif |
1617 | kfree(codec->private_data); | 1619 | kfree(codec->private_data); |