On Thu, May 26, 2011 at 10:46:02PM +0200, Petr Štetiar wrote:
>
> Nowhere :-) As I understand it, it's just generic ep93xx SPI framework. You
> need to explicitly tell the driver what SPI device and chip select/gpio pin
> it's using and register it in the board file ts72xx.c manually.
>
Yup. For example I'm using SPI to communicate with EEPROM (and occasionally
with SD-card) and the sample board configuration is below. Hope it helps.
diff --git a/arch/arm/mach-ep93xx/ts72xx.c b/arch/arm/mach-ep93xx/ts72xx.c
index c2d2cf4..1b3f441 100644
--- a/arch/arm/mach-ep93xx/ts72xx.c
+++ b/arch/arm/mach-ep93xx/ts72xx.c
@@ -16,12 +16,18 @@
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/io.h>
+#include <linux/gpio.h>
#include <linux/m48t86.h>
+#include <linux/mmc/host.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/eeprom.h>
+#include <linux/spi/mmc_spi.h>
#include <mach/hardware.h>
#include <mach/ts72xx.h>
+#include <mach/ep93xx_spi.h>
#include <asm/mach-types.h>
#include <asm/mach/map.h>
@@ -45,6 +51,11 @@ static struct map_desc ts72xx_io_desc[] __initdata = {
.length = TS72XX_OPTIONS2_SIZE,
.type = MT_DEVICE,
}, {
+ .virtual = TS72XX_COM2_MODE_VIRT_BASE,
+ .pfn = __phys_to_pfn(TS72XX_COM2_MODE_PHYS_BASE),
+ .length = TS72XX_COM2_MODE_SIZE,
+ .type = MT_DEVICE,
+ }, {
.virtual = TS72XX_RTC_INDEX_VIRT_BASE,
.pfn = __phys_to_pfn(TS72XX_RTC_INDEX_PHYS_BASE),
.length = TS72XX_RTC_INDEX_SIZE,
@@ -245,6 +256,106 @@ static struct ep93xx_eth_data __initdata ts72xx_eth_data
= {
.phy_id = 1,
};
+#if defined(CONFIG_EEPROM_AT25) && !defined(CONFIG_MMC_SPI)
+#define USE_SPI_EEPROM
+#define SPI_CHIPSELECT EP93XX_GPIO_LINE_EGPIO8
+#else
+#define SPI_CHIPSELECT EP93XX_GPIO_LINE_EGPIO9
+#endif
+
+static int ts72xx_spi_setup(struct spi_device *spi)
+{
+ int gpio = SPI_CHIPSELECT;
+ int err;
+
+ err = gpio_request(gpio, spi->modalias);
+ if (err)
+ return err;
+
+ gpio_direction_output(gpio, 1);
+ return 0;
+}
+
+static void ts72xx_spi_cleanup(struct spi_device *spi)
+{
+ int gpio = SPI_CHIPSELECT;
+
+ gpio_set_value(gpio, 1);
+ gpio_direction_input(gpio);
+ gpio_free(gpio);
+}
+
+static void ts72xx_spi_cs_control(struct spi_device *spi, int value)
+{
+ gpio_set_value(SPI_CHIPSELECT, value);
+}
+
+static struct ep93xx_spi_chip_ops ts72xx_spi_ops = {
+ .setup = ts72xx_spi_setup,
+ .cleanup = ts72xx_spi_cleanup,
+ .cs_control = ts72xx_spi_cs_control,
+};
+
+#ifdef USE_SPI_EEPROM
+static const struct spi_eeprom at25080a = {
+ .byte_len = SZ_1K,
+ .name = "at25080a",
+ .page_size = 32,
+ .flags = EE_ADDR2,
+};
+
+static struct spi_board_info ts72xx_spi_devices[] __initdata = {
+ {
+ .modalias = "at25",
+ .controller_data = &ts72xx_spi_ops,
+ .platform_data = &at25080a,
+ .max_speed_hz = 10 * 1000 * 1000,
+ .bus_num = 0,
+ .chip_select = 0,
+ .mode = SPI_MODE_0,
+ },
+};
+#else /* !USE_SPI_EEPROM */
+static struct mmc_spi_platform_data ts72xx_mmc_spi_data = {
+ .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
+};
+
+static struct spi_board_info ts72xx_spi_devices[] __initdata = {
+ {
+ .modalias = "mmc_spi",
+ .controller_data = &ts72xx_spi_ops,
+ .platform_data = &ts72xx_mmc_spi_data,
+ /*
+ * We use 10 MHz even though the maximum is 7.4 MHz. The driver
+ * will limit it automatically to max. frequency.
+ */
+ .max_speed_hz = 10 * 1000 * 1000,
+ .bus_num = 0,
+ .chip_select = 0,
+ .mode = SPI_MODE_3,
+ },
+};
+#endif /* USE_SPI_EEPROM */
+
+static struct ep93xx_spi_info ts72xx_spi_info = {
+ .num_chipselect = ARRAY_SIZE(ts72xx_spi_devices),
+ .use_dma = true,
+};
+
+static void __init ts72xx_register_spi(void)
+{
+ /*
+ * Just to be sure: we always deselect the boot SPI EEPROM
+ * chipselect before starting to register any SPI devices.
+ * Otherwise we might accidentaly overwrite the boot EEPROM
+ * contents.
+ */
+ __raw_writel(0, TS72XX_COM2_MODE_VIRT_BASE);
+
+ ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices,
+ ARRAY_SIZE(ts72xx_spi_devices));
+}
+
static void __init ts72xx_init_machine(void)
{
ep93xx_init_devices();
@@ -253,6 +364,7 @@ static void __init ts72xx_init_machine(void)
platform_device_register(&ts72xx_wdt_device);
ep93xx_register_eth(&ts72xx_eth_data, 1);
+ ts72xx_register_spi();
}
MACHINE_START(TS72XX, "Technologic Systems TS-72xx SBC")
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|