Re: Cannot shutdown power use from built in webcam in thinkpad T530 questions]

2013-09-22 Thread Ming Lei
On Thu, Sep 19, 2013 at 12:35 PM, Marc MERLIN m...@merlins.org wrote:

 gandalfthegreat:/sys/bus/usb/devices/3-1.6/power# grep . *
 active_duration:61227648
 async:enabled
 autosuspend:2
 autosuspend_delay_ms:2000
 connected_duration:66830880
 control:auto
 level:auto
 persist:1
 runtime_active_kids:0
 runtime_active_time:18870052
 runtime_enabled:enabled
 runtime_status:active
 runtime_suspended_time:5324088
 runtime_usage:0

The uvc device should have been put in auto-suspend state if no
application is using the device.  You can check if there is application
which is using the device by 'lsof | grep /dev/video'.

Also looks power usage estimation of 'power top' should be used
when battery provides power, and the data isn't correct if power is
provided from power adapter, if I remember correctly.

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


[PATCH v1 00/49] USB: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
/usb/serial/symbolserial.c |5 ++--
 drivers/usb/serial/ti_usb_3410_5052.c |9 +++---
 drivers/usb/serial/usb_wwan.c |5 ++--
 drivers/usb/usb-skeleton.c|   11 ---
 sound/usb/caiaq/audio.c   |5 ++--
 sound/usb/midi.c  |5 ++--
 54 files changed, 318 insertions(+), 221 deletions(-)


Thanks,
--
Ming Lei

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


[PATCH v1 40/49] media: usb: tlg2300: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/tlg2300/pd-alsa.c  |5 +++--
 drivers/media/usb/tlg2300/pd-video.c |5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/tlg2300/pd-alsa.c 
b/drivers/media/usb/tlg2300/pd-alsa.c
index 3f3e141..65c46a2 100644
--- a/drivers/media/usb/tlg2300/pd-alsa.c
+++ b/drivers/media/usb/tlg2300/pd-alsa.c
@@ -141,6 +141,7 @@ static inline void handle_audio_data(struct urb *urb, int 
*period_elapsed)
int len = urb-actual_length / stride;
unsigned char *cp   = urb-transfer_buffer;
unsigned int oldptr = pa-rcv_position;
+   unsigned long flags;
 
if (urb-actual_length == AUDIO_BUF_SIZE - 4)
len -= (AUDIO_TRAILER_SIZE / stride);
@@ -156,7 +157,7 @@ static inline void handle_audio_data(struct urb *urb, int 
*period_elapsed)
memcpy(runtime-dma_area + oldptr * stride, cp, len * stride);
 
/* update the statas */
-   snd_pcm_stream_lock(pa-capture_pcm_substream);
+   snd_pcm_stream_lock_irqsave(pa-capture_pcm_substream, flags);
pa-rcv_position+= len;
if (pa-rcv_position = runtime-buffer_size)
pa-rcv_position -= runtime-buffer_size;
@@ -166,7 +167,7 @@ static inline void handle_audio_data(struct urb *urb, int 
*period_elapsed)
pa-copied_position -= runtime-period_size;
*period_elapsed = 1;
}
-   snd_pcm_stream_unlock(pa-capture_pcm_substream);
+   snd_pcm_stream_unlock_irqrestore(pa-capture_pcm_substream, flags);
 }
 
 static void complete_handler_audio(struct urb *urb)
diff --git a/drivers/media/usb/tlg2300/pd-video.c 
b/drivers/media/usb/tlg2300/pd-video.c
index 8df668d..4e5bd07 100644
--- a/drivers/media/usb/tlg2300/pd-video.c
+++ b/drivers/media/usb/tlg2300/pd-video.c
@@ -151,11 +151,12 @@ static void init_copy(struct video_data *video, bool 
index)
 static bool get_frame(struct front_face *front, int *need_init)
 {
struct videobuf_buffer *vb = front-curr_frame;
+   unsigned long flags;
 
if (vb)
return true;
 
-   spin_lock(front-queue_lock);
+   spin_lock_irqsave(front-queue_lock, flags);
if (!list_empty(front-active)) {
vb = list_entry(front-active.next,
   struct videobuf_buffer, queue);
@@ -164,7 +165,7 @@ static bool get_frame(struct front_face *front, int 
*need_init)
front-curr_frame = vb;
list_del_init(vb-queue);
}
-   spin_unlock(front-queue_lock);
+   spin_unlock_irqrestore(front-queue_lock, flags);
 
return !!vb;
 }
-- 
1.7.9.5

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


[PATCH v1 38/49] media: usb: em28xx: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Reviewed-by: Devin Heitmueller dheitmuel...@kernellabs.com
Tested-by: Devin Heitmueller dheitmuel...@kernellabs.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/em28xx/em28xx-core.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index fc157af..0d698f9 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -941,6 +941,7 @@ static void em28xx_irq_callback(struct urb *urb)
 {
struct em28xx *dev = urb-context;
int i;
+   unsigned long flags;
 
switch (urb-status) {
case 0: /* success */
@@ -956,9 +957,9 @@ static void em28xx_irq_callback(struct urb *urb)
}
 
/* Copy data from URB */
-   spin_lock(dev-slock);
+   spin_lock_irqsave(dev-slock, flags);
dev-usb_ctl.urb_data_copy(dev, urb);
-   spin_unlock(dev-slock);
+   spin_unlock_irqrestore(dev-slock, flags);
 
/* Reset urb buffers */
for (i = 0; i  urb-number_of_packets; i++) {
-- 
1.7.9.5

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


[PATCH v1 41/49] media: usb: tm6000: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/tm6000/tm6000-video.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-video.c 
b/drivers/media/usb/tm6000/tm6000-video.c
index cc1aa14..8bb440f 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -434,6 +434,7 @@ static void tm6000_irq_callback(struct urb *urb)
struct tm6000_dmaqueue  *dma_q = urb-context;
struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
int i;
+   unsigned long flags;
 
switch (urb-status) {
case 0:
@@ -450,9 +451,9 @@ static void tm6000_irq_callback(struct urb *urb)
break;
}
 
-   spin_lock(dev-slock);
+   spin_lock_irqsave(dev-slock, flags);
tm6000_isoc_copy(urb);
-   spin_unlock(dev-slock);
+   spin_unlock_irqrestore(dev-slock, flags);
 
/* Reset urb buffers */
for (i = 0; i  urb-number_of_packets; i++) {
-- 
1.7.9.5

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


[PATCH v1 37/49] media: usb: cx231xx: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: Hans Verkuil hans.verk...@cisco.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/cx231xx/cx231xx-audio.c |   10 ++
 drivers/media/usb/cx231xx/cx231xx-core.c  |   10 ++
 drivers/media/usb/cx231xx/cx231xx-vbi.c   |5 +++--
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c 
b/drivers/media/usb/cx231xx/cx231xx-audio.c
index 81a1d97..f6fa0af 100644
--- a/drivers/media/usb/cx231xx/cx231xx-audio.c
+++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
@@ -136,6 +136,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
stride = runtime-frame_bits  3;
 
for (i = 0; i  urb-number_of_packets; i++) {
+   unsigned long flags;
int length = urb-iso_frame_desc[i].actual_length /
 stride;
cp = (unsigned char *)urb-transfer_buffer +
@@ -158,7 +159,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
   length * stride);
}
 
-   snd_pcm_stream_lock(substream);
+   snd_pcm_stream_lock_irqsave(substream, flags);
 
dev-adev.hwptr_done_capture += length;
if (dev-adev.hwptr_done_capture =
@@ -173,7 +174,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
runtime-period_size;
period_elapsed = 1;
}
-   snd_pcm_stream_unlock(substream);
+   snd_pcm_stream_unlock_irqrestore(substream, flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
@@ -224,6 +225,7 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
stride = runtime-frame_bits  3;
 
if (1) {
+   unsigned long flags;
int length = urb-actual_length /
 stride;
cp = (unsigned char *)urb-transfer_buffer;
@@ -242,7 +244,7 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
   length * stride);
}
 
-   snd_pcm_stream_lock(substream);
+   snd_pcm_stream_lock_irqsave(substream, flags);
 
dev-adev.hwptr_done_capture += length;
if (dev-adev.hwptr_done_capture =
@@ -257,7 +259,7 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
runtime-period_size;
period_elapsed = 1;
}
-   snd_pcm_stream_unlock(substream);
+   snd_pcm_stream_unlock_irqrestore(substream,flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c 
b/drivers/media/usb/cx231xx/cx231xx-core.c
index 4ba3ce0..593b397 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -798,6 +798,7 @@ static void cx231xx_isoc_irq_callback(struct urb *urb)
container_of(dma_q, struct cx231xx_video_mode, vidq);
struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode);
int i;
+   unsigned long flags;
 
switch (urb-status) {
case 0: /* success */
@@ -813,9 +814,9 @@ static void cx231xx_isoc_irq_callback(struct urb *urb)
}
 
/* Copy data from URB */
-   spin_lock(dev-video_mode.slock);
+   spin_lock_irqsave(dev-video_mode.slock, flags);
dev-video_mode.isoc_ctl.isoc_copy(dev, urb);
-   spin_unlock(dev-video_mode.slock);
+   spin_unlock_irqrestore(dev-video_mode.slock, flags);
 
/* Reset urb buffers */
for (i = 0; i  urb-number_of_packets; i++) {
@@ -842,6 +843,7 @@ static void cx231xx_bulk_irq_callback(struct urb *urb)
struct cx231xx_video_mode *vmode =
container_of(dma_q, struct cx231xx_video_mode, vidq);
struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode);
+   unsigned long flags;
 
switch (urb-status) {
case 0: /* success */
@@ -857,9 +859,9 @@ static void cx231xx_bulk_irq_callback(struct urb *urb)
}
 
/* Copy data from URB */
-   spin_lock(dev-video_mode.slock);
+   spin_lock_irqsave(dev-video_mode.slock, flags);
dev-video_mode.bulk_ctl.bulk_copy(dev, urb);
-   spin_unlock(dev-video_mode.slock);
+   spin_unlock_irqrestore(dev-video_mode.slock, flags);
 
/* Reset urb

[PATCH v1 42/49] media: dvb-core: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

These functions may be called inside URB-complete(), so use
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/dvb-core/dvb_demux.c |   17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_demux.c 
b/drivers/media/dvb-core/dvb_demux.c
index 3485655..58de441 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -476,7 +476,9 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux 
*demux, const u8 *buf)
 void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
  size_t count)
 {
-   spin_lock(demux-lock);
+   unsigned long flags;
+
+   spin_lock_irqsave(demux-lock, flags);
 
while (count--) {
if (buf[0] == 0x47)
@@ -484,7 +486,7 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, 
const u8 *buf,
buf += 188;
}
 
-   spin_unlock(demux-lock);
+   spin_unlock_irqrestore(demux-lock, flags);
 }
 
 EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
@@ -519,8 +521,9 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux 
*demux, const u8 *buf,
 {
int p = 0, i, j;
const u8 *q;
+   unsigned long flags;
 
-   spin_lock(demux-lock);
+   spin_lock_irqsave(demux-lock, flags);
 
if (demux-tsbufp) { /* tsbuf[0] is now 0x47. */
i = demux-tsbufp;
@@ -564,7 +567,7 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux 
*demux, const u8 *buf,
}
 
 bailout:
-   spin_unlock(demux-lock);
+   spin_unlock_irqrestore(demux-lock, flags);
 }
 
 void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
@@ -581,11 +584,13 @@ EXPORT_SYMBOL(dvb_dmx_swfilter_204);
 
 void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count)
 {
-   spin_lock(demux-lock);
+   unsigned long flags;
+
+   spin_lock_irqsave(demux-lock, flags);
 
demux-feed-cb.ts(buf, count, NULL, 0, demux-feed-feed.ts, DMX_OK);
 
-   spin_unlock(demux-lock);
+   spin_unlock_irqrestore(demux-lock, flags);
 }
 EXPORT_SYMBOL(dvb_dmx_swfilter_raw);
 
-- 
1.7.9.5

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


[PATCH v1 43/49] media: usb: em28xx: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so add local_irq_save()
before acquiring the lock without irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/em28xx/em28xx-audio.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index 2fdb66e..7fd1b2a 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -113,6 +113,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
stride = runtime-frame_bits  3;
 
for (i = 0; i  urb-number_of_packets; i++) {
+   unsigned long flags;
int length =
urb-iso_frame_desc[i].actual_length / stride;
cp = (unsigned char *)urb-transfer_buffer +
@@ -134,7 +135,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
   length * stride);
}
 
-   snd_pcm_stream_lock(substream);
+   snd_pcm_stream_lock_irqsave(substream, flags);
 
dev-adev.hwptr_done_capture += length;
if (dev-adev.hwptr_done_capture =
@@ -150,7 +151,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
period_elapsed = 1;
}
 
-   snd_pcm_stream_unlock(substream);
+   snd_pcm_stream_unlock_irqrestore(substream, flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
-- 
1.7.9.5

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


[PATCH v1 39/49] media: usb: sn9x102: prepare for enabling irq in complete()

2013-08-17 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/sn9c102/sn9c102_core.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/sn9c102/sn9c102_core.c 
b/drivers/media/usb/sn9c102/sn9c102_core.c
index 2cb44de..33dc595 100644
--- a/drivers/media/usb/sn9c102/sn9c102_core.c
+++ b/drivers/media/usb/sn9c102/sn9c102_core.c
@@ -784,12 +784,14 @@ end_of_frame:
  cam-sensor.pix_format.pixelformat ==
  V4L2_PIX_FMT_JPEG)  eof)) {
u32 b;
+   unsigned long flags;
 
b = (*f)-buf.bytesused;
(*f)-state = F_DONE;
(*f)-buf.sequence= ++cam-frame_count;
 
-   spin_lock(cam-queue_lock);
+   spin_lock_irqsave(cam-queue_lock,
+ flags);
list_move_tail((*f)-frame,
   cam-outqueue);
if (!list_empty(cam-inqueue))
@@ -799,7 +801,8 @@ end_of_frame:
frame );
else
(*f) = NULL;
-   spin_unlock(cam-queue_lock);
+   spin_unlock_irqrestore(cam-queue_lock,
+  flags);
 
memcpy(cam-sysfs.frame_header,
   cam-sof.header, soflen);
-- 
1.7.9.5

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


Re: [PATCH 35/50] media: usb: cx231xx: spin_lock in complete() cleanup

2013-07-27 Thread Ming Lei
On Fri, Jul 26, 2013 at 10:28 PM, Hans Verkuil hverk...@xs4all.nl wrote:


 On 07/11/2013 11:05 AM, Ming Lei wrote:
 Complete() will be run with interrupt enabled, so change to
 spin_lock_irqsave().

 Cc: Mauro Carvalho Chehab mche...@redhat.com
 Cc: Hans Verkuil hans.verk...@cisco.com
 Cc: linux-media@vger.kernel.org
 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/media/usb/cx231xx/cx231xx-audio.c |6 ++
  drivers/media/usb/cx231xx/cx231xx-core.c  |   10 ++
  drivers/media/usb/cx231xx/cx231xx-vbi.c   |5 +++--
  3 files changed, 15 insertions(+), 6 deletions(-)

 diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c 
 b/drivers/media/usb/cx231xx/cx231xx-audio.c
 index 81a1d97..58c1b5c 100644
 --- a/drivers/media/usb/cx231xx/cx231xx-audio.c
 +++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
 @@ -136,6 +136,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
   stride = runtime-frame_bits  3;

   for (i = 0; i  urb-number_of_packets; i++) {
 + unsigned long flags;
   int length = urb-iso_frame_desc[i].actual_length /
stride;
   cp = (unsigned char *)urb-transfer_buffer +
 @@ -158,6 +159,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
  length * stride);
   }

 + local_irq_save(flags);
   snd_pcm_stream_lock(substream);

 Can't you use snd_pcm_stream_lock_irqsave here?

Sure, that is already in my mind, :-)

 Ditto for the other media drivers where this happens: em28xx and tlg2300.

Yes.


 I've reviewed the media driver changes and they look OK to me, so if
 my comment above is fixed, then I can merge them for 3.12. Or are these
 changes required for 3.11?

These are for 3.12.

I will send out v2 next week, and thanks for your review.

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


Re: [PATCH 00/50] USB: cleanup spin_lock in URB-complete()

2013-07-14 Thread Ming Lei
On Sun, Jul 14, 2013 at 9:17 PM, Andy Walls awa...@md.metrocast.net wrote:
 On Thu, 2013-07-11 at 17:05 +0800, Ming Lei wrote:
 Hi,

 As we are going to run URB-complete() in tasklet context[1][2],

 Hi,

 Please pardon my naivete, but why was it decided to use tasklets to
 defer work, as opposed to some other deferred work mechanism?

 It seems to me that getting rid of tasklets has been an objective for
 years:

 http://lwn.net/Articles/239633/
 http://lwn.net/Articles/520076/
 http://lwn.net/Articles/240054/

We discussed the problem in the below link previously[1], Steven
and Thomas suggested to use threaded irq handler, but which
may degrade USB mass storage performance, so we have to
take tasklet now until we rewrite transport part of USB mass storage
driver.

Also the conversion[2] has avoided the tasklet spin lock problem
already.


[1], http://marc.info/?t=13707911921r=1w=2
[2], http://marc.info/?l=linux-usbm=137286326726326w=2


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


[PATCH 00/50] USB: cleanup spin_lock in URB-complete()

2013-07-11 Thread Ming Lei
Hi,

As we are going to run URB-complete() in tasklet context[1][2], and
hard interrupt may be enabled when running URB completion handler[3],
so we might need to disable interrupt when acquiring one lock in
the completion handler for the below reasons:

- URB-complete() holds a subsystem wide lock which may be acquired
in another hard irq context, and the subsystem wide lock is acquired
by spin_lock()/read_lock()/write_lock() in complete()

- URB-complete() holds a private lock with spin_lock()/read_lock()/write_lock()
but driver may export APIs to make other drivers acquire the same private
lock in its interrupt handler.

For the sake of safety and making the change simple, this patch set
converts all spin_lock()/read_lock()/write_lock() in completion handler
path into their irqsave version mechanically.

But if you are sure the above two cases do not happen in your driver,
please let me know and I can drop the unnecessary change.

Also if you find some conversions are missed, also please let me know so
that I can add it in the next round.


[1], http://marc.info/?l=linux-usbm=137286322526312w=2
[2], http://marc.info/?l=linux-usbm=137286326726326w=2
[3], http://marc.info/?l=linux-usbm=137286330626363w=2

 drivers/bluetooth/bfusb.c |   12 
 drivers/bluetooth/btusb.c |5 ++--
 drivers/hid/usbhid/hid-core.c |5 ++--
 drivers/input/misc/cm109.c|   10 ---
 drivers/isdn/hardware/mISDN/hfcsusb.c |   36 ---
 drivers/media/dvb-core/dvb_demux.c|   17 +++
 drivers/media/usb/cx231xx/cx231xx-audio.c |6 
 drivers/media/usb/cx231xx/cx231xx-core.c  |   10 ---
 drivers/media/usb/cx231xx/cx231xx-vbi.c   |5 ++--
 drivers/media/usb/em28xx/em28xx-audio.c   |3 ++
 drivers/media/usb/em28xx/em28xx-core.c|5 ++--
 drivers/media/usb/sn9c102/sn9c102_core.c  |7 +++--
 drivers/media/usb/tlg2300/pd-alsa.c   |3 ++
 drivers/media/usb/tlg2300/pd-video.c  |5 ++--
 drivers/media/usb/tm6000/tm6000-video.c   |5 ++--
 drivers/net/usb/cdc-phonet.c  |5 ++--
 drivers/net/usb/hso.c |   38 ++---
 drivers/net/usb/kaweth.c  |7 +++--
 drivers/net/usb/rtl8150.c |5 ++--
 drivers/net/wireless/ath/ath9k/hif_usb.c  |   29 ++-
 drivers/net/wireless/ath/ath9k/htc_drv_txrx.c |9 +++---
 drivers/net/wireless/ath/ath9k/wmi.c  |   11 +++
 drivers/net/wireless/ath/carl9170/rx.c|5 ++--
 drivers/net/wireless/libertas/if_usb.c|5 ++--
 drivers/net/wireless/libertas_tf/if_usb.c |6 ++--
 drivers/net/wireless/zd1211rw/zd_usb.c|   21 --
 drivers/staging/bcm/InterfaceRx.c |5 ++--
 drivers/staging/btmtk_usb/btmtk_usb.c |5 ++--
 drivers/staging/ced1401/usb1401.c |   35 ---
 drivers/staging/vt6656/usbpipe.c  |9 +++---
 drivers/usb/class/cdc-wdm.c   |   16 +++
 drivers/usb/class/usblp.c |   10 ---
 drivers/usb/core/devio.c  |5 ++--
 drivers/usb/misc/adutux.c |   10 ---
 drivers/usb/misc/iowarrior.c  |5 ++--
 drivers/usb/misc/ldusb.c  |7 +++--
 drivers/usb/misc/legousbtower.c   |5 ++--
 drivers/usb/misc/usbtest.c|   10 ---
 drivers/usb/misc/uss720.c |6 +++-
 drivers/usb/serial/cyberjack.c|   15 ++
 drivers/usb/serial/digi_acceleport.c  |   23 ---
 drivers/usb/serial/io_edgeport.c  |   14 +
 drivers/usb/serial/io_ti.c|5 ++--
 drivers/usb/serial/mos7720.c  |5 ++--
 drivers/usb/serial/mos7840.c  |5 ++--
 drivers/usb/serial/quatech2.c |5 ++--
 drivers/usb/serial/sierra.c   |9 +++---
 drivers/usb/serial/symbolserial.c |5 ++--
 drivers/usb/serial/ti_usb_3410_5052.c |9 +++---
 drivers/usb/serial/usb_wwan.c |5 ++--
 sound/usb/caiaq/audio.c   |5 ++--
 sound/usb/midi.c  |5 ++--
 sound/usb/misc/ua101.c|   14 +++--
 sound/usb/usx2y/usbusx2yaudio.c   |4 +++
 54 files changed, 322 insertions(+), 209 deletions(-)


Thanks,
--
Ming Lei

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


[PATCH 03/50] USB: usblp: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Pete Zaitcev zait...@redhat.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/class/usblp.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index d4c47d5..04163d8 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -297,6 +297,7 @@ static void usblp_bulk_read(struct urb *urb)
 {
struct usblp *usblp = urb-context;
int status = urb-status;
+   unsigned long flags;
 
if (usblp-present  usblp-used) {
if (status)
@@ -304,14 +305,14 @@ static void usblp_bulk_read(struct urb *urb)
nonzero read bulk status received: %d\n,
usblp-minor, status);
}
-   spin_lock(usblp-lock);
+   spin_lock_irqsave(usblp-lock, flags);
if (status  0)
usblp-rstatus = status;
else
usblp-rstatus = urb-actual_length;
usblp-rcomplete = 1;
wake_up(usblp-rwait);
-   spin_unlock(usblp-lock);
+   spin_unlock_irqrestore(usblp-lock, flags);
 
usb_free_urb(urb);
 }
@@ -320,6 +321,7 @@ static void usblp_bulk_write(struct urb *urb)
 {
struct usblp *usblp = urb-context;
int status = urb-status;
+   unsigned long flags;
 
if (usblp-present  usblp-used) {
if (status)
@@ -327,7 +329,7 @@ static void usblp_bulk_write(struct urb *urb)
nonzero write bulk status received: %d\n,
usblp-minor, status);
}
-   spin_lock(usblp-lock);
+   spin_lock_irqsave(usblp-lock, flags);
if (status  0)
usblp-wstatus = status;
else
@@ -335,7 +337,7 @@ static void usblp_bulk_write(struct urb *urb)
usblp-no_paper = 0;
usblp-wcomplete = 1;
wake_up(usblp-wwait);
-   spin_unlock(usblp-lock);
+   spin_unlock_irqrestore(usblp-lock, flags);
 
usb_free_urb(urb);
 }
-- 
1.7.9.5

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


[PATCH 06/50] USB: iowarrior: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/misc/iowarrior.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index d36f34e..010ed6d 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -162,6 +162,7 @@ static void iowarrior_callback(struct urb *urb)
int offset;
int status = urb-status;
int retval;
+   unsigned long flags;
 
switch (status) {
case 0:
@@ -175,7 +176,7 @@ static void iowarrior_callback(struct urb *urb)
goto exit;
}
 
-   spin_lock(dev-intr_idx_lock);
+   spin_lock_irqsave(dev-intr_idx_lock, flags);
intr_idx = atomic_read(dev-intr_idx);
/* aux_idx become previous intr_idx */
aux_idx = (intr_idx == 0) ? (MAX_INTERRUPT_BUFFER - 1) : (intr_idx - 1);
@@ -211,7 +212,7 @@ static void iowarrior_callback(struct urb *urb)
*(dev-read_queue + offset + (dev-report_size)) = dev-serial_number++;
 
atomic_set(dev-intr_idx, aux_idx);
-   spin_unlock(dev-intr_idx_lock);
+   spin_unlock_irqrestore(dev-intr_idx_lock, flags);
/* tell the blocking read about the new data */
wake_up_interruptible(dev-read_wait);
 
-- 
1.7.9.5

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


[PATCH 12/50] USB: serial: io_edgeport: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/io_edgeport.c |   14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index dc2803b..af2f7d8 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -569,6 +569,7 @@ static void edge_interrupt_callback(struct urb *urb)
int portNumber;
int result;
int status = urb-status;
+   unsigned long flags;
 
