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/device.h>
26 #include <linux/slab.h>
27 #include <linux/irq.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 / 2);
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] */
166 if (fw_arg0
>= CKSEG0
|| fw_arg1
< CKSEG0
) {
168 * argc is not a valid number, or argv32 is not a valid
175 argv32
= (int *)fw_arg1
;
178 arcs_cmdline
[0] = '\0';
180 for (i
= 1; i
< argc
; i
++) {
181 char *str
= (char *)(long)argv32
[i
];
183 strcat(arcs_cmdline
, " ");
184 if (strchr(str
, ' ')) {
185 strcat(arcs_cmdline
, "\"");
186 strcat(arcs_cmdline
, str
);
187 strcat(arcs_cmdline
, "\"");
189 strcat(arcs_cmdline
, str
);
193 static int txx9_ic_disable __initdata
;
194 static int txx9_dc_disable __initdata
;
196 #if defined(CONFIG_CPU_TX49XX)
197 /* flush all cache on very early stage (before 4k_cache_init) */
198 static void __init
early_flush_dcache(void)
200 unsigned int conf
= read_c0_config();
201 unsigned int dc_size
= 1 << (12 + ((conf
& CONF_DC
) >> 6));
202 unsigned int linesz
= 32;
203 unsigned long addr
, end
;
205 end
= INDEX_BASE
+ dc_size
/ 4;
207 for (addr
= INDEX_BASE
; addr
< end
; addr
+= linesz
) {
208 cache_op(Index_Writeback_Inv_D
, addr
| 0);
209 cache_op(Index_Writeback_Inv_D
, addr
| 1);
210 cache_op(Index_Writeback_Inv_D
, addr
| 2);
211 cache_op(Index_Writeback_Inv_D
, addr
| 3);
215 static void __init
txx9_cache_fixup(void)
219 conf
= read_c0_config();
220 /* flush and disable */
221 if (txx9_ic_disable
) {
222 conf
|= TX49_CONF_IC
;
223 write_c0_config(conf
);
225 if (txx9_dc_disable
) {
226 early_flush_dcache();
227 conf
|= TX49_CONF_DC
;
228 write_c0_config(conf
);
232 conf
= read_c0_config();
233 if (!txx9_ic_disable
)
234 conf
&= ~TX49_CONF_IC
;
235 if (!txx9_dc_disable
)
236 conf
&= ~TX49_CONF_DC
;
237 write_c0_config(conf
);
239 if (conf
& TX49_CONF_IC
)
240 pr_info("TX49XX I-Cache disabled.\n");
241 if (conf
& TX49_CONF_DC
)
242 pr_info("TX49XX D-Cache disabled.\n");
244 #elif defined(CONFIG_CPU_TX39XX)
245 /* flush all cache on very early stage (before tx39_cache_init) */
246 static void __init
early_flush_dcache(void)
248 unsigned int conf
= read_c0_config();
249 unsigned int dc_size
= 1 << (10 + ((conf
& TX39_CONF_DCS_MASK
) >>
250 TX39_CONF_DCS_SHIFT
));
251 unsigned int linesz
= 16;
252 unsigned long addr
, end
;
254 end
= INDEX_BASE
+ dc_size
/ 2;
256 for (addr
= INDEX_BASE
; addr
< end
; addr
+= linesz
) {
257 cache_op(Index_Writeback_Inv_D
, addr
| 0);
258 cache_op(Index_Writeback_Inv_D
, addr
| 1);
262 static void __init
txx9_cache_fixup(void)
266 conf
= read_c0_config();
267 /* flush and disable */
268 if (txx9_ic_disable
) {
269 conf
&= ~TX39_CONF_ICE
;
270 write_c0_config(conf
);
272 if (txx9_dc_disable
) {
273 early_flush_dcache();
274 conf
&= ~TX39_CONF_DCE
;
275 write_c0_config(conf
);
279 conf
= read_c0_config();
280 if (!txx9_ic_disable
)
281 conf
|= TX39_CONF_ICE
;
282 if (!txx9_dc_disable
)
283 conf
|= TX39_CONF_DCE
;
284 write_c0_config(conf
);
286 if (!(conf
& TX39_CONF_ICE
))
287 pr_info("TX39XX I-Cache disabled.\n");
288 if (!(conf
& TX39_CONF_DCE
))
289 pr_info("TX39XX D-Cache disabled.\n");
292 static inline void txx9_cache_fixup(void)
297 static void __init
preprocess_cmdline(void)
299 static char cmdline
[COMMAND_LINE_SIZE
] __initdata
;
302 strcpy(cmdline
, arcs_cmdline
);
304 arcs_cmdline
[0] = '\0';
306 char *str
= strsep(&s
, " ");
307 if (strncmp(str
, "board=", 6) == 0) {
308 txx9_board_vec
= find_board_byname(str
+ 6);
310 } else if (strncmp(str
, "masterclk=", 10) == 0) {
312 if (strict_strtoul(str
+ 10, 10, &val
) == 0)
313 txx9_master_clock
= val
;
315 } else if (strcmp(str
, "icdisable") == 0) {
318 } else if (strcmp(str
, "dcdisable") == 0) {
321 } else if (strcmp(str
, "toeoff") == 0) {
324 } else if (strcmp(str
, "toeon") == 0) {
329 strcat(arcs_cmdline
, " ");
330 strcat(arcs_cmdline
, str
);
336 static void __init
select_board(void)
340 /* first, determine by "board=" argument in preprocess_cmdline() */
343 /* next, determine by "board" envvar */
344 envstr
= prom_getenv("board");
346 txx9_board_vec
= find_board_byname(envstr
);
351 /* select "default" board */
352 #ifdef CONFIG_CPU_TX39XX
353 txx9_board_vec
= &jmr3927_vec
;
355 #ifdef CONFIG_CPU_TX49XX
356 switch (TX4938_REV_PCODE()) {
357 #ifdef CONFIG_TOSHIBA_RBTX4927
359 txx9_board_vec
= &rbtx4927_vec
;
362 txx9_board_vec
= &rbtx4937_vec
;
365 #ifdef CONFIG_TOSHIBA_RBTX4938
367 txx9_board_vec
= &rbtx4938_vec
;
370 #ifdef CONFIG_TOSHIBA_RBTX4939
372 txx9_board_vec
= &rbtx4939_vec
;
379 void __init
prom_init(void)
382 preprocess_cmdline();
385 strcpy(txx9_system_type
, txx9_board_vec
->system
);
387 txx9_board_vec
->prom_init();
390 void __init
prom_free_prom_memory(void)
392 unsigned long saddr
= PAGE_SIZE
;
393 unsigned long eaddr
= __pa_symbol(&_text
);
396 free_init_pages("prom memory", saddr
, eaddr
);
399 const char *get_system_type(void)
401 return txx9_system_type
;
404 const char *__init
prom_getenv(const char *name
)
408 if (fw_arg2
< CKSEG0
)
411 str
= (const s32
*)fw_arg2
;
412 /* YAMON style ("name", "value" pairs) */
413 while (str
[0] && str
[1]) {
414 if (!strcmp((const char *)(unsigned long)str
[0], name
))
415 return (const char *)(unsigned long)str
[1];
421 static void __noreturn
txx9_machine_halt(void)
424 clear_c0_status(ST0_IM
);
428 if (cpu_has_counter
) {
430 * Clear counter interrupt while it
431 * breaks WAIT instruction even if
440 /* Watchdog support */
441 void __init
txx9_wdt_init(unsigned long base
)
443 struct resource res
= {
445 .end
= base
+ 0x100 - 1,
446 .flags
= IORESOURCE_MEM
,
448 platform_device_register_simple("txx9wdt", -1, &res
, 1);
451 void txx9_wdt_now(unsigned long base
)
453 struct txx9_tmr_reg __iomem
*tmrptr
=
454 ioremap(base
, sizeof(struct txx9_tmr_reg
));
455 /* disable watch dog timer */
456 __raw_writel(TXx9_TMWTMR_WDIS
| TXx9_TMWTMR_TWC
, &tmrptr
->wtmr
);
457 __raw_writel(0, &tmrptr
->tcr
);
459 __raw_writel(TXx9_TMWTMR_TWIE
, &tmrptr
->wtmr
);
460 __raw_writel(1, &tmrptr
->cpra
); /* immediate */
461 __raw_writel(TXx9_TMTCR_TCE
| TXx9_TMTCR_CCDE
| TXx9_TMTCR_TMODE_WDOG
,
466 void __init
txx9_spi_init(int busid
, unsigned long base
, int irq
)
468 struct resource res
[] = {
471 .end
= base
+ 0x20 - 1,
472 .flags
= IORESOURCE_MEM
,
475 .flags
= IORESOURCE_IRQ
,
478 platform_device_register_simple("spi_txx9", busid
,
479 res
, ARRAY_SIZE(res
));
482 void __init
txx9_ethaddr_init(unsigned int id
, unsigned char *ethaddr
)
484 struct platform_device
*pdev
=
485 platform_device_alloc("tc35815-mac", id
);
487 platform_device_add_data(pdev
, ethaddr
, 6) ||
488 platform_device_add(pdev
))
489 platform_device_put(pdev
);
492 void __init
txx9_sio_init(unsigned long baseaddr
, int irq
,
493 unsigned int line
, unsigned int sclk
, int nocts
)
495 #ifdef CONFIG_SERIAL_TXX9
496 struct uart_port req
;
498 memset(&req
, 0, sizeof(req
));
500 req
.iotype
= UPIO_MEM
;
501 req
.membase
= ioremap(baseaddr
, 0x24);
502 req
.mapbase
= baseaddr
;
505 req
.flags
|= UPF_BUGGY_UART
/*HAVE_CTS_LINE*/;
507 req
.flags
|= UPF_MAGIC_MULTIPLIER
/*USE_SCLK*/;
510 req
.uartclk
= TXX9_IMCLK
;
511 early_serial_txx9_setup(&req
);
512 #endif /* CONFIG_SERIAL_TXX9 */
515 #ifdef CONFIG_EARLY_PRINTK
516 static void __init
null_prom_putchar(char c
)
519 void (*txx9_prom_putchar
)(char c
) __initdata
= null_prom_putchar
;
521 void __init
prom_putchar(char c
)
523 txx9_prom_putchar(c
);
526 static void __iomem
*early_txx9_sio_port
;
528 static void __init
early_txx9_sio_putchar(char c
)
530 #define TXX9_SICISR 0x0c
531 #define TXX9_SITFIFO 0x1c
532 #define TXX9_SICISR_TXALS 0x00000002
533 while (!(__raw_readl(early_txx9_sio_port
+ TXX9_SICISR
) &
536 __raw_writel(c
, early_txx9_sio_port
+ TXX9_SITFIFO
);
539 void __init
txx9_sio_putchar_init(unsigned long baseaddr
)
541 early_txx9_sio_port
= ioremap(baseaddr
, 0x24);
542 txx9_prom_putchar
= early_txx9_sio_putchar
;
544 #endif /* CONFIG_EARLY_PRINTK */
547 void __init
plat_mem_setup(void)
549 ioport_resource
.start
= 0;
550 ioport_resource
.end
= ~0UL; /* no limit */
551 iomem_resource
.start
= 0;
552 iomem_resource
.end
= ~0UL; /* no limit */
554 /* fallback restart/halt routines */
555 _machine_restart
= (void (*)(char *))txx9_machine_halt
;
556 _machine_halt
= txx9_machine_halt
;
557 pm_power_off
= txx9_machine_halt
;
560 pcibios_plat_setup
= txx9_pcibios_setup
;
562 txx9_board_vec
->mem_setup();
565 void __init
arch_init_irq(void)
567 txx9_board_vec
->irq_setup();
570 void __init
plat_time_init(void)
572 #ifdef CONFIG_CPU_TX49XX
573 mips_hpt_frequency
= txx9_cpu_clock
/ 2;
575 txx9_board_vec
->time_init();
578 static int __init
_txx9_arch_init(void)
580 if (txx9_board_vec
->arch_init
)
581 txx9_board_vec
->arch_init();
584 arch_initcall(_txx9_arch_init
);
586 static int __init
_txx9_device_init(void)
588 if (txx9_board_vec
->device_init
)
589 txx9_board_vec
->device_init();
592 device_initcall(_txx9_device_init
);
594 int (*txx9_irq_dispatch
)(int pending
);
595 asmlinkage
void plat_irq_dispatch(void)
597 int pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
598 int irq
= txx9_irq_dispatch(pending
);
600 if (likely(irq
>= 0))
603 spurious_interrupt();
606 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
607 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
608 static unsigned long __swizzle_addr_none(unsigned long port
)
612 unsigned long (*__swizzle_addr_b
)(unsigned long port
) = __swizzle_addr_none
;
613 EXPORT_SYMBOL(__swizzle_addr_b
);
616 #ifdef NEEDS_TXX9_IOSWABW
617 static u16
ioswabw_default(volatile u16
*a
, u16 x
)
619 return le16_to_cpu(x
);
621 static u16
__mem_ioswabw_default(volatile u16
*a
, u16 x
)
625 u16 (*ioswabw
)(volatile u16
*a
, u16 x
) = ioswabw_default
;
626 EXPORT_SYMBOL(ioswabw
);
627 u16 (*__mem_ioswabw
)(volatile u16
*a
, u16 x
) = __mem_ioswabw_default
;
628 EXPORT_SYMBOL(__mem_ioswabw
);
631 void __init
txx9_physmap_flash_init(int no
, unsigned long addr
,
633 const struct physmap_flash_data
*pdata
)
635 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
636 struct resource res
= {
638 .end
= addr
+ size
- 1,
639 .flags
= IORESOURCE_MEM
,
641 struct platform_device
*pdev
;
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) || \
674 defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE)
675 struct resource res
= {
677 .end
= baseaddr
+ 0x1000 - 1,
678 .flags
= IORESOURCE_MEM
,
680 struct platform_device
*pdev
= platform_device_alloc("txx9ndfmc", -1);
683 platform_device_add_resources(pdev
, &res
, 1) ||
684 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
685 platform_device_add(pdev
))
686 platform_device_put(pdev
);
690 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
691 static DEFINE_SPINLOCK(txx9_iocled_lock
);
693 #define TXX9_IOCLED_MAXLEDS 8
695 struct txx9_iocled_data
{
696 struct gpio_chip chip
;
698 void __iomem
*mmioaddr
;
699 struct gpio_led_platform_data pdata
;
700 struct gpio_led leds
[TXX9_IOCLED_MAXLEDS
];
701 char names
[TXX9_IOCLED_MAXLEDS
][32];
704 static int txx9_iocled_get(struct gpio_chip
*chip
, unsigned int offset
)
706 struct txx9_iocled_data
*data
=
707 container_of(chip
, struct txx9_iocled_data
, chip
);
708 return data
->cur_val
& (1 << offset
);
711 static void txx9_iocled_set(struct gpio_chip
*chip
, unsigned int offset
,
714 struct txx9_iocled_data
*data
=
715 container_of(chip
, struct txx9_iocled_data
, chip
);
717 spin_lock_irqsave(&txx9_iocled_lock
, flags
);
719 data
->cur_val
|= 1 << offset
;
721 data
->cur_val
&= ~(1 << offset
);
722 writeb(data
->cur_val
, data
->mmioaddr
);
724 spin_unlock_irqrestore(&txx9_iocled_lock
, flags
);
727 static int txx9_iocled_dir_in(struct gpio_chip
*chip
, unsigned int offset
)
732 static int txx9_iocled_dir_out(struct gpio_chip
*chip
, unsigned int offset
,
735 txx9_iocled_set(chip
, offset
, value
);
739 void __init
txx9_iocled_init(unsigned long baseaddr
,
740 int basenum
, unsigned int num
, int lowactive
,
741 const char *color
, char **deftriggers
)
743 struct txx9_iocled_data
*iocled
;
744 struct platform_device
*pdev
;
746 static char *default_triggers
[] __initdata
= {
754 deftriggers
= default_triggers
;
755 iocled
= kzalloc(sizeof(*iocled
), GFP_KERNEL
);
758 iocled
->mmioaddr
= ioremap(baseaddr
, 1);
759 if (!iocled
->mmioaddr
)
761 iocled
->chip
.get
= txx9_iocled_get
;
762 iocled
->chip
.set
= txx9_iocled_set
;
763 iocled
->chip
.direction_input
= txx9_iocled_dir_in
;
764 iocled
->chip
.direction_output
= txx9_iocled_dir_out
;
765 iocled
->chip
.label
= "iocled";
766 iocled
->chip
.base
= basenum
;
767 iocled
->chip
.ngpio
= num
;
768 if (gpiochip_add(&iocled
->chip
))
771 basenum
= iocled
->chip
.base
;
773 pdev
= platform_device_alloc("leds-gpio", basenum
);
776 iocled
->pdata
.num_leds
= num
;
777 iocled
->pdata
.leds
= iocled
->leds
;
778 for (i
= 0; i
< num
; i
++) {
779 struct gpio_led
*led
= &iocled
->leds
[i
];
780 snprintf(iocled
->names
[i
], sizeof(iocled
->names
[i
]),
781 "iocled:%s:%u", color
, i
);
782 led
->name
= iocled
->names
[i
];
783 led
->gpio
= basenum
+ i
;
784 led
->active_low
= lowactive
;
785 if (deftriggers
&& *deftriggers
)
786 led
->default_trigger
= *deftriggers
++;
788 pdev
->dev
.platform_data
= &iocled
->pdata
;
789 if (platform_device_add(pdev
))
793 platform_device_put(pdev
);
795 if (gpiochip_remove(&iocled
->chip
))
798 iounmap(iocled
->mmioaddr
);
802 #else /* CONFIG_LEDS_GPIO */
803 void __init
txx9_iocled_init(unsigned long baseaddr
,
804 int basenum
, unsigned int num
, int lowactive
,
805 const char *color
, char **deftriggers
)
808 #endif /* CONFIG_LEDS_GPIO */
810 void __init
txx9_dmac_init(int id
, unsigned long baseaddr
, int irq
,
811 const struct txx9dmac_platform_data
*pdata
)
813 #if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE)
814 struct resource res
[] = {
817 .end
= baseaddr
+ 0x800 - 1,
818 .flags
= IORESOURCE_MEM
,
819 #ifndef CONFIG_MACH_TX49XX
822 .flags
= IORESOURCE_IRQ
,
826 #ifdef CONFIG_MACH_TX49XX
827 struct resource chan_res
[] = {
829 .flags
= IORESOURCE_IRQ
,
833 struct platform_device
*pdev
= platform_device_alloc("txx9dmac", id
);
834 struct txx9dmac_chan_platform_data cpdata
;
838 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
839 platform_device_add_data(pdev
, pdata
, sizeof(*pdata
)) ||
840 platform_device_add(pdev
)) {
841 platform_device_put(pdev
);
844 memset(&cpdata
, 0, sizeof(cpdata
));
845 cpdata
.dmac_dev
= pdev
;
846 for (i
= 0; i
< TXX9_DMA_MAX_NR_CHANNELS
; i
++) {
847 #ifdef CONFIG_MACH_TX49XX
848 chan_res
[0].start
= irq
+ i
;
850 pdev
= platform_device_alloc("txx9dmac-chan",
851 id
* TXX9_DMA_MAX_NR_CHANNELS
+ i
);
853 #ifdef CONFIG_MACH_TX49XX
854 platform_device_add_resources(pdev
, chan_res
,
855 ARRAY_SIZE(chan_res
)) ||
857 platform_device_add_data(pdev
, &cpdata
, sizeof(cpdata
)) ||
858 platform_device_add(pdev
))
859 platform_device_put(pdev
);
864 void __init
txx9_aclc_init(unsigned long baseaddr
, int irq
,
865 unsigned int dmac_id
,
866 unsigned int dma_chan_out
,
867 unsigned int dma_chan_in
)
869 #if defined(CONFIG_SND_SOC_TXX9ACLC) || \
870 defined(CONFIG_SND_SOC_TXX9ACLC_MODULE)
871 unsigned int dma_base
= dmac_id
* TXX9_DMA_MAX_NR_CHANNELS
;
872 struct resource res
[] = {
875 .end
= baseaddr
+ 0x100 - 1,
876 .flags
= IORESOURCE_MEM
,
879 .flags
= IORESOURCE_IRQ
,
881 .name
= "txx9dmac-chan",
882 .start
= dma_base
+ dma_chan_out
,
883 .flags
= IORESOURCE_DMA
,
885 .name
= "txx9dmac-chan",
886 .start
= dma_base
+ dma_chan_in
,
887 .flags
= IORESOURCE_DMA
,
890 struct platform_device
*pdev
=
891 platform_device_alloc("txx9aclc-ac97", -1);
894 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
895 platform_device_add(pdev
))
896 platform_device_put(pdev
);
900 static struct bus_type txx9_sramc_subsys
= {
902 .dev_name
= "txx9_sram",
905 struct txx9_sramc_dev
{
907 struct bin_attribute bindata_attr
;
911 static ssize_t
txx9_sram_read(struct file
*filp
, struct kobject
*kobj
,
912 struct bin_attribute
*bin_attr
,
913 char *buf
, loff_t pos
, size_t size
)
915 struct txx9_sramc_dev
*dev
= bin_attr
->private;
916 size_t ramsize
= bin_attr
->size
;
920 if (pos
+ size
> ramsize
)
921 size
= ramsize
- pos
;
922 memcpy_fromio(buf
, dev
->base
+ pos
, size
);
926 static ssize_t
txx9_sram_write(struct file
*filp
, struct kobject
*kobj
,
927 struct bin_attribute
*bin_attr
,
928 char *buf
, loff_t pos
, size_t size
)
930 struct txx9_sramc_dev
*dev
= bin_attr
->private;
931 size_t ramsize
= bin_attr
->size
;
935 if (pos
+ size
> ramsize
)
936 size
= ramsize
- pos
;
937 memcpy_toio(dev
->base
+ pos
, buf
, size
);
941 void __init
txx9_sramc_init(struct resource
*r
)
943 struct txx9_sramc_dev
*dev
;
947 err
= subsys_system_register(&txx9_sramc_subsys
, NULL
);
950 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
953 size
= resource_size(r
);
954 dev
->base
= ioremap(r
->start
, size
);
957 dev
->dev
.bus
= &txx9_sramc_subsys
;
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
= device_register(&dev
->dev
);
968 err
= sysfs_create_bin_file(&dev
->dev
.kobj
, &dev
->bindata_attr
);
970 device_unregister(&dev
->dev
);