2 * linux/arch/mips/txx9/generic/setup.c
4 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
5 * and RBTX49xx patch from CELF patch archive.
7 * 2003-2005 (c) MontaVista Software, Inc.
8 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/interrupt.h>
18 #include <linux/string.h>
19 #include <linux/module.h>
20 #include <linux/clk.h>
21 #include <linux/err.h>
22 #include <linux/gpio.h>
23 #include <linux/platform_device.h>
24 #include <linux/serial_core.h>
25 #include <linux/mtd/physmap.h>
26 #include <linux/leds.h>
27 #include <linux/sysdev.h>
28 #include <asm/bootinfo.h>
30 #include <asm/reboot.h>
31 #include <asm/r4kcache.h>
32 #include <asm/sections.h>
33 #include <asm/txx9/generic.h>
34 #include <asm/txx9/pci.h>
35 #include <asm/txx9tmr.h>
36 #include <asm/txx9/ndfmc.h>
37 #include <asm/txx9/dmac.h>
38 #ifdef CONFIG_CPU_TX49XX
39 #include <asm/txx9/tx4938.h>
42 /* EBUSC settings of TX4927, etc. */
43 struct resource txx9_ce_res
[8];
44 static char txx9_ce_res_name
[8][4]; /* "CEn" */
46 /* pcode, internal register */
47 unsigned int txx9_pcode
;
48 char txx9_pcode_str
[8];
49 static struct resource txx9_reg_res
= {
50 .name
= txx9_pcode_str
,
51 .flags
= IORESOURCE_MEM
,
54 txx9_reg_res_init(unsigned int pcode
, unsigned long base
, unsigned long size
)
58 for (i
= 0; i
< ARRAY_SIZE(txx9_ce_res
); i
++) {
59 sprintf(txx9_ce_res_name
[i
], "CE%d", i
);
60 txx9_ce_res
[i
].flags
= IORESOURCE_MEM
;
61 txx9_ce_res
[i
].name
= txx9_ce_res_name
[i
];
65 sprintf(txx9_pcode_str
, "TX%x", pcode
);
67 txx9_reg_res
.start
= base
& 0xfffffffffULL
;
68 txx9_reg_res
.end
= (base
& 0xfffffffffULL
) + (size
- 1);
69 request_resource(&iomem_resource
, &txx9_reg_res
);
74 unsigned int txx9_master_clock
;
75 unsigned int txx9_cpu_clock
;
76 unsigned int txx9_gbus_clock
;
78 #ifdef CONFIG_CPU_TX39XX
79 /* don't enable by default - see errata */
80 int txx9_ccfg_toeon __initdata
;
82 int txx9_ccfg_toeon __initdata
= 1;
85 /* Minimum CLK support */
87 struct clk
*clk_get(struct device
*dev
, const char *id
)
89 if (!strcmp(id
, "spi-baseclk"))
90 return (struct clk
*)((unsigned long)txx9_gbus_clock
/ 2 / 4);
91 if (!strcmp(id
, "imbus_clk"))
92 return (struct clk
*)((unsigned long)txx9_gbus_clock
/ 2);
93 return ERR_PTR(-ENOENT
);
95 EXPORT_SYMBOL(clk_get
);
97 int clk_enable(struct clk
*clk
)
101 EXPORT_SYMBOL(clk_enable
);
103 void clk_disable(struct clk
*clk
)
106 EXPORT_SYMBOL(clk_disable
);
108 unsigned long clk_get_rate(struct clk
*clk
)
110 return (unsigned long)clk
;
112 EXPORT_SYMBOL(clk_get_rate
);
114 void clk_put(struct clk
*clk
)
117 EXPORT_SYMBOL(clk_put
);
121 #ifdef CONFIG_GENERIC_GPIO
122 int gpio_to_irq(unsigned gpio
)
126 EXPORT_SYMBOL(gpio_to_irq
);
128 int irq_to_gpio(unsigned irq
)
132 EXPORT_SYMBOL(irq_to_gpio
);
135 #define BOARD_VEC(board) extern struct txx9_board_vec board;
136 #include <asm/txx9/boards.h>
139 struct txx9_board_vec
*txx9_board_vec __initdata
;
140 static char txx9_system_type
[32];
142 static struct txx9_board_vec
*board_vecs
[] __initdata
= {
143 #define BOARD_VEC(board) &board,
144 #include <asm/txx9/boards.h>
148 static struct txx9_board_vec
*__init
find_board_byname(const char *name
)
152 /* search board_vecs table */
153 for (i
= 0; i
< ARRAY_SIZE(board_vecs
); i
++) {
154 if (strstr(board_vecs
[i
]->system
, name
))
155 return board_vecs
[i
];
160 static void __init
prom_init_cmdline(void)
164 int i
; /* Always ignore the "-c" at argv[0] */
165 char builtin
[CL_SIZE
];
167 if (fw_arg0
>= CKSEG0
|| fw_arg1
< CKSEG0
) {
169 * argc is not a valid number, or argv32 is not a valid
176 argv32
= (int *)fw_arg1
;
179 /* ignore all built-in args if any f/w args given */
181 * But if built-in strings was started with '+', append them
182 * to command line args. If built-in was started with '-',
183 * ignore all f/w args.
186 if (arcs_cmdline
[0] == '+')
187 strcpy(builtin
, arcs_cmdline
+ 1);
188 else if (arcs_cmdline
[0] == '-') {
189 strcpy(builtin
, arcs_cmdline
+ 1);
191 } else if (argc
<= 1)
192 strcpy(builtin
, arcs_cmdline
);
193 arcs_cmdline
[0] = '\0';
195 for (i
= 1; i
< argc
; i
++) {
196 char *str
= (char *)(long)argv32
[i
];
198 strcat(arcs_cmdline
, " ");
199 if (strchr(str
, ' ')) {
200 strcat(arcs_cmdline
, "\"");
201 strcat(arcs_cmdline
, str
);
202 strcat(arcs_cmdline
, "\"");
204 strcat(arcs_cmdline
, str
);
206 /* append saved builtin args */
209 strcat(arcs_cmdline
, " ");
210 strcat(arcs_cmdline
, builtin
);
214 static int txx9_ic_disable __initdata
;
215 static int txx9_dc_disable __initdata
;
217 #if defined(CONFIG_CPU_TX49XX)
218 /* flush all cache on very early stage (before 4k_cache_init) */
219 static void __init
early_flush_dcache(void)
221 unsigned int conf
= read_c0_config();
222 unsigned int dc_size
= 1 << (12 + ((conf
& CONF_DC
) >> 6));
223 unsigned int linesz
= 32;
224 unsigned long addr
, end
;
226 end
= INDEX_BASE
+ dc_size
/ 4;
228 for (addr
= INDEX_BASE
; addr
< end
; addr
+= linesz
) {
229 cache_op(Index_Writeback_Inv_D
, addr
| 0);
230 cache_op(Index_Writeback_Inv_D
, addr
| 1);
231 cache_op(Index_Writeback_Inv_D
, addr
| 2);
232 cache_op(Index_Writeback_Inv_D
, addr
| 3);
236 static void __init
txx9_cache_fixup(void)
240 conf
= read_c0_config();
241 /* flush and disable */
242 if (txx9_ic_disable
) {
243 conf
|= TX49_CONF_IC
;
244 write_c0_config(conf
);
246 if (txx9_dc_disable
) {
247 early_flush_dcache();
248 conf
|= TX49_CONF_DC
;
249 write_c0_config(conf
);
253 conf
= read_c0_config();
254 if (!txx9_ic_disable
)
255 conf
&= ~TX49_CONF_IC
;
256 if (!txx9_dc_disable
)
257 conf
&= ~TX49_CONF_DC
;
258 write_c0_config(conf
);
260 if (conf
& TX49_CONF_IC
)
261 pr_info("TX49XX I-Cache disabled.\n");
262 if (conf
& TX49_CONF_DC
)
263 pr_info("TX49XX D-Cache disabled.\n");
265 #elif defined(CONFIG_CPU_TX39XX)
266 /* flush all cache on very early stage (before tx39_cache_init) */
267 static void __init
early_flush_dcache(void)
269 unsigned int conf
= read_c0_config();
270 unsigned int dc_size
= 1 << (10 + ((conf
& TX39_CONF_DCS_MASK
) >>
271 TX39_CONF_DCS_SHIFT
));
272 unsigned int linesz
= 16;
273 unsigned long addr
, end
;
275 end
= INDEX_BASE
+ dc_size
/ 2;
277 for (addr
= INDEX_BASE
; addr
< end
; addr
+= linesz
) {
278 cache_op(Index_Writeback_Inv_D
, addr
| 0);
279 cache_op(Index_Writeback_Inv_D
, addr
| 1);
283 static void __init
txx9_cache_fixup(void)
287 conf
= read_c0_config();
288 /* flush and disable */
289 if (txx9_ic_disable
) {
290 conf
&= ~TX39_CONF_ICE
;
291 write_c0_config(conf
);
293 if (txx9_dc_disable
) {
294 early_flush_dcache();
295 conf
&= ~TX39_CONF_DCE
;
296 write_c0_config(conf
);
300 conf
= read_c0_config();
301 if (!txx9_ic_disable
)
302 conf
|= TX39_CONF_ICE
;
303 if (!txx9_dc_disable
)
304 conf
|= TX39_CONF_DCE
;
305 write_c0_config(conf
);
307 if (!(conf
& TX39_CONF_ICE
))
308 pr_info("TX39XX I-Cache disabled.\n");
309 if (!(conf
& TX39_CONF_DCE
))
310 pr_info("TX39XX D-Cache disabled.\n");
313 static inline void txx9_cache_fixup(void)
318 static void __init
preprocess_cmdline(void)
320 char cmdline
[CL_SIZE
];
323 strcpy(cmdline
, arcs_cmdline
);
325 arcs_cmdline
[0] = '\0';
327 char *str
= strsep(&s
, " ");
328 if (strncmp(str
, "board=", 6) == 0) {
329 txx9_board_vec
= find_board_byname(str
+ 6);
331 } else if (strncmp(str
, "masterclk=", 10) == 0) {
333 if (strict_strtoul(str
+ 10, 10, &val
) == 0)
334 txx9_master_clock
= val
;
336 } else if (strcmp(str
, "icdisable") == 0) {
339 } else if (strcmp(str
, "dcdisable") == 0) {
342 } else if (strcmp(str
, "toeoff") == 0) {
345 } else if (strcmp(str
, "toeon") == 0) {
350 strcat(arcs_cmdline
, " ");
351 strcat(arcs_cmdline
, str
);
357 static void __init
select_board(void)
361 /* first, determine by "board=" argument in preprocess_cmdline() */
364 /* next, determine by "board" envvar */
365 envstr
= prom_getenv("board");
367 txx9_board_vec
= find_board_byname(envstr
);
372 /* select "default" board */
373 #ifdef CONFIG_CPU_TX39XX
374 txx9_board_vec
= &jmr3927_vec
;
376 #ifdef CONFIG_CPU_TX49XX
377 switch (TX4938_REV_PCODE()) {
378 #ifdef CONFIG_TOSHIBA_RBTX4927
380 txx9_board_vec
= &rbtx4927_vec
;
383 txx9_board_vec
= &rbtx4937_vec
;
386 #ifdef CONFIG_TOSHIBA_RBTX4938
388 txx9_board_vec
= &rbtx4938_vec
;
391 #ifdef CONFIG_TOSHIBA_RBTX4939
393 txx9_board_vec
= &rbtx4939_vec
;
400 void __init
prom_init(void)
403 preprocess_cmdline();
406 strcpy(txx9_system_type
, txx9_board_vec
->system
);
408 txx9_board_vec
->prom_init();
411 void __init
prom_free_prom_memory(void)
413 unsigned long saddr
= PAGE_SIZE
;
414 unsigned long eaddr
= __pa_symbol(&_text
);
417 free_init_pages("prom memory", saddr
, eaddr
);
420 const char *get_system_type(void)
422 return txx9_system_type
;
425 char * __init
prom_getcmdline(void)
427 return &(arcs_cmdline
[0]);
430 const char *__init
prom_getenv(const char *name
)
434 if (fw_arg2
< CKSEG0
)
437 str
= (const s32
*)fw_arg2
;
438 /* YAMON style ("name", "value" pairs) */
439 while (str
[0] && str
[1]) {
440 if (!strcmp((const char *)(unsigned long)str
[0], name
))
441 return (const char *)(unsigned long)str
[1];
447 static void __noreturn
txx9_machine_halt(void)
450 clear_c0_status(ST0_IM
);
454 if (cpu_has_counter
) {
456 * Clear counter interrupt while it
457 * breaks WAIT instruction even if
466 /* Watchdog support */
467 void __init
txx9_wdt_init(unsigned long base
)
469 struct resource res
= {
471 .end
= base
+ 0x100 - 1,
472 .flags
= IORESOURCE_MEM
,
474 platform_device_register_simple("txx9wdt", -1, &res
, 1);
477 void txx9_wdt_now(unsigned long base
)
479 struct txx9_tmr_reg __iomem
*tmrptr
=
480 ioremap(base
, sizeof(struct txx9_tmr_reg
));
481 /* disable watch dog timer */
482 __raw_writel(TXx9_TMWTMR_WDIS
| TXx9_TMWTMR_TWC
, &tmrptr
->wtmr
);
483 __raw_writel(0, &tmrptr
->tcr
);
485 __raw_writel(TXx9_TMWTMR_TWIE
, &tmrptr
->wtmr
);
486 __raw_writel(1, &tmrptr
->cpra
); /* immediate */
487 __raw_writel(TXx9_TMTCR_TCE
| TXx9_TMTCR_CCDE
| TXx9_TMTCR_TMODE_WDOG
,
492 void __init
txx9_spi_init(int busid
, unsigned long base
, int irq
)
494 struct resource res
[] = {
497 .end
= base
+ 0x20 - 1,
498 .flags
= IORESOURCE_MEM
,
501 .flags
= IORESOURCE_IRQ
,
504 platform_device_register_simple("spi_txx9", busid
,
505 res
, ARRAY_SIZE(res
));
508 void __init
txx9_ethaddr_init(unsigned int id
, unsigned char *ethaddr
)
510 struct platform_device
*pdev
=
511 platform_device_alloc("tc35815-mac", id
);
513 platform_device_add_data(pdev
, ethaddr
, 6) ||
514 platform_device_add(pdev
))
515 platform_device_put(pdev
);
518 void __init
txx9_sio_init(unsigned long baseaddr
, int irq
,
519 unsigned int line
, unsigned int sclk
, int nocts
)
521 #ifdef CONFIG_SERIAL_TXX9
522 struct uart_port req
;
524 memset(&req
, 0, sizeof(req
));
526 req
.iotype
= UPIO_MEM
;
527 req
.membase
= ioremap(baseaddr
, 0x24);
528 req
.mapbase
= baseaddr
;
531 req
.flags
|= UPF_BUGGY_UART
/*HAVE_CTS_LINE*/;
533 req
.flags
|= UPF_MAGIC_MULTIPLIER
/*USE_SCLK*/;
536 req
.uartclk
= TXX9_IMCLK
;
537 early_serial_txx9_setup(&req
);
538 #endif /* CONFIG_SERIAL_TXX9 */
541 #ifdef CONFIG_EARLY_PRINTK
542 static void __init
null_prom_putchar(char c
)
545 void (*txx9_prom_putchar
)(char c
) __initdata
= null_prom_putchar
;
547 void __init
prom_putchar(char c
)
549 txx9_prom_putchar(c
);
552 static void __iomem
*early_txx9_sio_port
;
554 static void __init
early_txx9_sio_putchar(char c
)
556 #define TXX9_SICISR 0x0c
557 #define TXX9_SITFIFO 0x1c
558 #define TXX9_SICISR_TXALS 0x00000002
559 while (!(__raw_readl(early_txx9_sio_port
+ TXX9_SICISR
) &
562 __raw_writel(c
, early_txx9_sio_port
+ TXX9_SITFIFO
);
565 void __init
txx9_sio_putchar_init(unsigned long baseaddr
)
567 early_txx9_sio_port
= ioremap(baseaddr
, 0x24);
568 txx9_prom_putchar
= early_txx9_sio_putchar
;
570 #endif /* CONFIG_EARLY_PRINTK */
573 void __init
plat_mem_setup(void)
575 ioport_resource
.start
= 0;
576 ioport_resource
.end
= ~0UL; /* no limit */
577 iomem_resource
.start
= 0;
578 iomem_resource
.end
= ~0UL; /* no limit */
580 /* fallback restart/halt routines */
581 _machine_restart
= (void (*)(char *))txx9_machine_halt
;
582 _machine_halt
= txx9_machine_halt
;
583 pm_power_off
= txx9_machine_halt
;
586 pcibios_plat_setup
= txx9_pcibios_setup
;
588 txx9_board_vec
->mem_setup();
591 void __init
arch_init_irq(void)
593 txx9_board_vec
->irq_setup();
596 void __init
plat_time_init(void)
598 #ifdef CONFIG_CPU_TX49XX
599 mips_hpt_frequency
= txx9_cpu_clock
/ 2;
601 txx9_board_vec
->time_init();
604 static int __init
_txx9_arch_init(void)
606 if (txx9_board_vec
->arch_init
)
607 txx9_board_vec
->arch_init();
610 arch_initcall(_txx9_arch_init
);
612 static int __init
_txx9_device_init(void)
614 if (txx9_board_vec
->device_init
)
615 txx9_board_vec
->device_init();
618 device_initcall(_txx9_device_init
);
620 int (*txx9_irq_dispatch
)(int pending
);
621 asmlinkage
void plat_irq_dispatch(void)
623 int pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
624 int irq
= txx9_irq_dispatch(pending
);
626 if (likely(irq
>= 0))
629 spurious_interrupt();
632 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
633 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
634 static unsigned long __swizzle_addr_none(unsigned long port
)
638 unsigned long (*__swizzle_addr_b
)(unsigned long port
) = __swizzle_addr_none
;
639 EXPORT_SYMBOL(__swizzle_addr_b
);
642 #ifdef NEEDS_TXX9_IOSWABW
643 static u16
ioswabw_default(volatile u16
*a
, u16 x
)
645 return le16_to_cpu(x
);
647 static u16
__mem_ioswabw_default(volatile u16
*a
, u16 x
)
651 u16 (*ioswabw
)(volatile u16
*a
, u16 x
) = ioswabw_default
;
652 EXPORT_SYMBOL(ioswabw
);
653 u16 (*__mem_ioswabw
)(volatile u16
*a
, u16 x
) = __mem_ioswabw_default
;
654 EXPORT_SYMBOL(__mem_ioswabw
);
657 void __init
txx9_physmap_flash_init(int no
, unsigned long addr
,
659 const struct physmap_flash_data
*pdata
)
661 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
662 struct resource res
= {
664 .end
= addr
+ size
- 1,
665 .flags
= IORESOURCE_MEM
,
667 struct platform_device
*pdev
;
668 #ifdef CONFIG_MTD_PARTITIONS
669 static struct mtd_partition parts
[2];
670 struct physmap_flash_data pdata_part
;
672 /* If this area contained boot area, make separate partition */
673 if (pdata
->nr_parts
== 0 && !pdata
->parts
&&
674 addr
< 0x1fc00000 && addr
+ size
> 0x1fc00000 &&
676 parts
[0].name
= "boot";
677 parts
[0].offset
= 0x1fc00000 - addr
;
678 parts
[0].size
= addr
+ size
- 0x1fc00000;
679 parts
[1].name
= "user";
681 parts
[1].size
= 0x1fc00000 - addr
;
683 pdata_part
.nr_parts
= ARRAY_SIZE(parts
);
684 pdata_part
.parts
= parts
;
688 pdev
= platform_device_alloc("physmap-flash", no
);
690 platform_device_add_resources(pdev
, &res
, 1) ||
691 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
692 platform_device_add(pdev
))
693 platform_device_put(pdev
);
697 void __init
txx9_ndfmc_init(unsigned long baseaddr
,
698 const struct txx9ndfmc_platform_data
*pdata
)
700 #if defined(CONFIG_MTD_NAND_TXX9NDFMC) || \
701 defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE)
702 struct resource res
= {
704 .end
= baseaddr
+ 0x1000 - 1,
705 .flags
= IORESOURCE_MEM
,
707 struct platform_device
*pdev
= platform_device_alloc("txx9ndfmc", -1);
710 platform_device_add_resources(pdev
, &res
, 1) ||
711 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
712 platform_device_add(pdev
))
713 platform_device_put(pdev
);
717 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
718 static DEFINE_SPINLOCK(txx9_iocled_lock
);
720 #define TXX9_IOCLED_MAXLEDS 8
722 struct txx9_iocled_data
{
723 struct gpio_chip chip
;
725 void __iomem
*mmioaddr
;
726 struct gpio_led_platform_data pdata
;
727 struct gpio_led leds
[TXX9_IOCLED_MAXLEDS
];
728 char names
[TXX9_IOCLED_MAXLEDS
][32];
731 static int txx9_iocled_get(struct gpio_chip
*chip
, unsigned int offset
)
733 struct txx9_iocled_data
*data
=
734 container_of(chip
, struct txx9_iocled_data
, chip
);
735 return data
->cur_val
& (1 << offset
);
738 static void txx9_iocled_set(struct gpio_chip
*chip
, unsigned int offset
,
741 struct txx9_iocled_data
*data
=
742 container_of(chip
, struct txx9_iocled_data
, chip
);
744 spin_lock_irqsave(&txx9_iocled_lock
, flags
);
746 data
->cur_val
|= 1 << offset
;
748 data
->cur_val
&= ~(1 << offset
);
749 writeb(data
->cur_val
, data
->mmioaddr
);
751 spin_unlock_irqrestore(&txx9_iocled_lock
, flags
);
754 static int txx9_iocled_dir_in(struct gpio_chip
*chip
, unsigned int offset
)
759 static int txx9_iocled_dir_out(struct gpio_chip
*chip
, unsigned int offset
,
762 txx9_iocled_set(chip
, offset
, value
);
766 void __init
txx9_iocled_init(unsigned long baseaddr
,
767 int basenum
, unsigned int num
, int lowactive
,
768 const char *color
, char **deftriggers
)
770 struct txx9_iocled_data
*iocled
;
771 struct platform_device
*pdev
;
773 static char *default_triggers
[] __initdata
= {
781 deftriggers
= default_triggers
;
782 iocled
= kzalloc(sizeof(*iocled
), GFP_KERNEL
);
785 iocled
->mmioaddr
= ioremap(baseaddr
, 1);
786 if (!iocled
->mmioaddr
)
788 iocled
->chip
.get
= txx9_iocled_get
;
789 iocled
->chip
.set
= txx9_iocled_set
;
790 iocled
->chip
.direction_input
= txx9_iocled_dir_in
;
791 iocled
->chip
.direction_output
= txx9_iocled_dir_out
;
792 iocled
->chip
.label
= "iocled";
793 iocled
->chip
.base
= basenum
;
794 iocled
->chip
.ngpio
= num
;
795 if (gpiochip_add(&iocled
->chip
))
798 basenum
= iocled
->chip
.base
;
800 pdev
= platform_device_alloc("leds-gpio", basenum
);
803 iocled
->pdata
.num_leds
= num
;
804 iocled
->pdata
.leds
= iocled
->leds
;
805 for (i
= 0; i
< num
; i
++) {
806 struct gpio_led
*led
= &iocled
->leds
[i
];
807 snprintf(iocled
->names
[i
], sizeof(iocled
->names
[i
]),
808 "iocled:%s:%u", color
, i
);
809 led
->name
= iocled
->names
[i
];
810 led
->gpio
= basenum
+ i
;
811 led
->active_low
= lowactive
;
812 if (deftriggers
&& *deftriggers
)
813 led
->default_trigger
= *deftriggers
++;
815 pdev
->dev
.platform_data
= &iocled
->pdata
;
816 if (platform_device_add(pdev
))
817 platform_device_put(pdev
);
819 #else /* CONFIG_LEDS_GPIO */
820 void __init
txx9_iocled_init(unsigned long baseaddr
,
821 int basenum
, unsigned int num
, int lowactive
,
822 const char *color
, char **deftriggers
)
825 #endif /* CONFIG_LEDS_GPIO */
827 void __init
txx9_dmac_init(int id
, unsigned long baseaddr
, int irq
,
828 const struct txx9dmac_platform_data
*pdata
)
830 #if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE)
831 struct resource res
[] = {
834 .end
= baseaddr
+ 0x800 - 1,
835 .flags
= IORESOURCE_MEM
,
836 #ifndef CONFIG_MACH_TX49XX
839 .flags
= IORESOURCE_IRQ
,
843 #ifdef CONFIG_MACH_TX49XX
844 struct resource chan_res
[] = {
846 .flags
= IORESOURCE_IRQ
,
850 struct platform_device
*pdev
= platform_device_alloc("txx9dmac", id
);
851 struct txx9dmac_chan_platform_data cpdata
;
855 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
856 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
857 platform_device_add(pdev
)) {
858 platform_device_put(pdev
);
861 memset(&cpdata
, 0, sizeof(cpdata
));
862 cpdata
.dmac_dev
= pdev
;
863 for (i
= 0; i
< TXX9_DMA_MAX_NR_CHANNELS
; i
++) {
864 #ifdef CONFIG_MACH_TX49XX
865 chan_res
[0].start
= irq
+ i
;
867 pdev
= platform_device_alloc("txx9dmac-chan",
868 id
* TXX9_DMA_MAX_NR_CHANNELS
+ i
);
870 #ifdef CONFIG_MACH_TX49XX
871 platform_device_add_resources(pdev
, chan_res
,
872 ARRAY_SIZE(chan_res
)) ||
874 platform_device_add_data(pdev
, &cpdata
, sizeof(cpdata
)) ||
875 platform_device_add(pdev
))
876 platform_device_put(pdev
);
881 void __init
txx9_aclc_init(unsigned long baseaddr
, int irq
,
882 unsigned int dmac_id
,
883 unsigned int dma_chan_out
,
884 unsigned int dma_chan_in
)
886 #if defined(CONFIG_SND_SOC_TXX9ACLC) || \
887 defined(CONFIG_SND_SOC_TXX9ACLC_MODULE)
888 unsigned int dma_base
= dmac_id
* TXX9_DMA_MAX_NR_CHANNELS
;
889 struct resource res
[] = {
892 .end
= baseaddr
+ 0x100 - 1,
893 .flags
= IORESOURCE_MEM
,
896 .flags
= IORESOURCE_IRQ
,
898 .name
= "txx9dmac-chan",
899 .start
= dma_base
+ dma_chan_out
,
900 .flags
= IORESOURCE_DMA
,
902 .name
= "txx9dmac-chan",
903 .start
= dma_base
+ dma_chan_in
,
904 .flags
= IORESOURCE_DMA
,
907 struct platform_device
*pdev
=
908 platform_device_alloc("txx9aclc-ac97", -1);
911 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
912 platform_device_add(pdev
))
913 platform_device_put(pdev
);
917 static struct sysdev_class txx9_sramc_sysdev_class
;
919 struct txx9_sramc_sysdev
{
920 struct sys_device dev
;
921 struct bin_attribute bindata_attr
;
925 static ssize_t
txx9_sram_read(struct kobject
*kobj
,
926 struct bin_attribute
*bin_attr
,
927 char *buf
, loff_t pos
, size_t size
)
929 struct txx9_sramc_sysdev
*dev
= bin_attr
->private;
930 size_t ramsize
= bin_attr
->size
;
934 if (pos
+ size
> ramsize
)
935 size
= ramsize
- pos
;
936 memcpy_fromio(buf
, dev
->base
+ pos
, size
);
940 static ssize_t
txx9_sram_write(struct kobject
*kobj
,
941 struct bin_attribute
*bin_attr
,
942 char *buf
, loff_t pos
, size_t size
)
944 struct txx9_sramc_sysdev
*dev
= bin_attr
->private;
945 size_t ramsize
= bin_attr
->size
;
949 if (pos
+ size
> ramsize
)
950 size
= ramsize
- pos
;
951 memcpy_toio(dev
->base
+ pos
, buf
, size
);
955 void __init
txx9_sramc_init(struct resource
*r
)
957 struct txx9_sramc_sysdev
*dev
;
961 if (!txx9_sramc_sysdev_class
.name
) {
962 txx9_sramc_sysdev_class
.name
= "txx9_sram";
963 err
= sysdev_class_register(&txx9_sramc_sysdev_class
);
965 txx9_sramc_sysdev_class
.name
= NULL
;
969 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
972 size
= resource_size(r
);
973 dev
->base
= ioremap(r
->start
, size
);
976 dev
->dev
.cls
= &txx9_sramc_sysdev_class
;
977 dev
->bindata_attr
.attr
.name
= "bindata";
978 dev
->bindata_attr
.attr
.mode
= S_IRUSR
| S_IWUSR
;
979 dev
->bindata_attr
.read
= txx9_sram_read
;
980 dev
->bindata_attr
.write
= txx9_sram_write
;
981 dev
->bindata_attr
.size
= size
;
982 dev
->bindata_attr
.private = dev
;
983 err
= sysdev_register(&dev
->dev
);
986 err
= sysfs_create_bin_file(&dev
->dev
.kobj
, &dev
->bindata_attr
);
988 sysdev_unregister(&dev
->dev
);