ARM: lib: delay: align loop
[pandora-kernel.git] / arch / arm / kernel / sysfs_v7.c
1 /*
2  *  linux/arch/arm/kernel/sysfs.c
3  *
4  *  Copyright (C) 2008 Mans Rullgard
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/cpu.h>
13 #include <linux/sysdev.h>
14 #include <linux/fs.h>
15 #include <asm/page.h>
16
17 #define SETBITS(val, bits, new)                 \
18         do {                                    \
19                 val &= ~bits;                   \
20                 val |= new & bits;              \
21         } while (0)
22
23 #define SHOW_REG(name, opc1, crn, crm, opc2)                            \
24 static ssize_t name##_show(struct sys_device *dev,                      \
25                            struct sysdev_attribute *attr,               \
26                            char *buf)                                   \
27 {                                                                       \
28         unsigned val;                                                   \
29         asm ("mrc p15,"#opc1", %0,"#crn","#crm","#opc2 : "=r"(val));    \
30         return snprintf(buf, PAGE_SIZE, "%08x\n", val);                 \
31 }
32
33 #define STORE_REG(name, opc1, crn, crm, opc2, bits)                     \
34 static ssize_t name##_store(struct sys_device *dev,                     \
35                             struct sysdev_attribute *attr,              \
36                             const char *buf, size_t size)               \
37 {                                                                       \
38         char *end;                                                      \
39         unsigned new = simple_strtoul(buf, &end, 0);                    \
40         unsigned val;                                                   \
41                                                                         \
42         if (end == buf)                                                 \
43                 return -EINVAL;                                         \
44                                                                         \
45         asm ("mrc p15,"#opc1", %0,"#crn","#crm","#opc2 : "=r"(val));    \
46         SETBITS(val, bits, new);                                        \
47         asm ("mcr p15,"#opc1", %0,"#crn","#crm","#opc2 :: "r"(val));    \
48                                                                         \
49         return end - buf;                                               \
50 }
51
52 #define RD_REG(name, opc1, crn, crm, opc2)                              \
53         SHOW_REG(name, opc1, crn, crm, opc2)                            \
54         static SYSDEV_ATTR(name, S_IRUGO|S_IWUSR, name##_show, NULL)
55
56 #define RDWR_REG(name, opc1, crn, crm, opc2, bits)                      \
57         SHOW_REG(name, opc1, crn, crm, opc2)                            \
58         STORE_REG(name, opc1, crn, crm, opc2, bits)                     \
59         static SYSDEV_ATTR(name, S_IRUGO|S_IWUSR, name##_show, name##_store)
60
61 RDWR_REG(control, 0, c1, c0, 0, 0x802);
62
63 SHOW_REG(aux_ctl, 0, c1, c0, 1)
64
65 #ifdef CONFIG_ARCH_OMAP34XX
66 static ssize_t aux_ctl_store(struct sys_device *dev,
67                              struct sysdev_attribute *attr,
68                              const char *buf, size_t size)
69 {
70         char *end;
71         unsigned new = simple_strtoul(buf, &end, 0);
72         unsigned val;
73
74         if (end == buf)
75                 return -EINVAL;
76
77         asm ("mrc p15, 0, %0, c1, c0, 1" : "=r"(val));
78         SETBITS(val, 0xff8, new);
79         val &= ~2;
80         asm ("mov r0,  %0       \n\t"
81              "mov r12, #3       \n\t"
82              "smc #0            \n\t"
83              :: "r"(val) : "r0", "r12");
84
85         return end - buf;
86 }
87 #define AUX_WR S_IWUSR
88 #else
89 #define aux_ctl_store NULL
90 #define AUX_WR 0
91 #endif
92
93 static SYSDEV_ATTR(aux_control, S_IRUGO|AUX_WR, aux_ctl_show, aux_ctl_store);
94
95 SHOW_REG(l2_aux_ctl, 1, c9, c0, 2)
96
97 #ifdef CONFIG_ARCH_OMAP34XX
98 static ssize_t l2_aux_ctl_store(struct sys_device *dev,
99                                 struct sysdev_attribute *attr,
100                                 const char *buf, size_t size)
101 {
102         char *end;
103         unsigned new = simple_strtoul(buf, &end, 0);
104         unsigned val;
105
106         if (end == buf)
107                 return -EINVAL;
108
109         asm ("mrc p15, 1, %0, c9, c0, 2" : "=r"(val));
110         SETBITS(val, 0xbc00000, new);
111         asm ("mov r0,  %0       \n\t"
112              "mov r12, #2       \n\t"
113              "smc #0            \n\t"
114              :: "r"(val) : "r0", "r12");
115
116         return end - buf;
117 }
118 #define L2AUX_WR S_IWUSR
119 #else
120 #define l2_aux_ctl_store NULL
121 #define L2AUX_WR 0
122 #endif
123
124 static SYSDEV_ATTR(l2_aux_control, S_IRUGO|L2AUX_WR,
125                    l2_aux_ctl_show, l2_aux_ctl_store);
126
127 RDWR_REG(pmon_pmnc,   0, c9, c12, 0, 0x3f)
128 RDWR_REG(pmon_cntens, 0, c9, c12, 1, 0x8000000f)
129 RDWR_REG(pmon_cntenc, 0, c9, c12, 2, 0x8000000f)
130 RDWR_REG(pmon_ccnt,   0, c9, c13, 0, 0xffffffff)
131 RDWR_REG(pmon_useren, 0, c9, c14, 0, 1)
132
133 #define REG_ATTR(sysdev, name)                                          \
134         do {                                                            \
135                 int err = sysfs_create_file(&sysdev->kobj, &name.attr); \
136                 WARN_ON(err != 0);                                      \
137         } while (0)
138
139 static int __init cpu_sysfs_init(void)
140 {
141         struct sys_device *sysdev;
142         int cpu;
143
144         for_each_possible_cpu(cpu) {
145                 sysdev = get_cpu_sysdev(cpu);
146                 REG_ATTR(sysdev, attr_control);
147                 REG_ATTR(sysdev, attr_aux_control);
148                 REG_ATTR(sysdev, attr_l2_aux_control);
149                 REG_ATTR(sysdev, attr_pmon_pmnc);
150                 REG_ATTR(sysdev, attr_pmon_cntens);
151                 REG_ATTR(sysdev, attr_pmon_cntenc);
152                 REG_ATTR(sysdev, attr_pmon_ccnt);
153                 REG_ATTR(sysdev, attr_pmon_useren);
154         }
155
156         return 0;
157 }
158 device_initcall(cpu_sysfs_init);