blob: 9650e7c9c39e989c5763cca1182a4c5c69f8ae9a [file] [log] [blame]
Markus Brunnerdfc5ed22007-08-20 08:58:12 +09001/*
2 * include/asm-sh/gpio.h
3 *
Magnus Damm2967dab2008-10-08 20:41:43 +09004 * Generic GPIO API and pinmux table support for SuperH.
Markus Brunnerdfc5ed22007-08-20 08:58:12 +09005 *
Magnus Damm2967dab2008-10-08 20:41:43 +09006 * Copyright (c) 2008 Magnus Damm
Markus Brunnerdfc5ed22007-08-20 08:58:12 +09007 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#ifndef __ASM_SH_GPIO_H
13#define __ASM_SH_GPIO_H
14
15#if defined(CONFIG_CPU_SH3)
Paul Mundtf15cbe62008-07-29 08:09:44 +090016#include <cpu/gpio.h>
Markus Brunnerdfc5ed22007-08-20 08:58:12 +090017#endif
18
Magnus Damm2967dab2008-10-08 20:41:43 +090019typedef unsigned short pinmux_enum_t;
20typedef unsigned char pinmux_flag_t;
21
22#define PINMUX_TYPE_NONE 0
23#define PINMUX_TYPE_FUNCTION 1
24#define PINMUX_TYPE_GPIO 2
25#define PINMUX_TYPE_OUTPUT 3
26#define PINMUX_TYPE_INPUT 4
27#define PINMUX_TYPE_INPUT_PULLUP 5
28#define PINMUX_TYPE_INPUT_PULLDOWN 6
29
30#define PINMUX_FLAG_TYPE (0x7)
31#define PINMUX_FLAG_WANT_PULLUP (1 << 3)
32#define PINMUX_FLAG_WANT_PULLDOWN (1 << 4)
33
34struct pinmux_gpio {
35 pinmux_enum_t enum_id;
36 pinmux_flag_t flags;
37};
38
39#define PINMUX_GPIO(gpio, data_or_mark) [gpio] = { data_or_mark }
40#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
41
42struct pinmux_cfg_reg {
43 unsigned long reg, reg_width, field_width;
44 unsigned long *cnt;
45 pinmux_enum_t *enum_ids;
46};
47
48#define PINMUX_CFG_REG(name, r, r_width, f_width) \
49 .reg = r, .reg_width = r_width, .field_width = f_width, \
50 .cnt = (unsigned long [r_width / f_width]) {}, \
51 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) \
52
53struct pinmux_data_reg {
54 unsigned long reg, reg_width;
55 pinmux_enum_t *enum_ids;
56};
57
58#define PINMUX_DATA_REG(name, r, r_width) \
59 .reg = r, .reg_width = r_width, \
60 .enum_ids = (pinmux_enum_t [r_width]) \
61
62struct pinmux_range {
63 pinmux_enum_t begin;
64 pinmux_enum_t end;
65};
66
67struct pinmux_info {
68 char *name;
69 pinmux_enum_t reserved_id;
70 struct pinmux_range data;
71 struct pinmux_range input;
72 struct pinmux_range input_pd;
73 struct pinmux_range input_pu;
74 struct pinmux_range output;
75 struct pinmux_range mark;
76 struct pinmux_range function;
77
78 unsigned first_gpio, last_gpio;
79
80 struct pinmux_gpio *gpios;
81 struct pinmux_cfg_reg *cfg_regs;
82 struct pinmux_data_reg *data_regs;
83
84 pinmux_enum_t *gpio_data;
85 unsigned int gpio_data_size;
86
87 unsigned long *gpio_in_use;
88};
89
90int register_pinmux(struct pinmux_info *pip);
91
92int __gpio_request(unsigned gpio);
93static inline int gpio_request(unsigned gpio, const char *label)
94{
95 return __gpio_request(gpio);
96}
97void gpio_free(unsigned gpio);
98int gpio_direction_input(unsigned gpio);
99int gpio_direction_output(unsigned gpio, int value);
100int gpio_get_value(unsigned gpio);
101void gpio_set_value(unsigned gpio, int value);
102static inline int gpio_export(unsigned gpio, bool direction_may_change)
103{
104 return 0;
105}
106
Markus Brunnerdfc5ed22007-08-20 08:58:12 +0900107#endif /* __ASM_SH_GPIO_H */