Re: [PATCH 0/1] USB Audio Device Class 3.0 Gadget support

2017-12-07 Thread Ruslan Bilovol
Hi Felipe,

On Mon, Dec 4, 2017 at 1:36 PM, Felipe Balbi  wrote:
>
> Hi,
>
> Ruslan Bilovol  writes:
>> On Tue, Nov 7, 2017 at 3:52 AM, Ruslan Bilovol  
>> wrote:
>>> Hi,
>>>
>>> This patch adds USB Audio Device Class 3.0 [1] function
>>> support to gadget subsystem.
>>> I didn't add UAC3 support to legacy gadget as it will
>>> make preprocessor configuration too complex (UAC3 device
>>> must have two configurations for backward compatibility,
>>> first is UAC1/2 and second is UAC3), yet also I'm too lazy
>>> to do that and verify all possible configurations.
>>>
>>> For modern ConfigFS interface I'll provide my configuration
>>> for testing below; testing was done on a BeagleBone Black
>>> board.
>>>
>>> This patch depends on uac3 header files from include dir
>>> which I'll post as part of ALSA host UAC3 patch and will
>>> provide the link to it here.
>>
>> http://www.spinics.net/lists/alsa-devel/msg69071.html
>
> Once that patch hits upstream, then we can queue this for merge window
> otherwise we will just have issues and create unbisectable points in the
> tree.

Takashi promised to create an immutable branch for that purpose.

However, I'm currently reworking configfs part of UAC3 for channels
configuration handling, which is now more clear after sharing missing
parts of UAC3 spec by Pierre-Louis Bossart during host side patches
review; so I will send v2 soon.

Thanks,
Ruslan
--
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 0/1] USB Audio Device Class 3.0 Gadget support

2017-12-04 Thread Felipe Balbi

Hi,

Ruslan Bilovol  writes:
> On Tue, Nov 7, 2017 at 3:52 AM, Ruslan Bilovol  
> wrote:
>> Hi,
>>
>> This patch adds USB Audio Device Class 3.0 [1] function
>> support to gadget subsystem.
>> I didn't add UAC3 support to legacy gadget as it will
>> make preprocessor configuration too complex (UAC3 device
>> must have two configurations for backward compatibility,
>> first is UAC1/2 and second is UAC3), yet also I'm too lazy
>> to do that and verify all possible configurations.
>>
>> For modern ConfigFS interface I'll provide my configuration
>> for testing below; testing was done on a BeagleBone Black
>> board.
>>
>> This patch depends on uac3 header files from include dir
>> which I'll post as part of ALSA host UAC3 patch and will
>> provide the link to it here.
>
> http://www.spinics.net/lists/alsa-devel/msg69071.html

Once that patch hits upstream, then we can queue this for merge window
otherwise we will just have issues and create unbisectable points in the
tree.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH 1/1] usb: gadget: add USB Audio Device Class 3.0 gadget support

2017-11-07 Thread kbuild test robot
Hi Ruslan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on balbi-usb/next]
[also build test WARNING on v4.14-rc8 next-20171107]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Ruslan-Bilovol/usb-gadget-add-USB-Audio-Device-Class-3-0-gadget-support/20171107-175202
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next


coccinelle warnings: (new ones prefixed by >>)

>> drivers/usb/gadget/function/f_uac3.c:766:2-9: alloc with no test, possible 
>> model on line 780

vim +766 drivers/usb/gadget/function/f_uac3.c

   722  
   723  static int f_audio_bind(struct usb_configuration *cfg, struct 
usb_function *fn)
   724  {
   725  struct f_uac3 *uac3 = func_to_uac3(fn);
   726  struct g_audio *audio = func_to_g_audio(fn);
   727  struct usb_composite_dev *cdev = cfg->cdev;
   728  struct usb_gadget *gadget = cdev->gadget;
   729  struct device *dev = >dev;
   730  struct f_uac3_opts *uac3_opts;
   731  struct uac3_hc_descriptor_header *cluster_desc;
   732  struct uac3_hc_desc *hc_desc;
   733  struct usb_string *us;
   734  u16 hc_desc_id = 1; /* HC id always starts from 1 */
   735  int ret;
   736  
   737  uac3_opts = container_of(fn->fi, struct f_uac3_opts, func_inst);
   738  
   739  us = usb_gstrings_attach(cdev, fn_strings, 
ARRAY_SIZE(strings_fn));
   740  if (IS_ERR(us))
   741  return PTR_ERR(us);
   742  
   743  iad_desc.iFunction = us[STR_ASSOC].id;
   744  std_ac_if_desc.iInterface = us[STR_IF_CTRL].id;
   745  std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id;
   746  std_as_out_if1_desc.iInterface = us[STR_AS_OUT_ALT1].id;
   747  std_as_in_if0_desc.iInterface = us[STR_AS_IN_ALT0].id;
   748  std_as_in_if1_desc.iInterface = us[STR_AS_IN_ALT1].id;
   749  
   750  INIT_LIST_HEAD(>hc_desc_list);
   751  
   752  /* Initialize the configurable parameters */
   753  cluster_desc = build_cluster_descriptor(uac3_opts, 0); /* 
capture */
   754  if (cluster_desc) {
   755  hc_desc = kzalloc(sizeof *hc_desc, GFP_KERNEL);
   756  hc_desc->hc_header = cluster_desc;
   757  list_add(_desc->list, >hc_desc_list);
   758  cluster_desc->wDescriptorID = cpu_to_le16(hc_desc_id);
   759  usb_out_it_desc.wClusterDescrID = 
cluster_desc->wDescriptorID;
   760  as_out_hdr_desc.wClusterDescrID = 
cluster_desc->wDescriptorID;
   761  hc_desc_id++;
   762  }
   763  
   764  cluster_desc = build_cluster_descriptor(uac3_opts, 1); /* 
playback */
   765  if (cluster_desc) {
 > 766  hc_desc = kzalloc(sizeof *hc_desc, GFP_KERNEL);
   767  hc_desc->hc_header = cluster_desc;
   768  list_add(_desc->list, >hc_desc_list);
   769  cluster_desc->wDescriptorID = cpu_to_le16(hc_desc_id);
   770  io_in_it_desc.wClusterDescrID = 
cluster_desc->wDescriptorID;
   771  as_in_hdr_desc.wClusterDescrID = 
cluster_desc->wDescriptorID;
   772  }
   773  
   774  as_out_hdr_desc.bSubslotSize = uac3_opts->c_ssize;
   775  as_out_hdr_desc.bBitResolution = uac3_opts->c_ssize * 8;
   776  as_in_hdr_desc.bSubslotSize = uac3_opts->p_ssize;
   777  as_in_hdr_desc.bBitResolution = uac3_opts->p_ssize * 8;
   778  
   779  /* alloc and configure Feature Unit descriptors */
 > 780  usb_out_fu_desc = 
 > alloc_fu_desc(num_channels(uac3_opts->c_chmask),
   781  USB_OUT_FU_ID,
   782  USB_OUT_IT_ID);
   783  if (!usb_out_fu_desc) {
   784  dev_err(dev, "%s: can't allocate OUT FU descriptor on 
%s\n",
   785   fn->name, gadget->name);
   786  ret = -ENOMEM;
   787  goto err_free_hc_desc;
   788  }
   789  
   790  usb_in_fu_desc = 
alloc_fu_desc(num_channels(uac3_opts->p_chmask),
   791  USB_IN_FU_ID,
   792  IO_IN_IT_ID);
   793  if (!usb_in_fu_desc) {
   794  dev_err(dev, "%s: can't allocate IN FU descriptor on 
%s\n",
   795   fn->name, gadget->name);
   796  ret = -ENOMEM;
   797  goto err_free_out_fu_desc;
   798  }
   799  
   800  /* update AC desc size with allocated FUs */
   801  ac

Re: [PATCH 1/1] usb: gadget: add USB Audio Device Class 3.0 gadget support

2017-11-07 Thread kbuild test robot
Hi Ruslan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.14-rc8 next-20171107]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Ruslan-Bilovol/usb-gadget-add-USB-Audio-Device-Class-3-0-gadget-support/20171107-175202
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: i386-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

>> drivers/usb/gadget/function/f_uac3.c:10:32: fatal error: 
>> linux/usb/audio-v3.h: No such file or directory
#include 
   ^
   compilation terminated.

vim +10 drivers/usb/gadget/function/f_uac3.c

  > 10  #include 
11  #include 
12  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH 0/1] USB Audio Device Class 3.0 Gadget support

2017-11-06 Thread Ruslan Bilovol
On Tue, Nov 7, 2017 at 3:52 AM, Ruslan Bilovol  wrote:
> Hi,
>
> This patch adds USB Audio Device Class 3.0 [1] function
> support to gadget subsystem.
> I didn't add UAC3 support to legacy gadget as it will
> make preprocessor configuration too complex (UAC3 device
> must have two configurations for backward compatibility,
> first is UAC1/2 and second is UAC3), yet also I'm too lazy
> to do that and verify all possible configurations.
>
> For modern ConfigFS interface I'll provide my configuration
> for testing below; testing was done on a BeagleBone Black
> board.
>
> This patch depends on uac3 header files from include dir
> which I'll post as part of ALSA host UAC3 patch and will
> provide the link to it here.

http://www.spinics.net/lists/alsa-devel/msg69071.html

Thanks,
Ruslan
--
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


[PATCH 0/1] USB Audio Device Class 3.0 Gadget support

2017-11-06 Thread Ruslan Bilovol
Hi,

This patch adds USB Audio Device Class 3.0 [1] function
support to gadget subsystem.
I didn't add UAC3 support to legacy gadget as it will
make preprocessor configuration too complex (UAC3 device
must have two configurations for backward compatibility,
first is UAC1/2 and second is UAC3), yet also I'm too lazy
to do that and verify all possible configurations.

For modern ConfigFS interface I'll provide my configuration
for testing below; testing was done on a BeagleBone Black
board.

This patch depends on uac3 header files from include dir
which I'll post as part of ALSA host UAC3 patch and will
provide the link to it here.

uac_3

mkdir cfg
mount none cfg -t configfs
mkdir cfg/usb_gadget/g1
cd cfg/usb_gadget/g1
mkdir configs/c.1
mkdir functions/uac3.0
mkdir strings/0x409
mkdir configs/c.1/strings/0x409
echo 0x0101 > idProduct
echo 0x1d6b > idVendor
echo my-serial-num > strings/0x409/serialnumber
echo my-manufacturer > strings/0x409/manufacturer
echo "Test gadget" > strings/0x409/product
echo "Conf 1" > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower
ln -s functions/uac3.0 configs/c.1
echo musb-hdrc.0 > UDC

uac_3 + uac2

mkdir cfg
mount none cfg -t configfs
mkdir cfg/usb_gadget/g1
cd cfg/usb_gadget/g1
mkdir configs/c.1
mkdir functions/uac2.0
mkdir strings/0x409
mkdir configs/c.1/strings/0x409
echo "Test gadget" > strings/0x409/product
echo "Conf 1" > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower
ln -s functions/uac2.0 configs/c.1
mkdir configs/c.2
mkdir functions/uac3.0
mkdir strings/0x409
mkdir configs/c.2/strings/0x409
echo "Conf 2" > configs/c.2/strings/0x409/configuration
echo 120 > configs/c.2/MaxPower
ln -s functions/uac3.0 configs/c.2
echo 0x0101 > idProduct
echo 0x1d6b > idVendor
echo my-serial-num > strings/0x409/serialnumber
echo my-manufacturer > strings/0x409/manufacturer
echo musb-hdrc.0 > UDC


[1] http://www.usb.org/developers/docs/devclass_docs/USB_Audio_v3.0.zip

Ruslan Bilovol (1):
  usb: gadget: add USB Audio Device Class 3.0 gadget support

 Documentation/ABI/testing/configfs-usb-gadget-uac3 |   14 +
 Documentation/usb/gadget-testing.txt   |   41 +
 drivers/usb/gadget/Kconfig |   22 +
 drivers/usb/gadget/function/Makefile   |2 +
 drivers/usb/gadget/function/f_uac3.c   | 1497 
 drivers/usb/gadget/function/u_uac3.h   |   38 +
 drivers/usb/gadget/legacy/Kconfig  |3 +-
 7 files changed, 1616 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac3
 create mode 100644 drivers/usb/gadget/function/f_uac3.c
 create mode 100644 drivers/usb/gadget/function/u_uac3.h

-- 
1.9.1

--
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


[PATCH 1/1] usb: gadget: add USB Audio Device Class 3.0 gadget support

2017-11-06 Thread Ruslan Bilovol
Recently released USB Audio Class 3.0 specification
introduces many significant changes comparing to
previous versions, like
 - new Power Domains, support for LPM/L1
 - new Cluster descriptor
 - changed layout of all class-specific descriptors
 - new High Capability descriptors
 - New class-specific String descriptors
 - new and removed units
 - additional sources for interrupts
 - removed Type II Audio Data Formats
 - ... and many other things (check spec)

It also provides backward compatibility through
multiple configurations, as well as requires
mandatory support for BADD (Basic Audio Device
Definition) on each ADC3.0 compliant device

This patch adds UAC3 gadget support basing on UAC3
specification, implementing Generic I/O Profile
(BAOF + BAIF) from BADD document.

There are still few areas for future improvements
because not all functionality is completely
implemented, for example volume, mute and
power management handling has dummy implementation
in some places

Signed-off-by: Ruslan Bilovol <ruslan.bilo...@gmail.com>
---
 Documentation/ABI/testing/configfs-usb-gadget-uac3 |   14 +
 Documentation/usb/gadget-testing.txt   |   41 +
 drivers/usb/gadget/Kconfig |   22 +
 drivers/usb/gadget/function/Makefile   |2 +
 drivers/usb/gadget/function/f_uac3.c   | 1497 
 drivers/usb/gadget/function/u_uac3.h   |   38 +
 drivers/usb/gadget/legacy/Kconfig  |3 +-
 7 files changed, 1616 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac3
 create mode 100644 drivers/usb/gadget/function/f_uac3.c
 create mode 100644 drivers/usb/gadget/function/u_uac3.h

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uac3 
b/Documentation/ABI/testing/configfs-usb-gadget-uac3
new file mode 100644
index 000..54bb00e
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-uac3
@@ -0,0 +1,14 @@
+What:  /config/usb-gadget/gadget/functions/uac3.name
+Date:  Nov 2017
+KernelVersion: 4.16
+Description:
+   The attributes:
+
+   c_chmask - capture channel mask
+   c_srate - capture sampling rate
+   c_ssize - capture sample size (bytes)
+   p_chmask - playback channel mask
+   p_srate - playback sampling rate
+   p_ssize - playback sample size (bytes)
+   req_number - the number of pre-allocated request
+   for both capture and playback
diff --git a/Documentation/usb/gadget-testing.txt 
b/Documentation/usb/gadget-testing.txt
index fbc397d..36d5e2b 100644
--- a/Documentation/usb/gadget-testing.txt
+++ b/Documentation/usb/gadget-testing.txt
@@ -21,6 +21,7 @@ provided by gadgets.
 18. UVC function
 19. PRINTER function
 20. UAC1 function (new API)
+21. UAC3 function
 
 
 1. ACM function
@@ -817,3 +818,43 @@ e.g.:
 
 $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
 aplay -D default:CARD=OdroidU3
+
+21. UAC3 function
+=
+
+The function is provided by usb_f_uac3.ko module.
+
+Function-specific configfs interface
+
+
+The function name to use when creating the function directory is "uac3".
+The uac3 function provides these attributes in its function directory:
+
+   c_chmask - capture channel mask
+   c_srate - capture sampling rate
+   c_ssize - capture sample size (bytes)
+   p_chmask - playback channel mask
+   p_srate - playback sampling rate
+   p_ssize - playback sample size (bytes)
+   req_number - the number of pre-allocated request for both capture
+and playback
+
+The attributes have sane default values.
+
+Testing the UAC3 function
+-
+
+device: run the gadget
+host: aplay -l # should list our USB Audio Gadget
+
+This function does not require real hardware support, it just
+sends a stream of audio data to/from the host. In order to
+actually hear something at the device side, a command similar
+to this must be used at the device side:
+
+$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
+
+e.g.:
+
+$ arecord -f dat -t wav -D hw:CARD=UAC3Gadget,DEV=0 | \
+aplay -D default:CARD=OdroidU3
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 31cce78..d53ae7d 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -200,6 +200,9 @@ config USB_F_UAC1_LEGACY
 config USB_F_UAC2
tristate
 
+config USB_F_UAC3
+   tristate
+
 config USB_F_UVC
tristate
 
@@ -418,6 +421,25 @@ config USB_CONFIGFS_F_UAC2
  received from the USB Host and choose to provide whatever it
  wants as audio data to the USB Host.
 
+config USB_CONFIGFS_F_UAC3
+   bool "Audio Class 3.0"
+   depends on USB_CONFIGFS
+   depends on SND
+   select USB_LIBCOMPOSITE
+   select SND_PCM
+   select USB_U_A

[PATCHv2 0/3] USB Audio Gadget: Support multiple sampling rates

2017-06-30 Thread Julian Scheel
Sending v2 of this patch series, including fixes for build regressions
introduced with the original series. I missed the usage of f_uac* in the
legacy modules and did not test that. Fixed now, see patches changelog for
details.

This patch series adds support for exposing multiple supported sampling rates
from UAC1 and UAC2 USB gadgets to the connected host. It is currently limited
to up to ten discrete sampling frequencies. The USB specification does not
actually limit this, but to avoid complex list handling I am using a static
array for now.
As the configfs bindings for f_uac1 and f_uac2 have been identical already, I
decided to move the shared code for this out of the functions first. This
avoids code duplication and simplifies the addition of the list parsing for
sampling rates.
The host can configure active sampling rate and the function adapts it's
internal active rate automatically. On playback/capture start the rate is
checked, so that the user recognizes rate mismatches. Furthermore the active
rate is exposed as an amixer control with change notifications, so that
users can check current rate upfront and get notified about updates.

Julian Scheel (3):
  usb: gadget: f_uac1: Fix endpoint reading
  usb: gadget: f_uac*: Reduce code duplication
  usb: gadget: f_uac*: Support multiple sampling rates

 Documentation/ABI/testing/configfs-usb-gadget-uac1 |   4 +-
 Documentation/usb/gadget-testing.txt   |   8 +-
 drivers/usb/gadget/function/f_uac1.c   | 258 +-
 drivers/usb/gadget/function/f_uac2.c   | 297 ++---
 drivers/usb/gadget/function/u_audio.c  | 118 +++-
 drivers/usb/gadget/function/u_audio.h  |   9 +-
 drivers/usb/gadget/function/u_uac.h| 180 +
 drivers/usb/gadget/function/u_uac1.h   |  41 ---
 drivers/usb/gadget/function/u_uac2.h   |  44 ---
 drivers/usb/gadget/legacy/audio.c  |  91 ++-
 10 files changed, 608 insertions(+), 442 deletions(-)
 create mode 100644 drivers/usb/gadget/function/u_uac.h
 delete mode 100644 drivers/usb/gadget/function/u_uac1.h
 delete mode 100644 drivers/usb/gadget/function/u_uac2.h

-- 
2.13.2

--
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


[PATCH 0/3] USB Audio Gadget: Support multiple sampling rates

2017-06-26 Thread Julian Scheel
This patch series adds support for exposing multiple supported sampling rates
from UAC1 and UAC2 USB gadgets to the connected host. It is currently limited
to up to ten discrete sampling frequencies. The USB specification does not
actually limit this, but to avoid complex list handling I am using a static
array for now.
As the configfs bindings for f_uac1 and f_uac2 have been identical already, I
decided to move the shared code for this out of the functions first. This
avoids code duplication and simplifies the addition of the list parsing for
sampling rates.
The host can configure active sampling rate and the function adapts it's
internal active rate automatically. On playback/capture start the rate is
checked, so that the user recognizes rate mismatches. Furthermore the active
rate is exposed as an amixer control with change notifications, so that
users can check current rate upfront and get notified about updates.

Julian Scheel (3):
  usb: gadget: f_uac1: Fix endpoint reading
  usb: gadget: f_uac*: Reduce code duplication
  usb: gadget: f_uac*: Support multiple sampling rates

 Documentation/ABI/testing/configfs-usb-gadget-uac1 |   4 +-
 Documentation/usb/gadget-testing.txt   |   8 +-
 drivers/usb/gadget/function/f_uac1.c   | 258 +-
 drivers/usb/gadget/function/f_uac2.c   | 297 ++---
 drivers/usb/gadget/function/u_audio.c  | 116 +++-
 drivers/usb/gadget/function/u_audio.h  |   9 +-
 drivers/usb/gadget/function/u_uac.h| 178 
 drivers/usb/gadget/function/u_uac1.h   |  41 ---
 drivers/usb/gadget/function/u_uac2.h   |  44 ---
 9 files changed, 582 insertions(+), 373 deletions(-)
 create mode 100644 drivers/usb/gadget/function/u_uac.h
 delete mode 100644 drivers/usb/gadget/function/u_uac1.h
 delete mode 100644 drivers/usb/gadget/function/u_uac2.h

-- 
2.13.1

--
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 v19 2/4] usb: gadget: Support for the usb charger framework

