Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 3e33b60f authored by Stephen Boyd's avatar Stephen Boyd Committed by Michael Bestas
Browse files

alarmtimer: Make alarmtimer platform device child of RTC device



[ Upstream commit c79108bd19a8490315847e0c95ac6526fcd8e770 ]

The alarmtimer_suspend() function will fail if an RTC device is on a bus
such as SPI or i2c and that RTC device registers and probes after
alarmtimer_init() registers and probes the 'alarmtimer' platform device.

This is because system wide suspend suspends devices in the reverse order
of their probe. When alarmtimer_suspend() attempts to program the RTC for a
wakeup it will try to program an RTC device on a bus that has already been
suspended.

Move the alarmtimer device registration to happen when the RTC which is
used for wakeup is registered. Register the 'alarmtimer' platform device as
a child of the RTC device too, so that it can be guaranteed that the RTC
device won't be suspended when alarmtimer_suspend() is called.

Reported-by: default avatarDouglas Anderson <dianders@chromium.org>
Signed-off-by: default avatarStephen Boyd <swboyd@chromium.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20200124055849.154411-2-swboyd@chromium.org


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Change-Id: I4338fb4708dda7a759338cac33ea975e685ea7c6
parent a8804204
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ static int alarmtimer_rtc_add_device(struct device *dev,
	unsigned long flags;
	struct rtc_device *rtc = to_rtc_device(dev);
	struct wakeup_source *__ws;
	struct platform_device *pdev;
	int ret = 0;

	if (rtcdev)
@@ -102,9 +103,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
		return -1;

	__ws = wakeup_source_register(dev, "alarmtimer");
	pdev = platform_device_register_data(dev, "alarmtimer",
					     PLATFORM_DEVID_AUTO, NULL, 0);

	spin_lock_irqsave(&rtcdev_lock, flags);
	if (!rtcdev) {
	if (__ws && !IS_ERR(pdev) && !rtcdev) {
		if (!try_module_get(rtc->owner)) {
			ret = -1;
			goto unlock;
@@ -115,10 +118,14 @@ static int alarmtimer_rtc_add_device(struct device *dev,
		get_device(dev);
		ws = __ws;
		__ws = NULL;
		pdev = NULL;
	} else {
		ret = -1;
	}
unlock:
	spin_unlock_irqrestore(&rtcdev_lock, flags);

	platform_device_unregister(pdev);
	wakeup_source_unregister(__ws);

	return ret;
@@ -891,8 +898,7 @@ static struct platform_driver alarmtimer_driver = {
 */
static int __init alarmtimer_init(void)
{
	struct platform_device *pdev;
	int error = 0;
	int error;
	int i;

	alarmtimer_rtc_timer_init();
@@ -915,15 +921,7 @@ static int __init alarmtimer_init(void)
	if (error)
		goto out_if;

	pdev = platform_device_register_simple("alarmtimer", -1, NULL, 0);
	if (IS_ERR(pdev)) {
		error = PTR_ERR(pdev);
		goto out_drv;
	}
	return 0;

out_drv:
	platform_driver_unregister(&alarmtimer_driver);
out_if:
	alarmtimer_rtc_interface_remove();
	return error;