From patchwork Wed Mar 28 17:15:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiro TSUKADA X-Patchwork-Id: 10313683 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 D68C060467 for ; Wed, 28 Mar 2018 17:15:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C82B829F94 for ; Wed, 28 Mar 2018 17:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5BBF29FAD; Wed, 28 Mar 2018 17:15:31 +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 5282929FAF for ; Wed, 28 Mar 2018 17:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753096AbeC1RPa (ORCPT ); Wed, 28 Mar 2018 13:15:30 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:39131 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753074AbeC1RP2 (ORCPT ); Wed, 28 Mar 2018 13:15:28 -0400 Received: by mail-pg0-f65.google.com with SMTP id b9so1173696pgf.6 for ; Wed, 28 Mar 2018 10:15:28 -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=8tB31O4w+L1AxbTe9Cs5KgtWyTP59Ftjt0rcNsUAqyo=; b=EHHX2UAuhs5HVIKQ2/hrPBWc8kt+cB4Oi1we4cA3CnpWUtPAcHlS3Nw4JUWlDA/gtN H3oIj3s8UJbsAAx3xfa1V6qKL98lWswty8U1Q+vtOEyJNe6fI4DekSJny+nRIKzRld7L pW4p35knv1xRweEkrbQmCB04pDxMsn/TmLIqNsL9aQ1Kx0ICd6QfiJgIdMx23gB9NlgH 9tuzLOh3gpRqDnefKEWUL9gFm8RTJAE7vjjw/RXwB9iJo7gk3DOeo2TdLS3aQv0vBauq GsVP627eNmOI32Hgth67m/rE+/rcFHYFwb1xmNFCvgJ9N4izisDsJmwiTesAaTQL+0pT O0UA== 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=8tB31O4w+L1AxbTe9Cs5KgtWyTP59Ftjt0rcNsUAqyo=; b=Z6v6fZVGr1cVfr86N7LntjP+RF2nyNgdiHqAP/qT6nANXj7xs98NA63YYvQ92SlvN5 BA5d82X331+ckqvfgA0QagSsVPfVmCtHjT8fa0LbjfRrtYIggf4wqMlQazB+wDoa3P9J f7noKdkDtr2eWWaKAMSXyl4pQLMBuCQwbZ+2B2VI0Cuz+aT8wkcxb88sFL7lyWEEmrOn DHB0hDjqK+uCdFTbd+xKSN1ldRk6f96UsPZIkEGoWJefN6jj3xdptxBYIn00vJbarTtl PKQaVJvt7OyClULyUyfVzkYgbnbroIXQBChOndktmHPJnvzawp10Wi3jS2mhjGQmgf1O CZVw== X-Gm-Message-State: AElRT7GwGWGEXbr84GQ2cpJB+EBZcJspEO+48+Kc67zUEJaku31sZH8K limdv9u/11PIb9YuPCe3MOS9TQ== X-Google-Smtp-Source: AIpwx4+CoVtNRNTs4oOhbtwAynrPwtzBFb5pV3/rV9n2wPsZ9eBQd/gyXoktPAxiKtuRgrgfmFZ2hA== X-Received: by 2002:a17:902:bc02:: with SMTP id n2-v6mr4564502pls.347.1522257327832; Wed, 28 Mar 2018 10:15:27 -0700 (PDT) Received: from localhost.localdomain (softbank219203027033.bbtec.net. [219.203.27.33]) by smtp.googlemail.com with ESMTPSA id t75sm6504450pfe.124.2018.03.28.10.15.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Mar 2018 10:15:27 -0700 (PDT) From: tskd08@gmail.com To: linux-media@vger.kernel.org Cc: mchehab@s-opensource.com, Akihiro Tsukada Subject: [PATCH v2 4/5] dvb: earth-pt1: add support for suspend/resume Date: Thu, 29 Mar 2018 02:15:02 +0900 Message-Id: <20180328171503.30541-5-tskd08@gmail.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180328171503.30541-1-tskd08@gmail.com> References: <20180328171503.30541-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 --- Changes since v1: - none 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 60bf517e7fe..80510616c4c 100644 --- a/drivers/media/pci/pt1/pt1.c +++ b/drivers/media/pci/pt1/pt1.c @@ -461,12 +461,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)) { @@ -1165,6 +1171,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; @@ -1325,11 +1423,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);