summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2016-01-13 11:32:05 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-01-20 14:25:32 -0800
commit4c290b058a3393e8842de1583b29310d99c93d9a (patch)
tree070a341c8af014347489a69d41cd16345429c08f
parentd5ae5bc3702946c27ec5d9a84dfa3b32bb3664d2 (diff)
downloadchrome-ec-4c290b058a3393e8842de1583b29310d99c93d9a.tar.gz
GPIO: Simplify configuration
Previously there were only two uses of gpio_config_pins, one was gpio_config_module, which passed in GPIO_CONFIG_ALL_PORTS (the only place this is used), the other was the common I2C code when it needs to return the SDA and SCL lines to their alternate function after unwedging the bus. These uses are so different that it doesn't make much sense to keep a single API for them. This change adds a gpio_config_pin that is simpler to use as it just takes a gpio_signal enum to select the GPIO to configure and makes gpio_config_pins and GPIO_CONFIG_ALL_PORTS internal to gpio.c Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Change-Id: I92bfb0b520b0aa2165655b2ff5076e428c88631f Reviewed-on: https://chromium-review.googlesource.com/322437 Commit-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--common/gpio.c37
-rw-r--r--common/i2c.c18
-rw-r--r--include/gpio.h25
3 files changed, 40 insertions, 40 deletions
diff --git a/common/gpio.c b/common/gpio.c
index 0fd34d4a79..167207318f 100644
--- a/common/gpio.c
+++ b/common/gpio.c
@@ -58,17 +58,17 @@ static int last_val_changed(int i, int v)
}
}
-/*****************************************************************************/
-/* GPIO API */
-
-void gpio_config_module(enum module_id id, int enable)
-{
- /* Set all the alternate functions for this module. */
- gpio_config_pins(id, GPIO_CONFIG_ALL_PORTS, 0, enable);
-}
+/*
+ * GPIO_CONFIG_ALL_PORTS signifies a "don't care" for the GPIO port. This is
+ * used in gpio_config_pins(). When the port parameter is set to this, the
+ * pin_mask parameter is ignored.
+ */
+#define GPIO_CONFIG_ALL_PORTS 0xFFFFFFFF
-int gpio_config_pins(enum module_id id,
- uint32_t port, uint32_t pin_mask, int enable)
+static int gpio_config_pins(enum module_id id,
+ uint32_t port,
+ uint32_t pin_mask,
+ int enable)
{
const struct gpio_alt_func *af;
int rv = EC_ERROR_INVAL;
@@ -107,6 +107,23 @@ int gpio_config_pins(enum module_id id,
return rv;
}
+/*****************************************************************************/
+/* GPIO API */
+
+int gpio_config_module(enum module_id id, int enable)
+{
+ /* Set all the alternate functions for this module. */
+ return gpio_config_pins(id, GPIO_CONFIG_ALL_PORTS, 0, enable);
+}
+
+int gpio_config_pin(enum module_id id, enum gpio_signal signal, int enable)
+{
+ return gpio_config_pins(id,
+ gpio_list[signal].port,
+ gpio_list[signal].mask,
+ enable);
+}
+
void gpio_set_flags(enum gpio_signal signal, int flags)
{
const struct gpio_info *g = gpio_list + signal;
diff --git a/common/i2c.c b/common/i2c.c
index a051722a28..6e8bf10c4e 100644
--- a/common/i2c.c
+++ b/common/i2c.c
@@ -303,6 +303,7 @@ void i2c_raw_set_sda(int port, int level)
int i2c_raw_mode(int port, int enable)
{
enum gpio_signal sda, scl;
+ int ret_sda, ret_scl;
/* Get the SDA and SCL pins for this port. If none, then return. */
if (get_sda_from_i2c_port(port, &sda) != EC_SUCCESS)
@@ -315,10 +316,8 @@ int i2c_raw_mode(int port, int enable)
* To enable raw mode, take out of alternate function mode and
* set the flags to open drain output.
*/
- gpio_set_alternate_function(gpio_list[sda].port,
- gpio_list[sda].mask, -1);
- gpio_set_alternate_function(gpio_list[scl].port,
- gpio_list[scl].mask, -1);
+ ret_sda = gpio_config_pin(MODULE_I2C, sda, 0);
+ ret_scl = gpio_config_pin(MODULE_I2C, scl, 0);
gpio_set_flags(scl, GPIO_ODR_HIGH);
gpio_set_flags(sda, GPIO_ODR_HIGH);
@@ -327,16 +326,11 @@ int i2c_raw_mode(int port, int enable)
* Configure the I2C pins to exit raw mode and return
* to normal mode.
*/
- int ret_sda, ret_scl;
- ret_sda = gpio_config_pins(MODULE_I2C, gpio_list[sda].port,
- gpio_list[sda].mask, 1);
- ret_scl = gpio_config_pins(MODULE_I2C, gpio_list[scl].port,
- gpio_list[scl].mask, 1);
-
- return ret_sda == EC_SUCCESS ? ret_scl : ret_sda;
+ ret_sda = gpio_config_pin(MODULE_I2C, sda, 1);
+ ret_scl = gpio_config_pin(MODULE_I2C, scl, 1);
}
- return EC_SUCCESS;
+ return ret_sda == EC_SUCCESS ? ret_scl : ret_sda;
}
diff --git a/include/gpio.h b/include/gpio.h
index 02bdcc4f6f..060ef97c33 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -10,13 +10,6 @@
#include "common.h"
-/*
- * GPIO_CONFIG_ALL_PORTS signifies a "don't care" for the GPIO port. This is
- * used in gpio_config_pins(). When the port parameter is set to this, the
- * pin_mask parameter is ignored.
- */
-#define GPIO_CONFIG_ALL_PORTS 0xFFFFFFFF
-
/* Flag definitions for gpio_info and gpio_alt_func */
/* The following are valid for both gpio_info and gpio_alt_func: */
#define GPIO_OPEN_DRAIN (1 << 0) /* Output type is open-drain */
@@ -130,23 +123,19 @@ void gpio_pre_init(void);
*
* @param id Module ID to initialize
* @param enable Enable alternate functions if 1; high-Z pins if 0.
+ * @return EC_SUCCESS, or non-zero if module_id is not found.
*/
-void gpio_config_module(enum module_id id, int enable);
+int gpio_config_module(enum module_id id, int enable);
/**
- * Enable/disable alternate function for pins
- *
- * Note, you can also configure an entire module by setting the port parameter
- * equal to GPIO_CONFIG_ALL_PORTS.
+ * Enable/disable alternate function for single pin
*
* @param id module ID of pins
- * @param port Port of pins
- * @param pin_mask Bit mask of pins
- * @param enable Enable alternate functions if 1; high-Z pins if 0
- * @return EC_SUCCESS, or non-zero if pins are not found.
+ * @param signal Signal to configure
+ * @param enable Enable alternate function if 1; GPIO if 0
+ * @return EC_SUCCESS, or non-zero if pin is not found.
* */
-int gpio_config_pins(enum module_id id,
- uint32_t port, uint32_t pin_mask, int enable);
+int gpio_config_pin(enum module_id id, enum gpio_signal signal, int enable);
/**
* Get the current value of a signal.