| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com> |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Driver for Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip. |
|---|
| 5 | 6 | * Datasheets can be found here: |
|---|
| 6 | | - * http://www.ti.com/lit/ds/symlink/adc128s052.pdf |
|---|
| 7 | | - * http://www.ti.com/lit/ds/symlink/adc122s021.pdf |
|---|
| 8 | | - * http://www.ti.com/lit/ds/symlink/adc124s021.pdf |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 7 | + * https://www.ti.com/lit/ds/symlink/adc128s052.pdf |
|---|
| 8 | + * https://www.ti.com/lit/ds/symlink/adc122s021.pdf |
|---|
| 9 | + * https://www.ti.com/lit/ds/symlink/adc124s021.pdf |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 12 | +#include <linux/acpi.h> |
|---|
| 15 | 13 | #include <linux/err.h> |
|---|
| 16 | 14 | #include <linux/spi/spi.h> |
|---|
| 17 | 15 | #include <linux/module.h> |
|---|
| 16 | +#include <linux/mod_devicetable.h> |
|---|
| 18 | 17 | #include <linux/iio/iio.h> |
|---|
| 18 | +#include <linux/property.h> |
|---|
| 19 | 19 | #include <linux/regulator/consumer.h> |
|---|
| 20 | 20 | |
|---|
| 21 | 21 | struct adc128_configuration { |
|---|
| .. | .. |
|---|
| 135 | 135 | static int adc128_probe(struct spi_device *spi) |
|---|
| 136 | 136 | { |
|---|
| 137 | 137 | struct iio_dev *indio_dev; |
|---|
| 138 | + unsigned int config; |
|---|
| 138 | 139 | struct adc128 *adc; |
|---|
| 139 | | - int config = spi_get_device_id(spi)->driver_data; |
|---|
| 140 | 140 | int ret; |
|---|
| 141 | + |
|---|
| 142 | + if (dev_fwnode(&spi->dev)) |
|---|
| 143 | + config = (unsigned long) device_get_match_data(&spi->dev); |
|---|
| 144 | + else |
|---|
| 145 | + config = spi_get_device_id(spi)->driver_data; |
|---|
| 141 | 146 | |
|---|
| 142 | 147 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); |
|---|
| 143 | 148 | if (!indio_dev) |
|---|
| .. | .. |
|---|
| 148 | 153 | |
|---|
| 149 | 154 | spi_set_drvdata(spi, indio_dev); |
|---|
| 150 | 155 | |
|---|
| 151 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 152 | | - indio_dev->dev.of_node = spi->dev.of_node; |
|---|
| 153 | 156 | indio_dev->name = spi_get_device_id(spi)->name; |
|---|
| 154 | 157 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 155 | 158 | indio_dev->info = &adc128_info; |
|---|
| .. | .. |
|---|
| 192 | 195 | static const struct of_device_id adc128_of_match[] = { |
|---|
| 193 | 196 | { .compatible = "ti,adc128s052", }, |
|---|
| 194 | 197 | { .compatible = "ti,adc122s021", }, |
|---|
| 198 | + { .compatible = "ti,adc122s051", }, |
|---|
| 199 | + { .compatible = "ti,adc122s101", }, |
|---|
| 195 | 200 | { .compatible = "ti,adc124s021", }, |
|---|
| 201 | + { .compatible = "ti,adc124s051", }, |
|---|
| 202 | + { .compatible = "ti,adc124s101", }, |
|---|
| 196 | 203 | { /* sentinel */ }, |
|---|
| 197 | 204 | }; |
|---|
| 198 | 205 | MODULE_DEVICE_TABLE(of, adc128_of_match); |
|---|
| 199 | 206 | |
|---|
| 200 | 207 | static const struct spi_device_id adc128_id[] = { |
|---|
| 201 | | - { "adc128s052", 0}, /* index into adc128_config */ |
|---|
| 202 | | - { "adc122s021", 1}, |
|---|
| 203 | | - { "adc124s021", 2}, |
|---|
| 208 | + { "adc128s052", 0 }, /* index into adc128_config */ |
|---|
| 209 | + { "adc122s021", 1 }, |
|---|
| 210 | + { "adc122s051", 1 }, |
|---|
| 211 | + { "adc122s101", 1 }, |
|---|
| 212 | + { "adc124s021", 2 }, |
|---|
| 213 | + { "adc124s051", 2 }, |
|---|
| 214 | + { "adc124s101", 2 }, |
|---|
| 204 | 215 | { } |
|---|
| 205 | 216 | }; |
|---|
| 206 | 217 | MODULE_DEVICE_TABLE(spi, adc128_id); |
|---|
| 207 | 218 | |
|---|
| 219 | +#ifdef CONFIG_ACPI |
|---|
| 220 | +static const struct acpi_device_id adc128_acpi_match[] = { |
|---|
| 221 | + { "AANT1280", 2 }, /* ADC124S021 compatible ACPI ID */ |
|---|
| 222 | + { } |
|---|
| 223 | +}; |
|---|
| 224 | +MODULE_DEVICE_TABLE(acpi, adc128_acpi_match); |
|---|
| 225 | +#endif |
|---|
| 226 | + |
|---|
| 208 | 227 | static struct spi_driver adc128_driver = { |
|---|
| 209 | 228 | .driver = { |
|---|
| 210 | 229 | .name = "adc128s052", |
|---|
| 211 | | - .of_match_table = of_match_ptr(adc128_of_match), |
|---|
| 230 | + .of_match_table = adc128_of_match, |
|---|
| 231 | + .acpi_match_table = ACPI_PTR(adc128_acpi_match), |
|---|
| 212 | 232 | }, |
|---|
| 213 | 233 | .probe = adc128_probe, |
|---|
| 214 | 234 | .remove = adc128_remove, |
|---|