Source
static int atmel_pio4_direction_input(struct udevice *dev, unsigned offset)
// SPDX-License-Identifier: GPL-2.0+
/*
* Atmel PIO4 device driver
*
* Copyright (C) 2015 Atmel Corporation
* Wenyou.Yang <wenyou.yang@atmel.com>
*/
DECLARE_GLOBAL_DATA_PTR;
static struct atmel_pio4_port *atmel_pio4_port_base(u32 port)
{
struct atmel_pio4_port *base = NULL;
switch (port) {
case AT91_PIO_PORTA:
base = (struct atmel_pio4_port *)ATMEL_BASE_PIOA;
break;
case AT91_PIO_PORTB:
base = (struct atmel_pio4_port *)ATMEL_BASE_PIOB;
break;
case AT91_PIO_PORTC:
base = (struct atmel_pio4_port *)ATMEL_BASE_PIOC;
break;
case AT91_PIO_PORTD:
base = (struct atmel_pio4_port *)ATMEL_BASE_PIOD;
break;
default:
printf("Error: Atmel PIO4: Failed to get PIO base of port#%d!\n",
port);
break;
}
return base;
}
static int atmel_pio4_config_io_func(u32 port, u32 pin,
u32 func, u32 config)
{
struct atmel_pio4_port *port_base;
u32 reg, mask;
if (pin >= ATMEL_PIO_NPINS_PER_BANK)
return -EINVAL;
port_base = atmel_pio4_port_base(port);
if (!port_base)
return -EINVAL;
mask = 1 << pin;
reg = func;
reg |= config;
writel(mask, &port_base->mskr);
writel(reg, &port_base->cfgr);