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 10#include "mux2420.h" 11#include "mux2430.h" 12#include "mux34xx.h" 13 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 59/* Flags for omap_mux_init */ 60#define OMAP_PACKAGE_MASK 0xffff 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 */ 67 68 69#define OMAP_MUX_NR_MODES 8 /* Available modes */ 70#define OMAP_MUX_NR_SIDES 2 /* Bottom & top */ 71 72/** 73 * struct omap_mux - data for omap mux register offset and it's value 74 * @reg_offset: mux register offset from the mux base 75 * @gpio: GPIO number 76 * @muxnames: available signal modes for a ball 77 */ 78struct omap_mux { 79 u16 reg_offset; 80 u16 gpio; 81#ifdef CONFIG_OMAP_MUX 82 char *muxnames[OMAP_MUX_NR_MODES]; 83#ifdef CONFIG_DEBUG_FS 84 char *balls[OMAP_MUX_NR_SIDES]; 85#endif 86#endif 87}; 88 89/** 90 * struct omap_ball - data for balls on omap package 91 * @reg_offset: mux register offset from the mux base 92 * @balls: available balls on the package 93 */ 94struct omap_ball { 95 u16 reg_offset; 96 char *balls[OMAP_MUX_NR_SIDES]; 97}; 98 99/** 100 * struct omap_board_mux - data for initializing mux registers 101 * @reg_offset: mux register offset from the mux base 102 * @mux_value: desired mux value to set 103 */ 104struct omap_board_mux { 105 u16 reg_offset; 106 u16 value; 107}; 108 109#if defined(CONFIG_OMAP_MUX) 110 111/** 112 * omap_mux_init_gpio - initialize a signal based on the GPIO number 113 * @gpio: GPIO number 114 * @val: Options for the mux register value 115 */ 116int omap_mux_init_gpio(int gpio, int val); 117 118/** 119 * omap_mux_init_signal - initialize a signal based on the signal name 120 * @muxname: Mux name in mode0_name.signal_name format 121 * @val: Options for the mux register value 122 */ 123int omap_mux_init_signal(char *muxname, int val); 124 125#else 126 127static inline int omap_mux_init_gpio(int gpio, int val) 128{ 129 return 0; 130} 131static inline int omap_mux_init_signal(char *muxname, int val) 132{ 133 return 0; 134} 135 136#endif 137 138/** 139 * omap_mux_get_gpio() - get mux register value based on GPIO number 140 * @gpio: GPIO number 141 * 142 */ 143u16 omap_mux_get_gpio(int gpio); 144 145/** 146 * omap_mux_set_gpio() - set mux register value based on GPIO number 147 * @val: New mux register value 148 * @gpio: GPIO number 149 * 150 */ 151void omap_mux_set_gpio(u16 val, int gpio); 152 153/** 154 * omap_mux_read() - read mux register 155 * @mux_offset: Offset of the mux register 156 * 157 */ 158u16 omap_mux_read(u16 mux_offset); 159 160/** 161 * omap_mux_write() - write mux register 162 * @val: New mux register value 163 * @mux_offset: Offset of the mux register 164 * 165 * This should be only needed for dynamic remuxing of non-gpio signals. 166 */ 167void omap_mux_write(u16 val, u16 mux_offset); 168 169/** 170 * omap_mux_write_array() - write an array of mux registers 171 * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR 172 * 173 * This should be only needed for dynamic remuxing of non-gpio signals. 174 */ 175void omap_mux_write_array(struct omap_board_mux *board_mux); 176 177/** 178 * omap2420_mux_init() - initialize mux system with board specific set 179 * @board_mux: Board specific mux table 180 * @flags: OMAP package type used for the board 181 */ 182int omap2420_mux_init(struct omap_board_mux *board_mux, int flags); 183 184/** 185 * omap2430_mux_init() - initialize mux system with board specific set 186 * @board_mux: Board specific mux table 187 * @flags: OMAP package type used for the board 188 */ 189int omap2430_mux_init(struct omap_board_mux *board_mux, int flags); 190 191/** 192 * omap3_mux_init() - initialize mux system with board specific set 193 * @board_mux: Board specific mux table 194 * @flags: OMAP package type used for the board 195 */ 196int omap3_mux_init(struct omap_board_mux *board_mux, int flags); 197 198/** 199 * omap_mux_init - private mux init function, do not call 200 */ 201int omap_mux_init(u32 mux_pbase, u32 mux_size, 202 struct omap_mux *superset, 203 struct omap_mux *package_subset, 204 struct omap_board_mux *board_mux, 205 struct omap_ball *package_balls); 206