ARM: OMAP4: hsmmc: check for null pointer
[deliverable/linux.git] / arch / arm / mach-omap2 / board-omap4panda.c
1 /*
2 * Board support file for OMAP4430 based PandaBoard.
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * Author: David Anders <x0132446@ti.com>
7 *
8 * Based on mach-omap2/board-4430sdp.c
9 *
10 * Author: Santosh Shilimkar <santosh.shilimkar@ti.com>
11 *
12 * Based on mach-omap2/board-3430sdp.c
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/clk.h>
23 #include <linux/io.h>
24 #include <linux/leds.h>
25 #include <linux/gpio.h>
26 #include <linux/usb/otg.h>
27 #include <linux/i2c/twl.h>
28 #include <linux/mfd/twl6040.h>
29 #include <linux/regulator/machine.h>
30 #include <linux/regulator/fixed.h>
31 #include <linux/wl12xx.h>
32 #include <linux/platform_data/omap-abe-twl6040.h>
33
34 #include <mach/hardware.h>
35 #include <asm/hardware/gic.h>
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/map.h>
39 #include <video/omapdss.h>
40
41 #include <plat/board.h>
42 #include "common.h"
43 #include <plat/usb.h>
44 #include <plat/mmc.h>
45 #include <video/omap-panel-dvi.h>
46
47 #include "hsmmc.h"
48 #include "control.h"
49 #include "mux.h"
50 #include "common-board-devices.h"
51
52 #define GPIO_HUB_POWER 1
53 #define GPIO_HUB_NRESET 62
54 #define GPIO_WIFI_PMENA 43
55 #define GPIO_WIFI_IRQ 53
56 #define HDMI_GPIO_CT_CP_HPD 60 /* HPD mode enable/disable */
57 #define HDMI_GPIO_LS_OE 41 /* Level shifter for HDMI */
58 #define HDMI_GPIO_HPD 63 /* Hotplug detect */
59
60 /* wl127x BT, FM, GPS connectivity chip */
61 static int wl1271_gpios[] = {46, -1, -1};
62 static struct platform_device wl1271_device = {
63 .name = "kim",
64 .id = -1,
65 .dev = {
66 .platform_data = &wl1271_gpios,
67 },
68 };
69
70 static struct gpio_led gpio_leds[] = {
71 {
72 .name = "pandaboard::status1",
73 .default_trigger = "heartbeat",
74 .gpio = 7,
75 },
76 {
77 .name = "pandaboard::status2",
78 .default_trigger = "mmc0",
79 .gpio = 8,
80 },
81 };
82
83 static struct gpio_led_platform_data gpio_led_info = {
84 .leds = gpio_leds,
85 .num_leds = ARRAY_SIZE(gpio_leds),
86 };
87
88 static struct platform_device leds_gpio = {
89 .name = "leds-gpio",
90 .id = -1,
91 .dev = {
92 .platform_data = &gpio_led_info,
93 },
94 };
95
96 static struct omap_abe_twl6040_data panda_abe_audio_data = {
97 /* Audio out */
98 .has_hs = ABE_TWL6040_LEFT | ABE_TWL6040_RIGHT,
99 /* HandsFree through expasion connector */
100 .has_hf = ABE_TWL6040_LEFT | ABE_TWL6040_RIGHT,
101 /* PandaBoard: FM TX, PandaBoardES: can be connected to audio out */
102 .has_aux = ABE_TWL6040_LEFT | ABE_TWL6040_RIGHT,
103 /* PandaBoard: FM RX, PandaBoardES: audio in */
104 .has_afm = ABE_TWL6040_LEFT | ABE_TWL6040_RIGHT,
105 /* No jack detection. */
106 .jack_detection = 0,
107 /* MCLK input is 38.4MHz */
108 .mclk_freq = 38400000,
109
110 };
111
112 static struct platform_device panda_abe_audio = {
113 .name = "omap-abe-twl6040",
114 .id = -1,
115 .dev = {
116 .platform_data = &panda_abe_audio_data,
117 },
118 };
119
120 static struct platform_device btwilink_device = {
121 .name = "btwilink",
122 .id = -1,
123 };
124
125 static struct platform_device *panda_devices[] __initdata = {
126 &leds_gpio,
127 &wl1271_device,
128 &panda_abe_audio,
129 &btwilink_device,
130 };
131
132 static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
133 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
134 .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
135 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
136 .phy_reset = false,
137 .reset_gpio_port[0] = -EINVAL,
138 .reset_gpio_port[1] = -EINVAL,
139 .reset_gpio_port[2] = -EINVAL
140 };
141
142 static struct gpio panda_ehci_gpios[] __initdata = {
143 { GPIO_HUB_POWER, GPIOF_OUT_INIT_LOW, "hub_power" },
144 { GPIO_HUB_NRESET, GPIOF_OUT_INIT_LOW, "hub_nreset" },
145 };
146
147 static void __init omap4_ehci_init(void)
148 {
149 int ret;
150 struct clk *phy_ref_clk;
151
152 /* FREF_CLK3 provides the 19.2 MHz reference clock to the PHY */
153 phy_ref_clk = clk_get(NULL, "auxclk3_ck");
154 if (IS_ERR(phy_ref_clk)) {
155 pr_err("Cannot request auxclk3\n");
156 return;
157 }
158 clk_set_rate(phy_ref_clk, 19200000);
159 clk_enable(phy_ref_clk);
160
161 /* disable the power to the usb hub prior to init and reset phy+hub */
162 ret = gpio_request_array(panda_ehci_gpios,
163 ARRAY_SIZE(panda_ehci_gpios));
164 if (ret) {
165 pr_err("Unable to initialize EHCI power/reset\n");
166 return;
167 }
168
169 gpio_export(GPIO_HUB_POWER, 0);
170 gpio_export(GPIO_HUB_NRESET, 0);
171 gpio_set_value(GPIO_HUB_NRESET, 1);
172
173 usbhs_init(&usbhs_bdata);
174
175 /* enable power to hub */
176 gpio_set_value(GPIO_HUB_POWER, 1);
177 }
178
179 static struct omap_musb_board_data musb_board_data = {
180 .interface_type = MUSB_INTERFACE_UTMI,
181 .mode = MUSB_OTG,
182 .power = 100,
183 };
184
185 static struct omap2_hsmmc_info mmc[] = {
186 {
187 .mmc = 1,
188 .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
189 .gpio_wp = -EINVAL,
190 .gpio_cd = -EINVAL,
191 },
192 {
193 .name = "wl1271",
194 .mmc = 5,
195 .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_POWER_OFF_CARD,
196 .gpio_wp = -EINVAL,
197 .gpio_cd = -EINVAL,
198 .ocr_mask = MMC_VDD_165_195,
199 .nonremovable = true,
200 },
201 {} /* Terminator */
202 };
203
204 static struct regulator_consumer_supply omap4_panda_vmmc5_supply[] = {
205 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.4"),
206 };
207
208 static struct regulator_init_data panda_vmmc5 = {
209 .constraints = {
210 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
211 },
212 .num_consumer_supplies = ARRAY_SIZE(omap4_panda_vmmc5_supply),
213 .consumer_supplies = omap4_panda_vmmc5_supply,
214 };
215
216 static struct fixed_voltage_config panda_vwlan = {
217 .supply_name = "vwl1271",
218 .microvolts = 1800000, /* 1.8V */
219 .gpio = GPIO_WIFI_PMENA,
220 .startup_delay = 70000, /* 70msec */
221 .enable_high = 1,
222 .enabled_at_boot = 0,
223 .init_data = &panda_vmmc5,
224 };
225
226 static struct platform_device omap_vwlan_device = {
227 .name = "reg-fixed-voltage",
228 .id = 1,
229 .dev = {
230 .platform_data = &panda_vwlan,
231 },
232 };
233
234 struct wl12xx_platform_data omap_panda_wlan_data __initdata = {
235 /* PANDA ref clock is 38.4 MHz */
236 .board_ref_clock = 2,
237 };
238
239 static struct twl6040_codec_data twl6040_codec = {
240 /* single-step ramp for headset and handsfree */
241 .hs_left_step = 0x0f,
242 .hs_right_step = 0x0f,
243 .hf_left_step = 0x1d,
244 .hf_right_step = 0x1d,
245 };
246
247 static struct twl6040_platform_data twl6040_data = {
248 .codec = &twl6040_codec,
249 .audpwron_gpio = 127,
250 .irq_base = TWL6040_CODEC_IRQ_BASE,
251 };
252
253 /* Panda board uses the common PMIC configuration */
254 static struct twl4030_platform_data omap4_panda_twldata;
255
256 /*
257 * Display monitor features are burnt in their EEPROM as EDID data. The EEPROM
258 * is connected as I2C slave device, and can be accessed at address 0x50
259 */
260 static struct i2c_board_info __initdata panda_i2c_eeprom[] = {
261 {
262 I2C_BOARD_INFO("eeprom", 0x50),
263 },
264 };
265
266 static int __init omap4_panda_i2c_init(void)
267 {
268 omap4_pmic_get_config(&omap4_panda_twldata, TWL_COMMON_PDATA_USB,
269 TWL_COMMON_REGULATOR_VDAC |
270 TWL_COMMON_REGULATOR_VAUX2 |
271 TWL_COMMON_REGULATOR_VAUX3 |
272 TWL_COMMON_REGULATOR_VMMC |
273 TWL_COMMON_REGULATOR_VPP |
274 TWL_COMMON_REGULATOR_VANA |
275 TWL_COMMON_REGULATOR_VCXIO |
276 TWL_COMMON_REGULATOR_VUSB |
277 TWL_COMMON_REGULATOR_CLK32KG);
278 omap4_pmic_init("twl6030", &omap4_panda_twldata,
279 &twl6040_data, OMAP44XX_IRQ_SYS_2N);
280 omap_register_i2c_bus(2, 400, NULL, 0);
281 /*
282 * Bus 3 is attached to the DVI port where devices like the pico DLP
283 * projector don't work reliably with 400kHz
284 */
285 omap_register_i2c_bus(3, 100, panda_i2c_eeprom,
286 ARRAY_SIZE(panda_i2c_eeprom));
287 omap_register_i2c_bus(4, 400, NULL, 0);
288 return 0;
289 }
290
291 #ifdef CONFIG_OMAP_MUX
292 static struct omap_board_mux board_mux[] __initdata = {
293 /* WLAN IRQ - GPIO 53 */
294 OMAP4_MUX(GPMC_NCS3, OMAP_MUX_MODE3 | OMAP_PIN_INPUT),
295 /* WLAN POWER ENABLE - GPIO 43 */
296 OMAP4_MUX(GPMC_A19, OMAP_MUX_MODE3 | OMAP_PIN_OUTPUT),
297 /* WLAN SDIO: MMC5 CMD */
298 OMAP4_MUX(SDMMC5_CMD, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP),
299 /* WLAN SDIO: MMC5 CLK */
300 OMAP4_MUX(SDMMC5_CLK, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP),
301 /* WLAN SDIO: MMC5 DAT[0-3] */
302 OMAP4_MUX(SDMMC5_DAT0, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP),
303 OMAP4_MUX(SDMMC5_DAT1, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP),
304 OMAP4_MUX(SDMMC5_DAT2, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP),
305 OMAP4_MUX(SDMMC5_DAT3, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP),
306 /* gpio 0 - TFP410 PD */
307 OMAP4_MUX(KPD_COL1, OMAP_PIN_OUTPUT | OMAP_MUX_MODE3),
308 /* dispc2_data23 */
309 OMAP4_MUX(USBB2_ULPITLL_STP, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
310 /* dispc2_data22 */
311 OMAP4_MUX(USBB2_ULPITLL_DIR, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
312 /* dispc2_data21 */
313 OMAP4_MUX(USBB2_ULPITLL_NXT, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
314 /* dispc2_data20 */
315 OMAP4_MUX(USBB2_ULPITLL_DAT0, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
316 /* dispc2_data19 */
317 OMAP4_MUX(USBB2_ULPITLL_DAT1, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
318 /* dispc2_data18 */
319 OMAP4_MUX(USBB2_ULPITLL_DAT2, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
320 /* dispc2_data15 */
321 OMAP4_MUX(USBB2_ULPITLL_DAT3, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
322 /* dispc2_data14 */
323 OMAP4_MUX(USBB2_ULPITLL_DAT4, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
324 /* dispc2_data13 */
325 OMAP4_MUX(USBB2_ULPITLL_DAT5, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
326 /* dispc2_data12 */
327 OMAP4_MUX(USBB2_ULPITLL_DAT6, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
328 /* dispc2_data11 */
329 OMAP4_MUX(USBB2_ULPITLL_DAT7, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
330 /* dispc2_data10 */
331 OMAP4_MUX(DPM_EMU3, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
332 /* dispc2_data9 */
333 OMAP4_MUX(DPM_EMU4, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
334 /* dispc2_data16 */
335 OMAP4_MUX(DPM_EMU5, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
336 /* dispc2_data17 */
337 OMAP4_MUX(DPM_EMU6, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
338 /* dispc2_hsync */
339 OMAP4_MUX(DPM_EMU7, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
340 /* dispc2_pclk */
341 OMAP4_MUX(DPM_EMU8, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
342 /* dispc2_vsync */
343 OMAP4_MUX(DPM_EMU9, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
344 /* dispc2_de */
345 OMAP4_MUX(DPM_EMU10, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
346 /* dispc2_data8 */
347 OMAP4_MUX(DPM_EMU11, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
348 /* dispc2_data7 */
349 OMAP4_MUX(DPM_EMU12, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
350 /* dispc2_data6 */
351 OMAP4_MUX(DPM_EMU13, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
352 /* dispc2_data5 */
353 OMAP4_MUX(DPM_EMU14, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
354 /* dispc2_data4 */
355 OMAP4_MUX(DPM_EMU15, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
356 /* dispc2_data3 */
357 OMAP4_MUX(DPM_EMU16, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
358 /* dispc2_data2 */
359 OMAP4_MUX(DPM_EMU17, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
360 /* dispc2_data1 */
361 OMAP4_MUX(DPM_EMU18, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
362 /* dispc2_data0 */
363 OMAP4_MUX(DPM_EMU19, OMAP_PIN_OUTPUT | OMAP_MUX_MODE5),
364 { .reg_offset = OMAP_MUX_TERMINATOR },
365 };
366
367 #else
368 #define board_mux NULL
369 #endif
370
371 /* Display DVI */
372 #define PANDA_DVI_TFP410_POWER_DOWN_GPIO 0
373
374 static int omap4_panda_enable_dvi(struct omap_dss_device *dssdev)
375 {
376 gpio_set_value(dssdev->reset_gpio, 1);
377 return 0;
378 }
379
380 static void omap4_panda_disable_dvi(struct omap_dss_device *dssdev)
381 {
382 gpio_set_value(dssdev->reset_gpio, 0);
383 }
384
385 /* Using generic display panel */
386 static struct panel_dvi_platform_data omap4_dvi_panel = {
387 .platform_enable = omap4_panda_enable_dvi,
388 .platform_disable = omap4_panda_disable_dvi,
389 .i2c_bus_num = 3,
390 };
391
392 struct omap_dss_device omap4_panda_dvi_device = {
393 .type = OMAP_DISPLAY_TYPE_DPI,
394 .name = "dvi",
395 .driver_name = "dvi",
396 .data = &omap4_dvi_panel,
397 .phy.dpi.data_lines = 24,
398 .reset_gpio = PANDA_DVI_TFP410_POWER_DOWN_GPIO,
399 .channel = OMAP_DSS_CHANNEL_LCD2,
400 };
401
402 int __init omap4_panda_dvi_init(void)
403 {
404 int r;
405
406 /* Requesting TFP410 DVI GPIO and disabling it, at bootup */
407 r = gpio_request_one(omap4_panda_dvi_device.reset_gpio,
408 GPIOF_OUT_INIT_LOW, "DVI PD");
409 if (r)
410 pr_err("Failed to get DVI powerdown GPIO\n");
411
412 return r;
413 }
414
415 static struct gpio panda_hdmi_gpios[] = {
416 { HDMI_GPIO_CT_CP_HPD, GPIOF_OUT_INIT_HIGH, "hdmi_gpio_ct_cp_hpd" },
417 { HDMI_GPIO_LS_OE, GPIOF_OUT_INIT_HIGH, "hdmi_gpio_ls_oe" },
418 { HDMI_GPIO_HPD, GPIOF_DIR_IN, "hdmi_gpio_hpd" },
419 };
420
421 static int omap4_panda_panel_enable_hdmi(struct omap_dss_device *dssdev)
422 {
423 int status;
424
425 status = gpio_request_array(panda_hdmi_gpios,
426 ARRAY_SIZE(panda_hdmi_gpios));
427 if (status)
428 pr_err("Cannot request HDMI GPIOs\n");
429
430 return status;
431 }
432
433 static void omap4_panda_panel_disable_hdmi(struct omap_dss_device *dssdev)
434 {
435 gpio_free_array(panda_hdmi_gpios, ARRAY_SIZE(panda_hdmi_gpios));
436 }
437
438 static struct omap_dss_hdmi_data omap4_panda_hdmi_data = {
439 .hpd_gpio = HDMI_GPIO_HPD,
440 };
441
442 static struct omap_dss_device omap4_panda_hdmi_device = {
443 .name = "hdmi",
444 .driver_name = "hdmi_panel",
445 .type = OMAP_DISPLAY_TYPE_HDMI,
446 .platform_enable = omap4_panda_panel_enable_hdmi,
447 .platform_disable = omap4_panda_panel_disable_hdmi,
448 .channel = OMAP_DSS_CHANNEL_DIGIT,
449 .data = &omap4_panda_hdmi_data,
450 };
451
452 static struct omap_dss_device *omap4_panda_dss_devices[] = {
453 &omap4_panda_dvi_device,
454 &omap4_panda_hdmi_device,
455 };
456
457 static struct omap_dss_board_info omap4_panda_dss_data = {
458 .num_devices = ARRAY_SIZE(omap4_panda_dss_devices),
459 .devices = omap4_panda_dss_devices,
460 .default_device = &omap4_panda_dvi_device,
461 };
462
463 void __init omap4_panda_display_init(void)
464 {
465 int r;
466
467 r = omap4_panda_dvi_init();
468 if (r)
469 pr_err("error initializing panda DVI\n");
470
471 omap_display_init(&omap4_panda_dss_data);
472
473 /*
474 * OMAP4460SDP/Blaze and OMAP4430 ES2.3 SDP/Blaze boards and
475 * later have external pull up on the HDMI I2C lines
476 */
477 if (cpu_is_omap446x() || omap_rev() > OMAP4430_REV_ES2_2)
478 omap_hdmi_init(OMAP_HDMI_SDA_SCL_EXTERNAL_PULLUP);
479 else
480 omap_hdmi_init(0);
481
482 omap_mux_init_gpio(HDMI_GPIO_LS_OE, OMAP_PIN_OUTPUT);
483 omap_mux_init_gpio(HDMI_GPIO_CT_CP_HPD, OMAP_PIN_OUTPUT);
484 omap_mux_init_gpio(HDMI_GPIO_HPD, OMAP_PIN_INPUT_PULLDOWN);
485 }
486
487 static void omap4_panda_init_rev(void)
488 {
489 if (cpu_is_omap443x()) {
490 /* PandaBoard 4430 */
491 /* ASoC audio configuration */
492 panda_abe_audio_data.card_name = "PandaBoard";
493 panda_abe_audio_data.has_hsmic = 1;
494 } else {
495 /* PandaBoard ES */
496 /* ASoC audio configuration */
497 panda_abe_audio_data.card_name = "PandaBoardES";
498 }
499 }
500
501 static void __init omap4_panda_init(void)
502 {
503 int package = OMAP_PACKAGE_CBS;
504 int ret;
505
506 if (omap_rev() == OMAP4430_REV_ES1_0)
507 package = OMAP_PACKAGE_CBL;
508 omap4_mux_init(board_mux, NULL, package);
509
510 omap_panda_wlan_data.irq = gpio_to_irq(GPIO_WIFI_IRQ);
511 ret = wl12xx_set_platform_data(&omap_panda_wlan_data);
512 if (ret)
513 pr_err("error setting wl12xx data: %d\n", ret);
514
515 omap4_panda_init_rev();
516 omap4_panda_i2c_init();
517 platform_add_devices(panda_devices, ARRAY_SIZE(panda_devices));
518 platform_device_register(&omap_vwlan_device);
519 omap_serial_init();
520 omap_sdrc_init(NULL, NULL);
521 omap4_twl6030_hsmmc_init(mmc);
522 omap4_ehci_init();
523 usb_musb_init(&musb_board_data);
524 omap4_panda_display_init();
525 }
526
527 MACHINE_START(OMAP4_PANDA, "OMAP4 Panda board")
528 /* Maintainer: David Anders - Texas Instruments Inc */
529 .atag_offset = 0x100,
530 .reserve = omap_reserve,
531 .map_io = omap4_map_io,
532 .init_early = omap4430_init_early,
533 .init_irq = gic_init_irq,
534 .handle_irq = gic_handle_irq,
535 .init_machine = omap4_panda_init,
536 .timer = &omap4_timer,
537 .restart = omap_prcm_restart,
538 MACHINE_END
This page took 0.051477 seconds and 5 git commands to generate.