All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linaro.org>
To: Felipe Balbi <balbi@kernel.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	Sebastian Reichel <sre@kernel.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	robh@kernel.org, Jun Li <jun.li@nxp.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	Peter Chen <peter.chen@freescale.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	r.baldyga@samsung.com, grygorii.strashko@ti.com,
	Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
	Lee Jones <lee.jones@linaro.org>, Mark Brown <broonie@kernel.org>,
	Charles Keepax <ckeepax@opensource.wolfsonmicro.com>,
	patches@opensource.wolfsonmicro.com,
	Linux PM list <linux-pm@vger.kernel.org>,
	USB <linux-usb@vger.kernel.org>,
	device-mainlining@lists.linuxfoundation.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v14 1/4] usb: gadget: Introduce the usb charger framework
Date: Thu, 30 Jun 2016 19:01:06 +0800	[thread overview]
Message-ID: <CAMz4kuKk6H1wdMEH4qNt+4-Q+KSq_ScYkZPMLfVCrPzK6Fprtw@mail.gmail.com> (raw)
In-Reply-To: <87y45nezov.fsf@linux.intel.com>

Hi Felipe,

On 30 June 2016 at 18:30, Felipe Balbi <balbi@kernel.org> wrote:
>
> Hi,
>
> Baolin Wang <baolin.wang@linaro.org> writes:
>> +static ssize_t charger_state_show(struct device *dev,
>> +                               struct device_attribute *attr,
>> +                               char *buf)
>> +{
>> +     struct usb_charger *uchger = dev_to_uchger(dev);
>> +     int cnt;
>> +
>> +     switch (uchger->state) {
>> +     case USB_CHARGER_PRESENT:
>> +             cnt = sprintf(buf, "%s\n", "PRESENT");
>> +             break;
>> +     case USB_CHARGER_REMOVE:
>> +             cnt = sprintf(buf, "%s\n", "REMOVE");
>> +             break;
>> +     default:
>> +             cnt = sprintf(buf, "%s\n", "UNKNOWN");
>> +             break;
>
> are these the only states we need? Don't we need at least "CHARGING" and
> "ERROR" or something like that? Maybe those are exposed elsewhere,
> dunno.

Present state means we are charging. For charging error, I think it
can be exposed in power driver, which is more proper. Until now I only
see PRESENT and REMOVE state are useful.

>
>> +static int __usb_charger_set_cur_limit_by_type(struct usb_charger *uchger,
>> +                                            enum usb_charger_type type,
>> +                                            unsigned int cur_limit)
>> +{
>> +     if (WARN(!uchger, "charger can not be NULL"))
>> +             return -EINVAL;
>
> IIRC, I mentioned that this should assume charger to be a valid
> pointer. Look at this, for a second:
>
> You check that you have a valid pointer here...

Okay. I will remove this.

>
>> +int usb_charger_set_cur_limit_by_type(struct usb_charger *uchger,
>> +                                   enum usb_charger_type type,
>> +                                   unsigned int cur_limit)
>> +{
>> +     int ret;
>> +
>> +     if (WARN(!uchger, "charger can not be NULL"))
>> +             return -EINVAL;
>
> ... and here, before calling the other function. This is the only place
> which should check for valid uchger.

Okay.

>
>> +     mutex_lock(&uchger->lock);
>> +     ret = __usb_charger_set_cur_limit_by_type(uchger, type, cur_limit);
>> +     mutex_unlock(&uchger->lock);
>> +
>> +     return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(usb_charger_set_cur_limit_by_type);
>> +
>> +/*
>> + * usb_charger_set_cur_limit() - Set the current limitation.
>> + * @uchger - the usb charger instance.
>> + * @cur_limit_set - the current limitation.
>> + */
>> +int usb_charger_set_cur_limit(struct usb_charger *uchger,
>> +                           struct usb_charger_cur_limit *cur_limit_set)
>> +{
>> +     if (WARN(!uchger || !cur_limit_set, "charger or setting can't be NULL"))
>> +             return -EINVAL;
>
> I can see a pattern here. Not *all* errors need a splat. Sometimes a
> simple pr_err() or dev_err() (when you have a valid dev pointer) are
> enough.

Make sense.

>
>> diff --git a/include/linux/usb/charger.h b/include/linux/usb/charger.h
>> new file mode 100644
>> index 0000000..d2e745e
>> --- /dev/null
>> +++ b/include/linux/usb/charger.h
>> @@ -0,0 +1,164 @@
>> +#ifndef __LINUX_USB_CHARGER_H__
>> +#define __LINUX_USB_CHARGER_H__
>> +
>> +#include <uapi/linux/usb/ch9.h>
>> +#include <uapi/linux/usb/charger.h>
>> +
>> +#define CHARGER_NAME_MAX 30
>> +
>> +/* Current limitation by charger type */
>> +struct usb_charger_cur_limit {
>> +     unsigned int sdp_cur_limit;
>> +     unsigned int dcp_cur_limit;
>> +     unsigned int cdp_cur_limit;
>> +     unsigned int aca_cur_limit;
>> +};
>> +
>> +struct usb_charger_nb {
>> +     struct notifier_block   nb;
>> +     struct usb_charger      *uchger;
>> +};
>> +
>
> please add KernelDoc here. And mention the fields which aren't supposed
> to be accessed directly but should rely on the accessor functions. At
> least type and state prefer to be accessed by their respective
> getter/setter methods.

Will add kernel doc for struct usb_charger. Thanks for your comments.

>
>> +struct usb_charger {
>> +     char                    name[CHARGER_NAME_MAX];
>> +     struct list_head        list;
>> +     struct raw_notifier_head        uchger_nh;
>> +     /* protect the notifier head and charger */
>> +     struct mutex            lock;
>> +     int                     id;
>> +     enum usb_charger_type   type;
>> +     enum usb_charger_state  state;
>> +
>> +     /* for supporting extcon usb gpio */
>> +     struct extcon_dev       *extcon_dev;
>> +     struct usb_charger_nb   extcon_nb;
>> +
>> +     /* for supporting usb gadget */
>> +     struct usb_gadget       *gadget;
>> +     enum usb_device_state   old_gadget_state;
>> +
>> +     /* for supporting power supply */
>> +     struct power_supply     *psy;
>> +
>> +     /* user can get charger type by implementing this callback */
>> +     enum usb_charger_type   (*get_charger_type)(struct usb_charger *);
>> +     /*
>> +      * charger detection method can be implemented if you need to
>> +      * manually detect the charger type.
>> +      */
>> +     enum usb_charger_type   (*charger_detect)(struct usb_charger *);
>> +
>> +     /* current limitation */
>> +     struct usb_charger_cur_limit    cur_limit;
>> +     /* to check if it is needed to change the SDP charger default current */
>> +     unsigned int            sdp_default_cur_change;
>> +};
>
> --
> balbi



-- 
Baolin.wang
Best Regards

  reply	other threads:[~2016-06-30 11:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-30  5:35 [PATCH v14 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
2016-06-30  5:35 ` [PATCH v14 1/4] usb: gadget: Introduce the usb charger framework Baolin Wang
2016-06-30 10:30   ` Felipe Balbi
2016-06-30 10:30     ` Felipe Balbi
2016-06-30 11:01     ` Baolin Wang [this message]
2016-06-30  5:35 ` [PATCH v14 2/4] usb: gadget: Support for " Baolin Wang
2016-06-30  5:35 ` [PATCH v14 3/4] usb: gadget: Integrate with the usb gadget supporting for usb charger Baolin Wang
2016-06-30  5:35 ` [PATCH v14 4/4] power: wm831x_power: Support USB charger current limit management Baolin Wang

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=CAMz4kuKk6H1wdMEH4qNt+4-Q+KSq_ScYkZPMLfVCrPzK6Fprtw@mail.gmail.com \
    --to=baolin.wang@linaro.org \
    --cc=balbi@kernel.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=dbaryshkov@gmail.com \
    --cc=device-mainlining@lists.linuxfoundation.org \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=grygorii.strashko@ti.com \
    --cc=jun.li@nxp.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=peter.chen@freescale.com \
    --cc=r.baldyga@samsung.com \
    --cc=robh@kernel.org \
    --cc=ruslan.bilovol@gmail.com \
    --cc=sre@kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.