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/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/irq.h>
30 #include <asm/bootinfo.h>
33 #include <asm/reboot.h>
34 #include <asm/r4kcache.h>
35 #include <asm/sections.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>
45 /* EBUSC settings of TX4927, etc. */
46 struct resource txx9_ce_res[8];
47 static char txx9_ce_res_name[8][4]; /* "CEn" */
49 /* pcode, internal register */
50 unsigned int txx9_pcode;
51 char txx9_pcode_str[8];
52 static struct resource txx9_reg_res = {
53 .name = txx9_pcode_str,
54 .flags = IORESOURCE_MEM,
57 txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
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];
68 sprintf(txx9_pcode_str, "TX%x", pcode);
70 txx9_reg_res.start = base & 0xfffffffffULL;
71 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
72 request_resource(&iomem_resource, &txx9_reg_res);
77 unsigned int txx9_master_clock;
78 unsigned int txx9_cpu_clock;
79 unsigned int txx9_gbus_clock;
81 #ifdef CONFIG_CPU_TX39XX
82 /* don't enable by default - see errata */
83 int txx9_ccfg_toeon __initdata;
85 int txx9_ccfg_toeon __initdata = 1;
88 #define BOARD_VEC(board) extern struct txx9_board_vec board;
89 #include <asm/txx9/boards.h>
92 struct txx9_board_vec *txx9_board_vec __initdata;
93 static char txx9_system_type[32];
95 static struct txx9_board_vec *board_vecs[] __initdata = {
96 #define BOARD_VEC(board) &board,
97 #include <asm/txx9/boards.h>
101 static struct txx9_board_vec *__init find_board_byname(const char *name)
105 /* search board_vecs table */
106 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
107 if (strstr(board_vecs[i]->system, name))
108 return board_vecs[i];
113 static void __init prom_init_cmdline(void)
117 int i; /* Always ignore the "-c" at argv[0] */
119 if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) {
121 * argc is not a valid number, or argv32 is not a valid
128 argv32 = (int *)fw_arg1;
131 arcs_cmdline[0] = '\0';
133 for (i = 1; i < argc; i++) {
134 char *str = (char *)(long)argv32[i];
136 strcat(arcs_cmdline, " ");
137 if (strchr(str, ' ')) {
138 strcat(arcs_cmdline, "\"");
139 strcat(arcs_cmdline, str);
140 strcat(arcs_cmdline, "\"");
142 strcat(arcs_cmdline, str);
146 static int txx9_ic_disable __initdata;
147 static int txx9_dc_disable __initdata;
149 #if defined(CONFIG_CPU_TX49XX)
150 /* flush all cache on very early stage (before 4k_cache_init) */
151 static void __init early_flush_dcache(void)
153 unsigned int conf = read_c0_config();
154 unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
155 unsigned int linesz = 32;
156 unsigned long addr, end;
158 end = INDEX_BASE + dc_size / 4;
160 for (addr = INDEX_BASE; addr < end; addr += linesz) {
161 cache_op(Index_Writeback_Inv_D, addr | 0);
162 cache_op(Index_Writeback_Inv_D, addr | 1);
163 cache_op(Index_Writeback_Inv_D, addr | 2);
164 cache_op(Index_Writeback_Inv_D, addr | 3);
168 static void __init txx9_cache_fixup(void)
172 conf = read_c0_config();
173 /* flush and disable */
174 if (txx9_ic_disable) {
175 conf |= TX49_CONF_IC;
176 write_c0_config(conf);
178 if (txx9_dc_disable) {
179 early_flush_dcache();
180 conf |= TX49_CONF_DC;
181 write_c0_config(conf);
185 conf = read_c0_config();
186 if (!txx9_ic_disable)
187 conf &= ~TX49_CONF_IC;
188 if (!txx9_dc_disable)
189 conf &= ~TX49_CONF_DC;
190 write_c0_config(conf);
192 if (conf & TX49_CONF_IC)
193 pr_info("TX49XX I-Cache disabled.\n");
194 if (conf & TX49_CONF_DC)
195 pr_info("TX49XX D-Cache disabled.\n");
197 #elif defined(CONFIG_CPU_TX39XX)
198 /* flush all cache on very early stage (before tx39_cache_init) */
199 static void __init early_flush_dcache(void)
201 unsigned int conf = read_c0_config();
202 unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
203 TX39_CONF_DCS_SHIFT));
204 unsigned int linesz = 16;
205 unsigned long addr, end;
207 end = INDEX_BASE + dc_size / 2;
209 for (addr = INDEX_BASE; addr < end; addr += linesz) {
210 cache_op(Index_Writeback_Inv_D, addr | 0);
211 cache_op(Index_Writeback_Inv_D, addr | 1);
215 static void __init txx9_cache_fixup(void)
219 conf = read_c0_config();
220 /* flush and disable */
221 if (txx9_ic_disable) {
222 conf &= ~TX39_CONF_ICE;
223 write_c0_config(conf);
225 if (txx9_dc_disable) {
226 early_flush_dcache();
227 conf &= ~TX39_CONF_DCE;
228 write_c0_config(conf);
232 conf = read_c0_config();
233 if (!txx9_ic_disable)
234 conf |= TX39_CONF_ICE;
235 if (!txx9_dc_disable)
236 conf |= TX39_CONF_DCE;
237 write_c0_config(conf);
239 if (!(conf & TX39_CONF_ICE))
240 pr_info("TX39XX I-Cache disabled.\n");
241 if (!(conf & TX39_CONF_DCE))
242 pr_info("TX39XX D-Cache disabled.\n");
245 static inline void txx9_cache_fixup(void)
250 static void __init preprocess_cmdline(void)
252 static char cmdline[COMMAND_LINE_SIZE] __initdata;
255 strcpy(cmdline, arcs_cmdline);
257 arcs_cmdline[0] = '\0';
259 char *str = strsep(&s, " ");
260 if (strncmp(str, "board=", 6) == 0) {
261 txx9_board_vec = find_board_byname(str + 6);
263 } else if (strncmp(str, "masterclk=", 10) == 0) {
265 if (kstrtouint(str + 10, 10, &val) == 0)
266 txx9_master_clock = val;
268 } else if (strcmp(str, "icdisable") == 0) {
271 } else if (strcmp(str, "dcdisable") == 0) {
274 } else if (strcmp(str, "toeoff") == 0) {
277 } else if (strcmp(str, "toeon") == 0) {
282 strcat(arcs_cmdline, " ");
283 strcat(arcs_cmdline, str);
289 static void __init select_board(void)
293 /* first, determine by "board=" argument in preprocess_cmdline() */
296 /* next, determine by "board" envvar */
297 envstr = prom_getenv("board");
299 txx9_board_vec = find_board_byname(envstr);
304 /* select "default" board */
305 #ifdef CONFIG_TOSHIBA_JMR3927
306 txx9_board_vec = &jmr3927_vec;
308 #ifdef CONFIG_CPU_TX49XX
309 switch (TX4938_REV_PCODE()) {
310 #ifdef CONFIG_TOSHIBA_RBTX4927
312 txx9_board_vec = &rbtx4927_vec;
315 txx9_board_vec = &rbtx4937_vec;
318 #ifdef CONFIG_TOSHIBA_RBTX4938
320 txx9_board_vec = &rbtx4938_vec;
323 #ifdef CONFIG_TOSHIBA_RBTX4939
325 txx9_board_vec = &rbtx4939_vec;
332 void __init prom_init(void)
335 preprocess_cmdline();
338 strcpy(txx9_system_type, txx9_board_vec->system);
340 txx9_board_vec->prom_init();
343 void __init prom_free_prom_memory(void)
345 unsigned long saddr = PAGE_SIZE;
346 unsigned long eaddr = __pa_symbol(&_text);
349 free_init_pages("prom memory", saddr, eaddr);
352 const char *get_system_type(void)
354 return txx9_system_type;
357 const char *__init prom_getenv(const char *name)
361 if (fw_arg2 < CKSEG0)
364 str = (const s32 *)fw_arg2;
365 /* YAMON style ("name", "value" pairs) */
366 while (str[0] && str[1]) {
367 if (!strcmp((const char *)(unsigned long)str[0], name))
368 return (const char *)(unsigned long)str[1];
374 static void __noreturn txx9_machine_halt(void)
377 clear_c0_status(ST0_IM);
381 if (cpu_has_counter) {
383 * Clear counter interrupt while it
384 * breaks WAIT instruction even if
393 /* Watchdog support */
394 void __init txx9_wdt_init(unsigned long base)
396 struct resource res = {
398 .end = base + 0x100 - 1,
399 .flags = IORESOURCE_MEM,
401 platform_device_register_simple("txx9wdt", -1, &res, 1);
404 void txx9_wdt_now(unsigned long base)
406 struct txx9_tmr_reg __iomem *tmrptr =
407 ioremap(base, sizeof(struct txx9_tmr_reg));
408 /* disable watch dog timer */
409 __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
410 __raw_writel(0, &tmrptr->tcr);
412 __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
413 __raw_writel(1, &tmrptr->cpra); /* immediate */
414 __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
419 void __init txx9_spi_init(int busid, unsigned long base, int irq)
421 struct resource res[] = {
424 .end = base + 0x20 - 1,
425 .flags = IORESOURCE_MEM,
428 .flags = IORESOURCE_IRQ,
431 platform_device_register_simple("spi_txx9", busid,
432 res, ARRAY_SIZE(res));
435 void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
437 struct platform_device *pdev =
438 platform_device_alloc("tc35815-mac", id);
440 platform_device_add_data(pdev, ethaddr, 6) ||
441 platform_device_add(pdev))
442 platform_device_put(pdev);
445 void __init txx9_sio_init(unsigned long baseaddr, int irq,
446 unsigned int line, unsigned int sclk, int nocts)
448 #ifdef CONFIG_SERIAL_TXX9
449 struct uart_port req;
451 memset(&req, 0, sizeof(req));
453 req.iotype = UPIO_MEM;
454 req.membase = ioremap(baseaddr, 0x24);
455 req.mapbase = baseaddr;
458 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
460 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
463 req.uartclk = TXX9_IMCLK;
464 early_serial_txx9_setup(&req);
465 #endif /* CONFIG_SERIAL_TXX9 */
468 #ifdef CONFIG_EARLY_PRINTK
469 static void null_prom_putchar(char c)
472 void (*txx9_prom_putchar)(char c) = null_prom_putchar;
474 void prom_putchar(char c)
476 txx9_prom_putchar(c);
479 static void __iomem *early_txx9_sio_port;
481 static void early_txx9_sio_putchar(char c)
483 #define TXX9_SICISR 0x0c
484 #define TXX9_SITFIFO 0x1c
485 #define TXX9_SICISR_TXALS 0x00000002
486 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
489 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
492 void __init txx9_sio_putchar_init(unsigned long baseaddr)
494 early_txx9_sio_port = ioremap(baseaddr, 0x24);
495 txx9_prom_putchar = early_txx9_sio_putchar;
497 #endif /* CONFIG_EARLY_PRINTK */
500 void __init plat_mem_setup(void)
502 ioport_resource.start = 0;
503 ioport_resource.end = ~0UL; /* no limit */
504 iomem_resource.start = 0;
505 iomem_resource.end = ~0UL; /* no limit */
507 /* fallback restart/halt routines */
508 _machine_restart = (void (*)(char *))txx9_machine_halt;
509 _machine_halt = txx9_machine_halt;
510 pm_power_off = txx9_machine_halt;
513 pcibios_plat_setup = txx9_pcibios_setup;
515 txx9_board_vec->mem_setup();
518 void __init arch_init_irq(void)
520 txx9_board_vec->irq_setup();
523 void __init plat_time_init(void)
525 #ifdef CONFIG_CPU_TX49XX
526 mips_hpt_frequency = txx9_cpu_clock / 2;
528 txx9_board_vec->time_init();
531 static void txx9_clk_init(void)
536 hw = clk_hw_register_fixed_rate(NULL, "gbus", NULL, 0, txx9_gbus_clock);
542 hw = clk_hw_register_fixed_factor(NULL, "imbus", "gbus", 0, 1, 2);
543 error = clk_hw_register_clkdev(hw, "imbus_clk", NULL);
547 #ifdef CONFIG_CPU_TX49XX
548 if (TX4938_REV_PCODE() == 0x4938) {
549 hw = clk_hw_register_fixed_factor(NULL, "spi", "gbus", 0, 1, 4);
550 error = clk_hw_register_clkdev(hw, "spi-baseclk", NULL);
559 pr_err("Failed to register clocks: %d\n", error);
562 static int __init _txx9_arch_init(void)
566 if (txx9_board_vec->arch_init)
567 txx9_board_vec->arch_init();
570 arch_initcall(_txx9_arch_init);
572 static int __init _txx9_device_init(void)
574 if (txx9_board_vec->device_init)
575 txx9_board_vec->device_init();
578 device_initcall(_txx9_device_init);
580 int (*txx9_irq_dispatch)(int pending);
581 asmlinkage void plat_irq_dispatch(void)
583 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
584 int irq = txx9_irq_dispatch(pending);
586 if (likely(irq >= 0))
589 spurious_interrupt();
592 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
593 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
594 static unsigned long __swizzle_addr_none(unsigned long port)
598 unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
599 EXPORT_SYMBOL(__swizzle_addr_b);
602 #ifdef NEEDS_TXX9_IOSWABW
603 static u16 ioswabw_default(volatile u16 *a, u16 x)
605 return le16_to_cpu(x);
607 static u16 __mem_ioswabw_default(volatile u16 *a, u16 x)
611 u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default;
612 EXPORT_SYMBOL(ioswabw);
613 u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default;
614 EXPORT_SYMBOL(__mem_ioswabw);
617 void __init txx9_physmap_flash_init(int no, unsigned long addr,
619 const struct physmap_flash_data *pdata)
621 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
622 struct resource res = {
624 .end = addr + size - 1,
625 .flags = IORESOURCE_MEM,
627 struct platform_device *pdev;
628 static struct mtd_partition parts[2];
629 struct physmap_flash_data pdata_part;
631 /* If this area contained boot area, make separate partition */
632 if (pdata->nr_parts == 0 && !pdata->parts &&
633 addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
635 parts[0].name = "boot";
636 parts[0].offset = 0x1fc00000 - addr;
637 parts[0].size = addr + size - 0x1fc00000;
638 parts[1].name = "user";
640 parts[1].size = 0x1fc00000 - addr;
642 pdata_part.nr_parts = ARRAY_SIZE(parts);
643 pdata_part.parts = parts;
647 pdev = platform_device_alloc("physmap-flash", no);
649 platform_device_add_resources(pdev, &res, 1) ||
650 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
651 platform_device_add(pdev))
652 platform_device_put(pdev);
656 void __init txx9_ndfmc_init(unsigned long baseaddr,
657 const struct txx9ndfmc_platform_data *pdata)
659 #if IS_ENABLED(CONFIG_MTD_NAND_TXX9NDFMC)
660 struct resource res = {
662 .end = baseaddr + 0x1000 - 1,
663 .flags = IORESOURCE_MEM,
665 struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
668 platform_device_add_resources(pdev, &res, 1) ||
669 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
670 platform_device_add(pdev))
671 platform_device_put(pdev);
675 #if IS_ENABLED(CONFIG_LEDS_GPIO)
676 static DEFINE_SPINLOCK(txx9_iocled_lock);
678 #define TXX9_IOCLED_MAXLEDS 8
680 struct txx9_iocled_data {
681 struct gpio_chip chip;
683 void __iomem *mmioaddr;
684 struct gpio_led_platform_data pdata;
685 struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
686 char names[TXX9_IOCLED_MAXLEDS][32];
689 static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
691 struct txx9_iocled_data *data = gpiochip_get_data(chip);
692 return !!(data->cur_val & (1 << offset));
695 static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
698 struct txx9_iocled_data *data = gpiochip_get_data(chip);
700 spin_lock_irqsave(&txx9_iocled_lock, flags);
702 data->cur_val |= 1 << offset;
704 data->cur_val &= ~(1 << offset);
705 writeb(data->cur_val, data->mmioaddr);
707 spin_unlock_irqrestore(&txx9_iocled_lock, flags);
710 static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
715 static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
718 txx9_iocled_set(chip, offset, value);
722 void __init txx9_iocled_init(unsigned long baseaddr,
723 int basenum, unsigned int num, int lowactive,
724 const char *color, char **deftriggers)
726 struct txx9_iocled_data *iocled;
727 struct platform_device *pdev;
729 static char *default_triggers[] __initdata = {
737 deftriggers = default_triggers;
738 iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
741 iocled->mmioaddr = ioremap(baseaddr, 1);
742 if (!iocled->mmioaddr)
744 iocled->chip.get = txx9_iocled_get;
745 iocled->chip.set = txx9_iocled_set;
746 iocled->chip.direction_input = txx9_iocled_dir_in;
747 iocled->chip.direction_output = txx9_iocled_dir_out;
748 iocled->chip.label = "iocled";
749 iocled->chip.base = basenum;
750 iocled->chip.ngpio = num;
751 if (gpiochip_add_data(&iocled->chip, iocled))
754 basenum = iocled->chip.base;
756 pdev = platform_device_alloc("leds-gpio", basenum);
759 iocled->pdata.num_leds = num;
760 iocled->pdata.leds = iocled->leds;
761 for (i = 0; i < num; i++) {
762 struct gpio_led *led = &iocled->leds[i];
763 snprintf(iocled->names[i], sizeof(iocled->names[i]),
764 "iocled:%s:%u", color, i);
765 led->name = iocled->names[i];
766 led->gpio = basenum + i;
767 led->active_low = lowactive;
768 if (deftriggers && *deftriggers)
769 led->default_trigger = *deftriggers++;
771 pdev->dev.platform_data = &iocled->pdata;
772 if (platform_device_add(pdev))
777 platform_device_put(pdev);
779 gpiochip_remove(&iocled->chip);
781 iounmap(iocled->mmioaddr);
785 #else /* CONFIG_LEDS_GPIO */
786 void __init txx9_iocled_init(unsigned long baseaddr,
787 int basenum, unsigned int num, int lowactive,
788 const char *color, char **deftriggers)
791 #endif /* CONFIG_LEDS_GPIO */
793 void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
794 const struct txx9dmac_platform_data *pdata)
796 #if IS_ENABLED(CONFIG_TXX9_DMAC)
797 struct resource res[] = {
800 .end = baseaddr + 0x800 - 1,
801 .flags = IORESOURCE_MEM,
802 #ifndef CONFIG_MACH_TX49XX
805 .flags = IORESOURCE_IRQ,
809 #ifdef CONFIG_MACH_TX49XX
810 struct resource chan_res[] = {
812 .flags = IORESOURCE_IRQ,
816 struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
817 struct txx9dmac_chan_platform_data cpdata;
821 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
822 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
823 platform_device_add(pdev)) {
824 platform_device_put(pdev);
827 memset(&cpdata, 0, sizeof(cpdata));
828 cpdata.dmac_dev = pdev;
829 for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
830 #ifdef CONFIG_MACH_TX49XX
831 chan_res[0].start = irq + i;
833 pdev = platform_device_alloc("txx9dmac-chan",
834 id * TXX9_DMA_MAX_NR_CHANNELS + i);
836 #ifdef CONFIG_MACH_TX49XX
837 platform_device_add_resources(pdev, chan_res,
838 ARRAY_SIZE(chan_res)) ||
840 platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
841 platform_device_add(pdev))
842 platform_device_put(pdev);
847 void __init txx9_aclc_init(unsigned long baseaddr, int irq,
848 unsigned int dmac_id,
849 unsigned int dma_chan_out,
850 unsigned int dma_chan_in)
852 #if IS_ENABLED(CONFIG_SND_SOC_TXX9ACLC)
853 unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS;
854 struct resource res[] = {
857 .end = baseaddr + 0x100 - 1,
858 .flags = IORESOURCE_MEM,
861 .flags = IORESOURCE_IRQ,
863 .name = "txx9dmac-chan",
864 .start = dma_base + dma_chan_out,
865 .flags = IORESOURCE_DMA,
867 .name = "txx9dmac-chan",
868 .start = dma_base + dma_chan_in,
869 .flags = IORESOURCE_DMA,
872 struct platform_device *pdev =
873 platform_device_alloc("txx9aclc-ac97", -1);
876 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
877 platform_device_add(pdev))
878 platform_device_put(pdev);
882 static struct bus_type txx9_sramc_subsys = {
884 .dev_name = "txx9_sram",
887 struct txx9_sramc_dev {
889 struct bin_attribute bindata_attr;
893 static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
894 struct bin_attribute *bin_attr,
895 char *buf, loff_t pos, size_t size)
897 struct txx9_sramc_dev *dev = bin_attr->private;
898 size_t ramsize = bin_attr->size;
902 if (pos + size > ramsize)
903 size = ramsize - pos;
904 memcpy_fromio(buf, dev->base + pos, size);
908 static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
909 struct bin_attribute *bin_attr,
910 char *buf, loff_t pos, size_t size)
912 struct txx9_sramc_dev *dev = bin_attr->private;
913 size_t ramsize = bin_attr->size;
917 if (pos + size > ramsize)
918 size = ramsize - pos;
919 memcpy_toio(dev->base + pos, buf, size);
923 static void txx9_device_release(struct device *dev)
925 struct txx9_sramc_dev *tdev;
927 tdev = container_of(dev, struct txx9_sramc_dev, dev);
931 void __init txx9_sramc_init(struct resource *r)
933 struct txx9_sramc_dev *dev;
937 err = subsys_system_register(&txx9_sramc_subsys, NULL);
940 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
943 size = resource_size(r);
944 dev->base = ioremap(r->start, size);
949 dev->dev.release = &txx9_device_release;
950 dev->dev.bus = &txx9_sramc_subsys;
951 sysfs_bin_attr_init(&dev->bindata_attr);
952 dev->bindata_attr.attr.name = "bindata";
953 dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
954 dev->bindata_attr.read = txx9_sram_read;
955 dev->bindata_attr.write = txx9_sram_write;
956 dev->bindata_attr.size = size;
957 dev->bindata_attr.private = dev;
958 err = device_register(&dev->dev);
961 err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
964 device_unregister(&dev->dev);
969 put_device(&dev->dev);