0001
0002
0003
0004
0005
0006
0007 #include <linux/gpio.h>
0008 #include <linux/kernel.h>
0009 #include <linux/init.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/pci.h>
0012 #include <linux/irq.h>
0013 #include <linux/delay.h>
0014 #include <linux/mtd/physmap.h>
0015 #include <linux/mtd/rawnand.h>
0016 #include <linux/mv643xx_eth.h>
0017 #include <linux/i2c.h>
0018 #include <linux/serial_reg.h>
0019 #include <linux/ata_platform.h>
0020 #include <asm/mach-types.h>
0021 #include <asm/mach/arch.h>
0022 #include <asm/mach/pci.h>
0023 #include <linux/platform_data/mtd-orion_nand.h>
0024 #include "common.h"
0025 #include "mpp.h"
0026 #include "orion5x.h"
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #define KUROBOX_PRO_NOR_BOOT_BASE 0xf4000000
0037 #define KUROBOX_PRO_NOR_BOOT_SIZE SZ_256K
0038
0039
0040
0041
0042
0043 #define KUROBOX_PRO_NAND_BASE 0xfc000000
0044 #define KUROBOX_PRO_NAND_SIZE SZ_2M
0045
0046
0047
0048
0049
0050 static struct mtd_partition kurobox_pro_nand_parts[] = {
0051 {
0052 .name = "uImage",
0053 .offset = 0,
0054 .size = SZ_4M,
0055 }, {
0056 .name = "rootfs",
0057 .offset = SZ_4M,
0058 .size = SZ_64M,
0059 }, {
0060 .name = "extra",
0061 .offset = SZ_4M + SZ_64M,
0062 .size = SZ_256M - (SZ_4M + SZ_64M),
0063 },
0064 };
0065
0066 static struct resource kurobox_pro_nand_resource = {
0067 .flags = IORESOURCE_MEM,
0068 .start = KUROBOX_PRO_NAND_BASE,
0069 .end = KUROBOX_PRO_NAND_BASE + KUROBOX_PRO_NAND_SIZE - 1,
0070 };
0071
0072 static struct orion_nand_data kurobox_pro_nand_data = {
0073 .parts = kurobox_pro_nand_parts,
0074 .nr_parts = ARRAY_SIZE(kurobox_pro_nand_parts),
0075 .cle = 0,
0076 .ale = 1,
0077 .width = 8,
0078 };
0079
0080 static struct platform_device kurobox_pro_nand_flash = {
0081 .name = "orion_nand",
0082 .id = -1,
0083 .dev = {
0084 .platform_data = &kurobox_pro_nand_data,
0085 },
0086 .resource = &kurobox_pro_nand_resource,
0087 .num_resources = 1,
0088 };
0089
0090
0091
0092
0093
0094 static struct physmap_flash_data kurobox_pro_nor_flash_data = {
0095 .width = 1,
0096 };
0097
0098 static struct resource kurobox_pro_nor_flash_resource = {
0099 .flags = IORESOURCE_MEM,
0100 .start = KUROBOX_PRO_NOR_BOOT_BASE,
0101 .end = KUROBOX_PRO_NOR_BOOT_BASE + KUROBOX_PRO_NOR_BOOT_SIZE - 1,
0102 };
0103
0104 static struct platform_device kurobox_pro_nor_flash = {
0105 .name = "physmap-flash",
0106 .id = 0,
0107 .dev = {
0108 .platform_data = &kurobox_pro_nor_flash_data,
0109 },
0110 .num_resources = 1,
0111 .resource = &kurobox_pro_nor_flash_resource,
0112 };
0113
0114
0115
0116
0117
0118 static int __init kurobox_pro_pci_map_irq(const struct pci_dev *dev, u8 slot,
0119 u8 pin)
0120 {
0121 int irq;
0122
0123
0124
0125
0126 irq = orion5x_pci_map_irq(dev, slot, pin);
0127 if (irq != -1)
0128 return irq;
0129
0130
0131
0132
0133 return -1;
0134 }
0135
0136 static struct hw_pci kurobox_pro_pci __initdata = {
0137 .nr_controllers = 2,
0138 .setup = orion5x_pci_sys_setup,
0139 .scan = orion5x_pci_sys_scan_bus,
0140 .map_irq = kurobox_pro_pci_map_irq,
0141 };
0142
0143 static int __init kurobox_pro_pci_init(void)
0144 {
0145 if (machine_is_kurobox_pro()) {
0146 orion5x_pci_disable();
0147 pci_common_init(&kurobox_pro_pci);
0148 }
0149
0150 return 0;
0151 }
0152
0153 subsys_initcall(kurobox_pro_pci_init);
0154
0155
0156
0157
0158
0159 static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
0160 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
0161 };
0162
0163
0164
0165
0166 static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
0167 I2C_BOARD_INFO("rs5c372a", 0x32),
0168 };
0169
0170
0171
0172
0173 static struct mv_sata_platform_data kurobox_pro_sata_data = {
0174 .n_ports = 2,
0175 };
0176
0177
0178
0179
0180
0181 #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
0182
0183 static int kurobox_pro_miconread(unsigned char *buf, int count)
0184 {
0185 int i;
0186 int timeout;
0187
0188 for (i = 0; i < count; i++) {
0189 timeout = 10;
0190
0191 while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
0192 if (--timeout == 0)
0193 break;
0194 udelay(1000);
0195 }
0196
0197 if (timeout == 0)
0198 break;
0199 buf[i] = readl(UART1_REG(RX));
0200 }
0201
0202
0203 return i;
0204 }
0205
0206 static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
0207 {
0208 int i = 0;
0209
0210 while (count--) {
0211 while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
0212 barrier();
0213 writel(buf[i++], UART1_REG(TX));
0214 }
0215
0216 return 0;
0217 }
0218
0219 static int kurobox_pro_miconsend(const unsigned char *data, int count)
0220 {
0221 int i;
0222 unsigned char checksum = 0;
0223 unsigned char recv_buf[40];
0224 unsigned char send_buf[40];
0225 unsigned char correct_ack[3];
0226 int retry = 2;
0227
0228
0229 for (i = 0; i < count; i++)
0230 checksum -= data[i];
0231
0232 do {
0233
0234 kurobox_pro_miconwrite(data, count);
0235
0236
0237 kurobox_pro_miconwrite(&checksum, 1);
0238
0239 if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
0240 printk(KERN_ERR ">%s: receive failed.\n", __func__);
0241
0242
0243 memset(&send_buf, 0xff, sizeof(send_buf));
0244 kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
0245
0246
0247 mdelay(100);
0248 kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
0249 } else {
0250
0251 correct_ack[0] = 0x01;
0252 correct_ack[1] = data[1];
0253 correct_ack[2] = 0x00;
0254
0255
0256 if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
0257 recv_buf[3]) & 0xFF) {
0258 printk(KERN_ERR ">%s: Checksum Error : "
0259 "Received data[%02x, %02x, %02x, %02x]"
0260 "\n", __func__, recv_buf[0],
0261 recv_buf[1], recv_buf[2], recv_buf[3]);
0262 } else {
0263
0264 if (correct_ack[0] == recv_buf[0] &&
0265 correct_ack[1] == recv_buf[1] &&
0266 correct_ack[2] == recv_buf[2]) {
0267
0268 mdelay(10);
0269
0270
0271 return 0;
0272 }
0273 }
0274
0275 printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
0276 "Received\n", __func__);
0277 }
0278 } while (retry--);
0279
0280
0281 mdelay(10);
0282
0283 return -1;
0284 }
0285
0286 static void kurobox_pro_power_off(void)
0287 {
0288 const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
0289 const unsigned char shutdownwait[] = {0x00, 0x0c};
0290 const unsigned char poweroff[] = {0x00, 0x06};
0291
0292 const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
0293
0294 pr_info("%s: triggering power-off...\n", __func__);
0295
0296
0297 writel(0x83, UART1_REG(LCR));
0298 writel(divisor & 0xff, UART1_REG(DLL));
0299 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
0300 writel(0x1b, UART1_REG(LCR));
0301 writel(0x00, UART1_REG(IER));
0302 writel(0x07, UART1_REG(FCR));
0303 writel(0x00, UART1_REG(MCR));
0304
0305
0306 kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
0307 kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
0308 kurobox_pro_miconsend(poweroff, sizeof(poweroff));
0309 }
0310
0311
0312
0313
0314 static unsigned int kurobox_pro_mpp_modes[] __initdata = {
0315 MPP0_UNUSED,
0316 MPP1_UNUSED,
0317 MPP2_GPIO,
0318 MPP3_GPIO,
0319 MPP4_UNUSED,
0320 MPP5_UNUSED,
0321 MPP6_NAND,
0322 MPP7_NAND,
0323 MPP8_UNUSED,
0324 MPP9_UNUSED,
0325 MPP10_UNUSED,
0326 MPP11_UNUSED,
0327 MPP12_SATA_LED,
0328 MPP13_SATA_LED,
0329 MPP14_SATA_LED,
0330 MPP15_SATA_LED,
0331 MPP16_UART,
0332 MPP17_UART,
0333 MPP18_UART,
0334 MPP19_UART,
0335 0,
0336 };
0337
0338 static void __init kurobox_pro_init(void)
0339 {
0340
0341
0342
0343 orion5x_init();
0344
0345 orion5x_mpp_conf(kurobox_pro_mpp_modes);
0346
0347
0348
0349
0350 orion5x_ehci0_init();
0351 orion5x_ehci1_init();
0352 orion5x_eth_init(&kurobox_pro_eth_data);
0353 orion5x_i2c_init();
0354 orion5x_sata_init(&kurobox_pro_sata_data);
0355 orion5x_uart0_init();
0356 orion5x_uart1_init();
0357 orion5x_xor_init();
0358
0359 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
0360 ORION_MBUS_DEVBUS_BOOT_ATTR,
0361 KUROBOX_PRO_NOR_BOOT_BASE,
0362 KUROBOX_PRO_NOR_BOOT_SIZE);
0363 platform_device_register(&kurobox_pro_nor_flash);
0364
0365 if (machine_is_kurobox_pro()) {
0366 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(0),
0367 ORION_MBUS_DEVBUS_ATTR(0),
0368 KUROBOX_PRO_NAND_BASE,
0369 KUROBOX_PRO_NAND_SIZE);
0370 platform_device_register(&kurobox_pro_nand_flash);
0371 }
0372
0373 i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
0374
0375
0376 pm_power_off = kurobox_pro_power_off;
0377 }
0378
0379 #ifdef CONFIG_MACH_KUROBOX_PRO
0380 MACHINE_START(KUROBOX_PRO, "Buffalo/Revogear Kurobox Pro")
0381
0382 .atag_offset = 0x100,
0383 .nr_irqs = ORION5X_NR_IRQS,
0384 .init_machine = kurobox_pro_init,
0385 .map_io = orion5x_map_io,
0386 .init_early = orion5x_init_early,
0387 .init_irq = orion5x_init_irq,
0388 .init_time = orion5x_timer_init,
0389 .fixup = tag_fixup_mem32,
0390 .restart = orion5x_restart,
0391 MACHINE_END
0392 #endif
0393
0394 #ifdef CONFIG_MACH_LINKSTATION_PRO
0395 MACHINE_START(LINKSTATION_PRO, "Buffalo Linkstation Pro/Live")
0396
0397 .atag_offset = 0x100,
0398 .nr_irqs = ORION5X_NR_IRQS,
0399 .init_machine = kurobox_pro_init,
0400 .map_io = orion5x_map_io,
0401 .init_early = orion5x_init_early,
0402 .init_irq = orion5x_init_irq,
0403 .init_time = orion5x_timer_init,
0404 .fixup = tag_fixup_mem32,
0405 .restart = orion5x_restart,
0406 MACHINE_END
0407 #endif