Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-ep93xx/simone.c |
| 3 | * Simplemachines Sim.One support. |
| 4 | * |
Ryan Mallon | 1c5454e | 2011-06-15 14:45:36 +1000 | [diff] [blame] | 5 | * Copyright (C) 2010 Ryan Mallon |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 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> |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 21 | #include <linux/i2c.h> |
| 22 | #include <linux/i2c-gpio.h> |
Mika Westerberg | d50bfa4 | 2015-06-08 15:22:39 +0200 | [diff] [blame] | 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> |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 29 | |
| 30 | #include <mach/hardware.h> |
Linus Walleij | bd5f12a | 2011-09-22 08:07:00 +0100 | [diff] [blame] | 31 | #include <mach/gpio-ep93xx.h> |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 32 | |
| 33 | #include <asm/mach-types.h> |
| 34 | #include <asm/mach/arch.h> |
| 35 | |
Ryan Mallon | 258249e | 2012-01-11 09:06:08 +1100 | [diff] [blame] | 36 | #include "soc.h" |
| 37 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 38 | static struct ep93xx_eth_data __initdata simone_eth_data = { |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 39 | .phy_id = 1, |
| 40 | }; |
| 41 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 42 | static struct ep93xxfb_mach_info __initdata simone_fb_info = { |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 43 | .flags = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING, |
| 44 | }; |
| 45 | |
Mika Westerberg | d50bfa4 | 2015-06-08 15:22:39 +0200 | [diff] [blame] | 46 | /* |
| 47 | * GPIO lines used for MMC card detection. |
| 48 | */ |
| 49 | #define MMC_CARD_DETECT_GPIO EP93XX_GPIO_LINE_EGPIO0 |
| 50 | |
| 51 | /* |
| 52 | * Up to v1.3, the Sim.One used SFRMOUT as SD card chip select, but this goes |
| 53 | * low between multi-message command blocks. From v1.4, it uses a GPIO instead. |
| 54 | * v1.3 parts will still work, since the signal on SFRMOUT is automatic. |
| 55 | */ |
| 56 | #define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO1 |
| 57 | |
| 58 | /* |
| 59 | * MMC SPI chip select GPIO handling. If you are using SFRMOUT (SFRM1) signal, |
| 60 | * you can leave these empty and pass NULL as .controller_data. |
| 61 | */ |
| 62 | |
| 63 | static int simone_mmc_spi_setup(struct spi_device *spi) |
| 64 | { |
| 65 | unsigned int gpio = MMC_CHIP_SELECT_GPIO; |
| 66 | int err; |
| 67 | |
| 68 | err = gpio_request(gpio, spi->modalias); |
| 69 | if (err) |
| 70 | return err; |
| 71 | |
| 72 | err = gpio_direction_output(gpio, 1); |
| 73 | if (err) { |
| 74 | gpio_free(gpio); |
| 75 | return err; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static void simone_mmc_spi_cleanup(struct spi_device *spi) |
| 82 | { |
| 83 | unsigned int gpio = MMC_CHIP_SELECT_GPIO; |
| 84 | |
| 85 | gpio_set_value(gpio, 1); |
| 86 | gpio_direction_input(gpio); |
| 87 | gpio_free(gpio); |
| 88 | } |
| 89 | |
| 90 | static void simone_mmc_spi_cs_control(struct spi_device *spi, int value) |
| 91 | { |
| 92 | gpio_set_value(MMC_CHIP_SELECT_GPIO, value); |
| 93 | } |
| 94 | |
| 95 | static struct ep93xx_spi_chip_ops simone_mmc_spi_ops = { |
| 96 | .setup = simone_mmc_spi_setup, |
| 97 | .cleanup = simone_mmc_spi_cleanup, |
| 98 | .cs_control = simone_mmc_spi_cs_control, |
| 99 | }; |
| 100 | |
| 101 | /* |
| 102 | * MMC card detection GPIO setup. |
| 103 | */ |
| 104 | |
| 105 | static int simone_mmc_spi_init(struct device *dev, |
| 106 | irqreturn_t (*irq_handler)(int, void *), void *mmc) |
| 107 | { |
| 108 | unsigned int gpio = MMC_CARD_DETECT_GPIO; |
| 109 | int irq, err; |
| 110 | |
| 111 | err = gpio_request(gpio, dev_name(dev)); |
| 112 | if (err) |
| 113 | return err; |
| 114 | |
| 115 | err = gpio_direction_input(gpio); |
| 116 | if (err) |
| 117 | goto fail; |
| 118 | |
| 119 | irq = gpio_to_irq(gpio); |
| 120 | if (irq < 0) |
| 121 | goto fail; |
| 122 | |
| 123 | err = request_irq(irq, irq_handler, IRQF_TRIGGER_FALLING, |
| 124 | "MMC card detect", mmc); |
| 125 | if (err) |
| 126 | goto fail; |
| 127 | |
| 128 | printk(KERN_INFO "%s: using irq %d for MMC card detection\n", |
| 129 | dev_name(dev), irq); |
| 130 | |
| 131 | return 0; |
| 132 | fail: |
| 133 | gpio_free(gpio); |
| 134 | return err; |
| 135 | } |
| 136 | |
| 137 | static void simone_mmc_spi_exit(struct device *dev, void *mmc) |
| 138 | { |
| 139 | unsigned int gpio = MMC_CARD_DETECT_GPIO; |
| 140 | |
| 141 | free_irq(gpio_to_irq(gpio), mmc); |
| 142 | gpio_free(gpio); |
| 143 | } |
| 144 | |
| 145 | static struct mmc_spi_platform_data simone_mmc_spi_data = { |
| 146 | .init = simone_mmc_spi_init, |
| 147 | .exit = simone_mmc_spi_exit, |
| 148 | .detect_delay = 500, |
| 149 | .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, |
| 150 | }; |
| 151 | |
| 152 | static struct spi_board_info simone_spi_devices[] __initdata = { |
| 153 | { |
| 154 | .modalias = "mmc_spi", |
| 155 | .controller_data = &simone_mmc_spi_ops, |
| 156 | .platform_data = &simone_mmc_spi_data, |
| 157 | /* |
| 158 | * We use 10 MHz even though the maximum is 3.7 MHz. The driver |
| 159 | * will limit it automatically to max. frequency. |
| 160 | */ |
| 161 | .max_speed_hz = 10 * 1000 * 1000, |
| 162 | .bus_num = 0, |
| 163 | .chip_select = 0, |
| 164 | .mode = SPI_MODE_3, |
| 165 | }, |
| 166 | }; |
| 167 | |
| 168 | static struct ep93xx_spi_info simone_spi_info __initdata = { |
| 169 | .num_chipselect = ARRAY_SIZE(simone_spi_devices), |
Linus Walleij | 109965a | 2015-07-09 16:56:40 +0200 | [diff] [blame] | 170 | .use_dma = 1, |
Mika Westerberg | d50bfa4 | 2015-06-08 15:22:39 +0200 | [diff] [blame] | 171 | }; |
| 172 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 173 | static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = { |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 174 | .sda_pin = EP93XX_GPIO_LINE_EEDAT, |
| 175 | .sda_is_open_drain = 0, |
| 176 | .scl_pin = EP93XX_GPIO_LINE_EECLK, |
| 177 | .scl_is_open_drain = 0, |
| 178 | .udelay = 0, |
| 179 | .timeout = 0, |
| 180 | }; |
| 181 | |
| 182 | static struct i2c_board_info __initdata simone_i2c_board_info[] = { |
| 183 | { |
| 184 | I2C_BOARD_INFO("ds1337", 0x68), |
| 185 | }, |
| 186 | }; |
| 187 | |
Mika Westerberg | e5063fe | 2011-09-11 12:28:53 +0300 | [diff] [blame] | 188 | static struct platform_device simone_audio_device = { |
| 189 | .name = "simone-audio", |
| 190 | .id = -1, |
| 191 | }; |
| 192 | |
| 193 | static void __init simone_register_audio(void) |
| 194 | { |
| 195 | ep93xx_register_ac97(); |
| 196 | platform_device_register(&simone_audio_device); |
| 197 | } |
| 198 | |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 199 | static void __init simone_init_machine(void) |
| 200 | { |
| 201 | ep93xx_init_devices(); |
Hartley Sweeten | 16bcf78 | 2010-06-10 16:19:08 +0100 | [diff] [blame] | 202 | ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M); |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 203 | ep93xx_register_eth(&simone_eth_data, 1); |
| 204 | ep93xx_register_fb(&simone_fb_info); |
| 205 | ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, |
| 206 | ARRAY_SIZE(simone_i2c_board_info)); |
Mika Westerberg | d50bfa4 | 2015-06-08 15:22:39 +0200 | [diff] [blame] | 207 | ep93xx_register_spi(&simone_spi_info, simone_spi_devices, |
| 208 | ARRAY_SIZE(simone_spi_devices)); |
Mika Westerberg | e5063fe | 2011-09-11 12:28:53 +0300 | [diff] [blame] | 209 | simone_register_audio(); |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | MACHINE_START(SIM_ONE, "Simplemachines Sim.One Board") |
Nicolas Pitre | e562cf1 | 2011-07-05 22:38:11 -0400 | [diff] [blame] | 213 | /* Maintainer: Ryan Mallon */ |
| 214 | .atag_offset = 0x100, |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 215 | .map_io = ep93xx_map_io, |
| 216 | .init_irq = ep93xx_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 217 | .init_time = ep93xx_timer_init, |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 218 | .init_machine = simone_init_machine, |
Shawn Guo | c914283 | 2012-04-26 10:05:15 +0800 | [diff] [blame] | 219 | .init_late = ep93xx_init_late, |
Russell King | 3275166 | 2011-11-05 09:54:14 +0000 | [diff] [blame] | 220 | .restart = ep93xx_restart, |
Ryan Mallon | a3662f6 | 2010-01-22 01:42:02 +0100 | [diff] [blame] | 221 | MACHINE_END |