2 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
3 * and RBTX49xx patch from CELF patch archive.
5 * 2003-2005 (c) MontaVista Software, Inc.
6 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
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
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/module.h>
18 #include <linux/clk.h>
19 #include <linux/err.h>
20 #include <linux/gpio.h>
21 #include <linux/platform_device.h>
22 #include <linux/serial_core.h>
23 #include <linux/mtd/physmap.h>
24 #include <linux/leds.h>
25 #include <linux/sysdev.h>
26 #include <linux/slab.h>
27 #include <asm/bootinfo.h>
29 #include <asm/reboot.h>
30 #include <asm/r4kcache.h>
31 #include <asm/sections.h>
32 #include <asm/txx9/generic.h>
33 #include <asm/txx9/pci.h>
34 #include <asm/txx9tmr.h>
35 #include <asm/txx9/ndfmc.h>
36 #include <asm/txx9/dmac.h>
37 #ifdef CONFIG_CPU_TX49XX
38 #include <asm/txx9/tx4938.h>
41 /* EBUSC settings of TX4927, etc. */
42 struct resource txx9_ce_res
[8];
43 static char txx9_ce_res_name
[8][4]; /* "CEn" */
45 /* pcode, internal register */
46 unsigned int txx9_pcode
;
47 char txx9_pcode_str
[8];
48 static struct resource txx9_reg_res
= {
49 .name
= txx9_pcode_str
,
50 .flags
= IORESOURCE_MEM
,
53 txx9_reg_res_init(unsigned int pcode
, unsigned long base
, unsigned long size
)
57 for (i
= 0; i
< ARRAY_SIZE(txx9_ce_res
); i
++) {
58 sprintf(txx9_ce_res_name
[i
], "CE%d", i
);
59 txx9_ce_res
[i
].flags
= IORESOURCE_MEM
;
60 txx9_ce_res
[i
].name
= txx9_ce_res_name
[i
];
64 sprintf(txx9_pcode_str
, "TX%x", pcode
);
66 txx9_reg_res
.start
= base
& 0xfffffffffULL
;
67 txx9_reg_res
.end
= (base
& 0xfffffffffULL
) + (size
- 1);
68 request_resource(&iomem_resource
, &txx9_reg_res
);
73 unsigned int txx9_master_clock
;
74 unsigned int txx9_cpu_clock
;
75 unsigned int txx9_gbus_clock
;
77 #ifdef CONFIG_CPU_TX39XX
78 /* don't enable by default - see errata */
79 int txx9_ccfg_toeon __initdata
;
81 int txx9_ccfg_toeon __initdata
= 1;
84 /* Minimum CLK support */
86 struct clk
*clk_get(struct device
*dev
, const char *id
)
88 if (!strcmp(id
, "spi-baseclk"))
89 return (struct clk
*)((unsigned long)txx9_gbus_clock
/ 2 / 2);
90 if (!strcmp(id
, "imbus_clk"))
91 return (struct clk
*)((unsigned long)txx9_gbus_clock
/ 2);
92 return ERR_PTR(-ENOENT
);
94 EXPORT_SYMBOL(clk_get
);
96 int clk_enable(struct clk
*clk
)
100 EXPORT_SYMBOL(clk_enable
);
102 void clk_disable(struct clk
*clk
)
105 EXPORT_SYMBOL(clk_disable
);
107 unsigned long clk_get_rate(struct clk
*clk
)
109 return (unsigned long)clk
;
111 EXPORT_SYMBOL(clk_get_rate
);
113 void clk_put(struct clk
*clk
)
116 EXPORT_SYMBOL(clk_put
);
120 #ifdef CONFIG_GENERIC_GPIO
121 int gpio_to_irq(unsigned gpio
)
125 EXPORT_SYMBOL(gpio_to_irq
);
127 int irq_to_gpio(unsigned irq
)
131 EXPORT_SYMBOL(irq_to_gpio
);
134 #define BOARD_VEC(board) extern struct txx9_board_vec board;
135 #include <asm/txx9/boards.h>
138 struct txx9_board_vec
*txx9_board_vec __initdata
;
139 static char txx9_system_type
[32];
141 static struct txx9_board_vec
*board_vecs
[] __initdata
= {
142 #define BOARD_VEC(board) &board,
143 #include <asm/txx9/boards.h>
147 static struct txx9_board_vec
*__init
find_board_byname(const char *name
)
151 /* search board_vecs table */
152 for (i
= 0; i
< ARRAY_SIZE(board_vecs
); i
++) {
153 if (strstr(board_vecs
[i
]->system
, name
))
154 return board_vecs
[i
];
159 static void __init
prom_init_cmdline(void)
163 int i
; /* Always ignore the "-c" at argv[0] */
165 if (fw_arg0
>= CKSEG0
|| fw_arg1
< CKSEG0
) {
167 * argc is not a valid number, or argv32 is not a valid
174 argv32
= (int *)fw_arg1
;
177 arcs_cmdline
[0] = '\0';
179 for (i
= 1; i
< argc
; i
++) {
180 char *str
= (char *)(long)argv32
[i
];
182 strcat(arcs_cmdline
, " ");
183 if (strchr(str
, ' ')) {
184 strcat(arcs_cmdline
, "\"");
185 strcat(arcs_cmdline
, str
);
186 strcat(arcs_cmdline
, "\"");
188 strcat(arcs_cmdline
, str
);
192 static int txx9_ic_disable __initdata
;
193 static int txx9_dc_disable __initdata
;
195 #if defined(CONFIG_CPU_TX49XX)
196 /* flush all cache on very early stage (before 4k_cache_init) */
197 static void __init
early_flush_dcache(void)
199 unsigned int conf
= read_c0_config();
200 unsigned int dc_size
= 1 << (12 + ((conf
& CONF_DC
) >> 6));
201 unsigned int linesz
= 32;
202 unsigned long addr
, end
;
204 end
= INDEX_BASE
+ dc_size
/ 4;
206 for (addr
= INDEX_BASE
; addr
< end
; addr
+= linesz
) {
207 cache_op(Index_Writeback_Inv_D
, addr
| 0);
208 cache_op(Index_Writeback_Inv_D
, addr
| 1);
209 cache_op(Index_Writeback_Inv_D
, addr
| 2);
210 cache_op(Index_Writeback_Inv_D
, addr
| 3);
214 static void __init
txx9_cache_fixup(void)
218 conf
= read_c0_config();
219 /* flush and disable */
220 if (txx9_ic_disable
) {
221 conf
|= TX49_CONF_IC
;
222 write_c0_config(conf
);
224 if (txx9_dc_disable
) {
225 early_flush_dcache();
226 conf
|= TX49_CONF_DC
;
227 write_c0_config(conf
);
231 conf
= read_c0_config();
232 if (!txx9_ic_disable
)
233 conf
&= ~TX49_CONF_IC
;
234 if (!txx9_dc_disable
)
235 conf
&= ~TX49_CONF_DC
;
236 write_c0_config(conf
);
238 if (conf
& TX49_CONF_IC
)
239 pr_info("TX49XX I-Cache disabled.\n");
240 if (conf
& TX49_CONF_DC
)
241 pr_info("TX49XX D-Cache disabled.\n");
243 #elif defined(CONFIG_CPU_TX39XX)
244 /* flush all cache on very early stage (before tx39_cache_init) */
245 static void __init
early_flush_dcache(void)
247 unsigned int conf
= read_c0_config();
248 unsigned int dc_size
= 1 << (10 + ((conf
& TX39_CONF_DCS_MASK
) >>
249 TX39_CONF_DCS_SHIFT
));
250 unsigned int linesz
= 16;
251 unsigned long addr
, end
;
253 end
= INDEX_BASE
+ dc_size
/ 2;
255 for (addr
= INDEX_BASE
; addr
< end
; addr
+= linesz
) {
256 cache_op(Index_Writeback_Inv_D
, addr
| 0);
257 cache_op(Index_Writeback_Inv_D
, addr
| 1);
261 static void __init
txx9_cache_fixup(void)
265 conf
= read_c0_config();
266 /* flush and disable */
267 if (txx9_ic_disable
) {
268 conf
&= ~TX39_CONF_ICE
;
269 write_c0_config(conf
);
271 if (txx9_dc_disable
) {
272 early_flush_dcache();
273 conf
&= ~TX39_CONF_DCE
;
274 write_c0_config(conf
);
278 conf
= read_c0_config();
279 if (!txx9_ic_disable
)
280 conf
|= TX39_CONF_ICE
;
281 if (!txx9_dc_disable
)
282 conf
|= TX39_CONF_DCE
;
283 write_c0_config(conf
);
285 if (!(conf
& TX39_CONF_ICE
))
286 pr_info("TX39XX I-Cache disabled.\n");
287 if (!(conf
& TX39_CONF_DCE
))
288 pr_info("TX39XX D-Cache disabled.\n");
291 static inline void txx9_cache_fixup(void)
296 static void __init
preprocess_cmdline(void)
298 static char cmdline
[COMMAND_LINE_SIZE
] __initdata
;
301 strcpy(cmdline
, arcs_cmdline
);
303 arcs_cmdline
[0] = '\0';
305 char *str
= strsep(&s
, " ");
306 if (strncmp(str
, "board=", 6) == 0) {
307 txx9_board_vec
= find_board_byname(str
+ 6);
309 } else if (strncmp(str
, "masterclk=", 10) == 0) {
311 if (strict_strtoul(str
+ 10, 10, &val
) == 0)
312 txx9_master_clock
= val
;
314 } else if (strcmp(str
, "icdisable") == 0) {
317 } else if (strcmp(str
, "dcdisable") == 0) {
320 } else if (strcmp(str
, "toeoff") == 0) {
323 } else if (strcmp(str
, "toeon") == 0) {
328 strcat(arcs_cmdline
, " ");
329 strcat(arcs_cmdline
, str
);
335 static void __init
select_board(void)
339 /* first, determine by "board=" argument in preprocess_cmdline() */
342 /* next, determine by "board" envvar */
343 envstr
= prom_getenv("board");
345 txx9_board_vec
= find_board_byname(envstr
);
350 /* select "default" board */
351 #ifdef CONFIG_CPU_TX39XX
352 txx9_board_vec
= &jmr3927_vec
;
354 #ifdef CONFIG_CPU_TX49XX
355 switch (TX4938_REV_PCODE()) {
356 #ifdef CONFIG_TOSHIBA_RBTX4927
358 txx9_board_vec
= &rbtx4927_vec
;
361 txx9_board_vec
= &rbtx4937_vec
;
364 #ifdef CONFIG_TOSHIBA_RBTX4938
366 txx9_board_vec
= &rbtx4938_vec
;
369 #ifdef CONFIG_TOSHIBA_RBTX4939
371 txx9_board_vec
= &rbtx4939_vec
;
378 void __init
prom_init(void)
381 preprocess_cmdline();
384 strcpy(txx9_system_type
, txx9_board_vec
->system
);
386 txx9_board_vec
->prom_init();
389 void __init
prom_free_prom_memory(void)
391 unsigned long saddr
= PAGE_SIZE
;
392 unsigned long eaddr
= __pa_symbol(&_text
);
395 free_init_pages("prom memory", saddr
, eaddr
);
398 const char *get_system_type(void)
400 return txx9_system_type
;
403 const char *__init
prom_getenv(const char *name
)
407 if (fw_arg2
< CKSEG0
)
410 str
= (const s32
*)fw_arg2
;
411 /* YAMON style ("name", "value" pairs) */
412 while (str
[0] && str
[1]) {
413 if (!strcmp((const char *)(unsigned long)str
[0], name
))
414 return (const char *)(unsigned long)str
[1];
420 static void __noreturn
txx9_machine_halt(void)
423 clear_c0_status(ST0_IM
);
427 if (cpu_has_counter
) {
429 * Clear counter interrupt while it
430 * breaks WAIT instruction even if
439 /* Watchdog support */
440 void __init
txx9_wdt_init(unsigned long base
)
442 struct resource res
= {
444 .end
= base
+ 0x100 - 1,
445 .flags
= IORESOURCE_MEM
,
447 platform_device_register_simple("txx9wdt", -1, &res
, 1);
450 void txx9_wdt_now(unsigned long base
)
452 struct txx9_tmr_reg __iomem
*tmrptr
=
453 ioremap(base
, sizeof(struct txx9_tmr_reg
));
454 /* disable watch dog timer */
455 __raw_writel(TXx9_TMWTMR_WDIS
| TXx9_TMWTMR_TWC
, &tmrptr
->wtmr
);
456 __raw_writel(0, &tmrptr
->tcr
);
458 __raw_writel(TXx9_TMWTMR_TWIE
, &tmrptr
->wtmr
);
459 __raw_writel(1, &tmrptr
->cpra
); /* immediate */
460 __raw_writel(TXx9_TMTCR_TCE
| TXx9_TMTCR_CCDE
| TXx9_TMTCR_TMODE_WDOG
,
465 void __init
txx9_spi_init(int busid
, unsigned long base
, int irq
)
467 struct resource res
[] = {
470 .end
= base
+ 0x20 - 1,
471 .flags
= IORESOURCE_MEM
,
474 .flags
= IORESOURCE_IRQ
,
477 platform_device_register_simple("spi_txx9", busid
,
478 res
, ARRAY_SIZE(res
));
481 void __init
txx9_ethaddr_init(unsigned int id
, unsigned char *ethaddr
)
483 struct platform_device
*pdev
=
484 platform_device_alloc("tc35815-mac", id
);
486 platform_device_add_data(pdev
, ethaddr
, 6) ||
487 platform_device_add(pdev
))
488 platform_device_put(pdev
);
491 void __init
txx9_sio_init(unsigned long baseaddr
, int irq
,
492 unsigned int line
, unsigned int sclk
, int nocts
)
494 #ifdef CONFIG_SERIAL_TXX9
495 struct uart_port req
;
497 memset(&req
, 0, sizeof(req
));
499 req
.iotype
= UPIO_MEM
;
500 req
.membase
= ioremap(baseaddr
, 0x24);
501 req
.mapbase
= baseaddr
;
504 req
.flags
|= UPF_BUGGY_UART
/*HAVE_CTS_LINE*/;
506 req
.flags
|= UPF_MAGIC_MULTIPLIER
/*USE_SCLK*/;
509 req
.uartclk
= TXX9_IMCLK
;
510 early_serial_txx9_setup(&req
);
511 #endif /* CONFIG_SERIAL_TXX9 */
514 #ifdef CONFIG_EARLY_PRINTK
515 static void __init
null_prom_putchar(char c
)
518 void (*txx9_prom_putchar
)(char c
) __initdata
= null_prom_putchar
;
520 void __init
prom_putchar(char c
)
522 txx9_prom_putchar(c
);
525 static void __iomem
*early_txx9_sio_port
;
527 static void __init
early_txx9_sio_putchar(char c
)
529 #define TXX9_SICISR 0x0c
530 #define TXX9_SITFIFO 0x1c
531 #define TXX9_SICISR_TXALS 0x00000002
532 while (!(__raw_readl(early_txx9_sio_port
+ TXX9_SICISR
) &
535 __raw_writel(c
, early_txx9_sio_port
+ TXX9_SITFIFO
);
538 void __init
txx9_sio_putchar_init(unsigned long baseaddr
)
540 early_txx9_sio_port
= ioremap(baseaddr
, 0x24);
541 txx9_prom_putchar
= early_txx9_sio_putchar
;
543 #endif /* CONFIG_EARLY_PRINTK */
546 void __init
plat_mem_setup(void)
548 ioport_resource
.start
= 0;
549 ioport_resource
.end
= ~0UL; /* no limit */
550 iomem_resource
.start
= 0;
551 iomem_resource
.end
= ~0UL; /* no limit */
553 /* fallback restart/halt routines */
554 _machine_restart
= (void (*)(char *))txx9_machine_halt
;
555 _machine_halt
= txx9_machine_halt
;
556 pm_power_off
= txx9_machine_halt
;
559 pcibios_plat_setup
= txx9_pcibios_setup
;
561 txx9_board_vec
->mem_setup();
564 void __init
arch_init_irq(void)
566 txx9_board_vec
->irq_setup();
569 void __init
plat_time_init(void)
571 #ifdef CONFIG_CPU_TX49XX
572 mips_hpt_frequency
= txx9_cpu_clock
/ 2;
574 txx9_board_vec
->time_init();
577 static int __init
_txx9_arch_init(void)
579 if (txx9_board_vec
->arch_init
)
580 txx9_board_vec
->arch_init();
583 arch_initcall(_txx9_arch_init
);
585 static int __init
_txx9_device_init(void)
587 if (txx9_board_vec
->device_init
)
588 txx9_board_vec
->device_init();
591 device_initcall(_txx9_device_init
);
593 int (*txx9_irq_dispatch
)(int pending
);
594 asmlinkage
void plat_irq_dispatch(void)
596 int pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
597 int irq
= txx9_irq_dispatch(pending
);
599 if (likely(irq
>= 0))
602 spurious_interrupt();
605 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
606 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
607 static unsigned long __swizzle_addr_none(unsigned long port
)
611 unsigned long (*__swizzle_addr_b
)(unsigned long port
) = __swizzle_addr_none
;
612 EXPORT_SYMBOL(__swizzle_addr_b
);
615 #ifdef NEEDS_TXX9_IOSWABW
616 static u16
ioswabw_default(volatile u16
*a
, u16 x
)
618 return le16_to_cpu(x
);
620 static u16
__mem_ioswabw_default(volatile u16
*a
, u16 x
)
624 u16 (*ioswabw
)(volatile u16
*a
, u16 x
) = ioswabw_default
;
625 EXPORT_SYMBOL(ioswabw
);
626 u16 (*__mem_ioswabw
)(volatile u16
*a
, u16 x
) = __mem_ioswabw_default
;
627 EXPORT_SYMBOL(__mem_ioswabw
);
630 void __init
txx9_physmap_flash_init(int no
, unsigned long addr
,
632 const struct physmap_flash_data
*pdata
)
634 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
635 struct resource res
= {
637 .end
= addr
+ size
- 1,
638 .flags
= IORESOURCE_MEM
,
640 struct platform_device
*pdev
;
641 #ifdef CONFIG_MTD_PARTITIONS
642 static struct mtd_partition parts
[2];
643 struct physmap_flash_data pdata_part
;
645 /* If this area contained boot area, make separate partition */
646 if (pdata
->nr_parts
== 0 && !pdata
->parts
&&
647 addr
< 0x1fc00000 && addr
+ size
> 0x1fc00000 &&
649 parts
[0].name
= "boot";
650 parts
[0].offset
= 0x1fc00000 - addr
;
651 parts
[0].size
= addr
+ size
- 0x1fc00000;
652 parts
[1].name
= "user";
654 parts
[1].size
= 0x1fc00000 - addr
;
656 pdata_part
.nr_parts
= ARRAY_SIZE(parts
);
657 pdata_part
.parts
= parts
;
661 pdev
= platform_device_alloc("physmap-flash", no
);
663 platform_device_add_resources(pdev
, &res
, 1) ||
664 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
665 platform_device_add(pdev
))
666 platform_device_put(pdev
);
670 void __init
txx9_ndfmc_init(unsigned long baseaddr
,
671 const struct txx9ndfmc_platform_data
*pdata
)
673 #if defined(CONFIG_MTD_NAND_TXX9NDFMC) || defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE)
674 struct resource res
= {
676 .end
= baseaddr
+ 0x1000 - 1,
677 .flags
= IORESOURCE_MEM
,
679 struct platform_device
*pdev
= platform_device_alloc("txx9ndfmc", -1);
682 platform_device_add_resources(pdev
, &res
, 1) ||
683 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
684 platform_device_add(pdev
))
685 platform_device_put(pdev
);
689 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
690 static DEFINE_SPINLOCK(txx9_iocled_lock
);
692 #define TXX9_IOCLED_MAXLEDS 8
694 struct txx9_iocled_data
{
695 struct gpio_chip chip
;
697 void __iomem
*mmioaddr
;
698 struct gpio_led_platform_data pdata
;
699 struct gpio_led leds
[TXX9_IOCLED_MAXLEDS
];
700 char names
[TXX9_IOCLED_MAXLEDS
][32];
703 static int txx9_iocled_get(struct gpio_chip
*chip
, unsigned int offset
)
705 struct txx9_iocled_data
*data
=
706 container_of(chip
, struct txx9_iocled_data
, chip
);
707 return data
->cur_val
& (1 << offset
);
710 static void txx9_iocled_set(struct gpio_chip
*chip
, unsigned int offset
,
713 struct txx9_iocled_data
*data
=
714 container_of(chip
, struct txx9_iocled_data
, chip
);
716 spin_lock_irqsave(&txx9_iocled_lock
, flags
);
718 data
->cur_val
|= 1 << offset
;
720 data
->cur_val
&= ~(1 << offset
);
721 writeb(data
->cur_val
, data
->mmioaddr
);
723 spin_unlock_irqrestore(&txx9_iocled_lock
, flags
);
726 static int txx9_iocled_dir_in(struct gpio_chip
*chip
, unsigned int offset
)
731 static int txx9_iocled_dir_out(struct gpio_chip
*chip
, unsigned int offset
,
734 txx9_iocled_set(chip
, offset
, value
);
738 void __init
txx9_iocled_init(unsigned long baseaddr
,
739 int basenum
, unsigned int num
, int lowactive
,
740 const char *color
, char **deftriggers
)
742 struct txx9_iocled_data
*iocled
;
743 struct platform_device
*pdev
;
745 static char *default_triggers
[] __initdata
= {
753 deftriggers
= default_triggers
;
754 iocled
= kzalloc(sizeof(*iocled
), GFP_KERNEL
);
757 iocled
->mmioaddr
= ioremap(baseaddr
, 1);
758 if (!iocled
->mmioaddr
)
760 iocled
->chip
.get
= txx9_iocled_get
;
761 iocled
->chip
.set
= txx9_iocled_set
;
762 iocled
->chip
.direction_input
= txx9_iocled_dir_in
;
763 iocled
->chip
.direction_output
= txx9_iocled_dir_out
;
764 iocled
->chip
.label
= "iocled";
765 iocled
->chip
.base
= basenum
;
766 iocled
->chip
.ngpio
= num
;
767 if (gpiochip_add(&iocled
->chip
))
770 basenum
= iocled
->chip
.base
;
772 pdev
= platform_device_alloc("leds-gpio", basenum
);
775 iocled
->pdata
.num_leds
= num
;
776 iocled
->pdata
.leds
= iocled
->leds
;
777 for (i
= 0; i
< num
; i
++) {
778 struct gpio_led
*led
= &iocled
->leds
[i
];
779 snprintf(iocled
->names
[i
], sizeof(iocled
->names
[i
]),
780 "iocled:%s:%u", color
, i
);
781 led
->name
= iocled
->names
[i
];
782 led
->gpio
= basenum
+ i
;
783 led
->active_low
= lowactive
;
784 if (deftriggers
&& *deftriggers
)
785 led
->default_trigger
= *deftriggers
++;
787 pdev
->dev
.platform_data
= &iocled
->pdata
;
788 if (platform_device_add(pdev
))
792 platform_device_put(pdev
);
794 if (gpiochip_remove(&iocled
->chip
))
797 iounmap(iocled
->mmioaddr
);
801 #else /* CONFIG_LEDS_GPIO */
802 void __init
txx9_iocled_init(unsigned long baseaddr
,
803 int basenum
, unsigned int num
, int lowactive
,
804 const char *color
, char **deftriggers
)
807 #endif /* CONFIG_LEDS_GPIO */
809 void __init
txx9_dmac_init(int id
, unsigned long baseaddr
, int irq
,
810 const struct txx9dmac_platform_data
*pdata
)
812 #if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE)
813 struct resource res
[] = {
816 .end
= baseaddr
+ 0x800 - 1,
817 .flags
= IORESOURCE_MEM
,
818 #ifndef CONFIG_MACH_TX49XX
821 .flags
= IORESOURCE_IRQ
,
825 #ifdef CONFIG_MACH_TX49XX
826 struct resource chan_res
[] = {
828 .flags
= IORESOURCE_IRQ
,
832 struct platform_device
*pdev
= platform_device_alloc("txx9dmac", id
);
833 struct txx9dmac_chan_platform_data cpdata
;
837 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
838 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
839 platform_device_add(pdev
)) {
840 platform_device_put(pdev
);
843 memset(&cpdata
, 0, sizeof(cpdata
));
844 cpdata
.dmac_dev
= pdev
;
845 for (i
= 0; i
< TXX9_DMA_MAX_NR_CHANNELS
; i
++) {
846 #ifdef CONFIG_MACH_TX49XX
847 chan_res
[0].start
= irq
+ i
;
849 pdev
= platform_device_alloc("txx9dmac-chan",
850 id
* TXX9_DMA_MAX_NR_CHANNELS
+ i
);
852 #ifdef CONFIG_MACH_TX49XX
853 platform_device_add_resources(pdev
, chan_res
,
854 ARRAY_SIZE(chan_res
)) ||
856 platform_device_add_data(pdev
, &cpdata
, sizeof(cpdata
)) ||
857 platform_device_add(pdev
))
858 platform_device_put(pdev
);
863 void __init
txx9_aclc_init(unsigned long baseaddr
, int irq
,
864 unsigned int dmac_id
,
865 unsigned int dma_chan_out
,
866 unsigned int dma_chan_in
)
868 #if defined(CONFIG_SND_SOC_TXX9ACLC) || defined(CONFIG_SND_SOC_TXX9ACLC_MODULE)
869 unsigned int dma_base
= dmac_id
* TXX9_DMA_MAX_NR_CHANNELS
;
870 struct resource res
[] = {
873 .end
= baseaddr
+ 0x100 - 1,
874 .flags
= IORESOURCE_MEM
,
877 .flags
= IORESOURCE_IRQ
,
879 .name
= "txx9dmac-chan",
880 .start
= dma_base
+ dma_chan_out
,
881 .flags
= IORESOURCE_DMA
,
883 .name
= "txx9dmac-chan",
884 .start
= dma_base
+ dma_chan_in
,
885 .flags
= IORESOURCE_DMA
,
888 struct platform_device
*pdev
=
889 platform_device_alloc("txx9aclc-ac97", -1);
892 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
893 platform_device_add(pdev
))
894 platform_device_put(pdev
);
898 static struct sysdev_class txx9_sramc_sysdev_class
;
900 struct txx9_sramc_sysdev
{
901 struct sys_device dev
;
902 struct bin_attribute bindata_attr
;
906 static ssize_t
txx9_sram_read(struct file
*filp
, struct kobject
*kobj
,
907 struct bin_attribute
*bin_attr
,
908 char *buf
, loff_t pos
, size_t size
)
910 struct txx9_sramc_sysdev
*dev
= bin_attr
->private;
911 size_t ramsize
= bin_attr
->size
;
915 if (pos
+ size
> ramsize
)
916 size
= ramsize
- pos
;
917 memcpy_fromio(buf
, dev
->base
+ pos
, size
);
921 static ssize_t
txx9_sram_write(struct file
*filp
, struct kobject
*kobj
,
922 struct bin_attribute
*bin_attr
,
923 char *buf
, loff_t pos
, size_t size
)
925 struct txx9_sramc_sysdev
*dev
= bin_attr
->private;
926 size_t ramsize
= bin_attr
->size
;
930 if (pos
+ size
> ramsize
)
931 size
= ramsize
- pos
;
932 memcpy_toio(dev
->base
+ pos
, buf
, size
);
936 void __init
txx9_sramc_init(struct resource
*r
)
938 struct txx9_sramc_sysdev
*dev
;
942 if (!txx9_sramc_sysdev_class
.name
) {
943 txx9_sramc_sysdev_class
.name
= "txx9_sram";
944 err
= sysdev_class_register(&txx9_sramc_sysdev_class
);
946 txx9_sramc_sysdev_class
.name
= NULL
;
950 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
953 size
= resource_size(r
);
954 dev
->base
= ioremap(r
->start
, size
);
957 dev
->dev
.cls
= &txx9_sramc_sysdev_class
;
958 sysfs_bin_attr_init(&dev
->bindata_attr
);
959 dev
->bindata_attr
.attr
.name
= "bindata";
960 dev
->bindata_attr
.attr
.mode
= S_IRUSR
| S_IWUSR
;
961 dev
->bindata_attr
.read
= txx9_sram_read
;
962 dev
->bindata_attr
.write
= txx9_sram_write
;
963 dev
->bindata_attr
.size
= size
;
964 dev
->bindata_attr
.private = dev
;
965 err
= sysdev_register(&dev
->dev
);
968 err
= sysfs_create_bin_file(&dev
->dev
.kobj
, &dev
->bindata_attr
);
970 sysdev_unregister(&dev
->dev
);