pinmux: Move the Arduino Due board to the pinmux model

Change-Id: I53fb54c0d11bcdbc42191dd4a26787d9beebbf58
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
This commit is contained in:
Vinicius Costa Gomes 2016-03-15 15:24:45 -03:00 committed by Gerrit Code Review
commit f25c5ca061
3 changed files with 10 additions and 144 deletions

View file

@ -3,4 +3,3 @@ ccflags-y += -I$(srctree)/drivers
asflags-y := ${ccflags-y} asflags-y := ${ccflags-y}
obj-y += board.o obj-y += board.o
obj-$(CONFIG_PINMUX) += pinmux_due.o

View file

@ -3,3 +3,4 @@ ccflags-y +=-I$(srctree)/drivers
obj-$(CONFIG_PINMUX_K64) += pinmux_k64.o obj-$(CONFIG_PINMUX_K64) += pinmux_k64.o
obj-$(CONFIG_PINMUX_STM32) += pinmux_stm32.o obj-$(CONFIG_PINMUX_STM32) += pinmux_stm32.o
obj-$(CONFIG_BOARD_ARDUINO_101) += quark_mcu/pinmux_board_arduino_101.o obj-$(CONFIG_BOARD_ARDUINO_101) += quark_mcu/pinmux_board_arduino_101.o
obj-$(CONFIG_BOARD_ARDUINO_DUE) += sam3x/pinmux_board_arduino_due.o

View file

@ -1,3 +1,5 @@
/* pinmux_board_arduino_due.c - Arduino Due pinmux driver */
/* /*
* Copyright (c) 2016 Intel Corporation * Copyright (c) 2016 Intel Corporation
* *
@ -13,14 +15,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <nanokernel.h>
#include <board.h>
#include <device.h> #include <device.h>
#include <init.h> #include <init.h>
#include <nanokernel.h>
#include <pinmux.h> #include <pinmux.h>
#include <soc.h>
#include <sys_io.h>
#include <misc/util.h> #include "pinmux/pinmux.h"
/** /**
* @brief Pinmux driver for Arduino due * @brief Pinmux driver for Arduino due
@ -122,135 +125,6 @@
* IO_51 : PC12 * IO_51 : PC12
*/ */
#ifndef CONFIG_PINMUX_DEV
#define PRINT(...) {; }
#else
#if defined(CONFIG_PRINTK)
#include <misc/printk.h>
#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_PIOA 0
#define N_PIOB 1 #define N_PIOB 1
#define N_PIOC 2 #define N_PIOC 2
@ -418,21 +292,13 @@ static void __pinmux_defaults(void)
__PIOD->pudr = ~(pull_up[N_PIOD]); __PIOD->pudr = ~(pull_up[N_PIOD]);
} }
static struct pinmux_driver_api api_funcs = { static int pinmux_init(struct device *port)
.set = pinmux_set,
.get = pinmux_get,
.pullup = pinmux_pullup,
.input = pinmux_input
};
int pinmux_init(struct device *port)
{ {
port->driver_api = &api_funcs; ARG_UNUSED(port);
__pinmux_defaults(); __pinmux_defaults();
return 0; return 0;
} }
DEVICE_INIT(pmux, PINMUX_NAME, &pinmux_init, NULL, NULL, SYS_INIT(pinmux_init, PRIMARY, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
PRIMARY, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);