| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
#ifndef _LINUX_AD5446_H |
| 3 |
#define _LINUX_AD5446_H |
| 4 |
|
| 5 |
#include <linux/bits.h> |
| 6 |
#include <linux/compiler.h> |
| 7 |
#include <linux/iio/iio.h> |
| 8 |
#include <linux/mutex.h> |
| 9 |
#include <linux/types.h> |
| 10 |
|
| 11 |
struct device; |
| 12 |
|
| 13 |
extern const struct iio_chan_spec_ext_info ad5446_ext_info_powerdown[]; |
| 14 |
|
| 15 |
#define _AD5446_CHANNEL(bits, storage, _shift, ext) { \ |
| 16 |
.type = IIO_VOLTAGE, \ |
| 17 |
.indexed = 1, \ |
| 18 |
.output = 1, \ |
| 19 |
.channel = 0, \ |
| 20 |
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 21 |
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
| 22 |
.scan_type = { \ |
| 23 |
.sign = 'u', \ |
| 24 |
.realbits = (bits), \ |
| 25 |
.storagebits = (storage), \ |
| 26 |
.shift = (_shift), \ |
| 27 |
}, \ |
| 28 |
.ext_info = (ext), \ |
| 29 |
} |
| 30 |
|
| 31 |
#define AD5446_CHANNEL(bits, storage, shift) \ |
| 32 |
_AD5446_CHANNEL(bits, storage, shift, NULL) |
| 33 |
|
| 34 |
#define AD5446_CHANNEL_POWERDOWN(bits, storage, shift) \ |
| 35 |
_AD5446_CHANNEL(bits, storage, shift, ad5446_ext_info_powerdown) |
| 36 |
|
| 37 |
/** |
| 38 |
* struct ad5446_state - driver instance specific data |
| 39 |
* @dev: this device |
| 40 |
* @chip_info: chip model specific constants, available modes etc |
| 41 |
* @vref_mv: actual reference voltage used |
| 42 |
* @cached_val: store/retrieve values during power down |
| 43 |
* @pwr_down_mode: power down mode (1k, 100k or tristate) |
| 44 |
* @pwr_down: true if the device is in power down |
| 45 |
* @lock: lock to protect the data buffer during write ops |
| 46 |
*/ |
| 47 |
struct ad5446_state { |
| 48 |
struct device *dev; |
| 49 |
const struct ad5446_chip_info *chip_info; |
| 50 |
unsigned short vref_mv; |
| 51 |
unsigned int cached_val; |
| 52 |
unsigned int pwr_down_mode; |
| 53 |
unsigned int pwr_down; |
| 54 |
/* mutex to protect device shared data */ |
| 55 |
struct mutex lock; |
| 56 |
union { |
| 57 |
__be16 d16; |
| 58 |
u8 d24[3]; |
| 59 |
} __aligned(IIO_DMA_MINALIGN); |
| 60 |
}; |
| 61 |
|
| 62 |
/** |
| 63 |
* struct ad5446_chip_info - chip specific information |
| 64 |
* @channel: channel spec for the DAC |
| 65 |
* @int_vref_mv: AD5620/40/60: the internal reference voltage |
| 66 |
* @write: chip specific helper function to write to the register |
| 67 |
*/ |
| 68 |
struct ad5446_chip_info { |
| 69 |
struct iio_chan_spec channel; |
| 70 |
u16 int_vref_mv; |
| 71 |
int (*write)(struct ad5446_state *st, unsigned int val); |
| 72 |
}; |
| 73 |
|
| 74 |
int ad5446_probe(struct device *dev, const char *name, |
| 75 |
const struct ad5446_chip_info *chip_info); |
| 76 |
|
| 77 |
#endif |