Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * arch/arm/mach-iop32x/em7210.c
0004  *
0005  * Board support code for the Lanner EM7210 platforms.
0006  *
0007  * Based on arch/arm/mach-iop32x/iq31244.c file.
0008  *
0009  * Copyright (C) 2007 Arnaud Patard <arnaud.patard@rtp-net.org>
0010  */
0011 
0012 #include <linux/mm.h>
0013 #include <linux/init.h>
0014 #include <linux/kernel.h>
0015 #include <linux/pci.h>
0016 #include <linux/pm.h>
0017 #include <linux/serial_core.h>
0018 #include <linux/serial_8250.h>
0019 #include <linux/mtd/physmap.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/i2c.h>
0022 #include <linux/gpio.h>
0023 #include <linux/gpio/machine.h>
0024 #include <linux/io.h>
0025 #include <linux/irq.h>
0026 #include <asm/mach/arch.h>
0027 #include <asm/mach/map.h>
0028 #include <asm/mach/pci.h>
0029 #include <asm/mach/time.h>
0030 #include <asm/mach-types.h>
0031 
0032 #include "hardware.h"
0033 #include "gpio-iop32x.h"
0034 #include "irqs.h"
0035 
0036 static void __init em7210_timer_init(void)
0037 {
0038     /* http://www.kwaak.net/fotos/fotos-nas/slide_24.html */
0039     /* 33.333 MHz crystal.                                */
0040     iop_init_time(200000000);
0041 }
0042 
0043 /*
0044  * EM7210 RTC
0045  */
0046 static struct i2c_board_info __initdata em7210_i2c_devices[] = {
0047     {
0048         I2C_BOARD_INFO("rs5c372a", 0x32),
0049     },
0050 };
0051 
0052 /*
0053  * EM7210 I/O
0054  */
0055 static struct map_desc em7210_io_desc[] __initdata = {
0056     {   /* on-board devices */
0057         .virtual    = IQ31244_UART,
0058         .pfn        = __phys_to_pfn(IQ31244_UART),
0059         .length     = 0x00100000,
0060         .type       = MT_DEVICE,
0061     },
0062 };
0063 
0064 void __init em7210_map_io(void)
0065 {
0066     iop3xx_map_io();
0067     iotable_init(em7210_io_desc, ARRAY_SIZE(em7210_io_desc));
0068 }
0069 
0070 
0071 /*
0072  * EM7210 PCI
0073  */
0074 #define INTA    IRQ_IOP32X_XINT0
0075 #define INTB    IRQ_IOP32X_XINT1
0076 #define INTC    IRQ_IOP32X_XINT2
0077 #define INTD    IRQ_IOP32X_XINT3
0078 
0079 static int __init
0080 em7210_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
0081 {
0082     static int pci_irq_table[][4] = {
0083         /*
0084          * PCI IDSEL/INTPIN->INTLINE
0085          * A       B       C       D
0086          */
0087         {INTB, INTB, INTB, INTB}, /* console / uart */
0088         {INTA, INTA, INTA, INTA}, /* 1st 82541      */
0089         {INTD, INTD, INTD, INTD}, /* 2nd 82541      */
0090         {INTC, INTC, INTC, INTC}, /* GD31244        */
0091         {INTD, INTA, INTA, INTA}, /* mini-PCI       */
0092         {INTD, INTC, INTA, INTA}, /* NEC USB        */
0093     };
0094 
0095     if (pin < 1 || pin > 4)
0096         return -1;
0097 
0098     return pci_irq_table[slot % 6][pin - 1];
0099 }
0100 
0101 static struct hw_pci em7210_pci __initdata = {
0102     .nr_controllers = 1,
0103     .ops        = &iop3xx_ops,
0104     .setup      = iop3xx_pci_setup,
0105     .preinit    = iop3xx_pci_preinit,
0106     .map_irq    = em7210_pci_map_irq,
0107 };
0108 
0109 static int __init em7210_pci_init(void)
0110 {
0111     if (machine_is_em7210())
0112         pci_common_init(&em7210_pci);
0113 
0114     return 0;
0115 }
0116 
0117 subsys_initcall(em7210_pci_init);
0118 
0119 
0120 /*
0121  * EM7210 Flash
0122  */
0123 static struct physmap_flash_data em7210_flash_data = {
0124     .width      = 2,
0125 };
0126 
0127 static struct resource em7210_flash_resource = {
0128     .start      = 0xf0000000,
0129     .end        = 0xf1ffffff,
0130     .flags      = IORESOURCE_MEM,
0131 };
0132 
0133 static struct platform_device em7210_flash_device = {
0134     .name       = "physmap-flash",
0135     .id     = 0,
0136     .dev        = {
0137         .platform_data  = &em7210_flash_data,
0138     },
0139     .num_resources  = 1,
0140     .resource   = &em7210_flash_resource,
0141 };
0142 
0143 
0144 /*
0145  * EM7210 UART
0146  * The physical address of the serial port is 0xfe800000,
0147  * so it can be used for physical and virtual address.
0148  */
0149 static struct plat_serial8250_port em7210_serial_port[] = {
0150     {
0151         .mapbase    = IQ31244_UART,
0152         .membase    = (char *)IQ31244_UART,
0153         .irq        = IRQ_IOP32X_XINT1,
0154         .flags      = UPF_SKIP_TEST,
0155         .iotype     = UPIO_MEM,
0156         .regshift   = 0,
0157         .uartclk    = 1843200,
0158     },
0159     { },
0160 };
0161 
0162 static struct resource em7210_uart_resource = {
0163     .start      = IQ31244_UART,
0164     .end        = IQ31244_UART + 7,
0165     .flags      = IORESOURCE_MEM,
0166 };
0167 
0168 static struct platform_device em7210_serial_device = {
0169     .name       = "serial8250",
0170     .id     = PLAT8250_DEV_PLATFORM,
0171     .dev        = {
0172         .platform_data      = em7210_serial_port,
0173     },
0174     .num_resources  = 1,
0175     .resource   = &em7210_uart_resource,
0176 };
0177 
0178 #define EM7210_HARDWARE_POWER 0
0179 
0180 void em7210_power_off(void)
0181 {
0182     int ret;
0183 
0184     ret = gpio_direction_output(EM7210_HARDWARE_POWER, 1);
0185     if (ret)
0186         pr_crit("could not drive power off GPIO high\n");
0187 }
0188 
0189 static int __init em7210_request_gpios(void)
0190 {
0191     int ret;
0192 
0193     if (!machine_is_em7210())
0194         return 0;
0195 
0196     ret = gpio_request(EM7210_HARDWARE_POWER, "power");
0197     if (ret) {
0198         pr_err("could not request power off GPIO\n");
0199         return 0;
0200     }
0201 
0202     pm_power_off = em7210_power_off;
0203 
0204     return 0;
0205 }
0206 device_initcall(em7210_request_gpios);
0207 
0208 static void __init em7210_init_machine(void)
0209 {
0210     register_iop32x_gpio();
0211     platform_device_register(&em7210_serial_device);
0212     gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
0213     gpiod_add_lookup_table(&iop3xx_i2c1_gpio_lookup);
0214     platform_device_register(&iop3xx_i2c0_device);
0215     platform_device_register(&iop3xx_i2c1_device);
0216     platform_device_register(&em7210_flash_device);
0217     platform_device_register(&iop3xx_dma_0_channel);
0218     platform_device_register(&iop3xx_dma_1_channel);
0219 
0220     i2c_register_board_info(0, em7210_i2c_devices,
0221         ARRAY_SIZE(em7210_i2c_devices));
0222 }
0223 
0224 MACHINE_START(EM7210, "Lanner EM7210")
0225     .atag_offset    = 0x100,
0226     .nr_irqs    = IOP32X_NR_IRQS,
0227     .map_io     = em7210_map_io,
0228     .init_irq   = iop32x_init_irq,
0229     .init_time  = em7210_timer_init,
0230     .init_machine   = em7210_init_machine,
0231     .restart    = iop3xx_restart,
0232 MACHINE_END