2 * Hammerhead board-specific flash initialization
4 * Copyright (C) 2008 Miromico AG
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/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.h>
16 #include <linux/usb/isp116x.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/delay.h>
20 #include <mach/portmux.h>
21 #include <mach/at32ap700x.h>
24 #include "../../mach-at32ap/clock.h"
28 #define HAMMERHEAD_USB_PERIPH_GCLK0 0x40000000
29 #define HAMMERHEAD_USB_PERIPH_CS2 0x02000000
30 #define HAMMERHEAD_USB_PERIPH_EXTINT0 0x02000000
32 #define HAMMERHEAD_FPGA_PERIPH_MOSI 0x00000002
33 #define HAMMERHEAD_FPGA_PERIPH_SCK 0x00000020
34 #define HAMMERHEAD_FPGA_PERIPH_EXTINT3 0x10000000
36 static struct smc_timing flash_timing __initdata = {
44 .ncs_write_pulse = 65,
51 static struct smc_config flash_config __initdata = {
58 static struct mtd_partition flash_parts[] = {
62 .size = 0x00020000, /* 128 KiB */
63 .mask_flags = MTD_WRITEABLE,
74 .mask_flags = MTD_WRITEABLE,
78 static struct physmap_flash_data flash_data = {
80 .nr_parts = ARRAY_SIZE(flash_parts),
84 static struct resource flash_resource = {
87 .flags = IORESOURCE_MEM,
90 static struct platform_device flash_device = {
91 .name = "physmap-flash",
93 .resource = &flash_resource,
95 .dev = { .platform_data = &flash_data, },
98 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
100 static struct smc_timing isp1160_timing __initdata = {
101 .ncs_read_setup = 75,
103 .ncs_write_setup = 75,
107 /* We use conservative timing settings, as the minimal settings aren't
108 stable. There may be room for tweaking. */
109 .ncs_read_pulse = 75, /* min. 33ns */
110 .nrd_pulse = 75, /* min. 33ns */
111 .ncs_write_pulse = 75, /* min. 26ns */
112 .nwe_pulse = 75, /* min. 26ns */
114 .read_cycle = 225, /* min. 143ns */
115 .write_cycle = 225, /* min. 136ns */
118 static struct smc_config isp1160_config __initdata = {
126 * The platform delay function is only used to enforce the strange
127 * read to write delay. This can not be configured in the SMC. All other
128 * timings are controlled by the SMC (see timings obove)
129 * So in isp116x-hcd.c we should comment out USE_PLATFORM_DELAY
131 void isp116x_delay(struct device *dev, int delay)
137 static struct isp116x_platform_data isp1160_data = {
138 .sel15Kres = 1, /* use internal downstream resistors */
139 .oc_enable = 0, /* external overcurrent detection */
140 .int_edge_triggered = 0, /* interrupt is level triggered */
141 .int_act_high = 0, /* interrupt is active low */
142 .delay = isp116x_delay, /* platform delay function */
145 static struct resource isp1160_resource[] = {
149 .flags = IORESOURCE_MEM,
154 .flags = IORESOURCE_MEM,
158 .flags = IORESOURCE_IRQ,
162 static struct platform_device isp1160_device = {
163 .name = "isp116x-hcd",
165 .resource = isp1160_resource,
168 .platform_data = &isp1160_data,
173 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
174 static int __init hammerhead_usbh_init(void)
181 /* setup smc for usbh */
182 smc_set_timing(&isp1160_config, &isp1160_timing);
183 ret = smc_set_configuration(2, &isp1160_config);
187 "hammerhead: failed to set ISP1160 USBH timing\n");
191 /* setup gclk0 to run from osc1 */
192 gclk = clk_get(NULL, "gclk0");
196 osc = clk_get(NULL, "osc1");
200 if (clk_set_parent(gclk, osc)) {
201 pr_debug("hammerhead: failed to set osc1 for USBH clock\n");
205 /* set clock to 6MHz */
206 clk_set_rate(gclk, 6000000);
211 /* select GCLK0 peripheral function */
212 at32_select_periph(GPIO_PIOA_BASE, HAMMERHEAD_USB_PERIPH_GCLK0,
215 /* enable CS2 peripheral function */
216 at32_select_periph(GPIO_PIOE_BASE, HAMMERHEAD_USB_PERIPH_CS2,
219 /* H_WAKEUP must be driven low */
220 at32_select_gpio(GPIO_PIN_PA(8), AT32_GPIOF_OUTPUT);
222 /* Select EXTINT0 for PB25 */
223 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_USB_PERIPH_EXTINT0,
226 /* register usbh device driver */
227 platform_device_register(&isp1160_device);
238 #ifdef CONFIG_BOARD_HAMMERHEAD_FPGA
239 static struct smc_timing fpga_timing __initdata = {
240 .ncs_read_setup = 16,
242 .ncs_read_pulse = 48,
246 .ncs_write_setup = 16,
248 .ncs_write_pulse = 32,
253 static struct smc_config fpga_config __initdata = {
260 static struct resource hh_fpga0_resource[] = {
263 .end = 0xffe00400 + 0x3ff,
264 .flags = IORESOURCE_MEM,
269 .flags = IORESOURCE_IRQ,
274 .flags = IORESOURCE_MEM,
279 .flags = IORESOURCE_IRQ,
283 static u64 hh_fpga0_dma_mask = DMA_32BIT_MASK;
284 static struct platform_device hh_fpga0_device = {
288 .dma_mask = &hh_fpga0_dma_mask,
289 .coherent_dma_mask = DMA_32BIT_MASK,
291 .resource = hh_fpga0_resource,
292 .num_resources = ARRAY_SIZE(hh_fpga0_resource),
295 static struct clk hh_fpga0_spi_clk = {
297 .dev = &hh_fpga0_device.dev,
298 .mode = pba_clk_mode,
299 .get_rate = pba_clk_get_rate,
303 struct platform_device *__init at32_add_device_hh_fpga(void)
305 /* Select peripheral functionallity for SPI SCK and MOSI */
306 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_FPGA_PERIPH_SCK,
308 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_FPGA_PERIPH_MOSI,
311 /* reserve all other needed gpio
312 * We have on board pull ups, so there is no need
313 * to enable gpio pull ups */
314 /* INIT_DONE (input) */
315 at32_select_gpio(GPIO_PIN_PB(0), 0);
317 /* nSTATUS (input) */
318 at32_select_gpio(GPIO_PIN_PB(2), 0);
320 /* nCONFIG (output, low) */
321 at32_select_gpio(GPIO_PIN_PB(3), AT32_GPIOF_OUTPUT);
323 /* CONF_DONE (input) */
324 at32_select_gpio(GPIO_PIN_PB(4), 0);
326 /* Select EXTINT3 for PB28 (Interrupt from FPGA) */
327 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_FPGA_PERIPH_EXTINT3,
330 /* Get our parent clock */
331 hh_fpga0_spi_clk.parent = clk_get(NULL, "pba");
332 clk_put(hh_fpga0_spi_clk.parent);
334 /* Register clock in at32 clock tree */
335 at32_clk_register(&hh_fpga0_spi_clk);
337 platform_device_register(&hh_fpga0_device);
338 return &hh_fpga0_device;
342 /* This needs to be called after the SMC has been initialized */
343 static int __init hammerhead_flash_init(void)
347 smc_set_timing(&flash_config, &flash_timing);
348 ret = smc_set_configuration(0, &flash_config);
351 printk(KERN_ERR "hammerhead: failed to set NOR flash timing\n");
355 platform_device_register(&flash_device);
357 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
358 hammerhead_usbh_init();
361 #ifdef CONFIG_BOARD_HAMMERHEAD_FPGA
362 /* Setup SMC for FPGA interface */
363 smc_set_timing(&fpga_config, &fpga_timing);
364 ret = smc_set_configuration(3, &fpga_config);
369 printk(KERN_ERR "hammerhead: failed to set FPGA timing\n");
376 device_initcall(hammerhead_flash_init);