Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*
  2 *  RouterBoard 500 Platform devices
  3 *
  4 *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  5 *  Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  6 *
  7 *  This program is free software; you can redistribute it and/or modify
  8 *  it under the terms of the GNU General Public License as published by
  9 *  the Free Software Foundation; either version 2 of the License, or
 10 *  (at your option) any later version.
 11 *
 12 *  This program is distributed in the hope that it will be useful,
 13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *  GNU General Public License for more details.
 16 */
 17#include <linux/kernel.h>
 18#include <linux/export.h>
 19#include <linux/init.h>
 20#include <linux/ctype.h>
 21#include <linux/string.h>
 22#include <linux/platform_device.h>
 23#include <linux/mtd/nand.h>
 24#include <linux/mtd/mtd.h>
 25#include <linux/mtd/partitions.h>
 
 26#include <linux/gpio_keys.h>
 27#include <linux/input.h>
 28#include <linux/serial_8250.h>
 29
 30#include <asm/bootinfo.h>
 31
 32#include <asm/mach-rc32434/rc32434.h>
 33#include <asm/mach-rc32434/dma.h>
 34#include <asm/mach-rc32434/dma_v.h>
 35#include <asm/mach-rc32434/eth.h>
 36#include <asm/mach-rc32434/rb.h>
 37#include <asm/mach-rc32434/integ.h>
 38#include <asm/mach-rc32434/gpio.h>
 39#include <asm/mach-rc32434/irq.h>
 40
 41#define ETH0_RX_DMA_ADDR  (DMA0_BASE_ADDR + 0 * DMA_CHAN_OFFSET)
 42#define ETH0_TX_DMA_ADDR  (DMA0_BASE_ADDR + 1 * DMA_CHAN_OFFSET)
 43
 44extern unsigned int idt_cpu_freq;
 45
 46static struct mpmc_device dev3;
 47
 48void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
 49{
 50	unsigned long flags;
 51
 52	spin_lock_irqsave(&dev3.lock, flags);
 53
 54	dev3.state = (dev3.state | or_mask) & ~nand_mask;
 55	writeb(dev3.state, dev3.base);
 56
 57	spin_unlock_irqrestore(&dev3.lock, flags);
 58}
 59EXPORT_SYMBOL(set_latch_u5);
 60
 61unsigned char get_latch_u5(void)
 62{
 63	return dev3.state;
 64}
 65EXPORT_SYMBOL(get_latch_u5);
 66
 67static struct resource korina_dev0_res[] = {
 68	{
 69		.name = "korina_regs",
 70		.start = ETH0_BASE_ADDR,
 71		.end = ETH0_BASE_ADDR + sizeof(struct eth_regs),
 72		.flags = IORESOURCE_MEM,
 73	 }, {
 74		.name = "korina_rx",
 75		.start = ETH0_DMA_RX_IRQ,
 76		.end = ETH0_DMA_RX_IRQ,
 77		.flags = IORESOURCE_IRQ
 78	}, {
 79		.name = "korina_tx",
 80		.start = ETH0_DMA_TX_IRQ,
 81		.end = ETH0_DMA_TX_IRQ,
 82		.flags = IORESOURCE_IRQ
 83	}, {
 84		.name = "korina_ovr",
 85		.start = ETH0_RX_OVR_IRQ,
 86		.end = ETH0_RX_OVR_IRQ,
 87		.flags = IORESOURCE_IRQ
 88	}, {
 89		.name = "korina_und",
 90		.start = ETH0_TX_UND_IRQ,
 91		.end = ETH0_TX_UND_IRQ,
 92		.flags = IORESOURCE_IRQ
 93	}, {
 94		.name = "korina_dma_rx",
 95		.start = ETH0_RX_DMA_ADDR,
 96		.end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
 97		.flags = IORESOURCE_MEM,
 98	 }, {
 99		.name = "korina_dma_tx",
100		.start = ETH0_TX_DMA_ADDR,
101		.end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
102		.flags = IORESOURCE_MEM,
103	 }
104};
105
106static struct korina_device korina_dev0_data = {
107	.name = "korina0",
108	.mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
109};
110
111static struct platform_device korina_dev0 = {
112	.id = -1,
113	.name = "korina",
114	.resource = korina_dev0_res,
115	.num_resources = ARRAY_SIZE(korina_dev0_res),
116};
117
118static struct resource cf_slot0_res[] = {
119	{
120		.name = "cf_membase",
121		.flags = IORESOURCE_MEM
122	}, {
123		.name = "cf_irq",
124		.start = (8 + 4 * 32 + CF_GPIO_NUM),	/* 149 */
125		.end = (8 + 4 * 32 + CF_GPIO_NUM),
126		.flags = IORESOURCE_IRQ
127	}
128};
129
130static struct cf_device cf_slot0_data = {
131	.gpio_pin = CF_GPIO_NUM
 
 
 
 
 
132};
133
134static struct platform_device cf_slot0 = {
135	.id = -1,
136	.name = "pata-rb532-cf",
137	.dev.platform_data = &cf_slot0_data,
138	.resource = cf_slot0_res,
139	.num_resources = ARRAY_SIZE(cf_slot0_res),
140};
141
142/* Resources and device for NAND */
143static int rb532_dev_ready(struct mtd_info *mtd)
144{
145	return gpio_get_value(GPIO_RDY);
146}
147
148static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
149{
150	struct nand_chip *chip = mtd->priv;
151	unsigned char orbits, nandbits;
152
153	if (ctrl & NAND_CTRL_CHANGE) {
154		orbits = (ctrl & NAND_CLE) << 1;
155		orbits |= (ctrl & NAND_ALE) >> 1;
156
157		nandbits = (~ctrl & NAND_CLE) << 1;
158		nandbits |= (~ctrl & NAND_ALE) >> 1;
159
160		set_latch_u5(orbits, nandbits);
161	}
162	if (cmd != NAND_CMD_NONE)
163		writeb(cmd, chip->IO_ADDR_W);
164}
165
166static struct resource nand_slot0_res[] = {
167	[0] = {
168		.name = "nand_membase",
169		.flags = IORESOURCE_MEM
170	}
171};
172
173static struct platform_nand_data rb532_nand_data = {
174	.ctrl.dev_ready = rb532_dev_ready,
175	.ctrl.cmd_ctrl	= rb532_cmd_ctrl,
176};
177
178static struct platform_device nand_slot0 = {
179	.name = "gen_nand",
180	.id = -1,
181	.resource = nand_slot0_res,
182	.num_resources = ARRAY_SIZE(nand_slot0_res),
183	.dev.platform_data = &rb532_nand_data,
184};
185
186static struct mtd_partition rb532_partition_info[] = {
187	{
188		.name = "Routerboard NAND boot",
189		.offset = 0,
190		.size = 4 * 1024 * 1024,
191	}, {
192		.name = "rootfs",
193		.offset = MTDPART_OFS_NXTBLK,
194		.size = MTDPART_SIZ_FULL,
195	}
196};
197
198static struct platform_device rb532_led = {
199	.name = "rb532-led",
200	.id = -1,
201};
202
203static struct platform_device rb532_button = {
204	.name	= "rb532-button",
205	.id	= -1,
206};
207
208static struct resource rb532_wdt_res[] = {
209	{
210		.name = "rb532_wdt_res",
211		.start = INTEG0_BASE_ADDR,
212		.end = INTEG0_BASE_ADDR + sizeof(struct integ),
213		.flags = IORESOURCE_MEM,
214	}
215};
216
217static struct platform_device rb532_wdt = {
218	.name 		= "rc32434_wdt",
219	.id 		= -1,
220	.resource 	= rb532_wdt_res,
221	.num_resources	= ARRAY_SIZE(rb532_wdt_res),
222};
223
224static struct plat_serial8250_port rb532_uart_res[] = {
225	{
 
226		.membase	= (char *)KSEG1ADDR(REGBASE + UART0BASE),
227		.irq		= UART0_IRQ,
228		.regshift	= 2,
229		.iotype		= UPIO_MEM,
230		.flags		= UPF_BOOT_AUTOCONF,
231	},
232	{
233		.flags		= 0,
234	}
235};
236
237static struct platform_device rb532_uart = {
238	.name              = "serial8250",
239	.id                = PLAT8250_DEV_PLATFORM,
240	.dev.platform_data = &rb532_uart_res,
241};
242
243static struct platform_device *rb532_devs[] = {
244	&korina_dev0,
245	&nand_slot0,
246	&cf_slot0,
247	&rb532_led,
248	&rb532_button,
249	&rb532_uart,
250	&rb532_wdt
251};
252
253static void __init parse_mac_addr(char *macstr)
254{
255	int i, h, l;
256
257	for (i = 0; i < 6; i++) {
258		if (i != 5 && *(macstr + 2) != ':')
259			return;
260
261		h = hex_to_bin(*macstr++);
262		if (h == -1)
263			return;
264
265		l = hex_to_bin(*macstr++);
266		if (l == -1)
267			return;
268
269		macstr++;
270		korina_dev0_data.mac[i] = (h << 4) + l;
271	}
272}
273
274
275/* NAND definitions */
276#define NAND_CHIP_DELAY	25
277
278static void __init rb532_nand_setup(void)
279{
280	switch (mips_machtype) {
281	case MACH_MIKROTIK_RB532A:
282		set_latch_u5(LO_FOFF | LO_CEX,
283				LO_ULED | LO_ALE | LO_CLE | LO_WPX);
284		break;
285	default:
286		set_latch_u5(LO_WPX | LO_FOFF | LO_CEX,
287				LO_ULED | LO_ALE | LO_CLE);
288		break;
289	}
290
291	/* Setup NAND specific settings */
292	rb532_nand_data.chip.nr_chips = 1;
293	rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info);
294	rb532_nand_data.chip.partitions = rb532_partition_info;
295	rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
296}
297
298
299static int __init plat_setup_devices(void)
300{
301	/* Look for the CF card reader */
302	if (!readl(IDT434_REG_BASE + DEV1MASK))
303		rb532_devs[2] = NULL;	/* disable cf_slot0 at index 2 */
304	else {
305		cf_slot0_res[0].start =
306		    readl(IDT434_REG_BASE + DEV1BASE);
307		cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
308	}
309
310	/* Read the NAND resources from the device controller */
311	nand_slot0_res[0].start = readl(IDT434_REG_BASE + DEV2BASE);
312	nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
313
314	/* Read and map device controller 3 */
315	dev3.base = ioremap_nocache(readl(IDT434_REG_BASE + DEV3BASE), 1);
316
317	if (!dev3.base) {
318		printk(KERN_ERR "rb532: cannot remap device controller 3\n");
319		return -ENXIO;
320	}
321
322	/* Initialise the NAND device */
323	rb532_nand_setup();
324
325	/* set the uart clock to the current cpu frequency */
326	rb532_uart_res[0].uartclk = idt_cpu_freq;
327
328	dev_set_drvdata(&korina_dev0.dev, &korina_dev0_data);
329
 
330	return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
331}
332
 
 
333static int __init setup_kmac(char *s)
334{
335	printk(KERN_INFO "korina mac = %s\n", s);
336	parse_mac_addr(s);
 
 
 
337	return 0;
338}
339
340__setup("kmac=", setup_kmac);
 
 
341
342arch_initcall(plat_setup_devices);
v5.9
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  RouterBoard 500 Platform devices
  4 *
  5 *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  6 *  Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
 
 
 
 
 
 
 
 
 
 
  7 */
  8#include <linux/kernel.h>
  9#include <linux/export.h>
 10#include <linux/init.h>
 11#include <linux/ctype.h>
 12#include <linux/string.h>
 13#include <linux/platform_device.h>
 14#include <linux/mtd/platnand.h>
 15#include <linux/mtd/mtd.h>
 16#include <linux/gpio.h>
 17#include <linux/gpio/machine.h>
 18#include <linux/gpio_keys.h>
 19#include <linux/input.h>
 20#include <linux/serial_8250.h>
 21
 22#include <asm/bootinfo.h>
 23
 24#include <asm/mach-rc32434/rc32434.h>
 25#include <asm/mach-rc32434/dma.h>
 26#include <asm/mach-rc32434/dma_v.h>
 27#include <asm/mach-rc32434/eth.h>
 28#include <asm/mach-rc32434/rb.h>
 29#include <asm/mach-rc32434/integ.h>
 30#include <asm/mach-rc32434/gpio.h>
 31#include <asm/mach-rc32434/irq.h>
 32
 33#define ETH0_RX_DMA_ADDR  (DMA0_BASE_ADDR + 0 * DMA_CHAN_OFFSET)
 34#define ETH0_TX_DMA_ADDR  (DMA0_BASE_ADDR + 1 * DMA_CHAN_OFFSET)
 35
 36extern unsigned int idt_cpu_freq;
 37
 38static struct mpmc_device dev3;
 39
 40void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
 41{
 42	unsigned long flags;
 43
 44	spin_lock_irqsave(&dev3.lock, flags);
 45
 46	dev3.state = (dev3.state | or_mask) & ~nand_mask;
 47	writeb(dev3.state, dev3.base);
 48
 49	spin_unlock_irqrestore(&dev3.lock, flags);
 50}
 51EXPORT_SYMBOL(set_latch_u5);
 52
 53unsigned char get_latch_u5(void)
 54{
 55	return dev3.state;
 56}
 57EXPORT_SYMBOL(get_latch_u5);
 58
 59static struct resource korina_dev0_res[] = {
 60	{
 61		.name = "korina_regs",
 62		.start = ETH0_BASE_ADDR,
 63		.end = ETH0_BASE_ADDR + sizeof(struct eth_regs),
 64		.flags = IORESOURCE_MEM,
 65	 }, {
 66		.name = "korina_rx",
 67		.start = ETH0_DMA_RX_IRQ,
 68		.end = ETH0_DMA_RX_IRQ,
 69		.flags = IORESOURCE_IRQ
 70	}, {
 71		.name = "korina_tx",
 72		.start = ETH0_DMA_TX_IRQ,
 73		.end = ETH0_DMA_TX_IRQ,
 74		.flags = IORESOURCE_IRQ
 75	}, {
 76		.name = "korina_ovr",
 77		.start = ETH0_RX_OVR_IRQ,
 78		.end = ETH0_RX_OVR_IRQ,
 79		.flags = IORESOURCE_IRQ
 80	}, {
 81		.name = "korina_und",
 82		.start = ETH0_TX_UND_IRQ,
 83		.end = ETH0_TX_UND_IRQ,
 84		.flags = IORESOURCE_IRQ
 85	}, {
 86		.name = "korina_dma_rx",
 87		.start = ETH0_RX_DMA_ADDR,
 88		.end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
 89		.flags = IORESOURCE_MEM,
 90	 }, {
 91		.name = "korina_dma_tx",
 92		.start = ETH0_TX_DMA_ADDR,
 93		.end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
 94		.flags = IORESOURCE_MEM,
 95	 }
 96};
 97
 98static struct korina_device korina_dev0_data = {
 99	.name = "korina0",
100	.mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
101};
102
103static struct platform_device korina_dev0 = {
104	.id = -1,
105	.name = "korina",
106	.resource = korina_dev0_res,
107	.num_resources = ARRAY_SIZE(korina_dev0_res),
108};
109
110static struct resource cf_slot0_res[] = {
111	{
112		.name = "cf_membase",
113		.flags = IORESOURCE_MEM
114	}, {
115		.name = "cf_irq",
116		.start = (8 + 4 * 32 + CF_GPIO_NUM),	/* 149 */
117		.end = (8 + 4 * 32 + CF_GPIO_NUM),
118		.flags = IORESOURCE_IRQ
119	}
120};
121
122static struct gpiod_lookup_table cf_slot0_gpio_table = {
123	.dev_id = "pata-rb532-cf",
124	.table = {
125		GPIO_LOOKUP("gpio0", CF_GPIO_NUM,
126			    NULL, GPIO_ACTIVE_HIGH),
127		{ },
128	},
129};
130
131static struct platform_device cf_slot0 = {
132	.id = -1,
133	.name = "pata-rb532-cf",
 
134	.resource = cf_slot0_res,
135	.num_resources = ARRAY_SIZE(cf_slot0_res),
136};
137
138/* Resources and device for NAND */
139static int rb532_dev_ready(struct nand_chip *chip)
140{
141	return gpio_get_value(GPIO_RDY);
142}
143
144static void rb532_cmd_ctrl(struct nand_chip *chip, int cmd, unsigned int ctrl)
145{
 
146	unsigned char orbits, nandbits;
147
148	if (ctrl & NAND_CTRL_CHANGE) {
149		orbits = (ctrl & NAND_CLE) << 1;
150		orbits |= (ctrl & NAND_ALE) >> 1;
151
152		nandbits = (~ctrl & NAND_CLE) << 1;
153		nandbits |= (~ctrl & NAND_ALE) >> 1;
154
155		set_latch_u5(orbits, nandbits);
156	}
157	if (cmd != NAND_CMD_NONE)
158		writeb(cmd, chip->legacy.IO_ADDR_W);
159}
160
161static struct resource nand_slot0_res[] = {
162	[0] = {
163		.name = "nand_membase",
164		.flags = IORESOURCE_MEM
165	}
166};
167
168static struct platform_nand_data rb532_nand_data = {
169	.ctrl.dev_ready = rb532_dev_ready,
170	.ctrl.cmd_ctrl	= rb532_cmd_ctrl,
171};
172
173static struct platform_device nand_slot0 = {
174	.name = "gen_nand",
175	.id = -1,
176	.resource = nand_slot0_res,
177	.num_resources = ARRAY_SIZE(nand_slot0_res),
178	.dev.platform_data = &rb532_nand_data,
179};
180
181static struct mtd_partition rb532_partition_info[] = {
182	{
183		.name = "Routerboard NAND boot",
184		.offset = 0,
185		.size = 4 * 1024 * 1024,
186	}, {
187		.name = "rootfs",
188		.offset = MTDPART_OFS_NXTBLK,
189		.size = MTDPART_SIZ_FULL,
190	}
191};
192
193static struct platform_device rb532_led = {
194	.name = "rb532-led",
195	.id = -1,
196};
197
198static struct platform_device rb532_button = {
199	.name	= "rb532-button",
200	.id	= -1,
201};
202
203static struct resource rb532_wdt_res[] = {
204	{
205		.name = "rb532_wdt_res",
206		.start = INTEG0_BASE_ADDR,
207		.end = INTEG0_BASE_ADDR + sizeof(struct integ),
208		.flags = IORESOURCE_MEM,
209	}
210};
211
212static struct platform_device rb532_wdt = {
213	.name		= "rc32434_wdt",
214	.id		= -1,
215	.resource	= rb532_wdt_res,
216	.num_resources	= ARRAY_SIZE(rb532_wdt_res),
217};
218
219static struct plat_serial8250_port rb532_uart_res[] = {
220	{
221		.type           = PORT_16550A,
222		.membase	= (char *)KSEG1ADDR(REGBASE + UART0BASE),
223		.irq		= UART0_IRQ,
224		.regshift	= 2,
225		.iotype		= UPIO_MEM,
226		.flags		= UPF_BOOT_AUTOCONF,
227	},
228	{
229		.flags		= 0,
230	}
231};
232
233static struct platform_device rb532_uart = {
234	.name		   = "serial8250",
235	.id		   = PLAT8250_DEV_PLATFORM,
236	.dev.platform_data = &rb532_uart_res,
237};
238
239static struct platform_device *rb532_devs[] = {
240	&korina_dev0,
241	&nand_slot0,
242	&cf_slot0,
243	&rb532_led,
244	&rb532_button,
245	&rb532_uart,
246	&rb532_wdt
247};
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249/* NAND definitions */
250#define NAND_CHIP_DELAY 25
251
252static void __init rb532_nand_setup(void)
253{
254	switch (mips_machtype) {
255	case MACH_MIKROTIK_RB532A:
256		set_latch_u5(LO_FOFF | LO_CEX,
257				LO_ULED | LO_ALE | LO_CLE | LO_WPX);
258		break;
259	default:
260		set_latch_u5(LO_WPX | LO_FOFF | LO_CEX,
261				LO_ULED | LO_ALE | LO_CLE);
262		break;
263	}
264
265	/* Setup NAND specific settings */
266	rb532_nand_data.chip.nr_chips = 1;
267	rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info);
268	rb532_nand_data.chip.partitions = rb532_partition_info;
269	rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
270}
271
272
273static int __init plat_setup_devices(void)
274{
275	/* Look for the CF card reader */
276	if (!readl(IDT434_REG_BASE + DEV1MASK))
277		rb532_devs[2] = NULL;	/* disable cf_slot0 at index 2 */
278	else {
279		cf_slot0_res[0].start =
280		    readl(IDT434_REG_BASE + DEV1BASE);
281		cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
282	}
283
284	/* Read the NAND resources from the device controller */
285	nand_slot0_res[0].start = readl(IDT434_REG_BASE + DEV2BASE);
286	nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
287
288	/* Read and map device controller 3 */
289	dev3.base = ioremap(readl(IDT434_REG_BASE + DEV3BASE), 1);
290
291	if (!dev3.base) {
292		printk(KERN_ERR "rb532: cannot remap device controller 3\n");
293		return -ENXIO;
294	}
295
296	/* Initialise the NAND device */
297	rb532_nand_setup();
298
299	/* set the uart clock to the current cpu frequency */
300	rb532_uart_res[0].uartclk = idt_cpu_freq;
301
302	dev_set_drvdata(&korina_dev0.dev, &korina_dev0_data);
303
304	gpiod_add_lookup_table(&cf_slot0_gpio_table);
305	return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
306}
307
308#ifdef CONFIG_NET
309
310static int __init setup_kmac(char *s)
311{
312	printk(KERN_INFO "korina mac = %s\n", s);
313	if (!mac_pton(s, korina_dev0_data.mac)) {
314		printk(KERN_ERR "Invalid mac\n");
315		return -EINVAL;
316	}
317	return 0;
318}
319
320__setup("kmac=", setup_kmac);
321
322#endif /* CONFIG_NET */
323
324arch_initcall(plat_setup_devices);