hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
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,39 +42,45 @@
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)));
5249 u8 outbuf[2];
50
+ int ret;
5351
5452 outbuf[0] = (data->powerdown_mode + 1) << 4;
5553 outbuf[1] = 0;
5654 data->powerdown = true;
5755
58
- return i2c_master_send(data->client, outbuf, 2);
56
+ ret = i2c_master_send(data->client, outbuf, 2);
57
+ if (ret < 0)
58
+ return ret;
59
+ else if (ret != 2)
60
+ return -EIO;
61
+ return 0;
5962 }
6063
61
-static int mcp4725_resume(struct device *dev)
64
+static int __maybe_unused mcp4725_resume(struct device *dev)
6265 {
6366 struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
6467 to_i2c_client(dev)));
6568 u8 outbuf[2];
69
+ int ret;
6670
6771 /* restore previous DAC value */
6872 outbuf[0] = (data->dac_value >> 8) & 0xf;
6973 outbuf[1] = data->dac_value & 0xff;
7074 data->powerdown = false;
7175
72
- return i2c_master_send(data->client, outbuf, 2);
76
+ ret = i2c_master_send(data->client, outbuf, 2);
77
+ if (ret < 0)
78
+ return ret;
79
+ else if (ret != 2)
80
+ return -EIO;
81
+ return 0;
7382 }
74
-
75
-#ifdef CONFIG_PM_SLEEP
7683 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
8184
8285 static ssize_t mcp4725_store_eeprom(struct device *dev,
8386 struct device_attribute *attr, const char *buf, size_t len)
....@@ -366,29 +369,16 @@
366369 .attrs = &mcp4725_attribute_group,
367370 };
368371
369
-#ifdef CONFIG_OF
370372 static int mcp4725_probe_dt(struct device *dev,
371373 struct mcp4725_platform_data *pdata)
372374 {
373
- struct device_node *np = dev->of_node;
374
-
375
- if (!np)
376
- return -ENODEV;
377
-
378375 /* check if is the vref-supply defined */
379
- pdata->use_vref = of_property_read_bool(np, "vref-supply");
376
+ pdata->use_vref = device_property_read_bool(dev, "vref-supply");
380377 pdata->vref_buffered =
381
- of_property_read_bool(np, "microchip,vref-buffered");
378
+ device_property_read_bool(dev, "microchip,vref-buffered");
382379
383380 return 0;
384381 }
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
392382
393383 static int mcp4725_probe(struct i2c_client *client,
394384 const struct i2c_device_id *id)
....@@ -407,8 +397,8 @@
407397 data = iio_priv(indio_dev);
408398 i2c_set_clientdata(client, indio_dev);
409399 data->client = client;
410
- if (client->dev.of_node)
411
- data->id = (enum chip_id)of_device_get_match_data(&client->dev);
400
+ if (dev_fwnode(&client->dev))
401
+ data->id = (enum chip_id)device_get_match_data(&client->dev);
412402 else
413403 data->id = id->driver_data;
414404 pdata = dev_get_platdata(&client->dev);
....@@ -462,7 +452,6 @@
462452 goto err_disable_vdd_reg;
463453 }
464454
465
- indio_dev->dev.parent = &client->dev;
466455 indio_dev->name = id->name;
467456 indio_dev->info = &mcp4725_info;
468457 indio_dev->channels = &mcp472x_channel[id->driver_data];
....@@ -529,7 +518,6 @@
529518 };
530519 MODULE_DEVICE_TABLE(i2c, mcp4725_id);
531520
532
-#ifdef CONFIG_OF
533521 static const struct of_device_id mcp4725_of_match[] = {
534522 {
535523 .compatible = "microchip,mcp4725",
....@@ -542,13 +530,12 @@
542530 { }
543531 };
544532 MODULE_DEVICE_TABLE(of, mcp4725_of_match);
545
-#endif
546533
547534 static struct i2c_driver mcp4725_driver = {
548535 .driver = {
549536 .name = MCP4725_DRV_NAME,
550
- .of_match_table = of_match_ptr(mcp4725_of_match),
551
- .pm = MCP4725_PM_OPS,
537
+ .of_match_table = mcp4725_of_match,
538
+ .pm = &mcp4725_pm_ops,
552539 },
553540 .probe = mcp4725_probe,
554541 .remove = mcp4725_remove,