Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
[sfrench/cifs-2.6.git] / arch / arm / mach-kirkwood / tsx1x-common.c
1 #include <linux/kernel.h>
2 #include <linux/pci.h>
3 #include <linux/platform_device.h>
4 #include <linux/mtd/physmap.h>
5 #include <linux/spi/flash.h>
6 #include <linux/spi/spi.h>
7 #include <linux/spi/orion_spi.h>
8 #include <linux/serial_reg.h>
9 #include <mach/kirkwood.h>
10 #include "common.h"
11
12 /*
13  * QNAP TS-x1x Boards flash
14  */
15
16 /****************************************************************************
17  * 16 MiB NOR flash. The struct mtd_partition is not in the same order as the
18  *     partitions on the device because we want to keep compatability with
19  *     the QNAP firmware.
20  * Layout as used by QNAP:
21  *  0x00000000-0x00080000 : "U-Boot"
22  *  0x00200000-0x00400000 : "Kernel"
23  *  0x00400000-0x00d00000 : "RootFS"
24  *  0x00d00000-0x01000000 : "RootFS2"
25  *  0x00080000-0x000c0000 : "U-Boot Config"
26  *  0x000c0000-0x00200000 : "NAS Config"
27  *
28  * We'll use "RootFS1" instead of "RootFS" to stay compatible with the layout
29  * used by the QNAP TS-109/TS-209.
30  *
31  ***************************************************************************/
32
33 struct mtd_partition qnap_tsx1x_partitions[] = {
34         {
35                 .name           = "U-Boot",
36                 .size           = 0x00080000,
37                 .offset         = 0,
38                 .mask_flags     = MTD_WRITEABLE,
39         }, {
40                 .name           = "Kernel",
41                 .size           = 0x00200000,
42                 .offset         = 0x00200000,
43         }, {
44                 .name           = "RootFS1",
45                 .size           = 0x00900000,
46                 .offset         = 0x00400000,
47         }, {
48                 .name           = "RootFS2",
49                 .size           = 0x00300000,
50                 .offset         = 0x00d00000,
51         }, {
52                 .name           = "U-Boot Config",
53                 .size           = 0x00040000,
54                 .offset         = 0x00080000,
55         }, {
56                 .name           = "NAS Config",
57                 .size           = 0x00140000,
58                 .offset         = 0x000c0000,
59         },
60 };
61
62 const struct flash_platform_data qnap_tsx1x_flash = {
63         .type           = "m25p128",
64         .name           = "spi_flash",
65         .parts          = qnap_tsx1x_partitions,
66         .nr_parts       = ARRAY_SIZE(qnap_tsx1x_partitions),
67 };
68
69 struct spi_board_info __initdata qnap_tsx1x_spi_slave_info[] = {
70         {
71                 .modalias       = "m25p80",
72                 .platform_data  = &qnap_tsx1x_flash,
73                 .irq            = -1,
74                 .max_speed_hz   = 20000000,
75                 .bus_num        = 0,
76                 .chip_select    = 0,
77         },
78 };
79
80 void __init qnap_tsx1x_register_flash(void)
81 {
82         spi_register_board_info(qnap_tsx1x_spi_slave_info,
83                                 ARRAY_SIZE(qnap_tsx1x_spi_slave_info));
84         kirkwood_spi_init();
85 }
86
87
88 /*****************************************************************************
89  * QNAP TS-x1x specific power off method via UART1-attached PIC
90  ****************************************************************************/
91
92 #define UART1_REG(x)    (UART1_VIRT_BASE + ((UART_##x) << 2))
93
94 void qnap_tsx1x_power_off(void)
95 {
96         /* 19200 baud divisor */
97         const unsigned divisor = ((kirkwood_tclk + (8 * 19200)) / (16 * 19200));
98
99         pr_info("%s: triggering power-off...\n", __func__);
100
101         /* hijack UART1 and reset into sane state (19200,8n1) */
102         writel(0x83, UART1_REG(LCR));
103         writel(divisor & 0xff, UART1_REG(DLL));
104         writel((divisor >> 8) & 0xff, UART1_REG(DLM));
105         writel(0x03, UART1_REG(LCR));
106         writel(0x00, UART1_REG(IER));
107         writel(0x00, UART1_REG(FCR));
108         writel(0x00, UART1_REG(MCR));
109
110         /* send the power-off command 'A' to PIC */
111         writel('A', UART1_REG(TX));
112 }
113