GPIO: Prefer gpio_set_flags

Convert some uses of gpio_set_flags_by_mask to plain gpio_set_flags.
The result is usually more readable due to being able to use the
GPIO_* enum names, and it removes more instances of port/mask
implementation details leaking outside the gpio.c chip specific code.

Signed-off-by: Anton Staaf <robotboy@chromium.org>

BRANCH=None
BUG=None
TEST=make buildall -j

Change-Id: I06a7ad8a53e553a8e432a6abb5b38c25a98df6c6
Reviewed-on: https://chromium-review.googlesource.com/323815
Commit-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Anton Staaf
2016-01-26 10:38:47 -08:00
committed by chrome-bot
parent e9c8d3850c
commit 74e81bf9da
3 changed files with 38 additions and 46 deletions

View File

@@ -147,26 +147,18 @@ static void set_active_cc(int cc)
{
active_cc = cc;
/* High Z for no pull-up or pull-down resistor on CC1 */
gpio_set_flags_by_mask(GPIO_A, (1 << 2) | (1 << 9), GPIO_INPUT);
/* High Z for no pull-up or pull-down resistor on CC2 */
gpio_set_flags_by_mask(GPIO_B, (1 << 6) | (1 << 7), GPIO_INPUT);
if (cc) {
if (host_mode)
/* Pull-up on CC2 */
gpio_set_flags_by_mask(GPIO_B, (1 << 6), GPIO_OUT_HIGH);
else
/* Pull-down on CC2 */
gpio_set_flags_by_mask(GPIO_B, (1 << 7), GPIO_OUT_LOW);
} else {
if (host_mode)
/* Pull-up on CC1 */
gpio_set_flags_by_mask(GPIO_A, (1 << 2), GPIO_OUT_HIGH);
else
/* Pull-down on CC1 */
gpio_set_flags_by_mask(GPIO_A, (1 << 9), GPIO_OUT_LOW);
}
/* Pull-up on CC2 */
gpio_set_flags(GPIO_USBC_CC2_HOST,
(cc && host_mode) ? GPIO_OUT_HIGH : GPIO_INPUT);
/* Pull-down on CC2 */
gpio_set_flags(GPIO_USBC_CC2_DEVICE_ODL,
(cc && !host_mode) ? GPIO_OUT_LOW : GPIO_INPUT);
/* Pull-up on CC1 */
gpio_set_flags(GPIO_USBC_CC1_HOST,
(!cc && host_mode) ? GPIO_OUT_HIGH : GPIO_INPUT);
/* Pull-down on CC1 */
gpio_set_flags(GPIO_USBC_CC1_DEVICE_ODL,
(!cc && !host_mode) ? GPIO_OUT_LOW : GPIO_INPUT);
}
/**
@@ -230,10 +222,11 @@ static void fake_disconnect_start(void)
gpio_set_level(GPIO_VBUS_CHARGER_EN, 0);
gpio_set_level(GPIO_USBC_VSEL_0, 0);
gpio_set_level(GPIO_USBC_VSEL_1, 0);
/* High Z for no pull-up or pull-down resistor on CC1 */
gpio_set_flags_by_mask(GPIO_A, (1 << 2) | (1 << 9), GPIO_INPUT);
/* High Z for no pull-up or pull-down resistor on CC2 */
gpio_set_flags_by_mask(GPIO_B, (1 << 6) | (1 << 7), GPIO_INPUT);
/* High Z for no pull-up or pull-down resistor on CC1 and CC2 */
gpio_set_flags(GPIO_USBC_CC2_HOST, GPIO_INPUT);
gpio_set_flags(GPIO_USBC_CC2_DEVICE_ODL, GPIO_INPUT);
gpio_set_flags(GPIO_USBC_CC1_HOST, GPIO_INPUT);
gpio_set_flags(GPIO_USBC_CC1_DEVICE_ODL, GPIO_INPUT);
fake_pd_disconnected = 1;

View File

