From patchwork Tue Mar 27 15:16:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiro TSUKADA X-Patchwork-Id: 10310457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 42C7A600F6 for ; Tue, 27 Mar 2018 15:17:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 322B828EB9 for ; Tue, 27 Mar 2018 15:17:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26B8928EF3; Tue, 27 Mar 2018 15:17:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7FC9294CC for ; Tue, 27 Mar 2018 15:17:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752399AbeC0PRU (ORCPT ); Tue, 27 Mar 2018 11:17:20 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:45020 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752331AbeC0PRT (ORCPT ); Tue, 27 Mar 2018 11:17:19 -0400 Received: by mail-pf0-f194.google.com with SMTP id m68so8969762pfm.11 for ; Tue, 27 Mar 2018 08:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vDpkI9oMpQZq0+nNsyzewNuJqM41GBB5Fz+b3uShpMM=; b=bNYhT3wNy/Hr/3hPHn9oFd8/SD4HygcZjiM8Y1wppaTVYrxUHeHztbW7JwUxtWmCbj 4a7YkZlOR8CKngM109ymRAUASAKmT+mqS1IzdtQmqtRAzDi3RnGD+T9DNCNhHZZD0S9e 4bXQGKfQqDAzJ/Hz83e91xgUehXgjl72dlEuXRoIs+HnQS5BxjtUsVM1TsWHZb1CzTG6 2bB0ZV71fCEldgQmiKjg+puO3O9u38qN7ljCTte8VB+huI/v5qzifOzHo9M8CTgkUXfw 4vCJnARWvV2c67TsUFXu+XcimQqUh0XtV3eg47d0PxBHiTzszWY3vjxlzSXEnSkSL53L HWuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vDpkI9oMpQZq0+nNsyzewNuJqM41GBB5Fz+b3uShpMM=; b=ndvs3PFe7Dje2pk8p6zpDLrXVDvFwqb26FOmebMaqP031vgy/R9Qb2X+rnYC7iIZdr KIPFXbCdBSAE5Uuu46AE63fBXt8miZTRtx9+l6mln39KBLfjo8ubFMXXBk7X+o0vx3gI HwH8hGgHgk551egPLqgnKXJ8tupTSVXkQLkgMWQ7lKMFGvSRDH7h1PZJUKzNql3Vd8zN UxXo3l1mg9cNg4WE+W+vjz7S9G6Goy/ER/d8iwASHO5nxkRuAjanTQ0ahO6Ef26iX3UH +ouHJ8mB87WQzkH57x6hEfmYheXuJUBe8XqP98aDQoAFc1Nk4XXgiZ4gyZsnFCj4HqMU 3cjw== X-Gm-Message-State: AElRT7Emt9uSIRbFKRRftki7XeqHvINznfcQfCy4v7OYD8neptKwD4zJ Xt6pSLzehhnaQaxGO6WfE3dD5g== X-Google-Smtp-Source: AG47ELvSWks9ZPbPgolJqv/Znu5vqZsPZ5jryqkd3n6sW3sWZmHmMD03+PrBfm0WeVbWak5dDmFN8Q== X-Received: by 10.99.109.72 with SMTP id i69mr32319668pgc.417.1522163838495; Tue, 27 Mar 2018 08:17:18 -0700 (PDT) Received: from localhost.localdomain (softbank219203027033.bbtec.net. [219.203.27.33]) by smtp.googlemail.com with ESMTPSA id c15sm3957419pfm.114.2018.03.27.08.17.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 08:17:18 -0700 (PDT) From: tskd08@gmail.com To: linux-media@vger.kernel.org Cc: mchehab@s-opensource.com, hiranotaka@zng.info, Akihiro Tsukada Subject: [PATCH 4/5] dvb: earth-pt1: add support for suspend/resume Date: Wed, 28 Mar 2018 00:16:01 +0900 Message-Id: <20180327151602.12250-5-tskd08@gmail.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327151602.12250-1-tskd08@gmail.com> References: <20180327151602.12250-1-tskd08@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Akihiro Tsukada Without this patch, re-loading of the module was required after resume. Signed-off-by: Akihiro Tsukada --- drivers/media/pci/pt1/pt1.c | 107 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c index 34a688952e2..1a83a624776 100644 --- a/drivers/media/pci/pt1/pt1.c +++ b/drivers/media/pci/pt1/pt1.c @@ -467,12 +467,18 @@ static int pt1_thread(void *data) { struct pt1 *pt1; struct pt1_buffer_page *page; + bool was_frozen; pt1 = data; set_freezable(); - while (!kthread_should_stop()) { - try_to_freeze(); + while (!kthread_freezable_should_stop(&was_frozen)) { + if (was_frozen) { + int i; + + for (i = 0; i < PT1_NR_ADAPS; i++) + pt1_set_stream(pt1, i, !!pt1->adaps[i]->users); + } page = pt1->tables[pt1->table_index].bufs[pt1->buf_index].page; if (!pt1_filter(pt1, page)) { @@ -1171,6 +1177,98 @@ static void pt1_i2c_init(struct pt1 *pt1) pt1_i2c_emit(pt1, i, 0, 0, 1, 1, 0); } +#ifdef CONFIG_PM_SLEEP + +static int pt1_suspend(struct device *dev) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pt1 *pt1 = pci_get_drvdata(pdev); + + pt1_init_streams(pt1); + pt1_disable_ram(pt1); + pt1->power = 0; + pt1->reset = 1; + pt1_update_power(pt1); + return 0; +} + +static int pt1_resume(struct device *dev) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pt1 *pt1 = pci_get_drvdata(pdev); + int ret; + int i; + + pt1->power = 0; + pt1->reset = 1; + pt1_update_power(pt1); + + pt1_i2c_init(pt1); + pt1_i2c_wait(pt1); + + ret = pt1_sync(pt1); + if (ret < 0) + goto resume_err; + + pt1_identify(pt1); + + ret = pt1_unlock(pt1); + if (ret < 0) + goto resume_err; + + ret = pt1_reset_pci(pt1); + if (ret < 0) + goto resume_err; + + ret = pt1_reset_ram(pt1); + if (ret < 0) + goto resume_err; + + ret = pt1_enable_ram(pt1); + if (ret < 0) + goto resume_err; + + pt1_init_streams(pt1); + + pt1->power = 1; + pt1_update_power(pt1); + msleep(20); + + pt1->reset = 0; + pt1_update_power(pt1); + usleep_range(1000, 2000); + + for (i = 0; i < PT1_NR_ADAPS; i++) + dvb_frontend_reinitialise(pt1->adaps[i]->fe); + + pt1_init_table_count(pt1); + for (i = 0; i < pt1_nr_tables; i++) { + int j; + + for (j = 0; j < PT1_NR_BUFS; j++) + pt1->tables[i].bufs[j].page->upackets[PT1_NR_UPACKETS-1] + = 0; + pt1_increment_table_count(pt1); + } + pt1_register_tables(pt1, pt1->tables[0].addr >> PT1_PAGE_SHIFT); + + pt1->table_index = 0; + pt1->buf_index = 0; + for (i = 0; i < PT1_NR_ADAPS; i++) { + pt1->adaps[i]->upacket_count = 0; + pt1->adaps[i]->packet_count = 0; + pt1->adaps[i]->st_count = -1; + } + + return 0; + +resume_err: + dev_info(&pt1->pdev->dev, "failed to resume PT1/PT2."); + return 0; /* resume anyway */ +} + +#endif /* CONFIG_PM_SLEEP */ + static void pt1_remove(struct pci_dev *pdev) { struct pt1 *pt1; @@ -1331,11 +1429,16 @@ static const struct pci_device_id pt1_id_table[] = { }; MODULE_DEVICE_TABLE(pci, pt1_id_table); +static SIMPLE_DEV_PM_OPS(pt1_pm_ops, pt1_suspend, pt1_resume); + static struct pci_driver pt1_driver = { .name = DRIVER_NAME, .probe = pt1_probe, .remove = pt1_remove, .id_table = pt1_id_table, +#if CONFIG_PM_SLEEP + .driver.pm = &pt1_pm_ops, +#endif }; module_pci_driver(pt1_driver);