diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-09-01 13:46:58 -0400 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-09-04 04:34:20 -0400 |
commit | 88fc39d721c3e5d32fd57d682b80fe0626379efb (patch) | |
tree | 3fa6fbad7e4f93abb05153db58a3bbc1226f51e7 /sound/soc | |
parent | 7f9e9d761486e969af553bc352598c348ae7e51e (diff) |
ALSA: ASoC: Convert uda1380 to a new-style i2c driver
Convert the uda1380 codec driver to the new (standard) device driver
binding model.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/soc')
-rw-r--r-- | sound/soc/codecs/uda1380.c | 109 | ||||
-rw-r--r-- | sound/soc/codecs/uda1380.h | 1 |
2 files changed, 54 insertions, 56 deletions
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c index 807318fbdc8f..f0c80436b975 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 */ | 704 | static int uda1380_i2c_probe(struct i2c_client *i2c, |
705 | 705 | const struct i2c_device_id *id) | |
706 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
707 | |||
708 | /* Magic definition of all other variables and things */ | ||
709 | I2C_CLIENT_INSMOD; | ||
710 | |||
711 | static struct i2c_driver uda1380_i2c_driver; | ||
712 | static 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 | |||
717 | static 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 | ||
751 | err: | ||
752 | kfree(i2c); | ||
753 | return ret; | 719 | return ret; |
754 | } | 720 | } |
755 | 721 | ||
756 | static int uda1380_i2c_detach(struct i2c_client *client) | 722 | static 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 | ||
765 | static int uda1380_i2c_attach(struct i2c_adapter *adap) | 729 | static 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 | }; |
733 | MODULE_DEVICE_TABLE(i2c, uda1380_i2c_id); | ||
769 | 734 | ||
770 | static struct i2c_driver uda1380_i2c_driver = { | 735 | static 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 | ||
781 | static struct i2c_client client_template = { | 745 | static 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 | |||
780 | err_driver: | ||
781 | i2c_del_driver(&uda1380_i2c_driver); | ||
782 | return -ENODEV; | ||
783 | } | ||
785 | #endif | 784 | #endif |
786 | 785 | ||
787 | static int uda1380_probe(struct platform_device *pdev) | 786 | static int uda1380_probe(struct platform_device *pdev) |
@@ -806,11 +805,8 @@ static int uda1380_probe(struct platform_device *pdev) | |||
806 | uda1380_socdev = socdev; | 805 | uda1380_socdev = socdev; |
807 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 806 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
808 | if (setup->i2c_address) { | 807 | if (setup->i2c_address) { |
809 | normal_i2c[0] = setup->i2c_address; | ||
810 | codec->hw_write = (hw_write_t)i2c_master_send; | 808 | codec->hw_write = (hw_write_t)i2c_master_send; |
811 | ret = i2c_add_driver(&uda1380_i2c_driver); | 809 | ret = uda1380_add_i2c_device(pdev, setup); |
812 | if (ret != 0) | ||
813 | printk(KERN_ERR "can't add i2c driver"); | ||
814 | } | 810 | } |
815 | #else | 811 | #else |
816 | /* Add other interfaces here */ | 812 | /* Add other interfaces here */ |
@@ -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); |
diff --git a/sound/soc/codecs/uda1380.h b/sound/soc/codecs/uda1380.h index 50c603e2c9f2..c55c17a52a12 100644 --- a/sound/soc/codecs/uda1380.h +++ b/sound/soc/codecs/uda1380.h | |||
@@ -73,6 +73,7 @@ | |||
73 | #define R23_AGC_EN 0x0001 | 73 | #define R23_AGC_EN 0x0001 |
74 | 74 | ||
75 | struct uda1380_setup_data { | 75 | struct uda1380_setup_data { |
76 | int i2c_bus; | ||
76 | unsigned short i2c_address; | 77 | unsigned short i2c_address; |
77 | int dac_clk; | 78 | int dac_clk; |
78 | #define UDA1380_DAC_CLK_SYSCLK 0 | 79 | #define UDA1380_DAC_CLK_SYSCLK 0 |