aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/uda1380.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/uda1380.c')
-rw-r--r--sound/soc/codecs/uda1380.c115
1 files changed, 56 insertions, 59 deletions
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 807318fbdc8f..d206d7f892b6 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -701,87 +701,86 @@ static struct snd_soc_device *uda1380_socdev;
701 701
702#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 702#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
703 703
704#define I2C_DRIVERID_UDA1380 0xfefe /* liam - need a proper id */ 704static int uda1380_i2c_probe(struct i2c_client *i2c,
705 705 const struct i2c_device_id *id)
706static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
707
708/* Magic definition of all other variables and things */
709I2C_CLIENT_INSMOD;
710
711static struct i2c_driver uda1380_i2c_driver;
712static struct i2c_client client_template;
713
714/* If the i2c layer weren't so broken, we could pass this kind of data
715 around */
716
717static int uda1380_codec_probe(struct i2c_adapter *adap, int addr, int kind)
718{ 706{
719 struct snd_soc_device *socdev = uda1380_socdev; 707 struct snd_soc_device *socdev = uda1380_socdev;
720 struct uda1380_setup_data *setup = socdev->codec_data; 708 struct uda1380_setup_data *setup = socdev->codec_data;
721 struct snd_soc_codec *codec = socdev->codec; 709 struct snd_soc_codec *codec = socdev->codec;
722 struct i2c_client *i2c;
723 int ret; 710 int ret;
724 711
725 if (addr != setup->i2c_address)
726 return -ENODEV;
727
728 client_template.adapter = adap;
729 client_template.addr = addr;
730
731 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
732 if (i2c == NULL)
733 return -ENOMEM;
734
735 i2c_set_clientdata(i2c, codec); 712 i2c_set_clientdata(i2c, codec);
736 codec->control_data = i2c; 713 codec->control_data = i2c;
737 714
738 ret = i2c_attach_client(i2c);
739 if (ret < 0) {
740 pr_err("uda1380: failed to attach codec at addr %x\n", addr);
741 goto err;
742 }
743
744 ret = uda1380_init(socdev, setup->dac_clk); 715 ret = uda1380_init(socdev, setup->dac_clk);
745 if (ret < 0) { 716 if (ret < 0)
746 pr_err("uda1380: failed to initialise UDA1380\n"); 717 pr_err("uda1380: failed to initialise UDA1380\n");
747 goto err;
748 }
749 return ret;
750 718
751err:
752 kfree(i2c);
753 return ret; 719 return ret;
754} 720}
755 721
756static int uda1380_i2c_detach(struct i2c_client *client) 722static int uda1380_i2c_remove(struct i2c_client *client)
757{ 723{
758 struct snd_soc_codec *codec = i2c_get_clientdata(client); 724 struct snd_soc_codec *codec = i2c_get_clientdata(client);
759 i2c_detach_client(client);
760 kfree(codec->reg_cache); 725 kfree(codec->reg_cache);
761 kfree(client);
762 return 0; 726 return 0;
763} 727}
764 728
765static int uda1380_i2c_attach(struct i2c_adapter *adap) 729static const struct i2c_device_id uda1380_i2c_id[] = {
766{ 730 { "uda1380", 0 },
767 return i2c_probe(adap, &addr_data, uda1380_codec_probe); 731 { }
768} 732};
733MODULE_DEVICE_TABLE(i2c, uda1380_i2c_id);
769 734
770static struct i2c_driver uda1380_i2c_driver = { 735static struct i2c_driver uda1380_i2c_driver = {
771 .driver = { 736 .driver = {
772 .name = "UDA1380 I2C Codec", 737 .name = "UDA1380 I2C Codec",
773 .owner = THIS_MODULE, 738 .owner = THIS_MODULE,
774 }, 739 },
775 .id = I2C_DRIVERID_UDA1380, 740 .probe = uda1380_i2c_probe,
776 .attach_adapter = uda1380_i2c_attach, 741 .remove = uda1380_i2c_remove,
777 .detach_client = uda1380_i2c_detach, 742 .id_table = uda1380_i2c_id,
778 .command = NULL,
779}; 743};
780 744
781static struct i2c_client client_template = { 745static int uda1380_add_i2c_device(struct platform_device *pdev,
782 .name = "UDA1380", 746 const struct uda1380_setup_data *setup)
783 .driver = &uda1380_i2c_driver, 747{
784}; 748 struct i2c_board_info info;
749 struct i2c_adapter *adapter;
750 struct i2c_client *client;
751 int ret;
752
753 ret = i2c_add_driver(&uda1380_i2c_driver);
754 if (ret != 0) {
755 dev_err(&pdev->dev, "can't add i2c driver\n");
756 return ret;
757 }
758
759 memset(&info, 0, sizeof(struct i2c_board_info));
760 info.addr = setup->i2c_address;
761 strlcpy(info.type, "uda1380", I2C_NAME_SIZE);
762
763 adapter = i2c_get_adapter(setup->i2c_bus);
764 if (!adapter) {
765 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
766 setup->i2c_bus);
767 goto err_driver;
768 }
769
770 client = i2c_new_device(adapter, &info);
771 i2c_put_adapter(adapter);
772 if (!client) {
773 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
774 (unsigned int)info.addr);
775 goto err_driver;
776 }
777
778 return 0;
779
780err_driver:
781 i2c_del_driver(&uda1380_i2c_driver);
782 return -ENODEV;
783}
785#endif 784#endif
786 785
787static int uda1380_probe(struct platform_device *pdev) 786static int uda1380_probe(struct platform_device *pdev)
@@ -789,7 +788,7 @@ static int uda1380_probe(struct platform_device *pdev)
789 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 788 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
790 struct uda1380_setup_data *setup; 789 struct uda1380_setup_data *setup;
791 struct snd_soc_codec *codec; 790 struct snd_soc_codec *codec;
792 int ret = 0; 791 int ret;
793 792
794 pr_info("UDA1380 Audio Codec %s", UDA1380_VERSION); 793 pr_info("UDA1380 Audio Codec %s", UDA1380_VERSION);
795 794
@@ -804,16 +803,13 @@ static int uda1380_probe(struct platform_device *pdev)
804 INIT_LIST_HEAD(&codec->dapm_paths); 803 INIT_LIST_HEAD(&codec->dapm_paths);
805 804
806 uda1380_socdev = socdev; 805 uda1380_socdev = socdev;
806 ret = -ENODEV;
807
807#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 808#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
808 if (setup->i2c_address) { 809 if (setup->i2c_address) {
809 normal_i2c[0] = setup->i2c_address;
810 codec->hw_write = (hw_write_t)i2c_master_send; 810 codec->hw_write = (hw_write_t)i2c_master_send;
811 ret = i2c_add_driver(&uda1380_i2c_driver); 811 ret = uda1380_add_i2c_device(pdev, setup);
812 if (ret != 0)
813 printk(KERN_ERR "can't add i2c driver");
814 } 812 }
815#else
816 /* Add other interfaces here */
817#endif 813#endif
818 814
819 if (ret != 0) 815 if (ret != 0)
@@ -833,6 +829,7 @@ static int uda1380_remove(struct platform_device *pdev)
833 snd_soc_free_pcms(socdev); 829 snd_soc_free_pcms(socdev);
834 snd_soc_dapm_free(socdev); 830 snd_soc_dapm_free(socdev);
835#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 831#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
832 i2c_unregister_device(codec->control_data);
836 i2c_del_driver(&uda1380_i2c_driver); 833 i2c_del_driver(&uda1380_i2c_driver);
837#endif 834#endif
838 kfree(codec); 835 kfree(codec);