Skip to contentSkip to conversation

Set cros_ec_keyb as a wakeup source

PATCH New Jeffy Chen 3 participants 7 messages Apr 2, 2017 – Jun 21, 2017

Subsystems (2)
lore
Share & tools
lore

Jeffy Chen

author
#0 lore raw

v2 cover Set cros_ec_keyb as a wakeup source

This patches set cros_ec_keyb as a wakeup source, so the chromeos's powerd can control the keyboard's wakeup ability along with other ec event sources.

Changes in v2:
Remove unneeded dts changes.

Jeffy Chen (1):
input: cros_ec_keyb: Report wakeup events

 drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/1 input: cros_ec_keyb: Report wakeup events

Report wakeup events when process events.

---

Changes in v2:
Remove unneeded dts changes.

 drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/input/keyboard/cros_ec_keyb.c +9 -0
index 6a250d6..a93d55f 100644
@@ -286,6 +286,9 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
 		return NOTIFY_DONE;
 	}
 
+	if (device_may_wakeup(ckdev->dev))
+		pm_wakeup_event(ckdev->dev, 0);
+
 	return NOTIFY_OK;
 }
 
@@ -632,6 +635,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
 		return err;
 	}
 
+	err = device_init_wakeup(dev, 1);
+	if (err) {
+		dev_err(dev, "cannot init wakeup: %d\n", err);
+		return err;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.1.4
maintainer
#2 lore raw

Re: [PATCH v2] input: cros_ec_keyb: Report wakeup events

Quoted 26 lines · Jeffy Chen

Report wakeup events when process events.

---

Changes in v2:
Remove unneeded dts changes.

 drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/input/keyboard/cros_ec_keyb.c +3 -0
index 6a250d6..a93d55f 100644
@@ -286,6 +286,9 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
 		return NOTIFY_DONE;
 	}
 
+	if (device_may_wakeup(ckdev->dev))
+		pm_wakeup_event(ckdev->dev, 0);
+
 	return NOTIFY_OK;
 }
 

drivers/input/keyboard/cros_ec_keyb.c static int cros_ec_keyb_probe(struct platform_device *pdev) · line 638

Quoted 4 lines
drivers/input/keyboard/cros_ec_keyb.c +1 -0
@@ -632,6 +635,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
 		return err;
 	}
 
+	err = device_init_wakeup(dev, 1);

I would prefer if we did not mark cros_ec devices as wakeup sources unconditionally. Your original patch series was better (except it failed to parse the "wakeup-source" property that you introduced.

Quoted 12 lines
drivers/input/keyboard/cros_ec_keyb.c +5 -0
+	if (err) {
+		dev_err(dev, "cannot init wakeup: %d\n", err);
+		return err;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.1.4

Thanks.

Signature · 1 line
Dmitry
#3 lore raw

Re: [PATCH v2] input: cros_ec_keyb: Report wakeup events

+ others

Quoted 30 lines · Dmitry Torokhov
Quoted 29 lines · Jeffy Chen

Report wakeup events when process events.

---

Changes in v2:
Remove unneeded dts changes.

 drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/input/keyboard/cros_ec_keyb.c +3 -0
index 6a250d6..a93d55f 100644
@@ -286,6 +286,9 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
 		return NOTIFY_DONE;
 	}
 
+	if (device_may_wakeup(ckdev->dev))
+		pm_wakeup_event(ckdev->dev, 0);
+
 	return NOTIFY_OK;
 }
 
@@ -632,6 +635,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
 		return err;
 	}
 
Quoted 5 lines

drivers/input/keyboard/cros_ec_keyb.c static int cros_ec_keyb_probe(struct platform_device *pdev) · line 638

Quoted 1 line
drivers/input/keyboard/cros_ec_keyb.c +1 -0
+	err = device_init_wakeup(dev, 1);

