import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / mach-mt8127 / mt_mcu.c
1 #include <linux/kernel.h>
2 #include <linux/device.h>
3 #include <linux/platform_device.h>
4 #include <linux/module.h>
5 #include <mach/mt_mcu.h>
6 #include <mach/mt_reg_base.h>
7 #include <asm/system.h>
8 #include <linux/module.h>
9 #include <linux/uaccess.h>
10 #include <linux/vmalloc.h>
11 #include <linux/slab.h>
12 #include <mach/dma.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/cpu.h>
15 #include <linux/smp.h>
16 #define LDVT
17 #define MCU_DEBUG
18
19 #ifdef MCU_DEBUG
20 #define dbg_printk printk
21 #else
22 #define dbg_printk
23 #endif
24 extern void smp_inner_dcache_flush_all();
25
26 static struct mt_mcu_driver {
27 struct device_driver driver;
28 const struct platform_device_id *id_table;
29 };
30
31 static struct mt_mcu_driver mt_mcu_drv = {
32 .driver = {
33 .name = "mcu",
34 .bus = &platform_bus_type,
35 .owner = THIS_MODULE,
36 },
37 .id_table= NULL,
38 };
39
40 #ifdef LDVT
41 #define BUFF_LEN (1024*1024)
42
43 static int ts_emi_access(void){
44 unsigned int *test_array_v;
45 unsigned int *test_array_p;
46 unsigned int i;
47 test_array_v = dma_alloc_coherent(NULL, sizeof(unsigned int ) * BUFF_LEN/sizeof(unsigned int), &test_array_p, GFP_KERNEL );
48
49 for(i = 0; i < BUFF_LEN/sizeof(unsigned int); i++)
50 test_array_v[i] = i;
51 return 0;
52 }
53 static int ts_tran_count(void){
54
55 printk("in %s",__FUNCTION__);
56 /* set up performance counter */
57 /* enable counter */
58 #if 1
59 printk("in testcases:MCU_BIU_EVENT0_CNT=%x,MCU_BIU_EVENT1_CNT:%x\n",*((unsigned int *) MCU_BIU_EVENT0_CNT),*((unsigned int *) MCU_BIU_EVENT1_CNT));
60 *((unsigned int *) MCU_BIU_EVENT0_SEL) = 0x2; //AC_R snoop transaction count MCU->CPU
61 //*((unsigned int *) MCU_EVENT1_SEL) = 0x4; //AC_R snoop hit
62 *((unsigned int *) MCU_BIU_EVENT1_SEL) = 0x0; // DMA->MCU
63 *((unsigned int *) MCU_BIU_EVENT0_CON) = 0x1; // enable counter 0
64 *((unsigned int *) MCU_BIU_EVENT1_CON) = 0x1; // enable counter 1
65 *((unsigned int *) MCU_BIU_PMCR) |= 0x2; // retset perf counter
66 *((unsigned int *) MCU_BIU_PMCR) &= ~0x2; // reset performance counter
67 #endif
68
69 /* Invoke 4 cores concurrent write to EMI with 1MB data set per core. */
70 get_online_cpus();
71 on_each_cpu(ts_emi_access, NULL, false);
72 put_online_cpus();
73 /* check performance counter */
74 printk("in testcases:MCU_EVENT0_CNT=%x,MCU_EVENT1_CNT:%x\n",*((unsigned int *) MCU_BIU_EVENT0_CNT),*((unsigned int *) MCU_BIU_EVENT1_CNT));
75
76 return 0;
77 }
78 /*
79 * mci_dvt_show: To show usage.
80 */
81 static ssize_t mcu_dvt_show(struct device_driver *driver, char *buf)
82 {
83 return snprintf(buf, PAGE_SIZE, "MCU dvt test\n");
84 }
85
86 /*
87 * mci_dvt_store: To select mci test case.
88 */
89 static ssize_t mcu_dvt_store(struct device_driver *driver, const char *buf,
90 size_t count)
91 {
92 char *p = (char *)buf;
93 unsigned int num;
94
95 num = simple_strtoul(p, &p, 10);
96 switch(num){
97 case 1:
98 break;
99 case 2:
100 break;
101 case 3:
102 break;
103 case 4:
104 break;
105 default:
106 break;
107 }
108
109 return count;
110 }
111 DRIVER_ATTR(mcu_dvt, 0664, mcu_dvt_show, mcu_dvt_store);
112 #endif //!LDVT
113 int mt_mcu_init(void){
114 volatile unsigned int reg_val;
115 int ret;
116 dbg_printk("[MCU] MCU init...\n");
117 #if 0
118 /* enable Out of order*/
119 reg_val = readl(MCU_BIU_CON);
120 reg_val |= 0x1;
121 writel(reg_val, MCU_BIU_CON);
122 #endif
123
124 #if 0
125 /* set order_depth*/
126 reg_val = readl(MCU_BIU_CON);
127 reg_val |= (0x1 << 0x8);
128 writel(reg_val, MCU_BIU_CON);
129
130 #endif
131
132 #if 0
133 /* enable MCU_BIU DCM function*/
134 reg_val = readl(MCU_BIU_CON);
135 reg_val |= (0x1 << 12);
136 writel(reg_val, MCU_BIU_CON);
137 #endif
138
139 #if 0
140 /* enable MCUSYS DCM function */
141 reg_val = readl(MCUSYS_CA7_MISC_CONFIG);
142 reg_val |= (0x1 << 9);
143 writel(reg_val, MCUSYS_CA7_MISC_CONFIG);
144 #endif
145
146 #if 0
147 /*PC / FP / SP trapper */
148 dbg_printk("CPU0-PC:0x%x,CPU1-PC:0x%x,CPU2-PC:0x%x,CPU3-PC:0x%x\n",readl(MCUSYS_DBG_CORE0_PC),readl(MCUSYS_DBG_CORE1_PC),readl(MCUSYS_DBG_CORE2_PC),readl(MCUSYS_DBG_CORE3_PC));
149 dbg_printk("CPU0-FP:0x%x,CPU1-FP:0x%x,CPU2-FP:0x%x,CPU3-FP:0x%x\n",readl(MCUSYS_DBG_CORE0_FP),readl(MCUSYS_DBG_CORE1_FP),readl(MCUSYS_DBG_CORE2_FP),readl(MCUSYS_DBG_CORE3_FP));
150 dbg_printk("CPU0-SP:0x%x,CPU1-SP:0x%x,CPU2-SP:0x%x,CPU3-SP:0x%x\n",readl(MCUSYS_DBG_CORE0_SP),readl(MCUSYS_DBG_CORE1_SP),readl(MCUSYS_DBG_CORE2_SP),readl(MCUSYS_DBG_CORE3_SP));
151 #endif
152 ret = driver_register(&mt_mcu_drv.driver);
153 #ifdef LDVT
154 ret = driver_create_file(&mt_mcu_drv.driver, &driver_attr_mcu_dvt);
155 #endif
156 if (ret == 0)
157 dbg_printk("MCU init done...\n");
158 return ret;
159
160 }
161 int mt_mcu_exit(void){
162
163 return 0;
164
165 }
166 module_init(mt_mcu_init);
167 module_exit(mt_mcu_exit);