From patchwork Thu Jun 20 10:39:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Holler X-Patchwork-Id: 252866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-x23d.google.com (mail-wi0-x23d.google.com [IPv6:2a00:1450:400c:c05::23d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id DB7E32C0040 for ; Thu, 20 Jun 2013 20:39:59 +1000 (EST) Received: by mail-wi0-f189.google.com with SMTP id k10sf347843wiv.16 for ; Thu, 20 Jun 2013 03:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:x-beenthere:x-spam-checker-version:x-spam-level :x-spam-status:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=rlCKwCfGgsuZndHgcm1JbbM3wRwkcPhDU28/E2lN7Cg=; b=tV9QbZxpW++s0c+tlBzAP9JMwH8ueA17VFx4kSx6kgY/cDO/gpNp3S3TstluJwVTqj 9Am3tNhgtjuHHaIMDsNfFDhn/eNFBvRCg5XgUhuN1zIRm/+/K2K2QySzTIHRtevU4Uph HOryzQLrBccO9UKm2zrlDhSs0HwIbZDnW9B1dJhEoPvHyN+N0ak9lLUI7Zhpmj8iW9ij X6v6NIT8S7in2xvgZlWa+ec664cv0NbXpfEjbNuFyjWPbj5NpOsimDVTH1mtYfwGlarW DhM/JhOiEea0OwljlLeKvwTAIRaTuzMOxQGkdqqqh70D0CrtQ4GATMrQBEluCuUu8ltX V2nQ== X-Received: by 10.180.37.239 with SMTP id b15mr726302wik.12.1371724795786; Thu, 20 Jun 2013 03:39:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.83.132 with SMTP id q4ls103760wiy.48.canary; Thu, 20 Jun 2013 03:39:55 -0700 (PDT) X-Received: by 10.14.47.77 with SMTP id s53mr8645501eeb.5.1371724795227; Thu, 20 Jun 2013 03:39:55 -0700 (PDT) Received: from mail.ahsoftware.de (h1446028.stratoserver.net. [85.214.92.142]) by gmr-mx.google.com with ESMTP id ci6si6615079eeb.1.2013.06.20.03.39.55 for ; Thu, 20 Jun 2013 03:39:55 -0700 (PDT) Received-SPF: neutral (google.com: 85.214.92.142 is neither permitted nor denied by best guess record for domain of holler@ahsoftware.de) client-ip=85.214.92.142; Received: by mail.ahsoftware.de (Postfix, from userid 65534) id D92C9888B92; Thu, 20 Jun 2013 12:39:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.ahsoftware.de X-Spam-Level: X-Spam-Status: No, score=-101.0 required=5.0 tests=ALL_TRUSTED, USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from eiche.ahsoftware (p57B21577.dip0.t-ipconnect.de [87.178.21.119]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ahsoftware.de (Postfix) with ESMTPSA id F174F888A97 for ; Thu, 20 Jun 2013 12:39:53 +0200 (CEST) Received: by eiche.ahsoftware (Postfix, from userid 65534) id 3F0287F977; Thu, 20 Jun 2013 12:39:53 +0200 (CEST) Received: from krabat.ahsoftware (unknown [192.168.207.2]) by eiche.ahsoftware (Postfix) with ESMTP id AD2B67F963; Thu, 20 Jun 2013 10:39:46 +0000 (UTC) From: Alexander Holler To: linux-kernel@vger.kernel.org Cc: Andrew Morton , rtc-linux@googlegroups.com, Alessandro Zummo , Alexander Holler Subject: [rtc-linux] [PATCH 3/9 v2] rtc: rtc-hid-sensor-time: delay registering as rtc into a work Date: Thu, 20 Jun 2013 12:39:36 +0200 Message-Id: <1371724776-5572-1-git-send-email-holler@ahsoftware.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1371228732-5749-4-git-send-email-holler@ahsoftware.de> References: <1371228732-5749-4-git-send-email-holler@ahsoftware.de> X-Original-Sender: holler@ahsoftware.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.214.92.142 is neither permitted nor denied by best guess record for domain of holler@ahsoftware.de) smtp.mail=holler@ahsoftware.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , rtc_device_register() might want to read the clock which doesn't work before the hid device is registered. Therefor we delay the registration of the rtc driver by moving it to a work. Signed-off-by: Alexander Holler --- Changes to v1: I've fixed a bug calling rtc_device_unregister() in remove() which was necessary in 3.9 but leads to a crash in 3.10 (through the use of devm_*). Sorry for that, I assume I've resolved a conflict wrong while moving this patch from 3.9.x to 3.10. This patch can already be added to -mm. It is only necessary if rtc_device_register() reads the time (which would fail without this patch). I've left the "3/9" in the subject only there, because the patch was named as such before. But the patch is independ if hctosys will be changed or not. 1/9 and 2/9 are already in -mm, 4-9 are in discussion which will need some time. Thanks, Alexander Holler drivers/rtc/rtc-hid-sensor-time.c | 64 ++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index 7273b01..0767395 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c @@ -37,6 +37,11 @@ enum hid_time_channel { TIME_RTC_CHANNEL_MAX, }; +struct hid_time_workts { + struct work_struct work; + struct hid_time_state *time_state; +}; + struct hid_time_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; @@ -46,6 +51,7 @@ struct hid_time_state { struct completion comp_last_time; struct rtc_time time_buf; struct rtc_device *rtc; + struct hid_time_workts *workts; }; static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = { @@ -237,6 +243,36 @@ static const struct rtc_class_ops hid_time_rtc_ops = { .read_time = hid_rtc_read_time, }; +static void hid_time_register_rtc_work(struct work_struct *work) +{ + struct hid_time_state *time_state = + container_of(work, struct hid_time_workts, work) + ->time_state; + struct platform_device *pdev = time_state->callbacks.pdev; + + time_state->rtc = devm_rtc_device_register(&pdev->dev, + "hid-sensor-time", &hid_time_rtc_ops, + THIS_MODULE); + if (IS_ERR_OR_NULL(time_state->rtc)) { + struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; + sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); + time_state->rtc = NULL; + dev_err(&pdev->dev, "rtc device register failed!\n"); + /* + * I haven't a found a way to remove only this device from + * hid-sensor-hub. Removing the device a level above (the + * complete HID device) doesn't work, because a sensor-hub + * might provide more than just a time-sensor and thus we + * would remove all sensors not just this one. + * So we just leave this driver idling around until I or + * someone else has figured out how to remove this device + * from hid-sensor-hub. + */ + } + time_state->workts = NULL; + kfree(work); +} + static int hid_time_probe(struct platform_device *pdev) { int ret = 0; @@ -279,22 +315,34 @@ static int hid_time_probe(struct platform_device *pdev) return ret; } - time_state->rtc = devm_rtc_device_register(&pdev->dev, - "hid-sensor-time", &hid_time_rtc_ops, - THIS_MODULE); - - if (IS_ERR(time_state->rtc)) { - dev_err(&pdev->dev, "rtc device register failed!\n"); - return PTR_ERR(time_state->rtc); + /* + * The HID device has to be registered to read the clock. + * Because rtc_device_register() might read the time, we have to delay + * rtc_device_register() to a work in order to finish the probe before. + */ + time_state->workts = kmalloc(sizeof(struct hid_time_workts), + GFP_KERNEL); + if (time_state->workts == NULL) { + sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); + return -ENOMEM; } + time_state->workts->time_state = time_state; + INIT_WORK(&time_state->workts->work, + hid_time_register_rtc_work); + schedule_work(&time_state->workts->work); - return ret; + return 0; } static int hid_time_remove(struct platform_device *pdev) { struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; + struct hid_time_state *time_state = platform_get_drvdata(pdev); + if (time_state->workts) { + flush_work(&time_state->workts->work); + WARN_ON(time_state->workts != NULL); + } sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); return 0;