From patchwork Fri Sep 8 15:36:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 811660 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="o1RjT7Ru"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j+4lTOQl"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xphQF1f3Qz9t66 for ; Sat, 9 Sep 2017 01:41:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=98chZD2IOoLhWskJPKlA41m7NWuYKsMLA6+Cvp/An+o=; b=o1RjT7RubkyKxHTJh+jCUxDK/6 TcMRr6XBMwhe0qZfMDLYJ1htsV2ZnUkNU2D5Fe4VZCsWVIzmNRxhfPdrm4VbZ2UrRvG+pmhiv9Jjj vFdwr6gh1ojkD0SemlL1wgWKOUWSrnSRXNroyMw+7zcZLn72cHN0C15nF5O4OJdw/wVsCEfWKl061 t5d0bIorbIHQcOyuZg08vkHXKTJnY436b68bGSQ9pKl8Dw7mSGX6zx4D7xZH7uSSxj30UguffZ3sp wtIOAVysqU+8MT5WrYzpOch/7gr7VIvk/kMpMcOniyZMGoMkeTBY3O/6Gj6DbJgvdJ6uqkvfOqOU4 RP8o3/Kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dqLPg-0002Nx-BC; Fri, 08 Sep 2017 15:41:48 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dqLKn-00068X-Oa; Fri, 08 Sep 2017 15:36:53 +0000 Received: by mail-wm0-x242.google.com with SMTP id x17so1975539wmd.5; Fri, 08 Sep 2017 08:36:26 -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=leYrW6L0ZAgin3ZE6IBF4T1AHRveuovX/Zppbk5tYX0=; b=j+4lTOQltgZ+smEkBmKTjvXaLZqAtgLVsu5bj/O6S/VrHeH+Sfr48Wqo3UCJBp4Ah+ h3Uau5W4dwdo4ubpSbh5ANhgfzhpn2WFAp5MgiuCtXAJXC8/y/eWfcqJxArUx7gAP4X1 iR4xk4ZyMjg4GBeu5opA1oHrmKpK5/E0EZLKWyTrLUKeRnOPcEeODcjtDeYMXu4Csh9J 9F1nIM7Qa0JUPPt4f8aiEW/rt7wP92dsSfZTIoO/fh33FKUGPYy/XZT+b5Jro7BcWGi9 VSNDXo2HpRa6b7Gt86EU5FHtGrzrr/cESaDiNyVt8jKeETXhqWG6lqQy8MnxRYu1OQ9q kufg== 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=leYrW6L0ZAgin3ZE6IBF4T1AHRveuovX/Zppbk5tYX0=; b=lks7sRP1yoPUzvA9CSsFxdl6/6LoTbGIzugfmIERLIK+/yeVzto16BdFkkelhBiu6p 5NERt6gyGfdLkyzFBPdjc8Vk5KCHOmKhW4m2tAVJeyL9MSIW1rWrZG8TjTeSNvcjaYn+ nCEQV/u1KjaYrQzEDnD9v1UrUbfsj5gpQrf/ebZcsvB5vmwEFS+5M6FV5Qzc47PPgmcT Sl+Pax5TmRCLixd/+706+2BekRpV9hJV+qGxKusCq3xnmGjeLUXci7nUqXwvvq5tNhIV 5+pYYzwPJNu+nUt66EULnr2MGpnNPqoEPSaCSBjXyDqPZOB+xM6qqy5UTP2L7bWYPsw9 B1Dw== X-Gm-Message-State: AHPjjUjX59K+cBTMYuNSInHIvHdZZki60HXaW3o9XdwBikYQqlrxAFbX Mh2GocahsroPldsVFxPkktc= X-Google-Smtp-Source: AOwi7QCuZrYWjFlTk6VAnjoV4RNmAdRDCKjWHnUIqtUUP0EBxrSoKQSMpXuCu34A1JUFXlARvJVSoQ== X-Received: by 10.28.15.210 with SMTP id 201mr2181914wmp.10.1504884985380; Fri, 08 Sep 2017 08:36:25 -0700 (PDT) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id p199sm1689224wmb.28.2017.09.08.08.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 08:36:24 -0700 (PDT) From: Romain Izard To: Nicolas Ferre , Boris Brezillon , Michael Turquette , Stephen Boyd , Ludovic Desroches , Jonathan Cameron , Wenyou Yang , Josh Wu , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , Thierry Reding , Richard Genoud , Greg Kroah-Hartman , Alan Stern Subject: [PATCH v1 07/10] iio:adc:at91-sama5d2: Support backup mode Date: Fri, 8 Sep 2017 17:36:01 +0200 Message-Id: <20170908153604.28383-8-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170908153604.28383-1-romain.izard.pro@gmail.com> References: <20170908153604.28383-1-romain.izard.pro@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170908_083646_327312_EDC963B4 X-CRM114-Status: GOOD ( 13.46 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (romain.izard.pro[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-iio@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-serial@vger.kernel.org, Romain Izard , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Support the backup mode for platform suspend, by restoring the hardware registers on resume. Signed-off-by: Romain Izard --- drivers/iio/adc/at91-sama5d2_adc.c | 71 ++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index e10dca3ed74b..f9718c863363 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -200,6 +200,7 @@ struct at91_adc_state { u32 conversion_value; struct at91_adc_soc_info soc_info; wait_queue_head_t wq_data_available; + unsigned int current_rate; /* * lock to prevent concurrent 'single conversion' requests through * sysfs. @@ -269,6 +270,8 @@ static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) mr |= AT91_SAMA5D2_MR_PRESCAL(prescal); at91_adc_writel(st, AT91_SAMA5D2_MR, mr); + st->current_rate = freq; + dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", freq, startup, prescal); } @@ -375,7 +378,9 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, val > st->soc_info.max_sample_rate) return -EINVAL; + mutex_lock(&st->lock); at91_adc_setup_samp_freq(st, val); + mutex_unlock(&st->lock); return 0; } @@ -386,6 +391,21 @@ static const struct iio_info at91_adc_info = { .driver_module = THIS_MODULE, }; +static void at91_adc_init_hw(struct at91_adc_state *st, unsigned int freq) +{ + at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); + at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff); + /* + * Transfer field must be set to 2 according to the datasheet and + * allows different analog settings for each channel. + */ + at91_adc_writel(st, AT91_SAMA5D2_MR, + AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH); + + at91_adc_setup_samp_freq(st, freq); + +} + static int at91_adc_probe(struct platform_device *pdev) { struct iio_dev *indio_dev; @@ -482,16 +502,7 @@ static int at91_adc_probe(struct platform_device *pdev) goto vref_disable; } - at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); - at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff); - /* - * Transfer field must be set to 2 according to the datasheet and - * allows different analog settings for each channel. - */ - at91_adc_writel(st, AT91_SAMA5D2_MR, - AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH); - - at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate); + at91_adc_init_hw(st, st->soc_info.min_sample_rate); ret = clk_prepare_enable(st->per_clk); if (ret) @@ -541,12 +552,52 @@ static const struct of_device_id at91_adc_dt_match[] = { }; MODULE_DEVICE_TABLE(of, at91_adc_dt_match); +#ifdef CONFIG_PM_SLEEP +static int at91_adc_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + struct at91_adc_state *st = iio_priv(indio_dev); + + clk_disable_unprepare(st->per_clk); + + regulator_disable(st->vref); + regulator_disable(st->reg); + + return 0; +} + +static int at91_adc_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + struct at91_adc_state *st = iio_priv(indio_dev); + int err; + + err = regulator_enable(st->reg); + if (err) + return err; + + err = regulator_enable(st->vref); + if (err) + return err; + + at91_adc_init_hw(st, st->current_rate); + + err = clk_prepare_enable(st->per_clk); + return err; +} +#endif + +static SIMPLE_DEV_PM_OPS(at91_adc_pm_ops, at91_adc_suspend, at91_adc_resume); + static struct platform_driver at91_adc_driver = { .probe = at91_adc_probe, .remove = at91_adc_remove, .driver = { .name = "at91-sama5d2_adc", .of_match_table = at91_adc_dt_match, + .pm = &at91_adc_pm_ops, }, }; module_platform_driver(at91_adc_driver)