targets: prepare for supporting normal and initramfs images
[openwrt.git] / target / linux / ep93xx / patches-3.8 / 004-simone_add_mmc_spi.patch
1 This enables the mmc-over-spi driver for the Sim.One board, based on Mika's
2 patch, which used a GPIO for chip select in stead of the default SFRMOUT pin.
3 I've modified it to use the usual SFRMOUT; if you've modified your Sim.One
4 board to use a GPIO instead, uncomment and modify
5 // #define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO15
6 in the source file.
7    -martinwguy, 14 May 2010
8
9 From: Mika Westerberg <mika.westerberg@iki.fi>
10 Date: Wed, 28 Apr 2010 08:42:46 +0300
11 Subject: [PATCH] ep93xx: simone: added board specific SPI support for MMC/SD cards
12
13 This includes setting up EGPIOs 0 and 9 for card detection and chip select
14 respectively.
15
16 --- a/arch/arm/mach-ep93xx/simone.c
17 +++ b/arch/arm/mach-ep93xx/simone.c
18 @@ -20,10 +20,15 @@
19  #include <linux/platform_device.h>
20  #include <linux/i2c.h>
21  #include <linux/i2c-gpio.h>
22 +#include <linux/gpio.h>
23 +#include <linux/mmc/host.h>
24 +#include <linux/spi/spi.h>
25 +#include <linux/spi/mmc_spi.h>
26  
27  #include <mach/hardware.h>
28  #include <linux/platform_data/video-ep93xx.h>
29  #include <mach/gpio-ep93xx.h>
30 +#include <linux/platform_data/spi-ep93xx.h>
31  
32  #include <asm/hardware/vic.h>
33  #include <asm/mach-types.h>
34 @@ -41,6 +46,135 @@ static struct ep93xxfb_mach_info __initd
35         .flags          = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING,
36  };
37  
38 +/*
39 + * GPIO lines used for MMC card detection.
40 + */
41 +#define MMC_CARD_DETECT_GPIO EP93XX_GPIO_LINE_EGPIO0
42 +
43 +/*
44 + * If you have hacked your Sim.One to use a GPIO as SD card chip select
45 + * (SD pin 1), uncomment the following line.
46 + * The example, EGPIO15, is on TP17 near the CPU.
47 + */
48 +// #define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO15
49 +
50 +/*
51 + * MMC SPI chip select GPIO handling. If you are using SFRMOUT (SFRM1) signal,
52 + * you can leave these empty and pass NULL as .controller_data.
53 + */
54 +
55 +#ifdef MMC_CHIP_SELECT_GPIO
56 +static int simone_mmc_spi_setup(struct spi_device *spi)
57 +{
58 +       unsigned int gpio = MMC_CHIP_SELECT_GPIO;
59 +       int err;
60 +
61 +       err = gpio_request(gpio, spi->modalias);
62 +       if (err)
63 +               return err;
64 +
65 +       err = gpio_direction_output(gpio, 1);
66 +       if (err) {
67 +               gpio_free(gpio);
68 +               return err;
69 +       }
70 +
71 +       return 0;
72 +}
73 +
74 +static void simone_mmc_spi_cleanup(struct spi_device *spi)
75 +{
76 +       unsigned int gpio = MMC_CHIP_SELECT_GPIO;
77 +
78 +       gpio_set_value(gpio, 1);
79 +       gpio_direction_input(gpio);
80 +       gpio_free(gpio);
81 +}
82 +
83 +static void simone_mmc_spi_cs_control(struct spi_device *spi, int value)
84 +{
85 +       gpio_set_value(MMC_CHIP_SELECT_GPIO, value);
86 +}
87 +
88 +static struct ep93xx_spi_chip_ops simone_mmc_spi_ops = {
89 +       .setup          = simone_mmc_spi_setup,
90 +       .cleanup        = simone_mmc_spi_cleanup,
91 +       .cs_control     = simone_mmc_spi_cs_control,
92 +};
93 +#endif
94 +
95 +/*
96 + * MMC card detection GPIO setup.
97 + */
98 +static int simone_mmc_spi_init(struct device *dev,
99 +       irqreturn_t (*irq_handler)(int, void *), void *mmc)
100 +{
101 +       unsigned int gpio = MMC_CARD_DETECT_GPIO;
102 +       int irq, err;
103 +
104 +       err = gpio_request(gpio, dev_name(dev));
105 +       if (err)
106 +               return err;
107 +
108 +       err = gpio_direction_input(gpio);
109 +       if (err)
110 +               goto fail;
111 +
112 +       irq = gpio_to_irq(gpio);
113 +       if (irq < 0)
114 +               goto fail;
115 +
116 +       err = request_irq(irq, irq_handler, IRQF_TRIGGER_FALLING,
117 +                               "MMC card detect", mmc);
118 +       if (err)
119 +               goto fail;
120 +
121 +       printk(KERN_INFO "%s: using irq %d for MMC card detection\n",
122 +               dev_name(dev), irq);
123 +
124 +       return 0;
125 +fail:
126 +       gpio_free(gpio);
127 +       return err;
128 +}
129 +
130 +static void simone_mmc_spi_exit(struct device *dev, void *mmc)
131 +{
132 +       unsigned int gpio = MMC_CARD_DETECT_GPIO;
133 +
134 +       free_irq(gpio_to_irq(gpio), mmc);
135 +       gpio_free(gpio);
136 +}
137 +
138 +static struct mmc_spi_platform_data simone_mmc_spi_data = {
139 +       .init           = simone_mmc_spi_init,
140 +       .exit           = simone_mmc_spi_exit,
141 +       .detect_delay   = 500,
142 +       .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
143 +};
144 +
145 +static struct spi_board_info simone_spi_devices[] __initdata = {
146 +       {
147 +               .modalias               = "mmc_spi",
148 +#ifdef MMC_CHIP_SELECT_GPIO
149 +               .controller_data        = &simone_mmc_spi_ops,
150 +#endif
151 +               .platform_data          = &simone_mmc_spi_data,
152 +               /*
153 +                * We use 10 MHz even though the maximum is 3.7 MHz. The driver
154 +                * will limit it automatically to max. frequency.
155 +                */
156 +               .max_speed_hz           = 10 * 1000 * 1000,
157 +               .bus_num                = 0,
158 +               .chip_select            = 0,
159 +               .mode                   = SPI_MODE_3,
160 +       },
161 +};
162 +
163 +static struct ep93xx_spi_info simone_spi_info __initdata = {
164 +       .num_chipselect = ARRAY_SIZE(simone_spi_devices),
165 +};
166 +
167  static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
168         .sda_pin                = EP93XX_GPIO_LINE_EEDAT,
169         .sda_is_open_drain      = 0,
170 @@ -75,6 +209,8 @@ static void __init simone_init_machine(v
171         ep93xx_register_fb(&simone_fb_info);
172         ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
173                             ARRAY_SIZE(simone_i2c_board_info));
174 +       ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
175 +                           ARRAY_SIZE(simone_spi_devices));
176         simone_register_audio();
177  }
178