pwm: mtk: add support for MediaTek MT7981 SoC
authorWeijie Gao <weijie.gao@mediatek.com>
Fri, 9 Sep 2022 11:59:38 +0000 (19:59 +0800)
committerTom Rini <trini@konsulko.com>
Fri, 23 Sep 2022 19:09:15 +0000 (15:09 -0400)
This patch adds PWM support for MediaTek MT7981 SoC.
MT7981 uses a different register offset so we have to add a version field
to indicate the IP core version.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
drivers/pwm/pwm-mtk.c

index 3100b5c..605142e 100644 (file)
 
 #define NSEC_PER_SEC 1000000000L
 
-static const unsigned int mtk_pwm_reg_offset[] = {
+enum mtk_pwm_reg_ver {
+       PWM_REG_V1,
+       PWM_REG_V2,
+};
+
+static const unsigned int mtk_pwm_reg_offset_v1[] = {
        0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220
 };
 
+static const unsigned int mtk_pwm_reg_offset_v2[] = {
+       0x0080, 0x00c0, 0x0100, 0x0140, 0x0180, 0x01c0, 0x0200, 0x0240
+};
+
 struct mtk_pwm_soc {
        unsigned int num_pwms;
        bool pwm45_fixup;
+       enum mtk_pwm_reg_ver reg_ver;
 };
 
 struct mtk_pwm_priv {
@@ -49,7 +59,16 @@ struct mtk_pwm_priv {
 static void mtk_pwm_w32(struct udevice *dev, uint channel, uint reg, uint val)
 {
        struct mtk_pwm_priv *priv = dev_get_priv(dev);
-       u32 offset = mtk_pwm_reg_offset[channel];
+       u32 offset;
+
+       switch (priv->soc->reg_ver) {
+       case PWM_REG_V2:
+               offset = mtk_pwm_reg_offset_v2[channel];
+               break;
+
+       default:
+               offset = mtk_pwm_reg_offset_v1[channel];
+       }
 
        writel(val, priv->base + offset + reg);
 }
@@ -159,27 +178,38 @@ static const struct pwm_ops mtk_pwm_ops = {
 static const struct mtk_pwm_soc mt7622_data = {
        .num_pwms = 6,
        .pwm45_fixup = false,
+       .reg_ver = PWM_REG_V1,
 };
 
 static const struct mtk_pwm_soc mt7623_data = {
        .num_pwms = 5,
        .pwm45_fixup = true,
+       .reg_ver = PWM_REG_V1,
 };
 
 static const struct mtk_pwm_soc mt7629_data = {
        .num_pwms = 1,
        .pwm45_fixup = false,
+       .reg_ver = PWM_REG_V1,
+};
+
+static const struct mtk_pwm_soc mt7981_data = {
+       .num_pwms = 2,
+       .pwm45_fixup = false,
+       .reg_ver = PWM_REG_V2,
 };
 
 static const struct mtk_pwm_soc mt7986_data = {
        .num_pwms = 2,
        .pwm45_fixup = false,
+       .reg_ver = PWM_REG_V1,
 };
 
 static const struct udevice_id mtk_pwm_ids[] = {
        { .compatible = "mediatek,mt7622-pwm", .data = (ulong)&mt7622_data },
        { .compatible = "mediatek,mt7623-pwm", .data = (ulong)&mt7623_data },
        { .compatible = "mediatek,mt7629-pwm", .data = (ulong)&mt7629_data },
+       { .compatible = "mediatek,mt7981-pwm", .data = (ulong)&mt7981_data },
        { .compatible = "mediatek,mt7986-pwm", .data = (ulong)&mt7986_data },
        { }
 };