| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AD5593R Digital <-> Analog converters driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2015-2016 Analog Devices Inc. |
|---|
| 5 | 6 | * Author: Paul Cercueil <paul.cercueil@analog.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * Licensed under the GPL-2. |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | |
|---|
| 10 | 9 | #include "ad5592r-base.h" |
|---|
| .. | .. |
|---|
| 12 | 11 | #include <linux/bitops.h> |
|---|
| 13 | 12 | #include <linux/i2c.h> |
|---|
| 14 | 13 | #include <linux/module.h> |
|---|
| 15 | | -#include <linux/of.h> |
|---|
| 16 | | -#include <linux/acpi.h> |
|---|
| 14 | +#include <linux/mod_devicetable.h> |
|---|
| 15 | + |
|---|
| 16 | +#include <asm/unaligned.h> |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | #define AD5593R_MODE_CONF (0 << 4) |
|---|
| 19 | 19 | #define AD5593R_MODE_DAC_WRITE (1 << 4) |
|---|
| .. | .. |
|---|
| 21 | 21 | #define AD5593R_MODE_DAC_READBACK (5 << 4) |
|---|
| 22 | 22 | #define AD5593R_MODE_GPIO_READBACK (6 << 4) |
|---|
| 23 | 23 | #define AD5593R_MODE_REG_READBACK (7 << 4) |
|---|
| 24 | + |
|---|
| 25 | +static int ad5593r_read_word(struct i2c_client *i2c, u8 reg, u16 *value) |
|---|
| 26 | +{ |
|---|
| 27 | + int ret; |
|---|
| 28 | + u8 buf[2]; |
|---|
| 29 | + |
|---|
| 30 | + ret = i2c_smbus_write_byte(i2c, reg); |
|---|
| 31 | + if (ret < 0) |
|---|
| 32 | + return ret; |
|---|
| 33 | + |
|---|
| 34 | + ret = i2c_master_recv(i2c, buf, sizeof(buf)); |
|---|
| 35 | + if (ret < 0) |
|---|
| 36 | + return ret; |
|---|
| 37 | + |
|---|
| 38 | + *value = get_unaligned_be16(buf); |
|---|
| 39 | + |
|---|
| 40 | + return 0; |
|---|
| 41 | +} |
|---|
| 24 | 42 | |
|---|
| 25 | 43 | static int ad5593r_write_dac(struct ad5592r_state *st, unsigned chan, u16 value) |
|---|
| 26 | 44 | { |
|---|
| .. | .. |
|---|
| 40 | 58 | if (val < 0) |
|---|
| 41 | 59 | return (int) val; |
|---|
| 42 | 60 | |
|---|
| 43 | | - val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_ADC_READBACK); |
|---|
| 44 | | - if (val < 0) |
|---|
| 45 | | - return (int) val; |
|---|
| 46 | | - |
|---|
| 47 | | - *value = (u16) val; |
|---|
| 48 | | - |
|---|
| 49 | | - return 0; |
|---|
| 61 | + return ad5593r_read_word(i2c, AD5593R_MODE_ADC_READBACK, value); |
|---|
| 50 | 62 | } |
|---|
| 51 | 63 | |
|---|
| 52 | 64 | static int ad5593r_reg_write(struct ad5592r_state *st, u8 reg, u16 value) |
|---|
| .. | .. |
|---|
| 60 | 72 | static int ad5593r_reg_read(struct ad5592r_state *st, u8 reg, u16 *value) |
|---|
| 61 | 73 | { |
|---|
| 62 | 74 | struct i2c_client *i2c = to_i2c_client(st->dev); |
|---|
| 63 | | - s32 val; |
|---|
| 64 | 75 | |
|---|
| 65 | | - val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_REG_READBACK | reg); |
|---|
| 66 | | - if (val < 0) |
|---|
| 67 | | - return (int) val; |
|---|
| 68 | | - |
|---|
| 69 | | - *value = (u16) val; |
|---|
| 70 | | - |
|---|
| 71 | | - return 0; |
|---|
| 76 | + return ad5593r_read_word(i2c, AD5593R_MODE_REG_READBACK | reg, value); |
|---|
| 72 | 77 | } |
|---|
| 73 | 78 | |
|---|
| 74 | 79 | static int ad5593r_gpio_read(struct ad5592r_state *st, u8 *value) |
|---|
| 75 | 80 | { |
|---|
| 76 | 81 | struct i2c_client *i2c = to_i2c_client(st->dev); |
|---|
| 77 | | - s32 val; |
|---|
| 82 | + u16 val; |
|---|
| 83 | + int ret; |
|---|
| 78 | 84 | |
|---|
| 79 | | - val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_GPIO_READBACK); |
|---|
| 80 | | - if (val < 0) |
|---|
| 81 | | - return (int) val; |
|---|
| 85 | + ret = ad5593r_read_word(i2c, AD5593R_MODE_GPIO_READBACK, &val); |
|---|
| 86 | + if (ret) |
|---|
| 87 | + return ret; |
|---|
| 82 | 88 | |
|---|
| 83 | 89 | *value = (u8) val; |
|---|
| 84 | 90 | |
|---|
| .. | .. |
|---|
| 125 | 131 | static struct i2c_driver ad5593r_driver = { |
|---|
| 126 | 132 | .driver = { |
|---|
| 127 | 133 | .name = "ad5593r", |
|---|
| 128 | | - .of_match_table = of_match_ptr(ad5593r_of_match), |
|---|
| 129 | | - .acpi_match_table = ACPI_PTR(ad5593r_acpi_match), |
|---|
| 134 | + .of_match_table = ad5593r_of_match, |
|---|
| 135 | + .acpi_match_table = ad5593r_acpi_match, |
|---|
| 130 | 136 | }, |
|---|
| 131 | 137 | .probe = ad5593r_i2c_probe, |
|---|
| 132 | 138 | .remove = ad5593r_i2c_remove, |
|---|
| .. | .. |
|---|
| 135 | 141 | module_i2c_driver(ad5593r_driver); |
|---|
| 136 | 142 | |
|---|
| 137 | 143 | MODULE_AUTHOR("Paul Cercueil <paul.cercueil@analog.com>"); |
|---|
| 138 | | -MODULE_DESCRIPTION("Analog Devices AD5592R multi-channel converters"); |
|---|
| 144 | +MODULE_DESCRIPTION("Analog Devices AD5593R multi-channel converters"); |
|---|
| 139 | 145 | MODULE_LICENSE("GPL v2"); |
|---|