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 | 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 | |
Tony Lindgren | d623a0e | 2013-10-07 10:22:01 -0700 | [diff] [blame] | 29 | /* omap3/4/5 specific mux bit defines */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 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) |
Benoit Cousson | a041a52 | 2010-08-10 17:27:48 +0200 | [diff] [blame] | 37 | #define OMAP_WAKEUP_EVENT (1 << 15) |
| 38 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 39 | /* Active pin states */ |
| 40 | #define OMAP_PIN_OUTPUT 0 |
| 41 | #define OMAP_PIN_INPUT OMAP_INPUT_EN |
| 42 | #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \ |
| 43 | | OMAP_PULL_UP) |
| 44 | #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN) |
| 45 | |
| 46 | /* Off mode states */ |
| 47 | #define OMAP_PIN_OFF_NONE 0 |
| 48 | #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \ |
| 49 | | OMAP_OFFOUT_VAL) |
| 50 | #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN) |
| 51 | #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \ |
| 52 | | OMAP_OFF_PULL_UP) |
| 53 | #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN) |
| 54 | #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN |
| 55 | |
Oleg Matcovschi | 421e845 | 2012-11-26 17:02:03 -0800 | [diff] [blame] | 56 | #define OMAP_MODE_GPIO(partition, x) (((x) & OMAP_MUX_MODE7) == \ |
| 57 | partition->gpio) |
Govindraj.R | 9193065 | 2012-06-05 04:04:11 -0700 | [diff] [blame] | 58 | #define OMAP_MODE_UART(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE0) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 59 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 60 | /* Flags for omapX_mux_init */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 61 | #define OMAP_PACKAGE_MASK 0xffff |
Tony Lindgren | 6dd8a68 | 2010-07-05 16:31:35 +0300 | [diff] [blame] | 62 | #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */ |
| 63 | #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */ |
| 64 | #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */ |
| 65 | #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 66 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 67 | #define OMAP_MUX_NR_MODES 8 /* Available modes */ |
| 68 | #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */ |
| 69 | |
| 70 | /* |
| 71 | * omap_mux_init flags definition: |
| 72 | * |
Oleg Matcovschi | 421e845 | 2012-11-26 17:02:03 -0800 | [diff] [blame] | 73 | * OMAP_GPIO_MUX_MODE, bits 0-2: gpio muxing mode, same like pad control |
| 74 | * register which includes values from 0-7. |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 75 | * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits. |
| 76 | * The default value is 16 bits. |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 77 | */ |
Oleg Matcovschi | 421e845 | 2012-11-26 17:02:03 -0800 | [diff] [blame] | 78 | #define OMAP_MUX_GPIO_IN_MODE0 OMAP_MUX_MODE0 |
| 79 | #define OMAP_MUX_GPIO_IN_MODE1 OMAP_MUX_MODE1 |
| 80 | #define OMAP_MUX_GPIO_IN_MODE2 OMAP_MUX_MODE2 |
| 81 | #define OMAP_MUX_GPIO_IN_MODE3 OMAP_MUX_MODE3 |
| 82 | #define OMAP_MUX_GPIO_IN_MODE4 OMAP_MUX_MODE4 |
| 83 | #define OMAP_MUX_GPIO_IN_MODE5 OMAP_MUX_MODE5 |
| 84 | #define OMAP_MUX_GPIO_IN_MODE6 OMAP_MUX_MODE6 |
| 85 | #define OMAP_MUX_GPIO_IN_MODE7 OMAP_MUX_MODE7 |
| 86 | #define OMAP_MUX_REG_8BIT (1 << 3) |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 87 | |
| 88 | /** |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 89 | * struct omap_board_data - board specific device data |
| 90 | * @id: instance id |
| 91 | * @flags: additional flags for platform init code |
| 92 | * @pads: array of device specific pads |
| 93 | * @pads_cnt: ARRAY_SIZE() of pads |
| 94 | */ |
| 95 | struct omap_board_data { |
| 96 | int id; |
| 97 | u32 flags; |
| 98 | struct omap_device_pad *pads; |
| 99 | int pads_cnt; |
| 100 | }; |
| 101 | |
| 102 | /** |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 103 | * struct mux_partition - contain partition related information |
| 104 | * @name: name of the current partition |
| 105 | * @flags: flags specific to this partition |
Oleg Matcovschi | 421e845 | 2012-11-26 17:02:03 -0800 | [diff] [blame] | 106 | * @gpio: gpio mux mode |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 107 | * @phys: physical address |
| 108 | * @size: partition size |
| 109 | * @base: virtual address after ioremap |
| 110 | * @muxmodes: list of nodes that belong to a partition |
| 111 | * @node: list node for the partitions linked list |
| 112 | */ |
| 113 | struct omap_mux_partition { |
| 114 | const char *name; |
| 115 | u32 flags; |
Oleg Matcovschi | 421e845 | 2012-11-26 17:02:03 -0800 | [diff] [blame] | 116 | u32 gpio; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 117 | u32 phys; |
| 118 | u32 size; |
| 119 | void __iomem *base; |
| 120 | struct list_head muxmodes; |
| 121 | struct list_head node; |
| 122 | }; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * struct omap_mux - data for omap mux register offset and it's value |
| 126 | * @reg_offset: mux register offset from the mux base |
| 127 | * @gpio: GPIO number |
| 128 | * @muxnames: available signal modes for a ball |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 129 | * @balls: available balls on the package |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 130 | */ |
| 131 | struct omap_mux { |
| 132 | u16 reg_offset; |
| 133 | u16 gpio; |
| 134 | #ifdef CONFIG_OMAP_MUX |
| 135 | char *muxnames[OMAP_MUX_NR_MODES]; |
| 136 | #ifdef CONFIG_DEBUG_FS |
| 137 | char *balls[OMAP_MUX_NR_SIDES]; |
| 138 | #endif |
| 139 | #endif |
| 140 | }; |
| 141 | |
| 142 | /** |
| 143 | * struct omap_ball - data for balls on omap package |
| 144 | * @reg_offset: mux register offset from the mux base |
| 145 | * @balls: available balls on the package |
| 146 | */ |
| 147 | struct omap_ball { |
| 148 | u16 reg_offset; |
| 149 | char *balls[OMAP_MUX_NR_SIDES]; |
| 150 | }; |
| 151 | |
| 152 | /** |
| 153 | * struct omap_board_mux - data for initializing mux registers |
| 154 | * @reg_offset: mux register offset from the mux base |
| 155 | * @mux_value: desired mux value to set |
| 156 | */ |
| 157 | struct omap_board_mux { |
| 158 | u16 reg_offset; |
| 159 | u16 value; |
| 160 | }; |
| 161 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 162 | #define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad, |
| 163 | needs enable, idle and off |
| 164 | values */ |
| 165 | #define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */ |
| 166 | |
| 167 | /** |
| 168 | * struct omap_device_pad - device specific pad configuration |
| 169 | * @name: signal name |
| 170 | * @flags: pad specific runtime flags |
| 171 | * @enable: runtime value for a pad |
| 172 | * @idle: idle value for a pad |
| 173 | * @off: off value for a pad, defaults to safe mode |
| 174 | * @partition: mux partition |
| 175 | * @mux: mux register |
| 176 | */ |
| 177 | struct omap_device_pad { |
| 178 | char *name; |
| 179 | u8 flags; |
| 180 | u16 enable; |
| 181 | u16 idle; |
| 182 | u16 off; |
| 183 | struct omap_mux_partition *partition; |
| 184 | struct omap_mux *mux; |
| 185 | }; |
| 186 | |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 187 | struct omap_hwmod_mux_info; |
| 188 | |
Tony Lindgren | 8aee603 | 2011-03-11 11:32:26 -0800 | [diff] [blame] | 189 | #define OMAP_MUX_STATIC(signal, mode) \ |
| 190 | { \ |
| 191 | .name = (signal), \ |
| 192 | .enable = (mode), \ |
| 193 | } |
| 194 | |
Tony Lindgren | ac3dbee | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 195 | #if defined(CONFIG_OMAP_MUX) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * omap_mux_init_gpio - initialize a signal based on the GPIO number |
| 199 | * @gpio: GPIO number |
| 200 | * @val: Options for the mux register value |
| 201 | */ |
| 202 | int omap_mux_init_gpio(int gpio, int val); |
| 203 | |
| 204 | /** |
| 205 | * omap_mux_init_signal - initialize a signal based on the signal name |
| 206 | * @muxname: Mux name in mode0_name.signal_name format |
| 207 | * @val: Options for the mux register value |
| 208 | */ |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 209 | int omap_mux_init_signal(const char *muxname, int val); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 210 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 211 | /** |
| 212 | * omap_hwmod_mux_init - initialize hwmod specific mux data |
| 213 | * @bpads: Board specific device signal names |
| 214 | * @nr_pads: Number of signal names for the device |
| 215 | */ |
| 216 | extern struct omap_hwmod_mux_info * |
| 217 | omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads); |
| 218 | |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 219 | /** |
| 220 | * omap_hwmod_mux - omap hwmod specific pin muxing |
| 221 | * @hmux: Pads for a hwmod |
| 222 | * @state: Desired _HWMOD_STATE |
| 223 | * |
| 224 | * Called only from omap_hwmod.c, do not use. |
| 225 | */ |
| 226 | void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state); |
| 227 | |
Govindraj.R | 9193065 | 2012-06-05 04:04:11 -0700 | [diff] [blame] | 228 | int omap_mux_get_by_name(const char *muxname, |
| 229 | struct omap_mux_partition **found_partition, |
| 230 | struct omap_mux **found_mux); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 231 | #else |
| 232 | |
Govindraj.R | 9193065 | 2012-06-05 04:04:11 -0700 | [diff] [blame] | 233 | static inline int omap_mux_get_by_name(const char *muxname, |
| 234 | struct omap_mux_partition **found_partition, |
| 235 | struct omap_mux **found_mux) |
| 236 | { |
| 237 | return 0; |
| 238 | } |
| 239 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 240 | static inline int omap_mux_init_gpio(int gpio, int val) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
| 244 | static inline int omap_mux_init_signal(char *muxname, int val) |
| 245 | { |
| 246 | return 0; |
| 247 | } |
| 248 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 249 | static inline struct omap_hwmod_mux_info * |
| 250 | omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads) |
| 251 | { |
| 252 | return NULL; |
| 253 | } |
| 254 | |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 255 | static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state) |
| 256 | { |
| 257 | } |
| 258 | |
Tony Lindgren | cc4915d | 2012-02-23 14:21:28 -0800 | [diff] [blame] | 259 | static struct omap_board_mux *board_mux __maybe_unused; |
Aaro Koskinen | 7203f8a | 2010-12-02 13:25:40 +0000 | [diff] [blame] | 260 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 261 | #endif |
| 262 | |
| 263 | /** |
| 264 | * omap_mux_get_gpio() - get mux register value based on GPIO number |
| 265 | * @gpio: GPIO number |
| 266 | * |
| 267 | */ |
| 268 | u16 omap_mux_get_gpio(int gpio); |
| 269 | |
| 270 | /** |
| 271 | * omap_mux_set_gpio() - set mux register value based on GPIO number |
| 272 | * @val: New mux register value |
| 273 | * @gpio: GPIO number |
| 274 | * |
| 275 | */ |
| 276 | void omap_mux_set_gpio(u16 val, int gpio); |
| 277 | |
| 278 | /** |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 279 | * omap_mux_get() - get a mux partition by name |
| 280 | * @name: Name of the mux partition |
| 281 | * |
| 282 | */ |
| 283 | struct omap_mux_partition *omap_mux_get(const char *name); |
| 284 | |
| 285 | /** |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 286 | * omap_mux_read() - read mux register |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 287 | * @partition: Mux partition |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 288 | * @mux_offset: Offset of the mux register |
| 289 | * |
| 290 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 291 | u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 292 | |
| 293 | /** |
| 294 | * omap_mux_write() - write mux register |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 295 | * @partition: Mux partition |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 296 | * @val: New mux register value |
| 297 | * @mux_offset: Offset of the mux register |
| 298 | * |
| 299 | * This should be only needed for dynamic remuxing of non-gpio signals. |
| 300 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 301 | 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] | 302 | |
| 303 | /** |
| 304 | * omap_mux_write_array() - write an array of mux registers |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 305 | * @partition: Mux partition |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 306 | * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR |
| 307 | * |
| 308 | * This should be only needed for dynamic remuxing of non-gpio signals. |
| 309 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 310 | void omap_mux_write_array(struct omap_mux_partition *p, |
| 311 | struct omap_board_mux *board_mux); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 312 | |
| 313 | /** |
Tony Lindgren | fc44046 | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 314 | * omap2420_mux_init() - initialize mux system with board specific set |
| 315 | * @board_mux: Board specific mux table |
| 316 | * @flags: OMAP package type used for the board |
| 317 | */ |
| 318 | int omap2420_mux_init(struct omap_board_mux *board_mux, int flags); |
| 319 | |
| 320 | /** |
Tony Lindgren | 89ba109 | 2010-07-05 16:31:36 +0300 | [diff] [blame] | 321 | * omap2430_mux_init() - initialize mux system with board specific set |
| 322 | * @board_mux: Board specific mux table |
| 323 | * @flags: OMAP package type used for the board |
| 324 | */ |
| 325 | int omap2430_mux_init(struct omap_board_mux *board_mux, int flags); |
| 326 | |
| 327 | /** |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 328 | * omap3_mux_init() - initialize mux system with board specific set |
| 329 | * @board_mux: Board specific mux table |
| 330 | * @flags: OMAP package type used for the board |
| 331 | */ |
| 332 | int omap3_mux_init(struct omap_board_mux *board_mux, int flags); |
| 333 | |
| 334 | /** |
Benoit Cousson | a041a52 | 2010-08-10 17:27:48 +0200 | [diff] [blame] | 335 | * omap4_mux_init() - initialize mux system with board specific set |
Colin Cross | 21a42c9 | 2011-05-04 14:57:57 -0700 | [diff] [blame] | 336 | * @board_subset: Board specific mux table |
| 337 | * @board_wkup_subset: Board specific mux table for wakeup instance |
Benoit Cousson | a041a52 | 2010-08-10 17:27:48 +0200 | [diff] [blame] | 338 | * @flags: OMAP package type used for the board |
| 339 | */ |
Colin Cross | 21a42c9 | 2011-05-04 14:57:57 -0700 | [diff] [blame] | 340 | int omap4_mux_init(struct omap_board_mux *board_subset, |
| 341 | struct omap_board_mux *board_wkup_subset, int flags); |
Benoit Cousson | a041a52 | 2010-08-10 17:27:48 +0200 | [diff] [blame] | 342 | |
| 343 | /** |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 344 | * omap_mux_init - private mux init function, do not call |
| 345 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 346 | int omap_mux_init(const char *name, u32 flags, |
| 347 | u32 mux_pbase, u32 mux_size, |
| 348 | struct omap_mux *superset, |
| 349 | struct omap_mux *package_subset, |
| 350 | struct omap_board_mux *board_mux, |
| 351 | struct omap_ball *package_balls); |
| 352 | |