From: Sherman Yin <syin@broadcom.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Mark Brown <broonie@kernel.org>
Cc: "Rob Herring" <rob.herring@calxeda.com>,
"Heiko Stübner" <heiko@sntech.de>,
"Pawel Moll" <pawel.moll@arm.com>,
"Mark Rutland" <mark.rutland@arm.com>,
"Stephen Warren" <swarren@wwwdotorg.org>,
"Ian Campbell" <ijc+devicetree@hellion.org.uk>,
"Rob Landley" <rob@landley.net>,
"Christian Daudt" <bcm@fixthebug.org>,
"Russell King" <linux@arm.linux.org.uk>,
"Grant Likely" <grant.likely@linaro.org>,
"Matt Porter" <matt.porter@linaro.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
bcm-kernel-feedback-list <bcm-kernel-feedback-list@broadcom.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v3 5/6] ARM: pinctrl: Add Broadcom Capri pinctrl driver
Date: Wed, 18 Dec 2013 15:56:08 -0800 [thread overview]
Message-ID: <52B23618.2040508@broadcom.com> (raw)
In-Reply-To: <CACRpkdaeZCodKv6R+4ZS3o-5u=QQuV3JidEp7uaLsN9aYG7bqA@mail.gmail.com>
On 13-12-12 12:54 PM, Linus Walleij wrote:
>> +#define CAPRI_PIN_SHIFT(type, param) \
>> + (CAPRI_ ## type ## _PIN_REG_ ## param ## _SHIFT)
>> +
>> +#define CAPRI_PIN_MASK(type, param) \
>> + (CAPRI_ ## type ## _PIN_REG_ ## param ## _MASK)
>> +
>> +/* Macro to update reg with new pin config param */
>> +#define CAPRI_PIN_UPDATE(reg, type, param, val) \
>> + (((reg) & ~CAPRI_PIN_MASK(type, param)) | \
>> + (((val) << CAPRI_PIN_SHIFT(type, param)) & CAPRI_PIN_MASK(type, param)))
>
> Yuck! Are you sure you cannot convert these to static inlines and
> make them much simpler in the process?
>
> We do have an optimizing compiler, you don't need to do
> everything on one line... besides we're not on the hotpath.
If I were to convert the first 2 #defines to functions, it would either
be a 2-level switch statement or a 2D lookup table. IMO both of these
options are more difficult to read than this simple concatenation, so I
really rather keep them this way.
CAPRI_PIN_UPDATE, OTOH, doesn't require any concatenation so I can
easily make that into an inline.
>
>> +/*
>> + * Write to the register using the value and mask if current value is different
>> + */
>> +static void capri_reg_write(struct pinctrl_dev *pctldev,
>> + void __iomem *reg,
>> + u32 val,
>> + u32 mask)
>> +{
>> + u32 old_val;
>> + u32 new_val;
>> +
>> + old_val = readl(reg);
>> + new_val = (old_val & ~mask) | (val & mask);
>> +
>> + if (new_val == old_val) {
>> + dev_dbg(pctldev->dev,
>> + "Reg 0x%p=0x%x (no change)\n",
>> + reg, old_val);
>> + return;
>> + }
>> +
>> + dev_dbg(pctldev->dev,
>> + "Reg 0x%p change from 0x%x to 0x%x\n",
>> + reg, old_val, new_val);
>> + writel(new_val, reg);
>> +}
>
> This is a reimplementation of regmap for MMIO.
> See drivers/base/regmap/regmap-mmio.c
> Notice how regmap_update_bits() is used throughout the
> kernel.
>
> If you want to do this, use regmap.
Ok.
>
>> + case PIN_CONFIG_DRIVE_STRENGTH:
>> + /* Valid range is 2-16 mA, even numbers only */
>> + if ((arg < 2) || (arg > 16) || (arg % 2)) {
>> + dev_err(pctldev->dev,
>> + "Invalid Drive Strength value (%d) for "
>> + "pin %s (%d). Valid values are "
>> + "(2..16) mA, even numbers only.\n",
>> + arg, pdata->pins[pin].name, pin);
>> + return -EINVAL;
>> + }
>> + *val = CAPRI_PIN_UPDATE(*val, STD, DRV_STR, (arg/2)-1);
>> + *mask |= CAPRI_STD_PIN_REG_DRV_STR_MASK;
>> + break;
>
> Hm rather nice integer math...
Sorry, I can't tell if you are being sarcastic :) Drive strength is
represented by 3 bits in the register. If the values were 2-14 I could
have done some bit-checking instead of those 3 conditions in the if
statement. Or, if we use a enum of 0-7 then the check is much easier.
But as we discussed re: pull-up resistance, we rather let users specify
real numbers. The (arg/2)-1 is just to convert the mA into the 3 bits.
>> +/* Goes through the configs and update register val/mask */
>> +static int capri_i2c_pin_update(struct pinctrl_dev *pctldev,
>> + unsigned pin,
>> + unsigned long *configs,
>> + unsigned num_configs,
>> + u32 *val,
>> + u32 *mask)
>> +{
>> + struct capri_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
>> + int i;
>> + enum pin_config_param param;
>> + u16 arg;
>> +
>> + for (i = 0; i < num_configs; i++) {
>> + param = pinconf_to_config_param(configs[i]);
>> + arg = pinconf_to_config_argument(configs[i]);
>> +
>> + switch (param) {
>> + case PIN_CONFIG_BIAS_PULL_UP:
>> + if ((arg < 1) || (arg > 7)) {
>> + dev_err(pctldev->dev,
>> + "Invalid Pull Up value (%d) for pin %s "
>> + "(%d). Valid values are (1..7).\n",
>> + arg, pdata->pins[pin].name, pin);
>> + return -EINVAL;
>> + }
>
> No don't do that as mentioned in the other patch. Pass pull up strength
> in Ohms.
>
> Then have a translation table here, and do some best-effort fuzzy match.
Sure. I'm just going to error out if the user-supplied value is off,
since it is very clear what is acceptable from the binding documentation.
>> + /* Different pins have different configuration options */
>> + switch (pin_type) {
>> + case CAPRI_PIN_TYPE_STD:
>> + rc = capri_std_pin_update(pctldev, pin, configs, num_configs,
>> + &cfg_val, &cfg_mask);
>> + break;
>> +
>> + case CAPRI_PIN_TYPE_I2C:
>> + rc = capri_i2c_pin_update(pctldev, pin, configs, num_configs,
>> + &cfg_val, &cfg_mask);
>> + break;
>> +
>> + case CAPRI_PIN_TYPE_HDMI:
>> + rc = capri_hdmi_pin_update(pctldev, pin, configs, num_configs,
>> + &cfg_val, &cfg_mask);
>> + break;
>
> This is really nice and elegant.
Thanks. :)
Regards,
Sherman
next prev parent reply other threads:[~2013-12-18 23:56 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-04 0:23 [PATCH 0/4] Add Broadcom Capri pinctrl driver Sherman Yin
2013-10-04 0:23 ` [PATCH 1/4] pinctrl: Add void * to pinctrl_pin_desc Sherman Yin
2013-10-09 8:55 ` Linus Walleij
2013-10-09 22:57 ` Sherman Yin
2013-10-04 0:23 ` [PATCH 2/4] pinctrl: Add pinctrl binding for Broadcom Capri SoCs Sherman Yin
2013-10-04 12:51 ` Matt Porter
2013-10-09 8:53 ` Linus Walleij
2013-10-10 17:57 ` Sherman Yin
2013-10-04 0:23 ` [PATCH 3/4] ARM: pinctrl: Add Broadcom Capri pinctrl driver Sherman Yin
2013-10-09 9:10 ` Linus Walleij
2013-10-10 23:48 ` Sherman Yin
2013-10-11 8:14 ` Linus Walleij
2013-10-11 18:25 ` Sherman Yin
2013-10-22 23:29 ` Sherman Yin
2013-10-25 22:48 ` Sherman Yin
2013-11-04 12:24 ` Linus Walleij
2013-11-04 23:26 ` Heiko Stübner
2013-11-05 0:04 ` Stephen Warren
2013-11-06 2:02 ` Sherman Yin
2013-11-06 9:40 ` Linus Walleij
2013-11-08 0:29 ` Sherman Yin
2013-11-11 10:01 ` Linus Walleij
2013-11-13 23:43 ` Sherman Yin
2013-11-19 20:39 ` Linus Walleij
2013-11-06 17:00 ` Stephen Warren
2013-11-07 22:01 ` Sherman Yin
2013-11-06 9:29 ` Linus Walleij
2013-10-17 6:03 ` Christian Daudt
2013-10-17 14:54 ` Stephen Warren
2013-10-17 15:31 ` Christian Daudt
2013-12-11 0:05 ` Sherman Yin
2013-12-12 20:43 ` Linus Walleij
2013-10-04 0:23 ` [PATCH 4/4] pinctrl: Enable pinctrl for Broadcom Capri SoCs Sherman Yin
2013-10-09 9:11 ` Linus Walleij
2013-10-07 19:28 ` [PATCH v2 0/4] Add Broadcom Capri pinctrl driver Sherman Yin
2013-10-07 19:28 ` [PATCH v2 1/4] pinctrl: Add void * to pinctrl_pin_desc Sherman Yin
2013-10-07 19:28 ` [PATCH v2 2/4] pinctrl: Add pinctrl binding for Broadcom Capri SoCs Sherman Yin
2013-10-07 19:28 ` [PATCH v2 3/4] ARM: pinctrl: Add Broadcom Capri pinctrl driver Sherman Yin
2013-10-07 19:28 ` [PATCH v2 4/4] pinctrl: Enable pinctrl for Broadcom Capri SoCs Sherman Yin
2013-12-11 18:37 ` [PATCH v3 0/6] Add Broadcom Capri pinctrl driver Sherman Yin
2013-12-11 18:37 ` [PATCH v3 1/6] pinctrl: Add void * to pinctrl_pin_desc Sherman Yin
2013-12-11 18:37 ` [PATCH v3 2/6] pinctrl: Adds slew-rate, input-enable/disable Sherman Yin
2013-12-12 20:41 ` Linus Walleij
2013-12-16 9:55 ` Linus Walleij
2013-12-11 18:37 ` [PATCH v3 3/6] pinctrl: Make PINCTRL selectable by defconfig/menuconfig Sherman Yin
2013-12-12 20:39 ` Linus Walleij
2013-12-12 21:35 ` Christian Daudt
2013-12-16 10:01 ` Linus Walleij
2013-12-17 0:18 ` Bjorn Andersson
2013-12-20 9:37 ` Linus Walleij
2013-12-20 20:58 ` Arnd Bergmann
2013-12-21 2:15 ` Sherman Yin
2013-12-11 18:37 ` [PATCH v3 4/6] pinctrl: Add pinctrl binding for Broadcom Capri SoCs Sherman Yin
2013-12-12 20:37 ` Linus Walleij
2013-12-14 1:16 ` Sherman Yin
2013-12-16 13:17 ` Linus Walleij
2013-12-18 2:02 ` Sherman Yin
2013-12-11 18:37 ` [PATCH v3 5/6] ARM: pinctrl: Add Broadcom Capri pinctrl driver Sherman Yin
2013-12-12 20:54 ` Linus Walleij
2013-12-13 10:22 ` Mark Brown
2013-12-19 0:12 ` Sherman Yin
2013-12-18 23:56 ` Sherman Yin [this message]
2013-12-21 2:31 ` Sherman Yin
2013-12-11 18:37 ` [PATCH v3 6/6] pinctrl: Enable pinctrl for Broadcom Capri SoCs Sherman Yin
2013-12-21 2:13 ` [PATCH v4 0/6] Add Broadcom Capri pinctrl driver Sherman Yin
2013-12-21 2:13 ` [PATCH v4 1/4] pinctrl: Add void * to pinctrl_pin_desc Sherman Yin
2014-01-16 13:26 ` Linus Walleij
2013-12-21 2:13 ` [PATCH v4 2/4] pinctrl: Add pinctrl binding for Broadcom Capri SoCs Sherman Yin
2014-01-07 17:15 ` Linus Walleij
2014-01-07 20:45 ` Sherman Yin
2014-01-14 10:16 ` Linus Walleij
2014-01-14 19:00 ` Sherman Yin
2014-01-15 9:40 ` Linus Walleij
2014-01-15 16:39 ` Mark Rutland
2014-01-16 13:24 ` Linus Walleij
2013-12-21 2:13 ` [PATCH v4 3/4] ARM: pinctrl: Add Broadcom Capri pinctrl driver Sherman Yin
2014-01-16 13:19 ` Linus Walleij
2014-01-17 19:59 ` Sherman Yin
2014-01-18 2:56 ` Matt Porter
2014-01-20 8:16 ` Linus Walleij
2014-01-20 19:14 ` Sherman Yin
2014-01-21 12:35 ` Linus Walleij
2014-01-21 13:49 ` Matt Porter
2013-12-21 2:13 ` [PATCH v4 4/4] pinctrl: Enable pinctrl for Broadcom Capri SoCs Sherman Yin
2014-01-16 13:28 ` Linus Walleij
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=52B23618.2040508@broadcom.com \
--to=syin@broadcom.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bcm@fixthebug.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=grant.likely@linaro.org \
--cc=heiko@sntech.de \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mark.rutland@arm.com \
--cc=matt.porter@linaro.org \
--cc=pawel.moll@arm.com \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
--cc=swarren@wwwdotorg.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).