switch (status) {
case 0:
@@ -594,7 +595,7 @@ static void edge_interrupt_callback(struct urb *urb)
if (length  1) {
bytes_avail = data[0] | (data[1]  8);
if (bytes_avail) {
-   spin_lock(edge_serial-es_lock);
+   spin_lock_irqsave(edge_serial-es_lock, flags);
edge_serial-rxBytesAvail += bytes_avail;
dev_dbg(dev,
%s - bytes_avail=%d, rxBytesAvail=%d, 
read_in_progress=%d\n,
@@ -617,7 +618,7 @@ static void edge_interrupt_callback(struct urb *urb)
edge_serial-read_in_progress = 
false;
}
}
-   spin_unlock(edge_serial-es_lock);
+   spin_unlock_irqrestore(edge_serial-es_lock, 
flags);
}
}
/* grab the txcredits for the ports if available */
@@ -630,9 +631,9 @@ static void edge_interrupt_callback(struct urb *urb)
port = edge_serial-serial-port[portNumber];
edge_port = usb_get_serial_port_data(port);
if (edge_port-open) {
-   spin_lock(edge_port-ep_lock);
+   spin_lock_irqsave(edge_port-ep_lock, 
flags);
edge_port-txCredits += txCredits;
-   spin_unlock(edge_port-ep_lock);
+   
spin_unlock_irqrestore(edge_port-ep_lock, flags);
dev_dbg(dev, %s - txcredits for port%d 
= %d\n,
__func__, portNumber,
edge_port-txCredits);
@@ -673,6 +674,7 @@ static void edge_bulk_in_callback(struct urb *urb)
int retval;
__u16   raw_data_length;
int status = urb-status;
+   unsigned long flags;
 
if (status) {
dev_dbg(urb-dev-dev, %s - nonzero read bulk status 
received: %d\n,
@@ -692,7 +694,7 @@ static void edge_bulk_in_callback(struct urb *urb)
 
usb_serial_debug_data(dev, __func__, raw_data_length, data);
 
-   spin_lock(edge_serial-es_lock);
+   spin_lock_irqsave(edge_serial-es_lock, flags);
 
/* decrement our rxBytes available by the number that we just got */
edge_serial-rxBytesAvail -= raw_data_length;
@@ -716,7 +718,7 @@ static void edge_bulk_in_callback(struct urb *urb)
edge_serial-read_in_progress = false;
}
 
-   spin_unlock(edge_serial-es_lock);
+   spin_unlock_irqrestore(edge_serial-es_lock, flags);
 }
 
 
-- 
1.7.9.5

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


[PATCH 02/50] USB: cdc-wdm: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Oliver Neukum oli...@neukum.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/class/cdc-wdm.c |   16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 8a230f0..5f78d18 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -143,10 +143,12 @@ found:
 static void wdm_out_callback(struct urb *urb)
 {
struct wdm_device *desc;
+   unsigned long flags;
+
desc = urb-context;
-   spin_lock(desc-iuspin);
+   spin_lock_irqsave(desc-iuspin, flags);
desc-werr = urb-status;
-   spin_unlock(desc-iuspin);
+   spin_unlock_irqrestore(desc-iuspin, flags);
kfree(desc-outbuf);
desc-outbuf = NULL;
clear_bit(WDM_IN_USE, desc-flags);
@@ -158,8 +160,9 @@ static void wdm_in_callback(struct urb *urb)
struct wdm_device *desc = urb-context;
int status = urb-status;
int length = urb-actual_length;
+   unsigned long flags;
 
-   spin_lock(desc-iuspin);
+   spin_lock_irqsave(desc-iuspin, flags);
clear_bit(WDM_RESPONDING, desc-flags);
 
if (status) {
@@ -203,7 +206,7 @@ skip_error:
wake_up(desc-wait);
 
set_bit(WDM_READ, desc-flags);
-   spin_unlock(desc-iuspin);
+   spin_unlock_irqrestore(desc-iuspin, flags);
 }
 
 static void wdm_int_callback(struct urb *urb)
@@ -212,6 +215,7 @@ static void wdm_int_callback(struct urb *urb)
int status = urb-status;
struct wdm_device *desc;
struct usb_cdc_notification *dr;
+   unsigned long flags;
 
desc = urb-context;
dr = (struct usb_cdc_notification *)desc-sbuf;
@@ -260,7 +264,7 @@ static void wdm_int_callback(struct urb *urb)
goto exit;
}
 
-   spin_lock(desc-iuspin);
+   spin_lock_irqsave(desc-iuspin, flags);
clear_bit(WDM_READ, desc-flags);
set_bit(WDM_RESPONDING, desc-flags);
if (!test_bit(WDM_DISCONNECTING, desc-flags)
@@ -269,7 +273,7 @@ static void wdm_int_callback(struct urb *urb)
dev_dbg(desc-intf-dev, %s: usb_submit_urb %d,
__func__, rv);
}
-   spin_unlock(desc-iuspin);
+   spin_unlock_irqrestore(desc-iuspin, flags);
if (rv  0) {
clear_bit(WDM_RESPONDING, desc-flags);
if (rv == -EPERM)
-- 
1.7.9.5

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


[PATCH 11/50] USB: serial: digi_acceleportldusb: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Peter Berger pber...@brimson.com
Cc: Al Borchers alborch...@steinerpoint.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/digi_acceleport.c |   23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/serial/digi_acceleport.c 
b/drivers/usb/serial/digi_acceleport.c
index 19b467f..95b1959 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -988,6 +988,7 @@ static void digi_write_bulk_callback(struct urb *urb)
struct digi_serial *serial_priv;
int ret = 0;
int status = urb-status;
+   unsigned long flags;
 
/* port and serial sanity check */
if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
@@ -1006,15 +1007,15 @@ static void digi_write_bulk_callback(struct urb *urb)
/* handle oob callback */
if (priv-dp_port_num == serial_priv-ds_oob_port_num) {
dev_dbg(port-dev, digi_write_bulk_callback: oob callback\n);
-   spin_lock(priv-dp_port_lock);
+   spin_lock_irqsave(priv-dp_port_lock, flags);
priv-dp_write_urb_in_use = 0;
wake_up_interruptible(port-write_wait);
-   spin_unlock(priv-dp_port_lock);
+   spin_unlock_irqrestore(priv-dp_port_lock, flags);
return;
}
 
/* try to send any buffered data on this port */
-   spin_lock(priv-dp_port_lock);
+   spin_lock_irqsave(priv-dp_port_lock, flags);
priv-dp_write_urb_in_use = 0;
if (priv-dp_out_buf_len  0) {
*((unsigned char *)(port-write_urb-transfer_buffer))
@@ -1037,7 +1038,7 @@ static void digi_write_bulk_callback(struct urb *urb)
/* lost the race in write_chan(). */
schedule_work(priv-dp_wakeup_work);
 
-   spin_unlock(priv-dp_port_lock);
+   spin_unlock_irqrestore(priv-dp_port_lock, flags);
if (ret  ret != -EPERM)
dev_err_console(port,
%s: usb_submit_urb failed, ret=%d, port=%d\n,
@@ -1388,6 +1389,7 @@ static int digi_read_inb_callback(struct urb *urb)
unsigned char *data = ((unsigned char *)urb-transfer_buffer) + 3;
int flag, throttled;
int status = urb-status;
+   unsigned long flags;
 
/* do not process callbacks on closed ports */
/* but do continue the read chain */
@@ -1404,7 +1406,7 @@ static int digi_read_inb_callback(struct urb *urb)
return -1;
}
 
-   spin_lock(priv-dp_port_lock);
+   spin_lock_irqsave(priv-dp_port_lock, flags);
 
/* check for throttle; if set, do not resubmit read urb */
/* indicate the read chain needs to be restarted on unthrottle */
@@ -1438,7 +1440,7 @@ static int digi_read_inb_callback(struct urb *urb)
tty_flip_buffer_push(port-port);
}
}
-   spin_unlock(priv-dp_port_lock);
+   spin_unlock_irqrestore(priv-dp_port_lock, flags);
 
if (opcode == DIGI_CMD_RECEIVE_DISABLE)
dev_dbg(port-dev, %s: got RECEIVE_DISABLE\n, __func__);
@@ -1469,6 +1471,7 @@ static int digi_read_oob_callback(struct urb *urb)
int opcode, line, status, val;
int i;
unsigned int rts;
+   unsigned long flags;
 
/* handle each oob command */
for (i = 0; i  urb-actual_length - 3;) {
@@ -1496,7 +1499,7 @@ static int digi_read_oob_callback(struct urb *urb)
rts = tty-termios.c_cflag  CRTSCTS;

if (tty  opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
-   spin_lock(priv-dp_port_lock);
+   spin_lock_irqsave(priv-dp_port_lock, flags);
/* convert from digi flags to termiox flags */
if (val  DIGI_READ_INPUT_SIGNALS_CTS) {
priv-dp_modem_signals |= TIOCM_CTS;
@@ -1524,12 +1527,12 @@ static int digi_read_oob_callback(struct urb *urb)
else
priv-dp_modem_signals = ~TIOCM_CD;
 
-   spin_unlock(priv-dp_port_lock);
+   spin_unlock_irqrestore(priv-dp_port_lock, flags);
} else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
-   spin_lock(priv-dp_port_lock);
+   spin_lock_irqsave(priv-dp_port_lock, flags);
priv-dp_transmit_idle = 1;
wake_up_interruptible(priv-dp_transmit_idle_wait);
-   spin_unlock(priv-dp_port_lock);
+   spin_unlock_irqrestore(priv-dp_port_lock, flags);
} else if (opcode == DIGI_CMD_IFLUSH_FIFO) {
wake_up_interruptible(priv-dp_flush_wait);
}
-- 
1.7.9.5

--
To unsubscribe from this list: send

[PATCH 10/50] USB: serial: cyberjack: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Matthias Bruestle and Harald Welte supp...@reiner-sct.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/cyberjack.c |   15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 7814262..0ab0957 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -271,11 +271,12 @@ static void cyberjack_read_int_callback(struct urb *urb)
/* React only to interrupts signaling a bulk_in transfer */
if (urb-actual_length == 4  data[0] == 0x01) {
short old_rdtodo;
+   unsigned long flags;
 
/* This is a announcement of coming bulk_ins. */
unsigned short size = ((unsigned short)data[3]8)+data[2]+3;
 
-   spin_lock(priv-lock);
+   spin_lock_irqsave(priv-lock, flags);
 
old_rdtodo = priv-rdtodo;
 
@@ -290,7 +291,7 @@ static void cyberjack_read_int_callback(struct urb *urb)
 
dev_dbg(dev, %s - rdtodo: %d\n, __func__, priv-rdtodo);
 
-   spin_unlock(priv-lock);
+   spin_unlock_irqrestore(priv-lock, flags);
 
if (!old_rdtodo) {
result = usb_submit_urb(port-read_urb, GFP_ATOMIC);
@@ -317,6 +318,7 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
short todo;
int result;
int status = urb-status;
+   unsigned long flags;
 
usb_serial_debug_data(dev, __func__, urb-actual_length, data);
if (status) {
@@ -330,7 +332,7 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
tty_flip_buffer_push(port-port);
}
 
-   spin_lock(priv-lock);
+   spin_lock_irqsave(priv-lock, flags);
 
/* Reduce urbs to do by one. */
priv-rdtodo -= urb-actual_length;
@@ -339,7 +341,7 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
priv-rdtodo = 0;
todo = priv-rdtodo;
 
-   spin_unlock(priv-lock);
+   spin_unlock_irqrestore(priv-lock, flags);
 
dev_dbg(dev, %s - rdtodo: %d\n, __func__, todo);
 
@@ -359,6 +361,7 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
struct cyberjack_private *priv = usb_get_serial_port_data(port);
struct device *dev = port-dev;
int status = urb-status;
+   unsigned long flags;
 
set_bit(0, port-write_urbs_free);
if (status) {
@@ -367,7 +370,7 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
return;
}
 
-   spin_lock(priv-lock);
+   spin_lock_irqsave(priv-lock, flags);
 
/* only do something if we have more data to send */
if (priv-wrfilled) {
@@ -411,7 +414,7 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
}
 
 exit:
-   spin_unlock(priv-lock);
+   spin_unlock_irqrestore(priv-lock, flags);
usb_serial_port_softint(port);
 }
 
-- 
1.7.9.5

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


[PATCH 07/50] USB: ldusb: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/misc/ldusb.c |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index ac76229..8bae18e 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -249,6 +249,7 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
unsigned int next_ring_head;
int status = urb-status;
int retval;
+   unsigned long flags;
 
if (status) {
if (status == -ENOENT ||
@@ -258,12 +259,12 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
} else {
dbg_info(dev-intf-dev, %s: nonzero status received: 
%d\n,
 __func__, status);
-   spin_lock(dev-rbsl);
+   spin_lock_irqsave(dev-rbsl, flags);
goto resubmit; /* maybe we can recover */
}
}
 
-   spin_lock(dev-rbsl);
+   spin_lock_irqsave(dev-rbsl, flags);
if (urb-actual_length  0) {
next_ring_head = (dev-ring_head+1) % ring_buffer_size;
if (next_ring_head != dev-ring_tail) {
@@ -292,7 +293,7 @@ resubmit:
dev-buffer_overflow = 1;
}
}
-   spin_unlock(dev-rbsl);
+   spin_unlock_irqrestore(dev-rbsl, flags);
 exit:
dev-interrupt_in_done = 1;
wake_up_interruptible(dev-read_wait);
-- 
1.7.9.5

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


[PATCH 16/50] USB: serial: quatech2: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/quatech2.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index d997432..95e5dbf 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -630,16 +630,17 @@ static void qt2_write_bulk_callback(struct urb *urb)
 {
struct usb_serial_port *port;
struct qt2_port_private *port_priv;
+   unsigned long flags;
 
port = urb-context;
port_priv = usb_get_serial_port_data(port);
 
-   spin_lock(port_priv-urb_lock);
+   spin_lock_irqsave(port_priv-urb_lock, flags);
 
port_priv-urb_in_use = false;
usb_serial_port_softint(port);
 
-   spin_unlock(port_priv-urb_lock);
+   spin_unlock_irqrestore(port_priv-urb_lock, flags);
 
 }
 
-- 
1.7.9.5

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


[PATCH 34/50] wireless: libertas_tf: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: John W. Linville linvi...@tuxdriver.com
Cc: libertas-...@lists.infradead.org
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/wireless/libertas_tf/if_usb.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/libertas_tf/if_usb.c 
b/drivers/net/wireless/libertas_tf/if_usb.c
index d576dd6..0e9e972 100644
--- a/drivers/net/wireless/libertas_tf/if_usb.c
+++ b/drivers/net/wireless/libertas_tf/if_usb.c
@@ -610,6 +610,8 @@ static inline void process_cmdrequest(int recvlength, 
uint8_t *recvbuff,
  struct if_usb_card *cardp,
  struct lbtf_private *priv)
 {
+   unsigned long flags;
+
if (recvlength  LBS_CMD_BUFFER_SIZE) {
lbtf_deb_usbd(cardp-udev-dev,
 The receive buffer is too large\n);
@@ -619,12 +621,12 @@ static inline void process_cmdrequest(int recvlength, 
uint8_t *recvbuff,
 
BUG_ON(!in_interrupt());
 
-   spin_lock(priv-driver_lock);
+   spin_lock_irqsave(priv-driver_lock, flags);
memcpy(priv-cmd_resp_buff, recvbuff + MESSAGE_HEADER_LEN,
   recvlength - MESSAGE_HEADER_LEN);
kfree_skb(skb);
lbtf_cmd_response_rx(priv);
-   spin_unlock(priv-driver_lock);
+   spin_unlock_irqrestore(priv-driver_lock, flags);
 }
 
 /**
-- 
1.7.9.5

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


[PATCH 20/50] USB: serial: usb_wwan: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/usb_wwan.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 8257d30..c807d65 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -312,6 +312,7 @@ static void usb_wwan_outdat_callback(struct urb *urb)
struct usb_wwan_port_private *portdata;
struct usb_wwan_intf_private *intfdata;
int i;
+   unsigned long flags;
 
port = urb-context;
intfdata = port-serial-private;
@@ -319,9 +320,9 @@ static void usb_wwan_outdat_callback(struct urb *urb)
usb_serial_port_softint(port);
usb_autopm_put_interface_async(port-serial-interface);
portdata = usb_get_serial_port_data(port);
-   spin_lock(intfdata-susp_lock);
+   spin_lock_irqsave(intfdata-susp_lock, flags);
intfdata-in_flight--;
-   spin_unlock(intfdata-susp_lock);
+   spin_unlock_irqrestore(intfdata-susp_lock, flags);
 
for (i = 0; i  N_OUT_URB; ++i) {
if (portdata-out_urbs[i] == urb) {
-- 
1.7.9.5

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


[PATCH 36/50] media: usb: em28xx: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/em28xx/em28xx-core.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index fc157af..0d698f9 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -941,6 +941,7 @@ static void em28xx_irq_callback(struct urb *urb)
 {
struct em28xx *dev = urb-context;
int i;
+   unsigned long flags;
 
switch (urb-status) {
case 0: /* success */
@@ -956,9 +957,9 @@ static void em28xx_irq_callback(struct urb *urb)
}
 
/* Copy data from URB */
-   spin_lock(dev-slock);
+   spin_lock_irqsave(dev-slock, flags);
dev-usb_ctl.urb_data_copy(dev, urb);
-   spin_unlock(dev-slock);
+   spin_unlock_irqrestore(dev-slock, flags);
 
/* Reset urb buffers */
for (i = 0; i  urb-number_of_packets; i++) {
-- 
1.7.9.5

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


[PATCH 24/50] input: cm109: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Dmitry Torokhov dmitry.torok...@gmail.com
Cc: linux-in...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/input/misc/cm109.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/input/misc/cm109.c b/drivers/input/misc/cm109.c
index 082684e..cac4e37 100644
--- a/drivers/input/misc/cm109.c
+++ b/drivers/input/misc/cm109.c
@@ -340,6 +340,7 @@ static void cm109_urb_irq_callback(struct urb *urb)
struct cm109_dev *dev = urb-context;
const int status = urb-status;
int error;
+   unsigned long flags;
 
dev_dbg(dev-intf-dev, ### URB IRQ: [0x%02x 0x%02x 0x%02x 0x%02x] 
keybit=0x%02x\n,
 dev-irq_data-byte[0],
@@ -379,7 +380,7 @@ static void cm109_urb_irq_callback(struct urb *urb)
 
  out:
 
-   spin_lock(dev-ctl_submit_lock);
+   spin_lock_irqsave(dev-ctl_submit_lock, flags);
 
dev-irq_urb_pending = 0;
 
@@ -403,7 +404,7 @@ static void cm109_urb_irq_callback(struct urb *urb)
__func__, error);
}
 
-   spin_unlock(dev-ctl_submit_lock);
+   spin_unlock_irqrestore(dev-ctl_submit_lock, flags);
 }
 
 static void cm109_urb_ctl_callback(struct urb *urb)
@@ -411,6 +412,7 @@ static void cm109_urb_ctl_callback(struct urb *urb)
struct cm109_dev *dev = urb-context;
const int status = urb-status;
int error;
+   unsigned long flags;
 
dev_dbg(dev-intf-dev, ### URB CTL: [0x%02x 0x%02x 0x%02x 0x%02x]\n,
 dev-ctl_data-byte[0],
@@ -421,7 +423,7 @@ static void cm109_urb_ctl_callback(struct urb *urb)
if (status)
dev_err(dev-intf-dev, %s: urb status %d\n, __func__, 
status);
 
-   spin_lock(dev-ctl_submit_lock);
+   spin_lock_irqsave(dev-ctl_submit_lock, flags);
 
dev-ctl_urb_pending = 0;
 
@@ -442,7 +444,7 @@ static void cm109_urb_ctl_callback(struct urb *urb)
}
}
 
-   spin_unlock(dev-ctl_submit_lock);
+   spin_unlock_irqrestore(dev-ctl_submit_lock, flags);
 }
 
 static void cm109_toggle_buzzer_async(struct cm109_dev *dev)
-- 
1.7.9.5

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


[PATCH 15/50] USB: serial: mos77840: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/mos7840.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 0a818b2..f21dcd0 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -788,17 +788,18 @@ static void mos7840_bulk_out_data_callback(struct urb 
*urb)
struct usb_serial_port *port;
int status = urb-status;
int i;
+   unsigned long flags;
 
mos7840_port = urb-context;
port = mos7840_port-port;
-   spin_lock(mos7840_port-pool_lock);
+   spin_lock_irqsave(mos7840_port-pool_lock, flags);
for (i = 0; i  NUM_URBS; i++) {
if (urb == mos7840_port-write_urb_pool[i]) {
mos7840_port-busy[i] = 0;
break;
}
}
-   spin_unlock(mos7840_port-pool_lock);
+   spin_unlock_irqrestore(mos7840_port-pool_lock, flags);
 
if (status) {
dev_dbg(port-dev, nonzero write bulk status received:%d\n, 
status);
-- 
1.7.9.5

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


[PATCH 29/50] USBNET: rtl8150: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/usb/rtl8150.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 6cbdac6..199e0fb 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -372,6 +372,7 @@ static void read_bulk_callback(struct urb *urb)
u16 rx_stat;
int status = urb-status;
int result;
+   unsigned long flags;
 
dev = urb-context;
if (!dev)
@@ -413,9 +414,9 @@ static void read_bulk_callback(struct urb *urb)
netdev-stats.rx_packets++;
netdev-stats.rx_bytes += pkt_len;
 
-   spin_lock(dev-rx_pool_lock);
+   spin_lock_irqsave(dev-rx_pool_lock, flags);
skb = pull_skb(dev);
-   spin_unlock(dev-rx_pool_lock);
+   spin_unlock_irqrestore(dev-rx_pool_lock, flags);
if (!skb)
goto resched;
 
-- 
1.7.9.5

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


[PATCH 17/50] USB: serial: sierra: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/sierra.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index de958c5..e79b6ad 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -433,6 +433,7 @@ static void sierra_outdat_callback(struct urb *urb)
struct sierra_port_private *portdata = usb_get_serial_port_data(port);
struct sierra_intf_private *intfdata;
int status = urb-status;
+   unsigned long flags;
 
intfdata = port-serial-private;
 
@@ -443,12 +444,12 @@ static void sierra_outdat_callback(struct urb *urb)
dev_dbg(port-dev, %s - nonzero write bulk status 
received: %d\n, __func__, status);
 
-   spin_lock(portdata-lock);
+   spin_lock_irqsave(portdata-lock, flags);
--portdata-outstanding_urbs;
-   spin_unlock(portdata-lock);
-   spin_lock(intfdata-susp_lock);
+   spin_unlock_irqrestore(portdata-lock, flags);
+   spin_lock_irqsave(intfdata-susp_lock, flags);
--intfdata-in_flight;
-   spin_unlock(intfdata-susp_lock);
+   spin_unlock_irqrestore(intfdata-susp_lock, flags);
 
usb_serial_port_softint(port);
 }
-- 
1.7.9.5

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


[PATCH 33/50] wireless: libertas: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: John W. Linville linvi...@tuxdriver.com
Cc: libertas-...@lists.infradead.org
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/wireless/libertas/if_usb.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/libertas/if_usb.c 
b/drivers/net/wireless/libertas/if_usb.c
index 2798077..f6a8396 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -626,6 +626,7 @@ static inline void process_cmdrequest(int recvlength, 
uint8_t *recvbuff,
  struct lbs_private *priv)
 {
u8 i;
+   unsigned long flags;
 
if (recvlength  LBS_CMD_BUFFER_SIZE) {
lbs_deb_usbd(cardp-udev-dev,
@@ -636,7 +637,7 @@ static inline void process_cmdrequest(int recvlength, 
uint8_t *recvbuff,
 
BUG_ON(!in_interrupt());
 
-   spin_lock(priv-driver_lock);
+   spin_lock_irqsave(priv-driver_lock, flags);
 
i = (priv-resp_idx == 0) ? 1 : 0;
BUG_ON(priv-resp_len[i]);
@@ -646,7 +647,7 @@ static inline void process_cmdrequest(int recvlength, 
uint8_t *recvbuff,
kfree_skb(skb);
lbs_notify_command_response(priv, i);
 
-   spin_unlock(priv-driver_lock);
+   spin_unlock_irqrestore(priv-driver_lock, flags);
 
lbs_deb_usbd(cardp-udev-dev,
Wake up main thread to handle cmd response\n);
-- 
1.7.9.5

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


[PATCH 47/50] staging: btmtk_usb: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: de...@driverdev.osuosl.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/staging/btmtk_usb/btmtk_usb.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/btmtk_usb/btmtk_usb.c 
b/drivers/staging/btmtk_usb/btmtk_usb.c
index 0e783e8..ea10d4f 100644
--- a/drivers/staging/btmtk_usb/btmtk_usb.c
+++ b/drivers/staging/btmtk_usb/btmtk_usb.c
@@ -1218,6 +1218,7 @@ static void btmtk_usb_tx_complete(struct urb *urb)
struct sk_buff *skb = urb-context;
struct hci_dev *hdev = (struct hci_dev *)skb-dev;
struct btmtk_usb_data *data = hci_get_drvdata(hdev);
+   unsigned long flags;
 
BT_DBG(%s: %s urb %p status %d count %d\n, __func__, hdev-name,
urb, urb-status, urb-actual_length);
@@ -1231,9 +1232,9 @@ static void btmtk_usb_tx_complete(struct urb *urb)
hdev-stat.err_tx++;
 
 done:
-   spin_lock(data-txlock);
+   spin_lock_irqsave(data-txlock, flags);
data-tx_in_flight--;
-   spin_unlock(data-txlock);
+   spin_unlock_irqrestore(data-txlock, flags);
 
kfree(urb-setup_packet);
 
-- 
1.7.9.5

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


[PATCH 32/50] wireless: ath: carl9170: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Christian Lamparter chunk...@googlemail.com
Cc: John W. Linville linvi...@tuxdriver.com
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/wireless/ath/carl9170/rx.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/carl9170/rx.c 
b/drivers/net/wireless/ath/carl9170/rx.c
index 4684dd9..61f62a6 100644
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -129,6 +129,7 @@ static int carl9170_check_sequence(struct ar9170 *ar, 
unsigned int seq)
 
 static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
 {
+   unsigned long flags;
/*
 * Some commands may have a variable response length
 * and we cannot predict the correct length in advance.
@@ -148,7 +149,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 
len, void *buffer)
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
}
 
-   spin_lock(ar-cmd_lock);
+   spin_lock_irqsave(ar-cmd_lock, flags);
if (ar-readbuf) {
if (len = 4)
memcpy(ar-readbuf, buffer + 4, len - 4);
@@ -156,7 +157,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 
len, void *buffer)
ar-readbuf = NULL;
}
complete(ar-cmd_wait);
-   spin_unlock(ar-cmd_lock);
+   spin_unlock_irqrestore(ar-cmd_lock, flags);
 }
 
 void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
-- 
1.7.9.5

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


[PATCH 13/50] USB: serial: io_ti: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/io_ti.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 60054e7..4943194 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -1615,6 +1615,7 @@ static void edge_bulk_in_callback(struct urb *urb)
int retval = 0;
int port_number;
int status = urb-status;
+   unsigned long flags;
 
switch (status) {
case 0:
@@ -1663,13 +1664,13 @@ static void edge_bulk_in_callback(struct urb *urb)
 
 exit:
/* continue read unless stopped */
-   spin_lock(edge_port-ep_lock);
+   spin_lock_irqsave(edge_port-ep_lock, flags);
if (edge_port-ep_read_urb_state == EDGE_READ_URB_RUNNING)
retval = usb_submit_urb(urb, GFP_ATOMIC);
else if (edge_port-ep_read_urb_state == EDGE_READ_URB_STOPPING)
edge_port-ep_read_urb_state = EDGE_READ_URB_STOPPED;
 
-   spin_unlock(edge_port-ep_lock);
+   spin_unlock_irqrestore(edge_port-ep_lock, flags);
if (retval)
dev_err(dev, %s - usb_submit_urb failed with result %d\n, 
__func__, retval);
 }
-- 
1.7.9.5

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


[PATCH 25/50] ISDN: hfcsusb: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Karsten Keil i...@linux-pingi.de
Cc: David S. Miller da...@davemloft.net
Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/isdn/hardware/mISDN/hfcsusb.c |   36 ++---
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c 
b/drivers/isdn/hardware/mISDN/hfcsusb.c
index 114f3bc..082f9e0 100644
--- a/drivers/isdn/hardware/mISDN/hfcsusb.c
+++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
@@ -819,6 +819,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
int fifon = fifo-fifonum;
int i;
int hdlc = 0;
+   unsigned long   flags;
 
if (debug  DBG_HFC_CALL_TRACE)
printk(KERN_DEBUG %s: %s: fifo(%i) len(%i) 
@@ -835,7 +836,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
return;
}
 
-   spin_lock(hw-lock);
+   spin_lock_irqsave(hw-lock, flags);
if (fifo-dch) {
rx_skb = fifo-dch-rx_skb;
maxlen = fifo-dch-maxlen;
@@ -844,7 +845,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
if (fifo-bch) {
if (test_bit(FLG_RX_OFF, fifo-bch-Flags)) {
fifo-bch-dropcnt += len;
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
return;
}
maxlen = bchannel_get_rxbuf(fifo-bch, len);
@@ -854,7 +855,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
skb_trim(rx_skb, 0);
pr_warning(%s.B%d: No bufferspace for %d bytes\n,
   hw-name, fifo-bch-nr, len);
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
return;
}
maxlen = fifo-bch-maxlen;
@@ -878,7 +879,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
} else {
printk(KERN_DEBUG %s: %s: No mem for rx_skb\n,
   hw-name, __func__);
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
return;
}
}
@@ -888,7 +889,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
   for fifo(%d) HFCUSB_D_RX\n,
   hw-name, __func__, fifon);
skb_trim(rx_skb, 0);
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
return;
}
}
@@ -942,7 +943,7 @@ hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, 
unsigned int len,
/* deliver transparent data to layer2 */
recv_Bchannel(fifo-bch, MISDN_ID_ANY, false);
}
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
 }
 
 static void
@@ -979,18 +980,19 @@ rx_iso_complete(struct urb *urb)
__u8 *buf;
static __u8 eof[8];
__u8 s0_state;
+   unsigned long flags;
 
fifon = fifo-fifonum;
status = urb-status;
 
-   spin_lock(hw-lock);
+   spin_lock_irqsave(hw-lock, flags);
if (fifo-stop_gracefull) {
fifo-stop_gracefull = 0;
fifo-active = 0;
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
return;
}
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
 
