diff options
Diffstat (limited to 'drivers/iio/magnetometer/ak8975.c')
-rw-r--r-- | drivers/iio/magnetometer/ak8975.c | 107 |
1 files changed, 38 insertions, 69 deletions
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 893bec5a0312..3c881541ae72 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -16,8 +16,7 @@ #include <linux/mutex.h> #include <linux/delay.h> #include <linux/bitops.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <linux/acpi.h> #include <linux/regulator/consumer.h> #include <linux/pm_runtime.h> @@ -29,8 +28,6 @@ #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> -#include <linux/iio/magnetometer/ak8975.h> - /* * Register definitions, as well as various shifts and masks to get at the * individual fields of the registers. @@ -206,11 +203,11 @@ static long ak09912_raw_to_gauss(u16 data) /* Compatible Asahi Kasei Compass parts */ enum asahi_compass_chipset { + AKXXXX = 0, AK8975, AK8963, AK09911, AK09912, - AK_MAX_TYPE }; enum ak_ctrl_reg_addr { @@ -248,7 +245,7 @@ struct ak_def { u8 data_regs[3]; }; -static const struct ak_def ak_def_array[AK_MAX_TYPE] = { +static const struct ak_def ak_def_array[] = { { .type = AK8975, .raw_to_gauss = ak8975_raw_to_gauss, @@ -360,7 +357,7 @@ struct ak8975_data { struct mutex lock; u8 asa[3]; long raw_to_gauss[3]; - int eoc_gpio; + struct gpio_desc *eoc_gpiod; int eoc_irq; wait_queue_head_t data_ready_queue; unsigned long flags; @@ -498,15 +495,13 @@ static int ak8975_setup_irq(struct ak8975_data *data) if (client->irq) irq = client->irq; else - irq = gpio_to_irq(data->eoc_gpio); + irq = gpiod_to_irq(data->eoc_gpiod); rc = devm_request_irq(&client->dev, irq, ak8975_irq_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, dev_name(&client->dev), data); if (rc < 0) { - dev_err(&client->dev, - "irq %d request failed, (gpio %d): %d\n", - irq, data->eoc_gpio, rc); + dev_err(&client->dev, "irq %d request failed: %d\n", irq, rc); return rc; } @@ -549,7 +544,7 @@ static int ak8975_setup(struct i2c_client *client) return ret; } - if (data->eoc_gpio > 0 || client->irq > 0) { + if (data->eoc_gpiod || client->irq > 0) { ret = ak8975_setup_irq(data); if (ret < 0) { dev_err(&client->dev, @@ -574,7 +569,7 @@ static int wait_conversion_complete_gpio(struct ak8975_data *data) /* Wait for the conversion to complete. */ while (timeout_ms) { msleep(AK8975_CONVERSION_DONE_POLL_TIME); - if (gpio_get_value(data->eoc_gpio)) + if (gpiod_get_value(data->eoc_gpiod)) break; timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; } @@ -646,7 +641,7 @@ static int ak8975_start_read_axis(struct ak8975_data *data, /* Wait for the conversion to complete. */ if (data->eoc_irq) ret = wait_conversion_complete_interrupt(data); - else if (gpio_is_valid(data->eoc_gpio)) + else if (data->eoc_gpiod) ret = wait_conversion_complete_gpio(data); else ret = wait_conversion_complete_polled(data); @@ -786,19 +781,6 @@ static const struct acpi_device_id ak_acpi_match[] = { MODULE_DEVICE_TABLE(acpi, ak_acpi_match); #endif -static const char *ak8975_match_acpi_device(struct device *dev, - enum asahi_compass_chipset *chipset) -{ - const struct acpi_device_id *id; - - id = acpi_match_device(dev->driver->acpi_match_table, dev); - if (!id) - return NULL; - *chipset = (int)id->driver_data; - - return dev_name(dev); -} - static void ak8975_fill_buffer(struct iio_dev *indio_dev) { struct ak8975_data *data = iio_priv(indio_dev); @@ -856,36 +838,23 @@ static int ak8975_probe(struct i2c_client *client, { struct ak8975_data *data; struct iio_dev *indio_dev; - int eoc_gpio; + struct gpio_desc *eoc_gpiod; + const void *match; + unsigned int i; int err; + enum asahi_compass_chipset chipset; const char *name = NULL; - enum asahi_compass_chipset chipset = AK_MAX_TYPE; - const struct ak8975_platform_data *pdata = - dev_get_platdata(&client->dev); - - /* Grab and set up the supplied GPIO. */ - if (pdata) - eoc_gpio = pdata->eoc_gpio; - else if (client->dev.of_node) - eoc_gpio = of_get_gpio(client->dev.of_node, 0); - else - eoc_gpio = -1; - if (eoc_gpio == -EPROBE_DEFER) - return -EPROBE_DEFER; - - /* We may not have a GPIO based IRQ to scan, that is fine, we will - poll if so */ - if (gpio_is_valid(eoc_gpio)) { - err = devm_gpio_request_one(&client->dev, eoc_gpio, - GPIOF_IN, "ak_8975"); - if (err < 0) { - dev_err(&client->dev, - "failed to request GPIO %d, error %d\n", - eoc_gpio, err); - return err; - } - } + /* + * Grab and set up the supplied GPIO. + * We may not have a GPIO based IRQ to scan, that is fine, we will + * poll if so. + */ + eoc_gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN); + if (IS_ERR(eoc_gpiod)) + return PTR_ERR(eoc_gpiod); + if (eoc_gpiod) + gpiod_set_consumer_name(eoc_gpiod, "ak_8975"); /* Register with IIO */ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); @@ -896,35 +865,35 @@ static int ak8975_probe(struct i2c_client *client, i2c_set_clientdata(client, indio_dev); data->client = client; - data->eoc_gpio = eoc_gpio; + data->eoc_gpiod = eoc_gpiod; data->eoc_irq = 0; - if (!pdata) { - err = iio_read_mount_matrix(&client->dev, "mount-matrix", - &data->orientation); - if (err) - return err; - } else - data->orientation = pdata->orientation; + err = iio_read_mount_matrix(&client->dev, "mount-matrix", &data->orientation); + if (err) + return err; /* id will be NULL when enumerated via ACPI */ - if (id) { + match = device_get_match_data(&client->dev); + if (match) { + chipset = (enum asahi_compass_chipset)(match); + name = dev_name(&client->dev); + } else if (id) { chipset = (enum asahi_compass_chipset)(id->driver_data); name = id->name; - } else if (ACPI_HANDLE(&client->dev)) { - name = ak8975_match_acpi_device(&client->dev, &chipset); - if (!name) - return -ENODEV; } else return -ENOSYS; - if (chipset >= AK_MAX_TYPE) { + for (i = 0; i < ARRAY_SIZE(ak_def_array); i++) + if (ak_def_array[i].type == chipset) + break; + + if (i == ARRAY_SIZE(ak_def_array)) { dev_err(&client->dev, "AKM device type unsupported: %d\n", chipset); return -ENODEV; } - data->def = &ak_def_array[chipset]; + data->def = &ak_def_array[i]; /* Fetch the regulators */ data->vdd = devm_regulator_get(&client->dev, "vdd"); |