| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ti-dac5571.c - Texas Instruments 8/10/12-bit 1/4-channel DAC driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2018 Prevas A/S |
|---|
| 5 | 6 | * |
|---|
| 6 | | - * http://www.ti.com/lit/ds/symlink/dac5571.pdf |
|---|
| 7 | | - * http://www.ti.com/lit/ds/symlink/dac6571.pdf |
|---|
| 8 | | - * http://www.ti.com/lit/ds/symlink/dac7571.pdf |
|---|
| 9 | | - * http://www.ti.com/lit/ds/symlink/dac5574.pdf |
|---|
| 10 | | - * http://www.ti.com/lit/ds/symlink/dac6574.pdf |
|---|
| 11 | | - * http://www.ti.com/lit/ds/symlink/dac7574.pdf |
|---|
| 12 | | - * http://www.ti.com/lit/ds/symlink/dac5573.pdf |
|---|
| 13 | | - * http://www.ti.com/lit/ds/symlink/dac6573.pdf |
|---|
| 14 | | - * http://www.ti.com/lit/ds/symlink/dac7573.pdf |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 17 | | - * it under the terms of the GNU General Public License (version 2) as |
|---|
| 18 | | - * published by the Free Software Foundation. |
|---|
| 7 | + * https://www.ti.com/lit/ds/symlink/dac5571.pdf |
|---|
| 8 | + * https://www.ti.com/lit/ds/symlink/dac6571.pdf |
|---|
| 9 | + * https://www.ti.com/lit/ds/symlink/dac7571.pdf |
|---|
| 10 | + * https://www.ti.com/lit/ds/symlink/dac5574.pdf |
|---|
| 11 | + * https://www.ti.com/lit/ds/symlink/dac6574.pdf |
|---|
| 12 | + * https://www.ti.com/lit/ds/symlink/dac7574.pdf |
|---|
| 13 | + * https://www.ti.com/lit/ds/symlink/dac5573.pdf |
|---|
| 14 | + * https://www.ti.com/lit/ds/symlink/dac6573.pdf |
|---|
| 15 | + * https://www.ti.com/lit/ds/symlink/dac7573.pdf |
|---|
| 19 | 16 | */ |
|---|
| 20 | 17 | |
|---|
| 21 | 18 | #include <linux/iio/iio.h> |
|---|
| 22 | 19 | #include <linux/i2c.h> |
|---|
| 23 | 20 | #include <linux/module.h> |
|---|
| 24 | | -#include <linux/of_device.h> |
|---|
| 25 | | -#include <linux/of.h> |
|---|
| 21 | +#include <linux/mod_devicetable.h> |
|---|
| 26 | 22 | #include <linux/regulator/consumer.h> |
|---|
| 27 | 23 | |
|---|
| 28 | 24 | enum chip_id { |
|---|
| .. | .. |
|---|
| 50 | 46 | struct mutex lock; |
|---|
| 51 | 47 | struct regulator *vref; |
|---|
| 52 | 48 | u16 val[4]; |
|---|
| 53 | | - bool powerdown; |
|---|
| 54 | | - u8 powerdown_mode; |
|---|
| 49 | + bool powerdown[4]; |
|---|
| 50 | + u8 powerdown_mode[4]; |
|---|
| 55 | 51 | struct dac5571_spec const *spec; |
|---|
| 56 | 52 | int (*dac5571_cmd)(struct dac5571_data *data, int channel, u16 val); |
|---|
| 57 | 53 | int (*dac5571_pwrdwn)(struct dac5571_data *data, int channel, u8 pwrdwn); |
|---|
| .. | .. |
|---|
| 128 | 124 | { |
|---|
| 129 | 125 | struct dac5571_data *data = iio_priv(indio_dev); |
|---|
| 130 | 126 | |
|---|
| 131 | | - return data->powerdown_mode; |
|---|
| 127 | + return data->powerdown_mode[chan->channel]; |
|---|
| 132 | 128 | } |
|---|
| 133 | 129 | |
|---|
| 134 | 130 | static int dac5571_set_powerdown_mode(struct iio_dev *indio_dev, |
|---|
| .. | .. |
|---|
| 138 | 134 | struct dac5571_data *data = iio_priv(indio_dev); |
|---|
| 139 | 135 | int ret = 0; |
|---|
| 140 | 136 | |
|---|
| 141 | | - if (data->powerdown_mode == mode) |
|---|
| 137 | + if (data->powerdown_mode[chan->channel] == mode) |
|---|
| 142 | 138 | return 0; |
|---|
| 143 | 139 | |
|---|
| 144 | 140 | mutex_lock(&data->lock); |
|---|
| 145 | | - if (data->powerdown) { |
|---|
| 141 | + if (data->powerdown[chan->channel]) { |
|---|
| 146 | 142 | ret = data->dac5571_pwrdwn(data, chan->channel, |
|---|
| 147 | 143 | DAC5571_POWERDOWN(mode)); |
|---|
| 148 | 144 | if (ret) |
|---|
| 149 | 145 | goto out; |
|---|
| 150 | 146 | } |
|---|
| 151 | | - data->powerdown_mode = mode; |
|---|
| 147 | + data->powerdown_mode[chan->channel] = mode; |
|---|
| 152 | 148 | |
|---|
| 153 | 149 | out: |
|---|
| 154 | 150 | mutex_unlock(&data->lock); |
|---|
| .. | .. |
|---|
| 170 | 166 | { |
|---|
| 171 | 167 | struct dac5571_data *data = iio_priv(indio_dev); |
|---|
| 172 | 168 | |
|---|
| 173 | | - return sprintf(buf, "%d\n", data->powerdown); |
|---|
| 169 | + return sprintf(buf, "%d\n", data->powerdown[chan->channel]); |
|---|
| 174 | 170 | } |
|---|
| 175 | 171 | |
|---|
| 176 | 172 | static ssize_t dac5571_write_powerdown(struct iio_dev *indio_dev, |
|---|
| .. | .. |
|---|
| 186 | 182 | if (ret) |
|---|
| 187 | 183 | return ret; |
|---|
| 188 | 184 | |
|---|
| 189 | | - if (data->powerdown == powerdown) |
|---|
| 185 | + if (data->powerdown[chan->channel] == powerdown) |
|---|
| 190 | 186 | return len; |
|---|
| 191 | 187 | |
|---|
| 192 | 188 | mutex_lock(&data->lock); |
|---|
| 193 | 189 | if (powerdown) |
|---|
| 194 | 190 | ret = data->dac5571_pwrdwn(data, chan->channel, |
|---|
| 195 | | - DAC5571_POWERDOWN(data->powerdown_mode)); |
|---|
| 191 | + DAC5571_POWERDOWN(data->powerdown_mode[chan->channel])); |
|---|
| 196 | 192 | else |
|---|
| 197 | | - ret = data->dac5571_cmd(data, chan->channel, data->val[0]); |
|---|
| 193 | + ret = data->dac5571_cmd(data, chan->channel, |
|---|
| 194 | + data->val[chan->channel]); |
|---|
| 198 | 195 | if (ret) |
|---|
| 199 | 196 | goto out; |
|---|
| 200 | 197 | |
|---|
| 201 | | - data->powerdown = powerdown; |
|---|
| 198 | + data->powerdown[chan->channel] = powerdown; |
|---|
| 202 | 199 | |
|---|
| 203 | 200 | out: |
|---|
| 204 | 201 | mutex_unlock(&data->lock); |
|---|
| .. | .. |
|---|
| 212 | 209 | .name = "powerdown", |
|---|
| 213 | 210 | .read = dac5571_read_powerdown, |
|---|
| 214 | 211 | .write = dac5571_write_powerdown, |
|---|
| 215 | | - .shared = IIO_SHARED_BY_TYPE, |
|---|
| 212 | + .shared = IIO_SEPARATE, |
|---|
| 216 | 213 | }, |
|---|
| 217 | | - IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, &dac5571_powerdown_mode), |
|---|
| 214 | + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &dac5571_powerdown_mode), |
|---|
| 218 | 215 | IIO_ENUM_AVAILABLE("powerdown_mode", &dac5571_powerdown_mode), |
|---|
| 219 | 216 | {}, |
|---|
| 220 | 217 | }; |
|---|
| .. | .. |
|---|
| 279 | 276 | if (val >= (1 << data->spec->resolution) || val < 0) |
|---|
| 280 | 277 | return -EINVAL; |
|---|
| 281 | 278 | |
|---|
| 282 | | - if (data->powerdown) |
|---|
| 279 | + if (data->powerdown[chan->channel]) |
|---|
| 283 | 280 | return -EBUSY; |
|---|
| 284 | 281 | |
|---|
| 285 | 282 | mutex_lock(&data->lock); |
|---|
| .. | .. |
|---|
| 324 | 321 | i2c_set_clientdata(client, indio_dev); |
|---|
| 325 | 322 | data->client = client; |
|---|
| 326 | 323 | |
|---|
| 327 | | - indio_dev->dev.parent = dev; |
|---|
| 328 | | - indio_dev->dev.of_node = client->dev.of_node; |
|---|
| 329 | 324 | indio_dev->info = &dac5571_info; |
|---|
| 330 | 325 | indio_dev->name = id->name; |
|---|
| 331 | 326 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| .. | .. |
|---|
| 389 | 384 | return 0; |
|---|
| 390 | 385 | } |
|---|
| 391 | 386 | |
|---|
| 392 | | -#ifdef CONFIG_OF |
|---|
| 393 | 387 | static const struct of_device_id dac5571_of_id[] = { |
|---|
| 394 | 388 | {.compatible = "ti,dac5571"}, |
|---|
| 395 | 389 | {.compatible = "ti,dac6571"}, |
|---|
| .. | .. |
|---|
| 403 | 397 | {} |
|---|
| 404 | 398 | }; |
|---|
| 405 | 399 | MODULE_DEVICE_TABLE(of, dac5571_of_id); |
|---|
| 406 | | -#endif |
|---|
| 407 | 400 | |
|---|
| 408 | 401 | static const struct i2c_device_id dac5571_id[] = { |
|---|
| 409 | 402 | {"dac5571", single_8bit}, |
|---|
| .. | .. |
|---|
| 422 | 415 | static struct i2c_driver dac5571_driver = { |
|---|
| 423 | 416 | .driver = { |
|---|
| 424 | 417 | .name = "ti-dac5571", |
|---|
| 418 | + .of_match_table = dac5571_of_id, |
|---|
| 425 | 419 | }, |
|---|
| 426 | 420 | .probe = dac5571_probe, |
|---|
| 427 | 421 | .remove = dac5571_remove, |
|---|
| .. | .. |
|---|
| 429 | 423 | }; |
|---|
| 430 | 424 | module_i2c_driver(dac5571_driver); |
|---|
| 431 | 425 | |
|---|
| 432 | | -MODULE_AUTHOR("Sean Nyekjaer <sean.nyekjaer@prevas.dk>"); |
|---|
| 426 | +MODULE_AUTHOR("Sean Nyekjaer <sean@geanix.dk>"); |
|---|
| 433 | 427 | MODULE_DESCRIPTION("Texas Instruments 8/10/12-bit 1/4-channel DAC driver"); |
|---|
| 434 | 428 | MODULE_LICENSE("GPL v2"); |
|---|