diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-10-15 13:58:12 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-10-16 02:50:41 -0400 |
commit | 8ae6a5523f4188dbe2b98a9385f5860df6ee47a3 (patch) | |
tree | 80e3250c018fc7fa46f55e9810fb4d51d4618950 | |
parent | 17be5522f6de1d4920e7d9235bfb0e0c682c6f8f (diff) |
ALSA: ASoC: Convert wm8900 to a new-style i2c driver
Convert the wm8900 codec driver to the new (standard) device driver
binding model.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/soc/codecs/wm8900.c | 113 | ||||
-rw-r--r-- | sound/soc/codecs/wm8900.h | 1 |
2 files changed, 55 insertions, 59 deletions
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index 3b326c9b5586..de016f41e04c 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c | |||
@@ -1387,89 +1387,86 @@ static struct snd_soc_device *wm8900_socdev; | |||
1387 | 1387 | ||
1388 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1388 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1389 | 1389 | ||
1390 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
1391 | |||
1392 | /* Magic definition of all other variables and things */ | ||
1393 | I2C_CLIENT_INSMOD; | ||
1394 | |||
1395 | static struct i2c_driver wm8900_i2c_driver; | ||
1396 | static struct i2c_client client_template; | ||
1397 | |||
1398 | /* If the i2c layer weren't so broken, we could pass this kind of data | 1390 | /* If the i2c layer weren't so broken, we could pass this kind of data |
1399 | around */ | 1391 | around */ |
1400 | static int wm8900_codec_probe(struct i2c_adapter *adap, int addr, int kind) | 1392 | static int wm8900_i2c_probe(struct i2c_client *i2c, |
1393 | const struct i2c_device_id *id) | ||
1401 | { | 1394 | { |
1402 | struct snd_soc_device *socdev = wm8900_socdev; | 1395 | struct snd_soc_device *socdev = wm8900_socdev; |
1403 | struct wm8900_setup_data *setup = socdev->codec_data; | ||
1404 | struct snd_soc_codec *codec = socdev->codec; | 1396 | struct snd_soc_codec *codec = socdev->codec; |
1405 | struct i2c_client *i2c; | ||
1406 | int ret; | 1397 | int ret; |
1407 | 1398 | ||
1408 | if (addr != setup->i2c_address) | ||
1409 | return -ENODEV; | ||
1410 | |||
1411 | dev_err(&adap->dev, "Probe on %x\n", addr); | ||
1412 | |||
1413 | client_template.adapter = adap; | ||
1414 | client_template.addr = addr; | ||
1415 | |||
1416 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
1417 | if (i2c == NULL) { | ||
1418 | kfree(codec); | ||
1419 | return -ENOMEM; | ||
1420 | } | ||
1421 | i2c_set_clientdata(i2c, codec); | 1399 | i2c_set_clientdata(i2c, codec); |
1422 | codec->control_data = i2c; | 1400 | codec->control_data = i2c; |
1423 | 1401 | ||
1424 | ret = i2c_attach_client(i2c); | ||
1425 | if (ret < 0) { | ||
1426 | dev_err(&adap->dev, | ||
1427 | "failed to attach codec at addr %x\n", addr); | ||
1428 | goto err; | ||
1429 | } | ||
1430 | |||
1431 | ret = wm8900_init(socdev); | 1402 | ret = wm8900_init(socdev); |
1432 | if (ret < 0) { | 1403 | if (ret < 0) |
1433 | dev_err(&adap->dev, "failed to initialise WM8900\n"); | 1404 | dev_err(&i2c->dev, "failed to initialise WM8900\n"); |
1434 | goto err; | ||
1435 | } | ||
1436 | return ret; | ||
1437 | |||
1438 | err: | ||
1439 | kfree(codec); | ||
1440 | kfree(i2c); | ||
1441 | return ret; | 1405 | return ret; |
1442 | } | 1406 | } |
1443 | 1407 | ||
1444 | static int wm8900_i2c_detach(struct i2c_client *client) | 1408 | static int wm8900_i2c_remove(struct i2c_client *client) |
1445 | { | 1409 | { |
1446 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 1410 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
1447 | i2c_detach_client(client); | ||
1448 | kfree(codec->reg_cache); | 1411 | kfree(codec->reg_cache); |
1449 | kfree(client); | ||
1450 | return 0; | 1412 | return 0; |
1451 | } | 1413 | } |
1452 | 1414 | ||
1453 | static int wm8900_i2c_attach(struct i2c_adapter *adap) | 1415 | static const struct i2c_device_id wm8900_i2c_id[] = { |
1454 | { | 1416 | { "wm8900", 0 }, |
1455 | return i2c_probe(adap, &addr_data, wm8900_codec_probe); | 1417 | { } |
1456 | } | 1418 | }; |
1419 | MODULE_DEVICE_TABLE(i2c, wm8900_i2c_id); | ||
1457 | 1420 | ||
1458 | /* corgi i2c codec control layer */ | ||
1459 | static struct i2c_driver wm8900_i2c_driver = { | 1421 | static struct i2c_driver wm8900_i2c_driver = { |
1460 | .driver = { | 1422 | .driver = { |
1461 | .name = "WM8900 I2C codec", | 1423 | .name = "WM8900 I2C codec", |
1462 | .owner = THIS_MODULE, | 1424 | .owner = THIS_MODULE, |
1463 | }, | 1425 | }, |
1464 | .attach_adapter = wm8900_i2c_attach, | 1426 | .probe = wm8900_i2c_probe, |
1465 | .detach_client = wm8900_i2c_detach, | 1427 | .remove = wm8900_i2c_remove, |
1466 | .command = NULL, | 1428 | .id_table = wm8900_i2c_id, |
1467 | }; | 1429 | }; |
1468 | 1430 | ||
1469 | static struct i2c_client client_template = { | 1431 | static int wm8900_add_i2c_device(struct platform_device *pdev, |
1470 | .name = "WM8900", | 1432 | const struct wm8900_setup_data *setup) |
1471 | .driver = &wm8900_i2c_driver, | 1433 | { |
1472 | }; | 1434 | struct i2c_board_info info; |
1435 | struct i2c_adapter *adapter; | ||
1436 | struct i2c_client *client; | ||
1437 | int ret; | ||
1438 | |||
1439 | ret = i2c_add_driver(&wm8900_i2c_driver); | ||
1440 | if (ret != 0) { | ||
1441 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
1442 | return ret; | ||
1443 | } | ||
1444 | |||
1445 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
1446 | info.addr = setup->i2c_address; | ||
1447 | strlcpy(info.type, "wm8900", I2C_NAME_SIZE); | ||
1448 | |||
1449 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
1450 | if (!adapter) { | ||
1451 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
1452 | setup->i2c_bus); | ||
1453 | goto err_driver; | ||
1454 | } | ||
1455 | |||
1456 | client = i2c_new_device(adapter, &info); | ||
1457 | i2c_put_adapter(adapter); | ||
1458 | if (!client) { | ||
1459 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
1460 | (unsigned int)info.addr); | ||
1461 | goto err_driver; | ||
1462 | } | ||
1463 | |||
1464 | return 0; | ||
1465 | |||
1466 | err_driver: | ||
1467 | i2c_del_driver(&wm8900_i2c_driver); | ||
1468 | return -ENODEV; | ||
1469 | } | ||
1473 | #endif | 1470 | #endif |
1474 | 1471 | ||
1475 | static int wm8900_probe(struct platform_device *pdev) | 1472 | static int wm8900_probe(struct platform_device *pdev) |
@@ -1497,11 +1494,8 @@ static int wm8900_probe(struct platform_device *pdev) | |||
1497 | wm8900_socdev = socdev; | 1494 | wm8900_socdev = socdev; |
1498 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1495 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1499 | if (setup->i2c_address) { | 1496 | if (setup->i2c_address) { |
1500 | normal_i2c[0] = setup->i2c_address; | ||
1501 | codec->hw_write = (hw_write_t)i2c_master_send; | 1497 | codec->hw_write = (hw_write_t)i2c_master_send; |
1502 | ret = i2c_add_driver(&wm8900_i2c_driver); | 1498 | ret = wm8900_add_i2c_device(pdev, setup); |
1503 | if (ret != 0) | ||
1504 | printk(KERN_ERR "can't add i2c driver"); | ||
1505 | } | 1499 | } |
1506 | #else | 1500 | #else |
1507 | #error Non-I2C interfaces not yet supported | 1501 | #error Non-I2C interfaces not yet supported |
@@ -1521,6 +1515,7 @@ static int wm8900_remove(struct platform_device *pdev) | |||
1521 | snd_soc_free_pcms(socdev); | 1515 | snd_soc_free_pcms(socdev); |
1522 | snd_soc_dapm_free(socdev); | 1516 | snd_soc_dapm_free(socdev); |
1523 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1517 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1518 | i2c_unregister_device(codec->control_data); | ||
1524 | i2c_del_driver(&wm8900_i2c_driver); | 1519 | i2c_del_driver(&wm8900_i2c_driver); |
1525 | #endif | 1520 | #endif |
1526 | kfree(codec); | 1521 | kfree(codec); |
diff --git a/sound/soc/codecs/wm8900.h b/sound/soc/codecs/wm8900.h index ba450d99e902..2249a446ad37 100644 --- a/sound/soc/codecs/wm8900.h +++ b/sound/soc/codecs/wm8900.h | |||
@@ -55,6 +55,7 @@ | |||
55 | #define WM8900_ | 55 | #define WM8900_ |
56 | 56 | ||
57 | struct wm8900_setup_data { | 57 | struct wm8900_setup_data { |
58 | int i2c_bus; | ||
58 | unsigned short i2c_address; | 59 | unsigned short i2c_address; |
59 | }; | 60 | }; |
60 | 61 | ||