Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6] / arch / powerpc / platforms / 83xx / mpc832x_rdb.c
1 /*
2  * arch/powerpc/platforms/83xx/mpc832x_rdb.c
3  *
4  * Copyright (C) Freescale Semiconductor, Inc. 2007. All rights reserved.
5  *
6  * Description:
7  * MPC832x RDB board specific routines.
8  * This file is based on mpc832x_mds.c and mpc8313_rdb.c
9  * Author: Michael Barkowski <michael.barkowski@freescale.com>
10  *
11  * This program is free software; you can redistribute  it and/or modify it
12  * under  the terms of  the GNU General  Public License as published by the
13  * Free Software Foundation;  either version 2 of the  License, or (at your
14  * option) any later version.
15  */
16
17 #include <linux/pci.h>
18 #include <linux/interrupt.h>
19 #include <linux/spi/spi.h>
20 #include <linux/spi/mmc_spi.h>
21 #include <linux/mmc/host.h>
22 #include <linux/of_platform.h>
23
24 #include <asm/time.h>
25 #include <asm/ipic.h>
26 #include <asm/udbg.h>
27 #include <asm/qe.h>
28 #include <asm/qe_ic.h>
29 #include <sysdev/fsl_soc.h>
30 #include <sysdev/fsl_pci.h>
31
32 #include "mpc83xx.h"
33
34 #undef DEBUG
35 #ifdef DEBUG
36 #define DBG(fmt...) udbg_printf(fmt)
37 #else
38 #define DBG(fmt...)
39 #endif
40
41 #ifdef CONFIG_QUICC_ENGINE
42 static void mpc83xx_spi_activate_cs(u8 cs, u8 polarity)
43 {
44         pr_debug("%s %d %d\n", __func__, cs, polarity);
45         par_io_data_set(3, 13, polarity);
46 }
47
48 static void mpc83xx_spi_deactivate_cs(u8 cs, u8 polarity)
49 {
50         pr_debug("%s %d %d\n", __func__, cs, polarity);
51         par_io_data_set(3, 13, !polarity);
52 }
53
54 static struct mmc_spi_platform_data mpc832x_mmc_pdata = {
55         .ocr_mask = MMC_VDD_33_34,
56 };
57
58 static struct spi_board_info mpc832x_spi_boardinfo = {
59         .bus_num = 0x4c0,
60         .chip_select = 0,
61         .max_speed_hz = 50000000,
62         .modalias = "mmc_spi",
63         .platform_data = &mpc832x_mmc_pdata,
64 };
65
66 static int __init mpc832x_spi_init(void)
67 {
68         par_io_config_pin(3,  0, 3, 0, 1, 0); /* SPI1 MOSI, I/O */
69         par_io_config_pin(3,  1, 3, 0, 1, 0); /* SPI1 MISO, I/O */
70         par_io_config_pin(3,  2, 3, 0, 1, 0); /* SPI1 CLK,  I/O */
71         par_io_config_pin(3,  3, 2, 0, 1, 0); /* SPI1 SEL,  I   */
72
73         par_io_config_pin(3, 13, 1, 0, 0, 0); /* !SD_CS,    O */
74         par_io_config_pin(3, 14, 2, 0, 0, 0); /* SD_INSERT, I */
75         par_io_config_pin(3, 15, 2, 0, 0, 0); /* SD_PROTECT,I */
76
77         return fsl_spi_init(&mpc832x_spi_boardinfo, 1,
78                             mpc83xx_spi_activate_cs,
79                             mpc83xx_spi_deactivate_cs);
80 }
81 machine_device_initcall(mpc832x_rdb, mpc832x_spi_init);
82 #endif /* CONFIG_QUICC_ENGINE */
83
84 /* ************************************************************************
85  *
86  * Setup the architecture
87  *
88  */
89 static void __init mpc832x_rdb_setup_arch(void)
90 {
91 #if defined(CONFIG_PCI) || defined(CONFIG_QUICC_ENGINE)
92         struct device_node *np;
93 #endif
94
95         if (ppc_md.progress)
96                 ppc_md.progress("mpc832x_rdb_setup_arch()", 0);
97
98 #ifdef CONFIG_PCI
99         for_each_compatible_node(np, "pci", "fsl,mpc8349-pci")
100                 mpc83xx_add_bridge(np);
101 #endif
102
103 #ifdef CONFIG_QUICC_ENGINE
104         qe_reset();
105
106         if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {
107                 par_io_init(np);
108                 of_node_put(np);
109
110                 for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
111                         par_io_of_config(np);
112         }
113 #endif                          /* CONFIG_QUICC_ENGINE */
114 }
115
116 static struct of_device_id mpc832x_ids[] = {
117         { .type = "soc", },
118         { .compatible = "soc", },
119         { .compatible = "simple-bus", },
120         { .type = "qe", },
121         { .compatible = "fsl,qe", },
122         {},
123 };
124
125 static int __init mpc832x_declare_of_platform_devices(void)
126 {
127         /* Publish the QE devices */
128         of_platform_bus_probe(NULL, mpc832x_ids, NULL);
129
130         return 0;
131 }
132 machine_device_initcall(mpc832x_rdb, mpc832x_declare_of_platform_devices);
133
134 static void __init mpc832x_rdb_init_IRQ(void)
135 {
136
137         struct device_node *np;
138
139         np = of_find_node_by_type(NULL, "ipic");
140         if (!np)
141                 return;
142
143         ipic_init(np, 0);
144
145         /* Initialize the default interrupt mapping priorities,
146          * in case the boot rom changed something on us.
147          */
148         ipic_set_default_priority();
149         of_node_put(np);
150
151 #ifdef CONFIG_QUICC_ENGINE
152         np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
153         if (!np) {
154                 np = of_find_node_by_type(NULL, "qeic");
155                 if (!np)
156                         return;
157         }
158         qe_ic_init(np, 0, qe_ic_cascade_low_ipic, qe_ic_cascade_high_ipic);
159         of_node_put(np);
160 #endif                          /* CONFIG_QUICC_ENGINE */
161 }
162
163 /*
164  * Called very early, MMU is off, device-tree isn't unflattened
165  */
166 static int __init mpc832x_rdb_probe(void)
167 {
168         unsigned long root = of_get_flat_dt_root();
169
170         return of_flat_dt_is_compatible(root, "MPC832xRDB");
171 }
172
173 define_machine(mpc832x_rdb) {
174         .name           = "MPC832x RDB",
175         .probe          = mpc832x_rdb_probe,
176         .setup_arch     = mpc832x_rdb_setup_arch,
177         .init_IRQ       = mpc832x_rdb_init_IRQ,
178         .get_irq        = ipic_get_irq,
179         .restart        = mpc83xx_restart,
180         .time_init      = mpc83xx_time_init,
181         .calibrate_decr = generic_calibrate_decr,
182         .progress       = udbg_progress,
183 };