File Index
Files and directories
Sign in
FILE

setup.c

File preview with syntax highlighting.

linux-6.19.14/arch/mips/txx9/generic/setup.c C
  1/*
  2 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
  3 *	    and RBTX49xx patch from CELF patch archive.
  4 *
  5 * 2003-2005 (c) MontaVista Software, Inc.
  6 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
  7 *
  8 * This file is subject to the terms and conditions of the GNU General Public
  9 * License.  See the file "COPYING" in the main directory of this archive
 10 * for more details.
 11 */
 12#include <linux/init.h>
 13#include <linux/kernel.h>
 14#include <linux/types.h>
 15#include <linux/interrupt.h>
 16#include <linux/string.h>
 17#include <linux/export.h>
 18#include <linux/clk-provider.h>
 19#include <linux/clkdev.h>
 20#include <linux/err.h>
 21#include <linux/gpio/driver.h>
 22#include <linux/platform_device.h>
 23#include <linux/platform_data/txx9/ndfmc.h>
 24#include <linux/serial_core.h>
 25#include <linux/mtd/physmap.h>
 26#include <linux/leds.h>
 27#include <linux/device.h>
 28#include <linux/slab.h>
 29#include <linux/io.h>
 30#include <linux/irq.h>
 31#include <asm/bootinfo.h>
 32#include <asm/idle.h>
 33#include <asm/time.h>
 34#include <asm/reboot.h>
 35#include <asm/r4kcache.h>
 36#include <asm/setup.h>
 37#include <asm/txx9/generic.h>
 38#include <asm/txx9/pci.h>
 39#include <asm/txx9tmr.h>
 40#include <asm/txx9/dmac.h>
 41#ifdef CONFIG_CPU_TX49XX
 42#include <asm/txx9/tx4938.h>
 43#endif
 44
 45/* EBUSC settings of TX4927, etc. */
 46struct resource txx9_ce_res[8];
 47static char txx9_ce_res_name[8][4];	/* "CEn" */
 48
 49/* pcode, internal register */
 50unsigned int txx9_pcode;
 51char txx9_pcode_str[8];
 52static struct resource txx9_reg_res = {
 53	.name = txx9_pcode_str,
 54	.flags = IORESOURCE_MEM,
 55};
 56void __init
 57txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
 58{
 59	int i;
 60
 61	for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
 62		sprintf(txx9_ce_res_name[i], "CE%d", i);
 63		txx9_ce_res[i].flags = IORESOURCE_MEM;
 64		txx9_ce_res[i].name = txx9_ce_res_name[i];
 65	}
 66
 67	txx9_pcode = pcode;
 68	sprintf(txx9_pcode_str, "TX%x", pcode);
 69	if (base) {
 70		txx9_reg_res.start = base & 0xfffffffffULL;
 71		txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
 72		request_resource(&iomem_resource, &txx9_reg_res);
 73	}
 74}
 75
 76/* clocks */
 77unsigned int txx9_master_clock;
 78unsigned int txx9_cpu_clock;
 79unsigned int txx9_gbus_clock;
 80
 81int txx9_ccfg_toeon __initdata = 1;
 82
 83#define BOARD_VEC(board)	extern struct txx9_board_vec board;
 84#include <asm/txx9/boards.h>
 85#undef BOARD_VEC
 86
 87struct txx9_board_vec *txx9_board_vec __initdata;
 88static char txx9_system_type[32];
 89
 90static struct txx9_board_vec *board_vecs[] __initdata = {
 91#define BOARD_VEC(board)	&board,
 92#include <asm/txx9/boards.h>
 93#undef BOARD_VEC
 94};
 95
 96static struct txx9_board_vec *__init find_board_byname(const char *name)
 97{
 98	int i;
 99
100	/* search board_vecs table */
101	for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
102		if (strstr(board_vecs[i]->system, name))
103			return board_vecs[i];
104	}
105	return NULL;
106}
107
108static void __init prom_init_cmdline(void)
109{
110	int argc;
111	int *argv32;
112	int i;			/* Always ignore the "-c" at argv[0] */
113
114	if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) {
115		/*
116		 * argc is not a valid number, or argv32 is not a valid
117		 * pointer
118		 */
119		argc = 0;
120		argv32 = NULL;
121	} else {
122		argc = (int)fw_arg0;
123		argv32 = (int *)fw_arg1;
124	}
125
126	arcs_cmdline[0] = '\0';
127
128	for (i = 1; i < argc; i++) {
129		char *str = (char *)(long)argv32[i];
130		if (i != 1)
131			strcat(arcs_cmdline, " ");
132		if (strchr(str, ' ')) {
133			strcat(arcs_cmdline, "\"");
134			strcat(arcs_cmdline, str);
135			strcat(arcs_cmdline, "\"");
136		} else
137			strcat(arcs_cmdline, str);
138	}
139}
140
141static int txx9_ic_disable __initdata;
142static int txx9_dc_disable __initdata;
143
144#if defined(CONFIG_CPU_TX49XX)
145/* flush all cache on very early stage (before 4k_cache_init) */
146static void __init early_flush_dcache(void)
147{
148	unsigned int conf = read_c0_config();
149	unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
150	unsigned int linesz = 32;
151	unsigned long addr, end;
152
153	end = INDEX_BASE + dc_size / 4;
154	/* 4way, waybit=0 */
155	for (addr = INDEX_BASE; addr < end; addr += linesz) {
156		cache_op(Index_Writeback_Inv_D, addr | 0);
157		cache_op(Index_Writeback_Inv_D, addr | 1);
158		cache_op(Index_Writeback_Inv_D, addr | 2);
159		cache_op(Index_Writeback_Inv_D, addr | 3);
160	}
161}
162
163static void __init txx9_cache_fixup(void)
164{
165	unsigned int conf;
166
167	conf = read_c0_config();
168	/* flush and disable */
169	if (txx9_ic_disable) {
170		conf |= TX49_CONF_IC;
171		write_c0_config(conf);
172	}
173	if (txx9_dc_disable) {
174		early_flush_dcache();
175		conf |= TX49_CONF_DC;
176		write_c0_config(conf);
177	}
178
179	/* enable cache */
180	conf = read_c0_config();
181	if (!txx9_ic_disable)
182		conf &= ~TX49_CONF_IC;
183	if (!txx9_dc_disable)
184		conf &= ~TX49_CONF_DC;
185	write_c0_config(conf);
186
187	if (conf & TX49_CONF_IC)
188		pr_info("TX49XX I-Cache disabled.\n");
189	if (conf & TX49_CONF_DC)
190		pr_info("TX49XX D-Cache disabled.\n");
191}
192#else
193static inline void txx9_cache_fixup(void)
194{
195}
196#endif
197
198static void __init preprocess_cmdline(void)
199{
200	static char cmdline[COMMAND_LINE_SIZE] __initdata;
201	char *s;
202
203	strscpy(cmdline, arcs_cmdline);
204	s = cmdline;
205	arcs_cmdline[0] = '\0';
206	while (s && *s) {
207		char *str = strsep(&s, " ");
208		if (strncmp(str, "board=", 6) == 0) {
209			txx9_board_vec = find_board_byname(str + 6);
210			continue;
211		} else if (strncmp(str, "masterclk=", 10) == 0) {
212			unsigned int val;
213			if (kstrtouint(str + 10, 10, &val) == 0)
214				txx9_master_clock = val;
215			continue;
216		} else if (strcmp(str, "icdisable") == 0) {
217			txx9_ic_disable = 1;
218			continue;
219		} else if (strcmp(str, "dcdisable") == 0) {
220			txx9_dc_disable = 1;
221			continue;
222		} else if (strcmp(str, "toeoff") == 0) {
223			txx9_ccfg_toeon = 0;
224			continue;
225		} else if (strcmp(str, "toeon") == 0) {
226			txx9_ccfg_toeon = 1;
227			continue;
228		}
229		if (arcs_cmdline[0])
230			strcat(arcs_cmdline, " ");
231		strcat(arcs_cmdline, str);
232	}
233
234	txx9_cache_fixup();
235}
236
237static void __init select_board(void)
238{
239	const char *envstr;
240
241	/* first, determine by "board=" argument in preprocess_cmdline() */
242	if (txx9_board_vec)
243		return;
244	/* next, determine by "board" envvar */
245	envstr = prom_getenv("board");
246	if (envstr) {
247		txx9_board_vec = find_board_byname(envstr);
248		if (txx9_board_vec)
249			return;
250	}
251
252	/* select "default" board */
253#ifdef CONFIG_CPU_TX49XX
254	switch (TX4938_REV_PCODE()) {
255#ifdef CONFIG_TOSHIBA_RBTX4927
256	case 0x4927:
257		txx9_board_vec = &rbtx4927_vec;
258		break;
259	case 0x4937:
260		txx9_board_vec = &rbtx4937_vec;
261		break;
262#endif
263	}
264#endif
265}
266
267void __init prom_init(void)
268{
269	prom_init_cmdline();
270	preprocess_cmdline();
271	select_board();
272
273	strscpy(txx9_system_type, txx9_board_vec->system);
274
275	txx9_board_vec->prom_init();
276}
277
278const char *get_system_type(void)
279{
280	return txx9_system_type;
281}
282
283const char *__init prom_getenv(const char *name)
284{
285	const s32 *str;
286
287	if (fw_arg2 < CKSEG0)
288		return NULL;
289
290	str = (const s32 *)fw_arg2;
291	/* YAMON style ("name", "value" pairs) */
292	while (str[0] && str[1]) {
293		if (!strcmp((const char *)(unsigned long)str[0], name))
294			return (const char *)(unsigned long)str[1];
295		str += 2;
296	}
297	return NULL;
298}
299
300static void __noreturn txx9_machine_halt(void)
301{
302	local_irq_disable();
303	clear_c0_status(ST0_IM);
304	while (1) {
305		if (cpu_wait) {
306			(*cpu_wait)();
307			if (cpu_has_counter) {
308				/*
309				 * Clear counter interrupt while it
310				 * breaks WAIT instruction even if
311				 * masked.
312				 */
313				write_c0_compare(0);
314			}
315		}
316	}
317}
318
319/* Watchdog support */
320void __init txx9_wdt_init(unsigned long base)
321{
322	struct resource res = {
323		.start	= base,
324		.end	= base + 0x100 - 1,
325		.flags	= IORESOURCE_MEM,
326	};
327	platform_device_register_simple("txx9wdt", -1, &res, 1);
328}
329
330void txx9_wdt_now(unsigned long base)
331{
332	struct txx9_tmr_reg __iomem *tmrptr =
333		ioremap(base, sizeof(struct txx9_tmr_reg));
334	/* disable watch dog timer */
335	__raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
336	__raw_writel(0, &tmrptr->tcr);
337	/* kick watchdog */
338	__raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
339	__raw_writel(1, &tmrptr->cpra); /* immediate */
340	__raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
341		     &tmrptr->tcr);
342}
343
344/* SPI support */
345void __init txx9_spi_init(int busid, unsigned long base, int irq)
346{
347	struct resource res[] = {
348		{
349			.start	= base,
350			.end	= base + 0x20 - 1,
351			.flags	= IORESOURCE_MEM,
352		}, {
353			.start	= irq,
354			.flags	= IORESOURCE_IRQ,
355		},
356	};
357	platform_device_register_simple("spi_txx9", busid,
358					res, ARRAY_SIZE(res));
359}
360
361void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
362{
363	struct platform_device *pdev =
364		platform_device_alloc("tc35815-mac", id);
365	if (!pdev ||
366	    platform_device_add_data(pdev, ethaddr, 6) ||
367	    platform_device_add(pdev))
368		platform_device_put(pdev);
369}
370
371void __init txx9_sio_init(unsigned long baseaddr, int irq,
372			  unsigned int line, unsigned int sclk, int nocts)
373{
374#ifdef CONFIG_SERIAL_TXX9
375	struct uart_port req;
376
377	memset(&req, 0, sizeof(req));
378	req.line = line;
379	req.iotype = UPIO_MEM;
380	req.membase = ioremap(baseaddr, 0x24);
381	req.mapbase = baseaddr;
382	req.irq = irq;
383	if (!nocts)
384		req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
385	if (sclk) {
386		req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
387		req.uartclk = sclk;
388	} else
389		req.uartclk = TXX9_IMCLK;
390	early_serial_txx9_setup(&req);
391#endif /* CONFIG_SERIAL_TXX9 */
392}
393
394#ifdef CONFIG_EARLY_PRINTK
395static void null_prom_putchar(char c)
396{
397}
398void (*txx9_prom_putchar)(char c) = null_prom_putchar;
399
400void prom_putchar(char c)
401{
402	txx9_prom_putchar(c);
403}
404
405static void __iomem *early_txx9_sio_port;
406
407static void early_txx9_sio_putchar(char c)
408{
409#define TXX9_SICISR	0x0c
410#define TXX9_SITFIFO	0x1c
411#define TXX9_SICISR_TXALS	0x00000002
412	while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
413		 TXX9_SICISR_TXALS))
414		;
415	__raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
416}
417
418void __init txx9_sio_putchar_init(unsigned long baseaddr)
419{
420	early_txx9_sio_port = ioremap(baseaddr, 0x24);
421	txx9_prom_putchar = early_txx9_sio_putchar;
422}
423#endif /* CONFIG_EARLY_PRINTK */
424
425/* wrappers */
426void __init plat_mem_setup(void)
427{
428	ioport_resource.start = 0;
429	ioport_resource.end = ~0UL;	/* no limit */
430	iomem_resource.start = 0;
431	iomem_resource.end = ~0UL;	/* no limit */
432
433	/* fallback restart/halt routines */
434	_machine_restart = (void (*)(char *))txx9_machine_halt;
435	_machine_halt = txx9_machine_halt;
436	pm_power_off = txx9_machine_halt;
437
438#ifdef CONFIG_PCI
439	pcibios_plat_setup = txx9_pcibios_setup;
440#endif
441	txx9_board_vec->mem_setup();
442}
443
444void __init arch_init_irq(void)
445{
446	txx9_board_vec->irq_setup();
447}
448
449void __init plat_time_init(void)
450{
451#ifdef CONFIG_CPU_TX49XX
452	mips_hpt_frequency = txx9_cpu_clock / 2;
453#endif
454	txx9_board_vec->time_init();
455}
456
457static void txx9_clk_init(void)
458{
459	struct clk_hw *hw;
460	int error;
461
462	hw = clk_hw_register_fixed_rate(NULL, "gbus", NULL, 0, txx9_gbus_clock);
463	if (IS_ERR(hw)) {
464		error = PTR_ERR(hw);
465		goto fail;
466	}
467
468	hw = clk_hw_register_fixed_factor(NULL, "imbus", "gbus", 0, 1, 2);
469	error = clk_hw_register_clkdev(hw, "imbus_clk", NULL);
470	if (error)
471		goto fail;
472
473#ifdef CONFIG_CPU_TX49XX
474	if (TX4938_REV_PCODE() == 0x4938) {
475		hw = clk_hw_register_fixed_factor(NULL, "spi", "gbus", 0, 1, 4);
476		error = clk_hw_register_clkdev(hw, "spi-baseclk", NULL);
477		if (error)
478			goto fail;
479	}
480#endif
481
482	return;
483
484fail:
485	pr_err("Failed to register clocks: %d\n", error);
486}
487
488static int __init _txx9_arch_init(void)
489{
490	txx9_clk_init();
491
492	if (txx9_board_vec->arch_init)
493		txx9_board_vec->arch_init();
494	return 0;
495}
496arch_initcall(_txx9_arch_init);
497
498static int __init _txx9_device_init(void)
499{
500	if (txx9_board_vec->device_init)
501		txx9_board_vec->device_init();
502	return 0;
503}
504device_initcall(_txx9_device_init);
505
506int (*txx9_irq_dispatch)(int pending);
507asmlinkage void plat_irq_dispatch(void)
508{
509	int pending = read_c0_status() & read_c0_cause() & ST0_IM;
510	int irq = txx9_irq_dispatch(pending);
511
512	if (likely(irq >= 0))
513		do_IRQ(irq);
514	else
515		spurious_interrupt();
516}
517
518/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
519#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
520static unsigned long __swizzle_addr_none(unsigned long port)
521{
522	return port;
523}
524unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
525EXPORT_SYMBOL(__swizzle_addr_b);
526#endif
527
528void __init txx9_physmap_flash_init(int no, unsigned long addr,
529				    unsigned long size,
530				    const struct physmap_flash_data *pdata)
531{
532#if IS_ENABLED(CONFIG_MTD_PHYSMAP)
533	struct resource res = {
534		.start = addr,
535		.end = addr + size - 1,
536		.flags = IORESOURCE_MEM,
537	};
538	struct platform_device *pdev;
539	static struct mtd_partition parts[2];
540	struct physmap_flash_data pdata_part;
541
542	/* If this area contained boot area, make separate partition */
543	if (pdata->nr_parts == 0 && !pdata->parts &&
544	    addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
545	    !parts[0].name) {
546		parts[0].name = "boot";
547		parts[0].offset = 0x1fc00000 - addr;
548		parts[0].size = addr + size - 0x1fc00000;
549		parts[1].name = "user";
550		parts[1].offset = 0;
551		parts[1].size = 0x1fc00000 - addr;
552		pdata_part = *pdata;
553		pdata_part.nr_parts = ARRAY_SIZE(parts);
554		pdata_part.parts = parts;
555		pdata = &pdata_part;
556	}
557
558	pdev = platform_device_alloc("physmap-flash", no);
559	if (!pdev ||
560	    platform_device_add_resources(pdev, &res, 1) ||
561	    platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
562	    platform_device_add(pdev))
563		platform_device_put(pdev);
564#endif
565}
566
567void __init txx9_ndfmc_init(unsigned long baseaddr,
568			    const struct txx9ndfmc_platform_data *pdata)
569{
570#if IS_ENABLED(CONFIG_MTD_NAND_TXX9NDFMC)
571	struct resource res = {
572		.start = baseaddr,
573		.end = baseaddr + 0x1000 - 1,
574		.flags = IORESOURCE_MEM,
575	};
576	struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
577
578	if (!pdev ||
579	    platform_device_add_resources(pdev, &res, 1) ||
580	    platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
581	    platform_device_add(pdev))
582		platform_device_put(pdev);
583#endif
584}
585
586#if IS_ENABLED(CONFIG_LEDS_GPIO)
587static DEFINE_SPINLOCK(txx9_iocled_lock);
588
589#define TXX9_IOCLED_MAXLEDS 8
590
591struct txx9_iocled_data {
592	struct gpio_chip chip;
593	u8 cur_val;
594	void __iomem *mmioaddr;
595	struct gpio_led_platform_data pdata;
596	struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
597	char names[TXX9_IOCLED_MAXLEDS][32];
598};
599
600static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
601{
602	struct txx9_iocled_data *data = gpiochip_get_data(chip);
603	return !!(data->cur_val & (1 << offset));
604}
605
606static int txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
607			   int value)
608{
609	struct txx9_iocled_data *data = gpiochip_get_data(chip);
610	unsigned long flags;
611	spin_lock_irqsave(&txx9_iocled_lock, flags);
612	if (value)
613		data->cur_val |= 1 << offset;
614	else
615		data->cur_val &= ~(1 << offset);
616	writeb(data->cur_val, data->mmioaddr);
617	mmiowb();
618	spin_unlock_irqrestore(&txx9_iocled_lock, flags);
619
620	return 0;
621}
622
623static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
624{
625	return 0;
626}
627
628static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
629			       int value)
630{
631	txx9_iocled_set(chip, offset, value);
632	return 0;
633}
634
635void __init txx9_iocled_init(unsigned long baseaddr,
636			     int basenum, unsigned int num, int lowactive,
637			     const char *color, char **deftriggers)
638{
639	struct txx9_iocled_data *iocled;
640	struct platform_device *pdev;
641	int i;
642	static char *default_triggers[] __initdata = {
643		"heartbeat",
644		"disk-activity",
645		"nand-disk",
646		NULL,
647	};
648
649	if (!deftriggers)
650		deftriggers = default_triggers;
651	iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
652	if (!iocled)
653		return;
654	iocled->mmioaddr = ioremap(baseaddr, 1);
655	if (!iocled->mmioaddr)
656		goto out_free;
657	iocled->chip.get = txx9_iocled_get;
658	iocled->chip.set = txx9_iocled_set;
659	iocled->chip.direction_input = txx9_iocled_dir_in;
660	iocled->chip.direction_output = txx9_iocled_dir_out;
661	iocled->chip.label = "iocled";
662	iocled->chip.base = basenum;
663	iocled->chip.ngpio = num;
664	if (gpiochip_add_data(&iocled->chip, iocled))
665		goto out_unmap;
666	if (basenum < 0)
667		basenum = iocled->chip.base;
668
669	pdev = platform_device_alloc("leds-gpio", basenum);
670	if (!pdev)
671		goto out_gpio;
672	iocled->pdata.num_leds = num;
673	iocled->pdata.leds = iocled->leds;
674	for (i = 0; i < num; i++) {
675		struct gpio_led *led = &iocled->leds[i];
676		snprintf(iocled->names[i], sizeof(iocled->names[i]),
677			 "iocled:%s:%u", color, i);
678		led->name = iocled->names[i];
679		led->gpio = basenum + i;
680		led->active_low = lowactive;
681		if (deftriggers && *deftriggers)
682			led->default_trigger = *deftriggers++;
683	}
684	pdev->dev.platform_data = &iocled->pdata;
685	if (platform_device_add(pdev))
686		goto out_pdev;
687	return;
688
689out_pdev:
690	platform_device_put(pdev);
691out_gpio:
692	gpiochip_remove(&iocled->chip);
693out_unmap:
694	iounmap(iocled->mmioaddr);
695out_free:
696	kfree(iocled);
697}
698#else /* CONFIG_LEDS_GPIO */
699void __init txx9_iocled_init(unsigned long baseaddr,
700			     int basenum, unsigned int num, int lowactive,
701			     const char *color, char **deftriggers)
702{
703}
704#endif /* CONFIG_LEDS_GPIO */
705
706void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
707			   const struct txx9dmac_platform_data *pdata)
708{
709#if IS_ENABLED(CONFIG_TXX9_DMAC)
710	struct resource res[] = {
711		{
712			.start = baseaddr,
713			.end = baseaddr + 0x800 - 1,
714			.flags = IORESOURCE_MEM,
715#ifndef CONFIG_MACH_TX49XX
716		}, {
717			.start = irq,
718			.flags = IORESOURCE_IRQ,
719#endif
720		}
721	};
722#ifdef CONFIG_MACH_TX49XX
723	struct resource chan_res[] = {
724		{
725			.flags = IORESOURCE_IRQ,
726		}
727	};
728#endif
729	struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
730	struct txx9dmac_chan_platform_data cpdata;
731	int i;
732
733	if (!pdev ||
734	    platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
735	    platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
736	    platform_device_add(pdev)) {
737		platform_device_put(pdev);
738		return;
739	}
740	memset(&cpdata, 0, sizeof(cpdata));
741	cpdata.dmac_dev = pdev;
742	for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
743#ifdef CONFIG_MACH_TX49XX
744		chan_res[0].start = irq + i;
745#endif
746		pdev = platform_device_alloc("txx9dmac-chan",
747					     id * TXX9_DMA_MAX_NR_CHANNELS + i);
748		if (!pdev ||
749#ifdef CONFIG_MACH_TX49XX
750		    platform_device_add_resources(pdev, chan_res,
751						  ARRAY_SIZE(chan_res)) ||
752#endif
753		    platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
754		    platform_device_add(pdev))
755			platform_device_put(pdev);
756	}
757#endif
758}
759
760void __init txx9_aclc_init(unsigned long baseaddr, int irq,
761			   unsigned int dmac_id,
762			   unsigned int dma_chan_out,
763			   unsigned int dma_chan_in)
764{
765}
766
767static const struct bus_type txx9_sramc_subsys = {
768	.name = "txx9_sram",
769	.dev_name = "txx9_sram",
770};
771
772struct txx9_sramc_dev {
773	struct device dev;
774	struct bin_attribute bindata_attr;
775	void __iomem *base;
776};
777
778static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
779			      const struct bin_attribute *bin_attr,
780			      char *buf, loff_t pos, size_t size)
781{
782	struct txx9_sramc_dev *dev = bin_attr->private;
783	size_t ramsize = bin_attr->size;
784
785	if (pos >= ramsize)
786		return 0;
787	if (pos + size > ramsize)
788		size = ramsize - pos;
789	memcpy_fromio(buf, dev->base + pos, size);
790	return size;
791}
792
793static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
794			       const struct bin_attribute *bin_attr,
795			       char *buf, loff_t pos, size_t size)
796{
797	struct txx9_sramc_dev *dev = bin_attr->private;
798	size_t ramsize = bin_attr->size;
799
800	if (pos >= ramsize)
801		return 0;
802	if (pos + size > ramsize)
803		size = ramsize - pos;
804	memcpy_toio(dev->base + pos, buf, size);
805	return size;
806}
807
808static void txx9_device_release(struct device *dev)
809{
810	struct txx9_sramc_dev *tdev;
811
812	tdev = container_of(dev, struct txx9_sramc_dev, dev);
813	kfree(tdev);
814}
815
816void __init txx9_sramc_init(struct resource *r)
817{
818	struct txx9_sramc_dev *dev;
819	size_t size;
820	int err;
821
822	err = subsys_system_register(&txx9_sramc_subsys, NULL);
823	if (err)
824		return;
825	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
826	if (!dev)
827		return;
828	size = resource_size(r);
829	dev->base = ioremap(r->start, size);
830	if (!dev->base) {
831		kfree(dev);
832		return;
833	}
834	dev->dev.release = &txx9_device_release;
835	dev->dev.bus = &txx9_sramc_subsys;
836	sysfs_bin_attr_init(&dev->bindata_attr);
837	dev->bindata_attr.attr.name = "bindata";
838	dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
839	dev->bindata_attr.read = txx9_sram_read;
840	dev->bindata_attr.write = txx9_sram_write;
841	dev->bindata_attr.size = size;
842	dev->bindata_attr.private = dev;
843	err = device_register(&dev->dev);
844	if (err)
845		goto exit_put;
846	err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
847	if (err) {
848		iounmap(dev->base);
849		device_unregister(&dev->dev);
850	}
851	return;
852exit_put:
853	iounmap(dev->base);
854	put_device(&dev->dev);
855}
~/ Read-only file preview.