From patchwork Thu Jul 18 09:57:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 13736309 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 EE03585285 for ; Thu, 18 Jul 2024 09:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721296688; cv=none; b=Cf1JMnRXd05v/OUfYB5Tr7Qe/30Et92hyxuhNyE9XBBX+CM7xOJb0M/rked2OF/7LHBbd+7/qM4fyGf78a6jdz6oDmvNRQEqJkhNFSTMmO1c4IqCshl1NBqk0D4jjOX+MesO4U4AfW88Jhy4MKRzC6IWEeHpJAtGLnhrn8GQgw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721296688; c=relaxed/simple; bh=cxaqUoQ9aguHyFdmx85j2AoRbVwkuszVVEgKQCGMEX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lGB5r+KG35ZbR7jO8WCEJgBpcxMdmmZKn8pli9FFp/adCfmvOBDy73sK0ydg/XGeKAvjEnXb8zuX4dXBTg+FcbkjGAujx6wpKFNZd47DujQj9pLTN0UXlBSNI7jMgWDK6yGYJH2obEeKaK3r5ODaQvbZQ8IlyDBzYe5jrZE9Uz8= 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=JAp1nfl/; arc=none smtp.client-ip=209.85.221.46 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 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="JAp1nfl/" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-368380828d6so420423f8f.1 for ; Thu, 18 Jul 2024 02:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1721296684; x=1721901484; 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=JAp1nfl/mUpnT3GSrT+5Dc8Y0mNb84sLVaWAmDyW8veLLmLKy9Qihv0oyqKOM6SvmU YfWCtHUvb+LC7H3tMN7Urxfl5DWHdl6PHwGZV5zwMUP6JR97UYJBDZ1xFn+84pw2BXcu AXGPpJzk/0dV3EgA3uxMnyzafslm8HNbkGo/xcz4MNPGM0U8//j+N4QlK1dqcTK1RGlB asz5R3eajummhQQfwLfgNB3CctDFEIwQ9IwRmzkkgqMNsZwGBFOsXXQWQcTmPqUTw84d kpLtbWXavKuuEMT2tYTODUA26ENtO3kz6B3J/6AQ4gc6REF63y0nQ7V1XR3YVC4I7OEd NU2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721296684; x=1721901484; 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=kgb6ny9vve9svSFvSnw8/1PB7JhjBzU27rPtTG16CBGM/leWwduqu9Tp/lx3xdQo3A BPICZO2TQuxPRE7IZhrb6UqjQXEDbd17HsgkdJ1RFUiAuC445wR9H2BZzYAmFzCyDAok BAVfEPujqSHMpLS/8ADunVUB4oryJZFo3GeuNd94COqoVVMBRs7w27wrdcgwloeg1AsO v7qVZSJXwhsIKT8HMopLdTJIMTT1cds3/4o+j1L80gFvp/G3Ws4M4tykoMnStT54PYrP 47qWcdVi/g5+8GryVWDoTe1u2K5iJUkDObeRJUozX7F+e8Vql79vjGJFhH5Mfje2yx8p kMNw== X-Forwarded-Encrypted: i=1; AJvYcCWJLv0oon0MwyBhJOcH6BToY5xqwjzynL52OO85zT8PMaBh9O5jmYCnL6uNrkJzbJiR0RuxD7RLJaB6vUqILFGYZxpJ1jYUqj/i X-Gm-Message-State: AOJu0YxwnAM3P0u3zdemhJ9i0iK3aOacfvBgcEdwo60Hg4wxTrdxYalq Ws59Ia6PTbcWt0sojmcyrXxdOq7uN0BAHC0ZvLqwBDKgee4n1uzVksWboajPqN8= X-Google-Smtp-Source: AGHT+IF2wpylHtE0GsGjeKwrPISupVDdqlSWSz7Bc5nyMlVO3EB3+GjMC7UpkG8hkKpJnSbvcphnrQ== X-Received: by 2002:a5d:540d:0:b0:367:9803:bfe7 with SMTP id ffacd0b85a97d-3683171fe16mr2596315f8f.53.1721296684185; Thu, 18 Jul 2024 02:58:04 -0700 (PDT) Received: from toaster.lan ([2a01:e0a:3c5:5fb1:8d37:f44a:c212:e320]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3680dab3be3sm13837155f8f.24.2024.07.18.02.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 02:58:03 -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: [PATCH v2 1/9] reset: amlogic: convert driver to regmap Date: Thu, 18 Jul 2024 11:57:45 +0200 Message-ID: <20240718095755.3511992-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240718095755.3511992-1-jbrunet@baylibre.com> References: <20240718095755.3511992-1-jbrunet@baylibre.com> Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Bot: notify 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 = {