summaryrefslogtreecommitdiff
path: root/drivers/pinctrl/sh-pfc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pinctrl/sh-pfc')
-rw-r--r--drivers/pinctrl/sh-pfc/gpio.c11
-rw-r--r--drivers/pinctrl/sh-pfc/pinctrl.c43
2 files changed, 26 insertions, 28 deletions
diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c
index 97c1332c1045..5a55b8da7919 100644
--- a/drivers/pinctrl/sh-pfc/gpio.c
+++ b/drivers/pinctrl/sh-pfc/gpio.c
@@ -7,7 +7,7 @@
*/
#include <linux/device.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/pinctrl/consumer.h>
@@ -255,18 +255,13 @@ static int gpio_pin_setup(struct sh_pfc_chip *chip)
#ifdef CONFIG_PINCTRL_SH_FUNC_GPIO
static int gpio_function_request(struct gpio_chip *gc, unsigned offset)
{
- static bool __print_once;
struct sh_pfc *pfc = gpio_to_pfc(gc);
unsigned int mark = pfc->info->func_gpios[offset].enum_id;
unsigned long flags;
int ret;
- if (!__print_once) {
- dev_notice(pfc->dev,
- "Use of GPIO API for function requests is deprecated."
- " Convert to pinctrl\n");
- __print_once = true;
- }
+ dev_notice_once(pfc->dev,
+ "Use of GPIO API for function requests is deprecated, convert to pinctrl\n");
if (mark == 0)
return -EINVAL;
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c
index 2824be4eb887..212a4a9c3a8f 100644
--- a/drivers/pinctrl/sh-pfc/pinctrl.c
+++ b/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -26,7 +26,9 @@
#include "../pinconf.h"
struct sh_pfc_pin_config {
- u32 type;
+ unsigned int mux_mark;
+ bool mux_set;
+ bool gpio_enabled;
};
struct sh_pfc_pinctrl {
@@ -355,16 +357,27 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
- if (cfg->type != PINMUX_TYPE_NONE) {
+ /*
+ * This driver cannot manage both gpio and mux when the gpio
+ * pin is already enabled. So, this function fails.
+ */
+ if (cfg->gpio_enabled) {
ret = -EBUSY;
goto done;
}
- }
- for (i = 0; i < grp->nr_pins; ++i) {
ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
if (ret < 0)
- break;
+ goto done;
+ }
+
+ /* All group pins are configured, mark the pins as mux_set */
+ for (i = 0; i < grp->nr_pins; ++i) {
+ int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
+ struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
+
+ cfg->mux_set = true;
+ cfg->mux_mark = grp->mux[i];
}
done:
@@ -385,14 +398,6 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
spin_lock_irqsave(&pfc->lock, flags);
- if (cfg->type != PINMUX_TYPE_NONE) {
- dev_err(pfc->dev,
- "Pin %u is busy, can't configure it as GPIO.\n",
- offset);
- ret = -EBUSY;
- goto done;
- }
-
if (!pfc->gpio) {
/* If GPIOs are handled externally the pin mux type need to be
* set to GPIO here.
@@ -404,7 +409,7 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
goto done;
}
- cfg->type = PINMUX_TYPE_GPIO;
+ cfg->gpio_enabled = true;
ret = 0;
@@ -425,7 +430,10 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
unsigned long flags;
spin_lock_irqsave(&pfc->lock, flags);
- cfg->type = PINMUX_TYPE_NONE;
+ cfg->gpio_enabled = false;
+ /* If mux is already set, this configures it here */
+ if (cfg->mux_set)
+ sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
spin_unlock_irqrestore(&pfc->lock, flags);
}
@@ -438,7 +446,6 @@ static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
int idx = sh_pfc_get_pin_index(pfc, offset);
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
- struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
unsigned long flags;
unsigned int dir;
int ret;
@@ -458,8 +465,6 @@ static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
if (ret < 0)
goto done;
- cfg->type = new_type;
-
done:
spin_unlock_irqrestore(&pfc->lock, flags);
return ret;
@@ -782,13 +787,11 @@ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
for (i = 0; i < pfc->info->nr_pins; ++i) {
const struct sh_pfc_pin *info = &pfc->info->pins[i];
- struct sh_pfc_pin_config *cfg = &pmx->configs[i];
struct pinctrl_pin_desc *pin = &pmx->pins[i];
/* If the pin number is equal to -1 all pins are considered */
pin->number = info->pin != (u16)-1 ? info->pin : i;
pin->name = info->name;
- cfg->type = PINMUX_TYPE_NONE;
}
return 0;