Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * This file is part of AD5686 DAC driver |
| 4 | * |
| 5 | * Copyright 2018 Analog Devices Inc. |
| 6 | */ |
| 7 | |
| 8 | #ifndef __DRIVERS_IIO_DAC_AD5686_H__ |
| 9 | #define __DRIVERS_IIO_DAC_AD5686_H__ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/cache.h> |
| 13 | #include <linux/mutex.h> |
| 14 | #include <linux/kernel.h> |
| 15 | |
| 16 | #define AD5686_ADDR(x) ((x) << 16) |
| 17 | #define AD5686_CMD(x) ((x) << 20) |
| 18 | |
| 19 | #define AD5686_ADDR_DAC(chan) (0x1 << (chan)) |
| 20 | #define AD5686_ADDR_ALL_DAC 0xF |
| 21 | |
| 22 | #define AD5686_CMD_NOOP 0x0 |
| 23 | #define AD5686_CMD_WRITE_INPUT_N 0x1 |
| 24 | #define AD5686_CMD_UPDATE_DAC_N 0x2 |
| 25 | #define AD5686_CMD_WRITE_INPUT_N_UPDATE_N 0x3 |
| 26 | #define AD5686_CMD_POWERDOWN_DAC 0x4 |
| 27 | #define AD5686_CMD_LDAC_MASK 0x5 |
| 28 | #define AD5686_CMD_RESET 0x6 |
| 29 | #define AD5686_CMD_INTERNAL_REFER_SETUP 0x7 |
| 30 | #define AD5686_CMD_DAISY_CHAIN_ENABLE 0x8 |
| 31 | #define AD5686_CMD_READBACK_ENABLE 0x9 |
| 32 | |
| 33 | #define AD5686_LDAC_PWRDN_NONE 0x0 |
| 34 | #define AD5686_LDAC_PWRDN_1K 0x1 |
| 35 | #define AD5686_LDAC_PWRDN_100K 0x2 |
| 36 | #define AD5686_LDAC_PWRDN_3STATE 0x3 |
| 37 | |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 38 | #define AD5686_CMD_CONTROL_REG 0x4 |
| 39 | #define AD5693_REF_BIT_MSK BIT(12) |
| 40 | |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 41 | /** |
| 42 | * ad5686_supported_device_ids: |
| 43 | */ |
| 44 | enum ad5686_supported_device_ids { |
Stefan Popa | 4177381 | 2018-04-11 14:53:39 +0300 | [diff] [blame] | 45 | ID_AD5671R, |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 46 | ID_AD5672R, |
Stefan Popa | 4177381 | 2018-04-11 14:53:39 +0300 | [diff] [blame] | 47 | ID_AD5675R, |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 48 | ID_AD5676, |
| 49 | ID_AD5676R, |
| 50 | ID_AD5684, |
| 51 | ID_AD5684R, |
| 52 | ID_AD5685R, |
| 53 | ID_AD5686, |
| 54 | ID_AD5686R, |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 55 | ID_AD5691R, |
| 56 | ID_AD5692R, |
| 57 | ID_AD5693, |
| 58 | ID_AD5693R, |
Stefan Popa | 4177381 | 2018-04-11 14:53:39 +0300 | [diff] [blame] | 59 | ID_AD5694, |
| 60 | ID_AD5694R, |
| 61 | ID_AD5695R, |
| 62 | ID_AD5696, |
| 63 | ID_AD5696R, |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 64 | }; |
| 65 | |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 66 | enum ad5686_regmap_type { |
| 67 | AD5686_REGMAP, |
| 68 | AD5693_REGMAP |
| 69 | }; |
| 70 | |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 71 | struct ad5686_state; |
| 72 | |
| 73 | typedef int (*ad5686_write_func)(struct ad5686_state *st, |
| 74 | u8 cmd, u8 addr, u16 val); |
| 75 | |
| 76 | typedef int (*ad5686_read_func)(struct ad5686_state *st, u8 addr); |
| 77 | |
| 78 | /** |
| 79 | * struct ad5686_chip_info - chip specific information |
| 80 | * @int_vref_mv: AD5620/40/60: the internal reference voltage |
| 81 | * @num_channels: number of channels |
| 82 | * @channel: channel specification |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 83 | * @regmap_type: register map layout variant |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 84 | */ |
| 85 | |
| 86 | struct ad5686_chip_info { |
| 87 | u16 int_vref_mv; |
| 88 | unsigned int num_channels; |
| 89 | struct iio_chan_spec *channels; |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 90 | enum ad5686_regmap_type regmap_type; |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * struct ad5446_state - driver instance specific data |
| 95 | * @spi: spi_device |
| 96 | * @chip_info: chip model specific constants, available modes etc |
| 97 | * @reg: supply regulator |
| 98 | * @vref_mv: actual reference voltage used |
| 99 | * @pwr_down_mask: power down mask |
| 100 | * @pwr_down_mode: current power down mode |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 101 | * @use_internal_vref: set to true if the internal reference voltage is used |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 102 | * @data: spi transfer buffers |
| 103 | */ |
| 104 | |
| 105 | struct ad5686_state { |
| 106 | struct device *dev; |
| 107 | const struct ad5686_chip_info *chip_info; |
| 108 | struct regulator *reg; |
| 109 | unsigned short vref_mv; |
| 110 | unsigned int pwr_down_mask; |
| 111 | unsigned int pwr_down_mode; |
| 112 | ad5686_write_func write; |
| 113 | ad5686_read_func read; |
Stefan Popa | be1b24d | 2018-05-18 18:22:50 +0300 | [diff] [blame^] | 114 | bool use_internal_vref; |
Stefan Popa | 0357e48 | 2018-04-11 14:53:17 +0300 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * DMA (thus cache coherency maintenance) requires the |
| 118 | * transfer buffers to live in their own cache lines. |
| 119 | */ |
| 120 | |
| 121 | union { |
| 122 | __be32 d32; |
| 123 | __be16 d16; |
| 124 | u8 d8[4]; |
| 125 | } data[3] ____cacheline_aligned; |
| 126 | }; |
| 127 | |
| 128 | |
| 129 | int ad5686_probe(struct device *dev, |
| 130 | enum ad5686_supported_device_ids chip_type, |
| 131 | const char *name, ad5686_write_func write, |
| 132 | ad5686_read_func read); |
| 133 | |
| 134 | int ad5686_remove(struct device *dev); |
| 135 | |
| 136 | |
| 137 | #endif /* __DRIVERS_IIO_DAC_AD5686_H__ */ |