2017-02-20 Thread Baolin Wang
On 20 February 2017 at 18:08, kbuild test robot  wrote:
> Hi Baolin,
>
> [auto build test ERROR on v4.9-rc8]
> [cannot apply to balbi-usb/next usb/usb-testing battery/master next-20170220]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
>
> url:
> https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051
> config: i386-randconfig-x015-201708 (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=i386
>
> All errors (new ones prefixed by >>):
>
>In file included from drivers/usb/gadget/udc/core.c:28:0:
>include/linux/usb/charger.h: In function 'usb_charger_get_state':
>>> include/linux/usb/charger.h:151:9: error: 'USB_CHARGER_REMOVE' undeclared 
>>> (first use in this function)
>  return USB_CHARGER_REMOVE;

Ah, missed fixing the state name without enable USB charger. Will fix
in next version.

> ^~
>include/linux/usb/charger.h:151:9: note: each undeclared identifier is 
> reported only once for each function it appears in
>
> vim +/USB_CHARGER_REMOVE +151 include/linux/usb/charger.h
>
> 28929615 Baolin Wang 2017-02-20  145return UNKNOWN_TYPE;
> 28929615 Baolin Wang 2017-02-20  146  }
> 28929615 Baolin Wang 2017-02-20  147
> 28929615 Baolin Wang 2017-02-20  148  static inline enum usb_charger_state
> 28929615 Baolin Wang 2017-02-20  149  usb_charger_get_state(struct 
> usb_charger *uchger)
> 28929615 Baolin Wang 2017-02-20  150  {
> 28929615 Baolin Wang 2017-02-20 @151return USB_CHARGER_REMOVE;
> 28929615 Baolin Wang 2017-02-20  152  }
> 28929615 Baolin Wang 2017-02-20  153
> 28929615 Baolin Wang 2017-02-20  154  static inline int 
> usb_charger_detect_type(struct usb_charger *uchger)
>
> :: The code at line 151 was first introduced by commit
> :: 289296154f05985dedc08273f04d5b738450b3c7 usb: gadget: Introduce the 
> usb charger framework
>
> :: TO: Baolin Wang 
> :: CC: 0day robot 
>
> ---
> 0-DAY kernel test infrastructureOpen Source Technology Center
> https://lists.01.org/pipermail/kbuild-all   Intel Corporation



-- 
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 v19 2/4] usb: gadget: Support for the usb charger framework

2017-02-20 Thread kbuild test robot
Hi Baolin,

[auto build test ERROR on v4.9-rc8]
[cannot apply to balbi-usb/next usb/usb-testing battery/master next-20170220]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051
config: i386-randconfig-x015-201708 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

   In file included from drivers/usb/gadget/udc/core.c:28:0:
   include/linux/usb/charger.h: In function 'usb_charger_get_state':
>> include/linux/usb/charger.h:151:9: error: 'USB_CHARGER_REMOVE' undeclared 
>> (first use in this function)
 return USB_CHARGER_REMOVE;
^~
   include/linux/usb/charger.h:151:9: note: each undeclared identifier is 
reported only once for each function it appears in

vim +/USB_CHARGER_REMOVE +151 include/linux/usb/charger.h

28929615 Baolin Wang 2017-02-20  145return UNKNOWN_TYPE;
28929615 Baolin Wang 2017-02-20  146  }
28929615 Baolin Wang 2017-02-20  147  
28929615 Baolin Wang 2017-02-20  148  static inline enum usb_charger_state
28929615 Baolin Wang 2017-02-20  149  usb_charger_get_state(struct usb_charger 
*uchger)
28929615 Baolin Wang 2017-02-20  150  {
28929615 Baolin Wang 2017-02-20 @151return USB_CHARGER_REMOVE;
28929615 Baolin Wang 2017-02-20  152  }
28929615 Baolin Wang 2017-02-20  153  
28929615 Baolin Wang 2017-02-20  154  static inline int 
usb_charger_detect_type(struct usb_charger *uchger)

:: The code at line 151 was first introduced by commit
:: 289296154f05985dedc08273f04d5b738450b3c7 usb: gadget: Introduce the usb 
charger framework

:: TO: Baolin Wang 
:: CC: 0day robot 

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH v19 2/4] usb: gadget: Support for the usb charger framework

2017-02-20 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/core.c |   19 ++-
 include/linux/usb/gadget.h|3 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 9483489..90df022 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -576,12 +577,17 @@ int usb_gadget_vbus_connect(struct usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
int ret = 0;
 
+   usb_charger_set_cur_limit_by_gadget(gadget, mA);
+
if (!gadget->ops->vbus_draw) {
ret = -EOPNOTSUPP;
goto out;
@@ -963,6 +969,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -1132,6 +1141,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -1143,7 +1156,7 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret != -EPROBE_DEFER)
list_del(>pending);
if (ret)
-   goto err5;
+   goto err6;
break;
}
}
@@ -1152,6 +1165,9 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err6:
+   usb_charger_exit(gadget);
+
 err5:
device_del(>dev);
 
@@ -1263,6 +1279,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index e4516e9..b4d7be2 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define UDC_TRACE_STR_MAX  512
 
@@ -328,6 +329,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @charger: Negotiate the power with the usb charger.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -387,6 +389,7 @@ struct usb_gadget {
unsignedin_epnum;
unsignedmA;
struct usb_otg_caps *otg_caps;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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


[PATCH v18 2/4] usb: gadget: Support for the usb charger framework

2016-10-18 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/core.c |   19 ++-
 include/linux/usb/gadget.h|3 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 9483489..90df022 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -576,12 +577,17 @@ EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect);
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
int ret = 0;
 
+   usb_charger_set_cur_limit_by_gadget(gadget, mA);
+
if (!gadget->ops->vbus_draw) {
ret = -EOPNOTSUPP;
goto out;
@@ -963,6 +969,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -1132,6 +1141,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -1143,7 +1156,7 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret != -EPROBE_DEFER)
list_del(>pending);
if (ret)
-   goto err5;
+   goto err6;
break;
}
}
@@ -1152,6 +1165,9 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err6:
+   usb_charger_exit(gadget);
+
 err5:
device_del(>dev);
 
@@ -1263,6 +1279,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 8e81f9e..82a0d63 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define UDC_TRACE_STR_MAX  512
 
@@ -328,6 +329,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @charger: Negotiate the power with the usb charger.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -387,6 +389,7 @@ struct usb_gadget {
unsignedin_epnum;
unsignedmA;
struct usb_otg_caps *otg_caps;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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


[PATCH v17 2/4] usb: gadget: Support for the usb charger framework

2016-10-10 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/core.c |   19 ++-
 include/linux/usb/gadget.h|3 +++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 9483489..90df022 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -576,12 +577,17 @@ EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect);
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
int ret = 0;
 
+   usb_charger_set_cur_limit_by_gadget(gadget, mA);
+
if (!gadget->ops->vbus_draw) {
ret = -EOPNOTSUPP;
goto out;
@@ -963,6 +969,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -1132,6 +1141,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -1143,7 +1156,7 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret != -EPROBE_DEFER)
list_del(>pending);
if (ret)
-   goto err5;
+   goto err6;
break;
}
}
@@ -1152,6 +1165,9 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err6:
+   usb_charger_exit(gadget);
+
 err5:
device_del(>dev);
 
@@ -1263,6 +1279,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 8e81f9e..82a0d63 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define UDC_TRACE_STR_MAX  512
 
@@ -328,6 +329,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @charger: Negotiate the power with the usb charger.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -387,6 +389,7 @@ struct usb_gadget {
unsignedin_epnum;
unsignedmA;
struct usb_otg_caps *otg_caps;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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


[PATCH v16 2/4] usb: gadget: Support for the usb charger framework

2016-08-01 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/core.c |   17 +
 include/linux/usb/gadget.h|3 +++
 2 files changed, 20 insertions(+)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index ff8685e..bdf1874 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -578,12 +579,17 @@ EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect);
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
int ret = 0;
 
