From: Matti Vaittinen <mazziesaccount@gmail.com> To: Sebastian Reichel <sebastian.reichel@collabora.com>, Heiko Stuebner <heiko@sntech.de>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Lee Jones <lee@kernel.org> Cc: Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org>, Linus Walleij <linus.walleij@linaro.org>, Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>, Alexandre Belloni <alexandre.belloni@bootlin.com>, Alessandro Zummo <a.zummo@towertech.it>, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, shengfei Xu <xsf@rock-chips.com> Subject: Re: [PATCHv2 12/13] regulator: rk808: add rk806 support Date: Thu, 8 Sep 2022 10:45:40 +0300 [thread overview] Message-ID: <88f6110b-94b7-484d-cc37-d7f72c88090a@gmail.com> (raw) In-Reply-To: <20220908003107.220143-13-sebastian.reichel@collabora.com> On 9/8/22 03:31, Sebastian Reichel wrote: > Add rk806 support to the existing rk808 regulator > driver. > > This has been implemented using shengfei Xu's rk806 > specific driver from the vendor tree as reference. > > Co-Developed-by: shengfei Xu <xsf@rock-chips.com> > Signed-off-by: shengfei Xu <xsf@rock-chips.com> > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> > --- > drivers/regulator/rk808-regulator.c | 482 ++++++++++++++++++++++++++++ > 1 file changed, 482 insertions(+) > > diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c > index fa9fc1aa1ae3..cd1a2cff4a37 100644 > --- a/drivers/regulator/rk808-regulator.c > +++ b/drivers/regulator/rk808-regulator.c Thanks for upstreaming the downstream stuff! :) I wonder if we could drop some code by using the existing helpers? Or maybe I am missreading some code. Wouldn't be the first (and probably not the last) time... //snip > struct rk808_regulator_data { > struct gpio_desc *dvs_gpio[2]; > }; > @@ -216,6 +271,223 @@ static const unsigned int rk817_buck1_4_ramp_table[] = { > 3000, 6300, 12500, 25000 > }; > > +static int rk806_get_voltage_sel_regmap(struct regulator_dev *rdev) > +{ > + unsigned int val; > + int vsel_reg, ret; > + > + vsel_reg = rdev->desc->vsel_reg; > + > + ret = regmap_read(rdev->regmap, vsel_reg, &val); > + if (ret != 0) > + return ret; > + > + val &= rdev->desc->vsel_mask; > + val >>= ffs(rdev->desc->vsel_mask) - 1; > + > + return val; > +} Could we just use the regulator_get_voltage_sel_regmap()? > + > +static int rk806_set_voltage(struct regulator_dev *rdev, > + int req_min_uV, int req_max_uV, > + unsigned int *selector) > +{ > + int vsel_reg, ret, sel; > + > + ret = regulator_map_voltage_linear_range(rdev, req_min_uV, req_max_uV); > + if (ret >= 0) { > + *selector = ret; > + sel = ret; > + } else { > + return -EINVAL; > + } > + > + vsel_reg = rdev->desc->vsel_reg; > + > + sel <<= ffs(rdev->desc->vsel_mask) - 1; > + > + ret = regmap_update_bits(rdev->regmap, vsel_reg, > + rdev->desc->vsel_mask, sel); > + > + return ret; > +} Hmm. Maybe this is not necessary? I wonder if we could get away just with the .map and .set_voltage_sel (regulator_get_voltage_sel_regmap() and regulator_map_voltage_linear_range()). // snip > + > +static int rk806_set_ramp_delay_ldo(struct regulator_dev *rdev, int ramp_delay) > +{ > + unsigned int ramp_value = RK806_RAMP_RATE_2LSB_PER_1CLK; > + int regval; > + > + switch (ramp_delay) { > + case 1 ... 780: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_32CLK; > + break; > + case 781 ... 1900: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_13CLK; > + break; > + case 1901 ... 3120: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_8CLK; > + break; > + case 3121 ... 6280: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_4CLK; > + break; > + case 6281 ... 12500: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_2CLK; > + break; > + case 12501 ... 25000: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_1CLK; > + break; > + case 25001 ... 50000: > + ramp_value = RK806_RAMP_RATE_2LSB_PER_1CLK; > + break; > + case 50001 ... 100000: > + ramp_value = RK806_RAMP_RATE_4LSB_PER_1CLK; > + break; > + default: > + pr_warn("%s ramp_delay: %d not supported, setting 10000\n", > + rdev->desc->name, ramp_delay); > + } > + > + regval = ramp_value << (ffs(rdev->desc->ramp_mask) - 1); > + return regmap_update_bits(rdev->regmap, rdev->desc->ramp_reg, > + rdev->desc->ramp_mask, regval); > +} Do you think we could get rid of this function by populating a ramp-delay table and using regulator_set_ramp_delay_regmap()? Best Regards -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
WARNING: multiple messages have this Message-ID (diff)
From: Matti Vaittinen <mazziesaccount@gmail.com> To: Sebastian Reichel <sebastian.reichel@collabora.com>, Heiko Stuebner <heiko@sntech.de>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Lee Jones <lee@kernel.org> Cc: Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org>, Linus Walleij <linus.walleij@linaro.org>, Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>, Alexandre Belloni <alexandre.belloni@bootlin.com>, Alessandro Zummo <a.zummo@towertech.it>, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, shengfei Xu <xsf@rock-chips.com> Subject: Re: [PATCHv2 12/13] regulator: rk808: add rk806 support Date: Thu, 8 Sep 2022 10:45:40 +0300 [thread overview] Message-ID: <88f6110b-94b7-484d-cc37-d7f72c88090a@gmail.com> (raw) In-Reply-To: <20220908003107.220143-13-sebastian.reichel@collabora.com> On 9/8/22 03:31, Sebastian Reichel wrote: > Add rk806 support to the existing rk808 regulator > driver. > > This has been implemented using shengfei Xu's rk806 > specific driver from the vendor tree as reference. > > Co-Developed-by: shengfei Xu <xsf@rock-chips.com> > Signed-off-by: shengfei Xu <xsf@rock-chips.com> > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> > --- > drivers/regulator/rk808-regulator.c | 482 ++++++++++++++++++++++++++++ > 1 file changed, 482 insertions(+) > > diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c > index fa9fc1aa1ae3..cd1a2cff4a37 100644 > --- a/drivers/regulator/rk808-regulator.c > +++ b/drivers/regulator/rk808-regulator.c Thanks for upstreaming the downstream stuff! :) I wonder if we could drop some code by using the existing helpers? Or maybe I am missreading some code. Wouldn't be the first (and probably not the last) time... //snip > struct rk808_regulator_data { > struct gpio_desc *dvs_gpio[2]; > }; > @@ -216,6 +271,223 @@ static const unsigned int rk817_buck1_4_ramp_table[] = { > 3000, 6300, 12500, 25000 > }; > > +static int rk806_get_voltage_sel_regmap(struct regulator_dev *rdev) > +{ > + unsigned int val; > + int vsel_reg, ret; > + > + vsel_reg = rdev->desc->vsel_reg; > + > + ret = regmap_read(rdev->regmap, vsel_reg, &val); > + if (ret != 0) > + return ret; > + > + val &= rdev->desc->vsel_mask; > + val >>= ffs(rdev->desc->vsel_mask) - 1; > + > + return val; > +} Could we just use the regulator_get_voltage_sel_regmap()? > + > +static int rk806_set_voltage(struct regulator_dev *rdev, > + int req_min_uV, int req_max_uV, > + unsigned int *selector) > +{ > + int vsel_reg, ret, sel; > + > + ret = regulator_map_voltage_linear_range(rdev, req_min_uV, req_max_uV); > + if (ret >= 0) { > + *selector = ret; > + sel = ret; > + } else { > + return -EINVAL; > + } > + > + vsel_reg = rdev->desc->vsel_reg; > + > + sel <<= ffs(rdev->desc->vsel_mask) - 1; > + > + ret = regmap_update_bits(rdev->regmap, vsel_reg, > + rdev->desc->vsel_mask, sel); > + > + return ret; > +} Hmm. Maybe this is not necessary? I wonder if we could get away just with the .map and .set_voltage_sel (regulator_get_voltage_sel_regmap() and regulator_map_voltage_linear_range()). // snip > + > +static int rk806_set_ramp_delay_ldo(struct regulator_dev *rdev, int ramp_delay) > +{ > + unsigned int ramp_value = RK806_RAMP_RATE_2LSB_PER_1CLK; > + int regval; > + > + switch (ramp_delay) { > + case 1 ... 780: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_32CLK; > + break; > + case 781 ... 1900: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_13CLK; > + break; > + case 1901 ... 3120: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_8CLK; > + break; > + case 3121 ... 6280: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_4CLK; > + break; > + case 6281 ... 12500: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_2CLK; > + break; > + case 12501 ... 25000: > + ramp_value = RK806_RAMP_RATE_1LSB_PER_1CLK; > + break; > + case 25001 ... 50000: > + ramp_value = RK806_RAMP_RATE_2LSB_PER_1CLK; > + break; > + case 50001 ... 100000: > + ramp_value = RK806_RAMP_RATE_4LSB_PER_1CLK; > + break; > + default: > + pr_warn("%s ramp_delay: %d not supported, setting 10000\n", > + rdev->desc->name, ramp_delay); > + } > + > + regval = ramp_value << (ffs(rdev->desc->ramp_mask) - 1); > + return regmap_update_bits(rdev->regmap, rdev->desc->ramp_reg, > + rdev->desc->ramp_mask, regval); > +} Do you think we could get rid of this function by populating a ramp-delay table and using regulator_set_ramp_delay_regmap()? Best Regards -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~ _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip
next prev parent reply other threads:[~2022-09-08 7:45 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-08 0:30 [PATCHv2 00/13] Introduce RK806 Support Sebastian Reichel 2022-09-08 0:30 ` Sebastian Reichel 2022-09-08 0:30 ` [PATCHv2 01/13] mfd: rk808: convert to device managed resources Sebastian Reichel 2022-09-08 0:30 ` Sebastian Reichel 2022-09-08 0:30 ` [PATCHv2 02/13] mfd: rk808: use dev_err_probe Sebastian Reichel 2022-09-08 0:30 ` Sebastian Reichel 2022-09-08 8:45 ` Robin Murphy 2022-09-08 8:45 ` Robin Murphy 2022-09-08 0:30 ` [PATCHv2 03/13] clk: RK808: reduce 'struct rk808' usage Sebastian Reichel 2022-09-08 0:30 ` Sebastian Reichel 2022-09-08 0:30 ` [PATCHv2 04/13] regulator: rk808: " Sebastian Reichel 2022-09-08 0:30 ` Sebastian Reichel 2022-09-08 0:30 ` [PATCHv2 05/13] rtc: " Sebastian Reichel 2022-09-08 0:30 ` Sebastian Reichel 2022-09-08 0:31 ` [PATCHv2 06/13] mfd: rk808: replace 'struct i2c_client' with 'struct device' Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 0:31 ` [PATCHv2 07/13] mfd: rk808: split into core and i2c Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 0:31 ` [PATCHv2 08/13] dt-bindings: mfd: add rk806 binding Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 8:51 ` Krzysztof Kozlowski 2022-09-08 8:51 ` Krzysztof Kozlowski 2022-09-08 12:35 ` Rob Herring 2022-09-08 12:35 ` Rob Herring 2022-09-08 0:31 ` [PATCHv2 09/13] mfd: rk8xx: add rk806 support Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 0:31 ` [PATCHv2 10/13] pinctrl: rk805: add rk806 pinctrl support Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 0:31 ` [PATCHv2 11/13] regulator: rk808: Use dev_err_probe Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 0:31 ` [PATCHv2 12/13] regulator: rk808: add rk806 support Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel 2022-09-08 7:45 ` Matti Vaittinen [this message] 2022-09-08 7:45 ` Matti Vaittinen 2022-09-08 11:31 ` Mark Brown 2022-09-08 11:31 ` Mark Brown 2022-09-08 0:31 ` [PATCHv2 13/13] ASoC: rk817: Remove 'select REGMAP_I2C' Sebastian Reichel 2022-09-08 0:31 ` Sebastian Reichel
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=88f6110b-94b7-484d-cc37-d7f72c88090a@gmail.com \ --to=mazziesaccount@gmail.com \ --cc=a.zummo@towertech.it \ --cc=alexandre.belloni@bootlin.com \ --cc=broonie@kernel.org \ --cc=devicetree@vger.kernel.org \ --cc=heiko@sntech.de \ --cc=kernel@collabora.com \ --cc=krzysztof.kozlowski+dt@linaro.org \ --cc=lee@kernel.org \ --cc=lgirdwood@gmail.com \ --cc=linus.walleij@linaro.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=mturquette@baylibre.com \ --cc=robh+dt@kernel.org \ --cc=sboyd@kernel.org \ --cc=sebastian.reichel@collabora.com \ --cc=xsf@rock-chips.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.