/*
 * ISO transfer only partially completed,
@@ -1096,15 +1098,16 @@ rx_int_complete(struct urb *urb)
struct usb_fifo *fifo = (struct usb_fifo *) urb-context;
struct hfcsusb *hw = fifo-hw;
static __u8 eof[8];
+   unsigned long flags;
 
-   spin_lock(hw-lock);
+   spin_lock_irqsave(hw-lock, flags);
if (fifo-stop_gracefull) {
fifo-stop_gracefull = 0;
fifo-active = 0;
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
return;
}
-   spin_unlock(hw-lock);
+   spin_unlock_irqrestore(hw-lock, flags);
 
fifon = fifo-fifonum;
if ((!fifo-active) || (urb-status)) {
@@ -1172,12 +1175,13 @@ tx_iso_complete(struct urb *urb)
int *tx_idx;
int frame_complete, fifon, status, fillempty = 0;
__u8 threshbit, *p;
+   unsigned long flags;
 
-   spin_lock(hw-lock);
+   spin_lock_irqsave(hw-lock, flags);
if (fifo

[PATCH 26/50] USBNET: cdc-phonet: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/usb/cdc-phonet.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/cdc-phonet.c b/drivers/net/usb/cdc-phonet.c
index 7d78669..413ec32 100644
--- a/drivers/net/usb/cdc-phonet.c
+++ b/drivers/net/usb/cdc-phonet.c
@@ -99,6 +99,7 @@ static void tx_complete(struct urb *req)
struct net_device *dev = skb-dev;
struct usbpn_dev *pnd = netdev_priv(dev);
int status = req-status;
+   unsigned long flags;
 
switch (status) {
case 0:
@@ -115,10 +116,10 @@ static void tx_complete(struct urb *req)
}
dev-stats.tx_packets++;
 
-   spin_lock(pnd-tx_lock);
+   spin_lock_irqsave(pnd-tx_lock, flags);
pnd-tx_queue--;
netif_wake_queue(dev);
-   spin_unlock(pnd-tx_lock);
+   spin_unlock_irqrestore(pnd-tx_lock, flags);
 
dev_kfree_skb_any(skb);
usb_free_urb(req);
-- 
1.7.9.5

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


[PATCH 35/50] media: usb: cx231xx: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: Hans Verkuil hans.verk...@cisco.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/cx231xx/cx231xx-audio.c |6 ++
 drivers/media/usb/cx231xx/cx231xx-core.c  |   10 ++
 drivers/media/usb/cx231xx/cx231xx-vbi.c   |5 +++--
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c 
b/drivers/media/usb/cx231xx/cx231xx-audio.c
index 81a1d97..58c1b5c 100644
--- a/drivers/media/usb/cx231xx/cx231xx-audio.c
+++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
@@ -136,6 +136,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
stride = runtime-frame_bits  3;
 
for (i = 0; i  urb-number_of_packets; i++) {
+   unsigned long flags;
int length = urb-iso_frame_desc[i].actual_length /
 stride;
cp = (unsigned char *)urb-transfer_buffer +
@@ -158,6 +159,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
   length * stride);
}
 
+   local_irq_save(flags);
snd_pcm_stream_lock(substream);
 
dev-adev.hwptr_done_capture += length;
@@ -174,6 +176,7 @@ static void cx231xx_audio_isocirq(struct urb *urb)
period_elapsed = 1;
}
snd_pcm_stream_unlock(substream);
+   local_irq_restore(flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
@@ -224,6 +227,7 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
stride = runtime-frame_bits  3;
 
if (1) {
+   unsigned long flags;
int length = urb-actual_length /
 stride;
cp = (unsigned char *)urb-transfer_buffer;
@@ -242,6 +246,7 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
   length * stride);
}
 
+   local_irq_save(flags);
snd_pcm_stream_lock(substream);
 
dev-adev.hwptr_done_capture += length;
@@ -258,6 +263,7 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
period_elapsed = 1;
}
snd_pcm_stream_unlock(substream);
+   local_irq_restore(flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c 
b/drivers/media/usb/cx231xx/cx231xx-core.c
index 4ba3ce0..593b397 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -798,6 +798,7 @@ static void cx231xx_isoc_irq_callback(struct urb *urb)
container_of(dma_q, struct cx231xx_video_mode, vidq);
struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode);
int i;
+   unsigned long flags;
 
switch (urb-status) {
case 0: /* success */
@@ -813,9 +814,9 @@ static void cx231xx_isoc_irq_callback(struct urb *urb)
}
 
/* Copy data from URB */
-   spin_lock(dev-video_mode.slock);
+   spin_lock_irqsave(dev-video_mode.slock, flags);
dev-video_mode.isoc_ctl.isoc_copy(dev, urb);
-   spin_unlock(dev-video_mode.slock);
+   spin_unlock_irqrestore(dev-video_mode.slock, flags);
 
/* Reset urb buffers */
for (i = 0; i  urb-number_of_packets; i++) {
@@ -842,6 +843,7 @@ static void cx231xx_bulk_irq_callback(struct urb *urb)
struct cx231xx_video_mode *vmode =
container_of(dma_q, struct cx231xx_video_mode, vidq);
struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode);
+   unsigned long flags;
 
switch (urb-status) {
case 0: /* success */
@@ -857,9 +859,9 @@ static void cx231xx_bulk_irq_callback(struct urb *urb)
}
 
/* Copy data from URB */
-   spin_lock(dev-video_mode.slock);
+   spin_lock_irqsave(dev-video_mode.slock, flags);
dev-video_mode.bulk_ctl.bulk_copy(dev, urb);
-   spin_unlock(dev-video_mode.slock);
+   spin_unlock_irqrestore(dev-video_mode.slock, flags);
 
/* Reset urb buffers */
urb-status = usb_submit_urb(urb, GFP_ATOMIC);
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c 
b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index c027942..38e78f8 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -306,6 +306,7 @@ static void cx231xx_irq_vbi_callback(struct urb *urb

[PATCH 41/50] media: usb: em28xx: make sure irq disabled before acquiring lock

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so add local_irq_save()
before acquiring the lock without irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/em28xx/em28xx-audio.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index 2fdb66e..dca53ec 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -113,6 +113,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
stride = runtime-frame_bits  3;
 
for (i = 0; i  urb-number_of_packets; i++) {
+   unsigned long flags;
int length =
urb-iso_frame_desc[i].actual_length / stride;
cp = (unsigned char *)urb-transfer_buffer +
@@ -134,6 +135,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
   length * stride);
}
 
+   local_irq_save(flags);
snd_pcm_stream_lock(substream);
 
dev-adev.hwptr_done_capture += length;
@@ -151,6 +153,7 @@ static void em28xx_audio_isocirq(struct urb *urb)
}
 
snd_pcm_stream_unlock(substream);
+   local_irq_restore(flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
-- 
1.7.9.5

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


[PATCH 50/50] staging: vt6656: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: de...@driverdev.osuosl.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/staging/vt6656/usbpipe.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index 098be60..0282f2e 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -485,6 +485,7 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
int bIndicateReceive = false;
int bReAllocSkb = false;
int status;
+   unsigned long flags;
 
 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFOs_nsBulkInUsbIoCompleteRead\n);
 status = urb-status;
@@ -515,18 +516,18 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
 STAvUpdateUSBCounter(pDevice-scStatistic.USB_BulkInStat, status);
 
 if (bIndicateReceive) {
-spin_lock(pDevice-lock);
+spin_lock_irqsave(pDevice-lock, flags);
 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == true)
 bReAllocSkb = true;
-spin_unlock(pDevice-lock);
+spin_unlock_irqrestore(pDevice-lock, flags);
 }
 pRCB-Ref--;
 if (pRCB-Ref == 0)
 {
 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFORxvFreeNormal %d 
\n,pDevice-NumRecvFreeList);
-spin_lock(pDevice-lock);
+spin_lock_irqsave(pDevice-lock, flags);
 RXvFreeRCB(pRCB, bReAllocSkb);
-spin_unlock(pDevice-lock);
+spin_unlock_irqrestore(pDevice-lock, flags);
 }
 
 return;
-- 
1.7.9.5

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


[PATCH 43/50] sound: usb: midi: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Jaroslav Kysela pe...@perex.cz
Cc: Takashi Iwai ti...@suse.de
Cc: Clemens Ladisch clem...@ladisch.de
Cc: alsa-de...@alsa-project.org
Signed-off-by: Ming Lei ming@canonical.com
---
 sound/usb/midi.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index b901f46..86af276 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -279,15 +279,16 @@ static void snd_usbmidi_out_urb_complete(struct urb* urb)
struct out_urb_context *context = urb-context;
struct snd_usb_midi_out_endpoint* ep = context-ep;
unsigned int urb_index;
+   unsigned long flags;
 
-   spin_lock(ep-buffer_lock);
+   spin_lock_irqsave(ep-buffer_lock, flags);
urb_index = context - ep-urbs;
ep-active_urbs = ~(1  urb_index);
if (unlikely(ep-drain_urbs)) {
ep-drain_urbs = ~(1  urb_index);
wake_up(ep-drain_wait);
}
-   spin_unlock(ep-buffer_lock);
+   spin_unlock_irqrestore(ep-buffer_lock, flags);
if (urb-status  0) {
int err = snd_usbmidi_urb_error(urb-status);
if (err  0) {
-- 
1.7.9.5

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


[PATCH 39/50] media: usb: tm6000: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/tm6000/tm6000-video.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/tm6000/tm6000-video.c 
b/drivers/media/usb/tm6000/tm6000-video.c
index cc1aa14..8bb440f 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -434,6 +434,7 @@ static void tm6000_irq_callback(struct urb *urb)
struct tm6000_dmaqueue  *dma_q = urb-context;
struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
int i;
+   unsigned long flags;
 
switch (urb-status) {
case 0:
@@ -450,9 +451,9 @@ static void tm6000_irq_callback(struct urb *urb)
break;
}
 
-   spin_lock(dev-slock);
+   spin_lock_irqsave(dev-slock, flags);
tm6000_isoc_copy(urb);
-   spin_unlock(dev-slock);
+   spin_unlock_irqrestore(dev-slock, flags);
 
/* Reset urb buffers */
for (i = 0; i  urb-number_of_packets; i++) {
-- 
1.7.9.5

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


[PATCH 48/50] staging: bcm: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: de...@driverdev.osuosl.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/staging/bcm/InterfaceRx.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/bcm/InterfaceRx.c 
b/drivers/staging/bcm/InterfaceRx.c
index 26f5bc7..00af901 100644
--- a/drivers/staging/bcm/InterfaceRx.c
+++ b/drivers/staging/bcm/InterfaceRx.c
@@ -47,6 +47,7 @@ static void read_bulk_callback(struct urb *urb)
struct bcm_interface_adapter *psIntfAdapter = pRcb-psIntfAdapter;
struct bcm_mini_adapter *Adapter = psIntfAdapter-psAdapter;
struct bcm_leader *pLeader = urb-transfer_buffer;
+   unsigned long flags;
 
if (unlikely(netif_msg_rx_status(Adapter)))
pr_info(PFX %s: rx urb status %d length %d\n,
@@ -129,9 +130,9 @@ static void read_bulk_callback(struct urb *urb)
(sizeof(struct bcm_leader)), pLeader-PLength);
skb-len = pLeader-PLength + sizeof(USHORT);
 
-   spin_lock(Adapter-control_queue_lock);
+   spin_lock_irqsave(Adapter-control_queue_lock, flags);

ENQUEUEPACKET(Adapter-RxControlHead,Adapter-RxControlTail,skb);
-   spin_unlock(Adapter-control_queue_lock);
+   spin_unlock_irqretore(Adapter-control_queue_lock, flags);
 
atomic_inc(Adapter-cntrlpktCnt);
wake_up(Adapter-process_rx_cntrlpkt);
-- 
1.7.9.5

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


[PATCH 38/50] media: usb: tlg2300: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/tlg2300/pd-video.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/tlg2300/pd-video.c 
b/drivers/media/usb/tlg2300/pd-video.c
index 8df668d..4e5bd07 100644
--- a/drivers/media/usb/tlg2300/pd-video.c
+++ b/drivers/media/usb/tlg2300/pd-video.c
@@ -151,11 +151,12 @@ static void init_copy(struct video_data *video, bool 
index)
 static bool get_frame(struct front_face *front, int *need_init)
 {
struct videobuf_buffer *vb = front-curr_frame;
+   unsigned long flags;
 
if (vb)
return true;
 
-   spin_lock(front-queue_lock);
+   spin_lock_irqsave(front-queue_lock, flags);
if (!list_empty(front-active)) {
vb = list_entry(front-active.next,
   struct videobuf_buffer, queue);
@@ -164,7 +165,7 @@ static bool get_frame(struct front_face *front, int 
*need_init)
front-curr_frame = vb;
list_del_init(vb-queue);
}
-   spin_unlock(front-queue_lock);
+   spin_unlock_irqrestore(front-queue_lock, flags);
 
return !!vb;
 }
-- 
1.7.9.5

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


[PATCH 45/50] sound: usb: usx2y: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Jaroslav Kysela pe...@perex.cz
Cc: Takashi Iwai ti...@suse.de
Cc: alsa-de...@alsa-project.org
Signed-off-by: Ming Lei ming@canonical.com
---
 sound/usb/usx2y/usbusx2yaudio.c |4 
 1 file changed, 4 insertions(+)

diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 4967fe9..e2ee893 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -273,7 +273,11 @@ static void usX2Y_clients_stop(struct usX2Ydev *usX2Y)
struct snd_usX2Y_substream *subs = usX2Y-subs[s];
if (subs) {
if (atomic_read(subs-state) = state_PRERUNNING) {
+   unsigned long flags;
+
+   local_irq_save(flags);
snd_pcm_stop(subs-pcm_substream, 
SNDRV_PCM_STATE_XRUN);
+   local_irq_restore(flags);
}
for (u = 0; u  NRURBS; u++) {
struct urb *urb = subs-urb[u];
-- 
1.7.9.5

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


[PATCH 44/50] sound: usb: caiaq: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Daniel Mack zon...@gmail.com
Cc: Jaroslav Kysela pe...@perex.cz
Cc: Takashi Iwai ti...@suse.de
Cc: alsa-de...@alsa-project.org
Signed-off-by: Ming Lei ming@canonical.com
---
 sound/usb/caiaq/audio.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 7103b09..e5675ab 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -672,10 +672,11 @@ static void read_completed(struct urb *urb)
offset += len;
 
if (len  0) {
-   spin_lock(cdev-spinlock);
+   unsigned long flags;
+   spin_lock_irqsave(cdev-spinlock, flags);
fill_out_urb(cdev, out, out-iso_frame_desc[outframe]);
read_in_urb(cdev, urb, urb-iso_frame_desc[frame]);
-   spin_unlock(cdev-spinlock);
+   spin_unlock_irqrestore(cdev-spinlock, flags);
check_for_elapsed_periods(cdev, cdev-sub_playback);
check_for_elapsed_periods(cdev, cdev-sub_capture);
send_it = 1;
-- 
1.7.9.5

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


[PATCH 42/50] media: usb: tlg2300: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so disable local
interrupt before holding a global lock which is held without
irqsave.

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/tlg2300/pd-alsa.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/usb/tlg2300/pd-alsa.c 
b/drivers/media/usb/tlg2300/pd-alsa.c
index 3f3e141..cbccc96 100644
--- a/drivers/media/usb/tlg2300/pd-alsa.c
+++ b/drivers/media/usb/tlg2300/pd-alsa.c
@@ -141,6 +141,7 @@ static inline void handle_audio_data(struct urb *urb, int 
*period_elapsed)
int len = urb-actual_length / stride;
unsigned char *cp   = urb-transfer_buffer;
unsigned int oldptr = pa-rcv_position;
+   unsigned long flags;
 
if (urb-actual_length == AUDIO_BUF_SIZE - 4)
len -= (AUDIO_TRAILER_SIZE / stride);
@@ -156,6 +157,7 @@ static inline void handle_audio_data(struct urb *urb, int 
*period_elapsed)
memcpy(runtime-dma_area + oldptr * stride, cp, len * stride);
 
/* update the statas */
+   local_irq_save(flags);
snd_pcm_stream_lock(pa-capture_pcm_substream);
pa-rcv_position+= len;
if (pa-rcv_position = runtime-buffer_size)
@@ -167,6 +169,7 @@ static inline void handle_audio_data(struct urb *urb, int 
*period_elapsed)
*period_elapsed = 1;
}
snd_pcm_stream_unlock(pa-capture_pcm_substream);
+   local_irq_restore(flags);
 }
 
 static void complete_handler_audio(struct urb *urb)
-- 
1.7.9.5

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


[PATCH 46/50] Sound: usb: ua101: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so disable local
interrupt before holding a global lock which is held without irqsave.

Cc: Clemens Ladisch clem...@ladisch.de
Cc: Jaroslav Kysela pe...@perex.cz
Cc: Takashi Iwai ti...@suse.de
Cc: alsa-de...@alsa-project.org
Signed-off-by: Ming Lei ming@canonical.com
---
 sound/usb/misc/ua101.c |   14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/sound/usb/misc/ua101.c b/sound/usb/misc/ua101.c
index 8b5d2c5..52a60c6 100644
--- a/sound/usb/misc/ua101.c
+++ b/sound/usb/misc/ua101.c
@@ -613,14 +613,24 @@ static int start_usb_playback(struct ua101 *ua)
 
 static void abort_alsa_capture(struct ua101 *ua)
 {
-   if (test_bit(ALSA_CAPTURE_RUNNING, ua-states))
+   if (test_bit(ALSA_CAPTURE_RUNNING, ua-states)) {
+   unsigned long flags;
+
+   local_irq_save(flags);
snd_pcm_stop(ua-capture.substream, SNDRV_PCM_STATE_XRUN);
+   local_irq_restore(flags);
+   }
 }
 
 static void abort_alsa_playback(struct ua101 *ua)
 {
-   if (test_bit(ALSA_PLAYBACK_RUNNING, ua-states))
+   if (test_bit(ALSA_PLAYBACK_RUNNING, ua-states)) {
+   unsigned long flags;
+
+   local_irq_save(flags);
snd_pcm_stop(ua-playback.substream, SNDRV_PCM_STATE_XRUN);
+   local_irq_restore(flags);
+   }
 }
 
 static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream,
-- 
1.7.9.5

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


[PATCH 04/50] USB: adutux: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Lisa Nguyen l...@xenapiadmin.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/misc/adutux.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index eb3c8c1..387c75e 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -195,12 +195,13 @@ static void adu_interrupt_in_callback(struct urb *urb)
 {
struct adu_device *dev = urb-context;
int status = urb-status;
+   unsigned long flags;
 
dbg(4,  %s : enter, status %d, __func__, status);
adu_debug_data(5, __func__, urb-actual_length,
   urb-transfer_buffer);
 
-   spin_lock(dev-buflock);
+   spin_lock_irqsave(dev-buflock, flags);
 
if (status != 0) {
if ((status != -ENOENT)  (status != -ECONNRESET) 
@@ -229,7 +230,7 @@ static void adu_interrupt_in_callback(struct urb *urb)
 
 exit:
dev-read_urb_finished = 1;
-   spin_unlock(dev-buflock);
+   spin_unlock_irqrestore(dev-buflock, flags);
/* always wake up so we recover from errors */
wake_up_interruptible(dev-read_wait);
adu_debug_data(5, __func__, urb-actual_length,
@@ -241,6 +242,7 @@ static void adu_interrupt_out_callback(struct urb *urb)
 {
struct adu_device *dev = urb-context;
int status = urb-status;
+   unsigned long flags;
 
dbg(4,  %s : enter, status %d, __func__, status);
adu_debug_data(5, __func__, urb-actual_length, urb-transfer_buffer);
@@ -254,10 +256,10 @@ static void adu_interrupt_out_callback(struct urb *urb)
goto exit;
}
 
-   spin_lock(dev-buflock);
+   spin_lock_irqsave(dev-buflock, flags);
dev-out_urb_finished = 1;
wake_up(dev-write_wait);
-   spin_unlock(dev-buflock);
+   spin_unlock_irqrestore(dev-buflock, flags);
 exit:
 
adu_debug_data(5, __func__, urb-actual_length,
-- 
1.7.9.5

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


[PATCH 05/50] USB: misc: uss720: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/misc/uss720.c |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index e129cf6..f7d15e8 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -121,6 +121,7 @@ static void async_complete(struct urb *urb)
dev_err(urb-dev-dev, async_complete: urb error %d\n,
status);
} else if (rq-dr.bRequest == 3) {
+   unsigned long flags;
memcpy(priv-reg, rq-reg, sizeof(priv-reg));
 #if 0
dev_dbg(priv-usbdev-dev,
@@ -131,8 +132,11 @@ static void async_complete(struct urb *urb)
(unsigned int)priv-reg[6]);
 #endif
/* if nAck interrupts are enabled and we have an interrupt, 
call the interrupt procedure */
-   if (rq-reg[2]  rq-reg[1]  0x10  pp)
+   if (rq-reg[2]  rq-reg[1]  0x10  pp) {
+   local_irq_save(flags);
parport_generic_irq(pp);
+   local_irq_restore(flags);
+   }
}
complete(rq-compl);
kref_put(rq-ref_count, destroy_async);
-- 
1.7.9.5

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


[PATCH 49/50] staging: ced1401: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: de...@driverdev.osuosl.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/staging/ced1401/usb1401.c |   35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/ced1401/usb1401.c 
b/drivers/staging/ced1401/usb1401.c
index 97c55f9..70d2f43 100644
--- a/drivers/staging/ced1401/usb1401.c
+++ b/drivers/staging/ced1401/usb1401.c
@@ -265,6 +265,7 @@ static void ced_writechar_callback(struct urb *pUrb)
 {
DEVICE_EXTENSION *pdx = pUrb-context;
int nGot = pUrb-actual_length; /*  what we transferred */
+   unsigned long flags;
 
if (pUrb-status) { /*  sync/async unlink faults aren't errors */
if (!
@@ -275,24 +276,24 @@ static void ced_writechar_callback(struct urb *pUrb)
__func__, pUrb-status);
}
 
-   spin_lock(pdx-err_lock);
+   spin_lock_irqsave(pdx-err_lock, flags);
pdx-errors = pUrb-status;
-   spin_unlock(pdx-err_lock);
+   spin_unlock_irqrestore(pdx-err_lock, flags);
nGot = 0;   /*   and tidy up again if so */
 
-   spin_lock(pdx-charOutLock);   /*  already at irq level */
+   spin_lock_irqsave(pdx-charOutLock, flags);/*  already at 
irq level */
pdx-dwOutBuffGet = 0;  /*  Reset the output buffer */
pdx-dwOutBuffPut = 0;
pdx-dwNumOutput = 0;   /*  Clear the char count */
pdx-bPipeError[0] = 1; /*  Flag an error for later */
pdx-bSendCharsPending = false; /*  Allow other threads again */
-   spin_unlock(pdx-charOutLock); /*  already at irq level */
+   spin_unlock_irqrestore(pdx-charOutLock, flags);   /*  
already at irq level */
dev_dbg(pdx-interface-dev,
%s - char out done, 0 chars sent, __func__);
} else {
dev_dbg(pdx-interface-dev,
%s - char out done, %d chars sent, __func__, nGot);
-   spin_lock(pdx-charOutLock);   /*  already at irq level */
+   spin_lock_irqsave(pdx-charOutLock, flags);/*  already at 
irq level */
pdx-dwNumOutput -= nGot;   /*  Now adjust the char send 
buffer */
pdx-dwOutBuffGet += nGot;  /*  to match what we did */
if (pdx-dwOutBuffGet = OUTBUF_SZ) /*  Can't do this any 
earlier as data could be overwritten */
@@ -305,7 +306,7 @@ static void ced_writechar_callback(struct urb *pUrb)
unsigned int dwCount = pdx-dwNumOutput;/*  
maximum to send */
if ((pdx-dwOutBuffGet + dwCount)  OUTBUF_SZ)  /*  
does it cross buffer end? */
dwCount = OUTBUF_SZ - pdx-dwOutBuffGet;
-   spin_unlock(pdx-charOutLock); /*  we are done with 
stuff that changes */
+   spin_unlock_irqrestore(pdx-charOutLock, flags);   
/*  we are done with stuff that changes */
memcpy(pdx-pCoherCharOut, pDat, dwCount);  /*  
copy output data to the buffer */
usb_fill_bulk_urb(pdx-pUrbCharOut, pdx-udev,
  usb_sndbulkpipe(pdx-udev,
@@ -318,7 +319,7 @@ static void ced_writechar_callback(struct urb *pUrb)
iReturn = usb_submit_urb(pdx-pUrbCharOut, GFP_ATOMIC);
dev_dbg(pdx-interface-dev, %s n=%d%s, __func__,
dwCount, pDat);
-   spin_lock(pdx-charOutLock);   /*  grab lock for 
errors */
+   spin_lock_irqsave(pdx-charOutLock, flags);/*  
grab lock for errors */
if (iReturn) {
pdx-bPipeError[nPipe] = 1; /*  Flag an 
error to be handled later */
pdx-bSendCharsPending = false; /*  Allow other 
threads again */
@@ -329,7 +330,7 @@ static void ced_writechar_callback(struct urb *pUrb)
}
} else
pdx-bSendCharsPending = false; /*  Allow other threads 
again */
-   spin_unlock(pdx-charOutLock); /*  already at irq level */
+   spin_unlock_irqrestore(pdx-charOutLock, flags);   /*  
already at irq level */
}
 }
 
@@ -505,8 +506,9 @@ static void staged_callback(struct urb *pUrb)
unsigned int nGot = pUrb-actual_length;/*  what we transferred 
*/
bool bCancel = false;
bool bRestartCharInput; /*  used at the end */
+   unsigned long flags;
 
-   spin_lock(pdx-stagedLock);/*  stop ReadWriteMem() action while 
this routine is running */
+   spin_lock_irqsave(pdx-stagedLock, flags); /*  stop ReadWriteMem() 
action while this routine

[PATCH 08/50] USB: legousbtower: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Juergen Stuber starb...@users.sourceforge.net
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/misc/legousbtower.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 8089479..4044989 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -771,6 +771,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
struct lego_usb_tower *dev = urb-context;
int status = urb-status;
int retval;
+   unsigned long flags;
 
dbg(4, %s: enter, status %d, __func__, status);
 
@@ -788,7 +789,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
}
 
if (urb-actual_length  0) {
-   spin_lock (dev-read_buffer_lock);
+   spin_lock_irqsave (dev-read_buffer_lock, flags);
if (dev-read_buffer_length + urb-actual_length  
read_buffer_size) {
memcpy (dev-read_buffer + dev-read_buffer_length,
dev-interrupt_in_buffer,
@@ -799,7 +800,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
} else {
printk(KERN_WARNING %s: read_buffer overflow, %d bytes 
dropped, __func__, urb-actual_length);
}
-   spin_unlock (dev-read_buffer_lock);
+   spin_unlock_irqrestore (dev-read_buffer_lock, flags);
}
 
 resubmit:
-- 
1.7.9.5

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


[PATCH 40/50] media: dvb-core: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

These functions may be called inside URB-complete(), so use
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/dvb-core/dvb_demux.c |   17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_demux.c 
b/drivers/media/dvb-core/dvb_demux.c
index 3485655..58de441 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -476,7 +476,9 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux 
*demux, const u8 *buf)
 void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
  size_t count)
 {
-   spin_lock(demux-lock);
+   unsigned long flags;
+
+   spin_lock_irqsave(demux-lock, flags);
 
while (count--) {
if (buf[0] == 0x47)
@@ -484,7 +486,7 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, 
const u8 *buf,
buf += 188;
}
 
-   spin_unlock(demux-lock);
+   spin_unlock_irqrestore(demux-lock, flags);
 }
 
 EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
@@ -519,8 +521,9 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux 
*demux, const u8 *buf,
 {
int p = 0, i, j;
const u8 *q;
+   unsigned long flags;
 
-   spin_lock(demux-lock);
+   spin_lock_irqsave(demux-lock, flags);
 
if (demux-tsbufp) { /* tsbuf[0] is now 0x47. */
i = demux-tsbufp;
@@ -564,7 +567,7 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux 
*demux, const u8 *buf,
}
 
 bailout:
-   spin_unlock(demux-lock);
+   spin_unlock_irqrestore(demux-lock, flags);
 }
 
 void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
@@ -581,11 +584,13 @@ EXPORT_SYMBOL(dvb_dmx_swfilter_204);
 
 void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count)
 {
-   spin_lock(demux-lock);
+   unsigned long flags;
+
+   spin_lock_irqsave(demux-lock, flags);
 
demux-feed-cb.ts(buf, count, NULL, 0, demux-feed-feed.ts, DMX_OK);
 
-   spin_unlock(demux-lock);
+   spin_unlock_irqrestore(demux-lock, flags);
 }
 EXPORT_SYMBOL(dvb_dmx_swfilter_raw);
 
-- 
1.7.9.5

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


[PATCH 31/50] wireless: zd1211rw: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Daniel Drake d...@gentoo.org
Cc: Ulrich Kunitz k...@deine-taler.de
Cc: John W. Linville linvi...@tuxdriver.com
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/wireless/zd1211rw/zd_usb.c |   21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c 
b/drivers/net/wireless/zd1211rw/zd_usb.c
index 7ef0b4a..8169ee0 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -372,14 +372,15 @@ static inline void handle_regs_int_override(struct urb 
*urb)
 {
struct zd_usb *usb = urb-context;
struct zd_usb_interrupt *intr = usb-intr;
+   unsigned long flags;
 
-   spin_lock(intr-lock);
+   spin_lock_irqsave(intr-lock, flags);
if (atomic_read(intr-read_regs_enabled)) {
atomic_set(intr-read_regs_enabled, 0);
intr-read_regs_int_overridden = 1;
complete(intr-read_regs.completion);
}
-   spin_unlock(intr-lock);
+   spin_unlock_irqrestore(intr-lock, flags);
 }
 
 static inline void handle_regs_int(struct urb *urb)
@@ -388,9 +389,10 @@ static inline void handle_regs_int(struct urb *urb)
struct zd_usb_interrupt *intr = usb-intr;
int len;
u16 int_num;
+   unsigned long flags;
 
ZD_ASSERT(in_interrupt());
-   spin_lock(intr-lock);
+   spin_lock_irqsave(intr-lock, flags);
 
int_num = le16_to_cpu(*(__le16 *)(urb-transfer_buffer+2));
if (int_num == CR_INTERRUPT) {
@@ -426,7 +428,7 @@ static inline void handle_regs_int(struct urb *urb)
}
 
 out:
-   spin_unlock(intr-lock);
+   spin_unlock_irqrestore(intr-lock, flags);
 
/* CR_INTERRUPT might override read_reg too. */
if (int_num == CR_INTERRUPT  atomic_read(intr-read_regs_enabled))
@@ -666,6 +668,7 @@ static void rx_urb_complete(struct urb *urb)
struct zd_usb_rx *rx;
const u8 *buffer;
unsigned int length;
+   unsigned long flags;
 
switch (urb-status) {
case 0:
@@ -694,14 +697,14 @@ static void rx_urb_complete(struct urb *urb)
/* If there is an old first fragment, we don't care. */
dev_dbg_f(urb_dev(urb), *** first fragment ***\n);
ZD_ASSERT(length = ARRAY_SIZE(rx-fragment));
-   spin_lock(rx-lock);
+   spin_lock_irqsave(rx-lock, flags);
memcpy(rx-fragment, buffer, length);
rx-fragment_length = length;
-   spin_unlock(rx-lock);
+   spin_unlock_irqrestore(rx-lock, flags);
goto resubmit;
}
 
-   spin_lock(rx-lock);
+   spin_lock_irqsave(rx-lock, flags);
if (rx-fragment_length  0) {
/* We are on a second fragment, we believe */
ZD_ASSERT(length + rx-fragment_length =
@@ -711,9 +714,9 @@ static void rx_urb_complete(struct urb *urb)
handle_rx_packet(usb, rx-fragment,
 rx-fragment_length + length);
rx-fragment_length = 0;
-   spin_unlock(rx-lock);
+   spin_unlock_irqrestore(rx-lock, flags);
} else {
-   spin_unlock(rx-lock);
+   spin_unlock_irqrestore(rx-lock, flags);
handle_rx_packet(usb, buffer, length);
}
 
-- 
1.7.9.5

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


[PATCH 18/50] USB: serial: symbolserial: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/symbolserial.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/symbolserial.c 
b/drivers/usb/serial/symbolserial.c
index 9b16489..b4f5cbe 100644
--- a/drivers/usb/serial/symbolserial.c
+++ b/drivers/usb/serial/symbolserial.c
@@ -41,6 +41,7 @@ static void symbol_int_callback(struct urb *urb)
int status = urb-status;
int result;
int data_length;
+   unsigned long flags;
 
switch (status) {
case 0:
@@ -81,7 +82,7 @@ static void symbol_int_callback(struct urb *urb)
}
 
 exit:
-   spin_lock(priv-lock);
+   spin_lock_irqsave(priv-lock, flags);
 
/* Continue trying to always read if we should */
if (!priv-throttled) {
@@ -92,7 +93,7 @@ exit:
__func__, result);
} else
priv-actually_throttled = true;
-   spin_unlock(priv-lock);
+   spin_unlock_irqrestore(priv-lock, flags);
 }
 
 static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port)
-- 
1.7.9.5

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


[PATCH 27/50] USBNET: hso: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/usb/hso.c |   38 ++
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index cba1d46..c865441 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1008,6 +1008,7 @@ static void read_bulk_callback(struct urb *urb)
struct net_device *net;
int result;
int status = urb-status;
+   unsigned long flags;
 
/* is al ok?  (Filip: Who's Al ?) */
if (status) {
@@ -1036,11 +1037,11 @@ static void read_bulk_callback(struct urb *urb)
if (urb-actual_length) {
/* Handle the IP stream, add header and push it onto network
 * stack if the packet is complete. */
-   spin_lock(odev-net_lock);
+   spin_lock_irqsave(odev-net_lock, flags);
packetizeRx(odev, urb-transfer_buffer, urb-actual_length,
(urb-transfer_buffer_length 
 urb-actual_length) ? 1 : 0);
-   spin_unlock(odev-net_lock);
+   spin_unlock_irqrestore(odev-net_lock, flags);
}
 
/* We are done with this URB, resubmit it. Prep the USB to wait for
@@ -1201,6 +1202,7 @@ static void hso_std_serial_read_bulk_callback(struct urb 
*urb)
 {
struct hso_serial *serial = urb-context;
int status = urb-status;
+   unsigned long flags;
 
/* sanity check */
if (!serial) {
@@ -1223,17 +1225,17 @@ static void hso_std_serial_read_bulk_callback(struct 
urb *urb)
if (serial-parent-port_spec  HSO_INFO_CRC_BUG)
fix_crc_bug(urb, serial-in_endp-wMaxPacketSize);
/* Valid data, handle RX data */
-   spin_lock(serial-serial_lock);
+   spin_lock_irqsave(serial-serial_lock, flags);
serial-rx_urb_filled[hso_urb_to_index(serial, urb)] = 1;
put_rxbuf_data_and_resubmit_bulk_urb(serial);
-   spin_unlock(serial-serial_lock);
+   spin_unlock_irqrestore(serial-serial_lock, flags);
} else if (status == -ENOENT || status == -ECONNRESET) {
/* Unlinked - check for throttled port. */
D2(Port %d, successfully unlinked urb, serial-minor);
-   spin_lock(serial-serial_lock);
+   spin_lock_irqsave(serial-serial_lock, flags);
serial-rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
hso_resubmit_rx_bulk_urb(serial, urb);
-   spin_unlock(serial-serial_lock);
+   spin_unlock_irqrestore(serial-serial_lock, flags);
} else {
D2(Port %d, status = %d for read urb, serial-minor, status);
return;
@@ -1510,12 +1512,13 @@ static void tiocmget_intr_callback(struct urb *urb)
DUMP(serial_state_notification,
 sizeof(struct hso_serial_state_notification));
} else {
+   unsigned long flags;
 
UART_state_bitmap = le16_to_cpu(serial_state_notification-
UART_state_bitmap);
prev_UART_state_bitmap = tiocmget-prev_UART_state_bitmap;
icount = tiocmget-icount;
-   spin_lock(serial-serial_lock);
+   spin_lock_irqsave(serial-serial_lock, flags);
if ((UART_state_bitmap  B_OVERRUN) !=
   (prev_UART_state_bitmap  B_OVERRUN))
icount-parity++;
@@ -1538,7 +1541,7 @@ static void tiocmget_intr_callback(struct urb *urb)
   (prev_UART_state_bitmap  B_RX_CARRIER))
icount-dcd++;
tiocmget-prev_UART_state_bitmap = UART_state_bitmap;
-   spin_unlock(serial-serial_lock);
+   spin_unlock_irqrestore(serial-serial_lock, flags);
tiocmget-intr_completed = 1;
wake_up_interruptible(tiocmget-waitq);
}
@@ -1883,8 +1886,9 @@ static void intr_callback(struct urb *urb)
serial = get_serial_by_shared_int_and_type(shared_int,
   (1  i));
if (serial != NULL) {
+   unsigned long flags;
D1(Pending read interrupt on port %d\n, i);
-   spin_lock(serial-serial_lock);
+   spin_lock_irqsave(serial-serial_lock, flags);
if (serial-rx_state == RX_IDLE 
serial-port.count  0) {
/* Setup and send a ctrl req read on
@@ -1898,7 +1902,7 @@ static void intr_callback(struct urb *urb

[PATCH 22/50] BT: btusb: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Marcel Holtmann mar...@holtmann.org
Cc: Gustavo Padovan gust...@padovan.org
Cc: Johan Hedberg johan.hedb...@gmail.com
Cc: linux-blueto...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/bluetooth/btusb.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index ea63958..018b8b0 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -573,6 +573,7 @@ static void btusb_tx_complete(struct urb *urb)
struct sk_buff *skb = urb-context;
struct hci_dev *hdev = (struct hci_dev *) skb-dev;
struct btusb_data *data = hci_get_drvdata(hdev);
+   unsigned long flags;
 
BT_DBG(%s urb %p status %d count %d, hdev-name,
urb, urb-status, urb-actual_length);
@@ -586,9 +587,9 @@ static void btusb_tx_complete(struct urb *urb)
hdev-stat.err_tx++;
 
 done:
-   spin_lock(data-txlock);
+   spin_lock_irqsave(data-txlock, flags);
data-tx_in_flight--;
-   spin_unlock(data-txlock);
+   spin_unlock_irqrestore(data-txlock, flags);
 
kfree(urb-setup_packet);
 
-- 
1.7.9.5

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


[PATCH 09/50] USB: usbtest: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/misc/usbtest.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 8b4ca1c..5c73df5 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -804,11 +804,12 @@ static void ctrl_complete(struct urb *urb)
struct usb_ctrlrequest  *reqp;
struct subcase  *subcase;
int status = urb-status;
+   unsigned long   flags;
 
reqp = (struct usb_ctrlrequest *)urb-setup_packet;
subcase = container_of(reqp, struct subcase, setup);
 
-   spin_lock(ctx-lock);
+   spin_lock_irqsave(ctx-lock, flags);
ctx-count--;
ctx-pending--;
 
@@ -907,7 +908,7 @@ error:
/* signal completion when nothing's queued */
if (ctx-pending == 0)
complete(ctx-complete);
-   spin_unlock(ctx-lock);
+   spin_unlock_irqrestore(ctx-lock, flags);
 }
 
 static int
@@ -1552,8 +1553,9 @@ struct iso_context {
 static void iso_callback(struct urb *urb)
 {
struct iso_context  *ctx = urb-context;
+   unsigned long   flags;
 
-   spin_lock(ctx-lock);
+   spin_lock_irqsave(ctx-lock, flags);
ctx-count--;
 
ctx-packet_count += urb-number_of_packets;
@@ -1593,7 +1595,7 @@ static void iso_callback(struct urb *urb)
complete(ctx-done);
}
 done:
-   spin_unlock(ctx-lock);
+   spin_unlock_irqrestore(ctx-lock, flags);
 }
 
 static struct urb *iso_alloc_urb(
-- 
1.7.9.5

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


[PATCH 14/50] USB: serial: mos7720: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/mos7720.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 51da424..9b8c866 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -338,14 +338,15 @@ static void async_complete(struct urb *urb)
 {
struct urbtracker *urbtrack = urb-context;
int status = urb-status;
+   unsigned long flags;
 
if (unlikely(status))
dev_dbg(urb-dev-dev, %s - nonzero urb status received: 
%d\n, __func__, status);
 
/* remove the urbtracker from the active_urbs list */
-   spin_lock(urbtrack-mos_parport-listlock);
+   spin_lock_irqsave(urbtrack-mos_parport-listlock, flags);
list_del(urbtrack-urblist_entry);
-   spin_unlock(urbtrack-mos_parport-listlock);
+   spin_unlock_irqrestore(urbtrack-mos_parport-listlock, flags);
kref_put(urbtrack-ref_count, destroy_urbtracker);
 }
 
-- 
1.7.9.5

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


[PATCH 28/50] USBNET: kaweth: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/usb/kaweth.c |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index afb117c..4addbbf 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -598,6 +598,7 @@ static void kaweth_usb_receive(struct urb *urb)
struct kaweth_device *kaweth = urb-context;
struct net_device *net = kaweth-net;
int status = urb-status;
+   unsigned long flags;
 
int count = urb-actual_length;
int count2 = urb-transfer_buffer_length;
@@ -630,12 +631,12 @@ static void kaweth_usb_receive(struct urb *urb)
kaweth-stats.rx_errors++;
dev_dbg(dev, Status was -EOVERFLOW.\n);
}
-   spin_lock(kaweth-device_lock);
+   spin_lock_irqsave(kaweth-device_lock, flags);
if (IS_BLOCKED(kaweth-status)) {
-   spin_unlock(kaweth-device_lock);
+   spin_unlock_irqrestore(kaweth-device_lock, flags);
return;
}
-   spin_unlock(kaweth-device_lock);
+   spin_unlock_irqrestore(kaweth-device_lock, flags);
 
if(status  status != -EREMOTEIO  count != 1) {
dev_err(kaweth-intf-dev,
-- 
1.7.9.5

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


[PATCH 37/50] media: usb: sn9x102: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Mauro Carvalho Chehab mche...@redhat.com
Cc: linux-media@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/usb/sn9c102/sn9c102_core.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/sn9c102/sn9c102_core.c 
b/drivers/media/usb/sn9c102/sn9c102_core.c
index 2cb44de..33dc595 100644
--- a/drivers/media/usb/sn9c102/sn9c102_core.c
+++ b/drivers/media/usb/sn9c102/sn9c102_core.c
@@ -784,12 +784,14 @@ end_of_frame:
  cam-sensor.pix_format.pixelformat ==
  V4L2_PIX_FMT_JPEG)  eof)) {
u32 b;
+   unsigned long flags;
 
b = (*f)-buf.bytesused;
(*f)-state = F_DONE;
(*f)-buf.sequence= ++cam-frame_count;
 
-   spin_lock(cam-queue_lock);
+   spin_lock_irqsave(cam-queue_lock,
+ flags);
list_move_tail((*f)-frame,
   cam-outqueue);
if (!list_empty(cam-inqueue))
@@ -799,7 +801,8 @@ end_of_frame:
frame );
else
(*f) = NULL;
-   spin_unlock(cam-queue_lock);
+   spin_unlock_irqrestore(cam-queue_lock,
+  flags);
 
memcpy(cam-sysfs.frame_header,
   cam-sof.header, soflen);
-- 
1.7.9.5

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


[PATCH 21/50] hid: usbhid: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Jiri Kosina jkos...@suse.cz
Cc: linux-in...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/hid/usbhid/hid-core.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 9941828..e1d8518 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -489,8 +489,9 @@ static void hid_ctrl(struct urb *urb)
struct hid_device *hid = urb-context;
struct usbhid_device *usbhid = hid-driver_data;
int unplug = 0, status = urb-status;
+   unsigned long flags;
 
-   spin_lock(usbhid-lock);
+   spin_lock_irqsave(usbhid-lock, flags);
 
switch (status) {
case 0: /* success */
@@ -525,7 +526,7 @@ static void hid_ctrl(struct urb *urb)
}
 
clear_bit(HID_CTRL_RUNNING, usbhid-iofl);
-   spin_unlock(usbhid-lock);
+   spin_unlock_irqrestore(usbhid-lock, flags);
usb_autopm_put_interface_async(usbhid-intf);
wake_up(usbhid-wait);
 }
-- 
1.7.9.5

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


[PATCH 23/50] BT: bfusb: read_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
read_lock_irqsave().

Cc: Marcel Holtmann mar...@holtmann.org
Cc: Gustavo Padovan gust...@padovan.org
Cc: Johan Hedberg johan.hedb...@gmail.com
Cc: linux-blueto...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/bluetooth/bfusb.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 995aee9..2e93501 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -186,6 +186,7 @@ static void bfusb_tx_complete(struct urb *urb)
 {
struct sk_buff *skb = (struct sk_buff *) urb-context;
struct bfusb_data *data = (struct bfusb_data *) skb-dev;
+   unsigned long flags;
 
BT_DBG(bfusb %p urb %p skb %p len %d, data, urb, skb, skb-len);
 
@@ -199,14 +200,14 @@ static void bfusb_tx_complete(struct urb *urb)
else
data-hdev-stat.err_tx++;
 
-   read_lock(data-lock);
+   read_lock_irqsave(data-lock, flags);
 
skb_unlink(skb, data-pending_q);
skb_queue_tail(data-completed_q, skb);
 
bfusb_tx_wakeup(data);
 
-   read_unlock(data-lock);
+   read_unlock_irqrestore(data-lock, flags);
 }
 
 
@@ -347,10 +348,11 @@ static void bfusb_rx_complete(struct urb *urb)
unsigned char *buf = urb-transfer_buffer;
int count = urb-actual_length;
int err, hdr, len;
+   unsigned long flags;
 
BT_DBG(bfusb %p urb %p skb %p len %d, data, urb, skb, skb-len);
 
-   read_lock(data-lock);
+   read_lock_irqsave(data-lock, flags);
 
if (!test_bit(HCI_RUNNING, data-hdev-flags))
goto unlock;
@@ -392,7 +394,7 @@ static void bfusb_rx_complete(struct urb *urb)
 
bfusb_rx_submit(data, urb);
 
-   read_unlock(data-lock);
+   read_unlock_irqrestore(data-lock, flags);
 
return;
 
@@ -406,7 +408,7 @@ resubmit:
}
 
 unlock:
-   read_unlock(data-lock);
+   read_unlock_irqrestore(data-lock, flags);
 }
 
 static int bfusb_open(struct hci_dev *hdev)
