forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/iio/potentiometer/mcp4131.c
....@@ -1,10 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Industrial I/O driver for Microchip digital potentiometers
34 *
45 * Copyright (c) 2016 Slawomir Stepien
56 * Based on: Peter Rosin's code from mcp4531.c
67 *
7
- * Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
8
+ * Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
89 *
910 * DEVID #Wipers #Positions Resistor Opts (kOhm)
1011 * mcp4131 1 129 5, 10, 50, 100
....@@ -23,10 +24,6 @@
2324 * mcp4252 2 257 5, 10, 50, 100
2425 * mcp4261 2 257 5, 10, 50, 100
2526 * mcp4262 2 257 5, 10, 50, 100
26
- *
27
- * This program is free software; you can redistribute it and/or modify it
28
- * under the terms of the GNU General Public License version 2 as published by
29
- * the Free Software Foundation.
3027 */
3128
3229 /*
....@@ -40,8 +37,9 @@
4037 #include <linux/iio/iio.h>
4138 #include <linux/iio/types.h>
4239 #include <linux/module.h>
40
+#include <linux/mod_devicetable.h>
4341 #include <linux/mutex.h>
44
-#include <linux/of.h>
42
+#include <linux/property.h>
4543 #include <linux/spi/spi.h>
4644
4745 #define MCP4131_WRITE (0x00 << 2)
....@@ -243,7 +241,7 @@
243241 {
244242 int err;
245243 struct device *dev = &spi->dev;
246
- unsigned long devid = spi_get_device_id(spi)->driver_data;
244
+ unsigned long devid;
247245 struct mcp4131_data *data;
248246 struct iio_dev *indio_dev;
249247
....@@ -254,11 +252,14 @@
254252 data = iio_priv(indio_dev);
255253 spi_set_drvdata(spi, indio_dev);
256254 data->spi = spi;
257
- data->cfg = &mcp4131_cfg[devid];
255
+ data->cfg = device_get_match_data(&spi->dev);
256
+ if (!data->cfg) {
257
+ devid = spi_get_device_id(spi)->driver_data;
258
+ data->cfg = &mcp4131_cfg[devid];
259
+ }
258260
259261 mutex_init(&data->lock);
260262
261
- indio_dev->dev.parent = dev;
262263 indio_dev->info = &mcp4131_info;
263264 indio_dev->channels = mcp4131_channels;
264265 indio_dev->num_channels = data->cfg->wipers;
....@@ -273,7 +274,6 @@
273274 return 0;
274275 }
275276
276
-#if defined(CONFIG_OF)
277277 static const struct of_device_id mcp4131_dt_ids[] = {
278278 { .compatible = "microchip,mcp4131-502",
279279 .data = &mcp4131_cfg[MCP413x_502] },
....@@ -406,7 +406,6 @@
406406 {}
407407 };
408408 MODULE_DEVICE_TABLE(of, mcp4131_dt_ids);
409
-#endif /* CONFIG_OF */
410409
411410 static const struct spi_device_id mcp4131_id[] = {
412411 { "mcp4131-502", MCP413x_502 },
....@@ -480,7 +479,7 @@
480479 static struct spi_driver mcp4131_driver = {
481480 .driver = {
482481 .name = "mcp4131",
483
- .of_match_table = of_match_ptr(mcp4131_dt_ids),
482
+ .of_match_table = mcp4131_dt_ids,
484483 },
485484 .probe = mcp4131_probe,
486485 .id_table = mcp4131_id,