Skip to content

Commit 6cca83d

Browse files
committed
Platform: OLPC: move debugfs support from x86 EC driver
There's nothing about the debugfs interface for the EC driver that is architecture-specific, so move it into the arch-independent driver. The code is mostly unchanged with the exception of renamed variables, coding style changes, and API updates. Signed-off-by: Andres Salomon <dilinger@queued.net> Acked-by: Paul Fox <pgf@laptop.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 85f90cf commit 6cca83d

File tree

2 files changed

+117
-97
lines changed

2 files changed

+117
-97
lines changed

arch/x86/platform/olpc/olpc.c

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/platform_device.h>
2020
#include <linux/of.h>
2121
#include <linux/syscore_ops.h>
22-
#include <linux/debugfs.h>
2322
#include <linux/mutex.h>
2423
#include <linux/olpc-ec.h>
2524

@@ -31,15 +30,6 @@
3130
struct olpc_platform_t olpc_platform_info;
3231
EXPORT_SYMBOL_GPL(olpc_platform_info);
3332

34-
/* debugfs interface to EC commands */
35-
#define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */
36-
#define EC_MAX_CMD_REPLY (8)
37-
38-
static struct dentry *ec_debugfs_dir;
39-
static DEFINE_MUTEX(ec_debugfs_cmd_lock);
40-
static unsigned char ec_debugfs_resp[EC_MAX_CMD_REPLY];
41-
static unsigned int ec_debugfs_resp_bytes;
42-
4333
/* EC event mask to be applied during suspend (defining wakeup sources). */
4434
static u16 ec_wakeup_mask;
4535

@@ -273,91 +263,6 @@ int olpc_ec_sci_query(u16 *sci_value)
273263
}
274264
EXPORT_SYMBOL_GPL(olpc_ec_sci_query);
275265

276-
static ssize_t ec_debugfs_cmd_write(struct file *file, const char __user *buf,
277-
size_t size, loff_t *ppos)
278-
{
279-
int i, m;
280-
unsigned char ec_cmd[EC_MAX_CMD_ARGS];
281-
unsigned int ec_cmd_int[EC_MAX_CMD_ARGS];
282-
char cmdbuf[64];
283-
int ec_cmd_bytes;
284-
285-
mutex_lock(&ec_debugfs_cmd_lock);
286-
287-
size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size);
288-
289-
m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0],
290-
&ec_debugfs_resp_bytes,
291-
&ec_cmd_int[1], &ec_cmd_int[2], &ec_cmd_int[3],
292-
&ec_cmd_int[4], &ec_cmd_int[5]);
293-
if (m < 2 || ec_debugfs_resp_bytes > EC_MAX_CMD_REPLY) {
294-
/* reset to prevent overflow on read */
295-
ec_debugfs_resp_bytes = 0;
296-
297-
printk(KERN_DEBUG "olpc-ec: bad ec cmd: "
298-
"cmd:response-count [arg1 [arg2 ...]]\n");
299-
size = -EINVAL;
300-
goto out;
301-
}
302-
303-
/* convert scanf'd ints to char */
304-
ec_cmd_bytes = m - 2;
305-
for (i = 0; i <= ec_cmd_bytes; i++)
306-
ec_cmd[i] = ec_cmd_int[i];
307-
308-
printk(KERN_DEBUG "olpc-ec: debugfs cmd 0x%02x with %d args "
309-
"%02x %02x %02x %02x %02x, want %d returns\n",
310-
ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], ec_cmd[3],
311-
ec_cmd[4], ec_cmd[5], ec_debugfs_resp_bytes);
312-
313-
olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1],
314-
ec_cmd_bytes, ec_debugfs_resp, ec_debugfs_resp_bytes);
315-
316-
printk(KERN_DEBUG "olpc-ec: response "
317-
"%02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n",
318-
ec_debugfs_resp[0], ec_debugfs_resp[1], ec_debugfs_resp[2],
319-
ec_debugfs_resp[3], ec_debugfs_resp[4], ec_debugfs_resp[5],
320-
ec_debugfs_resp[6], ec_debugfs_resp[7], ec_debugfs_resp_bytes);
321-
322-
out:
323-
mutex_unlock(&ec_debugfs_cmd_lock);
324-
return size;
325-
}
326-
327-
static ssize_t ec_debugfs_cmd_read(struct file *file, char __user *buf,
328-
size_t size, loff_t *ppos)
329-
{
330-
unsigned int i, r;
331-
char *rp;
332-
char respbuf[64];
333-
334-
mutex_lock(&ec_debugfs_cmd_lock);
335-
rp = respbuf;
336-
rp += sprintf(rp, "%02x", ec_debugfs_resp[0]);
337-
for (i = 1; i < ec_debugfs_resp_bytes; i++)
338-
rp += sprintf(rp, ", %02x", ec_debugfs_resp[i]);
339-
mutex_unlock(&ec_debugfs_cmd_lock);
340-
rp += sprintf(rp, "\n");
341-
342-
r = rp - respbuf;
343-
return simple_read_from_buffer(buf, size, ppos, respbuf, r);
344-
}
345-
346-
static const struct file_operations ec_debugfs_genops = {
347-
.write = ec_debugfs_cmd_write,
348-
.read = ec_debugfs_cmd_read,
349-
};
350-
351-
static void setup_debugfs(void)
352-
{
353-
ec_debugfs_dir = debugfs_create_dir("olpc-ec", 0);
354-
if (ec_debugfs_dir == ERR_PTR(-ENODEV))
355-
return;
356-
357-
debugfs_create_file("cmd", 0600, ec_debugfs_dir, NULL,
358-
&ec_debugfs_genops);
359-
}
360-
361266
static int olpc_ec_suspend(struct platform_device *pdev)
362267
{
363268
return olpc_ec_mask_write(ec_wakeup_mask);
@@ -470,8 +375,6 @@ static int __init olpc_init(void)
470375
return r;
471376
}
472377

