1 /* 2 * Copyright (c) 2023 Grinn 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_AD559X_H_ 7 #define ZEPHYR_INCLUDE_DRIVERS_MFD_AD559X_H_ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include <zephyr/device.h> 14 15 #define AD559X_REG_SEQ_ADC 0x02U 16 #define AD559X_REG_ADC_CONFIG 0x04U 17 #define AD559X_REG_LDAC_EN 0x05U 18 #define AD559X_REG_GPIO_PULLDOWN 0x06U 19 #define AD559X_REG_READ_AND_LDAC 0x07U 20 #define AD559X_REG_GPIO_OUTPUT_EN 0x08U 21 #define AD559X_REG_GPIO_SET 0x09U 22 #define AD559X_REG_GPIO_INPUT_EN 0x0AU 23 #define AD559X_REG_PD_REF_CTRL 0x0BU 24 25 #define AD559X_EN_REF BIT(9) 26 27 #define AD559X_PIN_MAX 8U 28 29 /** 30 * @defgroup mdf_interface_ad559x MFD AD559X interface 31 * @ingroup mfd_interfaces 32 * @{ 33 */ 34 35 /** 36 * @brief Check if the chip has a pointer byte map 37 * 38 * @param[in] dev Pointer to MFD device 39 * 40 * @retval true if chip has a pointer byte map, false if it has normal register map 41 */ 42 bool mfd_ad559x_has_pointer_byte_map(const struct device *dev); 43 44 /** 45 * @brief Read raw data from the chip 46 * 47 * @param[in] dev Pointer to MFD device 48 * @param[in] val Pointer to data buffer 49 * @param[in] len Number of bytes to be read 50 * 51 * @retval 0 if success 52 * @retval negative errno if failure 53 */ 54 int mfd_ad559x_read_raw(const struct device *dev, uint8_t *val, size_t len); 55 56 /** 57 * @brief Write raw data to chip 58 * 59 * @param[in] dev Pointer to MFD device 60 * @param[in] val Data to be written 61 * @param[in] len Number of bytes to be written 62 * 63 * @retval 0 if success 64 * @retval negative errno if failure 65 */ 66 int mfd_ad559x_write_raw(const struct device *dev, uint8_t *val, size_t len); 67 68 /** 69 * @brief Read data from provided register 70 * 71 * @param[in] dev Pointer to MFD device 72 * @param[in] reg Register to be read 73 * @param[in] reg_data Additional data passed to selected register 74 * @param[in] val Pointer to data buffer 75 * 76 * @retval 0 if success 77 * @retval negative errno if failure 78 */ 79 int mfd_ad559x_read_reg(const struct device *dev, uint8_t reg, uint8_t reg_data, uint16_t *val); 80 81 /** 82 * @brief Write data to provided register 83 * 84 * @param[in] dev Pointer to MFD device 85 * @param[in] reg Register to be written 86 * @param[in] val Data to be written 87 * 88 * @retval 0 if success 89 * @retval negative errno if failure 90 */ 91 int mfd_ad559x_write_reg(const struct device *dev, uint8_t reg, uint16_t val); 92 93 /** 94 * @brief Read ADC channel data from the chip 95 * 96 * @param[in] dev Pointer to MFD device 97 * @param[in] channel Channel to read 98 * @param[out] result ADC channel value read 99 * 100 * @retval 0 if success 101 * @retval negative errno if failure 102 */ 103 int mfd_ad559x_read_adc_chan(const struct device *dev, uint8_t channel, uint16_t *result); 104 105 /** 106 * @brief Write ADC channel data to the chip 107 * 108 * @param[in] dev Pointer to MFD device 109 * @param[in] channel Channel to write to 110 * @param[in] value DAC channel value 111 * 112 * @retval 0 if success 113 * @retval negative errno if failure 114 */ 115 int mfd_ad559x_write_dac_chan(const struct device *dev, uint8_t channel, uint16_t value); 116 117 /** 118 * @brief Read GPIO port from the chip 119 * 120 * @param[in] dev Pointer to MFD device 121 * @param[in] gpio GPIO to read 122 * @param[in] value DAC channel value 123 * 124 * @retval 0 if success 125 * @retval negative errno if failure 126 */ 127 int mfd_ad559x_gpio_port_get_raw(const struct device *dev, uint8_t gpio, uint16_t *value); 128 /** 129 * @} 130 */ 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_AD559X_H_ */ 137