From nobody Mon Dec 1 23:32:44 2025 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 67F042FFDF3 for ; Wed, 26 Nov 2025 12:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764160988; cv=none; b=MQ7SuNsjVrAje5HGrf+SWg1Kl33CLeDO7L37TwzTl+80aJggwAQ23NRtPXGhD8jFY+VIviyNh96kpQ8JLal5Wmj5XSQjs+paIY5D2mZ95REp/f5p7q9kjAxJOqkUlfRa7ugrhZPuFIrFwM+SD6A9UEQ7ChAswIcrXn/yowr1JxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764160988; c=relaxed/simple; bh=yhPuiR6XrfoigONn7YjeXv5GIwSDKgMVMn3NKSqWbcw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XAYGozAde45THzHJO5Ws/nghbvaAZ1NqNWTSQGnP902QD4ZQgjfqOka+C3+zwUaBRZiH/GRPoV+eohUEnoGoRs9Fi86O9kGBjAQvcGNo5y7XKe91KKxP79TEPTtppBJaN9/najZOgLpkYvAz2vJnYqqR/sN9q380/ltHA0U1oy0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X9BhvZTE; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X9BhvZTE" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-64320b9bb4bso1702784a12.0 for ; Wed, 26 Nov 2025 04:43:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764160985; x=1764765785; 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=R/PKuQqJhmcmf0FdDQDCr8/x7Yh0ZaImvK0r2Y0Qm/o=; b=X9BhvZTEIGLDZqdiOSObcXENx5IP+UOxdOpXjlRsB3Mm5XM+GESmFrf830xBkS7j9B EwXWz0LTQt+k/bAY9D2dsfW62/YOiwtE2LH8yGu+ycdtFvIVc04AzqQzCl/QsW5Gt7k7 VV8XrEnXYQha/Lgg+9d6cbYHVLTxuhoBUpN3xYqBc5DZDg8xYVWn+rizlVZ37qus50B3 Wh6cf4wLF1Ib0S1+4832HljjrCMcR/djzDpNU13mTPKZMUJfMUmsiFXuQO0bVBe9O4dO dvBsAUF4H0/mKwbais2f3Ce4ao722b2cxJlJySNCqJ9M3PN5lgcXL/Tj8hXRtzA0mIsS c3ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764160985; x=1764765785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R/PKuQqJhmcmf0FdDQDCr8/x7Yh0ZaImvK0r2Y0Qm/o=; b=k7xNVbcWbj3/3hFRCgMj4xeGoULrwNlNBDIqnJl+1bbQzosLUn/F4n9LZ474/vcKHm JCdDuUoeb27iyOWpdx5w4yXgtUhBXkBibfvPLO69gHGMw/IMhVe8yER5VyfA/Qloqc2v AhagnNM9iVJ2xtc4lvgR43EDQd0HqOnreg5Nrh4SXfknnKjsnePHNl4Qu1TFCq6kV51k IHPbF99nYeWfPZxtKqUdBKUQie4BPL6bTXd6TsQd7Swd3B0hRW92UYaUL7iXTmbtqCM3 otZyOVquqtDRev9jRJVqk7dhcO7pbJ9rEYMBsAtiQNhzOgKSEOc/xCCcQvOf980h+0iU odxw== X-Forwarded-Encrypted: i=1; AJvYcCUdNsrb6HdpTgwZ1cXEgU5aBaqRX0/9rA7jD0xJvwd0iEYMiJTGyIeuTWmrAGAeheks8ddxRjxBCwyE98U=@vger.kernel.org X-Gm-Message-State: AOJu0Yypf7Im6D6nOaXcjqqYndGyhR0qMBLa1qfETXRAoDFMlRCe/cxL jkGRhgpUz6UVbYJlDoirRUoc0raPtMlLP5VeOwQMwljkxE7SBpOqkHoc X-Gm-Gg: ASbGnctJU0oDpGvceGALxK5jCvkyYgxrlDvn4tzoDBGDTVKj/fUfh290lWfnRVLu90G UjkhoJY0Ol1+Eccwatk63KmeZAJBnNxmfJyApI5GAjS3AYoe3xhwJt8MvRFbb7hpds39s+pjY/j yqfLEASWFD1/VHHDLbToJy0rCpSZGduO133xbnyEWf25ZyNQ+IEUQFOYQslCzi8Z2cSzam2hxYE woE2aEUawsPDzk9iJnlu0X2RxfDuePLPvmoDt66yCN1I4Cca+9jb3eW34XIveRqDjQGoFduYpCe XS5mNDky4ez42PiBpJ16P/o6JV2+KFqMCHoxm+2/pVI2WP8XfWz+RgIG+5QQeNf6vmMYp4TXcrN UMUJh6TO96hYaT9MbymuqBtHvQOdP1OJ9vkBvbRgx4WCzvShYic10jG4Og7qN4un/YCV7WejCf1 cVbIBLzZqYvy82K9OTNwg1uoPPD4Mm0s7pPw7e X-Google-Smtp-Source: AGHT+IE/BZ0ev8jczVI6ig5ZypcAIr/hIiYi2tdzGsQKsQ4dJMO7/o1MUW3qqxHJXJn1yXPjYPs2Yg== X-Received: by 2002:a05:6402:4499:b0:643:130b:c615 with SMTP id 4fb4d7f45d1cf-64539639594mr18794499a12.6.1764160984613; Wed, 26 Nov 2025 04:43:04 -0800 (PST) Received: from SMW024614.wbi.nxp.com ([128.77.115.157]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64536459d92sm17654824a12.31.2025.11.26.04.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 04:43:04 -0800 (PST) From: Laurentiu Mihalcea To: Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Fabio Estevam , Philipp Zabel , Daniel Baluta , Shengjiu Wang , Frank Li Cc: devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Pengutronix Kernel Team Subject: [PATCH v6 2/5] reset: imx8mp-audiomix: Switch to using regmap API Date: Wed, 26 Nov 2025 04:42:15 -0800 Message-ID: <20251126124218.803-3-laurentiumihalcea111@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251126124218.803-1-laurentiumihalcea111@gmail.com> References: <20251126124218.803-1-laurentiumihalcea111@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Laurentiu Mihalcea Switch to using the regmap API to allow performing register operations under the same lock. This is needed for cases such as i.MX8ULP's SIM LPAV where clock gating, reset control and MUX-ing is performed via the same register (i.e. SYSCTRL0) and different subsystem APIs. Reviewed-by: Philipp Zabel Reviewed-by: Frank Li Signed-off-by: Laurentiu Mihalcea --- drivers/reset/reset-imx8mp-audiomix.c | 92 +++++++++++++++++---------- 1 file changed, 57 insertions(+), 35 deletions(-) diff --git a/drivers/reset/reset-imx8mp-audiomix.c b/drivers/reset/reset-im= x8mp-audiomix.c index acfa92b15329..f6152c0cc5ff 100644 --- a/drivers/reset/reset-imx8mp-audiomix.c +++ b/drivers/reset/reset-imx8mp-audiomix.c @@ -12,6 +12,7 @@ #include #include #include +#include #include =20 #define IMX8MP_AUDIOMIX_EARC_RESET_OFFSET 0x200 @@ -43,8 +44,7 @@ static const struct imx8mp_reset_map reset_map[] =3D { =20 struct imx8mp_audiomix_reset { struct reset_controller_dev rcdev; - spinlock_t lock; /* protect register read-modify-write cycle */ - void __iomem *base; + struct regmap *regmap; }; =20 static struct imx8mp_audiomix_reset *to_imx8mp_audiomix_reset(struct reset= _controller_dev *rcdev) @@ -56,26 +56,14 @@ static int imx8mp_audiomix_update(struct reset_controll= er_dev *rcdev, unsigned long id, bool assert) { struct imx8mp_audiomix_reset *priv =3D to_imx8mp_audiomix_reset(rcdev); - void __iomem *reg_addr =3D priv->base; - unsigned int mask, offset, active_low; - unsigned long reg, flags; + unsigned int mask, offset, active_low, val; =20 mask =3D reset_map[id].mask; offset =3D reset_map[id].offset; active_low =3D reset_map[id].active_low; + val =3D (active_low ^ assert) ? mask : ~mask; =20 - spin_lock_irqsave(&priv->lock, flags); - - reg =3D readl(reg_addr + offset); - if (active_low ^ assert) - reg |=3D mask; - else - reg &=3D ~mask; - writel(reg, reg_addr + offset); - - spin_unlock_irqrestore(&priv->lock, flags); - - return 0; + return regmap_update_bits(priv->regmap, offset, mask, val); } =20 static int imx8mp_audiomix_reset_assert(struct reset_controller_dev *rcdev, @@ -95,6 +83,52 @@ static const struct reset_control_ops imx8mp_audiomix_re= set_ops =3D { .deassert =3D imx8mp_audiomix_reset_deassert, }; =20 +static const struct regmap_config regmap_config =3D { + .reg_bits =3D 32, + .val_bits =3D 32, + .reg_stride =3D 4, +}; + +/* assumption: registered only if not using parent regmap */ +static void imx8mp_audiomix_reset_iounmap(void *data) +{ + void __iomem *base =3D (void __iomem *)data; + + iounmap(base); +} + +static int imx8mp_audiomix_reset_get_regmap(struct imx8mp_audiomix_reset *= priv) +{ + void __iomem *base; + struct device *dev; + int ret; + + dev =3D priv->rcdev.dev; + + /* try to use the parent's regmap */ + priv->regmap =3D dev_get_regmap(dev->parent, NULL); + if (priv->regmap) + return 0; + + /* ... if that's not possible then initialize the regmap right now */ + base =3D of_iomap(dev->parent->of_node, 0); + if (!base) + return dev_err_probe(dev, -ENOMEM, "failed to iomap address space\n"); + + ret =3D devm_add_action_or_reset(dev, + imx8mp_audiomix_reset_iounmap, + (void __force *)base); + if (ret) + return dev_err_probe(dev, ret, "failed to register action\n"); + + priv->regmap =3D devm_regmap_init_mmio(dev, base, ®map_config); + if (IS_ERR(priv->regmap)) + return dev_err_probe(dev, PTR_ERR(priv->regmap), + "failed to initialize regmap\n"); + + return 0; +} + static int imx8mp_audiomix_reset_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) { @@ -106,36 +140,25 @@ static int imx8mp_audiomix_reset_probe(struct auxilia= ry_device *adev, if (!priv) return -ENOMEM; =20 - spin_lock_init(&priv->lock); - priv->rcdev.owner =3D THIS_MODULE; priv->rcdev.nr_resets =3D ARRAY_SIZE(reset_map); priv->rcdev.ops =3D &imx8mp_audiomix_reset_ops; priv->rcdev.of_node =3D dev->parent->of_node; priv->rcdev.dev =3D dev; priv->rcdev.of_reset_n_cells =3D 1; - priv->base =3D of_iomap(dev->parent->of_node, 0); - if (!priv->base) - return -ENOMEM; =20 dev_set_drvdata(dev, priv); =20 + ret =3D imx8mp_audiomix_reset_get_regmap(priv); + if (ret) + return dev_err_probe(dev, ret, "failed to get regmap\n"); + ret =3D devm_reset_controller_register(dev, &priv->rcdev); if (ret) - goto out_unmap; + return dev_err_probe(dev, ret, + "failed to register reset controller\n"); =20 return 0; - -out_unmap: - iounmap(priv->base); - return ret; -} - -static void imx8mp_audiomix_reset_remove(struct auxiliary_device *adev) -{ - struct imx8mp_audiomix_reset *priv =3D dev_get_drvdata(&adev->dev); - - iounmap(priv->base); } =20 static const struct auxiliary_device_id imx8mp_audiomix_reset_ids[] =3D { @@ -148,7 +171,6 @@ MODULE_DEVICE_TABLE(auxiliary, imx8mp_audiomix_reset_id= s); =20 static struct auxiliary_driver imx8mp_audiomix_reset_driver =3D { .probe =3D imx8mp_audiomix_reset_probe, - .remove =3D imx8mp_audiomix_reset_remove, .id_table =3D imx8mp_audiomix_reset_ids, }; =20 --=20 2.43.0