+   usb_charger_set_cur_limit_by_gadget(gadget, mA);
+
if (!gadget->ops->vbus_draw) {
ret = -EOPNOTSUPP;
goto out;
@@ -965,6 +971,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -1134,6 +1143,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -1154,6 +1167,9 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
+
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -1262,6 +1278,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 612dbdf..c864b51 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define UDC_TRACE_STR_MAX  512
 
@@ -328,6 +329,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @charger: Negotiate the power with the usb charger.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -385,6 +387,7 @@ struct usb_gadget {
unsignedin_epnum;
unsignedmA;
struct usb_otg_caps *otg_caps;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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


[PATCH v15 2/4] usb: gadget: Support for the usb charger framework

2016-07-01 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/core.c |   17 +
 include/linux/usb/gadget.h|3 +++
 2 files changed, 20 insertions(+)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index ff8685e..bdf1874 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -578,12 +579,17 @@ EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect);
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
int ret = 0;
 
+   usb_charger_set_cur_limit_by_gadget(gadget, mA);
+
if (!gadget->ops->vbus_draw) {
ret = -EOPNOTSUPP;
goto out;
@@ -965,6 +971,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -1134,6 +1143,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -1154,6 +1167,9 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
+
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -1262,6 +1278,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 612dbdf..c864b51 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define UDC_TRACE_STR_MAX  512
 
@@ -328,6 +329,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @charger: Negotiate the power with the usb charger.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -385,6 +387,7 @@ struct usb_gadget {
unsignedin_epnum;
unsignedmA;
struct usb_otg_caps *otg_caps;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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


[PATCH v14 2/4] usb: gadget: Support for the usb charger framework

2016-06-29 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/core.c |   17 +
 include/linux/usb/gadget.h|3 +++
 2 files changed, 20 insertions(+)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index ff8685e..bdf1874 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -578,12 +579,17 @@ EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect);
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
int ret = 0;
 
+   usb_charger_set_cur_limit_by_gadget(gadget, mA);
+
if (!gadget->ops->vbus_draw) {
ret = -EOPNOTSUPP;
goto out;
@@ -965,6 +971,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -1134,6 +1143,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -1154,6 +1167,9 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
+
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -1262,6 +1278,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 612dbdf..c864b51 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define UDC_TRACE_STR_MAX  512
 
@@ -328,6 +329,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @charger: Negotiate the power with the usb charger.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -385,6 +387,7 @@ struct usb_gadget {
unsignedin_epnum;
unsignedmA;
struct usb_otg_caps *otg_caps;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> For supporting the usb charger, it adds the usb_charger_init() and
> usb_charger_exit() functions for usb charger initialization and exit.
>
> It will report to the usb charger when the gadget state is changed,
> then the usb charger can do the power things.
>
> Signed-off-by: Baolin Wang 
> Reviewed-by: Li Jun 
> Tested-by: Li Jun 

 Before anything, I must say that I really liked this patch. It's
 minimaly invasive to udc core and does all the necessary changes. If it
 wasn't for the extra charger class, this would've been perfect.

 Can't you just tie a charger to a UDC and avoid the charger class
 completely?

>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, 
> unsigned mA)
>  {
> + if (gadget->charger)

 I guess you could do this check inside
 usb_gadget_set_cur_limit_by_type() itself.
>>>
>>> We will access the 'gadget->charger->type' member when issuing
>>> usb_gadget_set_cur_limit_by_type(), so I think I should leave the
>>> check here in next new version.
>>
>> Here's what I mean:
>>
>> int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
>> {
>> struct usb_charger *charger;
>> enum usb_charger_type type;
>>
>> if (!gadget->charger)
>> return 0;
>>
>> charger = gadget->charger;
>> type = charger->type;
>>
>> return __usb_charger_set_cur_limit(charger, type, mA);
>> }
>
> But that means we need to export  both 'usb_charger_set_cur_limit()'
> function and '__usb_charger_set_cur_limit()' function in charger.c
> file. Cause some user may want to set the current limitation by one
> charger type parameter (may be not from charger->type), like by
> issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do
> you think about this situation? Thanks.

 if we have that requirement, that's totally fine. Just rename
 __usb_charger_set_cur_limit() back to
 _usb_charger_set_cur_limit_by_type() and expose both. But
 set_cur_limit_by_type can assume its arguments are valid at all times.
>>>
>>> Make sense. I'll fix this issue in v14 version. Thanks.
>>
>> there's one thing bothering me though:
>>
>> gadget->charger is supposed to be "current detected charger" right? If
>> we have a single port tied to a single charger, in which case would we
>> *ever* need to change current limit of any charger type other than
>> "current charger" ?
>
> What I mean is user can set the current limit by charger type as what
> they want at initial stage. As we know the default current of SDP (not
> super speed) is 500 mA, but user can set the current limit of SDP as
> 450 mA if there are some special on their own platform by issuing
> '__usb_charger_set_cur_limit(charger, SDP_TYPE, 450)'.

Oh I see. Odd, but okay

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Baolin Wang
Hi Felipe,

On 29 June 2016 at 20:06, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
 For supporting the usb charger, it adds the usb_charger_init() and
 usb_charger_exit() functions for usb charger initialization and exit.

 It will report to the usb charger when the gadget state is changed,
 then the usb charger can do the power things.

 Signed-off-by: Baolin Wang 
 Reviewed-by: Li Jun 
 Tested-by: Li Jun 
>>>
>>> Before anything, I must say that I really liked this patch. It's
>>> minimaly invasive to udc core and does all the necessary changes. If it
>>> wasn't for the extra charger class, this would've been perfect.
>>>
>>> Can't you just tie a charger to a UDC and avoid the charger class
>>> completely?
>>>
  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, 
 unsigned mA)
  {
 + if (gadget->charger)
>>>
>>> I guess you could do this check inside
>>> usb_gadget_set_cur_limit_by_type() itself.
>>
>> We will access the 'gadget->charger->type' member when issuing
>> usb_gadget_set_cur_limit_by_type(), so I think I should leave the
>> check here in next new version.
>
> Here's what I mean:
>
> int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
> {
> struct usb_charger *charger;
> enum usb_charger_type type;
>
> if (!gadget->charger)
> return 0;
>
> charger = gadget->charger;
> type = charger->type;
>
> return __usb_charger_set_cur_limit(charger, type, mA);
> }

 But that means we need to export  both 'usb_charger_set_cur_limit()'
 function and '__usb_charger_set_cur_limit()' function in charger.c
 file. Cause some user may want to set the current limitation by one
 charger type parameter (may be not from charger->type), like by
 issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do
 you think about this situation? Thanks.
>>>
>>> if we have that requirement, that's totally fine. Just rename
>>> __usb_charger_set_cur_limit() back to
>>> _usb_charger_set_cur_limit_by_type() and expose both. But
>>> set_cur_limit_by_type can assume its arguments are valid at all times.
>>
>> Make sense. I'll fix this issue in v14 version. Thanks.
>
> there's one thing bothering me though:
>
> gadget->charger is supposed to be "current detected charger" right? If
> we have a single port tied to a single charger, in which case would we
> *ever* need to change current limit of any charger type other than
> "current charger" ?

What I mean is user can set the current limit by charger type as what
they want at initial stage. As we know the default current of SDP (not
super speed) is 500 mA, but user can set the current limit of SDP as
450 mA if there are some special on their own platform by issuing
'__usb_charger_set_cur_limit(charger, SDP_TYPE, 450)'.

>
> IOW, why do we need _set_cur_limit_by_type() exported at all?
>
> --
> balbi



-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
>>> For supporting the usb charger, it adds the usb_charger_init() and
>>> usb_charger_exit() functions for usb charger initialization and exit.
>>>
>>> It will report to the usb charger when the gadget state is changed,
>>> then the usb charger can do the power things.
>>>
>>> Signed-off-by: Baolin Wang 
>>> Reviewed-by: Li Jun 
>>> Tested-by: Li Jun 
>>
>> Before anything, I must say that I really liked this patch. It's
>> minimaly invasive to udc core and does all the necessary changes. If it
>> wasn't for the extra charger class, this would've been perfect.
>>
>> Can't you just tie a charger to a UDC and avoid the charger class
>> completely?
>>
>>>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, 
>>> unsigned mA)
>>>  {
>>> + if (gadget->charger)
>>
>> I guess you could do this check inside
>> usb_gadget_set_cur_limit_by_type() itself.
>
> We will access the 'gadget->charger->type' member when issuing
> usb_gadget_set_cur_limit_by_type(), so I think I should leave the
> check here in next new version.

 Here's what I mean:

 int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
 {
 struct usb_charger *charger;
 enum usb_charger_type type;

 if (!gadget->charger)
 return 0;

 charger = gadget->charger;
 type = charger->type;

 return __usb_charger_set_cur_limit(charger, type, mA);
 }
>>>
>>> But that means we need to export  both 'usb_charger_set_cur_limit()'
>>> function and '__usb_charger_set_cur_limit()' function in charger.c
>>> file. Cause some user may want to set the current limitation by one
>>> charger type parameter (may be not from charger->type), like by
>>> issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do
>>> you think about this situation? Thanks.
>>
>> if we have that requirement, that's totally fine. Just rename
>> __usb_charger_set_cur_limit() back to
>> _usb_charger_set_cur_limit_by_type() and expose both. But
>> set_cur_limit_by_type can assume its arguments are valid at all times.
>
> Make sense. I'll fix this issue in v14 version. Thanks.

there's one thing bothering me though:

gadget->charger is supposed to be "current detected charger" right? If
we have a single port tied to a single charger, in which case would we
*ever* need to change current limit of any charger type other than
"current charger" ?

IOW, why do we need _set_cur_limit_by_type() exported at all?

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Baolin Wang
On 29 June 2016 at 16:34, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>> For supporting the usb charger, it adds the usb_charger_init() and
>> usb_charger_exit() functions for usb charger initialization and exit.
>>
>> It will report to the usb charger when the gadget state is changed,
>> then the usb charger can do the power things.
>>
>> Signed-off-by: Baolin Wang 
>> Reviewed-by: Li Jun 
>> Tested-by: Li Jun 
>
> Before anything, I must say that I really liked this patch. It's
> minimaly invasive to udc core and does all the necessary changes. If it
> wasn't for the extra charger class, this would've been perfect.
>
> Can't you just tie a charger to a UDC and avoid the charger class
> completely?
>
>>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, 
>> unsigned mA)
>>  {
>> + if (gadget->charger)
>
> I guess you could do this check inside
> usb_gadget_set_cur_limit_by_type() itself.

 We will access the 'gadget->charger->type' member when issuing
 usb_gadget_set_cur_limit_by_type(), so I think I should leave the
 check here in next new version.
>>>
>>> Here's what I mean:
>>>
>>> int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
>>> {
>>> struct usb_charger *charger;
>>> enum usb_charger_type type;
>>>
>>> if (!gadget->charger)
>>> return 0;
>>>
>>> charger = gadget->charger;
>>> type = charger->type;
>>>
>>> return __usb_charger_set_cur_limit(charger, type, mA);
>>> }
>>
>> But that means we need to export  both 'usb_charger_set_cur_limit()'
>> function and '__usb_charger_set_cur_limit()' function in charger.c
>> file. Cause some user may want to set the current limitation by one
>> charger type parameter (may be not from charger->type), like by
>> issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do
>> you think about this situation? Thanks.
>
> if we have that requirement, that's totally fine. Just rename
> __usb_charger_set_cur_limit() back to
> _usb_charger_set_cur_limit_by_type() and expose both. But
> set_cur_limit_by_type can assume its arguments are valid at all times.

Make sense. I'll fix this issue in v14 version. Thanks.

-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> For supporting the usb charger, it adds the usb_charger_init() and
> usb_charger_exit() functions for usb charger initialization and exit.
>
> It will report to the usb charger when the gadget state is changed,
> then the usb charger can do the power things.
>
> Signed-off-by: Baolin Wang 
> Reviewed-by: Li Jun 
> Tested-by: Li Jun 

 Before anything, I must say that I really liked this patch. It's
 minimaly invasive to udc core and does all the necessary changes. If it
 wasn't for the extra charger class, this would've been perfect.

 Can't you just tie a charger to a UDC and avoid the charger class
 completely?

>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, 
> unsigned mA)
>  {
> + if (gadget->charger)

 I guess you could do this check inside
 usb_gadget_set_cur_limit_by_type() itself.
>>>
>>> We will access the 'gadget->charger->type' member when issuing
>>> usb_gadget_set_cur_limit_by_type(), so I think I should leave the
>>> check here in next new version.
>>
>> Here's what I mean:
>>
>> int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
>> {
>> struct usb_charger *charger;
>> enum usb_charger_type type;
>>
>> if (!gadget->charger)
>> return 0;
>>
>> charger = gadget->charger;
>> type = charger->type;
>>
>> return __usb_charger_set_cur_limit(charger, type, mA);
>> }
>
> But that means we need to export  both 'usb_charger_set_cur_limit()'
> function and '__usb_charger_set_cur_limit()' function in charger.c
> file. Cause some user may want to set the current limitation by one
> charger type parameter (may be not from charger->type), like by
> issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do
> you think about this situation? Thanks.

if we have that requirement, that's totally fine. Just rename
__usb_charger_set_cur_limit() back to
_usb_charger_set_cur_limit_by_type() and expose both. But
set_cur_limit_by_type can assume its arguments are valid at all times.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Baolin Wang
Hi Felipe,

On 29 June 2016 at 16:20, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>>> Baolin Wang  writes:
 For supporting the usb charger, it adds the usb_charger_init() and
 usb_charger_exit() functions for usb charger initialization and exit.

 It will report to the usb charger when the gadget state is changed,
 then the usb charger can do the power things.

 Signed-off-by: Baolin Wang 
 Reviewed-by: Li Jun 
 Tested-by: Li Jun 
>>>
>>> Before anything, I must say that I really liked this patch. It's
>>> minimaly invasive to udc core and does all the necessary changes. If it
>>> wasn't for the extra charger class, this would've been perfect.
>>>
>>> Can't you just tie a charger to a UDC and avoid the charger class
>>> completely?
>>>
  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, 
 unsigned mA)
  {
 + if (gadget->charger)
>>>
>>> I guess you could do this check inside
>>> usb_gadget_set_cur_limit_by_type() itself.
>>
>> We will access the 'gadget->charger->type' member when issuing
>> usb_gadget_set_cur_limit_by_type(), so I think I should leave the
>> check here in next new version.
>
> Here's what I mean:
>
> int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
> {
> struct usb_charger *charger;
> enum usb_charger_type type;
>
> if (!gadget->charger)
> return 0;
>
> charger = gadget->charger;
> type = charger->type;
>
> return __usb_charger_set_cur_limit(charger, type, mA);
> }

But that means we need to export  both 'usb_charger_set_cur_limit()'
function and '__usb_charger_set_cur_limit()' function in charger.c
file. Cause some user may want to set the current limitation by one
charger type parameter (may be not from charger->type), like by
issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do
you think about this situation? Thanks.

>
> static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
> {
> usb_charger_set_cur_limit(gadget,  mA);
>
> if (!gadget->ops->vbus_draw)
> return -EOPNOTSUPP;
> return gadget->ops->vbus_draw(gadget, mA);
> }
>
> --
> balbi



-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-29 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
>> Baolin Wang  writes:
>>> For supporting the usb charger, it adds the usb_charger_init() and
>>> usb_charger_exit() functions for usb charger initialization and exit.
>>>
>>> It will report to the usb charger when the gadget state is changed,
>>> then the usb charger can do the power things.
>>>
>>> Signed-off-by: Baolin Wang 
>>> Reviewed-by: Li Jun 
>>> Tested-by: Li Jun 
>>
>> Before anything, I must say that I really liked this patch. It's
>> minimaly invasive to udc core and does all the necessary changes. If it
>> wasn't for the extra charger class, this would've been perfect.
>>
>> Can't you just tie a charger to a UDC and avoid the charger class
>> completely?
>>
>>>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned 
>>> mA)
>>>  {
>>> + if (gadget->charger)
>>
>> I guess you could do this check inside
>> usb_gadget_set_cur_limit_by_type() itself.
>
> We will access the 'gadget->charger->type' member when issuing
> usb_gadget_set_cur_limit_by_type(), so I think I should leave the
> check here in next new version.

Here's what I mean:

int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
{
struct usb_charger *charger;
enum usb_charger_type type;

if (!gadget->charger)
return 0;

charger = gadget->charger;
type = charger->type;

return __usb_charger_set_cur_limit(charger, type, mA);
}

static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
{
usb_charger_set_cur_limit(gadget,  mA);

if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
}

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v13 2/4] usb: gadget: Support for the usb charger framework

2016-06-23 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 6e8300d..84c098c 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -242,6 +243,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -411,6 +415,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -431,6 +439,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -539,6 +549,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 457651b..40390ec 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -639,6 +640,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -855,10 +858,18 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+ gadget->charger->type,
+ mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-23 Thread Baolin Wang
Hi,

On 21 June 2016 at 18:27, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>> For supporting the usb charger, it adds the usb_charger_init() and
>> usb_charger_exit() functions for usb charger initialization and exit.
>>
>> It will report to the usb charger when the gadget state is changed,
>> then the usb charger can do the power things.
>>
>> Signed-off-by: Baolin Wang 
>> Reviewed-by: Li Jun 
>> Tested-by: Li Jun 
>
> Before anything, I must say that I really liked this patch. It's
> minimaly invasive to udc core and does all the necessary changes. If it
> wasn't for the extra charger class, this would've been perfect.
>
> Can't you just tie a charger to a UDC and avoid the charger class
> completely?
>
>>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned 
>> mA)
>>  {
>> + if (gadget->charger)
>
> I guess you could do this check inside
> usb_gadget_set_cur_limit_by_type() itself.

We will access the 'gadget->charger->type' member when issuing
usb_gadget_set_cur_limit_by_type(), so I think I should leave the
check here in next new version.

-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Baolin Wang
On 21 June 2016 at 20:53, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
> Can't you just tie a charger to a UDC and avoid the charger class
> completely?

 Yeah, I also hope so. But we really want something to manage the
 charger devices, do you have any good suggestion to avoid the 'class'
 but also can manage the charger devices?
>>>
>>> manage in what way? It seems to me that they don't need to be real
>>> devices, just a handle as part of struct usb_gadget, no?
>>
>> Although charger device is not one real hardware device, we also use
>> one 'struct device' to describe it in charger.c file. So we should
>> manage the 'struct device' with one proper way.
>
> that's fine, but why do you think they need a struct device to start with?

 We can get/put usb charger and mange usb charger attributes with the
 device model if we use a struct device.
>>>
>>> We already have that as part of struct usb_udc. Why don't you just
>>> create a subdirectory called charger which will hold all your
>>> charger-related attributes. That directory will only be created if a
>>> valid ->charger pointer exists.
>>
>> That means we can remove all the device and class things in charger.c
>> file, right? OK, I try to do that. Thanks.
>
> right. Keep your charger.c file, because to conditionally compile and
> link that to udc-core.ko, but remove all the class initialization and
> all of that extra code.

Make sense.

-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
>> Can't you just tie a charger to a UDC and avoid the charger class
>> completely?
>
> Yeah, I also hope so. But we really want something to manage the
> charger devices, do you have any good suggestion to avoid the 'class'
> but also can manage the charger devices?

manage in what way? It seems to me that they don't need to be real
devices, just a handle as part of struct usb_gadget, no?

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Felipe Balbi

Hi,

Felipe Balbi  writes:
> Can't you just tie a charger to a UDC and avoid the charger class
> completely?

 Yeah, I also hope so. But we really want something to manage the
 charger devices, do you have any good suggestion to avoid the 'class'
 but also can manage the charger devices?
>>>
>>> manage in what way? It seems to me that they don't need to be real
>>> devices, just a handle as part of struct usb_gadget, no?
>>
>> Although charger device is not one real hardware device, we also use
>> one 'struct device' to describe it in charger.c file. So we should
>> manage the 'struct device' with one proper way.
>
> that's fine, but why do you think they need a struct device to start with?

 We can get/put usb charger and mange usb charger attributes with the
 device model if we use a struct device.
>>>
>>> We already have that as part of struct usb_udc. Why don't you just
>>> create a subdirectory called charger which will hold all your
>>> charger-related attributes. That directory will only be created if a
>>> valid ->charger pointer exists.
>>
>> That means we can remove all the device and class things in charger.c
>> file, right? OK, I try to do that. Thanks.
>
> right. Keep your charger.c file, because to conditionally compile and
  ^
   we want   

> link that to udc-core.ko, but remove all the class initialization and
> all of that extra code.
>
> -- 
> balbi

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
 Can't you just tie a charger to a UDC and avoid the charger class
 completely?
>>>
>>> Yeah, I also hope so. But we really want something to manage the
>>> charger devices, do you have any good suggestion to avoid the 'class'
>>> but also can manage the charger devices?
>>
>> manage in what way? It seems to me that they don't need to be real
>> devices, just a handle as part of struct usb_gadget, no?
>
> Although charger device is not one real hardware device, we also use
> one 'struct device' to describe it in charger.c file. So we should
> manage the 'struct device' with one proper way.

 that's fine, but why do you think they need a struct device to start with?
>>>
>>> We can get/put usb charger and mange usb charger attributes with the
>>> device model if we use a struct device.
>>
>> We already have that as part of struct usb_udc. Why don't you just
>> create a subdirectory called charger which will hold all your
>> charger-related attributes. That directory will only be created if a
>> valid ->charger pointer exists.
>
> That means we can remove all the device and class things in charger.c
> file, right? OK, I try to do that. Thanks.

right. Keep your charger.c file, because to conditionally compile and
link that to udc-core.ko, but remove all the class initialization and
all of that extra code.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Baolin Wang
On 21 June 2016 at 20:36, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>>> Baolin Wang  writes:
> Baolin Wang  writes:
>>> Can't you just tie a charger to a UDC and avoid the charger class
>>> completely?
>>
>> Yeah, I also hope so. But we really want something to manage the
>> charger devices, do you have any good suggestion to avoid the 'class'
>> but also can manage the charger devices?
>
> manage in what way? It seems to me that they don't need to be real
> devices, just a handle as part of struct usb_gadget, no?

 Although charger device is not one real hardware device, we also use
 one 'struct device' to describe it in charger.c file. So we should
 manage the 'struct device' with one proper way.
>>>
>>> that's fine, but why do you think they need a struct device to start with?
>>
>> We can get/put usb charger and mange usb charger attributes with the
>> device model if we use a struct device.
>
> We already have that as part of struct usb_udc. Why don't you just
> create a subdirectory called charger which will hold all your
> charger-related attributes. That directory will only be created if a
> valid ->charger pointer exists.

That means we can remove all the device and class things in charger.c
file, right? OK, I try to do that. Thanks.

>
> USB Charging is always tied to a peripheral side controller, anyway.
>
> --
> balbi



-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
>> Baolin Wang  writes:
 Can't you just tie a charger to a UDC and avoid the charger class
 completely?
>>>
>>> Yeah, I also hope so. But we really want something to manage the
>>> charger devices, do you have any good suggestion to avoid the 'class'
>>> but also can manage the charger devices?
>>
>> manage in what way? It seems to me that they don't need to be real
>> devices, just a handle as part of struct usb_gadget, no?
>
> Although charger device is not one real hardware device, we also use
> one 'struct device' to describe it in charger.c file. So we should
> manage the 'struct device' with one proper way.

that's fine, but why do you think they need a struct device to start with?

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
>> Baolin Wang  writes:
 Baolin Wang  writes:
>> Can't you just tie a charger to a UDC and avoid the charger class
>> completely?
>
> Yeah, I also hope so. But we really want something to manage the
> charger devices, do you have any good suggestion to avoid the 'class'
> but also can manage the charger devices?

 manage in what way? It seems to me that they don't need to be real
 devices, just a handle as part of struct usb_gadget, no?
>>>
>>> Although charger device is not one real hardware device, we also use
>>> one 'struct device' to describe it in charger.c file. So we should
>>> manage the 'struct device' with one proper way.
>>
>> that's fine, but why do you think they need a struct device to start with?
>
> We can get/put usb charger and mange usb charger attributes with the
> device model if we use a struct device.

We already have that as part of struct usb_udc. Why don't you just
create a subdirectory called charger which will hold all your
charger-related attributes. That directory will only be created if a
valid ->charger pointer exists.

USB Charging is always tied to a peripheral side controller, anyway.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Baolin Wang
On 21 June 2016 at 20:27, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>>> Baolin Wang  writes:
> Can't you just tie a charger to a UDC and avoid the charger class
> completely?

 Yeah, I also hope so. But we really want something to manage the
 charger devices, do you have any good suggestion to avoid the 'class'
 but also can manage the charger devices?
>>>
>>> manage in what way? It seems to me that they don't need to be real
>>> devices, just a handle as part of struct usb_gadget, no?
>>
>> Although charger device is not one real hardware device, we also use
>> one 'struct device' to describe it in charger.c file. So we should
>> manage the 'struct device' with one proper way.
>
> that's fine, but why do you think they need a struct device to start with?

We can get/put usb charger and mange usb charger attributes with the
device model if we use a struct device.

-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Baolin Wang
On 21 June 2016 at 19:49, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>>> Can't you just tie a charger to a UDC and avoid the charger class
>>> completely?
>>
>> Yeah, I also hope so. But we really want something to manage the
>> charger devices, do you have any good suggestion to avoid the 'class'
>> but also can manage the charger devices?
>
> manage in what way? It seems to me that they don't need to be real
> devices, just a handle as part of struct usb_gadget, no?

Although charger device is not one real hardware device, we also use
one 'struct device' to describe it in charger.c file. So we should
manage the 'struct device' with one proper way.

-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Baolin Wang
On 21 June 2016 at 18:27, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>> For supporting the usb charger, it adds the usb_charger_init() and
>> usb_charger_exit() functions for usb charger initialization and exit.
>>
>> It will report to the usb charger when the gadget state is changed,
>> then the usb charger can do the power things.
>>
>> Signed-off-by: Baolin Wang 
>> Reviewed-by: Li Jun 
>> Tested-by: Li Jun 
>
> Before anything, I must say that I really liked this patch. It's

Thanks.

> minimaly invasive to udc core and does all the necessary changes. If it
> wasn't for the extra charger class, this would've been perfect.
>
> Can't you just tie a charger to a UDC and avoid the charger class
> completely?

Yeah, I also hope so. But we really want something to manage the
charger devices, do you have any good suggestion to avoid the 'class'
but also can manage the charger devices?

>
>>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned 
>> mA)
>>  {
>> + if (gadget->charger)
>
> I guess you could do this check inside
> usb_gadget_set_cur_limit_by_type() itself.

OK.

>
> --
> balbi



-- 
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 v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> For supporting the usb charger, it adds the usb_charger_init() and
> usb_charger_exit() functions for usb charger initialization and exit.
>
> It will report to the usb charger when the gadget state is changed,
> then the usb charger can do the power things.
>
> Signed-off-by: Baolin Wang 
> Reviewed-by: Li Jun 
> Tested-by: Li Jun 

Before anything, I must say that I really liked this patch. It's
minimaly invasive to udc core and does all the necessary changes. If it
wasn't for the extra charger class, this would've been perfect.

Can't you just tie a charger to a UDC and avoid the charger class
completely?

>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned 
> mA)
>  {
> + if (gadget->charger)

I guess you could do this check inside
usb_gadget_set_cur_limit_by_type() itself.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v12 2/4] gadget: Support for the usb charger framework

2016-06-21 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
Reviewed-by: Li Jun 
Tested-by: Li Jun 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 6e8300d..84c098c 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -242,6 +243,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -411,6 +415,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -431,6 +439,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -539,6 +549,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 457651b..40390ec 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -639,6 +640,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -855,10 +858,18 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+ gadget->charger->type,
+ mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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: [RESEND PATCH v11 2/4] gadget: Support for the usb charger framework

2016-06-13 Thread Jun Li
Hi

> -Original Message-
> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> ow...@vger.kernel.org] On Behalf Of Baolin Wang
> Sent: Monday, June 13, 2016 4:47 PM
> To: ba...@kernel.org; gre...@linuxfoundation.org; s...@kernel.org;
> dbarysh...@gmail.com; dw...@infradead.org
> Cc: r...@kernel.org; m.szyprow...@samsung.com; ruslan.bilo...@gmail.com;
> peter.c...@freescale.com; st...@rowland.harvard.edu; r.bald...@samsung.com;
> yoshihiro.shimoda...@renesas.com; lee.jo...@linaro.org; broo...@kernel.org;
> ckee...@opensource.wolfsonmicro.com; patc...@opensource.wolfsonmicro.com;
> baolin.w...@linaro.org; linux...@vger.kernel.org; linux-
> u...@vger.kernel.org; device-mainlin...@lists.linuxfoundation.org; linux-
> ker...@vger.kernel.org
> Subject: [RESEND PATCH v11 2/4] gadget: Support for the usb charger
> framework
> 
> For supporting the usb charger, it adds the usb_charger_init() and
> usb_charger_exit() functions for usb charger initialization and exit.
> 
> It will report to the usb charger when the gadget state is changed, then
> the usb charger can do the power things.
> 
> Signed-off-by: Baolin Wang <baolin.w...@linaro.org>

Reviewed-by: Li Jun <jun...@nxp.com>
Tested-by: Li Jun <jun...@nxp.com>

> ---
>  drivers/usb/gadget/udc/udc-core.c |   11 +++
>  include/linux/usb/gadget.h|   11 +++
>  2 files changed, 22 insertions(+)
--
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: [RESEND PATCH v11 2/4] gadget: Support for the usb charger framework

2016-06-13 Thread kbuild test robot
Hi,

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.7-rc3 next-20160609]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20160613-165523
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> ERROR: "usb_charger_init" [drivers/usb/gadget/udc/udc-core.ko] undefined!
>> ERROR: "usb_charger_plug_by_gadget" [drivers/usb/gadget/udc/udc-core.ko] 
>> undefined!
>> ERROR: "usb_charger_exit" [drivers/usb/gadget/udc/udc-core.ko] undefined!
>> ERROR: "usb_charger_set_cur_limit_by_type" 
>> [drivers/usb/gadget/libcomposite.ko] undefined!
>> ERROR: "usb_charger_set_cur_limit_by_type" 
>> [drivers/usb/gadget/legacy/gadgetfs.ko] undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [RESEND PATCH v11 2/4] gadget: Support for the usb charger framework

2016-06-13 Thread kbuild test robot
Hi,

[auto build test WARNING on balbi-usb/next]
[also build test WARNING on v4.7-rc3 next-20160609]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20160613-165523
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/linux/usb/gadget.h:228: warning: No description found for parameter 
'claimed'
   include/linux/usb/gadget.h:228: warning: No description found for parameter 
'enabled'
>> include/linux/usb/gadget.h:661: warning: No description found for parameter 
>> 'charger'
   include/linux/usb/gadget.h:661: warning: No description found for parameter 
'quirk_altset_not_supp'
   include/linux/usb/gadget.h:661: warning: No description found for parameter 
'quirk_stall_not_supp'
   include/linux/usb/gadget.h:661: warning: No description found for parameter 
'quirk_zlp_not_supp'
   include/linux/usb/composite.h:507: warning: Excess struct/union/enum/typedef 
member 'setup_pending' description in 'usb_composite_dev'
   include/linux/usb/composite.h:507: warning: Excess struct/union/enum/typedef 
member 'os_desc_pending' description in 'usb_composite_dev'
   drivers/usb/gadget/function/f_acm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_ecm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_subset.c:1: warning: no structured comments 
found
   drivers/usb/gadget/function/f_obex.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_serial.c:1: warning: no structured comments 
found

vim +/charger +661 include/linux/usb/gadget.h

