189d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto/*
289d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
389d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto *	    and RBTX49xx patch from CELF patch archive.
489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto *
589d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto * 2003-2005 (c) MontaVista Software, Inc.
689d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
789d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto *
889d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto * This file is subject to the terms and conditions of the GNU General Public
989d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto * License.  See the file "COPYING" in the main directory of this archive
1089d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto * for more details.
1189d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto */
1289d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto#include <linux/init.h>
1389d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto#include <linux/kernel.h>
1489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto#include <linux/types.h>
15edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <linux/interrupt.h>
16edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <linux/string.h>
17edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <linux/module.h>
18edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <linux/clk.h>
19edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <linux/err.h>
20e0eb730757665d7e8ec0e79d9042a9311f3edb7eAtsushi Nemoto#include <linux/gpio.h>
21683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto#include <linux/platform_device.h>
227779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto#include <linux/serial_core.h>
2351f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto#include <linux/mtd/physmap.h>
24ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto#include <linux/leds.h>
25269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers#include <linux/device.h>
265a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h>
27ca4d3e6746bdcfccb517349bce2d2c5b5614fb6fDavid Howells#include <linux/irq.h>
28edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <asm/bootinfo.h>
29bdc92d74e0ec95a8101447467c25f015105f2e5aRalf Baechle#include <asm/idle.h>
30e0eb730757665d7e8ec0e79d9042a9311f3edb7eAtsushi Nemoto#include <asm/time.h>
31a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto#include <asm/reboot.h>
32d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto#include <asm/r4kcache.h>
33b6263ff2d6e58cc2fe615219ab2a06778b5e6cefAtsushi Nemoto#include <asm/sections.h>
3489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto#include <asm/txx9/generic.h>
3507517529225ae4ce770271f83d8cd1004733a01dAtsushi Nemoto#include <asm/txx9/pci.h>
36496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto#include <asm/txx9tmr.h>
37a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto#include <asm/txx9/ndfmc.h>
38f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#include <asm/txx9/dmac.h>
39edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#ifdef CONFIG_CPU_TX49XX
40edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#include <asm/txx9/tx4938.h>
41edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#endif
4289d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto
4389d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto/* EBUSC settings of TX4927, etc. */
4489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotostruct resource txx9_ce_res[8];
4589d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotostatic char txx9_ce_res_name[8][4];	/* "CEn" */
4689d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto
4789d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto/* pcode, internal register */
4894a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemotounsigned int txx9_pcode;
4989d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotochar txx9_pcode_str[8];
5089d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotostatic struct resource txx9_reg_res = {
5189d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	.name = txx9_pcode_str,
5289d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	.flags = IORESOURCE_MEM,
5389d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto};
5489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotovoid __init
5589d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemototxx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
5689d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto{
5789d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	int i;
5889d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto
5989d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
6089d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto		sprintf(txx9_ce_res_name[i], "CE%d", i);
6189d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto		txx9_ce_res[i].flags = IORESOURCE_MEM;
6289d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto		txx9_ce_res[i].name = txx9_ce_res_name[i];
6389d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	}
6489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto
65073828d078d3e55b23b2b5937a49dc1019c5907dAtsushi Nemoto	txx9_pcode = pcode;
6689d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	sprintf(txx9_pcode_str, "TX%x", pcode);
6789d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	if (base) {
6889d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto		txx9_reg_res.start = base & 0xfffffffffULL;
6989d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto		txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
7089d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto		request_resource(&iomem_resource, &txx9_reg_res);
7189d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto	}
7289d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto}
7389d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto
7489d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemoto/* clocks */
7589d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotounsigned int txx9_master_clock;
7689d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotounsigned int txx9_cpu_clock;
7789d63fe179520b11f54de1f26755b7444c79e73aAtsushi Nemotounsigned int txx9_gbus_clock;
78edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
79c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto#ifdef CONFIG_CPU_TX39XX
80c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto/* don't enable by default - see errata */
81c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemotoint txx9_ccfg_toeon __initdata;
82c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto#else
8394a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemotoint txx9_ccfg_toeon __initdata = 1;
84c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto#endif
85edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
86edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto/* Minimum CLK support */
87edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
88edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotostruct clk *clk_get(struct device *dev, const char *id)
89edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
90edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	if (!strcmp(id, "spi-baseclk"))
91fcc152f3bf55cec61167b173774cbf717b0ff5e4Atsushi Nemoto		return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 2);
92edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	if (!strcmp(id, "imbus_clk"))
9394a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemoto		return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
94edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	return ERR_PTR(-ENOENT);
95edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
96edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi NemotoEXPORT_SYMBOL(clk_get);
97edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
98edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotoint clk_enable(struct clk *clk)
99edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
100edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	return 0;
101edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
102edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi NemotoEXPORT_SYMBOL(clk_enable);
103edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
104edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotovoid clk_disable(struct clk *clk)
105edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
106edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
107edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi NemotoEXPORT_SYMBOL(clk_disable);
108edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
109edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotounsigned long clk_get_rate(struct clk *clk)
110edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
111edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	return (unsigned long)clk;
112edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
113edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi NemotoEXPORT_SYMBOL(clk_get_rate);
114edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
115edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotovoid clk_put(struct clk *clk)
116edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
117edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
118edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi NemotoEXPORT_SYMBOL(clk_put);
119edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
1208d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto/* GPIO support */
1218d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto
122f9612a65ec0a0457ee62c94e42f89abf2f8fbe21Alexandre Courbot#ifdef CONFIG_GPIOLIB
1238d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemotoint gpio_to_irq(unsigned gpio)
1248d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto{
1258d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto	return -EINVAL;
1268d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto}
1278d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi NemotoEXPORT_SYMBOL(gpio_to_irq);
1288d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto
1298d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemotoint irq_to_gpio(unsigned irq)
1308d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto{
1318d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto	return -EINVAL;
1328d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto}
1338d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi NemotoEXPORT_SYMBOL(irq_to_gpio);
1348d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto#endif
1358d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto
136860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto#define BOARD_VEC(board)	extern struct txx9_board_vec board;
137860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto#include <asm/txx9/boards.h>
138860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto#undef BOARD_VEC
139edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
140edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotostruct txx9_board_vec *txx9_board_vec __initdata;
141edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotostatic char txx9_system_type[32];
142edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
143860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemotostatic struct txx9_board_vec *board_vecs[] __initdata = {
144860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto#define BOARD_VEC(board)	&board,
145860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto#include <asm/txx9/boards.h>
146860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto#undef BOARD_VEC
147860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto};
148860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
149860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemotostatic struct txx9_board_vec *__init find_board_byname(const char *name)
150860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto{
151860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	int i;
152860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
153860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	/* search board_vecs table */
154860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
155860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		if (strstr(board_vecs[i]->system, name))
156860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto			return board_vecs[i];
157860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	}
158860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	return NULL;
159860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto}
160860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
161e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemotostatic void __init prom_init_cmdline(void)
162edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
16397b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	int argc;
16497b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	int *argv32;
165edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	int i;			/* Always ignore the "-c" at argv[0] */
166edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
16797b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) {
16897b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		/*
16997b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		 * argc is not a valid number, or argv32 is not a valid
17097b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		 * pointer
17197b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		 */
17297b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		argc = 0;
17397b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		argv32 = NULL;
17497b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	} else {
17597b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		argc = (int)fw_arg0;
17697b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven		argv32 = (int *)fw_arg1;
17797b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	}
17897b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven
179e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto	arcs_cmdline[0] = '\0';
180edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
181edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	for (i = 1; i < argc; i++) {
182e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto		char *str = (char *)(long)argv32[i];
183edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		if (i != 1)
184edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto			strcat(arcs_cmdline, " ");
185e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto		if (strchr(str, ' ')) {
186e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto			strcat(arcs_cmdline, "\"");
187e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto			strcat(arcs_cmdline, str);
188e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto			strcat(arcs_cmdline, "\"");
189e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto		} else
190e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto			strcat(arcs_cmdline, str);
191e0dfb20c2b77c6626a24578240266ace928cd2e7Atsushi Nemoto	}
192edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
193edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
194d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic int txx9_ic_disable __initdata;
195d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic int txx9_dc_disable __initdata;
196d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
197d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto#if defined(CONFIG_CPU_TX49XX)
198d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto/* flush all cache on very early stage (before 4k_cache_init) */
199d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic void __init early_flush_dcache(void)
200d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto{
201d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int conf = read_c0_config();
202d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
203d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int linesz = 32;
204d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned long addr, end;
205d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
206d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	end = INDEX_BASE + dc_size / 4;
207d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	/* 4way, waybit=0 */
208d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	for (addr = INDEX_BASE; addr < end; addr += linesz) {
209d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		cache_op(Index_Writeback_Inv_D, addr | 0);
210d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		cache_op(Index_Writeback_Inv_D, addr | 1);
211d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		cache_op(Index_Writeback_Inv_D, addr | 2);
212d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		cache_op(Index_Writeback_Inv_D, addr | 3);
213d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	}
214d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto}
215d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
216d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic void __init txx9_cache_fixup(void)
217d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto{
218d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int conf;
219d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
220d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	conf = read_c0_config();
221d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	/* flush and disable */
222d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (txx9_ic_disable) {
223d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf |= TX49_CONF_IC;
224d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		write_c0_config(conf);
225d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	}
226d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (txx9_dc_disable) {
227d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		early_flush_dcache();
228d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf |= TX49_CONF_DC;
229d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		write_c0_config(conf);
230d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	}
231d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
232d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	/* enable cache */
233d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	conf = read_c0_config();
234d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (!txx9_ic_disable)
235d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf &= ~TX49_CONF_IC;
236d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (!txx9_dc_disable)
237d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf &= ~TX49_CONF_DC;
238d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	write_c0_config(conf);
239d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
240d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (conf & TX49_CONF_IC)
241d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		pr_info("TX49XX I-Cache disabled.\n");
242d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (conf & TX49_CONF_DC)
243d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		pr_info("TX49XX D-Cache disabled.\n");
244d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto}
245d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto#elif defined(CONFIG_CPU_TX39XX)
246d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto/* flush all cache on very early stage (before tx39_cache_init) */
247d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic void __init early_flush_dcache(void)
248d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto{
249d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int conf = read_c0_config();
250d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
251d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto					   TX39_CONF_DCS_SHIFT));
252d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int linesz = 16;
253d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned long addr, end;
254d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
255d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	end = INDEX_BASE + dc_size / 2;
256d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	/* 2way, waybit=0 */
257d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	for (addr = INDEX_BASE; addr < end; addr += linesz) {
258d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		cache_op(Index_Writeback_Inv_D, addr | 0);
259d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		cache_op(Index_Writeback_Inv_D, addr | 1);
260d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	}
261d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto}
262d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
263d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic void __init txx9_cache_fixup(void)
264d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto{
265d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	unsigned int conf;
266d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
267d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	conf = read_c0_config();
268d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	/* flush and disable */
269d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (txx9_ic_disable) {
270d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf &= ~TX39_CONF_ICE;
271d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		write_c0_config(conf);
272d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	}
273d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (txx9_dc_disable) {
274d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		early_flush_dcache();
275d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf &= ~TX39_CONF_DCE;
276d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		write_c0_config(conf);
277d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	}
278d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
279d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	/* enable cache */
280d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	conf = read_c0_config();
281d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (!txx9_ic_disable)
282d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf |= TX39_CONF_ICE;
283d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (!txx9_dc_disable)
284d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		conf |= TX39_CONF_DCE;
285d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	write_c0_config(conf);
286d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
287d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (!(conf & TX39_CONF_ICE))
288d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		pr_info("TX39XX I-Cache disabled.\n");
289d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	if (!(conf & TX39_CONF_DCE))
290d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		pr_info("TX39XX D-Cache disabled.\n");
291d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto}
292d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto#else
293d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemotostatic inline void txx9_cache_fixup(void)
294d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto{
295d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto}
296d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto#endif
297d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
298860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemotostatic void __init preprocess_cmdline(void)
299edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
3007580c9c3938f45b0d889728d5533cb46b0322a85Dmitri Vorobiev	static char cmdline[COMMAND_LINE_SIZE] __initdata;
301860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	char *s;
302860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
303860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	strcpy(cmdline, arcs_cmdline);
304860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	s = cmdline;
305860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	arcs_cmdline[0] = '\0';
306860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	while (s && *s) {
307860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		char *str = strsep(&s, " ");
308860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		if (strncmp(str, "board=", 6) == 0) {
309860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto			txx9_board_vec = find_board_byname(str + 6);
310860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto			continue;
311860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		} else if (strncmp(str, "masterclk=", 10) == 0) {
3128e9ecbc5e21bf82693e52ec75b1f45c1245a9beaDaniel Walter			unsigned int val;
3138e9ecbc5e21bf82693e52ec75b1f45c1245a9beaDaniel Walter			if (kstrtouint(str + 10, 10, &val) == 0)
314860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto				txx9_master_clock = val;
315860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto			continue;
316d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		} else if (strcmp(str, "icdisable") == 0) {
317d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto			txx9_ic_disable = 1;
318d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto			continue;
319d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto		} else if (strcmp(str, "dcdisable") == 0) {
320d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto			txx9_dc_disable = 1;
321d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto			continue;
322c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto		} else if (strcmp(str, "toeoff") == 0) {
323c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto			txx9_ccfg_toeon = 0;
324c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto			continue;
325c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto		} else if (strcmp(str, "toeon") == 0) {
326c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto			txx9_ccfg_toeon = 1;
327c7b95bcb38ea492fd025008ef99501a2b90aa237Atsushi Nemoto			continue;
328860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		}
329860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		if (arcs_cmdline[0])
330860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto			strcat(arcs_cmdline, " ");
331860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		strcat(arcs_cmdline, str);
332860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	}
333d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto
334d10e025f0e4ba4b96d7b5786d232ac5b0b232b11Atsushi Nemoto	txx9_cache_fixup();
335860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto}
336860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
337860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemotostatic void __init select_board(void)
338860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto{
339860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	const char *envstr;
340860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
341860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	/* first, determine by "board=" argument in preprocess_cmdline() */
342860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	if (txx9_board_vec)
343860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		return;
344860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	/* next, determine by "board" envvar */
345860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	envstr = prom_getenv("board");
346860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	if (envstr) {
347860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		txx9_board_vec = find_board_byname(envstr);
348860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto		if (txx9_board_vec)
349860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto			return;
350860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	}
351860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
352860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	/* select "default" board */
353c8acd40d38a7a2a82fb2e2fc59e5035643bb44d1Markos Chandras#ifdef CONFIG_TOSHIBA_JMR3927
3547a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa	txx9_board_vec = &jmr3927_vec;
355edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#endif
356edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#ifdef CONFIG_CPU_TX49XX
357edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	switch (TX4938_REV_PCODE()) {
3588d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto#ifdef CONFIG_TOSHIBA_RBTX4927
359edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	case 0x4927:
3607a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa		txx9_board_vec = &rbtx4927_vec;
361edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		break;
362edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	case 0x4937:
3637a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa		txx9_board_vec = &rbtx4937_vec;
364edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		break;
3658d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto#endif
3668d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto#ifdef CONFIG_TOSHIBA_RBTX4938
367edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	case 0x4938:
3687a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa		txx9_board_vec = &rbtx4938_vec;
369edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		break;
3708d795f2a5cf73338a467ac82bdeb73225e987c45Atsushi Nemoto#endif
371b27311e1cace4e296ace786c886d22f7a8ec78d6Atsushi Nemoto#ifdef CONFIG_TOSHIBA_RBTX4939
372b27311e1cace4e296ace786c886d22f7a8ec78d6Atsushi Nemoto	case 0x4939:
373b27311e1cace4e296ace786c886d22f7a8ec78d6Atsushi Nemoto		txx9_board_vec = &rbtx4939_vec;
374b27311e1cace4e296ace786c886d22f7a8ec78d6Atsushi Nemoto		break;
375b27311e1cace4e296ace786c886d22f7a8ec78d6Atsushi Nemoto#endif
376edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	}
377edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto#endif
378860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto}
379860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto
380860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemotovoid __init prom_init(void)
381860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto{
382860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	prom_init_cmdline();
383860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	preprocess_cmdline();
384860e546c19d88c21819c7f0861c505debd2d6eedAtsushi Nemoto	select_board();
3857a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa
3867a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa	strcpy(txx9_system_type, txx9_board_vec->system);
3877a1fdf1946b641f7c2866b3386414657eeb88084Yoichi Yuasa
3887b22609442a32050e37cec5f6735376af61e68a1Atsushi Nemoto	txx9_board_vec->prom_init();
389edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
390edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
391edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotovoid __init prom_free_prom_memory(void)
392edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
393b6263ff2d6e58cc2fe615219ab2a06778b5e6cefAtsushi Nemoto	unsigned long saddr = PAGE_SIZE;
394b6263ff2d6e58cc2fe615219ab2a06778b5e6cefAtsushi Nemoto	unsigned long eaddr = __pa_symbol(&_text);
395b6263ff2d6e58cc2fe615219ab2a06778b5e6cefAtsushi Nemoto
396b6263ff2d6e58cc2fe615219ab2a06778b5e6cefAtsushi Nemoto	if (saddr < eaddr)
397b6263ff2d6e58cc2fe615219ab2a06778b5e6cefAtsushi Nemoto		free_init_pages("prom memory", saddr, eaddr);
398edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
399edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
400edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotoconst char *get_system_type(void)
401edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
402edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	return txx9_system_type;
403edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
404edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
405265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemotoconst char *__init prom_getenv(const char *name)
406265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto{
40797b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	const s32 *str;
408265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto
40997b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	if (fw_arg2 < CKSEG0)
410265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto		return NULL;
41197b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven
41297b0511ce125b0cb95d73b198c1bdbb3cebc4de2Geert Uytterhoeven	str = (const s32 *)fw_arg2;
413265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto	/* YAMON style ("name", "value" pairs) */
414265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto	while (str[0] && str[1]) {
415265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto		if (!strcmp((const char *)(unsigned long)str[0], name))
416265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto			return (const char *)(unsigned long)str[1];
417265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto		str += 2;
418265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto	}
419265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto	return NULL;
420265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto}
421265b89db1058124ddbf0091ba3f8c020e3a5ae9dAtsushi Nemoto
422a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemotostatic void __noreturn txx9_machine_halt(void)
423a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto{
424a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	local_irq_disable();
425a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	clear_c0_status(ST0_IM);
426a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	while (1) {
427a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto		if (cpu_wait) {
428a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto			(*cpu_wait)();
429a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto			if (cpu_has_counter) {
430a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto				/*
431a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto				 * Clear counter interrupt while it
432a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto				 * breaks WAIT instruction even if
433a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto				 * masked.
434a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto				 */
435a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto				write_c0_compare(0);
436a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto			}
437a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto		}
438a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	}
439a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto}
440a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto
441683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto/* Watchdog support */
442683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemotovoid __init txx9_wdt_init(unsigned long base)
443683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto{
444683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto	struct resource res = {
445683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto		.start	= base,
446683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto		.end	= base + 0x100 - 1,
447683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto		.flags	= IORESOURCE_MEM,
448683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto	};
449683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto	platform_device_register_simple("txx9wdt", -1, &res, 1);
450683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto}
451683147254ef7e69ebbbe55280ba6a3c5ae2325d8Atsushi Nemoto
452496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemotovoid txx9_wdt_now(unsigned long base)
453496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto{
454496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	struct txx9_tmr_reg __iomem *tmrptr =
455496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto		ioremap(base, sizeof(struct txx9_tmr_reg));
456496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	/* disable watch dog timer */
457496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	__raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
458496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	__raw_writel(0, &tmrptr->tcr);
459496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	/* kick watchdog */
460496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	__raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
461496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	__raw_writel(1, &tmrptr->cpra); /* immediate */
462496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto	__raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
463496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto		     &tmrptr->tcr);
464496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto}
465496a3b5c2c188e8af07261792b3d4e6cf1c1dab9Atsushi Nemoto
466c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto/* SPI support */
467c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemotovoid __init txx9_spi_init(int busid, unsigned long base, int irq)
468c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto{
469c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	struct resource res[] = {
470c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto		{
471c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto			.start	= base,
472c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto			.end	= base + 0x20 - 1,
473c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto			.flags	= IORESOURCE_MEM,
474c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto		}, {
475c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto			.start	= irq,
476c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto			.flags	= IORESOURCE_IRQ,
477c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto		},
478c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	};
479c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	platform_device_register_simple("spi_txx9", busid,
480c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto					res, ARRAY_SIZE(res));
481c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto}
482c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto
483c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemotovoid __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
484c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto{
485c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	struct platform_device *pdev =
486c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto		platform_device_alloc("tc35815-mac", id);
487c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	if (!pdev ||
488c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	    platform_device_add_data(pdev, ethaddr, 6) ||
489c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto	    platform_device_add(pdev))
490c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto		platform_device_put(pdev);
491c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto}
492c49f91f51e3cca796494f69fd967a7f72df5d457Atsushi Nemoto
4937779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemotovoid __init txx9_sio_init(unsigned long baseaddr, int irq,
4947779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto			  unsigned int line, unsigned int sclk, int nocts)
4957779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto{
4967779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto#ifdef CONFIG_SERIAL_TXX9
4977779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	struct uart_port req;
4987779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto
4997779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	memset(&req, 0, sizeof(req));
5007779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	req.line = line;
5017779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	req.iotype = UPIO_MEM;
5027779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	req.membase = ioremap(baseaddr, 0x24);
5037779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	req.mapbase = baseaddr;
5047779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	req.irq = irq;
5057779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	if (!nocts)
5067779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto		req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
5077779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	if (sclk) {
5087779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto		req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
5097779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto		req.uartclk = sclk;
5107779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	} else
5117779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto		req.uartclk = TXX9_IMCLK;
5127779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto	early_serial_txx9_setup(&req);
5137779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto#endif /* CONFIG_SERIAL_TXX9 */
5147779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto}
5157779a5e07d33fe316fe468e7afe7975fb686a831Atsushi Nemoto
516e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto#ifdef CONFIG_EARLY_PRINTK
517f7be4e754b61681467f873400cbaa42a013b8973Aaro Koskinenstatic void null_prom_putchar(char c)
518e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto{
519e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto}
520f7be4e754b61681467f873400cbaa42a013b8973Aaro Koskinenvoid (*txx9_prom_putchar)(char c) = null_prom_putchar;
521e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto
522f7be4e754b61681467f873400cbaa42a013b8973Aaro Koskinenvoid prom_putchar(char c)
523e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto{
524e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto	txx9_prom_putchar(c);
525e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto}
526e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto
527e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemotostatic void __iomem *early_txx9_sio_port;
528e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto
529f7be4e754b61681467f873400cbaa42a013b8973Aaro Koskinenstatic void early_txx9_sio_putchar(char c)
530e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto{
531e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto#define TXX9_SICISR	0x0c
532e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto#define TXX9_SITFIFO	0x1c
533e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto#define TXX9_SICISR_TXALS	0x00000002
534e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto	while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
535e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto		 TXX9_SICISR_TXALS))
536e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto		;
537e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto	__raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
538e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto}
539e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto
540e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemotovoid __init txx9_sio_putchar_init(unsigned long baseaddr)
541e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto{
542e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto	early_txx9_sio_port = ioremap(baseaddr, 0x24);
543e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto	txx9_prom_putchar = early_txx9_sio_putchar;
544e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto}
545e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto#endif /* CONFIG_EARLY_PRINTK */
546e352953ce00bb870124e9054dbbbda2262f9269cAtsushi Nemoto
547edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto/* wrappers */
548edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotovoid __init plat_mem_setup(void)
549edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
55094a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemoto	ioport_resource.start = 0;
55194a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemoto	ioport_resource.end = ~0UL;	/* no limit */
55294a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemoto	iomem_resource.start = 0;
55394a4c32939dede9328c6e4face335eb8441fc18dAtsushi Nemoto	iomem_resource.end = ~0UL;	/* no limit */
554a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto
555a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	/* fallback restart/halt routines */
556a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	_machine_restart = (void (*)(char *))txx9_machine_halt;
557a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	_machine_halt = txx9_machine_halt;
558a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto	pm_power_off = txx9_machine_halt;
559a49297e8fc8a9a835ac4ec124aa83028abdcc7d5Atsushi Nemoto
56007517529225ae4ce770271f83d8cd1004733a01dAtsushi Nemoto#ifdef CONFIG_PCI
56107517529225ae4ce770271f83d8cd1004733a01dAtsushi Nemoto	pcibios_plat_setup = txx9_pcibios_setup;
56207517529225ae4ce770271f83d8cd1004733a01dAtsushi Nemoto#endif
563edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	txx9_board_vec->mem_setup();
564edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
565edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
566edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotovoid __init arch_init_irq(void)
567edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
568edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	txx9_board_vec->irq_setup();
569edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
570edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
571edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotovoid __init plat_time_init(void)
572edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
5731374d084736fff6f72f1d143ffdaa90cddd86e7eAtsushi Nemoto#ifdef CONFIG_CPU_TX49XX
5741374d084736fff6f72f1d143ffdaa90cddd86e7eAtsushi Nemoto	mips_hpt_frequency = txx9_cpu_clock / 2;
5751374d084736fff6f72f1d143ffdaa90cddd86e7eAtsushi Nemoto#endif
576edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	txx9_board_vec->time_init();
577edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
578edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
579edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotostatic int __init _txx9_arch_init(void)
580edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
581edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	if (txx9_board_vec->arch_init)
582edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		txx9_board_vec->arch_init();
583edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	return 0;
584edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
585edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotoarch_initcall(_txx9_arch_init);
586edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
587edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotostatic int __init _txx9_device_init(void)
588edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
589edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	if (txx9_board_vec->device_init)
590edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		txx9_board_vec->device_init();
591edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	return 0;
592edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
593edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotodevice_initcall(_txx9_device_init);
594edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
595edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotoint (*txx9_irq_dispatch)(int pending);
596edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemotoasmlinkage void plat_irq_dispatch(void)
597edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto{
598edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	int pending = read_c0_status() & read_c0_cause() & ST0_IM;
599edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	int irq = txx9_irq_dispatch(pending);
600edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto
601edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	if (likely(irq >= 0))
602edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		do_IRQ(irq);
603edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto	else
604edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto		spurious_interrupt();
605edcaf1a6a77315562e9781245cc8e028c9a921dcAtsushi Nemoto}
6064c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto
6074c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
6084c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
6094c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemotostatic unsigned long __swizzle_addr_none(unsigned long port)
6104c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto{
6114c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto	return port;
6124c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto}
6134c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemotounsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
6144c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi NemotoEXPORT_SYMBOL(__swizzle_addr_b);
6154c642f3f5e9f3f1a2fcce2c3fa1a94bf80142202Atsushi Nemoto#endif
61651f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto
6171ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto#ifdef NEEDS_TXX9_IOSWABW
6181ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemotostatic u16 ioswabw_default(volatile u16 *a, u16 x)
6191ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto{
6201ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto	return le16_to_cpu(x);
6211ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto}
6221ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemotostatic u16 __mem_ioswabw_default(volatile u16 *a, u16 x)
6231ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto{
6241ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto	return x;
6251ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto}
6261ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemotou16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default;
6271ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi NemotoEXPORT_SYMBOL(ioswabw);
6281ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemotou16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default;
6291ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi NemotoEXPORT_SYMBOL(__mem_ioswabw);
6301ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto#endif
6311ba5a1767416cfa4fa37096e160e764c56e1460aAtsushi Nemoto
63251f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemotovoid __init txx9_physmap_flash_init(int no, unsigned long addr,
63351f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto				    unsigned long size,
63451f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto				    const struct physmap_flash_data *pdata)
63551f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto{
636b33b44073734842ec0c75d376c40d0471d6113ffFlorian Fainelli#if IS_ENABLED(CONFIG_MTD_PHYSMAP)
63751f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	struct resource res = {
63851f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		.start = addr,
63951f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		.end = addr + size - 1,
64051f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		.flags = IORESOURCE_MEM,
64151f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	};
64251f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	struct platform_device *pdev;
64351f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	static struct mtd_partition parts[2];
64451f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	struct physmap_flash_data pdata_part;
64551f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto
64651f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	/* If this area contained boot area, make separate partition */
64751f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	if (pdata->nr_parts == 0 && !pdata->parts &&
64851f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	    addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
64951f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	    !parts[0].name) {
65051f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		parts[0].name = "boot";
65151f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		parts[0].offset = 0x1fc00000 - addr;
65251f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		parts[0].size = addr + size - 0x1fc00000;
65351f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		parts[1].name = "user";
65451f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		parts[1].offset = 0;
65551f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		parts[1].size = 0x1fc00000 - addr;
65651f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		pdata_part = *pdata;
65751f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		pdata_part.nr_parts = ARRAY_SIZE(parts);
65851f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		pdata_part.parts = parts;
65951f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		pdata = &pdata_part;
66051f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	}
66147854888cc21cb1afd7797c66886a8b06cf35979Jamie Iles
66251f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	pdev = platform_device_alloc("physmap-flash", no);
66351f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	if (!pdev ||
66451f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	    platform_device_add_resources(pdev, &res, 1) ||
665a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	    platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
666a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	    platform_device_add(pdev))
667a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto		platform_device_put(pdev);
668a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto#endif
669a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto}
670a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto
671a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemotovoid __init txx9_ndfmc_init(unsigned long baseaddr,
672a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto			    const struct txx9ndfmc_platform_data *pdata)
673a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto{
674b33b44073734842ec0c75d376c40d0471d6113ffFlorian Fainelli#if IS_ENABLED(CONFIG_MTD_NAND_TXX9NDFMC)
675a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	struct resource res = {
676a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto		.start = baseaddr,
677a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto		.end = baseaddr + 0x1000 - 1,
678a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto		.flags = IORESOURCE_MEM,
679a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	};
680a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
681a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto
682a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	if (!pdev ||
683a591f5d35e89be90c04830d7de01c276af68aeb7Atsushi Nemoto	    platform_device_add_resources(pdev, &res, 1) ||
68451f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	    platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
68551f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto	    platform_device_add(pdev))
68651f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto		platform_device_put(pdev);
68751f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto#endif
68851f607c76e1e7bd089dcad97b6b0a58649be06a3Atsushi Nemoto}
689ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
690b33b44073734842ec0c75d376c40d0471d6113ffFlorian Fainelli#if IS_ENABLED(CONFIG_LEDS_GPIO)
691ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotostatic DEFINE_SPINLOCK(txx9_iocled_lock);
692ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
693ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto#define TXX9_IOCLED_MAXLEDS 8
694ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
695ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotostruct txx9_iocled_data {
696ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct gpio_chip chip;
697ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	u8 cur_val;
698ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	void __iomem *mmioaddr;
699ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct gpio_led_platform_data pdata;
700ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
701ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	char names[TXX9_IOCLED_MAXLEDS][32];
702ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto};
703ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
704ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotostatic int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
705ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto{
706ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct txx9_iocled_data *data =
707ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		container_of(chip, struct txx9_iocled_data, chip);
708ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	return data->cur_val & (1 << offset);
709ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto}
710ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
711ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotostatic void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
712ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			    int value)
713ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto{
714ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct txx9_iocled_data *data =
715ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		container_of(chip, struct txx9_iocled_data, chip);
716ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	unsigned long flags;
717ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	spin_lock_irqsave(&txx9_iocled_lock, flags);
718ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (value)
719ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		data->cur_val |= 1 << offset;
720ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	else
721ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		data->cur_val &= ~(1 << offset);
722ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	writeb(data->cur_val, data->mmioaddr);
723ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	mmiowb();
724ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	spin_unlock_irqrestore(&txx9_iocled_lock, flags);
725ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto}
726ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
727ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotostatic int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
728ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto{
729ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	return 0;
730ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto}
731ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
732ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotostatic int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
733ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			       int value)
734ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto{
735ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	txx9_iocled_set(chip, offset, value);
736ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	return 0;
737ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto}
738ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
739ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotovoid __init txx9_iocled_init(unsigned long baseaddr,
740ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			     int basenum, unsigned int num, int lowactive,
741ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			     const char *color, char **deftriggers)
742ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto{
743ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct txx9_iocled_data *iocled;
744ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	struct platform_device *pdev;
745ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	int i;
746ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	static char *default_triggers[] __initdata = {
747ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		"heartbeat",
748ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		"ide-disk",
749ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		"nand-disk",
750ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		NULL,
751ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	};
752ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
753ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (!deftriggers)
754ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		deftriggers = default_triggers;
755ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
756ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (!iocled)
757ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		return;
758ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->mmioaddr = ioremap(baseaddr, 1);
759ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (!iocled->mmioaddr)
76070ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall		goto out_free;
761ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.get = txx9_iocled_get;
762ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.set = txx9_iocled_set;
763ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.direction_input = txx9_iocled_dir_in;
764ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.direction_output = txx9_iocled_dir_out;
765ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.label = "iocled";
766ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.base = basenum;
767ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->chip.ngpio = num;
768ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (gpiochip_add(&iocled->chip))
76970ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall		goto out_unmap;
770ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (basenum < 0)
771ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		basenum = iocled->chip.base;
772ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto
773ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	pdev = platform_device_alloc("leds-gpio", basenum);
774ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (!pdev)
77570ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall		goto out_gpio;
776ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->pdata.num_leds = num;
777ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	iocled->pdata.leds = iocled->leds;
778ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	for (i = 0; i < num; i++) {
779ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		struct gpio_led *led = &iocled->leds[i];
780ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		snprintf(iocled->names[i], sizeof(iocled->names[i]),
781ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			 "iocled:%s:%u", color, i);
782ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		led->name = iocled->names[i];
783ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		led->gpio = basenum + i;
784ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		led->active_low = lowactive;
785ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto		if (deftriggers && *deftriggers)
786ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			led->default_trigger = *deftriggers++;
787ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	}
788ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	pdev->dev.platform_data = &iocled->pdata;
789ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto	if (platform_device_add(pdev))
79070ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall		goto out_pdev;
79170ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall	return;
79288d5e520aa9701eb3e4f46165e02097cc03d363aabdoulaye berthe
79370ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawallout_pdev:
79470ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall	platform_device_put(pdev);
79570ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawallout_gpio:
79688d5e520aa9701eb3e4f46165e02097cc03d363aabdoulaye berthe	gpiochip_remove(&iocled->chip);
79770ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawallout_unmap:
79870ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall	iounmap(iocled->mmioaddr);
79970ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawallout_free:
80070ebadc8e30efef3bf21ba94b3571537de8bcf4eJulia Lawall	kfree(iocled);
801ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto}
802ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto#else /* CONFIG_LEDS_GPIO */
803ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemotovoid __init txx9_iocled_init(unsigned long baseaddr,
804ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			     int basenum, unsigned int num, int lowactive,
805ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto			     const char *color, char **deftriggers)
806ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto{
807ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto}
808ae027ead87b13cff99b4f48da7696aa4fe75393bAtsushi Nemoto#endif /* CONFIG_LEDS_GPIO */
809f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto
810f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemotovoid __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
811f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			   const struct txx9dmac_platform_data *pdata)
812f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto{
813b33b44073734842ec0c75d376c40d0471d6113ffFlorian Fainelli#if IS_ENABLED(CONFIG_TXX9_DMAC)
814f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	struct resource res[] = {
815f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		{
816f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			.start = baseaddr,
817f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			.end = baseaddr + 0x800 - 1,
818f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			.flags = IORESOURCE_MEM,
819f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#ifndef CONFIG_MACH_TX49XX
820f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		}, {
821f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			.start = irq,
822f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			.flags = IORESOURCE_IRQ,
823f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#endif
824f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		}
825f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	};
826f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#ifdef CONFIG_MACH_TX49XX
827f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	struct resource chan_res[] = {
828f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		{
829f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			.flags = IORESOURCE_IRQ,
830f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		}
831f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	};
832f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#endif
833f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
834f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	struct txx9dmac_chan_platform_data cpdata;
835f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	int i;
836f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto
837f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	if (!pdev ||
838f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	    platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
839f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	    platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
840f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	    platform_device_add(pdev)) {
841f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		platform_device_put(pdev);
842f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		return;
843f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	}
844f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	memset(&cpdata, 0, sizeof(cpdata));
845f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	cpdata.dmac_dev = pdev;
846f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
847f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#ifdef CONFIG_MACH_TX49XX
848f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		chan_res[0].start = irq + i;
849f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#endif
850f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		pdev = platform_device_alloc("txx9dmac-chan",
851f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto					     id * TXX9_DMA_MAX_NR_CHANNELS + i);
852f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		if (!pdev ||
853f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#ifdef CONFIG_MACH_TX49XX
854f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		    platform_device_add_resources(pdev, chan_res,
855f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto						  ARRAY_SIZE(chan_res)) ||
856f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#endif
857f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		    platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
858f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto		    platform_device_add(pdev))
859f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto			platform_device_put(pdev);
860f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto	}
861f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto#endif
862f48c8c958a2d39f13dace880d15a6e711aafe577Atsushi Nemoto}
863742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto
864742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemotovoid __init txx9_aclc_init(unsigned long baseaddr, int irq,
865742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			   unsigned int dmac_id,
866742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			   unsigned int dma_chan_out,
867742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			   unsigned int dma_chan_in)
868742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto{
869b33b44073734842ec0c75d376c40d0471d6113ffFlorian Fainelli#if IS_ENABLED(CONFIG_SND_SOC_TXX9ACLC)
870742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS;
871742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	struct resource res[] = {
872742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		{
873742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.start = baseaddr,
874742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.end = baseaddr + 0x100 - 1,
875742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.flags = IORESOURCE_MEM,
876742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		}, {
877742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.start = irq,
878742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.flags = IORESOURCE_IRQ,
879742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		}, {
880742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.name = "txx9dmac-chan",
881742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.start = dma_base + dma_chan_out,
882742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.flags = IORESOURCE_DMA,
883742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		}, {
884742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.name = "txx9dmac-chan",
885742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.start = dma_base + dma_chan_in,
886742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto			.flags = IORESOURCE_DMA,
887742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		}
888742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	};
889742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	struct platform_device *pdev =
890742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		platform_device_alloc("txx9aclc-ac97", -1);
891742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto
892742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	if (!pdev ||
893742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	    platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
894742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto	    platform_device_add(pdev))
895742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto		platform_device_put(pdev);
896742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto#endif
897742cd5867b2ef7ce865d7ab67574c4e3aa1fb155Atsushi Nemoto}
898c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
899269a3eb1bf10a078ede74747a61603693a3f7853Kay Sieversstatic struct bus_type txx9_sramc_subsys = {
900269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	.name = "txx9_sram",
901269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	.dev_name = "txx9_sram",
902269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers};
903c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
904269a3eb1bf10a078ede74747a61603693a3f7853Kay Sieversstruct txx9_sramc_dev {
905269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	struct device dev;
906c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	struct bin_attribute bindata_attr;
907c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	void __iomem *base;
908c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto};
909c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
9102c3c8bea608866d8bd9dcf92657d57fdcac011c5Chris Wrightstatic ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
911c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto			      struct bin_attribute *bin_attr,
912c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto			      char *buf, loff_t pos, size_t size)
913c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto{
914269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	struct txx9_sramc_dev *dev = bin_attr->private;
915c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	size_t ramsize = bin_attr->size;
916c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
917c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (pos >= ramsize)
918c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto		return 0;
919c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (pos + size > ramsize)
920c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto		size = ramsize - pos;
921c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	memcpy_fromio(buf, dev->base + pos, size);
922c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	return size;
923c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto}
924c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
9252c3c8bea608866d8bd9dcf92657d57fdcac011c5Chris Wrightstatic ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
926c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto			       struct bin_attribute *bin_attr,
927c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto			       char *buf, loff_t pos, size_t size)
928c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto{
929269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	struct txx9_sramc_dev *dev = bin_attr->private;
930c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	size_t ramsize = bin_attr->size;
931c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
932c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (pos >= ramsize)
933c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto		return 0;
934c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (pos + size > ramsize)
935c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto		size = ramsize - pos;
936c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	memcpy_toio(dev->base + pos, buf, size);
937c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	return size;
938c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto}
939c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
9401610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusastatic void txx9_device_release(struct device *dev)
9411610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa{
9421610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	struct txx9_sramc_dev *tdev;
9431610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa
9441610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	tdev = container_of(dev, struct txx9_sramc_dev, dev);
9451610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	kfree(tdev);
9461610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa}
9471610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa
948c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemotovoid __init txx9_sramc_init(struct resource *r)
949c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto{
950269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	struct txx9_sramc_dev *dev;
951c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	size_t size;
952c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	int err;
953c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto
954269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	err = subsys_system_register(&txx9_sramc_subsys, NULL);
955269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	if (err)
956269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers		return;
957c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
958c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (!dev)
959c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto		return;
960c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	size = resource_size(r);
961c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->base = ioremap(r->start, size);
9621610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	if (!dev->base) {
9631610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa		kfree(dev);
9641610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa		return;
9651610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	}
9661610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	dev->dev.release = &txx9_device_release;
967269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	dev->dev.bus = &txx9_sramc_subsys;
968f937331b3f92cb2f67bc81baa1b8cc5198c439e5Wolfram Sang	sysfs_bin_attr_init(&dev->bindata_attr);
969c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->bindata_attr.attr.name = "bindata";
970c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
971c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->bindata_attr.read = txx9_sram_read;
972c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->bindata_attr.write = txx9_sram_write;
973c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->bindata_attr.size = size;
974c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	dev->bindata_attr.private = dev;
975269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers	err = device_register(&dev->dev);
976c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (err)
9771610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa		goto exit_put;
978c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
979c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	if (err) {
980269a3eb1bf10a078ede74747a61603693a3f7853Kay Sievers		device_unregister(&dev->dev);
9811610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa		iounmap(dev->base);
982c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto		kfree(dev);
983c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto	}
9841610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	return;
9851610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusaexit_put:
9861610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	put_device(&dev->dev);
9871610c8a8f2d3eb5dac5a418356c179d28da4e74eLevente Kurusa	return;
988c3b28ae260d99a5364a31210a36a3246bd9647f7Atsushi Nemoto}
989