diff --git a/boards/arduino_due/Makefile b/boards/arduino_due/Makefile index aa6fc65fff5..9c255466e43 100644 --- a/boards/arduino_due/Makefile +++ b/boards/arduino_due/Makefile @@ -3,4 +3,3 @@ ccflags-y += -I$(srctree)/drivers asflags-y := ${ccflags-y} obj-y += board.o -obj-$(CONFIG_PINMUX) += pinmux_due.o diff --git a/drivers/pinmux/Makefile b/drivers/pinmux/Makefile index c23c9e218bd..a6fbe661358 100644 --- a/drivers/pinmux/Makefile +++ b/drivers/pinmux/Makefile @@ -3,3 +3,4 @@ ccflags-y +=-I$(srctree)/drivers obj-$(CONFIG_PINMUX_K64) += pinmux_k64.o obj-$(CONFIG_PINMUX_STM32) += pinmux_stm32.o obj-$(CONFIG_BOARD_ARDUINO_101) += quark_mcu/pinmux_board_arduino_101.o +obj-$(CONFIG_BOARD_ARDUINO_DUE) += sam3x/pinmux_board_arduino_due.o diff --git a/boards/arduino_due/pinmux_due.c b/drivers/pinmux/sam3x/pinmux_board_arduino_due.c similarity index 73% rename from boards/arduino_due/pinmux_due.c rename to drivers/pinmux/sam3x/pinmux_board_arduino_due.c index 7eeb8b8092a..88b2116a85e 100644 --- a/boards/arduino_due/pinmux_due.c +++ b/drivers/pinmux/sam3x/pinmux_board_arduino_due.c @@ -1,3 +1,5 @@ +/* pinmux_board_arduino_due.c - Arduino Due pinmux driver */ + /* * Copyright (c) 2016 Intel Corporation * @@ -13,14 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include #include #include +#include #include +#include +#include -#include +#include "pinmux/pinmux.h" /** * @brief Pinmux driver for Arduino due @@ -122,135 +125,6 @@ * IO_51 : PC12 */ -#ifndef CONFIG_PINMUX_DEV -#define PRINT(...) {; } -#else -#if defined(CONFIG_PRINTK) -#include -#define PRINT printk -#elif defined(CONFIG_STDOUT_CONSOLE) -#define PRINT printf -#endif /* CONFIG_PRINTK */ -#endif /*CONFIG_PINMUX_DEV */ - -static volatile struct __pio *_get_port(uint32_t pin) -{ - uint32_t port_num = pin / 32; - - switch (port_num) { - case 0: - return __PIOA; - case 1: - return __PIOB; - case 2: - return __PIOC; - case 3: - return __PIOD; - default: - /* return null if pin is outside range */ - return NULL; - } -} - -#ifdef CONFIG_PINMUX_DEV -static int pinmux_set(struct device *dev, uint32_t pin, uint32_t func) -{ - volatile struct __pio *port = _get_port(pin); - uint32_t tmp; - - ARG_UNUSED(dev); - - if (!port) { - return -EINVAL; - } - - tmp = port->absr; - if (func) { - tmp |= (1 << (pin % 32)); - } else { - tmp &= ~(1 << (pin % 32)); - } - port->absr = tmp; - - return 0; -} - -static int pinmux_get(struct device *dev, uint32_t pin, uint32_t *func) -{ - volatile struct __pio *port = _get_port(pin); - - ARG_UNUSED(dev); - - if (!port) { - return -EINVAL; - } - - *func = (port->absr & (1 << (pin % 32))) ? 1 : 0; - - return 0; -} -#else -static int pinmux_set(struct device *dev, uint32_t pin, uint32_t func) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(func); - - PRINT("ERROR: %s is not enabled", __func__); - - return -EPERM; -} - -static int pinmux_get(struct device *dev, uint32_t pin, uint32_t *func) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(func); - - PRINT("ERROR: %s is not enabled", __func__); - - return -EPERM; -} -#endif /* CONFIG_PINMUX_DEV */ - -static int pinmux_pullup(struct device *dev, uint32_t pin, uint8_t func) -{ - volatile struct __pio *port = _get_port(pin); - - ARG_UNUSED(dev); - - if (!port) { - return -EINVAL; - } - - if (func) { - port->puer = (1 << (pin % 32)); - } else { - port->pudr = (1 << (pin % 32)); - } - - return 0; -} -static int pinmux_input(struct device *dev, uint32_t pin, uint8_t func) -{ - volatile struct __pio *port = _get_port(pin); - - ARG_UNUSED(dev); - - if (!port) { - return -EINVAL; - } - - if (func) { - port->odr = (1 << (pin % 32)); - } else { - port->oer = (1 << (pin % 32)); - } - - return 0; -} - - #define N_PIOA 0 #define N_PIOB 1 #define N_PIOC 2 @@ -418,21 +292,13 @@ static void __pinmux_defaults(void) __PIOD->pudr = ~(pull_up[N_PIOD]); } -static struct pinmux_driver_api api_funcs = { - .set = pinmux_set, - .get = pinmux_get, - .pullup = pinmux_pullup, - .input = pinmux_input -}; - -int pinmux_init(struct device *port) +static int pinmux_init(struct device *port) { - port->driver_api = &api_funcs; + ARG_UNUSED(port); __pinmux_defaults(); return 0; } -DEVICE_INIT(pmux, PINMUX_NAME, &pinmux_init, NULL, NULL, - PRIMARY, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(pinmux_init, PRIMARY, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);