d8318d7f include/linux/usb/gadget.h David Cohen 2013-12-09  645  
898c6086 include/linux/usb/gadget.h Felipe Balbi2011-11-22  646 
unsignedsg_supported:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  647 
unsignedis_otg:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  648 
unsignedis_a_peripheral:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  649 
unsignedb_hnp_enable:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  650 
unsigneda_hnp_support:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  651 
unsigneda_alt_hnp_support:1;
75a9c82a include/linux/usb/gadget.h Li Jun  2016-02-19  652 
unsignedhnp_polling_support:1;
75a9c82a include/linux/usb/gadget.h Li Jun  2016-02-19  653 
unsignedhost_request_flag:1;
0b2d2bba include/linux/usb/gadget.h David Cohen 2013-12-09  654 
unsignedquirk_ep_out_aligned_size:1;
ffd9a0fc include/linux/usb/gadget.h Robert Baldyga  2015-07-28  655 
unsignedquirk_altset_not_supp:1;
02ded1b0 include/linux/usb/gadget.h Robert Baldyga  2015-07-28  656 
unsignedquirk_stall_not_supp:1;
ca1023c8 include/linux/usb/gadget.h Robert Baldyga  2015-07-28  657 
unsignedquirk_zlp_not_supp:1;
80b2502c include/linux/usb/gadget.h Peter Chen  2015-01-28  658 
unsignedis_selfpowered:1;
ccdf138f include/linux/usb/gadget.h Robert Baldyga  2015-05-04  659 
unsigneddeactivated:1;
ccdf138f include/linux/usb/gadget.h Robert Baldyga  2015-05-04  660 
unsignedconnected:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16 @661  };
5702f753 include/linux/usb/gadget.h Felipe Balbi2013-07-17  662  #define 
work_to_gadget(w)  (container_of((w), struct usb_gadget, work))
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  663  
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  664  static 
inline void set_gadget_data(struct usb_gadget *gadget, void *data)
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  665 { 
dev_set_drvdata(>dev, data); }
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  666  static 
inline void *get_gadget_data(struct usb_gadget *gadget)
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  667 { 
return dev_get_drvdata(>dev); }
f48cf80f include/linux/usb/gadget.h Fabien Chouteau 2010-04-23  668  static 
inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
f48cf80f include/linux/usb/gadget.h Fabien Chouteau 2010-04-23  669  {

:: The code at line 661 was first introduced by commit
:: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:: TO: Linus Torvalds 
:: CC: Linus Torvalds 

---
0-DAY kernel test 

[RESEND PATCH v11 2/4] gadget: Support for the usb charger framework

2016-06-13 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 6e8300d..84c098c 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -242,6 +243,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -411,6 +415,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -431,6 +439,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -539,6 +549,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 457651b..40390ec 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -639,6 +640,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -855,10 +858,18 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+ gadget->charger->type,
+ mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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


[PATCH v11 2/4] gadget: Support for the usb charger framework

2016-05-20 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index e4e70e1..58207d0 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -230,6 +231,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -399,6 +403,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
if (ret)
goto err4;
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
udc->vbus = true;
 
@@ -419,6 +427,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -527,6 +537,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 5d4e151..9735309 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -639,6 +640,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -855,10 +858,18 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+ gadget->charger->type,
+ mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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


[RESEND PATCH v10 2/4] gadget: Support for the usb charger framework

2016-05-02 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   13 +
 2 files changed, 24 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 4151597..3a37980 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -230,6 +231,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -423,8 +427,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -533,6 +543,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 5d4e151..f82ed6b 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -639,6 +640,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -855,10 +858,20 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   enum usb_charger_type type;
+
+   if (gadget->charger) {
+   type = usb_charger_get_type(gadget->charger);
+   usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
+   }
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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


[PATCH v10 2/4] gadget: Support for the usb charger framework

2016-04-07 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   13 +
 2 files changed, 24 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index b86a6f0..8d98c6b 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -230,6 +231,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -423,8 +427,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -503,6 +513,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index d82d006..8b36a4e 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -635,6 +636,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -839,10 +842,20 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   enum usb_charger_type type;
+
+   if (gadget->charger) {
+   type = usb_charger_get_type(gadget->charger);
+   usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
+   }
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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 v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Felipe Balbi

Hi,

Peter Chen  writes:
>> >> > In below change of usb_gadget_vbus_draw(), already can get charger
>> >> > type via usb_charger_get_type().
>> >> >
>> >> > static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget,
>> >> > unsigned mA)  {
>> >> > +   enum usb_charger_type type;
>> >> > +
>> >> > +   if (gadget->charger) {
>> >> > +   type = usb_charger_get_type(gadget->charger);
>> >> > +   usb_charger_set_cur_limit_by_type(gadget->charger, type,
>> >> mA);
>> >> > +   }
>> >> > +
>> >> > if (!gadget->ops->vbus_draw)
>> >> > return -EOPNOTSUPP;
>> >> > return gadget->ops->vbus_draw(gadget, mA);
>> >> >
>> >> > Could you detail in what situation gadget->ops-> get_charger_type() is
>> >> used?
>> >> 
>> >> isn't it right there in the code ? Isn't usb_gadget_vbus_draw() calling
>> >> it ? What did I miss here ?
>> >
>> > Well, that's true, so my real meaning is why gadget need get charger type
>> > via another new api gadget->ops->get_charger_type().
>> 
>> because of semantics. usb_gadget_vbus_draw() is *only* supposed to
>> connect a load across vbus and gnd so some battery can be charged. Also,
>> we need to abstract away this ->get_charger_type() operation because it
>> might be different for each UDC.
>
> In this patch set, there are two ->get_charger_type in below two
> structures, as my understanding, get_charger_type at struct usb_charger
> can be implemented at UDC drivers; But I don't see necessary we
> need to implement get_charger_type for usb_gadget_ops at UDC drivers
> again. What do you think?

I had missed that completely, nice catch. I agree with you, there should
be one place where this is implemented and struct usb_charger sounds
like it is that place.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Peter Chen
On Wed, Apr 06, 2016 at 04:58:03PM +0300, Felipe Balbi wrote:
> 
> Hi,
> 
> Jun Li  writes:
> >> >> >> > Since we already have get_charger_type callback at usb_charger
> >> >> >> > structure, why we still need this API at usb_gadget_ops?
> >> >> >>
> >> >> >> In case some users want to get charger type at gadget level.
> >> >> >>
> >> >> > Why gadget needs to know charger type? I also don't catch the
> >> >> > intent of
> >> >>
> >> >> because some gadgets need to call usb_gadget_vbus_draw(), although
> >> >> for that they need power in mA rather.
> >> >
> >> > In below change of usb_gadget_vbus_draw(), already can get charger
> >> > type via usb_charger_get_type().
> >> >
> >> > static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget,
> >> > unsigned mA)  {
> >> > +   enum usb_charger_type type;
> >> > +
> >> > +   if (gadget->charger) {
> >> > +   type = usb_charger_get_type(gadget->charger);
> >> > +   usb_charger_set_cur_limit_by_type(gadget->charger, type,
> >> mA);
> >> > +   }
> >> > +
> >> > if (!gadget->ops->vbus_draw)
> >> > return -EOPNOTSUPP;
> >> > return gadget->ops->vbus_draw(gadget, mA);
> >> >
> >> > Could you detail in what situation gadget->ops-> get_charger_type() is
> >> used?
> >> 
> >> isn't it right there in the code ? Isn't usb_gadget_vbus_draw() calling
> >> it ? What did I miss here ?
> >
> > Well, that's true, so my real meaning is why gadget need get charger type
> > via another new api gadget->ops->get_charger_type().
> 
> because of semantics. usb_gadget_vbus_draw() is *only* supposed to
> connect a load across vbus and gnd so some battery can be charged. Also,
> we need to abstract away this ->get_charger_type() operation because it
> might be different for each UDC.

In this patch set, there are two ->get_charger_type in below two
structures, as my understanding, get_charger_type at struct usb_charger
can be implemented at UDC drivers; But I don't see necessary we
need to implement get_charger_type for usb_gadget_ops at UDC drivers
again. What do you think?

struct usb_gadget_ops {

struct usb_ep *(*match_ep)(struct usb_gadget *,
+   /* get the charger type */
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
};

struct usb_charger {
...
+   /* user can get charger type by implementing this callback */
+   enum usb_charger_type   (*get_charger_type)(struct usb_charger
*);
}
> 
> $subject has a fragility, however: It's assuming that we should always
> call ->get_charger_type() before ->vbus_draw(), but that's a good
> default, I'd say.
> 

-- 

Best Regards,
Peter Chen
--
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 v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Felipe Balbi

Hi,

Jun Li  writes:
>> >> >> > Since we already have get_charger_type callback at usb_charger
>> >> >> > structure, why we still need this API at usb_gadget_ops?
>> >> >>
>> >> >> In case some users want to get charger type at gadget level.
>> >> >>
>> >> > Why gadget needs to know charger type? I also don't catch the
>> >> > intent of
>> >>
>> >> because some gadgets need to call usb_gadget_vbus_draw(), although
>> >> for that they need power in mA rather.
>> >
>> > In below change of usb_gadget_vbus_draw(), already can get charger
>> > type via usb_charger_get_type().
>> >
>> > static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget,
>> > unsigned mA)  {
>> > +   enum usb_charger_type type;
>> > +
>> > +   if (gadget->charger) {
>> > +   type = usb_charger_get_type(gadget->charger);
>> > +   usb_charger_set_cur_limit_by_type(gadget->charger, type,
>> mA);
>> > +   }
>> > +
>> > if (!gadget->ops->vbus_draw)
>> > return -EOPNOTSUPP;
>> > return gadget->ops->vbus_draw(gadget, mA);
>> >
>> > Could you detail in what situation gadget->ops-> get_charger_type() is
>> used?
>> 
>> isn't it right there in the code ? Isn't usb_gadget_vbus_draw() calling
>> it ? What did I miss here ?
>
> Well, that's true, so my real meaning is why gadget need get charger type
> via another new api gadget->ops->get_charger_type().

because of semantics. usb_gadget_vbus_draw() is *only* supposed to
connect a load across vbus and gnd so some battery can be charged. Also,
we need to abstract away this ->get_charger_type() operation because it
might be different for each UDC.

$subject has a fragility, however: It's assuming that we should always
call ->get_charger_type() before ->vbus_draw(), but that's a good
default, I'd say.

>> >> > This api, as my understanding, gadget only need report gadget state
>> >> changes.
>> >> > All information required for usb charger is charger type and gadget
>> >> state.
>> >>
>> >> you're making an assumption about how the HW is laid out which might
>> >> not be true.
>> >>
>> >
>> > What other information you refer to here? Or what I am not aware of?
>> 
>> what I'm trying to say is that you're assuming gadgets don't need to know
>> anything other than charger type and gadget state (suspended, resume,
>> enumerated, default state, addressed, etc), but that might not be true for
>> all UDCs. You can't make that assumption that charger type and gadget
>> state is enough. The real question is what do we need *now*, but still
>> keep in mind that what we need *now* might be valid 2 years from now, so
>> API needs to be a little flexible.
>
> Get your point, flexible, I just thought create an api without any user
> for existing case/spec, wouldn't it be better to let the real user add it
> later when it's needed.

that sure is a fair point.

-- 
balbi


signature.asc
Description: PGP signature


RE: [PATCH v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Jun Li
Hi

> -Original Message-
> From: Felipe Balbi [mailto:ba...@kernel.org]
> Sent: Wednesday, April 06, 2016 8:56 PM
> To: Jun Li <jun...@nxp.com>; Baolin Wang <baolin.w...@linaro.org>; Peter
> Chen <hzpeterc...@gmail.com>
> Cc: Greg KH <gre...@linuxfoundation.org>; Sebastian Reichel
> <s...@kernel.org>; Dmitry Eremin-Solenikov <dbarysh...@gmail.com>; David
> Woodhouse <dw...@infradead.org>; Peter Chen <peter.c...@freescale.com>;
> Alan Stern <st...@rowland.harvard.edu>; r.bald...@samsung.com; Yoshihiro
> Shimoda <yoshihiro.shimoda...@renesas.com>; Lee Jones
> <lee.jo...@linaro.org>; Mark Brown <broo...@kernel.org>; Charles Keepax
> <ckee...@opensource.wolfsonmicro.com>; patc...@opensource.wolfsonmicro.com;
> Linux PM list <linux...@vger.kernel.org>; USB <linux-usb@vger.kernel.org>;
> device-mainlin...@lists.linuxfoundation.org; LKML  ker...@vger.kernel.org>
> Subject: RE: [PATCH v9 2/4] gadget: Support for the usb charger framework
> 
> 
> Hi,
> 
> Jun Li <jun...@nxp.com> writes:
> >> >> On 6 April 2016 at 15:19, Peter Chen <hzpeterc...@gmail.com> wrote:
> >> >> > On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
> >> >> >>
> >> >> >> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
> >> >> >>   struct usb_ep *(*match_ep)(struct usb_gadget *,
> >> >> >>   struct usb_endpoint_descriptor *,
> >> >> >>   struct usb_ss_ep_comp_descriptor *);
> >> >> >> + /* get the charger type */
> >> >> >> + enum usb_charger_type (*get_charger_type)(struct
> >> >> >> + usb_gadget *);
> >> >> >>  };
> >> >> >
> >> >> > Since we already have get_charger_type callback at usb_charger
> >> >> > structure, why we still need this API at usb_gadget_ops?
> >> >>
> >> >> In case some users want to get charger type at gadget level.
> >> >>
> >> > Why gadget needs to know charger type? I also don't catch the
> >> > intent of
> >>
> >> because some gadgets need to call usb_gadget_vbus_draw(), although
> >> for that they need power in mA rather.
> >
> > In below change of usb_gadget_vbus_draw(), already can get charger
> > type via usb_charger_get_type().
> >
> > static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget,
> > unsigned mA)  {
> > +   enum usb_charger_type type;
> > +
> > +   if (gadget->charger) {
> > +   type = usb_charger_get_type(gadget->charger);
> > +   usb_charger_set_cur_limit_by_type(gadget->charger, type,
> mA);
> > +   }
> > +
> > if (!gadget->ops->vbus_draw)
> > return -EOPNOTSUPP;
> > return gadget->ops->vbus_draw(gadget, mA);
> >
> > Could you detail in what situation gadget->ops-> get_charger_type() is
> used?
> 
> isn't it right there in the code ? Isn't usb_gadget_vbus_draw() calling
> it ? What did I miss here ?

Well, that's true, so my real meaning is why gadget need get charger type
via another new api gadget->ops->get_charger_type().
 
> 
> >> > This api, as my understanding, gadget only need report gadget state
> >> changes.
> >> > All information required for usb charger is charger type and gadget
> >> state.
> >>
> >> you're making an assumption about how the HW is laid out which might
> >> not be true.
> >>
> >
> > What other information you refer to here? Or what I am not aware of?
> 
> what I'm trying to say is that you're assuming gadgets don't need to know
> anything other than charger type and gadget state (suspended, resume,
> enumerated, default state, addressed, etc), but that might not be true for
> all UDCs. You can't make that assumption that charger type and gadget
> state is enough. The real question is what do we need *now*, but still
> keep in mind that what we need *now* might be valid 2 years from now, so
> API needs to be a little flexible.

Get your point, flexible, I just thought create an api without any user
for existing case/spec, wouldn't it be better to let the real user add it
later when it's needed.

> 
> cheers
> 
> --
> balbi
--
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 v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Felipe Balbi

Hi,

Jun Li  writes:
>> >> On 6 April 2016 at 15:19, Peter Chen  wrote:
>> >> > On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
>> >> >>
>> >> >> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
>> >> >>   struct usb_ep *(*match_ep)(struct usb_gadget *,
>> >> >>   struct usb_endpoint_descriptor *,
>> >> >>   struct usb_ss_ep_comp_descriptor *);
>> >> >> + /* get the charger type */
>> >> >> + enum usb_charger_type (*get_charger_type)(struct usb_gadget
>> >> >> + *);
>> >> >>  };
>> >> >
>> >> > Since we already have get_charger_type callback at usb_charger
>> >> > structure, why we still need this API at usb_gadget_ops?
>> >>
>> >> In case some users want to get charger type at gadget level.
>> >>
>> > Why gadget needs to know charger type? I also don't catch the intent
>> > of
>> 
>> because some gadgets need to call usb_gadget_vbus_draw(), although for
>> that they need power in mA rather.
>
> In below change of usb_gadget_vbus_draw(), already can get charger type
> via usb_charger_get_type().
>
> static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
>  {
> +   enum usb_charger_type type;
> +
> +   if (gadget->charger) {
> +   type = usb_charger_get_type(gadget->charger);
> +   usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
> +   }
> +
> if (!gadget->ops->vbus_draw)
> return -EOPNOTSUPP;
> return gadget->ops->vbus_draw(gadget, mA);
>
> Could you detail in what situation gadget->ops-> get_charger_type() is used?

isn't it right there in the code ? Isn't usb_gadget_vbus_draw() calling
it ? What did I miss here ?

>> > This api, as my understanding, gadget only need report gadget state
>> changes.
>> > All information required for usb charger is charger type and gadget
>> state.
>> 
>> you're making an assumption about how the HW is laid out which might not
>> be true.
>> 
>
> What other information you refer to here? Or what I am not aware of?

what I'm trying to say is that you're assuming gadgets don't need to
know anything other than charger type and gadget state (suspended,
resume, enumerated, default state, addressed, etc), but that might not
be true for all UDCs. You can't make that assumption that charger type
and gadget state is enough. The real question is what do we need *now*,
but still keep in mind that what we need *now* might be valid 2 years
from now, so API needs to be a little flexible.

cheers

-- 
balbi


signature.asc
Description: PGP signature


RE: [PATCH v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Jun Li


> -Original Message-
> From: Felipe Balbi [mailto:ba...@kernel.org]
> Sent: Wednesday, April 06, 2016 8:22 PM
> To: Jun Li <jun...@nxp.com>; Baolin Wang <baolin.w...@linaro.org>; Peter
> Chen <hzpeterc...@gmail.com>
> Cc: Greg KH <gre...@linuxfoundation.org>; Sebastian Reichel
> <s...@kernel.org>; Dmitry Eremin-Solenikov <dbarysh...@gmail.com>; David
> Woodhouse <dw...@infradead.org>; Peter Chen <peter.c...@freescale.com>;
> Alan Stern <st...@rowland.harvard.edu>; r.bald...@samsung.com; Yoshihiro
> Shimoda <yoshihiro.shimoda...@renesas.com>; Lee Jones
> <lee.jo...@linaro.org>; Mark Brown <broo...@kernel.org>; Charles Keepax
> <ckee...@opensource.wolfsonmicro.com>; patc...@opensource.wolfsonmicro.com;
> Linux PM list <linux...@vger.kernel.org>; USB <linux-usb@vger.kernel.org>;
> device-mainlin...@lists.linuxfoundation.org; LKML  ker...@vger.kernel.org>
> Subject: RE: [PATCH v9 2/4] gadget: Support for the usb charger framework
> 
> 
> Hi,
> 
> Jun Li <jun...@nxp.com> writes:
> >> -Original Message-
> >> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> >> ow...@vger.kernel.org] On Behalf Of Baolin Wang
> >> Sent: Wednesday, April 06, 2016 6:47 PM
> >> To: Peter Chen <hzpeterc...@gmail.com>
> >> Cc: Felipe Balbi <ba...@kernel.org>; Greg KH
> >> <gre...@linuxfoundation.org>; Sebastian Reichel <s...@kernel.org>;
> >> Dmitry Eremin-Solenikov <dbarysh...@gmail.com>; David Woodhouse
> >> <dw...@infradead.org>; Peter Chen <peter.c...@freescale.com>; Alan
> >> Stern <st...@rowland.harvard.edu>; r.bald...@samsung.com; Yoshihiro
> >> Shimoda <yoshihiro.shimoda...@renesas.com>; Lee Jones
> >> <lee.jo...@linaro.org>; Mark Brown <broo...@kernel.org>; Charles
> >> Keepax <ckee...@opensource.wolfsonmicro.com>;
> >> patc...@opensource.wolfsonmicro.com;
> >> Linux PM list <linux...@vger.kernel.org>; USB
> >> <linux-usb@vger.kernel.org>;
> >> device-mainlin...@lists.linuxfoundation.org; LKML  >> ker...@vger.kernel.org>
> >> Subject: Re: [PATCH v9 2/4] gadget: Support for the usb charger
> >> framework
> >>
> >> On 6 April 2016 at 15:19, Peter Chen <hzpeterc...@gmail.com> wrote:
> >> > On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
> >> >>
> >> >> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
> >> >>   struct usb_ep *(*match_ep)(struct usb_gadget *,
> >> >>   struct usb_endpoint_descriptor *,
> >> >>   struct usb_ss_ep_comp_descriptor *);
> >> >> + /* get the charger type */
> >> >> + enum usb_charger_type (*get_charger_type)(struct usb_gadget
> >> >> + *);
> >> >>  };
> >> >
> >> > Since we already have get_charger_type callback at usb_charger
> >> > structure, why we still need this API at usb_gadget_ops?
> >>
> >> In case some users want to get charger type at gadget level.
> >>
> > Why gadget needs to know charger type? I also don't catch the intent
> > of
> 
> because some gadgets need to call usb_gadget_vbus_draw(), although for
> that they need power in mA rather.

In below change of usb_gadget_vbus_draw(), already can get charger type
via usb_charger_get_type().

static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   enum usb_charger_type type;
+
+   if (gadget->charger) {
+   type = usb_charger_get_type(gadget->charger);
+   usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
+   }
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);

Could you detail in what situation gadget->ops-> get_charger_type() is used?

> 
> > This api, as my understanding, gadget only need report gadget state
> changes.
> > All information required for usb charger is charger type and gadget
> state.
> 
> you're making an assumption about how the HW is laid out which might not
> be true.
> 

What other information you refer to here? Or what I am not aware of?

Thanks.
Li Jun  

> --
> balbi
--
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 v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Felipe Balbi

Hi,

Jun Li <jun...@nxp.com> writes:
>> -Original Message-
>> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
>> ow...@vger.kernel.org] On Behalf Of Baolin Wang
>> Sent: Wednesday, April 06, 2016 6:47 PM
>> To: Peter Chen <hzpeterc...@gmail.com>
>> Cc: Felipe Balbi <ba...@kernel.org>; Greg KH <gre...@linuxfoundation.org>;
>> Sebastian Reichel <s...@kernel.org>; Dmitry Eremin-Solenikov
>> <dbarysh...@gmail.com>; David Woodhouse <dw...@infradead.org>; Peter Chen
>> <peter.c...@freescale.com>; Alan Stern <st...@rowland.harvard.edu>;
>> r.bald...@samsung.com; Yoshihiro Shimoda
>> <yoshihiro.shimoda...@renesas.com>; Lee Jones <lee.jo...@linaro.org>; Mark
>> Brown <broo...@kernel.org>; Charles Keepax
>> <ckee...@opensource.wolfsonmicro.com>; patc...@opensource.wolfsonmicro.com;
>> Linux PM list <linux...@vger.kernel.org>; USB <linux-usb@vger.kernel.org>;
>> device-mainlin...@lists.linuxfoundation.org; LKML > ker...@vger.kernel.org>
>> Subject: Re: [PATCH v9 2/4] gadget: Support for the usb charger framework
>> 
>> On 6 April 2016 at 15:19, Peter Chen <hzpeterc...@gmail.com> wrote:
>> > On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
>> >>
>> >> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
>> >>   struct usb_ep *(*match_ep)(struct usb_gadget *,
>> >>   struct usb_endpoint_descriptor *,
>> >>   struct usb_ss_ep_comp_descriptor *);
>> >> + /* get the charger type */
>> >> + enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
>> >>  };
>> >
>> > Since we already have get_charger_type callback at usb_charger
>> > structure, why we still need this API at usb_gadget_ops?
>> 
>> In case some users want to get charger type at gadget level.
>> 
> Why gadget needs to know charger type? I also don't catch the intent of

