On Thu, Jun 15, 2017 at 12:39 AM,This issue exist from the first commit. Should I add fixes tag for it ?
<sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx> wrote:
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx>It seems it should have a Fixes tag.
According to Whiskey Cove PMIC GPIO controller specification, for GPIO
pins 0-12, GPIO input and output register control address range from,
0x4e44-0x4e50 for GPIO outputs control register
0x4e51-0x4e5d for GPIO input control register
But, currently when calculating the GPIO register offsets in to_reg()
function, all GPIO pins in the same bank uses the same GPIO control
register address. This logic is incorrect. This patch fixes this
issue.
This patch also adds support to selectively skip register modification
for virtual GPIOs.
In case of Whiskey Cove PMIC, ACPI code may use up 94 virtual GPIOs.
These virtual GPIOs are used by the ACPI code as means to access various
non GPIO bits of PMIC. So for these virtual GPIOs, we don't need to
manipulate the physical GPIO pin register. A similar patch has been
merged recently by Hans for Crystal Cove PMIC GPIO driver. You can
find more details about it in Commit 9a752b4c9ab9 ("gpio: crystalcove:
Do not write regular gpio registers for virtual GPIOs")
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx>
Reported-by: Jukka Laitinen <jukka.laitinen@xxxxxxxxx>
Whiskey Cove PMIC only has 13 real GPIO pins. But if you look at the gpio chip configuration in gpio-wcove.c driver, ngpio value is set as 94.
static inline unsigned int to_reg(int gpio, enum ctrl_register reg_type)How this can happen?
{
unsigned int reg;
- int bank;
- if (gpio < BANK0_NR_PINS)
- bank = 0;
- else if (gpio < BANK0_NR_PINS + BANK1_NR_PINS)
- bank = 1;
- else
- bank = 2;
+ if (gpio >= WCOVE_GPIO_NUM)
+ return -EOPNOTSUPP;
Will remove it.if (reg_type == CTRL_IN)Noise.
- reg = GPIO_IN_CTRL_BASE + bank;
+ /*
+ * GPIO input control registers
+ * (one per pin): 0x4e51 - 0x4e5d
+ */
I will just remove it.
+ reg = GPIO_IN_CTRL_BASE + gpio;Wrong multi-line comment and noise overall.
else
- reg = GPIO_OUT_CTRL_BASE + bank;
+ /* GPIO output control registers
+ * (one per pin): 0x4e44 - 0x4e50
+ */
If you wish to leave the comments, put them on top of the function as
its description.
+ reg = GPIO_OUT_CTRL_BASE + gpio;Since above comment this change would gone.
return reg;
}
@@ -145,7 +147,10 @@ static void wcove_update_irq_mask(struct wcove_gpio *wg, int gpio)
static void wcove_update_irq_ctrl(struct wcove_gpio *wg, int gpio)
{
- unsigned int reg = to_reg(gpio, CTRL_IN);
+ int reg = to_reg(gpio, CTRL_IN);
+
+ if (reg < 0)
+ return;
+ int reg = to_reg(gpio, CTRL_OUT);Ditto.
+
+ if (reg < 0)
+ return 0;
- return regmap_write(wg->regmap, to_reg(gpio, CTRL_OUT),
- CTLO_INPUT_SET);
+ return regmap_write(wg->regmap, reg, CTLO_INPUT_SET);
+ int reg = to_reg(gpio, CTRL_OUT);Ditto.
- return regmap_write(wg->regmap, to_reg(gpio, CTRL_OUT),
- CTLO_OUTPUT_SET | value);
+ if (reg < 0)
+ return 0;
+
+ return regmap_write(wg->regmap, reg, CTLO_OUTPUT_SET | value);
+ int ret, reg = to_reg(gpio, CTRL_OUT);Don't fit such variable on one line.
+This would gone after addressing first comment.
+ if (reg < 0)
+ return 0;
- ret = regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &val);
+ ret = regmap_read(wg->regmap, reg, &val);
- int ret;Ditto.
+ int ret, reg = to_reg(gpio, CTRL_IN);
+
+ if (reg < 0)
+ return 0;
- ret = regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &val);
+ ret = regmap_read(wg->regmap, reg, &val);
+ int reg = to_reg(gpio, CTRL_OUT);Ditto.
+
+ if (reg < 0)
+ return;
if (value)
- regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 1, 1);
+ regmap_update_bits(wg->regmap, reg, 1, 1);
else
- regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 1, 0);
+ regmap_update_bits(wg->regmap, reg, 1, 0);
+ int reg = to_reg(gpio, CTRL_OUT);Ditto.
+
+ if (reg < 0)
+ return 0;
switch (pinconf_to_config_param(config)) {
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
- return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT),
- CTLO_DRV_MASK, CTLO_DRV_OD);
+ return regmap_update_bits(wg->regmap, reg, CTLO_DRV_MASK,
+ CTLO_DRV_OD);
case PIN_CONFIG_DRIVE_PUSH_PULL:
- return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT),
- CTLO_DRV_MASK, CTLO_DRV_CMOS);
+ return regmap_update_bits(wg->regmap, reg, CTLO_DRV_MASK,
+ CTLO_DRV_CMOS);
+ if (data->hwirq >= WCOVE_GPIO_NUM)How could it happen?
+ return 0;
+
+ if (data->hwirq >= WCOVE_GPIO_NUM)Ditto.
+ return;
+ if (data->hwirq >= WCOVE_GPIO_NUM)Ditto.
+ return;