1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __DT_POWER_DELIVERY_H 3 #define __DT_POWER_DELIVERY_H 4 5 /* Power delivery Power Data Object definitions */ 6 #define PDO_TYPE_FIXED 0 7 #define PDO_TYPE_BATT 1 8 #define PDO_TYPE_VAR 2 9 #define PDO_TYPE_APDO 3 10 11 #define PDO_TYPE_SHIFT 30 12 #define PDO_TYPE_MASK 0x3 13 14 #define PDO_TYPE(t) ((t) << PDO_TYPE_SHIFT) 15 16 #define PDO_VOLT_MASK 0x3ff 17 #define PDO_CURR_MASK 0x3ff 18 #define PDO_PWR_MASK 0x3ff 19 20 #define PDO_FIXED_DUAL_ROLE (1 << 29) /* Power role swap supported */ 21 #define PDO_FIXED_SUSPEND (1 << 28) /* USB Suspend supported (Source) */ 22 #define PDO_FIXED_HIGHER_CAP (1 << 28) /* Requires more than vSafe5V (Sink) */ 23 #define PDO_FIXED_EXTPOWER (1 << 27) /* Externally powered */ 24 #define PDO_FIXED_USB_COMM (1 << 26) /* USB communications capable */ 25 #define PDO_FIXED_DATA_SWAP (1 << 25) /* Data role swap supported */ 26 #define PDO_FIXED_VOLT_SHIFT 10 /* 50mV units */ 27 #define PDO_FIXED_CURR_SHIFT 0 /* 10mA units */ 28 29 #define PDO_FIXED_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_FIXED_VOLT_SHIFT) 30 #define PDO_FIXED_CURR(ma) ((((ma) / 10) & PDO_CURR_MASK) << PDO_FIXED_CURR_SHIFT) 31 32 #define PDO_FIXED(mv, ma, flags) \ 33 (PDO_TYPE(PDO_TYPE_FIXED) | (flags) | \ 34 PDO_FIXED_VOLT(mv) | PDO_FIXED_CURR(ma)) 35 36 #define VSAFE5V 5000 /* mv units */ 37 38 #define PDO_BATT_MAX_VOLT_SHIFT 20 /* 50mV units */ 39 #define PDO_BATT_MIN_VOLT_SHIFT 10 /* 50mV units */ 40 #define PDO_BATT_MAX_PWR_SHIFT 0 /* 250mW units */ 41 42 #define PDO_BATT_MIN_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_BATT_MIN_VOLT_SHIFT) 43 #define PDO_BATT_MAX_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_BATT_MAX_VOLT_SHIFT) 44 #define PDO_BATT_MAX_POWER(mw) ((((mw) / 250) & PDO_PWR_MASK) << PDO_BATT_MAX_PWR_SHIFT) 45 46 #define PDO_BATT(min_mv, max_mv, max_mw) \ 47 (PDO_TYPE(PDO_TYPE_BATT) | PDO_BATT_MIN_VOLT(min_mv) | \ 48 PDO_BATT_MAX_VOLT(max_mv) | PDO_BATT_MAX_POWER(max_mw)) 49 50 #define PDO_VAR_MAX_VOLT_SHIFT 20 /* 50mV units */ 51 #define PDO_VAR_MIN_VOLT_SHIFT 10 /* 50mV units */ 52 #define PDO_VAR_MAX_CURR_SHIFT 0 /* 10mA units */ 53 54 #define PDO_VAR_MIN_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_VAR_MIN_VOLT_SHIFT) 55 #define PDO_VAR_MAX_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_VAR_MAX_VOLT_SHIFT) 56 #define PDO_VAR_MAX_CURR(ma) ((((ma) / 10) & PDO_CURR_MASK) << PDO_VAR_MAX_CURR_SHIFT) 57 58 #define PDO_VAR(min_mv, max_mv, max_ma) \ 59 (PDO_TYPE(PDO_TYPE_VAR) | PDO_VAR_MIN_VOLT(min_mv) | \ 60 PDO_VAR_MAX_VOLT(max_mv) | PDO_VAR_MAX_CURR(max_ma)) 61 62 #endif /* __DT_POWER_DELIVERY_H */ 63