| .. | .. |
|---|
| 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))); |
|---|
| .. | .. |
|---|
| 58 | 55 | return i2c_master_send(data->client, outbuf, 2); |
|---|
| 59 | 56 | } |
|---|
| 60 | 57 | |
|---|
| 61 | | -static int mcp4725_resume(struct device *dev) |
|---|
| 58 | +static int __maybe_unused mcp4725_resume(struct device *dev) |
|---|
| 62 | 59 | { |
|---|
| 63 | 60 | struct mcp4725_data *data = iio_priv(i2c_get_clientdata( |
|---|
| 64 | 61 | to_i2c_client(dev))); |
|---|
| .. | .. |
|---|
| 71 | 68 | |
|---|
| 72 | 69 | return i2c_master_send(data->client, outbuf, 2); |
|---|
| 73 | 70 | } |
|---|
| 74 | | - |
|---|
| 75 | | -#ifdef CONFIG_PM_SLEEP |
|---|
| 76 | 71 | 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 | 72 | |
|---|
| 82 | 73 | static ssize_t mcp4725_store_eeprom(struct device *dev, |
|---|
| 83 | 74 | struct device_attribute *attr, const char *buf, size_t len) |
|---|
| .. | .. |
|---|
| 366 | 357 | .attrs = &mcp4725_attribute_group, |
|---|
| 367 | 358 | }; |
|---|
| 368 | 359 | |
|---|
| 369 | | -#ifdef CONFIG_OF |
|---|
| 370 | 360 | static int mcp4725_probe_dt(struct device *dev, |
|---|
| 371 | 361 | struct mcp4725_platform_data *pdata) |
|---|
| 372 | 362 | { |
|---|
| 373 | | - struct device_node *np = dev->of_node; |
|---|
| 374 | | - |
|---|
| 375 | | - if (!np) |
|---|
| 376 | | - return -ENODEV; |
|---|
| 377 | | - |
|---|
| 378 | 363 | /* 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"); |
|---|
| 380 | 365 | pdata->vref_buffered = |
|---|
| 381 | | - of_property_read_bool(np, "microchip,vref-buffered"); |
|---|
| 366 | + device_property_read_bool(dev, "microchip,vref-buffered"); |
|---|
| 382 | 367 | |
|---|
| 383 | 368 | return 0; |
|---|
| 384 | 369 | } |
|---|
| 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 | 370 | |
|---|
| 393 | 371 | static int mcp4725_probe(struct i2c_client *client, |
|---|
| 394 | 372 | const struct i2c_device_id *id) |
|---|
| .. | .. |
|---|
| 407 | 385 | data = iio_priv(indio_dev); |
|---|
| 408 | 386 | i2c_set_clientdata(client, indio_dev); |
|---|
| 409 | 387 | 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); |
|---|
| 412 | 390 | else |
|---|
| 413 | 391 | data->id = id->driver_data; |
|---|
| 414 | 392 | pdata = dev_get_platdata(&client->dev); |
|---|
| .. | .. |
|---|
| 462 | 440 | goto err_disable_vdd_reg; |
|---|
| 463 | 441 | } |
|---|
| 464 | 442 | |
|---|
| 465 | | - indio_dev->dev.parent = &client->dev; |
|---|
| 466 | 443 | indio_dev->name = id->name; |
|---|
| 467 | 444 | indio_dev->info = &mcp4725_info; |
|---|
| 468 | 445 | indio_dev->channels = &mcp472x_channel[id->driver_data]; |
|---|
| .. | .. |
|---|
| 529 | 506 | }; |
|---|
| 530 | 507 | MODULE_DEVICE_TABLE(i2c, mcp4725_id); |
|---|
| 531 | 508 | |
|---|
| 532 | | -#ifdef CONFIG_OF |
|---|
| 533 | 509 | static const struct of_device_id mcp4725_of_match[] = { |
|---|
| 534 | 510 | { |
|---|
| 535 | 511 | .compatible = "microchip,mcp4725", |
|---|
| .. | .. |
|---|
| 542 | 518 | { } |
|---|
| 543 | 519 | }; |
|---|
| 544 | 520 | MODULE_DEVICE_TABLE(of, mcp4725_of_match); |
|---|
| 545 | | -#endif |
|---|
| 546 | 521 | |
|---|
| 547 | 522 | static struct i2c_driver mcp4725_driver = { |
|---|
| 548 | 523 | .driver = { |
|---|
| 549 | 524 | .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, |
|---|
| 552 | 527 | }, |
|---|
| 553 | 528 | .probe = mcp4725_probe, |
|---|
| 554 | 529 | .remove = mcp4725_remove, |
|---|