From nobody Tue Nov 26 20:02:28 2024 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (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 C0F474A1B; Wed, 16 Oct 2024 00:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729037973; cv=none; b=N0vi4Q9du5dSFVdrydm0YgUlpuuKtDgnHot4fHy936oqzmCP2e59QVlcg6CrTtTpvZSnhC2NOv4zRhoHHhQkBt6XjqTD4exi0eXBlvJrcA2o4RTBpWcTO/J/rFO/LbFOatlk+difNELzfeCznBmx+9pN4p2sBuvrBWEutMruJlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729037973; c=relaxed/simple; bh=K6wTO0XXcUltPS1eFJkf7vAFnY2/gPwEUzXU3Ct6GMs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ia6Jg/Y5YskVnGySZaDqP2mQ+yJGYyGxQXuuYgoJd3Sc2DuHY3Yth8MTiykH0rIYdzMQTy1+P6BekRv5w+KPlWxAOob2qECusvJb7IM4I2/vytQft7B9JQskAI3rbWm5fLNm8h0RktafgPsRRgRAoDG65HhTuocZ5fjmv0y3oL8= 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=Wx1sGEat; arc=none smtp.client-ip=209.85.210.49 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="Wx1sGEat" Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-7180120a78dso698121a34.1; Tue, 15 Oct 2024 17:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729037971; x=1729642771; 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=UlWzcYJ31J9Ws/z9sFG6bpzdTEyI/n4+1H05qgKO0vE=; b=Wx1sGEatzVVW3avGE9TlYkQTcezX8SRIQ8Hisp1QuBfCaIrqaBMNZfnifY2UgOwVVC Nwo0E8ldWSTjCnOPg9uG0CqpJgCVUgONgXUmPAW9cS7cq1NOncPfLZq1LIxcodRwZlb9 2ZoGnIVKA0pAwpVRy0WCtandRO3DFeBQL0bAENTl8LTVLKTfPa9Pvnziw2no26mL5ts6 pxaM2D27oZNDy+pCpkiEMymVTvlHyc1knBx8U17gM1ZuGO9RA9t4ldBI3t5Y5HpPNOo7 evsSG1x+d4yVUp6UACf2LLLQdhzVBsWMJVynFjkm+tmxCEeidImqOEZW5fs8tbEY1ucB kPgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729037971; x=1729642771; 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=UlWzcYJ31J9Ws/z9sFG6bpzdTEyI/n4+1H05qgKO0vE=; b=rfEAARsMJ/B4LP79m2tozSWgXKddrJDmcjl08ocjoXoBbBIEBw56EKKpkltgZxTHMq He+rJ1GOMsvdfArRIjED5GOQj2qcX9YDskcYK/2GbhUfn43Uc5ijVN1rmgFMmnF2qLNa hF1ALtoW8jHb4XodC7xT65Exf0NNNQAsYjA53r1GkNVM3pGtoPWgfm7HvaGZE4A8fmLF SvHRxo0L+zekkHonKqF6saL4QlCzjrTQTrP/sP2IBxaf94btCZ4Jgiy5wwA+dagfFk5T BHvP+GGU5H8c1HgAhv7/lzpgA982O4u6vLedHbUeRd/1a2zJ+904cTtax07VF89HWj+l mB3w== X-Forwarded-Encrypted: i=1; AJvYcCWKrdfkTbYSnsk3WD1xsTApNRB2qkKFvP/ZsXuGnRvY7EUdXJWPYNM6UNt9m7JQckKy9I6m+gOE8B4o@vger.kernel.org, AJvYcCXJ8MnvYeotFlEXiWLPvBV+qPwiMSzZBbZvW3a99945L4nEKivmFduFpwaA1VVWA49V3nH1rGbvh2Dt@vger.kernel.org, AJvYcCXNGM2Jp50dDq6MT7+9HXWuioZEZhllbxXeZRv76387KY36CMkxsxhUvYVmI6qx2JeVM1dNlUA6/RL1rO4/@vger.kernel.org X-Gm-Message-State: AOJu0YwvhYFz4UswwYKZLEeIFJQww6IUDKNzRrlLHjm0joI5mNkGY9J1 lI/g21BDzIercA+A8fZetVNCaufWqowXiBL524orJkTSj+beudEC X-Google-Smtp-Source: AGHT+IFw8zlbKDtvNmVePRwavyGsAfAi2KYxPiUFzfeRVIsRw9ZlHlAgw/BduzdJ6EYOR/iAMn5T9Q== X-Received: by 2002:a05:6830:4119:b0:715:4e38:a1ad with SMTP id 46e09a7af769-717d653fc85mr14661117a34.21.1729037970597; Tue, 15 Oct 2024 17:19:30 -0700 (PDT) Received: from localhost.localdomain ([122.8.183.87]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-717fb8e40a0sm594829a34.16.2024.10.15.17.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 17:19:30 -0700 (PDT) From: Chen Wang To: ukleinek@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, unicorn_wang@outlook.com, inochiama@outlook.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-riscv@lists.infradead.org, chao.wei@sophgo.com, haijiao.liu@sophgo.com, xiaoguang.xing@sophgo.com, chunzhi.lin@sophgo.com Cc: Krzysztof Kozlowski Subject: [PATCH v4 1/3] dt-bindings: pwm: sophgo: add PWM controller for SG2042 Date: Wed, 16 Oct 2024 08:19:22 +0800 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: Chen Wang Sophgo SG2042 contains a PWM controller, which has 4 channels and can generate PWM waveforms output. Signed-off-by: Chen Wang Reviewed-by: Krzysztof Kozlowski --- .../bindings/pwm/sophgo,sg2042-pwm.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm= .yaml diff --git a/Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml b= /Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml new file mode 100644 index 000000000000..fe89719ed9dd --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/sophgo,sg2042-pwm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sophgo SG2042 PWM controller + +maintainers: + - Chen Wang + +description: + This controller contains 4 channels which can generate PWM waveforms. + +allOf: + - $ref: pwm.yaml# + +properties: + compatible: + const: sophgo,sg2042-pwm + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: apb + + "#pwm-cells": + const: 2 + +required: + - compatible + - reg + - clocks + - clock-names + +unevaluatedProperties: false + +examples: + - | + pwm@7f006000 { + compatible =3D "sophgo,sg2042-pwm"; + reg =3D <0x7f006000 0x1000>; + #pwm-cells =3D <2>; + clocks =3D <&clock 67>; + clock-names =3D "apb"; + }; --=20 2.34.1 From nobody Tue Nov 26 20:02:28 2024 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 A1D9B21E3CD; Wed, 16 Oct 2024 00:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729038030; cv=none; b=d7LWuoLHTDQrjnbvz431iabJzjldicIen1/MYLQ7PxnzftGyw3X9aIjRcPqsigml6L9ppg+liz/MYk58wXOpkaNnTNF2uPOBKoULMXORFO65ergPKbiO3z6jB2kgypCRrOY66w2Er1NOFFS2XHdlTEZzSHI5DQDJoSH1zztZIDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729038030; c=relaxed/simple; bh=WJ+pDDYO9o+WoDmZ4X5dROVEVzJ4wwyDstMo2Vf+klo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z3RURbIZ++lujHeu9WL19dSTcR1ig2tNFqMsmOtL+myt6foVtn//FqhisZozWEkDLE1YdNodE0RUCE4ADnRPQq314Ue1r8WKoIPc7jv2UN7jXZIQIPkYNXToJbEkfy31TWZZNxsc61NrdcCEQfAkDf61nPmTwwsXwKhxdA6CHao= 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=D6vSGs5V; arc=none smtp.client-ip=209.85.167.176 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="D6vSGs5V" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3e3e0a8aaabso2005307b6e.3; Tue, 15 Oct 2024 17:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729038027; x=1729642827; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=92VubGYyXALAVnQRA8GVr+urTCCGJBZXT1C9yLWdrMo=; b=D6vSGs5V5bwm8a1sW30o+g54UpTSM8KBQQMXaRZc+K92RfBr2gszfGc/kTyMACihjJ xYV9UutMQ2s/WEtcdwA7NluYi15PRlZOaRDNEQpB93kFm9Ks3u8pgG00I+gIhbFqVTm1 j+gcmclVUkJ3wNT07O9LcB1xNMCzPUWs2DlClYUlU4aDyesl5ib84ezS5hoSlzzm7iNM x9f0Cb9YV2WbOms58WKM5xZrtAhEPxMxqRzq16tqeobI/xOiqf3dJFP2JHgczWitK2Kk /zl2W2ipX8mBKbtKZOIRhK/yopIhTgvLXAXLYRzgx+sLAYbfOEzHW3perFpgQMHFVE82 gbdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729038027; x=1729642827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=92VubGYyXALAVnQRA8GVr+urTCCGJBZXT1C9yLWdrMo=; b=Dmm+5WTjTQl395tn/KkZ4QDQ+i988WOOlhXzzlZd2zvHg8FxKUuRKd6za0no0yWnKx zb99UuOEJe5JF0El+ZlQIgeueOEydfYQVlGFY7MFeAfkqeqsOTJVbBIHz6+c2k2jeN7o UhiugJLiNocLNilU7P9kxK9+peJ9ssJAKygzKDo1049GXJ+lIrI2qOXHTNbAAXTKtJas jLZ2yeP8Nu5+G4HYto+8j38t7V34C2eNDcw6hplMrsSu1ms3A9LhCX0NkA50U2lmzRHL mbgNbRVkbtZMYgp+RqIm7jSycpM4eMJpxdWCk9RzoKdVRp/8vdam+UW3b6pQ66Hzb86Q qMDw== X-Forwarded-Encrypted: i=1; AJvYcCV+pREEiUIghwJo4yGBrJ0gYCBSjwkepzh9gr4X1XWwJr7Ji2xPQEJNvGUXbpVWBnZufvo5qJXH1tVv@vger.kernel.org, AJvYcCXRfo5AChQwRd2F5GMGDxR/gqhFR0QohOZz5HRT/dn8XmtOadXq3oPfGF+OI0aS/ggAcKVhsA3yQz2X@vger.kernel.org, AJvYcCXgMvTU+wTa+ckfCKp0dTaoB7Q3GKXTP4C3QeLLE50k5eNOrRbpyR7s5a9TE3TxvllXbt9TAiDND4Px3Adi@vger.kernel.org X-Gm-Message-State: AOJu0YxdCZDjRbjsZYr1d+/1Ul7VyYd9rS1llvzxAdLpdObute/rNm1m 0cID3zt4/3MgvxeC4Cj9UjN4CUiDaFn2y2/CaTuLYkEymvN33rom X-Google-Smtp-Source: AGHT+IGggwTQpU/fZt9x3V9eDWYPhRnofWhHB5l7vHyW3i3HG/9uWe1jwPwJPpk0YM/IQBBQqcKLgA== X-Received: by 2002:a05:6808:1a02:b0:3e4:d683:c242 with SMTP id 5614622812f47-3e5d220de87mr9263719b6e.15.1729038027519; Tue, 15 Oct 2024 17:20:27 -0700 (PDT) Received: from localhost.localdomain ([122.8.183.87]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e5e85e1c7fsm591950b6e.39.2024.10.15.17.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 17:20:26 -0700 (PDT) From: Chen Wang To: ukleinek@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, unicorn_wang@outlook.com, inochiama@outlook.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-riscv@lists.infradead.org, chao.wei@sophgo.com, haijiao.liu@sophgo.com, xiaoguang.xing@sophgo.com, chunzhi.lin@sophgo.com Subject: [PATCH v4 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM Date: Wed, 16 Oct 2024 08:20:18 +0800 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: Chen Wang Add a PWM driver for PWM controller in Sophgo SG2042 SoC. Signed-off-by: Chen Wang --- drivers/pwm/Kconfig | 10 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-sophgo-sg2042.c | 181 ++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 drivers/pwm/pwm-sophgo-sg2042.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 0915c1e7df16..ec85f3895936 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -584,6 +584,16 @@ config PWM_SL28CPLD To compile this driver as a module, choose M here: the module will be called pwm-sl28cpld. =20 +config PWM_SOPHGO_SG2042 + tristate "Sophgo SG2042 PWM support" + depends on ARCH_SOPHGO || COMPILE_TEST + help + PWM driver for the PWM controller on Sophgo SG2042 SoC. The PWM + controller supports outputing 4 channels of PWM waveforms. + + To compile this driver as a module, choose M here: the module + will be called pwm_sophgo_sg2042. + config PWM_SPEAR tristate "STMicroelectronics SPEAr PWM support" depends on PLAT_SPEAR || COMPILE_TEST diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 9081e0c0e9e0..539e0def3f82 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_PWM_RZ_MTU3) +=3D pwm-rz-mtu3.o obj-$(CONFIG_PWM_SAMSUNG) +=3D pwm-samsung.o obj-$(CONFIG_PWM_SIFIVE) +=3D pwm-sifive.o obj-$(CONFIG_PWM_SL28CPLD) +=3D pwm-sl28cpld.o +obj-$(CONFIG_PWM_SOPHGO_SG2042) +=3D pwm-sophgo-sg2042.o obj-$(CONFIG_PWM_SPEAR) +=3D pwm-spear.o obj-$(CONFIG_PWM_SPRD) +=3D pwm-sprd.o obj-$(CONFIG_PWM_STI) +=3D pwm-sti.o diff --git a/drivers/pwm/pwm-sophgo-sg2042.c b/drivers/pwm/pwm-sophgo-sg204= 2.c new file mode 100644 index 000000000000..bed753877851 --- /dev/null +++ b/drivers/pwm/pwm-sophgo-sg2042.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sophgo SG2042 PWM Controller Driver + * + * Copyright (C) 2024 Sophgo Technology Inc. + * Copyright (C) 2024 Chen Wang + * + * Limitations: + * - After reset, the output of the PWM channel is always high. + * The value of HLPERIOD/PERIOD is 0. + * - When HLPERIOD or PERIOD is reconfigured, PWM will start to + * output waveforms with the new configuration after completing + * the running period. + * - When PERIOD and HLPERIOD is set to 0, the PWM wave output will + * be stopped and the output is pulled to high. + */ + +#include +#include +#include +#include +#include +#include + +#include + +/* + * Offset RegisterName + * 0x0000 HLPERIOD0 + * 0x0004 PERIOD0 + * 0x0008 HLPERIOD1 + * 0x000C PERIOD1 + * 0x0010 HLPERIOD2 + * 0x0014 PERIOD2 + * 0x0018 HLPERIOD3 + * 0x001C PERIOD3 + * Four groups and every group is composed of HLPERIOD & PERIOD + */ +#define SG2042_HLPERIOD(chan) ((chan) * 8 + 0) +#define SG2042_PERIOD(chan) ((chan) * 8 + 4) + +#define SG2042_PWM_CHANNELNUM 4 + +/** + * struct sg2042_pwm_ddata - private driver data + * @base: base address of mapped PWM registers + * @clk_rate_hz: rate of base clock in HZ + */ +struct sg2042_pwm_ddata { + void __iomem *base; + unsigned long clk_rate_hz; +}; + +static void pwm_sg2042_config(void __iomem *base, unsigned int chan, u32 p= eriod, u32 hlperiod) +{ + writel(period, base + SG2042_PERIOD(chan)); + writel(hlperiod, base + SG2042_HLPERIOD(chan)); +} + +static int pwm_sg2042_apply(struct pwm_chip *chip, struct pwm_device *pwm, + const struct pwm_state *state) +{ + struct sg2042_pwm_ddata *ddata =3D pwmchip_get_drvdata(chip); + u32 hlperiod; + u32 period; + + if (state->polarity =3D=3D PWM_POLARITY_INVERSED) + return -EINVAL; + + if (!state->enabled) { + pwm_sg2042_config(ddata->base, pwm->hwpwm, 0, 0); + return 0; + } + + /* + * Period of High level (duty_cycle) =3D HLPERIOD x Period_clk + * Period of One Cycle (period) =3D PERIOD x Period_clk + */ + period =3D min(mul_u64_u64_div_u64(ddata->clk_rate_hz, state->period, NSE= C_PER_SEC), U32_MAX); + hlperiod =3D min(mul_u64_u64_div_u64(ddata->clk_rate_hz, state->duty_cycl= e, NSEC_PER_SEC), U32_MAX); + + if (hlperiod > period) { + dev_err(pwmchip_parent(chip), "period < hlperiod, failed to apply curren= t setting\n"); + return -EINVAL; + } + + dev_dbg(pwmchip_parent(chip), "chan[%u]: period=3D%u, hlperiod=3D%u\n", + pwm->hwpwm, period, hlperiod); + + pwm_sg2042_config(ddata->base, pwm->hwpwm, period, hlperiod); + + return 0; +} + +static int pwm_sg2042_get_state(struct pwm_chip *chip, struct pwm_device *= pwm, + struct pwm_state *state) +{ + struct sg2042_pwm_ddata *ddata =3D pwmchip_get_drvdata(chip); + unsigned int chan =3D pwm->hwpwm; + u32 hlperiod; + u32 period; + + period =3D readl(ddata->base + SG2042_PERIOD(chan)); + hlperiod =3D readl(ddata->base + SG2042_HLPERIOD(chan)); + + if (!period && !hlperiod) + state->enabled =3D false; + else + state->enabled =3D true; + + state->period =3D DIV_ROUND_UP_ULL((u64)period * NSEC_PER_SEC, ddata->clk= _rate_hz); + state->duty_cycle =3D DIV_ROUND_UP_ULL((u64)hlperiod * NSEC_PER_SEC, ddat= a->clk_rate_hz); + + state->polarity =3D PWM_POLARITY_NORMAL; + + return 0; +} + +static const struct pwm_ops pwm_sg2042_ops =3D { + .apply =3D pwm_sg2042_apply, + .get_state =3D pwm_sg2042_get_state, +}; + +static const struct of_device_id sg2042_pwm_ids[] =3D { + { .compatible =3D "sophgo,sg2042-pwm" }, + { } +}; +MODULE_DEVICE_TABLE(of, sg2042_pwm_ids); + +static int pwm_sg2042_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct sg2042_pwm_ddata *ddata; + struct pwm_chip *chip; + struct clk *clk; + int ret; + + chip =3D devm_pwmchip_alloc(dev, SG2042_PWM_CHANNELNUM, sizeof(*ddata)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + ddata =3D pwmchip_get_drvdata(chip); + + ddata->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(ddata->base)) + return PTR_ERR(ddata->base); + + clk =3D devm_clk_get_enabled(dev, "apb"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "failed to get base clk\n"); + + ret =3D devm_clk_rate_exclusive_get(dev, clk); + if (ret) + return dev_err_probe(dev, ret, "failed to get exclusive rate\n"); + + ddata->clk_rate_hz =3D clk_get_rate(clk); + if (!ddata->clk_rate_hz || ddata->clk_rate_hz > NSEC_PER_SEC) + return dev_err_probe(dev, -EINVAL, + "Invalid clock rate: %lu\n", ddata->clk_rate_hz); + + chip->ops =3D &pwm_sg2042_ops; + chip->atomic =3D true; + + ret =3D devm_pwmchip_add(dev, chip); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to register PWM chip\n"); + + return 0; +} + +static struct platform_driver pwm_sg2042_driver =3D { + .driver =3D { + .name =3D "sg2042-pwm", + .of_match_table =3D sg2042_pwm_ids, + }, + .probe =3D pwm_sg2042_probe, +}; +module_platform_driver(pwm_sg2042_driver); + +MODULE_AUTHOR("Chen Wang"); +MODULE_DESCRIPTION("Sophgo SG2042 PWM driver"); +MODULE_LICENSE("GPL"); --=20 2.34.1 From nobody Tue Nov 26 20:02:28 2024 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 B4A5021E3CD; Wed, 16 Oct 2024 00:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729038050; cv=none; b=jsCg1Qv7HpRsxolxyrrk0mHHeDWbFpbNeGQaHYr/JunhRgvHkvPcsZkKttBex8YqzxE9Css0XiUHLSZLbY9w1ZNXscP7vG6f3rF0xb/oKRGt7IM1FHrssZKjvpziabNTAWvao31Z98Yu+mvVqDlKQOIaAX1HAYzrUauyjZX6iSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729038050; c=relaxed/simple; bh=kuKctZJOjS2OUZaqeOyTGjg/MdoY3xFfnNR1RUfMJ0M=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RdyK2pvGZhDvEZEWlgZ6mzBZ8wMrJvmxUa/Thz/IEjsCiRzwBce9jV13poSvO1fHflxUZvfSB+pEgjnHg9lGViZGG8WFoFBE8OvruazNeflLV5Lbrj2xGoEnDDQl7eQAUO0upspACFMaNP1/mfMDUU4I3EZI54nZGwMPd3qHSXs= 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=b6tu7ny5; arc=none smtp.client-ip=209.85.160.44 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="b6tu7ny5" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-277e6002b7dso1712224fac.1; Tue, 15 Oct 2024 17:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729038048; x=1729642848; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=qVj0JZ+cVfOjaLAf/i9q4f7a0NWdixO3jwQiTDHespQ=; b=b6tu7ny5Hgpq1AAx/3orRn+Hbw12QPBwSxfogUVOkm3MgHJYmuqugXBUPfnH++hkhz euuWHYaCwG1+ykzecLn1fkTSTLCKbCKQVARJ4DpUj5By4udwGZR3j6ceG8f7H4m2nmh3 yKe3hG8+XSqzz/R8hx4ZcIuYu+m6asNAImOAlvz4S/XfOf02THpZcT5w+nhzSTTQbFer 6PCTjEniHeWCdTdM5JFY6KSJuOnGGcWidd/KEHrLkgM0x6uPy7rTKRUgO8Y0hR85kYwz zbDlafcKGd8XRgRhDRB8AR7LK6iY0zlp7BSfzT+A2rs3N+cgOfSrGZEvxyPcxA4BnahW umow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729038048; x=1729642848; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qVj0JZ+cVfOjaLAf/i9q4f7a0NWdixO3jwQiTDHespQ=; b=iQyTwaADcfOi2Shl9YsLwUs3PZTGL0Qf62uvxMeGBphmxje//sG5erh9Xbu+ZHWDi9 CDEqFJrcl1KSilSga1kcoFSd4LYHCfUqN17vjFecdvMnjJnBFDehsU6QJZcHXE4kxxAf uAMHyJYDCMTIcJmsbhSwxff8szPYOmC3Mptj10/8lAu8gPHkPuERA8IqFdxfu9puq/6V nEgnJ36sPnMNM9coF0LLrXSWYjLfflXKMuDEfECtfXhNUN8GDKseDHX0Lmr/swLIU9aS b2ev06DwMX1vWx4MKWVjQEYSGTCDdZ/7XiToRmIgqU4wRlZBtHQlm8+UNE0ni59pqVTL YVXQ== X-Forwarded-Encrypted: i=1; AJvYcCUZvhgpbzcNtCnFYu9XSSnFT/B4A2at9CaP3FmCAcKQCjyLMelL8vwecWDV3XBJ8mekscqgQ7olfR8U@vger.kernel.org, AJvYcCWWCXeagzDoYTtV/+slmfrKTQJ4wVfI1Zj+gu+PFAoYi0E4fVmfanRmvWJFqIUfJZw5V2FcmVqsiT/e2mGb@vger.kernel.org, AJvYcCXDIIctEjx9VIHjYDam+cIaaVQlPnYx3Gh8jMYwfz3pMI79QL+WDLA9I6JmmkNgqm+/x98Ac4KIKUsM@vger.kernel.org X-Gm-Message-State: AOJu0Yyki26XjEO3ejMcKeJM2DqksybXsfmwtrYt8+SG4vvtWNNZgN3l Siyiwh2DeCXgsAAmAIB8/GVAe3//L/nmp59EDQJ/S5I1LlXdU3pa X-Google-Smtp-Source: AGHT+IHvf7ouPtaSG82xKb3eFmMLOpPLuTSfsOfTvP7DU8b6q07TaVWaTqCFDJB3CQRdG09P+SIIXg== X-Received: by 2002:a05:6870:a692:b0:286:f24f:c231 with SMTP id 586e51a60fabf-28887376bfcmr7450243fac.25.1729038047659; Tue, 15 Oct 2024 17:20:47 -0700 (PDT) Received: from localhost.localdomain ([122.8.183.87]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-288dab8a172sm623857fac.6.2024.10.15.17.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 17:20:47 -0700 (PDT) From: Chen Wang To: ukleinek@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, unicorn_wang@outlook.com, inochiama@outlook.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-riscv@lists.infradead.org, chao.wei@sophgo.com, haijiao.liu@sophgo.com, xiaoguang.xing@sophgo.com, chunzhi.lin@sophgo.com Subject: [PATCH v4 3/3] riscv: sophgo: dts: add pwm controller for SG2042 SoC Date: Wed, 16 Oct 2024 08:20:40 +0800 Message-Id: <56550a6c9ba94c170d32b1f7c076b6faee42ae9f.1729037302.git.unicorn_wang@outlook.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: Chen Wang SG2042 has one PWM controller, which has 4 pwm output channels. Signed-off-by: Chen Wang --- arch/riscv/boot/dts/sophgo/sg2042.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/boot/dts/sophgo/sg2042.dtsi b/arch/riscv/boot/dts/s= ophgo/sg2042.dtsi index 4e5fa6591623..048792b30617 100644 --- a/arch/riscv/boot/dts/sophgo/sg2042.dtsi +++ b/arch/riscv/boot/dts/sophgo/sg2042.dtsi @@ -165,6 +165,14 @@ port2a: gpio-controller@0 { }; }; =20 + pwm: pwm@703000c000 { + compatible =3D "sophgo,sg2042-pwm"; + reg =3D <0x70 0x3000c000 0x0 0x20>; + #pwm-cells =3D <2>; + clocks =3D <&clkgen GATE_CLK_APB_PWM>; + clock-names =3D "apb"; + }; + pllclk: clock-controller@70300100c0 { compatible =3D "sophgo,sg2042-pll"; reg =3D <0x70 0x300100c0 0x0 0x40>; --=20 2.34.1