because some gadgets need to call usb_gadget_vbus_draw(), although for
that they need power in mA rather.

> This api, as my understanding, gadget only need report gadget state changes.
> All information required for usb charger is charger type and gadget state.

you're making an assumption about how the HW is laid out which might not
be true.

-- 
balbi


signature.asc
Description: PGP signature


RE: [PATCH v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Jun Li
Hi

> -Original Message-
> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> ow...@vger.kernel.org] On Behalf Of Baolin Wang
> Sent: Wednesday, April 06, 2016 6:47 PM
> To: Peter Chen <hzpeterc...@gmail.com>
> Cc: Felipe Balbi <ba...@kernel.org>; Greg KH <gre...@linuxfoundation.org>;
> Sebastian Reichel <s...@kernel.org>; Dmitry Eremin-Solenikov
> <dbarysh...@gmail.com>; David Woodhouse <dw...@infradead.org>; Peter Chen
> <peter.c...@freescale.com>; Alan Stern <st...@rowland.harvard.edu>;
> r.bald...@samsung.com; Yoshihiro Shimoda
> <yoshihiro.shimoda...@renesas.com>; Lee Jones <lee.jo...@linaro.org>; Mark
> Brown <broo...@kernel.org>; Charles Keepax
> <ckee...@opensource.wolfsonmicro.com>; patc...@opensource.wolfsonmicro.com;
> Linux PM list <linux...@vger.kernel.org>; USB <linux-usb@vger.kernel.org>;
> device-mainlin...@lists.linuxfoundation.org; LKML  ker...@vger.kernel.org>
> Subject: Re: [PATCH v9 2/4] gadget: Support for the usb charger framework
> 
> On 6 April 2016 at 15:19, Peter Chen <hzpeterc...@gmail.com> wrote:
> > On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
> >>
> >> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
> >>   struct usb_ep *(*match_ep)(struct usb_gadget *,
> >>   struct usb_endpoint_descriptor *,
> >>   struct usb_ss_ep_comp_descriptor *);
> >> + /* get the charger type */
> >> + enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
> >>  };
> >
> > Since we already have get_charger_type callback at usb_charger
> > structure, why we still need this API at usb_gadget_ops?
> 
> In case some users want to get charger type at gadget level.
> 
Why gadget needs to know charger type? I also don't catch the intent of
This api, as my understanding, gadget only need report gadget state changes.
All information required for usb charger is charger type and gadget state.

Li Jun



Re: [PATCH v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Baolin Wang
On 6 April 2016 at 15:19, Peter Chen  wrote:
> On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
>>
>> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
>>   struct usb_ep *(*match_ep)(struct usb_gadget *,
>>   struct usb_endpoint_descriptor *,
>>   struct usb_ss_ep_comp_descriptor *);
>> + /* get the charger type */
>> + enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
>>  };
>
> Since we already have get_charger_type callback at usb_charger
> structure, why we still need this API at usb_gadget_ops?

In case some users want to get charger type at gadget level.

>
>>
>>  /**
>> @@ -635,6 +638,8 @@ struct usb_gadget {
>>   unsignedout_epnum;
>>   unsignedin_epnum;
>>   struct usb_otg_caps *otg_caps;
>> + /* negotiate the power with the usb charger */
>> + struct usb_charger  *charger;
>>
>>   unsignedsg_supported:1;
>>   unsignedis_otg:1;
>> @@ -839,10 +844,20 @@ static inline int usb_gadget_vbus_connect(struct 
>> usb_gadget *gadget)
>>   * reporting how much power the device may consume.  For example, this
>>   * could affect how quickly batteries are recharged.
>>   *
>> + * It will also notify the USB charger how much power the device may
>> + * consume if there is a USB charger linking with the gadget.
>> + *
>>   * Returns zero on success, else negative errno.
>>   */
>>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned 
>> mA)
>>  {
>> + enum usb_charger_type type;
>> +
>> + if (gadget->charger) {
>> + type = usb_charger_get_type(gadget->charger);
>> + usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
>> + }
>> +
>
> You may do something redundant.
>
> - Charger detection only occurs at connection period, at other periods,
> we only change the current limit, and notify charger IC. That is to
> say, we may only need to save charger type and current limit at
> usb_charger structure, we don't need to distinguish all chargers
> type from time to time.

That's right. I just want to get the charger type as one parameter to
set current. The function is implemented as below:

enum usb_charger_type usb_charger_get_type(struct usb_charger *uchger)
{
enum usb_charger_type type;

mutex_lock(>lock);
type = uchger->type;
mutex_unlock(>lock);

return type;
}

>
> - The purpose of usb_gadget_vbus_draw design is notify charger IC too,
> so you can do set current limit and notify charger IC together at this
> API together, it has already covered all situations. We don't need to
> notify charger IC again when the gadget status has changed again.

It did not notify charger IC again. You are right,
usb_gadget_vbus_draw design will notify charger IC, so we want to
record the current in usb charger framework at the same time.

>
>>   if (!gadget->ops->vbus_draw)
>>   return -EOPNOTSUPP;
>>   return gadget->ops->vbus_draw(gadget, mA);
>> --
>> 1.7.9.5
>>
>> --
>> 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
>
> --
>
> Best Regards,
> Peter Chen



-- 
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 v9 2/4] gadget: Support for the usb charger framework

2016-04-06 Thread Peter Chen
On Fri, Apr 01, 2016 at 03:21:50PM +0800, Baolin Wang wrote:
> For supporting the usb charger, it adds the usb_charger_init() and
> usb_charger_exit() functions for usb charger initialization and exit.
> 
> It will report to the usb charger when the gadget state is changed,
> then the usb charger can do the power things.
> 
> Introduce a callback 'get_charger_type' which will implemented by
> user for usb gadget operations to get the usb charger type.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/usb/gadget/udc/udc-core.c |   11 +++
>  include/linux/usb/gadget.h|   15 +++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/udc-core.c 
> b/drivers/usb/gadget/udc/udc-core.c
> index b86a6f0..8d98c6b 100644
> --- a/drivers/usb/gadget/udc/udc-core.c
> +++ b/drivers/usb/gadget/udc/udc-core.c
> @@ -28,6 +28,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  /**
>   * struct usb_udc - describes one usb device controller
> @@ -230,6 +231,9 @@ static void usb_gadget_state_work(struct work_struct 
> *work)
>   struct usb_gadget *gadget = work_to_gadget(work);
>   struct usb_udc *udc = gadget->udc;
>  
> + /* when the gadget state is changed, then report to USB charger */
> + usb_charger_plug_by_gadget(gadget, gadget->state);
> +
>   if (udc)
>   sysfs_notify(>dev.kobj, NULL, "state");
>  }
> @@ -423,8 +427,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
> struct usb_gadget *gadget,
>  
>   mutex_unlock(_lock);
>  
> + ret = usb_charger_init(gadget);
> + if (ret)
> + goto err5;
> +
>   return 0;
>  
> +err5:
> + device_del(>dev);
>  err4:
>   list_del(>list);
>   mutex_unlock(_lock);
> @@ -503,6 +513,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
>   kobject_uevent(>dev.kobj, KOBJ_REMOVE);
>   flush_work(>work);
>   device_unregister(>dev);
> + usb_charger_exit(gadget);
>   device_unregister(>dev);
>  }
>  EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index d82d006..054488a 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  struct usb_ep;
>  
> @@ -563,6 +564,8 @@ struct usb_gadget_ops {
>   struct usb_ep *(*match_ep)(struct usb_gadget *,
>   struct usb_endpoint_descriptor *,
>   struct usb_ss_ep_comp_descriptor *);
> + /* get the charger type */
> + enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
>  };

Since we already have get_charger_type callback at usb_charger
structure, why we still need this API at usb_gadget_ops?

>  
>  /**
> @@ -635,6 +638,8 @@ struct usb_gadget {
>   unsignedout_epnum;
>   unsignedin_epnum;
>   struct usb_otg_caps *otg_caps;
> + /* negotiate the power with the usb charger */
> + struct usb_charger  *charger;
>  
>   unsignedsg_supported:1;
>   unsignedis_otg:1;
> @@ -839,10 +844,20 @@ static inline int usb_gadget_vbus_connect(struct 
> usb_gadget *gadget)
>   * reporting how much power the device may consume.  For example, this
>   * could affect how quickly batteries are recharged.
>   *
> + * It will also notify the USB charger how much power the device may
> + * consume if there is a USB charger linking with the gadget.
> + *
>   * Returns zero on success, else negative errno.
>   */
>  static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned 
> mA)
>  {
> + enum usb_charger_type type;
> +
> + if (gadget->charger) {
> + type = usb_charger_get_type(gadget->charger);
> + usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
> + }
> +

You may do something redundant.

- Charger detection only occurs at connection period, at other periods,
we only change the current limit, and notify charger IC. That is to
say, we may only need to save charger type and current limit at
usb_charger structure, we don't need to distinguish all chargers
type from time to time.

- The purpose of usb_gadget_vbus_draw design is notify charger IC too,
so you can do set current limit and notify charger IC together at this
API together, it has already covered all situations. We don't need to
notify charger IC again when the gadget status has changed again.

>   if (!gadget->ops->vbus_draw)
>   return -EOPNOTSUPP;
>   return gadget->ops->vbus_draw(gadget, mA);
> -- 
> 1.7.9.5
> 
> --
> 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

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the 

[PATCH v9 2/4] gadget: Support for the usb charger framework

2016-04-01 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   15 +++
 2 files changed, 26 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index b86a6f0..8d98c6b 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -230,6 +231,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -423,8 +427,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -503,6 +513,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index d82d006..054488a 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -563,6 +564,8 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   /* get the charger type */
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -635,6 +638,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -839,10 +844,20 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   enum usb_charger_type type;
+
+   if (gadget->charger) {
+   type = usb_charger_get_type(gadget->charger);
+   usb_charger_set_cur_limit_by_type(gadget->charger, type, mA);
+   }
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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 v8 2/4] gadget: Support for the usb charger framework

2016-03-26 Thread kbuild test robot
Hi Baolin,

[auto build test ERROR on v4.5-rc7]
[also build test ERROR on next-20160324]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20160324-204018
config: m68k-allmodconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=m68k 

All errors (new ones prefixed by >>):

>> ERROR: "usb_charger_init" [drivers/usb/gadget/udc/udc-core.ko] undefined!
>> ERROR: "usb_charger_plug_by_gadget" [drivers/usb/gadget/udc/udc-core.ko] 
>> undefined!
>> ERROR: "usb_charger_exit" [drivers/usb/gadget/udc/udc-core.ko] undefined!
>> ERROR: "usb_charger_set_cur_limit_by_type" 
>> [drivers/usb/gadget/libcomposite.ko] undefined!
>> ERROR: "usb_charger_detect_type" [drivers/usb/gadget/libcomposite.ko] 
>> undefined!
>> ERROR: "usb_charger_set_cur_limit_by_type" 
>> [drivers/usb/gadget/legacy/gadgetfs.ko] undefined!
>> ERROR: "usb_charger_detect_type" [drivers/usb/gadget/legacy/gadgetfs.ko] 
>> undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


[PATCH v8 2/4] gadget: Support for the usb charger framework

2016-03-24 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index b86a6f0..3d9a489 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -230,6 +231,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -423,8 +427,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -503,6 +513,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index d82d006..024b33d 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -563,6 +564,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -635,6 +637,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -839,10 +843,17 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+   usb_charger_detect_type(gadget->charger), mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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 v7 2/4] gadget: Support for the usb charger framework

2016-03-19 Thread kbuild test robot
Hi Baolin,

[auto build test WARNING on v4.5-rc7]
[also build test WARNING on next-20160316]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20160316-195102
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/linux/usb/gadget.h:228: warning: No description found for parameter 
'claimed'
   include/linux/usb/gadget.h:228: warning: No description found for parameter 
'enabled'
>> include/linux/usb/gadget.h:656: warning: No description found for parameter 
>> 'charger'
   include/linux/usb/gadget.h:656: warning: No description found for parameter 
'quirk_altset_not_supp'
   include/linux/usb/gadget.h:656: warning: No description found for parameter 
'quirk_stall_not_supp'
   include/linux/usb/gadget.h:656: warning: No description found for parameter 
'quirk_zlp_not_supp'
   include/linux/usb/composite.h:501: warning: Excess struct/union/enum/typedef 
member 'setup_pending' description in 'usb_composite_dev'
   include/linux/usb/composite.h:501: warning: Excess struct/union/enum/typedef 
member 'os_desc_pending' description in 'usb_composite_dev'
   drivers/usb/gadget/function/f_acm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_ecm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_subset.c:1: warning: no structured comments 
found
   drivers/usb/gadget/function/f_obex.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_serial.c:1: warning: no structured comments 
found

vim +/charger +656 include/linux/usb/gadget.h

77e9162f include/linux/usb/gadget.h Baolin Wang 2016-03-16  640 /* 
negotiate the power with the usb charger */
77e9162f include/linux/usb/gadget.h Baolin Wang 2016-03-16  641 struct 
usb_charger  *charger;
d8318d7f include/linux/usb/gadget.h David Cohen 2013-12-09  642  
898c6086 include/linux/usb/gadget.h Felipe Balbi2011-11-22  643 
unsignedsg_supported:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  644 
unsignedis_otg:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  645 
unsignedis_a_peripheral:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  646 
unsignedb_hnp_enable:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  647 
unsigneda_hnp_support:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  648 
unsigneda_alt_hnp_support:1;
0b2d2bba include/linux/usb/gadget.h David Cohen 2013-12-09  649 
unsignedquirk_ep_out_aligned_size:1;
ffd9a0fc include/linux/usb/gadget.h Robert Baldyga  2015-07-28  650 
unsignedquirk_altset_not_supp:1;
02ded1b0 include/linux/usb/gadget.h Robert Baldyga  2015-07-28  651 
unsignedquirk_stall_not_supp:1;
ca1023c8 include/linux/usb/gadget.h Robert Baldyga  2015-07-28  652 
unsignedquirk_zlp_not_supp:1;
80b2502c include/linux/usb/gadget.h Peter Chen  2015-01-28  653 
unsignedis_selfpowered:1;
ccdf138f include/linux/usb/gadget.h Robert Baldyga  2015-05-04  654 
unsigneddeactivated:1;
ccdf138f include/linux/usb/gadget.h Robert Baldyga  2015-05-04  655 
unsignedconnected:1;
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16 @656  };
5702f753 include/linux/usb/gadget.h Felipe Balbi2013-07-17  657  #define 
work_to_gadget(w)  (container_of((w), struct usb_gadget, work))
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  658  
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  659  static 
inline void set_gadget_data(struct usb_gadget *gadget, void *data)
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  660 { 
dev_set_drvdata(>dev, data); }
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  661  static 
inline void *get_gadget_data(struct usb_gadget *gadget)
^1da177e include/linux/usb_gadget.h Linus Torvalds  2005-04-16  662 { 
return dev_get_drvdata(>dev); }
f48cf80f include/linux/usb/gadget.h Fabien Chouteau 2010-04-23  663  static 
inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
f48cf80f include/linux/usb/gadget.h Fabien Chouteau 2010-04-23  664  {

:: The code at line 656 was first introduced by commit
:: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:: TO: Linus Torvalds 
:: CC: Linus Torvalds 

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all  

Re: [PATCH v7 2/4] gadget: Support for the usb charger framework

2016-03-18 Thread kbuild test robot
Hi Baolin,

[auto build test ERROR on v4.5-rc7]
[also build test ERROR on next-20160316]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20160316-195102
config: x86_64-allmodconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> ERROR: "usb_charger_init" [drivers/usb/gadget/udc/udc-core.ko] undefined!
>> ERROR: "usb_charger_plug_by_gadget" [drivers/usb/gadget/udc/udc-core.ko] 
>> undefined!
>> ERROR: "usb_charger_exit" [drivers/usb/gadget/udc/udc-core.ko] undefined!
>> ERROR: "usb_charger_set_cur_limit_by_type" 
>> [drivers/usb/gadget/libcomposite.ko] undefined!
>> ERROR: "usb_charger_detect_type" [drivers/usb/gadget/libcomposite.ko] 
>> undefined!
>> ERROR: "usb_charger_set_cur_limit_by_type" 
>> [drivers/usb/gadget/legacy/gadgetfs.ko] undefined!
>> ERROR: "usb_charger_detect_type" [drivers/usb/gadget/legacy/gadgetfs.ko] 
>> undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


[PATCH v7 2/4] gadget: Support for the usb charger framework

2016-01-03 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f660afb..2727f01 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -226,6 +227,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -405,8 +409,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -481,6 +491,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3d583a1..52c19b1 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -560,6 +561,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -632,6 +634,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -836,10 +840,17 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+   usb_charger_detect_type(gadget->charger), mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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


[PATCH v7 2/4] gadget: Support for the usb charger framework

2015-12-08 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   11 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f660afb..2727f01 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -226,6 +227,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -405,8 +409,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -481,6 +491,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3d583a1..52c19b1 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -560,6 +561,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -632,6 +634,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -836,10 +840,17 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger,
+   usb_charger_detect_type(gadget->charger), mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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 v7 2/4] gadget: Support for the usb charger framework

2015-12-08 Thread kbuild test robot
Hi Baolin,

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.4-rc4 next-20151208]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/gadget-Introduce-the-usb-charger-framework/20151208-163942
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: m68k-allmodconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=m68k 

All errors (new ones prefixed by >>):

   ERROR: "usb_charger_init" [drivers/usb/gadget/udc/udc-core.ko] undefined!
   ERROR: "usb_charger_plug_by_gadget" [drivers/usb/gadget/udc/udc-core.ko] 
undefined!
   ERROR: "usb_charger_exit" [drivers/usb/gadget/udc/udc-core.ko] undefined!
   ERROR: "usb_charger_set_cur_limit_by_type" 
[drivers/usb/gadget/libcomposite.ko] undefined!
>> ERROR: "usb_charger_detect_type" [drivers/usb/gadget/libcomposite.ko] 
>> undefined!
   ERROR: "usb_charger_set_cur_limit_by_type" 
[drivers/usb/gadget/legacy/gadgetfs.ko] undefined!
>> ERROR: "usb_charger_detect_type" [drivers/usb/gadget/legacy/gadgetfs.ko] 
>> undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


[PATCH v6 2/4] gadget: Support for the usb charger framework

2015-11-15 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   10 ++
 2 files changed, 21 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f660afb..2727f01 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -226,6 +227,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -405,8 +409,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -481,6 +491,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3d583a1..b8a6d38 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -560,6 +561,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -632,6 +634,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -836,10 +840,16 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger, mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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 v5 3/5] gadget: Support for the usb charger framework

2015-11-06 Thread kbuild test robot
Hi Baolin,

[auto build test WARNING on v4.3-rc7]
[also build test WARNING on next-20151106]

url:
https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20151106-194008
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/linux/usb/gadget.h:227: warning: No description found for parameter 
'claimed'
   include/linux/usb/gadget.h:631: warning: No description found for parameter 
'nh'
   include/linux/usb/gadget.h:631: warning: No description found for parameter 
'lock'
>> include/linux/usb/gadget.h:631: warning: No description found for parameter 
>> 'charger'
   include/linux/usb/gadget.h:631: warning: No description found for parameter 
'quirk_altset_not_supp'
   include/linux/usb/gadget.h:631: warning: No description found for parameter 
'quirk_stall_not_supp'
   include/linux/usb/gadget.h:631: warning: No description found for parameter 
'quirk_zlp_not_supp'
   include/linux/usb/gadget.h:1202: warning: No description found for parameter 
'gadget'
   include/linux/usb/gadget.h:1202: warning: No description found for parameter 
'nb'
   include/linux/usb/composite.h:501: warning: Excess struct/union/enum/typedef 
member 'setup_pending' description in 'usb_composite_dev'
   include/linux/usb/composite.h:501: warning: Excess struct/union/enum/typedef 
member 'os_desc_pending' description in 'usb_composite_dev'
   drivers/usb/gadget/function/f_acm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_ecm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_subset.c:1: warning: no structured comments 
found
   drivers/usb/gadget/function/f_obex.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_serial.c:1: warning: no structured comments 
found

vim +/charger +631 include/linux/usb/gadget.h

