devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>
Cc: Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Liam Girdwood <lgirdwood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Ian Campbell
	<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
	Kumar Gala <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	Boris BREZILLON
	<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Maxime Ripard
	<maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Carlo Caione <carlo-KA+7E9HrN00dnm+yROfE0A@public.gmane.org>,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: [PATCH RESEND v6 3/6] regulator: axp20x: prepare support for multiple AXP chip families
Date: Wed, 13 May 2015 16:30:29 +0100	[thread overview]
Message-ID: <20150513153029.GE3394@x1> (raw)
In-Reply-To: <1428638946-24890-4-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>

On Fri, 10 Apr 2015, Chen-Yu Tsai wrote:

> From: Boris BREZILLON <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> 
> Rework the AXP20X_ macros and probe function to support the several chip
> families, so that each family can define it's own set of regulators.
> 
> Signed-off-by: Boris BREZILLON <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> [wens-jdAy2FN1RRM@public.gmane.org: Support different DC-DC work frequency ranges]
> Signed-off-by: Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>
> Reviewed-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
>  drivers/regulator/axp20x-regulator.c | 143 +++++++++++++++++++++++------------
>  1 file changed, 94 insertions(+), 49 deletions(-)

Applied, thanks.

> diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
> index e4331f5e5d7d..50ae0b5f2c0c 100644
> --- a/drivers/regulator/axp20x-regulator.c
> +++ b/drivers/regulator/axp20x-regulator.c
> @@ -32,15 +32,15 @@
>  
>  #define AXP20X_FREQ_DCDC_MASK		0x0f
>  
> -#define AXP20X_DESC_IO(_id, _match, _supply, _min, _max, _step, _vreg, _vmask,	\
> -		       _ereg, _emask, _enable_val, _disable_val)		\
> -	[AXP20X_##_id] = {							\
> +#define AXP_DESC_IO(_family, _id, _match, _supply, _min, _max, _step, _vreg,	\
> +		    _vmask, _ereg, _emask, _enable_val, _disable_val)		\
> +	[_family##_##_id] = {							\
>  		.name		= #_id,						\
>  		.supply_name	= (_supply),					\
>  		.of_match	= of_match_ptr(_match),				\
>  		.regulators_node = of_match_ptr("regulators"),			\
>  		.type		= REGULATOR_VOLTAGE,				\
> -		.id		= AXP20X_##_id,					\
> +		.id		= _family##_##_id,				\
>  		.n_voltages	= (((_max) - (_min)) / (_step) + 1),		\
>  		.owner		= THIS_MODULE,					\
>  		.min_uV		= (_min) * 1000,				\
> @@ -54,15 +54,15 @@
>  		.ops		= &axp20x_ops,					\
>  	}
>  
> -#define AXP20X_DESC(_id, _match, _supply, _min, _max, _step, _vreg, _vmask,	\
> -		    _ereg, _emask)						\
> -	[AXP20X_##_id] = {							\
> +#define AXP_DESC(_family, _id, _match, _supply, _min, _max, _step, _vreg,	\
> +		 _vmask, _ereg, _emask) 					\
> +	[_family##_##_id] = {							\
>  		.name		= #_id,						\
>  		.supply_name	= (_supply),					\
>  		.of_match	= of_match_ptr(_match),				\
>  		.regulators_node = of_match_ptr("regulators"),			\
>  		.type		= REGULATOR_VOLTAGE,				\
> -		.id		= AXP20X_##_id,					\
> +		.id		= _family##_##_id,				\
>  		.n_voltages	= (((_max) - (_min)) / (_step) + 1),		\
>  		.owner		= THIS_MODULE,					\
>  		.min_uV		= (_min) * 1000,				\
> @@ -74,29 +74,29 @@
>  		.ops		= &axp20x_ops,					\
>  	}
>  
> -#define AXP20X_DESC_FIXED(_id, _match, _supply, _volt)				\
> -	[AXP20X_##_id] = {							\
> +#define AXP_DESC_FIXED(_family, _id, _match, _supply, _volt)			\
> +	[_family##_##_id] = {							\
>  		.name		= #_id,						\
>  		.supply_name	= (_supply),					\
>  		.of_match	= of_match_ptr(_match),				\
>  		.regulators_node = of_match_ptr("regulators"),			\
>  		.type		= REGULATOR_VOLTAGE,				\
> -		.id		= AXP20X_##_id,					\
> +		.id		= _family##_##_id,				\
>  		.n_voltages	= 1,						\
>  		.owner		= THIS_MODULE,					\
>  		.min_uV		= (_volt) * 1000,				\
>  		.ops		= &axp20x_ops_fixed				\
>  	}
>  
> -#define AXP20X_DESC_TABLE(_id, _match, _supply, _table, _vreg, _vmask, _ereg,	\
> -			  _emask)						\
> -	[AXP20X_##_id] = {							\
> +#define AXP_DESC_TABLE(_family, _id, _match, _supply, _table, _vreg, _vmask,	\
> +		       _ereg, _emask)						\
> +	[_family##_##_id] = {							\
>  		.name		= #_id,						\
>  		.supply_name	= (_supply),					\
>  		.of_match	= of_match_ptr(_match),				\
>  		.regulators_node = of_match_ptr("regulators"),			\
>  		.type		= REGULATOR_VOLTAGE,				\
> -		.id		= AXP20X_##_id,					\
> +		.id		= _family##_##_id,				\
>  		.n_voltages	= ARRAY_SIZE(_table),				\
>  		.owner		= THIS_MODULE,					\
>  		.vsel_reg	= (_vreg),					\
> @@ -136,37 +136,57 @@ static struct regulator_ops axp20x_ops = {
>  };
>  
>  static const struct regulator_desc axp20x_regulators[] = {
> -	AXP20X_DESC(DCDC2, "dcdc2", "vin2", 700, 2275, 25, AXP20X_DCDC2_V_OUT,
> -		    0x3f, AXP20X_PWR_OUT_CTRL, 0x10),
> -	AXP20X_DESC(DCDC3, "dcdc3", "vin3", 700, 3500, 25, AXP20X_DCDC3_V_OUT,
> -		    0x7f, AXP20X_PWR_OUT_CTRL, 0x02),
> -	AXP20X_DESC_FIXED(LDO1, "ldo1", "acin", 1300),
> -	AXP20X_DESC(LDO2, "ldo2", "ldo24in", 1800, 3300, 100,
> -		    AXP20X_LDO24_V_OUT, 0xf0, AXP20X_PWR_OUT_CTRL, 0x04),
> -	AXP20X_DESC(LDO3, "ldo3", "ldo3in", 700, 3500, 25, AXP20X_LDO3_V_OUT,
> -		    0x7f, AXP20X_PWR_OUT_CTRL, 0x40),
> -	AXP20X_DESC_TABLE(LDO4, "ldo4", "ldo24in", axp20x_ldo4_data,
> -			  AXP20X_LDO24_V_OUT, 0x0f, AXP20X_PWR_OUT_CTRL, 0x08),
> -	AXP20X_DESC_IO(LDO5, "ldo5", "ldo5in", 1800, 3300, 100,
> -		       AXP20X_LDO5_V_OUT, 0xf0, AXP20X_GPIO0_CTRL, 0x07,
> -		       AXP20X_IO_ENABLED, AXP20X_IO_DISABLED),
> +	AXP_DESC(AXP20X, DCDC2, "dcdc2", "vin2", 700, 2275, 25,
> +		 AXP20X_DCDC2_V_OUT, 0x3f, AXP20X_PWR_OUT_CTRL, 0x10),
> +	AXP_DESC(AXP20X, DCDC3, "dcdc3", "vin3", 700, 3500, 25,
> +		 AXP20X_DCDC3_V_OUT, 0x7f, AXP20X_PWR_OUT_CTRL, 0x02),
> +	AXP_DESC_FIXED(AXP20X, LDO1, "ldo1", "acin", 1300),
> +	AXP_DESC(AXP20X, LDO2, "ldo2", "ldo24in", 1800, 3300, 100,
> +		 AXP20X_LDO24_V_OUT, 0xf0, AXP20X_PWR_OUT_CTRL, 0x04),
> +	AXP_DESC(AXP20X, LDO3, "ldo3", "ldo3in", 700, 3500, 25,
> +		 AXP20X_LDO3_V_OUT, 0x7f, AXP20X_PWR_OUT_CTRL, 0x40),
> +	AXP_DESC_TABLE(AXP20X, LDO4, "ldo4", "ldo24in", axp20x_ldo4_data,
> +		       AXP20X_LDO24_V_OUT, 0x0f, AXP20X_PWR_OUT_CTRL, 0x08),
> +	AXP_DESC_IO(AXP20X, LDO5, "ldo5", "ldo5in", 1800, 3300, 100,
> +		    AXP20X_LDO5_V_OUT, 0xf0, AXP20X_GPIO0_CTRL, 0x07,
> +		    AXP20X_IO_ENABLED, AXP20X_IO_DISABLED),
>  };
>  
>  static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)
>  {
>  	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
> +	u32 min, max, def, step;
> +
> +	switch (axp20x->variant) {
> +	case AXP202_ID:
> +	case AXP209_ID:
> +		min = 750;
> +		max = 1875;
> +		def = 1500;
> +		step = 75;
> +		break;
> +	default:
> +		dev_err(&pdev->dev,
> +			"Setting DCDC frequency for unsupported AXP variant\n");
> +		return -EINVAL;
> +	}
> +
> +	if (dcdcfreq == 0)
> +		dcdcfreq = def;
>  
> -	if (dcdcfreq < 750) {
> -		dcdcfreq = 750;
> -		dev_warn(&pdev->dev, "DCDC frequency too low. Set to 750kHz\n");
> +	if (dcdcfreq < min) {
> +		dcdcfreq = min;
> +		dev_warn(&pdev->dev, "DCDC frequency too low. Set to %ukHz\n",
> +			 min);
>  	}
>  
> -	if (dcdcfreq > 1875) {
> -		dcdcfreq = 1875;
> -		dev_warn(&pdev->dev, "DCDC frequency too high. Set to 1875kHz\n");
> +	if (dcdcfreq > max) {
> +		dcdcfreq = max;
> +		dev_warn(&pdev->dev, "DCDC frequency too high. Set to %ukHz\n",
> +			 max);
>  	}
>  
> -	dcdcfreq = (dcdcfreq - 750) / 75;
> +	dcdcfreq = (dcdcfreq - min) / step;
>  
>  	return regmap_update_bits(axp20x->regmap, AXP20X_DCDC_FREQ,
>  				  AXP20X_FREQ_DCDC_MASK, dcdcfreq);
> @@ -176,7 +196,7 @@ static int axp20x_regulator_parse_dt(struct platform_device *pdev)
>  {
>  	struct device_node *np, *regulators;
>  	int ret;
> -	u32 dcdcfreq;
> +	u32 dcdcfreq = 0;
>  
>  	np = of_node_get(pdev->dev.parent->of_node);
>  	if (!np)
> @@ -186,7 +206,6 @@ static int axp20x_regulator_parse_dt(struct platform_device *pdev)
>  	if (!regulators) {
>  		dev_warn(&pdev->dev, "regulators node not found\n");
>  	} else {
> -		dcdcfreq = 1500;
>  		of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
>  		ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
>  		if (ret < 0) {
> @@ -202,15 +221,27 @@ static int axp20x_regulator_parse_dt(struct platform_device *pdev)
>  
>  static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 workmode)
>  {
> -	unsigned int mask = AXP20X_WORKMODE_DCDC2_MASK;
> +	struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
> +	unsigned int mask;
>  
> -	if ((id != AXP20X_DCDC2) && (id != AXP20X_DCDC3))
> -		return -EINVAL;
> +	switch (axp20x->variant) {
> +	case AXP202_ID:
> +	case AXP209_ID:
> +		if ((id != AXP20X_DCDC2) && (id != AXP20X_DCDC3))
> +			return -EINVAL;
> +
> +		mask = AXP20X_WORKMODE_DCDC2_MASK;
> +		if (id == AXP20X_DCDC3)
> +			mask = AXP20X_WORKMODE_DCDC3_MASK;
>  
> -	if (id == AXP20X_DCDC3)
> -		mask = AXP20X_WORKMODE_DCDC3_MASK;
> +		workmode <<= ffs(mask) - 1;
> +		break;
>  
> -	workmode <<= ffs(mask) - 1;
> +	default:
> +		/* should not happen */
> +		WARN_ON(1);
> +		return -EINVAL;
> +	}
>  
>  	return regmap_update_bits(rdev->regmap, AXP20X_DCDC_MODE, mask, workmode);
>  }
> @@ -219,22 +250,36 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
>  {
>  	struct regulator_dev *rdev;
>  	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
> +	const struct regulator_desc *regulators;
>  	struct regulator_config config = {
>  		.dev = pdev->dev.parent,
>  		.regmap = axp20x->regmap,
> +		.driver_data = axp20x,
>  	};
> -	int ret, i;
> +	int ret, i, nregulators;
>  	u32 workmode;
>  
> +	switch (axp20x->variant) {
> +	case AXP202_ID:
> +	case AXP209_ID:
> +		regulators = axp20x_regulators;
> +		nregulators = AXP20X_REG_ID_MAX;
> +		break;
> +	default:
> +		dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
> +			axp20x->variant);
> +		return -EINVAL;
> +	}
> +
>  	/* This only sets the dcdc freq. Ignore any errors */
>  	axp20x_regulator_parse_dt(pdev);
>  
> -	for (i = 0; i < AXP20X_REG_ID_MAX; i++) {
> -		rdev = devm_regulator_register(&pdev->dev, &axp20x_regulators[i],
> +	for (i = 0; i < nregulators; i++) {
> +		rdev = devm_regulator_register(&pdev->dev, &regulators[i],
>  					       &config);
>  		if (IS_ERR(rdev)) {
>  			dev_err(&pdev->dev, "Failed to register %s\n",
> -				axp20x_regulators[i].name);
> +				regulators[i].name);
>  
>  			return PTR_ERR(rdev);
>  		}
> @@ -245,7 +290,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
>  		if (!ret) {
>  			if (axp20x_set_dcdc_workmode(rdev, i, workmode))
>  				dev_err(&pdev->dev, "Failed to set workmode on %s\n",
> -					axp20x_regulators[i].name);
> +					rdev->desc->name);
>  		}
>  	}
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

  parent reply	other threads:[~2015-05-13 15:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10  4:09 [PATCH RESEND v6 0/6] mfd: axp20x: add AXP221 PMIC support Chen-Yu Tsai
     [not found] ` <1428638946-24890-1-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-04-10  4:09   ` [PATCH RESEND v6 1/6] mfd: axp20x: add AXP22x " Chen-Yu Tsai
     [not found]     ` <1428638946-24890-2-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-04-10  9:25       ` Lee Jones
2015-05-13 15:30       ` Lee Jones
2015-04-10  4:09   ` [PATCH RESEND v6 2/6] mfd: axp20x: update DT bindings with AXP22x compatibles Chen-Yu Tsai
     [not found]     ` <1428638946-24890-3-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-05-13 15:30       ` Lee Jones
2015-04-10  4:09   ` [PATCH RESEND v6 3/6] regulator: axp20x: prepare support for multiple AXP chip families Chen-Yu Tsai
     [not found]     ` <1428638946-24890-4-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-05-13 15:30       ` Lee Jones [this message]
2015-04-10  4:09   ` [PATCH RESEND v6 4/6] regulator: axp20x: add support for AXP22X regulators Chen-Yu Tsai
     [not found]     ` <1428638946-24890-5-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-04-10 15:48       ` Mark Brown
     [not found]         ` <20150410154809.GN6023-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-04-14  6:45           ` Lee Jones
2015-04-29 12:36           ` Lee Jones
2015-05-13 15:30       ` Lee Jones
2015-04-10  4:09   ` [PATCH RESEND v6 5/6] mfd: axp20x: Add AXP22x regulator information to DT bindings Chen-Yu Tsai
     [not found]     ` <1428638946-24890-6-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-05-13 15:30       ` Lee Jones
2015-04-10  4:09   ` [PATCH RESEND v6 6/6] mfd: axp20x: Enable AXP22X regulators Chen-Yu Tsai
     [not found]     ` <1428638946-24890-7-git-send-email-wens-jdAy2FN1RRM@public.gmane.org>
2015-05-13 15:31       ` Lee Jones
2015-05-13 15:41   ` [PATCH RESEND v6 0/6] mfd: axp20x: add AXP221 PMIC support Lee Jones

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=20150513153029.GE3394@x1 \
    --to=lee.jones-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=carlo-KA+7E9HrN00dnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
    --cc=lgirdwood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=wens-jdAy2FN1RRM@public.gmane.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).