blob: 60a18e12e6cec7d95681c3d389859f636e116720 [file] [log] [blame]
Alessandro Rubini28ad94e2009-07-02 19:06:47 +01001/*
2 * Copyright STMicroelectronics, 2007.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/device.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010022#include <linux/amba/bus.h>
Rabin Vincent3e3c62c2010-03-03 04:52:34 +010023#include <linux/platform_device.h>
Russell King35b47a4052011-11-28 10:48:02 +000024#include <linux/io.h>
Linus Walleij7c778522012-01-09 12:40:02 +010025#include <linux/slab.h>
26#include <linux/irq.h>
27#include <linux/dma-mapping.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010028#include <linux/irqchip.h>
Linus Walleij4a31bd22012-01-11 13:52:34 +010029#include <linux/platform_data/clk-nomadik.h>
Linus Walleijbb16bd92012-10-10 14:27:58 +020030#include <linux/platform_data/pinctrl-nomadik.h>
Linus Walleij1b542752013-01-05 01:00:59 +010031#include <linux/pinctrl/machine.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010032#include <linux/platform_data/clocksource-nomadik-mtu.h>
33#include <linux/of_irq.h>
Linus Walleij2ad6e392013-01-06 01:02:42 +010034#include <linux/of_gpio.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010035#include <linux/of_address.h>
36#include <linux/of_platform.h>
Linus Walleijba785202013-01-05 22:28:32 +010037#include <linux/mtd/fsmc.h>
Linus Walleij2ad6e392013-01-06 01:02:42 +010038#include <linux/gpio.h>
Linus Walleij4fd243c2013-01-06 01:47:29 +010039#include <linux/amba/mmci.h>
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010040
41#include <mach/hardware.h>
42#include <mach/irqs.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010043#include <asm/mach/arch.h>
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010044#include <asm/mach/map.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010045#include <asm/mach/time.h>
Linus Walleij27bda032013-01-05 10:38:57 +010046#include <asm/mach-types.h>
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010047
Alessandro Rubini0b260fd2009-07-02 15:29:43 +010048#include <asm/cacheflush.h>
49#include <asm/hardware/cache-l2x0.h>
50
Linus Walleij1b542752013-01-05 01:00:59 +010051static unsigned long out_low[] = { PIN_OUTPUT_LOW };
52static unsigned long out_high[] = { PIN_OUTPUT_HIGH };
53static unsigned long in_nopull[] = { PIN_INPUT_NOPULL };
54static unsigned long in_pullup[] = { PIN_INPUT_PULLUP };
55
56static struct pinctrl_map __initdata nhk8815_pinmap[] = {
57 PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"),
58 PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"),
59 /* Hog in MMC/SD card mux */
60 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"),
61 /* MCCLK */
62 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low),
63 /* MCCMD */
64 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup),
65 /* MCCMDDIR */
66 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high),
67 /* MCDAT3-0 */
68 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup),
69 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup),
70 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup),
71 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup),
72 /* MCDAT0DIR */
73 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high),
74 /* MCDAT31DIR */
75 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high),
76 /* MCMSFBCLK */
77 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup),
78 /* CD input GPIO */
79 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull),
80 /* CD bias drive */
81 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low),
82 /* I2C0 */
83 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup),
84 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup),
85 /* I2C1 */
86 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup),
87 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup),
88 /* I2C2 */
89 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup),
90 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup),
91};
92
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010093/* All SoC devices live in the same area (see hardware.h) */
94static struct map_desc nomadik_io_desc[] __initdata = {
95 {
96 .virtual = NOMADIK_IO_VIRTUAL,
97 .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL),
98 .length = NOMADIK_IO_SIZE,
99 .type = MT_DEVICE,
100 }
101 /* static ram and secured ram may be added later */
102};
103
Linus Walleij5f66d482013-01-06 02:25:20 +0100104static void __init cpu8815_map_io(void)
Alessandro Rubini28ad94e2009-07-02 19:06:47 +0100105{
106 iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
107}
108
Linus Walleij5f66d482013-01-06 02:25:20 +0100109static void cpu8815_restart(char mode, const char *cmd)
Russell King35b47a4052011-11-28 10:48:02 +0000110{
111 void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
112
113 /* FIXME: use egpio when implemented */
114
115 /* Write anything to Reset status register */
116 writel(1, src_rstsr);
117}
Linus Walleijf8635ab2013-01-05 00:29:31 +0100118
Linus Walleijf8635ab2013-01-05 00:29:31 +0100119/* Initial value for SRC control register: all timers use MXTAL/8 source */
120#define SRC_CR_INIT_MASK 0x00007fff
121#define SRC_CR_INIT_VAL 0x2aaa8000
122
123static void __init cpu8815_timer_init_of(void)
124{
125 struct device_node *mtu;
126 void __iomem *base;
127 int irq;
128 u32 src_cr;
129
130 /* We need this to be up now */
131 nomadik_clk_init();
132
133 mtu = of_find_node_by_path("/mtu0");
134 if (!mtu)
135 return;
136 base = of_iomap(mtu, 0);
137 if (WARN_ON(!base))
138 return;
139 irq = irq_of_parse_and_map(mtu, 0);
140
141 pr_info("Remapped MTU @ %p, irq: %d\n", base, irq);
142
143 /* Configure timer sources in "system reset controller" ctrl reg */
144 src_cr = readl(base);
145 src_cr &= SRC_CR_INIT_MASK;
146 src_cr |= SRC_CR_INIT_VAL;
147 writel(src_cr, base);
148
149 nmdk_timer_init(base, irq);
150}
151
Linus Walleijba785202013-01-05 22:28:32 +0100152static struct fsmc_nand_timings cpu8815_nand_timings = {
153 .thiz = 0,
154 .thold = 0x10,
155 .twait = 0x0A,
156 .tset = 0,
157};
158
159static struct fsmc_nand_platform_data cpu8815_nand_data = {
160 .nand_timings = &cpu8815_nand_timings,
161};
162
Linus Walleij2ad6e392013-01-06 01:02:42 +0100163/*
164 * The SMSC911x IRQ is connected to a GPIO pin, but the driver expects
165 * to simply request an IRQ passed as a resource. So the GPIO pin needs
166 * to be requested by this hog and set as input.
167 */
168static int __init cpu8815_eth_init(void)
169{
170 struct device_node *eth;
171 int gpio, irq, err;
172
173 eth = of_find_node_by_path("/usb-s8815/ethernet-gpio");
174 if (!eth) {
175 pr_info("could not find any ethernet GPIO\n");
176 return 0;
177 }
178 gpio = of_get_gpio(eth, 0);
179 err = gpio_request(gpio, "eth_irq");
180 if (err) {
181 pr_info("failed to request ethernet GPIO\n");
182 return -ENODEV;
183 }
184 err = gpio_direction_input(gpio);
185 if (err) {
186 pr_info("failed to set ethernet GPIO as input\n");
187 return -ENODEV;
188 }
189 irq = gpio_to_irq(gpio);
190 pr_info("enabled USB-S8815 ethernet GPIO %d, IRQ %d\n", gpio, irq);
191 return 0;
192}
193device_initcall(cpu8815_eth_init);
194
Linus Walleij4fd243c2013-01-06 01:47:29 +0100195/*
196 * TODO:
197 * cannot be set from device tree, convert to a proper DT
198 * binding.
199 */
200static struct mmci_platform_data mmcsd_plat_data = {
201 .ocr_mask = MMC_VDD_29_30,
202};
203
204/*
205 * This GPIO pin turns on a line that is used to detect card insertion
206 * on this board.
207 */
208static int __init cpu8815_mmcsd_init(void)
209{
210 struct device_node *cdbias;
211 int gpio, err;
212
213 cdbias = of_find_node_by_path("/usb-s8815/mmcsd-gpio");
214 if (!cdbias) {
215 pr_info("could not find MMC/SD card detect bias node\n");
216 return 0;
217 }
218 gpio = of_get_gpio(cdbias, 0);
219 if (gpio < 0) {
220 pr_info("could not obtain MMC/SD card detect bias GPIO\n");
221 return 0;
222 }
223 err = gpio_request(gpio, "card detect bias");
224 if (err) {
225 pr_info("failed to request card detect bias GPIO %d\n", gpio);
226 return -ENODEV;
227 }
228 err = gpio_direction_output(gpio, 0);
229 if (err){
230 pr_info("failed to set GPIO %d as output, low\n", gpio);
231 return err;
232 }
233 pr_info("enabled USB-S8815 CD bias GPIO %d, low\n", gpio);
234 return 0;
235}
236device_initcall(cpu8815_mmcsd_init);
237
238
Linus Walleijf8635ab2013-01-05 00:29:31 +0100239/* These are mostly to get the right device names for the clock lookups */
240static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = {
Linus Walleij6010d402013-01-05 23:10:09 +0100241 OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO0_BASE,
242 "gpio.0", NULL),
243 OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO1_BASE,
244 "gpio.1", NULL),
245 OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO2_BASE,
246 "gpio.2", NULL),
247 OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO3_BASE,
248 "gpio.3", NULL),
249 OF_DEV_AUXDATA("stericsson,nmk-pinctrl-stn8815", 0,
250 "pinctrl-stn8815", NULL),
Linus Walleijf8635ab2013-01-05 00:29:31 +0100251 OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE,
252 "uart0", NULL),
253 OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE,
254 "uart1", NULL),
Linus Walleij27bda032013-01-05 10:38:57 +0100255 OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE,
256 "rng", NULL),
257 OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE,
258 "rtc-pl031", NULL),
Linus Walleijba785202013-01-05 22:28:32 +0100259 OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE,
260 "fsmc-nand", &cpu8815_nand_data),
Linus Walleij4fd243c2013-01-06 01:47:29 +0100261 OF_DEV_AUXDATA("arm,primecell", NOMADIK_SDI_BASE,
262 "mmci", &mmcsd_plat_data),
Linus Walleijf8635ab2013-01-05 00:29:31 +0100263 { /* sentinel */ },
264};
265
266static void __init cpu8815_init_of(void)
267{
268#ifdef CONFIG_CACHE_L2X0
269 /* At full speed latency must be >=2, so 0x249 in low bits */
270 l2x0_of_init(0x00730249, 0xfe000fff);
271#endif
Linus Walleij6010d402013-01-05 23:10:09 +0100272 pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
Linus Walleijf8635ab2013-01-05 00:29:31 +0100273 of_platform_populate(NULL, of_default_bus_match_table,
274 cpu8815_auxdata_lookup, NULL);
275}
276
277static const char * cpu8815_board_compat[] = {
278 "calaosystems,usb-s8815",
279 NULL,
280};
281
282DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815")
283 .map_io = cpu8815_map_io,
284 .init_irq = irqchip_init,
285 .init_time = cpu8815_timer_init_of,
286 .init_machine = cpu8815_init_of,
287 .restart = cpu8815_restart,
288 .dt_compat = cpu8815_board_compat,
289MACHINE_END