a64cbb7e92 include/linux/usb/gadget.h Baolin Wang 2015-11-06  615   struct 
mutexlock;
a8d202b50d include/linux/usb/gadget.h Baolin Wang 2015-11-06  616   struct 
usb_charger  *charger;
d8318d7f6b include/linux/usb/gadget.h David Cohen 2013-12-09  617  
898c608678 include/linux/usb/gadget.h Felipe Balbi2011-11-22  618   
unsignedsg_supported:1;
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  619   
unsignedis_otg:1;
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  620   
unsignedis_a_peripheral:1;
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  621   
unsignedb_hnp_enable:1;
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  622   
unsigneda_hnp_support:1;
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  623   
unsigneda_alt_hnp_support:1;
0b2d2bbade include/linux/usb/gadget.h David Cohen 2013-12-09  624   
unsignedquirk_ep_out_aligned_size:1;
ffd9a0fcbb include/linux/usb/gadget.h Robert Baldyga  2015-07-28  625   
unsignedquirk_altset_not_supp:1;
02ded1b0d8 include/linux/usb/gadget.h Robert Baldyga  2015-07-28  626   
unsignedquirk_stall_not_supp:1;
ca1023c81d include/linux/usb/gadget.h Robert Baldyga  2015-07-28  627   
unsignedquirk_zlp_not_supp:1;
80b2502cea include/linux/usb/gadget.h Peter Chen  2015-01-28  628   
unsignedis_selfpowered:1;
ccdf138fe3 include/linux/usb/gadget.h Robert Baldyga  2015-05-04  629   
unsigneddeactivated:1;
ccdf138fe3 include/linux/usb/gadget.h Robert Baldyga  2015-05-04  630   
unsignedconnected:1;
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16 @631  };
5702f75375 include/linux/usb/gadget.h Felipe Balbi2013-07-17  632  #define 
work_to_gadget(w)(container_of((w), struct usb_gadget, work))
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  633  
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  634  static 
inline void set_gadget_data(struct usb_gadget *gadget, void *data)
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  635   { 
dev_set_drvdata(>dev, data); }
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  636  static 
inline void *get_gadget_data(struct usb_gadget *gadget)
^1da177e4c include/linux/usb_gadget.h Linus Torvalds  2005-04-16  637   { 
return dev_get_drvdata(>dev); }
f48cf80f93 include/linux/usb/gadget.h Fabien Chouteau 2010-04-23  638  static 
inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
f48cf80f93 include/linux/usb/gadget.h Fabien Chouteau 2010-04-23  639  {

:: The code at line 631 was first introduced by commit
:: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:: TO: Linus Torvalds 
:: CC: 

[PATCH v5 3/5] gadget: Support for the usb charger framework

2015-11-06 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |8 
 include/linux/usb/gadget.h|9 +
 2 files changed, 17 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 4238fc3..370376e 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -437,8 +438,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -513,6 +520,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 755e8bc..c2610c4 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -537,6 +538,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -611,6 +613,7 @@ struct usb_gadget {
struct usb_otg_caps *otg_caps;
struct raw_notifier_headnh;
struct mutexlock;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -815,10 +818,16 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger, mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
1.7.9.5

--
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


[PATCH v4 3/5] gadget: Support for the usb charger framework

2015-09-24 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c | 8 
 include/linux/usb/gadget.h| 2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 4238fc3..370376e 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -437,8 +438,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -513,6 +520,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 755e8bc..451ad32 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -537,6 +537,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -611,6 +612,7 @@ struct usb_gadget {
struct usb_otg_caps *otg_caps;
struct raw_notifier_headnh;
struct mutexlock;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.9.1

--
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


[PATCH v4 3/5] gadget: Support for the usb charger framework

2015-08-20 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 drivers/usb/gadget/udc/udc-core.c |8 
 include/linux/usb/gadget.h|2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 4238fc3..370376e 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
 #include linux/usb.h
+#include linux/usb/usb_charger.h
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -437,8 +438,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(udc_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(udc-dev);
 err4:
list_del(udc-list);
mutex_unlock(udc_lock);
@@ -513,6 +520,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
flush_work(gadget-work);
device_unregister(udc-dev);
+   usb_charger_exit(gadget);
device_unregister(gadget-dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 755e8bc..451ad32 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -537,6 +537,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -611,6 +612,7 @@ struct usb_gadget {
struct usb_otg_caps *otg_caps;
struct raw_notifier_headnh;
struct mutexlock;
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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 v4 3/5] gadget: Support for the usb charger framework

2015-08-19 Thread Sergei Shtylyov

Hello.

On 8/19/2015 12:13 PM, Baolin Wang wrote:


For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang baolin.w...@linaro.org

[...]


diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 755e8bc..44d82f5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -537,6 +537,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);

 ^^^ please use space, not tab here


  };

  /**
@@ -611,6 +612,7 @@ struct usb_gadget {
struct usb_otg_caps *otg_caps;
struct raw_notifier_headnh;
struct mutexlock;
+   struct usb_charger  *uchger;


   Why not simply call the field 'charger'? :-)

[...]

WBR, Sergei

--
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 v4 3/5] gadget: Support for the usb charger framework

2015-08-19 Thread Baolin Wang
On 19 August 2015 at 20:56, Sergei Shtylyov
sergei.shtyl...@cogentembedded.com wrote:
 Hello.

 On 8/19/2015 12:13 PM, Baolin Wang wrote:

 For supporting the usb charger, it adds the usb_charger_init() and
 usb_charger_exit() functions for usb charger initialization and exit.

 Introduce a callback 'get_charger_type' which will implemented by
 user for usb gadget operations to get the usb charger type.

 Signed-off-by: Baolin Wang baolin.w...@linaro.org

 [...]

 diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
 index 755e8bc..44d82f5 100644
 --- a/include/linux/usb/gadget.h
 +++ b/include/linux/usb/gadget.h
 @@ -537,6 +537,7 @@ struct usb_gadget_ops {
 struct usb_ep *(*match_ep)(struct usb_gadget *,
 struct usb_endpoint_descriptor *,
 struct usb_ss_ep_comp_descriptor *);
 +   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);

  ^^^ please use space, not tab here

OK.


   };

   /**
 @@ -611,6 +612,7 @@ struct usb_gadget {
 struct usb_otg_caps *otg_caps;
 struct raw_notifier_headnh;
 struct mutexlock;
 +   struct usb_charger  *uchger;


Why not simply call the field 'charger'? :-)

I think 'uchger' is the abbreviation of 'usb charger' which is maybe a
little verbous, I'll change it. Thanks for your comments.


 [...]

 WBR, Sergei




-- 
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


[PATCH v4 3/5] gadget: Support for the usb charger framework

2015-08-19 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 drivers/usb/gadget/udc/udc-core.c |8 
 include/linux/usb/gadget.h|2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 4238fc3..370376e 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
 #include linux/usb.h
+#include linux/usb/usb_charger.h
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -437,8 +438,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(udc_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(udc-dev);
 err4:
list_del(udc-list);
mutex_unlock(udc_lock);
@@ -513,6 +520,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
flush_work(gadget-work);
device_unregister(udc-dev);
+   usb_charger_exit(gadget);
device_unregister(gadget-dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 755e8bc..44d82f5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -537,6 +537,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -611,6 +612,7 @@ struct usb_gadget {
struct usb_otg_caps *otg_caps;
struct raw_notifier_headnh;
struct mutexlock;
+   struct usb_charger  *uchger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
1.7.9.5

--
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


[PATCH v3 1/3] gadget: Support for the usb charger framework

2015-08-18 Thread Baolin Wang
The usb charger framework is based on usb gadget, and each usb gadget
can be one usb charger to set the current limitation.

This patch adds a notifier mechanism for usb charger to report to usb
charger when the usb gadget state is changed.

Also we introduce a callback 'get_charger_type' which will implemented
by user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 drivers/usb/gadget/udc/udc-core.c |   41 -
 include/linux/usb/gadget.h|   20 ++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f660afb..1971218 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
 #include linux/usb.h
+#include linux/usb/usb_charger.h
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -129,6 +130,32 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
 }
 EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb)
+{
+   int ret;
+
+   mutex_lock(gadget-lock);
+   ret = raw_notifier_chain_register(gadget-nh, nb);
+   mutex_unlock(gadget-lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_register_notify);
+
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb)
+{
+   int ret;
+
+   mutex_lock(gadget-lock);
+   ret = raw_notifier_chain_unregister(gadget-nh, nb);
+   mutex_unlock(gadget-lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify);
+
 /* - */
 
 /**
@@ -226,6 +253,10 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget-udc;
 
+   mutex_lock(gadget-lock);
+   raw_notifier_call_chain(gadget-nh, gadget-state, gadget);
+   mutex_unlock(gadget-lock);
+
if (udc)
sysfs_notify(udc-dev.kobj, NULL, state);
 }
@@ -364,6 +395,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
dev_set_name(gadget-dev, gadget);
INIT_WORK(gadget-work, usb_gadget_state_work);
+   RAW_INIT_NOTIFIER_HEAD(gadget-nh);
+   mutex_init(gadget-lock);
gadget-dev.parent = parent;
 
 #ifdef CONFIG_HAS_DMA
@@ -405,8 +438,13 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(udc_lock);
 
-   return 0;
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
 
+   return 0;
+err5:
+   device_del(udc-dev);
 err4:
list_del(udc-list);
mutex_unlock(udc_lock);
@@ -481,6 +519,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
flush_work(gadget-work);
device_unregister(udc-dev);
+   usb_charger_exit(gadget);
device_unregister(gadget-dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index c14a69b..78cc862 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -537,6 +537,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -609,6 +610,9 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   struct raw_notifier_headnh;
+   struct usb_charger  *uchger;
+   struct mutexlock;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -1183,6 +1187,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget 
*gadget,
 
 /*-*/
 
+/**
+ * Register a notifiee to get notified by any attach status changes from
+ * the usb gadget
+ */
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb);
+
+/*-*/
+
+
+/* Unregister a notifiee from the usb gadget */
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb);
+
+/*-*/
+
 /* utility to set gadget state properly 

Re: [PATCH v3 1/3] gadget: Support for the usb charger framework

2015-08-18 Thread Baolin Wang
On 19 August 2015 at 00:04, Greg KH gre...@linuxfoundation.org wrote:
 On Tue, Aug 18, 2015 at 07:14:19PM +0800, Baolin Wang wrote:
 The usb charger framework is based on usb gadget, and each usb gadget
 can be one usb charger to set the current limitation.

 This patch adds a notifier mechanism for usb charger to report to usb
 charger when the usb gadget state is changed.

 Also we introduce a callback 'get_charger_type' which will implemented
 by user for usb gadget operations to get the usb charger type.

 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/udc/udc-core.c |   41 
 -
  include/linux/usb/gadget.h|   20 ++
  2 files changed, 60 insertions(+), 1 deletion(-)

 diff --git a/drivers/usb/gadget/udc/udc-core.c 
 b/drivers/usb/gadget/udc/udc-core.c
 index f660afb..1971218 100644
 --- a/drivers/usb/gadget/udc/udc-core.c
 +++ b/drivers/usb/gadget/udc/udc-core.c
 @@ -28,6 +28,7 @@
  #include linux/usb/ch9.h
  #include linux/usb/gadget.h
  #include linux/usb.h
 +#include linux/usb/usb_charger.h

 You just broke the build, which proves you did not properly test this
 patch series, so why should we even consider it?


Oh, I'm very sorry about that. I'll re-check my patch and test it
carefully. Thanks for your comments.

 greg k-h



-- 
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 v3 1/3] gadget: Support for the usb charger framework

2015-08-18 Thread Greg KH
On Tue, Aug 18, 2015 at 07:14:19PM +0800, Baolin Wang wrote:
 The usb charger framework is based on usb gadget, and each usb gadget
 can be one usb charger to set the current limitation.
 
 This patch adds a notifier mechanism for usb charger to report to usb
 charger when the usb gadget state is changed.
 
 Also we introduce a callback 'get_charger_type' which will implemented
 by user for usb gadget operations to get the usb charger type.
 
 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/udc/udc-core.c |   41 
 -
  include/linux/usb/gadget.h|   20 ++
  2 files changed, 60 insertions(+), 1 deletion(-)
 
 diff --git a/drivers/usb/gadget/udc/udc-core.c 
 b/drivers/usb/gadget/udc/udc-core.c
 index f660afb..1971218 100644
 --- a/drivers/usb/gadget/udc/udc-core.c
 +++ b/drivers/usb/gadget/udc/udc-core.c
 @@ -28,6 +28,7 @@
  #include linux/usb/ch9.h
  #include linux/usb/gadget.h
  #include linux/usb.h
 +#include linux/usb/usb_charger.h

You just broke the build, which proves you did not properly test this
patch series, so why should we even consider it?

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 1/3] gadget: Support for the usb charger framework

2015-08-16 Thread Baolin Wang
On 17 August 2015 at 08:40, Peter Chen peter.c...@freescale.com wrote:
 On Fri, Aug 14, 2015 at 05:47:44PM +0800, Baolin Wang wrote:
 The usb charger framework is based on usb gadget, and each usb gadget
 can be one usb charger to set the current limitation.

 This patch adds a notifier mechanism for usb charger to report to usb
 charger when the usb gadget state is changed.

 Also we introduce a callback 'get_charger_type' which will implemented
 by user for usb gadget operations to get the usb charger type.

 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/udc/udc-core.c |   38 
 +
  include/linux/usb/gadget.h|   20 +++
  2 files changed, 58 insertions(+)

 diff --git a/drivers/usb/gadget/udc/udc-core.c 
 b/drivers/usb/gadget/udc/udc-core.c
 index f660afb..47b231c 100644
 --- a/drivers/usb/gadget/udc/udc-core.c
 +++ b/drivers/usb/gadget/udc/udc-core.c
 @@ -28,6 +28,7 @@
  #include linux/usb/ch9.h
  #include linux/usb/gadget.h
  #include linux/usb.h
 +#include linux/usb/usb_charger.h

  /**
   * struct usb_udc - describes one usb device controller
 @@ -129,6 +130,32 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
  }
  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);

 +int usb_gadget_register_notify(struct usb_gadget *gadget,
 +struct notifier_block *nb)
 +{
 + int ret;
 +
 + mutex_lock(gadget-lock);
 + ret = raw_notifier_chain_register(gadget-nh, nb);
 + mutex_unlock(gadget-lock);
 +
 + return ret;
 +}
 +EXPORT_SYMBOL_GPL(usb_gadget_register_notify);
 +
 +int usb_gadget_unregister_notify(struct usb_gadget *gadget,
 +  struct notifier_block *nb)
 +{
 + int ret;
 +
 + mutex_lock(gadget-lock);
 + ret = raw_notifier_chain_unregister(gadget-nh, nb);
 + mutex_unlock(gadget-lock);
 +
 + return ret;
 +}
 +EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify);
 +
  /* 
 - */

  /**
 @@ -226,6 +253,10 @@ static void usb_gadget_state_work(struct work_struct 
 *work)
   struct usb_gadget *gadget = work_to_gadget(work);
   struct usb_udc *udc = gadget-udc;

 + mutex_lock(gadget-lock);
 + raw_notifier_call_chain(gadget-nh, gadget-state, gadget);
 + mutex_unlock(gadget-lock);
 +
   if (udc)
   sysfs_notify(udc-dev.kobj, NULL, state);
  }
 @@ -364,6 +395,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
 struct usb_gadget *gadget,

   dev_set_name(gadget-dev, gadget);
   INIT_WORK(gadget-work, usb_gadget_state_work);
 + RAW_INIT_NOTIFIER_HEAD(gadget-nh);
 + mutex_init(gadget-lock);
   gadget-dev.parent = parent;

  #ifdef   CONFIG_HAS_DMA
 @@ -405,6 +438,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
 struct usb_gadget *gadget,

   mutex_unlock(udc_lock);

 + ret = usb_charger_init(gadget);
 + if (ret)
 + goto err4;
 +

 If the charger's initialization fails, you may need to
 call device_del(udc-dev).


Yes, I missed that. Thanks for your comments.

 Peter

   return 0;

  err4:
 @@ -481,6 +518,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
   kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
   flush_work(gadget-work);
   device_unregister(udc-dev);
 + usb_charger_exit(gadget);
   device_unregister(gadget-dev);
  }
  EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
 index c14a69b..78cc862 100644
 --- a/include/linux/usb/gadget.h
 +++ b/include/linux/usb/gadget.h
 @@ -537,6 +537,7 @@ struct usb_gadget_ops {
   struct usb_ep *(*match_ep)(struct usb_gadget *,
   struct usb_endpoint_descriptor *,
   struct usb_ss_ep_comp_descriptor *);
 + enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
  };

  /**
 @@ -609,6 +610,9 @@ struct usb_gadget {
   unsignedout_epnum;
   unsignedin_epnum;
   struct usb_otg_caps *otg_caps;
 + struct raw_notifier_headnh;
 + struct usb_charger  *uchger;
 + struct mutexlock;

   unsignedsg_supported:1;
   unsignedis_otg:1;
 @@ -1183,6 +1187,22 @@ extern void usb_gadget_unmap_request(struct 
 usb_gadget *gadget,

  
 /*-*/

 +/**
 + * Register a notifiee to get notified by any attach status changes from
 + * the usb gadget
 + */
 +int usb_gadget_register_notify(struct usb_gadget *gadget,
 +struct notifier_block *nb);
 +
 +/*-*/
 +
 +
 +/* Unregister a notifiee from the usb gadget */
 +int usb_gadget_unregister_notify(struct usb_gadget *gadget,
 + 

Re: [PATCH v2 1/3] gadget: Support for the usb charger framework

2015-08-16 Thread Peter Chen
On Fri, Aug 14, 2015 at 05:47:44PM +0800, Baolin Wang wrote:
 The usb charger framework is based on usb gadget, and each usb gadget
 can be one usb charger to set the current limitation.
 
 This patch adds a notifier mechanism for usb charger to report to usb
 charger when the usb gadget state is changed.
 
 Also we introduce a callback 'get_charger_type' which will implemented
 by user for usb gadget operations to get the usb charger type.
 
 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/udc/udc-core.c |   38 
 +
  include/linux/usb/gadget.h|   20 +++
  2 files changed, 58 insertions(+)
 
 diff --git a/drivers/usb/gadget/udc/udc-core.c 
 b/drivers/usb/gadget/udc/udc-core.c
 index f660afb..47b231c 100644
 --- a/drivers/usb/gadget/udc/udc-core.c
 +++ b/drivers/usb/gadget/udc/udc-core.c
 @@ -28,6 +28,7 @@
  #include linux/usb/ch9.h
  #include linux/usb/gadget.h
  #include linux/usb.h
 +#include linux/usb/usb_charger.h
  
  /**
   * struct usb_udc - describes one usb device controller
 @@ -129,6 +130,32 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
  }
  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
  
 +int usb_gadget_register_notify(struct usb_gadget *gadget,
 +struct notifier_block *nb)
 +{
 + int ret;
 +
 + mutex_lock(gadget-lock);
 + ret = raw_notifier_chain_register(gadget-nh, nb);
 + mutex_unlock(gadget-lock);
 +
 + return ret;
 +}
 +EXPORT_SYMBOL_GPL(usb_gadget_register_notify);
 +
 +int usb_gadget_unregister_notify(struct usb_gadget *gadget,
 +  struct notifier_block *nb)
 +{
 + int ret;
 +
 + mutex_lock(gadget-lock);
 + ret = raw_notifier_chain_unregister(gadget-nh, nb);
 + mutex_unlock(gadget-lock);
 +
 + return ret;
 +}
 +EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify);
 +
  /* - 
 */
  
  /**
 @@ -226,6 +253,10 @@ static void usb_gadget_state_work(struct work_struct 
 *work)
   struct usb_gadget *gadget = work_to_gadget(work);
   struct usb_udc *udc = gadget-udc;
  
 + mutex_lock(gadget-lock);
 + raw_notifier_call_chain(gadget-nh, gadget-state, gadget);
 + mutex_unlock(gadget-lock);
 +
   if (udc)
   sysfs_notify(udc-dev.kobj, NULL, state);
  }
 @@ -364,6 +395,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
 struct usb_gadget *gadget,
  
   dev_set_name(gadget-dev, gadget);
   INIT_WORK(gadget-work, usb_gadget_state_work);
 + RAW_INIT_NOTIFIER_HEAD(gadget-nh);
 + mutex_init(gadget-lock);
   gadget-dev.parent = parent;
  
  #ifdef   CONFIG_HAS_DMA
 @@ -405,6 +438,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
 struct usb_gadget *gadget,
  
   mutex_unlock(udc_lock);
  
 + ret = usb_charger_init(gadget);
 + if (ret)
 + goto err4;
 +

If the charger's initialization fails, you may need to
call device_del(udc-dev).

Peter

   return 0;
  
  err4:
 @@ -481,6 +518,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
   kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
   flush_work(gadget-work);
   device_unregister(udc-dev);
 + usb_charger_exit(gadget);
   device_unregister(gadget-dev);
  }
  EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
 index c14a69b..78cc862 100644
 --- a/include/linux/usb/gadget.h
 +++ b/include/linux/usb/gadget.h
 @@ -537,6 +537,7 @@ struct usb_gadget_ops {
   struct usb_ep *(*match_ep)(struct usb_gadget *,
   struct usb_endpoint_descriptor *,
   struct usb_ss_ep_comp_descriptor *);
 + enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
  };
  
  /**
 @@ -609,6 +610,9 @@ struct usb_gadget {
   unsignedout_epnum;
   unsignedin_epnum;
   struct usb_otg_caps *otg_caps;
 + struct raw_notifier_headnh;
 + struct usb_charger  *uchger;
 + struct mutexlock;
  
   unsignedsg_supported:1;
   unsignedis_otg:1;
 @@ -1183,6 +1187,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget 
 *gadget,
  
  /*-*/
  
 +/**
 + * Register a notifiee to get notified by any attach status changes from
 + * the usb gadget
 + */
 +int usb_gadget_register_notify(struct usb_gadget *gadget,
 +struct notifier_block *nb);
 +
 +/*-*/
 +
 +
 +/* Unregister a notifiee from the usb gadget */
 +int usb_gadget_unregister_notify(struct usb_gadget *gadget,
 +  struct notifier_block *nb);
 +
 

[PATCH v2 1/3] gadget: Support for the usb charger framework

2015-08-14 Thread Baolin Wang
The usb charger framework is based on usb gadget, and each usb gadget
can be one usb charger to set the current limitation.

This patch adds a notifier mechanism for usb charger to report to usb
charger when the usb gadget state is changed.

Also we introduce a callback 'get_charger_type' which will implemented
by user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 drivers/usb/gadget/udc/udc-core.c |   38 +
 include/linux/usb/gadget.h|   20 +++
 2 files changed, 58 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f660afb..47b231c 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
 #include linux/usb.h
+#include linux/usb/usb_charger.h
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -129,6 +130,32 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
 }
 EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb)
