2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-07-20 09:16:27 +00:00
|
|
|
/*
|
|
|
|
* Atmel PIO4 pinctrl driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Atmel Corporation
|
|
|
|
* Wenyou.Yang <wenyou.yang@atmel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2017-05-17 23:18:03 +00:00
|
|
|
#include <dm.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-07-20 09:16:27 +00:00
|
|
|
#include <dm/pinctrl.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2016-07-20 09:16:27 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <mach/atmel_pio4.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Warning:
|
|
|
|
* In order to not introduce confusion between Atmel PIO groups and pinctrl
|
|
|
|
* framework groups, Atmel PIO groups will be called banks.
|
|
|
|
*/
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct atmel_pio4_plat {
|
2016-07-20 09:16:27 +00:00
|
|
|
struct atmel_pio4_port *reg_base;
|
2021-01-27 13:00:30 +00:00
|
|
|
unsigned int slew_rate_support;
|
2016-07-20 09:16:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pinconf_param conf_params[] = {
|
|
|
|
{ "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
|
|
|
|
{ "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
|
|
|
|
{ "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
|
|
|
|
{ "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
|
|
|
|
{ "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },
|
|
|
|
{ "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },
|
|
|
|
{ "input-debounce", PIN_CONFIG_INPUT_DEBOUNCE, 0 },
|
2021-01-05 08:54:01 +00:00
|
|
|
{ "atmel,drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
|
2021-01-27 13:00:30 +00:00
|
|
|
{ "slew-rate", PIN_CONFIG_SLEW_RATE, 0},
|
2016-07-20 09:16:27 +00:00
|
|
|
};
|
|
|
|
|
2021-01-27 13:00:30 +00:00
|
|
|
static u32 atmel_pinctrl_get_pinconf(struct udevice *config,
|
|
|
|
struct atmel_pio4_plat *plat)
|
2016-07-20 09:16:27 +00:00
|
|
|
{
|
|
|
|
const struct pinconf_param *params;
|
|
|
|
u32 param, arg, conf = 0;
|
|
|
|
u32 i;
|
2021-01-05 08:54:01 +00:00
|
|
|
u32 val;
|
2016-07-20 09:16:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(conf_params); i++) {
|
|
|
|
params = &conf_params[i];
|
2021-01-05 08:51:53 +00:00
|
|
|
if (!dev_read_prop(config, params->property, NULL))
|
2016-07-20 09:16:27 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
param = params->param;
|
|
|
|
arg = params->default_value;
|
|
|
|
|
2021-01-27 13:00:30 +00:00
|
|
|
/* Keep slew rate enabled by default. */
|
|
|
|
if (plat->slew_rate_support)
|
|
|
|
conf |= ATMEL_PIO_SR;
|
|
|
|
|
2016-07-20 09:16:27 +00:00
|
|
|
switch (param) {
|
|
|
|
case PIN_CONFIG_BIAS_DISABLE:
|
|
|
|
conf &= (~ATMEL_PIO_PUEN_MASK);
|
|
|
|
conf &= (~ATMEL_PIO_PDEN_MASK);
|
|
|
|
break;
|
|
|
|
case PIN_CONFIG_BIAS_PULL_UP:
|
|
|
|
conf |= ATMEL_PIO_PUEN_MASK;
|
|
|
|
break;
|
|
|
|
case PIN_CONFIG_BIAS_PULL_DOWN:
|
|
|
|
conf |= ATMEL_PIO_PDEN_MASK;
|
|
|
|
break;
|
|
|
|
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
|
|
|
|
if (arg == 0)
|
|
|
|
conf &= (~ATMEL_PIO_OPD_MASK);
|
|
|
|
else
|
|
|
|
conf |= ATMEL_PIO_OPD_MASK;
|
|
|
|
break;
|
|
|
|
case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
|
|
|
|
if (arg == 0)
|
|
|
|
conf |= ATMEL_PIO_SCHMITT_MASK;
|
|
|
|
else
|
|
|
|
conf &= (~ATMEL_PIO_SCHMITT_MASK);
|
|
|
|
break;
|
|
|
|
case PIN_CONFIG_INPUT_DEBOUNCE:
|
|
|
|
if (arg == 0) {
|
|
|
|
conf &= (~ATMEL_PIO_IFEN_MASK);
|
|
|
|
conf &= (~ATMEL_PIO_IFSCEN_MASK);
|
|
|
|
} else {
|
|
|
|
conf |= ATMEL_PIO_IFEN_MASK;
|
|
|
|
conf |= ATMEL_PIO_IFSCEN_MASK;
|
|
|
|
}
|
|
|
|
break;
|
2021-01-05 08:54:01 +00:00
|
|
|
case PIN_CONFIG_DRIVE_STRENGTH:
|
|
|
|
dev_read_u32(config, params->property, &val);
|
|
|
|
conf &= (~ATMEL_PIO_DRVSTR_MASK);
|
|
|
|
conf |= (val << ATMEL_PIO_DRVSTR_OFFSET)
|
|
|
|
& ATMEL_PIO_DRVSTR_MASK;
|
|
|
|
break;
|
2021-01-27 13:00:30 +00:00
|
|
|
case PIN_CONFIG_SLEW_RATE:
|
|
|
|
if (!plat->slew_rate_support)
|
|
|
|
break;
|
|
|
|
|
|
|
|
dev_read_u32(config, params->property, &val);
|
|
|
|
/* And disable it if requested. */
|
|
|
|
if (val == 0)
|
|
|
|
conf &= ~ATMEL_PIO_SR;
|
|
|
|
break;
|
2016-07-20 09:16:27 +00:00
|
|
|
default:
|
|
|
|
printf("%s: Unsupported configuration parameter: %u\n",
|
|
|
|
__func__, param);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct atmel_pio4_port *atmel_pio4_bank_base(struct udevice *dev,
|
|
|
|
u32 bank)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct atmel_pio4_plat *plat = dev_get_plat(dev);
|
2016-07-20 09:16:27 +00:00
|
|
|
struct atmel_pio4_port *bank_base =
|
|
|
|
(struct atmel_pio4_port *)((u32)plat->reg_base +
|
|
|
|
ATMEL_PIO_BANK_OFFSET * bank);
|
|
|
|
|
|
|
|
return bank_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_PINMUX_ENTRIES 40
|
|
|
|
|
|
|
|
static int atmel_pinctrl_set_state(struct udevice *dev, struct udevice *config)
|
|
|
|
{
|
2021-01-27 13:00:30 +00:00
|
|
|
struct atmel_pio4_plat *plat = dev_get_plat(dev);
|
2016-07-20 09:16:27 +00:00
|
|
|
struct atmel_pio4_port *bank_base;
|
|
|
|
const void *blob = gd->fdt_blob;
|
2017-01-17 23:52:55 +00:00
|
|
|
int node = dev_of_offset(config);
|
2016-07-20 09:16:27 +00:00
|
|
|
u32 offset, func, bank, line;
|
|
|
|
u32 cells[MAX_PINMUX_ENTRIES];
|
|
|
|
u32 i, conf;
|
|
|
|
int count;
|
|
|
|
|
2021-01-27 13:00:30 +00:00
|
|
|
conf = atmel_pinctrl_get_pinconf(config, plat);
|
2016-07-20 09:16:27 +00:00
|
|
|
|
|
|
|
count = fdtdec_get_int_array_count(blob, node, "pinmux",
|
|
|
|
cells, ARRAY_SIZE(cells));
|
|
|
|
if (count < 0) {
|
|
|
|
printf("%s: bad pinmux array %d\n", __func__, count);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > MAX_PINMUX_ENTRIES) {
|
|
|
|
printf("%s: unsupported pinmux array count %d\n",
|
|
|
|
__func__, count);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < count; i++) {
|
|
|
|
offset = ATMEL_GET_PIN_NO(cells[i]);
|
|
|
|
func = ATMEL_GET_PIN_FUNC(cells[i]);
|
|
|
|
|
|
|
|
bank = ATMEL_PIO_BANK(offset);
|
|
|
|
line = ATMEL_PIO_LINE(offset);
|
|
|
|
|
|
|
|
bank_base = atmel_pio4_bank_base(dev, bank);
|
|
|
|
|
|
|
|
writel(BIT(line), &bank_base->mskr);
|
|
|
|
conf &= (~ATMEL_PIO_CFGR_FUNC_MASK);
|
|
|
|
conf |= (func & ATMEL_PIO_CFGR_FUNC_MASK);
|
|
|
|
writel(conf, &bank_base->cfgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct pinctrl_ops atmel_pinctrl_ops = {
|
|
|
|
.set_state = atmel_pinctrl_set_state,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int atmel_pinctrl_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct atmel_pio4_plat *plat = dev_get_plat(dev);
|
2021-01-27 13:00:30 +00:00
|
|
|
ulong priv = dev_get_driver_data(dev);
|
2016-07-20 09:16:27 +00:00
|
|
|
fdt_addr_t addr_base;
|
|
|
|
|
|
|
|
dev = dev_get_parent(dev);
|
2020-07-17 05:36:48 +00:00
|
|
|
addr_base = dev_read_addr(dev);
|
2016-07-20 09:16:27 +00:00
|
|
|
if (addr_base == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
plat->reg_base = (struct atmel_pio4_port *)addr_base;
|
2021-01-27 13:00:30 +00:00
|
|
|
plat->slew_rate_support = priv;
|
2016-07-20 09:16:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id atmel_pinctrl_match[] = {
|
|
|
|
{ .compatible = "atmel,sama5d2-pinctrl" },
|
2021-01-27 13:00:30 +00:00
|
|
|
{ .compatible = "microchip,sama7g5-pinctrl",
|
|
|
|
.data = (ulong)1, },
|
2016-07-20 09:16:27 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(atmel_pinctrl) = {
|
|
|
|
.name = "pinctrl_atmel_pio4",
|
|
|
|
.id = UCLASS_PINCTRL,
|
|
|
|
.of_match = atmel_pinctrl_match,
|
|
|
|
.probe = atmel_pinctrl_probe,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct atmel_pio4_plat),
|
2016-07-20 09:16:27 +00:00
|
|
|
.ops = &atmel_pinctrl_ops,
|
|
|
|
};
|