diff options
Diffstat (limited to 'sound/soc/codecs/ak4535.c')
-rw-r--r-- | sound/soc/codecs/ak4535.c | 117 |
1 files changed, 56 insertions, 61 deletions
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index 7da9f467b7b8..2a89b5888e11 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c | |||
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | #include "ak4535.h" | 29 | #include "ak4535.h" |
30 | 30 | ||
31 | #define AUDIO_NAME "ak4535" | ||
32 | #define AK4535_VERSION "0.3" | 31 | #define AK4535_VERSION "0.3" |
33 | 32 | ||
34 | struct snd_soc_codec_device soc_codec_dev_ak4535; | 33 | struct snd_soc_codec_device soc_codec_dev_ak4535; |
@@ -535,87 +534,85 @@ static struct snd_soc_device *ak4535_socdev; | |||
535 | 534 | ||
536 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 535 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
537 | 536 | ||
538 | #define I2C_DRIVERID_AK4535 0xfefe /* liam - need a proper id */ | 537 | static int ak4535_i2c_probe(struct i2c_client *i2c, |
539 | 538 | const struct i2c_device_id *id) | |
540 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
541 | |||
542 | /* Magic definition of all other variables and things */ | ||
543 | I2C_CLIENT_INSMOD; | ||
544 | |||
545 | static struct i2c_driver ak4535_i2c_driver; | ||
546 | static struct i2c_client client_template; | ||
547 | |||
548 | /* If the i2c layer weren't so broken, we could pass this kind of data | ||
549 | around */ | ||
550 | static int ak4535_codec_probe(struct i2c_adapter *adap, int addr, int kind) | ||
551 | { | 539 | { |
552 | struct snd_soc_device *socdev = ak4535_socdev; | 540 | struct snd_soc_device *socdev = ak4535_socdev; |
553 | struct ak4535_setup_data *setup = socdev->codec_data; | ||
554 | struct snd_soc_codec *codec = socdev->codec; | 541 | struct snd_soc_codec *codec = socdev->codec; |
555 | struct i2c_client *i2c; | ||
556 | int ret; | 542 | int ret; |
557 | 543 | ||
558 | if (addr != setup->i2c_address) | ||
559 | return -ENODEV; | ||
560 | |||
561 | client_template.adapter = adap; | ||
562 | client_template.addr = addr; | ||
563 | |||
564 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
565 | if (i2c == NULL) | ||
566 | return -ENOMEM; | ||
567 | |||
568 | i2c_set_clientdata(i2c, codec); | 544 | i2c_set_clientdata(i2c, codec); |
569 | codec->control_data = i2c; | 545 | codec->control_data = i2c; |
570 | 546 | ||
571 | ret = i2c_attach_client(i2c); | ||
572 | if (ret < 0) { | ||
573 | printk(KERN_ERR "failed to attach codec at addr %x\n", addr); | ||
574 | goto err; | ||
575 | } | ||
576 | |||
577 | ret = ak4535_init(socdev); | 547 | ret = ak4535_init(socdev); |
578 | if (ret < 0) { | 548 | if (ret < 0) |
579 | printk(KERN_ERR "failed to initialise AK4535\n"); | 549 | printk(KERN_ERR "failed to initialise AK4535\n"); |
580 | goto err; | ||
581 | } | ||
582 | return ret; | ||
583 | 550 | ||
584 | err: | ||
585 | kfree(i2c); | ||
586 | return ret; | 551 | return ret; |
587 | } | 552 | } |
588 | 553 | ||
589 | static int ak4535_i2c_detach(struct i2c_client *client) | 554 | static int ak4535_i2c_remove(struct i2c_client *client) |
590 | { | 555 | { |
591 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 556 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
592 | i2c_detach_client(client); | ||
593 | kfree(codec->reg_cache); | 557 | kfree(codec->reg_cache); |
594 | kfree(client); | ||
595 | return 0; | 558 | return 0; |
596 | } | 559 | } |
597 | 560 | ||
598 | static int ak4535_i2c_attach(struct i2c_adapter *adap) | 561 | static const struct i2c_device_id ak4535_i2c_id[] = { |
599 | { | 562 | { "ak4535", 0 }, |
600 | return i2c_probe(adap, &addr_data, ak4535_codec_probe); | 563 | { } |
601 | } | 564 | }; |
565 | MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id); | ||
602 | 566 | ||
603 | /* corgi i2c codec control layer */ | ||
604 | static struct i2c_driver ak4535_i2c_driver = { | 567 | static struct i2c_driver ak4535_i2c_driver = { |
605 | .driver = { | 568 | .driver = { |
606 | .name = "AK4535 I2C Codec", | 569 | .name = "AK4535 I2C Codec", |
607 | .owner = THIS_MODULE, | 570 | .owner = THIS_MODULE, |
608 | }, | 571 | }, |
609 | .id = I2C_DRIVERID_AK4535, | 572 | .probe = ak4535_i2c_probe, |
610 | .attach_adapter = ak4535_i2c_attach, | 573 | .remove = ak4535_i2c_remove, |
611 | .detach_client = ak4535_i2c_detach, | 574 | .id_table = ak4535_i2c_id, |
612 | .command = NULL, | ||
613 | }; | 575 | }; |
614 | 576 | ||
615 | static struct i2c_client client_template = { | 577 | static int ak4535_add_i2c_device(struct platform_device *pdev, |
616 | .name = "AK4535", | 578 | const struct ak4535_setup_data *setup) |
617 | .driver = &ak4535_i2c_driver, | 579 | { |
618 | }; | 580 | struct i2c_board_info info; |
581 | struct i2c_adapter *adapter; | ||
582 | struct i2c_client *client; | ||
583 | int ret; | ||
584 | |||
585 | ret = i2c_add_driver(&ak4535_i2c_driver); | ||
586 | if (ret != 0) { | ||
587 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
588 | return ret; | ||
589 | } | ||
590 | |||
591 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
592 | info.addr = setup->i2c_address; | ||
593 | strlcpy(info.type, "ak4535", I2C_NAME_SIZE); | ||
594 | |||
595 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
596 | if (!adapter) { | ||
597 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
598 | setup->i2c_bus); | ||
599 | goto err_driver; | ||
600 | } | ||
601 | |||
602 | client = i2c_new_device(adapter, &info); | ||
603 | i2c_put_adapter(adapter); | ||
604 | if (!client) { | ||
605 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
606 | (unsigned int)info.addr); | ||
607 | goto err_driver; | ||
608 | } | ||
609 | |||
610 | return 0; | ||
611 | |||
612 | err_driver: | ||
613 | i2c_del_driver(&ak4535_i2c_driver); | ||
614 | return -ENODEV; | ||
615 | } | ||
619 | #endif | 616 | #endif |
620 | 617 | ||
621 | static int ak4535_probe(struct platform_device *pdev) | 618 | static int ak4535_probe(struct platform_device *pdev) |
@@ -624,7 +621,7 @@ static int ak4535_probe(struct platform_device *pdev) | |||
624 | struct ak4535_setup_data *setup; | 621 | struct ak4535_setup_data *setup; |
625 | struct snd_soc_codec *codec; | 622 | struct snd_soc_codec *codec; |
626 | struct ak4535_priv *ak4535; | 623 | struct ak4535_priv *ak4535; |
627 | int ret = 0; | 624 | int ret; |
628 | 625 | ||
629 | printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); | 626 | printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); |
630 | 627 | ||
@@ -646,17 +643,14 @@ static int ak4535_probe(struct platform_device *pdev) | |||
646 | INIT_LIST_HEAD(&codec->dapm_paths); | 643 | INIT_LIST_HEAD(&codec->dapm_paths); |
647 | 644 | ||
648 | ak4535_socdev = socdev; | 645 | ak4535_socdev = socdev; |
646 | ret = -ENODEV; | ||
647 | |||
649 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 648 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
650 | if (setup->i2c_address) { | 649 | if (setup->i2c_address) { |
651 | normal_i2c[0] = setup->i2c_address; | ||
652 | codec->hw_write = (hw_write_t)i2c_master_send; | 650 | codec->hw_write = (hw_write_t)i2c_master_send; |
653 | codec->hw_read = (hw_read_t)i2c_master_recv; | 651 | codec->hw_read = (hw_read_t)i2c_master_recv; |
654 | ret = i2c_add_driver(&ak4535_i2c_driver); | 652 | ret = ak4535_add_i2c_device(pdev, setup); |
655 | if (ret != 0) | ||
656 | printk(KERN_ERR "can't add i2c driver"); | ||
657 | } | 653 | } |
658 | #else | ||
659 | /* Add other interfaces here */ | ||
660 | #endif | 654 | #endif |
661 | 655 | ||
662 | if (ret != 0) { | 656 | if (ret != 0) { |
@@ -678,6 +672,7 @@ static int ak4535_remove(struct platform_device *pdev) | |||
678 | snd_soc_free_pcms(socdev); | 672 | snd_soc_free_pcms(socdev); |
679 | snd_soc_dapm_free(socdev); | 673 | snd_soc_dapm_free(socdev); |
680 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 674 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
675 | i2c_unregister_device(codec->control_data); | ||
681 | i2c_del_driver(&ak4535_i2c_driver); | 676 | i2c_del_driver(&ak4535_i2c_driver); |
682 | #endif | 677 | #endif |
683 | kfree(codec->private_data); | 678 | kfree(codec->private_data); |