1 /* linux/arch/arm/mach-s5pv310/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/clk.h>
15 #include <mach/irqs.h>
18 #include <mach/gpio.h>
19 #include <mach/spi-clocks.h>
20 #include <mach/regs-clock.h>
22 #include <plat/s3c64xx-spi.h>
23 #include <plat/gpio-cfg.h>
24 #include <plat/irqs.h>
26 static char *spi_src_clks[] = {
27 [S5PV310_SPI_SRCCLK_SCLK] = "sclk_spi",
30 /* SPI Controller platform_devices */
32 /* Since we emulate multi-cs capability, we do not touch the CS.
33 * The emulated CS is toggled by board specific mechanism, as it can
34 * be either some immediate GPIO or some signal out of some other
35 * chip in between ... or some yet another way.
36 * We simply do not assume anything about CS.
38 static int s5pv310_spi_cfg_gpio(struct platform_device *pdev)
42 s3c_gpio_cfgpin(S5PV310_GPB(0), S3C_GPIO_SFN(2));
43 s3c_gpio_cfgpin(S5PV310_GPB(2), S3C_GPIO_SFN(2));
44 s3c_gpio_cfgpin(S5PV310_GPB(3), S3C_GPIO_SFN(2));
45 s3c_gpio_setpull(S5PV310_GPB(0), S3C_GPIO_PULL_UP);
46 s3c_gpio_setpull(S5PV310_GPB(2), S3C_GPIO_PULL_UP);
47 s3c_gpio_setpull(S5PV310_GPB(3), S3C_GPIO_PULL_UP);
51 s3c_gpio_cfgpin(S5PV310_GPB(4), S3C_GPIO_SFN(2));
52 s3c_gpio_cfgpin(S5PV310_GPB(6), S3C_GPIO_SFN(2));
53 s3c_gpio_cfgpin(S5PV310_GPB(7), S3C_GPIO_SFN(2));
54 s3c_gpio_setpull(S5PV310_GPB(4), S3C_GPIO_PULL_UP);
55 s3c_gpio_setpull(S5PV310_GPB(6), S3C_GPIO_PULL_UP);
56 s3c_gpio_setpull(S5PV310_GPB(7), S3C_GPIO_PULL_UP);
60 s3c_gpio_cfgpin(S5PV310_GPC1(1), S3C_GPIO_SFN(5));
61 s3c_gpio_cfgpin(S5PV310_GPC1(3), S3C_GPIO_SFN(5));
62 s3c_gpio_cfgpin(S5PV310_GPC1(4), S3C_GPIO_SFN(5));
63 s3c_gpio_setpull(S5PV310_GPC1(1), S3C_GPIO_PULL_UP);
64 s3c_gpio_setpull(S5PV310_GPC1(3), S3C_GPIO_PULL_UP);
65 s3c_gpio_setpull(S5PV310_GPC1(4), S3C_GPIO_PULL_UP);
69 dev_err(&pdev->dev, "Invalid SPI Controller number!");
76 static struct resource s5pv310_spi0_resource[] = {
78 .start = S5PV310_PA_SPI0,
79 .end = S5PV310_PA_SPI0 + 0x100 - 1,
80 .flags = IORESOURCE_MEM,
83 .start = DMACH_SPI0_TX,
85 .flags = IORESOURCE_DMA,
88 .start = DMACH_SPI0_RX,
90 .flags = IORESOURCE_DMA,
95 .flags = IORESOURCE_IRQ,
99 static struct s3c64xx_spi_info s5pv310_spi0_pdata = {
100 .cfg_gpio = s5pv310_spi_cfg_gpio,
101 .fifo_lvl_mask = 0x1ff,
104 .clk_from_cmu = true,
107 static u64 spi_dmamask = DMA_BIT_MASK(32);
109 struct platform_device s5pv310_device_spi0 = {
110 .name = "s3c64xx-spi",
112 .num_resources = ARRAY_SIZE(s5pv310_spi0_resource),
113 .resource = s5pv310_spi0_resource,
115 .dma_mask = &spi_dmamask,
116 .coherent_dma_mask = DMA_BIT_MASK(32),
117 .platform_data = &s5pv310_spi0_pdata,
121 static struct resource s5pv310_spi1_resource[] = {
123 .start = S5PV310_PA_SPI1,
124 .end = S5PV310_PA_SPI1 + 0x100 - 1,
125 .flags = IORESOURCE_MEM,
128 .start = DMACH_SPI1_TX,
129 .end = DMACH_SPI1_TX,
130 .flags = IORESOURCE_DMA,
133 .start = DMACH_SPI1_RX,
134 .end = DMACH_SPI1_RX,
135 .flags = IORESOURCE_DMA,
140 .flags = IORESOURCE_IRQ,
144 static struct s3c64xx_spi_info s5pv310_spi1_pdata = {
145 .cfg_gpio = s5pv310_spi_cfg_gpio,
146 .fifo_lvl_mask = 0x7f,
149 .clk_from_cmu = true,
152 struct platform_device s5pv310_device_spi1 = {
153 .name = "s3c64xx-spi",
155 .num_resources = ARRAY_SIZE(s5pv310_spi1_resource),
156 .resource = s5pv310_spi1_resource,
158 .dma_mask = &spi_dmamask,
159 .coherent_dma_mask = DMA_BIT_MASK(32),
160 .platform_data = &s5pv310_spi1_pdata,
164 static struct resource s5pv310_spi2_resource[] = {
166 .start = S5PV310_PA_SPI2,
167 .end = S5PV310_PA_SPI2 + 0x100 - 1,
168 .flags = IORESOURCE_MEM,
171 .start = DMACH_SPI2_TX,
172 .end = DMACH_SPI2_TX,
173 .flags = IORESOURCE_DMA,
176 .start = DMACH_SPI2_RX,
177 .end = DMACH_SPI2_RX,
178 .flags = IORESOURCE_DMA,
183 .flags = IORESOURCE_IRQ,
187 static struct s3c64xx_spi_info s5pv310_spi2_pdata = {
188 .cfg_gpio = s5pv310_spi_cfg_gpio,
189 .fifo_lvl_mask = 0x7f,
192 .clk_from_cmu = true,
195 struct platform_device s5pv310_device_spi2 = {
196 .name = "s3c64xx-spi",
198 .num_resources = ARRAY_SIZE(s5pv310_spi2_resource),
199 .resource = s5pv310_spi2_resource,
201 .dma_mask = &spi_dmamask,
202 .coherent_dma_mask = DMA_BIT_MASK(32),
203 .platform_data = &s5pv310_spi2_pdata,
207 void __init s5pv310_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
209 struct s3c64xx_spi_info *pd;
211 /* Reject invalid configuration */
212 if (!num_cs || src_clk_nr < 0
213 || src_clk_nr > S5PV310_SPI_SRCCLK_SCLK) {
214 printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
220 pd = &s5pv310_spi0_pdata;
223 pd = &s5pv310_spi1_pdata;
226 pd = &s5pv310_spi2_pdata;
229 printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
235 pd->src_clk_nr = src_clk_nr;
236 pd->src_clk_name = spi_src_clks[src_clk_nr];