blob: 82bb9fd3bac2c21e5028453402226eb3dd1a9c41 [file] [log] [blame]
Chandan Nath5289e832011-10-14 02:58:26 +00001/*
2 * mux.c
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
Tom Rinidb7dd812012-07-31 10:50:01 -070016#include <common.h>
17#include <asm/arch/sys_proto.h>
Chandan Nath5289e832011-10-14 02:58:26 +000018#include <asm/arch/hardware.h>
19#include <asm/io.h>
Tom Rini036fd652012-08-08 09:03:07 -070020#include <i2c.h>
Peter Korsgaarde3634262012-10-18 01:21:09 +000021#include "board.h"
Chandan Nath5289e832011-10-14 02:58:26 +000022
23#define MUX_CFG(value, offset) \
24 __raw_writel(value, (CTRL_BASE + offset));
25
26/* PAD Control Fields */
27#define SLEWCTRL (0x1 << 6)
28#define RXACTIVE (0x1 << 5)
29#define PULLUP_EN (0x1 << 4) /* Pull UP Selection */
30#define PULLUDEN (0x0 << 3) /* Pull up enabled */
31#define PULLUDDIS (0x1 << 3) /* Pull up disabled */
32#define MODE(val) val /* used for Readability */
33
34/*
35 * PAD CONTROL OFFSETS
36 * Field names corresponds to the pad signal name
37 */
38struct pad_signals {
39 int gpmc_ad0;
40 int gpmc_ad1;
41 int gpmc_ad2;
42 int gpmc_ad3;
43 int gpmc_ad4;
44 int gpmc_ad5;
45 int gpmc_ad6;
46 int gpmc_ad7;
47 int gpmc_ad8;
48 int gpmc_ad9;
49 int gpmc_ad10;
50 int gpmc_ad11;
51 int gpmc_ad12;
52 int gpmc_ad13;
53 int gpmc_ad14;
54 int gpmc_ad15;
55 int gpmc_a0;
56 int gpmc_a1;
57 int gpmc_a2;
58 int gpmc_a3;
59 int gpmc_a4;
60 int gpmc_a5;
61 int gpmc_a6;
62 int gpmc_a7;
63 int gpmc_a8;
64 int gpmc_a9;
65 int gpmc_a10;
66 int gpmc_a11;
67 int gpmc_wait0;
68 int gpmc_wpn;
69 int gpmc_be1n;
70 int gpmc_csn0;
71 int gpmc_csn1;
72 int gpmc_csn2;
73 int gpmc_csn3;
74 int gpmc_clk;
75 int gpmc_advn_ale;
76 int gpmc_oen_ren;
77 int gpmc_wen;
78 int gpmc_be0n_cle;
79 int lcd_data0;
80 int lcd_data1;
81 int lcd_data2;
82 int lcd_data3;
83 int lcd_data4;
84 int lcd_data5;
85 int lcd_data6;
86 int lcd_data7;
87 int lcd_data8;
88 int lcd_data9;
89 int lcd_data10;
90 int lcd_data11;
91 int lcd_data12;
92 int lcd_data13;
93 int lcd_data14;
94 int lcd_data15;
95 int lcd_vsync;
96 int lcd_hsync;
97 int lcd_pclk;
98 int lcd_ac_bias_en;
99 int mmc0_dat3;
100 int mmc0_dat2;
101 int mmc0_dat1;
102 int mmc0_dat0;
103 int mmc0_clk;
104 int mmc0_cmd;
105 int mii1_col;
106 int mii1_crs;
107 int mii1_rxerr;
108 int mii1_txen;
109 int mii1_rxdv;
110 int mii1_txd3;
111 int mii1_txd2;
112 int mii1_txd1;
113 int mii1_txd0;
114 int mii1_txclk;
115 int mii1_rxclk;
116 int mii1_rxd3;
117 int mii1_rxd2;
118 int mii1_rxd1;
119 int mii1_rxd0;
120 int rmii1_refclk;
121 int mdio_data;
122 int mdio_clk;
123 int spi0_sclk;
124 int spi0_d0;
125 int spi0_d1;
126 int spi0_cs0;
127 int spi0_cs1;
128 int ecap0_in_pwm0_out;
129 int uart0_ctsn;
130 int uart0_rtsn;
131 int uart0_rxd;
132 int uart0_txd;
133 int uart1_ctsn;
134 int uart1_rtsn;
135 int uart1_rxd;
136 int uart1_txd;
137 int i2c0_sda;
138 int i2c0_scl;
139 int mcasp0_aclkx;
140 int mcasp0_fsx;
141 int mcasp0_axr0;
142 int mcasp0_ahclkr;
143 int mcasp0_aclkr;
144 int mcasp0_fsr;
145 int mcasp0_axr1;
146 int mcasp0_ahclkx;
147 int xdma_event_intr0;
148 int xdma_event_intr1;
149 int nresetin_out;
150 int porz;
151 int nnmi;
152 int osc0_in;
153 int osc0_out;
154 int rsvd1;
155 int tms;
156 int tdi;
157 int tdo;
158 int tck;
159 int ntrst;
160 int emu0;
161 int emu1;
162 int osc1_in;
163 int osc1_out;
164 int pmic_power_en;
165 int rtc_porz;
166 int rsvd2;
167 int ext_wakeup;
168 int enz_kaldo_1p8v;
169 int usb0_dm;
170 int usb0_dp;
171 int usb0_ce;
172 int usb0_id;
173 int usb0_vbus;
174 int usb0_drvvbus;
175 int usb1_dm;
176 int usb1_dp;
177 int usb1_ce;
178 int usb1_id;
179 int usb1_vbus;
180 int usb1_drvvbus;
181 int ddr_resetn;
182 int ddr_csn0;
183 int ddr_cke;
184 int ddr_ck;
185 int ddr_nck;
186 int ddr_casn;
187 int ddr_rasn;
188 int ddr_wen;
189 int ddr_ba0;
190 int ddr_ba1;
191 int ddr_ba2;
192 int ddr_a0;
193 int ddr_a1;
194 int ddr_a2;
195 int ddr_a3;
196 int ddr_a4;
197 int ddr_a5;
198 int ddr_a6;
199 int ddr_a7;
200 int ddr_a8;
201 int ddr_a9;
202 int ddr_a10;
203 int ddr_a11;
204 int ddr_a12;
205 int ddr_a13;
206 int ddr_a14;
207 int ddr_a15;
208 int ddr_odt;
209 int ddr_d0;
210 int ddr_d1;
211 int ddr_d2;
212 int ddr_d3;
213 int ddr_d4;
214 int ddr_d5;
215 int ddr_d6;
216 int ddr_d7;
217 int ddr_d8;
218 int ddr_d9;
219 int ddr_d10;
220 int ddr_d11;
221 int ddr_d12;
222 int ddr_d13;
223 int ddr_d14;
224 int ddr_d15;
225 int ddr_dqm0;
226 int ddr_dqm1;
227 int ddr_dqs0;
228 int ddr_dqsn0;
229 int ddr_dqs1;
230 int ddr_dqsn1;
231 int ddr_vref;
232 int ddr_vtp;
233 int ddr_strben0;
234 int ddr_strben1;
235 int ain7;
236 int ain6;
237 int ain5;
238 int ain4;
239 int ain3;
240 int ain2;
241 int ain1;
242 int ain0;
243 int vrefp;
244 int vrefn;
245};
246
247struct module_pin_mux {
248 short reg_offset;
249 unsigned char val;
250};
251
252/* Pad control register offset */
253#define PAD_CTRL_BASE 0x800
254#define OFFSET(x) (unsigned int) (&((struct pad_signals *) \
255 (PAD_CTRL_BASE))->x)
256
257static struct module_pin_mux uart0_pin_mux[] = {
258 {OFFSET(uart0_rxd), (MODE(0) | PULLUP_EN | RXACTIVE)}, /* UART0_RXD */
259 {OFFSET(uart0_txd), (MODE(0) | PULLUDEN)}, /* UART0_TXD */
260 {-1},
261};
262
Chandan Nath876bdd62012-01-09 20:38:58 +0000263static struct module_pin_mux mmc0_pin_mux[] = {
264 {OFFSET(mmc0_dat3), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT3 */
265 {OFFSET(mmc0_dat2), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT2 */
266 {OFFSET(mmc0_dat1), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT1 */
267 {OFFSET(mmc0_dat0), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT0 */
268 {OFFSET(mmc0_clk), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CLK */
269 {OFFSET(mmc0_cmd), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CMD */
270 {OFFSET(mcasp0_aclkr), (MODE(4) | RXACTIVE)}, /* MMC0_WP */
271 {OFFSET(spi0_cs1), (MODE(5) | RXACTIVE | PULLUP_EN)}, /* MMC0_CD */
272 {-1},
273};
Tom Rinidb7dd812012-07-31 10:50:01 -0700274
275static struct module_pin_mux mmc0_pin_mux_sk_evm[] = {
276 {OFFSET(mmc0_dat3), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT3 */
277 {OFFSET(mmc0_dat2), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT2 */
278 {OFFSET(mmc0_dat1), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT1 */
279 {OFFSET(mmc0_dat0), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT0 */
280 {OFFSET(mmc0_clk), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CLK */
281 {OFFSET(mmc0_cmd), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CMD */
282 {OFFSET(spi0_cs1), (MODE(5) | RXACTIVE | PULLUP_EN)}, /* MMC0_CD */
283 {-1},
284};
Chandan Nath876bdd62012-01-09 20:38:58 +0000285
Tom Rini6bfca502012-08-08 10:32:09 -0700286static struct module_pin_mux mmc1_pin_mux[] = {
287 {OFFSET(gpmc_ad3), (MODE(1) | RXACTIVE | PULLUP_EN)}, /* MMC1_DAT3 */
288 {OFFSET(gpmc_ad2), (MODE(1) | RXACTIVE | PULLUP_EN)}, /* MMC1_DAT2 */
289 {OFFSET(gpmc_ad1), (MODE(1) | RXACTIVE | PULLUP_EN)}, /* MMC1_DAT1 */
290 {OFFSET(gpmc_ad0), (MODE(1) | RXACTIVE | PULLUP_EN)}, /* MMC1_DAT0 */
291 {OFFSET(gpmc_csn1), (MODE(2) | RXACTIVE | PULLUP_EN)}, /* MMC1_CLK */
292 {OFFSET(gpmc_csn2), (MODE(2) | RXACTIVE | PULLUP_EN)}, /* MMC1_CMD */
293 {OFFSET(gpmc_csn0), (MODE(7) | RXACTIVE | PULLUP_EN)}, /* MMC1_WP */
294 {OFFSET(gpmc_advn_ale), (MODE(7) | RXACTIVE | PULLUP_EN)}, /* MMC1_CD */
295 {-1},
296};
297
Patil, Rachnab4116ed2012-01-22 23:47:01 +0000298static struct module_pin_mux i2c0_pin_mux[] = {
299 {OFFSET(i2c0_sda), (MODE(0) | RXACTIVE |
300 PULLUDEN | SLEWCTRL)}, /* I2C_DATA */
301 {OFFSET(i2c0_scl), (MODE(0) | RXACTIVE |
302 PULLUDEN | SLEWCTRL)}, /* I2C_SCLK */
303 {-1},
304};
305
Steve Sakomand3decde2012-06-22 07:45:57 +0000306static struct module_pin_mux i2c1_pin_mux[] = {
307 {OFFSET(spi0_d1), (MODE(2) | RXACTIVE |
308 PULLUDEN | SLEWCTRL)}, /* I2C_DATA */
309 {OFFSET(spi0_cs0), (MODE(2) | RXACTIVE |
310 PULLUDEN | SLEWCTRL)}, /* I2C_SCLK */
311 {-1},
312};
313
Tom Rinia4a99ff2012-08-08 14:35:55 -0700314static struct module_pin_mux spi0_pin_mux[] = {
315 {OFFSET(spi0_sclk), (MODE(0) | RXACTIVE | PULLUDEN)}, /* SPI0_SCLK */
316 {OFFSET(spi0_d0), (MODE(0) | RXACTIVE |
317 PULLUDEN | PULLUP_EN)}, /* SPI0_D0 */
318 {OFFSET(spi0_d1), (MODE(0) | RXACTIVE | PULLUDEN)}, /* SPI0_D1 */
319 {OFFSET(spi0_cs0), (MODE(0) | RXACTIVE |
320 PULLUDEN | PULLUP_EN)}, /* SPI0_CS0 */
321 {-1},
322};
323
Tom Rini65d750b2012-07-31 08:55:01 -0700324static struct module_pin_mux gpio0_7_pin_mux[] = {
325 {OFFSET(ecap0_in_pwm0_out), (MODE(7) | PULLUDEN)}, /* GPIO0_7 */
326 {-1},
327};
328
Chandan Nath89017e12012-07-24 12:22:18 +0000329static struct module_pin_mux rgmii1_pin_mux[] = {
330 {OFFSET(mii1_txen), MODE(2)}, /* RGMII1_TCTL */
331 {OFFSET(mii1_rxdv), MODE(2) | RXACTIVE}, /* RGMII1_RCTL */
332 {OFFSET(mii1_txd3), MODE(2)}, /* RGMII1_TD3 */
333 {OFFSET(mii1_txd2), MODE(2)}, /* RGMII1_TD2 */
334 {OFFSET(mii1_txd1), MODE(2)}, /* RGMII1_TD1 */
335 {OFFSET(mii1_txd0), MODE(2)}, /* RGMII1_TD0 */
336 {OFFSET(mii1_txclk), MODE(2)}, /* RGMII1_TCLK */
337 {OFFSET(mii1_rxclk), MODE(2) | RXACTIVE}, /* RGMII1_RCLK */
338 {OFFSET(mii1_rxd3), MODE(2) | RXACTIVE}, /* RGMII1_RD3 */
339 {OFFSET(mii1_rxd2), MODE(2) | RXACTIVE}, /* RGMII1_RD2 */
340 {OFFSET(mii1_rxd1), MODE(2) | RXACTIVE}, /* RGMII1_RD1 */
341 {OFFSET(mii1_rxd0), MODE(2) | RXACTIVE}, /* RGMII1_RD0 */
342 {OFFSET(mdio_data), MODE(0) | RXACTIVE | PULLUP_EN},/* MDIO_DATA */
343 {OFFSET(mdio_clk), MODE(0) | PULLUP_EN}, /* MDIO_CLK */
344 {-1},
345};
346
347static struct module_pin_mux mii1_pin_mux[] = {
348 {OFFSET(mii1_rxerr), MODE(0) | RXACTIVE}, /* MII1_RXERR */
349 {OFFSET(mii1_txen), MODE(0)}, /* MII1_TXEN */
350 {OFFSET(mii1_rxdv), MODE(0) | RXACTIVE}, /* MII1_RXDV */
351 {OFFSET(mii1_txd3), MODE(0)}, /* MII1_TXD3 */
352 {OFFSET(mii1_txd2), MODE(0)}, /* MII1_TXD2 */
353 {OFFSET(mii1_txd1), MODE(0)}, /* MII1_TXD1 */
354 {OFFSET(mii1_txd0), MODE(0)}, /* MII1_TXD0 */
355 {OFFSET(mii1_txclk), MODE(0) | RXACTIVE}, /* MII1_TXCLK */
356 {OFFSET(mii1_rxclk), MODE(0) | RXACTIVE}, /* MII1_RXCLK */
357 {OFFSET(mii1_rxd3), MODE(0) | RXACTIVE}, /* MII1_RXD3 */
358 {OFFSET(mii1_rxd2), MODE(0) | RXACTIVE}, /* MII1_RXD2 */
359 {OFFSET(mii1_rxd1), MODE(0) | RXACTIVE}, /* MII1_RXD1 */
360 {OFFSET(mii1_rxd0), MODE(0) | RXACTIVE}, /* MII1_RXD0 */
361 {OFFSET(mdio_data), MODE(0) | RXACTIVE | PULLUP_EN}, /* MDIO_DATA */
362 {OFFSET(mdio_clk), MODE(0) | PULLUP_EN}, /* MDIO_CLK */
363 {-1},
364};
365
Chandan Nath5289e832011-10-14 02:58:26 +0000366/*
367 * Configure the pin mux for the module
368 */
369static void configure_module_pin_mux(struct module_pin_mux *mod_pin_mux)
370{
371 int i;
372
373 if (!mod_pin_mux)
374 return;
375
376 for (i = 0; mod_pin_mux[i].reg_offset != -1; i++)
377 MUX_CFG(mod_pin_mux[i].val, mod_pin_mux[i].reg_offset);
378}
379
380void enable_uart0_pin_mux(void)
381{
382 configure_module_pin_mux(uart0_pin_mux);
383}
Chandan Nath876bdd62012-01-09 20:38:58 +0000384
Patil, Rachnab4116ed2012-01-22 23:47:01 +0000385
386void enable_i2c0_pin_mux(void)
387{
388 configure_module_pin_mux(i2c0_pin_mux);
389}
Steve Sakomand3decde2012-06-22 07:45:57 +0000390
Tom Rini036fd652012-08-08 09:03:07 -0700391/*
392 * The AM335x GP EVM, if daughter card(s) are connected, can have 8
393 * different profiles. These profiles determine what peripherals are
394 * valid and need pinmux to be configured.
395 */
396#define PROFILE_NONE 0x0
397#define PROFILE_0 (1 << 0)
398#define PROFILE_1 (1 << 1)
399#define PROFILE_2 (1 << 2)
400#define PROFILE_3 (1 << 3)
401#define PROFILE_4 (1 << 4)
402#define PROFILE_5 (1 << 5)
403#define PROFILE_6 (1 << 6)
404#define PROFILE_7 (1 << 7)
405#define PROFILE_MASK 0x7
406#define PROFILE_ALL 0xFF
407
408/* CPLD registers */
409#define I2C_CPLD_ADDR 0x35
410#define CFG_REG 0x10
411
412static unsigned short detect_daughter_board_profile(void)
413{
414 unsigned short val;
415
416 if (i2c_probe(I2C_CPLD_ADDR))
417 return PROFILE_NONE;
418
419 if (i2c_read(I2C_CPLD_ADDR, CFG_REG, 1, (unsigned char *)(&val), 2))
420 return PROFILE_NONE;
421
422 return (1 << (val & PROFILE_MASK));
423}
424
Tom Rinidb7dd812012-07-31 10:50:01 -0700425void enable_board_pin_mux(struct am335x_baseboard_id *header)
Steve Sakomand3decde2012-06-22 07:45:57 +0000426{
Tom Rini036fd652012-08-08 09:03:07 -0700427 /* Do board-specific muxes. */
Tom Rinidb7dd812012-07-31 10:50:01 -0700428 if (!strncmp(header->name, "A335BONE", HDR_NAME_LEN)) {
429 /* Beaglebone pinmux */
Tom Rini036fd652012-08-08 09:03:07 -0700430 configure_module_pin_mux(i2c1_pin_mux);
Tom Rinidb7dd812012-07-31 10:50:01 -0700431 configure_module_pin_mux(mii1_pin_mux);
432 configure_module_pin_mux(mmc0_pin_mux);
Tom Rini6bfca502012-08-08 10:32:09 -0700433 configure_module_pin_mux(mmc1_pin_mux);
Tom Rinidb7dd812012-07-31 10:50:01 -0700434 } else if (!strncmp(header->config, "SKU#01", 6)) {
435 /* General Purpose EVM */
Tom Rini036fd652012-08-08 09:03:07 -0700436 unsigned short profile = detect_daughter_board_profile();
Tom Rinidb7dd812012-07-31 10:50:01 -0700437 configure_module_pin_mux(rgmii1_pin_mux);
438 configure_module_pin_mux(mmc0_pin_mux);
Tom Rini036fd652012-08-08 09:03:07 -0700439 /* In profile #2 i2c1 and spi0 conflict. */
440 if (profile & ~PROFILE_2)
441 configure_module_pin_mux(i2c1_pin_mux);
Tom Rini6bfca502012-08-08 10:32:09 -0700442 else if (profile == PROFILE_2) {
443 configure_module_pin_mux(mmc1_pin_mux);
Tom Rinia4a99ff2012-08-08 14:35:55 -0700444 configure_module_pin_mux(spi0_pin_mux);
Tom Rini6bfca502012-08-08 10:32:09 -0700445 }
Tom Rinidb7dd812012-07-31 10:50:01 -0700446 } else if (!strncmp(header->name, "A335X_SK", HDR_NAME_LEN)) {
447 /* Starter Kit EVM */
Tom Rini036fd652012-08-08 09:03:07 -0700448 configure_module_pin_mux(i2c1_pin_mux);
Tom Rinidb7dd812012-07-31 10:50:01 -0700449 configure_module_pin_mux(gpio0_7_pin_mux);
450 configure_module_pin_mux(rgmii1_pin_mux);
451 configure_module_pin_mux(mmc0_pin_mux_sk_evm);
452 } else {
453 puts("Unknown board, cannot configure pinmux.");
454 hang();
455 }
Tom Rini65d750b2012-07-31 08:55:01 -0700456}