Re: [Device-mainlining] [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-10-08 Thread Pavel Machek
Hi!

> On 08/16/2015 08:03 PM, Baolin Wang via device-mainlining wrote:
> > On 14 August 2015 at 23:27, Greg KH  wrote:
> >> On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:
> >>> + *
> >>> + * This program is free software; you can redistribute it and/or modify
> >>> + * it under the terms of the GNU General Public License as published by
> >>> + * the Free Software Foundation; either version 2 of the License, or
> >>> + * (at your option) any later version.
> >>
> >> I have to ask, do you really mean "any later version"?
> >>
> > 
> > I think I did not get your point, could you explain it detailedly?
> 
> The full kernel is licensed under v2 of the GPL only, not "any later version".
> See the second paragraph at the top of the COPYING file in the root directory
> of the kernel source tree. There are differences on individual files, but
> having this file allow "any later version" makes it different from much of
> rest of the kernel.
> 
> Unless you have a specific reason to allow greater-than-V2 GPL licensing on 
> this
> file, you should change the licensing clause.  The following wording appears
> to be pretty popular:
> 
> * This program is free software; you can redistribute it and/or modify
> * it under the terms of the GNU General Public License version 2 as
> * published by the Free Software Foundation.

Please, keep it V2 or later, if you can. It makes sharing code with U-Boot (for
example) easier.

There's long tradition of "V2 or later" code in the kernel.

Best regards,
Pavel
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Device-mainlining] [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-10-08 Thread Greg KH
On Thu, Oct 08, 2015 at 05:50:31PM +0200, Pavel Machek wrote:
> Hi!
> 
> > On 08/16/2015 08:03 PM, Baolin Wang via device-mainlining wrote:
> > > On 14 August 2015 at 23:27, Greg KH  wrote:
> > >> On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:
> > >>> + *
> > >>> + * This program is free software; you can redistribute it and/or modify
> > >>> + * it under the terms of the GNU General Public License as published by
> > >>> + * the Free Software Foundation; either version 2 of the License, or
> > >>> + * (at your option) any later version.
> > >>
> > >> I have to ask, do you really mean "any later version"?
> > >>
> > > 
> > > I think I did not get your point, could you explain it detailedly?
> > 
> > The full kernel is licensed under v2 of the GPL only, not "any later 
> > version".
> > See the second paragraph at the top of the COPYING file in the root 
> > directory
> > of the kernel source tree. There are differences on individual files, but
> > having this file allow "any later version" makes it different from much of
> > rest of the kernel.
> > 
> > Unless you have a specific reason to allow greater-than-V2 GPL licensing on 
> > this
> > file, you should change the licensing clause.  The following wording appears
> > to be pretty popular:
> > 
> > * This program is free software; you can redistribute it and/or modify
> > * it under the terms of the GNU General Public License version 2 as
> > * published by the Free Software Foundation.
> 
> Please, keep it V2 or later, if you can. It makes sharing code with U-Boot 
> (for
> example) easier.
> 
> There's long tradition of "V2 or later" code in the kernel.

And there's even longer "v2 only" tradition as well.  It's up to the
person / company submitting the code to pick the license for it, let
them make the decision please.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Device-mainlining] [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-10-08 Thread Pavel Machek
Hi!

> > > * This program is free software; you can redistribute it and/or modify
> > > * it under the terms of the GNU General Public License version 2 as
> > > * published by the Free Software Foundation.
> > 
> > Please, keep it V2 or later, if you can. It makes sharing code with U-Boot 
> > (for
> > example) easier.
> > 
> > There's long tradition of "V2 or later" code in the kernel.
> 
> And there's even longer "v2 only" tradition as well.  It's up to the
> person / company submitting the code to pick the license for it, let
> them make the decision please.

You wrote:

>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>
>I have to ask, do you really mean "any later version"?

Given that you are quite high-level maintainer, that does not sound exactly
like "let them make the decision". It sounds like a pressure to change the
license to the one you liked. WHy did you have to ask?

Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Device-mainlining] [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-10-08 Thread Greg KH
On Thu, Oct 08, 2015 at 07:04:05PM +0200, Pavel Machek wrote:
> Hi!
> 
> > > > * This program is free software; you can redistribute it and/or modify
> > > > * it under the terms of the GNU General Public License version 2 as
> > > > * published by the Free Software Foundation.
> > > 
> > > Please, keep it V2 or later, if you can. It makes sharing code with 
> > > U-Boot (for
> > > example) easier.
> > > 
> > > There's long tradition of "V2 or later" code in the kernel.
> > 
> > And there's even longer "v2 only" tradition as well.  It's up to the
> > person / company submitting the code to pick the license for it, let
> > them make the decision please.
> 
> You wrote:
> 
> >> + *
> >> + * This program is free software; you can redistribute it and/or modify
> >> + * it under the terms of the GNU General Public License as published by
> >> + * the Free Software Foundation; either version 2 of the License, or
> >> + * (at your option) any later version.
> >
> >I have to ask, do you really mean "any later version"?
> 
> Given that you are quite high-level maintainer, that does not sound exactly
> like "let them make the decision". It sounds like a pressure to change the
> license to the one you liked. WHy did you have to ask?

I have to "ask" because I need to ensure that people put thought into
the license they chose instead of blindly cut-and-pasting it from a
random web site.  Companies all have policies on what the license of the
kernel code they produce are, and by nicely asking new developers this
question, it ensures that they are picking the license in a thoughtful
manner.

If they pick v2 vs. v2+ is of no opinion of mine, either is just
wonderful.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-17 Thread Baolin Wang
On 18 August 2015 at 01:24, Mark Brown broo...@kernel.org wrote:
 On Mon, Aug 17, 2015 at 11:03:26AM +0800, Baolin Wang wrote:
 On 14 August 2015 at 23:27, Greg KH gre...@linuxfoundation.org wrote:
  On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:

  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License as published by
  + * the Free Software Foundation; either version 2 of the License, or
  + * (at your option) any later version.

  I have to ask, do you really mean any later version?

 I think I did not get your point, could you explain it detailedly?

 Unlike a lot of userspace projects the kernel is normally just licensed
 under GPLv2 without the option to relicense with a later version so the
 ...or any later version is a bit unusual.  There is some controversy
 about some of the changes in GPLv3.

Make sense. Thanks a lot.


-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Device-mainlining] [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-17 Thread Baolin Wang
On 17 August 2015 at 23:25, Tim Bird tim.b...@sonymobile.com wrote:


 On 08/16/2015 08:03 PM, Baolin Wang via device-mainlining wrote:
 On 14 August 2015 at 23:27, Greg KH gre...@linuxfoundation.org wrote:
 On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.

 I have to ask, do you really mean any later version?


 I think I did not get your point, could you explain it detailedly?

 The full kernel is licensed under v2 of the GPL only, not any later version.
 See the second paragraph at the top of the COPYING file in the root directory
 of the kernel source tree. There are differences on individual files, but
 having this file allow any later version makes it different from much of
 rest of the kernel.

 Unless you have a specific reason to allow greater-than-V2 GPL licensing on 
 this
 file, you should change the licensing clause.  The following wording appears
 to be pretty popular:

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.


Hi Tim,

Make sense of it. Thanks for your explanation.

   -- Tim



-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-17 Thread Mark Brown
On Mon, Aug 17, 2015 at 11:03:26AM +0800, Baolin Wang wrote:
 On 14 August 2015 at 23:27, Greg KH gre...@linuxfoundation.org wrote:
  On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:

  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License as published by
  + * the Free Software Foundation; either version 2 of the License, or
  + * (at your option) any later version.

  I have to ask, do you really mean any later version?

 I think I did not get your point, could you explain it detailedly?

Unlike a lot of userspace projects the kernel is normally just licensed
under GPLv2 without the option to relicense with a later version so the
...or any later version is a bit unusual.  There is some controversy
about some of the changes in GPLv3.


signature.asc
Description: Digital signature


Re: [Device-mainlining] [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-17 Thread Tim Bird


On 08/16/2015 08:03 PM, Baolin Wang via device-mainlining wrote:
 On 14 August 2015 at 23:27, Greg KH gre...@linuxfoundation.org wrote:
 On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.

 I have to ask, do you really mean any later version?

 
 I think I did not get your point, could you explain it detailedly?

The full kernel is licensed under v2 of the GPL only, not any later version.
See the second paragraph at the top of the COPYING file in the root directory
of the kernel source tree. There are differences on individual files, but
having this file allow any later version makes it different from much of
rest of the kernel.

Unless you have a specific reason to allow greater-than-V2 GPL licensing on this
file, you should change the licensing clause.  The following wording appears
to be pretty popular:

* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.

  -- Tim
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-16 Thread Baolin Wang
On 14 August 2015 at 23:27, Greg KH gre...@linuxfoundation.org wrote:
 On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:
 This patch introduces the usb charger driver based on usb gadget that
 makes an enhancement to a power driver. It works well in practice but
 that requires a system with suitable hardware.

 The basic conception of the usb charger is that, when one usb charger
 is added or removed by reporting from the usb gadget state change or
 the extcon device state change, the usb charger will report to power
 user to set the current limitation.

 The usb charger will register notifiees on the usb gadget or the extcon
 device to get notified the usb charger state.

 Power user will register a notifiee on the usb charger to get notified
 by status changes from the usb charger. It will report to power user
 to set the current limitation when detecting the usb charger is added
 or removed from extcon device state or usb gadget state.

 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/Kconfig  |7 +
  drivers/usb/gadget/Makefile |1 +
  drivers/usb/gadget/charger.c|  561 
 +++
  include/linux/usb/usb_charger.h |  145 ++
  4 files changed, 714 insertions(+)
  create mode 100644 drivers/usb/gadget/charger.c
  create mode 100644 include/linux/usb/usb_charger.h

 diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
 index bcf83c0..3d2b959 100644
 --- a/drivers/usb/gadget/Kconfig
 +++ b/drivers/usb/gadget/Kconfig
 @@ -127,6 +127,13 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
  a module parameter as well.
  If unsure, say 2.

 +config USB_CHARGER
 + bool USB charger support
 + help
 +   The usb charger driver based on the usb gadget that makes an
 +   enhancement to a power driver which can set the current limitation
 +   when the usb charger is added or removed.
 +
  source drivers/usb/gadget/udc/Kconfig

  #
 diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
 index 598a67d..1e421c1 100644
 --- a/drivers/usb/gadget/Makefile
 +++ b/drivers/usb/gadget/Makefile
 @@ -10,3 +10,4 @@ libcomposite-y  := usbstring.o 
 config.o epautoconf.o
  libcomposite-y   += composite.o functions.o configfs.o 
 u_f.o

  obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/
 +obj-$(CONFIG_USB_CHARGER)+= charger.o
 diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
 new file mode 100644
 index 000..f24f7b7
 --- /dev/null
 +++ b/drivers/usb/gadget/charger.c
 @@ -0,0 +1,561 @@
 +/*
 + * usb charger.c -- USB charger driver

 I think your company also wants a copyright line here.  Not that it
 means anything at all, but some lawyers love cargo-cult text blobs.


Hi Greg,

Thanks for your reviewing and comments. I'll add it in next patch.


 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.

 I have to ask, do you really mean any later version?


I think I did not get your point, could you explain it detailedly?

 + */
 +
 +#include linux/device.h
 +#include linux/err.h
 +#include linux/extcon.h
 +#include linux/export.h
 +#include linux/kernel.h
 +#include linux/module.h
 +#include linux/of.h
 +#include linux/of_device.h
 +#include linux/of_address.h
 +#include linux/platform_device.h
 +#include linux/slab.h
 +#include linux/usb.h
 +#include linux/usb/ch9.h
 +#include linux/usb/gadget.h
 +#include linux/usb/usb_charger.h
 +
 +#define DEFAULT_CUR_PROTECT  (50)
 +#define DEFAULT_SDP_CUR_LIMIT(500 - DEFAULT_CUR_PROTECT)
 +#define DEFAULT_DCP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
 +#define DEFAULT_CDP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
 +#define DEFAULT_ACA_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
 +
 +static DEFINE_IDA(usb_charger_ida);
 +static struct bus_type usb_charger_subsys = {
 + .name   = usb-charger,
 + .dev_name   = usb-charger,
 +};
 +
 +static struct usb_charger *dev_to_uchger(struct device *udev)
 +{
 + return container_of(udev, struct usb_charger, dev);
 +}
 +
 +static ssize_t usb_charger_cur_show(struct device *dev,
 + struct device_attribute *attr,
 + char *buf)
 +{
 + struct usb_charger *uchger = dev_to_uchger(dev);
 +
 + return scnprintf(buf, PAGE_SIZE, %d %d %d %d\n,
 +  uchger-cur_limit.sdp_cur_limit,
 +  uchger-cur_limit.dcp_cur_limit,
 +  uchger-cur_limit.cdp_cur_limit,
 +  uchger-cur_limit.aca_cur_limit);
 +}
 +
 +static ssize_t usb_charger_cur_store(struct device *dev,
 +  struct device_attribute *attr,
 +

Re: [PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-14 Thread Greg KH
On Fri, Aug 14, 2015 at 05:47:45PM +0800, Baolin Wang wrote:
 This patch introduces the usb charger driver based on usb gadget that
 makes an enhancement to a power driver. It works well in practice but
 that requires a system with suitable hardware.
 
 The basic conception of the usb charger is that, when one usb charger
 is added or removed by reporting from the usb gadget state change or
 the extcon device state change, the usb charger will report to power
 user to set the current limitation.
 
 The usb charger will register notifiees on the usb gadget or the extcon
 device to get notified the usb charger state.
 
 Power user will register a notifiee on the usb charger to get notified
 by status changes from the usb charger. It will report to power user
 to set the current limitation when detecting the usb charger is added
 or removed from extcon device state or usb gadget state.
 
 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/Kconfig  |7 +
  drivers/usb/gadget/Makefile |1 +
  drivers/usb/gadget/charger.c|  561 
 +++
  include/linux/usb/usb_charger.h |  145 ++
  4 files changed, 714 insertions(+)
  create mode 100644 drivers/usb/gadget/charger.c
  create mode 100644 include/linux/usb/usb_charger.h
 
 diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
 index bcf83c0..3d2b959 100644
 --- a/drivers/usb/gadget/Kconfig
 +++ b/drivers/usb/gadget/Kconfig
 @@ -127,6 +127,13 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
  a module parameter as well.
  If unsure, say 2.
  
 +config USB_CHARGER
 + bool USB charger support
 + help
 +   The usb charger driver based on the usb gadget that makes an
 +   enhancement to a power driver which can set the current limitation
 +   when the usb charger is added or removed.
 +
  source drivers/usb/gadget/udc/Kconfig
  
  #
 diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
 index 598a67d..1e421c1 100644
 --- a/drivers/usb/gadget/Makefile
 +++ b/drivers/usb/gadget/Makefile
 @@ -10,3 +10,4 @@ libcomposite-y  := usbstring.o config.o 
 epautoconf.o
  libcomposite-y   += composite.o functions.o configfs.o 
 u_f.o
  
  obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/
 +obj-$(CONFIG_USB_CHARGER)+= charger.o
 diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
 new file mode 100644
 index 000..f24f7b7
 --- /dev/null
 +++ b/drivers/usb/gadget/charger.c
 @@ -0,0 +1,561 @@
 +/*
 + * usb charger.c -- USB charger driver

I think your company also wants a copyright line here.  Not that it
means anything at all, but some lawyers love cargo-cult text blobs.


 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.

I have to ask, do you really mean any later version?

 + */
 +
 +#include linux/device.h
 +#include linux/err.h
 +#include linux/extcon.h
 +#include linux/export.h
 +#include linux/kernel.h
 +#include linux/module.h
 +#include linux/of.h
 +#include linux/of_device.h
 +#include linux/of_address.h
 +#include linux/platform_device.h
 +#include linux/slab.h
 +#include linux/usb.h
 +#include linux/usb/ch9.h
 +#include linux/usb/gadget.h
 +#include linux/usb/usb_charger.h
 +
 +#define DEFAULT_CUR_PROTECT  (50)
 +#define DEFAULT_SDP_CUR_LIMIT(500 - DEFAULT_CUR_PROTECT)
 +#define DEFAULT_DCP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
 +#define DEFAULT_CDP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
 +#define DEFAULT_ACA_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
 +
 +static DEFINE_IDA(usb_charger_ida);
 +static struct bus_type usb_charger_subsys = {
 + .name   = usb-charger,
 + .dev_name   = usb-charger,
 +};
 +
 +static struct usb_charger *dev_to_uchger(struct device *udev)
 +{
 + return container_of(udev, struct usb_charger, dev);
 +}
 +
 +static ssize_t usb_charger_cur_show(struct device *dev,
 + struct device_attribute *attr,
 + char *buf)
 +{
 + struct usb_charger *uchger = dev_to_uchger(dev);
 +
 + return scnprintf(buf, PAGE_SIZE, %d %d %d %d\n,
 +  uchger-cur_limit.sdp_cur_limit,
 +  uchger-cur_limit.dcp_cur_limit,
 +  uchger-cur_limit.cdp_cur_limit,
 +  uchger-cur_limit.aca_cur_limit);
 +}
 +
 +static ssize_t usb_charger_cur_store(struct device *dev,
 +  struct device_attribute *attr,
 +  const char *buf, size_t count)
 +{
 + struct usb_charger *uchger = dev_to_uchger(dev);
 + struct usb_charger_cur_limit cur;
 + int ret;
 +
 + ret = sscanf(buf, %d %d %d %d,
 +  

[PATCH v2 2/3] gadget: Introduce the usb charger framework

2015-08-14 Thread Baolin Wang
This patch introduces the usb charger driver based on usb gadget that
makes an enhancement to a power driver. It works well in practice but
that requires a system with suitable hardware.

The basic conception of the usb charger is that, when one usb charger
is added or removed by reporting from the usb gadget state change or
the extcon device state change, the usb charger will report to power
user to set the current limitation.

The usb charger will register notifiees on the usb gadget or the extcon
device to get notified the usb charger state.

Power user will register a notifiee on the usb charger to get notified
by status changes from the usb charger. It will report to power user
to set the current limitation when detecting the usb charger is added
or removed from extcon device state or usb gadget state.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 drivers/usb/gadget/Kconfig  |7 +
 drivers/usb/gadget/Makefile |1 +
 drivers/usb/gadget/charger.c|  561 +++
 include/linux/usb/usb_charger.h |  145 ++
 4 files changed, 714 insertions(+)
 create mode 100644 drivers/usb/gadget/charger.c
 create mode 100644 include/linux/usb/usb_charger.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index bcf83c0..3d2b959 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -127,6 +127,13 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
   a module parameter as well.
   If unsure, say 2.
 
+config USB_CHARGER
+   bool USB charger support
+   help
+ The usb charger driver based on the usb gadget that makes an
+ enhancement to a power driver which can set the current limitation
+ when the usb charger is added or removed.
+
 source drivers/usb/gadget/udc/Kconfig
 
 #
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 598a67d..1e421c1 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -10,3 +10,4 @@ libcomposite-y:= usbstring.o config.o 
epautoconf.o
 libcomposite-y += composite.o functions.o configfs.o u_f.o
 
 obj-$(CONFIG_USB_GADGET)   += udc/ function/ legacy/
+obj-$(CONFIG_USB_CHARGER)  += charger.o
diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
new file mode 100644
index 000..f24f7b7
--- /dev/null
+++ b/drivers/usb/gadget/charger.c
@@ -0,0 +1,561 @@
+/*
+ * usb charger.c -- USB charger driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include linux/device.h
+#include linux/err.h
+#include linux/extcon.h
+#include linux/export.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/of.h
+#include linux/of_device.h
+#include linux/of_address.h
+#include linux/platform_device.h
+#include linux/slab.h
+#include linux/usb.h
+#include linux/usb/ch9.h
+#include linux/usb/gadget.h
+#include linux/usb/usb_charger.h
+
+#define DEFAULT_CUR_PROTECT(50)
+#define DEFAULT_SDP_CUR_LIMIT  (500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_DCP_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_CDP_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_ACA_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+
+static DEFINE_IDA(usb_charger_ida);
+static struct bus_type usb_charger_subsys = {
+   .name   = usb-charger,
+   .dev_name   = usb-charger,
+};
+
+static struct usb_charger *dev_to_uchger(struct device *udev)
+{
+   return container_of(udev, struct usb_charger, dev);
+}
+
+static ssize_t usb_charger_cur_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct usb_charger *uchger = dev_to_uchger(dev);
+
+   return scnprintf(buf, PAGE_SIZE, %d %d %d %d\n,
+uchger-cur_limit.sdp_cur_limit,
+uchger-cur_limit.dcp_cur_limit,
+uchger-cur_limit.cdp_cur_limit,
+uchger-cur_limit.aca_cur_limit);
+}
+
+static ssize_t usb_charger_cur_store(struct device *dev,
+struct device_attribute *attr,
+const char *buf, size_t count)
+{
+   struct usb_charger *uchger = dev_to_uchger(dev);
+   struct usb_charger_cur_limit cur;
+   int ret;
+
+   ret = sscanf(buf, %d %d %d %d,
+cur.sdp_cur_limit, cur.dcp_cur_limit,
+cur.cdp_cur_limit, cur.aca_cur_limit);
+   if (ret == 0)
+   return -EINVAL;
+
+   ret = usb_charger_set_cur_limit(uchger, cur);
+   if (ret  0)
+   return ret;
+
+   return count;
+}
+static DEVICE_ATTR(cur_limit, 0644, usb_charger_cur_show,