Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp353153lqo; Thu, 16 May 2024 08:09:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmwIQ4w44Eb7xNF8eni89Nv7AglK4JA6UuNWWXRg9qzykgoH+FliDIaFPBli3HJl9jEu/mzwXicBNCmXVyLc/NXyfRg4Kmz4ZtwRagAg== X-Google-Smtp-Source: AGHT+IEEebwgpEFDmETTqQ/PVt+ZPerJ9vr14kgwlkCDgw1JGjUypXKu1bkmYxxf9zpuSprHSERq X-Received: by 2002:a17:907:1b17:b0:a59:aa69:9791 with SMTP id a640c23a62f3a-a5a2d5eeb92mr1857794466b.34.1715872147070; Thu, 16 May 2024 08:09:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715872147; cv=pass; d=google.com; s=arc-20160816; b=HbSS6fCPtQmSb+nJZRYJ9ZKqUoKQqFnRhDya1B0RiQ2lyvntHIa8+b4A6vmCHVAkyz X0V68qybON/PbmOBBjmcQRAsOvLkGsCT6lrhO5oS9ID6OSzC1aFmb6JF6D/7PyjKSJRm 8HZthSIbh8JItIIL5KPkuGCQaISwOcDz+C+ilI8hqdWBNzoLCwCaBhGdgNj7V9xA0gAc Q2jd9Z2FqNLkXDVeUMSjmJJsXKoFeXkEgYwm4Hv/+hJhRYDRIn0vO/VQEj/tQDOamSmP MH/sFRD60+neksq8u5C/DZc3bdfd+jJZQJaUPpIQUx2DAXnPH0t17VdXD9qf8Jdaj6L3 GdDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+f/3bReYMesF4TJq9BOi7hv3PG6ArjPAwHRzmWrlWAw=; fh=CAtHdJJcxBh9wIDswwz7fzxj8DC3v1d9OnFzRRWEfKM=; b=ZQSzujCvxEjeQZVUFmuhE/e8bcfmO4/QiorhA7NdhApSAjUHJJjVnNnBNobSEZn/io dQkkcvy/JtH7u8Eck6ZQ2xsnSYq9pWaw1MG9etvRn4FAIJEh3EgFnO1a79jtXYK2ZSnn 9tdseQtkeJUNB13JeQ+iwtMdX+I2Bym3xoN2Wi8JPnHlrwPyF8GpGDj02ajI4v+y0X+r 1znbicFnvf63uW8ZCOSQfcz+0cT3ei2PZx0TudAlWi7ewlFeoUZHxCrkUTJG6Qn780Qw dDCQiYCJkx+4wq2aKKe6WlmLT63By917leOPZ1Njv9+J8uCUSMwgv2lVRyEe6aiF0N5I T65A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qiT2ujII; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-181203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181203-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a8ba6b6e5si273564666b.8.2024.05.16.08.09.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:09:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qiT2ujII; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-181203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181203-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9D4961F214D8 for ; Thu, 16 May 2024 15:09:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D59B14D435; Thu, 16 May 2024 15:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="qiT2ujII" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2475214B97A for ; Thu, 16 May 2024 15:08:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715872132; cv=none; b=fE+QcrU/e/lr2kRh67P8o+IgulRaiAkOn4upwCoZ0vLDx3hWOrDr4TCIZWL67c1jUQR9sDG/9QmGrZvTqq3DzG9o3aSXPBleZpZjWQ8muIQ3zMuDf9k3z8PUqO8ke89bCVeuXLGsBJodKGvY2uToHpbwZpoEB1nP0jCa9gYrnyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715872132; c=relaxed/simple; bh=cxaqUoQ9aguHyFdmx85j2AoRbVwkuszVVEgKQCGMEX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cmdWBYvMTgl3lYeGPRPle6riVBp8rREKpqw5sC5l4Ko21VVNA4YCJpBmFVmsVF7Qsf71tAkGrY/VNt6kv+K+c4cB+JYG+PFWVmG7OqpFKawrde/6Z39LxuKmxC2pnF/tgLIq7UzgBfVZtK1hcXBIixUsbeUg8kAKUnFqBVf/anE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=qiT2ujII; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4202c1d19d5so5018365e9.2 for ; Thu, 16 May 2024 08:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1715872128; x=1716476928; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+f/3bReYMesF4TJq9BOi7hv3PG6ArjPAwHRzmWrlWAw=; b=qiT2ujIIVGhrnuqOh3+FX8h23MZkpHqzNIhTFqsgLttZUVWi9NhtGcq7sh/HCpXPqS HnSdeWHSUiunY81T+sjuCYgvD9h44XvslU2HzSRxEA3PckF+6W+k7WauDx8JhvUnKN6L 3td+XdAWwgn2DkqL3cEBi8NbXX6ZVAKYSf1gdJaPWiRcCYIxc2n+XhjFXMgo+Wq23yvc jSGCrTrRgzmW+1impZgD9sP3WLKwHe4tgrA0w/hNNUceQcTfc8/BkdOGUaQNHYeP9ZUY 2MmiAwZXqVDOI0wzi9DGJqllfEJF8AhX5x9TPxfO9G2hG4LlKpoGQk8swM9zzSiGv/IY eYTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715872128; x=1716476928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+f/3bReYMesF4TJq9BOi7hv3PG6ArjPAwHRzmWrlWAw=; b=jDPJT8XZnxWzP5yqERKcoj9CmgLwXzz0pu9v+vc5DzkxWHbhR8buizXpMMEKt4qUgZ T+qDI9LCmrmt3kDE6/jKcsHYjbAYZPcyeWwVfTEElLAHR5CkXJ3nYIMBfoMvckOJszBo pYYbop6GBXKPI6A5pOvx3+ez4repOcEYD9O+KEld66mdqojSA2WHD3qBlto+M5+MNN1d kVjS509uLMtrix1YAUb/V7tYbnNHJajTxyReonL9jgNvJTr6A95Q88dWdwH5IBlzUYeQ Wm5Xz8AJTiWT5ABDUoEOZi1XReMAhRs2iDM3x4tBR0AhI4aSHefb52S0rQvpWs40d6sW LzNw== X-Forwarded-Encrypted: i=1; AJvYcCUFKkmN1vaRWOmm0wl79hg9PcVDQcaJASZUcoLaaEiXmt/edrbm14ShbK5M1yiAQBViYkMctXY1MxN8ReN+cjkdYruw2aIK/SMwpZpQ X-Gm-Message-State: AOJu0YwNap5n4UtF2HJaszVFaougGuexJYmSOi8JncwG2/hyA0fyn31+ B2Hewi94KAnOtq6xGI9PL+2daAoxBcedr2pVdpE296i7RbUs90KNqsbQhfzlszc= X-Received: by 2002:a05:600c:5008:b0:41f:e7ac:cc72 with SMTP id 5b1f17b1804b1-41fead643a0mr145586765e9.40.1715872128318; Thu, 16 May 2024 08:08:48 -0700 (PDT) Received: from toaster.lan ([2a01:e0a:3c5:5fb1:1fce:7e5a:e201:edd5]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-41f87c25459sm309351725e9.18.2024.05.16.08.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:08:48 -0700 (PDT) From: Jerome Brunet To: Philipp Zabel , Stephen Boyd , Neil Armstrong Cc: Jerome Brunet , Jan Dakinevich , linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org Subject: [RFC PATCH 1/9] reset: amlogic: convert driver to regmap Date: Thu, 16 May 2024 17:08:31 +0200 Message-ID: <20240516150842.705844-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240516150842.705844-1-jbrunet@baylibre.com> References: <20240516150842.705844-1-jbrunet@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit To allow using the same driver for the main reset controller and the auxiliary ones embedded in the clock controllers, convert the the Amlogic reset driver to regmap. Signed-off-by: Jerome Brunet --- drivers/reset/reset-meson.c | 80 ++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/drivers/reset/reset-meson.c b/drivers/reset/reset-meson.c index f78be97898bc..8f3d6e9df235 100644 --- a/drivers/reset/reset-meson.c +++ b/drivers/reset/reset-meson.c @@ -11,36 +11,44 @@ #include #include #include +#include #include #include #include -#define BITS_PER_REG 32 - struct meson_reset_param { int reg_count; int level_offset; }; struct meson_reset { - void __iomem *reg_base; const struct meson_reset_param *param; struct reset_controller_dev rcdev; - spinlock_t lock; + struct regmap *map; }; +static void meson_reset_offset_and_bit(struct meson_reset *data, + unsigned long id, + unsigned int *offset, + unsigned int *bit) +{ + unsigned int stride = regmap_get_reg_stride(data->map); + + *offset = (id / (stride * BITS_PER_BYTE)) * stride; + *bit = id % (stride * BITS_PER_BYTE); +} + static int meson_reset_reset(struct reset_controller_dev *rcdev, - unsigned long id) + unsigned long id) { struct meson_reset *data = container_of(rcdev, struct meson_reset, rcdev); - unsigned int bank = id / BITS_PER_REG; - unsigned int offset = id % BITS_PER_REG; - void __iomem *reg_addr = data->reg_base + (bank << 2); + unsigned int offset, bit; - writel(BIT(offset), reg_addr); + meson_reset_offset_and_bit(data, id, &offset, &bit); - return 0; + return regmap_update_bits(data->map, offset, + BIT(bit), BIT(bit)); } static int meson_reset_level(struct reset_controller_dev *rcdev, @@ -48,25 +56,13 @@ static int meson_reset_level(struct reset_controller_dev *rcdev, { struct meson_reset *data = container_of(rcdev, struct meson_reset, rcdev); - unsigned int bank = id / BITS_PER_REG; - unsigned int offset = id % BITS_PER_REG; - void __iomem *reg_addr; - unsigned long flags; - u32 reg; + unsigned int offset, bit; - reg_addr = data->reg_base + data->param->level_offset + (bank << 2); + meson_reset_offset_and_bit(data, id, &offset, &bit); + offset += data->param->level_offset; - spin_lock_irqsave(&data->lock, flags); - - reg = readl(reg_addr); - if (assert) - writel(reg & ~BIT(offset), reg_addr); - else - writel(reg | BIT(offset), reg_addr); - - spin_unlock_irqrestore(&data->lock, flags); - - return 0; + return regmap_update_bits(data->map, offset, + BIT(bit), assert ? 0 : BIT(bit)); } static int meson_reset_assert(struct reset_controller_dev *rcdev, @@ -113,30 +109,42 @@ static const struct of_device_id meson_reset_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, meson_reset_dt_ids); +static const struct regmap_config regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, +}; + static int meson_reset_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct meson_reset *data; + void __iomem *base; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; - data->reg_base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(data->reg_base)) - return PTR_ERR(data->reg_base); + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); - data->param = of_device_get_match_data(&pdev->dev); + data->param = of_device_get_match_data(dev); if (!data->param) return -ENODEV; - spin_lock_init(&data->lock); + data->map = devm_regmap_init_mmio(dev, base, ®map_config); + if (IS_ERR(data->map)) + return dev_err_probe(dev, PTR_ERR(data->map), + "can't init regmap mmio region\n"); data->rcdev.owner = THIS_MODULE; - data->rcdev.nr_resets = data->param->reg_count * BITS_PER_REG; + data->rcdev.nr_resets = data->param->reg_count * BITS_PER_BYTE + * regmap_config.reg_stride; data->rcdev.ops = &meson_reset_ops; - data->rcdev.of_node = pdev->dev.of_node; + data->rcdev.of_node = dev->of_node; - return devm_reset_controller_register(&pdev->dev, &data->rcdev); + return devm_reset_controller_register(dev, &data->rcdev); } static struct platform_driver meson_reset_driver = { -- 2.43.0