summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2022-03-18 17:44:19 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-03-23 08:06:08 +0000
commita1f098ecd727634a7f7e243234d659d7dc919db6 (patch)
treee3dbaf34b5bcc2f05e558c87f871037628e75c7f /driver
parentb83014e44a3dad7ced86c8c327eaa99140d604a7 (diff)
downloadchrome-ec-a1f098ecd727634a7f7e243234d659d7dc919db6.tar.gz
util: align the IN_RANGE implementation with zephyr
The design of IN_RANGE() is slightly different between CrosEC and Zephyr's. Zephyr IN_RANGE() includes both upper and lower bound. (Ref: https://docs.zephyrproject.org/latest/reference/util/index.html#c.IN_RANGE) Update legacy code to work with CONFIG_ZEPHYR. BUG=none TEST=manually verify that all occurarence of IN_RANGE is updated BRANCH=none Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: I67e83a92be574be96535a3fe1b14454754e32072 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3534749 Tested-by: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/bc12/mt6360.c6
-rw-r--r--driver/charger/rt9490.c8
2 files changed, 7 insertions, 7 deletions
diff --git a/driver/bc12/mt6360.c b/driver/bc12/mt6360.c
index c84cb36ff3..5addba7a0c 100644
--- a/driver/bc12/mt6360.c
+++ b/driver/bc12/mt6360.c
@@ -550,7 +550,7 @@ DECLARE_HOOK(HOOK_INIT, mt6360_led_init, HOOK_PRIO_DEFAULT);
int mt6360_led_enable(enum mt6360_led_id led_id, int enable)
{
- if (!IN_RANGE(led_id, 0, MT6360_LED_COUNT))
+ if (!IN_RANGE(led_id, 0, MT6360_LED_COUNT - 1))
return EC_ERROR_INVAL;
if (enable)
@@ -563,9 +563,9 @@ int mt6360_led_set_brightness(enum mt6360_led_id led_id, int brightness)
{
int val;
- if (!IN_RANGE(led_id, 0, MT6360_LED_COUNT))
+ if (!IN_RANGE(led_id, 0, MT6360_LED_COUNT - 1))
return EC_ERROR_INVAL;
- if (!IN_RANGE(brightness, 0, 16))
+ if (!IN_RANGE(brightness, 0, 15))
return EC_ERROR_INVAL;
RETURN_ERROR(mt6360_read8(MT6360_REG_RGB_ISINK(led_id), &val));
diff --git a/driver/charger/rt9490.c b/driver/charger/rt9490.c
index df12e141b9..42428458b5 100644
--- a/driver/charger/rt9490.c
+++ b/driver/charger/rt9490.c
@@ -149,7 +149,7 @@ static enum ec_error_list rt9490_set_current(int chgnum, int current)
if (current == 0)
current = info->current_min;
- if (!IN_RANGE(current, info->current_min, info->current_max + 1))
+ if (!IN_RANGE(current, info->current_min, info->current_max))
return EC_ERROR_PARAM2;
reg_ichg = current / info->current_step;
@@ -178,7 +178,7 @@ static enum ec_error_list rt9490_set_voltage(int chgnum, int voltage)
if (voltage == 0)
voltage = info->voltage_min;
- if (!IN_RANGE(voltage, info->voltage_min, info->voltage_max + 1))
+ if (!IN_RANGE(voltage, info->voltage_min, info->voltage_max))
return EC_ERROR_PARAM2;
reg_cv = voltage / info->voltage_step;
@@ -198,9 +198,9 @@ enum ec_error_list rt9490_set_otg_current_voltage(int chgnum,
{
uint16_t reg_cur, reg_vol;
- if (!IN_RANGE(output_current, RT9490_IOTG_MIN, RT9490_IOTG_MAX + 1))
+ if (!IN_RANGE(output_current, RT9490_IOTG_MIN, RT9490_IOTG_MAX))
return EC_ERROR_PARAM2;
- if (!IN_RANGE(output_voltage, RT9490_VOTG_MIN, RT9490_VOTG_MAX + 1))
+ if (!IN_RANGE(output_voltage, RT9490_VOTG_MIN, RT9490_VOTG_MAX))
return EC_ERROR_PARAM3;
reg_cur = (output_current - RT9490_IOTG_MIN) / RT9490_IOTG_STEP;