13 #include <linux/slab.h>
15 #include <linux/module.h>
16 #include <linux/list.h>
57 static void *ec_cb_arg;
74 if (!list_empty(&ec->
cmd_q)) {
78 spin_unlock_irqrestore(&ec->
cmd_q_lock, flags);
101 static void queue_ec_descriptor(
struct ec_cmd_desc *desc,
106 INIT_LIST_HEAD(&desc->
node);
110 spin_unlock_irqrestore(&ec->
cmd_q_lock, flags);
141 queue_ec_descriptor(&desc, ec);
151 #ifdef CONFIG_DEBUG_FS
158 #define EC_MAX_CMD_ARGS (5 + 1)
159 #define EC_MAX_CMD_REPLY (8)
162 static unsigned char ec_dbgfs_resp[EC_MAX_CMD_REPLY];
163 static unsigned int ec_dbgfs_resp_bytes;
166 size_t size, loff_t *ppos)
169 unsigned char ec_cmd[EC_MAX_CMD_ARGS];
170 unsigned int ec_cmd_int[EC_MAX_CMD_ARGS];
178 m =
sscanf(cmdbuf,
"%x:%u %x %x %x %x %x", &ec_cmd_int[0],
179 &ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2],
180 &ec_cmd_int[3], &ec_cmd_int[4], &ec_cmd_int[5]);
181 if (m < 2 || ec_dbgfs_resp_bytes > EC_MAX_CMD_REPLY) {
183 ec_dbgfs_resp_bytes = 0;
185 pr_debug(
"olpc-ec: bad ec cmd: cmd:response-count [arg1 [arg2 ...]]\n");
191 ec_cmd_bytes = m - 2;
192 for (i = 0; i <= ec_cmd_bytes; i++)
193 ec_cmd[i] = ec_cmd_int[i];
195 pr_debug(
"olpc-ec: debugfs cmd 0x%02x with %d args %02x %02x %02x %02x %02x, want %d returns\n",
196 ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2],
197 ec_cmd[3], ec_cmd[4], ec_cmd[5], ec_dbgfs_resp_bytes);
200 ec_cmd_bytes, ec_dbgfs_resp, ec_dbgfs_resp_bytes);
202 pr_debug(
"olpc-ec: response %02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n",
203 ec_dbgfs_resp[0], ec_dbgfs_resp[1], ec_dbgfs_resp[2],
204 ec_dbgfs_resp[3], ec_dbgfs_resp[4], ec_dbgfs_resp[5],
205 ec_dbgfs_resp[6], ec_dbgfs_resp[7],
206 ec_dbgfs_resp_bytes);
213 static ssize_t ec_dbgfs_cmd_read(
struct file *file,
char __user *buf,
214 size_t size, loff_t *ppos)
222 rp +=
sprintf(rp,
"%02x", ec_dbgfs_resp[0]);
223 for (i = 1; i < ec_dbgfs_resp_bytes; i++)
224 rp +=
sprintf(rp,
", %02x", ec_dbgfs_resp[i]);
233 .
write = ec_dbgfs_cmd_write,
234 .read = ec_dbgfs_cmd_read,
237 static struct dentry *olpc_ec_setup_debugfs(
void)
242 if (IS_ERR_OR_NULL(dbgfs_dir))
252 static struct dentry *olpc_ec_setup_debugfs(
void)
275 INIT_LIST_HEAD(&ec->
cmd_q);
279 platform_set_drvdata(pdev, ec);
281 err = ec_driver->
probe ? ec_driver->
probe(pdev) : 0;
292 static int olpc_ec_suspend(
struct device *
dev)
299 err = ec_driver->
suspend(pdev);
306 static int olpc_ec_resume(
struct device *dev)
315 static const struct dev_pm_ops olpc_ec_pm_ops = {
316 .suspend_late = olpc_ec_suspend,
317 .resume_early = olpc_ec_resume,
321 .probe = olpc_ec_probe,
324 .pm = &olpc_ec_pm_ops,
328 static int __init olpc_ec_init_module(
void)