]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/mfd/cros_ec.c
Merge tag 'backlight-for-linus-3.17' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / drivers / mfd / cros_ec.c
index 2e86c282f0b4f088e29f149e5358a570d5ccfc1f..4873f9c504526503eaef81ba97dfd640e65e3386 100644 (file)
@@ -44,45 +44,23 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
 }
 EXPORT_SYMBOL(cros_ec_prepare_tx);
 
-static int cros_ec_command_sendrecv(struct cros_ec_device *ec_dev,
-               uint16_t cmd, void *out_buf, int out_len,
-               void *in_buf, int in_len)
+int cros_ec_check_result(struct cros_ec_device *ec_dev,
+                        struct cros_ec_command *msg)
 {
-       struct cros_ec_command msg;
-
-       msg.version = cmd >> 8;
-       msg.command = cmd & 0xff;
-       msg.outdata = out_buf;
-       msg.outsize = out_len;
-       msg.indata = in_buf;
-       msg.insize = in_len;
-
-       return ec_dev->cmd_xfer(ec_dev, &msg);
-}
-
-static int cros_ec_command_recv(struct cros_ec_device *ec_dev,
-               uint16_t cmd, void *buf, int buf_len)
-{
-       return cros_ec_command_sendrecv(ec_dev, cmd, NULL, 0, buf, buf_len);
-}
-
-static int cros_ec_command_send(struct cros_ec_device *ec_dev,
-               uint16_t cmd, void *buf, int buf_len)
-{
-       return cros_ec_command_sendrecv(ec_dev, cmd, buf, buf_len, NULL, 0);
-}
-
-static irqreturn_t ec_irq_thread(int irq, void *data)
-{
-       struct cros_ec_device *ec_dev = data;
-
-       if (device_may_wakeup(ec_dev->dev))
-               pm_wakeup_event(ec_dev->dev, 0);
-
-       blocking_notifier_call_chain(&ec_dev->event_notifier, 1, ec_dev);
-
-       return IRQ_HANDLED;
+       switch (msg->result) {
+       case EC_RES_SUCCESS:
+               return 0;
+       case EC_RES_IN_PROGRESS:
+               dev_dbg(ec_dev->dev, "command 0x%02x in progress\n",
+                       msg->command);
+               return -EAGAIN;
+       default:
+               dev_dbg(ec_dev->dev, "command 0x%02x returned %d\n",
+                       msg->command, msg->result);
+               return 0;
+       }
 }
+EXPORT_SYMBOL(cros_ec_check_result);
 
 static const struct mfd_cell cros_devs[] = {
        {
@@ -102,12 +80,6 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
        struct device *dev = ec_dev->dev;
        int err = 0;
 
-       BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->event_notifier);
-
-       ec_dev->command_send = cros_ec_command_send;
-       ec_dev->command_recv = cros_ec_command_recv;
-       ec_dev->command_sendrecv = cros_ec_command_sendrecv;
-
        if (ec_dev->din_size) {
                ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL);
                if (!ec_dev->din)
@@ -119,42 +91,23 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
                        return -ENOMEM;
        }
 
-       if (!ec_dev->irq) {
-               dev_dbg(dev, "no valid IRQ: %d\n", ec_dev->irq);
-               return err;
-       }
-
-       err = request_threaded_irq(ec_dev->irq, NULL, ec_irq_thread,
-                                  IRQF_TRIGGER_LOW | IRQF_ONESHOT,
-                                  "chromeos-ec", ec_dev);
-       if (err) {
-               dev_err(dev, "request irq %d: error %d\n", ec_dev->irq, err);
-               return err;
-       }
-
        err = mfd_add_devices(dev, 0, cros_devs,
                              ARRAY_SIZE(cros_devs),
                              NULL, ec_dev->irq, NULL);
        if (err) {
                dev_err(dev, "failed to add mfd devices\n");
-               goto fail_mfd;
+               return err;
        }
 
-       dev_info(dev, "Chrome EC (%s)\n", ec_dev->name);
+       dev_info(dev, "Chrome EC device registered\n");
 
        return 0;
-
-fail_mfd:
-       free_irq(ec_dev->irq, ec_dev);
-
-       return err;
 }
 EXPORT_SYMBOL(cros_ec_register);
 
 int cros_ec_remove(struct cros_ec_device *ec_dev)
 {
        mfd_remove_devices(ec_dev->dev);
-       free_irq(ec_dev->irq, ec_dev);
 
        return 0;
 }