1 // SPDX-License-Identifier: GPL-2.0-only
3 * arch/arm/mach-orion5x/kurobox_pro-setup.c
5 * Maintainer: Ronen Shitrit <rshitrit@marvell.com>
7 #include <linux/gpio.h>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/platform_device.h>
11 #include <linux/pci.h>
12 #include <linux/irq.h>
13 #include <linux/delay.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/mtd/rawnand.h>
16 #include <linux/mv643xx_eth.h>
17 #include <linux/i2c.h>
18 #include <linux/serial_reg.h>
19 #include <linux/ata_platform.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/arch.h>
22 #include <asm/mach/pci.h>
23 #include <linux/platform_data/mtd-orion_nand.h>
28 /*****************************************************************************
30 ****************************************************************************/
33 * 256K NOR flash Device bus boot chip select
36 #define KUROBOX_PRO_NOR_BOOT_BASE 0xf4000000
37 #define KUROBOX_PRO_NOR_BOOT_SIZE SZ_256K
40 * 256M NAND flash on Device bus chip select 1
43 #define KUROBOX_PRO_NAND_BASE 0xfc000000
44 #define KUROBOX_PRO_NAND_SIZE SZ_2M
46 /*****************************************************************************
47 * 256MB NAND Flash on Device bus CS0
48 ****************************************************************************/
50 static struct mtd_partition kurobox_pro_nand_parts[] = {
61 .offset = SZ_4M + SZ_64M,
62 .size = SZ_256M - (SZ_4M + SZ_64M),
66 static struct resource kurobox_pro_nand_resource = {
67 .flags = IORESOURCE_MEM,
68 .start = KUROBOX_PRO_NAND_BASE,
69 .end = KUROBOX_PRO_NAND_BASE + KUROBOX_PRO_NAND_SIZE - 1,
72 static struct orion_nand_data kurobox_pro_nand_data = {
73 .parts = kurobox_pro_nand_parts,
74 .nr_parts = ARRAY_SIZE(kurobox_pro_nand_parts),
80 static struct platform_device kurobox_pro_nand_flash = {
84 .platform_data = &kurobox_pro_nand_data,
86 .resource = &kurobox_pro_nand_resource,
90 /*****************************************************************************
91 * 256KB NOR Flash on BOOT Device
92 ****************************************************************************/
94 static struct physmap_flash_data kurobox_pro_nor_flash_data = {
98 static struct resource kurobox_pro_nor_flash_resource = {
99 .flags = IORESOURCE_MEM,
100 .start = KUROBOX_PRO_NOR_BOOT_BASE,
101 .end = KUROBOX_PRO_NOR_BOOT_BASE + KUROBOX_PRO_NOR_BOOT_SIZE - 1,
104 static struct platform_device kurobox_pro_nor_flash = {
105 .name = "physmap-flash",
108 .platform_data = &kurobox_pro_nor_flash_data,
111 .resource = &kurobox_pro_nor_flash_resource,
114 /*****************************************************************************
116 ****************************************************************************/
118 static int __init kurobox_pro_pci_map_irq(const struct pci_dev *dev, u8 slot,
124 * Check for devices with hard-wired IRQs.
126 irq = orion5x_pci_map_irq(dev, slot, pin);
131 * PCI isn't used on the Kuro
136 static struct hw_pci kurobox_pro_pci __initdata = {
138 .setup = orion5x_pci_sys_setup,
139 .scan = orion5x_pci_sys_scan_bus,
140 .map_irq = kurobox_pro_pci_map_irq,
143 static int __init kurobox_pro_pci_init(void)
145 if (machine_is_kurobox_pro()) {
146 orion5x_pci_disable();
147 pci_common_init(&kurobox_pro_pci);
153 subsys_initcall(kurobox_pro_pci_init);
155 /*****************************************************************************
157 ****************************************************************************/
159 static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
160 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
163 /*****************************************************************************
164 * RTC 5C372a on I2C bus
165 ****************************************************************************/
166 static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
167 I2C_BOARD_INFO("rs5c372a", 0x32),
170 /*****************************************************************************
172 ****************************************************************************/
173 static struct mv_sata_platform_data kurobox_pro_sata_data = {
177 /*****************************************************************************
178 * Kurobox Pro specific power off method via UART1-attached microcontroller
179 ****************************************************************************/
181 #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
183 static int kurobox_pro_miconread(unsigned char *buf, int count)
188 for (i = 0; i < count; i++) {
191 while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
199 buf[i] = readl(UART1_REG(RX));
202 /* return read bytes */
206 static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
211 while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
213 writel(buf[i++], UART1_REG(TX));
219 static int kurobox_pro_miconsend(const unsigned char *data, int count)
222 unsigned char checksum = 0;
223 unsigned char recv_buf[40];
224 unsigned char send_buf[40];
225 unsigned char correct_ack[3];
228 /* Generate checksum */
229 for (i = 0; i < count; i++)
234 kurobox_pro_miconwrite(data, count);
237 kurobox_pro_miconwrite(&checksum, 1);
239 if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
240 printk(KERN_ERR ">%s: receive failed.\n", __func__);
242 /* send preamble to clear the receive buffer */
243 memset(&send_buf, 0xff, sizeof(send_buf));
244 kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
246 /* make dummy reads */
248 kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
250 /* Generate expected ack */
251 correct_ack[0] = 0x01;
252 correct_ack[1] = data[1];
253 correct_ack[2] = 0x00;
256 if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
257 recv_buf[3]) & 0xFF) {
258 printk(KERN_ERR ">%s: Checksum Error : "
259 "Received data[%02x, %02x, %02x, %02x]"
260 "\n", __func__, recv_buf[0],
261 recv_buf[1], recv_buf[2], recv_buf[3]);
263 /* Check Received Data */
264 if (correct_ack[0] == recv_buf[0] &&
265 correct_ack[1] == recv_buf[1] &&
266 correct_ack[2] == recv_buf[2]) {
267 /* Interval for next command */
274 /* Received NAK or illegal Data */
275 printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
276 "Received\n", __func__);
280 /* Interval for next command */
286 static void kurobox_pro_power_off(void)
288 const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
289 const unsigned char shutdownwait[] = {0x00, 0x0c};
290 const unsigned char poweroff[] = {0x00, 0x06};
291 /* 38400 baud divisor */
292 const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
294 pr_info("%s: triggering power-off...\n", __func__);
296 /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
297 writel(0x83, UART1_REG(LCR));
298 writel(divisor & 0xff, UART1_REG(DLL));
299 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
300 writel(0x1b, UART1_REG(LCR));
301 writel(0x00, UART1_REG(IER));
302 writel(0x07, UART1_REG(FCR));
303 writel(0x00, UART1_REG(MCR));
305 /* Send the commands to shutdown the Kurobox Pro */
306 kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
307 kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
308 kurobox_pro_miconsend(poweroff, sizeof(poweroff));
311 /*****************************************************************************
313 ****************************************************************************/
314 static unsigned int kurobox_pro_mpp_modes[] __initdata = {
317 MPP2_GPIO, /* GPIO Micon */
318 MPP3_GPIO, /* GPIO Rtc */
321 MPP6_NAND, /* NAND Flash REn */
322 MPP7_NAND, /* NAND Flash WEn */
327 MPP12_SATA_LED, /* SATA 0 presence */
328 MPP13_SATA_LED, /* SATA 1 presence */
329 MPP14_SATA_LED, /* SATA 0 active */
330 MPP15_SATA_LED, /* SATA 1 active */
331 MPP16_UART, /* UART1 RXD */
332 MPP17_UART, /* UART1 TXD */
333 MPP18_UART, /* UART1 CTSn */
334 MPP19_UART, /* UART1 RTSn */
338 static void __init kurobox_pro_init(void)
341 * Setup basic Orion functions. Need to be called early.
345 orion5x_mpp_conf(kurobox_pro_mpp_modes);
348 * Configure peripherals.
350 orion5x_ehci0_init();
351 orion5x_ehci1_init();
352 orion5x_eth_init(&kurobox_pro_eth_data);
354 orion5x_sata_init(&kurobox_pro_sata_data);
355 orion5x_uart0_init();
356 orion5x_uart1_init();
359 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
360 ORION_MBUS_DEVBUS_BOOT_ATTR,
361 KUROBOX_PRO_NOR_BOOT_BASE,
362 KUROBOX_PRO_NOR_BOOT_SIZE);
363 platform_device_register(&kurobox_pro_nor_flash);
365 if (machine_is_kurobox_pro()) {
366 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(0),
367 ORION_MBUS_DEVBUS_ATTR(0),
368 KUROBOX_PRO_NAND_BASE,
369 KUROBOX_PRO_NAND_SIZE);
370 platform_device_register(&kurobox_pro_nand_flash);
373 i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
375 /* register Kurobox Pro specific power-off method */
376 pm_power_off = kurobox_pro_power_off;
379 #ifdef CONFIG_MACH_KUROBOX_PRO
380 MACHINE_START(KUROBOX_PRO, "Buffalo/Revogear Kurobox Pro")
381 /* Maintainer: Ronen Shitrit <rshitrit@marvell.com> */
382 .atag_offset = 0x100,
383 .nr_irqs = ORION5X_NR_IRQS,
384 .init_machine = kurobox_pro_init,
385 .map_io = orion5x_map_io,
386 .init_early = orion5x_init_early,
387 .init_irq = orion5x_init_irq,
388 .init_time = orion5x_timer_init,
389 .fixup = tag_fixup_mem32,
390 .restart = orion5x_restart,
394 #ifdef CONFIG_MACH_LINKSTATION_PRO
395 MACHINE_START(LINKSTATION_PRO, "Buffalo Linkstation Pro/Live")
396 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
397 .atag_offset = 0x100,
398 .nr_irqs = ORION5X_NR_IRQS,
399 .init_machine = kurobox_pro_init,
400 .map_io = orion5x_map_io,
401 .init_early = orion5x_init_early,
402 .init_irq = orion5x_init_irq,
403 .init_time = orion5x_timer_init,
404 .fixup = tag_fixup_mem32,
405 .restart = orion5x_restart,