blob: e14cd4dc9a4d632247c15d2f99043e6807506e4f [file] [log] [blame]
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001/*
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 Lindgrenfc440462010-07-05 16:31:36 +030010#include "mux2420.h"
Tony Lindgrenddaa9122009-12-11 16:16:32 -080011#include "mux34xx.h"
12
Tony Lindgren15ac7af2009-12-11 16:16:32 -080013#define OMAP_MUX_TERMINATOR 0xffff
14
15/* 34xx mux mode options for each pin. See TRM for options */
16#define OMAP_MUX_MODE0 0
17#define OMAP_MUX_MODE1 1
18#define OMAP_MUX_MODE2 2
19#define OMAP_MUX_MODE3 3
20#define OMAP_MUX_MODE4 4
21#define OMAP_MUX_MODE5 5
22#define OMAP_MUX_MODE6 6
23#define OMAP_MUX_MODE7 7
24
25/* 24xx/34xx mux bit defines */
26#define OMAP_PULL_ENA (1 << 3)
27#define OMAP_PULL_UP (1 << 4)
28#define OMAP_ALTELECTRICALSEL (1 << 5)
29
30/* 34xx specific mux bit defines */
31#define OMAP_INPUT_EN (1 << 8)
32#define OMAP_OFF_EN (1 << 9)
33#define OMAP_OFFOUT_EN (1 << 10)
34#define OMAP_OFFOUT_VAL (1 << 11)
35#define OMAP_OFF_PULL_EN (1 << 12)
36#define OMAP_OFF_PULL_UP (1 << 13)
37#define OMAP_WAKEUP_EN (1 << 14)
38
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
56#define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
57
58/* Flags for omap_mux_init */
59#define OMAP_PACKAGE_MASK 0xffff
Tony Lindgren6dd8a682010-07-05 16:31:35 +030060#define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
61#define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
62#define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
63#define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
64#define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
65#define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080066
67
68#define OMAP_MUX_NR_MODES 8 /* Available modes */
69#define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
70
71/**
72 * struct omap_mux - data for omap mux register offset and it's value
73 * @reg_offset: mux register offset from the mux base
74 * @gpio: GPIO number
75 * @muxnames: available signal modes for a ball
76 */
77struct omap_mux {
78 u16 reg_offset;
79 u16 gpio;
80#ifdef CONFIG_OMAP_MUX
81 char *muxnames[OMAP_MUX_NR_MODES];
82#ifdef CONFIG_DEBUG_FS
83 char *balls[OMAP_MUX_NR_SIDES];
84#endif
85#endif
86};
87
88/**
89 * struct omap_ball - data for balls on omap package
90 * @reg_offset: mux register offset from the mux base
91 * @balls: available balls on the package
92 */
93struct omap_ball {
94 u16 reg_offset;
95 char *balls[OMAP_MUX_NR_SIDES];
96};
97
98/**
99 * struct omap_board_mux - data for initializing mux registers
100 * @reg_offset: mux register offset from the mux base
101 * @mux_value: desired mux value to set
102 */
103struct omap_board_mux {
104 u16 reg_offset;
105 u16 value;
106};
107
Tony Lindgrenac3dbee2010-07-05 16:31:36 +0300108#if defined(CONFIG_OMAP_MUX)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800109
110/**
111 * omap_mux_init_gpio - initialize a signal based on the GPIO number
112 * @gpio: GPIO number
113 * @val: Options for the mux register value
114 */
115int omap_mux_init_gpio(int gpio, int val);
116
117/**
118 * omap_mux_init_signal - initialize a signal based on the signal name
119 * @muxname: Mux name in mode0_name.signal_name format
120 * @val: Options for the mux register value
121 */
122int omap_mux_init_signal(char *muxname, int val);
123
124#else
125
126static inline int omap_mux_init_gpio(int gpio, int val)
127{
128 return 0;
129}
130static inline int omap_mux_init_signal(char *muxname, int val)
131{
132 return 0;
133}
134
135#endif
136
137/**
138 * omap_mux_get_gpio() - get mux register value based on GPIO number
139 * @gpio: GPIO number
140 *
141 */
142u16 omap_mux_get_gpio(int gpio);
143
144/**
145 * omap_mux_set_gpio() - set mux register value based on GPIO number
146 * @val: New mux register value
147 * @gpio: GPIO number
148 *
149 */
150void omap_mux_set_gpio(u16 val, int gpio);
151
152/**
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800153 * omap_mux_read() - read mux register
154 * @mux_offset: Offset of the mux register
155 *
156 */
157u16 omap_mux_read(u16 mux_offset);
158
159/**
160 * omap_mux_write() - write mux register
161 * @val: New mux register value
162 * @mux_offset: Offset of the mux register
163 *
164 * This should be only needed for dynamic remuxing of non-gpio signals.
165 */
166void omap_mux_write(u16 val, u16 mux_offset);
167
168/**
169 * omap_mux_write_array() - write an array of mux registers
170 * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
171 *
172 * This should be only needed for dynamic remuxing of non-gpio signals.
173 */
174void omap_mux_write_array(struct omap_board_mux *board_mux);
175
176/**
Tony Lindgrenfc440462010-07-05 16:31:36 +0300177 * omap2420_mux_init() - initialize mux system with board specific set
178 * @board_mux: Board specific mux table
179 * @flags: OMAP package type used for the board
180 */
181int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
182
183/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800184 * omap3_mux_init() - initialize mux system with board specific set
185 * @board_mux: Board specific mux table
186 * @flags: OMAP package type used for the board
187 */
188int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
189
190/**
191 * omap_mux_init - private mux init function, do not call
192 */
193int omap_mux_init(u32 mux_pbase, u32 mux_size,
194 struct omap_mux *superset,
195 struct omap_mux *package_subset,
196 struct omap_board_mux *board_mux,
197 struct omap_ball *package_balls);