1 /*
2  * Copyright (c) 2024 SILA Embedded Solutions GmbH
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_MAX31790_H_
7 #define ZEPHYR_INCLUDE_DRIVERS_MFD_MAX31790_H_
8 
9 #include <zephyr/sys/util.h>
10 #include <zephyr/sys/util_macro.h>
11 
12 #define MAX31790_OSCILLATOR_FREQUENCY_IN_HZ 32768
13 #define MAX31790_PWMTARGETDUTYCYCLE_MAXIMUM ((1 << 9) - 1)
14 #define MAX31790_TACHTARGETCOUNT_MAXIMUM    ((1 << 11) - 1)
15 #define MAX31790_CHANNEL_COUNT              6
16 #define MAX31790_RESET_TIMEOUT_IN_US        1000
17 
18 #define MAX37190_REGISTER_GLOBALCONFIGURATION               0x00
19 #define MAX37190_REGISTER_PWMFREQUENCY                      0x01
20 #define MAX37190_REGISTER_FANCONFIGURATION(channel)         (0x02 + channel)
21 #define MAX31790_REGISTER_FANDYNAMICS(channel)              (0x08 + channel)
22 #define MAX37190_REGISTER_FANFAULTSTATUS1                   0x11
23 #define MAX37190_REGISTER_TACHCOUNTMSB(channel)             (0x18 + 2 * channel)
24 #define MAX31790_REGISTER_PWMOUTTARGETDUTYCYCLEMSB(channel) (0x40 + 2 * channel)
25 #define MAX31790_REGISTER_TACHTARGETCOUNTMSB(channel)       (0x50 + 2 * channel)
26 
27 #define MAX37190_GLOBALCONFIGURATION_STANDBY_BIT             BIT(7)
28 #define MAX37190_GLOBALCONFIGURATION_RESET_BIT               BIT(6)
29 #define MAX37190_GLOBALCONFIGURATION_BUSTIMEOUT_BIT          BIT(5)
30 #define MAX37190_GLOBALCONFIGURATION_OSCILLATORSELECTION_BIT BIT(3)
31 #define MAX37190_GLOBALCONFIGURATION_I2CWATCHDOGSTATUS_BIT   BIT(0)
32 #define MAX37190_FANXCONFIGURATION_MONITOR_BIT               BIT(4)
33 #define MAX37190_FANXCONFIGURATION_TACHINPUTENABLED_BIT      BIT(3)
34 #define MAX37190_FANXCONFIGURATION_LOCKEDROTOR_BIT           BIT(2)
35 #define MAX37190_FANXCONFIGURATION_LOCKEDROTORPOLARITY_BIT   BIT(1)
36 #define MAX37190_FANXCONFIGURATION_TACH_BIT                  BIT(0)
37 #define MAX37190_FANXCONFIGURATION_MODE_BIT                  BIT(7)
38 #define MAX37190_FANXDYNAMICS_ASYMMETRICRATEOFCHANGE_BIT     BIT(1)
39 
40 #define MAX37190_GLOBALCONFIGURATION_I2CWATCHDOG_LENGTH 2
41 #define MAX37190_GLOBALCONFIGURATION_I2CWATCHDOG_POS    1
42 #define MAX37190_FANXDYNAMICS_SPEEDRANGE_LENGTH         3
43 #define MAX37190_FANXDYNAMICS_SPEEDRANGE_POS            5
44 #define MAX37190_FANXDYNAMICS_PWMRATEOFCHANGE_LENGTH    3
45 #define MAX37190_FANXDYNAMICS_PWMRATEOFCHANGE_POS       2
46 #define MAX37190_PWMFREQUENCY_PWM_LENGTH                4
47 #define MAX37190_PWMFREQUENCY_PWM4TO6_POS               4
48 #define MAX37190_PWMFREQUENCY_PWM1TO3_LENGTH            4
49 #define MAX37190_PWMFREQUENCY_PWM1TO3_POS               0
50 #define MAX37190_FANXCONFIGURATION_SPINUP_LENGTH        2
51 #define MAX37190_FANXCONFIGURATION_SPINUP_POS           5
52 
53 #define MAX31790_FANXDYNAMCIS_SPEED_RANGE_GET(value)                                               \
54 	FIELD_GET(GENMASK(MAX37190_FANXDYNAMICS_SPEEDRANGE_LENGTH +                                \
55 				  MAX37190_FANXDYNAMICS_SPEEDRANGE_POS - 1,                        \
56 			  MAX37190_FANXDYNAMICS_SPEEDRANGE_POS),                                   \
57 		  value)
58 
59 #define MAX31790_FLAG_SPEED_RANGE_GET(flags)                                                       \
60 	FIELD_GET(GENMASK(MAX37190_FANXDYNAMICS_SPEEDRANGE_LENGTH +                                \
61 				  PWM_MAX31790_FLAG_SPEED_RANGE_POS - 1,                           \
62 			  PWM_MAX31790_FLAG_SPEED_RANGE_POS),                                      \
63 		  flags)
64 #define MAX31790_FLAG_PWM_RATE_OF_CHANGE_GET(flags)                                                \
65 	FIELD_GET(GENMASK(MAX37190_FANXDYNAMICS_PWMRATEOFCHANGE_LENGTH +                           \
66 				  PWM_MAX31790_FLAG_PWM_RATE_OF_CHANGE_POS - 1,                    \
67 			  PWM_MAX31790_FLAG_PWM_RATE_OF_CHANGE_POS),                               \
68 		  flags)
69 
70 #endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_MAX31790_H_ */
71