2020-09-09 15:50:15 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017-2020 STMicroelectronics - All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
2020-11-06 18:01:32 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_PINCTRL
|
|
|
|
|
2017-02-12 18:25:49 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2018-11-27 12:49:53 +00:00
|
|
|
#include <hwspinlock.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2017-04-10 22:02:57 +00:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/io.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2019-07-30 17:16:10 +00:00
|
|
|
#include <dm/lists.h>
|
|
|
|
#include <dm/pinctrl.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <linux/libfdt.h>
|
2017-02-12 18:25:49 +00:00
|
|
|
|
2021-10-22 18:12:34 +00:00
|
|
|
#include "../gpio/stm32_gpio_priv.h"
|
|
|
|
|
2017-04-10 22:03:04 +00:00
|
|
|
#define MAX_PINS_ONE_IP 70
|
2017-04-10 22:02:57 +00:00
|
|
|
#define MODE_BITS_MASK 3
|
|
|
|
#define OSPEED_MASK 3
|
|
|
|
#define PUPD_MASK 3
|
|
|
|
#define OTYPE_MSK 1
|
|
|
|
#define AFR_MASK 0xF
|
|
|
|
|
2018-10-24 12:10:18 +00:00
|
|
|
struct stm32_pinctrl_priv {
|
2018-11-27 12:49:53 +00:00
|
|
|
struct hwspinlock hws;
|
2018-10-24 12:10:18 +00:00
|
|
|
int pinctrl_ngpios;
|
|
|
|
struct list_head gpio_dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_gpio_bank {
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2018-11-27 12:49:53 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
|
|
|
|
2018-10-24 12:10:19 +00:00
|
|
|
static char pin_name[PINNAME_SIZE];
|
2018-10-24 12:10:20 +00:00
|
|
|
#define PINMUX_MODE_COUNT 5
|
|
|
|
static const char * const pinmux_mode[PINMUX_MODE_COUNT] = {
|
|
|
|
"gpio input",
|
|
|
|
"gpio output",
|
|
|
|
"analog",
|
|
|
|
"unknown",
|
|
|
|
"alt function",
|
|
|
|
};
|
|
|
|
|
2020-10-28 09:49:07 +00:00
|
|
|
static const char * const pinmux_bias[] = {
|
|
|
|
[STM32_GPIO_PUPD_NO] = "",
|
|
|
|
[STM32_GPIO_PUPD_UP] = "pull-up",
|
|
|
|
[STM32_GPIO_PUPD_DOWN] = "pull-down",
|
2020-06-04 12:30:33 +00:00
|
|
|
};
|
|
|
|
|
2021-01-21 16:39:07 +00:00
|
|
|
static const char * const pinmux_otype[] = {
|
2020-10-28 09:49:07 +00:00
|
|
|
[STM32_GPIO_OTYPE_PP] = "push-pull",
|
|
|
|
[STM32_GPIO_OTYPE_OD] = "open-drain",
|
2020-06-04 12:30:33 +00:00
|
|
|
};
|
|
|
|
|
2018-10-24 12:10:20 +00:00
|
|
|
static int stm32_pinctrl_get_af(struct udevice *dev, unsigned int offset)
|
|
|
|
{
|
|
|
|
struct stm32_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
struct stm32_gpio_regs *regs = priv->regs;
|
|
|
|
u32 af;
|
|
|
|
u32 alt_shift = (offset % 8) * 4;
|
|
|
|
u32 alt_index = offset / 8;
|
|
|
|
|
|
|
|
af = (readl(®s->afr[alt_index]) &
|
|
|
|
GENMASK(alt_shift + 3, alt_shift)) >> alt_shift;
|
|
|
|
|
|
|
|
return af;
|
|
|
|
}
|
|
|
|
|
2018-12-03 09:52:50 +00:00
|
|
|
static int stm32_populate_gpio_dev_list(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct stm32_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
struct udevice *child;
|
|
|
|
struct stm32_gpio_bank *gpio_bank;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse pin-controller sub-nodes (ie gpio bank nodes) and fill
|
|
|
|
* a list with all gpio device reference which belongs to the
|
|
|
|
* current pin-controller. This list is used to find pin_name and
|
|
|
|
* pin muxing
|
|
|
|
*/
|
|
|
|
list_for_each_entry(child, &dev->child_head, sibling_node) {
|
|
|
|
ret = uclass_get_device_by_name(UCLASS_GPIO, child->name,
|
|
|
|
&gpio_dev);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gpio_bank = malloc(sizeof(*gpio_bank));
|
|
|
|
if (!gpio_bank) {
|
|
|
|
dev_err(dev, "Not enough memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpio_bank->gpio_dev = gpio_dev;
|
|
|
|
list_add_tail(&gpio_bank->list, &priv->gpio_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:10:18 +00:00
|
|
|
static int stm32_pinctrl_get_pins_count(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct stm32_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
struct gpio_dev_priv *uc_priv;
|
|
|
|
struct stm32_gpio_bank *gpio_bank;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if get_pins_count has already been executed once on this
|
|
|
|
* pin-controller, no need to run it again
|
|
|
|
*/
|
|
|
|
if (priv->pinctrl_ngpios)
|
|
|
|
return priv->pinctrl_ngpios;
|
|
|
|
|
2018-12-03 09:52:50 +00:00
|
|
|
if (list_empty(&priv->gpio_dev))
|
|
|
|
stm32_populate_gpio_dev_list(dev);
|
2018-10-24 12:10:18 +00:00
|
|
|
/*
|
|
|
|
* walk through all banks to retrieve the pin-controller
|
|
|
|
* pins number
|
|
|
|
*/
|
|
|
|
list_for_each_entry(gpio_bank, &priv->gpio_dev, list) {
|
|
|
|
uc_priv = dev_get_uclass_priv(gpio_bank->gpio_dev);
|
|
|
|
|
|
|
|
priv->pinctrl_ngpios += uc_priv->gpio_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv->pinctrl_ngpios;
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:10:19 +00:00
|
|
|
static struct udevice *stm32_pinctrl_get_gpio_dev(struct udevice *dev,
|
2018-12-03 09:52:54 +00:00
|
|
|
unsigned int selector,
|
|
|
|
unsigned int *idx)
|
2018-10-24 12:10:19 +00:00
|
|
|
{
|
|
|
|
struct stm32_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
struct stm32_gpio_bank *gpio_bank;
|
|
|
|
struct gpio_dev_priv *uc_priv;
|
2018-12-03 09:52:54 +00:00
|
|
|
int pin_count = 0;
|
2018-10-24 12:10:19 +00:00
|
|
|
|
2018-12-03 09:52:50 +00:00
|
|
|
if (list_empty(&priv->gpio_dev))
|
|
|
|
stm32_populate_gpio_dev_list(dev);
|
|
|
|
|
2018-10-24 12:10:19 +00:00
|
|
|
/* look up for the bank which owns the requested pin */
|
|
|
|
list_for_each_entry(gpio_bank, &priv->gpio_dev, list) {
|
|
|
|
uc_priv = dev_get_uclass_priv(gpio_bank->gpio_dev);
|
|
|
|
|
2018-12-03 09:52:54 +00:00
|
|
|
if (selector < (pin_count + uc_priv->gpio_count)) {
|
|
|
|
/*
|
|
|
|
* we found the bank, convert pin selector to
|
|
|
|
* gpio bank index
|
|
|
|
*/
|
|
|
|
*idx = stm32_offset_to_index(gpio_bank->gpio_dev,
|
|
|
|
selector - pin_count);
|
2019-06-21 13:26:52 +00:00
|
|
|
if (IS_ERR_VALUE(*idx))
|
2018-12-03 09:52:54 +00:00
|
|
|
return NULL;
|
2018-10-24 12:10:19 +00:00
|
|
|
|
2018-12-03 09:52:54 +00:00
|
|
|
return gpio_bank->gpio_dev;
|
|
|
|
}
|
|
|
|
pin_count += uc_priv->gpio_count;
|
2018-10-24 12:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *stm32_pinctrl_get_pin_name(struct udevice *dev,
|
|
|
|
unsigned int selector)
|
|
|
|
{
|
|
|
|
struct gpio_dev_priv *uc_priv;
|
|
|
|
struct udevice *gpio_dev;
|
2018-12-03 09:52:54 +00:00
|
|
|
unsigned int gpio_idx;
|
2018-10-24 12:10:19 +00:00
|
|
|
|
|
|
|
/* look up for the bank which owns the requested pin */
|
2018-12-03 09:52:54 +00:00
|
|
|
gpio_dev = stm32_pinctrl_get_gpio_dev(dev, selector, &gpio_idx);
|
2018-10-24 12:10:19 +00:00
|
|
|
if (!gpio_dev) {
|
|
|
|
snprintf(pin_name, PINNAME_SIZE, "Error");
|
|
|
|
} else {
|
|
|
|
uc_priv = dev_get_uclass_priv(gpio_dev);
|
|
|
|
|
|
|
|
snprintf(pin_name, PINNAME_SIZE, "%s%d",
|
|
|
|
uc_priv->bank_name,
|
2018-12-03 09:52:54 +00:00
|
|
|
gpio_idx);
|
2018-10-24 12:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pin_name;
|
|
|
|
}
|
2018-10-24 12:10:20 +00:00
|
|
|
|
|
|
|
static int stm32_pinctrl_get_pin_muxing(struct udevice *dev,
|
|
|
|
unsigned int selector,
|
|
|
|
char *buf,
|
|
|
|
int size)
|
|
|
|
{
|
|
|
|
struct udevice *gpio_dev;
|
2020-06-04 12:30:33 +00:00
|
|
|
struct stm32_gpio_priv *priv;
|
2018-10-24 12:10:20 +00:00
|
|
|
const char *label;
|
|
|
|
int mode;
|
|
|
|
int af_num;
|
2018-12-03 09:52:54 +00:00
|
|
|
unsigned int gpio_idx;
|
2020-06-04 12:30:33 +00:00
|
|
|
u32 pupd, otype;
|
2018-10-24 12:10:20 +00:00
|
|
|
|
|
|
|
/* look up for the bank which owns the requested pin */
|
2018-12-03 09:52:54 +00:00
|
|
|
gpio_dev = stm32_pinctrl_get_gpio_dev(dev, selector, &gpio_idx);
|
2018-10-24 12:10:20 +00:00
|
|
|
|
|
|
|
if (!gpio_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2018-12-03 09:52:54 +00:00
|
|
|
mode = gpio_get_raw_function(gpio_dev, gpio_idx, &label);
|
|
|
|
dev_dbg(dev, "selector = %d gpio_idx = %d mode = %d\n",
|
|
|
|
selector, gpio_idx, mode);
|
2020-06-04 12:30:33 +00:00
|
|
|
priv = dev_get_priv(gpio_dev);
|
2020-10-28 09:49:07 +00:00
|
|
|
pupd = (readl(&priv->regs->pupdr) >> (gpio_idx * 2)) & PUPD_MASK;
|
2021-01-21 16:39:07 +00:00
|
|
|
otype = (readl(&priv->regs->otyper) >> gpio_idx) & OTYPE_MSK;
|
2018-10-24 12:10:20 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case GPIOF_UNKNOWN:
|
|
|
|
/* should never happen */
|
|
|
|
return -EINVAL;
|
|
|
|
case GPIOF_UNUSED:
|
|
|
|
snprintf(buf, size, "%s", pinmux_mode[mode]);
|
|
|
|
break;
|
|
|
|
case GPIOF_FUNC:
|
2018-12-03 09:52:54 +00:00
|
|
|
af_num = stm32_pinctrl_get_af(gpio_dev, gpio_idx);
|
2021-01-21 16:39:07 +00:00
|
|
|
snprintf(buf, size, "%s %d %s %s", pinmux_mode[mode], af_num,
|
|
|
|
pinmux_otype[otype], pinmux_bias[pupd]);
|
2018-10-24 12:10:20 +00:00
|
|
|
break;
|
|
|
|
case GPIOF_OUTPUT:
|
2021-01-21 16:39:07 +00:00
|
|
|
snprintf(buf, size, "%s %s %s %s",
|
|
|
|
pinmux_mode[mode], pinmux_otype[otype],
|
|
|
|
pinmux_bias[pupd], label ? label : "");
|
2020-06-04 12:30:33 +00:00
|
|
|
break;
|
2018-10-24 12:10:20 +00:00
|
|
|
case GPIOF_INPUT:
|
2021-01-21 16:39:07 +00:00
|
|
|
snprintf(buf, size, "%s %s %s", pinmux_mode[mode],
|
2020-10-28 09:49:07 +00:00
|
|
|
pinmux_bias[pupd], label ? label : "");
|
2018-10-24 12:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-27 12:49:53 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-21 13:26:52 +00:00
|
|
|
static int stm32_pinctrl_probe(struct udevice *dev)
|
2018-10-24 12:10:18 +00:00
|
|
|
{
|
|
|
|
struct stm32_pinctrl_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&priv->gpio_dev);
|
|
|
|
|
2018-11-27 12:49:53 +00:00
|
|
|
/* hwspinlock property is optional, just log the error */
|
|
|
|
ret = hwspinlock_get_by_index(dev, 0, &priv->hws);
|
|
|
|
if (ret)
|
2020-11-06 18:01:32 +00:00
|
|
|
dev_dbg(dev, "hwspinlock_get_by_index may have failed (%d)\n",
|
|
|
|
ret);
|
2018-11-27 12:49:53 +00:00
|
|
|
|
2018-10-24 12:10:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:02:57 +00:00
|
|
|
static int stm32_gpio_config(struct gpio_desc *desc,
|
|
|
|
const struct stm32_gpio_ctl *ctl)
|
|
|
|
{
|
|
|
|
struct stm32_gpio_priv *priv = dev_get_priv(desc->dev);
|
|
|
|
struct stm32_gpio_regs *regs = priv->regs;
|
2018-11-27 12:49:53 +00:00
|
|
|
struct stm32_pinctrl_priv *ctrl_priv;
|
|
|
|
int ret;
|
2017-04-10 22:02:57 +00:00
|
|
|
u32 index;
|
|
|
|
|
|
|
|
if (!ctl || ctl->af > 15 || ctl->mode > 3 || ctl->otype > 1 ||
|
|
|
|
ctl->pupd > 2 || ctl->speed > 3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-11-27 12:49:53 +00:00
|
|
|
ctrl_priv = dev_get_priv(dev_get_parent(desc->dev));
|
|
|
|
ret = hwspinlock_lock_timeout(&ctrl_priv->hws, 10);
|
|
|
|
if (ret == -ETIME) {
|
|
|
|
dev_err(desc->dev, "HWSpinlock timeout\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:02:57 +00:00
|
|
|
index = (desc->offset & 0x07) * 4;
|
|
|
|
clrsetbits_le32(®s->afr[desc->offset >> 3], AFR_MASK << index,
|
|
|
|
ctl->af << index);
|
|
|
|
|
|
|
|
index = desc->offset * 2;
|
|
|
|
clrsetbits_le32(®s->moder, MODE_BITS_MASK << index,
|
|
|
|
ctl->mode << index);
|
|
|
|
clrsetbits_le32(®s->ospeedr, OSPEED_MASK << index,
|
|
|
|
ctl->speed << index);
|
|
|
|
clrsetbits_le32(®s->pupdr, PUPD_MASK << index, ctl->pupd << index);
|
|
|
|
|
|
|
|
index = desc->offset;
|
|
|
|
clrsetbits_le32(®s->otyper, OTYPE_MSK << index, ctl->otype << index);
|
|
|
|
|
2018-11-27 12:49:53 +00:00
|
|
|
hwspinlock_unlock(&ctrl_priv->hws);
|
|
|
|
|
2017-04-10 22:02:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-12 09:46:13 +00:00
|
|
|
|
2017-02-12 18:25:49 +00:00
|
|
|
static int prep_gpio_dsc(struct stm32_gpio_dsc *gpio_dsc, u32 port_pin)
|
|
|
|
{
|
2018-03-12 09:46:13 +00:00
|
|
|
gpio_dsc->port = (port_pin & 0x1F000) >> 12;
|
2017-02-12 18:25:49 +00:00
|
|
|
gpio_dsc->pin = (port_pin & 0x0F00) >> 8;
|
2020-11-06 18:01:32 +00:00
|
|
|
log_debug("GPIO:port= %d, pin= %d\n", gpio_dsc->port, gpio_dsc->pin);
|
2017-02-12 18:25:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
static int prep_gpio_ctl(struct stm32_gpio_ctl *gpio_ctl, u32 gpio_fn,
|
|
|
|
ofnode node)
|
2017-02-12 18:25:49 +00:00
|
|
|
{
|
|
|
|
gpio_fn &= 0x00FF;
|
2017-04-10 22:02:57 +00:00
|
|
|
gpio_ctl->af = 0;
|
2017-02-12 18:25:49 +00:00
|
|
|
|
|
|
|
switch (gpio_fn) {
|
|
|
|
case 0:
|
|
|
|
gpio_ctl->mode = STM32_GPIO_MODE_IN;
|
|
|
|
break;
|
|
|
|
case 1 ... 16:
|
|
|
|
gpio_ctl->mode = STM32_GPIO_MODE_AF;
|
|
|
|
gpio_ctl->af = gpio_fn - 1;
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
gpio_ctl->mode = STM32_GPIO_MODE_AN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gpio_ctl->mode = STM32_GPIO_MODE_OUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
gpio_ctl->speed = ofnode_read_u32_default(node, "slew-rate", 0);
|
2017-02-12 18:25:49 +00:00
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
if (ofnode_read_bool(node, "drive-open-drain"))
|
2017-02-12 18:25:49 +00:00
|
|
|
gpio_ctl->otype = STM32_GPIO_OTYPE_OD;
|
|
|
|
else
|
|
|
|
gpio_ctl->otype = STM32_GPIO_OTYPE_PP;
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
if (ofnode_read_bool(node, "bias-pull-up"))
|
2017-02-12 18:25:49 +00:00
|
|
|
gpio_ctl->pupd = STM32_GPIO_PUPD_UP;
|
2020-09-09 15:50:14 +00:00
|
|
|
else if (ofnode_read_bool(node, "bias-pull-down"))
|
2017-02-12 18:25:49 +00:00
|
|
|
gpio_ctl->pupd = STM32_GPIO_PUPD_DOWN;
|
|
|
|
else
|
|
|
|
gpio_ctl->pupd = STM32_GPIO_PUPD_NO;
|
|
|
|
|
2020-11-06 18:01:32 +00:00
|
|
|
log_debug("gpio fn= %d, slew-rate= %x, op type= %x, pull-upd is = %x\n",
|
|
|
|
gpio_fn, gpio_ctl->speed, gpio_ctl->otype,
|
|
|
|
gpio_ctl->pupd);
|
2017-02-12 18:25:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
static int stm32_pinctrl_config(ofnode node)
|
2017-02-12 18:25:49 +00:00
|
|
|
{
|
2017-04-10 22:03:04 +00:00
|
|
|
u32 pin_mux[MAX_PINS_ONE_IP];
|
2017-02-12 18:25:49 +00:00
|
|
|
int rv, len;
|
2020-09-09 15:50:14 +00:00
|
|
|
ofnode subnode;
|
2017-02-12 18:25:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for "pinmux" property in each subnode (e.g. pins1 and pins2 for
|
|
|
|
* usart1) of pin controller phandle "pinctrl-0"
|
|
|
|
* */
|
2020-09-09 15:50:14 +00:00
|
|
|
ofnode_for_each_subnode(subnode, node) {
|
2017-02-12 18:25:49 +00:00
|
|
|
struct stm32_gpio_dsc gpio_dsc;
|
|
|
|
struct stm32_gpio_ctl gpio_ctl;
|
|
|
|
int i;
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
rv = ofnode_read_size(subnode, "pinmux");
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
|
|
|
len = rv / sizeof(pin_mux[0]);
|
2020-11-06 18:01:32 +00:00
|
|
|
log_debug("No of pinmux entries= %d\n", len);
|
2020-09-09 15:50:14 +00:00
|
|
|
if (len > MAX_PINS_ONE_IP)
|
2017-02-12 18:25:49 +00:00
|
|
|
return -EINVAL;
|
2020-09-09 15:50:14 +00:00
|
|
|
rv = ofnode_read_u32_array(subnode, "pinmux", pin_mux, len);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2017-02-12 18:25:49 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2017-04-10 22:02:59 +00:00
|
|
|
struct gpio_desc desc;
|
2018-03-12 09:46:13 +00:00
|
|
|
|
2020-11-06 18:01:32 +00:00
|
|
|
log_debug("pinmux = %x\n", *(pin_mux + i));
|
2017-02-12 18:25:49 +00:00
|
|
|
prep_gpio_dsc(&gpio_dsc, *(pin_mux + i));
|
2020-09-09 15:50:14 +00:00
|
|
|
prep_gpio_ctl(&gpio_ctl, *(pin_mux + i), subnode);
|
2017-04-10 22:02:59 +00:00
|
|
|
rv = uclass_get_device_by_seq(UCLASS_GPIO,
|
2018-03-12 09:46:13 +00:00
|
|
|
gpio_dsc.port,
|
|
|
|
&desc.dev);
|
2017-04-10 22:02:59 +00:00
|
|
|
if (rv)
|
|
|
|
return rv;
|
|
|
|
desc.offset = gpio_dsc.pin;
|
|
|
|
rv = stm32_gpio_config(&desc, &gpio_ctl);
|
2020-11-06 18:01:32 +00:00
|
|
|
log_debug("rv = %d\n\n", rv);
|
2017-02-12 18:25:49 +00:00
|
|
|
if (rv)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-21 13:39:23 +00:00
|
|
|
static int stm32_pinctrl_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
ofnode node;
|
|
|
|
const char *name;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_for_each_subnode(node, dev) {
|
2020-11-06 18:01:32 +00:00
|
|
|
dev_dbg(dev, "bind %s\n", ofnode_get_name(node));
|
2019-06-21 13:39:23 +00:00
|
|
|
|
2021-01-21 16:39:08 +00:00
|
|
|
if (!ofnode_is_enabled(node))
|
|
|
|
continue;
|
|
|
|
|
2019-06-21 13:39:23 +00:00
|
|
|
ofnode_get_property(node, "gpio-controller", &ret);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
/* Get the name of each gpio node */
|
|
|
|
name = ofnode_get_name(node);
|
|
|
|
if (!name)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Bind each gpio node */
|
|
|
|
ret = device_bind_driver_to_node(dev, "gpio_stm32",
|
|
|
|
name, node, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-11-06 18:01:32 +00:00
|
|
|
dev_dbg(dev, "bind %s\n", name);
|
2019-06-21 13:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-20 15:04:19 +00:00
|
|
|
#if CONFIG_IS_ENABLED(PINCTRL_FULL)
|
|
|
|
static int stm32_pinctrl_set_state(struct udevice *dev, struct udevice *config)
|
|
|
|
{
|
2020-09-09 15:50:14 +00:00
|
|
|
return stm32_pinctrl_config(dev_ofnode(config));
|
2017-06-20 15:04:19 +00:00
|
|
|
}
|
|
|
|
#else /* PINCTRL_FULL */
|
2017-06-20 15:04:18 +00:00
|
|
|
static int stm32_pinctrl_set_state_simple(struct udevice *dev,
|
|
|
|
struct udevice *periph)
|
|
|
|
{
|
|
|
|
const fdt32_t *list;
|
|
|
|
uint32_t phandle;
|
2020-09-09 15:50:14 +00:00
|
|
|
ofnode config_node;
|
2017-06-20 15:04:18 +00:00
|
|
|
int size, i, ret;
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
list = ofnode_get_property(dev_ofnode(periph), "pinctrl-0", &size);
|
2017-06-20 15:04:18 +00:00
|
|
|
if (!list)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-11-06 18:01:32 +00:00
|
|
|
dev_dbg(dev, "periph->name = %s\n", periph->name);
|
2017-06-20 15:04:18 +00:00
|
|
|
|
|
|
|
size /= sizeof(*list);
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
phandle = fdt32_to_cpu(*list++);
|
|
|
|
|
2020-09-09 15:50:14 +00:00
|
|
|
config_node = ofnode_get_by_phandle(phandle);
|
|
|
|
if (!ofnode_valid(config_node)) {
|
2020-11-06 18:01:32 +00:00
|
|
|
dev_err(periph,
|
|
|
|
"prop pinctrl-0 index %d invalid phandle\n", i);
|
2017-06-20 15:04:18 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = stm32_pinctrl_config(config_node);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-20 15:04:19 +00:00
|
|
|
#endif /* PINCTRL_FULL */
|
2017-06-20 15:04:18 +00:00
|
|
|
|
2017-02-12 18:25:49 +00:00
|
|
|
static struct pinctrl_ops stm32_pinctrl_ops = {
|
2017-06-20 15:04:19 +00:00
|
|
|
#if CONFIG_IS_ENABLED(PINCTRL_FULL)
|
|
|
|
.set_state = stm32_pinctrl_set_state,
|
|
|
|
#else /* PINCTRL_FULL */
|
2017-02-12 18:25:49 +00:00
|
|
|
.set_state_simple = stm32_pinctrl_set_state_simple,
|
2017-06-20 15:04:19 +00:00
|
|
|
#endif /* PINCTRL_FULL */
|
2018-10-24 12:10:18 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2018-10-24 12:10:19 +00:00
|
|
|
.get_pin_name = stm32_pinctrl_get_pin_name,
|
2018-10-24 12:10:18 +00:00
|
|
|
.get_pins_count = stm32_pinctrl_get_pins_count,
|
2018-10-24 12:10:20 +00:00
|
|
|
.get_pin_muxing = stm32_pinctrl_get_pin_muxing,
|
2018-10-24 12:10:18 +00:00
|
|
|
#endif
|
2017-02-12 18:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id stm32_pinctrl_ids[] = {
|
2017-12-12 08:49:35 +00:00
|
|
|
{ .compatible = "st,stm32f429-pinctrl" },
|
|
|
|
{ .compatible = "st,stm32f469-pinctrl" },
|
2017-02-12 18:25:49 +00:00
|
|
|
{ .compatible = "st,stm32f746-pinctrl" },
|
2018-12-11 13:49:18 +00:00
|
|
|
{ .compatible = "st,stm32f769-pinctrl" },
|
2017-09-13 16:00:04 +00:00
|
|
|
{ .compatible = "st,stm32h743-pinctrl" },
|
2018-03-12 09:46:13 +00:00
|
|
|
{ .compatible = "st,stm32mp157-pinctrl" },
|
|
|
|
{ .compatible = "st,stm32mp157-z-pinctrl" },
|
2017-02-12 18:25:49 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(pinctrl_stm32) = {
|
2018-10-24 12:10:18 +00:00
|
|
|
.name = "pinctrl_stm32",
|
|
|
|
.id = UCLASS_PINCTRL,
|
|
|
|
.of_match = stm32_pinctrl_ids,
|
|
|
|
.ops = &stm32_pinctrl_ops,
|
2019-06-21 13:39:23 +00:00
|
|
|
.bind = stm32_pinctrl_bind,
|
2018-10-24 12:10:18 +00:00
|
|
|
.probe = stm32_pinctrl_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct stm32_pinctrl_priv),
|
2017-02-12 18:25:49 +00:00
|
|
|
};
|