Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Nokia |
| 3 | * Copyright (C) 2009 Texas Instruments |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
Tony Lindgren | ddaa912 | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 10 | #include "mux34xx.h" |
| 11 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 12 | #define OMAP_MUX_TERMINATOR 0xffff |
| 13 | |
| 14 | /* 34xx mux mode options for each pin. See TRM for options */ |
| 15 | #define OMAP_MUX_MODE0 0 |
| 16 | #define OMAP_MUX_MODE1 1 |
| 17 | #define OMAP_MUX_MODE2 2 |
| 18 | #define OMAP_MUX_MODE3 3 |
| 19 | #define OMAP_MUX_MODE4 4 |
| 20 | #define OMAP_MUX_MODE5 5 |
| 21 | #define OMAP_MUX_MODE6 6 |
| 22 | #define OMAP_MUX_MODE7 7 |
| 23 | |
| 24 | /* 24xx/34xx mux bit defines */ |
| 25 | #define OMAP_PULL_ENA (1 << 3) |
| 26 | #define OMAP_PULL_UP (1 << 4) |
| 27 | #define OMAP_ALTELECTRICALSEL (1 << 5) |
| 28 | |
| 29 | /* 34xx specific mux bit defines */ |
| 30 | #define OMAP_INPUT_EN (1 << 8) |
| 31 | #define OMAP_OFF_EN (1 << 9) |
| 32 | #define OMAP_OFFOUT_EN (1 << 10) |
| 33 | #define OMAP_OFFOUT_VAL (1 << 11) |
| 34 | #define OMAP_OFF_PULL_EN (1 << 12) |
| 35 | #define OMAP_OFF_PULL_UP (1 << 13) |
| 36 | #define OMAP_WAKEUP_EN (1 << 14) |
| 37 | |
| 38 | /* Active pin states */ |
| 39 | #define OMAP_PIN_OUTPUT 0 |
| 40 | #define OMAP_PIN_INPUT OMAP_INPUT_EN |
| 41 | #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \ |
| 42 | | OMAP_PULL_UP) |
| 43 | #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN) |
| 44 | |
| 45 | /* Off mode states */ |
| 46 | #define OMAP_PIN_OFF_NONE 0 |
| 47 | #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \ |
| 48 | | OMAP_OFFOUT_VAL) |
| 49 | #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN) |
| 50 | #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \ |
| 51 | | OMAP_OFF_PULL_UP) |
| 52 | #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN) |
| 53 | #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN |
| 54 | |
| 55 | #define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4) |
| 56 | |
| 57 | /* Flags for omap_mux_init */ |
| 58 | #define OMAP_PACKAGE_MASK 0xffff |
Tony Lindgren | 6dd8a68 | 2010-07-05 16:31:35 +0300 | [diff] [blame^] | 59 | #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */ |
| 60 | #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */ |
| 61 | #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */ |
| 62 | #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */ |
| 63 | #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */ |
| 64 | #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 65 | |
| 66 | |
| 67 | #define OMAP_MUX_NR_MODES 8 /* Available modes */ |
| 68 | #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */ |
| 69 | |
| 70 | /** |
| 71 | * struct omap_mux - data for omap mux register offset and it's value |
| 72 | * @reg_offset: mux register offset from the mux base |
| 73 | * @gpio: GPIO number |
| 74 | * @muxnames: available signal modes for a ball |
| 75 | */ |
| 76 | struct omap_mux { |
| 77 | u16 reg_offset; |
| 78 | u16 gpio; |
| 79 | #ifdef CONFIG_OMAP_MUX |
| 80 | char *muxnames[OMAP_MUX_NR_MODES]; |
| 81 | #ifdef CONFIG_DEBUG_FS |
| 82 | char *balls[OMAP_MUX_NR_SIDES]; |
| 83 | #endif |
| 84 | #endif |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * struct omap_ball - data for balls on omap package |
| 89 | * @reg_offset: mux register offset from the mux base |
| 90 | * @balls: available balls on the package |
| 91 | */ |
| 92 | struct omap_ball { |
| 93 | u16 reg_offset; |
| 94 | char *balls[OMAP_MUX_NR_SIDES]; |
| 95 | }; |
| 96 | |
| 97 | /** |
| 98 | * struct omap_board_mux - data for initializing mux registers |
| 99 | * @reg_offset: mux register offset from the mux base |
| 100 | * @mux_value: desired mux value to set |
| 101 | */ |
| 102 | struct omap_board_mux { |
| 103 | u16 reg_offset; |
| 104 | u16 value; |
| 105 | }; |
| 106 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 107 | #if defined(CONFIG_OMAP_MUX) && defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * omap_mux_init_gpio - initialize a signal based on the GPIO number |
| 111 | * @gpio: GPIO number |
| 112 | * @val: Options for the mux register value |
| 113 | */ |
| 114 | int omap_mux_init_gpio(int gpio, int val); |
| 115 | |
| 116 | /** |
| 117 | * omap_mux_init_signal - initialize a signal based on the signal name |
| 118 | * @muxname: Mux name in mode0_name.signal_name format |
| 119 | * @val: Options for the mux register value |
| 120 | */ |
| 121 | int omap_mux_init_signal(char *muxname, int val); |
| 122 | |
| 123 | #else |
| 124 | |
| 125 | static inline int omap_mux_init_gpio(int gpio, int val) |
| 126 | { |
| 127 | return 0; |
| 128 | } |
| 129 | static inline int omap_mux_init_signal(char *muxname, int val) |
| 130 | { |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | #endif |
| 135 | |
| 136 | /** |
| 137 | * omap_mux_get_gpio() - get mux register value based on GPIO number |
| 138 | * @gpio: GPIO number |
| 139 | * |
| 140 | */ |
| 141 | u16 omap_mux_get_gpio(int gpio); |
| 142 | |
| 143 | /** |
| 144 | * omap_mux_set_gpio() - set mux register value based on GPIO number |
| 145 | * @val: New mux register value |
| 146 | * @gpio: GPIO number |
| 147 | * |
| 148 | */ |
| 149 | void omap_mux_set_gpio(u16 val, int gpio); |
| 150 | |
| 151 | /** |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 152 | * omap_mux_read() - read mux register |
| 153 | * @mux_offset: Offset of the mux register |
| 154 | * |
| 155 | */ |
| 156 | u16 omap_mux_read(u16 mux_offset); |
| 157 | |
| 158 | /** |
| 159 | * omap_mux_write() - write mux register |
| 160 | * @val: New mux register value |
| 161 | * @mux_offset: Offset of the mux register |
| 162 | * |
| 163 | * This should be only needed for dynamic remuxing of non-gpio signals. |
| 164 | */ |
| 165 | void omap_mux_write(u16 val, u16 mux_offset); |
| 166 | |
| 167 | /** |
| 168 | * omap_mux_write_array() - write an array of mux registers |
| 169 | * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR |
| 170 | * |
| 171 | * This should be only needed for dynamic remuxing of non-gpio signals. |
| 172 | */ |
| 173 | void omap_mux_write_array(struct omap_board_mux *board_mux); |
| 174 | |
| 175 | /** |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 176 | * omap3_mux_init() - initialize mux system with board specific set |
| 177 | * @board_mux: Board specific mux table |
| 178 | * @flags: OMAP package type used for the board |
| 179 | */ |
| 180 | int omap3_mux_init(struct omap_board_mux *board_mux, int flags); |
| 181 | |
| 182 | /** |
| 183 | * omap_mux_init - private mux init function, do not call |
| 184 | */ |
| 185 | int omap_mux_init(u32 mux_pbase, u32 mux_size, |
| 186 | struct omap_mux *superset, |
| 187 | struct omap_mux *package_subset, |
| 188 | struct omap_board_mux *board_mux, |
| 189 | struct omap_ball *package_balls); |