power: supply: gpio-charger: use helper variable to access device info

Using explicit struct device variable makes code a bit more readable.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
This commit is contained in:
Ladislav Michl 2018-01-17 21:31:49 +01:00 committed by Sebastian Reichel
parent 419cac572b
commit 416a1ae673
1 changed files with 20 additions and 22 deletions

View File

@ -118,7 +118,8 @@ struct gpio_charger_platform_data *gpio_charger_parse_dt(struct device *dev)
static int gpio_charger_probe(struct platform_device *pdev) static int gpio_charger_probe(struct platform_device *pdev)
{ {
const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data; struct device *dev = &pdev->dev;
const struct gpio_charger_platform_data *pdata = dev->platform_data;
struct power_supply_config psy_cfg = {}; struct power_supply_config psy_cfg = {};
struct gpio_charger *gpio_charger; struct gpio_charger *gpio_charger;
struct power_supply_desc *charger_desc; struct power_supply_desc *charger_desc;
@ -126,19 +127,18 @@ static int gpio_charger_probe(struct platform_device *pdev)
int irq; int irq;
if (!pdata) { if (!pdata) {
pdata = gpio_charger_parse_dt(&pdev->dev); pdata = gpio_charger_parse_dt(dev);
if (IS_ERR(pdata)) { if (IS_ERR(pdata)) {
ret = PTR_ERR(pdata); ret = PTR_ERR(pdata);
if (ret != -EPROBE_DEFER) if (ret != -EPROBE_DEFER)
dev_err(&pdev->dev, "No platform data\n"); dev_err(dev, "No platform data\n");
return ret; return ret;
} }
} }
gpio_charger = devm_kzalloc(&pdev->dev, sizeof(*gpio_charger), gpio_charger = devm_kzalloc(dev, sizeof(*gpio_charger), GFP_KERNEL);
GFP_KERNEL);
if (!gpio_charger) { if (!gpio_charger) {
dev_err(&pdev->dev, "Failed to alloc driver structure\n"); dev_err(dev, "Failed to alloc driver structure\n");
return -ENOMEM; return -ENOMEM;
} }
@ -146,20 +146,20 @@ static int gpio_charger_probe(struct platform_device *pdev)
* This will fetch a GPIO descriptor from device tree, ACPI or * This will fetch a GPIO descriptor from device tree, ACPI or
* boardfile descriptor tables. It's good to try this first. * boardfile descriptor tables. It's good to try this first.
*/ */
gpio_charger->gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_IN); gpio_charger->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
/* /*
* If this fails and we're not using device tree, try the * If this fails and we're not using device tree, try the
* legacy platform data method. * legacy platform data method.
*/ */
if (IS_ERR(gpio_charger->gpiod) && !pdev->dev.of_node) { if (IS_ERR(gpio_charger->gpiod) && !dev->of_node) {
/* Non-DT: use legacy GPIO numbers */ /* Non-DT: use legacy GPIO numbers */
if (!gpio_is_valid(pdata->gpio)) { if (!gpio_is_valid(pdata->gpio)) {
dev_err(&pdev->dev, "Invalid gpio pin in pdata\n"); dev_err(dev, "Invalid gpio pin in pdata\n");
return -EINVAL; return -EINVAL;
} }
ret = devm_gpio_request_one(&pdev->dev, pdata->gpio, GPIOF_IN, ret = devm_gpio_request_one(dev, pdata->gpio, GPIOF_IN,
dev_name(&pdev->dev)); dev_name(dev));
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to request gpio pin: %d\n", dev_err(&pdev->dev, "Failed to request gpio pin: %d\n",
ret); ret);
@ -171,7 +171,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
/* Just try again if this happens */ /* Just try again if this happens */
if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER) if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
dev_err(&pdev->dev, "error getting GPIO descriptor\n"); dev_err(dev, "error getting GPIO descriptor\n");
return PTR_ERR(gpio_charger->gpiod); return PTR_ERR(gpio_charger->gpiod);
} }
@ -185,33 +185,31 @@ static int gpio_charger_probe(struct platform_device *pdev)
psy_cfg.supplied_to = pdata->supplied_to; psy_cfg.supplied_to = pdata->supplied_to;
psy_cfg.num_supplicants = pdata->num_supplicants; psy_cfg.num_supplicants = pdata->num_supplicants;
psy_cfg.of_node = pdev->dev.of_node; psy_cfg.of_node = dev->of_node;
psy_cfg.drv_data = gpio_charger; psy_cfg.drv_data = gpio_charger;
gpio_charger->charger = devm_power_supply_register(&pdev->dev, gpio_charger->charger = devm_power_supply_register(dev, charger_desc,
charger_desc, &psy_cfg); &psy_cfg);
if (IS_ERR(gpio_charger->charger)) { if (IS_ERR(gpio_charger->charger)) {
ret = PTR_ERR(gpio_charger->charger); ret = PTR_ERR(gpio_charger->charger);
dev_err(&pdev->dev, "Failed to register power supply: %d\n", dev_err(dev, "Failed to register power supply: %d\n", ret);
ret);
return ret; return ret;
} }
irq = gpiod_to_irq(gpio_charger->gpiod); irq = gpiod_to_irq(gpio_charger->gpiod);
if (irq > 0) { if (irq > 0) {
ret = devm_request_any_context_irq(&pdev->dev, irq, ret = devm_request_any_context_irq(dev, irq, gpio_charger_irq,
gpio_charger_irq,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
dev_name(&pdev->dev), gpio_charger->charger); dev_name(dev), gpio_charger->charger);
if (ret < 0) if (ret < 0)
dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret); dev_warn(dev, "Failed to request irq: %d\n", ret);
else else
gpio_charger->irq = irq; gpio_charger->irq = irq;
} }
platform_set_drvdata(pdev, gpio_charger); platform_set_drvdata(pdev, gpio_charger);
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(dev, 1);
return 0; return 0;
} }