@@ -44,22 +44,21 @@ static enum inj_pol inj_polarity = INJ_POL_CC1;
static const struct res_cfg {
const char *name;
struct config {
uint32_t port;
uint32_t mask;
enum gpio_signal signal;
uint32_t flags;
} cfgs[2];
} res_cfg[] = {
[INJ_RES_NONE] = {"NONE"},
[INJ_RES_RA] = {"RA", {{GPIO_A, 0x0100, GPIO_ODR_LOW},
{GPIO_B, 0x8000, GPIO_ODR_LOW} } },
[INJ_RES_RD] = {"RD", {{GPIO_B, 0x0020, GPIO_ODR_LOW},
{GPIO_B, 0x0100, GPIO_ODR_LOW} } },
[INJ_RES_RPUSB] = {"RPUSB", {{GPIO_A, 0x2000, GPIO_OUT_HIGH},
{GPIO_B, 0x0001, GPIO_OUT_HIGH} } },
[INJ_RES_RP1A5] = {"RP1A5", {{GPIO_A, 0x4000, GPIO_OUT_HIGH},
{GPIO_C, 0x4000, GPIO_OUT_HIGH} } },
[INJ_RES_RP3A0] = {"RP3A0", {{GPIO_A, 0x8000, GPIO_OUT_HIGH},
{GPIO_C, 0x8000, GPIO_OUT_HIGH} } },
[INJ_RES_RA] = {"RA", {{GPIO_CC1_RA, GPIO_ODR_LOW},
{GPIO_CC2_RA, GPIO_ODR_LOW} } },
[INJ_RES_RD] = {"RD", {{GPIO_CC1_RD, GPIO_ODR_LOW},
{GPIO_CC2_RD, GPIO_ODR_LOW} } },
[INJ_RES_RPUSB] = {"RPUSB", {{GPIO_CC1_RPUSB, GPIO_OUT_HIGH},
{GPIO_CC2_RPUSB, GPIO_OUT_HIGH} } },
[INJ_RES_RP1A5] = {"RP1A5", {{GPIO_CC1_RP1A5, GPIO_OUT_HIGH},
{GPIO_CC2_RP1A5, GPIO_OUT_HIGH} } },
[INJ_RES_RP3A0] = {"RP3A0", {{GPIO_CC1_RP3A0, GPIO_OUT_HIGH},
{GPIO_CC2_RP3A0, GPIO_OUT_HIGH} } },
};
#define CC_RA(cc) (cc < PD_SRC_RD_THRESHOLD)
@@ -124,14 +123,16 @@ static int send_hrst(int polarity)
static void set_resistor(int pol, enum inj_res res)
{
/* reset everything on one CC to high impedance */
gpio_set_flags_by_mask(GPIO_A, pol ? 0x0000 : 0xE100, GPIO_ODR_HIGH);
gpio_set_flags_by_mask(GPIO_B, pol ? 0x8101 : 0x0020, GPIO_ODR_HIGH);
gpio_set_flags_by_mask(GPIO_C, pol ? 0xC000 : 0x0000, GPIO_ODR_HIGH);
gpio_set_flags(res_cfg[INJ_RES_RA].cfgs[pol].signal, GPIO_ODR_HIGH);
gpio_set_flags(res_cfg[INJ_RES_RD].cfgs[pol].signal, GPIO_ODR_HIGH);
gpio_set_flags(res_cfg[INJ_RES_RPUSB].cfgs[pol].signal, GPIO_ODR_HIGH);
gpio_set_flags(res_cfg[INJ_RES_RP1A5].cfgs[pol].signal, GPIO_ODR_HIGH);
gpio_set_flags(res_cfg[INJ_RES_RP3A0].cfgs[pol].signal, GPIO_ODR_HIGH);
/* connect the resistor if needed */
if (res_cfg[res].cfgs[pol].mask)
gpio_set_flags_by_mask(res_cfg[res].cfgs[pol].port,
res_cfg[res].cfgs[pol].mask,
res_cfg[res].cfgs[pol].flags);
if (res != INJ_RES_NONE)
gpio_set_flags(res_cfg[res].cfgs[pol].signal,
res_cfg[res].cfgs[pol].flags);
}
static enum inj_pol guess_polarity(enum inj_pol pol)

View File

@@ -400,9 +400,7 @@ void board_set_gpio_hibernate_state(void)
/* Change GPIOs' state in hibernate for better power consumption */
for (i = 0; i < ARRAY_SIZE(hibernate_pins); ++i)
gpio_set_flags_by_mask(gpio_list[hibernate_pins[i][0]].port,
gpio_list[hibernate_pins[i][0]].mask,
hibernate_pins[i][1]);
gpio_set_flags(hibernate_pins[i][0], hibernate_pins[i][1]);
}
/* Any wheatley boards post version 2 should have ROP_LDO_EN stuffed. */