From patchwork Sun Apr 8 17:39:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiro TSUKADA X-Patchwork-Id: 10328439 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 7337B6037F for ; Sun, 8 Apr 2018 17:41:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61162289A9 for ; Sun, 8 Apr 2018 17:41:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55E73289FF; Sun, 8 Apr 2018 17:41: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 D6DDC289A9 for ; Sun, 8 Apr 2018 17:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752915AbeDHRl3 (ORCPT ); Sun, 8 Apr 2018 13:41:29 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:34313 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752688AbeDHRka (ORCPT ); Sun, 8 Apr 2018 13:40:30 -0400 Received: by mail-pl0-f67.google.com with SMTP id y12-v6so3625121plt.1 for ; Sun, 08 Apr 2018 10:40:29 -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=kC3gzZn3n5S6+IMxS7TbnhvMslm5YDl8+lohbdtFP5c=; b=D05D4RVj6vpEyhe8Vlk6Rz6cvKs54Xs1fYRcZMoTVedaJ7nSuNzpKqS9A60U68QCR7 l//OL5KKWuPSAG/I02IKQZiJMKyGVGjUuLxtJi2dYEwzSDgyZt05ZVpCHiFWuffNZXI/ sW/n8wGy/3R4OTeFrzU+YkkbCUMpbItkZl83BYgMMsQLo/Tyq5xp3lsEFtB2FSSlqW+Q mXtDybyIYliGmBJmn6nEKiO3e2Vm4Z6dmn6UzA/5a2F4E0ki3Z1c1M38H+pXaKQUekkr W46FSl/bu4xou/BcN88OsbDpgSfPfJC1v3xzjykDpcElnDQW7FL7YlTr6TMRLsWpGySt I6xw== 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=kC3gzZn3n5S6+IMxS7TbnhvMslm5YDl8+lohbdtFP5c=; b=TyvG59s9w0oqlQWcPsnUQxZ9dnxqE7sYaxKDY2jAzn143+Y2aNmxoV+nPGKG1ARUKR Df4AQS0Dnexjo9Ak/Q0XUeCZ/vH7xNgFU3j4xBZPtw1L/YTznpgux7aXVRKN1zFd24uL 4G+JidRjtEkk8P+SWitiZA9mnH6U3dl2S7z3PNJDp2j2zQ+EOk1uTD6AbLc4ojFGze6C GdolipWW4uJnUoyERuOfVM5yjaQl6xMbJiei7D3HXDBrNxIFnUcjTQdhAPtt470Nwjnv lWMe9cVWNw3FjJ0hixqgTEW4MzFPbUE2zpNswk+CFP6tkYVC3mTkn8YtIoHMMOeOfLOu TxZg== X-Gm-Message-State: AElRT7FOgXZqY5dkdJgt2krOkpL4ZlZe5iAVCJbAgXqHteHFcnweoKJp 2cAvmutJVT8R3Xb+hhZvAoqcaQ== X-Google-Smtp-Source: AIpwx4+0b7nj/5K3bTrrlhDhYiLYQmUrE99NCFUyoy5PfWkExHtBtyDgpAPS040An9s9N6rts/B82Q== X-Received: by 2002:a17:902:8f8c:: with SMTP id z12-v6mr35937314plo.400.1523209229469; Sun, 08 Apr 2018 10:40:29 -0700 (PDT) Received: from localhost.localdomain (softbank219203027033.bbtec.net. [219.203.27.33]) by smtp.googlemail.com with ESMTPSA id r76sm31750910pfl.24.2018.04.08.10.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Apr 2018 10:40:28 -0700 (PDT) From: tskd08@gmail.com To: linux-media@vger.kernel.org Cc: mchehab@s-opensource.com, Akihiro Tsukada , hiranotaka@zng.info Subject: [PATCH v3 4/5] dvb: earth-pt1: add support for suspend/resume Date: Mon, 9 Apr 2018 02:39:52 +0900 Message-Id: <20180408173953.11076-5-tskd08@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180408173953.11076-1-tskd08@gmail.com> References: <20180408173953.11076-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 v2: - none 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 40b6c0ac342..b169175d85e 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);