]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/arm/mach-mv78xx0/rdstor-setup.c
Add pm_power_off() to call IPM for cutting power (and formatting cleanups)
[mv-sheeva.git] / arch / arm / mach-mv78xx0 / rdstor-setup.c
1 /*
2  * Cogent CSB1725 CPU module board setup with customizations
3  * for BDT RDStor
4  *
5  * based on:
6  * arch/arm/mach-mv78xx0/db78x00-bp-setup.c
7  *
8  * This file is licensed under the terms of the GNU General Public
9  * License version 2.  This program is licensed "as is" without any
10  * warranty of any kind, whether express or implied.
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/ata_platform.h>
17 #include <linux/mv643xx_eth.h>
18 #include <linux/ethtool.h>
19 #include <linux/spi/spi.h>
20 #include <linux/spi/flash.h>
21 #include <linux/i2c.h>
22 #include <linux/i2c/pca953x.h>
23 #include <linux/mtd/nand.h>
24 #include <linux/mtd/physmap.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/gpio.h>
27 #include <linux/io.h>
28 #include <linux/irq.h>
29 #include <mach/mv78xx0.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <plat/orion_nand.h>
33 #include "common.h"
34 #include "mpp.h"
35
36
37 static unsigned int rdstor_mpp_config[] __initdata = {
38         /* GPIO8 -              n.a. */
39         /* GPIO9 -              n.a. */
40         /* GPI10 -              n.a. */
41         /* GPI11 -              n.a. */
42         MPP12_GPIO,     /* parallel LCD */
43         MPP13_GPIO,     /* parallel LCD */
44         MPP14_GPIO,     /* parallel LCD */
45         MPP15_GPIO,     /* parallel LCD */
46         MPP16_UNUSED,   /* GPIO16 -             n.a. */
47         MPP17_UNUSED,   /* GPIO17 */
48         MPP18_GPIO,     /* parallel LCD A0 */
49         MPP19_GPIO,     /* parallel LCD R/W */
50         MPP20_GPIO,     /* parallel LCD LCD_EN */
51         MPP21_GPIO,     /* parallel LCD CSn */
52         MPP22_GPIO,     /* GPIO22 WAKE0         PCI Express 0 Wake Input (on pin MPP22) */
53         MPP23_GPIO,     /* GPIO23 WAKE0         PCI Express 0 Wake Input (on pin MPP23) */
54         MPP24_UA2_TXD,
55         MPP25_UA2_RXD,
56         MPP26_GPIO,     /* LCD module RESETn */
57         MPP27_GPIO,     /* LCD module switch */
58         MPP28_GPIO,     /* parallel LCD */
59         MPP29_GPIO,     /* parallel LCD */
60         MPP30_GPIO,     /* parallel LCD */
61         MPP31_GPIO,     /* parallel LCD */
62         MPP32_GPIO,     /* GPIO0 I2C0_INT       I2C IRQ */
63         MPP33_GPIO,     /* GPIO1 T_CRIT         LM86 thermal IRQ */
64         MPP34_GPIO,     /* GPIO2 MII_INT        PHY Interrupt for off module MII Bus */
65         MPP35_GPIO,     /* GPIO3 PHY_INT        88E1121R Dual PHY Interrupt */
66         MPP36_GPIO,     /* PS1 PF input, GPIO4 INTA             MXM Interrupt A */
67         MPP37_GPIO,     /* PWR SWITCH CSB, GPIO5 INTB           MXM Interrupt B */
68         MPP38_GPIO,     /* GPIO6 INTC           MXM Interrupt C */
69         MPP39_GPIO,     /* GPIO7 INTD           MXM Interrupt D */
70         MPP47_GPIO,     /* GPIO16 N_RDY         NAND ready/busy */
71         MPP48_SATA1_ACTn,
72         MPP49_SATA0_ACTn,
73         0,
74 };
75
76
77 /*
78  * GigE
79  */
80 static struct mv643xx_eth_platform_data db78x00_ge00_data = {
81         .phy_addr       = MV643XX_ETH_PHY_ADDR(0),
82 };
83
84 static struct mv643xx_eth_platform_data db78x00_ge01_data = {
85         .phy_addr       = MV643XX_ETH_PHY_ADDR(1),
86 };
87
88
89 /*
90  * SATA
91  */
92 static struct mv_sata_platform_data db78x00_sata_data = {
93         .n_ports        = 2,
94 };
95
96
97 /*
98  * GPIO
99  */
100 static struct pca953x_platform_data rdstor_gpio_ext_pdata = {
101         .gpio_base = 128,
102 };
103
104
105 /*
106  * I2C
107  */
108 static struct i2c_board_info __initdata rdstor_i2c_bus0[] = {
109         {
110                 I2C_BOARD_INFO("pca9555", 0x27),
111                 .platform_data = &rdstor_gpio_ext_pdata,
112         },
113 };
114
115 static struct i2c_board_info __initdata rdstor_i2c_bus1[] = {
116         {
117                 I2C_BOARD_INFO("lm86", 0x4c)
118         }, {
119                 I2C_BOARD_INFO("24aa00", 0x50)
120         }, {
121                 I2C_BOARD_INFO("ds1338", 0x68)
122         }
123 };
124
125
126 /*
127  * NAND flash
128  */
129 static struct mtd_partition rdstor_nand_parts[] = {
130         {
131                 .name = "nand-kernel",
132                 .offset = 0,
133                 .size = SZ_4M,
134                 /* .mask_flags = MTD_WRITEABLE */
135         },
136         {
137                 .name = "nand-kernel-fallback",
138                 .offset = MTDPART_OFS_APPEND,
139                 .size = SZ_4M,
140                 /* .mask_flags = MTD_WRITEABLE */
141         },
142         {
143                 .name = "nand-rootfs",
144                 .offset = MTDPART_OFS_APPEND,
145                 .size = MTDPART_SIZ_FULL,
146                 /* .mask_flags = MTD_WRITEABLE */
147         }
148 };
149
150 static struct resource mv78xx0_nand_resource = {
151         .flags          = IORESOURCE_MEM,
152         .start          = MV78XX0_NAND_MEM_PHYS_BASE,
153         .end            = MV78XX0_NAND_MEM_PHYS_BASE +
154                                 MV78XX0_NAND_MEM_SIZE - 1,
155 };
156
157 static struct orion_nand_data mv78xx0_nand_data = {
158         .cle            = 0,
159         .ale            = 1,
160         .width          = 8,
161 };
162
163 static struct platform_device mv78xx0_nand_flash = {
164         .name           = "orion_nand",
165         .id             = -1,
166         .dev            = {
167                 .platform_data  = &mv78xx0_nand_data,
168         },
169         .resource       = &mv78xx0_nand_resource,
170         .num_resources  = 1,
171 };
172
173
174 static int rdstor_nand_dev_ready(struct mtd_info *mtd)
175 {
176         return gpio_get_value(16);
177 }
178
179 void __init mv78xx0_nand_init_rb(struct mtd_partition *parts, int nr_parts)
180 {
181         mv78xx0_nand_data.parts = parts;
182         mv78xx0_nand_data.nr_parts = nr_parts;
183         mv78xx0_nand_data.dev_ready = rdstor_nand_dev_ready;
184         
185         platform_device_register(&mv78xx0_nand_flash);
186 }
187
188
189 void __init mv78xx0_nand_init(struct mtd_partition *parts, int nr_parts,
190                                 int chip_delay)
191 {
192         mv78xx0_nand_data.parts = parts;
193         mv78xx0_nand_data.nr_parts = nr_parts;
194         mv78xx0_nand_data.chip_delay = chip_delay;
195         
196         platform_device_register(&mv78xx0_nand_flash);
197 }
198
199 /*
200  * NOR flash
201  */
202 static struct resource rdstor_mtd_resource = {
203         /* NOR Flash 64MB */
204         .start  = MV78XX0_BOOTCS_MEM_PHY_BASE /*0xfc000000*/,
205         .end    = MV78XX0_BOOTCS_MEM_PHY_BASE + MV78XX0_BOOTCS_MEM_SIZE /*0xfc000000 + SZ_64M*/ - 1,
206         .flags  = IORESOURCE_MEM,
207 };
208
209 static struct mtd_partition rdstor_nor_parts[] = {
210         {
211                 .name = "nor-user",
212                 .offset = 0,
213                 .size = 0x3f60000,
214                 /* .mask_flags = MTD_WRITEABLE */
215         },
216         {
217                 .name = "nor-uboot-env",
218                 .offset = MTDPART_OFS_APPEND,
219                 .size = 0x20000,
220                 /* .mask_flags = MTD_WRITEABLE */
221         },
222         {
223                 .name = "nor-uboot",
224                 .offset = MTDPART_OFS_APPEND,
225                 .size = MTDPART_SIZ_FULL,
226                 .mask_flags = MTD_WRITEABLE
227         }
228 };
229
230 static struct physmap_flash_data rdstor_flash_data[] = {
231         {
232                 .width          = 2,
233                 .parts          = rdstor_nor_parts,
234                 .nr_parts       = 3,
235         }
236 };
237
238 static struct platform_device rdstor_mtd_device = {
239         .name           = "physmap-flash",
240         .id             = 0,
241         .dev            = {
242                 .platform_data = &rdstor_flash_data,
243         },
244         .resource       = &rdstor_mtd_resource,
245         .num_resources  = 1,
246 };
247
248 /* SPI flash */
249 static struct mtd_partition rdstor_dataflash_partitions[] = {
250         {
251                 .name = "dataflash",
252                 .offset = 0,
253                 .size = MTDPART_SIZ_FULL,
254                 /* .mask_flags = MTD_WRITEABLE */
255         }
256 };
257
258 static struct flash_platform_data rdstor_spi_slave_data = {
259         // .type           = "m25p64",
260         .nr_parts       = ARRAY_SIZE(rdstor_dataflash_partitions),
261         .parts          = rdstor_dataflash_partitions,
262 };
263
264 static struct spi_board_info rdstor_spi_devices[] = {
265         {       /* DataFlash card */
266                 .modalias       = "m25p64",
267                 .irq            = NO_IRQ,
268                 .chip_select    = 0,
269                 .max_speed_hz   = 20000000,
270                 .bus_num        = 0,
271                 .platform_data  = &rdstor_spi_slave_data,
272         },
273 };
274
275 static void rdstor_poweroff(void)
276 {
277         struct i2c_msg msg;
278         struct i2c_adapter *adap = i2c_get_adapter(1);
279         unsigned char buf[2];
280
281         if (!adap) {
282                 printk(KERN_ERR "I2C adapter 1 not found\n");
283                 return;
284         }
285
286         buf[0] = 0x01;  /* cmd arg offset */
287         buf[1] = 0x00;  /* 0 seconds delay */
288         msg.addr = 0x38;
289         msg.flags = 0;
290         msg.len = 2;
291         msg.buf = buf;
292
293         i2c_transfer(adap, &msg, 1);
294
295         printk(KERN_INFO "RDStor powering off...\n");
296
297         buf[0] = 0x00;  /* cmd offset */
298         buf[1] = 0x02;  /* shutdown cmd */
299         msg.addr = 0x38;
300         msg.flags = 0;
301         msg.len = 2;
302         msg.buf = buf;
303
304         i2c_transfer(adap, &msg, 1);
305 }
306
307 static void __init db78x00_init(void)
308 {
309         /*
310          * Basic MV78xx0 setup. Needs to be called early.
311          */
312         mv78xx0_init();
313
314         /* setup MMPs */
315         mv78xx0_mpp_conf(rdstor_mpp_config);
316
317         /*
318          * Partition on-chip peripherals between the two CPU cores.
319          * On the RDstor we also have the single core option so for now
320          * all peripherals are assigned to core #0.
321          */
322         if (mv78xx0_core_index() == 0) {
323                 /* first CPU core */
324                 mv78xx0_uart0_init();
325                 mv78xx0_uart1_init();
326                 mv78xx0_uart2_init();
327                 //mv78xx0_uart3_init();
328
329                 mv78xx0_i2c_init();
330
331                 mv78xx0_ge00_init(&db78x00_ge00_data);
332                 mv78xx0_ge01_init(&db78x00_ge01_data);
333
334                 mv78xx0_sata_init(&db78x00_sata_data);
335
336                 /*mv78xx0_ehci0_init();*/ /* somewhere? */
337                 mv78xx0_ehci1_init(); /* ext USB */
338                 /* USB2 is device mode */
339
340                 i2c_register_board_info(0, ARRAY_AND_SIZE(rdstor_i2c_bus0));
341                 i2c_register_board_info(1, ARRAY_AND_SIZE(rdstor_i2c_bus1));
342
343                 /* NOR flash */
344                 platform_device_register(&rdstor_mtd_device);
345
346                 /* NAND flash */
347 #if 1
348                 printk(KERN_ERR "NAND read params:  0x%08x\n", readl(MV78XX0_REGS_VIRT_BASE | 0x10418));
349                 printk(KERN_ERR "NAND write params: 0x%08x\n", readl(MV78XX0_REGS_VIRT_BASE | 0x1041C));
350                 printk(KERN_ERR "NAND control:      0x%08x\n", readl(MV78XX0_REGS_VIRT_BASE | 0x10470));
351 #endif
352
353                 if (gpio_request(16, "NAND READY") != 0 ||
354                     gpio_direction_input(16) != 0) {
355                         printk(KERN_ERR "nand_init: failed to request GPIO16 for NAND_READY, falling back to udelay\n");
356                         mv78xx0_nand_init(ARRAY_AND_SIZE(rdstor_nand_parts), 30);
357                 } else
358                         mv78xx0_nand_init_rb(ARRAY_AND_SIZE(rdstor_nand_parts));
359
360                 spi_register_board_info(rdstor_spi_devices, ARRAY_SIZE(rdstor_spi_devices));
361                 mv78x00_spi_init();
362
363                 mv78xx0_crypto_init();
364
365                 mv78xx0_xor0_init();
366
367                 /* mv78xx0_wdt_init(); */
368                 pm_power_off = rdstor_poweroff;
369         } else {
370                 /* second CPU core */
371         }
372 }
373
374 static int __init db78x00_pci_init(void)
375 {
376         if (1 /*machine_is_db78x00_bp()*/ /*machine_is_rdstor()*/) {
377                 /*
378                  * Assign the x16 PCIe slot on the board to CPU core
379                  * #0, and let CPU core #1 have the four x1 slots.
380                  */
381                 if (mv78xx0_core_index() == 0) {
382                         printk(KERN_ERR "pcie_init core#0\n");
383                         mv78xx0_pcie_init(1, 1);
384                 } else {
385                         mv78xx0_pcie_init(1, 0);
386                         printk(KERN_ERR "pcie_init other core\n");
387                 }
388         } else
389                 printk(KERN_ERR "pcie_init machine mismatch\n");
390
391         return 0;
392 }
393 subsys_initcall(db78x00_pci_init);
394
395 MACHINE_START(RDSTOR, "BDT RDStor, with CSB1725 module")
396         /* Maintainer: Nils Faerber <nils.faerber@kernelconcepts.de> */
397         .boot_params    = 0x00000100,
398         .init_machine   = db78x00_init,
399         .map_io         = mv78xx0_map_io,
400         .init_irq       = mv78xx0_init_irq,
401         .timer          = &mv78xx0_timer,
402 MACHINE_END