-- 
1.7.9.5

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


[PATCH 30/50] wireless: ath9k: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Luis R. Rodriguez mcg...@qca.qualcomm.com
Cc: John W. Linville linvi...@tuxdriver.com
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/net/wireless/ath/ath9k/hif_usb.c  |   29 ++---
 drivers/net/wireless/ath/ath9k/htc_drv_txrx.c |9 
 drivers/net/wireless/ath/ath9k/wmi.c  |   11 +-
 3 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c 
b/drivers/net/wireless/ath/ath9k/hif_usb.c
index 9e582e1..9d5e15a 100644
--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
+++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -136,6 +136,7 @@ static void hif_usb_mgmt_cb(struct urb *urb)
struct cmd_buf *cmd = (struct cmd_buf *)urb-context;
struct hif_device_usb *hif_dev;
bool txok = true;
+   unsigned long flags;
 
if (!cmd || !cmd-skb || !cmd-hif_dev)
return;
@@ -155,14 +156,14 @@ static void hif_usb_mgmt_cb(struct urb *urb)
 * If the URBs are being flushed, no need to complete
 * this packet.
 */
-   spin_lock(hif_dev-tx.tx_lock);
+   spin_lock_irqsave(hif_dev-tx.tx_lock, flags);
if (hif_dev-tx.flags  HIF_USB_TX_FLUSH) {
-   spin_unlock(hif_dev-tx.tx_lock);
+   spin_unlock_irqrestore(hif_dev-tx.tx_lock, flags);
dev_kfree_skb_any(cmd-skb);
kfree(cmd);
return;
}
-   spin_unlock(hif_dev-tx.tx_lock);
+   spin_unlock_irqrestore(hif_dev-tx.tx_lock, flags);
 
break;
default:
@@ -253,6 +254,7 @@ static void hif_usb_tx_cb(struct urb *urb)
struct tx_buf *tx_buf = (struct tx_buf *) urb-context;
struct hif_device_usb *hif_dev;
bool txok = true;
+   unsigned long flags;
 
if (!tx_buf || !tx_buf-hif_dev)
return;
@@ -272,13 +274,13 @@ static void hif_usb_tx_cb(struct urb *urb)
 * If the URBs are being flushed, no need to add this
 * URB to the free list.
 */
-   spin_lock(hif_dev-tx.tx_lock);
+   spin_lock_irqsave(hif_dev-tx.tx_lock, flags);
if (hif_dev-tx.flags  HIF_USB_TX_FLUSH) {
-   spin_unlock(hif_dev-tx.tx_lock);
+   spin_unlock_irqrestore(hif_dev-tx.tx_lock, flags);
ath9k_skb_queue_purge(hif_dev, tx_buf-skb_queue);
return;
}
-   spin_unlock(hif_dev-tx.tx_lock);
+   spin_unlock_irqrestore(hif_dev-tx.tx_lock, flags);
 
break;
default:
@@ -293,13 +295,13 @@ static void hif_usb_tx_cb(struct urb *urb)
__skb_queue_head_init(tx_buf-skb_queue);
 
/* Add this TX buffer to the free list */
-   spin_lock(hif_dev-tx.tx_lock);
+   spin_lock_irqsave(hif_dev-tx.tx_lock, flags);
list_move_tail(tx_buf-list, hif_dev-tx.tx_buf);
hif_dev-tx.tx_buf_cnt++;
if (!(hif_dev-tx.flags  HIF_USB_TX_STOP))
__hif_usb_tx(hif_dev); /* Check for pending SKBs */
TX_STAT_INC(buf_completed);
-   spin_unlock(hif_dev-tx.tx_lock);
+   spin_unlock_irqrestore(hif_dev-tx.tx_lock, flags);
 }
 
 /* TX lock has to be taken */
@@ -530,8 +532,9 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb 
*hif_dev,
int rx_remain_len, rx_pkt_len;
u16 pool_index = 0;
u8 *ptr;
+   unsigned long flags;
 
-   spin_lock(hif_dev-rx_lock);
+   spin_lock_irqsave(hif_dev-rx_lock, flags);
 
rx_remain_len = hif_dev-rx_remain_len;
rx_pkt_len = hif_dev-rx_transfer_len;
@@ -559,7 +562,7 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb 
*hif_dev,
}
}
 
-   spin_unlock(hif_dev-rx_lock);
+   spin_unlock_irqrestore(hif_dev-rx_lock, flags);
 
