Commit 82bf0afd authored by Matti Vaittinen's avatar Matti Vaittinen Committed by Bartosz Golaszewski

gpio: bd7xxxx: Do not depend on parent driver data

The ROHM BD70528 and BD71828 GPIO drivers only need the regmap
pointer from parent. Regmap can be obtained via dev_get_regmap()
so do not require parent to populate driver data for that.
Signed-off-by: default avatarMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent 032653ef
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
#define GPIO_OUT_REG(offset) (BD70528_REG_GPIO1_OUT + (offset) * 2) #define GPIO_OUT_REG(offset) (BD70528_REG_GPIO1_OUT + (offset) * 2)
struct bd70528_gpio { struct bd70528_gpio {
struct rohm_regmap_dev chip; struct regmap *regmap;
struct device *dev;
struct gpio_chip gpio; struct gpio_chip gpio;
}; };
...@@ -35,11 +36,11 @@ static int bd70528_set_debounce(struct bd70528_gpio *bdgpio, ...@@ -35,11 +36,11 @@ static int bd70528_set_debounce(struct bd70528_gpio *bdgpio,
val = BD70528_DEBOUNCE_50MS; val = BD70528_DEBOUNCE_50MS;
break; break;
default: default:
dev_err(bdgpio->chip.dev, dev_err(bdgpio->dev,
"Invalid debounce value %u\n", debounce); "Invalid debounce value %u\n", debounce);
return -EINVAL; return -EINVAL;
} }
return regmap_update_bits(bdgpio->chip.regmap, GPIO_IN_REG(offset), return regmap_update_bits(bdgpio->regmap, GPIO_IN_REG(offset),
BD70528_DEBOUNCE_MASK, val); BD70528_DEBOUNCE_MASK, val);
} }
...@@ -49,9 +50,9 @@ static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset) ...@@ -49,9 +50,9 @@ static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset)
int val, ret; int val, ret;
/* Do we need to do something to IRQs here? */ /* Do we need to do something to IRQs here? */
ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val); ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val);
if (ret) { if (ret) {
dev_err(bdgpio->chip.dev, "Could not read gpio direction\n"); dev_err(bdgpio->dev, "Could not read gpio direction\n");
return ret; return ret;
} }
if (val & BD70528_GPIO_OUT_EN_MASK) if (val & BD70528_GPIO_OUT_EN_MASK)
...@@ -67,13 +68,13 @@ static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset, ...@@ -67,13 +68,13 @@ static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
switch (pinconf_to_config_param(config)) { switch (pinconf_to_config_param(config)) {
case PIN_CONFIG_DRIVE_OPEN_DRAIN: case PIN_CONFIG_DRIVE_OPEN_DRAIN:
return regmap_update_bits(bdgpio->chip.regmap, return regmap_update_bits(bdgpio->regmap,
GPIO_OUT_REG(offset), GPIO_OUT_REG(offset),
BD70528_GPIO_DRIVE_MASK, BD70528_GPIO_DRIVE_MASK,
BD70528_GPIO_OPEN_DRAIN); BD70528_GPIO_OPEN_DRAIN);
break; break;
case PIN_CONFIG_DRIVE_PUSH_PULL: case PIN_CONFIG_DRIVE_PUSH_PULL:
return regmap_update_bits(bdgpio->chip.regmap, return regmap_update_bits(bdgpio->regmap,
GPIO_OUT_REG(offset), GPIO_OUT_REG(offset),
BD70528_GPIO_DRIVE_MASK, BD70528_GPIO_DRIVE_MASK,
BD70528_GPIO_PUSH_PULL); BD70528_GPIO_PUSH_PULL);
...@@ -93,7 +94,7 @@ static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset) ...@@ -93,7 +94,7 @@ static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset)
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
/* Do we need to do something to IRQs here? */ /* Do we need to do something to IRQs here? */
return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset),
BD70528_GPIO_OUT_EN_MASK, BD70528_GPIO_OUT_EN_MASK,
BD70528_GPIO_OUT_DISABLE); BD70528_GPIO_OUT_DISABLE);
} }
...@@ -105,10 +106,10 @@ static void bd70528_gpio_set(struct gpio_chip *chip, unsigned int offset, ...@@ -105,10 +106,10 @@ static void bd70528_gpio_set(struct gpio_chip *chip, unsigned int offset,
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
u8 val = (value) ? BD70528_GPIO_OUT_HI : BD70528_GPIO_OUT_LO; u8 val = (value) ? BD70528_GPIO_OUT_HI : BD70528_GPIO_OUT_LO;
ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), ret = regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset),
BD70528_GPIO_OUT_MASK, val); BD70528_GPIO_OUT_MASK, val);
if (ret) if (ret)
dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value); dev_err(bdgpio->dev, "Could not set gpio to %d\n", value);
} }
static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset, static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset,
...@@ -117,7 +118,7 @@ static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset, ...@@ -117,7 +118,7 @@ static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset,
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
bd70528_gpio_set(chip, offset, value); bd70528_gpio_set(chip, offset, value);
return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset),
BD70528_GPIO_OUT_EN_MASK, BD70528_GPIO_OUT_EN_MASK,
BD70528_GPIO_OUT_ENABLE); BD70528_GPIO_OUT_ENABLE);
} }
...@@ -129,11 +130,11 @@ static int bd70528_gpio_get_o(struct bd70528_gpio *bdgpio, unsigned int offset) ...@@ -129,11 +130,11 @@ static int bd70528_gpio_get_o(struct bd70528_gpio *bdgpio, unsigned int offset)
int ret; int ret;
unsigned int val; unsigned int val;
ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val); ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val);
if (!ret) if (!ret)
ret = !!(val & BD70528_GPIO_OUT_MASK); ret = !!(val & BD70528_GPIO_OUT_MASK);
else else
dev_err(bdgpio->chip.dev, "GPIO (out) state read failed\n"); dev_err(bdgpio->dev, "GPIO (out) state read failed\n");
return ret; return ret;
} }
...@@ -143,12 +144,12 @@ static int bd70528_gpio_get_i(struct bd70528_gpio *bdgpio, unsigned int offset) ...@@ -143,12 +144,12 @@ static int bd70528_gpio_get_i(struct bd70528_gpio *bdgpio, unsigned int offset)
unsigned int val; unsigned int val;
int ret; int ret;
ret = regmap_read(bdgpio->chip.regmap, BD70528_REG_GPIO_STATE, &val); ret = regmap_read(bdgpio->regmap, BD70528_REG_GPIO_STATE, &val);
if (!ret) if (!ret)
ret = !(val & GPIO_IN_STATE_MASK(offset)); ret = !(val & GPIO_IN_STATE_MASK(offset));
else else
dev_err(bdgpio->chip.dev, "GPIO (in) state read failed\n"); dev_err(bdgpio->dev, "GPIO (in) state read failed\n");
return ret; return ret;
} }
...@@ -173,7 +174,7 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset) ...@@ -173,7 +174,7 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset)
else if (ret == GPIO_LINE_DIRECTION_IN) else if (ret == GPIO_LINE_DIRECTION_IN)
ret = bd70528_gpio_get_i(bdgpio, offset); ret = bd70528_gpio_get_i(bdgpio, offset);
else else
dev_err(bdgpio->chip.dev, "failed to read GPIO direction\n"); dev_err(bdgpio->dev, "failed to read GPIO direction\n");
return ret; return ret;
} }
...@@ -181,20 +182,13 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset) ...@@ -181,20 +182,13 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset)
static int bd70528_probe(struct platform_device *pdev) static int bd70528_probe(struct platform_device *pdev)
{ {
struct bd70528_gpio *bdgpio; struct bd70528_gpio *bdgpio;
struct rohm_regmap_dev *bd70528;
int ret; int ret;
bd70528 = dev_get_drvdata(pdev->dev.parent);
if (!bd70528) {
dev_err(&pdev->dev, "No MFD driver data\n");
return -EINVAL;
}
bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio), bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio),
GFP_KERNEL); GFP_KERNEL);
if (!bdgpio) if (!bdgpio)
return -ENOMEM; return -ENOMEM;
bdgpio->chip.dev = &pdev->dev; bdgpio->dev = &pdev->dev;
bdgpio->gpio.parent = pdev->dev.parent; bdgpio->gpio.parent = pdev->dev.parent;
bdgpio->gpio.label = "bd70528-gpio"; bdgpio->gpio.label = "bd70528-gpio";
bdgpio->gpio.owner = THIS_MODULE; bdgpio->gpio.owner = THIS_MODULE;
...@@ -210,7 +204,9 @@ static int bd70528_probe(struct platform_device *pdev) ...@@ -210,7 +204,9 @@ static int bd70528_probe(struct platform_device *pdev)
#ifdef CONFIG_OF_GPIO #ifdef CONFIG_OF_GPIO
bdgpio->gpio.of_node = pdev->dev.parent->of_node; bdgpio->gpio.of_node = pdev->dev.parent->of_node;
#endif #endif
bdgpio->chip.regmap = bd70528->regmap; bdgpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!bdgpio->regmap)
return -ENODEV;
ret = devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio, ret = devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio,
bdgpio); bdgpio);
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#define HALL_GPIO_OFFSET 3 #define HALL_GPIO_OFFSET 3
struct bd71828_gpio { struct bd71828_gpio {
struct rohm_regmap_dev chip; struct regmap *regmap;
struct device *dev;
struct gpio_chip gpio; struct gpio_chip gpio;
}; };
...@@ -29,10 +30,10 @@ static void bd71828_gpio_set(struct gpio_chip *chip, unsigned int offset, ...@@ -29,10 +30,10 @@ static void bd71828_gpio_set(struct gpio_chip *chip, unsigned int offset,
if (offset == HALL_GPIO_OFFSET) if (offset == HALL_GPIO_OFFSET)
return; return;
ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), ret = regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset),
BD71828_GPIO_OUT_MASK, val); BD71828_GPIO_OUT_MASK, val);
if (ret) if (ret)
dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value); dev_err(bdgpio->dev, "Could not set gpio to %d\n", value);
} }
static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset) static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset)
...@@ -42,10 +43,10 @@ static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset) ...@@ -42,10 +43,10 @@ static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset)
struct bd71828_gpio *bdgpio = gpiochip_get_data(chip); struct bd71828_gpio *bdgpio = gpiochip_get_data(chip);
if (offset == HALL_GPIO_OFFSET) if (offset == HALL_GPIO_OFFSET)
ret = regmap_read(bdgpio->chip.regmap, BD71828_REG_IO_STAT, ret = regmap_read(bdgpio->regmap, BD71828_REG_IO_STAT,
&val); &val);
else else
ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset),
&val); &val);
if (!ret) if (!ret)
ret = (val & BD71828_GPIO_OUT_MASK); ret = (val & BD71828_GPIO_OUT_MASK);
...@@ -63,12 +64,12 @@ static int bd71828_gpio_set_config(struct gpio_chip *chip, unsigned int offset, ...@@ -63,12 +64,12 @@ static int bd71828_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
switch (pinconf_to_config_param(config)) { switch (pinconf_to_config_param(config)) {
case PIN_CONFIG_DRIVE_OPEN_DRAIN: case PIN_CONFIG_DRIVE_OPEN_DRAIN:
return regmap_update_bits(bdgpio->chip.regmap, return regmap_update_bits(bdgpio->regmap,
GPIO_OUT_REG(offset), GPIO_OUT_REG(offset),
BD71828_GPIO_DRIVE_MASK, BD71828_GPIO_DRIVE_MASK,
BD71828_GPIO_OPEN_DRAIN); BD71828_GPIO_OPEN_DRAIN);
case PIN_CONFIG_DRIVE_PUSH_PULL: case PIN_CONFIG_DRIVE_PUSH_PULL:
return regmap_update_bits(bdgpio->chip.regmap, return regmap_update_bits(bdgpio->regmap,
GPIO_OUT_REG(offset), GPIO_OUT_REG(offset),
BD71828_GPIO_DRIVE_MASK, BD71828_GPIO_DRIVE_MASK,
BD71828_GPIO_PUSH_PULL); BD71828_GPIO_PUSH_PULL);
...@@ -97,20 +98,13 @@ static int bd71828_get_direction(struct gpio_chip *chip, unsigned int offset) ...@@ -97,20 +98,13 @@ static int bd71828_get_direction(struct gpio_chip *chip, unsigned int offset)
static int bd71828_probe(struct platform_device *pdev) static int bd71828_probe(struct platform_device *pdev)
{ {
struct bd71828_gpio *bdgpio; struct bd71828_gpio *bdgpio;
struct rohm_regmap_dev *bd71828;
bd71828 = dev_get_drvdata(pdev->dev.parent);
if (!bd71828) {
dev_err(&pdev->dev, "No MFD driver data\n");
return -EINVAL;
}
bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio), bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio),
GFP_KERNEL); GFP_KERNEL);
if (!bdgpio) if (!bdgpio)
return -ENOMEM; return -ENOMEM;
bdgpio->chip.dev = &pdev->dev; bdgpio->dev = &pdev->dev;
bdgpio->gpio.parent = pdev->dev.parent; bdgpio->gpio.parent = pdev->dev.parent;
bdgpio->gpio.label = "bd71828-gpio"; bdgpio->gpio.label = "bd71828-gpio";
bdgpio->gpio.owner = THIS_MODULE; bdgpio->gpio.owner = THIS_MODULE;
...@@ -128,7 +122,9 @@ static int bd71828_probe(struct platform_device *pdev) ...@@ -128,7 +122,9 @@ static int bd71828_probe(struct platform_device *pdev)
*/ */
bdgpio->gpio.ngpio = 4; bdgpio->gpio.ngpio = 4;
bdgpio->gpio.of_node = pdev->dev.parent->of_node; bdgpio->gpio.of_node = pdev->dev.parent->of_node;
bdgpio->chip.regmap = bd71828->regmap; bdgpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!bdgpio->regmap)
return -ENODEV;
return devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio, return devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio,
bdgpio); bdgpio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment