Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp14935lqk; Fri, 8 Mar 2024 21:21:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV96vtfUEBNkAqQhFPqWvuqPGlRbVjSOVM4M0r6TdRAi4aq92cvontastHKG7LR3qC6OoG8tPbjsYNnjluI55xaTfu0oxAFg6zJoLSbVA== X-Google-Smtp-Source: AGHT+IHZfVPRllOfMYISmGCFu8lSx/2ggLm3+ffIPdyh1UjoHTf8R0CTlzuibrhvbco5B7vIeBvt X-Received: by 2002:a17:902:d2c9:b0:1db:47bb:671b with SMTP id n9-20020a170902d2c900b001db47bb671bmr1198638plc.19.1709961711270; Fri, 08 Mar 2024 21:21:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709961711; cv=pass; d=google.com; s=arc-20160816; b=R93zlyvcQrdSI17c3hKWlVy4SK7PY8Mcg6wfFxI8/WqCD5WRoTIkudr2bMQcy9tBR0 s959wCqJgE6AfnJJ3L9ZJQ07gcD9fGRTdKjwmTZHNgs3scaz3JPcKbdGtIS0Ur7qkIbv /05TijlfhdikG26XqyiKkwtrMMtgtb3aUh5vn9xOBVvPY+hQnWVPaypzAMk8u/bt0Jni G+XJU2kJDTGO5UjkOizSr+VRQZxLCE4UXEYBIaYhXyTBy1tbLi6sosgDZdESscpG0tBc 7dr2CbmY4Q6FcTcSpe7dO+c1wjrojFF2TFkgG/zRTVAX9Y75Mk3TVmumf6AbiZ1yY0cS iacQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:date:to:cc:from:subject:references:in-reply-to :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:dkim-signature; bh=wUPNEyPcGKK3Y23q1FLg3Bf+LjrV+OWZVNOq8rzQRjQ=; fh=5szMMver4I4jIQK96fxChvB/sydH4WzR9y/pG8xn9bs=; b=nTl5Qe+BQu2r5CxDlfLFUpQnhSOLAWfgRrD8hgsiwAI9xcAP6SyrmK1vbNVxC8WMnV 4tPPklw+4mh6tU0L2i6l8V3OtZgUjVyG603RHXTrWxkPw2DvwMB45NcDdbnwRGWhCQa5 14TRtmbUfZ/48Tiw+jj+A+6DvTWImer02ujcGTb2OtUnHhbOI4yRNEMMTYCJbpZVvMP7 kVVJsZ5qOrXVwiKq/BJSAe86LhqCiQheBcKmUULH39q8VBOJDSgBrIA1vGgdUsypTu/D juBU/XhS2Qw1sPnUoyTkzocXiytZ3CJyKs2Blr/EM639xEyJCkej6qu2tCZRj0sWod1W OtfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="GZx0C8/z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97778-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n17-20020a170903111100b001d9b8bc0fd8si835429plh.68.2024.03.08.21.21.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 21:21:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97778-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="GZx0C8/z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97778-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B4AD6B21250 for ; Sat, 9 Mar 2024 05:21:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5F0133070; Sat, 9 Mar 2024 05:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GZx0C8/z" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC279B656; Sat, 9 Mar 2024 05:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709961697; cv=none; b=j9lTh0CyAz5DYuxH7mG5EvTOGAN1E8l/E0Bf1/Gv3uY19ebYdsl+xELZhUCOn+cWG7etSnBXaLiT3YAQdl7eZnbcRB5SNKJCseQVK+/YE+qUFuObeL05cL+NZ6S+gK/PKRJTI9jWh+UxvjaeopWkZKkYf7OmTuGzsFm1yN3R48E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709961697; c=relaxed/simple; bh=tqY4JVDtTjXz4kbJkAYJ+KcUDc570PmGen8k2hpbpBU=; h=Message-ID:Content-Type:MIME-Version:In-Reply-To:References: Subject:From:Cc:To:Date; b=rsfeeISM9m8Z7VnXuwmUkGHUrIQjPUK1dBfwoOlvwQGwEEVIV+HUVh1EAvjyf4IDglntIN19hO1VZUoWLMRZEF5KvDxuqk0s35vNgCoLB3txC6Wj+gRy1L3oJYRcScngmJtmZl8HRStzODP/fH0UWU9Sk1kZ+9LYq5kKjSzFVPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GZx0C8/z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14F34C433C7; Sat, 9 Mar 2024 05:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709961697; bh=tqY4JVDtTjXz4kbJkAYJ+KcUDc570PmGen8k2hpbpBU=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=GZx0C8/zLHn49Fbe/alM0hhq763Bha3aaoB2N6cdez2gYXeDO/sdP/ZFaPqP3+nuV TFl0tGNmoLp57fFvStiBZ2KqEO6lzOBI2lHFNXOJeb6DLhG7AweD99XR+04NW4OMrm fLCCAx+wC31Tro+Iw9umL2ObeIIOjjSxtgFk+c0/hin+gkRjL5vtc3U1jImCud2lkk EGLZeAA+ryX8oTaMW2lYmw7qLOzkPZOtKx3aYlUfpz82gONLC7QNSiOwVKccUmiizc Mle405ajB6zi0AnP4rpGlqxwSuZ7ASCwFTtyOvrXwnzj1z1mHfhr206Aj4e+J/kG6t xK6ml6v16AOEw== Message-ID: <55a896bcb94af629bb58c304268ac7ec.sboyd@kernel.org> Content-Type: text/plain; charset="utf-8" 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 In-Reply-To: References: Subject: Re: [PATCH v8 2/8] clk: sophgo: Add CV1800/SG2000 series clock controller driver skeleton From: Stephen Boyd Cc: Jisheng Zhang , Liu Gui , Jingbao Qiu , dlan@gentoo.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org To: Albert Ou , Chao Wei , Chen Wang , Conor Dooley , Inochi Amaoto , Krzysztof Kozlowski , Michael Turquette , Palmer Dabbelt , Paul Walmsley , Rob Herring Date: Fri, 08 Mar 2024 21:21:34 -0800 User-Agent: alot/0.10 Quoting Inochi Amaoto (2024-02-13 00:22:34) > diff --git a/drivers/clk/sophgo/Kconfig b/drivers/clk/sophgo/Kconfig > new file mode 100644 > index 000000000000..d67009fa749f > --- /dev/null > +++ b/drivers/clk/sophgo/Kconfig > @@ -0,0 +1,12 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# common clock support for SOPHGO SoC family. > + > +config CLK_SOPHGO_CV1800 > + tristate "Support for the Sophgo CV1800 series SoCs clock control= ler" > + default m Please remove any default and set it in the defconfig instead. > + depends on ARCH_SOPHGO || COMPILE_TEST > + help > + This driver supports clock controller of Sophgo CV18XX series S= oC. > + The driver require a 25MHz Oscillator to function generate cloc= k. > + It includes PLLs, common clock function and some vendor clock f= or > + IPs of CV18XX series SoC > diff --git a/drivers/clk/sophgo/clk-cv1800.c b/drivers/clk/sophgo/clk-cv1= 800.c > new file mode 100644 > index 000000000000..7183e67f20bf > --- /dev/null > +++ b/drivers/clk/sophgo/clk-cv1800.c > @@ -0,0 +1,113 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2023 Inochi Amaoto > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include "clk-cv18xx-common.h" > + > +struct cv1800_clk_ctrl; > + > +struct cv1800_clk_desc { > + struct clk_hw_onecell_data *clks_data; > + > + int (*pre_init)(struct device *dev, void __iomem *base, > + struct cv1800_clk_ctrl *ctrl, > + const struct cv1800_clk_desc *desc); > +}; > + > +struct cv1800_clk_ctrl { > + const struct cv1800_clk_desc *desc; > + spinlock_t lock; > +}; > + > +static int cv1800_clk_init_ctrl(struct device *dev, void __iomem *reg, > + struct cv1800_clk_ctrl *ctrl, > + const struct cv1800_clk_desc *desc) > +{ > + int i, ret; > + > + ctrl->desc =3D desc; > + spin_lock_init(&ctrl->lock); > + > + for (i =3D 0; i < desc->clks_data->num; i++) { > + struct clk_hw *hw =3D desc->clks_data->hws[i]; > + struct cv1800_clk_common *common; > + const char *name; > + > + if (!hw) > + continue; > + > + name =3D hw->init->name; > + > + common =3D hw_to_cv1800_clk_common(hw); > + common->base =3D reg; > + common->lock =3D &ctrl->lock; > + > + ret =3D devm_clk_hw_register(dev, hw); > + if (ret) { > + dev_err(dev, "Couldn't register clock %d - %s\n", > + i, name); > + return ret; > + } > + } > + > + ret =3D devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, > + desc->clks_data); > + > + return ret; Just return devm... > +} > + > +static int cv1800_clk_probe(struct platform_device *pdev) > +{ > + struct device *dev =3D &pdev->dev; > + void __iomem *reg; > + int ret; > + const struct cv1800_clk_desc *desc; > + struct cv1800_clk_ctrl *ctrl; > + > + reg =3D devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(reg)) > + return PTR_ERR(reg); > + > + desc =3D device_get_match_data(dev); > + if (!desc) { > + dev_err(dev, "no match data for platform\n"); > + return -EINVAL; > + } > + > + ctrl =3D devm_kmalloc(dev, sizeof(*ctrl), GFP_KERNEL); Why not devm_kzalloc? > + if (!ctrl) > + return -ENOMEM; > + > + if (desc->pre_init) { > + ret =3D desc->pre_init(dev, reg, ctrl, desc); > + if (ret) > + return ret; > + } > + > + ret =3D cv1800_clk_init_ctrl(dev, reg, ctrl, desc); > + > + return ret; This is return cv1800_clk_init_ctrl(... > +} > + > +static const struct of_device_id cv1800_clk_ids[] =3D { > + { } Don't do this. Just send the whole driver as one patch. > +}; > +MODULE_DEVICE_TABLE(of, cv1800_clk_ids); > + > +static struct platform_driver cv1800_clk_driver =3D { > + .probe =3D cv1800_clk_probe, > + .driver =3D { > + .name =3D "cv1800-clk", > + .suppress_bind_attrs =3D true, > + .of_match_table =3D cv1800_clk_ids, > + }, > +}; > +module_platform_driver(cv1800_clk_driver); > +MODULE_LICENSE("GPL"); > diff --git a/drivers/clk/sophgo/clk-cv18xx-common.c b/drivers/clk/sophgo/= clk-cv18xx-common.c > new file mode 100644 > index 000000000000..cbcdd88f0e23 > --- /dev/null > +++ b/drivers/clk/sophgo/clk-cv18xx-common.c > @@ -0,0 +1,66 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2023 Inochi Amaoto > + */ > + > +#include > +#include > +#include > +#include > + > +#include "clk-cv18xx-common.h" > + > +int cv1800_clk_setbit(struct cv1800_clk_common *common, > + struct cv1800_clk_regbit *field) > +{ > + u32 mask =3D BIT(field->shift); > + u32 value; > + unsigned long flags; > + > + spin_lock_irqsave(common->lock, flags); > + > + value =3D readl(common->base + field->reg); > + writel(value | mask, common->base + field->reg); > + > + spin_unlock_irqrestore(common->lock, flags); > + > + return 0; > +} > + > +int cv1800_clk_clearbit(struct cv1800_clk_common *common, > + struct cv1800_clk_regbit *field) > +{ > + u32 mask =3D BIT(field->shift); > + u32 value; > + unsigned long flags; > + > + spin_lock_irqsave(common->lock, flags); > + > + value =3D readl(common->base + field->reg); > + writel(value & ~mask, common->base + field->reg); > + > + spin_unlock_irqrestore(common->lock, flags); > + > + return 0; > +} > + > +int cv1800_clk_checkbit(struct cv1800_clk_common *common, > + struct cv1800_clk_regbit *field) > +{ > + return readl(common->base + field->reg) & BIT(field->shift); > +} > + > +#define PLL_LOCK_TIMEOUT_US (200 * 1000) > + > +void cv1800_clk_wait_for_lock(struct cv1800_clk_common *common, > + u32 reg, u32 lock) > +{ > + void __iomem *addr =3D common->base + reg; > + u32 regval; > + > + if (!lock) > + return; > + > + WARN_ON(readl_relaxed_poll_timeout(addr, regval, regval & lock, > + 100, PLL_LOCK_TIMEOUT_US)); > +} > diff --git a/drivers/clk/sophgo/clk-cv18xx-common.h b/drivers/clk/sophgo/= clk-cv18xx-common.h > new file mode 100644 > index 000000000000..2bfda02b2064 > --- /dev/null > +++ b/drivers/clk/sophgo/clk-cv18xx-common.h > @@ -0,0 +1,81 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2023 Inochi Amaoto > + */ > + > +#ifndef _CLK_SOPHGO_CV18XX_IP_H_ > +#define _CLK_SOPHGO_CV18XX_IP_H_ > + > +#include > +#include > +#include > + > +struct cv1800_clk_common { > + void __iomem *base; > + spinlock_t *lock; > + struct clk_hw hw; > + unsigned long features; > +}; > + > +#define CV1800_CLK_COMMON(_name, _parents, _op, _flags) = \ > + { \ > + .hw.init =3D CLK_HW_INIT_PARENTS_DATA(_name, _parents, = \ > + _op, _flags), \ > + } > + > +static inline struct cv1800_clk_common * > +hw_to_cv1800_clk_common(struct clk_hw *hw) > +{ > + return container_of(hw, struct cv1800_clk_common, hw); > +} > + > +struct cv1800_clk_regbit { > + u16 reg; > + s8 shift; > +}; > + > +struct cv1800_clk_regfield { > + u16 reg; > + u8 shift; > + u8 width; > + s16 initval; > + unsigned long flags; > +}; > + > +#define CV1800_CLK_BIT(_reg, _shift) \ > + { \ > + .reg =3D _reg, \ > + .shift =3D _shift, \ > + } > + > +#define CV1800_CLK_REG(_reg, _shift, _width, _initval, _flags) \ > + { \ > + .reg =3D _reg, \ > + .shift =3D _shift, \ > + .width =3D _width, \ > + .initval =3D _initval, \ > + .flags =3D _flags, \ > + } > + > +#define cv1800_clk_regfield_genmask(_reg) \ > + GENMASK((_reg)->shift + (_reg)->width - 1, (_reg)->shift) > +#define cv1800_clk_regfield_get(_val, _reg) \ > + (((_val) >> (_reg)->shift) & GENMASK((_reg)->width - 1, 0)) > +#define cv1800_clk_regfield_set(_val, _new, _reg) \ > + (((_val) & ~cv1800_clk_regfield_genmask((_reg))) | \ > + (((_new) & GENMASK((_reg)->width - 1, 0)) << (_reg)->shift)) > + > +#define _CV1800_SET_FIELD(_reg, _val, _field) \ > + (((_reg) & ~(_field)) | FIELD_PREP((_field), (_val))) > + > +int cv1800_clk_setbit(struct cv1800_clk_common *common, > + struct cv1800_clk_regbit *field); > +int cv1800_clk_clearbit(struct cv1800_clk_common *common, > + struct cv1800_clk_regbit *field); > +int cv1800_clk_checkbit(struct cv1800_clk_common *common, > + struct cv1800_clk_regbit *field); > + > +void cv1800_clk_wait_for_lock(struct cv1800_clk_common *common, > + u32 reg, u32 lock); > + > +#endif // _CLK_SOPHGO_CV18XX_IP_H_ > diff --git a/drivers/clk/sophgo/clk-cv18xx-ip.c b/drivers/clk/sophgo/clk-= cv18xx-ip.c > new file mode 100644 > index 000000000000..cd397d102442 > --- /dev/null > +++ b/drivers/clk/sophgo/clk-cv18xx-ip.c > @@ -0,0 +1,98 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2023 Inochi Amaoto > + */ > + > +#include > +#include > +#include > +#include > + > +#include "clk-cv18xx-ip.h" > + > +/* GATE */ > +const struct clk_ops cv1800_clk_gate_ops =3D { > + .disable =3D NULL, > + .enable =3D NULL, > + .is_enabled =3D NULL, > + > + .recalc_rate =3D NULL, > + .round_rate =3D NULL, > + .set_rate =3D NULL, > +}; Everything is NULL. What are you trying to do? Point out what will come later? Please squash patches. > + > +/* DIV */ > +const struct clk_ops cv1800_clk_div_ops =3D { > + .disable =3D NULL, > + .enable =3D NULL, > + .is_enabled =3D NULL, > + > + .determine_rate =3D NULL, > + .recalc_rate =3D NULL, > + .set_rate =3D NULL, > +}; > + > +const struct clk_ops cv1800_clk_bypass_div_ops =3D { > + .disable =3D NULL, > + .enable =3D NULL, > + .is_enabled =3D NULL, > + > + .determine_rate =3D NULL,