2017-07-26 19:36:39 +08:00
|
|
|
/*
|
2020-06-25 23:25:21 +08:00
|
|
|
* Copyright (c) 2017-2020, NXP
|
2017-07-26 19:36:39 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-04-17 23:37:37 +08:00
|
|
|
#define DT_DRV_COMPAT nxp_lpc_iocon_pio
|
|
|
|
|
2017-07-26 19:36:39 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <device.h>
|
2019-06-26 03:53:57 +08:00
|
|
|
#include <drivers/pinmux.h>
|
2017-07-26 19:36:39 +08:00
|
|
|
#include <fsl_common.h>
|
|
|
|
#include <fsl_clock.h>
|
|
|
|
#include <fsl_device_registers.h>
|
|
|
|
|
|
|
|
struct pinmux_mcux_lpc_config {
|
|
|
|
clock_ip_name_t clock_ip_name;
|
2020-04-17 23:37:37 +08:00
|
|
|
volatile uint32_t *base;
|
2017-07-26 19:36:39 +08:00
|
|
|
};
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int pinmux_mcux_lpc_set(const struct device *dev, uint32_t pin,
|
|
|
|
uint32_t func)
|
2017-07-26 19:36:39 +08:00
|
|
|
{
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct pinmux_mcux_lpc_config *config = dev->config;
|
2020-04-17 23:37:37 +08:00
|
|
|
volatile uint32_t *base = config->base;
|
2017-07-26 19:36:39 +08:00
|
|
|
|
2020-04-17 23:37:37 +08:00
|
|
|
base[pin] = func;
|
2017-07-26 19:36:39 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int pinmux_mcux_lpc_get(const struct device *dev, uint32_t pin,
|
|
|
|
uint32_t *func)
|
2017-07-26 19:36:39 +08:00
|
|
|
{
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct pinmux_mcux_lpc_config *config = dev->config;
|
2020-04-17 23:37:37 +08:00
|
|
|
volatile uint32_t *base = config->base;
|
2017-07-26 19:36:39 +08:00
|
|
|
|
2020-04-17 23:37:37 +08:00
|
|
|
*func = base[pin];
|
2017-07-26 19:36:39 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int pinmux_mcux_lpc_pullup(const struct device *dev, uint32_t pin,
|
|
|
|
uint8_t func)
|
2017-07-26 19:36:39 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int pinmux_mcux_lpc_input(const struct device *dev, uint32_t pin,
|
|
|
|
uint8_t func)
|
2017-07-26 19:36:39 +08:00
|
|
|
{
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int pinmux_mcux_lpc_init(const struct device *dev)
|
2017-07-26 19:36:39 +08:00
|
|
|
{
|
2020-06-25 23:25:21 +08:00
|
|
|
#ifndef IOPCTL
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct pinmux_mcux_lpc_config *config = dev->config;
|
2017-07-26 19:36:39 +08:00
|
|
|
|
|
|
|
CLOCK_EnableClock(config->clock_ip_name);
|
2020-06-25 23:25:21 +08:00
|
|
|
#endif
|
2017-07-26 19:36:39 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pinmux_driver_api pinmux_mcux_driver_api = {
|
|
|
|
.set = pinmux_mcux_lpc_set,
|
|
|
|
.get = pinmux_mcux_lpc_get,
|
|
|
|
.pullup = pinmux_mcux_lpc_pullup,
|
|
|
|
.input = pinmux_mcux_lpc_input,
|
|
|
|
};
|
|
|
|
|
2020-06-25 23:25:21 +08:00
|
|
|
#ifdef IOPCTL
|
2020-04-17 23:37:37 +08:00
|
|
|
#define LPC_CLOCK_IP_NAME kCLOCK_IpInvalid
|
2020-06-25 23:25:21 +08:00
|
|
|
#else
|
2020-04-17 23:37:37 +08:00
|
|
|
#define LPC_CLOCK_IP_NAME kCLOCK_Iocon
|
2020-06-25 23:25:21 +08:00
|
|
|
#endif
|
2017-07-26 19:36:39 +08:00
|
|
|
|
2020-04-17 23:37:37 +08:00
|
|
|
#define PINMUX_LPC_INIT(n) \
|
|
|
|
static const struct pinmux_mcux_lpc_config \
|
|
|
|
pinmux_mcux_lpc_port##n##_cfg = { \
|
|
|
|
.base = (uint32_t *)DT_INST_REG_ADDR(n), \
|
|
|
|
.clock_ip_name = LPC_CLOCK_IP_NAME, \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
DEVICE_DT_INST_DEFINE(n, \
|
|
|
|
&pinmux_mcux_lpc_init, \
|
2021-04-28 17:30:51 +08:00
|
|
|
NULL, \
|
2020-04-17 23:37:37 +08:00
|
|
|
NULL, &pinmux_mcux_lpc_port##n##_cfg, \
|
|
|
|
PRE_KERNEL_1, \
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
|
|
|
&pinmux_mcux_driver_api);
|
|
|
|
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(PINMUX_LPC_INIT)
|