Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * GPR board platform device registration (Au1550)
0004  *
0005  * Copyright (C) 2010 Wolfgang Grandegger <wg@denx.de>
0006  */
0007 
0008 #include <linux/delay.h>
0009 #include <linux/init.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/kernel.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/pm.h>
0014 #include <linux/mtd/partitions.h>
0015 #include <linux/mtd/physmap.h>
0016 #include <linux/leds.h>
0017 #include <linux/gpio.h>
0018 #include <linux/i2c.h>
0019 #include <linux/platform_data/i2c-gpio.h>
0020 #include <linux/gpio/machine.h>
0021 #include <asm/bootinfo.h>
0022 #include <asm/idle.h>
0023 #include <asm/reboot.h>
0024 #include <asm/setup.h>
0025 #include <asm/mach-au1x00/au1000.h>
0026 #include <asm/mach-au1x00/gpio-au1000.h>
0027 #include <prom.h>
0028 
0029 const char *get_system_type(void)
0030 {
0031     return "GPR";
0032 }
0033 
0034 void prom_putchar(char c)
0035 {
0036     alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
0037 }
0038 
0039 static void gpr_reset(char *c)
0040 {
0041     /* switch System-LED to orange (red# and green# on) */
0042     alchemy_gpio_direction_output(4, 0);
0043     alchemy_gpio_direction_output(5, 0);
0044 
0045     /* trigger watchdog to reset board in 200ms */
0046     printk(KERN_EMERG "Triggering watchdog soft reset...\n");
0047     raw_local_irq_disable();
0048     alchemy_gpio_direction_output(1, 0);
0049     udelay(1);
0050     alchemy_gpio_set_value(1, 1);
0051     while (1)
0052         cpu_wait();
0053 }
0054 
0055 static void gpr_power_off(void)
0056 {
0057     while (1)
0058         cpu_wait();
0059 }
0060 
0061 void __init board_setup(void)
0062 {
0063     printk(KERN_INFO "Trapeze ITS GPR board\n");
0064 
0065     pm_power_off = gpr_power_off;
0066     _machine_halt = gpr_power_off;
0067     _machine_restart = gpr_reset;
0068 
0069     /* Enable UART1/3 */
0070     alchemy_uart_enable(AU1000_UART3_PHYS_ADDR);
0071     alchemy_uart_enable(AU1000_UART1_PHYS_ADDR);
0072 
0073     /* Take away Reset of UMTS-card */
0074     alchemy_gpio_direction_output(215, 1);
0075 }
0076 
0077 /*
0078  * Watchdog
0079  */
0080 static struct resource gpr_wdt_resource[] = {
0081     [0] = {
0082         .start  = 1,
0083         .end    = 1,
0084         .name   = "gpr-adm6320-wdt",
0085         .flags  = IORESOURCE_IRQ,
0086     }
0087 };
0088 
0089 static struct platform_device gpr_wdt_device = {
0090     .name = "adm6320-wdt",
0091     .id = 0,
0092     .num_resources = ARRAY_SIZE(gpr_wdt_resource),
0093     .resource = gpr_wdt_resource,
0094 };
0095 
0096 /*
0097  * FLASH
0098  *
0099  * 0x00000000-0x00200000 : "kernel"
0100  * 0x00200000-0x00a00000 : "rootfs"
0101  * 0x01d00000-0x01f00000 : "config"
0102  * 0x01c00000-0x01d00000 : "yamon"
0103  * 0x01d00000-0x01d40000 : "yamon env vars"
0104  * 0x00000000-0x00a00000 : "kernel+rootfs"
0105  */
0106 static struct mtd_partition gpr_mtd_partitions[] = {
0107     {
0108         .name   = "kernel",
0109         .size   = 0x00200000,
0110         .offset = 0,
0111     },
0112     {
0113         .name   = "rootfs",
0114         .size   = 0x00800000,
0115         .offset = MTDPART_OFS_APPEND,
0116         .mask_flags = MTD_WRITEABLE,
0117     },
0118     {
0119         .name   = "config",
0120         .size   = 0x00200000,
0121         .offset = 0x01d00000,
0122     },
0123     {
0124         .name   = "yamon",
0125         .size   = 0x00100000,
0126         .offset = 0x01c00000,
0127     },
0128     {
0129         .name   = "yamon env vars",
0130         .size   = 0x00040000,
0131         .offset = MTDPART_OFS_APPEND,
0132     },
0133     {
0134         .name   = "kernel+rootfs",
0135         .size   = 0x00a00000,
0136         .offset = 0,
0137     },
0138 };
0139 
0140 static struct physmap_flash_data gpr_flash_data = {
0141     .width      = 4,
0142     .nr_parts   = ARRAY_SIZE(gpr_mtd_partitions),
0143     .parts      = gpr_mtd_partitions,
0144 };
0145 
0146 static struct resource gpr_mtd_resource = {
0147     .start  = 0x1e000000,
0148     .end    = 0x1fffffff,
0149     .flags  = IORESOURCE_MEM,
0150 };
0151 
0152 static struct platform_device gpr_mtd_device = {
0153     .name       = "physmap-flash",
0154     .dev        = {
0155         .platform_data  = &gpr_flash_data,
0156     },
0157     .num_resources  = 1,
0158     .resource   = &gpr_mtd_resource,
0159 };
0160 
0161 /*
0162  * LEDs
0163  */
0164 static const struct gpio_led gpr_gpio_leds[] = {
0165     {   /* green */
0166         .name           = "gpr:green",
0167         .gpio           = 4,
0168         .active_low     = 1,
0169     },
0170     {   /* red */
0171         .name           = "gpr:red",
0172         .gpio           = 5,
0173         .active_low     = 1,
0174     }
0175 };
0176 
0177 static struct gpio_led_platform_data gpr_led_data = {
0178     .num_leds = ARRAY_SIZE(gpr_gpio_leds),
0179     .leds = gpr_gpio_leds,
0180 };
0181 
0182 static struct platform_device gpr_led_devices = {
0183     .name = "leds-gpio",
0184     .id = -1,
0185     .dev = {
0186         .platform_data = &gpr_led_data,
0187     }
0188 };
0189 
0190 /*
0191  * I2C
0192  */
0193 static struct gpiod_lookup_table gpr_i2c_gpiod_table = {
0194     .dev_id = "i2c-gpio",
0195     .table = {
0196         /*
0197          * This should be on "GPIO2" which has base at 200 so
0198          * the global numbers 209 and 210 should correspond to
0199          * local offsets 9 and 10.
0200          */
0201         GPIO_LOOKUP_IDX("alchemy-gpio2", 9, NULL, 0,
0202                 GPIO_ACTIVE_HIGH),
0203         GPIO_LOOKUP_IDX("alchemy-gpio2", 10, NULL, 1,
0204                 GPIO_ACTIVE_HIGH),
0205     },
0206 };
0207 
0208 static struct i2c_gpio_platform_data gpr_i2c_data = {
0209     /*
0210      * The open drain mode is hardwired somewhere or an electrical
0211      * property of the alchemy GPIO controller.
0212      */
0213     .sda_is_open_drain  = 1,
0214     .scl_is_open_drain  = 1,
0215     .udelay         = 2,        /* ~100 kHz */
0216     .timeout        = HZ,
0217 };
0218 
0219 static struct platform_device gpr_i2c_device = {
0220     .name           = "i2c-gpio",
0221     .id         = -1,
0222     .dev.platform_data  = &gpr_i2c_data,
0223 };
0224 
0225 static struct i2c_board_info gpr_i2c_info[] __initdata = {
0226     {
0227         I2C_BOARD_INFO("lm83", 0x18),
0228     }
0229 };
0230 
0231 
0232 
0233 static struct resource alchemy_pci_host_res[] = {
0234     [0] = {
0235         .start  = AU1500_PCI_PHYS_ADDR,
0236         .end    = AU1500_PCI_PHYS_ADDR + 0xfff,
0237         .flags  = IORESOURCE_MEM,
0238     },
0239 };
0240 
0241 static int gpr_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
0242 {
0243     if ((slot == 0) && (pin == 1))
0244         return AU1550_PCI_INTA;
0245     else if ((slot == 0) && (pin == 2))
0246         return AU1550_PCI_INTB;
0247 
0248     return 0xff;
0249 }
0250 
0251 static struct alchemy_pci_platdata gpr_pci_pd = {
0252     .board_map_irq  = gpr_map_pci_irq,
0253     .pci_cfg_set    = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
0254               PCI_CONFIG_CH |
0255 #if defined(__MIPSEB__)
0256               PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
0257 #else
0258               0,
0259 #endif
0260 };
0261 
0262 static struct platform_device gpr_pci_host_dev = {
0263     .dev.platform_data = &gpr_pci_pd,
0264     .name       = "alchemy-pci",
0265     .id     = 0,
0266     .num_resources  = ARRAY_SIZE(alchemy_pci_host_res),
0267     .resource   = alchemy_pci_host_res,
0268 };
0269 
0270 static struct platform_device *gpr_devices[] __initdata = {
0271     &gpr_wdt_device,
0272     &gpr_mtd_device,
0273     &gpr_i2c_device,
0274     &gpr_led_devices,
0275 };
0276 
0277 static int __init gpr_pci_init(void)
0278 {
0279     return platform_device_register(&gpr_pci_host_dev);
0280 }
0281 /* must be arch_initcall; MIPS PCI scans busses in a subsys_initcall */
0282 arch_initcall(gpr_pci_init);
0283 
0284 
0285 static int __init gpr_dev_init(void)
0286 {
0287     gpiod_add_lookup_table(&gpr_i2c_gpiod_table);
0288     i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info));
0289 
0290     return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
0291 }
0292 device_initcall(gpr_dev_init);