+{
+   int ret;
+
+   mutex_lock(gadget-lock);
+   ret = raw_notifier_chain_register(gadget-nh, nb);
+   mutex_unlock(gadget-lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_register_notify);
+
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb)
+{
+   int ret;
+
+   mutex_lock(gadget-lock);
+   ret = raw_notifier_chain_unregister(gadget-nh, nb);
+   mutex_unlock(gadget-lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify);
+
 /* - */
 
 /**
@@ -226,6 +253,10 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget-udc;
 
+   mutex_lock(gadget-lock);
+   raw_notifier_call_chain(gadget-nh, gadget-state, gadget);
+   mutex_unlock(gadget-lock);
+
if (udc)
sysfs_notify(udc-dev.kobj, NULL, state);
 }
@@ -364,6 +395,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
dev_set_name(gadget-dev, gadget);
INIT_WORK(gadget-work, usb_gadget_state_work);
+   RAW_INIT_NOTIFIER_HEAD(gadget-nh);
+   mutex_init(gadget-lock);
gadget-dev.parent = parent;
 
 #ifdef CONFIG_HAS_DMA
@@ -405,6 +438,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(udc_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err4;
+
return 0;
 
 err4:
@@ -481,6 +518,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
flush_work(gadget-work);
device_unregister(udc-dev);
+   usb_charger_exit(gadget);
device_unregister(gadget-dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index c14a69b..78cc862 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -537,6 +537,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -609,6 +610,9 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   struct raw_notifier_headnh;
+   struct usb_charger  *uchger;
+   struct mutexlock;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -1183,6 +1187,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget 
*gadget,
 
 /*-*/
 
+/**
+ * Register a notifiee to get notified by any attach status changes from
+ * the usb gadget
+ */
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb);
+
+/*-*/
+
+
+/* Unregister a notifiee from the usb gadget */
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb);
+
+/*-*/
+
 /* utility to set gadget state properly */
 
 extern void usb_gadget_set_state(struct usb_gadget *gadget,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line 

Re: [PATCH 2/2] gadget: Support for the usb charger framework

2015-08-08 Thread Baolin Wang
On 8 August 2015 at 01:53, Greg KH gre...@linuxfoundation.org wrote:
 On Fri, Aug 07, 2015 at 05:22:47PM +0800, Baolin Wang wrote:
 On 7 August 2015 at 17:07, Peter Chen peter.c...@freescale.com wrote:
 
/**
 * struct usb_udc - describes one usb device controller @@ -127,12
   +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,  }
   EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
  
   +int usb_gadget_register_notify(struct usb_gadget *gadget,
   +struct notifier_block *nb) {
   + unsigned long flags;
   + int ret;
   +
   + spin_lock_irqsave(gadget-lock, flags);
  
   I find you use so many spin_lock_irqsave, any reasons for that?
   Why mutex_lock can't be used?
  
 
  The spin_lock_irqsave() can make it as a atomic notifier, that can make 
  sure the
  gadget state event can be quickly reported to the user who register a 
  notifier
  on the gadget device. Is it OK?
 
 
  I don't think it is a good reason, spin_lock_irqsave is usually used for 
  protecting
  data which is accessed at atomic environment.
 

 Yes, we want the notify process is a atomic environment which do not
 want to be interrupted by irq or other things to make the notice can
 be quickly reported to the user.

 No, this is a slow event, you don't need to notify anyone under atomic
 context, that's crazy.

 Also i think the notify process is less cost, thus i use the spinlock. 
 Thanks.

 No, use a mutex please, that's the safe thing.  This is not
 time-critical code at all.


OK, Thanks for your comments and will fix the lock thing.

 thanks,

 greg k-h



-- 
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 2/2] gadget: Support for the usb charger framework

2015-08-07 Thread Peter Chen
 
   /**
* struct usb_udc - describes one usb device controller @@ -127,12
  +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,  }
  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
  +int usb_gadget_register_notify(struct usb_gadget *gadget,
  +struct notifier_block *nb) {
  + unsigned long flags;
  + int ret;
  +
  + spin_lock_irqsave(gadget-lock, flags);
 
  I find you use so many spin_lock_irqsave, any reasons for that?
  Why mutex_lock can't be used?
 
 
 The spin_lock_irqsave() can make it as a atomic notifier, that can make sure 
 the
 gadget state event can be quickly reported to the user who register a notifier
 on the gadget device. Is it OK?
 

I don't think it is a good reason, spin_lock_irqsave is usually used for 
protecting
data which is accessed at atomic environment. 

Peter


Re: [PATCH 2/2] gadget: Support for the usb charger framework

2015-08-07 Thread Peter Chen
On Thu, Aug 06, 2015 at 03:03:49PM +0800, Baolin Wang wrote:
 The usb charger framework is based on usb gadget, and each usb gadget
 can be one usb charger to set the current limitation.
 
 This patch adds a notifier mechanism for usb charger to report to usb
 charger when the usb gadget state is changed.
 
 Also we introduce a callback 'get_charger_type' which will implemented
 by user for usb gadget operations to get the usb charger type.
 
 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/udc/udc-core.c |   41 
 +
  include/linux/usb/gadget.h|   20 ++
  2 files changed, 61 insertions(+)
 
 diff --git a/drivers/usb/gadget/udc/udc-core.c 
 b/drivers/usb/gadget/udc/udc-core.c
 index d69c355..d5368088 100644
 --- a/drivers/usb/gadget/udc/udc-core.c
 +++ b/drivers/usb/gadget/udc/udc-core.c
 @@ -28,6 +28,7 @@
  #include linux/usb/ch9.h
  #include linux/usb/gadget.h
  #include linux/usb.h
 +#include linux/usb/usb_charger.h
  
  /**
   * struct usb_udc - describes one usb device controller
 @@ -127,12 +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
  }
  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
  
 +int usb_gadget_register_notify(struct usb_gadget *gadget,
 +struct notifier_block *nb)
 +{
 + unsigned long flags;
 + int ret;
 +
 + spin_lock_irqsave(gadget-lock, flags);

I find you use so many spin_lock_irqsave, any reasons for that?
Why mutex_lock can't be used?

-- 

Best Regards,
Peter Chen
--
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 2/2] gadget: Support for the usb charger framework

2015-08-07 Thread Baolin Wang
On 7 August 2015 at 13:45, Peter Chen peter.c...@freescale.com wrote:
 On Thu, Aug 06, 2015 at 03:03:49PM +0800, Baolin Wang wrote:
 The usb charger framework is based on usb gadget, and each usb gadget
 can be one usb charger to set the current limitation.

 This patch adds a notifier mechanism for usb charger to report to usb
 charger when the usb gadget state is changed.

 Also we introduce a callback 'get_charger_type' which will implemented
 by user for usb gadget operations to get the usb charger type.

 Signed-off-by: Baolin Wang baolin.w...@linaro.org
 ---
  drivers/usb/gadget/udc/udc-core.c |   41 
 +
  include/linux/usb/gadget.h|   20 ++
  2 files changed, 61 insertions(+)

 diff --git a/drivers/usb/gadget/udc/udc-core.c 
 b/drivers/usb/gadget/udc/udc-core.c
 index d69c355..d5368088 100644
 --- a/drivers/usb/gadget/udc/udc-core.c
 +++ b/drivers/usb/gadget/udc/udc-core.c
 @@ -28,6 +28,7 @@
  #include linux/usb/ch9.h
  #include linux/usb/gadget.h
  #include linux/usb.h
 +#include linux/usb/usb_charger.h

  /**
   * struct usb_udc - describes one usb device controller
 @@ -127,12 +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
  }
  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);

 +int usb_gadget_register_notify(struct usb_gadget *gadget,
 +struct notifier_block *nb)
 +{
 + unsigned long flags;
 + int ret;
 +
 + spin_lock_irqsave(gadget-lock, flags);

 I find you use so many spin_lock_irqsave, any reasons for that?
 Why mutex_lock can't be used?


The spin_lock_irqsave() can make it as a atomic notifier, that can
make sure the gadget state event can be quickly reported to the user
who register a notifier on the gadget device. Is it OK?

 --

 Best Regards,
 Peter Chen



-- 
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 2/2] gadget: Support for the usb charger framework

2015-08-07 Thread Baolin Wang
On 7 August 2015 at 17:07, Peter Chen peter.c...@freescale.com wrote:

   /**
* struct usb_udc - describes one usb device controller @@ -127,12
  +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,  }
  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
  +int usb_gadget_register_notify(struct usb_gadget *gadget,
  +struct notifier_block *nb) {
  + unsigned long flags;
  + int ret;
  +
  + spin_lock_irqsave(gadget-lock, flags);
 
  I find you use so many spin_lock_irqsave, any reasons for that?
  Why mutex_lock can't be used?
 

 The spin_lock_irqsave() can make it as a atomic notifier, that can make sure 
 the
 gadget state event can be quickly reported to the user who register a 
 notifier
 on the gadget device. Is it OK?


 I don't think it is a good reason, spin_lock_irqsave is usually used for 
 protecting
 data which is accessed at atomic environment.


Yes, we want the notify process is a atomic environment which do not
want to be interrupted by irq or other things to make the notice can
be quickly reported to the user.

Also i think the notify process is less cost, thus i use the spinlock. Thanks.

 Peter



-- 
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 2/2] gadget: Support for the usb charger framework

2015-08-07 Thread Greg KH
On Fri, Aug 07, 2015 at 05:22:47PM +0800, Baolin Wang wrote:
 On 7 August 2015 at 17:07, Peter Chen peter.c...@freescale.com wrote:
 
/**
 * struct usb_udc - describes one usb device controller @@ -127,12
   +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,  }
   EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
  
   +int usb_gadget_register_notify(struct usb_gadget *gadget,
   +struct notifier_block *nb) {
   + unsigned long flags;
   + int ret;
   +
   + spin_lock_irqsave(gadget-lock, flags);
  
   I find you use so many spin_lock_irqsave, any reasons for that?
   Why mutex_lock can't be used?
  
 
  The spin_lock_irqsave() can make it as a atomic notifier, that can make 
  sure the
  gadget state event can be quickly reported to the user who register a 
  notifier
  on the gadget device. Is it OK?
 
 
  I don't think it is a good reason, spin_lock_irqsave is usually used for 
  protecting
  data which is accessed at atomic environment.
 
 
 Yes, we want the notify process is a atomic environment which do not
 want to be interrupted by irq or other things to make the notice can
 be quickly reported to the user.

No, this is a slow event, you don't need to notify anyone under atomic
context, that's crazy.

 Also i think the notify process is less cost, thus i use the spinlock. Thanks.

No, use a mutex please, that's the safe thing.  This is not
time-critical code at all.

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


[PATCH 2/2] gadget: Support for the usb charger framework

2015-08-06 Thread Baolin Wang
The usb charger framework is based on usb gadget, and each usb gadget
can be one usb charger to set the current limitation.

This patch adds a notifier mechanism for usb charger to report to usb
charger when the usb gadget state is changed.

Also we introduce a callback 'get_charger_type' which will implemented
by user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 drivers/usb/gadget/udc/udc-core.c |   41 +
 include/linux/usb/gadget.h|   20 ++
 2 files changed, 61 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index d69c355..d5368088 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
 #include linux/usb.h
+#include linux/usb/usb_charger.h
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -127,12 +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
 }
 EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb)
+{
+   unsigned long flags;
+   int ret;
+
+   spin_lock_irqsave(gadget-lock, flags);
+   ret = raw_notifier_chain_register(gadget-nh, nb);
+   spin_unlock_irqrestore(gadget-lock, flags);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_register_notify);
+
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb)
+{
+   unsigned long flags;
+   int ret;
+
+   spin_lock_irqsave(gadget-lock, flags);
+   ret = raw_notifier_chain_unregister(gadget-nh, nb);
+   spin_unlock_irqrestore(gadget-lock, flags);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify);
+
 /* - */
 
 static void usb_gadget_state_work(struct work_struct *work)
 {
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget-udc;
+   unsigned long flags;
+
+   spin_lock_irqsave(gadget-lock, flags);
+   raw_notifier_call_chain(gadget-nh, gadget-state, gadget);
+   spin_unlock_irqrestore(gadget-lock, flags);
 
if (udc)
sysfs_notify(udc-dev.kobj, NULL, state);
@@ -272,6 +306,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
dev_set_name(gadget-dev, gadget);
INIT_WORK(gadget-work, usb_gadget_state_work);
+   RAW_INIT_NOTIFIER_HEAD(gadget-nh);
+   spin_lock_init(gadget-lock);
gadget-dev.parent = parent;
 
 #ifdef CONFIG_HAS_DMA
@@ -313,6 +349,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(udc_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err4;
+
return 0;
 
 err4:
@@ -388,6 +428,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(udc-dev.kobj, KOBJ_REMOVE);
flush_work(gadget-work);
device_unregister(udc-dev);
+   usb_charger_exit(gadget);
device_unregister(gadget-dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 4f3dfb7..f24d6ac 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -492,6 +492,7 @@ struct usb_gadget_ops {
int (*udc_start)(struct usb_gadget *,
struct usb_gadget_driver *);
int (*udc_stop)(struct usb_gadget *);
+   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -559,6 +560,9 @@ struct usb_gadget {
struct device   dev;
unsignedout_epnum;
unsignedin_epnum;
+   struct raw_notifier_headnh;
+   struct usb_charger  *uchger;
+   spinlock_t  lock;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -1014,6 +1018,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget 
*gadget,
 
 /*-*/
 
+/**
+ * Register a notifiee to get notified by any attach status changes from
+ * the usb gadget
+ */
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb);
+
+/*-*/
+
+
+/* Unregister a notifiee from the usb gadget */
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb);
+
+/*-*/
+
 /* utility to set gadget state 

[PATCH 0/3] ARM: at91: at91sam9n12ek: enable usb gadget support

2015-02-09 Thread Bo Shen
This patch series enable the usb gadget support on at91sam9n12ek
board. On at91sam9n12 SoC which integrate the full speed udc device.


Bo Shen (3):
  USB: gadget: at91_udc: add at91sam9n12 support
  ARM: at91: dt: at91sam9n12: add udp device node
  ARM: at91: dt: at91sam9n12ek: enable udp

 arch/arm/boot/dts/at91sam9n12.dtsi  | 9 +
 arch/arm/boot/dts/at91sam9n12ek.dts | 5 +
 drivers/usb/gadget/udc/at91_udc.c   | 9 ++---
 3 files changed, 20 insertions(+), 3 deletions(-)

-- 
2.3.0.rc0

--
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: USB HID Gadget Support for Intel Edison

2015-01-12 Thread Chris McClimans
The upstream sources for platform/intel-mid aren't in any public git
repos and are distributed
as a tarball. I  have been unable to find any platform/intel-mid
specific mailing lists, so
I created my own repos and tickets to track my progress. I haven't
done much work in the
kernel, but I'm trying to learn. If there are more appropriate or
effective ways to approach Intel,
the Linux (usb) community, or a solution... please let me know. :)

On Fri, Jan 9, 2015 at 1:16 AM, Andrzej Pietrasiewicz
andrze...@samsung.com wrote:
 In the very same file there is an example platform driver; well, at least
 the most important hid-specific parts of it. You must add the usual
 module boilerplate code and in module's init do platform_device_register(),
 while in module's exit do platform_device_unregister().

This ticket tracks my progress as I attempt to understand what parts
of platform/intel-mid to edit.
https://github.com/instantinfrastructure/edison-src/issues/1
I'm currently trying to figure out what all the *_init functions do
hoping I can find where to place the module boilerplate
platform_device_[un]register functions.
I found some references to folks just adding directly to
drivers/usb/gadget/hid.c
https://github.com/instantinfrastructure/linux-yocto-3.10/commit/4a7c648b3d0cf96ccaf6b6fd133577293984ca45
but I still get errors:

# modprobe g_hid
[11677.348746] Device 'hidg.0' does not have a release() function, it
is broken and must be fixed.
modprobe: ERROR: could not insert 'g_hid': No such device

 You might also want to have a look at a configfs-composed gadget

configfs looks awesome! Having just been added to 3.19.0-rc series,
I'm not sure I could get it that kernel to work on the Edison.
There are quite a few differences in platform/intel-mid  in 3.10.17 w/
the intel patches and the vanilla 3.19.0-rc series.
I've tried reaching out to someone from the platform/intel-mid team at
Intel, but have as of yet been unsuccessful.

I also looked at gadgetfs but get failed to start errors:

```
root@edison:~# mkdir /dev/gadget
root@edison:~# rmmod g_multi
root@edison:~# mount -t gadgetfs gadetfs /dev/gadget
[   54.781038] nop dwc3-device.1: failed to start (null): -120
root@edison:~# ls /dev/gadget
dwc3-gadget
root@edison:~# ls /dev/gadget/dwc3-gadget/
ls: /dev/gadget/dwc3-gadget/: Not a directory
root@edison:~# dmesg | tail -10
[   44.184839] g_multi gadget: unbind function 'acm'/f5d7f840
[   44.184862] g_multi gadget: unbind function 'Mass Storage Function'/f5c8c380
[   44.184878] g_multi gadget: unbind
[   44.184947]  lun0: close backing file
[   44.284976] gs_close: ttyGS0 (f5453400,f5e8c300) ...
[   44.285005] gs_close: ttyGS0 (f5453400,f5e8c300) done!
[   44.286415] usb0: stop stats: rx/tx 0/20, errs 0/0
[   54.779953] gadgetfs: USB Gadget filesystem, version 24 Aug 2004
[   54.781010] udc dwc3-device.1: registering UDC driver [(null)]
[   54.781038] nop dwc3-device.1: failed to start (null): -120
root@edison:~# uname -a
Linux edison 3.10.17-poky-edison+ #6 SMP PREEMPT Fri Jan 9 19:27:34
UTC 2015 i686 GNU/Linux
```

= Upstream sources and the resultant repos 
The edison-src build system and platform/intel-mid patch (Yocto derived BSP from
  https://downloadcenter.intel.com/Detail_Desc.aspx?DwnldID=24389)

* https://github.com/instantinfrastructure/edison-src)

The yocto-3.10.17 sources with the patch applied
(https://github.com/instantinfrastructure/edison-src/blob/master/device-software/meta-edison/recipes-kernel/linux/files/upstream_to_edison.patch)

* https://github.com/instantinfrastructure/linux-yocto-3.10
--
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: USB HID Gadget Support for Intel Edison

2015-01-09 Thread Andrzej Pietrasiewicz

W dniu 08.01.2015 o 18:09, Felipe Balbi pisze:

Hi,

On Thu, Jan 08, 2015 at 09:05:24AM -0800, Chris McClimans wrote:

I'm trying to get the g_hid module working with the Intel Edison.

I tried just compiling intel's patch(1) to 3.10.17 with
CONFIG_USB_GADGETFS=m CONFIG_USB_G_HID=m but I get an error trying to
load the module:

modprobe: ERROR: could not insert 'g_hid': No such device

According to https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt:



In the very same file there is an example platform driver; well, at least
the most important hid-specific parts of it. You must add the usual
module boilerplate code and in module's init do platform_device_register(),
while in module's exit do platform_device_unregister().

You might also want to have a look at a configfs-composed gadget,
where the hid function does not require creating nor registering any
platform devices; the report descriptors are passed through
a configfs attribute (file). For more information you can have
a look here:

http://www.spinics.net/lists/linux-usb/msg116980.html

and here:

http://www.spinics.net/lists/linux-usb/msg118705.html

AP

--
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: Fwd: USB HID Gadget support for dwc3 on platform/intel-mid

2015-01-09 Thread Tobias Klauser
Hi Chris

On 2015-01-08 at 17:38:07 +0100, Chris McClimans ch...@hippiehacker.org wrote:
 I found your email in the commits for gadget_hid.txt and thought one of you
 might might be able to point me in the right direction. I'm trying to get
 the g_hid module working with the Intel Edison.

Please don't send such e-mails to people in private, this is considered
quite rude by some. Rather send the e-mail to the respective mailing
list (linux-usb@vger.kernel.org in your case). That way the person
considering herself proficient on the subject can answer. Additionally
the possible solution for the problem will be archived in the mailin
list's archive, such that other people having the same problem in the
future might get their answer directly from there.

As for myself, I only did some minor edits to the documentation file and
haven't worked with g_hid in a while.

 I tried just compiling intel's patch(1) to 3.10.17
 with CONFIG_USB_GADGETFS=m CONFIG_USB_G_HID=m but I get an error trying to
 load the module:
 
 modprobe: ERROR: could not insert 'g_hid': No such device
 
 According to https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt:
 
 g_hid is a platform driver, so to use it you need to add
 
   struct platform_device(s) to your platform code defining the
   HID function descriptors you want to use
 
 It's not clear to me what part of the platform code I should be adding, but
 I assume it's something under:
 https://github.com/instantinfrastructure/linux-yocto-3.10/tree/edison/arch/x86/platform/intel-mid

The documentation file already contains the respective code. Did you try
adding that to the appropriate place for your platform? You might want
to ask on a list specifc to the platform for where that would be.
--
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


USB HID Gadget Support for Intel Edison

2015-01-08 Thread Chris McClimans
I'm trying to get the g_hid module working with the Intel Edison.

I tried just compiling intel's patch(1) to 3.10.17 with
CONFIG_USB_GADGETFS=m CONFIG_USB_G_HID=m but I get an error trying to
load the module:

modprobe: ERROR: could not insert 'g_hid': No such device

According to https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt:

g_hid is a platform driver, so to use it you need to add
 struct platform_device(s) to your platform code defining the
 HID function descriptors you want to use

It's not clear to me what part of the platform code I should be
adding, but I assume it's something under:
https://github.com/instantinfrastructure/linux-yocto-3.10/tree/edison/arch/x86/platform/intel-mid

I have a thread open(2) on the intel community forums, but I figured
going straight to the source would be a good approach.

Thanks heaps,
Chris McClimans
ch...@hippiehacker.org

(1)* 
https://github.com/instantinfrastructure/edison-src/blob/master/device-software/meta-edison/recipes-kernel/linux/files/upstream_to_edison.patch

(2)* https://communities.intel.com/thread/58917?sr=stream
--
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: USB HID Gadget Support for Intel Edison

2015-01-08 Thread Felipe Balbi
Hi,

On Thu, Jan 08, 2015 at 09:05:24AM -0800, Chris McClimans wrote:
 I'm trying to get the g_hid module working with the Intel Edison.
 
 I tried just compiling intel's patch(1) to 3.10.17 with
 CONFIG_USB_GADGETFS=m CONFIG_USB_G_HID=m but I get an error trying to
 load the module:
 
 modprobe: ERROR: could not insert 'g_hid': No such device
 
 According to https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt:
 
 g_hid is a platform driver, so to use it you need to add
  struct platform_device(s) to your platform code defining the
  HID function descriptors you want to use

this is telling you to register a platform_device with
platform_device_register() and use platform_data to pass the descriptors
you wish.

-- 
balbi


signature.asc
Description: Digital signature


Re: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-19 Thread Barry G
On Wed, Jun 18, 2014 at 1:52 PM, Fabio Estevam feste...@gmail.com wrote:
 MPC does not use it only because no one has converted it yet :-)

Okay.  That makes sense :-)

 Take a look at the existing bindings of i.MX. You probably only needs
 to add the drivers/usb/chipidea/ci_hdrc_imx.c equivalent for MPC.

That doesn't look too bad.  I might take a crack at writing a binding
for the 83xx series.  If things go well look for a patch.  I do have
several 83xx custom boards I could try it on.

For the sake of completeness in case some other poor sap finds this
in a few months, I was able to get USB Gadget functioning on the v3.10
kernel with the following 2 complete hacks and 1 back port:
diff --git a/drivers/usb/gadget/fsl_udc_core.c
b/drivers/usb/gadget/fsl_udc_core.c
index dcd0b07..a2f26cd 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1219,6 +1219,10 @@ static int fsl_pullup(struct usb_gadget
*gadget, int is_on)
struct fsl_udc *udc;

udc = container_of(gadget, struct fsl_udc, gadget);
+
+   if (!udc-vbus_active)
+   return -EOPNOTSUPP;
+
udc-softconnect = (is_on != 0);
if (can_pullup(udc))
fsl_writel((fsl_readl(dr_regs-usbcmd) | USB_CMD_RUN_STOP),
diff --git a/arch/powerpc/include/asm/dma-mapping.h
b/arch/powerpc/include/asm/dma-mapping.h
index 150866b..6f7367a 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -87,6 +87,9 @@ static inline struct dma_map_ops *get_dma_ops(struct
device *dev)
if (unlikely(dev == NULL))
return NULL;

+   if (dev-archdata.dma_ops == NULL)
+   return dma_direct_ops;
+
return dev-archdata.dma_ops;
 }

diff --git a/drivers/usb/gadget/fsl_udc_core.c
b/drivers/usb/gadget/fsl_udc_core.c
index 28e4fc9..3385e8a 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2662,7 +2662,7 @@ MODULE_DEVICE_TABLE(platform, fsl_udc_devtype);
 static struct platform_driver udc_driver = {
.remove = __exit_p(fsl_udc_remove),
/* Just for FSL i.mx SoC currently */
-   .id_table   = fsl_udc_devtype,
+   /* .id_table= fsl_udc_devtype, */
/* these suspend and resume are not usb suspend and resume */
.suspend= fsl_udc_suspend,
.resume = fsl_udc_resume,

Not this code is hacky and probably not something you would want to
use in production,
but for the test system I am running it was sufficient to fix my problem.

Thanks for your help Fabio and Felipe!

Barry
--
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: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-18 Thread Barry G
On Tue, Jun 17, 2014 at 8:47 PM, Felipe Balbi ba...@ti.com wrote:
 Hi,
 3.10 is a pretty old kernel, you need to ask support from whoever gave
 you that kernel, unless you can try v3.16-rc1 on your board.


Thanks for responding.

We are just running Vanilla 3.10 from kernel.org without any vendor per se.

I did a quick port to 3.16-rc1 and booted off NFS so I didn't have
to port our NAND drivers.  Here is the dmesg:
Using Custom Platform machine description
Initializing cgroup subsys cpu
Initializing cgroup subsys cpuacct
Linux version 3.16.0-rc1+ (barrgr@zoidberg) (gcc version 4.2.4) #2
PREEMPT Wed Jun 18 08:39:02 PDT 2014
Found legacy serial port 0 for /immr@e000/serial@4500
  mem=e0004500, taddr=e0004500, irq=0, clk=13200, speed=0
Found legacy serial port 1 for /immr@e000/serial@4600
  mem=e0004600, taddr=e0004600, irq=0, clk=13200, speed=0
bootconsole [udbg0] enabled
Top of RAM: 0x2000, Total RAM: 0x2000
Memory hole size: 0MB
Zone ranges:
  DMA  [mem 0x-0x1fff]
  Normal   empty
Movable zone start for each node
Early memory node ranges
  node   0: [mem 0x-0x1fff]
On node 0 totalpages: 131072
free_area_init_node: node 0, pgdat c054c700, node_mem_map c07fd000
  DMA zone: 1024 pages used for memmap
  DMA zone: 0 pages reserved
  DMA zone: 131072 pages, LIFO batch:31
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: root=/dev/nfs
nfsroot=192.168.1.1:/srv/nfs_powerpc
ip=192.168.1.4::192.168.1.1:255.255.255.0::eth0:off panic=10
console=ttyS0,115200 selinux=0
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Sorting __ex_table...
Memory: 514080K/524288K available (4156K kernel code, 268K rwdata,
880K rodata, 188K init, 116K bss, 10208K reserved)
Kernel virtual memory layout:
  * 0xfffdf000..0xf000  : fixmap
  * 0xfdffc000..0xfe00  : early ioremap
  * 0xe100..0xfdffc000  : vmalloc  ioremap
Preemptible hierarchical RCU implementation.
NR_IRQS:512 nr_irqs:512 16
IPIC (128 IRQ sources) at e1000700
time_init: decrementer frequency = 33.00 MHz
time_init: processor frequency   = 330.00 MHz
clocksource: timebase mult[1e4d9365] shift[24] registered
clockevent: decrementer mult[872b021] shift[32] cpu[0]
pid_max: default: 32768 minimum: 301
Security Framework initialized
SELinux:  Disabled at boot.
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
NET: Registered protocol family 16
Registering ipic system core operations
Freescale Elo series DMA driver
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti
giome...@linux.it
PTP clock support registered
EDAC MC: Ver: 3.0.0
Switched to clocksource timebase
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP: reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
futex hash table entries: 256 (order: -1, 3072 bytes)
audit: initializing netlink subsys (disabled)
audit: type=2000 audit(0.217:1): initialized
msgmni has been set to 1004
alg: No test for stdrng (krng)
io scheduler noop registered (default)
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
console [ttyS0] disabled
serial8250.0: ttyS0 at MMIO 0xe0004500 (irq = 16, base_baud = 825)
is a 16550A
console [ttyS0] enabled
bootconsole [udbg0] disabled
serial8250.0: ttyS1 at MMIO 0xe0004600 (irq = 17, base_baud = 825)
is a 16550A
fe00.flash: Found 1 x16 devices at 0x0 in 16-bit bank.
Manufacturer ID 0x01 Chip ID 0x002201
Amd/Fujitsu Extended Query Table at 0x0040
  Amd/Fujitsu Extended Query version 1.3.
number of CFI chips: 1
fsl_spi e0007000.spi: master is unqueued, this is deprecated
fsl_spi e0007000.spi: at 0xe10a6000 (irq = 21), CPU mode
bonding: Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
libphy: Freescale PowerQUICC MII Bus: probed
fsl-gianfar e0024000.ethernet: enabled errata workarounds, flags: 0x4
fsl-gianfar e0024000.ethernet eth0: mac: 00:30:a7:07:15:f6
fsl-gianfar e0024000.ethernet eth0: Running with NAPI enabled
fsl-gianfar e0024000.ethernet eth0: RX BD ring size for Q[0]: 256
fsl-gianfar e0024000.ethernet eth0: TX BD ring size for 

Re: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-18 Thread Barry G
On Wed, Jun 18, 2014 at 9:17 AM, Barry G mr.sc...@gmail.com wrote:

 NIP [c02b3f58] usb_gadget_map_request+0x118/0x1a4
 LR [c02bc68c] fsl_ep_queue+0xc4/0x19c
 Call Trace:
 [dfff7ea8] [c02bc68c] fsl_ep_queue+0xc4/0x19c
 [dfff7ec8] [c02b7514] composite_setup+0x1324/0x13e8
 [dfff7f20] [c02bd070] fsl_udc_irq+0x5cc/0xcbc
 [dfff7f78] [c004b42c] handle_irq_event_percpu+0x4c/0x150
 [dfff7fa8] [c004b594] handle_irq_event+0x64/0x94
 [dfff7fc0] [c004e7bc] handle_level_irq+0x138/0x15c
 [dfff7fd8] [c004b118] generic_handle_irq+0x38/0x50
 [dfff7fe8] [c000530c] __do_irq+0x44/0x58
 [dfff7ff0] [c000c510] call_do_irq+0x24/0x3c
 [c054fe98] [c0005510] do_IRQ+0x94/0xe0
 [c054fec0] [c000dca4] ret_from_except+0x0/0x14
 --- Exception: 501 at arch_cpu_idle+0x24/0x68
 LR = arch_cpu_idle+0x24/0x68
 [c054ff80] [c054e000] 0xc054e000 (unreliable)
 [c054ff88] [c0042dec] cpu_startup_entry+0x100/0x180
 [c054ffa8] [c0004068] rest_init+0x84/0x9c
 [c054ffc0] [c04edd18] start_kernel+0x334/0x348
 [c054fff0] [3438] 0x3438
 Instruction dump:
 7fff0034 57ffd97f 41a2000c 3960 4808 817e00bc 20070002 7c000110
 7cd0 0f00 3d20c056 3c854000 816b0010 8009f200 5484c9f4 54a5053e
 ---[ end trace 1e1b78a0b4f63fb8 ]---


Did some more digging into this.  I found out that
usb_gadget_map_request is failing
in the dma_map_single call because get_dma_ops is returning NULL (and map_page
is offset 16 into dma_maps_ops hence the 0x10 offset).

Looks like nothing on the Freescale 83XX is calling set_dma_ops.

The following complete hacks give me USB gadget support:
diff --git a/arch/powerpc/include/asm/dma-mapping.h
b/arch/powerpc/include/asm/dma-mapping.h
index 150866b..50db4f7 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -87,6 +87,12 @@ static inline struct dma_map_ops
*get_dma_ops(struct device *dev)
if (unlikely(dev == NULL))
return NULL;

+   if (dev-archdata.dma_ops == NULL)
+   {
+   printk(KERN_ERR Barry's Complete Hack triggered
%s\n, __func__);
+   return dma_direct_ops;
+   }
+
return dev-archdata.dma_ops;
 }

diff --git a/drivers/usb/gadget/fsl_udc_core.c
b/drivers/usb/gadget/fsl_udc_core.c
index 28e4fc9..3385e8a 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2662,7 +2662,7 @@ MODULE_DEVICE_TABLE(platform, fsl_udc_devtype);
 static struct platform_driver udc_driver = {
.remove = __exit_p(fsl_udc_remove),
/* Just for FSL i.mx SoC currently */
-   .id_table   = fsl_udc_devtype,
+   /* .id_table= fsl_udc_devtype, */
/* these suspend and resume are not usb suspend and resume */
.suspend= fsl_udc_suspend,
.resume = fsl_udc_resume,

Seems to me the right solution is making a patch to add the 83XX stuff
to the id_table
and finding the right place to set_dma_ops?  I am fine doing the leg work of
creating/testing/submitting the patch providing that sounds right and people
can point me in the right direction :-)

Thanks,

Barry
--
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: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-18 Thread Fabio Estevam
On Wed, Jun 18, 2014 at 4:47 PM, Barry G mr.sc...@gmail.com wrote:

 Seems to me the right solution is making a patch to add the 83XX stuff
 to the id_table
 and finding the right place to set_dma_ops?  I am fine doing the leg work of
 creating/testing/submitting the patch providing that sounds right and people
 can point me in the right direction :-)

Can't you use the chipidea driver instead of drivers/usb/gadget/fsl_udc_core.c?
--
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: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-18 Thread Barry G
On Wed, Jun 18, 2014 at 1:00 PM, Fabio Estevam feste...@gmail.com wrote:
 Can't you use the chipidea driver instead of 
 drivers/usb/gadget/fsl_udc_core.c?

I was under the impression that the chipidea stuff was for iMX series
processors.
The comments in fsl_udc_core.c say it is for the MPC8349E and friends and
it worked fine for us until eb65796e.

I checked out the arch/powerpc/boot/dts/mpc8308rdb.dts for the RDB and it is
claiming a compatibility of fsl-usb2-dr.

What would you recommend I use as a new device tree node/compatible string?

Thanks,

Barry
--
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: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-18 Thread Fabio Estevam
On Wed, Jun 18, 2014 at 5:31 PM, Barry G mr.sc...@gmail.com wrote:
 On Wed, Jun 18, 2014 at 1:00 PM, Fabio Estevam feste...@gmail.com wrote:
 Can't you use the chipidea driver instead of 
 drivers/usb/gadget/fsl_udc_core.c?

 I was under the impression that the chipidea stuff was for iMX series
 processors.

MPC does not use it only because no one has converted it yet :-)

 The comments in fsl_udc_core.c say it is for the MPC8349E and friends and
 it worked fine for us until eb65796e.

i.MX used fsl_udc_core.c in the past. Now we have moved all of the
i.MX SoCs into chipidea driver.

It would make things a lot simpler if MPC could be moved to chipidea
driver as well so that fsl_udc_core.c could go away.


 I checked out the arch/powerpc/boot/dts/mpc8308rdb.dts for the RDB and it is
 claiming a compatibility of fsl-usb2-dr.

 What would you recommend I use as a new device tree node/compatible string?

Take a look at the existing bindings of i.MX. You probably only needs
to add the drivers/usb/chipidea/ci_hdrc_imx.c equivalent for MPC.
--
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


[bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-17 Thread Barry G
Hi all,

We have a custom board that has been running on the v3.0 kernel
for a while.  Since that kernel version is deprecated we are working
on upgrading to the 3.10 kernel (some products are 3.10-ltsi so trying
to be common).

Everything is now working except the USB gadget support.  This is a
Freescale MPC8308 based board.  Our device tree entry is:
usb@23000 {
compatible = fsl-usb2-dr;
reg = 0x23000 0x1000;
#address-cells = 1;
#size-cells = 0;
interrupt-parent = ipic;
interrupts = 38 0x8;
dr_mode = peripheral;
phy_type = ulpi;
};

In 3.0, the dmesg shows:
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)
g_ether gadget: using random self ethernet address
g_ether gadget: using random host ethernet address
usb0: MAC fa:75:de:cd:cc:80
usb0: HOST MAC f6:64:f6:b4:6b:23
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
fsl-usb2-udc: bind to driver g_ether


But in 3.10 I was only getting the base ECHI driver line.

After some debugging I found fsl_udc_probe wasn't getting called.
I made the following change:
diff -Naurp linux_kernel.orig/drivers/usb/gadget/fsl_udc_core.c
linux_kernel/drivers/usb/gadget/fsl_udc_core.c
--- linux_kernel.orig/drivers/usb/gadget/fsl_udc_core.c 2014-06-17
11:23:57.008453643 -0700
+++ linux_kernel/drivers/usb/gadget/fsl_udc_core.c  2014-06-17
11:25:45.881727426 -0700
@@ -2661,7 +2661,7 @@ MODULE_DEVICE_TABLE(platform, fsl_udc_de
 static struct platform_driver udc_driver = {
.remove = __exit_p(fsl_udc_remove),
/* Just for FSL i.mx SoC currently */
-   .id_table   = fsl_udc_devtype,
+   /* .id_table= fsl_udc_devtype, */
/* these suspend and resume are not usb suspend and resume */
.suspend= fsl_udc_suspend,
.resume = fsl_udc_resume,


And now on boot I get:
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
usbcore: registered new interface driver usb-storage
g_ether gadget: using random self ethernet address
usb0: MAC c6:62:4c:03:81:9a
usb0: HOST MAC 00:11:22:33:44:55
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
i2c /dev entries driver

But plugging the cable in results in nothing.  The host computer
doesn't see anything via lsusb or dmesg, nor does the 8308 usb client
computer.  It is like the cable isn't connected.

In an effort to figure out what broke I bisected the kernel down
to:
eb65796ef161f1b2f959a6ab4b818976054b235d
[PATCH] usb: gadget: fsl_udc_core: convert to udc_start/udc_stop

Unfortunately this patch just switches us over to the new interface
and isn't really revertible as the old interface doesn't exist.

In a futile attempt to make it work, I grabbed the 3.15 fsl_udc_core.c,
remarked the calls to usb_ep-set_maxpacket_limit, and booted that. I got:
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
usbcore: registered new interface driver usb-storage
g_ether gadget: using random self ethernet address
usb0: MAC d6:bc:72:e8:87:a1
usb0: HOST MAC 00:11:22:33:44:55
g_ether gadget: rndis: can't bind, err -19
g_ether fsl-usb2-udc.0: failed to start g_ether: -19

I know crossing over kernel versions like that is dangerous so I am
not sure if I am getting to the garbage in/garbage out stage yet.

What can I do to get the USB Ethernet Gadget functionality working again?
Thoughts or directions would be appreciated.

Thanks,

Barry
--
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: [bisected][regression] USB Ethernet Gadget Support - Freescale 8308

2014-06-17 Thread Felipe Balbi
Hi,

On Tue, Jun 17, 2014 at 04:04:04PM -0700, Barry G wrote:
 Hi all,
 
 We have a custom board that has been running on the v3.0 kernel
 for a while.  Since that kernel version is deprecated we are working
 on upgrading to the 3.10 kernel (some products are 3.10-ltsi so trying

3.10 is a pretty old kernel, you need to ask support from whoever gave
you that kernel, unless you can try v3.16-rc1 on your board.

Good luck.

-- 
balbi


signature.asc
Description: Digital signature


gadget support

2014-02-18 Thread Arturo Veras
hi all
In my PC have the kernel linux usb gadget support enabled but when i
try to load the module:

sudo modprobe g_ether
FATAL: Error inserting g_ether
(/lib/modules/3.13.2/kernel/drivers/usb/gadget/g_ether.ko): No such
device

maybe my usb is not supported by the driver. I don't know.
i have a NM10/ICH7 Family USB UHCI Controller
-- 
Atte.
Arturo
--
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: gadget support

2014-02-18 Thread Andrzej Pietrasiewicz

W dniu 18.02.2014 14:15, Arturo Veras pisze:

hi all
In my PC have the kernel linux usb gadget support enabled but when i


Why do you have usb gadget support in a PC in the first place?
What are you trying to achieve? What you could achieve is for
example to make your PC act as a mass storage device which can
be connected to some PC host via USB.


try to load the module:

sudo modprobe g_ether
FATAL: Error inserting g_ether
(/lib/modules/3.13.2/kernel/drivers/usb/gadget/g_ether.ko): No such
device



Does your system have a USB device controller (UDC or OTG chip)?
If not, the above is exactly what you should get.


maybe my usb is not supported by the driver. I don't know.
i have a NM10/ICH7 Family USB UHCI Controller


UHCI is a host controller, not a device controller.
You need a UDC/OTG chip in your system.

If you don't have the required hardware, you can use
the dummy_hcd driver, which combines a host and a device
controllers emulated in software. But this is meant
for playing with USB gadgets development; the dummy hcd
is connected (in software) to the dummy udc so taking the example of
mass storage you can make your PC act as a mass storage
device connected to the very same PC acting both as a
host and a device.

AP


--
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


  1   2   >