xref: /OK3568_Linux_fs/kernel/arch/mips/alchemy/board-mtx1.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * MTX-1 platform devices registration (Au1500)
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/init.h>
9*4882a593Smuzhiyun #include <linux/interrupt.h>
10*4882a593Smuzhiyun #include <linux/kernel.h>
11*4882a593Smuzhiyun #include <linux/platform_device.h>
12*4882a593Smuzhiyun #include <linux/leds.h>
13*4882a593Smuzhiyun #include <linux/gpio.h>
14*4882a593Smuzhiyun #include <linux/gpio/machine.h>
15*4882a593Smuzhiyun #include <linux/gpio_keys.h>
16*4882a593Smuzhiyun #include <linux/input.h>
17*4882a593Smuzhiyun #include <linux/mtd/partitions.h>
18*4882a593Smuzhiyun #include <linux/mtd/physmap.h>
19*4882a593Smuzhiyun #include <mtd/mtd-abi.h>
20*4882a593Smuzhiyun #include <asm/bootinfo.h>
21*4882a593Smuzhiyun #include <asm/reboot.h>
22*4882a593Smuzhiyun #include <asm/setup.h>
23*4882a593Smuzhiyun #include <asm/mach-au1x00/au1000.h>
24*4882a593Smuzhiyun #include <asm/mach-au1x00/gpio-au1000.h>
25*4882a593Smuzhiyun #include <asm/mach-au1x00/au1xxx_eth.h>
26*4882a593Smuzhiyun #include <prom.h>
27*4882a593Smuzhiyun 
get_system_type(void)28*4882a593Smuzhiyun const char *get_system_type(void)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	return "MTX-1";
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun 
prom_putchar(char c)33*4882a593Smuzhiyun void prom_putchar(char c)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun 	alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
mtx1_reset(char * c)38*4882a593Smuzhiyun static void mtx1_reset(char *c)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	/* Jump to the reset vector */
41*4882a593Smuzhiyun 	__asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun 
mtx1_power_off(void)44*4882a593Smuzhiyun static void mtx1_power_off(void)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun 	while (1)
47*4882a593Smuzhiyun 		asm volatile (
48*4882a593Smuzhiyun 		"	.set	mips32					\n"
49*4882a593Smuzhiyun 		"	wait						\n"
50*4882a593Smuzhiyun 		"	.set	mips0					\n");
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
board_setup(void)53*4882a593Smuzhiyun void __init board_setup(void)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
56*4882a593Smuzhiyun 	/* Enable USB power switch */
57*4882a593Smuzhiyun 	alchemy_gpio_direction_output(204, 0);
58*4882a593Smuzhiyun #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	/* Initialize sys_pinfunc */
61*4882a593Smuzhiyun 	alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	/* Initialize GPIO */
64*4882a593Smuzhiyun 	alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR);
65*4882a593Smuzhiyun 	alchemy_gpio_direction_output(0, 0);	/* Disable M66EN (PCI 66MHz) */
66*4882a593Smuzhiyun 	alchemy_gpio_direction_output(3, 1);	/* Disable PCI CLKRUN# */
67*4882a593Smuzhiyun 	alchemy_gpio_direction_output(1, 1);	/* Enable EXT_IO3 */
68*4882a593Smuzhiyun 	alchemy_gpio_direction_output(5, 0);	/* Disable eth PHY TX_ER */
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	/* Enable LED and set it to green */
71*4882a593Smuzhiyun 	alchemy_gpio_direction_output(211, 1);	/* green on */
72*4882a593Smuzhiyun 	alchemy_gpio_direction_output(212, 0);	/* red off */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	pm_power_off = mtx1_power_off;
75*4882a593Smuzhiyun 	_machine_halt = mtx1_power_off;
76*4882a593Smuzhiyun 	_machine_restart = mtx1_reset;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	printk(KERN_INFO "4G Systems MTX-1 Board\n");
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /******************************************************************************/
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun static struct gpio_keys_button mtx1_gpio_button[] = {
84*4882a593Smuzhiyun 	{
85*4882a593Smuzhiyun 		.gpio = 207,
86*4882a593Smuzhiyun 		.code = BTN_0,
87*4882a593Smuzhiyun 		.desc = "System button",
88*4882a593Smuzhiyun 	}
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun static struct gpio_keys_platform_data mtx1_buttons_data = {
92*4882a593Smuzhiyun 	.buttons = mtx1_gpio_button,
93*4882a593Smuzhiyun 	.nbuttons = ARRAY_SIZE(mtx1_gpio_button),
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun static struct platform_device mtx1_button = {
97*4882a593Smuzhiyun 	.name = "gpio-keys",
98*4882a593Smuzhiyun 	.id = -1,
99*4882a593Smuzhiyun 	.dev = {
100*4882a593Smuzhiyun 		.platform_data = &mtx1_buttons_data,
101*4882a593Smuzhiyun 	}
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun static struct gpiod_lookup_table mtx1_wdt_gpio_table = {
105*4882a593Smuzhiyun 	.dev_id = "mtx1-wdt.0",
106*4882a593Smuzhiyun 	.table = {
107*4882a593Smuzhiyun 		/* Global number 215 is offset 15 on Alchemy GPIO 2 */
108*4882a593Smuzhiyun 		GPIO_LOOKUP("alchemy-gpio2", 15, NULL, GPIO_ACTIVE_HIGH),
109*4882a593Smuzhiyun 		{ },
110*4882a593Smuzhiyun 	},
111*4882a593Smuzhiyun };
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun static struct platform_device mtx1_wdt = {
114*4882a593Smuzhiyun 	.name = "mtx1-wdt",
115*4882a593Smuzhiyun 	.id = 0,
116*4882a593Smuzhiyun };
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun static const struct gpio_led default_leds[] = {
119*4882a593Smuzhiyun 	{
120*4882a593Smuzhiyun 		.name	= "mtx1:green",
121*4882a593Smuzhiyun 		.gpio = 211,
122*4882a593Smuzhiyun 	}, {
123*4882a593Smuzhiyun 		.name = "mtx1:red",
124*4882a593Smuzhiyun 		.gpio = 212,
125*4882a593Smuzhiyun 	},
126*4882a593Smuzhiyun };
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun static struct gpio_led_platform_data mtx1_led_data = {
129*4882a593Smuzhiyun 	.num_leds = ARRAY_SIZE(default_leds),
130*4882a593Smuzhiyun 	.leds = default_leds,
131*4882a593Smuzhiyun };
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun static struct platform_device mtx1_gpio_leds = {
134*4882a593Smuzhiyun 	.name = "leds-gpio",
135*4882a593Smuzhiyun 	.id = -1,
136*4882a593Smuzhiyun 	.dev = {
137*4882a593Smuzhiyun 		.platform_data = &mtx1_led_data,
138*4882a593Smuzhiyun 	}
139*4882a593Smuzhiyun };
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun static struct mtd_partition mtx1_mtd_partitions[] = {
142*4882a593Smuzhiyun 	{
143*4882a593Smuzhiyun 		.name	= "filesystem",
144*4882a593Smuzhiyun 		.size	= 0x01C00000,
145*4882a593Smuzhiyun 		.offset = 0,
146*4882a593Smuzhiyun 	},
147*4882a593Smuzhiyun 	{
148*4882a593Smuzhiyun 		.name	= "yamon",
149*4882a593Smuzhiyun 		.size	= 0x00100000,
150*4882a593Smuzhiyun 		.offset = MTDPART_OFS_APPEND,
151*4882a593Smuzhiyun 		.mask_flags = MTD_WRITEABLE,
152*4882a593Smuzhiyun 	},
153*4882a593Smuzhiyun 	{
154*4882a593Smuzhiyun 		.name	= "kernel",
155*4882a593Smuzhiyun 		.size	= 0x002c0000,
156*4882a593Smuzhiyun 		.offset = MTDPART_OFS_APPEND,
157*4882a593Smuzhiyun 	},
158*4882a593Smuzhiyun 	{
159*4882a593Smuzhiyun 		.name	= "yamon env",
160*4882a593Smuzhiyun 		.size	= 0x00040000,
161*4882a593Smuzhiyun 		.offset = MTDPART_OFS_APPEND,
162*4882a593Smuzhiyun 	},
163*4882a593Smuzhiyun };
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun static struct physmap_flash_data mtx1_flash_data = {
166*4882a593Smuzhiyun 	.width		= 4,
167*4882a593Smuzhiyun 	.nr_parts	= 4,
168*4882a593Smuzhiyun 	.parts		= mtx1_mtd_partitions,
169*4882a593Smuzhiyun };
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun static struct resource mtx1_mtd_resource = {
172*4882a593Smuzhiyun 	.start	= 0x1e000000,
173*4882a593Smuzhiyun 	.end	= 0x1fffffff,
174*4882a593Smuzhiyun 	.flags	= IORESOURCE_MEM,
175*4882a593Smuzhiyun };
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun static struct platform_device mtx1_mtd = {
178*4882a593Smuzhiyun 	.name		= "physmap-flash",
179*4882a593Smuzhiyun 	.dev		= {
180*4882a593Smuzhiyun 		.platform_data	= &mtx1_flash_data,
181*4882a593Smuzhiyun 	},
182*4882a593Smuzhiyun 	.num_resources	= 1,
183*4882a593Smuzhiyun 	.resource	= &mtx1_mtd_resource,
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun static struct resource alchemy_pci_host_res[] = {
187*4882a593Smuzhiyun 	[0] = {
188*4882a593Smuzhiyun 		.start	= AU1500_PCI_PHYS_ADDR,
189*4882a593Smuzhiyun 		.end	= AU1500_PCI_PHYS_ADDR + 0xfff,
190*4882a593Smuzhiyun 		.flags	= IORESOURCE_MEM,
191*4882a593Smuzhiyun 	},
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun 
mtx1_pci_idsel(unsigned int devsel,int assert)194*4882a593Smuzhiyun static int mtx1_pci_idsel(unsigned int devsel, int assert)
195*4882a593Smuzhiyun {
196*4882a593Smuzhiyun 	/* This function is only necessary to support a proprietary Cardbus
197*4882a593Smuzhiyun 	 * adapter on the mtx-1 "singleboard" variant. It triggers a custom
198*4882a593Smuzhiyun 	 * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
199*4882a593Smuzhiyun 	 */
200*4882a593Smuzhiyun 	udelay(1);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	if (assert && devsel != 0)
203*4882a593Smuzhiyun 		/* Suppress signal to Cardbus */
204*4882a593Smuzhiyun 		alchemy_gpio_set_value(1, 0);	/* set EXT_IO3 OFF */
205*4882a593Smuzhiyun 	else
206*4882a593Smuzhiyun 		alchemy_gpio_set_value(1, 1);	/* set EXT_IO3 ON */
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	udelay(1);
209*4882a593Smuzhiyun 	return 1;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun static const char mtx1_irqtab[][5] = {
213*4882a593Smuzhiyun 	[0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
214*4882a593Smuzhiyun 	[1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
215*4882a593Smuzhiyun 	[2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
216*4882a593Smuzhiyun 	[3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
217*4882a593Smuzhiyun 	[4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
218*4882a593Smuzhiyun 	[5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
219*4882a593Smuzhiyun 	[6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
220*4882a593Smuzhiyun 	[7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
221*4882a593Smuzhiyun };
222*4882a593Smuzhiyun 
mtx1_map_pci_irq(const struct pci_dev * d,u8 slot,u8 pin)223*4882a593Smuzhiyun static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
224*4882a593Smuzhiyun {
225*4882a593Smuzhiyun 	return mtx1_irqtab[slot][pin];
226*4882a593Smuzhiyun }
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun static struct alchemy_pci_platdata mtx1_pci_pd = {
229*4882a593Smuzhiyun 	.board_map_irq	 = mtx1_map_pci_irq,
230*4882a593Smuzhiyun 	.board_pci_idsel = mtx1_pci_idsel,
231*4882a593Smuzhiyun 	.pci_cfg_set	 = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
232*4882a593Smuzhiyun 			   PCI_CONFIG_CH |
233*4882a593Smuzhiyun #if defined(__MIPSEB__)
234*4882a593Smuzhiyun 			   PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
235*4882a593Smuzhiyun #else
236*4882a593Smuzhiyun 			   0,
237*4882a593Smuzhiyun #endif
238*4882a593Smuzhiyun };
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun static struct platform_device mtx1_pci_host = {
241*4882a593Smuzhiyun 	.dev.platform_data = &mtx1_pci_pd,
242*4882a593Smuzhiyun 	.name		= "alchemy-pci",
243*4882a593Smuzhiyun 	.id		= 0,
244*4882a593Smuzhiyun 	.num_resources	= ARRAY_SIZE(alchemy_pci_host_res),
245*4882a593Smuzhiyun 	.resource	= alchemy_pci_host_res,
246*4882a593Smuzhiyun };
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun static struct platform_device *mtx1_devs[] __initdata = {
249*4882a593Smuzhiyun 	&mtx1_pci_host,
250*4882a593Smuzhiyun 	&mtx1_gpio_leds,
251*4882a593Smuzhiyun 	&mtx1_wdt,
252*4882a593Smuzhiyun 	&mtx1_button,
253*4882a593Smuzhiyun 	&mtx1_mtd,
254*4882a593Smuzhiyun };
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
257*4882a593Smuzhiyun 	.phy_search_highest_addr	= 1,
258*4882a593Smuzhiyun 	.phy1_search_mac0		= 1,
259*4882a593Smuzhiyun };
260*4882a593Smuzhiyun 
mtx1_register_devices(void)261*4882a593Smuzhiyun static int __init mtx1_register_devices(void)
262*4882a593Smuzhiyun {
263*4882a593Smuzhiyun 	int rc;
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH);
266*4882a593Smuzhiyun 	irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW);
267*4882a593Smuzhiyun 	irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW);
268*4882a593Smuzhiyun 	irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW);
269*4882a593Smuzhiyun 	irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 	au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun 	rc = gpio_request(mtx1_gpio_button[0].gpio,
274*4882a593Smuzhiyun 					mtx1_gpio_button[0].desc);
275*4882a593Smuzhiyun 	if (rc < 0) {
276*4882a593Smuzhiyun 		printk(KERN_INFO "mtx1: failed to request %d\n",
277*4882a593Smuzhiyun 					mtx1_gpio_button[0].gpio);
278*4882a593Smuzhiyun 		goto out;
279*4882a593Smuzhiyun 	}
280*4882a593Smuzhiyun 	gpio_direction_input(mtx1_gpio_button[0].gpio);
281*4882a593Smuzhiyun out:
282*4882a593Smuzhiyun 	gpiod_add_lookup_table(&mtx1_wdt_gpio_table);
283*4882a593Smuzhiyun 	return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
284*4882a593Smuzhiyun }
285*4882a593Smuzhiyun arch_initcall(mtx1_register_devices);
286