Markus Brunner | dfc5ed2 | 2007-08-20 08:58:12 +0900 | [diff] [blame] | 1 | /* |
| 2 | * include/asm-sh/gpio.h |
| 3 | * |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 4 | * Generic GPIO API and pinmux table support for SuperH. |
Markus Brunner | dfc5ed2 | 2007-08-20 08:58:12 +0900 | [diff] [blame] | 5 | * |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 6 | * Copyright (c) 2008 Magnus Damm |
Markus Brunner | dfc5ed2 | 2007-08-20 08:58:12 +0900 | [diff] [blame] | 7 | * |
| 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 Mundt | f15cbe6 | 2008-07-29 08:09:44 +0900 | [diff] [blame] | 16 | #include <cpu/gpio.h> |
Markus Brunner | dfc5ed2 | 2007-08-20 08:58:12 +0900 | [diff] [blame] | 17 | #endif |
| 18 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 19 | typedef unsigned short pinmux_enum_t; |
| 20 | typedef 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 | |
| 34 | struct 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 | |
| 42 | struct 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 | |
| 53 | struct 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 | |
| 62 | struct pinmux_range { |
| 63 | pinmux_enum_t begin; |
| 64 | pinmux_enum_t end; |
| 65 | }; |
| 66 | |
| 67 | struct 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 | |
| 90 | int register_pinmux(struct pinmux_info *pip); |
| 91 | |
| 92 | int __gpio_request(unsigned gpio); |
| 93 | static inline int gpio_request(unsigned gpio, const char *label) |
| 94 | { |
| 95 | return __gpio_request(gpio); |
| 96 | } |
| 97 | void gpio_free(unsigned gpio); |
| 98 | int gpio_direction_input(unsigned gpio); |
| 99 | int gpio_direction_output(unsigned gpio, int value); |
| 100 | int gpio_get_value(unsigned gpio); |
| 101 | void gpio_set_value(unsigned gpio, int value); |
Paul Mundt | 10bfc6e | 2008-10-21 14:27:05 +0900 | [diff] [blame^] | 102 | |
| 103 | #include <asm-generic/gpio.h> |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 104 | |
Markus Brunner | dfc5ed2 | 2007-08-20 08:58:12 +0900 | [diff] [blame] | 105 | #endif /* __ASM_SH_GPIO_H */ |