Re: [PATCH 1/3] uio: Allow handling of non page-aligned memory regions

2017-03-16 Thread Michal Sojka
On Thu, Mar 16 2017, Greg KH wrote:
> On Thu, Mar 16, 2017 at 02:33:25PM +0100, Michal Sojka wrote:
>> On Thu, Mar 16 2017, Greg KH wrote:
>> > On Thu, Mar 16, 2017 at 01:45:50PM +0100, Michal Sojka wrote:
>> >> On Thu, Mar 16 2017, Greg KH wrote:
>> >> > On Tue, Mar 07, 2017 at 03:09:46PM +0100, Michal Sojka wrote:
>> >> >> Since commit b65502879556 ("uio: we cannot mmap unaligned page
>> >> >> contents") addresses and sizes of UIO memory regions must be
>> >> >> page-aligned. If the address in the BAR register is not page-aligned,
>> >> >> the mentioned commit forces the UIO driver to round the address down
>> >> >> to the page size. Then, there is no easy way for user-space to learn
>> >> >> the offset of the actual memory region within the page, because the
>> >> >> offset seen in the sysfs is calculated from the rounded address and
>> >> >> thus it is always zero.
>> >> >> 
>> >> >> Fix that problem by including the offset in struct uio_mem. UIO
>> >> >> drivers can set this field and its value is reported via sysfs.
>> >> >
>> >> > It is, where?
>> >> 
>> >> /sys/class/uio/uio0/maps/map0/offset
>> >
>> > Did you change the Documentation/ABI entry for it?
>> 
>> No, because it seems that UIO is not documented there.
>
> Wow, it really isn't, that sucks, I messed up :(
>
> But, the uio-howto.rst file should probably be updated, right?

I checked that and the document is correct. The relevant part is:

> -  ``offset``: The offset, in bytes, that has to be added to the pointer
>returned by :c:func:`mmap()` to get to the actual device memory.
>This is important if the device's memory is not page aligned.
>Remember that pointers returned by :c:func:`mmap()` are always
>page aligned, so it is good style to always add this offset.

So, as described in the commit, the only problem was that without my
patch the offset has either been zero or mmap() failed. Now, mmap() can
succeed even if offset is non-zero.

-Michal


[PATCH v2 1/3] uio: Allow handling of non page-aligned memory regions

2017-03-16 Thread Michal Sojka
Since commit b65502879556 ("uio: we cannot mmap unaligned page
contents") addresses and sizes of UIO memory regions must be
page-aligned. If the address in the BAR register is not
page-aligned (which is the case of the mf264 card), the mentioned
commit forces the UIO driver to round the address down to the page
size. Then, there is no easy way for user-space to learn the offset of
the actual memory region within the page, because the offset seen in
/sys/class/uio/uio?/maps/map?/offset is calculated from the rounded
address and thus it is always zero.

Fix that problem by including the offset in struct uio_mem. UIO
drivers can set this field and userspace can read its value from
/sys/class/uio/uio?/maps/map?/offset.

The following commits update the uio_mf264 driver to set this new offs
field.

Drivers for hardware with page-aligned BARs need not to be modified
provided that they initialize struct uio_info (which contains uio_mem)
with zeros.

Signed-off-by: Michal Sojka 
---
 drivers/uio/uio.c  |  2 +-
 include/linux/uio_driver.h | 13 -
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index fba021f5736a..27c329131350 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -66,7 +66,7 @@ static ssize_t map_size_show(struct uio_mem *mem, char *buf)
 
 static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
 {
-   return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & 
~PAGE_MASK);
+   return sprintf(buf, "0x%llx\n", (unsigned long long)mem->offs);
 }
 
 struct map_sysfs_entry {
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 32c0e83d6239..3c85c81b0027 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -23,11 +23,13 @@ struct uio_map;
 /**
  * struct uio_mem - description of a UIO memory region
  * @name:  name of the memory region for identification
- * @addr:  address of the device's memory (phys_addr is used since
- * addr can be logical, virtual, or physical & phys_addr_t
- * should always be large enough to handle any of the
- * address types)
- * @size:  size of IO
+ * @addr:   address of the device's memory rounded to page
+ * size (phys_addr is used since addr can be
+ * logical, virtual, or physical & phys_addr_t
+ * should always be large enough to handle any of
+ * the address types)
+ * @offs:   offset of device memory within the page
+ * @size:  size of IO (multiple of page size)
  * @memtype:   type of memory addr points to
  * @internal_addr: ioremap-ped version of addr, for driver internal use
  * @map:   for use by the UIO core only.
@@ -35,6 +37,7 @@ struct uio_map;
 struct uio_mem {
const char  *name;
phys_addr_t addr;
+   unsigned long   offs;
resource_size_t size;
int memtype;
void __iomem*internal_addr;
-- 
2.11.0



[PATCH v2 2/3] uio_mf624: Refactor memory info initialization

2017-03-16 Thread Michal Sojka
No functional changes. Move initialization of struct uio_mem to a
function. This will allow the next commit to change the initialization
code at a single place rather that at three different places.

Signed-off-by: Michal Sojka 
---
 drivers/uio/uio_mf624.c | 44 ++--
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c
index d1f95a1567bb..8f30fa1af2ab 100644
--- a/drivers/uio/uio_mf624.c
+++ b/drivers/uio/uio_mf624.c
@@ -127,6 +127,20 @@ static int mf624_irqcontrol(struct uio_info *info, s32 
irq_on)
return 0;
 }
 
+static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, 
const char *name)
+{
+   mem->name = name;
+   mem->addr = pci_resource_start(dev, bar);
+   if (!mem->addr)
+   return -ENODEV;
+   mem->size = pci_resource_len(dev, bar);
+   mem->memtype = UIO_MEM_PHYS;
+   mem->internal_addr = pci_ioremap_bar(dev, bar);
+   if (!mem->internal_addr)
+   return -ENODEV;
+   return 0;
+}
+
 static int mf624_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
struct uio_info *info;
@@ -147,37 +161,15 @@ static int mf624_pci_probe(struct pci_dev *dev, const 
struct pci_device_id *id)
/* Note: Datasheet says device uses BAR0, BAR1, BAR2 -- do not trust it 
*/
 
/* BAR0 */
-   info->mem[0].name = "PCI chipset, interrupts, status "
-   "bits, special functions";
-   info->mem[0].addr = pci_resource_start(dev, 0);
-   if (!info->mem[0].addr)
+   if (mf624_setup_mem(dev, 0, &info->mem[0], "PCI chipset, interrupts, 
status "
+   "bits, special functions"))
goto out_release;
-   info->mem[0].size = pci_resource_len(dev, 0);
-   info->mem[0].memtype = UIO_MEM_PHYS;
-   info->mem[0].internal_addr = pci_ioremap_bar(dev, 0);
-   if (!info->mem[0].internal_addr)
-   goto out_release;
-
/* BAR2 */
-   info->mem[1].name = "ADC, DAC, DIO";
-   info->mem[1].addr = pci_resource_start(dev, 2);
-   if (!info->mem[1].addr)
-   goto out_unmap0;
-   info->mem[1].size = pci_resource_len(dev, 2);
-   info->mem[1].memtype = UIO_MEM_PHYS;
-   info->mem[1].internal_addr = pci_ioremap_bar(dev, 2);
-   if (!info->mem[1].internal_addr)
+   if (mf624_setup_mem(dev, 2, &info->mem[1], "ADC, DAC, DIO"))
goto out_unmap0;
 
/* BAR4 */
-   info->mem[2].name = "Counter/timer chip";
-   info->mem[2].addr = pci_resource_start(dev, 4);
-   if (!info->mem[2].addr)
-   goto out_unmap1;
-   info->mem[2].size = pci_resource_len(dev, 4);
-   info->mem[2].memtype = UIO_MEM_PHYS;
-   info->mem[2].internal_addr = pci_ioremap_bar(dev, 4);
-   if (!info->mem[2].internal_addr)
+   if (mf624_setup_mem(dev, 4, &info->mem[2], "Counter/timer chip"))
goto out_unmap1;
 
info->irq = dev->irq;
-- 
2.11.0



[PATCH v2 3/3] uio_mf624: Align memory regions to page size and set correct offsets

2017-03-16 Thread Michal Sojka
mf624 card has its registers not aligned to pages. Since commit
b65502879556 ("uio: we cannot mmap unaligned page contents") mmap()ing
mf624 registers fails, because now the uio drivers must set
uio_mem->addr to be page-aligned.

We align the address here and set the newly introduced offs field to
the offset of the mf264 registers within the page so that userspace
can find the address of the mmap()ed register by reading
/sys/class/uio/uio?/maps/map?/offset.

Tested with real mf624 card.

Signed-off-by: Michal Sojka 
---
 drivers/uio/uio_mf624.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c
index 8f30fa1af2ab..35187c052e8c 100644
--- a/drivers/uio/uio_mf624.c
+++ b/drivers/uio/uio_mf624.c
@@ -129,11 +129,15 @@ static int mf624_irqcontrol(struct uio_info *info, s32 
irq_on)
 
 static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, 
const char *name)
 {
+   resource_size_t start = pci_resource_start(dev, bar);
+   resource_size_t len = pci_resource_len(dev, bar);
+
mem->name = name;
-   mem->addr = pci_resource_start(dev, bar);
+   mem->addr = start & PAGE_MASK;
+   mem->offs = start & ~PAGE_MASK;
if (!mem->addr)
return -ENODEV;
-   mem->size = pci_resource_len(dev, bar);
+   mem->size = ((start & ~PAGE_MASK) + len + PAGE_SIZE - 1) & PAGE_MASK;
mem->memtype = UIO_MEM_PHYS;
mem->internal_addr = pci_ioremap_bar(dev, bar);
if (!mem->internal_addr)
-- 
2.11.0



Re: [PATCH 1/3] uio: Allow handling of non page-aligned memory regions

2017-03-16 Thread Michal Sojka
On Thu, Mar 16 2017, Greg KH wrote:
> On Thu, Mar 16, 2017 at 01:45:50PM +0100, Michal Sojka wrote:
>> On Thu, Mar 16 2017, Greg KH wrote:
>> > On Tue, Mar 07, 2017 at 03:09:46PM +0100, Michal Sojka wrote:
>> >> Since commit b65502879556 ("uio: we cannot mmap unaligned page
>> >> contents") addresses and sizes of UIO memory regions must be
>> >> page-aligned. If the address in the BAR register is not page-aligned,
>> >> the mentioned commit forces the UIO driver to round the address down
>> >> to the page size. Then, there is no easy way for user-space to learn
>> >> the offset of the actual memory region within the page, because the
>> >> offset seen in the sysfs is calculated from the rounded address and
>> >> thus it is always zero.
>> >> 
>> >> Fix that problem by including the offset in struct uio_mem. UIO
>> >> drivers can set this field and its value is reported via sysfs.
>> >
>> > It is, where?
>> 
>> /sys/class/uio/uio0/maps/map0/offset
>
> Did you change the Documentation/ABI entry for it?

No, because it seems that UIO is not documented there.

-Michal


Re: [PATCH 1/3] uio: Allow handling of non page-aligned memory regions

2017-03-16 Thread Michal Sojka
On Thu, Mar 16 2017, Greg KH wrote:
> On Tue, Mar 07, 2017 at 03:09:46PM +0100, Michal Sojka wrote:
>> Since commit b65502879556 ("uio: we cannot mmap unaligned page
>> contents") addresses and sizes of UIO memory regions must be
>> page-aligned. If the address in the BAR register is not page-aligned,
>> the mentioned commit forces the UIO driver to round the address down
>> to the page size. Then, there is no easy way for user-space to learn
>> the offset of the actual memory region within the page, because the
>> offset seen in the sysfs is calculated from the rounded address and
>> thus it is always zero.
>> 
>> Fix that problem by including the offset in struct uio_mem. UIO
>> drivers can set this field and its value is reported via sysfs.
>
> It is, where?

/sys/class/uio/uio0/maps/map0/offset

>> 
>> Drivers for hardware with page-aligned BARs need not to be modified
>> provided that they initialize struct uio_info with zeros.
>> 
>> Signed-off-by: Michal Sojka 
>> ---
>>  drivers/uio/uio.c  |  2 +-
>>  include/linux/uio_driver.h | 13 -
>>  2 files changed, 9 insertions(+), 6 deletions(-)
>> 
>> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
>> index fba021f5736a..27c329131350 100644
>> --- a/drivers/uio/uio.c
>> +++ b/drivers/uio/uio.c
>> @@ -66,7 +66,7 @@ static ssize_t map_size_show(struct uio_mem *mem, char 
>> *buf)
>>  
>>  static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
>>  {
>> -return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & 
>> ~PAGE_MASK);
>> +return sprintf(buf, "0x%llx\n", (unsigned long long)mem->offs);
>
> All you changed was this value that sysfs shows.
>
>>  }
>>  
>>  struct map_sysfs_entry {
>> diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
>> index 32c0e83d6239..89b53094f127 100644
>> --- a/include/linux/uio_driver.h
>> +++ b/include/linux/uio_driver.h
>> @@ -23,11 +23,13 @@ struct uio_map;
>>  /**
>>   * struct uio_mem - description of a UIO memory region
>>   * @name:   name of the memory region for identification
>> - * @addr:   address of the device's memory (phys_addr is used since
>> - *  addr can be logical, virtual, or physical & phys_addr_t
>> - *  should always be large enough to handle any of the
>> - *  address types)
>> - * @size:   size of IO
>> + * @addr:   address of the device's memory rounded to page
>> + *  size (phys_addr is used since addr can be
>> + *  logical, virtual, or physical & phys_addr_t
>> + *  should always be large enough to handle any of
>> + *  the address types)
>> + * @offs:   offset of device memory within the page
>> + * @size:   size of IO (multiple of page size)
>>   * @memtype:type of memory addr points to
>>   * @internal_addr:  ioremap-ped version of addr, for driver internal use
>>   * @map:for use by the UIO core only.
>> @@ -35,6 +37,7 @@ struct uio_map;
>>  struct uio_mem {
>>  const char  *name;
>>  phys_addr_t addr;
>> +unsigned long   offs;;
>
> Did you really test this patch?  Why the two ;;?  And who sets this?
>
> I think you broke things :(

This is set in patch 3/3 and it works correctly on my hardware. It seems
like you would like to have patches 2/3 and 3/3 merged in a single one.
I'll send v2 in a while and address your other comments as well.

Thanks.
-Michal


[PATCH 3/3] uio_mf624: Align memory regions to page size

2017-03-07 Thread Michal Sojka
Without that, one cannot mmap() the registers to user-space, at least since
commit b65502879556 ("uio: we cannot mmap unaligned page contents").

Tested with real mf624 card.

Signed-off-by: Michal Sojka 
---
 drivers/uio/uio_mf624.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c
index 8f30fa1af2ab..35187c052e8c 100644
--- a/drivers/uio/uio_mf624.c
+++ b/drivers/uio/uio_mf624.c
@@ -129,11 +129,15 @@ static int mf624_irqcontrol(struct uio_info *info, s32 
irq_on)
 
 static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, 
const char *name)
 {
+   resource_size_t start = pci_resource_start(dev, bar);
+   resource_size_t len = pci_resource_len(dev, bar);
+
mem->name = name;
-   mem->addr = pci_resource_start(dev, bar);
+   mem->addr = start & PAGE_MASK;
+   mem->offs = start & ~PAGE_MASK;
if (!mem->addr)
return -ENODEV;
-   mem->size = pci_resource_len(dev, bar);
+   mem->size = ((start & ~PAGE_MASK) + len + PAGE_SIZE - 1) & PAGE_MASK;
mem->memtype = UIO_MEM_PHYS;
mem->internal_addr = pci_ioremap_bar(dev, bar);
if (!mem->internal_addr)
-- 
2.11.0



[PATCH 1/3] uio: Allow handling of non page-aligned memory regions

2017-03-07 Thread Michal Sojka
Since commit b65502879556 ("uio: we cannot mmap unaligned page
contents") addresses and sizes of UIO memory regions must be
page-aligned. If the address in the BAR register is not page-aligned,
the mentioned commit forces the UIO driver to round the address down
to the page size. Then, there is no easy way for user-space to learn
the offset of the actual memory region within the page, because the
offset seen in the sysfs is calculated from the rounded address and
thus it is always zero.

Fix that problem by including the offset in struct uio_mem. UIO
drivers can set this field and its value is reported via sysfs.

Drivers for hardware with page-aligned BARs need not to be modified
provided that they initialize struct uio_info with zeros.

Signed-off-by: Michal Sojka 
---
 drivers/uio/uio.c  |  2 +-
 include/linux/uio_driver.h | 13 -
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index fba021f5736a..27c329131350 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -66,7 +66,7 @@ static ssize_t map_size_show(struct uio_mem *mem, char *buf)
 
 static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
 {
-   return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & 
~PAGE_MASK);
+   return sprintf(buf, "0x%llx\n", (unsigned long long)mem->offs);
 }
 
 struct map_sysfs_entry {
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 32c0e83d6239..89b53094f127 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -23,11 +23,13 @@ struct uio_map;
 /**
  * struct uio_mem - description of a UIO memory region
  * @name:  name of the memory region for identification
- * @addr:  address of the device's memory (phys_addr is used since
- * addr can be logical, virtual, or physical & phys_addr_t
- * should always be large enough to handle any of the
- * address types)
- * @size:  size of IO
+ * @addr:   address of the device's memory rounded to page
+ * size (phys_addr is used since addr can be
+ * logical, virtual, or physical & phys_addr_t
+ * should always be large enough to handle any of
+ * the address types)
+ * @offs:   offset of device memory within the page
+ * @size:  size of IO (multiple of page size)
  * @memtype:   type of memory addr points to
  * @internal_addr: ioremap-ped version of addr, for driver internal use
  * @map:   for use by the UIO core only.
@@ -35,6 +37,7 @@ struct uio_map;
 struct uio_mem {
const char  *name;
phys_addr_t addr;
+   unsigned long   offs;;
resource_size_t size;
int memtype;
void __iomem*internal_addr;
-- 
2.11.0



[PATCH 2/3] uio_mf624: Refactor memory info initialization

2017-03-07 Thread Michal Sojka
No functional changes.

Signed-off-by: Michal Sojka 
---
 drivers/uio/uio_mf624.c | 44 ++--
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c
index d1f95a1567bb..8f30fa1af2ab 100644
--- a/drivers/uio/uio_mf624.c
+++ b/drivers/uio/uio_mf624.c
@@ -127,6 +127,20 @@ static int mf624_irqcontrol(struct uio_info *info, s32 
irq_on)
return 0;
 }
 
+static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, 
const char *name)
+{
+   mem->name = name;
+   mem->addr = pci_resource_start(dev, bar);
+   if (!mem->addr)
+   return -ENODEV;
+   mem->size = pci_resource_len(dev, bar);
+   mem->memtype = UIO_MEM_PHYS;
+   mem->internal_addr = pci_ioremap_bar(dev, bar);
+   if (!mem->internal_addr)
+   return -ENODEV;
+   return 0;
+}
+
 static int mf624_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
struct uio_info *info;
@@ -147,37 +161,15 @@ static int mf624_pci_probe(struct pci_dev *dev, const 
struct pci_device_id *id)
/* Note: Datasheet says device uses BAR0, BAR1, BAR2 -- do not trust it 
*/
 
/* BAR0 */
-   info->mem[0].name = "PCI chipset, interrupts, status "
-   "bits, special functions";
-   info->mem[0].addr = pci_resource_start(dev, 0);
-   if (!info->mem[0].addr)
+   if (mf624_setup_mem(dev, 0, &info->mem[0], "PCI chipset, interrupts, 
status "
+   "bits, special functions"))
goto out_release;
-   info->mem[0].size = pci_resource_len(dev, 0);
-   info->mem[0].memtype = UIO_MEM_PHYS;
-   info->mem[0].internal_addr = pci_ioremap_bar(dev, 0);
-   if (!info->mem[0].internal_addr)
-   goto out_release;
-
/* BAR2 */
-   info->mem[1].name = "ADC, DAC, DIO";
-   info->mem[1].addr = pci_resource_start(dev, 2);
-   if (!info->mem[1].addr)
-   goto out_unmap0;
-   info->mem[1].size = pci_resource_len(dev, 2);
-   info->mem[1].memtype = UIO_MEM_PHYS;
-   info->mem[1].internal_addr = pci_ioremap_bar(dev, 2);
-   if (!info->mem[1].internal_addr)
+   if (mf624_setup_mem(dev, 2, &info->mem[1], "ADC, DAC, DIO"))
goto out_unmap0;
 
/* BAR4 */
-   info->mem[2].name = "Counter/timer chip";
-   info->mem[2].addr = pci_resource_start(dev, 4);
-   if (!info->mem[2].addr)
-   goto out_unmap1;
-   info->mem[2].size = pci_resource_len(dev, 4);
-   info->mem[2].memtype = UIO_MEM_PHYS;
-   info->mem[2].internal_addr = pci_ioremap_bar(dev, 4);
-   if (!info->mem[2].internal_addr)
+   if (mf624_setup_mem(dev, 4, &info->mem[2], "Counter/timer chip"))
goto out_unmap1;
 
info->irq = dev->irq;
-- 
2.11.0



error: 'struct net_device' has no member named 'nf_hooks_ingress'

2016-10-05 Thread Michal Sojka
Hi,

On Tue, Oct 04 2016, Sergey Senozhatsky wrote:
> On (09/27/16 19:03), Sergey Senozhatsky wrote:
>> Hello,
>> 
>> On (09/27/16 16:40), Stephen Rothwell wrote:
>> > 
>> > Changes since 20160923:
>> > 
>> 
>> seems that commit e3b37f11e6e4e6b6 ("netfilter: replace list_head with
>> single linked list") breaks the build on !CONFIG_NETFILTER_INGRESS systems
>> accessing ->nf_hooks_ingress

this commit is now in mainline as
e3b37f11e6e4e6b6f02cc762f182ce233d2c1c9d and it breaks my build:

net/netfilter/core.c: In function 'nf_set_hooks_head':
net/netfilter/core.c:96:3: error: 'struct net_device' has no member named 
'nf_hooks_ingress'

Are the fixes (see below) on the way to mainline too?

Thanks.
-Michal



>> 
>> static void nf_set_hooks_head(struct net *net, const struct nf_hook_ops *reg,
>>  struct nf_hook_entry *entry)
>> {
>>switch (reg->pf) {
>>case NFPROTO_NETDEV:
>>/* We already checked in nf_register_net_hook() that this is
>> * used from ingress.
>> */
>>rcu_assign_pointer(reg->dev->nf_hooks_ingress, entry);
>>  
>
>
> so I see two commits in linux-next now that fix the commit in question in
> two patches
>
>  : commit 7816ec564ec40ae20bb7925f733a181cad0cc491 ("netfilter: accommodate
>  : different kconfig in nf_set_hooks_head")
>  :
>  :When CONFIG_NETFILTER_INGRESS is unset (or no), we need to handle
>  :the request for registration properly by dropping the hook.  This
>  :releases the entry during the set.
>  :
>  :Fixes: e3b37f11e6e4 ("netfilter: replace list_head with single linked 
> list")
>
> and
>
>  : commit 5119e4381a90fabd3442bde02707cbd9e5d7367a ("netfilter: Fix potential
>  : null pointer dereference")
>  :
>  :It's possible for nf_hook_entry_head to return NULL.  If two
>  :nf_unregister_net_hook calls happen simultaneously with a single hook
>  :entry in the list, both will enter the nf_hook_mutex critical section.
>  :The first will successfully delete the head, but the second will see
>  :this NULL pointer and attempt to dereference.
>  :
>  :This fix ensures that no null pointer dereference could occur when such
>  :a condition happens.
>  :
>  :Fixes: e3b37f11e6e4 ("netfilter: replace list_head with single linked 
> list")
>
>
> do you guys plan to fold those into "e3b37f11e6e4" (a preferred way)
> or will send it out as 3 separate patches (um, why) ?
>
>   -ss


[PATCH] kconfig: Fix copy&paste error

2015-10-19 Thread Michal Sojka
Signed-off-by: Michal Sojka 
---
 scripts/kconfig/expr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 667d1aa..cbf4996 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1113,7 +1113,7 @@ void expr_print(struct expr *e, void (*fn)(void *, struct 
symbol *, const char *
fn(data, e->left.sym, e->left.sym->name);
else
fn(data, NULL, "");
-   fn(data, NULL, e->type == E_LEQ ? ">=" : ">");
+   fn(data, NULL, e->type == E_GEQ ? ">=" : ">");
fn(data, e->right.sym, e->right.sym->name);
break;
case E_UNEQUAL:
-- 
2.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: error: implicit declaration of function 'zero_bytemask'

2015-10-07 Thread Michal Sojka


On 7. října 2015 15:29:28 CEST, Chris Metcalf  wrote:
>On 10/07/2015 08:53 AM, Michal Sojka wrote:
>> Dear Chris,
>>
>> the following commit breaks my Linux build.
>>
>>  commit 990486c8af044f89bddfbde1d1cf9fde449bedbf
>>  Author: Chris Metcalf 
>>  Date:   Tue Oct 6 12:37:41 2015 -0400
>>   
>>  strscpy: zero any trailing garbage bytes in the destination
>>  
>>  It's possible that the destination can be shadowed in
>userspace
>>  (as, for example, the perf buffers are now).  So we should
>take
>>  care not to leak data that could be inspected by userspace.
>>
>> The error message is:
>>
>>  lib/string.c: In function 'strscpy':
>>  lib/string.c:209:4: error: implicit declaration of function
>'zero_bytemask' [-Werror=implicit-function-declaration]
>>  cc1: some warnings being treated as errors
>>
>> I compile the kernel for PowerPC (32 bit) with the attached config.
>
>Ah, it appears that big-endian powerpc does not provide
>zero_bytemask(), only little-endian.  I'll fix this in v3 of
>the patch series - thanks!

The patch is already in mainline so I guess a fixup patch would be more 
appropriate.

-- 
Odesláno z mého telefonu pomocí Kaiten Mail. Omluvte prosím mou stručnost.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


error: implicit declaration of function 'zero_bytemask'

2015-10-07 Thread Michal Sojka
Dear Chris,

the following commit breaks my Linux build.

commit 990486c8af044f89bddfbde1d1cf9fde449bedbf
Author: Chris Metcalf 
Date:   Tue Oct 6 12:37:41 2015 -0400
 
strscpy: zero any trailing garbage bytes in the destination

It's possible that the destination can be shadowed in userspace
(as, for example, the perf buffers are now).  So we should take
care not to leak data that could be inspected by userspace.

The error message is:

lib/string.c: In function 'strscpy':
lib/string.c:209:4: error: implicit declaration of function 'zero_bytemask' 
[-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors

I compile the kernel for PowerPC (32 bit) with the attached config.

Best regards,
-Michal




.config
Description: Binary data


Re: [PATCH v3] powerpc32: memset: only use dcbz once cache is enabled

2015-09-14 Thread Michal Sojka
On Mon, Sep 14 2015, Christophe Leroy wrote:
> memset() uses instruction dcbz to speed up clearing by not wasting time
> loading cache line with data that will be overwritten.
> Some platform like mpc52xx do no have cache active at startup and
> can therefore not use memset(). Allthough no part of the code
> explicitly uses memset(), GCC may makes calls to it.
>
> This patch modifies memset() such that at startup, memset()
> unconditionally jumps to simple_memset() which doesn't use
> the dcbz instruction.

I tested both v3 patches (memcpy and memset) and they work for me.

Thanks
-Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] powerpc32: memcpy: only use dcbz once cache is enabled

2015-09-07 Thread Michal Sojka
On Mon, Sep 07 2015, Christophe Leroy wrote:
> memcpy() uses instruction dcbz to speed up copy by not wasting time
> loading cache line with data that will be overwritten.
> Some platform like mpc52xx do no have cache active at startup and
> can therefore not use memcpy(). Allthough no part of the code
> explicitly uses memcpy(), GCC makes calls to it.
>
> This patch modifies memcpy() such that at startup, the 'dcbz'
> instruction is replaced by 'dcbt' which is harmless if cache is not
> enabled, and which helps a bit (allthough not as much as dcbz) if
> cache is already enabled.
>
> Once the initial MMU is setup, in machine_init() we patch memcpy()
> by replacing the temporary 'dcbt' by 'dcbz'
>
> Reported-by: Michal Sojka 
> Signed-off-by: Christophe Leroy 
> ---
> @Michal, can you please test it ?

Yes, it works.

Tested-by: Michal Sojka 

-Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Update help of CONFIG_MTD_OF_PARTS

2014-10-10 Thread Michal Sojka
The help text of CONFIG_MTD_OF_PARTS refers to additional documentation
in booting-without-of.txt but this documentation was moved to another
file in commit efcc2da3fd148c9acb7d7cf1d9800e0649f950fc (Stefan Roese:
Factor MTD physmap bindings out of booting-without-of). This updates the
help text to point to the right place.

Signed-off-by: Michal Sojka 
---
 drivers/mtd/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 94b8210..fa8371a 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -133,7 +133,7 @@ config MTD_OF_PARTS
help
  This provides a partition parsing function which derives
  the partition map from the children of the flash node,
- as described in Documentation/devicetree/booting-without-of.txt.
+ as described in Documentation/devicetree/bindings/mtd/mtd-physmap.txt.
 
 config MTD_AR7_PARTS
tristate "TI AR7 partitioning support"
-- 
2.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Linker error in function sys_bpf: undefined reference to `anon_inode_getfd'

2014-10-09 Thread Michal Sojka
Hi Alexei,

the following commit causes a failure of my linux build.

commit 99c55f7d47c0dc6fc64729f37bf435abf43f4c60
Author: Alexei Starovoitov 
Date:   Fri Sep 26 00:16:57 2014 -0700
 
bpf: introduce BPF syscall and maps

The error is:

kernel/built-in.o: In function `sys_bpf':
(.text+0x3b4fc): undefined reference to `anon_inode_getfd'

My .config (for powerpc arch) is attached.

Best regards,
-Michal




.config
Description: Binary data


Re: [PATCH v6 2/4] usb: gadget: Refactor request completion

2014-09-29 Thread Michal Sojka
On Mon, Sep 29 2014, Robert Baldyga wrote:
> Hi,
>
> On 09/24/2014 10:43 PM, Michal Sojka wrote:
>> Use the recently introduced usb_gadget_giveback_request() in favor of
>> direct invocation of the completion routine.
>> 
>> All places in drivers/usb/ matching "[-.]complete(" were replaced with a
>> call to usb_gadget_giveback_request(). This was compile-tested with all
>> ARM drivers enabled and runtime-tested for musb.
>> 
>> Signed-off-by: Michal Sojka 

[...]

>> diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c 
>> b/drivers/usb/gadget/udc/fsl_qe_udc.c
>> index 7324308..dd18ea3 100644
>> --- a/drivers/usb/gadget/udc/fsl_qe_udc.c
>> +++ b/drivers/usb/gadget/udc/fsl_qe_udc.c
>> @@ -118,10 +118,7 @@ static void done(struct qe_ep *ep, struct qe_req *req, 
>> int status)
>>  ep->stopped = 1;
>>  spin_unlock(&udc->lock);
>>  
>> -/* this complete() should a func implemented by gadget layer,
>> - * eg fsg->bulk_in_complete() */
>> -if (req->req.complete)
>> -req->req.complete(&ep->ep, &req->req);
>> +usb_gadget_giveback_request(&ep->ep, &req->req);
>
> It looks like you have omitted if() statement. Are you sure that request
> has set complete() callback?

Yes, see the rest of the thread. This was suggested by other reviewers.

-Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 3/4] usb: Rename usb-common.c

2014-09-24 Thread Michal Sojka
In the next commit, we will want the usb-common module to be composed of
two object files. Since Kbuild cannot "append" another object to an
existing one, we need to rename usb-common.c to something
else (common.c) and create usb-common.o by linking the wanted objects
together. Currently, usb-common.o comprises only common.o.

Signed-off-by: Michal Sojka 
---
 drivers/usb/common/Makefile |   4 +-
 drivers/usb/common/common.c | 144 
 drivers/usb/common/usb-common.c | 144 
 3 files changed, 147 insertions(+), 145 deletions(-)
 create mode 100644 drivers/usb/common/common.c
 delete mode 100644 drivers/usb/common/usb-common.c

diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 7526461..052c120 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -2,5 +2,7 @@
 # Makefile for the usb common parts.
 #
 
-obj-$(CONFIG_USB_COMMON) += usb-common.o
+obj-$(CONFIG_USB_COMMON) += usb-common.o
+usb-common-y += common.o
+
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
new file mode 100644
index 000..6dfd30a
--- /dev/null
+++ b/drivers/usb/common/common.c
@@ -0,0 +1,144 @@
+/*
+ * Provides code common for host and device side USB.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ * If either host side (ie. CONFIG_USB=y) or device side USB stack
+ * (ie. CONFIG_USB_GADGET=y) is compiled in the kernel, this module is
+ * compiled-in as well.  Otherwise, if either of the two stacks is
+ * compiled as module, this file is compiled as module as well.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+const char *usb_otg_state_string(enum usb_otg_state state)
+{
+   static const char *const names[] = {
+   [OTG_STATE_A_IDLE] = "a_idle",
+   [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
+   [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
+   [OTG_STATE_A_HOST] = "a_host",
+   [OTG_STATE_A_SUSPEND] = "a_suspend",
+   [OTG_STATE_A_PERIPHERAL] = "a_peripheral",
+   [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
+   [OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
+   [OTG_STATE_B_IDLE] = "b_idle",
+   [OTG_STATE_B_SRP_INIT] = "b_srp_init",
+   [OTG_STATE_B_PERIPHERAL] = "b_peripheral",
+   [OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
+   [OTG_STATE_B_HOST] = "b_host",
+   };
+
+   if (state < 0 || state >= ARRAY_SIZE(names))
+   return "UNDEFINED";
+
+   return names[state];
+}
+EXPORT_SYMBOL_GPL(usb_otg_state_string);
+
+static const char *const speed_names[] = {
+   [USB_SPEED_UNKNOWN] = "UNKNOWN",
+   [USB_SPEED_LOW] = "low-speed",
+   [USB_SPEED_FULL] = "full-speed",
+   [USB_SPEED_HIGH] = "high-speed",
+   [USB_SPEED_WIRELESS] = "wireless",
+   [USB_SPEED_SUPER] = "super-speed",
+};
+
+const char *usb_speed_string(enum usb_device_speed speed)
+{
+   if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
+   speed = USB_SPEED_UNKNOWN;
+   return speed_names[speed];
+}
+EXPORT_SYMBOL_GPL(usb_speed_string);
+
+const char *usb_state_string(enum usb_device_state state)
+{
+   static const char *const names[] = {
+   [USB_STATE_NOTATTACHED] = "not attached",
+   [USB_STATE_ATTACHED] = "attached",
+   [USB_STATE_POWERED] = "powered",
+   [USB_STATE_RECONNECTING] = "reconnecting",
+   [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
+   [USB_STATE_DEFAULT] = "default",
+   [USB_STATE_ADDRESS] = "addressed",
+   [USB_STATE_CONFIGURED] = "configured",
+   [USB_STATE_SUSPENDED] = "suspended",
+   };
+
+   if (state < 0 || state >= ARRAY_SIZE(names))
+   return "UNKNOWN";
+
+   return names[state];
+}
+EXPORT_SYMBOL_GPL(usb_state_string);
+
+#ifdef CONFIG_OF
+static const char *const usb_dr_modes[] = {
+   [USB_DR_MODE_UNKNOWN]   = "",
+   [USB_DR_MODE_HOST]  = "host",
+   [USB_DR_MODE_PERIPHERAL]= "peripheral",
+   [USB_DR_MODE_OTG]   = "otg",
+};
+
+/**
+ * of_usb_get_dr_mode - Get dual role mode for given device_node
+ * @np:Pointer to the given device_node
+ *
+ * The functio

[PATCH v6 4/4] usb: Add LED triggers for USB activity

2014-09-24 Thread Michal Sojka
With this patch, USB activity can be signaled by blinking a LED. There
are two triggers, one for activity on USB host and one for USB gadget.

Both triggers should work with all host/device controllers. Tested only
with musb.

Performace: I measured performance overheads on ARM Cortex-A8 (TI
AM335x) running on 600 MHz.

Duration of usb_led_activity():
- with no LED attached to the trigger:2 ± 1 µs
- with one GPIO LED attached to the trigger:  2 ± 1 µs or 8 ± 2 µs (two peaks 
in histogram)

Duration of functions calling usb_led_activity() (with this patch
applied and no LED attached to the trigger):
- __usb_hcd_giveback_urb():10 - 25 µs
- usb_gadget_giveback_request(): 2 - 6 µs

Signed-off-by: Michal Sojka 
---
 drivers/usb/Kconfig   | 10 +++
 drivers/usb/common/Makefile   |  1 +
 drivers/usb/common/led.c  | 57 +++
 drivers/usb/core/hcd.c|  2 ++
 drivers/usb/gadget/udc/udc-core.c |  4 +++
 include/linux/usb.h   | 12 +
 6 files changed, 86 insertions(+)
 create mode 100644 drivers/usb/common/led.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index cf1b19b..ae481c3 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -149,4 +149,14 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+config USB_LED_TRIG
+   bool "USB LED Triggers"
+   depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
+   help
+ This option adds LED triggers for USB host and/or gadget activity.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as activity indicators for USB host or
+ gadget.
+
 endif # USB_SUPPORT
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 052c120..ca2f8bd 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -4,5 +4,6 @@
 
 obj-$(CONFIG_USB_COMMON) += usb-common.o
 usb-common-y += common.o
+usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c
new file mode 100644
index 000..df23da0
--- /dev/null
+++ b/drivers/usb/common/led.c
@@ -0,0 +1,57 @@
+/*
+ * LED Triggers for USB Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+static unsigned long usb_blink_delay = BLINK_DELAY;
+
+DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
+DEFINE_LED_TRIGGER(ledtrig_usb_host);
+
+void usb_led_activity(enum usb_led_event ev)
+{
+   struct led_trigger *trig = NULL;
+
+   switch (ev) {
+   case USB_LED_EVENT_GADGET:
+   trig = ledtrig_usb_gadget;
+   break;
+   case USB_LED_EVENT_HOST:
+   trig = ledtrig_usb_host;
+   break;
+   }
+   /* led_trigger_blink_oneshot() handles trig == NULL gracefully */
+   led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
+}
+EXPORT_SYMBOL_GPL(usb_led_activity);
+
+
+static int __init ledtrig_usb_init(void)
+{
+   led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
+   led_trigger_register_simple("usb-host", &ledtrig_usb_host);
+   return 0;
+}
+
+static void __exit ledtrig_usb_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usb_gadget);
+   led_trigger_unregister_simple(ledtrig_usb_host);
+}
+
+module_init(ledtrig_usb_init);
+module_exit(ledtrig_usb_exit);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 487abcf..409cb95 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (likely(status == 0))
+   usb_led_activity(USB_LED_EVENT_HOST);
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f7b3151..931b9f1 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -116,6 +117,9 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 void usb_gadget_giveback_request(struct usb_ep *ep,
struct usb_request *req)
 {
+   if (likely(req->status == 0))
+   usb_led_activity(USB_LED_EVENT_GADGET);
+
req->complete(ep, req);
 }
 EXPORT_SYM

[PATCH v6 2/4] usb: gadget: Refactor request completion

2014-09-24 Thread Michal Sojka
Use the recently introduced usb_gadget_giveback_request() in favor of
direct invocation of the completion routine.

All places in drivers/usb/ matching "[-.]complete(" were replaced with a
call to usb_gadget_giveback_request(). This was compile-tested with all
ARM drivers enabled and runtime-tested for musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/chipidea/udc.c  |  6 +++---
 drivers/usb/dwc2/gadget.c   |  6 +++---
 drivers/usb/dwc3/gadget.c   |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c |  2 +-
 drivers/usb/gadget/udc/at91_udc.c   |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
 drivers/usb/gadget/udc/bcm63xx_udc.c|  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  | 10 +-
 drivers/usb/gadget/udc/fotg210-udc.c|  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |  6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |  6 ++
 drivers/usb/gadget/udc/fusb300_udc.c|  2 +-
 drivers/usb/gadget/udc/goku_udc.c   |  2 +-
 drivers/usb/gadget/udc/gr_udc.c |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|  2 +-
 drivers/usb/gadget/udc/m66592-udc.c |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|  8 ++--
 drivers/usb/gadget/udc/mv_udc_core.c|  8 ++--
 drivers/usb/gadget/udc/net2272.c|  2 +-
 drivers/usb/gadget/udc/net2280.c|  2 +-
 drivers/usb/gadget/udc/omap_udc.c   |  2 +-
 drivers/usb/gadget/udc/pch_udc.c|  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |  3 +--
 drivers/usb/gadget/udc/s3c2410_udc.c|  2 +-
 drivers/usb/musb/musb_gadget.c  |  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |  2 +-
 29 files changed, 41 insertions(+), 56 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index b8125aa..0444d3f 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -627,7 +627,7 @@ __acquires(hwep->lock)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -922,7 +922,7 @@ __acquires(hwep->lock)
if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) &&
hwreq->req.length)
hweptemp = hwep->ci->ep0in;
-   hwreq->req.complete(&hweptemp->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -1347,7 +1347,7 @@ static int ep_dequeue(struct usb_ep *ep, struct 
usb_request *req)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index ce6071d..ada5f30 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -987,8 +987,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg 
*hsotg,
hs_req = ep->req;
ep->req = NULL;
list_del_init(&hs_req->queue);
-   hs_req->req.complete(&ep->ep,
-&hs_req->req);
+   usb_gadget_giveback_request(&ep->ep,
+   
&hs_req->req);
}
 
/* If we have pending request, then start it */
@@ -1245,7 +1245,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg 
*hsotg,
 
if (hs_req->req.complete) {
spin_unlock(&hsotg->lock);
-   hs_req->req.complete(&hs_ep->ep, &hs_req->req);
+   usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req);
spin_lock(&hsotg->lock);
}
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 490a6ca..45f1dfc 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -268,7 +268,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct 
dwc3_request *req,
req->request.length, status);
 
spin_unlo

[PATCH v6 0/4] LED triggers for USB host and device

2014-09-24 Thread Michal Sojka
This adds LED triggers for USB host and device. First two patches
refactor UDC drivers as requested by Felipe Balbi, the next renames a
file and the last is the actual implementation of the LED triggers.

Changes from v5:
- Refactoring of USB gadget completion split into two patches (Filipe
  Balbi)
- Removed check for non-NULL req->completion (Filipe Balbi)

Changes from v4:
- Added performance numbers to the commit message of the last patch
  (greg k-h).
- Replaced BUG_ON with pr_err (Alan Stern, greg k-h).
- Used proper coding style for switch statement (greg k-h).
- Added comment about NULL argument (greg k-h).
- EXPORT_SYMBOL changed to EXPORT_SYMBOL_GPL (greg k-h).
- Both triggers are now registerd even if host or gagdet subsystem
  is not enabled (Bryan Wu, greg k-h).

Changes from v3:
- usb_gadget_giveback_request() moved outside of CONFIG_HAS_DMA
  conditioned block.
- Added kernel-doc for usb_gadget_giveback_request() (Felipe Balbi).
- Removed outdated comment (Alan Stern).
- req->complete == NULL is now a bug. Previously, this was ignored
  (Alan Stern).
- File rename moved to a separate commit (greg k-h).

Changes from v2:
- Host/gadget triggers merged to a single file in usb/common/ (Felipe
  Balbi).
- UDC drivers refactored so that LED trigger works for all of them.

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/.
- Improved Kconfig help.
- Linked with other modules rather than being standalone modules.

Michal Sojka (4):
  usb: gadget: Introduce usb_gadget_giveback_request()
  usb: gadget: Refactor request completion
  usb: Rename usb-common.c
  usb: Add LED triggers for USB activity

 drivers/usb/Kconfig |  10 +++
 drivers/usb/chipidea/udc.c  |   6 +-
 drivers/usb/common/Makefile |   5 +-
 drivers/usb/common/common.c | 144 
 drivers/usb/common/led.c|  57 +
 drivers/usb/common/usb-common.c | 144 
 drivers/usb/core/hcd.c  |   2 +
 drivers/usb/dwc2/gadget.c   |   6 +-
 drivers/usb/dwc3/gadget.c   |   2 +-
 drivers/usb/gadget/udc/amd5536udc.c |   2 +-
 drivers/usb/gadget/udc/at91_udc.c   |   2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |   4 +-
 drivers/usb/gadget/udc/bcm63xx_udc.c|   2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  |  10 +--
 drivers/usb/gadget/udc/fotg210-udc.c|   2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |   6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |   6 +-
 drivers/usb/gadget/udc/fusb300_udc.c|   2 +-
 drivers/usb/gadget/udc/goku_udc.c   |   2 +-
 drivers/usb/gadget/udc/gr_udc.c |   2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|   2 +-
 drivers/usb/gadget/udc/m66592-udc.c |   2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|   8 +-
 drivers/usb/gadget/udc/mv_udc_core.c|   8 +-
 drivers/usb/gadget/udc/net2272.c|   2 +-
 drivers/usb/gadget/udc/net2280.c|   2 +-
 drivers/usb/gadget/udc/omap_udc.c   |   2 +-
 drivers/usb/gadget/udc/pch_udc.c|   2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |   2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |   2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |   2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |   3 +-
 drivers/usb/gadget/udc/s3c2410_udc.c|   2 +-
 drivers/usb/gadget/udc/udc-core.c   |  20 +
 drivers/usb/musb/musb_gadget.c  |   2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |   2 +-
 include/linux/usb.h |  12 +++
 include/linux/usb/gadget.h  |   8 ++
 38 files changed, 298 insertions(+), 201 deletions(-)
 create mode 100644 drivers/usb/common/common.c
 create mode 100644 drivers/usb/common/led.c
 delete mode 100644 drivers/usb/common/usb-common.c

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 1/4] usb: gadget: Introduce usb_gadget_giveback_request()

2014-09-24 Thread Michal Sojka
All USB peripheral controller drivers call completion routines directly.
This patch adds usb_gadget_giveback_request() which will be used instead
of direct invocation in the next patch. The goal here is to have a place
where common functionality can be added.

Signed-off-by: Michal Sojka 
---
 drivers/usb/gadget/udc/udc-core.c | 16 
 include/linux/usb/gadget.h|  8 
 2 files changed, 24 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index b0d9817..f7b3151 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -106,6 +106,22 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 
 /* - */
 
+/**
+ * usb_gadget_giveback_request - give the request back to the gadget layer
+ * Context: in_interrupt()
+ *
+ * This is called by device controller drivers in order to return the
+ * completed request back to the gadget layer.
+ */
+void usb_gadget_giveback_request(struct usb_ep *ep,
+   struct usb_request *req)
+{
+   req->complete(ep, req);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
+
+/* - */
+
 static void usb_gadget_state_work(struct work_struct *work)
 {
struct usb_gadget   *gadget = work_to_gadget(work);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index c3a6185..f795e95 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -1013,6 +1013,14 @@ extern void usb_gadget_set_state(struct usb_gadget 
*gadget,
 
 /*-*/
 
+/* utility to give requests back to the gadget layer */
+
+extern void usb_gadget_giveback_request(struct usb_ep *ep,
+   struct usb_request *req);
+
+
+/*-*/
+
 /* utility wrapping a simple endpoint selection policy */
 
 extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5 1/3] usb: gadget: Refactor request completion

2014-09-23 Thread Michal Sojka
Dear Felipe,

On Wed, Sep 17 2014, Felipe Balbi wrote:
> On Wed, Sep 17, 2014 at 09:21:11AM +0200, Michal Sojka wrote:
>> All USB peripheral controller drivers called completion routines
>> directly. This patch moves the completion call from drivers to
>> usb_gadget_giveback_request(), in order to have a place where common
>> functionality can be added.
>> 
>> All places in drivers/usb/ matching "[-.]complete(" were replaced with a
>> call to usb_gadget_giveback_request(). This was compile-tested with all
>> ARM drivers enabled and runtime-tested for musb.
>> 
>> Signed-off-by: Michal Sojka 
>> ---
>>  drivers/usb/chipidea/udc.c  |  6 +++---
>>  drivers/usb/dwc2/gadget.c   |  6 +++---
>>  drivers/usb/dwc3/gadget.c   |  2 +-
>>  drivers/usb/gadget/udc/amd5536udc.c |  2 +-
>>  drivers/usb/gadget/udc/at91_udc.c   |  2 +-
>>  drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
>>  drivers/usb/gadget/udc/bcm63xx_udc.c|  2 +-
>>  drivers/usb/gadget/udc/dummy_hcd.c  | 10 +-
>>  drivers/usb/gadget/udc/fotg210-udc.c|  2 +-
>>  drivers/usb/gadget/udc/fsl_qe_udc.c |  6 +-
>>  drivers/usb/gadget/udc/fsl_udc_core.c   |  6 ++
>>  drivers/usb/gadget/udc/fusb300_udc.c|  2 +-
>>  drivers/usb/gadget/udc/goku_udc.c   |  2 +-
>>  drivers/usb/gadget/udc/gr_udc.c |  2 +-
>>  drivers/usb/gadget/udc/lpc32xx_udc.c|  2 +-
>>  drivers/usb/gadget/udc/m66592-udc.c |  2 +-
>>  drivers/usb/gadget/udc/mv_u3d_core.c|  8 ++--
>>  drivers/usb/gadget/udc/mv_udc_core.c|  8 ++--
>>  drivers/usb/gadget/udc/net2272.c|  2 +-
>>  drivers/usb/gadget/udc/net2280.c|  2 +-
>>  drivers/usb/gadget/udc/omap_udc.c   |  2 +-
>>  drivers/usb/gadget/udc/pch_udc.c|  2 +-
>>  drivers/usb/gadget/udc/pxa25x_udc.c |  2 +-
>>  drivers/usb/gadget/udc/pxa27x_udc.c |  2 +-
>>  drivers/usb/gadget/udc/r8a66597-udc.c   |  2 +-
>>  drivers/usb/gadget/udc/s3c-hsudc.c  |  3 +--
>>  drivers/usb/gadget/udc/s3c2410_udc.c|  2 +-
>>  drivers/usb/gadget/udc/udc-core.c   | 19 +++
>>  drivers/usb/musb/musb_gadget.c  |  2 +-
>>  drivers/usb/renesas_usbhs/mod_gadget.c  |  2 +-
>>  include/linux/usb/gadget.h  |  8 
>
> I would rather split this into several patches, btw. With the
> introduction of usb_gadget_giveback_request() being the first one in the
> series. It's easier to review that way.

This would be no problem.

>> diff --git a/drivers/usb/gadget/udc/udc-core.c 
>> b/drivers/usb/gadget/udc/udc-core.c
>> index b0d9817..29789f1 100644
>> --- a/drivers/usb/gadget/udc/udc-core.c
>> +++ b/drivers/usb/gadget/udc/udc-core.c
>> @@ -106,6 +106,25 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
>>  
>>  /* 
>> - */
>>  
>> +/**
>> + * usb_gadget_giveback_request - give the request back to the gadget layer
>> + * Context: in_interrupt()
>> + *
>> + * This is called by device controller drivers in order to return the
>> + * completed request back to the gadget layer.
>> + */
>> +void usb_gadget_giveback_request(struct usb_ep *ep,
>> +struct usb_request *req)
>> +{
>> +if (likely(req->complete))
>> +req->complete(ep, req);
>> +else
>> +pr_err("%s : req->complete must not be NULL\n", __func__);
>
> let it Oops. We require ->complete to be valid, if there's any gadget
> driver not setting ->complete, it deserves to oops so we can the
> error.

The Oops was there before, but I removed it because greg k-h didn't want
it. See http://marc.info/?l=linux-usb&m=140917381611947&w=2. Do you
still want the oops here?

-Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 3/3] usb: Add LED triggers for USB activity

2014-09-17 Thread Michal Sojka
With this patch, USB activity can be signaled by blinking a LED. There
are two triggers, one for activity on USB host and one for USB gadget.

Both triggers should work with all host/device controllers. Tested only
with musb.

Performace: I measured performance overheads on ARM Cortex-A8 (TI
AM335x) running on 600 MHz.

Duration of usb_led_activity():
- with no LED attached to the trigger:2 ± 1 µs
- with one GPIO LED attached to the trigger:  2 ± 1 µs or 8 ± 2 µs (two peaks 
in histogram)

Duration of functions calling usb_led_activity() (with this patch
applied and no LED attached to the trigger):
- __usb_hcd_giveback_urb():10 - 25 µs
- usb_gadget_giveback_request(): 2 - 6 µs

Signed-off-by: Michal Sojka 
---
 drivers/usb/Kconfig   | 10 +++
 drivers/usb/common/Makefile   |  1 +
 drivers/usb/common/led.c  | 57 +++
 drivers/usb/core/hcd.c|  2 ++
 drivers/usb/gadget/udc/udc-core.c |  4 +++
 include/linux/usb.h   | 12 +
 6 files changed, 86 insertions(+)
 create mode 100644 drivers/usb/common/led.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index e0cad441..9d9cc3b 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -147,4 +147,14 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+config USB_LED_TRIG
+   bool "USB LED Triggers"
+   depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
+   help
+ This option adds LED triggers for USB host and/or gadget activity.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as activity indicators for USB host or
+ gadget.
+
 endif # USB_SUPPORT
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 052c120..ca2f8bd 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -4,5 +4,6 @@
 
 obj-$(CONFIG_USB_COMMON) += usb-common.o
 usb-common-y += common.o
+usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c
new file mode 100644
index 000..df23da0
--- /dev/null
+++ b/drivers/usb/common/led.c
@@ -0,0 +1,57 @@
+/*
+ * LED Triggers for USB Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+static unsigned long usb_blink_delay = BLINK_DELAY;
+
+DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
+DEFINE_LED_TRIGGER(ledtrig_usb_host);
+
+void usb_led_activity(enum usb_led_event ev)
+{
+   struct led_trigger *trig = NULL;
+
+   switch (ev) {
+   case USB_LED_EVENT_GADGET:
+   trig = ledtrig_usb_gadget;
+   break;
+   case USB_LED_EVENT_HOST:
+   trig = ledtrig_usb_host;
+   break;
+   }
+   /* led_trigger_blink_oneshot() handles trig == NULL gracefully */
+   led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
+}
+EXPORT_SYMBOL_GPL(usb_led_activity);
+
+
+static int __init ledtrig_usb_init(void)
+{
+   led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
+   led_trigger_register_simple("usb-host", &ledtrig_usb_host);
+   return 0;
+}
+
+static void __exit ledtrig_usb_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usb_gadget);
+   led_trigger_unregister_simple(ledtrig_usb_host);
+}
+
+module_init(ledtrig_usb_init);
+module_exit(ledtrig_usb_exit);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 487abcf..409cb95 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (likely(status == 0))
+   usb_led_activity(USB_LED_EVENT_HOST);
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 29789f1..f272cf0 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -116,6 +117,9 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 void usb_gadget_giveback_request(struct usb_ep *ep,
struct usb_request *req)
 {
+   if (likely(req->status == 0))
+   usb_led_activity(USB_LED_EVENT_GADGET);
+
if (likely(req->complete))
 

[PATCH v5 1/3] usb: gadget: Refactor request completion

2014-09-17 Thread Michal Sojka
All USB peripheral controller drivers called completion routines
directly. This patch moves the completion call from drivers to
usb_gadget_giveback_request(), in order to have a place where common
functionality can be added.

All places in drivers/usb/ matching "[-.]complete(" were replaced with a
call to usb_gadget_giveback_request(). This was compile-tested with all
ARM drivers enabled and runtime-tested for musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/chipidea/udc.c  |  6 +++---
 drivers/usb/dwc2/gadget.c   |  6 +++---
 drivers/usb/dwc3/gadget.c   |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c |  2 +-
 drivers/usb/gadget/udc/at91_udc.c   |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
 drivers/usb/gadget/udc/bcm63xx_udc.c|  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  | 10 +-
 drivers/usb/gadget/udc/fotg210-udc.c|  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |  6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |  6 ++
 drivers/usb/gadget/udc/fusb300_udc.c|  2 +-
 drivers/usb/gadget/udc/goku_udc.c   |  2 +-
 drivers/usb/gadget/udc/gr_udc.c |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|  2 +-
 drivers/usb/gadget/udc/m66592-udc.c |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|  8 ++--
 drivers/usb/gadget/udc/mv_udc_core.c|  8 ++--
 drivers/usb/gadget/udc/net2272.c|  2 +-
 drivers/usb/gadget/udc/net2280.c|  2 +-
 drivers/usb/gadget/udc/omap_udc.c   |  2 +-
 drivers/usb/gadget/udc/pch_udc.c|  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |  3 +--
 drivers/usb/gadget/udc/s3c2410_udc.c|  2 +-
 drivers/usb/gadget/udc/udc-core.c   | 19 +++
 drivers/usb/musb/musb_gadget.c  |  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |  2 +-
 include/linux/usb/gadget.h  |  8 
 31 files changed, 68 insertions(+), 56 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index b8125aa..0444d3f 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -627,7 +627,7 @@ __acquires(hwep->lock)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -922,7 +922,7 @@ __acquires(hwep->lock)
if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) &&
hwreq->req.length)
hweptemp = hwep->ci->ep0in;
-   hwreq->req.complete(&hweptemp->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -1347,7 +1347,7 @@ static int ep_dequeue(struct usb_ep *ep, struct 
usb_request *req)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0ba9c33..5a524a6 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -987,8 +987,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg 
*hsotg,
hs_req = ep->req;
ep->req = NULL;
list_del_init(&hs_req->queue);
-   hs_req->req.complete(&ep->ep,
-&hs_req->req);
+   usb_gadget_giveback_request(&ep->ep,
+   
&hs_req->req);
}
 
/* If we have pending request, then start it */
@@ -1245,7 +1245,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg 
*hsotg,
 
if (hs_req->req.complete) {
spin_unlock(&hsotg->lock);
-   hs_req->req.complete(&hs_ep->ep, &hs_req->req);
+   usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req);
spin_lock(&hsotg->lock);
}
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 349cacc..b4b7a6b 100644
--

[PATCH v5 2/3] usb: Rename usb-common.c

2014-09-17 Thread Michal Sojka
In the next commit, we will want the usb-common module to be composed of
two object files. Since Kbuild cannot "append" another object to an
existing one, we need to rename usb-common.c to something
else (common.c) and create usb-common.o by linking the wanted objects
together. Currently, usb-common.o comprises only common.o.

Signed-off-by: Michal Sojka 
---
 drivers/usb/common/Makefile   | 4 +++-
 drivers/usb/common/{usb-common.c => common.c} | 0
 2 files changed, 3 insertions(+), 1 deletion(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)

diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 7526461..052c120 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -2,5 +2,7 @@
 # Makefile for the usb common parts.
 #
 
-obj-$(CONFIG_USB_COMMON) += usb-common.o
+obj-$(CONFIG_USB_COMMON) += usb-common.o
+usb-common-y += common.o
+
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/usb-common.c b/drivers/usb/common/common.c
similarity index 100%
rename from drivers/usb/common/usb-common.c
rename to drivers/usb/common/common.c
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 0/3] LED triggers for USB host and device

2014-09-17 Thread Michal Sojka
(this is resend of a patch series from about three weeks ago)

This adds LED triggers for USB host and device. First patch refactors
UDC drivers as requested by Felipe Balbi, second is a preparation for
the third, which adds the LED triggers.

Changes from v4:
- Added performance numbers to the commit message of the last patch
  (greg k-h).
- Replaced BUG_ON with pr_err (Alan Stern, greg k-h).
- Used proper coding style for switch statement (greg k-h).
- Added comment about NULL argument (greg k-h).
- EXPORT_SYMBOL changed to EXPORT_SYMBOL_GPL (greg k-h).
- Both triggers are now registerd even if host or gagdet subsystem
  is not enabled (Bryan Wu, greg k-h).

Changes from v3:
- usb_gadget_giveback_request() moved outside of CONFIG_HAS_DMA
  conditioned block.
- Added kernel-doc for usb_gadget_giveback_request() (Felipe Balbi).
- Removed outdated comment (Alan Stern).
- req->complete == NULL is now a bug. Previously, this was ignored
  (Alan Stern).
- File rename moved to a separate commit (greg k-h).

Changes from v2:
- Host/gadget triggers merged to a single file in usb/common/ (Felipe
  Balbi).
- UDC drivers refactored so that LED trigger works for all of them.

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/.
- Improved Kconfig help.
- Linked with other modules rather than being standalone modules.

Michal Sojka (3):
  usb: gadget: Refactor request completion
  usb: Rename usb-common.c
  usb: Add LED triggers for USB activity

 drivers/usb/Kconfig   | 10 +
 drivers/usb/chipidea/udc.c|  6 +--
 drivers/usb/common/Makefile   |  5 ++-
 drivers/usb/common/{usb-common.c => common.c} |  0
 drivers/usb/common/led.c  | 57 +++
 drivers/usb/core/hcd.c|  2 +
 drivers/usb/dwc2/gadget.c |  6 +--
 drivers/usb/dwc3/gadget.c |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c   |  2 +-
 drivers/usb/gadget/udc/at91_udc.c |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c   |  4 +-
 drivers/usb/gadget/udc/bcm63xx_udc.c  |  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c| 10 ++---
 drivers/usb/gadget/udc/fotg210-udc.c  |  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c   |  6 +--
 drivers/usb/gadget/udc/fsl_udc_core.c |  6 +--
 drivers/usb/gadget/udc/fusb300_udc.c  |  2 +-
 drivers/usb/gadget/udc/goku_udc.c |  2 +-
 drivers/usb/gadget/udc/gr_udc.c   |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c  |  2 +-
 drivers/usb/gadget/udc/m66592-udc.c   |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c  |  8 +---
 drivers/usb/gadget/udc/mv_udc_core.c  |  8 +---
 drivers/usb/gadget/udc/net2272.c  |  2 +-
 drivers/usb/gadget/udc/net2280.c  |  2 +-
 drivers/usb/gadget/udc/omap_udc.c |  2 +-
 drivers/usb/gadget/udc/pch_udc.c  |  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c   |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c   |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c|  3 +-
 drivers/usb/gadget/udc/s3c2410_udc.c  |  2 +-
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 drivers/usb/musb/musb_gadget.c|  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c|  2 +-
 include/linux/usb.h   | 12 ++
 include/linux/usb/gadget.h|  8 
 37 files changed, 157 insertions(+), 57 deletions(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)
 create mode 100644 drivers/usb/common/led.c

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 2/3] usb: Rename usb-common.c

2014-08-29 Thread Michal Sojka
In the next commit, we will want the usb-common module to be composed of
two object files. Since Kbuild cannot "append" another object to an
existing one, we need to rename usb-common.c to something
else (common.c) and create usb-common.o by linking the wanted objects
together. Currently, usb-common.o comprises only common.o.

Signed-off-by: Michal Sojka 
---
 drivers/usb/common/Makefile   | 4 +++-
 drivers/usb/common/{usb-common.c => common.c} | 0
 2 files changed, 3 insertions(+), 1 deletion(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)

diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 7526461..052c120 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -2,5 +2,7 @@
 # Makefile for the usb common parts.
 #
 
-obj-$(CONFIG_USB_COMMON) += usb-common.o
+obj-$(CONFIG_USB_COMMON) += usb-common.o
+usb-common-y += common.o
+
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/usb-common.c b/drivers/usb/common/common.c
similarity index 100%
rename from drivers/usb/common/usb-common.c
rename to drivers/usb/common/common.c
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 1/3] usb: gadget: Refactor request completion

2014-08-29 Thread Michal Sojka
All USB peripheral controller drivers called completion routines
directly. This patch moves the completion call from drivers to
usb_gadget_giveback_request(), in order to have a place where common
functionality can be added.

All places in drivers/usb/ matching "[-.]complete(" were replaced with a
call to usb_gadget_giveback_request(). This was compile-tested with all
ARM drivers enabled and runtime-tested for musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/chipidea/udc.c  |  6 +++---
 drivers/usb/dwc2/gadget.c   |  6 +++---
 drivers/usb/dwc3/gadget.c   |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c |  2 +-
 drivers/usb/gadget/udc/at91_udc.c   |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
 drivers/usb/gadget/udc/bcm63xx_udc.c|  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  | 10 +-
 drivers/usb/gadget/udc/fotg210-udc.c|  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |  6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |  6 ++
 drivers/usb/gadget/udc/fusb300_udc.c|  2 +-
 drivers/usb/gadget/udc/goku_udc.c   |  2 +-
 drivers/usb/gadget/udc/gr_udc.c |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|  2 +-
 drivers/usb/gadget/udc/m66592-udc.c |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|  8 ++--
 drivers/usb/gadget/udc/mv_udc_core.c|  8 ++--
 drivers/usb/gadget/udc/net2272.c|  2 +-
 drivers/usb/gadget/udc/net2280.c|  2 +-
 drivers/usb/gadget/udc/omap_udc.c   |  2 +-
 drivers/usb/gadget/udc/pch_udc.c|  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |  3 +--
 drivers/usb/gadget/udc/s3c2410_udc.c|  2 +-
 drivers/usb/gadget/udc/udc-core.c   | 19 +++
 drivers/usb/musb/musb_gadget.c  |  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |  2 +-
 include/linux/usb/gadget.h  |  8 
 31 files changed, 68 insertions(+), 56 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index b8125aa..0444d3f 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -627,7 +627,7 @@ __acquires(hwep->lock)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -922,7 +922,7 @@ __acquires(hwep->lock)
if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) &&
hwreq->req.length)
hweptemp = hwep->ci->ep0in;
-   hwreq->req.complete(&hweptemp->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -1347,7 +1347,7 @@ static int ep_dequeue(struct usb_ep *ep, struct 
usb_request *req)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0ba9c33..5a524a6 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -987,8 +987,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg 
*hsotg,
hs_req = ep->req;
ep->req = NULL;
list_del_init(&hs_req->queue);
-   hs_req->req.complete(&ep->ep,
-&hs_req->req);
+   usb_gadget_giveback_request(&ep->ep,
+   
&hs_req->req);
}
 
/* If we have pending request, then start it */
@@ -1245,7 +1245,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg 
*hsotg,
 
if (hs_req->req.complete) {
spin_unlock(&hsotg->lock);
-   hs_req->req.complete(&hs_ep->ep, &hs_req->req);
+   usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req);
spin_lock(&hsotg->lock);
}
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 349cacc..b4b7a6b 100644
--

[PATCH v5 0/3] LED triggers for USB host and device

2014-08-29 Thread Michal Sojka

This adds LED triggers for USB host and device. First patch refactors
UDC drivers as requested by Felipe Balbi, second is a preparation for
the third, which adds the LED triggers.

Changes from v4:
- Replaced BUG_ON with pr_err (Alan Stern, greg k-h).
- Used proper coding style for switch statement (greg k-h).
- Added comment about NULL argument (greg k-h).
- EXPORT_SYMBOL changed to EXPORT_SYMBOL_GPL (greg k-h).
- Both triggers are now registerd even if host or gagdet subsystem
  is not enabled (Bryan Wu, greg k-h).
- Added performance numbers to the commit message of the last patch
  (greg k-h).

Changes from v3:
- usb_gadget_giveback_request() moved outside of CONFIG_HAS_DMA
  conditioned block.
- Added kernel-doc for usb_gadget_giveback_request() (Felipe Balbi).
- Removed outdated comment (Alan Stern).
- req->complete == NULL is now a bug. Previously, this was ignored
  (Alan Stern).
- File rename moved to a separate commit (greg k-h).

Changes from v2:
- Host/gadget triggers merged to a single file in usb/common/ (Felipe
  Balbi).
- UDC drivers refactored so that LED trigger works for all of them.

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/.
- Improved Kconfig help.
- Linked with other modules rather than being standalone modules.

Michal Sojka (3):
  usb: gadget: Refactor request completion
  usb: Rename usb-common.c
  usb: Add LED triggers for USB activity

 drivers/usb/Kconfig   | 10 +
 drivers/usb/chipidea/udc.c|  6 +--
 drivers/usb/common/Makefile   |  5 ++-
 drivers/usb/common/{usb-common.c => common.c} |  0
 drivers/usb/common/led.c  | 57 +++
 drivers/usb/core/hcd.c|  2 +
 drivers/usb/dwc2/gadget.c |  6 +--
 drivers/usb/dwc3/gadget.c |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c   |  2 +-
 drivers/usb/gadget/udc/at91_udc.c |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c   |  4 +-
 drivers/usb/gadget/udc/bcm63xx_udc.c  |  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c| 10 ++---
 drivers/usb/gadget/udc/fotg210-udc.c  |  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c   |  6 +--
 drivers/usb/gadget/udc/fsl_udc_core.c |  6 +--
 drivers/usb/gadget/udc/fusb300_udc.c  |  2 +-
 drivers/usb/gadget/udc/goku_udc.c |  2 +-
 drivers/usb/gadget/udc/gr_udc.c   |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c  |  2 +-
 drivers/usb/gadget/udc/m66592-udc.c   |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c  |  8 +---
 drivers/usb/gadget/udc/mv_udc_core.c  |  8 +---
 drivers/usb/gadget/udc/net2272.c  |  2 +-
 drivers/usb/gadget/udc/net2280.c  |  2 +-
 drivers/usb/gadget/udc/omap_udc.c |  2 +-
 drivers/usb/gadget/udc/pch_udc.c  |  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c   |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c   |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c|  3 +-
 drivers/usb/gadget/udc/s3c2410_udc.c  |  2 +-
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 drivers/usb/musb/musb_gadget.c|  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c|  2 +-
 include/linux/usb.h   | 12 ++
 include/linux/usb/gadget.h|  8 
 37 files changed, 157 insertions(+), 57 deletions(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)
 create mode 100644 drivers/usb/common/led.c

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 3/3] usb: Add LED triggers for USB activity

2014-08-29 Thread Michal Sojka
With this patch, USB activity can be signaled by blinking a LED. There
are two triggers, one for activity on USB host and one for USB gadget.

Both triggers should work with all host/device controllers. Tested only
with musb.

Performace: I measured performance overheads on ARM Cortex-A8 (TI
AM335x) running on 600 MHz.

Duration of usb_led_activity():
- with no LED attached to the trigger:2 ± 1 µs
- with one GPIO LED attached to the trigger:  2 ± 1 µs or 8 ± 2 µs (two peaks 
in histogram)

Duration of functions calling usb_led_activity() (with this patch
applied and no LED attached to the trigger):
- __usb_hcd_giveback_urb():10 - 25 µs
- usb_gadget_giveback_request(): 2 - 6 µs

Signed-off-by: Michal Sojka 
---
 drivers/usb/Kconfig   | 10 +++
 drivers/usb/common/Makefile   |  1 +
 drivers/usb/common/led.c  | 57 +++
 drivers/usb/core/hcd.c|  2 ++
 drivers/usb/gadget/udc/udc-core.c |  4 +++
 include/linux/usb.h   | 12 +
 6 files changed, 86 insertions(+)
 create mode 100644 drivers/usb/common/led.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index e0cad441..9d9cc3b 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -147,4 +147,14 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+config USB_LED_TRIG
+   bool "USB LED Triggers"
+   depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
+   help
+ This option adds LED triggers for USB host and/or gadget activity.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as activity indicators for USB host or
+ gadget.
+
 endif # USB_SUPPORT
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 052c120..ca2f8bd 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -4,5 +4,6 @@
 
 obj-$(CONFIG_USB_COMMON) += usb-common.o
 usb-common-y += common.o
+usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c
new file mode 100644
index 000..df23da0
--- /dev/null
+++ b/drivers/usb/common/led.c
@@ -0,0 +1,57 @@
+/*
+ * LED Triggers for USB Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+static unsigned long usb_blink_delay = BLINK_DELAY;
+
+DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
+DEFINE_LED_TRIGGER(ledtrig_usb_host);
+
+void usb_led_activity(enum usb_led_event ev)
+{
+   struct led_trigger *trig = NULL;
+
+   switch (ev) {
+   case USB_LED_EVENT_GADGET:
+   trig = ledtrig_usb_gadget;
+   break;
+   case USB_LED_EVENT_HOST:
+   trig = ledtrig_usb_host;
+   break;
+   }
+   /* led_trigger_blink_oneshot() handles trig == NULL gracefully */
+   led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
+}
+EXPORT_SYMBOL_GPL(usb_led_activity);
+
+
+static int __init ledtrig_usb_init(void)
+{
+   led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
+   led_trigger_register_simple("usb-host", &ledtrig_usb_host);
+   return 0;
+}
+
+static void __exit ledtrig_usb_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usb_gadget);
+   led_trigger_unregister_simple(ledtrig_usb_host);
+}
+
+module_init(ledtrig_usb_init);
+module_exit(ledtrig_usb_exit);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 487abcf..409cb95 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (likely(status == 0))
+   usb_led_activity(USB_LED_EVENT_HOST);
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 29789f1..f272cf0 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -116,6 +117,9 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 void usb_gadget_giveback_request(struct usb_ep *ep,
struct usb_request *req)
 {
+   if (likely(req->status == 0))
+   usb_led_activity(USB_LED_EVENT_GADGET);
+
if (likely(req->complete))
 

Re: [PATCH v4 3/3] usb: Add LED triggers for USB activity

2014-08-29 Thread Michal Sojka
On Wed, Aug 27 2014, Greg Kroah-Hartman wrote:
> On Wed, Aug 27, 2014 at 10:58:00PM +0200, Michal Sojka wrote:
>> With this patch, USB activity can be signaled by blinking a LED. There
>> are two triggers, one for activity on USB host and one for USB gadget.
>> 
>> Both trigger should work with all host/device controllers. Tested only
>> with musb.
>> 
>> Signed-off-by: Michal Sojka 
>> ---
>>  drivers/usb/Kconfig   | 11 
>>  drivers/usb/common/Makefile   |  1 +
>>  drivers/usb/common/led.c  | 56 
>> +++
>>  drivers/usb/core/hcd.c|  2 ++
>>  drivers/usb/gadget/udc/udc-core.c |  4 +++
>>  include/linux/usb.h   | 12 +
>>  6 files changed, 86 insertions(+)
>>  create mode 100644 drivers/usb/common/led.c
>> 
>> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
>> index e0cad441..fc90cda 100644
>> --- a/drivers/usb/Kconfig
>> +++ b/drivers/usb/Kconfig
>> @@ -147,4 +147,15 @@ source "drivers/usb/phy/Kconfig"
>>  
>>  source "drivers/usb/gadget/Kconfig"
>>  
>> +config USB_LED_TRIG
>> +bool "USB LED Triggers"
>> +depends on LEDS_CLASS && USB_COMMON
>> +select LEDS_TRIGGERS
>
> I hate select lines, can't we just depend on LEDS_TRIGGERS as well as
> LEDS_CLASS?
>
>
>> +help
>> +  This option adds LED triggers for USB host and/or gadget activity.
>> +
>> +  Say Y here if you are working on a system with led-class supported
>> +  LEDs and you want to use them as activity indicators for USB host or
>> +  gadget.
>> +
>>  endif # USB_SUPPORT
>> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
>> index 052c120..ca2f8bd 100644
>> --- a/drivers/usb/common/Makefile
>> +++ b/drivers/usb/common/Makefile
>> @@ -4,5 +4,6 @@
>>  
>>  obj-$(CONFIG_USB_COMMON)  += usb-common.o
>>  usb-common-y  += common.o
>> +usb-common-$(CONFIG_USB_LED_TRIG) += led.o
>>  
>>  obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
>> diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c
>> new file mode 100644
>> index 000..af3ce2c
>> --- /dev/null
>> +++ b/drivers/usb/common/led.c
>> @@ -0,0 +1,56 @@
>> +/*
>> + * LED Triggers for USB Activity
>> + *
>> + * Copyright 2014 Michal Sojka 
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define BLINK_DELAY 30
>> +
>> +static unsigned long usb_blink_delay = BLINK_DELAY;
>> +
>> +DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
>> +DEFINE_LED_TRIGGER(ledtrig_usb_host);
>> +
>> +void usb_led_activity(enum usb_led_event ev)
>> +{
>> +struct led_trigger *trig = NULL;
>> +
>> +switch (ev) {
>> +case USB_LED_EVENT_GADGET: trig = ledtrig_usb_gadget; break;
>> +case USB_LED_EVENT_HOST:   trig = ledtrig_usb_host;break;
>> +}
>
> Very odd formatting, please use the correct one and don't try to put
> case expressions all on one line.
>
>> +led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
>
> What happens if trig is NULL?

This will work correctly - I added a comment about it in v5.

>> +}
>> +EXPORT_SYMBOL(usb_led_activity);
>
> EXPORT_SYMBOL_GPL() please.
>
>> +static int __init ledtrig_usb_init(void)
>> +{
>> +#ifdef CONFIG_USB_GADGET
>> +led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
>> +#endif
>> +#ifdef CONFIG_USB
>> +led_trigger_register_simple("usb-host", &ledtrig_usb_host);
>> +#endif
>
> Why not just always register both?

I didn't want to offer users a trigger that doesn't do anything useful
on their system. Since you are the second person suggesting registering
both, I did just that in v5.

>> +return 0;
>> +}
>> +
>> +static void __exit ledtrig_usb_exit(void)
>> +{
>> +led_trigger_unregister_simple(ledtrig_usb_gadget);
>> +led_trigger_unregister_simple(ledtrig_usb_host);
>
> So you can unregister things that you never registered with no issues?

Yes, but it doesn't matter anymore in v5.

>> +}
>

[PATCH v4 0/3] LED triggers for USB host and device

2014-08-27 Thread Michal Sojka
This adds LED triggers for USB host and device. First patch refactors
UDC drivers as requested by Felipe Balbi, second is a preparation for
the third, which adds the LED triggers.

Changes from v3:
- usb_gadget_giveback_request() moved outside of CONFIG_HAS_DMA
  conditioned block.
- Added kernel-doc for usb_gadget_giveback_request() (Felipe Balbi).
- Removed outdated comment (Alan Stern).
- req->complete == NULL is now a bug. Previously, this was ignored
  (Alan Stern).
- File rename moved to a separate commit (greg k-h).

Changes from v2:
- Host/gadget triggers merged to a single file in usb/common/ (Felipe
  Balbi).
- UDC drivers refactored so that LED trigger works for all of them.

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/.
- Improved Kconfig help.
- Linked with other modules rather than being standalone modules.

Michal Sojka (2):
  usb: gadget: Refactor request completion
  usb: Add LED triggers for USB activity

 drivers/usb/Kconfig |  11 +++
 drivers/usb/chipidea/udc.c  |   6 +-
 drivers/usb/common/Makefile |   5 +-
 drivers/usb/common/common.c | 144 
 drivers/usb/common/led.c|  59 +
 drivers/usb/common/usb-common.c | 144 
 drivers/usb/core/hcd.c  |   2 +
 drivers/usb/dwc2/gadget.c   |   6 +-
 drivers/usb/dwc3/gadget.c   |   2 +-
 drivers/usb/gadget/udc/amd5536udc.c |   2 +-
 drivers/usb/gadget/udc/at91_udc.c   |   2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |   4 +-
 drivers/usb/gadget/udc/bcm63xx_udc.c|   2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  |  10 +--
 drivers/usb/gadget/udc/fotg210-udc.c|   2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |   6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |   6 +-
 drivers/usb/gadget/udc/fusb300_udc.c|   2 +-
 drivers/usb/gadget/udc/goku_udc.c   |   2 +-
 drivers/usb/gadget/udc/gr_udc.c |   2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|   2 +-
 drivers/usb/gadget/udc/m66592-udc.c |   2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|   8 +-
 drivers/usb/gadget/udc/mv_udc_core.c|   8 +-
 drivers/usb/gadget/udc/net2272.c|   2 +-
 drivers/usb/gadget/udc/net2280.c|   2 +-
 drivers/usb/gadget/udc/omap_udc.c   |   2 +-
 drivers/usb/gadget/udc/pch_udc.c|   2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |   2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |   2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |   2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |   3 +-
 drivers/usb/gadget/udc/s3c2410_udc.c|   2 +-
 drivers/usb/gadget/udc/udc-core.c   |  13 +++
 drivers/usb/musb/musb_gadget.c  |   2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |   2 +-
 include/linux/usb.h |  12 +++
 include/linux/usb/gadget.h  |   8 ++
 38 files changed, 294 insertions(+), 201 deletions(-)
 create mode 100644 drivers/usb/common/common.c
 create mode 100644 drivers/usb/common/led.c
 delete mode 100644 drivers/usb/common/usb-common.c

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 3/3] usb: Add LED triggers for USB activity

2014-08-27 Thread Michal Sojka
With this patch, USB activity can be signaled by blinking a LED. There
are two triggers, one for activity on USB host and one for USB gadget.

Both trigger should work with all host/device controllers. Tested only
with musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/Kconfig   | 11 
 drivers/usb/common/Makefile   |  1 +
 drivers/usb/common/led.c  | 56 +++
 drivers/usb/core/hcd.c|  2 ++
 drivers/usb/gadget/udc/udc-core.c |  4 +++
 include/linux/usb.h   | 12 +
 6 files changed, 86 insertions(+)
 create mode 100644 drivers/usb/common/led.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index e0cad441..fc90cda 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -147,4 +147,15 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+config USB_LED_TRIG
+   bool "USB LED Triggers"
+   depends on LEDS_CLASS && USB_COMMON
+   select LEDS_TRIGGERS
+   help
+ This option adds LED triggers for USB host and/or gadget activity.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as activity indicators for USB host or
+ gadget.
+
 endif # USB_SUPPORT
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 052c120..ca2f8bd 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -4,5 +4,6 @@
 
 obj-$(CONFIG_USB_COMMON) += usb-common.o
 usb-common-y += common.o
+usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c
new file mode 100644
index 000..af3ce2c
--- /dev/null
+++ b/drivers/usb/common/led.c
@@ -0,0 +1,56 @@
+/*
+ * LED Triggers for USB Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+static unsigned long usb_blink_delay = BLINK_DELAY;
+
+DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
+DEFINE_LED_TRIGGER(ledtrig_usb_host);
+
+void usb_led_activity(enum usb_led_event ev)
+{
+   struct led_trigger *trig = NULL;
+
+   switch (ev) {
+   case USB_LED_EVENT_GADGET: trig = ledtrig_usb_gadget; break;
+   case USB_LED_EVENT_HOST:   trig = ledtrig_usb_host;break;
+   }
+   led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
+}
+EXPORT_SYMBOL(usb_led_activity);
+
+
+static int __init ledtrig_usb_init(void)
+{
+#ifdef CONFIG_USB_GADGET
+   led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
+#endif
+#ifdef CONFIG_USB
+   led_trigger_register_simple("usb-host", &ledtrig_usb_host);
+#endif
+   return 0;
+}
+
+static void __exit ledtrig_usb_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usb_gadget);
+   led_trigger_unregister_simple(ledtrig_usb_host);
+}
+
+module_init(ledtrig_usb_init);
+module_exit(ledtrig_usb_exit);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 487abcf..409cb95 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (likely(status == 0))
+   usb_led_activity(USB_LED_EVENT_HOST);
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index c1df19b..9fc4a36 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -116,6 +117,9 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 void usb_gadget_giveback_request(struct usb_ep *ep,
struct usb_request *req)
 {
+   if (likely(req->status == 0))
+   usb_led_activity(USB_LED_EVENT_GADGET);
+
BUG_ON(req->complete == NULL);
req->complete(ep, req);
 }
diff --git a/include/linux/usb.h b/include/linux/usb.h
index d2465bc..447a7e2 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1862,6 +1862,18 @@ extern void usb_unregister_notify(struct notifier_block 
*nb);
 /* debugfs stuff */
 extern struct dentry *usb_debug_root;
 
+/* LED triggers */
+enum usb_led_event {
+   USB_LED_EVENT_HOST = 0,
+   USB_LED_EVENT_GADGET = 1,
+};
+
+#ifdef CONFIG_USB_LED_TRIG
+extern void usb_led_activity(enum usb_led_event ev);
+#else
+static inline 

[PATCH v4 2/3] usb: Rename usb-common.c

2014-08-27 Thread Michal Sojka
In the next commit, we will want the usb-common module to be composed of
two object files. Since Kbuild cannot "append" another object to an
existing one, we need to rename usb-common.c to something
else (common.c) and create usb-common.o by linking the wanted objects
together. Currently, usb-common.o comprises only common.o.

Signed-off-by: Michal Sojka 
---
 drivers/usb/common/Makefile   | 4 +++-
 drivers/usb/common/{usb-common.c => common.c} | 0
 2 files changed, 3 insertions(+), 1 deletion(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)

diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 7526461..052c120 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -2,5 +2,7 @@
 # Makefile for the usb common parts.
 #
 
-obj-$(CONFIG_USB_COMMON) += usb-common.o
+obj-$(CONFIG_USB_COMMON) += usb-common.o
+usb-common-y += common.o
+
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/usb-common.c b/drivers/usb/common/common.c
similarity index 100%
rename from drivers/usb/common/usb-common.c
rename to drivers/usb/common/common.c
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 1/3] usb: gadget: Refactor request completion

2014-08-27 Thread Michal Sojka
All USB peripheral controller drivers called completion routines
directly. This patch moves the completion call from drivers to
usb_gadget_giveback_request(), in order to have a place where common
functionality can be added.

All places in drivers/usb/ matching "[-.]complete(" were replaced with a
call to usb_gadget_giveback_request(). This was compile-tested with all
ARM drivers enabled and runtime-tested for musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/chipidea/udc.c  |  6 +++---
 drivers/usb/dwc2/gadget.c   |  6 +++---
 drivers/usb/dwc3/gadget.c   |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c |  2 +-
 drivers/usb/gadget/udc/at91_udc.c   |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
 drivers/usb/gadget/udc/bcm63xx_udc.c|  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  | 10 +-
 drivers/usb/gadget/udc/fotg210-udc.c|  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |  6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |  6 ++
 drivers/usb/gadget/udc/fusb300_udc.c|  2 +-
 drivers/usb/gadget/udc/goku_udc.c   |  2 +-
 drivers/usb/gadget/udc/gr_udc.c |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|  2 +-
 drivers/usb/gadget/udc/m66592-udc.c |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|  8 ++--
 drivers/usb/gadget/udc/mv_udc_core.c|  8 ++--
 drivers/usb/gadget/udc/net2272.c|  2 +-
 drivers/usb/gadget/udc/net2280.c|  2 +-
 drivers/usb/gadget/udc/omap_udc.c   |  2 +-
 drivers/usb/gadget/udc/pch_udc.c|  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |  3 +--
 drivers/usb/gadget/udc/s3c2410_udc.c|  2 +-
 drivers/usb/gadget/udc/udc-core.c   | 17 +
 drivers/usb/musb/musb_gadget.c  |  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |  2 +-
 include/linux/usb/gadget.h  |  8 
 31 files changed, 66 insertions(+), 56 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index b8125aa..0444d3f 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -627,7 +627,7 @@ __acquires(hwep->lock)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -922,7 +922,7 @@ __acquires(hwep->lock)
if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) &&
hwreq->req.length)
hweptemp = hwep->ci->ep0in;
-   hwreq->req.complete(&hweptemp->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -1347,7 +1347,7 @@ static int ep_dequeue(struct usb_ep *ep, struct 
usb_request *req)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0ba9c33..5a524a6 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -987,8 +987,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg 
*hsotg,
hs_req = ep->req;
ep->req = NULL;
list_del_init(&hs_req->queue);
-   hs_req->req.complete(&ep->ep,
-&hs_req->req);
+   usb_gadget_giveback_request(&ep->ep,
+   
&hs_req->req);
}
 
/* If we have pending request, then start it */
@@ -1245,7 +1245,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg 
*hsotg,
 
if (hs_req->req.complete) {
spin_unlock(&hsotg->lock);
-   hs_req->req.complete(&hs_ep->ep, &hs_req->req);
+   usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req);
spin_lock(&hsotg->lock);
}
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 349cacc..b4b7a6b 100644
--

Re: [PATCH v3 1/2] usb: gadget: Refactor request completion

2014-08-27 Thread Michal Sojka
On Wed, Aug 27 2014, Michal Sojka wrote:
> All USB peripheral controller drivers called completion routines
> directly. This patch moves the completion call from drivers to
> usb_gadget_giveback_request(), in order to have a place where common
> functionality can be added.
>
> All places in drivers/usb/ matching "[-.]complete(" were replaced with a
> call to usb_gadget_giveback_request(). This was compile-tested with all
> ARM drivers enabled and runtime-tested for musb.

[...]

> diff --git a/drivers/usb/gadget/udc/udc-core.c 
> b/drivers/usb/gadget/udc/udc-core.c
> index b0d9817..2eb0ae4 100644
> --- a/drivers/usb/gadget/udc/udc-core.c
> +++ b/drivers/usb/gadget/udc/udc-core.c
> @@ -102,6 +102,15 @@ void usb_gadget_unmap_request(struct usb_gadget *gadget,
>  }
>  EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
>  
> +void usb_gadget_giveback_request(struct usb_ep *ep,
> + struct usb_request *req)
> +{
> + /* complete() is from gadget layer,
> +  * eg fsg->bulk_in_complete() */
> + if (req->complete)
> + req->complete(ep, req);
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
>  #endif   /* CONFIG_HAS_DMA */

#endif should be before usb_gadget_giveback_request(). I'll fix this in
v4.

-Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/2] LED triggers for USB host and device

2014-08-27 Thread Michal Sojka
This adds LED triggers for USB host and device. First patch refactors
UDC drivers as requested by Felipe Balbi, second patch adds the LED
triggers.

Changes from v2:
- host/gadget triggers merged to a single file in usb/common/
- udc drivers refactored so that LED trigger works for all of them

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/
- Improved Kconfig help
- Linked with other modules rather than being standalone modules

Michal Sojka (2):
  usb: gadget: Refactor request completion
  usb: Add LED triggers for USB activity

 drivers/usb/Kconfig |  11 +++
 drivers/usb/chipidea/udc.c  |   6 +-
 drivers/usb/common/Makefile |   5 +-
 drivers/usb/common/common.c | 144 
 drivers/usb/common/led.c|  59 +
 drivers/usb/common/usb-common.c | 144 
 drivers/usb/core/hcd.c  |   2 +
 drivers/usb/dwc2/gadget.c   |   6 +-
 drivers/usb/dwc3/gadget.c   |   2 +-
 drivers/usb/gadget/udc/amd5536udc.c |   2 +-
 drivers/usb/gadget/udc/at91_udc.c   |   2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |   4 +-
 drivers/usb/gadget/udc/bcm63xx_udc.c|   2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  |  10 +--
 drivers/usb/gadget/udc/fotg210-udc.c|   2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |   6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |   6 +-
 drivers/usb/gadget/udc/fusb300_udc.c|   2 +-
 drivers/usb/gadget/udc/goku_udc.c   |   2 +-
 drivers/usb/gadget/udc/gr_udc.c |   2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|   2 +-
 drivers/usb/gadget/udc/m66592-udc.c |   2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|   8 +-
 drivers/usb/gadget/udc/mv_udc_core.c|   8 +-
 drivers/usb/gadget/udc/net2272.c|   2 +-
 drivers/usb/gadget/udc/net2280.c|   2 +-
 drivers/usb/gadget/udc/omap_udc.c   |   2 +-
 drivers/usb/gadget/udc/pch_udc.c|   2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |   2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |   2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |   2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |   3 +-
 drivers/usb/gadget/udc/s3c2410_udc.c|   2 +-
 drivers/usb/gadget/udc/udc-core.c   |  13 +++
 drivers/usb/musb/musb_gadget.c  |   2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |   2 +-
 include/linux/usb.h |  12 +++
 include/linux/usb/gadget.h  |   8 ++
 38 files changed, 294 insertions(+), 201 deletions(-)
 create mode 100644 drivers/usb/common/common.c
 create mode 100644 drivers/usb/common/led.c
 delete mode 100644 drivers/usb/common/usb-common.c

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/2] usb: Add LED triggers for USB activity

2014-08-27 Thread Michal Sojka
With this patch, USB activity can be signaled by blinking a LED. There
are two triggers, one for activity on USB host and one for USB gadget.

Both trigger should work with all host/device controllers. Tested only
with musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/Kconfig   | 11 ++
 drivers/usb/common/Makefile   |  5 ++-
 drivers/usb/common/{usb-common.c => common.c} |  0
 drivers/usb/common/led.c  | 56 +++
 drivers/usb/core/hcd.c|  2 +
 drivers/usb/gadget/udc/udc-core.c |  4 ++
 include/linux/usb.h   | 12 ++
 7 files changed, 89 insertions(+), 1 deletion(-)
 rename drivers/usb/common/{usb-common.c => common.c} (100%)
 create mode 100644 drivers/usb/common/led.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index e0cad441..fc90cda 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -147,4 +147,15 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+config USB_LED_TRIG
+   bool "USB LED Triggers"
+   depends on LEDS_CLASS && USB_COMMON
+   select LEDS_TRIGGERS
+   help
+ This option adds LED triggers for USB host and/or gadget activity.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as activity indicators for USB host or
+ gadget.
+
 endif # USB_SUPPORT
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 7526461..ca2f8bd 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -2,5 +2,8 @@
 # Makefile for the usb common parts.
 #
 
-obj-$(CONFIG_USB_COMMON) += usb-common.o
+obj-$(CONFIG_USB_COMMON) += usb-common.o
+usb-common-y += common.o
+usb-common-$(CONFIG_USB_LED_TRIG) += led.o
+
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
diff --git a/drivers/usb/common/usb-common.c b/drivers/usb/common/common.c
similarity index 100%
rename from drivers/usb/common/usb-common.c
rename to drivers/usb/common/common.c
diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c
new file mode 100644
index 000..af3ce2c
--- /dev/null
+++ b/drivers/usb/common/led.c
@@ -0,0 +1,56 @@
+/*
+ * LED Triggers for USB Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+static unsigned long usb_blink_delay = BLINK_DELAY;
+
+DEFINE_LED_TRIGGER(ledtrig_usb_gadget);
+DEFINE_LED_TRIGGER(ledtrig_usb_host);
+
+void usb_led_activity(enum usb_led_event ev)
+{
+   struct led_trigger *trig = NULL;
+
+   switch (ev) {
+   case USB_LED_EVENT_GADGET: trig = ledtrig_usb_gadget; break;
+   case USB_LED_EVENT_HOST:   trig = ledtrig_usb_host;break;
+   }
+   led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0);
+}
+EXPORT_SYMBOL(usb_led_activity);
+
+
+static int __init ledtrig_usb_init(void)
+{
+#ifdef CONFIG_USB_GADGET
+   led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget);
+#endif
+#ifdef CONFIG_USB
+   led_trigger_register_simple("usb-host", &ledtrig_usb_host);
+#endif
+   return 0;
+}
+
+static void __exit ledtrig_usb_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usb_gadget);
+   led_trigger_unregister_simple(ledtrig_usb_host);
+}
+
+module_init(ledtrig_usb_init);
+module_exit(ledtrig_usb_exit);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 487abcf..409cb95 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (likely(status == 0))
+   usb_led_activity(USB_LED_EVENT_HOST);
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 2eb0ae4..2ce42f9 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -105,6 +106,9 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 void usb_gadget_giveback_request(struct usb_ep *ep,
struct usb_request *req)
 {
+   if (likely(req->status == 0))
+   usb_led_activity(USB_LED_EVENT_GADGET);
+
/* complete() is from gadget layer,
 * eg fsg->bulk_in_complete() */
if (req->complete)
diff --git a/incl

[PATCH v3 1/2] usb: gadget: Refactor request completion

2014-08-27 Thread Michal Sojka
All USB peripheral controller drivers called completion routines
directly. This patch moves the completion call from drivers to
usb_gadget_giveback_request(), in order to have a place where common
functionality can be added.

All places in drivers/usb/ matching "[-.]complete(" were replaced with a
call to usb_gadget_giveback_request(). This was compile-tested with all
ARM drivers enabled and runtime-tested for musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/chipidea/udc.c  |  6 +++---
 drivers/usb/dwc2/gadget.c   |  6 +++---
 drivers/usb/dwc3/gadget.c   |  2 +-
 drivers/usb/gadget/udc/amd5536udc.c |  2 +-
 drivers/usb/gadget/udc/at91_udc.c   |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
 drivers/usb/gadget/udc/bcm63xx_udc.c|  2 +-
 drivers/usb/gadget/udc/dummy_hcd.c  | 10 +-
 drivers/usb/gadget/udc/fotg210-udc.c|  2 +-
 drivers/usb/gadget/udc/fsl_qe_udc.c |  6 +-
 drivers/usb/gadget/udc/fsl_udc_core.c   |  6 ++
 drivers/usb/gadget/udc/fusb300_udc.c|  2 +-
 drivers/usb/gadget/udc/goku_udc.c   |  2 +-
 drivers/usb/gadget/udc/gr_udc.c |  2 +-
 drivers/usb/gadget/udc/lpc32xx_udc.c|  2 +-
 drivers/usb/gadget/udc/m66592-udc.c |  2 +-
 drivers/usb/gadget/udc/mv_u3d_core.c|  8 ++--
 drivers/usb/gadget/udc/mv_udc_core.c|  8 ++--
 drivers/usb/gadget/udc/net2272.c|  2 +-
 drivers/usb/gadget/udc/net2280.c|  2 +-
 drivers/usb/gadget/udc/omap_udc.c   |  2 +-
 drivers/usb/gadget/udc/pch_udc.c|  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.c |  2 +-
 drivers/usb/gadget/udc/pxa27x_udc.c |  2 +-
 drivers/usb/gadget/udc/r8a66597-udc.c   |  2 +-
 drivers/usb/gadget/udc/s3c-hsudc.c  |  3 +--
 drivers/usb/gadget/udc/s3c2410_udc.c|  2 +-
 drivers/usb/gadget/udc/udc-core.c   |  9 +
 drivers/usb/musb/musb_gadget.c  |  2 +-
 drivers/usb/renesas_usbhs/mod_gadget.c  |  2 +-
 include/linux/usb/gadget.h  |  8 
 31 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index b8125aa..0444d3f 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -627,7 +627,7 @@ __acquires(hwep->lock)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -922,7 +922,7 @@ __acquires(hwep->lock)
if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) &&
hwreq->req.length)
hweptemp = hwep->ci->ep0in;
-   hwreq->req.complete(&hweptemp->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req);
spin_lock(hwep->lock);
}
}
@@ -1347,7 +1347,7 @@ static int ep_dequeue(struct usb_ep *ep, struct 
usb_request *req)
 
if (hwreq->req.complete != NULL) {
spin_unlock(hwep->lock);
-   hwreq->req.complete(&hwep->ep, &hwreq->req);
+   usb_gadget_giveback_request(&hwep->ep, &hwreq->req);
spin_lock(hwep->lock);
}
 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0ba9c33..5a524a6 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -987,8 +987,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg 
*hsotg,
hs_req = ep->req;
ep->req = NULL;
list_del_init(&hs_req->queue);
-   hs_req->req.complete(&ep->ep,
-&hs_req->req);
+   usb_gadget_giveback_request(&ep->ep,
+   
&hs_req->req);
}
 
/* If we have pending request, then start it */
@@ -1245,7 +1245,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg 
*hsotg,
 
if (hs_req->req.complete) {
spin_unlock(&hsotg->lock);
-   hs_req->req.complete(&hs_ep->ep, &hs_req->req);
+   usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req);
spin_lock(&hsotg->lock);
}
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 349cacc..b4b7a6b 100644
--- a/drivers/us

Re: [PATCH v2 2/3] usb: Add LED trigger for USB host activity

2014-08-23 Thread Michal Sojka
Hi Bryan,

thanks for the review. See some comments below.

On Sat, Aug 23 2014, Bryan Wu wrote:
> On Fri, Aug 22, 2014 at 5:08 PM, Michal Sojka  wrote:
>> With this patch, USB host activity can be signaled by blinking a LED.
>>
>> This should work with all host controllers. Tested only with musb.
>>
>> Signed-off-by: Michal Sojka 
>> ---
>>  drivers/usb/core/Kconfig  |  9 +
>>  drivers/usb/core/Makefile |  1 +
>>  drivers/usb/core/hcd.c|  2 ++
>>  drivers/usb/core/led.c| 38 ++
>>  include/linux/usb/hcd.h   |  6 ++
>>  5 files changed, 56 insertions(+)
>>  create mode 100644 drivers/usb/core/led.c
>>
>> diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
>> index 1060657..8295f65 100644
>> --- a/drivers/usb/core/Kconfig
>> +++ b/drivers/usb/core/Kconfig
>> @@ -90,3 +90,12 @@ config USB_OTG_FSM
>>   Implements OTG Finite State Machine as specified in On-The-Go
>>   and Embedded Host Supplement to the USB Revision 2.0 Specification.
>>
>> +config USB_HOST_LED
>> +   bool "USB Host LED Trigger"
>> +   depends on LEDS_CLASS
>> +   select LEDS_TRIGGERS
>> +   help
>> + This option adds a LED trigger for USB host controllers.
>> +
>> + Say Y here if you are working on a system with led-class supported
>> + LEDs and you want to use them as USB host activity indicators.
>> diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
>> index 2f6f932..324c8c9 100644
>> --- a/drivers/usb/core/Makefile
>> +++ b/drivers/usb/core/Makefile
>> @@ -9,5 +9,6 @@ usbcore-y += port.o
>>
>>  usbcore-$(CONFIG_PCI)  += hcd-pci.o
>>  usbcore-$(CONFIG_ACPI) += usb-acpi.o
>> +usbcore-$(CONFIG_USB_HOST_LED) += led.o
>>
>>  obj-$(CONFIG_USB)  += usbcore.o
>> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
>> index 487abcf..46d9f3a 100644
>> --- a/drivers/usb/core/hcd.c
>> +++ b/drivers/usb/core/hcd.c
>> @@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
>> usbmon_urb_complete(&hcd->self, urb, status);
>> usb_anchor_suspend_wakeups(anchor);
>> usb_unanchor_urb(urb);
>> +   if (status == 0)
>> +   usb_hcd_led_activity();
>>
>> /* pass ownership to the completion handler */
>> urb->status = status;
>> diff --git a/drivers/usb/core/led.c b/drivers/usb/core/led.c
>> new file mode 100644
>> index 000..49ff76c
>> --- /dev/null
>> +++ b/drivers/usb/core/led.c
>> @@ -0,0 +1,38 @@
>> +/*
>> + * LED Trigger for USB Host Activity
>> + *
>> + * Copyright 2014 Michal Sojka 
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define BLINK_DELAY 30
>> +
>> +DEFINE_LED_TRIGGER(ledtrig_usb_hcd);
>
> Add one more trigger named ledtrig_usb_gadget
>
>> +static unsigned long usb_hcd_blink_delay = BLINK_DELAY;
>> +
>> +void usb_hcd_led_activity(void)
>
> Give an input parameter like emum usb_led_event.
> USB_LED_EVENT_HOST = 0
> USB_LED_EVENT_GADGET = 1
>
>
>> +{
>
> Add case for USB_LED_EVENT_HOST:
>> +   led_trigger_blink_oneshot(ledtrig_usb_hcd,
>> + &usb_hcd_blink_delay, 
>> &usb_hcd_blink_delay, 0);
>
> Add case for USB_LED_EVENT_GADGET:
>  led_trigger_blink_oneshot(ledtrig_usb_gadget,
>  &usb_gadget_blink_delay,
> &usb_gadget_blink_delay, 0);
>
>> +}
>> +
>> +int __init ledtrig_usb_hcd_init(void)
>> +{
>> +   led_trigger_register_simple("usb-host", &ledtrig_usb_hcd);
> register one more trigger for gadget.

This way, the code will be full of #ifdefs. Is the following really what
you want? If you want to have it without #ifdefs, then I don't think it
is a good idea to offer users the usb-gadget trigger on systems without
usb gadget support.

#define BLINK_DELAY 30

static unsigned long usb_blink_delay = BLINK_DELAY;

enum usb_led_event {
USB_LED_EVENT_HOST = 0,
USB_LED_EVENT_GADGET = 1,
};

#ifdef CONFIG_USB_GADGET_LED
DEFINE_LED_TRIGGER(ledtrig_usbgadget);
#endif
#ifdef CONFIG_USB_HOST_LE

[PATCH v2 1/3] usb: Add missing #include

2014-08-22 Thread Michal Sojka
linux/usb/hcd.h needs the definition of struct usb_bus.

Signed-off-by: Michal Sojka 
---
 include/linux/usb/hcd.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 485cd5e..b43f0fe 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -23,6 +23,7 @@
 
 #include 
 #include 
+#include 
 
 #define MAX_TOPO_LEVEL 6
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 0/3] LED triggers for USB host and device

2014-08-22 Thread Michal Sojka
This adds LED triggers for USB host and device.

Changes from v1:
- Moved from drivers/leds/ to drivers/usb/
- Improved Kconfig help
- Linked with other modules rather than being standalone modules

Michal Sojka (3):
  usb: Add missing #include
  usb: Add LED trigger for USB host activity
  usb: Add LED trigger for USB gadget activity

 drivers/usb/core/Kconfig|  9 +
 drivers/usb/core/Makefile   |  1 +
 drivers/usb/core/hcd.c  |  2 ++
 drivers/usb/core/led.c  | 38 ++
 drivers/usb/gadget/Kconfig  | 12 
 drivers/usb/gadget/udc/Makefile |  5 -
 drivers/usb/gadget/udc/led.c| 38 ++
 drivers/usb/musb/musb_gadget.c  |  5 +++--
 include/linux/usb/gadget.h  | 10 ++
 include/linux/usb/hcd.h |  7 +++
 10 files changed, 124 insertions(+), 3 deletions(-)
 create mode 100644 drivers/usb/core/led.c
 create mode 100644 drivers/usb/gadget/udc/led.c

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/3] usb: Add LED trigger for USB host activity

2014-08-22 Thread Michal Sojka
With this patch, USB host activity can be signaled by blinking a LED.

This should work with all host controllers. Tested only with musb.

Signed-off-by: Michal Sojka 
---
 drivers/usb/core/Kconfig  |  9 +
 drivers/usb/core/Makefile |  1 +
 drivers/usb/core/hcd.c|  2 ++
 drivers/usb/core/led.c| 38 ++
 include/linux/usb/hcd.h   |  6 ++
 5 files changed, 56 insertions(+)
 create mode 100644 drivers/usb/core/led.c

diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index 1060657..8295f65 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -90,3 +90,12 @@ config USB_OTG_FSM
  Implements OTG Finite State Machine as specified in On-The-Go
  and Embedded Host Supplement to the USB Revision 2.0 Specification.
 
+config USB_HOST_LED
+   bool "USB Host LED Trigger"
+   depends on LEDS_CLASS
+   select LEDS_TRIGGERS
+   help
+ This option adds a LED trigger for USB host controllers.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as USB host activity indicators.
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index 2f6f932..324c8c9 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -9,5 +9,6 @@ usbcore-y += port.o
 
 usbcore-$(CONFIG_PCI)  += hcd-pci.o
 usbcore-$(CONFIG_ACPI) += usb-acpi.o
+usbcore-$(CONFIG_USB_HOST_LED) += led.o
 
 obj-$(CONFIG_USB)  += usbcore.o
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 487abcf..46d9f3a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,6 +1664,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (status == 0)
+   usb_hcd_led_activity();
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/drivers/usb/core/led.c b/drivers/usb/core/led.c
new file mode 100644
index 000..49ff76c
--- /dev/null
+++ b/drivers/usb/core/led.c
@@ -0,0 +1,38 @@
+/*
+ * LED Trigger for USB Host Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+DEFINE_LED_TRIGGER(ledtrig_usb_hcd);
+static unsigned long usb_hcd_blink_delay = BLINK_DELAY;
+
+void usb_hcd_led_activity(void)
+{
+   led_trigger_blink_oneshot(ledtrig_usb_hcd,
+ &usb_hcd_blink_delay, &usb_hcd_blink_delay, 
0);
+}
+
+int __init ledtrig_usb_hcd_init(void)
+{
+   led_trigger_register_simple("usb-host", &ledtrig_usb_hcd);
+   return 0;
+}
+
+void __exit ledtrig_usb_hcd_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usb_hcd);
+}
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index b43f0fe..eb5fa0f 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -700,6 +700,12 @@ extern struct rw_semaphore ehci_cf_port_reset_rwsem;
 #define USB_EHCI_LOADED2
 extern unsigned long usb_hcds_loaded;
 
+#ifdef CONFIG_USB_HOST_LED
+extern void usb_hcd_led_activity(void);
+#else
+static inline void usb_hcd_led_activity(void) {}
+#endif
+
 #endif /* __KERNEL__ */
 
 #endif /* __USB_CORE_HCD_H */
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/3] usb: Add LED trigger for USB gadget activity

2014-08-22 Thread Michal Sojka
With this patch, USB gadget activity can be signaled by blinking a LED.

Since there is no generic code where to put the trigger for all USB
controllers, each USB controller needs to call the trigger individually.
This patch adds the call only for the musb controller where I can test
it.

Signed-off-by: Michal Sojka 
---
 drivers/usb/gadget/Kconfig  | 12 
 drivers/usb/gadget/udc/Makefile |  5 -
 drivers/usb/gadget/udc/led.c| 38 ++
 drivers/usb/musb/musb_gadget.c  |  5 +++--
 include/linux/usb/gadget.h  | 10 ++
 5 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/led.c

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 5c822af..612c859 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -127,6 +127,18 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
   a module parameter as well.
   If unsure, say 2.
 
+config USB_GADGET_LED
+   bool "USB Gadget LED Trigger"
+   depends on (USB_MUSB_GADGET || USB_MUSB_DUAL_ROLE)
+   depends on LEDS_CLASS
+   select LEDS_TRIGGERS
+   help
+ This option adds a LED trigger for USB gadgets. The trigger will
+ only work with supported USB device controllers.
+
+ Say Y here if you are working on a system with led-class supported
+ LEDs and you want to use them as USB gadget activity indicators.
+
 source "drivers/usb/gadget/udc/Kconfig"
 
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4096122..acbe3ca 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -1,7 +1,10 @@
 #
 # USB peripheral controller drivers
 #
-obj-$(CONFIG_USB_GADGET)   += udc-core.o
+obj-$(CONFIG_USB_GADGET)   += udc.o
+udc-y  := udc-core.o
+udc-$(CONFIG_USB_GADGET_LED)   += led.o
+
 obj-$(CONFIG_USB_DUMMY_HCD)+= dummy_hcd.o
 obj-$(CONFIG_USB_NET2272)  += net2272.o
 obj-$(CONFIG_USB_NET2280)  += net2280.o
diff --git a/drivers/usb/gadget/udc/led.c b/drivers/usb/gadget/udc/led.c
new file mode 100644
index 000..29a8b3f
--- /dev/null
+++ b/drivers/usb/gadget/udc/led.c
@@ -0,0 +1,38 @@
+/*
+ * LED Trigger for USB Gadget Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+DEFINE_LED_TRIGGER(ledtrig_usbgadget);
+static unsigned long usbgadget_blink_delay = BLINK_DELAY;
+
+void usb_gadget_led_activity(void)
+{
+   led_trigger_blink_oneshot(ledtrig_usbgadget,
+ &usbgadget_blink_delay, 
&usbgadget_blink_delay, 0);
+}
+EXPORT_SYMBOL(usb_gadget_led_activity);
+
+int __init ledtrig_usbgadget_init(void)
+{
+   led_trigger_register_simple("usb-gadget", &ledtrig_usbgadget);
+   return 0;
+}
+
+void __exit ledtrig_usbgadget_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usbgadget);
+}
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index d4aa779..0bf06f9 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -167,11 +167,12 @@ __acquires(ep->musb->lock)
if (!dma_mapping_error(&musb->g.dev, request->dma))
unmap_dma_buffer(req, musb);
 
-   if (request->status == 0)
+   if (request->status == 0) {
dev_dbg(musb->controller, "%s done request %p,  %d/%d\n",
ep->end_point.name, request,
req->request.actual, req->request.length);
-   else
+   usb_gadget_led_activity();
+   } else
dev_dbg(musb->controller, "%s request %p, %d/%d fault %d\n",
ep->end_point.name, request,
req->request.actual, req->request.length,
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index c3a6185..69bd9bc 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -1025,4 +1025,14 @@ extern struct usb_ep *usb_ep_autoconfig_ss(struct 
usb_gadget *,
 
 extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
+/*-*/
+
+/* LED trigger */
+
+#ifdef CONFIG_USB_GADGET_LED
+extern void usb_gadget_led_activity(void);
+#else
+static inline void usb_gadget_led_activity(void) {}
+#endif
+
 #endif /* __LINUX_USB_GADGET_H */
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity

2014-08-22 Thread Michal Sojka
On Fri, Aug 22 2014, Greg Kroah-Hartman wrote:
> On Fri, Aug 22, 2014 at 10:39:03AM -0700, Bryan Wu wrote:
>> On Fri, Aug 22, 2014 at 4:53 AM, Michal Sojka  wrote:
>> > With this patch, USB gadget activity can be signaled by blinking a LED.
>> >
>> > Since there is no generic code where to put the trigger for all USB
>> > controllers, each USB controller needs to call the trigger individually.
>> > This patch adds the call only for the musb controller where I can test
>> > it.
>> >
>> 
>> Generally I think one led trigger for both USB host and USB gadget
>> activity is good enough. We don't need 2 same led trigger here.
>
> What about systems that have both running at the same time?  Don't you
> want individual control?

Yes, I have a device with two USB connectors (host, device) and a LED
next to each. From the LEDs it should be clear, which connector is being
used.

Thanks,
-Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity

2014-08-22 Thread Michal Sojka
Hi Felipe,

On Fri, Aug 22 2014, Felipe Balbi wrote:
> Hi,
>
> On Fri, Aug 22, 2014 at 01:53:12PM +0200, Michal Sojka wrote:
>> With this patch, USB gadget activity can be signaled by blinking a LED.
>> 
>> Since there is no generic code where to put the trigger for all USB
>> controllers, each USB controller needs to call the trigger individually.
>> This patch adds the call only for the musb controller where I can test
>> it.
>> 
>> Signed-off-by: Michal Sojka 
>> ---
>>  drivers/leds/trigger/Kconfig |  8 ++
>>  drivers/leds/trigger/Makefile|  1 +
>>  drivers/leds/trigger/ledtrig-usbgadget.c | 45 
>> 
>>  drivers/usb/musb/musb_gadget.c   |  6 +++--
>>  include/linux/leds.h |  6 +
>>  5 files changed, 64 insertions(+), 2 deletions(-)
>>  create mode 100644 drivers/leds/trigger/ledtrig-usbgadget.c
>> 
>> diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
>> index 49794b4..9562963 100644
>> --- a/drivers/leds/trigger/Kconfig
>> +++ b/drivers/leds/trigger/Kconfig
>> @@ -41,6 +41,14 @@ config LEDS_TRIGGER_IDE_DISK
>>This allows LEDs to be controlled by IDE disk activity.
>>If unsure, say Y.
>>  
>> +config LEDS_TRIGGER_USBGADGET
>> +bool "LED USB Gadget Trigger"
>> +depends on (USB_MUSB_GADGET || USB_MUSB_DUAL_ROLE)
>> +depends on LEDS_TRIGGERS
>> +help
>> +  This allows LEDs to be controlled by USB gadget activity.
>> +  If unsure, say Y.
>> +
>>  config LEDS_TRIGGER_HEARTBEAT
>>  tristate "LED Heartbeat Trigger"
>>  depends on LEDS_TRIGGERS
>> diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
>> index 1abf48d..45917c0 100644
>> --- a/drivers/leds/trigger/Makefile
>> +++ b/drivers/leds/trigger/Makefile
>> @@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU)   += ledtrig-cpu.o
>>  obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON)   += ledtrig-default-on.o
>>  obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT)+= ledtrig-transient.o
>>  obj-$(CONFIG_LEDS_TRIGGER_CAMERA)   += ledtrig-camera.o
>> +obj-$(CONFIG_LEDS_TRIGGER_USBGADGET)+= ledtrig-usbgadget.o
>> diff --git a/drivers/leds/trigger/ledtrig-usbgadget.c 
>> b/drivers/leds/trigger/ledtrig-usbgadget.c
>> new file mode 100644
>> index 000..1eb90da
>> --- /dev/null
>> +++ b/drivers/leds/trigger/ledtrig-usbgadget.c
>> @@ -0,0 +1,45 @@
>> +/*
>> + * LED Trigger for USB Gadget Activity
>> + *
>> + * Copyright 2014 Michal Sojka 
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define BLINK_DELAY 30
>> +
>> +DEFINE_LED_TRIGGER(ledtrig_usbgadget);
>> +static unsigned long usbgadget_blink_delay = BLINK_DELAY;
>> +
>> +void ledtrig_usbgadget_activity(void)
>> +{
>> +led_trigger_blink_oneshot(ledtrig_usbgadget,
>> +  &usbgadget_blink_delay, 
>> &usbgadget_blink_delay, 0);
>> +}
>> +EXPORT_SYMBOL(ledtrig_usbgadget_activity);
>> +
>> +static int __init ledtrig_usbgadget_init(void)
>> +{
>> +led_trigger_register_simple("usb-gadget", &ledtrig_usbgadget);
>> +return 0;
>> +}
>> +
>> +static void __exit ledtrig_usbgadget_exit(void)
>> +{
>> +led_trigger_unregister_simple(ledtrig_usbgadget);
>> +}
>> +
>> +module_init(ledtrig_usbgadget_init);
>> +module_exit(ledtrig_usbgadget_exit);
>> +
>> +MODULE_AUTHOR("Michal Sojka ");
>> +MODULE_DESCRIPTION("LED Trigger for USB Gadget Activity");
>> +MODULE_LICENSE("GPL");
>> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
>> index d4aa779..98f8b24 100644
>> --- a/drivers/usb/musb/musb_gadget.c
>> +++ b/drivers/usb/musb/musb_gadget.c
>> @@ -42,6 +42,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  #include "musb_core.h"
>>  
>> @@ -167,11 +168,12 @@ __acquires(ep->musb->lock)
>>  if (!dma_mapping_error(&musb->g.dev, request->dma))
>>  unmap_dma_buffer(req, musb);
>>  
>> -if (request->status == 0)
>

[PATCH 2/2] leds: usb: Add LED trigger for USB host activity

2014-08-22 Thread Michal Sojka
With this patch, USB host activity can be signaled by blinking a LED.

This should work with all host controllers. Tested only with musb.

Signed-off-by: Michal Sojka 
---
 drivers/leds/trigger/Kconfig   |  8 ++
 drivers/leds/trigger/Makefile  |  1 +
 drivers/leds/trigger/ledtrig-usbhost.c | 45 ++
 drivers/usb/core/hcd.c |  3 +++
 include/linux/leds.h   |  6 +
 5 files changed, 63 insertions(+)
 create mode 100644 drivers/leds/trigger/ledtrig-usbhost.c

diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index 9562963..528d736 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -49,6 +49,14 @@ config LEDS_TRIGGER_USBGADGET
  This allows LEDs to be controlled by USB gadget activity.
  If unsure, say Y.
 
+config LEDS_TRIGGER_USBHOST
+   bool "LED USB Host Trigger"
+   depends on USB
+   depends on LEDS_TRIGGERS
+   help
+ This allows LEDs to be controlled by USB host activity.
+ If unsure, say Y.
+
 config LEDS_TRIGGER_HEARTBEAT
tristate "LED Heartbeat Trigger"
depends on LEDS_TRIGGERS
diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
index 45917c0..9e9ca19 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON)   += ledtrig-default-on.o
 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT)   += ledtrig-transient.o
 obj-$(CONFIG_LEDS_TRIGGER_CAMERA)  += ledtrig-camera.o
 obj-$(CONFIG_LEDS_TRIGGER_USBGADGET)   += ledtrig-usbgadget.o
+obj-$(CONFIG_LEDS_TRIGGER_USBHOST) += ledtrig-usbhost.o
diff --git a/drivers/leds/trigger/ledtrig-usbhost.c 
b/drivers/leds/trigger/ledtrig-usbhost.c
new file mode 100644
index 000..0a12f67
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-usbhost.c
@@ -0,0 +1,45 @@
+/*
+ * LED Trigger for USB Host Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+DEFINE_LED_TRIGGER(ledtrig_usbhost);
+static unsigned long usbhost_blink_delay = BLINK_DELAY;
+
+void ledtrig_usbhost_activity(void)
+{
+   led_trigger_blink_oneshot(ledtrig_usbhost,
+ &usbhost_blink_delay, &usbhost_blink_delay, 
0);
+}
+EXPORT_SYMBOL(ledtrig_usbhost_activity);
+
+static int __init ledtrig_usbhost_init(void)
+{
+   led_trigger_register_simple("usb-host", &ledtrig_usbhost);
+   return 0;
+}
+
+static void __exit ledtrig_usbhost_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usbhost);
+}
+
+module_init(ledtrig_usbhost_init);
+module_exit(ledtrig_usbhost_exit);
+
+MODULE_AUTHOR("Michal Sojka ");
+MODULE_DESCRIPTION("LED Trigger for USB Host Activity");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 9c4e292..bcfea14 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1664,6 +1665,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
usbmon_urb_complete(&hcd->self, urb, status);
usb_anchor_suspend_wakeups(anchor);
usb_unanchor_urb(urb);
+   if (status == 0)
+   ledtrig_usbhost_activity();
 
/* pass ownership to the completion handler */
urb->status = status;
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 5d9668e..5653495 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -224,6 +224,12 @@ extern void ledtrig_usbgadget_activity(void);
 static inline void ledtrig_usbgadget_activity(void) {}
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_USBHOST
+extern void ledtrig_usbhost_activity(void);
+#else
+static inline void ledtrig_usbhost_activity(void) {}
+#endif
+
 #if defined(CONFIG_LEDS_TRIGGER_CAMERA) || 
defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
 extern void ledtrig_flash_ctrl(bool on);
 extern void ledtrig_torch_ctrl(bool on);
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] leds: usb: Add LED trigger for USB gadget activity

2014-08-22 Thread Michal Sojka
With this patch, USB gadget activity can be signaled by blinking a LED.

Since there is no generic code where to put the trigger for all USB
controllers, each USB controller needs to call the trigger individually.
This patch adds the call only for the musb controller where I can test
it.

Signed-off-by: Michal Sojka 
---
 drivers/leds/trigger/Kconfig |  8 ++
 drivers/leds/trigger/Makefile|  1 +
 drivers/leds/trigger/ledtrig-usbgadget.c | 45 
 drivers/usb/musb/musb_gadget.c   |  6 +++--
 include/linux/leds.h |  6 +
 5 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 drivers/leds/trigger/ledtrig-usbgadget.c

diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index 49794b4..9562963 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -41,6 +41,14 @@ config LEDS_TRIGGER_IDE_DISK
  This allows LEDs to be controlled by IDE disk activity.
  If unsure, say Y.
 
+config LEDS_TRIGGER_USBGADGET
+   bool "LED USB Gadget Trigger"
+   depends on (USB_MUSB_GADGET || USB_MUSB_DUAL_ROLE)
+   depends on LEDS_TRIGGERS
+   help
+ This allows LEDs to be controlled by USB gadget activity.
+ If unsure, say Y.
+
 config LEDS_TRIGGER_HEARTBEAT
tristate "LED Heartbeat Trigger"
depends on LEDS_TRIGGERS
diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
index 1abf48d..45917c0 100644
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU)  += ledtrig-cpu.o
 obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON)  += ledtrig-default-on.o
 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT)   += ledtrig-transient.o
 obj-$(CONFIG_LEDS_TRIGGER_CAMERA)  += ledtrig-camera.o
+obj-$(CONFIG_LEDS_TRIGGER_USBGADGET)   += ledtrig-usbgadget.o
diff --git a/drivers/leds/trigger/ledtrig-usbgadget.c 
b/drivers/leds/trigger/ledtrig-usbgadget.c
new file mode 100644
index 000..1eb90da
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-usbgadget.c
@@ -0,0 +1,45 @@
+/*
+ * LED Trigger for USB Gadget Activity
+ *
+ * Copyright 2014 Michal Sojka 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define BLINK_DELAY 30
+
+DEFINE_LED_TRIGGER(ledtrig_usbgadget);
+static unsigned long usbgadget_blink_delay = BLINK_DELAY;
+
+void ledtrig_usbgadget_activity(void)
+{
+   led_trigger_blink_oneshot(ledtrig_usbgadget,
+ &usbgadget_blink_delay, 
&usbgadget_blink_delay, 0);
+}
+EXPORT_SYMBOL(ledtrig_usbgadget_activity);
+
+static int __init ledtrig_usbgadget_init(void)
+{
+   led_trigger_register_simple("usb-gadget", &ledtrig_usbgadget);
+   return 0;
+}
+
+static void __exit ledtrig_usbgadget_exit(void)
+{
+   led_trigger_unregister_simple(ledtrig_usbgadget);
+}
+
+module_init(ledtrig_usbgadget_init);
+module_exit(ledtrig_usbgadget_exit);
+
+MODULE_AUTHOR("Michal Sojka ");
+MODULE_DESCRIPTION("LED Trigger for USB Gadget Activity");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index d4aa779..98f8b24 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "musb_core.h"
 
@@ -167,11 +168,12 @@ __acquires(ep->musb->lock)
if (!dma_mapping_error(&musb->g.dev, request->dma))
unmap_dma_buffer(req, musb);
 
-   if (request->status == 0)
+   if (request->status == 0) {
dev_dbg(musb->controller, "%s done request %p,  %d/%d\n",
ep->end_point.name, request,
req->request.actual, req->request.length);
-   else
+   ledtrig_usbgadget_activity();
+   } else
dev_dbg(musb->controller, "%s request %p, %d/%d fault %d\n",
ep->end_point.name, request,
req->request.actual, req->request.length,
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 0287ab2..5d9668e 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -218,6 +218,12 @@ extern void ledtrig_ide_activity(void);
 static inline void ledtrig_ide_activity(void) {}
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_USBGADGET
+extern void ledtrig_usbgadget_activity(void);
+#else
+static inline void ledtrig_usbgadget_activity(void) {}
+#endif
+
 #if defined(CONFIG_LEDS_TRIGGER_CAMERA) || 
defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
 extern void ledtrig_flash_ctrl(bool on);
 extern void l

Regulatory of 5.9 GHz band and OCB mode (was: [RFC 1/4] cfg80211: Add channel flags limiting availability to OCB mode only)

2014-08-01 Thread Michal Sojka
Dear Luis and others,

I work with Rostislav on the Linux support of ITS-G5. I did some
research on the regulatory staff for 5.9 GHz band. See my findings below
and sorry for long delay of my reply.

On Tue, Jun 10 2014, Luis R. Rodriguez wrote:
> On Mon, Jun 9, 2014 at 7:21 AM, Rostislav Lisovy  wrote:
>> Dear Luis;
>> Thank you for the introduction in the wireless-regdb mailing-list.
>>
>> On Wed, 2014-06-04 at 00:18 +0200, Luis R. Rodriguez wrote:
>>> Rostislav, can you provide documentation references which would
>>> clarify
>>> the stance on 802.11p and restrictions for only allowing  OCB mode?
>>
>> If I may cite the 802.11-2012 standard:
>> -- 1st Quote
>> 4.3.11 STA transmission of data frames outside the context of a BSS
>>
>> Communication of data frames when dot11OCBActivated is true might take
>> place in a frequency band that is dedicated for its use, and such a band
>> might require licensing depending on the regulatory domain. A STA for
>> which dot11OCBActivated is true initially transmits and receives on a
>> channel known in advance, either through regulatory designation or some
>> other out-of-band communication.
>> -- End of quote
>
> OK the spec does not rule out communication on that special band for
> regular operation as such that special band is mentioned in the
> context of OCB communication, but it does say that the frequency range
> may be licensed. As it stands the public wireless-regdb only covers
> unlicensed frequency ranges, but it obviously can support licensed
> frequency ranges, just that the distribution mechanism and integration
> of the wireless-regdb files then would have to be done separately
> through separate distributors -- ie, not upstream. If the OCB bands
> are unlicensed then we can surely add them to wireless-regdb, however
> it remains unclear if those bands are unlicensed if we can use them
> for regular non OCB communication.
>
> Follow this logic to move forward then:
>
>   * Poke folks to see if the US band for OCB is licensed or unlicensed
>   * Poke folks to see if the EU band for OCB is licensed or unlicensed

I only researched status in the EU. In summary, the band is unlicensed.

The relevant document for Europe is 2008/671/EC (see below). This was
confirmed to us by Czech Telecommunication Office which is responsible
for the administration of radio frequencies in the Czech republic.

The document can be found at
http://www.erodocdb.dk/docs/doc98/official/pdf/2008671EC.pdf and its
full name is "2008/671/EC, Commission Decision of 5 August 2008 on the
harmonised use of radio spectrum in the 5 875-5 905 MHz frequency band
for safety-related applications of Intelligent Transport Systems (ITS)".

  Few quotes from the document:

  Article 3 §1:

Member States shall, not later than six months after entry
into force of this Decision, designate the frequency band
5 875-5 905 MHz for Intelligent Transport Systems and, as
soon as reasonably practicable following such designation,
make that frequency band available on a non-exclusive
basis.

Such designation shall be in compliance with the
parameters set out in the Annex.

  Annex:

Maximum spectral power density (mean e.i.r.p.): 23 dBm/MHz
Maximum total transmit power (mean e.i.r.p.):   33 dBm
Channel access and occupation rules:

Techniques to mitigate interference that provide at least
equivalent performance to the techniques described in
harmonised standards adopted under Directive 1999/5/EC
must be used. These require a transmitter power control
(TPC) range of at least 30 dB.

  Intro (8):

Harmonised standard EN 302 571 [...], thus ensuring that
compliant ITS equipment avoids causing harmful interference.

  The EN 302 571 standard describes in detail the technical parameters
  mentioned above. See
  
http://www.etsi.org/deliver/etsi_en/302500_302599/302571/01.01.01_60/en_302571v010101p.pdf

  This all means that the band in unlicensed and can be used by anybody
  compliant with the annex parameters. This interpretation was explicitly
  confirmed by Czech Telecommunication Office.

I've also found the document ECC/DEC/(08)01 (see below) which predates
2008/671/EC, but since it also mentions 2008/671/EC it seems it is
basically the same thing.

ECC Decision of 14 March 2008 on the harmonised use of the 5875-5925
MHz frequency band for Intelligent Transport Systems (ITS)

  (ECC/DEC/(08)01) (2008/671/EC)

  [http://www.erodocdb.dk/docs/doc98/official/Pdf/ECCDec0801.pdf]

  The document, among others, says:

  3. that CEPT administrations shall designate the frequency sub-band
 5875-5905 MHz on a non-exclusive basis for ITS road safety
 applications;

  8. that CEPT administrations shall exempt in-vehicle ITS equipment
 from individual licensing;

>   * If the bands are *not licensed* there is one corner case that I
> still think sh

[PATCH] USB: serial: ftdi_sio: Add Infineon Triboard

2014-07-10 Thread Michal Sojka
This adds support for Infineon TriBoard TC1798 [1]. Only interface 1
is used as serial line (see [2], Figure 8-6).

[1] 
http://www.infineon.com/cms/de/product/microcontroller/development-tools-software-and-kits/tricore-tm-development-tools-software-and-kits/starterkits-and-evaluation-boards/starter-kit-tc1798/channel.html?channel=db3a304333b8a7ca0133cfa3d73e4268
[2] 
http://www.infineon.com/dgdl/TriBoardManual-TC1798-V10.pdf?folderId=db3a304412b407950112b409ae7c0343&fileId=db3a304333b8a7ca0133cfae99fe426a

Signed-off-by: Michal Sojka 
---
 drivers/usb/serial/ftdi_sio.c | 2 ++
 drivers/usb/serial/ftdi_sio_ids.h | 6 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 115662c1..0c2b6e0 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -944,6 +944,8 @@ static const struct usb_device_id id_table_combined[] = {
{ USB_DEVICE(BRAINBOXES_VID, BRAINBOXES_US_842_2_PID) },
{ USB_DEVICE(BRAINBOXES_VID, BRAINBOXES_US_842_3_PID) },
{ USB_DEVICE(BRAINBOXES_VID, BRAINBOXES_US_842_4_PID) },
+   /* Infineon Devices */
+   { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_PID, 1) },
{ } /* Terminating entry */
 };
 
diff --git a/drivers/usb/serial/ftdi_sio_ids.h 
b/drivers/usb/serial/ftdi_sio_ids.h
index 500474c..8d959a7 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -584,6 +584,12 @@
 #define RATOC_PRODUCT_ID_USB60F0xb020
 
 /*
+ * Infineon Technologies
+ */
+#define INFINEON_VID   0x058b
+#define INFINEON_TRIBOARD_PID  0x0028 /* DAS JTAG TriBoard TC1798 V1.0 */
+
+/*
  * Acton Research Corp.
  */
 #define ACTON_VID  0x0647  /* Vendor ID */
-- 
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/