Advertisement
xerpi

nintendo3ds_ctr.c VRAM putch

Oct 17th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.78 KB | None | 0 0
  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include <linux/io.h>
  4. #include <linux/irqchip/arm-gic.h>
  5. #include <linux/platform_device.h>
  6.  
  7. #include <linux/clk-provider.h>
  8. #include <linux/dma-mapping.h>
  9. #include <linux/init.h>
  10. #include <linux/of.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/platform_device.h>
  13.  
  14. #include <asm/mach-types.h>
  15. #include <asm/mach/arch.h>
  16. #include <asm/mach/map.h>
  17. #include <asm/smp_twd.h>
  18.  
  19. #include <mach/hardware.h>
  20. #include <mach/platform.h>
  21.  
  22. /*
  23. static struct map_desc nintendo3ds_ctr_io_desc[] __initdata = {
  24.     {
  25.         .virtual    = IO_ADDRESS(NINTENDO3DS_CTR_PRIV_MEM_BASE),
  26.         .pfn        = __phys_to_pfn(NINTENDO3DS_CTR_PRIV_MEM_BASE),
  27.         .length     = NINTENDO3DS_CTR_PRIV_MEM_SIZE,
  28.         .type       = MT_DEVICE,
  29.     }
  30. };*/
  31.  
  32.  
  33. /*
  34. static void __init nintendo3ds_ctr_init_irq(void)
  35. {
  36.     int i;
  37.  
  38.     printk("nintendo3ds_ctr_init_irq\n");
  39.  
  40.     // Enable clear all the GID interrupts
  41.     // Pending clear all the GID interrupts
  42.     for (i = 0; i < 8; i++) {
  43.         writel(0xFFFFFFFF, __io_address(NINTENDO3DS_CTR_GIC_INT_PEND_CLR_REG(i)));
  44.         writel(0xFFFFFFFF, __io_address(NINTENDO3DS_CTR_GIC_INT_EN_CLR_REG(i)));
  45.     }
  46.  
  47.     gic_init(0, 29, __io_address(NINTENDO3DS_CTR_GIC_BASE),
  48.         __io_address(NINTENDO3DS_CTR_CPU_INT_INTERFACE_BASE));
  49.  
  50.     //printk("nintendo3ds_ctr_init_irq DONE\n");
  51.  
  52.     //gic_init(unsigned int nr, int start, void __iomem *dist , void __iomem *cpu)
  53.  
  54.     // Enable CPU Interrupt Interface
  55.     //writel(1, __io_address(NINTENDO3DS_CTR_CPU_INT_INTERFACE_CONTROL));
  56.  
  57.     // Enable Global Interrupt Distributor
  58.     //writel(1, __io_address(NINTENDO3DS_CTR_GID_IDCR));
  59. }*/
  60.  
  61. // Shared with 3DS's ARM9 CPU
  62. /*#define SHARED_CHAR_PA (0x20000000)
  63. #define SHARED_CHAR    (*(volatile char *)__va(SHARED_CHAR_PA))
  64.  
  65. void n3ds_putch(char c)
  66. {
  67.     SHARED_CHAR = c;
  68.     // Clean and Invalidate Entire Data Cache
  69.     // Data Synchronization Barrier
  70.     asm volatile (
  71.         "mov r0, #0\n\t"
  72.         "mcr p15, 0, r0, c7, c14, 0\n\t"
  73.         "mcr p15, 0, r0, c7, c10, 4\n\t"
  74.         : : : "r0"
  75.     );
  76.     do {
  77.         // Invalidate Entire Data Cache
  78.         asm volatile (
  79.             "mov r0, #0\n\t"
  80.             "mcr p15, 0, r0, c7, c6, 0\n\t"
  81.             : : : "r0"
  82.         );
  83.     } while (SHARED_CHAR != 0);
  84. }
  85.  
  86. void n3ds_print(const char *str)
  87. {
  88.     while (*str) {
  89.         n3ds_putch(*str);
  90.         str++;
  91.     }
  92. }
  93.  
  94. void n3ds_printf(const char *str, ...)
  95. {
  96.     char dest[1020];
  97.     va_list argptr;
  98.     va_start(argptr, str);
  99.     vsnprintf(dest, 1020, str, argptr);
  100.     va_end(argptr);
  101.     n3ds_print(dest);
  102. }
  103.  
  104. #define printk(...) n3ds_printf(__VA_ARGS__)*/
  105.  
  106. static void *vram_va = NULL;
  107.  
  108. static void __init nintendo3ds_ctr_map_io(void)
  109. {
  110.     printk("nintendo3ds_ctr_map_io\n");
  111.  
  112.     // Try to map VRAM
  113.     /*if (!request_mem_region(NINTENDO3DS_CTR_VRAM_BASE,
  114.         NINTENDO3DS_CTR_VRAM_SIZE, "N3DS_VRAM")) {
  115.             printk("VRAM region not available.\n");
  116.     } else {
  117.         vram_va = ioremap_nocache(NINTENDO3DS_CTR_VRAM_BASE,
  118.             NINTENDO3DS_CTR_VRAM_SIZE);
  119.  
  120.         printk("VRAM mapped to: %p - %p\n", vram_va,
  121.             vram_va + NINTENDO3DS_CTR_VRAM_SIZE);
  122.     }*/
  123.  
  124.     //iotable_init(nintendo3ds_ctr_io_desc, ARRAY_SIZE(nintendo3ds_ctr_io_desc));
  125. }
  126.  
  127. static void __init nintendo3ds_ctr_init_early(void)
  128. {
  129. }
  130.  
  131. static void __init nintendo3ds_ctr_dt_init_machine(void)
  132. {
  133.     printk("nintendo3ds_ctr_dt_init_machine\n");
  134.     of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  135. }
  136.  
  137. static void __init nintendo3ds_ctr_restart(enum reboot_mode mode, const char *cmd)
  138. {
  139.     printk("nintendo3ds_ctr_restart\n");
  140. }
  141.  
  142.  
  143. static const char *nintendo3ds_ctr_dt_platform_compat[] __initconst = {
  144.     "nintendo3ds,ctr",
  145.     NULL,
  146. };
  147.  
  148. DT_MACHINE_START(NINTENDO3DS_DT, "Nintendo 3DS (CTR) (Device Tree)")
  149.     .map_io     = nintendo3ds_ctr_map_io,
  150.     .init_early = nintendo3ds_ctr_init_early,
  151.     .init_machine   = nintendo3ds_ctr_dt_init_machine,
  152.     .dt_compat  = nintendo3ds_ctr_dt_platform_compat,
  153.     .restart    = nintendo3ds_ctr_restart,
  154. MACHINE_END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement