• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/arch/arm/mach-davinci/include/mach/
1/*
2 * TI DaVinci GPIO Support
3 *
4 * Copyright (c) 2006 David Brownell
5 * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef	__DAVINCI_GPIO_H
14#define	__DAVINCI_GPIO_H
15
16#include <linux/io.h>
17#include <linux/spinlock.h>
18
19#include <asm-generic/gpio.h>
20
21#include <mach/irqs.h>
22#include <mach/common.h>
23
24#define DAVINCI_GPIO_BASE 0x01C67000
25
26enum davinci_gpio_type {
27	GPIO_TYPE_DAVINCI = 0,
28	GPIO_TYPE_TNETV107X,
29};
30
31#define	GPIO(X)		(X)		/* 0 <= X <= (DAVINCI_N_GPIO - 1) */
32
33/* Convert GPIO signal to GPIO pin number */
34#define GPIO_TO_PIN(bank, gpio)	(16 * (bank) + (gpio))
35
36struct davinci_gpio_controller {
37	struct gpio_chip	chip;
38	int			irq_base;
39	spinlock_t		lock;
40	void __iomem		*regs;
41	void __iomem		*set_data;
42	void __iomem		*clr_data;
43	void __iomem		*in_data;
44};
45
46/* The __gpio_to_controller() and __gpio_mask() functions inline to constants
47 * with constant parameters; or in outlined code they execute at runtime.
48 *
49 * You'd access the controller directly when reading or writing more than
50 * one gpio value at a time, and to support wired logic where the value
51 * being driven by the cpu need not match the value read back.
52 *
53 * These are NOT part of the cross-platform GPIO interface
54 */
55static inline struct davinci_gpio_controller *
56__gpio_to_controller(unsigned gpio)
57{
58	struct davinci_gpio_controller *ctlrs = davinci_soc_info.gpio_ctlrs;
59	int index = gpio / 32;
60
61	if (!ctlrs || index >= davinci_soc_info.gpio_ctlrs_num)
62		return NULL;
63
64	return ctlrs + index;
65}
66
67static inline u32 __gpio_mask(unsigned gpio)
68{
69	return 1 << (gpio % 32);
70}
71
72/*
73 * The get/set/clear functions will inline when called with constant
74 * parameters referencing built-in GPIOs, for low-overhead bitbanging.
75 *
76 * gpio_set_value() will inline only on traditional Davinci style controllers
77 * with distinct set/clear registers.
78 *
79 * Otherwise, calls with variable parameters or referencing external
80 * GPIOs (e.g. on GPIO expander chips) use outlined functions.
81 */
82static inline void gpio_set_value(unsigned gpio, int value)
83{
84	if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {
85		struct davinci_gpio_controller *ctlr;
86		u32				mask;
87
88		ctlr = __gpio_to_controller(gpio);
89
90		if (ctlr->set_data != ctlr->clr_data) {
91			mask = __gpio_mask(gpio);
92			if (value)
93				__raw_writel(mask, ctlr->set_data);
94			else
95				__raw_writel(mask, ctlr->clr_data);
96			return;
97		}
98	}
99
100	__gpio_set_value(gpio, value);
101}
102
103/* Returns zero or nonzero; works for gpios configured as inputs OR
104 * as outputs, at least for built-in GPIOs.
105 *
106 * NOTE: for built-in GPIOs, changes in reported values are synchronized
107 * to the GPIO clock.  This is easily seen after calling gpio_set_value()
108 * and then immediately gpio_get_value(), where the gpio_get_value() will
109 * return the old value until the GPIO clock ticks and the new value gets
110 * latched.
111 */
112static inline int gpio_get_value(unsigned gpio)
113{
114	struct davinci_gpio_controller *ctlr;
115
116	if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
117		return __gpio_get_value(gpio);
118
119	ctlr = __gpio_to_controller(gpio);
120	return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
121}
122
123static inline int gpio_cansleep(unsigned gpio)
124{
125	if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)
126		return 0;
127	else
128		return __gpio_cansleep(gpio);
129}
130
131static inline int gpio_to_irq(unsigned gpio)
132{
133	return __gpio_to_irq(gpio);
134}
135
136static inline int irq_to_gpio(unsigned irq)
137{
138	/* don't support the reverse mapping */
139	return -ENOSYS;
140}
141
142#endif				/* __DAVINCI_GPIO_H */
143