while (index  len) {
u16 pkt_len;
@@ -585,7 +588,7 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb 
*hif_dev,
index = index + 4 + pkt_len + pad_len;
 
if (index  MAX_RX_BUF_SIZE) {
-   spin_lock(hif_dev-rx_lock);
+   spin_lock_irqsave(hif_dev-rx_lock, flags);
hif_dev-rx_remain_len = index - MAX_RX_BUF_SIZE;
hif_dev-rx_transfer_len =
MAX_RX_BUF_SIZE - chk_idx - 4;
@@ -595,7 +598,7 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb 
*hif_dev,
if (!nskb) {
dev_err(hif_dev-udev-dev,
ath9k_htc: RX memory allocation 
error\n

[PATCH 19/50] USB: serial: ti_usb_3410_5052: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/serial/ti_usb_3410_5052.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/serial/ti_usb_3410_5052.c 
b/drivers/usb/serial/ti_usb_3410_5052.c
index 7182bb7..4b984e9 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -1081,6 +1081,7 @@ static void ti_bulk_in_callback(struct urb *urb)
struct device *dev = urb-dev-dev;
int status = urb-status;
int retval = 0;
+   unsigned long flags;
 
switch (status) {
case 0:
@@ -1116,20 +1117,20 @@ static void ti_bulk_in_callback(struct urb *urb)
__func__);
else
ti_recv(port, urb-transfer_buffer, urb-actual_length);
-   spin_lock(tport-tp_lock);
+   spin_lock_irqsave(tport-tp_lock, flags);
port-icount.rx += urb-actual_length;
-   spin_unlock(tport-tp_lock);
+   spin_unlock_irqrestore(tport-tp_lock, flags);
}
 
 exit:
/* continue to read unless stopping */
-   spin_lock(tport-tp_lock);
+   spin_lock_irqsave(tport-tp_lock, flags);
if (tport-tp_read_urb_state == TI_READ_URB_RUNNING)
retval = usb_submit_urb(urb, GFP_ATOMIC);
else if (tport-tp_read_urb_state == TI_READ_URB_STOPPING)
tport-tp_read_urb_state = TI_READ_URB_STOPPED;
 
-   spin_unlock(tport-tp_lock);
+   spin_unlock_irqrestore(tport-tp_lock, flags);
if (retval)
dev_err(dev, %s - resubmit read urb failed, %d\n,
__func__, retval);
-- 
1.7.9.5

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


[PATCH 01/50] USB: devio: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
Complete() will be run with interrupt enabled, so change to
spin_lock_irqsave().

Cc: Alan Stern st...@rowland.harvard.edu
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/core/devio.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 0598650..21e6ec6 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -495,8 +495,9 @@ static void async_completed(struct urb *urb)
u32 secid = 0;
const struct cred *cred = NULL;
int signr;
+   unsigned long flags;
 
-   spin_lock(ps-lock);
+   spin_lock_irqsave(ps-lock, flags);
list_move_tail(as-asynclist, ps-async_completed);
as-status = urb-status;
signr = as-signr;
@@ -518,7 +519,7 @@ static void async_completed(struct urb *urb)
if (as-status  0  as-bulk_addr  as-status != -ECONNRESET 
as-status != -ENOENT)
cancel_bulk_urbs(ps, as-bulk_addr);
-   spin_unlock(ps-lock);
+   spin_unlock_irqrestore(ps-lock, flags);
 
if (signr) {
kill_pid_info_as_cred(sinfo.si_signo, sinfo, pid, cred, secid);
-- 
1.7.9.5

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


Re: [PATCH 08/50] USB: legousbtower: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
On Thu, Jul 11, 2013 at 8:18 PM, Sergei Shtylyov
sergei.shtyl...@cogentembedded.com wrote:
 Hello.


 On 11-07-2013 13:05, Ming Lei wrote:

 Complete() will be run with interrupt enabled, so change to
 spin_lock_irqsave().


 Cc: Juergen Stuber starb...@users.sourceforge.net
 Signed-off-by: Ming Lei ming@canonical.com
 ---
   drivers/usb/misc/legousbtower.c |5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)


 diff --git a/drivers/usb/misc/legousbtower.c
 b/drivers/usb/misc/legousbtower.c
 index 8089479..4044989 100644
 --- a/drivers/usb/misc/legousbtower.c
 +++ b/drivers/usb/misc/legousbtower.c
 @@ -771,6 +771,7 @@ static void tower_interrupt_in_callback (struct urb
 *urb)
 struct lego_usb_tower *dev = urb-context;
 int status = urb-status;
 int retval;
 +   unsigned long flags;

 dbg(4, %s: enter, status %d, __func__, status);

 @@ -788,7 +789,7 @@ static void tower_interrupt_in_callback (struct urb
 *urb)
 }

 if (urb-actual_length  0) {
 -   spin_lock (dev-read_buffer_lock);
 +   spin_lock_irqsave (dev-read_buffer_lock, flags);
 if (dev-read_buffer_length + urb-actual_length 
 read_buffer_size) {
 memcpy (dev-read_buffer +
 dev-read_buffer_length,
 dev-interrupt_in_buffer,
 @@ -799,7 +800,7 @@ static void tower_interrupt_in_callback (struct urb
 *urb)
 } else {
 printk(KERN_WARNING %s: read_buffer overflow, %d
 bytes dropped, __func__, urb-actual_length);
 }
 -   spin_unlock (dev-read_buffer_lock);
 +   spin_unlock_irqrestore (dev-read_buffer_lock, flags);
 }


I don't think this patch passes checkpatch.pl.

No errors reported from checkpatch.pl, only warnings which isn't introduced
by this patch.

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


Re: [PATCH 45/50] sound: usb: usx2y: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
On Thu, Jul 11, 2013 at 9:50 PM, Takashi Iwai ti...@suse.de wrote:
 At Thu, 11 Jul 2013 17:08:30 +0400,
 Sergei Shtylyov wrote:

 On 11-07-2013 13:06, Ming Lei wrote:

  Complete() will be run with interrupt enabled, so change to
  spin_lock_irqsave().

 Changelog doesn't match the patch.

 Yep, but moreover...

  Cc: Jaroslav Kysela pe...@perex.cz
  Cc: Takashi Iwai ti...@suse.de
  Cc: alsa-de...@alsa-project.org
  Signed-off-by: Ming Lei ming@canonical.com
  ---
sound/usb/usx2y/usbusx2yaudio.c |4 
1 file changed, 4 insertions(+)

  diff --git a/sound/usb/usx2y/usbusx2yaudio.c 
  b/sound/usb/usx2y/usbusx2yaudio.c
  index 4967fe9..e2ee893 100644
  --- a/sound/usb/usx2y/usbusx2yaudio.c
  +++ b/sound/usb/usx2y/usbusx2yaudio.c
  @@ -273,7 +273,11 @@ static void usX2Y_clients_stop(struct usX2Ydev *usX2Y)
  struct snd_usX2Y_substream *subs = usX2Y-subs[s];
  if (subs) {
  if (atomic_read(subs-state) = state_PRERUNNING) {
  +   unsigned long flags;
  +
  +   local_irq_save(flags);
  snd_pcm_stop(subs-pcm_substream, 
  SNDRV_PCM_STATE_XRUN);
  +   local_irq_restore(flags);
  }

 ... actually this snd_pcm_stop() call should have been covered by
 snd_pcm_stream_lock().  Maybe it'd be enough to have a single patch
 together with the change, i.e. wrapping with
 snd_pcm_stream_lock_irqsave().

Please use snd_pcm_stream_lock_irqsave() so that I can avoid sending
out similar patch later, :-)


 I'll prepare the patch for 3.11 independently from your patch series,
 so please drop this one.

OK, thanks for dealing with that.



 BTW, the word cleanup in the subject is inappropriate.  This is
 rather a fix together with the core change.

It is a cleanup since the patchset only addresses lock problem which
is caused by the tasklet conversion.


 And, I wonder whether we can take a safer approach.  When the caller
 condition changed, we often introduced either a different ops
 (e.g. ioctl case) or a flag for the new condition, at least during the
 transition period.

Interrupt is't enabled until all current drivers are cleaned up, so it is really
safe, please see patch [2].


 Last but not least, is a conversion to tasklet really preferred?
 tasklet is rather an obsoleted infrastructure nowadays, and people
 don't recommend to use it any longer, AFAIK.

We discussed the problem in the below link previously[1], Steven
and Thomas suggested to use threaded irq handler, but which
may degrade USB mass storage performance, so we have to
take tasklet now until we rewrite transport part of USB mass storage
driver.

Also the conversion[2] has avoided the tasklet spin lock problem
already.


[1], http://marc.info/?t=13707911921r=1w=2
[2], http://marc.info/?l=linux-usbm=137286326726326w=2

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


Re: [PATCH 45/50] sound: usb: usx2y: spin_lock in complete() cleanup

2013-07-11 Thread Ming Lei
On Thu, Jul 11, 2013 at 10:34 PM, Takashi Iwai ti...@suse.de wrote:
 At Thu, 11 Jul 2013 22:13:35 +0800,
 Ming Lei wrote:

 On Thu, Jul 11, 2013 at 9:50 PM, Takashi Iwai ti...@suse.de wrote:
  At Thu, 11 Jul 2013 17:08:30 +0400,
  Sergei Shtylyov wrote:
 
  On 11-07-2013 13:06, Ming Lei wrote:
 
   Complete() will be run with interrupt enabled, so change to
   spin_lock_irqsave().
 
  Changelog doesn't match the patch.
 
  Yep, but moreover...
 
   Cc: Jaroslav Kysela pe...@perex.cz
   Cc: Takashi Iwai ti...@suse.de
   Cc: alsa-de...@alsa-project.org
   Signed-off-by: Ming Lei ming@canonical.com
   ---
 sound/usb/usx2y/usbusx2yaudio.c |4 
 1 file changed, 4 insertions(+)
 
   diff --git a/sound/usb/usx2y/usbusx2yaudio.c 
   b/sound/usb/usx2y/usbusx2yaudio.c
   index 4967fe9..e2ee893 100644
   --- a/sound/usb/usx2y/usbusx2yaudio.c
   +++ b/sound/usb/usx2y/usbusx2yaudio.c
   @@ -273,7 +273,11 @@ static void usX2Y_clients_stop(struct usX2Ydev 
   *usX2Y)
   struct snd_usX2Y_substream *subs = usX2Y-subs[s];
   if (subs) {
   if (atomic_read(subs-state) = state_PRERUNNING) {
   +   unsigned long flags;
   +
   +   local_irq_save(flags);
   snd_pcm_stop(subs-pcm_substream, 
   SNDRV_PCM_STATE_XRUN);
   +   local_irq_restore(flags);
   }
 
  ... actually this snd_pcm_stop() call should have been covered by
  snd_pcm_stream_lock().  Maybe it'd be enough to have a single patch
  together with the change, i.e. wrapping with
  snd_pcm_stream_lock_irqsave().

 Please use snd_pcm_stream_lock_irqsave() so that I can avoid sending
 out similar patch later, :-)

 
  I'll prepare the patch for 3.11 independently from your patch series,
  so please drop this one.

 OK, thanks for dealing with that.

 
 
  BTW, the word cleanup in the subject is inappropriate.  This is
  rather a fix together with the core change.

 It is a cleanup since the patchset only addresses lock problem which
 is caused by the tasklet conversion.

 Well, the conversion to irqsave() is needed for the future drop of
 irq_save() in the caller, right?  Then this isn't a cleanup but a
 preparation for movement ahead.

Sounds more accurate, and I will change the title in next round, :-)

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


Re: linux-next: Tree for July 12 (v4l2-ioctl.c)

2012-07-16 Thread Ming Lei
On Thu, Jul 12, 2012 at 11:49 PM, Randy Dunlap rdun...@xenotime.net wrote:
 On 07/11/2012 11:03 PM, Stephen Rothwell wrote:

 Hi all,

 Changes since 20120710:



 on i386 and/or x86_64, drivers/media/video/v4l2-ioctl.c has too many
 errors to be listed here.  This is the beginning few lines of the errors:

I see the errors on ARM too.


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


Re: [RFC PATCH v2 6/8] media: v4l2: introduce two IOCTLs for object detection

2012-01-18 Thread Ming Lei
Remove other unrelated lists.

Hi Sylwester,

Thanks for your comment.

On Sat, Jan 14, 2012 at 5:16 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Ming,

 sorry for the late response. It's all looking better now, however there
 is still a few things that could be improved.

 On 12/14/2011 03:00 PM, Ming Lei wrote:
 This patch introduces two new IOCTLs and related data
 structure which will be used by the coming video device
 with object detect capability.

 The two IOCTLs and related data structure will be used by
 user space application to retrieve the results of object
 detection.

 The utility fdif[1] is useing the two IOCTLs to find
 objects(faces) deteced in raw images or video streams.

 [1],http://kernel.ubuntu.com/git?p=ming/fdif.git;a=shortlog;h=refs/heads/v4l2-fdif

 Signed-off-by: Ming Leiming@canonical.com
 ---
 v2:
       - extend face detection API to object detection API
       - introduce capability of V4L2_CAP_OBJ_DETECTION for object detection
       - 32/64 safe array parameter
 ---
   drivers/media/video/v4l2-ioctl.c |   41 -
   include/linux/videodev2.h        |  124 
 ++
   include/media/v4l2-ioctl.h       |    6 ++
   3 files changed, 170 insertions(+), 1 deletions(-)

 diff --git a/drivers/media/video/v4l2-ioctl.c 
 b/drivers/media/video/v4l2-ioctl.c
 index ded8b72..575d445 100644
 --- a/drivers/media/video/v4l2-ioctl.c
 +++ b/drivers/media/video/v4l2-ioctl.c
 @@ -2140,6 +2140,30 @@ static long __video_do_ioctl(struct file *file,
               dbgarg(cmd, index=%d, b-index);
               break;
       }
 +     case VIDIOC_G_OD_RESULT:
 +     {
 +             struct v4l2_od_result *or = arg;
 +
 +             if (!ops-vidioc_g_od_result)
 +                     break;
 +
 +             ret = ops-vidioc_g_od_result(file, fh, or);
 +
 +             dbgarg(cmd, index=%d, or-frm_seq);
 +             break;
 +     }

 +     case VIDIOC_G_OD_COUNT:
 +     {
 +             struct v4l2_od_count *oc = arg;
 +
 +             if (!ops-vidioc_g_od_count)
 +                     break;
 +
 +             ret = ops-vidioc_g_od_count(file, fh, oc);
 +
 +             dbgarg(cmd, index=%d, oc-frm_seq);
 +             break;
 +     }

 I'm uncertain if we need this ioctl at all. Now struct v4l2_od_result is:

IMO, it can simplify user application very much if the ioctl of
VIDIOC_G_OD_COUNT
is kept, see below.


 struct v4l2_od_result {
        __u32                   frame_sequence;
        __u32                   object_count;
        __u32                   reserved[6];
        struct v4l2_od_object   objects[0];
 };

 and

 struct v4l2_od_object {
        __u16                   type;
        __u16                   confidence;
        union {
                struct v4l2_od_face_desc  face;
                struct v4l2_od_eye_desc   eye;
                struct v4l2_od_mouth_desc mouth;
                __u8    rawdata[60];
        } o;
 };

 If we had added a 'size' field to struct v4l2_od_result, i.e.

 struct v4l2_od_result {
        __u32                   size;
        __u32                   frame_sequence;
        __u32                   objects_count;
        __u32                   reserved[5];
        struct v4l2_od_object   objects[0];
 };

 the application could have allocated memory for the objects array and
 have the 'size' member set to the size of that allocation. Then it
 would have called VIDIOC_G_OD_RESULT and the driver would have filled
 the 'objects'  array, if it was big enough for the requested result
 data. The driver would also update the 'objects_count'. If the size
 would be too small to fit the result data, i.e.

 size  number_of_detected_objects * sizeof(struct v4l2_od_object)

 the driver could return -ENOSPC error while also setting 'size' to
 the required value. Something similar is done with

Without VIDIOC_G_OD_COUNT ioctl, user applications has no way to
know how many objects are detected in the specified frame, so it has
to allocate much more space to send to VIDIOC_G_OD_RESULT. Sometimes
it is enough, and sometimes it is not enough, looks a bit extra complicated
logic is introduced to space application.

 VIDIOC_G_EXT_CTRLS ioctl [3].

 There is one more OD API requirement, for camera sensors with embedded
 SoC ISP that support face detection, i.e. VIDIOC_G_OD_RESULT should
 allow to retrieve face detection result for the very last image frame,
 i.e. current frame.

IMO, it is better to always retrieve detection result via frame sequence number
if the seq can be known beforehand. But if it is difficult to get the
seq number in
user application for camera sensor case,  maybe we can introduce the flags to
handle it.


 One solution to support this could be adding a 'flags' field, i.e.

 struct v4l2_od_result {
        __u32                   size;
        __u32                   flags;
        __u32                   frame_sequence;
        __u32                   objects_count;
        __u16

Re: [RFC PATCH v2 4/8] media: videobuf2: introduce VIDEOBUF2_PAGE memops

2012-01-10 Thread Ming Lei
Hi,

On Tue, Jan 10, 2012 at 6:20 PM, Marek Szyprowski
m.szyprow...@samsung.com wrote:

 Sorry, could you describe the abuse problem in a bit detail?

 Videobuf2 requires memory module handlers to provide vaddr method to provide 
 a pointer in
 kernel virtual address space to video data (buffer content). It is used for 
 example by

Yes, this is what the patch is doing, __get_free_pages just  returns
the kernel virtual
address which will be passed to driver.

 read()/write() io method emulator. Memory allocator/handler should not be 
 specific to any
 particular use case in the device driver. That's the design. Simple.

Most of the patch is copied from videobuf-vmalloc.c, and the
interfaces are totally same
with videobuf-vmalloc.c.


 I your case you want to give pointer to struct page from the memory allocator 
 to the

In my case, the pointer to struct page is not required to the driver
at all, so I think you
have misunderstood the patch, don't I?

 driver. The cookie method has been introduced exactly for this purpose. 
 Memory allocator
 also provides a simple inline function to convert generic 'void *' return 
 type from cookie
 method to allocator specific structure/pointer. 
 vb2_dma_contig_plane_dma_addr() and
 vb2_dma_sg_plane_desc() were examples how does passing allocator specific 
 type though the
 cookie method works.

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


Re: [RFC PATCH v2 7/8] media: video: introduce object detection driver module

2012-01-04 Thread Ming Lei
Hi Sylwester,

Thanks for your review.

On Fri, Dec 30, 2011 at 1:16 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Ming,

 On 12/14/2011 03:00 PM, Ming Lei wrote:
 This patch introduces object detection generic driver.

 The driver is responsible for all v4l2 stuff, buffer management
 and other general things, and doesn't touch object detection hardware
 directly. Several interfaces are exported to low level drivers
 (such as the coming omap4 FD driver) which will communicate with
 object detection hw module.

 So the driver will make driving object detection hw modules more
 easy.
 TODO:
       - implement object detection setting interfaces with v4l2
       controls or ext controls

 Signed-off-by: Ming Lei ming@canonical.com
 ---
 v2:
       - extend face detection driver to object detection driver
       - introduce subdevice and media entity
       - provide support to detect object from media HW
 ---
  drivers/media/video/Kconfig       |    2 +
  drivers/media/video/Makefile      |    1 +
  drivers/media/video/odif/Kconfig  |    7 +
  drivers/media/video/odif/Makefile |    1 +
  drivers/media/video/odif/odif.c   |  890 
 +
  drivers/media/video/odif/odif.h   |  157 +++
  6 files changed, 1058 insertions(+), 0 deletions(-)
  create mode 100644 drivers/media/video/odif/Kconfig
  create mode 100644 drivers/media/video/odif/Makefile
  create mode 100644 drivers/media/video/odif/odif.c
  create mode 100644 drivers/media/video/odif/odif.h

 diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
 index 5684a00..8740ee9 100644
 --- a/drivers/media/video/Kconfig
 +++ b/drivers/media/video/Kconfig
 @@ -1166,3 +1166,5 @@ config VIDEO_SAMSUNG_S5P_MFC
           MFC 5.1 driver for V4L2.

  endif # V4L_MEM2MEM_DRIVERS
 +
 +source drivers/media/video/odif/Kconfig
 diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
 index bc797f2..259c8d8 100644
 --- a/drivers/media/video/Makefile
 +++ b/drivers/media/video/Makefile
 @@ -197,6 +197,7 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
  obj-y        += davinci/

  obj-$(CONFIG_ARCH_OMAP)      += omap/
 +obj-$(CONFIG_ODIF)   += odif/

  ccflags-y += -Idrivers/media/dvb/dvb-core
  ccflags-y += -Idrivers/media/dvb/frontends
 diff --git a/drivers/media/video/odif/Kconfig 
 b/drivers/media/video/odif/Kconfig
 new file mode 100644
 index 000..5090bd6
 --- /dev/null
 +++ b/drivers/media/video/odif/Kconfig
 @@ -0,0 +1,7 @@
 +config ODIF
 +     depends on VIDEO_DEV  VIDEO_V4L2
 +     select VIDEOBUF2_PAGE
 +     tristate Object Detection module
 +     help
 +       The ODIF is a object detection module, which can be integrated into
 +       some SoCs to detect objects in images or video.
 diff --git a/drivers/media/video/odif/Makefile 
 b/drivers/media/video/odif/Makefile
 new file mode 100644
 index 000..a55ff66
 --- /dev/null
 +++ b/drivers/media/video/odif/Makefile
 @@ -0,0 +1 @@
 +obj-$(CONFIG_ODIF)           += odif.o
 diff --git a/drivers/media/video/odif/odif.c 
 b/drivers/media/video/odif/odif.c
 new file mode 100644
 index 000..381ab9d
 --- /dev/null
 +++ b/drivers/media/video/odif/odif.c
 @@ -0,0 +1,890 @@
 +/*
 + *      odif.c  --  object detection module driver
 + *
 + *      Copyright (C) 2011  Ming Lei (ming@canonical.com)
 + *
 + *   This file is based on drivers/media/video/vivi.c.
 + *
 + *      This program is free software; you can redistribute it and/or modify
 + *      it under the terms of the GNU General Public License as published by
 + *      the Free Software Foundation; either version 2 of the License, or
 + *      (at your option) any later version.
 + *
 + *      This program is distributed in the hope that it will be useful,
 + *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *      GNU General Public License for more details.
 + *
 + *      You should have received a copy of the GNU General Public License
 + *      along with this program; if not, write to the Free Software
 + *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 + *
 + */
 +
 +/*/
 +
 +#include linux/module.h
 +#include linux/fs.h
 +#include linux/mm.h
 +#include linux/signal.h
 +#include linux/wait.h
 +#include linux/poll.h
 +#include linux/mman.h
 +#include linux/pm_runtime.h
 +#include linux/delay.h
 +#include linux/platform_device.h
 +#include linux/interrupt.h
 +#include asm/uaccess.h
 +#include asm/byteorder.h
 +#include asm/io.h
 +#include odif.h
 +
 +#define      input_from_user(dev) \
 +     (dev-input == OD_INPUT_FROM_USER_SPACE)
 +
 +#define      DEFAULT_PENDING_RESULT_CNT      8
 +
 +static unsigned debug = 0;
 +module_param(debug, uint, 0644);
 +MODULE_PARM_DESC(debug, activates debug info);
 +
 +static unsigned result_cnt_threshold = DEFAULT_PENDING_RESULT_CNT;
 +module_param

Re: [RFC PATCH v1 5/7] media: v4l2: introduce two IOCTLs for face detection

2011-12-25 Thread Ming Lei
Hi,

On Thu, Dec 22, 2011 at 3:32 AM, Sylwester Nawrocki snj...@gmail.com wrote:

 How is face detection enabled or disabled?

 Currently, streaming on will trigger detection enabling, and streaming off
 will trigger detection disabling.

 We would need to develop a boolean control for this I think, this seems one of
 the basic features for the configuration interface.

Yes, it is another way to do it, but considered that for the current two use
cases(detect objects on user space image or video, detect objects on
video stream from internal SoC bus), it is implicit that the video device
should have stream capability, so I think it is still OK to do it via
streaming on
and streaming off interface.


 Could you let me know how to do it?

 You would have to use multi-planar interface for that, which would introduce
 additional complexity at user interface. Moreover variable plane count is not
 supported in vb2. Relatively significant effort is required to add this IMHO.

So the the introduced two IOCTLs are good to do it, right?

Sylwester, could you help to review the v2 patches if you are available?

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


Re: [RFC PATCH v2 4/8] media: videobuf2: introduce VIDEOBUF2_PAGE memops

2011-12-23 Thread Ming Lei
On Thu, Dec 22, 2011 at 5:28 PM, Marek Szyprowski
m.szyprow...@samsung.com wrote:
 Hello,

 On Wednesday, December 14, 2011 3:00 PM Ming Lei wrote:

 DMA contig memory resource is very limited and precious, also
 accessing to it from CPU is very slow on some platform.

 For some cases(such as the comming face detection driver), DMA Streaming
 buffer is enough, so introduce VIDEOBUF2_PAGE to allocate continuous
 physical memory but letting video device driver to handle DMA buffer mapping
 and unmapping things.

 Signed-off-by: Ming Lei ming@canonical.com

 Could you elaborate a bit why do you think that DMA contig memory resource
 is so limited? If dma_alloc_coherent fails because of the memory 
 fragmentation,
 the alloc_pages() call with order  0 will also fail.

For example, on ARM, there is very limited kernel virtual address space reserved
for DMA coherent buffer mapping, the default size is about 2M if I
don't remember
mistakenly.


 I understand that there might be some speed issues with coherent (uncached)
 userspace mappings, but I would solve it in completely different way. The 
 interface

Also there is poor performance inside kernel space, see [1]

 for both coherent/uncached and non-coherent/cached contig allocator should be 
 the
 same, so exchanging them is easy and will not require changes in the driver.
 I'm planning to introduce some design changes in memory allocator api and 
 introduce
 prepare and finish callbacks in allocator ops. I hope to post the rfc after
 Christmas. For your face detection driver using standard dma-contig allocator
 shouldn't be a big issue.

 Your current implementation also abuses the design and api of videobuf2 memory
 allocators. If the allocator needs to return a custom structure to the driver

I think returning vaddr is enough.

 you should use cookie method. vaddr is intended to provide only a pointer to
 kernel virtual mapping, but you pass a struct page * there.

No, __get_free_pages returns virtual address instead of 'struct page *'.


thanks,
--
Ming Lei

[1], http://marc.info/?t=13119814851r=1w=2
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH v2 4/8] media: videobuf2: introduce VIDEOBUF2_PAGE memops

2011-12-23 Thread Ming Lei
Hi,

On Fri, Dec 23, 2011 at 5:34 PM, Marek Szyprowski
m.szyprow...@samsung.com wrote:

 For example, on ARM, there is very limited kernel virtual address space 
 reserved
 for DMA coherent buffer mapping, the default size is about 2M if I
 don't remember mistakenly.

 It can be easily increased for particular boards, there is no problem with 
 this.

It is not easily to increase it because there is very limited space reserved for
this purpose, see Documentation/arm/memory.txt. Also looks like it is
not configurable.


  I understand that there might be some speed issues with coherent (uncached)
  userspace mappings, but I would solve it in completely different way. The 
  interface

 Also there is poor performance inside kernel space, see [1]

 Your driver doesn't access video data inside kernel space, so this is also 
 not an issue.

Why not introduce it so that other drivers(include face detection) can
benefit with it? :-)

 
  Your current implementation also abuses the design and api of videobuf2 
  memory
  allocators. If the allocator needs to return a custom structure to the 
  driver

 I think returning vaddr is enough.

  you should use cookie method. vaddr is intended to provide only a pointer 
  to
  kernel virtual mapping, but you pass a struct page * there.

 No, __get_free_pages returns virtual address instead of 'struct page *'.

 Then you MUST use cookie for it. vaddr method should return kernel virtual 
 address
 to the buffer video data. Some parts of videobuf2 relies on this - it is used 
 by file
 io emulator (read(), write() calls) and mmap equivalent for non-mmu systems.

 Manual casting in the driver is also a bad idea, that's why there are helper 
 functions

I don't see any casts are needed. The dma address can be got from vaddr with
dma_map_* easily in drivers, see the usage on patch 8/8(media: video: introduce
omap4 face detection module driver).

 defined for both dma_contig and dma_sg allocators: 
 vb2_dma_contig_plane_dma_addr() and
 vb2_dma_sg_plane_desc().

These two helpers are not needed and won't be provided by VIDEOBUF2_PAGE memops.

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


Re: [RFC PATCH v2 4/8] media: videobuf2: introduce VIDEOBUF2_PAGE memops

2011-12-23 Thread Ming Lei
Hi,

On Fri, Dec 23, 2011 at 6:38 PM, Marek Szyprowski
m.szyprow...@samsung.com wrote:
 Hello,

 On Friday, December 23, 2011 10:51 AM Ming Lei wrote:

 On Fri, Dec 23, 2011 at 5:34 PM, Marek Szyprowski
 m.szyprow...@samsung.com wrote:

  For example, on ARM, there is very limited kernel virtual address space 
  reserved
  for DMA coherent buffer mapping, the default size is about 2M if I
  don't remember mistakenly.
 
  It can be easily increased for particular boards, there is no problem with 
  this.

 It is not easily to increase it because there is very limited space reserved 
 for
 this purpose, see Documentation/arm/memory.txt. Also looks like it is
 not configurable.

 It is really not a big issue to increase it by a few MBytes.

IMO, the extra few MBytes are not helpful for the issue at all, considered the
kernel virtual memory address fragmentation problem, you know there is only
several MBytes DMA coherent virtual address space on ARM.


   I understand that there might be some speed issues with coherent 
   (uncached)
   userspace mappings, but I would solve it in completely different way. 
   The interface
 
  Also there is poor performance inside kernel space, see [1]
 
  Your driver doesn't access video data inside kernel space, so this is also 
  not an issue.

 Why not introduce it so that other drivers(include face detection) can
 benefit with it? :-)

 We can get back into this once a driver which really benefits from comes.

In fact, streaming DMA is more widespread used than coherent DMA in
kernel, so why can't videobuf2 support streaming dma? :-)

You know under some situation, coherent DMA buffer is very slower than
other buffer to be accessed by CPU.


  
   Your current implementation also abuses the design and api of videobuf2 
   memory
   allocators. If the allocator needs to return a custom structure to the 
   driver
 
  I think returning vaddr is enough.
 
   you should use cookie method. vaddr is intended to provide only a 
   pointer to
   kernel virtual mapping, but you pass a struct page * there.
 
  No, __get_free_pages returns virtual address instead of 'struct page *'.
 
  Then you MUST use cookie for it. vaddr method should return kernel virtual 
  address
  to the buffer video data. Some parts of videobuf2 relies on this - it is 
  used by file
  io emulator (read(), write() calls) and mmap equivalent for non-mmu 
  systems.
 
  Manual casting in the driver is also a bad idea, that's why there are 
  helper functions

 I don't see any casts are needed. The dma address can be got from vaddr with
 dma_map_* easily in drivers, see the usage on patch 8/8(media: video: 
 introduce
 omap4 face detection module driver).

 Sorry, but I won't accept such driver/allocator which abuses the defined API. 
 I've already
 pointed what vaddr method is used for.

Sorry, could you describe the abuse problem in a bit detail?


  defined for both dma_contig and dma_sg allocators: 
  vb2_dma_contig_plane_dma_addr() and
  vb2_dma_sg_plane_desc().

 These two helpers are not needed and won't be provided by VIDEOBUF2_PAGE 
 memops.

 I gave the example. Your allocator should have something similar.

I don't think the two helper are required for the VIDEOBUF2_PAGE memops, why
can't driver handle DMA mapping directly?


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


[RFC PATCH v2 0/7] media: introduce object detection(OD) driver

2011-12-14 Thread Ming Lei
Hi,

These v2 patches(against -next tree) introduce v4l2 based object
detection(OD) device driver, and enable face detection hardware[1]
on omap4 SoC.. The idea of implementing it on v4l2 is from from
Alan Cox, Sylwester and Greg-Kh.

For verification purpose, I write one user space utility[2] to
test the module and driver, follows its basic functions:

- detect faces in input grayscal picture(PGM raw, 320 by 240)
- detect faces in input y8 format video stream
- plot a rectangle to mark the detected faces, and save it as
another same format picture or video stream

Looks the performance of the module is not bad, see some detection
results on the link[3][4].

Face detection can be used to implement some interesting applications
(camera, face unlock, baby monitor, ...).

v2-v1:
- extend face detection API to object detection API
- extend face detection generic module to object detection module
- introduce subdevice and media entity to object detection module
- some minor fixes

TODO:
- implement OD setting interfaces with v4l2 controls or
ext controls

 arch/arm/mach-omap2/devices.c  |   33 +
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |   81 +++
 drivers/media/video/Kconfig|6 +
 drivers/media/video/Makefile   |2 +
 drivers/media/video/odif/Kconfig   |   13 +
 drivers/media/video/odif/Makefile  |2 +
 drivers/media/video/odif/fdif_omap4.c  |  685 +
 drivers/media/video/odif/odif.c|  890 
 drivers/media/video/odif/odif.h|  157 +
 drivers/media/video/v4l2-ioctl.c   |   72 +++-
 drivers/media/video/videobuf2-dma-contig.c |1 +
 drivers/media/video/videobuf2-memops.c |1 -
 drivers/media/video/videobuf2-page.c   |  117 
 include/linux/videodev2.h  |  124 
 include/media/v4l2-ioctl.h |6 +
 include/media/videobuf2-page.h |   20 +
 16 files changed, 2207 insertions(+), 3 deletions(-)



thanks,
--
Ming Lei

[1], Ch9 of OMAP4 Technical Reference Manual
[2], 
http://kernel.ubuntu.com/git?p=ming/fdif.git;a=shortlog;h=refs/heads/v4l2-fdif
[3], http://kernel.ubuntu.com/~ming/dev/fdif/output
[4], All pictures are taken from http://www.google.com/imghp
and converted to pnm from jpeg format, only for test purpose.

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


[RFC PATCH v2 2/8] omap4: build fdif omap device from hwmod

2011-12-14 Thread Ming Lei
Signed-off-by: Ming Lei ming@canonical.com
---
 arch/arm/mach-omap2/devices.c |   33 +
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 1166bdc..bd7f9b3 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -728,6 +728,38 @@ void __init omap242x_init_mmc(struct 
omap_mmc_platform_data **mmc_data)
 
 #endif
 
+static __init struct platform_device *omap4_init_fdif(void)
+{
+   struct platform_device *pd;
+   struct omap_hwmod *oh;
+   const char *dev_name = omap-fdif;
+
+   oh = omap_hwmod_lookup(fdif);
+   if (!oh) {
+   pr_err(Could not look up fdif hwmod\n);
+   return NULL;
+   }
+
+   pd = omap_device_build(dev_name, -1, oh, NULL, 0, NULL, 0, 0);
+   WARN(IS_ERR(pd), Can't build omap_device for %s.\n,
+   dev_name);
+   return pd;
+}
+
+static void __init omap_init_fdif(void)
+{
+   struct platform_device *pd;
+
+   if (!cpu_is_omap44xx())
+   return;
+
+   pd = omap4_init_fdif();
+   if (!pd)
+   return;
+
+   pm_runtime_enable(pd-dev);
+}
+
 /*-*/
 
 #if defined(CONFIG_HDQ_MASTER_OMAP) || defined(CONFIG_HDQ_MASTER_OMAP_MODULE)
@@ -808,6 +840,7 @@ static int __init omap2_init_devices(void)
omap_init_sham();
omap_init_aes();
omap_init_vout();
+   omap_init_fdif();
 
return 0;
 }
-- 
1.7.5.4

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


[RFC PATCH v2 4/8] media: videobuf2: introduce VIDEOBUF2_PAGE memops

2011-12-14 Thread Ming Lei
DMA contig memory resource is very limited and precious, also
accessing to it from CPU is very slow on some platform.

For some cases(such as the comming face detection driver), DMA Streaming
buffer is enough, so introduce VIDEOBUF2_PAGE to allocate continuous
physical memory but letting video device driver to handle DMA buffer mapping
and unmapping things.

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/video/Kconfig  |4 +
 drivers/media/video/Makefile |1 +
 drivers/media/video/videobuf2-page.c |  117 ++
 include/media/videobuf2-page.h   |   20 ++
 4 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/videobuf2-page.c
 create mode 100644 include/media/videobuf2-page.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 4e8a0c4..5684a00 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -60,6 +60,10 @@ config VIDEOBUF2_VMALLOC
select VIDEOBUF2_MEMOPS
tristate
 
+config VIDEOBUF2_PAGE
+   select VIDEOBUF2_CORE
+   select VIDEOBUF2_MEMOPS
+   tristate
 
 config VIDEOBUF2_DMA_SG
#depends on HAS_DMA
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index ddeaa6c..bc797f2 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -125,6 +125,7 @@ obj-$(CONFIG_VIDEO_BTCX)  += btcx-risc.o
 obj-$(CONFIG_VIDEOBUF2_CORE)   += videobuf2-core.o
 obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o
 obj-$(CONFIG_VIDEOBUF2_VMALLOC)+= videobuf2-vmalloc.o
+obj-$(CONFIG_VIDEOBUF2_PAGE)   += videobuf2-page.o
 obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o
 obj-$(CONFIG_VIDEOBUF2_DMA_SG) += videobuf2-dma-sg.o
 
diff --git a/drivers/media/video/videobuf2-page.c 
b/drivers/media/video/videobuf2-page.c
new file mode 100644
index 000..6a24a34
--- /dev/null
+++ b/drivers/media/video/videobuf2-page.c
@@ -0,0 +1,117 @@
+/*
+ * videobuf2-page.c - page memory allocator for videobuf2
+ *
+ * Copyright (C) 2011 Canonical Ltd.
+ *
+ * Author: Ming Lei ming@canonical.com
+ *
+ * This file is based on videobuf2-vmalloc.c
+ *
+ * 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.
+ */
+
+#include linux/module.h
+#include linux/mm.h
+#include linux/slab.h
+
+#include media/videobuf2-core.h
+#include media/videobuf2-memops.h
+
+struct vb2_page_buf {
+   void*vaddr;
+   unsigned long   size;
+   atomic_trefcount;
+   struct vb2_vmarea_handler   handler;
+};
+
+static void vb2_page_put(void *buf_priv);
+
+static void *vb2_page_alloc(void *alloc_ctx, unsigned long size)
+{
+   struct vb2_page_buf *buf;
+
+   buf = kzalloc(sizeof *buf, GFP_KERNEL);
+   if (!buf)
+   return NULL;
+
+   buf-size = size;
+   buf-vaddr = (void *)__get_free_pages(GFP_KERNEL,
+   get_order(buf-size));
+   buf-handler.refcount = buf-refcount;
+   buf-handler.put = vb2_page_put;
+   buf-handler.arg = buf;
+
+   if (!buf-vaddr) {
+   printk(KERN_ERR page of size %ld failed\n, buf-size);
+   kfree(buf);
+   return NULL;
+   }
+
+   atomic_inc(buf-refcount);
+   printk(KERN_DEBUG Allocated page buffer of size %ld at vaddr=%p\n,
+   buf-size, buf-vaddr);
+
+   return buf;
+}
+
+static void vb2_page_put(void *buf_priv)
+{
+   struct vb2_page_buf *buf = buf_priv;
+
+   if (atomic_dec_and_test(buf-refcount)) {
+   printk(KERN_DEBUG %s: Freeing page mem at vaddr=%p\n,
+   __func__, buf-vaddr);
+   free_pages((unsigned long)buf-vaddr, get_order(buf-size));
+   kfree(buf);
+   }
+}
+
+static void *vb2_page_vaddr(void *buf_priv)
+{
+   struct vb2_page_buf *buf = buf_priv;
+
+   BUG_ON(!buf);
+
+   if (!buf-vaddr) {
+   printk(KERN_ERR Address of an unallocated plane requested\n);
+   return NULL;
+   }
+
+   return buf-vaddr;
+}
+
+static unsigned int vb2_page_num_users(void *buf_priv)
+{
+   struct vb2_page_buf *buf = buf_priv;
+   return atomic_read(buf-refcount);
+}
+
+static int vb2_page_mmap(void *buf_priv, struct vm_area_struct *vma)
+{
+   struct vb2_page_buf *buf = buf_priv;
+
+   if (!buf) {
+   printk(KERN_ERR No memory to map\n);
+   return -EINVAL;
+   }
+
+   vma-vm_page_prot = vm_get_page_prot(vma-vm_flags);
+   return vb2_mmap_pfn_range(vma, virt_to_phys(buf-vaddr),
+   buf-size, vb2_common_vm_ops,
+   buf-handler);
+}
+
+const struct vb2_mem_ops vb2_page_memops = {
+   .alloc

[RFC PATCH v2 7/8] media: video: introduce object detection driver module

2011-12-14 Thread Ming Lei
This patch introduces object detection generic driver.

The driver is responsible for all v4l2 stuff, buffer management
and other general things, and doesn't touch object detection hardware
directly. Several interfaces are exported to low level drivers
(such as the coming omap4 FD driver) which will communicate with
object detection hw module.

So the driver will make driving object detection hw modules more
easy.

TODO:
- implement object detection setting interfaces with v4l2
controls or ext controls

Signed-off-by: Ming Lei ming@canonical.com
---
v2:
- extend face detection driver to object detection driver
- introduce subdevice and media entity
- provide support to detect object from media HW
---
 drivers/media/video/Kconfig   |2 +
 drivers/media/video/Makefile  |1 +
 drivers/media/video/odif/Kconfig  |7 +
 drivers/media/video/odif/Makefile |1 +
 drivers/media/video/odif/odif.c   |  890 +
 drivers/media/video/odif/odif.h   |  157 +++
 6 files changed, 1058 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/odif/Kconfig
 create mode 100644 drivers/media/video/odif/Makefile
 create mode 100644 drivers/media/video/odif/odif.c
 create mode 100644 drivers/media/video/odif/odif.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 5684a00..8740ee9 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -1166,3 +1166,5 @@ config VIDEO_SAMSUNG_S5P_MFC
MFC 5.1 driver for V4L2.
 
 endif # V4L_MEM2MEM_DRIVERS
+
+source drivers/media/video/odif/Kconfig
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index bc797f2..259c8d8 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -197,6 +197,7 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
 obj-y  += davinci/
 
 obj-$(CONFIG_ARCH_OMAP)+= omap/
+obj-$(CONFIG_ODIF) += odif/
 
 ccflags-y += -Idrivers/media/dvb/dvb-core
 ccflags-y += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/video/odif/Kconfig b/drivers/media/video/odif/Kconfig
new file mode 100644
index 000..5090bd6
--- /dev/null
+++ b/drivers/media/video/odif/Kconfig
@@ -0,0 +1,7 @@
+config ODIF
+   depends on VIDEO_DEV  VIDEO_V4L2
+   select VIDEOBUF2_PAGE
+   tristate Object Detection module
+   help
+ The ODIF is a object detection module, which can be integrated into
+ some SoCs to detect objects in images or video.
diff --git a/drivers/media/video/odif/Makefile 
b/drivers/media/video/odif/Makefile
new file mode 100644
index 000..a55ff66
--- /dev/null
+++ b/drivers/media/video/odif/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_ODIF) += odif.o
diff --git a/drivers/media/video/odif/odif.c b/drivers/media/video/odif/odif.c
new file mode 100644
index 000..381ab9d
--- /dev/null
+++ b/drivers/media/video/odif/odif.c
@@ -0,0 +1,890 @@
+/*
+ *  odif.c  --  object detection module driver
+ *
+ *  Copyright (C) 2011  Ming Lei (ming@canonical.com)
+ *
+ * This file is based on drivers/media/video/vivi.c.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*/
+
+#include linux/module.h
+#include linux/fs.h
+#include linux/mm.h
+#include linux/signal.h
+#include linux/wait.h
+#include linux/poll.h
+#include linux/mman.h
+#include linux/pm_runtime.h
+#include linux/delay.h
+#include linux/platform_device.h
+#include linux/interrupt.h
+#include asm/uaccess.h
+#include asm/byteorder.h
+#include asm/io.h
+#include odif.h
+
+#defineinput_from_user(dev) \
+   (dev-input == OD_INPUT_FROM_USER_SPACE)
+
+#defineDEFAULT_PENDING_RESULT_CNT  8
+
+static unsigned debug = 0;
+module_param(debug, uint, 0644);
+MODULE_PARM_DESC(debug, activates debug info);
+
+static unsigned result_cnt_threshold = DEFAULT_PENDING_RESULT_CNT;
+module_param(result_cnt_threshold, uint, 0644);
+MODULE_PARM_DESC(result_cnt, max pending result count);
+
+static LIST_HEAD(odif_devlist);
+static unsigned video_nr = -1;
+
+int odif_open(struct file *file)
+{
+   struct odif_dev *dev = video_drvdata(file);
+
+   kref_get(dev

[RFC PATCH v2 6/8] media: v4l2: introduce two IOCTLs for object detection

2011-12-14 Thread Ming Lei
This patch introduces two new IOCTLs and related data
structure which will be used by the coming video device
with object detect capability.

The two IOCTLs and related data structure will be used by
user space application to retrieve the results of object
detection.

The utility fdif[1] is useing the two IOCTLs to find
objects(faces) deteced in raw images or video streams.

[1],http://kernel.ubuntu.com/git?p=ming/fdif.git;a=shortlog;h=refs/heads/v4l2-fdif

Signed-off-by: Ming Lei ming@canonical.com
---
v2:
- extend face detection API to object detection API
- introduce capability of V4L2_CAP_OBJ_DETECTION for object detection
- 32/64 safe array parameter
---
 drivers/media/video/v4l2-ioctl.c |   41 -
 include/linux/videodev2.h|  124 ++
 include/media/v4l2-ioctl.h   |6 ++
 3 files changed, 170 insertions(+), 1 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index ded8b72..575d445 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -2140,6 +2140,30 @@ static long __video_do_ioctl(struct file *file,
dbgarg(cmd, index=%d, b-index);
break;
}
+   case VIDIOC_G_OD_RESULT:
+   {
+   struct v4l2_od_result *or = arg;
+
+   if (!ops-vidioc_g_od_result)
+   break;
+
+   ret = ops-vidioc_g_od_result(file, fh, or);
+
+   dbgarg(cmd, index=%d, or-frm_seq);
+   break;
+   }
+   case VIDIOC_G_OD_COUNT:
+   {
+   struct v4l2_od_count *oc = arg;
+
+   if (!ops-vidioc_g_od_count)
+   break;
+
+   ret = ops-vidioc_g_od_count(file, fh, oc);
+
+   dbgarg(cmd, index=%d, oc-frm_seq);
+   break;
+   }
default:
if (!ops-vidioc_default)
break;
@@ -2241,7 +2265,22 @@ static int check_array_args(unsigned int cmd, void 
*parg, size_t *array_size,
 
 static int is_64_32_array_args(unsigned int cmd, void *parg, int *extra_len)
 {
-   return 0;
+   int ret = 0;
+
+   switch (cmd) {
+   case VIDIOC_G_OD_RESULT: {
+   struct v4l2_od_result *or = parg;
+
+   *extra_len = or-obj_cnt *
+   sizeof(struct v4l2_od_object);
+   ret = 1;
+   break;
+   }
+   default:
+   break;
+   }
+
+   return ret;
 }
 
 long
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 4b752d5..c08ceaf 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -270,6 +270,9 @@ struct v4l2_capability {
 #define V4L2_CAP_RADIO 0x0004  /* is a radio device */
 #define V4L2_CAP_MODULATOR 0x0008  /* has a modulator */
 
+/* The device has capability of object detection */
+#define V4L2_CAP_OBJ_DETECTION 0x0010
+
 #define V4L2_CAP_READWRITE  0x0100  /* read/write systemcalls 
*/
 #define V4L2_CAP_ASYNCIO0x0200  /* async I/O */
 #define V4L2_CAP_STREAMING  0x0400  /* streaming I/O ioctls */
@@ -2160,6 +2163,125 @@ struct v4l2_create_buffers {
__u32   reserved[8];
 };
 
+/**
+ * struct v4l2_od_obj_desc
+ * @centerx:   return, position in x direction of detected object
+ * @centery:   return, position in y direction of detected object
+ * @sizex: return, size in x direction of detected object
+ * @sizey: return, size in y direction of detected object
+ * @angle: return, angle of detected object
+ * 0 deg ~ 359 deg, vertical is 0 deg, clockwise
+ * @reserved:  future extensions
+ */
+struct v4l2_od_obj_desc {
+   __u16   centerx;
+   __u16   centery;
+   __u16   sizex;
+   __u16   sizey;
+   __u16   angle;
+   __u16   reserved[5];
+};
+
+/**
+ * struct v4l2_od_face_desc
+ * @id:return, used to be associated with detected eyes, mouth,
+ * and other objects inside this face, and each face in one
+ * frame has a unique id, start from 1
+ * @smile_level:return, smile level of the face
+ * @f: return, face description
+ */
+struct v4l2_od_face_desc {
+   __u16   id;
+   __u8smile_level;
+   __u8reserved[15];
+
+   struct v4l2_od_obj_desc f;
+};
+
+/**
+ * struct v4l2_od_eye_desc
+ * @face_id:   return, used to associate with which face, 0 means
+ * no face associated with the eye
+ * @blink_level:return, blink level of the eye
+ * @e: return, eye description
+ */
+struct v4l2_od_eye_desc {
+   __u16   face_id;
+   __u8blink_level;
+   __u8reserved[15];
+
+   struct v4l2_od_obj_desc e;
+};
+
+/**
+ * struct v4l2_od_mouth_desc
+ * @face_id:   return, used to associate

Re: [RFC PATCH v1 5/7] media: v4l2: introduce two IOCTLs for face detection

2011-12-14 Thread Ming Lei
Hi,

On Wed, Dec 14, 2011 at 11:34 PM, Sakari Ailus sakari.ai...@iki.fi wrote:

 +     case VIDIOC_G_FD_RESULT:
 +     {
 +             struct v4l2_fd_result *fr = arg;
 +
 +             if (!ops-vidioc_g_fd_result)
 +                     break;
 +
 +             ret = ops-vidioc_g_fd_result(file, fh, fr);
 +
 +             dbgarg(cmd, index=%d, fr-buf_index);
 +             break;
 +     }
 +     case VIDIOC_G_FD_COUNT:
 +     {
 +             struct v4l2_fd_count *fc = arg;
 +
 +             if (!ops-vidioc_g_fd_count)
 +                     break;
 +
 +             ret = ops-vidioc_g_fd_count(file, fh, fc);
 +
 +             dbgarg(cmd, index=%d, fc-buf_index);
 +             break;
 +     }

 The patch description tells these ioctls may be called between... what? I'd

In fact, these ioctls should be called after return from poll.

 think such information could be better provided as events.

Yes, I still think so, but the length of returned data is variant, also
event has the 64 byte length's limitation.

 How is face detection enabled or disabled?

Currently, streaming on will trigger detection enabling, and streaming off
will trigger detection disabling.


 Could you detect other objects than faces?

The -v2 has been extended to detect objects, not limited to faces.

 Would events be large enough to deliver you the necessary data? We could

Looks like event(64 bytes) is not large enough to deliver the data.

 also consider delivering the information as a data structure on a separate
 plane.

Could you let me know how to do it?

 +/**
 + * struct v4l2_fd_result - VIDIOC_G_FD_RESULT argument
 + * @buf_index:       entry, index of v4l2_buffer for face detection
 + * @face_cnt:        return, how many faces detected from the @buf_index
 + * @fd:              return, result of faces' detection
 + */
 +struct v4l2_fd_result {
 +     __u32   buf_index;
 +     __u32   face_cnt;
 +     __u32   reserved[6];
 +     struct v4l2_fd_detection *fd;

 Aligning structure sizes to a power of two is considered to be a good
 practice.

There are many changes on these structure in -v2.


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


Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-12 Thread Ming Lei
Hi,

On Mon, Dec 12, 2011 at 1:43 AM, Sylwester Nawrocki snj...@gmail.com

 For OMAP4 FD, it is not needed to include FD into MC framework since a
 intermediate buffer is always required. If your HW doesn't belong to this
 case, what is the output of your HW FD in the link? Also sounds FD results
 may not be needed at all for use space application in the case.

 The result data is similar to OMAP4 one, plus a few other attributes.
 User buffers may be filled by other than FD device driver.

OK.


 Could you provide some practical use cases about these?

 As above, and any device with a camera that controls something and makes
 decision according to presence of human face in his view.

Sounds a reasonable case, :-)


 If FD result is associated with a frame, how can user space get the frame seq
 if no v4l2 buffer is involved? Without a frame sequence, it is a bit
 difficult to retrieve FD results from user space.

 If you pass image data in memory buffers from user space, yes, it could be
 impossible.

It is easy to get the frame sequence from v4l2_buffer for the case too, :-)


 Not really, still v4l2_buffer may be used by other (sub)driver within same 
 video
 processing pipeline.

OK.

A related question: how can we make one application to support the two kinds of
devices(input from user space data as OMAP4, input from SoC bus as Samsung)
at the same time? Maybe some capability info is to be exported to user space?
or other suggestions?

And will your Samsung FD HW support to detect faces from memory? or just only
detect from SoC bus?


 It will be included in the FD result... or in a dedicated v4l2 event data 
 structure.
 More important, at the end of the day, we'll be getting buffers with image 
 data
 at some stage of a video pipeline, which would contain same frame identifier
 (I think we can ignore v4l2_buffer.field for FD purpose).

OK, I will associate FD result with frame identifier, and not invent a
dedicated v4l2 event for query frame seq now until a specific requirement
for it is proposed.

I will convert/integrate recent discussions into patches of v2 for further
review, and sub device support will be provided. But before starting to do it,
I am still not clear how to integrate FD into MC framework. I understand FD
sub device is only a media entity, so how can FD sub device find the media
device(struct media_device)?  or just needn't to care about it now?


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


Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-12 Thread Ming Lei
Hi,

On Mon, Dec 12, 2011 at 8:08 PM, HeungJun, Kim riverful@samsung.com wrote:
 Hi Ming,

 It's maybe late, but I want to suggest one thing about FD API.

 This OMAP FD block looks detection ability of just face.
 But, It's possible to occur another device which can detect
 specific object or patterns. Moreover, this API can expand
 object recognition area. So, I think it's good to change the API name
 like v4l2_recog.

IMO, object detection is better,  at least now OMAP4 and samsung has
face detection IP module, and face recognition is often done on results
of face detection and more complicated interfaces will be involved.


 Actually, I'm preparing similar control class for mainline with m5mols
 camera sensor driver. The m5mols camera sensor has the function about
 face detection. But, I has experienced about Robot Recognition, and I
 remember the image processing chip which can detect spefic pattern.
 So, I hesitated naming the API(control or ioctl whatever) with face.
 It can be possible to provide just object or pattern, not face.
 Even user library on windows, there is famous OpenCV. And this is also
 support not only face, but also object.

Yes, object is better than face, and we can use enum flag to describe that
the objects detected are which kind of objects. In fact, I plan to rename the
face detection generic driver as object detection generic driver and let
hardware driver to handle the object detection details.


 The function of OMAP FDIF looks like m5mols ISP's one.
 please understand I don't have experience about OMAP AP. But, I can tell
 you it's better to use the name object recognition, not the face 
 detection,
 for any other device or driver.

 In a few days, I'll share the CIDs I have thought for m5mols driver.
 And, I hope to discuss about this with OMAP FDIF.

You have been doing it already, :-)

thanks,
--
Ming Lei


 Thank you.

 Regards,
 Heungjun Kim


 -Original Message-
 From: linux-media-ow...@vger.kernel.org [mailto:linux-media-
 ow...@vger.kernel.org] On Behalf Of Ming Lei
 Sent: Monday, December 12, 2011 6:50 PM
 To: Sylwester Nawrocki
 Cc: linux-o...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
 ker...@vger.kernel.org; linux-media@vger.kernel.org
 Subject: Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver
 module

 Hi,

 On Mon, Dec 12, 2011 at 1:43 AM, Sylwester Nawrocki snj...@gmail.com

  For OMAP4 FD, it is not needed to include FD into MC framework since a
  intermediate buffer is always required. If your HW doesn't belong to this
  case, what is the output of your HW FD in the link? Also sounds FD results
  may not be needed at all for use space application in the case.
 
  The result data is similar to OMAP4 one, plus a few other attributes.
  User buffers may be filled by other than FD device driver.

 OK.


  Could you provide some practical use cases about these?
 
  As above, and any device with a camera that controls something and makes
  decision according to presence of human face in his view.

 Sounds a reasonable case, :-)


  If FD result is associated with a frame, how can user space get the frame
 seq
  if no v4l2 buffer is involved? Without a frame sequence, it is a bit
  difficult to retrieve FD results from user space.
 
  If you pass image data in memory buffers from user space, yes, it could be
  impossible.

 It is easy to get the frame sequence from v4l2_buffer for the case too, :-)

 
  Not really, still v4l2_buffer may be used by other (sub)driver within same
 video
  processing pipeline.

 OK.

 A related question: how can we make one application to support the two kinds
 of
 devices(input from user space data as OMAP4, input from SoC bus as Samsung)
 at the same time? Maybe some capability info is to be exported to user space?
 or other suggestions?

 And will your Samsung FD HW support to detect faces from memory? or just only
 detect from SoC bus?


  It will be included in the FD result... or in a dedicated v4l2 event data
 structure.
  More important, at the end of the day, we'll be getting buffers with image
 data
  at some stage of a video pipeline, which would contain same frame 
  identifier
  (I think we can ignore v4l2_buffer.field for FD purpose).

 OK, I will associate FD result with frame identifier, and not invent a
 dedicated v4l2 event for query frame seq now until a specific requirement
 for it is proposed.

 I will convert/integrate recent discussions into patches of v2 for further
 review, and sub device support will be provided. But before starting to do 
 it,
 I am still not clear how to integrate FD into MC framework. I understand FD
 sub device is only a media entity, so how can FD sub device find the media
 device(struct media_device)?  or just needn't to care about it now?


 thanks,
 --
 Ming Lei
 --
 To unsubscribe from this list: send the line unsubscribe linux-media in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http

Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-12 Thread Ming Lei
On Tue, Dec 13, 2011 at 1:59 PM, HeungJun, Kim riverful@samsung.com wrote:
 Hi Ming and Sylwester,

 Thanks for the reply.

 -Original Message-
 From: Ming Lei [mailto:ming@canonical.com]
 Sent: Tuesday, December 13, 2011 1:02 PM
 To: HeungJun, Kim
 Cc: Sylwester Nawrocki; linux-o...@vger.kernel.org; linux-arm-
 ker...@lists.infradead.org; linux-ker...@vger.kernel.org; linux-
 me...@vger.kernel.org
 Subject: Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver
 module

 Hi,

 On Mon, Dec 12, 2011 at 8:08 PM, HeungJun, Kim riverful@samsung.com
 wrote:
  Hi Ming,
 
  It's maybe late, but I want to suggest one thing about FD API.
 
  This OMAP FD block looks detection ability of just face.
  But, It's possible to occur another device which can detect
  specific object or patterns. Moreover, this API can expand
  object recognition area. So, I think it's good to change the API name
  like v4l2_recog.

 IMO, object detection is better,  at least now OMAP4 and samsung has
 face detection IP module, and face recognition is often done on results
 of face detection and more complicated interfaces will be involved.
 Actually, the detection point is different, I guess.
 The OMAP has the detection block separately, named FDIF. But, Samsung
 Exynos doing detection process with externel sensor - m5mols, in our case.
 This sensor(m5mols) has ISP function, and these ISP can process detection.
 The expert of FIMC is Sylwester. Probably, he can tell the differences
 between both in more details. :)


 
  Actually, I'm preparing similar control class for mainline with m5mols
  camera sensor driver. The m5mols camera sensor has the function about
  face detection. But, I has experienced about Robot Recognition, and I
  remember the image processing chip which can detect spefic pattern.
  So, I hesitated naming the API(control or ioctl whatever) with face.
  It can be possible to provide just object or pattern, not face.
  Even user library on windows, there is famous OpenCV. And this is also
  support not only face, but also object.

 Yes, object is better than face, and we can use enum flag to describe that
 the objects detected are which kind of objects. In fact, I plan to rename the
 face detection generic driver as object detection generic driver and let
 hardware driver to handle the object detection details.

 
  The function of OMAP FDIF looks like m5mols ISP's one.
  please understand I don't have experience about OMAP AP. But, I can tell
  you it's better to use the name object recognition, not the face
 detection,
  for any other device or driver.
 
  In a few days, I'll share the CIDs I have thought for m5mols driver.
  And, I hope to discuss about this with OMAP FDIF.

 You have been doing it already, :-)
 Yeah, actually I did. :)
 But, until I see OMAP FDIF case, I did not recognize AP(like OMAP) can
 have detection capability. :) So, although I did not think about at that time,
 I also think we should re-consider this case for now.

 As I look around your patch quickly, the functions is very similar with ours.
 (even detection of left/right eye)
 So, the problem is there are two ways to proceed recognition.
 - Does it handle at the level of IOCTLs? or CIDs?

