uboot/arch/avr32/include/asm/arch-common/portmux-pio.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2006, 2008 Atmel Corporation
   3 *
   4 * SPDX-License-Identifier:     GPL-2.0+
   5 */
   6#ifndef __AVR32_PORTMUX_PIO_H__
   7#define __AVR32_PORTMUX_PIO_H__
   8
   9#include <asm/io.h>
  10
  11/* PIO register offsets */
  12#define PIO_PER                 0x0000
  13#define PIO_PDR                 0x0004
  14#define PIO_PSR                 0x0008
  15#define PIO_OER                 0x0010
  16#define PIO_ODR                 0x0014
  17#define PIO_OSR                 0x0018
  18#define PIO_IFER                0x0020
  19#define PIO_IFDR                0x0024
  20#define PIO_ISFR                0x0028
  21#define PIO_SODR                0x0030
  22#define PIO_CODR                0x0034
  23#define PIO_ODSR                0x0038
  24#define PIO_PDSR                0x003c
  25#define PIO_IER                 0x0040
  26#define PIO_IDR                 0x0044
  27#define PIO_IMR                 0x0048
  28#define PIO_ISR                 0x004c
  29#define PIO_MDER                0x0050
  30#define PIO_MDDR                0x0054
  31#define PIO_MDSR                0x0058
  32#define PIO_PUDR                0x0060
  33#define PIO_PUER                0x0064
  34#define PIO_PUSR                0x0068
  35#define PIO_ASR                 0x0070
  36#define PIO_BSR                 0x0074
  37#define PIO_ABSR                0x0078
  38#define PIO_OWER                0x00a0
  39#define PIO_OWDR                0x00a4
  40#define PIO_OWSR                0x00a8
  41
  42/* Hardware register access */
  43#define pio_readl(base, reg)                            \
  44        __raw_readl((void *)base + PIO_##reg)
  45#define pio_writel(base, reg, value)                    \
  46        __raw_writel((value), (void *)base + PIO_##reg)
  47
  48/* Portmux API starts here. See doc/README.AVR32-port-muxing */
  49
  50enum portmux_function {
  51        PORTMUX_FUNC_A,
  52        PORTMUX_FUNC_B,
  53};
  54
  55/* Pull-down, buskeeper and drive strength are not supported */
  56#define PORTMUX_DIR_INPUT       (0 << 0)
  57#define PORTMUX_DIR_OUTPUT      (1 << 0)
  58#define PORTMUX_INIT_LOW        (0 << 1)
  59#define PORTMUX_INIT_HIGH       (1 << 1)
  60#define PORTMUX_PULL_UP         (1 << 2)
  61#define PORTMUX_PULL_DOWN       (0)
  62#define PORTMUX_BUSKEEPER       PORTMUX_PULL_UP
  63#define PORTMUX_DRIVE_MIN       (0)
  64#define PORTMUX_DRIVE_LOW       (0)
  65#define PORTMUX_DRIVE_HIGH      (0)
  66#define PORTMUX_DRIVE_MAX       (0)
  67#define PORTMUX_OPEN_DRAIN      (1 << 3)
  68
  69void portmux_select_peripheral(void *port, unsigned long pin_mask,
  70                enum portmux_function func, unsigned long flags);
  71void portmux_select_gpio(void *port, unsigned long pin_mask,
  72                unsigned long flags);
  73
  74/* Internal helper functions */
  75
  76static inline void __pio_set_output_value(void *port, unsigned int pin,
  77                int value)
  78{
  79        /*
  80         * value will usually be constant, but it's pretty cheap
  81         * either way.
  82         */
  83        if (value)
  84                pio_writel(port, SODR, 1 << pin);
  85        else
  86                pio_writel(port, CODR, 1 << pin);
  87}
  88
  89static inline int __pio_get_input_value(void *port, unsigned int pin)
  90{
  91        return (pio_readl(port, PDSR) >> pin) & 1;
  92}
  93
  94void pio_set_output_value(unsigned int pin, int value);
  95int pio_get_input_value(unsigned int pin);
  96
  97/* GPIO API starts here */
  98
  99/*
 100 * GCC doesn't realize that the constant case is extremely trivial,
 101 * so we need to help it make the right decision by using
 102 * always_inline.
 103 */
 104__attribute__((always_inline))
 105static inline void gpio_set_value(unsigned int pin, int value)
 106{
 107        if (__builtin_constant_p(pin))
 108                __pio_set_output_value(pio_pin_to_port(pin), pin & 0x1f, value);
 109        else
 110                pio_set_output_value(pin, value);
 111}
 112
 113__attribute__((always_inline))
 114static inline int gpio_get_value(unsigned int pin)
 115{
 116        if (__builtin_constant_p(pin))
 117                return __pio_get_input_value(pio_pin_to_port(pin), pin & 0x1f);
 118        else
 119                return pio_get_input_value(pin);
 120}
 121
 122#endif /* __AVR32_PORTMUX_PIO_H__ */
 123