1 /*
2  *  LogicPD i.MX31 SOM-LV development board support
3  *
4  *    Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
5  *
6  *  based on code for other MX31 boards,
7  *
8  *    Copyright 2005-2007 Freescale Semiconductor
9  *    Copyright (c) 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
10  *    Copyright (C) 2009 Valentin Longchamp, EPFL Mobots group
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  */
22 
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/init.h>
26 #include <linux/gpio.h>
27 #include <linux/leds.h>
28 #include <linux/platform_device.h>
29 
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 
34 #include "board-mx31lite.h"
35 #include "common.h"
36 #include "devices-imx31.h"
37 #include "hardware.h"
38 #include "iomux-mx3.h"
39 
40 /*
41  * This file contains board-specific initialization routines for the
42  * LogicPD i.MX31 SOM-LV development board, aka 'LiteKit'.
43  * If you design an own baseboard for the module, use this file as base
44  * for support code.
45  */
46 
47 static unsigned int litekit_db_board_pins[] __initdata = {
48 	/* SDHC1 */
49 	MX31_PIN_SD1_DATA0__SD1_DATA0,
50 	MX31_PIN_SD1_DATA1__SD1_DATA1,
51 	MX31_PIN_SD1_DATA2__SD1_DATA2,
52 	MX31_PIN_SD1_DATA3__SD1_DATA3,
53 	MX31_PIN_SD1_CLK__SD1_CLK,
54 	MX31_PIN_SD1_CMD__SD1_CMD,
55 };
56 
57 /* MMC */
58 
59 static int gpio_det, gpio_wp;
60 
61 #define MMC_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
62 		     PAD_CTL_ODE_CMOS)
63 
mxc_mmc1_get_ro(struct device * dev)64 static int mxc_mmc1_get_ro(struct device *dev)
65 {
66 	return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_GPIO1_6));
67 }
68 
mxc_mmc1_init(struct device * dev,irq_handler_t detect_irq,void * data)69 static int mxc_mmc1_init(struct device *dev,
70 			 irq_handler_t detect_irq, void *data)
71 {
72 	int ret;
73 
74 	gpio_det = IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1);
75 	gpio_wp = IOMUX_TO_GPIO(MX31_PIN_GPIO1_6);
76 
77 	mxc_iomux_set_pad(MX31_PIN_SD1_DATA0,
78 			  MMC_PAD_CFG | PAD_CTL_PUE_PUD | PAD_CTL_100K_PU);
79 	mxc_iomux_set_pad(MX31_PIN_SD1_DATA1,
80 			  MMC_PAD_CFG | PAD_CTL_PUE_PUD | PAD_CTL_100K_PU);
81 	mxc_iomux_set_pad(MX31_PIN_SD1_DATA2,
82 			  MMC_PAD_CFG | PAD_CTL_PUE_PUD | PAD_CTL_100K_PU);
83 	mxc_iomux_set_pad(MX31_PIN_SD1_DATA3,
84 			  MMC_PAD_CFG | PAD_CTL_PUE_PUD | PAD_CTL_100K_PU);
85 	mxc_iomux_set_pad(MX31_PIN_SD1_CMD,
86 			  MMC_PAD_CFG | PAD_CTL_PUE_PUD | PAD_CTL_100K_PU);
87 	mxc_iomux_set_pad(MX31_PIN_SD1_CLK, MMC_PAD_CFG);
88 
89 	ret = gpio_request(gpio_det, "MMC detect");
90 	if (ret)
91 		return ret;
92 
93 	ret = gpio_request(gpio_wp, "MMC w/p");
94 	if (ret)
95 		goto exit_free_det;
96 
97 	gpio_direction_input(gpio_det);
98 	gpio_direction_input(gpio_wp);
99 
100 	ret = request_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1)),
101 			  detect_irq,
102 			  IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
103 			  "MMC detect", data);
104 	if (ret)
105 		goto exit_free_wp;
106 
107 	return 0;
108 
109 exit_free_wp:
110 	gpio_free(gpio_wp);
111 
112 exit_free_det:
113 	gpio_free(gpio_det);
114 
115 	return ret;
116 }
117 
mxc_mmc1_exit(struct device * dev,void * data)118 static void mxc_mmc1_exit(struct device *dev, void *data)
119 {
120 	gpio_free(gpio_det);
121 	gpio_free(gpio_wp);
122 	free_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1)), data);
123 }
124 
125 static const struct imxmmc_platform_data mmc_pdata __initconst = {
126 	.get_ro	 = mxc_mmc1_get_ro,
127 	.init	   = mxc_mmc1_init,
128 	.exit	   = mxc_mmc1_exit,
129 };
130 
131 /* GPIO LEDs */
132 
133 static const struct gpio_led litekit_leds[] __initconst = {
134 	{
135 		.name           = "GPIO0",
136 		.gpio           = IOMUX_TO_GPIO(MX31_PIN_COMPARE),
137 		.active_low     = 1,
138 		.default_state  = LEDS_GPIO_DEFSTATE_OFF,
139 	},
140 	{
141 		.name           = "GPIO1",
142 		.gpio           = IOMUX_TO_GPIO(MX31_PIN_CAPTURE),
143 		.active_low     = 1,
144 		.default_state  = LEDS_GPIO_DEFSTATE_OFF,
145 	}
146 };
147 
148 static const struct gpio_led_platform_data
149 		litekit_led_platform_data __initconst = {
150 	.leds           = litekit_leds,
151 	.num_leds       = ARRAY_SIZE(litekit_leds),
152 };
153 
mx31lite_db_init(void)154 void __init mx31lite_db_init(void)
155 {
156 	mxc_iomux_setup_multiple_pins(litekit_db_board_pins,
157 					ARRAY_SIZE(litekit_db_board_pins),
158 					"development board pins");
159 	imx31_add_mxc_mmc(0, &mmc_pdata);
160 	gpio_led_register_device(-1, &litekit_led_platform_data);
161 	imx31_add_imx2_wdt();
162 	imx31_add_mxc_rtc();
163 }
164