^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Generic driver for the OLPC Embedded Controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Andres Salomon <dilinger@queued.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2011-2012 One Laptop per Child Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/olpc-ec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct ec_cmd_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u8 *inbuf, *outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) size_t inlen, outlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct completion finished;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct olpc_ec_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct olpc_ec_driver *drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u8 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct work_struct worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct mutex cmd_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* DCON regulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct regulator_dev *dcon_rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) bool dcon_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* Pending EC commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct list_head cmd_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) spinlock_t cmd_q_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct dentry *dbgfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * EC event mask to be applied during suspend (defining wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * sources).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u16 ec_wakeup_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Running an EC command while suspending means we don't always finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * the command before the machine suspends. This means that the EC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * is expecting the command protocol to finish, but we after a period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * of time (while the OS is asleep) the EC times out and restarts its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * idle loop. Meanwhile, the OS wakes up, thinks it's still in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * middle of the command protocol, starts throwing random things at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * the EC... and everyone's uphappy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) bool suspended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct olpc_ec_driver *ec_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static struct olpc_ec_priv *ec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static void *ec_cb_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) void olpc_ec_driver_register(struct olpc_ec_driver *drv, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ec_driver = drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ec_cb_arg = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) EXPORT_SYMBOL_GPL(olpc_ec_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static void olpc_ec_worker(struct work_struct *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct olpc_ec_priv *ec = container_of(w, struct olpc_ec_priv, worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct ec_cmd_desc *desc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Grab the first pending command from the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_lock_irqsave(&ec->cmd_q_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!list_empty(&ec->cmd_q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) desc = list_first_entry(&ec->cmd_q, struct ec_cmd_desc, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) list_del(&desc->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) spin_unlock_irqrestore(&ec->cmd_q_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Do we actually have anything to do? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Protect the EC hw with a mutex; only run one cmd at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) mutex_lock(&ec->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) desc->err = ec_driver->ec_cmd(desc->cmd, desc->inbuf, desc->inlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) desc->outbuf, desc->outlen, ec_cb_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) mutex_unlock(&ec->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* Finished, wake up olpc_ec_cmd() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) complete(&desc->finished);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Run the worker thread again in case there are more cmds pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) schedule_work(&ec->worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Throw a cmd descripter onto the list. We now have SMP OLPC machines, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * locking is pretty critical.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void queue_ec_descriptor(struct ec_cmd_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct olpc_ec_priv *ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) INIT_LIST_HEAD(&desc->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) spin_lock_irqsave(&ec->cmd_q_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) list_add_tail(&desc->node, &ec->cmd_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) spin_unlock_irqrestore(&ec->cmd_q_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) schedule_work(&ec->worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int olpc_ec_cmd(u8 cmd, u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct olpc_ec_priv *ec = ec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct ec_cmd_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* Driver not yet registered. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!ec_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (WARN_ON(!ec_driver->ec_cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* Suspending in the middle of a command hoses things really badly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (WARN_ON(ec->suspended))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) desc.cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) desc.inbuf = inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) desc.outbuf = outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) desc.inlen = inlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) desc.outlen = outlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) desc.err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) init_completion(&desc.finished);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) queue_ec_descriptor(&desc, ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* Timeouts must be handled in the platform-specific EC hook */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) wait_for_completion(&desc.finished);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* The worker thread dequeues the cmd; no need to do anything here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return desc.err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) EXPORT_SYMBOL_GPL(olpc_ec_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) void olpc_ec_wakeup_set(u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct olpc_ec_priv *ec = ec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (WARN_ON(!ec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ec->ec_wakeup_mask |= value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) EXPORT_SYMBOL_GPL(olpc_ec_wakeup_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) void olpc_ec_wakeup_clear(u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct olpc_ec_priv *ec = ec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (WARN_ON(!ec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ec->ec_wakeup_mask &= ~value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL_GPL(olpc_ec_wakeup_clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int olpc_ec_mask_write(u16 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct olpc_ec_priv *ec = ec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (WARN_ON(!ec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* EC version 0x5f adds support for wide SCI mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ec->version >= 0x5f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) __be16 ec_word = cpu_to_be16(bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return olpc_ec_cmd(EC_WRITE_EXT_SCI_MASK, (void *)&ec_word, 2, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) u8 ec_byte = bits & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return olpc_ec_cmd(EC_WRITE_SCI_MASK, &ec_byte, 1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) EXPORT_SYMBOL_GPL(olpc_ec_mask_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Returns true if the compile and runtime configurations allow for EC events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * to wake the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) bool olpc_ec_wakeup_available(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (WARN_ON(!ec_driver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return ec_driver->wakeup_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) EXPORT_SYMBOL_GPL(olpc_ec_wakeup_available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int olpc_ec_sci_query(u16 *sci_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct olpc_ec_priv *ec = ec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (WARN_ON(!ec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* EC version 0x5f adds support for wide SCI mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (ec->version >= 0x5f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) __be16 ec_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ret = olpc_ec_cmd(EC_EXT_SCI_QUERY, NULL, 0, (void *)&ec_word, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *sci_value = be16_to_cpu(ec_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) u8 ec_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ret = olpc_ec_cmd(EC_SCI_QUERY, NULL, 0, &ec_byte, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *sci_value = ec_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) EXPORT_SYMBOL_GPL(olpc_ec_sci_query);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * debugfs support for "generic commands", to allow sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * arbitrary EC commands from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #define EC_MAX_CMD_ARGS (5 + 1) /* cmd byte + 5 args */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define EC_MAX_CMD_REPLY (8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static DEFINE_MUTEX(ec_dbgfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static unsigned char ec_dbgfs_resp[EC_MAX_CMD_REPLY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static unsigned int ec_dbgfs_resp_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) size_t size, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int i, m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) unsigned char ec_cmd[EC_MAX_CMD_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) unsigned int ec_cmd_int[EC_MAX_CMD_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) char cmdbuf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int ec_cmd_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mutex_lock(&ec_dbgfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) &ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) &ec_cmd_int[3], &ec_cmd_int[4], &ec_cmd_int[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (m < 2 || ec_dbgfs_resp_bytes > EC_MAX_CMD_REPLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* reset to prevent overflow on read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ec_dbgfs_resp_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) pr_debug("olpc-ec: bad ec cmd: cmd:response-count [arg1 [arg2 ...]]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) size = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* convert scanf'd ints to char */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ec_cmd_bytes = m - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) for (i = 0; i <= ec_cmd_bytes; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ec_cmd[i] = ec_cmd_int[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) pr_debug("olpc-ec: debugfs cmd 0x%02x with %d args %5ph, want %d returns\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ec_cmd[0], ec_cmd_bytes, ec_cmd + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ec_dbgfs_resp_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ec_cmd_bytes, ec_dbgfs_resp, ec_dbgfs_resp_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) pr_debug("olpc-ec: response %8ph (%d bytes expected)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ec_dbgfs_resp, ec_dbgfs_resp_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) mutex_unlock(&ec_dbgfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static ssize_t ec_dbgfs_cmd_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) size_t size, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) unsigned int i, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) char *rp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) char respbuf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) mutex_lock(&ec_dbgfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) rp = respbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) rp += sprintf(rp, "%02x", ec_dbgfs_resp[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) for (i = 1; i < ec_dbgfs_resp_bytes; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) rp += sprintf(rp, ", %02x", ec_dbgfs_resp[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) mutex_unlock(&ec_dbgfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) rp += sprintf(rp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) r = rp - respbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return simple_read_from_buffer(buf, size, ppos, respbuf, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static const struct file_operations ec_dbgfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .write = ec_dbgfs_cmd_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .read = ec_dbgfs_cmd_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static struct dentry *olpc_ec_setup_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct dentry *dbgfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dbgfs_dir = debugfs_create_dir("olpc-ec", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (IS_ERR_OR_NULL(dbgfs_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) debugfs_create_file("cmd", 0600, dbgfs_dir, NULL, &ec_dbgfs_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return dbgfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static struct dentry *olpc_ec_setup_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #endif /* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static int olpc_ec_set_dcon_power(struct olpc_ec_priv *ec, bool state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) unsigned char ec_byte = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (ec->dcon_enabled == state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ret = olpc_ec_cmd(EC_DCON_POWER_MODE, &ec_byte, 1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ec->dcon_enabled = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static int dcon_regulator_enable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return olpc_ec_set_dcon_power(ec, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static int dcon_regulator_disable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return olpc_ec_set_dcon_power(ec, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static int dcon_regulator_is_enabled(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct olpc_ec_priv *ec = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return ec->dcon_enabled ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static struct regulator_ops dcon_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .enable = dcon_regulator_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .disable = dcon_regulator_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .is_enabled = dcon_regulator_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static const struct regulator_desc dcon_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .name = "dcon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .id = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .ops = &dcon_regulator_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int olpc_ec_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct olpc_ec_priv *ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (!ec_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ec = kzalloc(sizeof(*ec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (!ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ec->drv = ec_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) INIT_WORK(&ec->worker, olpc_ec_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) mutex_init(&ec->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) INIT_LIST_HEAD(&ec->cmd_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) spin_lock_init(&ec->cmd_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ec_priv = ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) platform_set_drvdata(pdev, ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* get the EC revision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) err = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ec->version, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) config.dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) config.driver_data = ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) ec->dcon_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ec->dcon_rdev = devm_regulator_register(&pdev->dev, &dcon_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (IS_ERR(ec->dcon_rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) dev_err(&pdev->dev, "failed to register DCON regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) err = PTR_ERR(ec->dcon_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) ec->dbgfs_dir = olpc_ec_setup_debugfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ec_priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) kfree(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static int olpc_ec_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct olpc_ec_priv *ec = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) olpc_ec_mask_write(ec->ec_wakeup_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (ec_driver->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) err = ec_driver->suspend(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ec->suspended = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int olpc_ec_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct olpc_ec_priv *ec = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ec->suspended = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return ec_driver->resume ? ec_driver->resume(pdev) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static const struct dev_pm_ops olpc_ec_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) .suspend_late = olpc_ec_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) .resume_early = olpc_ec_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static struct platform_driver olpc_ec_plat_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) .probe = olpc_ec_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) .name = "olpc-ec",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) .pm = &olpc_ec_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static int __init olpc_ec_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return platform_driver_register(&olpc_ec_plat_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) arch_initcall(olpc_ec_init_module);