diff options
author | Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | 2012-02-22 07:43:50 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-02-22 08:10:31 -0500 |
commit | 09c6ecd394105c4864a0e409e181c9b1578c2a63 (patch) | |
tree | 84ddf6946e4aeeb70d39c919f18bc5f6441e54ca /drivers/base/regmap/regmap-debugfs.c | |
parent | b8fb5ab156055b745254609f4635fcfd6b7dabc8 (diff) |
regmap: Add support for writing to regmap registers via debugfs
To enable writing to the regmap debugfs registers file users will
need to modify the source directly and #define REGMAP_ALLOW_WRITE_DEBUGFS.
The reason for this is that it is dangerous to expose this
functionality in general where clients could potentially be PMICs.
[A couple of minor style updates -- broonie]
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base/regmap/regmap-debugfs.c')
-rw-r--r-- | drivers/base/regmap/regmap-debugfs.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index b3b4b8f7f409..7accb81dd94e 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c | |||
@@ -103,9 +103,51 @@ out: | |||
103 | return ret; | 103 | return ret; |
104 | } | 104 | } |
105 | 105 | ||
106 | #undef REGMAP_ALLOW_WRITE_DEBUGFS | ||
107 | #ifdef REGMAP_ALLOW_WRITE_DEBUGFS | ||
108 | /* | ||
109 | * This can be dangerous especially when we have clients such as | ||
110 | * PMICs, therefore don't provide any real compile time configuration option | ||
111 | * for this feature, people who want to use this will need to modify | ||
112 | * the source code directly. | ||
113 | */ | ||
114 | static ssize_t regmap_map_write_file(struct file *file, | ||
115 | const char __user *user_buf, | ||
116 | size_t count, loff_t *ppos) | ||
117 | { | ||
118 | char buf[32]; | ||
119 | size_t buf_size; | ||
120 | char *start = buf; | ||
121 | unsigned long reg, value; | ||
122 | struct regmap *map = file->private_data; | ||
123 | |||
124 | buf_size = min(count, (sizeof(buf)-1)); | ||
125 | if (copy_from_user(buf, user_buf, buf_size)) | ||
126 | return -EFAULT; | ||
127 | buf[buf_size] = 0; | ||
128 | |||
129 | while (*start == ' ') | ||
130 | start++; | ||
131 | reg = simple_strtoul(start, &start, 16); | ||
132 | while (*start == ' ') | ||
133 | start++; | ||
134 | if (strict_strtoul(start, 16, &value)) | ||
135 | return -EINVAL; | ||
136 | |||
137 | /* Userspace has been fiddling around behind the kernel's back */ | ||
138 | add_taint(TAINT_USER); | ||
139 | |||
140 | regmap_write(map, reg, value); | ||
141 | return buf_size; | ||
142 | } | ||
143 | #else | ||
144 | #define regmap_map_write_file NULL | ||
145 | #endif | ||
146 | |||
106 | static const struct file_operations regmap_map_fops = { | 147 | static const struct file_operations regmap_map_fops = { |
107 | .open = regmap_open_file, | 148 | .open = regmap_open_file, |
108 | .read = regmap_map_read_file, | 149 | .read = regmap_map_read_file, |
150 | .write = regmap_map_write_file, | ||
109 | .llseek = default_llseek, | 151 | .llseek = default_llseek, |
110 | }; | 152 | }; |
111 | 153 | ||