Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ef45106 authored by Dmitry Eremin-Solenikov's avatar Dmitry Eremin-Solenikov Committed by Anton Vorontsov
Browse files

pda_power: only register available psu



Currently pda-power adds both ac and usb power supply units.
This patch fixes it so that psu are added only if they are enabled.

Signed-off-by: default avatarDmitry Baryshkov <dbaryshkov@gmail.com>
Signed-off-by: default avatarAnton Vorontsov <cbou@mail.ru>
parent 839dc9f1
Loading
Loading
Loading
Loading
+44 −36
Original line number Diff line number Diff line
@@ -168,18 +168,12 @@ static int pda_power_probe(struct platform_device *pdev)
		pda_power_supplies[1].num_supplicants = pdata->num_supplicants;
	}

	if (pdata->is_ac_online) {
		ret = power_supply_register(&pdev->dev, &pda_power_supplies[0]);
		if (ret) {
			dev_err(dev, "failed to register %s power supply\n",
				pda_power_supplies[0].name);
		goto supply0_failed;
	}

	ret = power_supply_register(&pdev->dev, &pda_power_supplies[1]);
	if (ret) {
		dev_err(dev, "failed to register %s power supply\n",
			pda_power_supplies[1].name);
		goto supply1_failed;
			goto ac_supply_failed;
		}

		if (ac_irq) {
@@ -191,42 +185,56 @@ static int pda_power_probe(struct platform_device *pdev)
				goto ac_irq_failed;
			}
		}
	}

	if (pdata->is_usb_online) {
		ret = power_supply_register(&pdev->dev, &pda_power_supplies[1]);
		if (ret) {
			dev_err(dev, "failed to register %s power supply\n",
				pda_power_supplies[1].name);
			goto usb_supply_failed;
		}

		if (usb_irq) {
			ret = request_irq(usb_irq->start, power_changed_isr,
				  get_irq_flags(usb_irq), usb_irq->name,
					  get_irq_flags(usb_irq),
					  usb_irq->name,
					  &pda_power_supplies[1]);
			if (ret) {
				dev_err(dev, "request usb irq failed\n");
				goto usb_irq_failed;
			}
		}
	}

	goto success;
	return 0;

usb_irq_failed:
	if (ac_irq)
	if (pdata->is_usb_online)
		power_supply_unregister(&pda_power_supplies[1]);
usb_supply_failed:
	if (pdata->is_ac_online && ac_irq)
		free_irq(ac_irq->start, &pda_power_supplies[0]);
ac_irq_failed:
	power_supply_unregister(&pda_power_supplies[1]);
supply1_failed:
	if (pdata->is_ac_online)
		power_supply_unregister(&pda_power_supplies[0]);
supply0_failed:
ac_supply_failed:
noirqs:
wrongid:
success:
	return ret;
}

static int pda_power_remove(struct platform_device *pdev)
{
	if (usb_irq)
	if (pdata->is_usb_online && usb_irq)
		free_irq(usb_irq->start, &pda_power_supplies[1]);
	if (ac_irq)
	if (pdata->is_ac_online && ac_irq)
		free_irq(ac_irq->start, &pda_power_supplies[0]);
	del_timer_sync(&charger_timer);
	del_timer_sync(&supply_timer);
	if (pdata->is_usb_online)
		power_supply_unregister(&pda_power_supplies[1]);
	if (pdata->is_ac_online)
		power_supply_unregister(&pda_power_supplies[0]);
	return 0;
}