Skip to content

Commit 26b0d14

Browse files
andreas-schwabozbenh
authored andcommitted
sound/aoa: Adapt to new i2c probing scheme
The i2c-powermac driver now creates the i2c devices properly from the device-tree, including workarounds for broken or missing device-tree bits, so let's just use the normal probe methods and get rid of the hand made device creation code. Signed-off-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 3a3dd01 commit 26b0d14

2 files changed

Lines changed: 6 additions & 149 deletions

File tree

‎sound/aoa/codecs/onyx.c‎

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -997,45 +997,10 @@ static void onyx_exit_codec(struct aoa_codec *codec)
997997
onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx);
998998
}
999999

1000-
static int onyx_create(struct i2c_adapter *adapter,
1001-
struct device_node *node,
1002-
int addr)
1003-
{
1004-
struct i2c_board_info info;
1005-
struct i2c_client *client;
1006-
1007-
memset(&info, 0, sizeof(struct i2c_board_info));
1008-
strlcpy(info.type, "aoa_codec_onyx", I2C_NAME_SIZE);
1009-
info.addr = addr;
1010-
info.platform_data = node;
1011-
client = i2c_new_device(adapter, &info);
1012-
if (!client)
1013-
return -ENODEV;
1014-
1015-
/*
1016-
* We know the driver is already loaded, so the device should be
1017-
* already bound. If not it means binding failed, which suggests
1018-
* the device doesn't really exist and should be deleted.
1019-
* Ideally this would be replaced by better checks _before_
1020-
* instantiating the device.
1021-
*/
1022-
if (!client->driver) {
1023-
i2c_unregister_device(client);
1024-
return -ENODEV;
1025-
}
1026-
1027-
/*
1028-
* Let i2c-core delete that device on driver removal.
1029-
* This is safe because i2c-core holds the core_lock mutex for us.
1030-
*/
1031-
list_add_tail(&client->detected, &client->driver->clients);
1032-
return 0;
1033-
}
1034-
10351000
static int onyx_i2c_probe(struct i2c_client *client,
10361001
const struct i2c_device_id *id)
10371002
{
1038-
struct device_node *node = client->dev.platform_data;
1003+
struct device_node *node = client->dev.of_node;
10391004
struct onyx *onyx;
10401005
u8 dummy;
10411006

@@ -1071,40 +1036,6 @@ static int onyx_i2c_probe(struct i2c_client *client,
10711036
return -ENODEV;
10721037
}
10731038

1074-
static int onyx_i2c_attach(struct i2c_adapter *adapter)
1075-
{
1076-
struct device_node *busnode, *dev = NULL;
1077-
struct pmac_i2c_bus *bus;
1078-
1079-
bus = pmac_i2c_adapter_to_bus(adapter);
1080-
if (bus == NULL)
1081-
return -ENODEV;
1082-
busnode = pmac_i2c_get_bus_node(bus);
1083-
1084-
while ((dev = of_get_next_child(busnode, dev)) != NULL) {
1085-
if (of_device_is_compatible(dev, "pcm3052")) {
1086-
const u32 *addr;
1087-
printk(KERN_DEBUG PFX "found pcm3052\n");
1088-
addr = of_get_property(dev, "reg", NULL);
1089-
if (!addr)
1090-
return -ENODEV;
1091-
return onyx_create(adapter, dev, (*addr)>>1);
1092-
}
1093-
}
1094-
1095-
/* if that didn't work, try desperate mode for older
1096-
* machines that have stuff missing from the device tree */
1097-
1098-
if (!of_device_is_compatible(busnode, "k2-i2c"))
1099-
return -ENODEV;
1100-
1101-
printk(KERN_DEBUG PFX "found k2-i2c, checking if onyx chip is on it\n");
1102-
/* probe both possible addresses for the onyx chip */
1103-
if (onyx_create(adapter, NULL, 0x46) == 0)
1104-
return 0;
1105-
return onyx_create(adapter, NULL, 0x47);
1106-
}
1107-
11081039
static int onyx_i2c_remove(struct i2c_client *client)
11091040
{
11101041
struct onyx *onyx = i2c_get_clientdata(client);
@@ -1117,16 +1048,16 @@ static int onyx_i2c_remove(struct i2c_client *client)
11171048
}
11181049

11191050
static const struct i2c_device_id onyx_i2c_id[] = {
1120-
{ "aoa_codec_onyx", 0 },
1051+
{ "MAC,pcm3052", 0 },
11211052
{ }
11221053
};
1054+
MODULE_DEVICE_TABLE(i2c,onyx_i2c_id);
11231055

11241056
static struct i2c_driver onyx_driver = {
11251057
.driver = {
11261058
.name = "aoa_codec_onyx",
11271059
.owner = THIS_MODULE,
11281060
},
1129-
.attach_adapter = onyx_i2c_attach,
11301061
.probe = onyx_i2c_probe,
11311062
.remove = onyx_i2c_remove,
11321063
.id_table = onyx_i2c_id,

‎sound/aoa/codecs/tas.c‎

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -883,43 +883,10 @@ static void tas_exit_codec(struct aoa_codec *codec)
883883
}
884884

885885

886-
static int tas_create(struct i2c_adapter *adapter,
887-
struct device_node *node,
888-
int addr)
889-
{
890-
struct i2c_board_info info;
891-
struct i2c_client *client;
892-
893-
memset(&info, 0, sizeof(struct i2c_board_info));
894-
strlcpy(info.type, "aoa_codec_tas", I2C_NAME_SIZE);
895-
info.addr = addr;
896-
info.platform_data = node;
897-
898-
client = i2c_new_device(adapter, &info);
899-
if (!client)
900-
return -ENODEV;
901-
/*
902-
* We know the driver is already loaded, so the device should be
903-
* already bound. If not it means binding failed, and then there
904-
* is no point in keeping the device instantiated.
905-
*/
906-
if (!client->driver) {
907-
i2c_unregister_device(client);
908-
return -ENODEV;
909-
}
910-
911-
/*
912-
* Let i2c-core delete that device on driver removal.
913-
* This is safe because i2c-core holds the core_lock mutex for us.
914-
*/
915-
list_add_tail(&client->detected, &client->driver->clients);
916-
return 0;
917-
}
918-
919886
static int tas_i2c_probe(struct i2c_client *client,
920887
const struct i2c_device_id *id)
921888
{
922-
struct device_node *node = client->dev.platform_data;
889+
struct device_node *node = client->dev.of_node;
923890
struct tas *tas;
924891

925892
tas = kzalloc(sizeof(struct tas), GFP_KERNEL);
@@ -953,47 +920,6 @@ static int tas_i2c_probe(struct i2c_client *client,
953920
return -EINVAL;
954921
}
955922

956-
static int tas_i2c_attach(struct i2c_adapter *adapter)
957-
{
958-
struct device_node *busnode, *dev = NULL;
959-
struct pmac_i2c_bus *bus;
960-
961-
bus = pmac_i2c_adapter_to_bus(adapter);
962-
if (bus == NULL)
963-
return -ENODEV;
964-
busnode = pmac_i2c_get_bus_node(bus);
965-
966-
while ((dev = of_get_next_child(busnode, dev)) != NULL) {
967-
if (of_device_is_compatible(dev, "tas3004")) {
968-
const u32 *addr;
969-
printk(KERN_DEBUG PFX "found tas3004\n");
970-
addr = of_get_property(dev, "reg", NULL);
971-
if (!addr)
972-
continue;
973-
return tas_create(adapter, dev, ((*addr) >> 1) & 0x7f);
974-
}
975-
/* older machines have no 'codec' node with a 'compatible'
976-
* property that says 'tas3004', they just have a 'deq'
977-
* node without any such property... */
978-
if (strcmp(dev->name, "deq") == 0) {
979-
const u32 *_addr;
980-
u32 addr;
981-
printk(KERN_DEBUG PFX "found 'deq' node\n");
982-
_addr = of_get_property(dev, "i2c-address", NULL);
983-
if (!_addr)
984-
continue;
985-
addr = ((*_addr) >> 1) & 0x7f;
986-
/* now, if the address doesn't match any of the two
987-
* that a tas3004 can have, we cannot handle this.
988-
* I doubt it ever happens but hey. */
989-
if (addr != 0x34 && addr != 0x35)
990-
continue;
991-
return tas_create(adapter, dev, addr);
992-
}
993-
}
994-
return -ENODEV;
995-
}
996-
997923
static int tas_i2c_remove(struct i2c_client *client)
998924
{
999925
struct tas *tas = i2c_get_clientdata(client);
@@ -1011,16 +937,16 @@ static int tas_i2c_remove(struct i2c_client *client)
1011937
}
1012938

1013939
static const struct i2c_device_id tas_i2c_id[] = {
1014-
{ "aoa_codec_tas", 0 },
940+
{ "MAC,tas3004", 0 },
1015941
{ }
1016942
};
943+
MODULE_DEVICE_TABLE(i2c,tas_i2c_id);
1017944

1018945
static struct i2c_driver tas_driver = {
1019946
.driver = {
1020947
.name = "aoa_codec_tas",
1021948
.owner = THIS_MODULE,
1022949
},
1023-
.attach_adapter = tas_i2c_attach,
1024950
.probe = tas_i2c_probe,
1025951
.remove = tas_i2c_remove,
1026952
.id_table = tas_i2c_id,

0 commit comments

Comments
 (0)