1 /* 2 * Copyright (c) 2024 Vitrolife A/S 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #ifndef ZEPHYR_DRIVERS_MFD_AD559X_H_ 7 #define ZEPHYR_DRIVERS_MFD_AD559X_H_ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #define DT_DRV_COMPAT adi_ad559x 14 15 #include <zephyr/device.h> 16 #include <zephyr/drivers/gpio.h> 17 18 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) 19 #include <zephyr/drivers/i2c.h> 20 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */ 21 22 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) 23 #include <zephyr/drivers/spi.h> 24 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */ 25 26 #define AD559X_GPIO_READBACK_EN BIT(10) 27 #define AD559X_LDAC_READBACK_EN BIT(6) 28 #define AD559X_REG_SOFTWARE_RESET 0x0FU 29 #define AD559X_SOFTWARE_RESET_MAGIC_VAL 0x5AC 30 #define AD559X_REG_VAL_MASK 0x3FF 31 #define AD559X_REG_RESET_VAL_MASK 0x7FF 32 #define AD559X_REG_SHIFT_VAL 11 33 #define AD559X_REG_READBACK_SHIFT_VAL 2 34 35 struct mfd_ad559x_transfer_function { 36 int (*read_raw)(const struct device *dev, uint8_t *val, size_t len); 37 int (*write_raw)(const struct device *dev, uint8_t *val, size_t len); 38 int (*read_reg)(const struct device *dev, uint8_t reg, uint8_t reg_data, uint16_t *val); 39 int (*write_reg)(const struct device *dev, uint8_t reg, uint16_t val); 40 }; 41 42 struct mfd_ad559x_config { 43 struct gpio_dt_spec reset_gpio; 44 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) 45 struct i2c_dt_spec i2c; 46 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */ 47 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) 48 struct spi_dt_spec spi; 49 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */ 50 int (*bus_init)(const struct device *dev); 51 bool has_pointer_byte_map; 52 }; 53 54 struct mfd_ad559x_data { 55 const struct mfd_ad559x_transfer_function *transfer_function; 56 }; 57 58 int mfd_ad559x_i2c_init(const struct device *dev); 59 int mfd_ad559x_spi_init(const struct device *dev); 60 61 #ifdef __cplusplus 62 } 63 #endif 64 65 #endif /* ZEPHYR_DRIVERS_MFD_AD559X_H_*/ 66