I would prefer if we did not mark cros_ec devices as wakeup sources unconditionally. Your original patch series was better (except it failed to parse the "wakeup-source" property that you introduced.

I'm curious, why is this keyboard device different than any other keyboard device? I see several other drivers in drivers/input/keyboard/ that do an unconditional 'device_init_wakeup(..., 1)'. Keyboards tend to be wakeup devices...

Also, what's the idea behind sub-devices vs. the main cros-ec device reporting wakeups? Right now, we have this in drivers/mfd/cros_ec.c:

static irqreturn_t ec_irq_thread(int irq, void *data)

{
        struct cros_ec_device *ec_dev = data;
        int ret;

        if (device_may_wakeup(ec_dev->dev))
                pm_wakeup_event(ec_dev->dev, 0);

        ret = cros_ec_get_next_event(ec_dev);
        if (ret > 0)
                blocking_notifier_call_chain(&ec_dev->event_notifier,
                                             0, ec_dev);
        return IRQ_HANDLED;
}

But now, we're going to start double-reporting wakeups? Is that expected?

I think we have a similar overlap with the RTC driver (which is being upstreamed now?):

https://lkml.org/lkml/2017/2/14/658
[PATCH v3 3/4] rtc: cros-ec: add cros-ec-rtc driver.

except that also goes through the trouble of enabling/disabling wakeup for the EC IRQ. It seems to me (though I haven't dug in thoroughly) like the main MFD shouldn't really be doing the wakeup reporting at all, and we should depend on the sub-devices to do this. (i.e., the current patchset is a step in the right direction, but it's not 100%.)

Anyway, I could be wrong about the above, but I think we should make sure there's a consistent answer across the drivers tree.

Regards,
Brian

Quoted 17 lines
Quoted 12 lines
drivers/input/keyboard/cros_ec_keyb.c +5 -0
+	if (err) {
+		dev_err(dev, "cannot init wakeup: %d\n", err);
+		return err;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.1.4

Thanks.

Signature · 1 line
Dmitry
maintainer
#4 lore raw

Re: [PATCH v2] input: cros_ec_keyb: Report wakeup events

Quoted 39 lines · Brian Norris

+ others

Quoted 30 lines · Dmitry Torokhov
Quoted 29 lines · Jeffy Chen

Report wakeup events when process events.

---

Changes in v2:
Remove unneeded dts changes.

 drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/input/keyboard/cros_ec_keyb.c +3 -0
index 6a250d6..a93d55f 100644
@@ -286,6 +286,9 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
 		return NOTIFY_DONE;
 	}
 
+	if (device_may_wakeup(ckdev->dev))
+		pm_wakeup_event(ckdev->dev, 0);
+
 	return NOTIFY_OK;
 }
 
@@ -632,6 +635,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
 		return err;
 	}
 
Quoted 5 lines

drivers/input/keyboard/cros_ec_keyb.c static int cros_ec_keyb_probe(struct platform_device *pdev) · line 638

Quoted 1 line
drivers/input/keyboard/cros_ec_keyb.c +1 -0
+	err = device_init_wakeup(dev, 1);

I would prefer if we did not mark cros_ec devices as wakeup sources unconditionally. Your original patch series was better (except it failed to parse the "wakeup-source" property that you introduced.

Quoted 4 lines

I'm curious, why is this keyboard device different than any other keyboard device? I see several other drivers in drivers/input/keyboard/ that do an unconditional 'device_init_wakeup(..., 1)'. Keyboards tend to be wakeup devices...

If we did something before it does not mean we should continue doing this forever. I think providing an option to mark device as wakeup capable should be left to the platform.

Quoted 19 lines

Also, what's the idea behind sub-devices vs. the main cros-ec device reporting wakeups? Right now, we have this in drivers/mfd/cros_ec.c:

static irqreturn_t ec_irq_thread(int irq, void *data)

{
        struct cros_ec_device *ec_dev = data;
        int ret;

        if (device_may_wakeup(ec_dev->dev))
                pm_wakeup_event(ec_dev->dev, 0);

        ret = cros_ec_get_next_event(ec_dev);
        if (ret > 0)
                blocking_notifier_call_chain(&ec_dev->event_notifier,
                                             0, ec_dev);
        return IRQ_HANDLED;
}
Quoted 2 lines

But now, we're going to start double-reporting wakeups? Is that expected?

No, and not always (below).

Quoted 7 lines

I think we have a similar overlap with the RTC driver (which is being upstreamed now?):

https://lkml.org/lkml/2017/2/14/658
[PATCH v3 3/4] rtc: cros-ec: add cros-ec-rtc driver.

Quoted 8 lines

except that also goes through the trouble of enabling/disabling wakeup for the EC IRQ. It seems to me (though I haven't dug in thoroughly) like the main MFD shouldn't really be doing the wakeup reporting at all, and we should depend on the sub-devices to do this. (i.e., the current patchset is a step in the right direction, but it's not 100%.)

Anyway, I could be wrong about the above, but I think we should make sure there's a consistent answer across the drivers tree.

Hm, it appears we have quite a mess. SPI-based EC declares entire EC as wakeup source (unconditionally I must add; we do mention "wakeup-source" in binding document at least). I2C-based EC does not call device_init_wakeup() at all, presumably that is what caused the calls to be added into sub-drivers.

We need to resolve this one way or another. You probably do not want to wake up any time you move your device (accelerometer or other sensors), so I would try to move this property into individual devices, and try to come up with a reasonable binding.

Thanks.

Signature · 1 line
Dmitry
author
#5 lore raw

Re: [PATCH v2] input: cros_ec_keyb: Report wakeup events

Hi dmitry,

Quoted 95 lines · Dmitry Torokhov
Quoted 39 lines · Brian Norris

+ others

Quoted 30 lines · Dmitry Torokhov
Quoted 29 lines · Jeffy Chen

Report wakeup events when process events.

---

Changes in v2:
Remove unneeded dts changes.

  drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/input/keyboard/cros_ec_keyb.c +3 -0
index 6a250d6..a93d55f 100644
@@ -286,6 +286,9 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
  		return NOTIFY_DONE;
  	}
 
+	if (device_may_wakeup(ckdev->dev))
+		pm_wakeup_event(ckdev->dev, 0);
+
  	return NOTIFY_OK;
  }
 
@@ -632,6 +635,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
  		return err;
  	}
 
Quoted 5 lines

drivers/input/keyboard/cros_ec_keyb.c static int cros_ec_keyb_probe(struct platform_device *pdev) · line 638

Quoted 1 line
drivers/input/keyboard/cros_ec_keyb.c +1 -0
+	err = device_init_wakeup(dev, 1);

I would prefer if we did not mark cros_ec devices as wakeup sources unconditionally. Your original patch series was better (except it failed to parse the "wakeup-source" property that you introduced.

Quoted 4 lines

I'm curious, why is this keyboard device different than any other keyboard device? I see several other drivers in drivers/input/keyboard/ that do an unconditional 'device_init_wakeup(..., 1)'. Keyboards tend to be wakeup devices...

If we did something before it does not mean we should continue doing this forever. I think providing an option to mark device as wakeup capable should be left to the platform.

Quoted 19 lines

Also, what's the idea behind sub-devices vs. the main cros-ec device reporting wakeups? Right now, we have this in drivers/mfd/cros_ec.c:

static irqreturn_t ec_irq_thread(int irq, void *data)

{
         struct cros_ec_device *ec_dev = data;
         int ret;

         if (device_may_wakeup(ec_dev->dev))
                 pm_wakeup_event(ec_dev->dev, 0);

         ret = cros_ec_get_next_event(ec_dev);
         if (ret > 0)
                 blocking_notifier_call_chain(&ec_dev->event_notifier,
                                              0, ec_dev);
         return IRQ_HANDLED;
}
Quoted 2 lines

But now, we're going to start double-reporting wakeups? Is that expected?

No, and not always (below).

Quoted 7 lines

I think we have a similar overlap with the RTC driver (which is being upstreamed now?):

https://lkml.org/lkml/2017/2/14/658
[PATCH v3 3/4] rtc: cros-ec: add cros-ec-rtc driver.

Quoted 8 lines

except that also goes through the trouble of enabling/disabling wakeup for the EC IRQ. It seems to me (though I haven't dug in thoroughly) like the main MFD shouldn't really be doing the wakeup reporting at all, and we should depend on the sub-devices to do this. (i.e., the current patchset is a step in the right direction, but it's not 100%.)

Anyway, I could be wrong about the above, but I think we should make sure there's a consistent answer across the drivers tree.

Hm, it appears we have quite a mess. SPI-based EC declares entire EC as wakeup source (unconditionally I must add; we do mention "wakeup-source" in binding document at least). I2C-based EC does not call device_init_wakeup() at all, presumably that is what caused the calls to be added into sub-drivers.

Quoted 4 lines

We need to resolve this one way or another. You probably do not want to wake up any time you move your device (accelerometer or other sensors), so I would try to move this property into individual devices, and try to come up with a reasonable binding.

right, we do have a issue about gyro sensor break suspend(https://partnerissuetracker.corp.google.com/issues/36705709)

it would be better if we move wakeup codes to sub drivers. and if you do this, it would also solve the original issue of this patchset ;)

Quoted 3 lines

Thanks.

author
#6 lore raw

Re: [PATCH v2] input: cros_ec_keyb: Report wakeup events

Hi guys,

Quoted 57 lines · jeffy

Hi dmitry,

Quoted 54 lines · Dmitry Torokhov
Quoted 43 lines · Brian Norris

+ others

Quoted 33 lines · Dmitry Torokhov
Quoted 32 lines · Jeffy Chen

Report wakeup events when process events.

---

Changes in v2:
Remove unneeded dts changes.

  drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/input/keyboard/cros_ec_keyb.c +3 -0
index 6a250d6..a93d55f 100644
@@ -286,6 +286,9 @@ static int cros_ec_keyb_work(struct
 notifier_block *nb,
          return NOTIFY_DONE;
      }
 
+    if (device_may_wakeup(ckdev->dev))
+        pm_wakeup_event(ckdev->dev, 0);
+
      return NOTIFY_OK;
  }
@@ -632,6 +635,12 @@ static int cros_ec_keyb_probe(struct
 platform_device *pdev)
          return err;
      }
 
Quoted 6 lines

drivers/input/keyboard/cros_ec_keyb.c static int cros_ec_keyb_probe(struct platform_device *pdev) · line 638

Quoted 1 line
drivers/input/keyboard/cros_ec_keyb.c +1 -0
+    err = device_init_wakeup(dev, 1);

I would prefer if we did not mark cros_ec devices as wakeup sources unconditionally. Your original patch series was better (except it failed
to parse the "wakeup-source" property that you introduced.

Quoted 6 lines

I'm curious, why is this keyboard device different than any other keyboard
device? I see several other drivers in drivers/input/keyboard/ that do an
unconditional 'device_init_wakeup(..., 1)'. Keyboards tend to be wakeup devices...

If we did something before it does not mean we should continue doing this forever. I think providing an option to mark device as wakeup capable should be left to the platform.

right, so i'll add this:
+ device_init_wakeup(dev,
+ device_property_read_bool(dev, "wakeup-source"));

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

Also, what's the idea behind sub-devices vs. the main cros-ec device reporting
wakeups? Right now, we have this in drivers/mfd/cros_ec.c:

static irqreturn_t ec_irq_thread(int irq, void *data)

{
         struct cros_ec_device *ec_dev = data;
         int ret;

         if (device_may_wakeup(ec_dev->dev))
                 pm_wakeup_event(ec_dev->dev, 0);

         ret = cros_ec_get_next_event(ec_dev);
         if (ret > 0)
                 blocking_notifier_call_chain(&ec_dev->event_notifier,
                                              0, ec_dev);
         return IRQ_HANDLED;
}
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

But now, we're going to start double-reporting wakeups? Is that expected?

the double-reporting wakeup could be harmless, but i saw we added a wake mask in our 4.4 kernel(for non-wake events):

        if (device_may_wakeup(ec_dev->dev) && wake_event)
                pm_wakeup_event(ec_dev->dev, 0);

maybe we can do something similar to filter out wakeup events already handled by sub devices?

Quoted 17 lines
Quoted 17 lines

No, and not always (below).

Quoted 14 lines

I think we have a similar overlap with the RTC driver (which is being upstreamed now?):

https://lkml.org/lkml/2017/2/14/658
[PATCH v3 3/4] rtc: cros-ec: add cros-ec-rtc driver.

except that also goes through the trouble of enabling/disabling wakeup for the
EC IRQ. It seems to me (though I haven't dug in thoroughly) like the main MFD shouldn't really be doing the wakeup reporting at all, and we should depend on the sub-devices to do this. (i.e., the current patchset is a step in the right direction, but it's not 100%.)

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Anyway, I could be wrong about the above, but I think we should make sure there's a consistent answer across the drivers tree.

Hm, it appears we have quite a mess. SPI-based EC declares entire EC as wakeup source (unconditionally I must add; we do mention "wakeup-source" in binding document at least). I2C-based EC does not call device_init_wakeup() at all, presumably that is what caused the calls to be added into sub-drivers.

hmmm, it looks like the i2c-based ec also do this, but through i2c-core:

if (of_get_property(node, "wakeup-source", NULL))
info.flags |= I2C_CLIENT_WAKE;
...

        if (client->flags & I2C_CLIENT_WAKE) {
                device_init_wakeup(&client->dev, true);

exynos5250-spring.dts:

        cros_ec: embedded-controller@1e {
                compatible = "google,cros-ec-i2c";
...
                wakeup-source;

and the binding document said we need to add wakeup-source for cros ec spi:
Documentation/devicetree/bindings/mfd/cros-ec.txt

spi@131b0000 {
        ec@0 {
                compatible = "google,cros-ec-spi";
                reg = <0x0>;
                interrupts = <14 0>;
                interrupt-parent = <&wakeup_eint>;
                wakeup-source;

so do we need to add wakeup-source property support in cros_ec_spi? or maybe even in spi core(like i2c core)?

Quoted 5 lines
Quoted 5 lines

We need to resolve this one way or another. You probably do not want to wake up any time you move your device (accelerometer or other sensors), so I would try to move this property into individual devices, and try to come up with a reasonable binding.

we have this https://chromium-review.googlesource.com/c/372399/ in cros 4.4 kernel, but somehow not upstream.

but it would still be good to move wakeup to sub devices.

Quoted 9 lines

right, we do have a issue about gyro sensor break suspend(https://partnerissuetracker.corp.google.com/issues/36705709)

it would be better if we move wakeup codes to sub drivers. and if you do this, it would also solve the original issue of this patchset ;)

Quoted 3 lines

Thanks.

so i'll try to add wakeup-source property for spi core and cros-ec-keyboard as a first step