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/platform_device.h>
19 #include <linux/delay.h>
21 #include <mach/portmux.h>
22 #include <mach/at32ap700x.h>
25 #include "../../mach-at32ap/clock.h"
29 #define HAMMERHEAD_USB_PERIPH_GCLK0 0x40000000
30 #define HAMMERHEAD_USB_PERIPH_CS2 0x02000000
31 #define HAMMERHEAD_USB_PERIPH_EXTINT0 0x02000000
33 #define HAMMERHEAD_FPGA_PERIPH_MOSI 0x00000002
34 #define HAMMERHEAD_FPGA_PERIPH_SCK 0x00000020
35 #define HAMMERHEAD_FPGA_PERIPH_EXTINT3 0x10000000
37 static struct smc_timing flash_timing __initdata = {
45 .ncs_write_pulse = 65,
52 static struct smc_config flash_config __initdata = {
59 static struct mtd_partition flash_parts[] = {
63 .size = 0x00020000, /* 128 KiB */
64 .mask_flags = MTD_WRITEABLE,
75 .mask_flags = MTD_WRITEABLE,
79 static struct physmap_flash_data flash_data = {
81 .nr_parts = ARRAY_SIZE(flash_parts),
85 static struct resource flash_resource = {
88 .flags = IORESOURCE_MEM,
91 static struct platform_device flash_device = {
92 .name = "physmap-flash",
94 .resource = &flash_resource,
96 .dev = { .platform_data = &flash_data, },
99 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
101 static struct smc_timing isp1160_timing __initdata = {
102 .ncs_read_setup = 75,
104 .ncs_write_setup = 75,
108 /* We use conservative timing settings, as the minimal settings aren't
109 stable. There may be room for tweaking. */
110 .ncs_read_pulse = 75, /* min. 33ns */
111 .nrd_pulse = 75, /* min. 33ns */
112 .ncs_write_pulse = 75, /* min. 26ns */
113 .nwe_pulse = 75, /* min. 26ns */
115 .read_cycle = 225, /* min. 143ns */
116 .write_cycle = 225, /* min. 136ns */
119 static struct smc_config isp1160_config __initdata = {
127 * The platform delay function is only used to enforce the strange
128 * read to write delay. This can not be configured in the SMC. All other
129 * timings are controlled by the SMC (see timings obove)
130 * So in isp116x-hcd.c we should comment out USE_PLATFORM_DELAY
132 void isp116x_delay(struct device *dev, int delay)
138 static struct isp116x_platform_data isp1160_data = {
139 .sel15Kres = 1, /* use internal downstream resistors */
140 .oc_enable = 0, /* external overcurrent detection */
141 .int_edge_triggered = 0, /* interrupt is level triggered */
142 .int_act_high = 0, /* interrupt is active low */
143 .delay = isp116x_delay, /* platform delay function */
146 static struct resource isp1160_resource[] = {
150 .flags = IORESOURCE_MEM,
155 .flags = IORESOURCE_MEM,
159 .flags = IORESOURCE_IRQ,
163 static struct platform_device isp1160_device = {
164 .name = "isp116x-hcd",
166 .resource = isp1160_resource,
169 .platform_data = &isp1160_data,
174 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
175 static int __init hammerhead_usbh_init(void)
182 /* setup smc for usbh */
183 smc_set_timing(&isp1160_config, &isp1160_timing);
184 ret = smc_set_configuration(2, &isp1160_config);
188 "hammerhead: failed to set ISP1160 USBH timing\n");
192 /* setup gclk0 to run from osc1 */
193 gclk = clk_get(NULL, "gclk0");
197 osc = clk_get(NULL, "osc1");
201 if (clk_set_parent(gclk, osc)) {
202 pr_debug("hammerhead: failed to set osc1 for USBH clock\n");
206 /* set clock to 6MHz */
207 clk_set_rate(gclk, 6000000);
212 /* select GCLK0 peripheral function */
213 at32_select_periph(GPIO_PIOA_BASE, HAMMERHEAD_USB_PERIPH_GCLK0,
216 /* enable CS2 peripheral function */
217 at32_select_periph(GPIO_PIOE_BASE, HAMMERHEAD_USB_PERIPH_CS2,
220 /* H_WAKEUP must be driven low */
221 at32_select_gpio(GPIO_PIN_PA(8), AT32_GPIOF_OUTPUT);
223 /* Select EXTINT0 for PB25 */
224 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_USB_PERIPH_EXTINT0,
227 /* register usbh device driver */
228 platform_device_register(&isp1160_device);
239 #ifdef CONFIG_BOARD_HAMMERHEAD_FPGA
240 static struct smc_timing fpga_timing __initdata = {
241 .ncs_read_setup = 16,
243 .ncs_read_pulse = 48,
247 .ncs_write_setup = 16,
249 .ncs_write_pulse = 32,
254 static struct smc_config fpga_config __initdata = {
261 static struct resource hh_fpga0_resource[] = {
264 .end = 0xffe00400 + 0x3ff,
265 .flags = IORESOURCE_MEM,
270 .flags = IORESOURCE_IRQ,
275 .flags = IORESOURCE_MEM,
280 .flags = IORESOURCE_IRQ,
284 static u64 hh_fpga0_dma_mask = DMA_32BIT_MASK;
285 static struct platform_device hh_fpga0_device = {
289 .dma_mask = &hh_fpga0_dma_mask,
290 .coherent_dma_mask = DMA_32BIT_MASK,
292 .resource = hh_fpga0_resource,
293 .num_resources = ARRAY_SIZE(hh_fpga0_resource),
296 static struct clk hh_fpga0_spi_clk = {
298 .dev = &hh_fpga0_device.dev,
299 .mode = pba_clk_mode,
300 .get_rate = pba_clk_get_rate,
304 struct platform_device *__init at32_add_device_hh_fpga(void)
306 /* Select peripheral functionallity for SPI SCK and MOSI */
307 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_FPGA_PERIPH_SCK,
309 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_FPGA_PERIPH_MOSI,
312 /* reserve all other needed gpio
313 * We have on board pull ups, so there is no need
314 * to enable gpio pull ups */
315 /* INIT_DONE (input) */
316 at32_select_gpio(GPIO_PIN_PB(0), 0);
318 /* nSTATUS (input) */
319 at32_select_gpio(GPIO_PIN_PB(2), 0);
321 /* nCONFIG (output, low) */
322 at32_select_gpio(GPIO_PIN_PB(3), AT32_GPIOF_OUTPUT);
324 /* CONF_DONE (input) */
325 at32_select_gpio(GPIO_PIN_PB(4), 0);
327 /* Select EXTINT3 for PB28 (Interrupt from FPGA) */
328 at32_select_periph(GPIO_PIOB_BASE, HAMMERHEAD_FPGA_PERIPH_EXTINT3,
331 /* Get our parent clock */
332 hh_fpga0_spi_clk.parent = clk_get(NULL, "pba");
333 clk_put(hh_fpga0_spi_clk.parent);
335 /* Register clock in at32 clock tree */
336 at32_clk_register(&hh_fpga0_spi_clk);
338 platform_device_register(&hh_fpga0_device);
339 return &hh_fpga0_device;
343 /* This needs to be called after the SMC has been initialized */
344 static int __init hammerhead_flash_init(void)
348 smc_set_timing(&flash_config, &flash_timing);
349 ret = smc_set_configuration(0, &flash_config);
352 printk(KERN_ERR "hammerhead: failed to set NOR flash timing\n");
356 platform_device_register(&flash_device);
358 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
359 hammerhead_usbh_init();
362 #ifdef CONFIG_BOARD_HAMMERHEAD_FPGA
363 /* Setup SMC for FPGA interface */
364 smc_set_timing(&fpga_config, &fpga_timing);
365 ret = smc_set_configuration(3, &fpga_config);
370 printk(KERN_ERR "hammerhead: failed to set FPGA timing\n");
377 device_initcall(hammerhead_flash_init);