From a4e823eee01f2e8e046099ad661f5399f2c4cdd4 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 23 Nov 2016 09:10:03 -0600 Subject: [PATCH] pinmux: Introduce new ksdk pinmux driver Kinetis SoCs contain one or more PORT modules to handle pin muxing and pin configuration. Unlike the existing k64 pinmux driver, this driver handles each PORT module individually and can be used for other Kinetis SoCs. This driver uses KSDK CMSIS register accesses to the PORT module rather than the KSDK PORT driver (fsl_port.h), because the Zephyr pinmux interface contains both set() and get() functions to access the pin configuration. The KSDK PORT driver only contains a set() function (which is a very thin static inline function to modify the PCR register), therefore building a shim on top of it would result in a strange mix of using the KSDK PORT driver for the set() and a direct CMSIS register access for the get(). Jira: ZEP-1393 Change-Id: I2f7c6b08b207350697d590dcd665223f81de9f9e Signed-off-by: Maureen Helm --- drivers/pinmux/Kconfig | 2 + drivers/pinmux/Kconfig.ksdk | 57 +++++++++++++ drivers/pinmux/Makefile | 5 +- drivers/pinmux/dev/Kconfig | 2 + drivers/pinmux/dev/Kconfig.ksdk | 52 ++++++++++++ drivers/pinmux/dev/Makefile | 1 + drivers/pinmux/dev/pinmux_dev_ksdk.c | 122 +++++++++++++++++++++++++++ drivers/pinmux/pinmux_ksdk.c | 39 +++++++++ drivers/pinmux/pinmux_ksdk.h | 37 ++++++++ 9 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 drivers/pinmux/Kconfig.ksdk create mode 100644 drivers/pinmux/dev/Kconfig.ksdk create mode 100644 drivers/pinmux/dev/pinmux_dev_ksdk.c create mode 100644 drivers/pinmux/pinmux_ksdk.c create mode 100644 drivers/pinmux/pinmux_ksdk.h diff --git a/drivers/pinmux/Kconfig b/drivers/pinmux/Kconfig index f4a904042bc..2ac5020799f 100644 --- a/drivers/pinmux/Kconfig +++ b/drivers/pinmux/Kconfig @@ -56,6 +56,8 @@ config PINMUX_K64 help Enable driver for Freescale K64-based Pin multiplexer. +source "drivers/pinmux/Kconfig.ksdk" + source "drivers/pinmux/Kconfig.stm32" source "drivers/pinmux/Kconfig.beetle" diff --git a/drivers/pinmux/Kconfig.ksdk b/drivers/pinmux/Kconfig.ksdk new file mode 100644 index 00000000000..0545d8d4d83 --- /dev/null +++ b/drivers/pinmux/Kconfig.ksdk @@ -0,0 +1,57 @@ +# Kconfig - Kinetis SDK pinmux +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +menuconfig PINMUX_KSDK + bool "KSDK pinmux driver" + depends on HAS_KSDK + default n + help + Enable the KSDK pinmux driver. + +if PINMUX_KSDK + +config PINMUX_KSDK_PORTA + bool "Port A" + default n + help + Enable Port A. + +config PINMUX_KSDK_PORTB + bool "Port B" + default n + help + Enable Port B. + +config PINMUX_KSDK_PORTC + bool "Port C" + default n + help + Enable Port C. + +config PINMUX_KSDK_PORTD + bool "Port D" + default n + help + Enable Port D. + +config PINMUX_KSDK_PORTE + bool "Port E" + default n + help + Enable Port E. + +endif # PINMUX_KSDK diff --git a/drivers/pinmux/Makefile b/drivers/pinmux/Makefile index b0114922c41..e2ebc8942e1 100644 --- a/drivers/pinmux/Makefile +++ b/drivers/pinmux/Makefile @@ -1,9 +1,12 @@ ccflags-y +=-I$(srctree)/drivers # Board initialization -obj-$(CONFIG_PINMUX_K64) += k64/pinmux.o +ifdef CONFIG_PINMUX_K64 +obj-y += k64/pinmux.o obj-$(CONFIG_BOARD_FRDM_K64F) += k64/pinmux_board_frdm_k64f.o obj-$(CONFIG_BOARD_HEXIWEAR_K64) += k64/pinmux_board_hexiwear.o +endif +obj-$(CONFIG_PINMUX_KSDK) += pinmux_ksdk.o obj-$(CONFIG_PINMUX_STM32) += stm32/pinmux_stm32.o obj-$(CONFIG_PINMUX_BEETLE) += beetle/pinmux_board_v2m_beetle.o obj-$(CONFIG_BOARD_NUCLEO_F103RB) += stm32/pinmux_board_nucleo_f103rb.o diff --git a/drivers/pinmux/dev/Kconfig b/drivers/pinmux/dev/Kconfig index 49dd0b10dfd..fecf70a28f9 100644 --- a/drivers/pinmux/dev/Kconfig +++ b/drivers/pinmux/dev/Kconfig @@ -75,3 +75,5 @@ config PINMUX_DEV_ARM_V2M_BEETLE Enables the pinmux dev driver for boards based on the ARM Beetle SoC MCUs. default n + +source "drivers/pinmux/dev/Kconfig.ksdk" diff --git a/drivers/pinmux/dev/Kconfig.ksdk b/drivers/pinmux/dev/Kconfig.ksdk new file mode 100644 index 00000000000..c6beade805e --- /dev/null +++ b/drivers/pinmux/dev/Kconfig.ksdk @@ -0,0 +1,52 @@ +# Kconfig - Kinetis SDK pinmux dev +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +menuconfig PINMUX_DEV_KSDK + bool "KSDK pinmux dev driver" + depends on PINMUX_DEV && PINMUX_KSDK + default n + help + Enable the KSDK pinmux dev driver. + +if PINMUX_DEV_KSDK + +config PINMUX_DEV_KSDK_PORTA_NAME + string "Pinmux Dev Port A driver name" + depends on PINMUX_KSDK_PORTA + default "pinmux_dev_porta" + +config PINMUX_DEV_KSDK_PORTB_NAME + string "Pinmux Dev Port B driver name" + depends on PINMUX_KSDK_PORTB + default "pinmux_dev_portb" + +config PINMUX_DEV_KSDK_PORTC_NAME + string "Pinmux Dev Port C driver name" + depends on PINMUX_KSDK_PORTC + default "pinmux_dev_portc" + +config PINMUX_DEV_KSDK_PORTD_NAME + string "Pinmux Dev Port D driver name" + depends on PINMUX_KSDK_PORTD + default "pinmux_dev_portd" + +config PINMUX_DEV_KSDK_PORTE_NAME + string "Pinmux Dev Port E driver name" + depends on PINMUX_KSDK_PORTE + default "pinmux_dev_porte" + +endif # PINMUX_DEV_KSDK diff --git a/drivers/pinmux/dev/Makefile b/drivers/pinmux/dev/Makefile index a90933cdc25..6c7ae77643f 100644 --- a/drivers/pinmux/dev/Makefile +++ b/drivers/pinmux/dev/Makefile @@ -4,6 +4,7 @@ ccflags-$(CONFIG_PINMUX_DEV_QMSI) += -I$(CONFIG_QMSI_INSTALL_PATH)/include obj-$(CONFIG_PINMUX_DEV_ATMEL_SAM3X) += pinmux_dev_atmel_sam3x.o obj-$(CONFIG_PINMUX_DEV_K64) += pinmux_dev_k64.o +obj-$(CONFIG_PINMUX_DEV_KSDK) += pinmux_dev_ksdk.o obj-$(CONFIG_PINMUX_DEV_QMSI) += pinmux_dev_qmsi.o obj-$(CONFIG_PINMUX_DEV_STM32) += pinmux_dev_stm32.o obj-$(CONFIG_PINMUX_DEV_ARM_V2M_BEETLE) += pinmux_dev_arm_beetle.o diff --git a/drivers/pinmux/dev/pinmux_dev_ksdk.c b/drivers/pinmux/dev/pinmux_dev_ksdk.c new file mode 100644 index 00000000000..8cc46db4d08 --- /dev/null +++ b/drivers/pinmux/dev/pinmux_dev_ksdk.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2016 Freescale Semiconductor, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +struct pinmux_dev_ksdk_config { + PORT_Type *base; +}; + +static int pinmux_dev_ksdk_set(struct device *dev, uint32_t pin, uint32_t func) +{ + const struct pinmux_dev_ksdk_config *config = dev->config->config_info; + + return pinmux_ksdk_set(config->base, pin, func); +} + +static int pinmux_dev_ksdk_get(struct device *dev, uint32_t pin, uint32_t *func) +{ + const struct pinmux_dev_ksdk_config *config = dev->config->config_info; + + return pinmux_ksdk_get(config->base, pin, func); +} + +static int pinmux_dev_ksdk_pullup(struct device *dev, uint32_t pin, + uint8_t func) +{ + return -ENOTSUP; +} + +static int pinmux_dev_ksdk_input(struct device *dev, uint32_t pin, + uint8_t func) +{ + return -ENOTSUP; +} + +static const struct pinmux_driver_api pinmux_dev_ksdk_driver_api = { + .set = pinmux_dev_ksdk_set, + .get = pinmux_dev_ksdk_get, + .pullup = pinmux_dev_ksdk_pullup, + .input = pinmux_dev_ksdk_input, +}; + +static int pinmux_dev_ksdk_init(struct device *dev) +{ + return 0; +} + +#ifdef CONFIG_PINMUX_KSDK_PORTA +static const struct pinmux_dev_ksdk_config pinmux_dev_ksdk_porta_config = { + .base = PORTA, +}; + +DEVICE_AND_API_INIT(pinmux_dev_porta, CONFIG_PINMUX_DEV_KSDK_PORTA_NAME, + &pinmux_dev_ksdk_init, + NULL, &pinmux_dev_ksdk_porta_config, + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &pinmux_dev_ksdk_driver_api); +#endif + +#ifdef CONFIG_PINMUX_KSDK_PORTB +static const struct pinmux_dev_ksdk_config pinmux_dev_ksdk_portb_config = { + .base = PORTB, +}; + +DEVICE_AND_API_INIT(pinmux_dev_portb, CONFIG_PINMUX_DEV_KSDK_PORTB_NAME, + &pinmux_dev_ksdk_init, + NULL, &pinmux_dev_ksdk_portb_config, + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &pinmux_dev_ksdk_driver_api); +#endif + +#ifdef CONFIG_PINMUX_KSDK_PORTC +static const struct pinmux_dev_ksdk_config pinmux_dev_ksdk_portc_config = { + .base = PORTC, +}; + +DEVICE_AND_API_INIT(pinmux_dev_portc, CONFIG_PINMUX_DEV_KSDK_PORTC_NAME, + &pinmux_dev_ksdk_init, + NULL, &pinmux_dev_ksdk_portc_config, + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &pinmux_dev_ksdk_driver_api); +#endif + +#ifdef CONFIG_PINMUX_KSDK_PORTD +static const struct pinmux_dev_ksdk_config pinmux_dev_ksdk_portd_config = { + .base = PORTD, +}; + +DEVICE_AND_API_INIT(pinmux_dev_portd, CONFIG_PINMUX_DEV_KSDK_PORTD_NAME, + &pinmux_dev_ksdk_init, + NULL, &pinmux_dev_ksdk_portd_config, + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &pinmux_dev_ksdk_driver_api); +#endif + +#ifdef CONFIG_PINMUX_KSDK_PORTE +static const struct pinmux_dev_ksdk_config pinmux_dev_ksdk_porte_config = { + .base = PORTE, +}; + +DEVICE_AND_API_INIT(pinmux_dev_porte, CONFIG_PINMUX_DEV_KSDK_PORTE_NAME, + &pinmux_dev_ksdk_init, + NULL, &pinmux_dev_ksdk_porte_config, + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &pinmux_dev_ksdk_driver_api); +#endif diff --git a/drivers/pinmux/pinmux_ksdk.c b/drivers/pinmux/pinmux_ksdk.c new file mode 100644 index 00000000000..51dc2439535 --- /dev/null +++ b/drivers/pinmux/pinmux_ksdk.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Freescale Semiconductor, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +int pinmux_ksdk_init(void) +{ +#ifdef CONFIG_PINMUX_KSDK_PORTA + CLOCK_EnableClock(kCLOCK_PortA); +#endif +#ifdef CONFIG_PINMUX_KSDK_PORTB + CLOCK_EnableClock(kCLOCK_PortB); +#endif +#ifdef CONFIG_PINMUX_KSDK_PORTC + CLOCK_EnableClock(kCLOCK_PortC); +#endif +#ifdef CONFIG_PINMUX_KSDK_PORTD + CLOCK_EnableClock(kCLOCK_PortD); +#endif +#ifdef CONFIG_PINMUX_KSDK_PORTE + CLOCK_EnableClock(kCLOCK_PortE); +#endif + return 0; +} diff --git a/drivers/pinmux/pinmux_ksdk.h b/drivers/pinmux/pinmux_ksdk.h new file mode 100644 index 00000000000..2b3f6c81263 --- /dev/null +++ b/drivers/pinmux/pinmux_ksdk.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 Freescale Semiconductor, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __INCLUDE_PINMUX_KSDK_H +#define __INCLUDE_PINMUX_KSDK_H + +#include +#include + +int pinmux_ksdk_init(void); + +static inline int pinmux_ksdk_set(PORT_Type *base, uint32_t pin, uint32_t func) +{ + base->PCR[pin] = func; + return 0; +} + +static inline int pinmux_ksdk_get(PORT_Type *base, uint32_t pin, uint32_t *func) +{ + *func = base->PCR[pin]; + return 0; +} + +#endif /* __INCLUDE_PINMUX_KSDK_H */