| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * mcp3422.c - driver for the Microchip mcp3421/2/3/4/5/6/7/8 chip family |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com> |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf |
|---|
| 8 | | - * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf |
|---|
| 9 | | - * http://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf |
|---|
| 9 | + * https://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf |
|---|
| 10 | + * https://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf |
|---|
| 10 | 11 | * |
|---|
| 11 | 12 | * This driver exports the value of analog input voltage to sysfs, the |
|---|
| 12 | 13 | * voltage unit is nV. |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 15 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 16 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 17 | | - * (at your option) any later version. |
|---|
| 18 | 14 | */ |
|---|
| 19 | 15 | |
|---|
| 20 | 16 | #include <linux/err.h> |
|---|
| 21 | 17 | #include <linux/i2c.h> |
|---|
| 22 | 18 | #include <linux/module.h> |
|---|
| 19 | +#include <linux/mod_devicetable.h> |
|---|
| 23 | 20 | #include <linux/delay.h> |
|---|
| 24 | 21 | #include <linux/sysfs.h> |
|---|
| 25 | | -#include <linux/of.h> |
|---|
| 22 | +#include <asm/unaligned.h> |
|---|
| 26 | 23 | |
|---|
| 27 | 24 | #include <linux/iio/iio.h> |
|---|
| 28 | 25 | #include <linux/iio/sysfs.h> |
|---|
| .. | .. |
|---|
| 117 | 114 | |
|---|
| 118 | 115 | if (sample_rate == MCP3422_SRATE_3) { |
|---|
| 119 | 116 | ret = i2c_master_recv(adc->i2c, buf, 4); |
|---|
| 120 | | - temp = buf[0] << 16 | buf[1] << 8 | buf[2]; |
|---|
| 117 | + temp = get_unaligned_be24(&buf[0]); |
|---|
| 121 | 118 | *config = buf[3]; |
|---|
| 122 | 119 | } else { |
|---|
| 123 | 120 | ret = i2c_master_recv(adc->i2c, buf, 3); |
|---|
| 124 | | - temp = buf[0] << 8 | buf[1]; |
|---|
| 121 | + temp = get_unaligned_be16(&buf[0]); |
|---|
| 125 | 122 | *config = buf[2]; |
|---|
| 126 | 123 | } |
|---|
| 127 | 124 | |
|---|
| .. | .. |
|---|
| 354 | 351 | |
|---|
| 355 | 352 | mutex_init(&adc->lock); |
|---|
| 356 | 353 | |
|---|
| 357 | | - indio_dev->dev.parent = &client->dev; |
|---|
| 358 | | - indio_dev->dev.of_node = client->dev.of_node; |
|---|
| 359 | 354 | indio_dev->name = dev_name(&client->dev); |
|---|
| 360 | 355 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 361 | 356 | indio_dev->info = &mcp3422_info; |
|---|
| .. | .. |
|---|
| 411 | 406 | }; |
|---|
| 412 | 407 | MODULE_DEVICE_TABLE(i2c, mcp3422_id); |
|---|
| 413 | 408 | |
|---|
| 414 | | -#ifdef CONFIG_OF |
|---|
| 415 | 409 | static const struct of_device_id mcp3422_of_match[] = { |
|---|
| 416 | 410 | { .compatible = "mcp3422" }, |
|---|
| 417 | 411 | { } |
|---|
| 418 | 412 | }; |
|---|
| 419 | 413 | MODULE_DEVICE_TABLE(of, mcp3422_of_match); |
|---|
| 420 | | -#endif |
|---|
| 421 | 414 | |
|---|
| 422 | 415 | static struct i2c_driver mcp3422_driver = { |
|---|
| 423 | 416 | .driver = { |
|---|
| 424 | 417 | .name = "mcp3422", |
|---|
| 425 | | - .of_match_table = of_match_ptr(mcp3422_of_match), |
|---|
| 418 | + .of_match_table = mcp3422_of_match, |
|---|
| 426 | 419 | }, |
|---|
| 427 | 420 | .probe = mcp3422_probe, |
|---|
| 428 | 421 | .id_table = mcp3422_id, |
|---|