1 /*
2  * Copyright (c) 2023 Grinn
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_AD5592_H_
7 #define ZEPHYR_INCLUDE_DRIVERS_MFD_AD5592_H_
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #include <zephyr/device.h>
14 
15 #define AD5592_REG_SEQ_ADC 0x02U
16 #define AD5592_REG_ADC_CONFIG 0x04U
17 #define AD5592_REG_LDAC_EN 0x05U
18 #define AD5592_REG_GPIO_PULLDOWN 0x06U
19 #define AD5592_REG_READ_AND_LDAC 0x07U
20 #define AD5592_REG_GPIO_OUTPUT_EN 0x08U
21 #define AD5592_REG_GPIO_SET 0x09U
22 #define AD5592_REG_GPIO_INPUT_EN 0x0AU
23 #define AD5592_REG_PD_REF_CTRL 0x0BU
24 
25 #define AD5592_EN_REF BIT(9)
26 
27 #define AD5592_PIN_MAX 8U
28 
29 /**
30  * @defgroup mdf_interface_ad5592 MFD AD5592 interface
31  * @ingroup mfd_interfaces
32  * @{
33  */
34 
35 /**
36  * @brief Read raw data from the chip
37  *
38  * @param[in] dev Pointer to MFD device
39  * @param[in] val Pointer to data buffer
40  *
41  * @retval 0 if success
42  * @retval negative errno if failure
43  */
44 int mfd_ad5592_read_raw(const struct device *dev, uint16_t *val);
45 
46 /**
47  * @brief Write raw data to chip
48  *
49  * @param[in] dev Pointer to MFD device
50  * @param[in] val Data to be written
51  *
52  *
53  * @retval 0 if success
54  * @retval negative errno if failure
55  */
56 int mfd_ad5592_write_raw(const struct device *dev, uint16_t val);
57 
58 /**
59  * @brief Read data from provided register
60  *
61  * @param[in] dev Pointer to MFD device
62  * @param[in] reg Register to be read
63  * @param[in] reg_data Additional data passed to selected register
64  * @param[in] val Pointer to data buffer
65  *
66  * @retval 0 if success
67  * @retval negative errno if failure
68  */
69 int mfd_ad5592_read_reg(const struct device *dev, uint8_t reg, uint8_t reg_data, uint16_t *val);
70 
71 /**
72  * @brief Write data to provided register
73  *
74  * @param[in] dev Pointer to MFD device
75  * @param[in] reg Register to be written
76  * @param[in] val Data to be written
77  *
78  * @retval 0 if success
79  * @retval negative errno if failure
80  */
81 int mfd_ad5592_write_reg(const struct device *dev, uint8_t reg, uint16_t val);
82 
83 /**
84  * @}
85  */
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_AD5952_H_ */
92