summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2019-03-11 16:07:55 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-03-26 04:42:56 -0700
commitac77140b7f4f42075d2377fc9d956a636b05aacf (patch)
treec64c6a30916ff741a2ab235141f7bd071cd54483 /driver
parentbb266fc26fc05d4ab22de6ad7bce5b477c9f9140 (diff)
downloadchrome-ec-ac77140b7f4f42075d2377fc9d956a636b05aacf.tar.gz
common: bit change 1 << constants with BIT(constants)
Mechanical replacement of bit operation where operand is a constant. More bit operation exist, but prone to errors. Reveal a bug in npcx: chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow] BUG=None BRANCH=None TEST=None Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/accelgyro_bmi160.c4
-rw-r--r--driver/baro_bmp280.h4
-rw-r--r--driver/charger/bd9995x.c2
-rw-r--r--driver/charger/rt946x.h78
-rw-r--r--driver/ioexpander_pca9534.c4
-rw-r--r--driver/ppc/nx20p348x.c4
-rw-r--r--driver/ppc/sn5s330.c4
-rw-r--r--driver/touchpad_st.c2
8 files changed, 51 insertions, 51 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index b2a59cb17c..d441ee3c9e 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -763,9 +763,9 @@ int manage_activity(const struct motion_sensor_t *s,
if (ret == EC_RES_SUCCESS) {
if (enable) {
data->enabled_activities |= 1 << activity;
- data->disabled_activities &= ~(1 << activity);
+ data->disabled_activities &= ~BIT(activity);
} else {
- data->enabled_activities &= ~(1 << activity);
+ data->enabled_activities &= ~BIT(activity);
data->disabled_activities |= 1 << activity;
}
}
diff --git a/driver/baro_bmp280.h b/driver/baro_bmp280.h
index be2611289c..a3cb919a7c 100644
--- a/driver/baro_bmp280.h
+++ b/driver/baro_bmp280.h
@@ -144,8 +144,8 @@
*/
#define BMP280_COMPUTE_TIME \
((T_INIT_MAX + T_MEASURE_PER_OSRS_MAX * \
- (((1 << BMP280_OVERSAMP_TEMP) >> 1) + \
- ((1 << BMP280_OVERSAMP_PRES) >> 1)) + \
+ ((BIT(BMP280_OVERSAMP_TEMP) >> 1) + \
+ (BIT(BMP280_OVERSAMP_PRES) >> 1)) + \
(BMP280_OVERSAMP_PRES ? T_SETUP_PRESSURE_MAX : 0) + 15) / 16)
/*
diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c
index 9ab69a7c38..1eba3e9aa6 100644
--- a/driver/charger/bd9995x.c
+++ b/driver/charger/bd9995x.c
@@ -1507,7 +1507,7 @@ static int bd9995x_psys_charger_adc(void)
* Calculate power in mW
* PSYS = VACP×IACP+VBAT×IBAT = IPMON / GPMON
*/
- return (int) ((ipmon * 1000) / ((1 << BD9995X_PSYS_GAIN_SELECT) *
+ return (int) ((ipmon * 1000) / (BIT(BD9995X_PSYS_GAIN_SELECT) *
BD9995X_PMON_IOUT_ADC_READ_COUNT));
}
diff --git a/driver/charger/rt946x.h b/driver/charger/rt946x.h
index b28a87f3f5..0f7bcb2426 100644
--- a/driver/charger/rt946x.h
+++ b/driver/charger/rt946x.h
@@ -246,14 +246,14 @@
#define RT946X_SHIFT_DB_RST 1
#define RT946X_SHIFT_REG_RST 0
-#define RT946X_MASK_RST (1 << RT946X_SHIFT_RST)
-#define RT946X_MASK_CHG_RST (1 << RT946X_SHIFT_CHG_RST)
-#define RT946X_MASK_FLED_RST (1 << RT946X_SHIFT_FLED_RST)
-#define RT946X_MASK_LDO_RST (1 << RT946X_SHIFT_LDO_RST)
-#define RT946X_MASK_RGB_RST (1 << RT946X_SHIFT_RGB_RST)
-#define RT946X_MASK_BL_RST (1 << RT946X_SHIFT_BL_RST)
-#define RT946X_MASK_DB_RST (1 << RT946X_SHIFT_DB_RST)
-#define RT946X_MASK_REG_RST (1 << RT946X_SHIFT_REG_RST)
+#define RT946X_MASK_RST BIT(RT946X_SHIFT_RST)
+#define RT946X_MASK_CHG_RST BIT(RT946X_SHIFT_CHG_RST)
+#define RT946X_MASK_FLED_RST BIT(RT946X_SHIFT_FLED_RST)
+#define RT946X_MASK_LDO_RST BIT(RT946X_SHIFT_LDO_RST)
+#define RT946X_MASK_RGB_RST BIT(RT946X_SHIFT_RGB_RST)
+#define RT946X_MASK_BL_RST BIT(RT946X_SHIFT_BL_RST)
+#define RT946X_MASK_DB_RST BIT(RT946X_SHIFT_DB_RST)
+#define RT946X_MASK_REG_RST BIT(RT946X_SHIFT_REG_RST)
#define RT946X_MASK_SOFT_RST \
(RT946X_MASK_CHG_RST | RT946X_MASK_FLED_RST | RT946X_MASK_LDO_RST | \
RT946X_MASK_RGB_RST | RT946X_MASK_BL_RST | RT946X_MASK_DB_RST | \
@@ -263,8 +263,8 @@
#define RT946X_SHIFT_OPA_MODE 0
#define RT946X_SHIFT_HZ_EN 2
-#define RT946X_MASK_OPA_MODE (1 << RT946X_SHIFT_OPA_MODE)
-#define RT946X_MASK_HZ_EN (1 << RT946X_SHIFT_HZ_EN)
+#define RT946X_MASK_OPA_MODE BIT(RT946X_SHIFT_OPA_MODE)
+#define RT946X_MASK_HZ_EN BIT(RT946X_SHIFT_HZ_EN)
/* ========== CHGCTRL2 0x02 ============ */
#define RT946X_SHIFT_SHIP_MODE 7
@@ -273,11 +273,11 @@
#define RT946X_SHIFT_CFO_EN 1
#define RT946X_SHIFT_CHG_EN 0
-#define RT946X_MASK_SHIP_MODE (1 << RT946X_SHIFT_SHIP_MODE)
-#define RT946X_MASK_TE (1 << RT946X_SHIFT_TE)
+#define RT946X_MASK_SHIP_MODE BIT(RT946X_SHIFT_SHIP_MODE)
+#define RT946X_MASK_TE BIT(RT946X_SHIFT_TE)
#define RT946X_MASK_ILMTSEL (0x3 << RT946X_SHIFT_ILMTSEL)
-#define RT946X_MASK_CFO_EN (1 << RT946X_SHIFT_CFO_EN)
-#define RT946X_MASK_CHG_EN (1 << RT946X_SHIFT_CHG_EN)
+#define RT946X_MASK_CFO_EN BIT(RT946X_SHIFT_CFO_EN)
+#define RT946X_MASK_CHG_EN BIT(RT946X_SHIFT_CHG_EN)
/* ========== RSTPASCODE1 0x03 (mt6370) ============ */
#define MT6370_MASK_RSTPASCODE1 0xA9
@@ -287,7 +287,7 @@
#define RT946X_SHIFT_ILIMEN 0
#define RT946X_MASK_AICR (0x3F << RT946X_SHIFT_AICR)
-#define RT946X_MASK_ILIMEN (1 << RT946X_SHIFT_ILIMEN)
+#define RT946X_MASK_ILIMEN BIT(RT946X_SHIFT_ILIMEN)
/* ========== RSTPASCODE2 0x04 (mt6370) ============ */
#define MT6370_MASK_RSTPASCODE2 0x96
@@ -332,31 +332,31 @@
/* ========== CHGCTRL12 0x0C ============ */
#define RT946X_SHIFT_TMR_EN 1
-#define RT946X_MASK_TMR_EN (1 << RT946X_SHIFT_TMR_EN)
+#define RT946X_MASK_TMR_EN BIT(RT946X_SHIFT_TMR_EN)
/* ========== CHGCTRL13 0x0D ============ */
#define RT946X_SHIFT_WDT_EN 7
-#define RT946X_MASK_WDT_EN (1 << RT946X_SHIFT_WDT_EN)
+#define RT946X_MASK_WDT_EN BIT(RT946X_SHIFT_WDT_EN)
/* ========== CHGCTRL14 0x0E ============ */
#define RT946X_SHIFT_AICLMEAS 7
#define RT946X_SHIFT_AICLVTH 0
-#define RT946X_MASK_AICLMEAS (1 << RT946X_SHIFT_AICLMEAS)
+#define RT946X_MASK_AICLMEAS BIT(RT946X_SHIFT_AICLMEAS)
#define RT946X_MASK_AICLVTH 0x07
/* ========== CHGCTRL16 0x10 ============ */
#define RT946X_SHIFT_JEITA_EN 4
-#define RT946X_MASK_JEITA_EN (1 << RT946X_SHIFT_JEITA_EN)
+#define RT946X_MASK_JEITA_EN BIT(RT946X_SHIFT_JEITA_EN)
/* ========== CHGADC 0x11 ============ */
#define RT946X_SHIFT_ADC_IN_SEL 4
#define RT946X_SHIFT_ADC_START 0
#define RT946X_MASK_ADC_IN_SEL (0xF << RT946X_SHIFT_ADC_IN_SEL)
-#define RT946X_MASK_ADC_START (1 << RT946X_SHIFT_ADC_START)
+#define RT946X_MASK_ADC_START BIT(RT946X_SHIFT_ADC_START)
/* ========== CHGDPDM1 0x12 (rt946x) DEVICETYPE 0x22 (mt6370) ============ */
#define RT946X_SHIFT_USBCHGEN 7
@@ -364,10 +364,10 @@
#define RT946X_SHIFT_CDP 1
#define RT946X_SHIFT_SDP 0
-#define RT946X_MASK_USBCHGEN (1 << RT946X_SHIFT_USBCHGEN)
-#define RT946X_MASK_DCP (1 << RT946X_SHIFT_DCP)
-#define RT946X_MASK_CDP (1 << RT946X_SHIFT_CDP)
-#define RT946X_MASK_SDP (1 << RT946X_SHIFT_SDP)
+#define RT946X_MASK_USBCHGEN BIT(RT946X_SHIFT_USBCHGEN)
+#define RT946X_MASK_DCP BIT(RT946X_SHIFT_DCP)
+#define RT946X_MASK_CDP BIT(RT946X_SHIFT_CDP)
+#define RT946X_MASK_SDP BIT(RT946X_SHIFT_SDP)
#define RT946X_MASK_BC12_TYPE (RT946X_MASK_DCP | \
RT946X_MASK_CDP | \
@@ -401,7 +401,7 @@
#define RT946X_SHIFT_ADC_STAT 0
#define RT946X_MASK_CHG_STAT (0x3 << RT946X_SHIFT_CHG_STAT)
-#define RT946X_MASK_ADC_STAT (1 << RT946X_SHIFT_ADC_STAT)
+#define RT946X_MASK_ADC_STAT BIT(RT946X_SHIFT_ADC_STAT)
/* ========== CHGNTC 0x43 ============ */
#define RT946X_SHIFT_BATNTC_FAULT 4
@@ -411,7 +411,7 @@
/* ========== CHGSTATC 0x50 (rt946x) ============ */
#define RT946X_SHIFT_PWR_RDY 7
-#define RT946X_MASK_PWR_RDY (1 << RT946X_SHIFT_PWR_RDY)
+#define RT946X_MASK_PWR_RDY BIT(RT946X_SHIFT_PWR_RDY)
/* ========== CHGFAULT 0x51 (rt946x) ============ */
#if defined(CONFIG_CHARGER_RT9466) || defined(CONFIG_CHARGER_RT9467)
@@ -420,10 +420,10 @@
#define RT946X_SHIFT_CHG_VBATOV 6
#define RT946X_SHIFT_CHG_VBUSOV 7
-#define RT946X_MASK_CHG_VSYSUV (1 << RT946X_SHIFT_CHG_VSYSUV)
-#define RT946X_MASK_CHG_VSYSOV (1 << RT946X_SHIFT_CHG_VSYSOV)
-#define RT946X_MASK_CHG_VBATOV (1 << RT946X_SHIFT_CHG_VBATOV)
-#define RT946X_MASK_CHG_VBUSOV (1 << RT946X_SHIFT_CHG_VBUSOV)
+#define RT946X_MASK_CHG_VSYSUV BIT(RT946X_SHIFT_CHG_VSYSUV)
+#define RT946X_MASK_CHG_VSYSOV BIT(RT946X_SHIFT_CHG_VSYSOV)
+#define RT946X_MASK_CHG_VBATOV BIT(RT946X_SHIFT_CHG_VBATOV)
+#define RT946X_MASK_CHG_VBUSOV BIT(RT946X_SHIFT_CHG_VBUSOV)
#endif
/* ========== DPDMIRQ 0x56 ============ */
@@ -431,21 +431,21 @@
#define RT946X_SHIFT_DPDMIRQ_DETACH 1
#define RT946X_SHIFT_DPDMIRQ_ATTACH 0
-#define RT946X_MASK_DPDMIRQ_DETACH (1 << RT946X_SHIFT_DPDMIRQ_DETACH)
-#define RT946X_MASK_DPDMIRQ_ATTACH (1 << RT946X_SHIFT_DPDMIRQ_ATTACH)
+#define RT946X_MASK_DPDMIRQ_DETACH BIT(RT946X_SHIFT_DPDMIRQ_DETACH)
+#define RT946X_MASK_DPDMIRQ_ATTACH BIT(RT946X_SHIFT_DPDMIRQ_ATTACH)
#endif
/* ========== LDOCFG 0x80 (mt6370) ============ */
#define MT6370_SHIFT_LDOCFG_OMS 6
-#define MT6370_MASK_LDOCFG_OMS (1 << MT6370_SHIFT_LDOCFG_OMS)
+#define MT6370_MASK_LDOCFG_OMS BIT(MT6370_SHIFT_LDOCFG_OMS)
/* ========== LDOVOUT 0x81 (mt6370) ============ */
#define MT6370_SHIFT_LDOVOUT_EN 7
#define MT6370_SHIFT_LDOVOUT_VOUT 0
-#define MT6370_MASK_LDOVOUT_EN (1 << MT6370_SHIFT_LDOVOUT_EN)
+#define MT6370_MASK_LDOVOUT_EN BIT(MT6370_SHIFT_LDOVOUT_EN)
#define MT6370_MASK_LDOVOUT_VOUT (0xf << MT6370_SHIFT_LDOVOUT_VOUT)
/* ========== RGBDIM 0x82/0x83/0x84 (mt6370) ============ */
@@ -464,9 +464,9 @@
#define MT6370_SHIFT_RGB_ISNK3DIM 5
#define MT6370_SHIFT_RGB_ISNKDIM_BASE 8
-#define MT6370_MASK_RGB_ISNK1DIM_EN (1 << MT6370_SHIFT_RGB_ISNK1DIM)
-#define MT6370_MASK_RGB_ISNK2DIM_EN (1 << MT6370_SHIFT_RGB_ISNK2DIM)
-#define MT6370_MASK_RGB_ISNK3DIM_EN (1 << MT6370_SHIFT_RGB_ISNK3DIM)
+#define MT6370_MASK_RGB_ISNK1DIM_EN BIT(MT6370_SHIFT_RGB_ISNK1DIM)
+#define MT6370_MASK_RGB_ISNK2DIM_EN BIT(MT6370_SHIFT_RGB_ISNK2DIM)
+#define MT6370_MASK_RGB_ISNK3DIM_EN BIT(MT6370_SHIFT_RGB_ISNK3DIM)
#define MT6370_MASK_RGB_ISNK_ALL_EN (MT6370_MASK_RGB_ISNK1DIM_EN | \
MT6370_MASK_RGB_ISNK2DIM_EN | \
MT6370_MASK_RGB_ISNK3DIM_EN)
@@ -500,8 +500,8 @@
#define RT946X_MASK_CHG_VBATOV MT6370_SHIFT_CHG_VBATOV_STAT
-#define MT6370_MASK_CHG_VBUSOV_STAT (1 << MT6370_SHIFT_CHG_VBUSOV_STAT)
-#define MT6370_MASK_CHG_VBATOV_STAT (1 << MT6370_SHIFT_CHG_VBATOV_STAT)
+#define MT6370_MASK_CHG_VBUSOV_STAT BIT(MT6370_SHIFT_CHG_VBUSOV_STAT)
+#define MT6370_MASK_CHG_VBATOV_STAT BIT(MT6370_SHIFT_CHG_VBATOV_STAT)
#endif
/* ========== Variant-specific configuration ============ */
diff --git a/driver/ioexpander_pca9534.c b/driver/ioexpander_pca9534.c
index 1ac9a5164b..1a1015b1f1 100644
--- a/driver/ioexpander_pca9534.c
+++ b/driver/ioexpander_pca9534.c
@@ -12,7 +12,7 @@ static int pca9534_pin_read(int port, int addr, int reg, int pin, int *val)
{
int ret;
ret = i2c_read8(port, addr, reg, val);
- *val = (*val & (1 << pin)) ? 1 : 0;
+ *val = (*val & BIT(pin)) ? 1 : 0;
return ret;
}
@@ -22,7 +22,7 @@ static int pca9534_pin_write(int port, int addr, int reg, int pin, int val)
ret = i2c_read8(port, addr, reg, &v);
if (ret != EC_SUCCESS)
return ret;
- v &= ~(1 << pin);
+ v &= ~BIT(pin);
if (val)
v |= 1 << pin;
return i2c_write8(port, addr, reg, v);
diff --git a/driver/ppc/nx20p348x.c b/driver/ppc/nx20p348x.c
index 3423b77f53..aae4e18f56 100644
--- a/driver/ppc/nx20p348x.c
+++ b/driver/ppc/nx20p348x.c
@@ -376,14 +376,14 @@ static void nx20p348x_irq_deferred(void)
uint32_t pending = atomic_read_clear(&irq_pending);
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++)
- if ((1 << i) & pending)
+ if (BIT(i) & pending)
nx20p348x_handle_interrupt(i);
}
DECLARE_DEFERRED(nx20p348x_irq_deferred);
void nx20p348x_interrupt(int port)
{
- atomic_or(&irq_pending, (1 << port));
+ atomic_or(&irq_pending, BIT(port));
hook_call_deferred(&nx20p348x_irq_deferred_data, 0);
}
diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c
index ef63402b6b..98c2641440 100644
--- a/driver/ppc/sn5s330.c
+++ b/driver/ppc/sn5s330.c
@@ -707,14 +707,14 @@ static void sn5s330_irq_deferred(void)
uint32_t pending = atomic_read_clear(&irq_pending);
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++)
- if ((1 << i) & pending)
+ if (BIT(i) & pending)
sn5s330_handle_interrupt(i);
}
DECLARE_DEFERRED(sn5s330_irq_deferred);
void sn5s330_interrupt(int port)
{
- atomic_or(&irq_pending, (1 << port));
+ atomic_or(&irq_pending, BIT(port));
hook_call_deferred(&sn5s330_irq_deferred_data, 0);
}
diff --git a/driver/touchpad_st.c b/driver/touchpad_st.c
index 8c4a5cf2dd..e4327a2054 100644
--- a/driver/touchpad_st.c
+++ b/driver/touchpad_st.c
@@ -196,7 +196,7 @@ static int st_tp_parse_finger(struct usb_hid_touchpad_report *report,
if (event->evt_id == ST_TP_EVENT_ID_ENTER_POINTER)
touch_slot |= 1 << id;
else if (event->evt_id == ST_TP_EVENT_ID_LEAVE_POINTER)
- touch_slot &= ~(1 << id);
+ touch_slot &= ~BIT(id);
/* We cannot report more fingers */
if (i >= ARRAY_SIZE(report->finger)) {