The patch introduces two IOCTL to retrieve object detection result.
I think it should be handled by IOCTL. The interface is a little complex,
so it is not easy to handle it by CIDs, IMO.


 If the detection algorithm is proceeded at the level of HW block,
 it's right the platform driver provide APIs as IOCTLs(as you're FDIF patches).
 On the other hand, if it is proceeded at the sensor(subdevice) level,
 I think it's more right to control using CIDs.

Certainly, some generic CIDs for object detection will be introduced later and
will be handled in the object detection(the current fdif generic
driver, patch 6/7)
generic driver.

 We need the solution including those two cases.
 And the name - object detection? object recognition?

I think object detection is better. For example, face detection is very
different with face recognition, isn't it?

thanks,
--
Ming Lei


 So, do you have any good ideas?

 ps. There can be another not-matched HW block level issues.
 But, the problem which I can check is just above issue for now.


 Thanks,
 Heungjun Kim



 thanks,
 --
 Ming Lei

 
  Thank you.
 
  Regards,
  Heungjun Kim
 
 
  -Original Message-
  From: linux-media-ow...@vger.kernel.org [mailto:linux-media-
  ow...@vger.kernel.org] On Behalf Of Ming Lei
  Sent: Monday, December 12, 2011 6:50 PM
  To: Sylwester Nawrocki
  Cc: linux-o...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
 linux-
  ker...@vger.kernel.org; linux-media@vger.kernel.org
  Subject: Re: [RFC PATCH v1 6/7] media: video: introduce face detection
 driver
  module
 
  Hi,
 
  On Mon, Dec 12, 2011 at 1:43 AM, Sylwester Nawrocki snj...@gmail.com
 
   For OMAP4 FD, it is not needed to include FD into MC framework since a
   intermediate buffer

Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-09 Thread Ming Lei
On Fri, Dec 9, 2011 at 7:25 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 On 12/07/2011 02:40 PM, Ming Lei wrote:
 I understand the API you mentioned here should belong to kernel internal
 API, correct me if it is wrong.

 Yes, I meant the in kernel design, i.e. generic face detection kernel module
 and an OMAP4 FDIF driver. It makes lots of sense to separate common code
 in this way, maybe even when there would be only OMAP devices using it.

 Yes, that is the motivation of the generic FD module. I think we can focus on
 two use cases for the generic FD now:

 - one is to detect faces from user space image data

 - another one is to detect faces in image data generated from HW(SoC
 internal bus, resize hardware)

 For OMAP4 hardware, input data is always from physically continuous
 memory directly, so it is very easy to support the two cases. For the
 use case 2,
 if buffer copy is to be avoided, we can use the coming shared dma-buf[1]
 to pass the image buffer produced by other HW to FD hw directly.

 Some H/W uses direct data buses to exchange data between processing blocks,
 and there is no need for additional memory. We only need to manage the data
 links, for which MC has been designed.

For OMAP4 FD, it is not needed to include FD into MC framework since a
intermediate buffer is always required. If your HW doesn't belong to this
case, what is the output of your HW FD in the link? Also sounds FD results
may not be needed at all for use space application in the case.



 For other FD hardware, if it supports to detect faces in image data from
 physically continuous memory, I think the patch is OK to support it.

 If the FD hw doesn't support to detect faces from physically continuous
 memory, I have some questions: how does user space app to parse the
 FD result if application can't get the input image data? If user space can

 Do we need the map of detected objects on a input image in all cases ?

For normal cases, I think we need, :-)

 If an application needs only coordinates of detected object on a video
 signal to for example, focus on it, trigger some action, or just count
 detected faces, etc. Perhaps there are more practical similar use cases.

Could you provide some practical use cases about these?

 get image data, how does it connect the image data with FD result? and

 If hardware provides frame sequence numbers the FD result can be associated
 with a frame, whether it's passing through H/W interconnect or is located
 in memory.

If FD result is associated with a frame, how can user space get the frame seq
if no v4l2 buffer is involved? Without a frame sequence, it is a bit
difficult to
retrieve FD results from user space.

 what standard v4l2 ways(v4l2_buffer?) can the app use to describe the
 image data?

 We have USERPTR and MMAP memeory buffer for streaming IO, those use
 v4l2_buffer 1). read()/write() is also used 2), mostly for compressed formats.
 Except that there are works on shared buffers.

If the input image data is from other HW(SoC bus, resizer HW, ...), is the
v4l2_buffer needed for the FD HW driver or application?



 I'm sure now the Samsung devices won't fit in video output node based driver
 design. They read image data in different ways and also the FD result format
 is totally different.

 I think user space will need the FD result, so it is very important to define
 API to describe the FD result format to user space. And the input about your
 FD HW result format is certainly helpful to define the API.

 I'll post exact attributes generated by our FD detection H/W soon.

Good news, :-)



 AFAICS OMAP4 FDIF processes only data stored in memory, thus it seems
 reasonable to use the videodev interface for passing data to the kernel
 from user space.

 But there might be face detection devices that accept data from other
 H/W modules, e.g. transferred through SoC internal data buses between
 image processing pipeline blocks. Thus any new interfaces need to be
 designed with such devices in mind.

 Also the face detection hardware block might now have an input DMA
 engine in it, the data could be fed from memory through some other
 subsystem (e.g. resize/colour converter). Then the driver for that
 subsystem would implement a video node.

 I think the direct input image or frame data to FD should be from memory
 no matter the actual data is from external H/W modules or input DMA because
 FD will take lot of time to detect faces in one image or frame and FD can't
 have so much memory to cache several images or frames data.

 Sorry, I cannot provide much details at the moment, but there exists 
 hardware
 that reads data from internal SoC buses and even if it uses some sort of
 cache memory it doesn't necessarily have to be available for the user.

 Without some hardware background, it is not easy to give a generic FD module
 design.

 Yes, please give me some time so I can prepare the list of requirements.


 Still the FD result is associated with an image frame

