Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * arch/arm/mach-orion5x/db88f5281-setup.c
0004  *
0005  * Marvell Orion-2 Development Board Setup
0006  *
0007  * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
0008  */
0009 #include <linux/gpio.h>
0010 #include <linux/kernel.h>
0011 #include <linux/init.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/pci.h>
0014 #include <linux/irq.h>
0015 #include <linux/mtd/physmap.h>
0016 #include <linux/mtd/rawnand.h>
0017 #include <linux/timer.h>
0018 #include <linux/mv643xx_eth.h>
0019 #include <linux/i2c.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  * DB-88F5281 on board devices
0030  ****************************************************************************/
0031 
0032 /*
0033  * 512K NOR flash Device bus boot chip select
0034  */
0035 
0036 #define DB88F5281_NOR_BOOT_BASE     0xf4000000
0037 #define DB88F5281_NOR_BOOT_SIZE     SZ_512K
0038 
0039 /*
0040  * 7-Segment on Device bus chip select 0
0041  */
0042 
0043 #define DB88F5281_7SEG_BASE     0xfa000000
0044 #define DB88F5281_7SEG_SIZE     SZ_1K
0045 
0046 /*
0047  * 32M NOR flash on Device bus chip select 1
0048  */
0049 
0050 #define DB88F5281_NOR_BASE      0xfc000000
0051 #define DB88F5281_NOR_SIZE      SZ_32M
0052 
0053 /*
0054  * 32M NAND flash on Device bus chip select 2
0055  */
0056 
0057 #define DB88F5281_NAND_BASE     0xfa800000
0058 #define DB88F5281_NAND_SIZE     SZ_1K
0059 
0060 /*
0061  * PCI
0062  */
0063 
0064 #define DB88F5281_PCI_SLOT0_OFFS        7
0065 #define DB88F5281_PCI_SLOT0_IRQ_PIN     12
0066 #define DB88F5281_PCI_SLOT1_SLOT2_IRQ_PIN   13
0067 
0068 /*****************************************************************************
0069  * 512M NOR Flash on Device bus Boot CS
0070  ****************************************************************************/
0071 
0072 static struct physmap_flash_data db88f5281_boot_flash_data = {
0073     .width      = 1,    /* 8 bit bus width */
0074 };
0075 
0076 static struct resource db88f5281_boot_flash_resource = {
0077     .flags      = IORESOURCE_MEM,
0078     .start      = DB88F5281_NOR_BOOT_BASE,
0079     .end        = DB88F5281_NOR_BOOT_BASE + DB88F5281_NOR_BOOT_SIZE - 1,
0080 };
0081 
0082 static struct platform_device db88f5281_boot_flash = {
0083     .name       = "physmap-flash",
0084     .id     = 0,
0085     .dev        = {
0086         .platform_data  = &db88f5281_boot_flash_data,
0087     },
0088     .num_resources  = 1,
0089     .resource   = &db88f5281_boot_flash_resource,
0090 };
0091 
0092 /*****************************************************************************
0093  * 32M NOR Flash on Device bus CS1
0094  ****************************************************************************/
0095 
0096 static struct physmap_flash_data db88f5281_nor_flash_data = {
0097     .width      = 4,    /* 32 bit bus width */
0098 };
0099 
0100 static struct resource db88f5281_nor_flash_resource = {
0101     .flags      = IORESOURCE_MEM,
0102     .start      = DB88F5281_NOR_BASE,
0103     .end        = DB88F5281_NOR_BASE + DB88F5281_NOR_SIZE - 1,
0104 };
0105 
0106 static struct platform_device db88f5281_nor_flash = {
0107     .name       = "physmap-flash",
0108     .id     = 1,
0109     .dev        = {
0110         .platform_data  = &db88f5281_nor_flash_data,
0111     },
0112     .num_resources  = 1,
0113     .resource   = &db88f5281_nor_flash_resource,
0114 };
0115 
0116 /*****************************************************************************
0117  * 32M NAND Flash on Device bus CS2
0118  ****************************************************************************/
0119 
0120 static struct mtd_partition db88f5281_nand_parts[] = {
0121     {
0122         .name = "kernel",
0123         .offset = 0,
0124         .size = SZ_2M,
0125     }, {
0126         .name = "root",
0127         .offset = SZ_2M,
0128         .size = (SZ_16M - SZ_2M),
0129     }, {
0130         .name = "user",
0131         .offset = SZ_16M,
0132         .size = SZ_8M,
0133     }, {
0134         .name = "recovery",
0135         .offset = (SZ_16M + SZ_8M),
0136         .size = SZ_8M,
0137     },
0138 };
0139 
0140 static struct resource db88f5281_nand_resource = {
0141     .flags      = IORESOURCE_MEM,
0142     .start      = DB88F5281_NAND_BASE,
0143     .end        = DB88F5281_NAND_BASE + DB88F5281_NAND_SIZE - 1,
0144 };
0145 
0146 static struct orion_nand_data db88f5281_nand_data = {
0147     .parts      = db88f5281_nand_parts,
0148     .nr_parts   = ARRAY_SIZE(db88f5281_nand_parts),
0149     .cle        = 0,
0150     .ale        = 1,
0151     .width      = 8,
0152 };
0153 
0154 static struct platform_device db88f5281_nand_flash = {
0155     .name       = "orion_nand",
0156     .id     = -1,
0157     .dev        = {
0158         .platform_data  = &db88f5281_nand_data,
0159     },
0160     .resource   = &db88f5281_nand_resource,
0161     .num_resources  = 1,
0162 };
0163 
0164 /*****************************************************************************
0165  * 7-Segment on Device bus CS0
0166  * Dummy counter every 2 sec
0167  ****************************************************************************/
0168 
0169 static void __iomem *db88f5281_7seg;
0170 static struct timer_list db88f5281_timer;
0171 
0172 static void db88f5281_7seg_event(struct timer_list *unused)
0173 {
0174     static int count = 0;
0175     writel(0, db88f5281_7seg + (count << 4));
0176     count = (count + 1) & 7;
0177     mod_timer(&db88f5281_timer, jiffies + 2 * HZ);
0178 }
0179 
0180 static int __init db88f5281_7seg_init(void)
0181 {
0182     if (machine_is_db88f5281()) {
0183         db88f5281_7seg = ioremap(DB88F5281_7SEG_BASE,
0184                     DB88F5281_7SEG_SIZE);
0185         if (!db88f5281_7seg) {
0186             printk(KERN_ERR "Failed to ioremap db88f5281_7seg\n");
0187             return -EIO;
0188         }
0189         timer_setup(&db88f5281_timer, db88f5281_7seg_event, 0);
0190         mod_timer(&db88f5281_timer, jiffies + 2 * HZ);
0191     }
0192 
0193     return 0;
0194 }
0195 
0196 __initcall(db88f5281_7seg_init);
0197 
0198 /*****************************************************************************
0199  * PCI
0200  ****************************************************************************/
0201 
0202 static void __init db88f5281_pci_preinit(void)
0203 {
0204     int pin;
0205 
0206     /*
0207      * Configure PCI GPIO IRQ pins
0208      */
0209     pin = DB88F5281_PCI_SLOT0_IRQ_PIN;
0210     if (gpio_request(pin, "PCI Int1") == 0) {
0211         if (gpio_direction_input(pin) == 0) {
0212             irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
0213         } else {
0214             printk(KERN_ERR "db88f5281_pci_preinit failed to "
0215                     "set_irq_type pin %d\n", pin);
0216             gpio_free(pin);
0217         }
0218     } else {
0219         printk(KERN_ERR "db88f5281_pci_preinit failed to gpio_request %d\n", pin);
0220     }
0221 
0222     pin = DB88F5281_PCI_SLOT1_SLOT2_IRQ_PIN;
0223     if (gpio_request(pin, "PCI Int2") == 0) {
0224         if (gpio_direction_input(pin) == 0) {
0225             irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
0226         } else {
0227             printk(KERN_ERR "db88f5281_pci_preinit failed "
0228                     "to set_irq_type pin %d\n", pin);
0229             gpio_free(pin);
0230         }
0231     } else {
0232         printk(KERN_ERR "db88f5281_pci_preinit failed to gpio_request %d\n", pin);
0233     }
0234 }
0235 
0236 static int __init db88f5281_pci_map_irq(const struct pci_dev *dev, u8 slot,
0237     u8 pin)
0238 {
0239     int irq;
0240 
0241     /*
0242      * Check for devices with hard-wired IRQs.
0243      */
0244     irq = orion5x_pci_map_irq(dev, slot, pin);
0245     if (irq != -1)
0246         return irq;
0247 
0248     /*
0249      * PCI IRQs are connected via GPIOs.
0250      */
0251     switch (slot - DB88F5281_PCI_SLOT0_OFFS) {
0252     case 0:
0253         return gpio_to_irq(DB88F5281_PCI_SLOT0_IRQ_PIN);
0254     case 1:
0255     case 2:
0256         return gpio_to_irq(DB88F5281_PCI_SLOT1_SLOT2_IRQ_PIN);
0257     default:
0258         return -1;
0259     }
0260 }
0261 
0262 static struct hw_pci db88f5281_pci __initdata = {
0263     .nr_controllers = 2,
0264     .preinit    = db88f5281_pci_preinit,
0265     .setup      = orion5x_pci_sys_setup,
0266     .scan       = orion5x_pci_sys_scan_bus,
0267     .map_irq    = db88f5281_pci_map_irq,
0268 };
0269 
0270 static int __init db88f5281_pci_init(void)
0271 {
0272     if (machine_is_db88f5281())
0273         pci_common_init(&db88f5281_pci);
0274 
0275     return 0;
0276 }
0277 
0278 subsys_initcall(db88f5281_pci_init);
0279 
0280 /*****************************************************************************
0281  * Ethernet
0282  ****************************************************************************/
0283 static struct mv643xx_eth_platform_data db88f5281_eth_data = {
0284     .phy_addr   = MV643XX_ETH_PHY_ADDR(8),
0285 };
0286 
0287 /*****************************************************************************
0288  * RTC DS1339 on I2C bus
0289  ****************************************************************************/
0290 static struct i2c_board_info __initdata db88f5281_i2c_rtc = {
0291     I2C_BOARD_INFO("ds1339", 0x68),
0292 };
0293 
0294 /*****************************************************************************
0295  * General Setup
0296  ****************************************************************************/
0297 static unsigned int db88f5281_mpp_modes[] __initdata = {
0298     MPP0_GPIO,      /* USB Over Current */
0299     MPP1_GPIO,      /* USB Vbat input */
0300     MPP2_PCI_ARB,       /* PCI_REQn[2] */
0301     MPP3_PCI_ARB,       /* PCI_GNTn[2] */
0302     MPP4_PCI_ARB,       /* PCI_REQn[3] */
0303     MPP5_PCI_ARB,       /* PCI_GNTn[3] */
0304     MPP6_GPIO,      /* JP0, CON17.2 */
0305     MPP7_GPIO,      /* JP1, CON17.1 */
0306     MPP8_GPIO,      /* JP2, CON11.2 */
0307     MPP9_GPIO,      /* JP3, CON11.3 */
0308     MPP10_GPIO,     /* RTC int */
0309     MPP11_GPIO,     /* Baud Rate Generator */
0310     MPP12_GPIO,     /* PCI int 1 */
0311     MPP13_GPIO,     /* PCI int 2 */
0312     MPP14_NAND,     /* NAND_REn[2] */
0313     MPP15_NAND,     /* NAND_WEn[2] */
0314     MPP16_UART,     /* UART1_RX */
0315     MPP17_UART,     /* UART1_TX */
0316     MPP18_UART,     /* UART1_CTSn */
0317     MPP19_UART,     /* UART1_RTSn */
0318     0,
0319 };
0320 
0321 static void __init db88f5281_init(void)
0322 {
0323     /*
0324      * Basic Orion setup. Need to be called early.
0325      */
0326     orion5x_init();
0327 
0328     orion5x_mpp_conf(db88f5281_mpp_modes);
0329     writel(0, MPP_DEV_CTRL);        /* DEV_D[31:16] */
0330 
0331     /*
0332      * Configure peripherals.
0333      */
0334     orion5x_ehci0_init();
0335     orion5x_eth_init(&db88f5281_eth_data);
0336     orion5x_i2c_init();
0337     orion5x_uart0_init();
0338     orion5x_uart1_init();
0339 
0340     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
0341                     ORION_MBUS_DEVBUS_BOOT_ATTR,
0342                     DB88F5281_NOR_BOOT_BASE,
0343                     DB88F5281_NOR_BOOT_SIZE);
0344     platform_device_register(&db88f5281_boot_flash);
0345 
0346     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(0),
0347                     ORION_MBUS_DEVBUS_ATTR(0),
0348                     DB88F5281_7SEG_BASE,
0349                     DB88F5281_7SEG_SIZE);
0350 
0351     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(1),
0352                     ORION_MBUS_DEVBUS_ATTR(1),
0353                     DB88F5281_NOR_BASE,
0354                     DB88F5281_NOR_SIZE);
0355     platform_device_register(&db88f5281_nor_flash);
0356 
0357     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(2),
0358                     ORION_MBUS_DEVBUS_ATTR(2),
0359                     DB88F5281_NAND_BASE,
0360                     DB88F5281_NAND_SIZE);
0361     platform_device_register(&db88f5281_nand_flash);
0362 
0363     i2c_register_board_info(0, &db88f5281_i2c_rtc, 1);
0364 }
0365 
0366 MACHINE_START(DB88F5281, "Marvell Orion-2 Development Board")
0367     /* Maintainer: Tzachi Perelstein <tzachi@marvell.com> */
0368     .atag_offset    = 0x100,
0369     .nr_irqs    = ORION5X_NR_IRQS,
0370     .init_machine   = db88f5281_init,
0371     .map_io     = orion5x_map_io,
0372     .init_early = orion5x_init_early,
0373     .init_irq   = orion5x_init_irq,
0374     .init_time  = orion5x_timer_init,
0375     .restart    = orion5x_restart,
0376 MACHINE_END