[PATCH 2/4] mach-gta02: Add board setup for MLX90609 and SAR 100 on the SPI0 bus

Stefan Schmidt stefan at datenfreihafen.org
Mon Apr 26 09:25:04 CEST 2010


Both of these chips are hanging on the external SPI bus routed to the debug
port. Both are sharing the same GPIO for CS, but inverted in hardware for the
SAR100.
---
 arch/arm/mach-s3c2440/mach-gta02.c |   83 ++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
index 153549e..fc9ed16 100644
--- a/arch/arm/mach-s3c2440/mach-gta02.c
+++ b/arch/arm/mach-s3c2440/mach-gta02.c
@@ -1606,6 +1606,80 @@ static int __init hardware_ecc_setup(char *str)
 
 __setup("hardware_ecc=", hardware_ecc_setup);
 
+/* MLX90609 / SAR100 */
+static void spi_gpio_cs(struct s3c2410_spigpio_info *spi, int csidx, int cs)
+{
+	s3c2410_gpio_setpin(S3C2410_GPG2, cs ? 0 : 1);
+}
+
+static void spi_gpio_cs_inverted(struct s3c2410_spigpio_info *spi, int csidx, int cs)
+{
+	s3c2410_gpio_setpin(S3C2410_GPG2, cs ? 1 : 0);
+}
+
+static struct spi_board_info mlx_spi_board[] __initdata = {
+	{
+		.modalias	= "mlx90609",
+		.bus_num	= 0,
+		.chip_select    = 0,
+		/* The datasheet states it should have CPHA=1 and CPOL=1 which
+		 * means SPI_MODE_3, but it fails to work with it. SPI_MODE_0
+		 * is needed instead */
+		.mode		= SPI_MODE_0, /* CPOL=0, CPHA=0 */
+		.max_speed_hz	= 8 * 1000 * 1000,
+	}
+};
+
+static struct spi_board_info sar_spi_board[] __initdata = {
+	{
+		.modalias	= "sar100",
+		.bus_num	= 3,
+		.chip_select    = 0,
+		.mode		= SPI_MODE_0, /* CPOL=0, CPHA=0 */
+		.max_speed_hz	= 8 * 1000 * 1000,
+	}
+};
+
+static struct s3c2410_spigpio_info mlx_spi_gpio_cfg = {
+	.bus_num	= 0,
+        .pin_clk        = S3C2410_GPE13,
+        .pin_mosi       = S3C2410_GPE12,
+        .pin_miso       = S3C2410_GPE11,
+        .board_size     = ARRAY_SIZE(mlx_spi_board),
+        .board_info     = mlx_spi_board,
+        .num_chipselect = 1,
+        .chip_select    = &spi_gpio_cs,
+};
+
+static struct s3c2410_spigpio_info sar_spi_gpio_cfg = {
+	.bus_num	= 3,
+        .pin_clk        = S3C2410_GPE13,
+        .pin_mosi       = S3C2410_GPE12,
+        .pin_miso       = S3C2410_GPE11,
+        .board_size     = ARRAY_SIZE(sar_spi_board),
+        .board_info     = sar_spi_board,
+        .num_chipselect = 1,
+        .chip_select    = &spi_gpio_cs_inverted,
+};
+
+struct platform_device s3c_device_spi_mlx = {
+        .name             = "spi_s3c24xx_gpio",
+        .id               = 1,
+        .num_resources    = 0,
+        .dev = {
+		.platform_data = &mlx_spi_gpio_cfg,
+	},
+};
+
+struct platform_device s3c_device_spi_sar = {
+        .name             = "spi_s3c24xx_gpio",
+        .id               = 2,
+        .num_resources    = 0,
+        .dev = {
+		.platform_data = &sar_spi_gpio_cfg,
+	},
+};
+
 /* these are the guys that don't need to be children of PMU */
 
 static struct platform_device *gta02_devices[] __initdata = {
@@ -1625,6 +1699,9 @@ static struct platform_device *gta02_devices[] __initdata = {
 
 	&s3c_device_iis,
 	&s3c_device_i2c0,
+
+	&s3c_device_spi_mlx,
+	&s3c_device_spi_sar,
 };
 
 /* these guys DO need to be children of PMU */
@@ -1725,6 +1802,12 @@ static void __init gta02_machine_init(void)
 	s3c2410_gpio_setpin(S3C2410_GPD13, 1);
 	s3c2410_gpio_cfgpin(S3C2410_GPD13, S3C2410_GPIO_OUTPUT);
 
+/*===========================================================================*/
+	/* SPI chip select is gpio output */
+	s3c2410_gpio_cfgpin(S3C2410_GPG2, S3C2410_GPIO_OUTPUT);
+	s3c2410_gpio_setpin(S3C2410_GPG2, 1);
+/*===========================================================================*/
+
 	s3c24xx_udc_set_platdata(&gta02_udc_cfg);
 	s3c_i2c0_set_platdata(NULL);
 	set_s3c2410ts_info(&gta02_ts_cfg);
-- 
1.7.0.5




More information about the openmoko-kernel mailing list