1 /* linux/arch/arm/plat-s3c64xx/dev-spi.c
3 * Copyright (C) 2009 Samsung Electronics 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/kernel.h>
12 #include <linux/string.h>
13 #include <linux/export.h>
14 #include <linux/platform_device.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/gpio.h>
20 #include <mach/spi-clocks.h>
21 #include <mach/irqs.h>
23 #include <plat/s3c64xx-spi.h>
24 #include <plat/gpio-cfg.h>
25 #include <plat/devs.h>
27 static char *spi_src_clks
[] = {
28 [S3C64XX_SPI_SRCCLK_PCLK
] = "pclk",
29 [S3C64XX_SPI_SRCCLK_SPIBUS
] = "spi-bus",
30 [S3C64XX_SPI_SRCCLK_48M
] = "spi_48m",
33 /* SPI Controller platform_devices */
35 /* Since we emulate multi-cs capability, we do not touch the GPC-3,7.
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 s3c64xx_spi_cfg_gpio(struct platform_device
*pdev
)
47 base
= S3C64XX_GPC(0);
51 base
= S3C64XX_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 struct resource s3c64xx_spi0_resource
[] = {
67 .start
= S3C64XX_PA_SPI0
,
68 .end
= S3C64XX_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 s3c64xx_spi0_pdata
= {
89 .cfg_gpio
= s3c64xx_spi_cfg_gpio
,
90 .fifo_lvl_mask
= 0x7f,
95 static u64 spi_dmamask
= DMA_BIT_MASK(32);
97 struct platform_device s3c64xx_device_spi0
= {
98 .name
= "s3c64xx-spi",
100 .num_resources
= ARRAY_SIZE(s3c64xx_spi0_resource
),
101 .resource
= s3c64xx_spi0_resource
,
103 .dma_mask
= &spi_dmamask
,
104 .coherent_dma_mask
= DMA_BIT_MASK(32),
105 .platform_data
= &s3c64xx_spi0_pdata
,
108 EXPORT_SYMBOL(s3c64xx_device_spi0
);
110 static struct resource s3c64xx_spi1_resource
[] = {
112 .start
= S3C64XX_PA_SPI1
,
113 .end
= S3C64XX_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 s3c64xx_spi1_pdata
= {
134 .cfg_gpio
= s3c64xx_spi_cfg_gpio
,
135 .fifo_lvl_mask
= 0x7f,
140 struct platform_device s3c64xx_device_spi1
= {
141 .name
= "s3c64xx-spi",
143 .num_resources
= ARRAY_SIZE(s3c64xx_spi1_resource
),
144 .resource
= s3c64xx_spi1_resource
,
146 .dma_mask
= &spi_dmamask
,
147 .coherent_dma_mask
= DMA_BIT_MASK(32),
148 .platform_data
= &s3c64xx_spi1_pdata
,
151 EXPORT_SYMBOL(s3c64xx_device_spi1
);
153 void __init
s3c64xx_spi_set_info(int cntrlr
, int src_clk_nr
, int num_cs
)
155 struct s3c64xx_spi_info
*pd
;
157 /* Reject invalid configuration */
158 if (!num_cs
|| src_clk_nr
< 0
159 || src_clk_nr
> S3C64XX_SPI_SRCCLK_48M
) {
160 printk(KERN_ERR
"%s: Invalid SPI configuration\n", __func__
);
166 pd
= &s3c64xx_spi0_pdata
;
169 pd
= &s3c64xx_spi1_pdata
;
172 printk(KERN_ERR
"%s: Invalid SPI controller(%d)\n",
178 pd
->src_clk_nr
= src_clk_nr
;
179 pd
->src_clk_name
= spi_src_clks
[src_clk_nr
];