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