Re: [RFC PATCH v1 5/7] media: v4l2: introduce two IOCTLs for face detection

2011-12-08 Thread Ming Lei
Hi,

On Fri, Dec 9, 2011 at 6:27 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 On 12/08/2011 04:42 AM, Ming Lei wrote:
 +/**
 + * struct v4l2_obj_detection
 + * @buf_index:       entry, index of v4l2_buffer for face detection

 I would prefer having the frame sequence number here. It will be more
 future proof IMHO. If for instance we decide to use such an ioctl on
 a v4l2 sub-device, without dequeuing buffers, there will be no problem
 with that. And still in your specific use case it's not big deal to
 look up the buffer index given it's sequence number in the application.

OK, take your suggestion to use frame index, but I still have question
about it, see my question in another thread.


 + * @centerx: return, position in x direction of detected object
 + * @centery: return, position in y direction of detected object
 + * @angle:   return, angle of detected object
 + *           0 deg ~ 359 deg, vertical is 0 deg, clockwise
 + * @sizex:   return, size in x direction of detected object
 + * @sizey:   return, size in y direction of detected object
 + * @confidence:      return, confidence level of detection result
 + *           0: the heighest level, 9: the lowest level

 Hmm, not a good idea to align a public interface to the capabilities
 of a single hardware implementation.

 I think that the current omap interface is general enough, so why can't
 we use it as public interface?

 I meant exactly the line implying the range. What if for some hardware
 it's 0..11 ?

We can let driver to normalize it to user which doesn't care if the range
is 0~11 or 10~21, a uniform range should always make user happy,
shouldn't it?



 min/max confidence could be queried with
 relevant controls and here we could remove the line implying range.

 No, the confidence is used to describe the probability about
 the correctness of the current detection result. Anyway, no FD can
 make sure that it is 100% correct.  Other HW can normalize its
 confidence level to 0~9 so that application can handle it easily, IMO.

 1..100 might be better, to minimize rounding errors. Nevertheless IMO if we
 can export an exact range supported by FD device we should do it, and let
 upper layers do the normalization. And the bigger numbers should mean higher
 confidence, consistently for all devices.

Looks 1..100 is better, and I will change it to 1..100.


 Do you think we could assume that the FD threshold range (FD_LHIT register
 in case of OMAP4) is always same as the result confidence level ?

No, they are different. FD_LHIT is used to guild FD HW to detect more
faces but more false positives __or__ less faces but less false positives.

A control class is needed to be introduced for adjusting this value of FD
HW, and I think a normalized range is better too.


 If so then the confidence level range could possibly be queried with the
 detection threshold control. We could name it V4L2_CID_FD_CONFIDENCE_THRESHOLD

As I said above, there is no advantage to export the range to user, and a
uniform range will make user happy.

 for example.
 I could take care of preparing the control class draft and the documentation
 for it.

It is great to hear it, :-)



 + * @reserved:        future extensions
 + */
 +struct v4l2_obj_detection {

 How about changing name of this structure to v4l2_fd_primitive or 
 v4l2_fd_shape ?


I think v4l2_obj_detection is better because it can be reused to describe
some other kind of object detection from video in the future.

 +     __u16           centerx;
 +     __u16           centery;
 +     __u16           angle;
 +     __u16           sizex;
 +     __u16           sizey;

 How about using struct v4l2_rect in place of centerx/centery, sizex/sizey ?
 After all it describes a rectangle. We could also use struct 
 v4l2_frmsize_discrete
 for size but there seems to be missing en equivalent for position, e.g.

 Maybe user space would like to plot a circle or ellipse over the detected
 objection, and I am sure that I have seen this kind of plot over detected
 face before.

 OK, in any way I suggest to replace all __u16 with __u32, to minimize 
 performance
 issues and be consistent with the data type specifying pixel values elsewhere 
 in
 V4L.

OK, but may introduce more memory footprint for the fd result.

 It makes sense to make 'confidence' __u32 as well and add a flags attribute to
 indicate the shape.

Sounds good.



 +     __u16           confidence;
 +     __u32           reserved[4];

 And then
          __u32           reserved[10];

 or
          __u32           reserved[2];

 +};
 +
 +#define V4L2_FD_HAS_LEFT_EYE 0x1
 +#define V4L2_FD_HAS_RIGHT_EYE        0x2
 +#define V4L2_FD_HAS_MOUTH    0x4
 +#define V4L2_FD_HAS_FACE     0x8

 Do you think we could change it to:

 #define V4L2_FD_FL_LEFT_EYE     (1  0)
 #define V4L2_FD_FL_RIGHT_EYE    (1  1)
 #define V4L2_FD_FL_MOUTH        (1  2)
 #define V4L2_FD_FL_FACE         (1  3)

OK

 and add:

 #define V4L2_FD_FL_SMILE        (1  4)
 #define

Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-07 Thread Ming Lei
Hi,

