Path: blob/master/arch/arm/mach-davinci/include/mach/gpio.h
17612 views
/*1* TI DaVinci GPIO Support2*3* Copyright (c) 2006 David Brownell4* Copyright (c) 2007, MontaVista Software, Inc. <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*/1112#ifndef __DAVINCI_GPIO_H13#define __DAVINCI_GPIO_H1415#include <linux/io.h>16#include <linux/spinlock.h>1718#include <asm-generic/gpio.h>1920#include <mach/irqs.h>21#include <mach/common.h>2223#define DAVINCI_GPIO_BASE 0x01C670002425enum davinci_gpio_type {26GPIO_TYPE_DAVINCI = 0,27GPIO_TYPE_TNETV107X,28};2930/*31* basic gpio routines32*33* board-specific init should be done by arch/.../.../board-XXX.c (maybe34* initializing banks together) rather than boot loaders; kexec() won't35* go through boot loaders.36*37* the gpio clock will be turned on when gpios are used, and you may also38* need to pay attention to PINMUX registers to be sure those pins are39* used as gpios, not with other peripherals.40*41* On-chip GPIOs are numbered 0..(DAVINCI_N_GPIO-1). For documentation,42* and maybe for later updates, code may write GPIO(N). These may be43* all 1.8V signals, all 3.3V ones, or a mix of the two. A given chip44* may not support all the GPIOs in that range.45*46* GPIOs can also be on external chips, numbered after the ones built-in47* to the DaVinci chip. For now, they won't be usable as IRQ sources.48*/49#define GPIO(X) (X) /* 0 <= X <= (DAVINCI_N_GPIO - 1) */5051/* Convert GPIO signal to GPIO pin number */52#define GPIO_TO_PIN(bank, gpio) (16 * (bank) + (gpio))5354struct davinci_gpio_controller {55struct gpio_chip chip;56int irq_base;57spinlock_t lock;58void __iomem *regs;59void __iomem *set_data;60void __iomem *clr_data;61void __iomem *in_data;62};6364/* The __gpio_to_controller() and __gpio_mask() functions inline to constants65* with constant parameters; or in outlined code they execute at runtime.66*67* You'd access the controller directly when reading or writing more than68* one gpio value at a time, and to support wired logic where the value69* being driven by the cpu need not match the value read back.70*71* These are NOT part of the cross-platform GPIO interface72*/73static inline struct davinci_gpio_controller *74__gpio_to_controller(unsigned gpio)75{76struct davinci_gpio_controller *ctlrs = davinci_soc_info.gpio_ctlrs;77int index = gpio / 32;7879if (!ctlrs || index >= davinci_soc_info.gpio_ctlrs_num)80return NULL;8182return ctlrs + index;83}8485static inline u32 __gpio_mask(unsigned gpio)86{87return 1 << (gpio % 32);88}8990/*91* The get/set/clear functions will inline when called with constant92* parameters referencing built-in GPIOs, for low-overhead bitbanging.93*94* gpio_set_value() will inline only on traditional Davinci style controllers95* with distinct set/clear registers.96*97* Otherwise, calls with variable parameters or referencing external98* GPIOs (e.g. on GPIO expander chips) use outlined functions.99*/100static inline void gpio_set_value(unsigned gpio, int value)101{102if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {103struct davinci_gpio_controller *ctlr;104u32 mask;105106ctlr = __gpio_to_controller(gpio);107108if (ctlr->set_data != ctlr->clr_data) {109mask = __gpio_mask(gpio);110if (value)111__raw_writel(mask, ctlr->set_data);112else113__raw_writel(mask, ctlr->clr_data);114return;115}116}117118__gpio_set_value(gpio, value);119}120121/* Returns zero or nonzero; works for gpios configured as inputs OR122* as outputs, at least for built-in GPIOs.123*124* NOTE: for built-in GPIOs, changes in reported values are synchronized125* to the GPIO clock. This is easily seen after calling gpio_set_value()126* and then immediately gpio_get_value(), where the gpio_get_value() will127* return the old value until the GPIO clock ticks and the new value gets128* latched.129*/130static inline int gpio_get_value(unsigned gpio)131{132struct davinci_gpio_controller *ctlr;133134if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)135return __gpio_get_value(gpio);136137ctlr = __gpio_to_controller(gpio);138return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);139}140141static inline int gpio_cansleep(unsigned gpio)142{143if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)144return 0;145else146return __gpio_cansleep(gpio);147}148149static inline int gpio_to_irq(unsigned gpio)150{151return __gpio_to_irq(gpio);152}153154static inline int irq_to_gpio(unsigned irq)155{156/* don't support the reverse mapping */157return -ENOSYS;158}159160#endif /* __DAVINCI_GPIO_H */161162163