| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * mcp4725.c - Support for Microchip MCP4725/6 |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Peter Meerwald <pmeerw@pmeerw.net> |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * 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. |
|---|
| 11 | 8 | * |
|---|
| 12 | 9 | * driver for the Microchip I2C 12-bit digital-to-analog converter (DAC) |
|---|
| 13 | 10 | * (7-bit I2C slave address 0x60, the three LSBs can be configured in |
|---|
| .. | .. |
|---|
| 19 | 16 | #include <linux/err.h> |
|---|
| 20 | 17 | #include <linux/delay.h> |
|---|
| 21 | 18 | #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> |
|---|
| 24 | 21 | |
|---|
| 25 | 22 | #include <linux/iio/iio.h> |
|---|
| 26 | 23 | #include <linux/iio/sysfs.h> |
|---|
| .. | .. |
|---|
| 45 | 42 | struct regulator *vref_reg; |
|---|
| 46 | 43 | }; |
|---|
| 47 | 44 | |
|---|
| 48 | | -static int mcp4725_suspend(struct device *dev) |
|---|
| 45 | +static int __maybe_unused mcp4725_suspend(struct device *dev) |
|---|
| 49 | 46 | { |
|---|
| 50 | 47 | struct mcp4725_data *data = iio_priv(i2c_get_clientdata( |
|---|
| 51 | 48 | to_i2c_client(dev))); |
|---|
| 52 | 49 | u8 outbuf[2]; |
|---|
| 50 | + int ret; |
|---|
| 53 | 51 | |
|---|
| 54 | 52 | outbuf[0] = (data->powerdown_mode + 1) << 4; |
|---|
| 55 | 53 | outbuf[1] = 0; |
|---|
| 56 | 54 | data->powerdown = true; |
|---|
| 57 | 55 | |
|---|
| 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; |
|---|
| 59 | 62 | } |
|---|
| 60 | 63 | |
|---|
| 61 | | -static int mcp4725_resume(struct device *dev) |
|---|
| 64 | +static int __maybe_unused mcp4725_resume(struct device *dev) |
|---|
| 62 | 65 | { |
|---|
| 63 | 66 | struct mcp4725_data *data = iio_priv(i2c_get_clientdata( |
|---|
| 64 | 67 | to_i2c_client(dev))); |
|---|
| 65 | 68 | u8 outbuf[2]; |
|---|
| 69 | + int ret; |
|---|
| 66 | 70 | |
|---|
| 67 | 71 | /* restore previous DAC value */ |
|---|
| 68 | 72 | outbuf[0] = (data->dac_value >> 8) & 0xf; |
|---|
| 69 | 73 | outbuf[1] = data->dac_value & 0xff; |
|---|
| 70 | 74 | data->powerdown = false; |
|---|
| 71 | 75 | |
|---|
| 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; |
|---|
| 73 | 82 | } |
|---|
| 74 | | - |
|---|
| 75 | | -#ifdef CONFIG_PM_SLEEP |
|---|
| 76 | 83 | 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 |
|---|
| 81 | 84 | |
|---|
| 82 | 85 | static ssize_t mcp4725_store_eeprom(struct device *dev, |
|---|
| 83 | 86 | struct device_attribute *attr, const char *buf, size_t len) |
|---|
| .. | .. |
|---|
| 366 | 369 | .attrs = &mcp4725_attribute_group, |
|---|
| 367 | 370 | }; |
|---|
| 368 | 371 | |
|---|
| 369 | | -#ifdef CONFIG_OF |
|---|
| 370 | 372 | static int mcp4725_probe_dt(struct device *dev, |
|---|
| 371 | 373 | struct mcp4725_platform_data *pdata) |
|---|
| 372 | 374 | { |
|---|
| 373 | | - struct device_node *np = dev->of_node; |
|---|
| 374 | | - |
|---|
| 375 | | - if (!np) |
|---|
| 376 | | - return -ENODEV; |
|---|
| 377 | | - |
|---|
| 378 | 375 | /* 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"); |
|---|
| 380 | 377 | pdata->vref_buffered = |
|---|
| 381 | | - of_property_read_bool(np, "microchip,vref-buffered"); |
|---|
| 378 | + device_property_read_bool(dev, "microchip,vref-buffered"); |
|---|
| 382 | 379 | |
|---|
| 383 | 380 | return 0; |
|---|
| 384 | 381 | } |
|---|
| 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 |
|---|
| 392 | 382 | |
|---|
| 393 | 383 | static int mcp4725_probe(struct i2c_client *client, |
|---|
| 394 | 384 | const struct i2c_device_id *id) |
|---|
| .. | .. |
|---|
| 407 | 397 | data = iio_priv(indio_dev); |
|---|
| 408 | 398 | i2c_set_clientdata(client, indio_dev); |
|---|
| 409 | 399 | 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); |
|---|
| 412 | 402 | else |
|---|
| 413 | 403 | data->id = id->driver_data; |
|---|
| 414 | 404 | pdata = dev_get_platdata(&client->dev); |
|---|
| .. | .. |
|---|
| 462 | 452 | goto err_disable_vdd_reg; |
|---|
| 463 | 453 | } |
|---|
| 464 | 454 | |
|---|
| 465 | | - indio_dev->dev.parent = &client->dev; |
|---|
| 466 | 455 | indio_dev->name = id->name; |
|---|
| 467 | 456 | indio_dev->info = &mcp4725_info; |
|---|
| 468 | 457 | indio_dev->channels = &mcp472x_channel[id->driver_data]; |
|---|
| .. | .. |
|---|
| 529 | 518 | }; |
|---|
| 530 | 519 | MODULE_DEVICE_TABLE(i2c, mcp4725_id); |
|---|
| 531 | 520 | |
|---|
| 532 | | -#ifdef CONFIG_OF |
|---|
| 533 | 521 | static const struct of_device_id mcp4725_of_match[] = { |
|---|
| 534 | 522 | { |
|---|
| 535 | 523 | .compatible = "microchip,mcp4725", |
|---|
| .. | .. |
|---|
| 542 | 530 | { } |
|---|
| 543 | 531 | }; |
|---|
| 544 | 532 | MODULE_DEVICE_TABLE(of, mcp4725_of_match); |
|---|
| 545 | | -#endif |
|---|
| 546 | 533 | |
|---|
| 547 | 534 | static struct i2c_driver mcp4725_driver = { |
|---|
| 548 | 535 | .driver = { |
|---|
| 549 | 536 | .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, |
|---|
| 552 | 539 | }, |
|---|
| 553 | 540 | .probe = mcp4725_probe, |
|---|
| 554 | 541 | .remove = mcp4725_remove, |
|---|