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_cfgpin_range(S5PC100_GPB(0), 3, S3C_GPIO_SFN(2));
42 s3c_gpio_setpull(S5PC100_GPB(0), S3C_GPIO_PULL_UP);
43 s3c_gpio_setpull(S5PC100_GPB(1), S3C_GPIO_PULL_UP);
44 s3c_gpio_setpull(S5PC100_GPB(2), S3C_GPIO_PULL_UP);
48 s3c_gpio_cfgpin_range(S5PC100_GPB(4), 3, S3C_GPIO_SFN(2));
49 s3c_gpio_setpull(S5PC100_GPB(4), S3C_GPIO_PULL_UP);
50 s3c_gpio_setpull(S5PC100_GPB(5), S3C_GPIO_PULL_UP);
51 s3c_gpio_setpull(S5PC100_GPB(6), S3C_GPIO_PULL_UP);
55 s3c_gpio_cfgpin(S5PC100_GPG3(0), S3C_GPIO_SFN(3));
56 s3c_gpio_cfgpin_range(S5PC100_GPB(2), 2, S3C_GPIO_SFN(3));
57 s3c_gpio_setpull(S5PC100_GPG3(0), S3C_GPIO_PULL_UP);
58 s3c_gpio_setpull(S5PC100_GPG3(2), S3C_GPIO_PULL_UP);
59 s3c_gpio_setpull(S5PC100_GPG3(3), S3C_GPIO_PULL_UP);
63 dev_err(&pdev->dev, "Invalid SPI Controller number!");
70 static struct resource s5pc100_spi0_resource[] = {
72 .start = S5PC100_PA_SPI0,
73 .end = S5PC100_PA_SPI0 + 0x100 - 1,
74 .flags = IORESOURCE_MEM,
77 .start = DMACH_SPI0_TX,
79 .flags = IORESOURCE_DMA,
82 .start = DMACH_SPI0_RX,
84 .flags = IORESOURCE_DMA,
89 .flags = IORESOURCE_IRQ,
93 static struct s3c64xx_spi_info s5pc100_spi0_pdata = {
94 .cfg_gpio = s5pc100_spi_cfg_gpio,
95 .fifo_lvl_mask = 0x7f,
100 static u64 spi_dmamask = DMA_BIT_MASK(32);
102 struct platform_device s5pc100_device_spi0 = {
103 .name = "s3c64xx-spi",
105 .num_resources = ARRAY_SIZE(s5pc100_spi0_resource),
106 .resource = s5pc100_spi0_resource,
108 .dma_mask = &spi_dmamask,
109 .coherent_dma_mask = DMA_BIT_MASK(32),
110 .platform_data = &s5pc100_spi0_pdata,
114 static struct resource s5pc100_spi1_resource[] = {
116 .start = S5PC100_PA_SPI1,
117 .end = S5PC100_PA_SPI1 + 0x100 - 1,
118 .flags = IORESOURCE_MEM,
121 .start = DMACH_SPI1_TX,
122 .end = DMACH_SPI1_TX,
123 .flags = IORESOURCE_DMA,
126 .start = DMACH_SPI1_RX,
127 .end = DMACH_SPI1_RX,
128 .flags = IORESOURCE_DMA,
133 .flags = IORESOURCE_IRQ,
137 static struct s3c64xx_spi_info s5pc100_spi1_pdata = {
138 .cfg_gpio = s5pc100_spi_cfg_gpio,
139 .fifo_lvl_mask = 0x7f,
144 struct platform_device s5pc100_device_spi1 = {
145 .name = "s3c64xx-spi",
147 .num_resources = ARRAY_SIZE(s5pc100_spi1_resource),
148 .resource = s5pc100_spi1_resource,
150 .dma_mask = &spi_dmamask,
151 .coherent_dma_mask = DMA_BIT_MASK(32),
152 .platform_data = &s5pc100_spi1_pdata,
156 static struct resource s5pc100_spi2_resource[] = {
158 .start = S5PC100_PA_SPI2,
159 .end = S5PC100_PA_SPI2 + 0x100 - 1,
160 .flags = IORESOURCE_MEM,
163 .start = DMACH_SPI2_TX,
164 .end = DMACH_SPI2_TX,
165 .flags = IORESOURCE_DMA,
168 .start = DMACH_SPI2_RX,
169 .end = DMACH_SPI2_RX,
170 .flags = IORESOURCE_DMA,
175 .flags = IORESOURCE_IRQ,
179 static struct s3c64xx_spi_info s5pc100_spi2_pdata = {
180 .cfg_gpio = s5pc100_spi_cfg_gpio,
181 .fifo_lvl_mask = 0x7f,
186 struct platform_device s5pc100_device_spi2 = {
187 .name = "s3c64xx-spi",
189 .num_resources = ARRAY_SIZE(s5pc100_spi2_resource),
190 .resource = s5pc100_spi2_resource,
192 .dma_mask = &spi_dmamask,
193 .coherent_dma_mask = DMA_BIT_MASK(32),
194 .platform_data = &s5pc100_spi2_pdata,
198 void __init s5pc100_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
200 struct s3c64xx_spi_info *pd;
202 /* Reject invalid configuration */
203 if (!num_cs || src_clk_nr < 0
204 || src_clk_nr > S5PC100_SPI_SRCCLK_SPIBUS) {
205 printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
211 pd = &s5pc100_spi0_pdata;
214 pd = &s5pc100_spi1_pdata;
217 pd = &s5pc100_spi2_pdata;
220 printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
226 pd->src_clk_nr = src_clk_nr;
227 pd->src_clk_name = spi_src_clks[src_clk_nr];