/* Return: value between 0 and 127, negative on error.  */
static int bq25180_ma_to_ichg(uint32_t current_ma, uint8_t *ichg)
/* Return: value between 0 and 127, negative on error.  */
static int bq25180_ma_to_ichg(uint32_t current_ma, uint8_t *ichg)
{
	if (!IN_RANGE(current_ma, BQ25180_CURRENT_MIN_MA, BQ25180_CURRENT_MAX_MA)) {
		LOG_WRN("charging current out of range: %dmA, "
			"clamping to the nearest limit", current_ma);
	}
	current_ma = CLAMP(current_ma, BQ25180_CURRENT_MIN_MA, BQ25180_CURRENT_MAX_MA);
	if (current_ma <= 35) {
		*ichg = current_ma - 5;
		return 0;
	}
	*ichg = (current_ma - 40) / 10 + 31;
	return 0;
}