]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arm/mach-ep93xx/simone.c
ARM: ep93xx: simone: enable DMA on the SPI host
[karo-tx-linux.git] / arch / arm / mach-ep93xx / simone.c
1 /*
2  * arch/arm/mach-ep93xx/simone.c
3  * Simplemachines Sim.One support.
4  *
5  * Copyright (C) 2010 Ryan Mallon
6  *
7  * Based on the 2.6.24.7 support:
8  *   Copyright (C) 2009 Simplemachines
9  *   MMC support by Peter Ivanov <ivanovp@gmail.com>, 2007
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or (at
14  * your option) any later version.
15  *
16  */
17
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/i2c.h>
22 #include <linux/i2c-gpio.h>
23 #include <linux/mmc/host.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/mmc_spi.h>
26 #include <linux/platform_data/video-ep93xx.h>
27 #include <linux/platform_data/spi-ep93xx.h>
28 #include <linux/gpio.h>
29
30 #include <mach/hardware.h>
31 #include <mach/gpio-ep93xx.h>
32
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35
36 #include "soc.h"
37
38 static struct ep93xx_eth_data __initdata simone_eth_data = {
39         .phy_id         = 1,
40 };
41
42 static struct ep93xxfb_mach_info __initdata simone_fb_info = {
43         .num_modes      = EP93XXFB_USE_MODEDB,
44         .bpp            = 16,
45         .flags          = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING,
46 };
47
48 /*
49  * GPIO lines used for MMC card detection.
50  */
51 #define MMC_CARD_DETECT_GPIO EP93XX_GPIO_LINE_EGPIO0
52
53 /*
54  * Up to v1.3, the Sim.One used SFRMOUT as SD card chip select, but this goes
55  * low between multi-message command blocks. From v1.4, it uses a GPIO instead.
56  * v1.3 parts will still work, since the signal on SFRMOUT is automatic.
57  */
58 #define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO1
59
60 /*
61  * MMC SPI chip select GPIO handling. If you are using SFRMOUT (SFRM1) signal,
62  * you can leave these empty and pass NULL as .controller_data.
63  */
64
65 static int simone_mmc_spi_setup(struct spi_device *spi)
66 {
67         unsigned int gpio = MMC_CHIP_SELECT_GPIO;
68         int err;
69
70         err = gpio_request(gpio, spi->modalias);
71         if (err)
72                 return err;
73
74         err = gpio_direction_output(gpio, 1);
75         if (err) {
76                 gpio_free(gpio);
77                 return err;
78         }
79
80         return 0;
81 }
82
83 static void simone_mmc_spi_cleanup(struct spi_device *spi)
84 {
85         unsigned int gpio = MMC_CHIP_SELECT_GPIO;
86
87         gpio_set_value(gpio, 1);
88         gpio_direction_input(gpio);
89         gpio_free(gpio);
90 }
91
92 static void simone_mmc_spi_cs_control(struct spi_device *spi, int value)
93 {
94         gpio_set_value(MMC_CHIP_SELECT_GPIO, value);
95 }
96
97 static struct ep93xx_spi_chip_ops simone_mmc_spi_ops = {
98         .setup          = simone_mmc_spi_setup,
99         .cleanup        = simone_mmc_spi_cleanup,
100         .cs_control     = simone_mmc_spi_cs_control,
101 };
102
103 /*
104  * MMC card detection GPIO setup.
105  */
106
107 static int simone_mmc_spi_init(struct device *dev,
108         irqreturn_t (*irq_handler)(int, void *), void *mmc)
109 {
110         unsigned int gpio = MMC_CARD_DETECT_GPIO;
111         int irq, err;
112
113         err = gpio_request(gpio, dev_name(dev));
114         if (err)
115                 return err;
116
117         err = gpio_direction_input(gpio);
118         if (err)
119                 goto fail;
120
121         irq = gpio_to_irq(gpio);
122         if (irq < 0)
123                 goto fail;
124
125         err = request_irq(irq, irq_handler, IRQF_TRIGGER_FALLING,
126                           "MMC card detect", mmc);
127         if (err)
128                 goto fail;
129
130         printk(KERN_INFO "%s: using irq %d for MMC card detection\n",
131                dev_name(dev), irq);
132
133         return 0;
134 fail:
135         gpio_free(gpio);
136         return err;
137 }
138
139 static void simone_mmc_spi_exit(struct device *dev, void *mmc)
140 {
141         unsigned int gpio = MMC_CARD_DETECT_GPIO;
142
143         free_irq(gpio_to_irq(gpio), mmc);
144         gpio_free(gpio);
145 }
146
147 static struct mmc_spi_platform_data simone_mmc_spi_data = {
148         .init           = simone_mmc_spi_init,
149         .exit           = simone_mmc_spi_exit,
150         .detect_delay   = 500,
151         .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
152 };
153
154 static struct spi_board_info simone_spi_devices[] __initdata = {
155         {
156                 .modalias               = "mmc_spi",
157                 .controller_data        = &simone_mmc_spi_ops,
158                 .platform_data          = &simone_mmc_spi_data,
159                 /*
160                  * We use 10 MHz even though the maximum is 3.7 MHz. The driver
161                  * will limit it automatically to max. frequency.
162                  */
163                 .max_speed_hz           = 10 * 1000 * 1000,
164                 .bus_num                = 0,
165                 .chip_select            = 0,
166                 .mode                   = SPI_MODE_3,
167         },
168 };
169
170 static struct ep93xx_spi_info simone_spi_info __initdata = {
171         .num_chipselect = ARRAY_SIZE(simone_spi_devices),
172         .use_dma = 1,
173 };
174
175 static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
176         .sda_pin                = EP93XX_GPIO_LINE_EEDAT,
177         .sda_is_open_drain      = 0,
178         .scl_pin                = EP93XX_GPIO_LINE_EECLK,
179         .scl_is_open_drain      = 0,
180         .udelay                 = 0,
181         .timeout                = 0,
182 };
183
184 static struct i2c_board_info __initdata simone_i2c_board_info[] = {
185         {
186                 I2C_BOARD_INFO("ds1337", 0x68),
187         },
188 };
189
190 static struct platform_device simone_audio_device = {
191         .name           = "simone-audio",
192         .id             = -1,
193 };
194
195 static void __init simone_register_audio(void)
196 {
197         ep93xx_register_ac97();
198         platform_device_register(&simone_audio_device);
199 }
200
201 static void __init simone_init_machine(void)
202 {
203         ep93xx_init_devices();
204         ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M);
205         ep93xx_register_eth(&simone_eth_data, 1);
206         ep93xx_register_fb(&simone_fb_info);
207         ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
208                             ARRAY_SIZE(simone_i2c_board_info));
209         ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
210                             ARRAY_SIZE(simone_spi_devices));
211         simone_register_audio();
212 }
213
214 MACHINE_START(SIM_ONE, "Simplemachines Sim.One Board")
215         /* Maintainer: Ryan Mallon */
216         .atag_offset    = 0x100,
217         .map_io         = ep93xx_map_io,
218         .init_irq       = ep93xx_init_irq,
219         .init_time      = ep93xx_timer_init,
220         .init_machine   = simone_init_machine,
221         .init_late      = ep93xx_init_late,
222         .restart        = ep93xx_restart,
223 MACHINE_END