On Wed, Dec 7, 2011 at 6:01 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 On 12/06/2011 03:07 PM, Ming Lei wrote:
 Hi,

 Thanks for your review.

 On Tue, Dec 6, 2011 at 5:55 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Ming,

 (I've pruned the Cc list, leaving just the mailing lists)

 On 12/02/2011 04:02 PM, Ming Lei wrote:
 This patch introduces one driver for face detection purpose.

 The driver is responsible for all v4l2 stuff, buffer management
 and other general things, and doesn't touch face detection hardware
 directly. Several interfaces are exported to low level drivers
 (such as the coming omap4 FD driver)which will communicate with
 face detection hw module.

 So the driver will make driving face detection hw modules more
 easy.


 I would hold on for a moment on implementing generic face detection
 module which is based on the V4L2 video device interface. We need to
 first define an API that would be also usable at sub-device interface
 level (http://linuxtv.org/downloads/v4l-dvb-apis/subdev.html).

 If we can define a good/stable enough APIs between kernel and user space,
 I think the patches can be merged first. For internal kernel APIs, we should
 allow it to evolve as new hardware comes or new features are to be 
 introduced.

 I also don't see a problem in discussing it a bit more;)

OK, fair enough, let's discuss it, :-)



 I understand the API you mentioned here should belong to kernel internal
 API, correct me if it is wrong.

 Yes, I meant the in kernel design, i.e. generic face detection kernel module
 and an OMAP4 FDIF driver. It makes lots of sense to separate common code
 in this way, maybe even when there would be only OMAP devices using it.

Yes, that is the motivation of the generic FD module. I think we can focus on
two use cases for the generic FD now:

- one is to detect faces from user space image data

- another one is to detect faces in image data generated from HW(SoC
internal bus, resize hardware)

For OMAP4 hardware, input data is always from physically continuous
memory directly, so it is very easy to support the two cases. For the
use case 2,
if buffer copy is to be avoided, we can use the coming shared dma-buf[1]
to pass the image buffer produced by other HW to FD hw directly.

For other FD hardware, if it supports to detect faces in image data from
physically continuous memory, I think the patch is OK to support it.

If the FD hw doesn't support to detect faces from physically continuous
memory, I have some questions: how does user space app to parse the
FD result if application can't get the input image data? If user space can
get image data, how does it connect the image data with FD result? and
what standard v4l2 ways(v4l2_buffer?) can the app use to describe the
image data?

 I'm sure now the Samsung devices won't fit in video output node based driver
 design. They read image data in different ways and also the FD result format
 is totally different.

I think user space will need the FD result, so it is very important to define
API to describe the FD result format to user space. And the input about your
FD HW result format is certainly helpful to define the API.


 AFAICS OMAP4 FDIF processes only data stored in memory, thus it seems
 reasonable to use the videodev interface for passing data to the kernel
 from user space.

 But there might be face detection devices that accept data from other
 H/W modules, e.g. transferred through SoC internal data buses between
 image processing pipeline blocks. Thus any new interfaces need to be
 designed with such devices in mind.

 Also the face detection hardware block might now have an input DMA
 engine in it, the data could be fed from memory through some other
 subsystem (e.g. resize/colour converter). Then the driver for that
 subsystem would implement a video node.

 I think the direct input image or frame data to FD should be from memory
 no matter the actual data is from external H/W modules or input DMA because
 FD will take lot of time to detect faces in one image or frame and FD can't
 have so much memory to cache several images or frames data.

 Sorry, I cannot provide much details at the moment, but there exists hardware
 that reads data from internal SoC buses and even if it uses some sort of
 cache memory it doesn't necessarily have to be available for the user.

Without some hardware background, it is not easy to give a generic FD module
design.

 Still the FD result is associated with an image frame for such H/W, but not
 necessarily with a memory buffer queued by a user application.

For user space application, it doesn't make sense to handle FD results
only without image data.  Even though there are other ways of input
image data to FD, user space still need to know the image data, so it makes
sense to associate FD result with a memory buffer.

 How long it approximately takes to process single image for OMAP4 FDIF ?

See the link[2], and my test result is basically consistent

Re: [RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-06 Thread Ming Lei
Hi,

Thanks for your review.

On Tue, Dec 6, 2011 at 5:55 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Ming,

 (I've pruned the Cc list, leaving just the mailing lists)

 On 12/02/2011 04:02 PM, Ming Lei wrote:
 This patch introduces one driver for face detection purpose.

 The driver is responsible for all v4l2 stuff, buffer management
 and other general things, and doesn't touch face detection hardware
 directly. Several interfaces are exported to low level drivers
 (such as the coming omap4 FD driver)which will communicate with
 face detection hw module.

 So the driver will make driving face detection hw modules more
 easy.


 I would hold on for a moment on implementing generic face detection
 module which is based on the V4L2 video device interface. We need to
 first define an API that would be also usable at sub-device interface
 level (http://linuxtv.org/downloads/v4l-dvb-apis/subdev.html).

If we can define a good/stable enough APIs between kernel and user space,
I think the patches can be merged first. For internal kernel APIs, we should
allow it to evolve as new hardware comes or new features are to be introduced.

I understand the API you mentioned here should belong to kernel internal
API, correct me if it is wrong.

 AFAICS OMAP4 FDIF processes only data stored in memory, thus it seems
 reasonable to use the videodev interface for passing data to the kernel
 from user space.

 But there might be face detection devices that accept data from other
 H/W modules, e.g. transferred through SoC internal data buses between
 image processing pipeline blocks. Thus any new interfaces need to be
 designed with such devices in mind.

 Also the face detection hardware block might now have an input DMA
 engine in it, the data could be fed from memory through some other
 subsystem (e.g. resize/colour converter). Then the driver for that
 subsystem would implement a video node.

I think the direct input image or frame data to FD should be from memory
no matter the actual data is from external H/W modules or input DMA because
FD will take lot of time to detect faces in one image or frame and FD can't
have so much memory to cache several images or frames data.

If you have seen this kind of FD hardware design, please let me know.

 I'm for leaving the buffer handling details for individual drivers
 and focusing on a standard interface for applications, i.e. new

I think leaving buffer handling details in generic FD driver or
individual drivers
doesn't matter now, since it don't have effect on interfaces between kernel
and user space.

 ioctl(s) and controls.


 TODO:
       - implement FD setting interfaces with v4l2 controls or
       ext controls

 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/media/video/Kconfig       |    2 +
  drivers/media/video/Makefile      |    1 +
  drivers/media/video/fdif/Kconfig  |    7 +
  drivers/media/video/fdif/Makefile |    1 +
  drivers/media/video/fdif/fdif.c   |  645 
 +
  drivers/media/video/fdif/fdif.h   |  114 +++
  6 files changed, 770 insertions(+), 0 deletions(-)
  create mode 100644 drivers/media/video/fdif/Kconfig
  create mode 100644 drivers/media/video/fdif/Makefile
  create mode 100644 drivers/media/video/fdif/fdif.c
  create mode 100644 drivers/media/video/fdif/fdif.h

 [...]

 diff --git a/drivers/media/video/fdif/fdif.h 
 b/drivers/media/video/fdif/fdif.h
 new file mode 100644
 index 000..ae37ab8
 --- /dev/null
 +++ b/drivers/media/video/fdif/fdif.h
 @@ -0,0 +1,114 @@
 +#ifndef _LINUX_FDIF_H
 +#define _LINUX_FDIF_H
 +
 +#include linux/types.h
 +#include linux/magic.h
 +#include linux/errno.h
 +#include linux/kref.h
 +#include linux/kernel.h
 +#include linux/videodev2.h
 +#include media/videobuf2-page.h
 +#include media/v4l2-device.h
 +#include media/v4l2-ioctl.h
 +#include media/v4l2-ctrls.h
 +#include media/v4l2-fh.h
 +#include media/v4l2-event.h
 +#include media/v4l2-common.h
 +
 +#define MAX_FACE_COUNT               40
 +
 +#define      FACE_SIZE_20_PIXELS     0
 +#define      FACE_SIZE_25_PIXELS     1
 +#define      FACE_SIZE_32_PIXELS     2
 +#define      FACE_SIZE_40_PIXELS     3

 This is still OMAP4 FDIF specific, we need to think about v4l2 controls
 for this. An ideal would be a menu control type that supports pixel size
 (width/height), but unfortunately something like this isn't available
 in v4l2 yet.

Yes, it is on TODO list, :-)

 +
 +#define FACE_DIR_UP          0
 +#define FACE_DIR_RIGHT               1
 +#define FACE_DIR_LIFT                2
 +
 +struct fdif_fmt {
 +     char  *name;
 +     u32   fourcc;          /* v4l2 format id */
 +     int   depth;
 +     int   width, height;

 Could width/height be negative ? I don't think it's the case for pixel
 resolution. The more proper data type would be u32.

Yes, they should be, will fix it in next version.

 Please refer to struct v4l2_pix_format or struct v4l2_rect.

 +};
 +
 +struct fdif_setting {
 +     struct fdif_fmt

Re: [RFC PATCH v1 2/7] omap4: build fdif omap device from hwmod

2011-12-04 Thread Ming Lei
Hi,

On Sat, Dec 3, 2011 at 12:28 AM, Aguirre, Sergio saagui...@ti.com wrote:
 Hi Ming,

 Thanks for the patches.

Thanks for your review.

 On Fri, Dec 2, 2011 at 9:02 AM, Ming Lei ming@canonical.com wrote:
 Signed-off-by: Ming Lei ming@canonical.com
 ---
  arch/arm/mach-omap2/devices.c |   33 +
  1 files changed, 33 insertions(+), 0 deletions(-)

 diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
 index 1166bdc..a392af5 100644
 --- a/arch/arm/mach-omap2/devices.c
 +++ b/arch/arm/mach-omap2/devices.c
 @@ -728,6 +728,38 @@ void __init omap242x_init_mmc(struct 
 omap_mmc_platform_data **mmc_data)

  #endif

 +static struct platform_device* __init omap4_init_fdif(void)
 +{
 +       int id = -1;

 You could remove this , as it is being used only once, and never changed.

Yes.


 +       struct platform_device *pd;
 +       struct omap_hwmod *oh;
 +       const char *dev_name = fdif;
 +
 +       oh = omap_hwmod_lookup(fdif);
 +       if (!oh) {
 +               pr_err(Could not look up fdif hwmod\n);
 +               return NULL;
 +       }
 +
 +       pd = omap_device_build(dev_name, id, oh, NULL, 0, NULL, 0, 0);

 Just do:

 pd = omap_device_build(dev_name, -1, oh, NULL, 0, NULL, 0, 0);

 +       WARN(IS_ERR(pd), Can't build omap_device for %s.\n,
 +                               dev_name);
 +       return pd;
 +}
 +
 +static void __init omap_init_fdif(void)
 +{
 +       if (cpu_is_omap44xx()) {
 +               struct platform_device *pd;
 +
 +               pd = omap4_init_fdif();
 +               if (!pd)
 +                       return;
 +
 +               pm_runtime_enable(pd-dev);
 +       }
 +}

 IMHO, you could reduce 1 level of indentation here, like this:

 static void __init omap_init_fdif(void)
 {
        struct platform_device *pd;

        if (!cpu_is_omap44xx())
                return;

        pd = omap4_init_fdif();
        if (!pd)
                return;

        pm_runtime_enable(pd-dev);
 }

OK, will take this.

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


Re: [RFC PATCH v1 0/7] mediaomap4: introduce face detection(FD) driver

2011-12-02 Thread Ming Lei
Hi,

On Fri, Dec 2, 2011 at 6:28 PM, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Ming,

 On 12/02/2011 10:12 AM, Ming Lei wrote:
 Hi,

 These v1 patches(against -next tree) introduce v4l2 based face
 detection(FD) device driver, and enable FD hardware[1] on omap4 SoC..
 The idea of implementing it on v4l2 is from from Alan Cox, Sylwester
 and Greg-Kh.

 For verification purpose, I write one user space utility[2] to
 test the module and driver, follows its basic functions:

       - detect faces in input grayscal picture(PGM raw, 320 by 240)
       - detect faces in input y8 format video stream
       - plot a rectangle to mark the detected faces, and save it as
       another same format picture or video stream

 Looks the performance of the module is not bad, see some detection
 results on the link[3][4].

 Face detection can be used to implement some interesting applications
 (camera, face unlock, baby monitor, ...).

 TODO:
       - implement FD setting interfaces with v4l2 controls or
       ext controls

 thanks,
 --
 Ming Lei

 [1], Ch9 of OMAP4 Technical Reference Manual
 [2], 
 http://kernel.ubuntu.com/git?p=ming/fdif.git;a=shortlog;h=refs/heads/v4l2-fdif
 [3], http://kernel.ubuntu.com/~ming/dev/fdif/output
 [4], All pictures are taken from http://www.google.com/imghp
 and converted to pnm from jpeg format, only for test purpose.


 Could you please resend this series to Linux Media mailing list
 (linux-media@vger.kernel.org) ? It touches V4L core code and I'm

Yes, I will resend this series to linux-media mail list, thanks for pointing
it out.  Of course, the most important mail list is missed for the patches,
very sorry about it.

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


[RFC PATCH v1 0/7] mediaomap4: introduce face detection(FD) driver

2011-12-02 Thread Ming Lei
Hi,

These v1 patches(against -next tree) introduce v4l2 based face
detection(FD) device driver, and enable FD hardware[1] on omap4 SoC..
The idea of implementing it on v4l2 is from from Alan Cox, Sylwester
and Greg-Kh.

For verification purpose, I write one user space utility[2] to
test the module and driver, follows its basic functions:

- detect faces in input grayscal picture(PGM raw, 320 by 240)
- detect faces in input y8 format video stream
- plot a rectangle to mark the detected faces, and save it as 
another same type grayscal picture

Looks the performance of the module is not bad, see some detection
results on the link[3][4].

Face detection can be used to implement some interesting applications
(camera, face unlock, baby monitor, ...).

TODO:
- implement FD setting interfaces with v4l2 controls or
ext controls

thanks,
--
Ming Lei

[1], Ch9 of OMAP4 Technical Reference Manual
[2], 
http://kernel.ubuntu.com/git?p=ming/fdif.git;a=shortlog;h=refs/heads/v4l2-fdif
[3], http://kernel.ubuntu.com/~ming/dev/fdif/output
[4], All pictures are taken from http://www.google.com/imghp
and converted to pnm from jpeg format, only for test purpose.

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


[RFC PATCH v1 7/7] media: video: introduce omap4 face detection module driver

2011-12-02 Thread Ming Lei
The patch introduces one face detection device driver for
driving face detection hardware on omap4[1].

Most things of the driver are dealing with omap4 face detection
hardware.

This driver is platform independent, so in theory it can
be used to drive same IP module on other platforms.

[1], Ch9 of OMAP4 Technical Reference Manual

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/video/fdif/Kconfig  |6 +
 drivers/media/video/fdif/Makefile |1 +
 drivers/media/video/fdif/fdif_omap4.c |  663 +
 3 files changed, 670 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/fdif/fdif_omap4.c

diff --git a/drivers/media/video/fdif/Kconfig b/drivers/media/video/fdif/Kconfig
index e214cb4..0482a83 100644
--- a/drivers/media/video/fdif/Kconfig
+++ b/drivers/media/video/fdif/Kconfig
@@ -5,3 +5,9 @@ config FDIF
help
  The FDIF is a face detection module, which can be integrated into
  some SoCs to detect the location of faces in one image or video.
+
+config FDIF_OMAP4
+   depends on FDIF
+   tristate OMAP4 Face Detection module
+   help
+ OMAP4 face detection support
diff --git a/drivers/media/video/fdif/Makefile 
b/drivers/media/video/fdif/Makefile
index ba1e4c8..3744ced 100644
--- a/drivers/media/video/fdif/Makefile
+++ b/drivers/media/video/fdif/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_FDIF) += fdif.o
+obj-$(CONFIG_FDIF_OMAP4)   += fdif_omap4.o
diff --git a/drivers/media/video/fdif/fdif_omap4.c 
b/drivers/media/video/fdif/fdif_omap4.c
new file mode 100644
index 000..956ec51
--- /dev/null
+++ b/drivers/media/video/fdif/fdif_omap4.c
@@ -0,0 +1,663 @@
+/*
+ *  fdif_omap4.c  --  face detection module driver
+ *
+ *  Copyright (C) 2011  Ming Lei (ming@canonical.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*/
+#include linux/init.h
+#include linux/fs.h
+#include linux/mm.h
+#include linux/slab.h
+#include linux/signal.h
+#include linux/wait.h
+#include linux/poll.h
+#include linux/module.h
+#include linux/pm_runtime.h
+#include linux/delay.h
+#include linux/user_namespace.h
+#include linux/platform_device.h
+#include linux/interrupt.h
+#include linux/dma-mapping.h
+#include fdif.h
+#include asm/uaccess.h
+#include asm/byteorder.h
+#include asm/io.h
+
+#undef DEBUG
+
+#define PICT_SIZE_X 320
+#define PICT_SIZE_Y 240
+
+#defineWORK_MEM_SIZE   (52*1024)
+
+/* 9.5 FDIF Register Manua of TI OMAP4 TRM */
+#define FDIF_REVISION  0x0
+#define FDIF_HWINFO0x4
+#define FDIF_SYSCONFIG 0x10
+#define SOFTRESET  (1  0)
+
+#define FDIF_IRQSTATUS_RAW_j   (0x24 + 2*0x10)
+#define FDIF_IRQSTATUS_j   (0x28 + 2*0x10)
+#define FDIF_IRQENABLE_SET_j   (0x2c + 2*0x10)
+#define FDIF_IRQENABLE_CLR_j   (0x30 + 2*0x10)
+#define FINISH_IRQ (1  8)
+#define ERR_IRQ(1  0)
+
+#define FDIF_PICADDR   0x60
+#define FDIF_CTRL  0x64
+#define CTRL_MAX_TAGS  0x0A
+
+#define FDIF_WKADDR0x68
+#define FD_CTRL0x80
+#define CTRL_FINISH(1  2)
+#define CTRL_RUN   (1  1)
+#define CTRL_SRST  (1  0)
+
+
+#define FD_DNUM0x84
+#define FD_DCOND   0x88
+#define FD_STARTX  0x8c
+#define FD_STARTY  0x90
+#define FD_SIZEX   0x94
+#define FD_SIZEY   0x98
+#define FD_LHIT0x9c
+#define FD_CENTERX_i   0x160
+#define FD_CENTERY_i   0x164
+#define FD_CONFSIZE_i  0x168
+#define FD_ANGLE_i 0x16c
+
+static inline void fd_writel(void __iomem *base, u32 reg, u32 val)
+{
+   __raw_writel(val, base + reg);
+}
+
+static inline u32 fd_readl(void __iomem *base, u32 reg)
+{
+   return __raw_readl(base + reg);
+}
+
+struct fdif_qvga {
+   struct fdif_dev *dev;
+
+   /*should be removed*/
+   struct platform_device  *pdev;
+   int irq;
+   void __iomem*base;
+
+   void*work_mem_addr;
+   dma_addr_t  work_dma

[RFC PATCH v1 1/7] omap4: introduce fdif(face detect module) hwmod

2011-12-02 Thread Ming Lei
Signed-off-by: Ming Lei ming@canonical.com
---
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |   81 
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c 
b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index 6cf21ee..30db754 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -53,6 +53,7 @@ static struct omap_hwmod omap44xx_dmm_hwmod;
 static struct omap_hwmod omap44xx_dsp_hwmod;
 static struct omap_hwmod omap44xx_dss_hwmod;
 static struct omap_hwmod omap44xx_emif_fw_hwmod;
+static struct omap_hwmod omap44xx_fdif_hwmod;
 static struct omap_hwmod omap44xx_hsi_hwmod;
 static struct omap_hwmod omap44xx_ipu_hwmod;
 static struct omap_hwmod omap44xx_iss_hwmod;
@@ -354,6 +355,14 @@ static struct omap_hwmod_ocp_if 
omap44xx_dma_system__l3_main_2 = {
.user   = OCP_USER_MPU | OCP_USER_SDMA,
 };
 
+/* fdif - l3_main_2 */
+static struct omap_hwmod_ocp_if omap44xx_fdif__l3_main_2 = {
+   .master = omap44xx_fdif_hwmod,
+   .slave  = omap44xx_l3_main_2_hwmod,
+   .clk= l3_div_ck,
+   .user   = OCP_USER_MPU | OCP_USER_SDMA,
+};
+
 /* hsi - l3_main_2 */
 static struct omap_hwmod_ocp_if omap44xx_hsi__l3_main_2 = {
.master = omap44xx_hsi_hwmod,
@@ -5444,6 +5453,75 @@ static struct omap_hwmod omap44xx_wd_timer3_hwmod = {
.slaves_cnt = ARRAY_SIZE(omap44xx_wd_timer3_slaves),
 };
 
+/* 'fdif' class */
+static struct omap_hwmod_class_sysconfig omap44xx_fdif_sysc = {
+   .rev_offs   = 0x,
+   .sysc_offs  = 0x0010,
+   .sysc_flags = (SYSC_HAS_MIDLEMODE | SYSC_HAS_RESET_STATUS |
+  SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET),
+   .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
+  MSTANDBY_FORCE | MSTANDBY_NO |
+  MSTANDBY_SMART),
+   .sysc_fields= omap_hwmod_sysc_type2,
+};
+
+static struct omap_hwmod_class omap44xx_fdif_hwmod_class = {
+   .name   = fdif,
+   .sysc   = omap44xx_fdif_sysc,
+};
+
+/*fdif*/
+static struct omap_hwmod_addr_space omap44xx_fdif_addrs[] = {
+   {
+   .pa_start   = 0x4a10a000,
+   .pa_end = 0x4a10afff,
+   .flags  = ADDR_TYPE_RT
+   },
+   { }
+};
+
+/* l4_cfg - fdif */
+static struct omap_hwmod_ocp_if omap44xx_l4_cfg__fdif = {
+   .master = omap44xx_l4_cfg_hwmod,
+   .slave  = omap44xx_fdif_hwmod,
+   .clk= l4_div_ck,
+   .addr   = omap44xx_fdif_addrs,
+   .user   = OCP_USER_MPU | OCP_USER_SDMA,
+};
+
+/* fdif slave ports */
+static struct omap_hwmod_ocp_if *omap44xx_fdif_slaves[] = {
+   omap44xx_l4_cfg__fdif,
+};
+static struct omap_hwmod_irq_info omap44xx_fdif_irqs[] = {
+   { .irq = 69 + OMAP44XX_IRQ_GIC_START },
+   { .irq = -1 }
+};
+
+/* fdif master ports */
+static struct omap_hwmod_ocp_if *omap44xx_fdif_masters[] = {
+   omap44xx_fdif__l3_main_2,
+};
+
+static struct omap_hwmod omap44xx_fdif_hwmod = {
+   .name   = fdif,
+   .class  = omap44xx_fdif_hwmod_class,
+   .clkdm_name = iss_clkdm,
+   .mpu_irqs   = omap44xx_fdif_irqs,
+   .main_clk   = fdif_fck,
+   .prcm = {
+   .omap4 = {
+   .clkctrl_offs = OMAP4_CM_CAM_FDIF_CLKCTRL_OFFSET,
+   .context_offs = OMAP4_RM_CAM_FDIF_CONTEXT_OFFSET,
+   .modulemode   = MODULEMODE_SWCTRL,
+   },
+   },
+   .slaves = omap44xx_fdif_slaves,
+   .slaves_cnt = ARRAY_SIZE(omap44xx_fdif_slaves),
+   .masters= omap44xx_fdif_masters,
+   .masters_cnt= ARRAY_SIZE(omap44xx_fdif_masters),
+};
+
 static __initdata struct omap_hwmod *omap44xx_hwmods[] = {
 
/* dmm class */
@@ -5593,6 +5671,9 @@ static __initdata struct omap_hwmod *omap44xx_hwmods[] = {
omap44xx_wd_timer2_hwmod,
omap44xx_wd_timer3_hwmod,
 
+   /* fdif class */
+   omap44xx_fdif_hwmod,
+
NULL,
 };
 
-- 
1.7.5.4

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


[RFC PATCH v1 2/7] omap4: build fdif omap device from hwmod

2011-12-02 Thread Ming Lei
Signed-off-by: Ming Lei ming@canonical.com
---
 arch/arm/mach-omap2/devices.c |   33 +
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 1166bdc..a392af5 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -728,6 +728,38 @@ void __init omap242x_init_mmc(struct 
omap_mmc_platform_data **mmc_data)
 
 #endif
 
+static struct platform_device* __init omap4_init_fdif(void)
+{
+   int id = -1;
+   struct platform_device *pd;
+   struct omap_hwmod *oh;
+   const char *dev_name = fdif;
+
+   oh = omap_hwmod_lookup(fdif);
+   if (!oh) {
+   pr_err(Could not look up fdif hwmod\n);
+   return NULL;
+   }
+
+   pd = omap_device_build(dev_name, id, oh, NULL, 0, NULL, 0, 0);
+   WARN(IS_ERR(pd), Can't build omap_device for %s.\n,
+   dev_name);
+   return pd;
+}
+
+static void __init omap_init_fdif(void)
+{
+   if (cpu_is_omap44xx()) {
+   struct platform_device *pd;
+
+   pd = omap4_init_fdif();
+   if (!pd)
+   return;
+
+   pm_runtime_enable(pd-dev);
+   }
+}
+
 /*-*/
 
 #if defined(CONFIG_HDQ_MASTER_OMAP) || defined(CONFIG_HDQ_MASTER_OMAP_MODULE)
@@ -808,6 +840,7 @@ static int __init omap2_init_devices(void)
omap_init_sham();
omap_init_aes();
omap_init_vout();
+   omap_init_fdif();
 
return 0;
 }
-- 
1.7.5.4

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


[RFC PATCH v1 4/7] media: videobuf2: introduce VIDEOBUF2_PAGE memops

2011-12-02 Thread Ming Lei
DMA contig memory resource is very limited and precious, also
accessing to it from CPU is very slow on some platform.

For some cases(such as the comming face detection driver), DMA Streaming
buffer is enough, so introduce VIDEOBUF2_PAGE to allocate continuous
physical memory but letting video device driver to handle DMA buffer mapping
and unmapping things.

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/video/Kconfig  |4 +
 drivers/media/video/Makefile |1 +
 drivers/media/video/videobuf2-page.c |  115 ++
 include/media/videobuf2-page.h   |   20 ++
 4 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/videobuf2-page.c
 create mode 100644 include/media/videobuf2-page.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 4e8a0c4..5684a00 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -60,6 +60,10 @@ config VIDEOBUF2_VMALLOC
select VIDEOBUF2_MEMOPS
tristate
 
+config VIDEOBUF2_PAGE
+   select VIDEOBUF2_CORE
+   select VIDEOBUF2_MEMOPS
+   tristate
 
 config VIDEOBUF2_DMA_SG
#depends on HAS_DMA
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index ddeaa6c..bc797f2 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -125,6 +125,7 @@ obj-$(CONFIG_VIDEO_BTCX)  += btcx-risc.o
 obj-$(CONFIG_VIDEOBUF2_CORE)   += videobuf2-core.o
 obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o
 obj-$(CONFIG_VIDEOBUF2_VMALLOC)+= videobuf2-vmalloc.o
+obj-$(CONFIG_VIDEOBUF2_PAGE)   += videobuf2-page.o
 obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o
 obj-$(CONFIG_VIDEOBUF2_DMA_SG) += videobuf2-dma-sg.o
 
diff --git a/drivers/media/video/videobuf2-page.c 
b/drivers/media/video/videobuf2-page.c
new file mode 100644
index 000..b3f003a
--- /dev/null
+++ b/drivers/media/video/videobuf2-page.c
@@ -0,0 +1,115 @@
+/*
+ * videobuf2-page.c - page memory allocator for videobuf2
+ *
+ * Copyright (C) 2011 Canonical Ltd.
+ *
+ * Author: Ming Lei ming@canonical.com
+ *
+ * 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.
+ */
+
+#include linux/module.h
+#include linux/mm.h
+#include linux/slab.h
+
+#include media/videobuf2-core.h
+#include media/videobuf2-memops.h
+
+struct vb2_page_buf {
+   void*vaddr;
+   unsigned long   size;
+   atomic_trefcount;
+   struct vb2_vmarea_handler   handler;
+};
+
+static void vb2_page_put(void *buf_priv);
+
+static void *vb2_page_alloc(void *alloc_ctx, unsigned long size)
+{
+   struct vb2_page_buf *buf;
+
+   buf = kzalloc(sizeof *buf, GFP_KERNEL);
+   if (!buf)
+   return NULL;
+
+   buf-size = size;
+   buf-vaddr = (void *)__get_free_pages(GFP_KERNEL,
+   get_order(buf-size));
+   buf-handler.refcount = buf-refcount;
+   buf-handler.put = vb2_page_put;
+   buf-handler.arg = buf;
+
+   if (!buf-vaddr) {
+   printk(KERN_ERR page of size %ld failed\n, buf-size);
+   kfree(buf);
+   return NULL;
+   }
+
+   atomic_inc(buf-refcount);
+   printk(KERN_DEBUG Allocated page buffer of size %ld at vaddr=%p\n,
+   buf-size, buf-vaddr);
+
+   return buf;
+}
+
+static void vb2_page_put(void *buf_priv)
+{
+   struct vb2_page_buf *buf = buf_priv;
+
+   if (atomic_dec_and_test(buf-refcount)) {
+   printk(KERN_DEBUG %s: Freeing page mem at vaddr=%p\n,
+   __func__, buf-vaddr);
+   free_pages((unsigned long)buf-vaddr, get_order(buf-size));
+   kfree(buf);
+   }
+}
+
+static void *vb2_page_vaddr(void *buf_priv)
+{
+   struct vb2_page_buf *buf = buf_priv;
+
+   BUG_ON(!buf);
+
+   if (!buf-vaddr) {
+   printk(KERN_ERR Address of an unallocated plane requested\n);
+   return NULL;
+   }
+
+   return buf-vaddr;
+}
+
+static unsigned int vb2_page_num_users(void *buf_priv)
+{
+   struct vb2_page_buf *buf = buf_priv;
+   return atomic_read(buf-refcount);
+}
+
+static int vb2_page_mmap(void *buf_priv, struct vm_area_struct *vma)
+{
+   struct vb2_page_buf *buf = buf_priv;
+
+   if (!buf) {
+   printk(KERN_ERR No memory to map\n);
+   return -EINVAL;
+   }
+
+   vma-vm_page_prot = vm_get_page_prot(vma-vm_flags);
+   return vb2_mmap_pfn_range(vma, virt_to_phys(buf-vaddr),
+   buf-size, vb2_common_vm_ops,
+   buf-handler);
+}
+
+const struct vb2_mem_ops vb2_page_memops = {
+   .alloc  = vb2_page_alloc,
+   .put= vb2_page_put

[RFC PATCH v1 3/7] media: videobuf2: move out of setting pgprot_noncached from vb2_mmap_pfn_range

2011-12-02 Thread Ming Lei
So that we can reuse vb2_mmap_pfn_range for the coming videobuf2_page
memops.

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/video/videobuf2-dma-contig.c |1 +
 drivers/media/video/videobuf2-memops.c |1 -
 2 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/media/video/videobuf2-dma-contig.c 
b/drivers/media/video/videobuf2-dma-contig.c
index f17ad98..0ea8866 100644
--- a/drivers/media/video/videobuf2-dma-contig.c
+++ b/drivers/media/video/videobuf2-dma-contig.c
@@ -106,6 +106,7 @@ static int vb2_dma_contig_mmap(void *buf_priv, struct 
vm_area_struct *vma)
return -EINVAL;
}
 
+   vma-vm_page_prot = pgprot_noncached(vma-vm_page_prot);
return vb2_mmap_pfn_range(vma, buf-dma_addr, buf-size,
  vb2_common_vm_ops, buf-handler);
 }
diff --git a/drivers/media/video/videobuf2-memops.c 
b/drivers/media/video/videobuf2-memops.c
index 71a7a78..77e0def 100644
--- a/drivers/media/video/videobuf2-memops.c
+++ b/drivers/media/video/videobuf2-memops.c
@@ -162,7 +162,6 @@ int vb2_mmap_pfn_range(struct vm_area_struct *vma, unsigned 
long paddr,
 
size = min_t(unsigned long, vma-vm_end - vma-vm_start, size);
 
-   vma-vm_page_prot = pgprot_noncached(vma-vm_page_prot);
ret = remap_pfn_range(vma, vma-vm_start, paddr  PAGE_SHIFT,
size, vma-vm_page_prot);
if (ret) {
-- 
1.7.5.4

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


[RFC PATCH v1 5/7] media: v4l2: introduce two IOCTLs for face detection

2011-12-02 Thread Ming Lei
This patch introduces two new IOCTLs and related data
structure defination which will be used by the coming
face detection video device.

The two IOCTLs and related data structure are used by
user space application to retrieve the results of face
detection. They can be called after one v4l2_buffer
has been ioctl(VIDIOC_DQBUF) and before it will be
ioctl(VIDIOC_QBUF).

The utility fdif[1] is useing the two IOCTLs to find
faces deteced in raw images or video streams.

[1],http://kernel.ubuntu.com/git?p=ming/fdif.git;a=shortlog;h=refs/heads/v4l2-fdif

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/video/v4l2-ioctl.c |   38 
 include/linux/videodev2.h|   70 ++
 include/media/v4l2-ioctl.h   |6 +++
 3 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index e1da8fc..fc6266f 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -2140,6 +2140,30 @@ static long __video_do_ioctl(struct file *file,
dbgarg(cmd, index=%d, b-index);
break;
}
+   case VIDIOC_G_FD_RESULT:
+   {
+   struct v4l2_fd_result *fr = arg;
+
+   if (!ops-vidioc_g_fd_result)
+   break;
+
+   ret = ops-vidioc_g_fd_result(file, fh, fr);
+
+   dbgarg(cmd, index=%d, fr-buf_index);
+   break;
+   }
+   case VIDIOC_G_FD_COUNT:
+   {
+   struct v4l2_fd_count *fc = arg;
+
+   if (!ops-vidioc_g_fd_count)
+   break;
+
+   ret = ops-vidioc_g_fd_count(file, fh, fc);
+
+   dbgarg(cmd, index=%d, fc-buf_index);
+   break;
+   }
default:
if (!ops-vidioc_default)
break;
@@ -2234,6 +2258,20 @@ static int check_array_args(unsigned int cmd, void 
*parg, size_t *array_size,
}
break;
}
+
+   case VIDIOC_G_FD_RESULT: {
+   struct v4l2_fd_result *fr = parg;
+
+   if (fr-face_cnt != 0) {
+   *user_ptr = (void __user *)fr-fd;
+   *kernel_ptr = (void *)fr-fd;
+   *array_size = sizeof(struct v4l2_fd_detection)
+   * fr-face_cnt;
+   ret = 1;
+   }
+   break;
+
+   }
}
 
return ret;
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 4b752d5..073eb4d 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -2160,6 +2160,74 @@ struct v4l2_create_buffers {
__u32   reserved[8];
 };
 
+/**
+ * struct v4l2_obj_detection
+ * @buf_index: entry, index of v4l2_buffer for face detection
+ * @centerx:   return, position in x direction of detected object
+ * @centery:   return, position in y direction of detected object
+ * @angle: return, angle of detected object
+ * 0 deg ~ 359 deg, vertical is 0 deg, clockwise
+ * @sizex: return, size in x direction of detected object
+ * @sizey: return, size in y direction of detected object
+ * @confidence:return, confidence level of detection result
+ * 0: the heighest level, 9: the lowest level
+ * @reserved:  future extensions
+ */
+struct v4l2_obj_detection {
+   __u16   centerx;
+   __u16   centery;
+   __u16   angle;
+   __u16   sizex;
+   __u16   sizey;
+   __u16   confidence;
+   __u32   reserved[4];
+};
+
+#define V4L2_FD_HAS_LEFT_EYE   0x1
+#define V4L2_FD_HAS_RIGHT_EYE  0x2
+#define V4L2_FD_HAS_MOUTH  0x4
+#define V4L2_FD_HAS_FACE   0x8
+
+/**
+ * struct v4l2_fd_detection - VIDIOC_G_FD_RESULT argument
+ * @flag:  return, describe which objects are detected
+ * @left_eye:  return, left_eye position if detected
+ * @right_eye: return, right_eye position if detected
+ * @mouth_eye: return, mouth_eye position if detected
+ * @face:  return, face position if detected
+ */
+struct v4l2_fd_detection {
+   __u32   flag;
+   struct v4l2_obj_detection   left_eye;
+   struct v4l2_obj_detection   right_eye;
+   struct v4l2_obj_detection   mouth;
+   struct v4l2_obj_detection   face;
+};
+
+/**
+ * struct v4l2_fd_result - VIDIOC_G_FD_RESULT argument
+ * @buf_index: entry, index of v4l2_buffer for face detection
+ * @face_cnt:  return, how many faces detected from the @buf_index
+ * @fd:return, result of faces' detection
+ */
+struct v4l2_fd_result {
+   __u32   buf_index;
+   __u32   face_cnt;
+   __u32   reserved[6];
+   struct v4l2_fd_detection *fd;
+};
+
+/**
+ * struct v4l2_fd_count - VIDIOC_G_FD_COUNT argument
+ * @buf_index: entry, index of v4l2_buffer for face detection
+ * @face_cnt

[RFC PATCH v1 6/7] media: video: introduce face detection driver module

2011-12-02 Thread Ming Lei
This patch introduces one driver for face detection purpose.

The driver is responsible for all v4l2 stuff, buffer management
and other general things, and doesn't touch face detection hardware
directly. Several interfaces are exported to low level drivers
(such as the coming omap4 FD driver)which will communicate with
face detection hw module.

So the driver will make driving face detection hw modules more
easy.

TODO:
- implement FD setting interfaces with v4l2 controls or
ext controls

Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/media/video/Kconfig   |2 +
 drivers/media/video/Makefile  |1 +
 drivers/media/video/fdif/Kconfig  |7 +
 drivers/media/video/fdif/Makefile |1 +
 drivers/media/video/fdif/fdif.c   |  645 +
 drivers/media/video/fdif/fdif.h   |  114 +++
 6 files changed, 770 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/fdif/Kconfig
 create mode 100644 drivers/media/video/fdif/Makefile
 create mode 100644 drivers/media/video/fdif/fdif.c
 create mode 100644 drivers/media/video/fdif/fdif.h

diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 5684a00..2b01402 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -1166,3 +1166,5 @@ config VIDEO_SAMSUNG_S5P_MFC
MFC 5.1 driver for V4L2.
 
 endif # V4L_MEM2MEM_DRIVERS
+
+source drivers/media/video/fdif/Kconfig
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index bc797f2..fdf6b1a 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -197,6 +197,7 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
 obj-y  += davinci/
 
 obj-$(CONFIG_ARCH_OMAP)+= omap/
+obj-$(CONFIG_FDIF) += fdif/
 
 ccflags-y += -Idrivers/media/dvb/dvb-core
 ccflags-y += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/video/fdif/Kconfig b/drivers/media/video/fdif/Kconfig
new file mode 100644
index 000..e214cb4
--- /dev/null
+++ b/drivers/media/video/fdif/Kconfig
@@ -0,0 +1,7 @@
+config FDIF
+   depends on VIDEO_DEV  VIDEO_V4L2
+   select VIDEOBUF2_PAGE
+   tristate Face Detection module
+   help
+ The FDIF is a face detection module, which can be integrated into
+ some SoCs to detect the location of faces in one image or video.
diff --git a/drivers/media/video/fdif/Makefile 
b/drivers/media/video/fdif/Makefile
new file mode 100644
index 000..ba1e4c8
--- /dev/null
+++ b/drivers/media/video/fdif/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_FDIF) += fdif.o
diff --git a/drivers/media/video/fdif/fdif.c b/drivers/media/video/fdif/fdif.c
new file mode 100644
index 000..84522d6
--- /dev/null
+++ b/drivers/media/video/fdif/fdif.c
@@ -0,0 +1,645 @@
+/*
+ *  fdif.c  --  face detection module driver
+ *
+ *  Copyright (C) 2011  Ming Lei (ming@canonical.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*/
+
+#include linux/module.h
+#include linux/fs.h
+#include linux/mm.h
+#include linux/signal.h
+#include linux/wait.h
+#include linux/poll.h
+#include linux/mman.h
+#include linux/pm_runtime.h
+#include linux/delay.h
+#include linux/platform_device.h
+#include linux/interrupt.h
+#include asm/uaccess.h
+#include asm/byteorder.h
+#include asm/io.h
+#include fdif.h
+
+static unsigned debug = 0;
+module_param(debug, uint, 0644);
+MODULE_PARM_DESC(debug, activates debug info);
+
+static LIST_HEAD(fdif_devlist);
+static unsigned video_nr = -1;
+
+int fdif_open(struct file *file)
+{
+   struct fdif_dev *dev = video_drvdata(file);
+
+   kref_get(dev-ref);
+   return v4l2_fh_open(file);
+}
+
+static unsigned int
+fdif_poll(struct file *file, struct poll_table_struct *wait)
+{
+   struct fdif_dev *dev = video_drvdata(file);
+   unsigned int mask = 0;
+   unsigned long flags;
+
+   poll_wait(file, dev-fdif_dq.wq, wait);
+
+   spin_lock_irqsave(dev-lock, flags);
+   if ((file-f_mode  FMODE_READ) 
+   !list_empty(dev-fdif_dq.complete))
+   mask |= POLLIN | POLLWRNORM;
+   spin_unlock_irqrestore(dev-lock, flags);
+   return mask;
+}
+
+static int

Re: [PATCH 3/3] drivers/misc: introduce face detection module driver(fdif)

2011-11-27 Thread Ming Lei
Hi Sylwester,

Great thanks for providing so detailed v4l2 background.

On Mon, Nov 28, 2011 at 12:41 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Ming,

 On 11/27/2011 04:40 AM, Ming Lei wrote:
 Hi guys,

 Thanks for your comment.

 On Sun, Nov 27, 2011 at 6:16 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Cc: LMML

 On 11/26/2011 05:31 AM, tom.leim...@gmail.com wrote:
 From: Ming Lei ming@canonical.com

 One face detection IP[1] is integared inside OMAP4 SoC, so
 introduce this driver to make face detection function work
 on OMAP4 SoC.

 Face detection IP is of course not specific to OMAP, I've seen it in
 other SoCs already and integrated with the video capture pipeline.

 Yes, the driver is platform independent, so at least it can support
 the same IP on different platforms.

 It's all good, however we need to ensure interoperability with existing
 drivers. I mean it shouldn't be difficult to setup data processing
 pipelines containing  various types of devices, like video capture,
 resizers, filters, etc. The situation where each type of device makes up
 their own interface is rather far from ideal.

Yes, so it does make sense to implement FD based on v4l2 framework.



 And it clearly belongs to the media subsystem, there is already an
 infrastructure there that don't need to be re-invented, like buffer
 management and various IO method support.

 I think there is not much needed on top of that to support FD. We have
 already various mem-to-mem devices in V4L2, like video or image encoders
 or video post-processors.

 I have thought about the FD implementation on v4l2 core, but still not
 very clear
 how to do it. I will study v4l2 further to figure out how to do it.

 I think we need a new user interface for that, the closest match would be
 the Video Output Interface [1], IMHO this could be used as a base. I got
 a bit confused by the additional working memory requirement and thought

I think the working memory is used by FD HW module to run its built-in face
detection algorithm, so that lots of ram can be saved in the module.

 the FDIF needs input and output memory buffers to process single image
 frame. But that's not the case so there is no reason to bother with

I think only output memory buffers are enough for FD device, we can get
the detection result from ioctl, then let application to handle it.

 the mem-to-mem interface.

 Unfortunately there is no example of virtual output device driver in v4l2
 yet. There is only one for the capture devices - drivers/media/video/vivi.c

 For video output one uses V4L2_BUF_TYPE_VIDEO_OUTPUT buffer type instead of
 V4L2_BUF_TYPE_VIDEO_CAPTURE and at the kernel side .vidioc_*_out operations
 of struct v4l2_ioctl_ops should be implemented, rather than .vidioc_*_cap.

It is very helpful.


 Now below are the basic requirements from FD:

 - FD on video stream or pictures from external files
 - FD on video stream or pictures from video device
 (such as camera)

 It's up to the applications in what way the image data is loaded into
 memory buffer, if it comes from a file or from other device. Once it is in
 standard v4l2 buffer object it can be shared between v4l2 drivers,
 still user space needs to queue/de-queue buffers. See QBUF/DQBUF ioctls
 [4] for more information.

If the image data comes from a device(capture device, or resize
post-processing),
face detect module should use the buffer directly and avoid
to copy image data from capture or resize buffer if the image format is
same with what FD requires and the buffer is physical continuous.

But I am not sure how to handle this case? Could we need to add a ioctl to
make FD device see the buffer from capture or resize device?

Also, could you give a introduction about how v4l2 handles resize if
HW is capable of resizing?


 - the input video format may be different for different FD IP

 That's normally handled by each v4l2 device, see [2] for details at the
 user side, and vidioc_s_fmt_vid_cap() in vivi for example.

Agree.

 - one method is required to start or stop FD

 I suppose VIDIOC_STREAMON/VIDIOC_STREAMOFF would do the job, see [3] and
 start/stop_streaming functions in vivi.

Agree.

 - one method is required to report the detection results to user space

 Perhaps we need new ioctl(s) for that. And possibly some new controls,
 or even new control class [5], [6].

Agree.

 It would also be good to get requirements for other hardware implementations
 existing out there. I might be able to look at the Samsung ones eventually,
 but cannot guarantee this.

It is great for you to provide some information about FD on Samsung SoC,
so that we can figure out a more generic implementation to make support
for new FD IP easier.


 Any suggestions on how to implement FD on v4l2?

 thanks,
 --
 Ming Lei

 --
 Regards,
 Sylwester

 [1] http://linuxtv.org/downloads/v4l-dvb-apis/devices.html
 [2] http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-fmt.html
 [3] http://linuxtv.org/downloads/v4l-dvb-apis

Re: [PATCH 3/3] drivers/misc: introduce face detection module driver(fdif)

2011-11-26 Thread Ming Lei
Hi guys,

Thanks for your comment.

On Sun, Nov 27, 2011 at 6:16 AM, Sylwester Nawrocki snj...@gmail.com wrote:
 Cc: LMML

 On 11/26/2011 05:31 AM, tom.leim...@gmail.com wrote:
 From: Ming Lei ming@canonical.com

 One face detection IP[1] is integared inside OMAP4 SoC, so
 introduce this driver to make face detection function work
 on OMAP4 SoC.

 Face detection IP is of course not specific to OMAP, I've seen it in other 
 SoCs
 already and integrated with the video capture pipeline.

Yes, the driver is platform independent, so at least it can support
the same IP on different platforms.


 And it clearly belongs to the media subsystem, there is already an 
 infrastructure
 there that don't need to be re-invented, like buffer management and various IO
 method support.

 I think there is not much needed on top of that to support FD. We have already
 various mem-to-mem devices in V4L2, like video or image encoders or video
 post-processors.

I have thought about the FD implementation on v4l2 core, but still not
very clear
how to do it. I will study v4l2 further to figure out how to do it.

Now below are the basic requirements from FD:

- FD on video stream or pictures from external files
- FD on video stream or pictures from video device
(such as camera)
- the input video format may be different for different FD IP
- one method is required to start or stop FD
- one method is required to report the detection results to user space

Any suggestions on how to implement FD on v4l2?

thanks,
--
Ming Lei



 This driver is platform independent, so in theory can
 be used to drive same IP module on other platforms.

 [1], ch9 of OMAP4 TRM

 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/misc/Kconfig  |    7 +
  drivers/misc/Makefile |    1 +
  drivers/misc/fdif.c   |  874 
 +
  include/linux/fdif.h  |   67 
  include/linux/major.h |    1 +
  5 files changed, 950 insertions(+), 0 deletions(-)
  create mode 100644 drivers/misc/fdif.c
  create mode 100644 include/linux/fdif.h

 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
 index 5664696..884d8c7 100644
 --- a/drivers/misc/Kconfig
 +++ b/drivers/misc/Kconfig
 @@ -500,6 +500,13 @@ config USB_SWITCH_FSA9480
         stereo and mono audio, video, microphone and UART data to use
         a common connector port.

 +config FDIF
 +     tristate Face Detection module
 +     help
 +       The FDIF is a face detection module, which can be integrated into
 +       SoCs to detect the location of human beings' face in one image. At
 +       least now, TI OMAP4 has the module inside.
 +
  source drivers/misc/c2port/Kconfig
  source drivers/misc/eeprom/Kconfig
  source drivers/misc/cb710/Kconfig
 diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
 index b26495a..0ed85ef 100644
 --- a/drivers/misc/Makefile
 +++ b/drivers/misc/Makefile
 @@ -47,4 +47,5 @@ obj-$(CONFIG_AB8500_PWM)    += ab8500-pwm.o
  obj-y                                += lis3lv02d/
  obj-y                                += carma/
  obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
 +obj-$(CONFIG_FDIF)           += fdif.o
  obj-$(CONFIG_ALTERA_STAPL)   +=altera-stapl/
 diff --git a/drivers/misc/fdif.c b/drivers/misc/fdif.c
 new file mode 100644
 index 000..84a7049
 --- /dev/null
 +++ b/drivers/misc/fdif.c
 @@ -0,0 +1,874 @@
 +/*
 + *      fdif.c  --  face detection module driver
 + *
 + *      Copyright (C) 2011  Ming Lei (ming@canonical.com)
 + *
 + *      This program is free software; you can redistribute it and/or modify
 + *      it under the terms of the GNU General Public License as published by
 + *      the Free Software Foundation; either version 2 of the License, or
 + *      (at your option) any later version.
 + *
 + *      This program is distributed in the hope that it will be useful,
 + *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *      GNU General Public License for more details.
 + *
 + *      You should have received a copy of the GNU General Public License
 + *      along with this program; if not, write to the Free Software
 + *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 + *
 + */
 +
 +/*/
 +
 +#include linux/init.h
 +#include linux/fs.h
 +#include linux/mm.h
 +#include linux/slab.h
 +#include linux/signal.h
 +#include linux/wait.h
 +#include linux/poll.h
 +#include linux/module.h
 +#include linux/major.h
 +#include linux/cdev.h
 +#include linux/mman.h
 +#include linux/pm_runtime.h
 +#include linux/delay.h
 +#include linux/user_namespace.h
 +#include linux/platform_device.h
 +#include linux/interrupt.h
 +#include linux/dma-mapping.h
 +#include linux/fdif.h
 +#include asm/uaccess.h
 +#include asm/byteorder.h
 +#include asm/io.h
 +
 +#undef       DEBUG
 +
 +#define FDIF_DEV     MKDEV(FDIF_MAJOR, 0)
 +#define

Re: [PATCH] uvcvideo: add SetInterface(0) in .reset_resume handler

2011-07-31 Thread Ming Lei
Hi,

On Sun, Jul 31, 2011 at 11:38 PM, Laurent Pinchart
laurent.pinch...@ideasonboard.com wrote:
 Hi Ming,

 Thanks for the patch. I've queued it for v3.2 with a small modification (the
 usb_set_interface() call has been moved to uvc_video.c).

Thanks for queuing it.

Considered it is a fix patch, could you queue it for 3.1 -rcX as fix patch?
But anyway, it is up to you, :-)

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


Re: [PATCH] uvcvideo: add fix suspend/resume quirk for Microdia camera

2011-07-15 Thread Ming Lei
Hi,

On Thu, Jul 14, 2011 at 11:03 PM, Alan Stern st...@rowland.harvard.edu wrote:

 More likely, the reset erases some device setting that uvcvideo
 installed while binding.  Evidently uvcvideo does not re-install the
 setting during reset-resume; this is probably a bug in the driver.

Alan, you are right.

I think I have found the root cause. Given many devices can't
handle set_interface(0) if the interfaces were already in altsetting 0,
usb_reset_and_verify_device does not run set_interface(0). So we
need to do it in .reset_resume handler of uvc driver and it is always
safe for uvc devices.

I have tested the below patch, and it can make the uvc device work
well after rpm resume and system resume(reset resume), both in
streaming on and off case.

Alan, Laurent, if you have no objections, I will submit a formal one.

diff --git a/drivers/media/video/uvc/uvc_driver.c
b/drivers/media/video/uvc/uvc_driver.c
index b6eae48..4055dfc 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -1959,8 +1959,12 @@ static int __uvc_resume(struct usb_interface
*intf, int reset)
}

list_for_each_entry(stream, dev-streams, list) {
-   if (stream-intf == intf)
+   if (stream-intf == intf) {
+   if (reset)
+   usb_set_interface(stream-dev-udev,
+   stream-intfnum, 0);
return uvc_video_resume(stream);
+   }
}

uvc_trace(UVC_TRACE_SUSPEND, Resume: video streaming USB interface 



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


  1   2   >