1c8b61d50SAngelo Dureghello /*
2c8b61d50SAngelo Dureghello * stmark2.c -- Support for Sysam AMCORE open board
3c8b61d50SAngelo Dureghello *
4c8b61d50SAngelo Dureghello * (C) Copyright 2017, Angelo Dureghello <angelo@sysam.it>
5c8b61d50SAngelo Dureghello *
6c8b61d50SAngelo Dureghello * This file is subject to the terms and conditions of the GNU General Public
7c8b61d50SAngelo Dureghello * License. See the file COPYING in the main directory of this archive
8c8b61d50SAngelo Dureghello * for more details.
9c8b61d50SAngelo Dureghello */
10c8b61d50SAngelo Dureghello
11c8b61d50SAngelo Dureghello #include <linux/platform_device.h>
12c8b61d50SAngelo Dureghello #include <linux/mtd/partitions.h>
13c8b61d50SAngelo Dureghello #include <linux/spi/spi.h>
14c8b61d50SAngelo Dureghello #include <linux/spi/spi-fsl-dspi.h>
15c8b61d50SAngelo Dureghello #include <linux/spi/flash.h>
16fde87ebfSAngelo Dureghello #include <linux/dma-mapping.h>
17c8b61d50SAngelo Dureghello #include <asm/mcfsim.h>
18c8b61d50SAngelo Dureghello
19c8b61d50SAngelo Dureghello /*
20c8b61d50SAngelo Dureghello * Partitioning of parallel NOR flash (39VF3201B)
21c8b61d50SAngelo Dureghello */
22c8b61d50SAngelo Dureghello static struct mtd_partition stmark2_partitions[] = {
23c8b61d50SAngelo Dureghello {
24c8b61d50SAngelo Dureghello .name = "U-Boot (1024K)",
25c8b61d50SAngelo Dureghello .size = 0x100000,
26c8b61d50SAngelo Dureghello .offset = 0x0
27c8b61d50SAngelo Dureghello }, {
28c8b61d50SAngelo Dureghello .name = "Kernel+initramfs (7168K)",
29c8b61d50SAngelo Dureghello .size = 0x700000,
30c8b61d50SAngelo Dureghello .offset = MTDPART_OFS_APPEND
31c8b61d50SAngelo Dureghello }, {
32c8b61d50SAngelo Dureghello .name = "Flash Free Space (8192K)",
33c8b61d50SAngelo Dureghello .size = MTDPART_SIZ_FULL,
34c8b61d50SAngelo Dureghello .offset = MTDPART_OFS_APPEND
35c8b61d50SAngelo Dureghello }
36c8b61d50SAngelo Dureghello };
37c8b61d50SAngelo Dureghello
38c8b61d50SAngelo Dureghello static struct flash_platform_data stmark2_spi_flash_data = {
39c8b61d50SAngelo Dureghello .name = "is25lp128",
40c8b61d50SAngelo Dureghello .parts = stmark2_partitions,
41c8b61d50SAngelo Dureghello .nr_parts = ARRAY_SIZE(stmark2_partitions),
42c8b61d50SAngelo Dureghello .type = "is25lp128",
43c8b61d50SAngelo Dureghello };
44c8b61d50SAngelo Dureghello
45c8b61d50SAngelo Dureghello static struct spi_board_info stmark2_board_info[] __initdata = {
46c8b61d50SAngelo Dureghello {
47c8b61d50SAngelo Dureghello .modalias = "m25p80",
48c8b61d50SAngelo Dureghello .max_speed_hz = 5000000,
49c8b61d50SAngelo Dureghello .bus_num = 0,
50c8b61d50SAngelo Dureghello .chip_select = 1,
51c8b61d50SAngelo Dureghello .platform_data = &stmark2_spi_flash_data,
52c8b61d50SAngelo Dureghello .mode = SPI_MODE_3,
53c8b61d50SAngelo Dureghello }
54c8b61d50SAngelo Dureghello };
55c8b61d50SAngelo Dureghello
56c8b61d50SAngelo Dureghello /* SPI controller data, SPI (0) */
57c8b61d50SAngelo Dureghello static struct fsl_dspi_platform_data dspi_spi0_info = {
58c8b61d50SAngelo Dureghello .cs_num = 4,
59c8b61d50SAngelo Dureghello .bus_num = 0,
60c8b61d50SAngelo Dureghello .sck_cs_delay = 100,
61c8b61d50SAngelo Dureghello .cs_sck_delay = 100,
62c8b61d50SAngelo Dureghello };
63c8b61d50SAngelo Dureghello
64c8b61d50SAngelo Dureghello static struct resource dspi_spi0_resource[] = {
65c8b61d50SAngelo Dureghello [0] = {
66c8b61d50SAngelo Dureghello .start = MCFDSPI_BASE0,
67c8b61d50SAngelo Dureghello .end = MCFDSPI_BASE0 + 0xFF,
68c8b61d50SAngelo Dureghello .flags = IORESOURCE_MEM,
69c8b61d50SAngelo Dureghello },
70c8b61d50SAngelo Dureghello [1] = {
71c8b61d50SAngelo Dureghello .start = 12,
72c8b61d50SAngelo Dureghello .end = 13,
73c8b61d50SAngelo Dureghello .flags = IORESOURCE_DMA,
74c8b61d50SAngelo Dureghello },
75c8b61d50SAngelo Dureghello [2] = {
76c8b61d50SAngelo Dureghello .start = MCF_IRQ_DSPI0,
77c8b61d50SAngelo Dureghello .end = MCF_IRQ_DSPI0,
78c8b61d50SAngelo Dureghello .flags = IORESOURCE_IRQ,
79c8b61d50SAngelo Dureghello },
80c8b61d50SAngelo Dureghello };
81c8b61d50SAngelo Dureghello
82fde87ebfSAngelo Dureghello static u64 stmark2_dspi_mask = DMA_BIT_MASK(32);
83fde87ebfSAngelo Dureghello
84c8b61d50SAngelo Dureghello /* SPI controller, id = bus number */
85c8b61d50SAngelo Dureghello static struct platform_device dspi_spi0_device = {
86c8b61d50SAngelo Dureghello .name = "fsl-dspi",
87c8b61d50SAngelo Dureghello .id = 0,
88c8b61d50SAngelo Dureghello .num_resources = ARRAY_SIZE(dspi_spi0_resource),
89c8b61d50SAngelo Dureghello .resource = dspi_spi0_resource,
90c8b61d50SAngelo Dureghello .dev = {
91c8b61d50SAngelo Dureghello .platform_data = &dspi_spi0_info,
92fde87ebfSAngelo Dureghello .dma_mask = &stmark2_dspi_mask,
93fde87ebfSAngelo Dureghello .coherent_dma_mask = DMA_BIT_MASK(32),
94c8b61d50SAngelo Dureghello },
95c8b61d50SAngelo Dureghello };
96c8b61d50SAngelo Dureghello
97c8b61d50SAngelo Dureghello static struct platform_device *stmark2_devices[] __initdata = {
98c8b61d50SAngelo Dureghello &dspi_spi0_device,
99c8b61d50SAngelo Dureghello };
100c8b61d50SAngelo Dureghello
101c8b61d50SAngelo Dureghello /*
102c8b61d50SAngelo Dureghello * Note: proper pin-mux setup is mandatory for proper SPI functionality.
103c8b61d50SAngelo Dureghello */
init_stmark2(void)104c8b61d50SAngelo Dureghello static int __init init_stmark2(void)
105c8b61d50SAngelo Dureghello {
106c8b61d50SAngelo Dureghello /* DSPI0, all pins as DSPI, and using CS1 */
107c8b61d50SAngelo Dureghello __raw_writeb(0x80, MCFGPIO_PAR_DSPIOWL);
108c8b61d50SAngelo Dureghello __raw_writeb(0xfc, MCFGPIO_PAR_DSPIOWH);
109c8b61d50SAngelo Dureghello
110c8b61d50SAngelo Dureghello /* Board gpio setup */
111c8b61d50SAngelo Dureghello __raw_writeb(0x00, MCFGPIO_PAR_BE);
112c8b61d50SAngelo Dureghello __raw_writeb(0x00, MCFGPIO_PAR_FBCTL);
113c8b61d50SAngelo Dureghello __raw_writeb(0x00, MCFGPIO_PAR_CS);
114*40cff492SAngelo Dureghello
115*40cff492SAngelo Dureghello /* CAN pads */
116*40cff492SAngelo Dureghello __raw_writeb(0x50, MCFGPIO_PAR_CANI2C);
117c8b61d50SAngelo Dureghello
118c8b61d50SAngelo Dureghello platform_add_devices(stmark2_devices, ARRAY_SIZE(stmark2_devices));
119c8b61d50SAngelo Dureghello
120c8b61d50SAngelo Dureghello spi_register_board_info(stmark2_board_info,
121c8b61d50SAngelo Dureghello ARRAY_SIZE(stmark2_board_info));
122c8b61d50SAngelo Dureghello
123c8b61d50SAngelo Dureghello return 0;
124c8b61d50SAngelo Dureghello }
125c8b61d50SAngelo Dureghello
126*40cff492SAngelo Dureghello device_initcall(init_stmark2);
127