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