blob: a6bd58f02f72eecec7d7ce277d7f66638e36ca40 [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 Lindgrenddaa9122009-12-11 16:16:32 -080010#include "mux34xx.h"
11
Tony Lindgren15ac7af2009-12-11 16:16:32 -080012#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
29/* 34xx specific mux bit defines */
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)
37
38/* Active pin states */
39#define OMAP_PIN_OUTPUT 0
40#define OMAP_PIN_INPUT OMAP_INPUT_EN
41#define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \
42 | OMAP_PULL_UP)
43#define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN)
44
45/* Off mode states */
46#define OMAP_PIN_OFF_NONE 0
47#define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \
48 | OMAP_OFFOUT_VAL)
49#define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN)
50#define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
51 | OMAP_OFF_PULL_UP)
52#define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
53#define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN
54
55#define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
56
57/* Flags for omap_mux_init */
58#define OMAP_PACKAGE_MASK 0xffff
59#define OMAP_PACKAGE_CUS 3 /* 423-pin 0.65 */
60#define OMAP_PACKAGE_CBB 2 /* 515-pin 0.40 0.50 */
61#define OMAP_PACKAGE_CBC 1 /* 515-pin 0.50 0.65 */
62
63
64#define OMAP_MUX_NR_MODES 8 /* Available modes */
65#define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
66
67/**
68 * struct omap_mux - data for omap mux register offset and it's value
69 * @reg_offset: mux register offset from the mux base
70 * @gpio: GPIO number
71 * @muxnames: available signal modes for a ball
72 */
73struct omap_mux {
74 u16 reg_offset;
75 u16 gpio;
76#ifdef CONFIG_OMAP_MUX
77 char *muxnames[OMAP_MUX_NR_MODES];
78#ifdef CONFIG_DEBUG_FS
79 char *balls[OMAP_MUX_NR_SIDES];
80#endif
81#endif
82};
83
84/**
85 * struct omap_ball - data for balls on omap package
86 * @reg_offset: mux register offset from the mux base
87 * @balls: available balls on the package
88 */
89struct omap_ball {
90 u16 reg_offset;
91 char *balls[OMAP_MUX_NR_SIDES];
92};
93
94/**
95 * struct omap_board_mux - data for initializing mux registers
96 * @reg_offset: mux register offset from the mux base
97 * @mux_value: desired mux value to set
98 */
99struct omap_board_mux {
100 u16 reg_offset;
101 u16 value;
102};
103
104#if defined(CONFIG_OMAP_MUX) && defined(CONFIG_ARCH_OMAP34XX)
105
106/**
107 * omap_mux_init_gpio - initialize a signal based on the GPIO number
108 * @gpio: GPIO number
109 * @val: Options for the mux register value
110 */
111int omap_mux_init_gpio(int gpio, int val);
112
113/**
114 * omap_mux_init_signal - initialize a signal based on the signal name
115 * @muxname: Mux name in mode0_name.signal_name format
116 * @val: Options for the mux register value
117 */
118int omap_mux_init_signal(char *muxname, int val);
119
120#else
121
122static inline int omap_mux_init_gpio(int gpio, int val)
123{
124 return 0;
125}
126static inline int omap_mux_init_signal(char *muxname, int val)
127{
128 return 0;
129}
130
131#endif
132
133/**
134 * omap_mux_get_gpio() - get mux register value based on GPIO number
135 * @gpio: GPIO number
136 *
137 */
138u16 omap_mux_get_gpio(int gpio);
139
140/**
141 * omap_mux_set_gpio() - set mux register value based on GPIO number
142 * @val: New mux register value
143 * @gpio: GPIO number
144 *
145 */
146void omap_mux_set_gpio(u16 val, int gpio);
147
148/**
149 * omap3_mux_init() - initialize mux system with board specific set
150 * @board_mux: Board specific mux table
151 * @flags: OMAP package type used for the board
152 */
153int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
154
155/**
156 * omap_mux_init - private mux init function, do not call
157 */
158int omap_mux_init(u32 mux_pbase, u32 mux_size,
159 struct omap_mux *superset,
160 struct omap_mux *package_subset,
161 struct omap_board_mux *board_mux,
162 struct omap_ball *package_balls);