1 /* linux/arch/arm/mach-s5pc100/dev-spi.c
3 * Copyright (C) 2010 Samsung Electronics Co. Ltd.
4 * Jaswinder Singh <jassi.brar@samsung.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/platform_device.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/gpio.h>
17 #include <mach/spi-clocks.h>
19 #include <plat/s3c64xx-spi.h>
20 #include <plat/gpio-cfg.h>
21 #include <plat/irqs.h>
23 static char *spi_src_clks[] = {
24 [S5PC100_SPI_SRCCLK_PCLK] = "pclk",
25 [S5PC100_SPI_SRCCLK_48M] = "spi_48m",
26 [S5PC100_SPI_SRCCLK_SPIBUS] = "spi_bus",
29 /* SPI Controller platform_devices */
31 /* Since we emulate multi-cs capability, we do not touch the CS.
32 * The emulated CS is toggled by board specific mechanism, as it can
33 * be either some immediate GPIO or some signal out of some other
34 * chip in between ... or some yet another way.
35 * We simply do not assume anything about CS.
37 static int s5pc100_spi_cfg_gpio(struct platform_device *pdev)
41 s3c_gpio_cfgall_range(S5PC100_GPB(0), 3,
42 S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
46 s3c_gpio_cfgall_range(S5PC100_GPB(4), 3,
47 S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
51 s3c_gpio_cfgpin(S5PC100_GPG3(0), S3C_GPIO_SFN(3));
52 s3c_gpio_setpull(S5PC100_GPG3(0), S3C_GPIO_PULL_UP);
53 s3c_gpio_cfgall_range(S5PC100_GPB(2), 2,
54 S3C_GPIO_SFN(3), S3C_GPIO_PULL_UP);
58 dev_err(&pdev->dev, "Invalid SPI Controller number!");
65 static struct resource s5pc100_spi0_resource[] = {
67 .start = S5PC100_PA_SPI0,
68 .end = S5PC100_PA_SPI0 + 0x100 - 1,
69 .flags = IORESOURCE_MEM,
72 .start = DMACH_SPI0_TX,
74 .flags = IORESOURCE_DMA,
77 .start = DMACH_SPI0_RX,
79 .flags = IORESOURCE_DMA,
84 .flags = IORESOURCE_IRQ,
88 static struct s3c64xx_spi_info s5pc100_spi0_pdata = {
89 .cfg_gpio = s5pc100_spi_cfg_gpio,
90 .fifo_lvl_mask = 0x7f,
96 static u64 spi_dmamask = DMA_BIT_MASK(32);
98 struct platform_device s5pc100_device_spi0 = {
99 .name = "s3c64xx-spi",
101 .num_resources = ARRAY_SIZE(s5pc100_spi0_resource),
102 .resource = s5pc100_spi0_resource,
104 .dma_mask = &spi_dmamask,
105 .coherent_dma_mask = DMA_BIT_MASK(32),
106 .platform_data = &s5pc100_spi0_pdata,
110 static struct resource s5pc100_spi1_resource[] = {
112 .start = S5PC100_PA_SPI1,
113 .end = S5PC100_PA_SPI1 + 0x100 - 1,
114 .flags = IORESOURCE_MEM,
117 .start = DMACH_SPI1_TX,
118 .end = DMACH_SPI1_TX,
119 .flags = IORESOURCE_DMA,
122 .start = DMACH_SPI1_RX,
123 .end = DMACH_SPI1_RX,
124 .flags = IORESOURCE_DMA,
129 .flags = IORESOURCE_IRQ,
133 static struct s3c64xx_spi_info s5pc100_spi1_pdata = {
134 .cfg_gpio = s5pc100_spi_cfg_gpio,
135 .fifo_lvl_mask = 0x7f,
141 struct platform_device s5pc100_device_spi1 = {
142 .name = "s3c64xx-spi",
144 .num_resources = ARRAY_SIZE(s5pc100_spi1_resource),
145 .resource = s5pc100_spi1_resource,
147 .dma_mask = &spi_dmamask,
148 .coherent_dma_mask = DMA_BIT_MASK(32),
149 .platform_data = &s5pc100_spi1_pdata,
153 static struct resource s5pc100_spi2_resource[] = {
155 .start = S5PC100_PA_SPI2,
156 .end = S5PC100_PA_SPI2 + 0x100 - 1,
157 .flags = IORESOURCE_MEM,
160 .start = DMACH_SPI2_TX,
161 .end = DMACH_SPI2_TX,
162 .flags = IORESOURCE_DMA,
165 .start = DMACH_SPI2_RX,
166 .end = DMACH_SPI2_RX,
167 .flags = IORESOURCE_DMA,
172 .flags = IORESOURCE_IRQ,
176 static struct s3c64xx_spi_info s5pc100_spi2_pdata = {
177 .cfg_gpio = s5pc100_spi_cfg_gpio,
178 .fifo_lvl_mask = 0x7f,
184 struct platform_device s5pc100_device_spi2 = {
185 .name = "s3c64xx-spi",
187 .num_resources = ARRAY_SIZE(s5pc100_spi2_resource),
188 .resource = s5pc100_spi2_resource,
190 .dma_mask = &spi_dmamask,
191 .coherent_dma_mask = DMA_BIT_MASK(32),
192 .platform_data = &s5pc100_spi2_pdata,
196 void __init s5pc100_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
198 struct s3c64xx_spi_info *pd;
200 /* Reject invalid configuration */
201 if (!num_cs || src_clk_nr < 0
202 || src_clk_nr > S5PC100_SPI_SRCCLK_SPIBUS) {
203 printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
209 pd = &s5pc100_spi0_pdata;
212 pd = &s5pc100_spi1_pdata;
215 pd = &s5pc100_spi2_pdata;
218 printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
224 pd->src_clk_nr = src_clk_nr;
225 pd->src_clk_name = spi_src_clks[src_clk_nr];