1 /* linux/arch/arm/mach-s5p64x0/dev-spi.c
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Copyright (C) 2010 Samsung Electronics Co. Ltd.
7 * Jaswinder Singh <jassi.brar@samsung.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/platform_device.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/gpio.h>
20 #include <mach/irqs.h>
21 #include <mach/regs-clock.h>
22 #include <mach/spi-clocks.h>
25 #include <plat/s3c64xx-spi.h>
26 #include <plat/gpio-cfg.h>
28 static char *s5p64x0_spi_src_clks
[] = {
29 [S5P64X0_SPI_SRCCLK_PCLK
] = "pclk",
30 [S5P64X0_SPI_SRCCLK_SCLK
] = "sclk_spi",
33 /* SPI Controller platform_devices */
35 /* Since we emulate multi-cs capability, we do not touch the CS.
36 * The emulated CS is toggled by board specific mechanism, as it can
37 * be either some immediate GPIO or some signal out of some other
38 * chip in between ... or some yet another way.
39 * We simply do not assume anything about CS.
41 static int s5p6440_spi_cfg_gpio(struct platform_device
*pdev
)
47 base
= S5P6440_GPC(0);
51 base
= S5P6440_GPC(4);
55 dev_err(&pdev
->dev
, "Invalid SPI Controller number!");
59 s3c_gpio_cfgall_range(base
, 3,
60 S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP
);
65 static int s5p6450_spi_cfg_gpio(struct platform_device
*pdev
)
71 base
= S5P6450_GPC(0);
75 base
= S5P6450_GPC(4);
79 dev_err(&pdev
->dev
, "Invalid SPI Controller number!");
83 s3c_gpio_cfgall_range(base
, 3,
84 S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP
);
89 static struct resource s5p64x0_spi0_resource
[] = {
91 .start
= S5P64X0_PA_SPI0
,
92 .end
= S5P64X0_PA_SPI0
+ 0x100 - 1,
93 .flags
= IORESOURCE_MEM
,
96 .start
= DMACH_SPI0_TX
,
98 .flags
= IORESOURCE_DMA
,
101 .start
= DMACH_SPI0_RX
,
102 .end
= DMACH_SPI0_RX
,
103 .flags
= IORESOURCE_DMA
,
108 .flags
= IORESOURCE_IRQ
,
112 static struct s3c64xx_spi_info s5p6440_spi0_pdata
= {
113 .cfg_gpio
= s5p6440_spi_cfg_gpio
,
114 .fifo_lvl_mask
= 0x1ff,
119 static struct s3c64xx_spi_info s5p6450_spi0_pdata
= {
120 .cfg_gpio
= s5p6450_spi_cfg_gpio
,
121 .fifo_lvl_mask
= 0x1ff,
126 static u64 spi_dmamask
= DMA_BIT_MASK(32);
128 struct platform_device s5p64x0_device_spi0
= {
129 .name
= "s3c64xx-spi",
131 .num_resources
= ARRAY_SIZE(s5p64x0_spi0_resource
),
132 .resource
= s5p64x0_spi0_resource
,
134 .dma_mask
= &spi_dmamask
,
135 .coherent_dma_mask
= DMA_BIT_MASK(32),
139 static struct resource s5p64x0_spi1_resource
[] = {
141 .start
= S5P64X0_PA_SPI1
,
142 .end
= S5P64X0_PA_SPI1
+ 0x100 - 1,
143 .flags
= IORESOURCE_MEM
,
146 .start
= DMACH_SPI1_TX
,
147 .end
= DMACH_SPI1_TX
,
148 .flags
= IORESOURCE_DMA
,
151 .start
= DMACH_SPI1_RX
,
152 .end
= DMACH_SPI1_RX
,
153 .flags
= IORESOURCE_DMA
,
158 .flags
= IORESOURCE_IRQ
,
162 static struct s3c64xx_spi_info s5p6440_spi1_pdata
= {
163 .cfg_gpio
= s5p6440_spi_cfg_gpio
,
164 .fifo_lvl_mask
= 0x7f,
169 static struct s3c64xx_spi_info s5p6450_spi1_pdata
= {
170 .cfg_gpio
= s5p6450_spi_cfg_gpio
,
171 .fifo_lvl_mask
= 0x7f,
176 struct platform_device s5p64x0_device_spi1
= {
177 .name
= "s3c64xx-spi",
179 .num_resources
= ARRAY_SIZE(s5p64x0_spi1_resource
),
180 .resource
= s5p64x0_spi1_resource
,
182 .dma_mask
= &spi_dmamask
,
183 .coherent_dma_mask
= DMA_BIT_MASK(32),
187 void __init
s5p64x0_spi_set_info(int cntrlr
, int src_clk_nr
, int num_cs
)
189 struct s3c64xx_spi_info
*pd
;
191 /* Reject invalid configuration */
192 if (!num_cs
|| src_clk_nr
< 0
193 || src_clk_nr
> S5P64X0_SPI_SRCCLK_SCLK
) {
194 printk(KERN_ERR
"%s: Invalid SPI configuration\n", __func__
);
200 if (soc_is_s5p6450())
201 pd
= &s5p6450_spi0_pdata
;
203 pd
= &s5p6440_spi0_pdata
;
205 s5p64x0_device_spi0
.dev
.platform_data
= pd
;
208 if (soc_is_s5p6450())
209 pd
= &s5p6450_spi1_pdata
;
211 pd
= &s5p6440_spi1_pdata
;
213 s5p64x0_device_spi1
.dev
.platform_data
= pd
;
216 printk(KERN_ERR
"%s: Invalid SPI controller(%d)\n",
222 pd
->src_clk_nr
= src_clk_nr
;
223 pd
->src_clk_name
= s5p64x0_spi_src_clks
[src_clk_nr
];