Skip to content

Commit cfbf1ee

Browse files
Jean Delvaretiwai
authored andcommitted
ALSA: AOA: Convert onyx and tas codecs to new-style i2c drivers
The legacy i2c binding model is going away soon, so convert the AOA codec drivers to the new model or they'll break. Signed-off-by: Jean Delvare <khali@linux-fr.org> Tested-by: Johannes Berg <johannes@sipsolutions.net> Tested-by: Andreas Schwab <schwab@linux-m68k.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent d91dfbb commit cfbf1ee

2 files changed

Lines changed: 95 additions & 47 deletions

File tree

‎sound/aoa/codecs/onyx.c‎

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ MODULE_DESCRIPTION("pcm3052 (onyx) codec driver for snd-aoa");
4747
struct onyx {
4848
/* cache registers 65 to 80, they are write-only! */
4949
u8 cache[16];
50-
struct i2c_client i2c;
50+
struct i2c_client *i2c;
5151
struct aoa_codec codec;
5252
u32 initialised:1,
5353
spdif_locked:1,
@@ -72,7 +72,7 @@ static int onyx_read_register(struct onyx *onyx, u8 reg, u8 *value)
7272
*value = onyx->cache[reg-FIRSTREGISTER];
7373
return 0;
7474
}
75-
v = i2c_smbus_read_byte_data(&onyx->i2c, reg);
75+
v = i2c_smbus_read_byte_data(onyx->i2c, reg);
7676
if (v < 0)
7777
return -1;
7878
*value = (u8)v;
@@ -84,7 +84,7 @@ static int onyx_write_register(struct onyx *onyx, u8 reg, u8 value)
8484
{
8585
int result;
8686

87-
result = i2c_smbus_write_byte_data(&onyx->i2c, reg, value);
87+
result = i2c_smbus_write_byte_data(onyx->i2c, reg, value);
8888
if (!result)
8989
onyx->cache[reg-FIRSTREGISTER] = value;
9090
return result;
@@ -996,12 +996,45 @@ static void onyx_exit_codec(struct aoa_codec *codec)
996996
onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx);
997997
}
998998

999-
static struct i2c_driver onyx_driver;
1000-
1001999
static int onyx_create(struct i2c_adapter *adapter,
10021000
struct device_node *node,
10031001
int addr)
10041002
{
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;
10051038
struct onyx *onyx;
10061039
u8 dummy;
10071040

@@ -1011,20 +1044,12 @@ static int onyx_create(struct i2c_adapter *adapter,
10111044
return -ENOMEM;
10121045

10131046
mutex_init(&onyx->mutex);
1014-
onyx->i2c.driver = &onyx_driver;
1015-
onyx->i2c.adapter = adapter;
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-
}
1047+
onyx->i2c = client;
1048+
i2c_set_clientdata(client, onyx);
10231049

10241050
/* we try to read from register ONYX_REG_CONTROL
10251051
* to check if the codec is present */
10261052
if (onyx_read_register(onyx, ONYX_REG_CONTROL, &dummy) != 0) {
1027-
i2c_detach_client(&onyx->i2c);
10281053
printk(KERN_ERR PFX "failed to read control register\n");
10291054
goto fail;
10301055
}
@@ -1036,14 +1061,14 @@ static int onyx_create(struct i2c_adapter *adapter,
10361061
onyx->codec.node = of_node_get(node);
10371062

10381063
if (aoa_codec_register(&onyx->codec)) {
1039-
i2c_detach_client(&onyx->i2c);
10401064
goto fail;
10411065
}
10421066
printk(KERN_DEBUG PFX "created and attached onyx instance\n");
10431067
return 0;
10441068
fail:
1069+
i2c_set_clientdata(client, NULL);
10451070
kfree(onyx);
1046-
return -EINVAL;
1071+
return -ENODEV;
10471072
}
10481073

10491074
static int onyx_i2c_attach(struct i2c_adapter *adapter)
@@ -1080,28 +1105,33 @@ static int onyx_i2c_attach(struct i2c_adapter *adapter)
10801105
return onyx_create(adapter, NULL, 0x47);
10811106
}
10821107

1083-
static int onyx_i2c_detach(struct i2c_client *client)
1108+
static int onyx_i2c_remove(struct i2c_client *client)
10841109
{
1085-
struct onyx *onyx = container_of(client, struct onyx, i2c);
1086-
int err;
1110+
struct onyx *onyx = i2c_get_clientdata(client);
10871111

1088-
if ((err = i2c_detach_client(client)))
1089-
return err;
10901112
aoa_codec_unregister(&onyx->codec);
10911113
of_node_put(onyx->codec.node);
10921114
if (onyx->codec_info)
10931115
kfree(onyx->codec_info);
1116+
i2c_set_clientdata(client, onyx);
10941117
kfree(onyx);
10951118
return 0;
10961119
}
10971120

1121+
static const struct i2c_device_id onyx_i2c_id[] = {
1122+
{ "aoa_codec_onyx", 0 },
1123+
{ }
1124+
};
1125+
10981126
static struct i2c_driver onyx_driver = {
10991127
.driver = {
11001128
.name = "aoa_codec_onyx",
11011129
.owner = THIS_MODULE,
11021130
},
11031131
.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,
11051135
};
11061136

11071137
static int __init onyx_init(void)

‎sound/aoa/codecs/tas.c‎

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ MODULE_DESCRIPTION("tas codec driver for snd-aoa");
8282

8383
struct tas {
8484
struct aoa_codec codec;
85-
struct i2c_client i2c;
85+
struct i2c_client *i2c;
8686
u32 mute_l:1, mute_r:1 ,
8787
controls_created:1 ,
8888
drc_enabled:1,
@@ -108,9 +108,9 @@ static struct tas *codec_to_tas(struct aoa_codec *codec)
108108
static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data)
109109
{
110110
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);
112112
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);
114114
}
115115

116116
static void tas3004_set_drc(struct tas *tas)
@@ -882,12 +882,34 @@ static void tas_exit_codec(struct aoa_codec *codec)
882882
}
883883

884884

885-
static struct i2c_driver tas_driver;
886-
887885
static int tas_create(struct i2c_adapter *adapter,
888886
struct device_node *node,
889887
int addr)
890888
{
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;
891913
struct tas *tas;
892914

893915
tas = kzalloc(sizeof(struct tas), GFP_KERNEL);
@@ -896,17 +918,11 @@ static int tas_create(struct i2c_adapter *adapter,
896918
return -ENOMEM;
897919

898920
mutex_init(&tas->mtx);
899-
tas->i2c.driver = &tas_driver;
900-
tas->i2c.adapter = adapter;
901-
tas->i2c.addr = addr;
921+
tas->i2c = client;
922+
i2c_set_clientdata(client, tas);
923+
902924
/* seems that half is a saner default */
903925
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-
}
910926

911927
strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN);
912928
tas->codec.owner = THIS_MODULE;
@@ -915,14 +931,12 @@ static int tas_create(struct i2c_adapter *adapter,
915931
tas->codec.node = of_node_get(node);
916932

917933
if (aoa_codec_register(&tas->codec)) {
918-
goto detach;
934+
goto fail;
919935
}
920936
printk(KERN_DEBUG
921937
"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);
923939
return 0;
924-
detach:
925-
i2c_detach_client(&tas->i2c);
926940
fail:
927941
mutex_destroy(&tas->mtx);
928942
kfree(tas);
@@ -970,14 +984,11 @@ static int tas_i2c_attach(struct i2c_adapter *adapter)
970984
return -ENODEV;
971985
}
972986

973-
static int tas_i2c_detach(struct i2c_client *client)
987+
static int tas_i2c_remove(struct i2c_client *client)
974988
{
975-
struct tas *tas = container_of(client, struct tas, i2c);
976-
int err;
989+
struct tas *tas = i2c_get_clientdata(client);
977990
u8 tmp = TAS_ACR_ANALOG_PDOWN;
978991

979-
if ((err = i2c_detach_client(client)))
980-
return err;
981992
aoa_codec_unregister(&tas->codec);
982993
of_node_put(tas->codec.node);
983994

@@ -989,13 +1000,20 @@ static int tas_i2c_detach(struct i2c_client *client)
9891000
return 0;
9901001
}
9911002

1003+
static const struct i2c_device_id tas_i2c_id[] = {
1004+
{ "aoa_codec_tas", 0 },
1005+
{ }
1006+
};
1007+
9921008
static struct i2c_driver tas_driver = {
9931009
.driver = {
9941010
.name = "aoa_codec_tas",
9951011
.owner = THIS_MODULE,
9961012
},
9971013
.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,
9991017
};
10001018

10011019
static int __init tas_init(void)

0 commit comments

Comments
 (0)