2018-11-08 02:13:52 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Freescale Semiconductor, Inc.
|
|
|
|
* Copyright (c) 2018 Foundries.io
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-04-04 01:08:55 +08:00
|
|
|
#define DT_DRV_COMPAT openisa_rv32m1_pinmux
|
|
|
|
|
2018-11-08 02:13:52 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <device.h>
|
2019-06-26 03:53:57 +08:00
|
|
|
#include <drivers/pinmux.h>
|
2018-11-08 02:13:52 +08:00
|
|
|
|
|
|
|
#include <fsl_common.h>
|
|
|
|
#include <fsl_clock.h>
|
|
|
|
|
|
|
|
struct pinmux_rv32m1_config {
|
|
|
|
clock_ip_name_t clock_ip_name;
|
|
|
|
PORT_Type *base;
|
|
|
|
};
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static int pinmux_rv32m1_set(struct device *dev, uint32_t pin, uint32_t func)
|
2018-11-08 02:13:52 +08:00
|
|
|
{
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct pinmux_rv32m1_config *config = dev->config;
|
2018-11-08 02:13:52 +08:00
|
|
|
PORT_Type *base = config->base;
|
|
|
|
|
|
|
|
base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_MUX_MASK) | func;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static int pinmux_rv32m1_get(struct device *dev, uint32_t pin, uint32_t *func)
|
2018-11-08 02:13:52 +08:00
|
|
|
{
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct pinmux_rv32m1_config *config = dev->config;
|
2018-11-08 02:13:52 +08:00
|
|
|
PORT_Type *base = config->base;
|
|
|
|
|
|
|
|
*func = base->PCR[pin] & ~PORT_PCR_MUX_MASK;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static int pinmux_rv32m1_pullup(struct device *dev, uint32_t pin, uint8_t func)
|
2018-11-08 02:13:52 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static int pinmux_rv32m1_input(struct device *dev, uint32_t pin, uint8_t func)
|
2018-11-08 02:13:52 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pinmux_rv32m1_init(struct device *dev)
|
|
|
|
{
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct pinmux_rv32m1_config *config = dev->config;
|
2018-11-08 02:13:52 +08:00
|
|
|
|
|
|
|
CLOCK_EnableClock(config->clock_ip_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pinmux_driver_api pinmux_rv32m1_driver_api = {
|
|
|
|
.set = pinmux_rv32m1_set,
|
|
|
|
.get = pinmux_rv32m1_get,
|
|
|
|
.pullup = pinmux_rv32m1_pullup,
|
|
|
|
.input = pinmux_rv32m1_input,
|
|
|
|
};
|
|
|
|
|
2020-04-04 01:08:55 +08:00
|
|
|
#define PINMUX_RV32M1_INIT(n) \
|
|
|
|
static const struct pinmux_rv32m1_config pinmux_rv32m1_##n##_config = {\
|
|
|
|
.base = (PORT_Type *)DT_INST_REG_ADDR(n), \
|
|
|
|
.clock_ip_name = INST_DT_CLOCK_IP_NAME(n), \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
DEVICE_AND_API_INIT(pinmux_rv32m1_##n, DT_INST_LABEL(n), \
|
|
|
|
&pinmux_rv32m1_init, \
|
|
|
|
NULL, &pinmux_rv32m1_##n##_config, \
|
|
|
|
PRE_KERNEL_1, \
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
2020-05-08 03:09:05 +08:00
|
|
|
&pinmux_rv32m1_driver_api);
|
2020-04-04 01:08:55 +08:00
|
|
|
|
2020-05-07 02:23:07 +08:00
|
|
|
DT_INST_FOREACH_STATUS_OKAY(PINMUX_RV32M1_INIT)
|