Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Nokia |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 3 | * Copyright (C) 2009-2010 Texas Instruments |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 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 | fc44046 | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 10 | #include "mux2420.h" |
Tony Lindgren | 89ba109 | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 11 | #include "mux2430.h" |
Tony Lindgren | ddaa912 | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 12 | #include "mux34xx.h" |
| 13 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 14 | #define OMAP_MUX_TERMINATOR 0xffff |
| 15 | |
| 16 | /* 34xx mux mode options for each pin. See TRM for options */ |
| 17 | #define OMAP_MUX_MODE0 0 |
| 18 | #define OMAP_MUX_MODE1 1 |
| 19 | #define OMAP_MUX_MODE2 2 |
| 20 | #define OMAP_MUX_MODE3 3 |
| 21 | #define OMAP_MUX_MODE4 4 |
| 22 | #define OMAP_MUX_MODE5 5 |
| 23 | #define OMAP_MUX_MODE6 6 |
| 24 | #define OMAP_MUX_MODE7 7 |
| 25 | |
| 26 | /* 24xx/34xx mux bit defines */ |
| 27 | #define OMAP_PULL_ENA (1 << 3) |
| 28 | #define OMAP_PULL_UP (1 << 4) |
| 29 | #define OMAP_ALTELECTRICALSEL (1 << 5) |
| 30 | |
| 31 | /* 34xx specific mux bit defines */ |
| 32 | #define OMAP_INPUT_EN (1 << 8) |
| 33 | #define OMAP_OFF_EN (1 << 9) |
| 34 | #define OMAP_OFFOUT_EN (1 << 10) |
| 35 | #define OMAP_OFFOUT_VAL (1 << 11) |
| 36 | #define OMAP_OFF_PULL_EN (1 << 12) |
| 37 | #define OMAP_OFF_PULL_UP (1 << 13) |
| 38 | #define OMAP_WAKEUP_EN (1 << 14) |
| 39 | |
| 40 | /* Active pin states */ |
| 41 | #define OMAP_PIN_OUTPUT 0 |
| 42 | #define OMAP_PIN_INPUT OMAP_INPUT_EN |
| 43 | #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \ |
| 44 | | OMAP_PULL_UP) |
| 45 | #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN) |
| 46 | |
| 47 | /* Off mode states */ |
| 48 | #define OMAP_PIN_OFF_NONE 0 |
| 49 | #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \ |
| 50 | | OMAP_OFFOUT_VAL) |
| 51 | #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN) |
| 52 | #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \ |
| 53 | | OMAP_OFF_PULL_UP) |
| 54 | #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN) |
| 55 | #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN |
| 56 | |
| 57 | #define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4) |
| 58 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 59 | /* Flags for omapX_mux_init */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 60 | #define OMAP_PACKAGE_MASK 0xffff |
Tony Lindgren | 6dd8a68 | 2010-07-05 16:31:35 +0300 | [diff] [blame] | 61 | #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */ |
| 62 | #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */ |
| 63 | #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */ |
| 64 | #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */ |
| 65 | #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */ |
| 66 | #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 67 | |
| 68 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 69 | #define OMAP_MUX_NR_MODES 8 /* Available modes */ |
| 70 | #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */ |
| 71 | |
| 72 | /* |
| 73 | * omap_mux_init flags definition: |
| 74 | * |
| 75 | * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits. |
| 76 | * The default value is 16 bits. |
| 77 | * OMAP_MUX_GPIO_IN_MODE3: The GPIO is selected in mode3. |
| 78 | * The default is mode4. |
| 79 | */ |
| 80 | #define OMAP_MUX_REG_8BIT (1 << 0) |
| 81 | #define OMAP_MUX_GPIO_IN_MODE3 (1 << 1) |
| 82 | |
| 83 | /** |
| 84 | * struct mux_partition - contain partition related information |
| 85 | * @name: name of the current partition |
| 86 | * @flags: flags specific to this partition |
| 87 | * @phys: physical address |
| 88 | * @size: partition size |
| 89 | * @base: virtual address after ioremap |
| 90 | * @muxmodes: list of nodes that belong to a partition |
| 91 | * @node: list node for the partitions linked list |
| 92 | */ |
| 93 | struct omap_mux_partition { |
| 94 | const char *name; |
| 95 | u32 flags; |
| 96 | u32 phys; |
| 97 | u32 size; |
| 98 | void __iomem *base; |
| 99 | struct list_head muxmodes; |
| 100 | struct list_head node; |
| 101 | }; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * struct omap_mux - data for omap mux register offset and it's value |
| 105 | * @reg_offset: mux register offset from the mux base |
| 106 | * @gpio: GPIO number |
| 107 | * @muxnames: available signal modes for a ball |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 108 | * @balls: available balls on the package |
| 109 | * @partition: mux partition |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 110 | */ |
| 111 | struct omap_mux { |
| 112 | u16 reg_offset; |
| 113 | u16 gpio; |
| 114 | #ifdef CONFIG_OMAP_MUX |
| 115 | char *muxnames[OMAP_MUX_NR_MODES]; |
| 116 | #ifdef CONFIG_DEBUG_FS |
| 117 | char *balls[OMAP_MUX_NR_SIDES]; |
| 118 | #endif |
| 119 | #endif |
| 120 | }; |
| 121 | |
| 122 | /** |
| 123 | * struct omap_ball - data for balls on omap package |
| 124 | * @reg_offset: mux register offset from the mux base |
| 125 | * @balls: available balls on the package |
| 126 | */ |
| 127 | struct omap_ball { |
| 128 | u16 reg_offset; |
| 129 | char *balls[OMAP_MUX_NR_SIDES]; |
| 130 | }; |
| 131 | |
| 132 | /** |
| 133 | * struct omap_board_mux - data for initializing mux registers |
| 134 | * @reg_offset: mux register offset from the mux base |
| 135 | * @mux_value: desired mux value to set |
| 136 | */ |
| 137 | struct omap_board_mux { |
| 138 | u16 reg_offset; |
| 139 | u16 value; |
| 140 | }; |
| 141 | |
Tony Lindgren | ac3dbee | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 142 | #if defined(CONFIG_OMAP_MUX) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * omap_mux_init_gpio - initialize a signal based on the GPIO number |
| 146 | * @gpio: GPIO number |
| 147 | * @val: Options for the mux register value |
| 148 | */ |
| 149 | int omap_mux_init_gpio(int gpio, int val); |
| 150 | |
| 151 | /** |
| 152 | * omap_mux_init_signal - initialize a signal based on the signal name |
| 153 | * @muxname: Mux name in mode0_name.signal_name format |
| 154 | * @val: Options for the mux register value |
| 155 | */ |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 156 | int omap_mux_init_signal(const char *muxname, int val); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 157 | |
| 158 | #else |
| 159 | |
| 160 | static inline int omap_mux_init_gpio(int gpio, int val) |
| 161 | { |
| 162 | return 0; |
| 163 | } |
| 164 | static inline int omap_mux_init_signal(char *muxname, int val) |
| 165 | { |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | #endif |
| 170 | |
| 171 | /** |
| 172 | * omap_mux_get_gpio() - get mux register value based on GPIO number |
| 173 | * @gpio: GPIO number |
| 174 | * |
| 175 | */ |
| 176 | u16 omap_mux_get_gpio(int gpio); |
| 177 | |
| 178 | /** |
| 179 | * omap_mux_set_gpio() - set mux register value based on GPIO number |
| 180 | * @val: New mux register value |
| 181 | * @gpio: GPIO number |
| 182 | * |
| 183 | */ |
| 184 | void omap_mux_set_gpio(u16 val, int gpio); |
| 185 | |
| 186 | /** |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 187 | * omap_mux_get() - get a mux partition by name |
| 188 | * @name: Name of the mux partition |
| 189 | * |
| 190 | */ |
| 191 | struct omap_mux_partition *omap_mux_get(const char *name); |
| 192 | |
| 193 | /** |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 194 | * omap_mux_read() - read mux register |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 195 | * @partition: Mux partition |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 196 | * @mux_offset: Offset of the mux register |
| 197 | * |
| 198 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 199 | u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * omap_mux_write() - write mux register |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 203 | * @partition: Mux partition |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 204 | * @val: New mux register value |
| 205 | * @mux_offset: Offset of the mux register |
| 206 | * |
| 207 | * This should be only needed for dynamic remuxing of non-gpio signals. |
| 208 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 209 | void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * omap_mux_write_array() - write an array of mux registers |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 213 | * @partition: Mux partition |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 214 | * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR |
| 215 | * |
| 216 | * This should be only needed for dynamic remuxing of non-gpio signals. |
| 217 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 218 | void omap_mux_write_array(struct omap_mux_partition *p, |
| 219 | struct omap_board_mux *board_mux); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 220 | |
| 221 | /** |
Tony Lindgren | fc44046 | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 222 | * omap2420_mux_init() - initialize mux system with board specific set |
| 223 | * @board_mux: Board specific mux table |
| 224 | * @flags: OMAP package type used for the board |
| 225 | */ |
| 226 | int omap2420_mux_init(struct omap_board_mux *board_mux, int flags); |
| 227 | |
| 228 | /** |
Tony Lindgren | 89ba109 | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 229 | * omap2430_mux_init() - initialize mux system with board specific set |
| 230 | * @board_mux: Board specific mux table |
| 231 | * @flags: OMAP package type used for the board |
| 232 | */ |
| 233 | int omap2430_mux_init(struct omap_board_mux *board_mux, int flags); |
| 234 | |
| 235 | /** |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 236 | * omap3_mux_init() - initialize mux system with board specific set |
| 237 | * @board_mux: Board specific mux table |
| 238 | * @flags: OMAP package type used for the board |
| 239 | */ |
| 240 | int omap3_mux_init(struct omap_board_mux *board_mux, int flags); |
| 241 | |
| 242 | /** |
| 243 | * omap_mux_init - private mux init function, do not call |
| 244 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame^] | 245 | int omap_mux_init(const char *name, u32 flags, |
| 246 | u32 mux_pbase, u32 mux_size, |
| 247 | struct omap_mux *superset, |
| 248 | struct omap_mux *package_subset, |
| 249 | struct omap_board_mux *board_mux, |
| 250 | struct omap_ball *package_balls); |
| 251 | |