473-
setup_debugfs();
474-
475378
return 0;
476379
}
477380

drivers/platform/olpc/olpc-ec.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Licensed under the GPL v2 or later.
77
*/
88
#include <linux/completion.h>
9+
#include <linux/debugfs.h>
910
#include <linux/spinlock.h>
1011
#include <linux/mutex.h>
1112
#include <linux/platform_device.h>
@@ -31,6 +32,8 @@ struct ec_cmd_desc {
3132
struct olpc_ec_priv {
3233
struct olpc_ec_driver *drv;
3334

35+
struct dentry *dbgfs_dir;
36+
3437
/*
3538
* Running an EC command while suspending means we don't always finish
3639
* the command before the machine suspends. This means that the EC
@@ -144,6 +147,114 @@ int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen)
144147
}
145148
EXPORT_SYMBOL_GPL(olpc_ec_cmd);
146149

150+
#ifdef CONFIG_DEBUG_FS
151+
152+
/*
153+
* debugfs support for "generic commands", to allow sending
154+
* arbitrary EC commands from userspace.
155+
*/
156+
157+
#define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */
158+
#define EC_MAX_CMD_REPLY (8)
159+
160+
static DEFINE_MUTEX(ec_dbgfs_lock);
161+
static unsigned char ec_dbgfs_resp[EC_MAX_CMD_REPLY];
162+
static unsigned int ec_dbgfs_resp_bytes;
163+
164+
static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf,
165+
size_t size, loff_t *ppos)
166+
{
167+
int i, m;
168+
unsigned char ec_cmd[EC_MAX_CMD_ARGS];
169+
unsigned int ec_cmd_int[EC_MAX_CMD_ARGS];
170+
char cmdbuf[64];
171+
int ec_cmd_bytes;
172+
173+
mutex_lock(&ec_dbgfs_lock);
174+
175+
size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size);
176+
177+
m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0],
178+
&ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2],
179+
&ec_cmd_int[3], &ec_cmd_int[4], &ec_cmd_int[5]);
180+
if (m < 2 || ec_dbgfs_resp_bytes > EC_MAX_CMD_REPLY) {
181+
/* reset to prevent overflow on read */
182+
ec_dbgfs_resp_bytes = 0;
183+
184+
pr_debug("olpc-ec: bad ec cmd: cmd:response-count [arg1 [arg2 ...]]\n");
185+
size = -EINVAL;
186+
goto out;
187+
}
188+
189+
/* convert scanf'd ints to char */
190+
ec_cmd_bytes = m - 2;
191+
for (i = 0; i <= ec_cmd_bytes; i++)
192+
ec_cmd[i] = ec_cmd_int[i];
193+
194+
pr_debug("olpc-ec: debugfs cmd 0x%02x with %d args %02x %02x %02x %02x %02x, want %d returns\n",
195+
ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2],
196+
ec_cmd[3], ec_cmd[4], ec_cmd[5], ec_dbgfs_resp_bytes);
197+
198+
olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1],
199+
ec_cmd_bytes, ec_dbgfs_resp, ec_dbgfs_resp_bytes);
200+
201+
pr_debug("olpc-ec: response %02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n",
202+
ec_dbgfs_resp[0], ec_dbgfs_resp[1], ec_dbgfs_resp[2],
203+
ec_dbgfs_resp[3], ec_dbgfs_resp[4], ec_dbgfs_resp[5],
204+
ec_dbgfs_resp[6], ec_dbgfs_resp[7],
205+
ec_dbgfs_resp_bytes);
206+
207+
out:
208+
mutex_unlock(&ec_dbgfs_lock);
209+
return size;
210+
}
211+
212+
static ssize_t ec_dbgfs_cmd_read(struct file *file, char __user *buf,
213+
size_t size, loff_t *ppos)
214+
{
215+
unsigned int i, r;
216+
char *rp;
217+
char respbuf[64];
218+
219+
mutex_lock(&ec_dbgfs_lock);
220+
rp = respbuf;
221+
rp += sprintf(rp, "%02x", ec_dbgfs_resp[0]);
222+
for (i = 1; i < ec_dbgfs_resp_bytes; i++)
223+
rp += sprintf(rp, ", %02x", ec_dbgfs_resp[i]);
224+
mutex_unlock(&ec_dbgfs_lock);
225+
rp += sprintf(rp, "\n");
226+
227+
r = rp - respbuf;
228+
return simple_read_from_buffer(buf, size, ppos, respbuf, r);
229+
}
230+
231+
static const struct file_operations ec_dbgfs_ops = {
232+
.write = ec_dbgfs_cmd_write,
233+
.read = ec_dbgfs_cmd_read,
234+
};
235+
236+
static struct dentry *olpc_ec_setup_debugfs(void)
237+
{
238+
struct dentry *dbgfs_dir;
239+
240+
dbgfs_dir = debugfs_create_dir("olpc-ec", NULL);
241+
if (IS_ERR_OR_NULL(dbgfs_dir))
242+
return NULL;
243+
244+
debugfs_create_file("cmd", 0600, dbgfs_dir, NULL, &ec_dbgfs_ops);
245+
246+
return dbgfs_dir;
247+
}
248+
249+
#else
250+
251+
static struct dentry *olpc_ec_setup_debugfs(void)
252+
{
253+
return NULL;
254+
}
255+
256+
#endif /* CONFIG_DEBUG_FS */
257+
147258
static int olpc_ec_probe(struct platform_device *pdev)
148259
{
149260
struct olpc_ec_priv *ec;
@@ -160,6 +271,12 @@ static int olpc_ec_probe(struct platform_device *pdev)
160271
platform_set_drvdata(pdev, ec);
161272

162273
err = ec_driver->probe ? ec_driver->probe(pdev) : 0;
274+
if (err) {
275+
ec_priv = NULL;
276+
kfree(ec);
277+
} else {
278+
ec->dbgfs_dir = olpc_ec_setup_debugfs();
279+
}
163280

164281
return err;
165282
}

0 commit comments

Comments
 (0)