mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* power_supply: USB charging question
@ 2011-07-28 12:38 Heikki Krogerus
  0 siblings, 0 replies; only message in thread
From: Heikki Krogerus @ 2011-07-28 12:38 UTC (permalink / raw)
  To: Anton Vorontsov, David Woodhouse; +Cc: linux-kernel

Hi,

I'm looking for a way to create generic USB charging support. I want
to take advantage of the power supply class, but there is one problem.
How do I get properties from the external power supply?

The batteries need to get the CURRENT_MAX property from USB chargers.
It's not enough to be aware are they supplied or not. We must obey the
bMaxPower field from the USB configuration that the USB host has
selected when charging from normal downstream port.

There are several ways that I thought could solve this. Firstly,
simply deliver the external power_supply with the
external_power_changed hook and leave the problem to the drivers. This
did not feel like an ideal solution.

Next idea. Add functions for getting properties from the supplying
power supply:

static int power_supply_find_supplier(struct device *dev, void
data)
{
       struct power_supply *psy = (struct power_supply *)data;
       struct power_supply *epsy = dev_get_drvdata(dev);
       int i;

       for (i = 0; i < epsy->num_supplicants; i++)
               if (!strcmp(epsy->supplied_to[i], psy->name))
                       return 1;
                       
       return 0;
}

int power_supply_get_supplier_property(struct power_supply *psy,
                                       enum power_supply_property psp,
                                       union power_supply_propval *val);
{
       struct power_supply *epsy;
       struct device *dev;

       dev = class_find_device(power_supply_class, NULL, psy,
                               power_supply_find_supplier);
       if (!dev)
               return 1;

       epsy = dev_get_drvdata(dev);
       put_device(dev);

       return epsy->get_property(epsy, psp, &val);
}
EXPORT_SYMBOL_GPL(power_supply_get_supplier_property);


Third idea. We only need to know how much are we allowed to draw, so
add a function for that purpose only. Something like
"power_supply_how_much_can_i_draw". Same as power_supply_am_i_supplied()
except the property would be POWER_SUPPLY_PROP_CURRENT_MAX.

How do you think this should be handled? What would be the best
solution?

-- 
heikki

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-07-28 12:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-28 12:38 power_supply: USB charging question Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®