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: 9944535 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 43B036035D for ; Fri, 8 Sep 2017 15:37:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34BFD212D6 for ; Fri, 8 Sep 2017 15:37:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2927F28429; Fri, 8 Sep 2017 15:37:13 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 BB6A2212D6 for ; Fri, 8 Sep 2017 15:37:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932496AbdIHPge (ORCPT ); Fri, 8 Sep 2017 11:36:34 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35142 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756582AbdIHPg1 (ORCPT ); Fri, 8 Sep 2017 11:36:27 -0400 Received: by mail-wm0-f68.google.com with SMTP id e64so1985769wmi.2; 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=fXBsF79Umqxj4kWSsSSMgj1nUW+nsOmLHb6/C/gAa57hL8GU4182Yl2aVPMwBolf3R pm/jf+mHeMWVVeHtOD5NVtzbRaLWktJL7vymU2e0Y/XXZyUL9+6VQ23Cf4NMmsP5PwKp xKUiI6mJDDS3sQHHTbnGhJ+4YKUjebIzm2f4l/IxU+2AlOR2njJeCJwPgOPMVqIfhd2n DB73XY7DOIZKbKbI851V79Lf4eXCfFZQ2ci9feolHo1nOe8NVcQKeNC/l/5DwozAos4V CCrVkY7CjG3Thd4Hr94uUOG4KAfdPnoqIxglNgGZdiSQT1hGHDsI7orcTlvBf0WQvkND PXrQ== X-Gm-Message-State: AHPjjUieWjQ/nvHYaO7F9X/aC3WKPsqvN28xylmjPTenwXdyDUGAR7ks J3baEnzHhdY6KrcSu3OYIko= 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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-mtd@lists.infradead.org, linux-pwm@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Romain Izard 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> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)