forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/iio/dac/mcp4725.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * mcp4725.c - Support for Microchip MCP4725/6
34 *
45 * Copyright (C) 2012 Peter Meerwald <pmeerw@pmeerw.net>
56 *
67 * Based on max517 by Roland Stigge <stigge@antcom.de>
7
- *
8
- * This file is subject to the terms and conditions of version 2 of
9
- * the GNU General Public License. See the file COPYING in the main
10
- * directory of this archive for more details.
118 *
129 * driver for the Microchip I2C 12-bit digital-to-analog converter (DAC)
1310 * (7-bit I2C slave address 0x60, the three LSBs can be configured in
....@@ -19,8 +16,8 @@
1916 #include <linux/err.h>
2017 #include <linux/delay.h>
2118 #include <linux/regulator/consumer.h>
22
-#include <linux/of_device.h>
23
-#include <linux/of.h>
19
+#include <linux/mod_devicetable.h>
20
+#include <linux/property.h>
2421
2522 #include <linux/iio/iio.h>
2623 #include <linux/iio/sysfs.h>
....@@ -45,7 +42,7 @@
4542 struct regulator *vref_reg;
4643 };
4744
48
-static int mcp4725_suspend(struct device *dev)
45
+static int __maybe_unused mcp4725_suspend(struct device *dev)
4946 {
5047 struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
5148 to_i2c_client(dev)));
....@@ -58,7 +55,7 @@
5855 return i2c_master_send(data->client, outbuf, 2);
5956 }
6057
61
-static int mcp4725_resume(struct device *dev)
58
+static int __maybe_unused mcp4725_resume(struct device *dev)
6259 {
6360 struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
6461 to_i2c_client(dev)));
....@@ -71,13 +68,7 @@
7168
7269 return i2c_master_send(data->client, outbuf, 2);
7370 }
74
-
75
-#ifdef CONFIG_PM_SLEEP
7671 static SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend, mcp4725_resume);
77
-#define MCP4725_PM_OPS (&mcp4725_pm_ops)
78
-#else
79
-#define MCP4725_PM_OPS NULL
80
-#endif
8172
8273 static ssize_t mcp4725_store_eeprom(struct device *dev,
8374 struct device_attribute *attr, const char *buf, size_t len)
....@@ -366,29 +357,16 @@
366357 .attrs = &mcp4725_attribute_group,
367358 };
368359
369
-#ifdef CONFIG_OF
370360 static int mcp4725_probe_dt(struct device *dev,
371361 struct mcp4725_platform_data *pdata)
372362 {
373
- struct device_node *np = dev->of_node;
374
-
375
- if (!np)
376
- return -ENODEV;
377
-
378363 /* check if is the vref-supply defined */
379
- pdata->use_vref = of_property_read_bool(np, "vref-supply");
364
+ pdata->use_vref = device_property_read_bool(dev, "vref-supply");
380365 pdata->vref_buffered =
381
- of_property_read_bool(np, "microchip,vref-buffered");
366
+ device_property_read_bool(dev, "microchip,vref-buffered");
382367
383368 return 0;
384369 }
385
-#else
386
-static int mcp4725_probe_dt(struct device *dev,
387
- struct mcp4725_platform_data *platform_data)
388
-{
389
- return -ENODEV;
390
-}
391
-#endif
392370
393371 static int mcp4725_probe(struct i2c_client *client,
394372 const struct i2c_device_id *id)
....@@ -407,8 +385,8 @@
407385 data = iio_priv(indio_dev);
408386 i2c_set_clientdata(client, indio_dev);
409387 data->client = client;
410
- if (client->dev.of_node)
411
- data->id = (enum chip_id)of_device_get_match_data(&client->dev);
388
+ if (dev_fwnode(&client->dev))
389
+ data->id = (enum chip_id)device_get_match_data(&client->dev);
412390 else
413391 data->id = id->driver_data;
414392 pdata = dev_get_platdata(&client->dev);
....@@ -462,7 +440,6 @@
462440 goto err_disable_vdd_reg;
463441 }
464442
465
- indio_dev->dev.parent = &client->dev;
466443 indio_dev->name = id->name;
467444 indio_dev->info = &mcp4725_info;
468445 indio_dev->channels = &mcp472x_channel[id->driver_data];
....@@ -529,7 +506,6 @@
529506 };
530507 MODULE_DEVICE_TABLE(i2c, mcp4725_id);
531508
532
-#ifdef CONFIG_OF
533509 static const struct of_device_id mcp4725_of_match[] = {
534510 {
535511 .compatible = "microchip,mcp4725",
....@@ -542,13 +518,12 @@
542518 { }
543519 };
544520 MODULE_DEVICE_TABLE(of, mcp4725_of_match);
545
-#endif
546521
547522 static struct i2c_driver mcp4725_driver = {
548523 .driver = {
549524 .name = MCP4725_DRV_NAME,
550
- .of_match_table = of_match_ptr(mcp4725_of_match),
551
- .pm = MCP4725_PM_OPS,
525
+ .of_match_table = mcp4725_of_match,
526
+ .pm = &mcp4725_pm_ops,
552527 },
553528 .probe = mcp4725_probe,
554529 .remove = mcp4725_remove,