diff options
-rw-r--r-- | sound/aoa/codecs/onyx.c | 76 | ||||
-rw-r--r-- | sound/aoa/codecs/tas.c | 66 |
2 files changed, 95 insertions, 47 deletions
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c index 15500b9d2da0..84bb07d39a7f 100644 --- a/sound/aoa/codecs/onyx.c +++ b/sound/aoa/codecs/onyx.c | |||
@@ -47,7 +47,7 @@ MODULE_DESCRIPTION("pcm3052 (onyx) codec driver for snd-aoa"); | |||
47 | struct onyx { | 47 | struct onyx { |
48 | /* cache registers 65 to 80, they are write-only! */ | 48 | /* cache registers 65 to 80, they are write-only! */ |
49 | u8 cache[16]; | 49 | u8 cache[16]; |
50 | struct i2c_client i2c; | 50 | struct i2c_client *i2c; |
51 | struct aoa_codec codec; | 51 | struct aoa_codec codec; |
52 | u32 initialised:1, | 52 | u32 initialised:1, |
53 | spdif_locked:1, | 53 | spdif_locked:1, |
@@ -72,7 +72,7 @@ static int onyx_read_register(struct onyx *onyx, u8 reg, u8 *value) | |||
72 | *value = onyx->cache[reg-FIRSTREGISTER]; | 72 | *value = onyx->cache[reg-FIRSTREGISTER]; |
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | v = i2c_smbus_read_byte_data(&onyx->i2c, reg); | 75 | v = i2c_smbus_read_byte_data(onyx->i2c, reg); |
76 | if (v < 0) | 76 | if (v < 0) |
77 | return -1; | 77 | return -1; |
78 | *value = (u8)v; | 78 | *value = (u8)v; |
@@ -84,7 +84,7 @@ static int onyx_write_register(struct onyx *onyx, u8 reg, u8 value) | |||
84 | { | 84 | { |
85 | int result; | 85 | int result; |
86 | 86 | ||
87 | result = i2c_smbus_write_byte_data(&onyx->i2c, reg, value); | 87 | result = i2c_smbus_write_byte_data(onyx->i2c, reg, value); |
88 | if (!result) | 88 | if (!result) |
89 | onyx->cache[reg-FIRSTREGISTER] = value; | 89 | onyx->cache[reg-FIRSTREGISTER] = value; |
90 | return result; | 90 | return result; |
@@ -996,12 +996,45 @@ static void onyx_exit_codec(struct aoa_codec *codec) | |||
996 | onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx); | 996 | onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx); |
997 | } | 997 | } |
998 | 998 | ||
999 | static struct i2c_driver onyx_driver; | ||
1000 | |||
1001 | static int onyx_create(struct i2c_adapter *adapter, | 999 | static int onyx_create(struct i2c_adapter *adapter, |
1002 | struct device_node *node, | 1000 | struct device_node *node, |
1003 | int addr) | 1001 | int addr) |
1004 | { | 1002 | { |
1003 | struct i2c_board_info info; | ||
1004 | struct i2c_client *client; | ||
1005 | |||
1006 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
1007 | strlcpy(info.type, "aoa_codec_onyx", I2C_NAME_SIZE); | ||
1008 | info.addr = addr; | ||
1009 | info.platform_data = node; | ||
1010 | client = i2c_new_device(adapter, &info); | ||
1011 | if (!client) | ||
1012 | return -ENODEV; | ||
1013 | |||
1014 | /* | ||
1015 | * We know the driver is already loaded, so the device should be | ||
1016 | * already bound. If not it means binding failed, which suggests | ||
1017 | * the device doesn't really exist and should be deleted. | ||
1018 | * Ideally this would be replaced by better checks _before_ | ||
1019 | * instantiating the device. | ||
1020 | */ | ||
1021 | if (!client->driver) { | ||
1022 | i2c_unregister_device(client); | ||
1023 | return -ENODEV; | ||
1024 | } | ||
1025 | |||
1026 | /* | ||
1027 | * Let i2c-core delete that device on driver removal. | ||
1028 | * This is safe because i2c-core holds the core_lock mutex for us. | ||
1029 | */ | ||
1030 | list_add_tail(&client->detected, &client->driver->clients); | ||
1031 | return 0; | ||
1032 | } | ||
1033 | |||
1034 | static int onyx_i2c_probe(struct i2c_client *client, | ||
1035 | const struct i2c_device_id *id) | ||
1036 | { | ||
1037 | struct device_node *node = client->dev.platform_data; | ||
1005 | struct onyx *onyx; | 1038 | struct onyx *onyx; |
1006 | u8 dummy; | 1039 | u8 dummy; |
1007 | 1040 | ||
@@ -1011,20 +1044,12 @@ static int onyx_create(struct i2c_adapter *adapter, | |||
1011 | return -ENOMEM; | 1044 | return -ENOMEM; |
1012 | 1045 | ||
1013 | mutex_init(&onyx->mutex); | 1046 | mutex_init(&onyx->mutex); |
1014 | onyx->i2c.driver = &onyx_driver; | 1047 | onyx->i2c = client; |
1015 | onyx->i2c.adapter = adapter; | 1048 | i2c_set_clientdata(client, onyx); |
1016 | onyx->i2c.addr = addr & 0x7f; | ||
1017 | strlcpy(onyx->i2c.name, "onyx audio codec", I2C_NAME_SIZE); | ||
1018 | |||
1019 | if (i2c_attach_client(&onyx->i2c)) { | ||
1020 | printk(KERN_ERR PFX "failed to attach to i2c\n"); | ||
1021 | goto fail; | ||
1022 | } | ||
1023 | 1049 | ||
1024 | /* we try to read from register ONYX_REG_CONTROL | 1050 | /* we try to read from register ONYX_REG_CONTROL |
1025 | * to check if the codec is present */ | 1051 | * to check if the codec is present */ |
1026 | if (onyx_read_register(onyx, ONYX_REG_CONTROL, &dummy) != 0) { | 1052 | if (onyx_read_register(onyx, ONYX_REG_CONTROL, &dummy) != 0) { |
1027 | i2c_detach_client(&onyx->i2c); | ||
1028 | printk(KERN_ERR PFX "failed to read control register\n"); | 1053 | printk(KERN_ERR PFX "failed to read control register\n"); |
1029 | goto fail; | 1054 | goto fail; |
1030 | } | 1055 | } |
@@ -1036,14 +1061,14 @@ static int onyx_create(struct i2c_adapter *adapter, | |||
1036 | onyx->codec.node = of_node_get(node); | 1061 | onyx->codec.node = of_node_get(node); |
1037 | 1062 | ||
1038 | if (aoa_codec_register(&onyx->codec)) { | 1063 | if (aoa_codec_register(&onyx->codec)) { |
1039 | i2c_detach_client(&onyx->i2c); | ||
1040 | goto fail; | 1064 | goto fail; |
1041 | } | 1065 | } |
1042 | printk(KERN_DEBUG PFX "created and attached onyx instance\n"); | 1066 | printk(KERN_DEBUG PFX "created and attached onyx instance\n"); |
1043 | return 0; | 1067 | return 0; |
1044 | fail: | 1068 | fail: |
1069 | i2c_set_clientdata(client, NULL); | ||
1045 | kfree(onyx); | 1070 | kfree(onyx); |
1046 | return -EINVAL; | 1071 | return -ENODEV; |
1047 | } | 1072 | } |
1048 | 1073 | ||
1049 | static int onyx_i2c_attach(struct i2c_adapter *adapter) | 1074 | static int onyx_i2c_attach(struct i2c_adapter *adapter) |
@@ -1080,28 +1105,33 @@ static int onyx_i2c_attach(struct i2c_adapter *adapter) | |||
1080 | return onyx_create(adapter, NULL, 0x47); | 1105 | return onyx_create(adapter, NULL, 0x47); |
1081 | } | 1106 | } |
1082 | 1107 | ||
1083 | static int onyx_i2c_detach(struct i2c_client *client) | 1108 | static int onyx_i2c_remove(struct i2c_client *client) |
1084 | { | 1109 | { |
1085 | struct onyx *onyx = container_of(client, struct onyx, i2c); | 1110 | struct onyx *onyx = i2c_get_clientdata(client); |
1086 | int err; | ||
1087 | 1111 | ||
1088 | if ((err = i2c_detach_client(client))) | ||
1089 | return err; | ||
1090 | aoa_codec_unregister(&onyx->codec); | 1112 | aoa_codec_unregister(&onyx->codec); |
1091 | of_node_put(onyx->codec.node); | 1113 | of_node_put(onyx->codec.node); |
1092 | if (onyx->codec_info) | 1114 | if (onyx->codec_info) |
1093 | kfree(onyx->codec_info); | 1115 | kfree(onyx->codec_info); |
1116 | i2c_set_clientdata(client, onyx); | ||
1094 | kfree(onyx); | 1117 | kfree(onyx); |
1095 | return 0; | 1118 | return 0; |
1096 | } | 1119 | } |
1097 | 1120 | ||
1121 | static const struct i2c_device_id onyx_i2c_id[] = { | ||
1122 | { "aoa_codec_onyx", 0 }, | ||
1123 | { } | ||
1124 | }; | ||
1125 | |||
1098 | static struct i2c_driver onyx_driver = { | 1126 | static struct i2c_driver onyx_driver = { |
1099 | .driver = { | 1127 | .driver = { |
1100 | .name = "aoa_codec_onyx", | 1128 | .name = "aoa_codec_onyx", |
1101 | .owner = THIS_MODULE, | 1129 | .owner = THIS_MODULE, |
1102 | }, | 1130 | }, |
1103 | .attach_adapter = onyx_i2c_attach, | 1131 | .attach_adapter = onyx_i2c_attach, |
1104 | .detach_client = onyx_i2c_detach, | 1132 | .probe = onyx_i2c_probe, |
1133 | .remove = onyx_i2c_remove, | ||
1134 | .id_table = onyx_i2c_id, | ||
1105 | }; | 1135 | }; |
1106 | 1136 | ||
1107 | static int __init onyx_init(void) | 1137 | static int __init onyx_init(void) |
diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c index 008e0f85097d..f0ebc971c686 100644 --- a/sound/aoa/codecs/tas.c +++ b/sound/aoa/codecs/tas.c | |||
@@ -82,7 +82,7 @@ MODULE_DESCRIPTION("tas codec driver for snd-aoa"); | |||
82 | 82 | ||
83 | struct tas { | 83 | struct tas { |
84 | struct aoa_codec codec; | 84 | struct aoa_codec codec; |
85 | struct i2c_client i2c; | 85 | struct i2c_client *i2c; |
86 | u32 mute_l:1, mute_r:1 , | 86 | u32 mute_l:1, mute_r:1 , |
87 | controls_created:1 , | 87 | controls_created:1 , |
88 | drc_enabled:1, | 88 | drc_enabled:1, |
@@ -108,9 +108,9 @@ static struct tas *codec_to_tas(struct aoa_codec *codec) | |||
108 | static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data) | 108 | static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data) |
109 | { | 109 | { |
110 | if (len == 1) | 110 | if (len == 1) |
111 | return i2c_smbus_write_byte_data(&tas->i2c, reg, *data); | 111 | return i2c_smbus_write_byte_data(tas->i2c, reg, *data); |
112 | else | 112 | else |
113 | return i2c_smbus_write_i2c_block_data(&tas->i2c, reg, len, data); | 113 | return i2c_smbus_write_i2c_block_data(tas->i2c, reg, len, data); |
114 | } | 114 | } |
115 | 115 | ||
116 | static void tas3004_set_drc(struct tas *tas) | 116 | static void tas3004_set_drc(struct tas *tas) |
@@ -882,12 +882,34 @@ static void tas_exit_codec(struct aoa_codec *codec) | |||
882 | } | 882 | } |
883 | 883 | ||
884 | 884 | ||
885 | static struct i2c_driver tas_driver; | ||
886 | |||
887 | static int tas_create(struct i2c_adapter *adapter, | 885 | static int tas_create(struct i2c_adapter *adapter, |
888 | struct device_node *node, | 886 | struct device_node *node, |
889 | int addr) | 887 | int addr) |
890 | { | 888 | { |
889 | struct i2c_board_info info; | ||
890 | struct i2c_client *client; | ||
891 | |||
892 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
893 | strlcpy(info.type, "aoa_codec_tas", I2C_NAME_SIZE); | ||
894 | info.addr = addr; | ||
895 | info.platform_data = node; | ||
896 | |||
897 | client = i2c_new_device(adapter, &info); | ||
898 | if (!client) | ||
899 | return -ENODEV; | ||
900 | |||
901 | /* | ||
902 | * Let i2c-core delete that device on driver removal. | ||
903 | * This is safe because i2c-core holds the core_lock mutex for us. | ||
904 | */ | ||
905 | list_add_tail(&client->detected, &client->driver->clients); | ||
906 | return 0; | ||
907 | } | ||
908 | |||
909 | static int tas_i2c_probe(struct i2c_client *client, | ||
910 | const struct i2c_device_id *id) | ||
911 | { | ||
912 | struct device_node *node = client->dev.platform_data; | ||
891 | struct tas *tas; | 913 | struct tas *tas; |
892 | 914 | ||
893 | tas = kzalloc(sizeof(struct tas), GFP_KERNEL); | 915 | tas = kzalloc(sizeof(struct tas), GFP_KERNEL); |
@@ -896,17 +918,11 @@ static int tas_create(struct i2c_adapter *adapter, | |||
896 | return -ENOMEM; | 918 | return -ENOMEM; |
897 | 919 | ||
898 | mutex_init(&tas->mtx); | 920 | mutex_init(&tas->mtx); |
899 | tas->i2c.driver = &tas_driver; | 921 | tas->i2c = client; |
900 | tas->i2c.adapter = adapter; | 922 | i2c_set_clientdata(client, tas); |
901 | tas->i2c.addr = addr; | 923 | |
902 | /* seems that half is a saner default */ | 924 | /* seems that half is a saner default */ |
903 | tas->drc_range = TAS3004_DRC_MAX / 2; | 925 | tas->drc_range = TAS3004_DRC_MAX / 2; |
904 | strlcpy(tas->i2c.name, "tas audio codec", I2C_NAME_SIZE); | ||
905 | |||
906 | if (i2c_attach_client(&tas->i2c)) { | ||
907 | printk(KERN_ERR PFX "failed to attach to i2c\n"); | ||
908 | goto fail; | ||
909 | } | ||
910 | 926 | ||
911 | strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); | 927 | strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); |
912 | tas->codec.owner = THIS_MODULE; | 928 | tas->codec.owner = THIS_MODULE; |
@@ -915,14 +931,12 @@ static int tas_create(struct i2c_adapter *adapter, | |||
915 | tas->codec.node = of_node_get(node); | 931 | tas->codec.node = of_node_get(node); |
916 | 932 | ||
917 | if (aoa_codec_register(&tas->codec)) { | 933 | if (aoa_codec_register(&tas->codec)) { |
918 | goto detach; | 934 | goto fail; |
919 | } | 935 | } |
920 | printk(KERN_DEBUG | 936 | printk(KERN_DEBUG |
921 | "snd-aoa-codec-tas: tas found, addr 0x%02x on %s\n", | 937 | "snd-aoa-codec-tas: tas found, addr 0x%02x on %s\n", |
922 | addr, node->full_name); | 938 | (unsigned int)client->addr, node->full_name); |
923 | return 0; | 939 | return 0; |
924 | detach: | ||
925 | i2c_detach_client(&tas->i2c); | ||
926 | fail: | 940 | fail: |
927 | mutex_destroy(&tas->mtx); | 941 | mutex_destroy(&tas->mtx); |
928 | kfree(tas); | 942 | kfree(tas); |
@@ -970,14 +984,11 @@ static int tas_i2c_attach(struct i2c_adapter *adapter) | |||
970 | return -ENODEV; | 984 | return -ENODEV; |
971 | } | 985 | } |
972 | 986 | ||
973 | static int tas_i2c_detach(struct i2c_client *client) | 987 | static int tas_i2c_remove(struct i2c_client *client) |
974 | { | 988 | { |
975 | struct tas *tas = container_of(client, struct tas, i2c); | 989 | struct tas *tas = i2c_get_clientdata(client); |
976 | int err; | ||
977 | u8 tmp = TAS_ACR_ANALOG_PDOWN; | 990 | u8 tmp = TAS_ACR_ANALOG_PDOWN; |
978 | 991 | ||
979 | if ((err = i2c_detach_client(client))) | ||
980 | return err; | ||
981 | aoa_codec_unregister(&tas->codec); | 992 | aoa_codec_unregister(&tas->codec); |
982 | of_node_put(tas->codec.node); | 993 | of_node_put(tas->codec.node); |
983 | 994 | ||
@@ -989,13 +1000,20 @@ static int tas_i2c_detach(struct i2c_client *client) | |||
989 | return 0; | 1000 | return 0; |
990 | } | 1001 | } |
991 | 1002 | ||
1003 | static const struct i2c_device_id tas_i2c_id[] = { | ||
1004 | { "aoa_codec_tas", 0 }, | ||
1005 | { } | ||
1006 | }; | ||
1007 | |||
992 | static struct i2c_driver tas_driver = { | 1008 | static struct i2c_driver tas_driver = { |
993 | .driver = { | 1009 | .driver = { |
994 | .name = "aoa_codec_tas", | 1010 | .name = "aoa_codec_tas", |
995 | .owner = THIS_MODULE, | 1011 | .owner = THIS_MODULE, |
996 | }, | 1012 | }, |
997 | .attach_adapter = tas_i2c_attach, | 1013 | .attach_adapter = tas_i2c_attach, |
998 | .detach_client = tas_i2c_detach, | 1014 | .probe = tas_i2c_probe, |
1015 | .remove = tas_i2c_remove, | ||
1016 | .id_table = tas_i2c_id, | ||
999 | }; | 1017 | }; |
1000 | 1018 | ||
1001 | static int __init tas_init(void) | 1019 | static int __init tas_init(void) |