From: Heiko Stuebner <heiko@sntech.de> To: broonie@kernel.org Cc: linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, Heiko Stuebner <heiko@sntech.de> Subject: [PATCH v2 1/4] regulator: fan53555: use set_ramp_delay to set the ramp up slew rate Date: Tue, 16 Sep 2014 17:54:01 +0200 [thread overview] Message-ID: <1410882844-10349-2-git-send-email-heiko@sntech.de> (raw) In-Reply-To: <1410882844-10349-1-git-send-email-heiko@sntech.de> The regulator constraints already provide a field for the ramp_delay, so there is no need to set this manually. Therefore implement the set_ramp_delay callback and convert the pdata value to the constraint value if necessary. Signed-off-by: Heiko Stuebner <heiko@sntech.de> --- drivers/regulator/fan53555.c | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c index c912ba7..5808435 100644 --- a/drivers/regulator/fan53555.c +++ b/drivers/regulator/fan53555.c @@ -135,6 +135,38 @@ static unsigned int fan53555_get_mode(struct regulator_dev *rdev) return REGULATOR_MODE_NORMAL; } +static int slew_rates[] = { + 64000, + 32000, + 16000, + 8000, + 4000, + 2000, + 1000, + 500, +}; + +static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp) +{ + struct fan53555_device_info *di = rdev_get_drvdata(rdev); + int regval = -1, i; + + for (i = 0; i < ARRAY_SIZE(slew_rates); i++) { + if (ramp <= slew_rates[i]) + regval = i; + else + break; + } + + if (regval < 0) { + dev_err(di->dev, "unsupported ramp value %d\n", ramp); + return -EINVAL; + } + + return regmap_update_bits(di->regmap, FAN53555_CONTROL, + CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT); +} + static struct regulator_ops fan53555_regulator_ops = { .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, @@ -146,6 +178,7 @@ static struct regulator_ops fan53555_regulator_ops = { .is_enabled = regulator_is_enabled_regmap, .set_mode = fan53555_set_mode, .get_mode = fan53555_get_mode, + .set_ramp_delay = fan53555_set_ramp, }; /* For 00,01,03,05 options: @@ -156,8 +189,6 @@ static struct regulator_ops fan53555_regulator_ops = { static int fan53555_device_setup(struct fan53555_device_info *di, struct fan53555_platform_data *pdata) { - unsigned int reg, data, mask; - /* Setup voltage control register */ switch (pdata->sleep_vsel_id) { case FAN53555_VSEL_ID_0: @@ -190,15 +221,8 @@ static int fan53555_device_setup(struct fan53555_device_info *di, "Chip ID[%d]\n not supported!\n", di->chip_id); return -EINVAL; } - /* Init slew rate */ - if (pdata->slew_rate & 0x7) - di->slew_rate = pdata->slew_rate; - else - di->slew_rate = FAN53555_SLEW_RATE_64MV; - reg = FAN53555_CONTROL; - data = di->slew_rate << CTL_SLEW_SHIFT; - mask = CTL_SLEW_MASK; - return regmap_update_bits(di->regmap, reg, mask, data); + + return 0; } static int fan53555_regulator_register(struct fan53555_device_info *di, @@ -248,6 +272,13 @@ static int fan53555_regulator_probe(struct i2c_client *client, if (!di) return -ENOMEM; + /* if no ramp constraint set, get the pdata ramp_delay */ + if (!di->regulator->constraints.ramp_delay) { + int slew_idx = (pdata->slew_rate & 0x7) ? pdata->slew_rate : 0; + + di->regulator->constraints.ramp_delay = slew_rates[slew_idx]; + } + di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); if (IS_ERR(di->regmap)) { dev_err(&client->dev, "Failed to allocate regmap!\n"); -- 2.0.1
next prev parent reply other threads:[~2014-09-16 16:30 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-09-16 15:54 [PATCH v2 0/4] regulator: add support for syr82x to fan53555 Heiko Stuebner 2014-09-16 15:54 ` Heiko Stuebner [this message] 2014-09-16 15:54 ` [PATCH v2 2/4] dt-bindings: add devicetree bindings for Fairchild FAN53555 regulators Heiko Stuebner 2014-09-16 16:55 ` Mark Brown 2014-09-16 16:55 ` Mark Brown 2014-09-16 15:54 ` [PATCH v2 3/4] regulator: fan53555: add devicetree support Heiko Stuebner 2014-09-16 15:54 ` [PATCH v2 4/4] regulator: fan53555: add support for Silergy SYR82x regulators Heiko Stuebner 2014-09-16 15:54 ` Heiko Stuebner
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=1410882844-10349-2-git-send-email-heiko@sntech.de \ --to=heiko@sntech.de \ --cc=broonie@kernel.org \ --cc=devicetree@vger.kernel.org \ --cc=galak@codeaurora.org \ --cc=ijc+devicetree@hellion.org.uk \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=mark.rutland@arm.com \ --cc=pawel.moll@arm.com \ --cc=robh+dt@kernel.org \ --subject='Re: [PATCH v2 1/4] regulator: fan53555: use set_ramp_delay to set the ramp up slew rate' \ /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
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.