Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * arch/arm/mach-iop32x/n2100.c
0004  *
0005  * Board support code for the Thecus N2100 platform.
0006  *
0007  * Author: Rory Bolt <rorybolt@pacbell.net>
0008  * Copyright (C) 2002 Rory Bolt
0009  * Copyright 2003 (c) MontaVista, Software, Inc.
0010  * Copyright (C) 2004 Intel Corp.
0011  */
0012 
0013 #include <linux/mm.h>
0014 #include <linux/init.h>
0015 #include <linux/f75375s.h>
0016 #include <linux/leds-pca9532.h>
0017 #include <linux/delay.h>
0018 #include <linux/kernel.h>
0019 #include <linux/pci.h>
0020 #include <linux/pm.h>
0021 #include <linux/string.h>
0022 #include <linux/serial_core.h>
0023 #include <linux/serial_8250.h>
0024 #include <linux/mtd/physmap.h>
0025 #include <linux/i2c.h>
0026 #include <linux/platform_device.h>
0027 #include <linux/reboot.h>
0028 #include <linux/io.h>
0029 #include <linux/gpio.h>
0030 #include <linux/gpio/machine.h>
0031 #include <asm/irq.h>
0032 #include <asm/mach/arch.h>
0033 #include <asm/mach/map.h>
0034 #include <asm/mach/pci.h>
0035 #include <asm/mach/time.h>
0036 #include <asm/mach-types.h>
0037 #include <asm/page.h>
0038 
0039 #include "hardware.h"
0040 #include "irqs.h"
0041 #include "gpio-iop32x.h"
0042 
0043 /*
0044  * N2100 timer tick configuration.
0045  */
0046 static void __init n2100_timer_init(void)
0047 {
0048     /* 33.000 MHz crystal.  */
0049     iop_init_time(198000000);
0050 }
0051 
0052 
0053 /*
0054  * N2100 I/O.
0055  */
0056 static struct map_desc n2100_io_desc[] __initdata = {
0057     {   /* on-board devices */
0058         .virtual    = N2100_UART,
0059         .pfn        = __phys_to_pfn(N2100_UART),
0060         .length     = 0x00100000,
0061         .type       = MT_DEVICE
0062     },
0063 };
0064 
0065 void __init n2100_map_io(void)
0066 {
0067     iop3xx_map_io();
0068     iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
0069 }
0070 
0071 
0072 /*
0073  * N2100 PCI.
0074  */
0075 static int n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
0076 {
0077     int irq;
0078 
0079     if (PCI_SLOT(dev->devfn) == 1) {
0080         /* RTL8110SB #1 */
0081         irq = IRQ_IOP32X_XINT0;
0082     } else if (PCI_SLOT(dev->devfn) == 2) {
0083         /* RTL8110SB #2 */
0084         irq = IRQ_IOP32X_XINT3;
0085     } else if (PCI_SLOT(dev->devfn) == 3) {
0086         /* Sil3512 */
0087         irq = IRQ_IOP32X_XINT2;
0088     } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
0089         /* VT6212 INTA */
0090         irq = IRQ_IOP32X_XINT1;
0091     } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
0092         /* VT6212 INTB */
0093         irq = IRQ_IOP32X_XINT0;
0094     } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
0095         /* VT6212 INTC */
0096         irq = IRQ_IOP32X_XINT2;
0097     } else if (PCI_SLOT(dev->devfn) == 5) {
0098         /* Mini-PCI slot */
0099         irq = IRQ_IOP32X_XINT3;
0100     } else {
0101         printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
0102             "device PCI:%d:%d:%d\n", dev->bus->number,
0103             PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
0104         irq = -1;
0105     }
0106 
0107     return irq;
0108 }
0109 
0110 static struct hw_pci n2100_pci __initdata = {
0111     .nr_controllers = 1,
0112     .ops        = &iop3xx_ops,
0113     .setup      = iop3xx_pci_setup,
0114     .preinit    = iop3xx_pci_preinit,
0115     .map_irq    = n2100_pci_map_irq,
0116 };
0117 
0118 /*
0119  * Both r8169 chips on the n2100 exhibit PCI parity problems.  Turn
0120  * off parity reporting for both ports so we don't get error interrupts
0121  * for them.
0122  */
0123 static void n2100_fixup_r8169(struct pci_dev *dev)
0124 {
0125     if (dev->bus->number == 0 &&
0126         (dev->devfn == PCI_DEVFN(1, 0) ||
0127          dev->devfn == PCI_DEVFN(2, 0)))
0128         pci_disable_parity(dev);
0129 }
0130 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
0131 
0132 static int __init n2100_pci_init(void)
0133 {
0134     if (machine_is_n2100())
0135         pci_common_init(&n2100_pci);
0136 
0137     return 0;
0138 }
0139 
0140 subsys_initcall(n2100_pci_init);
0141 
0142 
0143 /*
0144  * N2100 machine initialisation.
0145  */
0146 static struct physmap_flash_data n2100_flash_data = {
0147     .width      = 2,
0148 };
0149 
0150 static struct resource n2100_flash_resource = {
0151     .start      = 0xf0000000,
0152     .end        = 0xf0ffffff,
0153     .flags      = IORESOURCE_MEM,
0154 };
0155 
0156 static struct platform_device n2100_flash_device = {
0157     .name       = "physmap-flash",
0158     .id     = 0,
0159     .dev        = {
0160         .platform_data  = &n2100_flash_data,
0161     },
0162     .num_resources  = 1,
0163     .resource   = &n2100_flash_resource,
0164 };
0165 
0166 
0167 static struct plat_serial8250_port n2100_serial_port[] = {
0168     {
0169         .mapbase    = N2100_UART,
0170         .membase    = (char *)N2100_UART,
0171         .irq        = 0,
0172         .flags      = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
0173         .iotype     = UPIO_MEM,
0174         .regshift   = 0,
0175         .uartclk    = 1843200,
0176     },
0177     { },
0178 };
0179 
0180 static struct resource n2100_uart_resource = {
0181     .start      = N2100_UART,
0182     .end        = N2100_UART + 7,
0183     .flags      = IORESOURCE_MEM,
0184 };
0185 
0186 static struct platform_device n2100_serial_device = {
0187     .name       = "serial8250",
0188     .id     = PLAT8250_DEV_PLATFORM,
0189     .dev        = {
0190         .platform_data      = n2100_serial_port,
0191     },
0192     .num_resources  = 1,
0193     .resource   = &n2100_uart_resource,
0194 };
0195 
0196 static struct f75375s_platform_data n2100_f75375s = {
0197     .pwm        = { 255, 255 },
0198     .pwm_enable = { 0, 0 },
0199 };
0200 
0201 static struct pca9532_platform_data n2100_leds = {
0202     .leds = {
0203     {   .name = "n2100:red:satafail0",
0204         .state = PCA9532_OFF,
0205         .type = PCA9532_TYPE_LED,
0206     },
0207     {   .name = "n2100:red:satafail1",
0208         .state = PCA9532_OFF,
0209         .type = PCA9532_TYPE_LED,
0210     },
0211     {   .name = "n2100:blue:usb",
0212         .state = PCA9532_OFF,
0213         .type = PCA9532_TYPE_LED,
0214     },
0215     {   .type = PCA9532_TYPE_NONE },
0216 
0217     {   .type = PCA9532_TYPE_NONE },
0218     {   .type = PCA9532_TYPE_NONE },
0219     {   .type = PCA9532_TYPE_NONE },
0220     {   .name = "n2100:red:usb",
0221         .state = PCA9532_OFF,
0222         .type = PCA9532_TYPE_LED,
0223     },
0224 
0225     {   .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
0226     {   .type = PCA9532_TYPE_NONE }, /* reset gpio */
0227     {   .type = PCA9532_TYPE_NONE },
0228     {   .type = PCA9532_TYPE_NONE },
0229 
0230     {   .type = PCA9532_TYPE_NONE },
0231     {   .name = "n2100:orange:system",
0232         .state = PCA9532_OFF,
0233         .type = PCA9532_TYPE_LED,
0234     },
0235     {   .name = "n2100:red:system",
0236         .state = PCA9532_OFF,
0237         .type = PCA9532_TYPE_LED,
0238     },
0239     {   .name = "N2100 beeper"  ,
0240         .state =  PCA9532_OFF,
0241         .type = PCA9532_TYPE_N2100_BEEP,
0242     },
0243     },
0244     .psc = { 0, 0 },
0245     .pwm = { 0, 0 },
0246 };
0247 
0248 static struct i2c_board_info __initdata n2100_i2c_devices[] = {
0249     {
0250         I2C_BOARD_INFO("rs5c372b", 0x32),
0251     },
0252     {
0253         I2C_BOARD_INFO("f75375", 0x2e),
0254         .platform_data = &n2100_f75375s,
0255     },
0256     {
0257         I2C_BOARD_INFO("pca9532", 0x60),
0258         .platform_data = &n2100_leds,
0259     },
0260 };
0261 
0262 /*
0263  * Pull PCA9532 GPIO #8 low to power off the machine.
0264  */
0265 static void n2100_power_off(void)
0266 {
0267     local_irq_disable();
0268 
0269     /* Start condition, I2C address of PCA9532, write transaction.  */
0270     *IOP3XX_IDBR0 = 0xc0;
0271     *IOP3XX_ICR0 = 0xe9;
0272     mdelay(1);
0273 
0274     /* Write address 0x08.  */
0275     *IOP3XX_IDBR0 = 0x08;
0276     *IOP3XX_ICR0 = 0xe8;
0277     mdelay(1);
0278 
0279     /* Write data 0x01, stop condition.  */
0280     *IOP3XX_IDBR0 = 0x01;
0281     *IOP3XX_ICR0 = 0xea;
0282 
0283     while (1)
0284         ;
0285 }
0286 
0287 static void n2100_restart(enum reboot_mode mode, const char *cmd)
0288 {
0289     int ret;
0290 
0291     ret = gpio_direction_output(N2100_HARDWARE_RESET, 0);
0292     if (ret) {
0293         pr_crit("could not drive reset GPIO low\n");
0294         return;
0295     }
0296     /* Wait for reset to happen */
0297     while (1)
0298         ;
0299 }
0300 
0301 
0302 static struct timer_list power_button_poll_timer;
0303 
0304 static void power_button_poll(struct timer_list *unused)
0305 {
0306     if (gpio_get_value(N2100_POWER_BUTTON) == 0) {
0307         ctrl_alt_del();
0308         return;
0309     }
0310 
0311     power_button_poll_timer.expires = jiffies + (HZ / 10);
0312     add_timer(&power_button_poll_timer);
0313 }
0314 
0315 static int __init n2100_request_gpios(void)
0316 {
0317     int ret;
0318 
0319     if (!machine_is_n2100())
0320         return 0;
0321 
0322     ret = gpio_request(N2100_HARDWARE_RESET, "reset");
0323     if (ret)
0324         pr_err("could not request reset GPIO\n");
0325 
0326     ret = gpio_request(N2100_POWER_BUTTON, "power");
0327     if (ret)
0328         pr_err("could not request power GPIO\n");
0329     else {
0330         ret = gpio_direction_input(N2100_POWER_BUTTON);
0331         if (ret)
0332             pr_err("could not set power GPIO as input\n");
0333     }
0334     /* Set up power button poll timer */
0335     timer_setup(&power_button_poll_timer, power_button_poll, 0);
0336     power_button_poll_timer.expires = jiffies + (HZ / 10);
0337     add_timer(&power_button_poll_timer);
0338     return 0;
0339 }
0340 device_initcall(n2100_request_gpios);
0341 
0342 static void __init n2100_init_machine(void)
0343 {
0344     register_iop32x_gpio();
0345     gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
0346     platform_device_register(&iop3xx_i2c0_device);
0347     platform_device_register(&n2100_flash_device);
0348     platform_device_register(&n2100_serial_device);
0349     platform_device_register(&iop3xx_dma_0_channel);
0350     platform_device_register(&iop3xx_dma_1_channel);
0351 
0352     i2c_register_board_info(0, n2100_i2c_devices,
0353         ARRAY_SIZE(n2100_i2c_devices));
0354 
0355     pm_power_off = n2100_power_off;
0356 }
0357 
0358 MACHINE_START(N2100, "Thecus N2100")
0359     /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
0360     .atag_offset    = 0x100,
0361     .nr_irqs    = IOP32X_NR_IRQS,
0362     .map_io     = n2100_map_io,
0363     .init_irq   = iop32x_init_irq,
0364     .init_time  = n2100_timer_init,
0365     .init_machine   = n2100_init_machine,
0366     .restart    = n2100_restart,
0367 MACHINE_END