mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Anton Vorontsov <cbouatmailru@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>
Cc: linux-kernel@vger.kernel.org
Subject: power_supply: USB charging question
Date: Thu, 28 Jul 2011 15:38:42 +0300	[thread overview]
Message-ID: <20110728123842.GA10955@xps8300> (raw)

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

                 reply	other threads:[~2011-07-28 12:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110728123842.GA10955@xps8300 \
    --to=heikki.krogerus@linux.intel.com \
    --cc=cbouatmailru@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®