Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp81851imm; Thu, 30 Aug 2018 08:48:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaSeHeAsKkxv6uT8OXB4JrCZh5ZdfqrLWxuFkHlK0Bt1HHsUErpktNpkbYejGpijg7m+Ezc X-Received: by 2002:a63:6881:: with SMTP id d123-v6mr2282647pgc.298.1535644127769; Thu, 30 Aug 2018 08:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535644127; cv=none; d=google.com; s=arc-20160816; b=lAuBjSr/HOwSMIGMq/Fj8ayxXvJ7fOPUoK/TfUOELSJkE7rnVsLcHa4WO4uuAMVhEB 7f7M0RBU/OT8RT+k1wZh+KhYGboxolKiwZ3fNlHu+L1kaw+AsdrhirI8oavMcbD5oVVm 25d792J3Aia7vg9+RpTQOs1qjo/3lLJTCC+9SxsJH10fnVWxrD9Y8mz6CZiSEfIxU5GQ dwaW8t3D6Xa8akz2v1PlFG1Qdh4QW3dDzhfJrPQnpSkLw5XUGej6EA9JjHYXQnDMsWtN aLL7zrhdXChlObu0GLaxX52OLbGRq2dQYHY2kKPjtgnjbECyiiItsxH0wh2fV3LaJDk0 Y8dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=awc7lOb1lT80drwezjxAgYVu4AbsJ53UXF1LdxXOCho=; b=VY9Aola9iCBPIGnawJ/rOwqtL8SNpqXUSaMnVeSr4FwT2jxyPkO2X/4/XQVJitSA5R vS72XVZkk4E93tDq36kl2m50yxH7DcXlfP5mPQiylkbRq0Ol2Kvft+F4ODIfXW/0+ikz BReH1E0u5UE5a5Gk+qp5DltG4HoacOavNoeUTzxQhgsYQwh3yjaVPxlwMu1RElWPiTXm SHifX04w8S0BGuj7E69toUobKfvCMncCnKhBh1Lp3WZltoAkxS3hxeZXVAPGerbbzDLJ LtC67hoh1rqeLgGGAtW5Xks48v2Kc1xa2ayt86CH98qhRTOTgKH3BwZjIdOemWoKhZ4T j8Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X0MxvQAW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4-v6si7488834pfb.52.2018.08.30.08.48.32; Thu, 30 Aug 2018 08:48:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X0MxvQAW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727759AbeH3TsZ (ORCPT + 99 others); Thu, 30 Aug 2018 15:48:25 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52409 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727683AbeH3TsZ (ORCPT ); Thu, 30 Aug 2018 15:48:25 -0400 Received: by mail-wm0-f65.google.com with SMTP id y139-v6so2458893wmc.2; Thu, 30 Aug 2018 08:45:37 -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=awc7lOb1lT80drwezjxAgYVu4AbsJ53UXF1LdxXOCho=; b=X0MxvQAWNa/QHG1a/x8gvN03aFC9bPKcstD3++OvpK/mWPr/Nu71ydd6Bi41ISzadw qIrOAT4F4OdsZ2kzh+q00Iis58hoEqbdTQiaJXXSzS2z9xTXQ5TxEH5tqgZjYazGaWjL bgRuTIATJ9oEsL4Wiu0TCg4IYGtnZMurHeihga0x6jkxCqTnuwwGYQJO+iPhrO6Es8uG PfJfsu2w7Xck8vTApyDRlNjCvRFoI5IwEtRAnxtxmXrFhmaoTmiGArLtORnF021wvrAd TAL+o92qdd4pPHPE+vbp5YWVnctSPkhqkJ92iBaWO2vxPhz1KGnXaQA3f6nl67oaEha3 JKrQ== 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=awc7lOb1lT80drwezjxAgYVu4AbsJ53UXF1LdxXOCho=; b=RlO5JBPY1Ynt6MAlVm7Q3VyjKbiF8PLuXEEC4f6fEfw7d6NjdEOL4dg1K+uEI6XuZU yH08gy9rL8vmV+0GdXichfRnk99oGr4OoObqxUptVWQwcFuVvakiYyoMG3YFG9e3c7lq Wkhtb5yf1f3KBhE+X7f/YvH6xyEyiqvX3NhXpizea6QNjI7jbZm6XE3PdEUVPhyXWwm6 v+AqbPhE+opsnZOmX2yuSZlB/Put9l6jVFvaqoafkwK9CXxb/aQR+lbJ/cYwmk8Ua1d4 a/KGr6exwwO8QFh/BbWPCoExLobq0XEP6JPUL9MX2n3Yr4ZlKDx8pSpLit8HJG6yeb2b h5Eg== X-Gm-Message-State: APzg51DqrotD9OusUHyFbj/9ZLvcMlEPpA+KWV2WGgycXJaa3HYtvNs8 Zs1R05QkhMDrUODYyVGteSU= X-Received: by 2002:a1c:7e13:: with SMTP id z19-v6mr2044367wmc.156.1535643937235; Thu, 30 Aug 2018 08:45:37 -0700 (PDT) Received: from debian-hp.wlan.uni-ulm.de (eduroam170-020.wlan.uni-ulm.de. [134.60.170.20]) by smtp.gmail.com with ESMTPSA id j20-v6sm1362759wmh.9.2018.08.30.08.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 08:45:36 -0700 (PDT) From: Philipp Rossak To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, eugen.hristev@microchip.com, rdunlap@infradead.org, vilhelm.gray@gmail.com, clabbe.montjoie@gmail.com, quentin.schulz@bootlin.com, geert+renesas@glider.be, lukas@wunner.de, icenowy@aosc.io, arnd@arndb.de, broonie@kernel.org, arnaud.pouliquen@st.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com Subject: [PATCH v3 17/30] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset Date: Thu, 30 Aug 2018 17:45:05 +0200 Message-Id: <20180830154518.29507-18-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180830154518.29507-1-embed3d@gmail.com> References: <20180830154518.29507-1-embed3d@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For adding newer sensor some basic rework of the code is necessary. The SoCs after H3 has newer thermal sensor ADCs, which have two clock inputs (bus clock and sampling clock) and a reset. The registers are also re-arranged. This commit reworks the code, adds the process of the clocks and resets. Signed-off-by: Philipp Rossak --- drivers/iio/adc/sun4i-gpadc-iio.c | 72 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index c278e165e161..c12de48c4e86 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -22,6 +22,7 @@ * shutdown for not being used. */ +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include @@ -63,6 +65,9 @@ struct gpadc_data { int (*ths_suspend)(struct sun4i_gpadc_iio *info); int (*ths_resume)(struct sun4i_gpadc_iio *info); bool support_irq; + bool has_bus_clk; + bool has_bus_rst; + bool has_mod_clk; u32 temp_data_base; }; @@ -127,6 +132,9 @@ struct sun4i_gpadc_iio { struct mutex mutex; struct thermal_zone_device *tzd; struct device *sensor_device; + struct clk *bus_clk; + struct clk *mod_clk; + struct reset_control *reset; }; static const struct iio_chan_spec sun4i_gpadc_channels[] = { @@ -472,8 +480,13 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, if (IS_ERR(base)) return PTR_ERR(base); - info->regmap = devm_regmap_init_mmio(&pdev->dev, base, - &sun4i_gpadc_regmap_config); + if (info->data->has_bus_clk) + info->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "bus", + base, &sun4i_gpadc_regmap_config); + else + info->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sun4i_gpadc_regmap_config); + if (IS_ERR(info->regmap)) { ret = PTR_ERR(info->regmap); dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); @@ -498,9 +511,58 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, } } + if (info->data->has_bus_rst) { + info->reset = devm_reset_control_get(&pdev->dev, NULL); + if (IS_ERR(info->reset)) { + ret = PTR_ERR(info->reset); + return ret; + } + + ret = reset_control_deassert(info->reset); + if (ret) + return ret; + } + + if (info->data->has_bus_clk) { + info->bus_clk = devm_clk_get(&pdev->dev, "bus"); + if (IS_ERR(info->bus_clk)) { + ret = PTR_ERR(info->bus_clk); + goto assert_reset; + } + + ret = clk_prepare_enable(info->bus_clk); + if (ret) + goto assert_reset; + } + + if (info->data->has_mod_clk) { + info->mod_clk = devm_clk_get(&pdev->dev, "mod"); + if (IS_ERR(info->mod_clk)) { + ret = PTR_ERR(info->mod_clk); + goto disable_bus_clk; + } + + /* Running at 4MHz */ + ret = clk_set_rate(info->mod_clk, 4000000); + if (ret) + goto disable_bus_clk; + + ret = clk_prepare_enable(info->mod_clk); + if (ret) + goto disable_bus_clk; + } + info->sensor_device = &pdev->dev; return 0; + +disable_bus_clk: + clk_disable_unprepare(info->bus_clk); + +assert_reset: + reset_control_assert(info->reset); + + return ret; } static int sun4i_gpadc_probe(struct platform_device *pdev) @@ -586,6 +648,12 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) if (!info->data->support_irq) iio_map_array_unregister(indio_dev); + clk_disable_unprepare(info->mod_clk); + + clk_disable_unprepare(info->bus_clk); + + reset_control_assert(info->reset); + return 0; } -- 2.11.0