brcm63xx: add initial support for BCM6318
[openwrt.git] / target / linux / brcm63xx / patches-3.10 / 415-MIPS-BCM63XX-store-the-flash-type-in-global-variable.patch
1 From f888824d352df894ab721a5ca067b0313500efe7 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Thu, 3 May 2012 12:17:54 +0200
4 Subject: [PATCH 38/59] MIPS: BCM63XX: store the flash type in global variable
5
6 ---
7  arch/mips/bcm63xx/dev-flash.c                      |   36 +++++++++++++------
8  .../include/asm/mach-bcm63xx/bcm63xx_dev_flash.h   |    2 +
9  2 files changed, 26 insertions(+), 12 deletions(-)
10
11 --- a/arch/mips/bcm63xx/dev-flash.c
12 +++ b/arch/mips/bcm63xx/dev-flash.c
13 @@ -25,6 +25,8 @@
14  #include <bcm63xx_regs.h>
15  #include <bcm63xx_io.h>
16  
17 +int bcm63xx_attached_flash = -1;
18 +
19  static struct mtd_partition mtd_partitions[] = {
20         {
21                 .name           = "cfe",
22 @@ -81,7 +83,8 @@ static int __init bcm63xx_detect_flash_t
23         case BCM6318_CPU_ID:
24                 /* only support serial flash */
25                 bcm63xx_spi_flash_info[0].max_speed_hz = 62500000;
26 -               return BCM63XX_FLASH_TYPE_SERIAL;
27 +               bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_SERIAL;
28 +               break;
29         case BCM6328_CPU_ID:
30                 val = bcm_misc_readl(MISC_STRAPBUS_6328_REG);
31                 if (val & STRAPBUS_6328_HSSPI_CLK_FAST)
32 @@ -90,21 +93,24 @@ static int __init bcm63xx_detect_flash_t
33                         bcm63xx_spi_flash_info[0].max_speed_hz = 16666667;
34  
35                 if (val & STRAPBUS_6328_BOOT_SEL_SERIAL)
36 -                       return BCM63XX_FLASH_TYPE_SERIAL;
37 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_SERIAL;
38                 else
39 -                       return BCM63XX_FLASH_TYPE_NAND;
40 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_NAND;
41 +               break;
42         case BCM6338_CPU_ID:
43         case BCM6345_CPU_ID:
44         case BCM6348_CPU_ID:
45                 /* no way to auto detect so assume parallel */
46 -               return BCM63XX_FLASH_TYPE_PARALLEL;
47 +               bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_PARALLEL;
48 +               break;
49         case BCM3368_CPU_ID:
50         case BCM6358_CPU_ID:
51                 val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
52                 if (val & STRAPBUS_6358_BOOT_SEL_PARALLEL)
53 -                       return BCM63XX_FLASH_TYPE_PARALLEL;
54 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_PARALLEL;
55                 else
56 -                       return BCM63XX_FLASH_TYPE_SERIAL;
57 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_SERIAL;
58 +               break;
59         case BCM6362_CPU_ID:
60                 val = bcm_misc_readl(MISC_STRAPBUS_6362_REG);
61                 if (val & STRAPBUS_6362_HSSPI_CLK_FAST)
62 @@ -113,9 +119,10 @@ static int __init bcm63xx_detect_flash_t
63                         bcm63xx_spi_flash_info[0].max_speed_hz = 20000000;
64  
65                 if (val & STRAPBUS_6362_BOOT_SEL_SERIAL)
66 -                       return BCM63XX_FLASH_TYPE_SERIAL;
67 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_SERIAL;
68                 else
69 -                       return BCM63XX_FLASH_TYPE_NAND;
70 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_NAND;
71 +               break;
72         case BCM6368_CPU_ID:
73                 val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
74                 if (val & STRAPBUS_6368_SPI_CLK_FAST)
75 @@ -123,11 +130,16 @@ static int __init bcm63xx_detect_flash_t
76  
77                 switch (val & STRAPBUS_6368_BOOT_SEL_MASK) {
78                 case STRAPBUS_6368_BOOT_SEL_NAND:
79 -                       return BCM63XX_FLASH_TYPE_NAND;
80 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_NAND;
81 +                       break;
82                 case STRAPBUS_6368_BOOT_SEL_SERIAL:
83 -                       return BCM63XX_FLASH_TYPE_SERIAL;
84 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_SERIAL;
85 +                       break;
86                 case STRAPBUS_6368_BOOT_SEL_PARALLEL:
87 -                       return BCM63XX_FLASH_TYPE_PARALLEL;
88 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_PARALLEL;
89 +                       break;
90 +               default:
91 +                       return -EINVAL;
92                 }
93         case BCM63268_CPU_ID:
94                 val = bcm_misc_readl(MISC_STRAPBUS_63268_REG);
95 @@ -137,22 +149,24 @@ static int __init bcm63xx_detect_flash_t
96                         bcm63xx_spi_flash_info[0].max_speed_hz = 20000000;
97  
98                 if (val & STRAPBUS_63268_BOOT_SEL_SERIAL)
99 -                       return BCM63XX_FLASH_TYPE_SERIAL;
100 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_SERIAL;
101                 else
102 -                       return BCM63XX_FLASH_TYPE_NAND;
103 +                       bcm63xx_attached_flash = BCM63XX_FLASH_TYPE_NAND;
104         default:
105                 return -EINVAL;
106         }
107 +
108 +       return 0;
109  }
110  
111  int __init bcm63xx_flash_register(void)
112  {
113 -       int flash_type;
114         u32 val;
115  
116 -       flash_type = bcm63xx_detect_flash_type();
117  
118 -       switch (flash_type) {
119 +       bcm63xx_detect_flash_type();
120 +
121 +       switch (bcm63xx_attached_flash) {
122         case BCM63XX_FLASH_TYPE_PARALLEL:
123                 /* read base address of boot chip select (0) */
124                 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
125 @@ -177,7 +191,7 @@ int __init bcm63xx_flash_register(void)
126                 return -ENODEV;
127         default:
128                 pr_err("flash detection failed for BCM%x: %d\n",
129 -                      bcm63xx_get_cpu_id(), flash_type);
130 +                      bcm63xx_get_cpu_id(), bcm63xx_attached_flash);
131                 return -ENODEV;
132         }
133  }
134 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_flash.h
135 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_flash.h
136 @@ -7,6 +7,8 @@ enum {
137         BCM63XX_FLASH_TYPE_NAND,
138  };
139  
140 +extern int bcm63xx_attached_flash;
141 +
142  int __init bcm63xx_flash_register(void);
143  
144  #endif /* __BCM63XX_FLASH_H */