Changeset 9118


Ignore:
Timestamp:
2007-10-04T12:56:38+02:00 (10 years ago)
Author:
juhosg
Message:

[adm5120] NAND driver cleanups, thanks to Alexandros C. Couloumbis for testing

  • use generic NAND driver from now
  • add experimental support for RouterBOARD 150 NAND device
Location:
trunk/target/linux/adm5120
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/target/linux/adm5120/files/arch/mips/adm5120/boards/mikrotik.c

    r9039 r9118  
    22 *  $Id$ 
    33 * 
    4  *  Mikrotik RouterBOARDs 1xx series 
     4 *  Mikrotik RouterBOARD 1xx series 
    55 * 
    66 *  Copyright (C) 2007 OpenWrt.org 
    77 *  Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org> 
     8 * 
     9 *  NAND initialization code was based on a driver for Linux 2.6.19+ which 
     10 *  was derived from the driver for Linux 2.4.xx published by Mikrotik for 
     11 *  their RouterBoard 1xx and 5xx series boards. 
     12 *    Copyright (C) 2007 David Goodenough <david.goodenough@linkchoose.co.uk> 
     13 *    Copyright (C) 2007 Florian Fainelli <florian@openwrt.org> 
     14 *    The original Mikrotik code seems not to have a license. 
    815 * 
    916 *  This program is free software; you can redistribute it and/or 
     
    2633#include <linux/kernel.h> 
    2734#include <linux/init.h> 
     35#include <linux/delay.h> 
    2836 
    2937#include <asm/bootinfo.h> 
    3038#include <asm/gpio.h> 
    3139 
     40#include <adm5120_defs.h> 
     41#include <adm5120_irq.h> 
     42#include <adm5120_nand.h> 
    3243#include <adm5120_board.h> 
    3344#include <adm5120_platform.h> 
    34 #include <adm5120_irq.h> 
     45 
     46#define RB1XX_NAND_CHIP_DELAY   25 
     47 
     48#define RB150_NAND_BASE         0x1FC80000 
     49#define RB150_NAND_SIZE         1 
     50 
     51#define RB150_GPIO_NAND_READY   ADM5120_GPIO_PIN0 
     52#define RB150_GPIO_NAND_NCE     ADM5120_GPIO_PIN1 
     53#define RB150_GPIO_NAND_CLE     ADM5120_GPIO_P2L2 
     54#define RB150_GPIO_NAND_ALE     ADM5120_GPIO_P3L2 
     55 
     56#define RB150_NAND_DELAY        100 
     57 
     58#define RB150_NAND_WRITE(v) \ 
     59        writeb((v),(void __iomem *)KSEG1ADDR(RB150_NAND_BASE)) 
     60 
     61/*--------------------------------------------------------------------------*/ 
    3562 
    3663static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = { 
     
    4067}; 
    4168 
    42 static struct mtd_partition rb1xx_partitions[] = { 
     69static struct mtd_partition rb1xx_nor_partitions[] = { 
    4370        { 
    4471                .name   = "booter", 
     
    5380}; 
    5481 
     82static struct mtd_partition rb1xx_nand_partitions[] = { 
     83        { 
     84                .name   = "kernel", 
     85                .offset = 0, 
     86                .size   = 4 * 1024 * 1024, 
     87        } , { 
     88                .name   = "rootfs", 
     89                .offset = MTDPART_OFS_NXTBLK, 
     90                .size   = MTDPART_SIZ_FULL 
     91        } 
     92}; 
     93 
    5594static struct platform_device *rb1xx_devices[] __initdata = { 
    5695        &adm5120_flash0_device, 
     
    5897}; 
    5998 
    60 static struct platform_device *rb150_devices[] __initdata = { 
    61         &adm5120_flash0_device, 
    62         /* TODO: nand device is not yet supported */ 
    63 }; 
    64  
    65 static void __init rb1xx_setup(void) 
    66 { 
    67         /* setup data for flash0 device */ 
    68         adm5120_flash0_data.nr_parts = ARRAY_SIZE(rb1xx_partitions); 
    69         adm5120_flash0_data.parts = rb1xx_partitions; 
    70  
    71         /* TODO: setup mac address */ 
    72 } 
     99/* 
     100 * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader 
     101 * will not be able to find the kernel that we load.  So set the oobinfo 
     102 * when creating the partitions 
     103 */ 
     104static struct nand_ecclayout rb1xx_nand_ecclayout = { 
     105        .eccbytes       = 6, 
     106        .eccpos         = { 8, 9, 10, 13, 14, 15 }, 
     107        .oobavail       = 9, 
     108        .oobfree        = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } } 
     109}; 
     110 
     111static struct resource rb150_nand_resource[] = { 
     112        [0] = { 
     113                .start  = RB150_NAND_BASE, 
     114                .end    = RB150_NAND_BASE + RB150_NAND_SIZE-1, 
     115                .flags  = IORESOURCE_MEM, 
     116        }, 
     117}; 
    73118 
    74119#if 0 
     
    111156#endif 
    112157 
     158/*--------------------------------------------------------------------------*/ 
     159 
     160static int rb150_nand_ready(struct mtd_info *mtd) { 
     161 
     162        return gpio_get_value(RB150_GPIO_NAND_READY); 
     163} 
     164 
     165static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 
     166                unsigned int ctrl) 
     167{ 
     168        if (ctrl & NAND_CTRL_CHANGE) { 
     169                gpio_set_value(RB150_GPIO_NAND_CLE, (ctrl & NAND_CLE) ? 1 : 0); 
     170                gpio_set_value(RB150_GPIO_NAND_ALE, (ctrl & NAND_ALE) ? 1 : 0); 
     171                gpio_set_value(RB150_GPIO_NAND_NCE, (ctrl & NAND_NCE) ? 0 : 1); 
     172        } 
     173 
     174        udelay(RB150_NAND_DELAY); 
     175 
     176        if (cmd != NAND_CMD_NONE) 
     177                RB150_NAND_WRITE(cmd); 
     178} 
     179 
     180/*--------------------------------------------------------------------------*/ 
     181 
     182static void __init rb1xx_mac_setup(void) 
     183{ 
     184        /* TODO */ 
     185} 
     186 
     187static void __init rb1xx_flash_setup(void) 
     188{ 
     189        /* setup data for flash0 device */ 
     190        adm5120_flash0_data.nr_parts = ARRAY_SIZE(rb1xx_nor_partitions); 
     191        adm5120_flash0_data.parts = rb1xx_nor_partitions; 
     192 
     193        /* setup data for NAND device */ 
     194        adm5120_nand_data.chip.nr_chips = 1; 
     195        adm5120_nand_data.chip.nr_partitions = ARRAY_SIZE(rb1xx_nand_partitions); 
     196        adm5120_nand_data.chip.partitions = rb1xx_nand_partitions; 
     197        adm5120_nand_data.chip.ecclayout = &rb1xx_nand_ecclayout; 
     198        adm5120_nand_data.chip.chip_delay = RB1XX_NAND_CHIP_DELAY; 
     199        adm5120_nand_data.chip.options = NAND_NO_AUTOINCR; 
     200} 
     201 
     202static void __init rb1xx_setup(void) 
     203{ 
     204        /* enable NAND flash interface */ 
     205        adm5120_nand_enable(); 
     206 
     207        /* initialize NAND chip */ 
     208        adm5120_nand_set_spn(1); 
     209        adm5120_nand_set_wpn(0); 
     210 
     211        rb1xx_flash_setup(); 
     212        rb1xx_mac_setup(); 
     213} 
     214 
     215static void __init rb150_setup(void) 
     216{ 
     217        /* setup GPIO pins for NAND flash chip */ 
     218        gpio_request(RB150_GPIO_NAND_READY, "nand-ready"); 
     219        gpio_direction_input(RB150_GPIO_NAND_READY); 
     220        gpio_request(RB150_GPIO_NAND_NCE, "nand-nce"); 
     221        gpio_direction_output(RB150_GPIO_NAND_NCE, 1); 
     222        gpio_request(RB150_GPIO_NAND_CLE, "nand-cle"); 
     223        gpio_direction_output(RB150_GPIO_NAND_CLE, 0); 
     224        gpio_request(RB150_GPIO_NAND_ALE, "nand-ale"); 
     225        gpio_direction_output(RB150_GPIO_NAND_ALE, 0); 
     226 
     227        adm5120_nand_device.num_resources = ARRAY_SIZE(rb150_nand_resource); 
     228        adm5120_nand_device.resource = rb150_nand_resource; 
     229        adm5120_nand_data.ctrl.cmd_ctrl = rb150_nand_cmd_ctrl; 
     230        adm5120_nand_data.ctrl.dev_ready = rb150_nand_ready; 
     231 
     232        rb1xx_flash_setup(); 
     233        rb1xx_mac_setup(); 
     234} 
     235 
     236/*--------------------------------------------------------------------------*/ 
     237 
    113238static struct adm5120_board rb111_board __initdata = { 
    114239        .mach_type      = MACH_ADM5120_RB_111, 
     
    162287        .mach_type      = MACH_ADM5120_RB_150, 
    163288        .name           = "Mikrotik RouterBOARD 150", 
    164         .board_setup    = rb1xx_setup, 
     289        .board_setup    = rb150_setup, 
    165290        .eth_num_ports  = 5, 
    166291        .eth_vlans      = rb15x_vlans, 
    167         .num_devices    = ARRAY_SIZE(rb150_devices), 
    168         .devices        = rb150_devices, 
     292        .num_devices    = ARRAY_SIZE(rb1xx_devices), 
     293        .devices        = rb1xx_devices, 
    169294}; 
    170295 
  • trunk/target/linux/adm5120/files/arch/mips/adm5120/platform.c

    r9009 r9118  
    3333#include <asm/gpio.h> 
    3434 
    35 #include <asm/mach-adm5120/adm5120_defs.h> 
    36 #include <asm/mach-adm5120/adm5120_info.h> 
    37 #include <asm/mach-adm5120/adm5120_irq.h> 
    38 #include <asm/mach-adm5120/adm5120_switch.h> 
    39 #include <asm/mach-adm5120/adm5120_platform.h> 
    40  
    41 static void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base, 
    42                 unsigned int mctrl); 
     35#include <adm5120_defs.h> 
     36#include <adm5120_info.h> 
     37#include <adm5120_irq.h> 
     38#include <adm5120_switch.h> 
     39#include <adm5120_nand.h> 
     40#include <adm5120_platform.h> 
    4341 
    4442#if 1 
     
    121119struct resource adm5120_nand_resource[] = { 
    122120        [0] = { 
    123                 .start  = ADM5120_SRAM1_BASE, 
    124                 .end    = ADM5120_SRAM1_BASE+ADM5120_MPMC_SIZE-1, 
     121                .start  = ADM5120_NAND_BASE, 
     122                .end    = ADM5120_NAND_BASE + ADM5120_NAND_SIZE-1, 
    125123                .flags  = IORESOURCE_MEM, 
    126124        }, 
    127125}; 
    128126 
    129 struct adm5120_nand_platform_data adm5120_nand_data; 
     127struct platform_nand_data adm5120_nand_data = { 
     128        .ctrl.dev_ready = adm5120_nand_ready, 
     129        .ctrl.cmd_ctrl  = adm5120_nand_cmd_ctrl, 
     130}; 
    130131 
    131132struct platform_device adm5120_nand_device = { 
    132         .name           = "adm5120-nand", 
     133        .name           = "gen_nand", 
    133134        .id             = -1, 
    134         .dev.platform_data = &adm5120_nand_data, 
    135135        .num_resources  = ARRAY_SIZE(adm5120_nand_resource), 
    136136        .resource       = adm5120_nand_resource, 
     137        .dev.platform_data = &adm5120_nand_data, 
    137138}; 
    138139 
     
    174175}; 
    175176 
    176 static void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base, 
     177void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base, 
    177178                unsigned int mctrl) 
    178179{ 
    179180} 
     181 
     182int adm5120_nand_ready(struct mtd_info *mtd) 
     183{ 
     184        return ((adm5120_nand_get_status() & ADM5120_NAND_STATUS_READY) != 0); 
     185} 
     186 
     187void adm5120_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 
     188{ 
     189        if (ctrl & NAND_CTRL_CHANGE) { 
     190                adm5120_nand_set_cle(ctrl & NAND_CLE); 
     191                adm5120_nand_set_ale(ctrl & NAND_ALE); 
     192                adm5120_nand_set_cen(ctrl & NAND_NCE); 
     193        } 
     194 
     195        if (cmd != NAND_CMD_NONE) 
     196                NAND_WRITE_REG(NAND_REG_DATA, cmd); 
     197} 
     198 
  • trunk/target/linux/adm5120/files/include/asm-mips/mach-adm5120/adm5120_defs.h

    r8538 r9118  
    3030#define ADM5120_SDRAM1_BASE     0x01000000 
    3131#define ADM5120_SRAM1_BASE      0x10000000 
     32#define ADM5120_NAND_BASE       ADM5120_SRAM1_BASE 
    3233#define ADM5120_MPMC_BASE       0x11000000 
    3334#define ADM5120_USBC_BASE       0x11200000 
     
    4243#define ADM5120_SRAM0_BASE      0x1FC00000 
    4344 
     45#define ADM5120_NAND_SIZE       0xB 
    4446#define ADM5120_MPMC_SIZE       0x1000 
    4547#define ADM5120_USBC_SIZE       0x84 
  • trunk/target/linux/adm5120/files/include/asm-mips/mach-adm5120/adm5120_platform.h

    r9017 r9118  
    3232#include <linux/mtd/map.h> 
    3333#include <linux/mtd/partitions.h> 
     34#include <linux/mtd/nand.h> 
    3435 
    3536#include <linux/amba/bus.h> 
     
    4344        struct mtd_partition    *parts; 
    4445#endif 
    45 }; 
    46  
    47 struct adm5120_nand_platform_data { 
    48         /* TODO : not yet implemented */ 
    4946}; 
    5047 
     
    7471extern struct adm5120_flash_platform_data adm5120_flash0_data; 
    7572extern struct adm5120_flash_platform_data adm5120_flash1_data; 
    76 extern struct adm5120_nand_platform_data adm5120_nand_data; 
     73extern struct platform_nand_data adm5120_nand_data; 
    7774extern struct adm5120_switch_platform_data adm5120_switch_data; 
    7875extern struct amba_pl010_data adm5120_uart0_data; 
     
    8784extern struct amba_device adm5120_uart1_device; 
    8885 
     86extern void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base, 
     87                unsigned int mctrl); 
     88 
     89extern void adm5120_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 
     90                unsigned int ctrl); 
     91extern int adm5120_nand_ready(struct mtd_info *mtd); 
     92 
    8993#endif /* _ADM5120_PLATFORM_H_ */ 
  • trunk/target/linux/adm5120/files/include/asm-mips/mach-adm5120/adm5120_switch.h

    r8704 r9118  
    172172#define P5RBC_SHIFT             12 
    173173 
     174#define BW_CNTL1_NAND_ENABLE    0x100 
     175 
    174176/* PHY_CNTL0 register bits */ 
    175177#define PHY_CNTL0_PHYA_MASK     BITMASK(5) 
  • trunk/target/linux/adm5120/router_le/config-2.6.22

    r9085 r9118  
    155155CONFIG_MTD_MYLOADER_PARTS=y 
    156156CONFIG_MTD_NAND=y 
    157 CONFIG_MTD_NAND_ADM5120=y 
     157# CONFIG_MTD_NAND_ADM5120 is not set 
    158158# CONFIG_MTD_NAND_CAFE is not set 
    159159# CONFIG_MTD_NAND_DISKONCHIP is not set 
     
    162162# CONFIG_MTD_NAND_MUSEUM_IDS is not set 
    163163# CONFIG_MTD_NAND_NANDSIM is not set 
    164 # CONFIG_MTD_NAND_PLATFORM is not set 
     164CONFIG_MTD_NAND_PLATFORM=y 
    165165# CONFIG_MTD_NAND_VERIFY_WRITE is not set 
    166166# CONFIG_MTD_ONENAND is not set 
Note: See TracChangeset for help on using the changeset viewer.