Skip to content

Commit c5a4a27

Browse files
bijudasgregkh
authored andcommitted
iio: magnetometer: ak8975: Convert enum->pointer for data in the match tables
[ Upstream commit 4f9ea93 ] Convert enum->pointer for data in the match tables to simplify the probe() by replacing device_get_match_data() and i2c_client_get_device_id by i2c_get_match_data() as we have similar I2C, ACPI and DT matching table. Signed-off-by: Biju Das <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]> Stable-dep-of: da6e316 ("iio: magnetometer: ak8975: drop incorrect AK09116 compatible") Signed-off-by: Sasha Levin <[email protected]>
1 parent 2bc96d4 commit c5a4a27

File tree

1 file changed

+30
-45
lines changed

1 file changed

+30
-45
lines changed

drivers/iio/magnetometer/ak8975.c

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,13 @@ static const struct iio_info ak8975_info = {
813813
};
814814

815815
static const struct acpi_device_id ak_acpi_match[] = {
816-
{"AK8975", AK8975},
817-
{"AK8963", AK8963},
818-
{"INVN6500", AK8963},
819-
{"AK009911", AK09911},
820-
{"AK09911", AK09911},
821-
{"AKM9911", AK09911},
822-
{"AK09912", AK09912},
816+
{"AK8975", (kernel_ulong_t)&ak_def_array[AK8975] },
817+
{"AK8963", (kernel_ulong_t)&ak_def_array[AK8963] },
818+
{"INVN6500", (kernel_ulong_t)&ak_def_array[AK8963] },
819+
{"AK009911", (kernel_ulong_t)&ak_def_array[AK09911] },
820+
{"AK09911", (kernel_ulong_t)&ak_def_array[AK09911] },
821+
{"AKM9911", (kernel_ulong_t)&ak_def_array[AK09911] },
822+
{"AK09912", (kernel_ulong_t)&ak_def_array[AK09912] },
823823
{ }
824824
};
825825
MODULE_DEVICE_TABLE(acpi, ak_acpi_match);
@@ -883,10 +883,7 @@ static int ak8975_probe(struct i2c_client *client)
883883
struct iio_dev *indio_dev;
884884
struct gpio_desc *eoc_gpiod;
885885
struct gpio_desc *reset_gpiod;
886-
const void *match;
887-
unsigned int i;
888886
int err;
889-
enum asahi_compass_chipset chipset;
890887
const char *name = NULL;
891888

892889
/*
@@ -928,27 +925,15 @@ static int ak8975_probe(struct i2c_client *client)
928925
return err;
929926

930927
/* id will be NULL when enumerated via ACPI */
931-
match = device_get_match_data(&client->dev);
932-
if (match) {
933-
chipset = (uintptr_t)match;
934-
name = dev_name(&client->dev);
935-
} else if (id) {
936-
chipset = (enum asahi_compass_chipset)(id->driver_data);
937-
name = id->name;
938-
} else
939-
return -ENOSYS;
940-
941-
for (i = 0; i < ARRAY_SIZE(ak_def_array); i++)
942-
if (ak_def_array[i].type == chipset)
943-
break;
944-
945-
if (i == ARRAY_SIZE(ak_def_array)) {
946-
dev_err(&client->dev, "AKM device type unsupported: %d\n",
947-
chipset);
928+
data->def = i2c_get_match_data(client);
929+
if (!data->def)
948930
return -ENODEV;
949-
}
950931

951-
data->def = &ak_def_array[i];
932+
/* If enumerated via firmware node, fix the ABI */
933+
if (dev_fwnode(&client->dev))
934+
name = dev_name(&client->dev);
935+
else
936+
name = id->name;
952937

953938
/* Fetch the regulators */
954939
data->vdd = devm_regulator_get(&client->dev, "vdd");
@@ -1077,28 +1062,28 @@ static DEFINE_RUNTIME_DEV_PM_OPS(ak8975_dev_pm_ops, ak8975_runtime_suspend,
10771062
ak8975_runtime_resume, NULL);
10781063

10791064
static const struct i2c_device_id ak8975_id[] = {
1080-
{"ak8975", AK8975},
1081-
{"ak8963", AK8963},
1082-
{"AK8963", AK8963},
1083-
{"ak09911", AK09911},
1084-
{"ak09912", AK09912},
1085-
{"ak09916", AK09916},
1065+
{"ak8975", (kernel_ulong_t)&ak_def_array[AK8975] },
1066+
{"ak8963", (kernel_ulong_t)&ak_def_array[AK8963] },
1067+
{"AK8963", (kernel_ulong_t)&ak_def_array[AK8963] },
1068+
{"ak09911", (kernel_ulong_t)&ak_def_array[AK09911] },
1069+
{"ak09912", (kernel_ulong_t)&ak_def_array[AK09912] },
1070+
{"ak09916", (kernel_ulong_t)&ak_def_array[AK09916] },
10861071
{}
10871072
};
10881073

10891074
MODULE_DEVICE_TABLE(i2c, ak8975_id);
10901075

10911076
static const struct of_device_id ak8975_of_match[] = {
1092-
{ .compatible = "asahi-kasei,ak8975", },
1093-
{ .compatible = "ak8975", },
1094-
{ .compatible = "asahi-kasei,ak8963", },
1095-
{ .compatible = "ak8963", },
1096-
{ .compatible = "asahi-kasei,ak09911", },
1097-
{ .compatible = "ak09911", },
1098-
{ .compatible = "asahi-kasei,ak09912", },
1099-
{ .compatible = "ak09912", },
1100-
{ .compatible = "asahi-kasei,ak09916", },
1101-
{ .compatible = "ak09916", },
1077+
{ .compatible = "asahi-kasei,ak8975", .data = &ak_def_array[AK8975] },
1078+
{ .compatible = "ak8975", .data = &ak_def_array[AK8975] },
1079+
{ .compatible = "asahi-kasei,ak8963", .data = &ak_def_array[AK8963] },
1080+
{ .compatible = "ak8963", .data = &ak_def_array[AK8963] },
1081+
{ .compatible = "asahi-kasei,ak09911", .data = &ak_def_array[AK09911] },
1082+
{ .compatible = "ak09911", .data = &ak_def_array[AK09911] },
1083+
{ .compatible = "asahi-kasei,ak09912", .data = &ak_def_array[AK09912] },
1084+
{ .compatible = "ak09912", .data = &ak_def_array[AK09912] },
1085+
{ .compatible = "asahi-kasei,ak09916", .data = &ak_def_array[AK09916] },
1086+
{ .compatible = "ak09916", .data = &ak_def_array[AK09916] },
11021087
{}
11031088
};
11041089
MODULE_DEVICE_TABLE(of, ak8975_of_match);

0 commit comments

Comments
 (0)