Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp418539rdh; Wed, 23 Aug 2023 04:11:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQrKgThOjRSwGRLKP954Xo5WeLZSna355xXywY55hkO6Vr40YYtA4Q+i0lFwU4pEOiPQJ6 X-Received: by 2002:a05:6402:505:b0:522:2d1b:5a38 with SMTP id m5-20020a056402050500b005222d1b5a38mr9212895edv.10.1692789089943; Wed, 23 Aug 2023 04:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692789089; cv=none; d=google.com; s=arc-20160816; b=ggAbO7tOdn313BFa7pvBzDaSyQsIrbMUlCoLzMnTptzkNVgU4SQgwSh4EUOuyVGl/p 2TKybil8/CzMel6fQ/9zeF6MyeLItTlh7mpwvxsAwWdHbJnUKFttaHeEnTQ3j7c8i0o0 71YP9ai2jbWAZFUiabk45cYrqDZNn15XyE0Xzra9K8bErci6vf+E/RSWeEyVFDTeEgZr yw3qm8DbGzgVjjp6SaDhPwLrJ9a09Gmms94KQra/Z6AzLynsaZgftJbPsdmpKEFwm3Hh SBLt3J2h091DFguIpyjv1j0DafN8obPUPQDOcZDs3JyvwmBPCfZySm8hFUldhJ3NMsIC kXvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:date:to:from:subject:references :in-reply-to:content-transfer-encoding:mime-version:message-id :dkim-signature; bh=kbIGMI+yOeAMYM2x+TITbzJJmO09Ek3aw68Y59IEOk8=; fh=bEvpF5nDeQxSh8JcoVzTENnLDEpFa4DcgCuUs3KZN6E=; b=DnVravIwku7itArwLzQLYHi+JC8+6LPdviUxdl2jsnUgrnRkmrnG2pZFmQ01mFlKRV c3qF6UYW19quKm1g0QwJTCAtSCVCuT6AsgT1F8m8GT/e/aNh3UxJw2zNqm6bWimOF02U 4UqcxGT9JE19vf0Nku+NXgoXxVDs5Z4JY3G1qqH7ZDP558fLwhr2dh0mUTE6gvJoE9IF oIFeJP81Db1oJ/8p+MPgSAXWAsDoKRGFkKWreY/VImyTbm+5kPcA4VumFLSPWpQMEr58 S04vUSJd+hM1txeHsk6rMiU8XxNLeN2PVSjD035+G9P+AH1Lc4XbRPR781SHzpan0teO jHTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jBpfAZt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f22-20020a056402151600b0052a02511a88si5786602edw.507.2023.08.23.04.11.05; Wed, 23 Aug 2023 04:11:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jBpfAZt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231408AbjHVWfP (ORCPT + 99 others); Tue, 22 Aug 2023 18:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbjHVWfO (ORCPT ); Tue, 22 Aug 2023 18:35:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F130CF3; Tue, 22 Aug 2023 15:35:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D048640C5; Tue, 22 Aug 2023 22:35:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78BDEC433C8; Tue, 22 Aug 2023 22:35:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692743701; bh=4SThI4EuvWqgq7E+zQ8jIRtu4s3TqWYlc6rSEHWhW2A=; h=In-Reply-To:References:Subject:From:To:Date:From; b=jBpfAZt/tgAt+HicTIQMspA3O2cEENT8yfaXkJ+ffJEIJWl+thpOST8iijaIPUZ9c Cdoz51qVhWp9xkpvGGvS+sEqccoAygqpo/KeR/sRg3ENglyFBV1+t6mWUIC6CSvcqo 6mqbBjGA216DZ1UDJwHjiuBtPpNsqeRs20/4TdTTUiTJIFmHHc1Che+sJrhZpOIH3M oVQeIPG6a8jsb6wC2GwqxHBeiryZ36ggDHYrs21BnE2u1c8a6cs9kvEh1ph6v+3MH9 /yU4HWSUfP2ZK4UuT1kxxvJHINQiQc7vcH0G5hNQLUGJoIC+ea6oS1cbYxHZYz2iof 9Mv5xTVgDt3Vw== Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20230819134147.456060-3-andreas@kemnade.info> References: <20230819134147.456060-1-andreas@kemnade.info> <20230819134147.456060-3-andreas@kemnade.info> Subject: Re: [PATCH 2/3] clk: twl: add clock driver for TWL6032 From: Stephen Boyd To: andreas@kemnade.info, bcousson@baylibre.com, conor+dt@kernel.org, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, mturquette@baylibre.com, robh+dt@kernel.org, tony@atomide.com Date: Tue, 22 Aug 2023 15:34:59 -0700 User-Agent: alot/0.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Andreas Kemnade (2023-08-19 06:41:46) > diff --git a/drivers/clk/clk-twl.c b/drivers/clk/clk-twl.c > new file mode 100644 > index 0000000000000..deb5742393bac > --- /dev/null > +++ b/drivers/clk/clk-twl.c > @@ -0,0 +1,205 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Clock driver for twl device. > + * > + * inspired by the driver for the Palmas device > + */ > + > +#include Is this include used? Hopefully not. Please drop. > +#include > +#include > +#include > +#include > +#include Is this include used? > +#include > +#include > + > +#define VREG_STATE 2 > +#define TWL6030_CFG_STATE_OFF 0x00 > +#define TWL6030_CFG_STATE_ON 0x01 > +#define TWL6030_CFG_STATE_MASK 0x03 > + > +struct twl_clk32k_desc { > + const char *clk_name; > + u8 base; > +}; > + > +struct twl_clock_info { > + struct device *dev; > + struct clk_hw hw; > + const struct twl_clk32k_desc *clk_desc; > +}; > + > +static inline int > +twlclk_read(struct twl_clock_info *info, unsigned int slave_subgp, > + unsigned int offset) > +{ > + u8 value; > + int status; > + > + status =3D twl_i2c_read_u8(slave_subgp, &value, > + info->clk_desc->base + offset); > + return (status < 0) ? status : value; > +} > + > +static inline int > +twlclk_write(struct twl_clock_info *info, unsigned int slave_subgp, > + unsigned int offset, u8 value) > +{ > + return twl_i2c_write_u8(slave_subgp, value, > + info->clk_desc->base + offset); > +} > + > +static inline struct twl_clock_info *to_twl_clks_info(struct clk_hw *hw) > +{ > + return container_of(hw, struct twl_clock_info, hw); > +} > + > +static unsigned long twl_clks_recalc_rate(struct clk_hw *hw, > + unsigned long parent_rate) > +{ > + return 32768; > +} > + > +static int twl6032_clks_prepare(struct clk_hw *hw) > +{ > + struct twl_clock_info *cinfo =3D to_twl_clks_info(hw); > + int ret; > + > + ret =3D twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE, > + TWL6030_CFG_STATE_ON); > + if (ret < 0) > + dev_err(cinfo->dev, "clk prepare failed\n"); > + > + return ret; > +} > + > +static void twl6032_clks_unprepare(struct clk_hw *hw) > +{ > + struct twl_clock_info *cinfo =3D to_twl_clks_info(hw); > + int ret; > + > + ret =3D twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE, > + TWL6030_CFG_STATE_OFF); > + if (ret < 0) > + dev_err(cinfo->dev, "clk unprepare failed\n"); > +} > + > +static int twl6032_clks_is_prepared(struct clk_hw *hw) > +{ > + struct twl_clock_info *cinfo =3D to_twl_clks_info(hw); > + int val; > + > + val =3D twlclk_read(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE); > + if (val < 0) { > + dev_err(cinfo->dev, "clk read failed\n"); > + return val; > + } > + > + val &=3D TWL6030_CFG_STATE_MASK; > + > + return val =3D=3D TWL6030_CFG_STATE_ON; > +} > + > +static const struct clk_ops twl6032_clks_ops =3D { > + .prepare =3D twl6032_clks_prepare, > + .unprepare =3D twl6032_clks_unprepare, > + .is_prepared =3D twl6032_clks_is_prepared, > + .recalc_rate =3D twl_clks_recalc_rate, > +}; > + > +struct twl_clks_of_match_data { > + struct clk_init_data init; > + const struct twl_clk32k_desc desc; > +}; > + > +static const struct twl_clks_of_match_data twl6032_of_clk32kg =3D { > + .init =3D { > + .name =3D "clk32kg", > + .ops =3D &twl6032_clks_ops, > + .flags =3D CLK_IGNORE_UNUSED, > + }, > + .desc =3D { > + .clk_name =3D "clk32kg", > + .base =3D 0x8C, > + }, > +}; > + > +static const struct twl_clks_of_match_data twl6032_of_clk32kaudio =3D { > + .init =3D { > + .name =3D "clk32kaudio", > + .ops =3D &twl6032_clks_ops, > + .flags =3D CLK_IGNORE_UNUSED, > + }, > + .desc =3D { > + .clk_name =3D "clk32kaudio", > + .base =3D 0x8F, > + }, > +}; > + > +static const struct of_device_id twl_clks_of_match[] =3D { > + { > + .compatible =3D "ti,twl6032-clk32kg", > + .data =3D &twl6032_of_clk32kg, > + }, > + { > + .compatible =3D "ti,twl6032-clk32kaudio", > + .data =3D &twl6032_of_clk32kaudio, > + }, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, twl_clks_of_match); This array can be moved next to the driver so that it isn't tempting to access the variable directly. > + > +static int twl_clks_probe(struct platform_device *pdev) > +{ > + struct device_node *node =3D pdev->dev.of_node; > + const struct twl_clks_of_match_data *match_data; > + struct twl_clock_info *cinfo; > + int ret; > + > + match_data =3D of_device_get_match_data(&pdev->dev); Use device_get_match_data() instead. > + if (!match_data) > + return 1; > + > + cinfo =3D devm_kzalloc(&pdev->dev, sizeof(*cinfo), GFP_KERNEL); > + if (!cinfo) > + return -ENOMEM; > + > + platform_set_drvdata(pdev, cinfo); > + > + cinfo->dev =3D &pdev->dev; > + > + cinfo->clk_desc =3D &match_data->desc; > + cinfo->hw.init =3D &match_data->init; > + ret =3D devm_clk_hw_register(&pdev->dev, &cinfo->hw); > + if (ret) { > + dev_err(&pdev->dev, "Fail to register clock %s, %d\n", > + match_data->desc.clk_name, ret); > + return ret; > + } > + > + ret =3D of_clk_add_hw_provider(node, of_clk_hw_simple_get, &cinfo= ->hw); Use devm? > + if (ret < 0) > + dev_err(&pdev->dev, "Fail to add clock driver, %d\n", ret= ); > + return ret; > +} > + > +static void twl_clks_remove(struct platform_device *pdev) > +{ > + of_clk_del_provider(pdev->dev.of_node); > +} And get rid of this entirely? > + > +static struct platform_driver twl_clks_driver =3D { > + .driver =3D { > + .name =3D "twl-clk", > + .of_match_table =3D twl_clks_of_match, > + }, > + .probe =3D twl_clks_probe, > + .remove_new =3D twl_clks_remove, > +}; > + > +module_platform_driver(twl_clks_driver); > + > +MODULE_DESCRIPTION("Clock driver for TWL Series Devices"); > +MODULE_ALIAS("platform:twl-clk"); This alias is unnecessary? > +MODULE_LICENSE("GPL");