diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-10-15 13:57:12 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-10-16 02:50:17 -0400 |
commit | 17be5522f6de1d4920e7d9235bfb0e0c682c6f8f (patch) | |
tree | d1d95b612fffa629e01c220161a2f9140e6b768d | |
parent | d5d8d83773165b951d190717637bfbc1eb0111a0 (diff) |
ALSA: ASoC: Convert wm8580 to a new-style i2c driver
Convert the wm8580 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/wm8580.c | 108 | ||||
-rw-r--r-- | sound/soc/codecs/wm8580.h | 1 |
2 files changed, 54 insertions, 55 deletions
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c index 627ebfb4209b..cbcd7c324ab9 100644 --- a/sound/soc/codecs/wm8580.c +++ b/sound/soc/codecs/wm8580.c | |||
@@ -900,85 +900,85 @@ static struct snd_soc_device *wm8580_socdev; | |||
900 | * low = 0x1a | 900 | * low = 0x1a |
901 | * high = 0x1b | 901 | * high = 0x1b |
902 | */ | 902 | */ |
903 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
904 | 903 | ||
905 | /* Magic definition of all other variables and things */ | 904 | static int wm8580_i2c_probe(struct i2c_client *i2c, |
906 | I2C_CLIENT_INSMOD; | 905 | const struct i2c_device_id *id) |
907 | |||
908 | static struct i2c_driver wm8580_i2c_driver; | ||
909 | static struct i2c_client client_template; | ||
910 | |||
911 | static int wm8580_codec_probe(struct i2c_adapter *adap, int addr, int kind) | ||
912 | { | 906 | { |
913 | struct snd_soc_device *socdev = wm8580_socdev; | 907 | struct snd_soc_device *socdev = wm8580_socdev; |
914 | struct wm8580_setup_data *setup = socdev->codec_data; | ||
915 | struct snd_soc_codec *codec = socdev->codec; | 908 | struct snd_soc_codec *codec = socdev->codec; |
916 | struct i2c_client *i2c; | ||
917 | int ret; | 909 | int ret; |
918 | 910 | ||
919 | if (addr != setup->i2c_address) | ||
920 | return -ENODEV; | ||
921 | |||
922 | client_template.adapter = adap; | ||
923 | client_template.addr = addr; | ||
924 | |||
925 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
926 | if (i2c == NULL) { | ||
927 | kfree(codec); | ||
928 | return -ENOMEM; | ||
929 | } | ||
930 | i2c_set_clientdata(i2c, codec); | 911 | i2c_set_clientdata(i2c, codec); |
931 | codec->control_data = i2c; | 912 | codec->control_data = i2c; |
932 | 913 | ||
933 | ret = i2c_attach_client(i2c); | ||
934 | if (ret < 0) { | ||
935 | dev_err(&i2c->dev, "failed to attach codec at addr %x\n", addr); | ||
936 | goto err; | ||
937 | } | ||
938 | |||
939 | ret = wm8580_init(socdev); | 914 | ret = wm8580_init(socdev); |
940 | if (ret < 0) { | 915 | if (ret < 0) |
941 | dev_err(&i2c->dev, "failed to initialise WM8580\n"); | 916 | dev_err(&i2c->dev, "failed to initialise WM8580\n"); |
942 | goto err; | ||
943 | } | ||
944 | |||
945 | return ret; | ||
946 | |||
947 | err: | ||
948 | kfree(codec); | ||
949 | kfree(i2c); | ||
950 | return ret; | 917 | return ret; |
951 | } | 918 | } |
952 | 919 | ||
953 | static int wm8580_i2c_detach(struct i2c_client *client) | 920 | static int wm8580_i2c_remove(struct i2c_client *client) |
954 | { | 921 | { |
955 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 922 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
956 | i2c_detach_client(client); | ||
957 | kfree(codec->reg_cache); | 923 | kfree(codec->reg_cache); |
958 | kfree(client); | ||
959 | return 0; | 924 | return 0; |
960 | } | 925 | } |
961 | 926 | ||
962 | static int wm8580_i2c_attach(struct i2c_adapter *adap) | 927 | static const struct i2c_device_id wm8580_i2c_id[] = { |
963 | { | 928 | { "wm8580", 0 }, |
964 | return i2c_probe(adap, &addr_data, wm8580_codec_probe); | 929 | { } |
965 | } | 930 | }; |
931 | MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id); | ||
966 | 932 | ||
967 | /* corgi i2c codec control layer */ | ||
968 | static struct i2c_driver wm8580_i2c_driver = { | 933 | static struct i2c_driver wm8580_i2c_driver = { |
969 | .driver = { | 934 | .driver = { |
970 | .name = "WM8580 I2C Codec", | 935 | .name = "WM8580 I2C Codec", |
971 | .owner = THIS_MODULE, | 936 | .owner = THIS_MODULE, |
972 | }, | 937 | }, |
973 | .attach_adapter = wm8580_i2c_attach, | 938 | .probe = wm8580_i2c_probe, |
974 | .detach_client = wm8580_i2c_detach, | 939 | .remove = wm8580_i2c_remove, |
975 | .command = NULL, | 940 | .id_table = wm8580_i2c_id, |
976 | }; | 941 | }; |
977 | 942 | ||
978 | static struct i2c_client client_template = { | 943 | static int wm8580_add_i2c_device(struct platform_device *pdev, |
979 | .name = "WM8580", | 944 | const struct wm8580_setup_data *setup) |
980 | .driver = &wm8580_i2c_driver, | 945 | { |
981 | }; | 946 | struct i2c_board_info info; |
947 | struct i2c_adapter *adapter; | ||
948 | struct i2c_client *client; | ||
949 | int ret; | ||
950 | |||
951 | ret = i2c_add_driver(&wm8580_i2c_driver); | ||
952 | if (ret != 0) { | ||
953 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
954 | return ret; | ||
955 | } | ||
956 | |||
957 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
958 | info.addr = setup->i2c_address; | ||
959 | strlcpy(info.type, "wm8580", I2C_NAME_SIZE); | ||
960 | |||
961 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
962 | if (!adapter) { | ||
963 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
964 | setup->i2c_bus); | ||
965 | goto err_driver; | ||
966 | } | ||
967 | |||
968 | client = i2c_new_device(adapter, &info); | ||
969 | i2c_put_adapter(adapter); | ||
970 | if (!client) { | ||
971 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
972 | (unsigned int)info.addr); | ||
973 | goto err_driver; | ||
974 | } | ||
975 | |||
976 | return 0; | ||
977 | |||
978 | err_driver: | ||
979 | i2c_del_driver(&wm8580_i2c_driver); | ||
980 | return -ENODEV; | ||
981 | } | ||
982 | #endif | 982 | #endif |
983 | 983 | ||
984 | static int wm8580_probe(struct platform_device *pdev) | 984 | static int wm8580_probe(struct platform_device *pdev) |
@@ -1011,11 +1011,8 @@ static int wm8580_probe(struct platform_device *pdev) | |||
1011 | 1011 | ||
1012 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1012 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1013 | if (setup->i2c_address) { | 1013 | if (setup->i2c_address) { |
1014 | normal_i2c[0] = setup->i2c_address; | ||
1015 | codec->hw_write = (hw_write_t)i2c_master_send; | 1014 | codec->hw_write = (hw_write_t)i2c_master_send; |
1016 | ret = i2c_add_driver(&wm8580_i2c_driver); | 1015 | ret = wm8580_add_i2c_device(pdev, setup); |
1017 | if (ret != 0) | ||
1018 | printk(KERN_ERR "can't add i2c driver"); | ||
1019 | } | 1016 | } |
1020 | #else | 1017 | #else |
1021 | /* Add other interfaces here */ | 1018 | /* Add other interfaces here */ |
@@ -1034,6 +1031,7 @@ static int wm8580_remove(struct platform_device *pdev) | |||
1034 | snd_soc_free_pcms(socdev); | 1031 | snd_soc_free_pcms(socdev); |
1035 | snd_soc_dapm_free(socdev); | 1032 | snd_soc_dapm_free(socdev); |
1036 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1033 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1034 | i2c_unregister_device(codec->control_data); | ||
1037 | i2c_del_driver(&wm8580_i2c_driver); | 1035 | i2c_del_driver(&wm8580_i2c_driver); |
1038 | #endif | 1036 | #endif |
1039 | kfree(codec->private_data); | 1037 | kfree(codec->private_data); |
diff --git a/sound/soc/codecs/wm8580.h b/sound/soc/codecs/wm8580.h index 589ddaba21d7..09e4422f6f2f 100644 --- a/sound/soc/codecs/wm8580.h +++ b/sound/soc/codecs/wm8580.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #define WM8580_CLKSRC_NONE 5 | 29 | #define WM8580_CLKSRC_NONE 5 |
30 | 30 | ||
31 | struct wm8580_setup_data { | 31 | struct wm8580_setup_data { |
32 | int i2c_bus; | ||
32 | unsigned short i2c_address; | 33 | unsigned short i2c_address; |
33 | }; | 34 | }; |
34 | 35 | ||