[PATCH v4 16/22] [media] em28xx: use a better value for I2C timeouts

2014-01-04 Thread Mauro Carvalho Chehab
In the lack of a better spec, let's assume the timeout
values compatible with SMBus spec:
http://smbus.org/specs/smbus110.pdf

at chapter 8 - Electrical Characteristics of SMBus devices

Ok, SMBus is a subset of I2C, and not all devices will be
following it, but the timeout value before this patch was not
even following the spec.

So, while we don't have a better guess for it, use 35 + 1
ms as the timeout.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx.h | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index db47c2236ca4..9af19332b0f1 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -183,8 +183,21 @@
 
 #define EM28XX_INTERLACED_DEFAULT 1
 
-/* time in msecs to wait for i2c xfers to finish */
-#define EM2800_I2C_XFER_TIMEOUT20
+/*
+ * Time in msecs to wait for i2c xfers to finish.
+ * 35ms is the maximum time a SMBUS device could wait when
+ * clock stretching is used. As the transfer itself will take
+ * some time to happen, set it to 35 ms.
+ *
+ * Ok, I2C doesn't specify any limit. So, eventually, we may need
+ * to increase this timeout.
+ *
+ * FIXME: this assumes that an I2C message is not longer than 1ms.
+ * This is actually dependent on the I2C bus speed, although most
+ * devices use a 100kHz clock. So, this assumtion is true most of
+ * the time.
+ */
+#define EM2800_I2C_XFER_TIMEOUT36
 
 /* time in msecs to wait for AC97 xfers to finish */
 #define EM2800_AC97_XFER_TIMEOUT   100
-- 
1.8.3.1

--
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 v4 11/22] [media] em28xx: check if a device has audio earlier

2014-01-04 Thread Mauro Carvalho Chehab
Better to split chipset detection from the audio setup. So, move the
detection code to em28xx_init_dev().

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-cards.c | 11 +++
 drivers/media/usb/em28xx/em28xx-core.c  | 12 +---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index d1c75e66554c..4fe742429f2c 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2930,6 +2930,16 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
}
}
 
+   if (dev-chip_id == CHIP_ID_EM2870 ||
+   dev-chip_id == CHIP_ID_EM2874 ||
+   dev-chip_id == CHIP_ID_EM28174 ||
+   dev-chip_id == CHIP_ID_EM28178) {
+   /* Digital only device - don't load any alsa module */
+   dev-audio_mode.has_audio = false;
+   dev-has_audio_class = false;
+   dev-has_alsa_audio = false;
+   }
+
if (chip_name != default_chip_name)
printk(KERN_INFO DRIVER_NAME
   : chip ID is %s\n, chip_name);
@@ -3196,6 +3206,7 @@ static int em28xx_usb_probe(struct usb_interface 
*interface,
dev-alt   = -1;
dev-is_audio_only = has_audio  !(has_video || has_dvb);
dev-has_alsa_audio = has_audio;
+   dev-audio_mode.has_audio = has_audio;
dev-has_video = has_video;
dev-audio_ifnum = ifnum;
 
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 33cf26e106b5..818248d3fd28 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -505,18 +505,8 @@ int em28xx_audio_setup(struct em28xx *dev)
int vid1, vid2, feat, cfg;
u32 vid;
 
-   if (dev-chip_id == CHIP_ID_EM2870 ||
-   dev-chip_id == CHIP_ID_EM2874 ||
-   dev-chip_id == CHIP_ID_EM28174 ||
-   dev-chip_id == CHIP_ID_EM28178) {
-   /* Digital only device - don't load any alsa module */
-   dev-audio_mode.has_audio = false;
-   dev-has_audio_class = false;
-   dev-has_alsa_audio = false;
+   if (!dev-audio_mode.has_audio)
return 0;
-   }
-
-   dev-audio_mode.has_audio = true;
 
/* See how this device is configured */
cfg = em28xx_read_reg(dev, EM28XX_R00_CHIPCFG);
-- 
1.8.3.1

--
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 v4 03/22] [media] em28xx: move analog-specific init to em28xx-video

2014-01-04 Thread Mauro Carvalho Chehab
There are several init code inside em28xx-cards that are actually
part of analog initialization. Move the code to em28x-video, in
order to remove part of the mess.

In thesis, no functional changes so far.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-cards.c | 71 -
 drivers/media/usb/em28xx/em28xx-video.c | 91 ++---
 2 files changed, 84 insertions(+), 78 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 551cbc294190..175cd776e0a1 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2907,7 +2907,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
   struct usb_interface *interface,
   int minor)
 {
-   struct v4l2_ctrl_handler *hdl = dev-ctrl_handler;
int retval;
static const char *default_chip_name = em28xx;
const char *chip_name = default_chip_name;
@@ -3034,15 +3033,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
}
}
 
-   retval = v4l2_device_register(interface-dev, dev-v4l2_dev);
-   if (retval  0) {
-   em28xx_errdev(Call to v4l2_device_register() failed!\n);
-   return retval;
-   }
-
-   v4l2_ctrl_handler_init(hdl, 8);
-   dev-v4l2_dev.ctrl_handler = hdl;
-
rt_mutex_init(dev-i2c_bus_lock);
 
/* register i2c bus 0 */
@@ -3071,72 +3061,14 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
}
}
 
-   /*
-* Default format, used for tvp5150 or saa711x output formats
-*/
-   dev-vinmode = 0x10;
-   dev-vinctl  = EM28XX_VINCTRL_INTERLACED |
-  EM28XX_VINCTRL_CCIR656_ENABLE;
-
/* Do board specific init and eeprom reading */
em28xx_card_setup(dev);
 
-   /* Configure audio */
-   retval = em28xx_audio_setup(dev);
-   if (retval  0) {
-   em28xx_errdev(%s: Error while setting audio - error [%d]!\n,
-   __func__, retval);
-   goto fail;
-   }
-   if (dev-audio_mode.ac97 != EM28XX_NO_AC97) {
-   v4l2_ctrl_new_std(hdl, em28xx_ctrl_ops,
-   V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
-   v4l2_ctrl_new_std(hdl, em28xx_ctrl_ops,
-   V4L2_CID_AUDIO_VOLUME, 0, 0x1f, 1, 0x1f);
-   } else {
-   /* install the em28xx notify callback */
-   v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_MUTE),
-   em28xx_ctrl_notify, dev);
-   v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_VOLUME),
-   em28xx_ctrl_notify, dev);
-   }
-
-   /* wake i2c devices */
-   em28xx_wake_i2c(dev);
-
-   /* init video dma queues */
-   INIT_LIST_HEAD(dev-vidq.active);
-   INIT_LIST_HEAD(dev-vbiq.active);
-
-   if (dev-board.has_msp34xx) {
-   /* Send a reset to other chips via gpio */
-   retval = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xf7);
-   if (retval  0) {
-   em28xx_errdev(%s: em28xx_write_reg - 
- msp34xx(1) failed! error [%d]\n,
- __func__, retval);
-   goto fail;
-   }
-   msleep(3);
-
-   retval = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xff);
-   if (retval  0) {
-   em28xx_errdev(%s: em28xx_write_reg - 
- msp34xx(2) failed! error [%d]\n,
- __func__, retval);
-   goto fail;
-   }
-   msleep(3);
-   }
-
retval = em28xx_register_analog_devices(dev);
if (retval  0) {
goto fail;
}
 
-   /* Save some power by putting tuner to sleep */
-   v4l2_device_call_all(dev-v4l2_dev, 0, core, s_power, 0);
-
return 0;
 
 fail:
@@ -3388,9 +3320,6 @@ static int em28xx_usb_probe(struct usb_interface 
*interface,
/* save our data pointer in this interface device */
usb_set_intfdata(interface, dev);
 
-   /* initialize videobuf2 stuff */
-   em28xx_vb2_setup(dev);
-
/* allocate device struct */
mutex_init(dev-lock);
mutex_lock(dev-lock);
diff --git a/drivers/media/usb/em28xx/em28xx-video.c 
b/drivers/media/usb/em28xx/em28xx-video.c
index 8b8a4eb96875..85284626dbd6 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -2186,10 +2186,78 @@ int em28xx_register_analog_devices(struct em28xx *dev)
u8 val;
int ret;
unsigned int maxw;
+   struct v4l2_ctrl_handler 

[PATCH v4 01/22] [media] em28xx: move some video-specific functions to em28xx-video

2014-01-04 Thread Mauro Carvalho Chehab
Now that we want to split the video handling to a separate
module, move all video-specific functions to em28xx-video.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-cards.c | 107 -
 drivers/media/usb/em28xx/em28xx-core.c  | 259 --
 drivers/media/usb/em28xx/em28xx-video.c | 374 +++-
 drivers/media/usb/em28xx/em28xx.h   |   1 +
 4 files changed, 371 insertions(+), 370 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 36853f16bf97..19827e79cf53 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2529,113 +2529,6 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
em28xx_set_mode(dev, EM28XX_SUSPEND);
 }
 
-static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
-{
-   memset(ctl, 0, sizeof(*ctl));
-
-   ctl-fname   = XC2028_DEFAULT_FIRMWARE;
-   ctl-max_len = 64;
-   ctl-mts = em28xx_boards[dev-model].mts_firmware;
-
-   switch (dev-model) {
-   case EM2880_BOARD_EMPIRE_DUAL_TV:
-   case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
-   case EM2882_BOARD_TERRATEC_HYBRID_XS:
-   ctl-demod = XC3028_FE_ZARLINK456;
-   break;
-   case EM2880_BOARD_TERRATEC_HYBRID_XS:
-   case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
-   case EM2881_BOARD_PINNACLE_HYBRID_PRO:
-   ctl-demod = XC3028_FE_ZARLINK456;
-   break;
-   case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
-   case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
-   ctl-demod = XC3028_FE_DEFAULT;
-   break;
-   case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
-   ctl-demod = XC3028_FE_DEFAULT;
-   ctl-fname = XC3028L_DEFAULT_FIRMWARE;
-   break;
-   case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
-   case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
-   case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
-   /* FIXME: Better to specify the needed IF */
-   ctl-demod = XC3028_FE_DEFAULT;
-   break;
-   case EM2883_BOARD_KWORLD_HYBRID_330U:
-   case EM2882_BOARD_DIKOM_DK300:
-   case EM2882_BOARD_KWORLD_VS_DVBT:
-   ctl-demod = XC3028_FE_CHINA;
-   ctl-fname = XC2028_DEFAULT_FIRMWARE;
-   break;
-   case EM2882_BOARD_EVGA_INDTUBE:
-   ctl-demod = XC3028_FE_CHINA;
-   ctl-fname = XC3028L_DEFAULT_FIRMWARE;
-   break;
-   default:
-   ctl-demod = XC3028_FE_OREN538;
-   }
-}
-
-static void em28xx_tuner_setup(struct em28xx *dev)
-{
-   struct tuner_setup   tun_setup;
-   struct v4l2_frequencyf;
-
-   if (dev-tuner_type == TUNER_ABSENT)
-   return;
-
-   memset(tun_setup, 0, sizeof(tun_setup));
-
-   tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
-   tun_setup.tuner_callback = em28xx_tuner_callback;
-
-   if (dev-board.radio.type) {
-   tun_setup.type = dev-board.radio.type;
-   tun_setup.addr = dev-board.radio_addr;
-
-   v4l2_device_call_all(dev-v4l2_dev, 0, tuner, s_type_addr, 
tun_setup);
-   }
-
-   if ((dev-tuner_type != TUNER_ABSENT)  (dev-tuner_type)) {
-   tun_setup.type   = dev-tuner_type;
-   tun_setup.addr   = dev-tuner_addr;
-
-   v4l2_device_call_all(dev-v4l2_dev, 0, tuner, s_type_addr, 
tun_setup);
-   }
-
-   if (dev-tda9887_conf) {
-   struct v4l2_priv_tun_config tda9887_cfg;
-
-   tda9887_cfg.tuner = TUNER_TDA9887;
-   tda9887_cfg.priv = dev-tda9887_conf;
-
-   v4l2_device_call_all(dev-v4l2_dev, 0, tuner, s_config, 
tda9887_cfg);
-   }
-
-   if (dev-tuner_type == TUNER_XC2028) {
-   struct v4l2_priv_tun_config  xc2028_cfg;
-   struct xc2028_ctrl   ctl;
-
-   memset(xc2028_cfg, 0, sizeof(xc2028_cfg));
-   memset(ctl, 0, sizeof(ctl));
-
-   em28xx_setup_xc3028(dev, ctl);
-
-   xc2028_cfg.tuner = TUNER_XC2028;
-   xc2028_cfg.priv  = ctl;
-
-   v4l2_device_call_all(dev-v4l2_dev, 0, tuner, s_config, 
xc2028_cfg);
-   }
-
-   /* configure tuner */
-   f.tuner = 0;
-   f.type = V4L2_TUNER_ANALOG_TV;
-   f.frequency = 9076; /* just a magic number */
-   dev-ctl_freq = f.frequency;
-   v4l2_device_call_all(dev-v4l2_dev, 0, tuner, s_frequency, f);
-}
-
 static int em28xx_hint_board(struct em28xx *dev)
 {
int i;
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index f6076a512e8f..3012912d2997 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -53,14 +53,6 @@ MODULE_PARM_DESC(reg_debug, enable 

[PATCH v4 05/22] [media] em28xx: initialize analog I2C devices at the right place

2014-01-04 Thread Mauro Carvalho Chehab
In order to initialize the analog tuner, v4l2 should be registere
first, or otherwise we get an oops:

[   51.783537] BUG: unable to handle kernel NULL pointer dereference at)
[   51.784479] IP: [81319fbb] __list_add+0x1b/0xc0
[   51.784479] PGD 0
[   51.784479] Oops:  [#1] SMP
[   51.784479] Modules linked in: tvp5150 em28xx(+) tveeprom v4l2_common videode
[   51.784479] CPU: 0 PID: 946 Comm: systemd-udevd Not tainted 3.13.0-rc1+ #38
[   51.784479] Hardware name: PCCHIPS P17G/P17G, BIOS 080012  05/14/2008
[   51.784479] task: 880027482080 ti: 88003c9b6000 task.ti: 88003c90
[   51.784479] RIP: 0010:[81319fbb]  [81319fbb] __list_add+0
[   51.784479] RSP: 0018:88003c9b7a10  EFLAGS: 00010246
[   51.784479] RAX:  RBX: 880036d12428 RCX: 
[   51.784479] RDX: 880036ce6040 RSI:  RDI: 880036d12428
[   51.784479] RBP: 88003c9b7a28 R08:  R09: 0001
[   51.784479] R10: 0001 R11:  R12: 880036ce6040
[   51.784479] R13:  R14: 880036ce62c0 R15: a045c176
[   51.784479] FS:  7fba89124880() GS:88003f40() knlGS:0
[   51.784479] CS:  0010 DS:  ES:  CR0: 8005003b
[   51.784479] CR2:  CR3: 3bccf000 CR4: 07f0
[   51.784479] Stack:
[   51.784479]  880036d12428 880036ce6038  88003c9b0
[   51.784479]  a0425bbc 880028246800 880036d12428 880036ce8
[   51.784479]  88003c9b7a80 a044d733 88003c9b7a90 880036ce8
[   51.784479] Call Trace:
[   51.784479]  [a0425bbc] v4l2_device_register_subdev+0xdc/0x120 [vi]
[   51.784479]  [a044d733] v4l2_i2c_new_subdev_board+0xa3/0x100 [v4l2]
[   51.784479]  [a044d7fa] v4l2_i2c_new_subdev+0x6a/0x90 [v4l2_common]
[   51.784479]  [a0455dcb] em28xx_usb_probe+0xd3b/0x10a0 [em28xx]
[   51.784479]  [81478f74] usb_probe_interface+0x1c4/0x2f0
[   51.784479]  [81400127] driver_probe_device+0x87/0x390
[   51.784479]  [81400503] __driver_attach+0x93/0xa0
[   51.784479]  [81400470] ? __device_attach+0x40/0x40
[   51.784479]  [813fe153] bus_for_each_dev+0x63/0xa0
[   51.784479]  [813ffb7e] driver_attach+0x1e/0x20
[   51.784479]  [813ff760] bus_add_driver+0x180/0x250
[   51.784479]  [81400b34] driver_register+0x64/0xf0
[   51.784479]  [81477751] usb_register_driver+0x81/0x160
[   51.784479]  [a0467000] ? 0xa0466fff
[   51.784479]  [a046701e] em28xx_usb_driver_init+0x1e/0x1000 [em28xx]
[   51.784479]  [8100214a] do_one_initcall+0xfa/0x1b0
[   51.784479]  [81053793] ? set_memory_nx+0x43/0x50
[   51.784479]  [810d9926] load_module+0x1bc6/0x24b0
[   51.784479]  [810d5940] ? store_uevent+0x40/0x40
[   51.784479]  [810da386] SyS_finit_module+0x86/0xb0
[   51.784479]  [81666529] system_call_fastpath+0x16/0x1b
[   51.784479] Code: ff ff 5b 41 5c 41 5d 41 5e 41 5f 5d c3 0f 1f 00 55 48 89 e
[   51.784479] RIP  [81319fbb] __list_add+0x1b/0xc0
[   51.784479]  RSP 88003c9b7a10
[   51.784479] CR2: 
[   52.218397] ---[ end trace 0bd601544e51b8a3 ]---

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-cards.c | 64 
 drivers/media/usb/em28xx/em28xx-video.c | 65 +
 2 files changed, 65 insertions(+), 64 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 938daaabd8e0..d1c75e66554c 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2362,24 +2362,6 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
 };
 /* NOTE: introduce a separate hash table for devices with 16 bit eeproms */
 
-/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */
-static unsigned short saa711x_addrs[] = {
-   0x4a  1, 0x48  1,   /* SAA7111, SAA7111A and SAA7113 */
-   0x42  1, 0x40  1,   /* SAA7114, SAA7115 and SAA7118 */
-   I2C_CLIENT_END };
-
-static unsigned short tvp5150_addrs[] = {
-   0xb8  1,
-   0xba  1,
-   I2C_CLIENT_END
-};
-
-static unsigned short msp3400_addrs[] = {
-   0x80  1,
-   0x88  1,
-   I2C_CLIENT_END
-};
-
 int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
 {
struct em28xx_i2c_bus *i2c_bus = ptr;
@@ -2784,54 +2766,8 @@ static void em28xx_card_setup(struct em28xx *dev)
/* Allow override tuner type by a module parameter */
if (tuner = 0)
dev-tuner_type = tuner;
-
-   /* request some modules */
-   if (dev-board.has_msp34xx)
-   v4l2_i2c_new_subdev(dev-v4l2_dev, 
dev-i2c_adap[dev-def_i2c_bus],
-   msp3400, 0, msp3400_addrs);
-
-

[PATCH v4 12/22] [media] em28xx: properly implement AC97 wait code

2014-01-04 Thread Mauro Carvalho Chehab
Instead of assuming that msleep() is precise, use a jiffies
based code to wait for AC97 to be available.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-core.c | 7 +--
 drivers/media/usb/em28xx/em28xx.h  | 5 -
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 818248d3fd28..36b2f1ab4474 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -23,6 +23,7 @@
  */
 
 #include linux/init.h
+#include linux/jiffies.h
 #include linux/list.h
 #include linux/module.h
 #include linux/slab.h
@@ -254,16 +255,18 @@ EXPORT_SYMBOL_GPL(em28xx_toggle_reg_bits);
  */
 static int em28xx_is_ac97_ready(struct em28xx *dev)
 {
-   int ret, i;
+   unsigned long timeout = jiffies + 
msecs_to_jiffies(EM2800_AC97_XFER_TIMEOUT);
+   int ret;
 
/* Wait up to 50 ms for AC97 command to complete */
-   for (i = 0; i  10; i++, msleep(5)) {
+   while (time_is_after_jiffies(timeout)) {
ret = em28xx_read_reg(dev, EM28XX_R43_AC97BUSY);
if (ret  0)
return ret;
 
if (!(ret  0x01))
return 0;
+   msleep (5);
}
 
em28xx_warn(AC97 command still being executed: not handled 
properly!\n);
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index 9d6f43e4681f..ac79501f5d9f 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -182,9 +182,12 @@
 
 #define EM28XX_INTERLACED_DEFAULT 1
 
-/* time in msecs to wait for i2c writes to finish */
+/* time in msecs to wait for i2c xfers to finish */
 #define EM2800_I2C_XFER_TIMEOUT20
 
+/* time in msecs to wait for AC97 xfers to finish */
+#define EM2800_AC97_XFER_TIMEOUT   100
+
 /* max. number of button state polling addresses */
 #define EM28XX_NUM_BUTTON_ADDRESSES_MAX5
 
-- 
1.8.3.1

--
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 v4 07/22] [media] em28xx: improve extension information messages

2014-01-04 Thread Mauro Carvalho Chehab
Add a message with consistent prints before and after each
extension initialization, and provide a better text for module
load.

While here, add a missing sanity check for extension finish
code at em28xx-v4l extension.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-audio.c |  4 +++-
 drivers/media/usb/em28xx/em28xx-core.c  |  2 +-
 drivers/media/usb/em28xx/em28xx-dvb.c   |  7 ---
 drivers/media/usb/em28xx/em28xx-input.c |  4 
 drivers/media/usb/em28xx/em28xx-video.c | 10 --
 5 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index 2fdb66ee44ab..263886adcf26 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -649,7 +649,8 @@ static int em28xx_audio_init(struct em28xx *dev)
return 0;
}
 
-   printk(KERN_INFO em28xx-audio.c: probing for em28xx Audio Vendor 
Class\n);
+   em28xx_info(Binding audio extension\n);
+
printk(KERN_INFO em28xx-audio.c: Copyright (C) 2006 Markus 
 Rechberger\n);
printk(KERN_INFO em28xx-audio.c: Copyright (C) 2007-2011 Mauro 
Carvalho Chehab\n);
@@ -702,6 +703,7 @@ static int em28xx_audio_init(struct em28xx *dev)
adev-sndcard = card;
adev-udev = dev-udev;
 
+   em28xx_info(Audio extension successfully initialized\n);
return 0;
 }
 
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 1113d4e107d8..33cf26e106b5 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -1069,7 +1069,7 @@ int em28xx_register_extension(struct em28xx_ops *ops)
ops-init(dev);
}
mutex_unlock(em28xx_devlist_mutex);
-   printk(KERN_INFO Em28xx: Initialized (%s) extension\n, ops-name);
+   printk(KERN_INFO em28xx: Registered (%s) extension\n, ops-name);
return 0;
 }
 EXPORT_SYMBOL(em28xx_register_extension);
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index ddc0e609065d..f72663a9b5c5 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -274,7 +274,7 @@ static int em28xx_stop_feed(struct dvb_demux_feed *feed)
 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
 {
struct em28xx_i2c_bus *i2c_bus = fe-dvb-priv;
-struct em28xx *dev = i2c_bus-dev;
+   struct em28xx *dev = i2c_bus-dev;
 
if (acquire)
return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
@@ -992,10 +992,11 @@ static int em28xx_dvb_init(struct em28xx *dev)
 
if (!dev-board.has_dvb) {
/* This device does not support the extension */
-   printk(KERN_INFO em28xx_dvb: This device does not support the 
extension\n);
return 0;
}
 
+   em28xx_info(Binding DVB extension\n);
+
dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
 
if (dvb == NULL) {
@@ -1407,7 +1408,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
/* MFE lock */
dvb-adapter.mfe_shared = mfe_shared;
 
-   em28xx_info(Successfully loaded em28xx-dvb\n);
+   em28xx_info(DVB extension successfully initialized\n);
 ret:
em28xx_set_mode(dev, EM28XX_SUSPEND);
mutex_unlock(dev-lock);
diff --git a/drivers/media/usb/em28xx/em28xx-input.c 
b/drivers/media/usb/em28xx/em28xx-input.c
index 93a7d02b9cb4..eed7dd79f734 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -692,6 +692,8 @@ static int em28xx_ir_init(struct em28xx *dev)
return 0;
}
 
+   em28xx_info(Registering input extension\n);
+
ir = kzalloc(sizeof(*ir), GFP_KERNEL);
rc = rc_allocate_device();
if (!ir || !rc)
@@ -785,6 +787,8 @@ static int em28xx_ir_init(struct em28xx *dev)
if (err)
goto error;
 
+   em28xx_info(Input extension successfully initalized\n);
+
return 0;
 
 error:
diff --git a/drivers/media/usb/em28xx/em28xx-video.c 
b/drivers/media/usb/em28xx/em28xx-video.c
index 56d1b46164a0..b767262c642b 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -1884,6 +1884,11 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
 
/*FIXME: I2C IR should be disconnected */
 
+   if (!dev-has_video) {
+   /* This device does not support the v4l2 extension */
+   return 0;
+   }
+
if (dev-radio_dev) {
if (video_is_registered(dev-radio_dev))
video_unregister_device(dev-radio_dev);
@@ -2215,8 +2220,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
return 0;
}
 
-   printk(KERN_INFO %s: v4l2 driver version %s\n,
-   dev-name, 

[PATCH v4 13/22] [media] em28xx: initialize audio latter

2014-01-04 Thread Mauro Carvalho Chehab
Better to first write the GPIOs of the input mux, before initializing
the audio.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-video.c | 40 -
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-video.c 
b/drivers/media/usb/em28xx/em28xx-video.c
index b767262c642b..328d724a13ea 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -2291,26 +2291,6 @@ static int em28xx_v4l2_init(struct em28xx *dev)
em28xx_tuner_setup(dev);
em28xx_init_camera(dev);
 
-   /* Configure audio */
-   ret = em28xx_audio_setup(dev);
-   if (ret  0) {
-   em28xx_errdev(%s: Error while setting audio - error [%d]!\n,
-   __func__, ret);
-   goto err;
-   }
-   if (dev-audio_mode.ac97 != EM28XX_NO_AC97) {
-   v4l2_ctrl_new_std(hdl, em28xx_ctrl_ops,
-   V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
-   v4l2_ctrl_new_std(hdl, em28xx_ctrl_ops,
-   V4L2_CID_AUDIO_VOLUME, 0, 0x1f, 1, 0x1f);
-   } else {
-   /* install the em28xx notify callback */
-   v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_MUTE),
-   em28xx_ctrl_notify, dev);
-   v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_VOLUME),
-   em28xx_ctrl_notify, dev);
-   }
-
/* wake i2c devices */
em28xx_wake_i2c(dev);
 
@@ -2356,6 +2336,26 @@ static int em28xx_v4l2_init(struct em28xx *dev)
 
video_mux(dev, 0);
 
+   /* Configure audio */
+   ret = em28xx_audio_setup(dev);
+   if (ret  0) {
+   em28xx_errdev(%s: Error while setting audio - error [%d]!\n,
+   __func__, ret);
+   goto err;
+   }
+   if (dev-audio_mode.ac97 != EM28XX_NO_AC97) {
+   v4l2_ctrl_new_std(hdl, em28xx_ctrl_ops,
+   V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
+   v4l2_ctrl_new_std(hdl, em28xx_ctrl_ops,
+   V4L2_CID_AUDIO_VOLUME, 0, 0x1f, 1, 0x1f);
+   } else {
+   /* install the em28xx notify callback */
+   v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_MUTE),
+   em28xx_ctrl_notify, dev);
+   v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_VOLUME),
+   em28xx_ctrl_notify, dev);
+   }
+
/* Audio defaults */
dev-mute = 1;
dev-volume = 0x1f;
-- 
1.8.3.1

--
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 v4 17/22] [media] em28xx-i2c: Fix error code for I2C error transfers

2014-01-04 Thread Mauro Carvalho Chehab
The proper error code for I2C errors are EREMOTEIO. The em28xx driver
is using EIO instead.

Replace all occurrences of EIO at em28xx-i2c, in order to fix it.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index 9fa7ed51e5b1..8b35aa51b9bb 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -72,7 +72,7 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, 
u8 *buf, u16 len)
if (ret != 2 + len) {
em28xx_warn(failed to trigger write to i2c address 0x%x 
(error=%i)\n,
addr, ret);
-   return (ret  0) ? ret : -EIO;
+   return (ret  0) ? ret : -EREMOTEIO;
}
/* wait for completion */
while (time_is_after_jiffies(timeout)) {
@@ -91,7 +91,7 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, 
u8 *buf, u16 len)
msleep(5);
}
em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
-   return -EIO;
+   return -EREMOTEIO;
 }
 
 /*
@@ -115,7 +115,7 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
if (ret != 2) {
em28xx_warn(failed to trigger read from i2c address 0x%x 
(error=%i)\n,
addr, ret);
-   return (ret  0) ? ret : -EIO;
+   return (ret  0) ? ret : -EREMOTEIO;
}
 
/* wait for completion */
@@ -142,7 +142,7 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
if (ret != len) {
em28xx_warn(reading from i2c device at 0x%x failed: couldn't 
get the received message from the bridge (error=%i)\n,
addr, ret);
-   return (ret  0) ? ret : -EIO;
+   return (ret  0) ? ret : -EREMOTEIO;
}
for (i = 0; i  len; i++)
buf[i] = buf2[len - 1 - i];
@@ -162,7 +162,7 @@ static int em2800_i2c_check_for_device(struct em28xx *dev, 
u8 addr)
ret = em2800_i2c_recv_bytes(dev, addr, buf, 1);
if (ret == 1)
return 0;
-   return (ret  0) ? ret : -EIO;
+   return (ret  0) ? ret : -EREMOTEIO;
 }
 
 /*
@@ -191,7 +191,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
} else {
em28xx_warn(%i bytes write to i2c device at 0x%x 
requested, but %i bytes written\n,
len, addr, ret);
-   return -EIO;
+   return -EREMOTEIO;
}
}
 
@@ -219,7 +219,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
}
 
em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
-   return -EIO;
+   return -EREMOTEIO;
 }
 
 /*
@@ -268,7 +268,7 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf, u16 len)
}
 
em28xx_warn(unknown i2c error (status=%i)\n, ret);
-   return -EIO;
+   return -EREMOTEIO;
 }
 
 /*
@@ -283,7 +283,7 @@ static int em28xx_i2c_check_for_device(struct em28xx *dev, 
u16 addr)
ret = em28xx_i2c_recv_bytes(dev, addr, buf, 1);
if (ret == 1)
return 0;
-   return (ret  0) ? ret : -EIO;
+   return (ret  0) ? ret : -EREMOTEIO;
 }
 
 /*
@@ -312,7 +312,7 @@ static int em25xx_bus_B_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
} else {
em28xx_warn(%i bytes write to i2c device at 0x%x 
requested, but %i bytes written\n,
len, addr, ret);
-   return -EIO;
+   return -EREMOTEIO;
}
}
/* Check success */
-- 
1.8.3.1

--
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 v4 18/22] [media] em28xx: don't return -ENODEV for I2C xfer errors

2014-01-04 Thread Mauro Carvalho Chehab
-ENODEV reports a permanent condition where a device is not found,
and used only during device probing or device removal, as stated
at  the V4L2 spec:
http://linuxtv.org/downloads/v4l-dvb-apis/gen_errors.html

Except during device detection, this is not the case of I2C
transfer timeout errors.

So, change them to return -EREMOTEIO instead.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index 8b35aa51b9bb..c3ba8ace5c94 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -81,7 +81,7 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, 
u8 *buf, u16 len)
return len;
if (ret == 0x94 + len - 1) {
em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
-   return -ENODEV;
+   return -EREMOTEIO;
}
if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
@@ -125,7 +125,7 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
break;
if (ret == 0x94 + len - 1) {
em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
-   return -ENODEV;
+   return -EREMOTEIO;
}
if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
@@ -203,7 +203,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
if (ret == 0x10) {
em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x,
addr);
-   return -ENODEV;
+   return -EREMOTEIO;
}
if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
@@ -249,7 +249,7 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf, u16 len)
 * bytes if we are on bus B AND there was no write attempt to the
 * specified slave address before AND no device is present at the
 * requested slave address.
-* Anyway, the next check will fail with -ENODEV in this case, so avoid
+* Anyway, the next check will fail with -EREMOTEIO in this case, so 
avoid
 * spamming the system log on device probing and do nothing here.
 */
 
@@ -264,7 +264,7 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf, u16 len)
}
if (ret == 0x10) {
em28xx_warn(I2C transfer timeout on read from addr 0x%02x, 
addr);
-   return -ENODEV;
+   return -EREMOTEIO;
}
 
em28xx_warn(unknown i2c error (status=%i)\n, ret);
@@ -325,7 +325,7 @@ static int em25xx_bus_B_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
return len;
else if (ret  0) {
em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout, ret);
-   return -ENODEV;
+   return -EREMOTEIO;
}
 
return ret;
@@ -364,8 +364,6 @@ static int em25xx_bus_B_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
 * bytes if we are on bus B AND there was no write attempt to the
 * specified slave address before AND no device is present at the
 * requested slave address.
-* Anyway, the next check will fail with -ENODEV in this case, so avoid
-* spamming the system log on device probing and do nothing here.
 */
 
/* Check success */
@@ -378,7 +376,7 @@ static int em25xx_bus_B_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
return len;
else if (ret  0) {
em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout, ret);
-   return -ENODEV;
+   return -EREMOTEIO;
}
 
return ret;
@@ -420,7 +418,7 @@ static inline int i2c_check_for_device(struct 
em28xx_i2c_bus *i2c_bus, u16 addr)
rc = em2800_i2c_check_for_device(dev, addr);
else if (i2c_bus-algo_type == EM28XX_I2C_ALGO_EM25XX_BUS_B)
rc = em25xx_bus_B_check_for_device(dev, addr);
-   if (rc == -ENODEV) {
+   if (rc  0) {
if (i2c_debug)
printk( no device\n);
}
@@ -510,7 +508,7 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
   addr, msgs[i].len);
if (!msgs[i].len) { /* no len: check only for device presence */
rc = i2c_check_for_device(i2c_bus, addr);
-   if (rc == -ENODEV) {
+   

[PATCH v4 21/22] [media] em28xx-audio: allocate URBs at device driver init

2014-01-04 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab mche...@redhat.com

Instead of allocating/deallocating URBs and transfer buffers
every time stream is started/stopped, just do it once.

That reduces the memory allocation pressure and makes the
code that start/stop streaming a way simpler.

Signed-off-by: Mauro Carvalho Chehab mche...@redhat.com
Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-audio.c | 128 ++--
 1 file changed, 73 insertions(+), 55 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index e5120430ec80..30ee389a07f0 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2006 Markus Rechberger mrechber...@gmail.com
  *
- *  Copyright (C) 2007-2011 Mauro Carvalho Chehab mche...@redhat.com
+ *  Copyright (C) 2007-2014 Mauro Carvalho Chehab
  * - Port to work with the in-kernel driver
  * - Cleanups, fixes, alsa-controls, etc.
  *
@@ -70,16 +70,6 @@ static int em28xx_deinit_isoc_audio(struct em28xx *dev)
usb_kill_urb(urb);
else
usb_unlink_urb(urb);
-
-   usb_free_coherent(dev-udev,
- urb-transfer_buffer_length,
- dev-adev.transfer_buffer[i],
- urb-transfer_dma);
-
-   dev-adev.transfer_buffer[i] = NULL;
-
-   usb_free_urb(urb);
-   dev-adev.urb[i] = NULL;
}
 
return 0;
@@ -174,53 +164,14 @@ static void em28xx_audio_isocirq(struct urb *urb)
 static int em28xx_init_audio_isoc(struct em28xx *dev)
 {
int   i, errCode;
-   const int sb_size = EM28XX_NUM_AUDIO_PACKETS *
-   EM28XX_AUDIO_MAX_PACKET_SIZE;
 
dprintk(Starting isoc transfers\n);
 
+   /* Start streaming */
for (i = 0; i  EM28XX_AUDIO_BUFS; i++) {
-   struct urb *urb;
-   int j, k;
-   void *buf;
-
-   urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
-   if (!urb) {
-   em28xx_errdev(usb_alloc_urb failed!\n);
-   for (j = 0; j  i; j++) {
-   usb_free_urb(dev-adev.urb[j]);
-   kfree(dev-adev.transfer_buffer[j]);
-   }
-   return -ENOMEM;
-   }
-
-   buf = usb_alloc_coherent(dev-udev, sb_size, GFP_ATOMIC,
-urb-transfer_dma);
-   if (!buf)
-   return -ENOMEM;
-   dev-adev.transfer_buffer[i] = buf;
-   memset(buf, 0x80, sb_size);
-
-   urb-dev = dev-udev;
-   urb-context = dev;
-   urb-pipe = usb_rcvisocpipe(dev-udev, EM28XX_EP_AUDIO);
-   urb-transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
-   urb-transfer_buffer = dev-adev.transfer_buffer[i];
-   urb-interval = 1;
-   urb-complete = em28xx_audio_isocirq;
-   urb-number_of_packets = EM28XX_NUM_AUDIO_PACKETS;
-   urb-transfer_buffer_length = sb_size;
-
-   for (j = k = 0; j  EM28XX_NUM_AUDIO_PACKETS;
-j++, k += EM28XX_AUDIO_MAX_PACKET_SIZE) {
-   urb-iso_frame_desc[j].offset = k;
-   urb-iso_frame_desc[j].length =
-   EM28XX_AUDIO_MAX_PACKET_SIZE;
-   }
-   dev-adev.urb[i] = urb;
-   }
+   memset(dev-adev.transfer_buffer[i], 0x80,
+  dev-adev.urb[i]-transfer_buffer_length);
 
-   for (i = 0; i  EM28XX_AUDIO_BUFS; i++) {
errCode = usb_submit_urb(dev-adev.urb[i], GFP_ATOMIC);
if (errCode) {
em28xx_errdev(submit of audio urb failed\n);
@@ -643,13 +594,36 @@ static struct snd_pcm_ops snd_em28xx_pcm_capture = {
.page  = snd_pcm_get_vmalloc_page,
 };
 
+static void em28xx_audio_free_urb(struct em28xx *dev)
+{
+   int i;
+
+   for (i = 0; i  EM28XX_AUDIO_BUFS; i++) {
+   struct urb *urb = dev-adev.urb[i];
+
+   if (!dev-adev.urb[i])
+   continue;
+
+   usb_free_coherent(dev-udev,
+ urb-transfer_buffer_length,
+ dev-adev.transfer_buffer[i],
+ urb-transfer_dma);
+
+   usb_free_urb(urb);
+   dev-adev.urb[i] = NULL;
+   dev-adev.transfer_buffer[i] = NULL;
+   }
+}
+
 static int em28xx_audio_init(struct em28xx *dev)
 {
struct em28xx_audio *adev = dev-adev;
struct snd_pcm  *pcm;
struct snd_card *card;
static int  devnr;

[PATCH v4 20/22] [media] em28xx: use usb_alloc_coherent() for audio

2014-01-04 Thread Mauro Carvalho Chehab
Instead of allocating transfer buffers with kmalloc() use
usb_alloc_coherent().

That makes it work also with arm CPUs.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-audio.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index a6eef06ffdcd..e5120430ec80 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -64,16 +64,22 @@ static int em28xx_deinit_isoc_audio(struct em28xx *dev)
 
dprintk(Stopping isoc\n);
for (i = 0; i  EM28XX_AUDIO_BUFS; i++) {
+   struct urb *urb = dev-adev.urb[i];
+
if (!irqs_disabled())
-   usb_kill_urb(dev-adev.urb[i]);
+   usb_kill_urb(urb);
else
-   usb_unlink_urb(dev-adev.urb[i]);
+   usb_unlink_urb(urb);
 
-   usb_free_urb(dev-adev.urb[i]);
-   dev-adev.urb[i] = NULL;
+   usb_free_coherent(dev-udev,
+ urb-transfer_buffer_length,
+ dev-adev.transfer_buffer[i],
+ urb-transfer_dma);
 
-   kfree(dev-adev.transfer_buffer[i]);
dev-adev.transfer_buffer[i] = NULL;
+
+   usb_free_urb(urb);
+   dev-adev.urb[i] = NULL;
}
 
return 0;
@@ -176,12 +182,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
for (i = 0; i  EM28XX_AUDIO_BUFS; i++) {
struct urb *urb;
int j, k;
+   void *buf;
 
-   dev-adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC);
-   if (!dev-adev.transfer_buffer[i])
-   return -ENOMEM;
-
-   memset(dev-adev.transfer_buffer[i], 0x80, sb_size);
urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
if (!urb) {
em28xx_errdev(usb_alloc_urb failed!\n);
@@ -192,10 +194,17 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
return -ENOMEM;
}
 
+   buf = usb_alloc_coherent(dev-udev, sb_size, GFP_ATOMIC,
+urb-transfer_dma);
+   if (!buf)
+   return -ENOMEM;
+   dev-adev.transfer_buffer[i] = buf;
+   memset(buf, 0x80, sb_size);
+
urb-dev = dev-udev;
urb-context = dev;
urb-pipe = usb_rcvisocpipe(dev-udev, EM28XX_EP_AUDIO);
-   urb-transfer_flags = URB_ISO_ASAP;
+   urb-transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
urb-transfer_buffer = dev-adev.transfer_buffer[i];
urb-interval = 1;
urb-complete = em28xx_audio_isocirq;
-- 
1.8.3.1

--
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 v4 15/22] [media] em28xx: Fix em28xx deplock

2014-01-04 Thread Mauro Carvalho Chehab
When em28xx extensions are loaded/removed, there are two locks:

a single static em28xx_devlist_mutex that registers each extension
and the struct em28xx dev-lock.

When extensions are registered, em28xx_devlist_mutex is taken first,
and then dev-lock.

Be sure that, when extensions are being removed, the same order
will be used.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-cards.c | 5 +++--
 drivers/media/usb/em28xx/em28xx-core.c  | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 4fe742429f2c..36aec50e5c3b 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -3334,9 +3334,7 @@ static void em28xx_usb_disconnect(struct usb_interface 
*interface)
dev-disconnected = 1;
 
if (dev-is_audio_only) {
-   mutex_lock(dev-lock);
em28xx_close_extension(dev);
-   mutex_unlock(dev-lock);
return;
}
 
@@ -3355,10 +3353,13 @@ static void em28xx_usb_disconnect(struct usb_interface 
*interface)
em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
}
+   mutex_unlock(dev-lock);
 
em28xx_close_extension(dev);
+
/* NOTE: must be called BEFORE the resources are released */
 
+   mutex_lock(dev-lock);
if (!dev-users)
em28xx_release_resources(dev);
 
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 2ad84ff1fc4f..97cc83c3c287 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -1097,10 +1097,12 @@ void em28xx_close_extension(struct em28xx *dev)
const struct em28xx_ops *ops = NULL;
 
mutex_lock(em28xx_devlist_mutex);
+   mutex_lock(dev-lock);
list_for_each_entry(ops, em28xx_extension_devlist, next) {
if (ops-fini)
ops-fini(dev);
}
+   mutex_unlock(dev-lock);
list_del(dev-devlist);
mutex_unlock(em28xx_devlist_mutex);
 }
-- 
1.8.3.1

--
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 v4 22/22] [media] em28xx: retry read operation if it fails

2014-01-04 Thread Mauro Carvalho Chehab
I2C read operations can also take some time to happen.

Try again, if it fails with return code different than 0x10
until timeout.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 62 +++
 1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index e030e0b7d645..6cd3d909bb3a 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -237,6 +237,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
  */
 static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 
len)
 {
+   unsigned long timeout = jiffies + 
msecs_to_jiffies(EM2800_I2C_XFER_TIMEOUT);
int ret;
 
if (len  1 || len  64)
@@ -246,39 +247,44 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf, u16 len)
 * Zero length reads always succeed, even if no device is connected
 */
 
-   /* Read data from i2c device */
-   ret = dev-em28xx_read_reg_req_len(dev, 2, addr, buf, len);
-   if (ret  0) {
-   em28xx_warn(reading from i2c device at 0x%x failed 
(error=%i)\n,
-   addr, ret);
-   return ret;
-   }
-   /*
-* NOTE: some devices with two i2c busses have the bad habit to return 0
-* bytes if we are on bus B AND there was no write attempt to the
-* specified slave address before AND no device is present at the
-* requested slave address.
-* Anyway, the next check will fail with -EREMOTEIO in this case, so 
avoid
-* spamming the system log on device probing and do nothing here.
-*/
+   do {
+   /* Read data from i2c device */
+   ret = dev-em28xx_read_reg_req_len(dev, 2, addr, buf, len);
+   if (ret  0) {
+   em28xx_warn(reading from i2c device at 0x%x failed 
(error=%i)\n,
+   addr, ret);
+   return ret;
+   }
+   /*
+* NOTE: some devices with two i2c busses have the bad habit to 
return 0
+   * bytes if we are on bus B AND there was no write attempt to the
+   * specified slave address before AND no device is present at the
+   * requested slave address.
+   * Anyway, the next check will fail with -EREMOTEIO in this 
case, so avoid
+   * spamming the system log on device probing and do nothing here.
+   */
+
+   /* Check success of the i2c operation */
+   ret = dev-em28xx_read_reg(dev, 0x05);
+   if (ret == 0) /* success */
+   return len;
+   if (ret  0) {
+   em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
+   ret);
+   return ret;
+   }
+   if (ret != 0x10)
+   break;
+   msleep(5);
+   } while (time_is_after_jiffies(timeout));
 
-   /* Check success of the i2c operation */
-   ret = dev-em28xx_read_reg(dev, 0x05);
-   if (ret == 0) /* success */
-   return len;
-   if (ret  0) {
-   em28xx_warn(failed to get i2c transfer status from bridge 
register (error=%i)\n,
-   ret);
-   return ret;
-   }
if (ret == 0x10) {
if (i2c_debug)
-   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x,
+   em28xx_warn(I2C transfer timeout on reading from addr 
0x%02x,
addr);
-   return -EREMOTEIO;
+   } else {
+   em28xx_warn(unknown i2c error (status=%i)\n, ret);
}
-
-   em28xx_warn(unknown i2c error (status=%i)\n, ret);
return -EREMOTEIO;
 }
 
-- 
1.8.3.1

--
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 v4 02/22] [media] em28xx: some cosmetic changes

2014-01-04 Thread Mauro Carvalho Chehab
In order to make easier for the next patches, do some
cosmetic changes.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-cards.c |  2 +-
 drivers/media/usb/em28xx/em28xx-video.c |  2 --
 drivers/media/usb/em28xx/em28xx.h   | 11 ++-
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 19827e79cf53..551cbc294190 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2106,7 +2106,7 @@ struct em28xx_board em28xx_boards[] = {
},
/* 1b80:e1cc Delock 61959
 * Empia EM2874B + Micronas DRX 3913KA2 + NXP TDA18271HDC2
- * mostly the same as MaxMedia UB-425-TC but different remote */
+* mostly the same as MaxMedia UB-425-TC but different remote */
[EM2874_BOARD_DELOCK_61959] = {
.name  = Delock 61959,
.tuner_type= TUNER_ABSENT,
diff --git a/drivers/media/usb/em28xx/em28xx-video.c 
b/drivers/media/usb/em28xx/em28xx-video.c
index 70ffe259df5b..8b8a4eb96875 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -51,8 +51,6 @@
 
 #define DRIVER_DESC Empia em28xx based USB video device driver
 
-#define EM28XX_VERSION 0.2.0
-
 static unsigned int isoc_debug;
 module_param(isoc_debug, int, 0644);
 MODULE_PARM_DESC(isoc_debug, enable debug messages [isoc transfers]);
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index 0259270dda46..7ae05ebc13c1 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -26,6 +26,8 @@
 #ifndef _EM28XX_H
 #define _EM28XX_H
 
+#define EM28XX_VERSION 0.2.0
+
 #include linux/workqueue.h
 #include linux/i2c.h
 #include linux/mutex.h
@@ -522,9 +524,12 @@ struct em28xx {
int model;  /* index in the device_data struct */
int devno;  /* marks the number of this device */
enum em28xx_chip_id chip_id;
-   unsigned int is_em25xx:1;   /* em25xx/em276x/7x/8x family bridge */
 
+   unsigned int is_em25xx:1;   /* em25xx/em276x/7x/8x family bridge */
unsigned char disconnected:1;   /* device has been diconnected */
+   unsigned int has_audio_class:1;
+   unsigned int has_alsa_audio:1;
+   unsigned int is_audio_only:1;
 
int audio_ifnum;
 
@@ -544,10 +549,6 @@ struct em28xx {
/* Vinmode/Vinctl used at the driver */
int vinmode, vinctl;
 
-   unsigned int has_audio_class:1;
-   unsigned int has_alsa_audio:1;
-   unsigned int is_audio_only:1;
-
/* Controls audio streaming */
struct work_struct wq_trigger;  /* Trigger to start/stop audio for alsa 
module */
atomic_t   stream_started;  /* stream should be running if true */
-- 
1.8.3.1

--
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 v4 04/22] [media] em28xx: make em28xx-video to be a separate module

2014-01-04 Thread Mauro Carvalho Chehab
Now that all analog-specific code are at em28xx-video, convert
it into an em28xx extension and load it as a separate module.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/Kconfig |  6 ++-
 drivers/media/usb/em28xx/Makefile|  5 ++-
 drivers/media/usb/em28xx/em28xx-camera.c |  1 +
 drivers/media/usb/em28xx/em28xx-cards.c  | 45 ---
 drivers/media/usb/em28xx/em28xx-core.c   | 12 ++
 drivers/media/usb/em28xx/em28xx-v4l.h| 20 +
 drivers/media/usb/em28xx/em28xx-vbi.c|  1 +
 drivers/media/usb/em28xx/em28xx-video.c  | 74 +++-
 drivers/media/usb/em28xx/em28xx.h| 23 ++
 9 files changed, 107 insertions(+), 80 deletions(-)
 create mode 100644 drivers/media/usb/em28xx/em28xx-v4l.h

diff --git a/drivers/media/usb/em28xx/Kconfig b/drivers/media/usb/em28xx/Kconfig
index d6ba514d31eb..838fc9dbb747 100644
--- a/drivers/media/usb/em28xx/Kconfig
+++ b/drivers/media/usb/em28xx/Kconfig
@@ -1,8 +1,12 @@
 config VIDEO_EM28XX
-   tristate Empia EM28xx USB video capture support
+   tristate Empia EM28xx USB devices support
depends on VIDEO_DEV  I2C
select VIDEO_TUNER
select VIDEO_TVEEPROM
+
+config VIDEO_EM28XX_V4L2
+   tristate Empia EM28xx analog TV, video capture and/or webcam support
+   depends on VIDEO_EM28XX  I2C
select VIDEOBUF2_VMALLOC
select VIDEO_SAA711X if MEDIA_SUBDRV_AUTOSELECT
select VIDEO_TVP5150 if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/usb/em28xx/Makefile 
b/drivers/media/usb/em28xx/Makefile
index ad6d48557940..3f850d5063d0 100644
--- a/drivers/media/usb/em28xx/Makefile
+++ b/drivers/media/usb/em28xx/Makefile
@@ -1,10 +1,11 @@
-em28xx-y +=em28xx-video.o em28xx-i2c.o em28xx-cards.o
-em28xx-y +=em28xx-core.o  em28xx-vbi.o em28xx-camera.o
+em28xx-y +=em28xx-core.o em28xx-i2c.o em28xx-cards.o em28xx-camera.o
 
+em28xx-v4l-objs := em28xx-video.o em28xx-vbi.o
 em28xx-alsa-objs := em28xx-audio.o
 em28xx-rc-objs := em28xx-input.o
 
 obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
+obj-$(CONFIG_VIDEO_EM28XX_V4L2) += em28xx-v4l.o
 obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o
 obj-$(CONFIG_VIDEO_EM28XX_DVB) += em28xx-dvb.o
 obj-$(CONFIG_VIDEO_EM28XX_RC) += em28xx-rc.o
diff --git a/drivers/media/usb/em28xx/em28xx-camera.c 
b/drivers/media/usb/em28xx/em28xx-camera.c
index d666741797d4..c29f5c4e7b40 100644
--- a/drivers/media/usb/em28xx/em28xx-camera.c
+++ b/drivers/media/usb/em28xx/em28xx-camera.c
@@ -454,3 +454,4 @@ int em28xx_init_camera(struct em28xx *dev)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(em28xx_init_camera);
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 175cd776e0a1..938daaabd8e0 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2159,6 +2159,8 @@ struct em28xx_board em28xx_boards[] = {
.ir_codes  = RC_MAP_PINNACLE_PCTV_HD,
},
 };
+EXPORT_SYMBOL_GPL(em28xx_boards);
+
 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
 
 /* table of devices that work with this driver */
@@ -2827,10 +2829,6 @@ static void em28xx_card_setup(struct em28xx *dev)
tuner, dev-tuner_addr, NULL);
}
}
-
-   em28xx_tuner_setup(dev);
-
-   em28xx_init_camera(dev);
 }
 
 
@@ -2848,11 +2846,12 @@ static void request_module_async(struct work_struct 
*work)
em28xx_init_extension(dev);
 
 #if defined(CONFIG_MODULES)  defined(MODULE)
+   if (dev-has_video)
+   request_module(em28xx-v4l);
if (dev-has_audio_class)
request_module(snd-usb-audio);
else if (dev-has_alsa_audio)
request_module(em28xx-alsa);
-
if (dev-board.has_dvb)
request_module(em28xx-dvb);
if (dev-board.buttons ||
@@ -2881,18 +2880,12 @@ void em28xx_release_resources(struct em28xx *dev)
 {
/*FIXME: I2C IR should be disconnected */
 
-   em28xx_release_analog_resources(dev);
-
if (dev-def_i2c_bus)
em28xx_i2c_unregister(dev, 1);
em28xx_i2c_unregister(dev, 0);
if (dev-clk)
v4l2_clk_unregister_fixed(dev-clk);
 
-   v4l2_ctrl_handler_free(dev-ctrl_handler);
-
-   v4l2_device_unregister(dev-v4l2_dev);
-
usb_put_dev(dev-udev);
 
/* Mark device as unused */
@@ -3043,7 +3036,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
if (retval  0) {
em28xx_errdev(%s: em28xx_i2c_register bus 0 - error [%d]!\n,
__func__, retval);
-   goto unregister_dev;
+   return retval;
}
 
/* register i2c bus 1 */
@@ -3057,30 +3050,14 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
if (retval  0) {
em28xx_errdev(%s: 

[PATCH v4 08/22] [media] em28xx: convert i2c wait completion logic to use jiffies

2014-01-04 Thread Mauro Carvalho Chehab
The I2C wait completion/timeout logic currently assumes that
msleep(5) will wait exaclty 5 ms. This is not true at all,
as it depends on CONFIG_HZ.

Convert it to use jiffies, in order to not wait for more time
than needed.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 65 ++-
 1 file changed, 34 insertions(+), 31 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index 9e6a11d01858..9fa7ed51e5b1 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -26,6 +26,7 @@
 #include linux/kernel.h
 #include linux/usb.h
 #include linux/i2c.h
+#include linux/jiffies.h
 
 #include em28xx.h
 #include tuner-xc2028.h
@@ -48,8 +49,8 @@ MODULE_PARM_DESC(i2c_debug, enable debug messages [i2c]);
  */
 static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
 {
+   unsigned long timeout = jiffies + 
msecs_to_jiffies(EM2800_I2C_XFER_TIMEOUT);
int ret;
-   int write_timeout;
u8 b2[6];
 
if (len  1 || len  4)
@@ -74,15 +75,15 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
return (ret  0) ? ret : -EIO;
}
/* wait for completion */
-   for (write_timeout = EM2800_I2C_XFER_TIMEOUT; write_timeout  0;
-write_timeout -= 5) {
+   while (time_is_after_jiffies(timeout)) {
ret = dev-em28xx_read_reg(dev, 0x05);
-   if (ret == 0x80 + len - 1) {
+   if (ret == 0x80 + len - 1)
return len;
-   } else if (ret == 0x94 + len - 1) {
+   if (ret == 0x94 + len - 1) {
em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
return -ENODEV;
-   } else if (ret  0) {
+   }
+   if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
ret);
return ret;
@@ -99,9 +100,9 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
  */
 static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
 {
+   unsigned long timeout = jiffies + 
msecs_to_jiffies(EM2800_I2C_XFER_TIMEOUT);
u8 buf2[4];
int ret;
-   int read_timeout;
int i;
 
if (len  1 || len  4)
@@ -118,15 +119,15 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
}
 
/* wait for completion */
-   for (read_timeout = EM2800_I2C_XFER_TIMEOUT; read_timeout  0;
-read_timeout -= 5) {
+   while (time_is_after_jiffies(timeout)) {
ret = dev-em28xx_read_reg(dev, 0x05);
-   if (ret == 0x84 + len - 1) {
+   if (ret == 0x84 + len - 1)
break;
-   } else if (ret == 0x94 + len - 1) {
+   if (ret == 0x94 + len - 1) {
em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
return -ENODEV;
-   } else if (ret  0) {
+   }
+   if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
ret);
return ret;
@@ -170,7 +171,8 @@ static int em2800_i2c_check_for_device(struct em28xx *dev, 
u8 addr)
 static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
 u16 len, int stop)
 {
-   int write_timeout, ret;
+   unsigned long timeout = jiffies + 
msecs_to_jiffies(EM2800_I2C_XFER_TIMEOUT);
+   int ret;
 
if (len  1 || len  64)
return -EOPNOTSUPP;
@@ -193,17 +195,18 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
}
}
 
-   /* Check success of the i2c operation */
-   for (write_timeout = EM2800_I2C_XFER_TIMEOUT; write_timeout  0;
-write_timeout -= 5) {
+   /* wait for completion */
+   while (time_is_after_jiffies(timeout)) {
ret = dev-em28xx_read_reg(dev, 0x05);
-   if (ret == 0) { /* success */
+   if (ret == 0) /* success */
return len;
-   } else if (ret == 0x10) {
-   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x, addr);
+   if (ret == 0x10) {
+   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x,
+   addr);
return -ENODEV;
-   } else if (ret  0) {
-   em28xx_warn(failed to read i2c transfer status from 
bridge (error=%i)\n,
+   }
+   if (ret  0) {
+ 

[PATCH v4 00/22] em28xx: split analog part into a separate module

2014-01-04 Thread Mauro Carvalho Chehab
This patch series split em28xx into a separate V4L2 driver,
allowing the new dvb-only chips to be supported without requiring
V4L2.

While testing the original patchset, I noticed several issues with
HVR-950. The remaining patches on this series fix most of those
issues.

There's one remaining issue: connecting an em28xx device into an USB 3.0
port is known to have issues. This is not addressed on this patch series.

v4:
- Fixed the issues pointed by Frank Sh??fer;
- Removed I2C write retry patch from this series;
- Removed experimental patch that removes URB_ISO_ASAP from
  the urb::transfer_flags.

The removed patches are experimental, and will be submitted in
separate.

Mauro Carvalho Chehab (22):
  [media] em28xx: move some video-specific functions to em28xx-video
  [media] em28xx: some cosmetic changes
  [media] em28xx: move analog-specific init to em28xx-video
  [media] em28xx: make em28xx-video to be a separate module
  [media] em28xx: initialize analog I2C devices at the right place
  [media] em28xx: add warn messages for timeout
  [media] em28xx: improve extension information messages
  [media] em28xx: convert i2c wait completion logic to use jiffies
  [media] tvp5150: make read operations atomic
  [media] tuner-xc2028: remove unused code
  [media] em28xx: check if a device has audio earlier
  [media] em28xx: properly implement AC97 wait code
  [media] em28xx: initialize audio latter
  [media] em28xx: unify module version
  [media] em28xx: Fix em28xx deplock
  [media] em28xx: use a better value for I2C timeouts
  [media] em28xx-i2c: Fix error code for I2C error transfers
  [media] em28xx: don't return -ENODEV for I2C xfer errors
  [media] em28xx: cleanup I2C debug messages
  [media] em28xx: use usb_alloc_coherent() for audio
  [media] em28xx-audio: allocate URBs at device driver init
  [media] em28xx: retry read operation if it fails

 drivers/media/i2c/tvp5150.c  |  26 +-
 drivers/media/tuners/tuner-xc2028.c  |   9 -
 drivers/media/usb/em28xx/Kconfig |   6 +-
 drivers/media/usb/em28xx/Makefile|   5 +-
 drivers/media/usb/em28xx/em28xx-audio.c  | 134 ---
 drivers/media/usb/em28xx/em28xx-camera.c |   1 +
 drivers/media/usb/em28xx/em28xx-cards.c  | 305 ++--
 drivers/media/usb/em28xx/em28xx-core.c   | 292 +--
 drivers/media/usb/em28xx/em28xx-dvb.c|  11 +-
 drivers/media/usb/em28xx/em28xx-i2c.c| 237 ++--
 drivers/media/usb/em28xx/em28xx-input.c  |   7 +-
 drivers/media/usb/em28xx/em28xx-v4l.h|  20 ++
 drivers/media/usb/em28xx/em28xx-vbi.c|   1 +
 drivers/media/usb/em28xx/em28xx-video.c  | 598 +--
 drivers/media/usb/em28xx/em28xx.h|  52 +--
 15 files changed, 905 insertions(+), 799 deletions(-)
 create mode 100644 drivers/media/usb/em28xx/em28xx-v4l.h

-- 
1.8.3.1

--
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 v4 09/22] [media] tvp5150: make read operations atomic

2014-01-04 Thread Mauro Carvalho Chehab
Instead of using two I2C operations between write and read,
use just one i2c_transfer. That allows I2C mutexes to not
let any other I2C transfer between the two.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/i2c/tvp5150.c | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 89c0b13463b7..2ed05b67218b 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -58,21 +58,17 @@ static int tvp5150_read(struct v4l2_subdev *sd, unsigned 
char addr)
struct i2c_client *c = v4l2_get_subdevdata(sd);
unsigned char buffer[1];
int rc;
-
-   buffer[0] = addr;
-
-   rc = i2c_master_send(c, buffer, 1);
-   if (rc  0) {
-   v4l2_err(sd, i2c i/o error: rc == %d (should be 1)\n, rc);
-   return rc;
-   }
-
-   msleep(10);
-
-   rc = i2c_master_recv(c, buffer, 1);
-   if (rc  0) {
-   v4l2_err(sd, i2c i/o error: rc == %d (should be 1)\n, rc);
-   return rc;
+   struct i2c_msg msg[] = {
+   { .addr = c-addr, .flags = 0,
+ .buf = addr, .len = 1 },
+   { .addr = c-addr, .flags = I2C_M_RD,
+ .buf = buffer, .len = 1 }
+   };
+
+   rc = i2c_transfer(c-adapter, msg, 2);
+   if (rc  0 || rc != 2) {
+   v4l2_err(sd, i2c i/o error: rc == %d (should be 2)\n, rc);
+   return rc  0 ? rc : -EIO;
}
 
v4l2_dbg(2, debug, sd, tvp5150: read 0x%02x = 0x%02x\n, addr, 
buffer[0]);
-- 
1.8.3.1

--
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 v4 10/22] [media] tuner-xc2028: remove unused code

2014-01-04 Thread Mauro Carvalho Chehab
This macro is not used. remove it.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/tuners/tuner-xc2028.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/media/tuners/tuner-xc2028.c 
b/drivers/media/tuners/tuner-xc2028.c
index 4be5cf808a40..1057da54c6e0 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -134,15 +134,6 @@ struct xc2028_data {
_rc;\
 })
 
-#define i2c_rcv(priv, buf, size) ({\
-   int _rc;\
-   _rc = tuner_i2c_xfer_recv(priv-i2c_props, buf, size); \
-   if (size != _rc)\
-   tuner_err(i2c input error: rc = %d (should be %d)\n,  \
-  _rc, (int)size); \
-   _rc;\
-})
-
 #define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({   \
int _rc;\
_rc = tuner_i2c_xfer_send_recv(priv-i2c_props, obuf, osize,   \
-- 
1.8.3.1

--
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 v4 06/22] [media] em28xx: add warn messages for timeout

2014-01-04 Thread Mauro Carvalho Chehab
changeset 45f04e82d035 added a logic to check if em28xx got
a timeout on an I2C transfer.

That patch started to produce a series of errors that is present
with HVR-950, like:

[ 4032.218656] xc2028 19-0061: Error on line 1299: -19

However, as there are several places where -ENODEV is produced,
there's no way to know what's happening.

So, let's add a printk to report what error condition was reached:

[ 4032.218652] em2882/3 #0: I2C transfer timeout on writing to addr 0xc2
[ 4032.218656] xc2028 19-0061: Error on line 1299: -19

Interesting enough, when connected to an USB3 port, the number of
errors increase:

[ 4249.941375] em2882/3 #0: I2C transfer timeout on writing to addr 0xb8
[ 4249.941378] tvp5150 19-005c: i2c i/o error: rc == -19 (should be 2)
[ 4250.023854] em2882/3 #0: I2C transfer timeout on writing to addr 0xc2
[ 4250.023857] xc2028 19-0061: Error on line 1299: -19

Due to that, I suspect that the logic in the driver is wrong: instead
of just returning an error if 0x10 is returned, it should be waiting for
a while and read the I2C status register again.

However, more tests are needed.

For now, instead of just returning -ENODEV, output an error message
to help debug what's happening.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index c4ff9739a7ae..9e6a11d01858 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -80,6 +80,7 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, 
u8 *buf, u16 len)
if (ret == 0x80 + len - 1) {
return len;
} else if (ret == 0x94 + len - 1) {
+   em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
return -ENODEV;
} else if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
@@ -123,6 +124,7 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
if (ret == 0x84 + len - 1) {
break;
} else if (ret == 0x94 + len - 1) {
+   em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
return -ENODEV;
} else if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
@@ -198,6 +200,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
if (ret == 0) { /* success */
return len;
} else if (ret == 0x10) {
+   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x, addr);
return -ENODEV;
} else if (ret  0) {
em28xx_warn(failed to read i2c transfer status from 
bridge (error=%i)\n,
@@ -255,6 +258,7 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf, u16 len)
}
if (ret  0) {
if (ret == 0x10) {
+   em28xx_warn(I2C transfer timeout on read from addr 
0x%02x, addr);
return -ENODEV;
} else {
em28xx_warn(unknown i2c error (status=%i)\n, ret);
@@ -316,8 +320,10 @@ static int em25xx_bus_B_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
 */
if (!ret)
return len;
-   else if (ret  0)
+   else if (ret  0) {
+   em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout, ret);
return -ENODEV;
+   }
 
return ret;
/*
@@ -367,8 +373,10 @@ static int em25xx_bus_B_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
 */
if (!ret)
return len;
-   else if (ret  0)
+   else if (ret  0) {
+   em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout, ret);
return -ENODEV;
+   }
 
return ret;
/*
-- 
1.8.3.1

--
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 v3 00/24] em28xx: split analog part into a separate module

2014-01-04 Thread Mauro Carvalho Chehab
Em Fri, 03 Jan 2014 21:29:20 +0100
Frank Schäfer fschaefer@googlemail.com escreveu:

 Am 28.12.2013 13:15, schrieb Mauro Carvalho Chehab:
  This patch series split em28xx into a separate V4L2 driver,
  allowing the new dvb-only chips to be supported without requiring
  V4L2.
 
  While testing the original patchset, I noticed several issues with
  HVR-950. The remaining patches on this series fix most of those
  issues.
 
  There's one remaining issue: on my tests, when connecting the device
  into an USB 3.0 port, the AC97 EMP202 is not properly detected. 
  Also, the audio doesn't work fine. I'm still investigating what
  would be the root cause for that.
 
  Mauro Carvalho Chehab (24):
em28xx: move some video-specific functions to em28xx-video
em28xx: some cosmetic changes
em28xx: move analog-specific init to em28xx-video
em28xx: make em28xx-video to be a separate module
em28xx: initialize analog I2C devices at the right place
em28xx-cards: remove a now dead code
em28xx: fix a cut and paste error
 
 I tried to review the core/V4L2 split patches [1-7] in detail, but it's
 nearly impossible.
 With one patch, you introduce issues which you then fix with other
 patches later.
 Patch 3 for example breaks compilation 2 times and introduces a deadlock
 and an oops...

That's actually the only patch that broke compilation. This patch was
actually generated as an intermediate step to patch 4, using git citool,
in order to make easier to review the code changes, splitting the code
move from the actual device split.

Anyway, it shouldn't break compilation.

The OOPS was fixed on a separate patch (patch 5). I opted to keep it in
separate, as it seemed interesting to preserve in git history why that
change happened. Eventually, I can reorder the patch to avoid the OOPS
to actually happen on bisect.

 Can you please rework these patches and resend them when you think they
 are ready for reviewing ?

Done. See Patch series v4.

 I've made some basic tests with the whole series applied and didn't
 observe any problems so far.

Ok. Then the better seems to apply them upstream, in order to allow
them to have a broader testing.

 Unfortunately I don't have a DVB-only device, too.

I'm acquiring two new em28xx devices. Let's hope that at least one of them
is DVB-only.

 
 Regards,
 Frank
 
em28xx: add warn messages for timeout
em28xx: improve extension information messages
em28xx: convert i2c wait completion logic to use jiffies
tvp5150: make read operations atomic
tuner-xc2028: remove unused code
em28xx: retry I2C ops if failed by timeout
em28xx: remove a false positive warning
em28xx: check if a device has audio earlier
em28xx: properly implement AC97 wait code
em28xx: initialize audio latter
em28xx: improve I2C timeout error message
em28xx: unify module version
em28xx: Fix em28xx deplock
em28xx: USB: adjust for changed 3.8 USB API
em28xx: use a better value for I2C timeouts
em28xx: don't return -ENODEV for I2C xfer errors
em28xx: cleanup I2C debug messages
 
   drivers/media/i2c/tvp5150.c  |  22 +-
   drivers/media/tuners/tuner-xc2028.c  |   9 -
   drivers/media/usb/em28xx/Kconfig |   6 +-
   drivers/media/usb/em28xx/Makefile|   5 +-
   drivers/media/usb/em28xx/em28xx-audio.c  |   9 +-
   drivers/media/usb/em28xx/em28xx-camera.c |   1 +
   drivers/media/usb/em28xx/em28xx-cards.c  | 310 ++--
   drivers/media/usb/em28xx/em28xx-core.c   | 295 +--
   drivers/media/usb/em28xx/em28xx-dvb.c|  11 +-
   drivers/media/usb/em28xx/em28xx-i2c.c| 226 ++--
   drivers/media/usb/em28xx/em28xx-input.c  |   7 +-
   drivers/media/usb/em28xx/em28xx-v4l.h|  24 ++
   drivers/media/usb/em28xx/em28xx-vbi.c|   1 +
   drivers/media/usb/em28xx/em28xx-video.c  | 607 
  +--
   drivers/media/usb/em28xx/em28xx.h|  52 +--
   15 files changed, 835 insertions(+), 750 deletions(-)
   create mode 100644 drivers/media/usb/em28xx/em28xx-v4l.h
 
 
 --
 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


-- 

Cheers,
Mauro
--
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/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/descriptors.h |2 --
 lib/libdvbv5/descriptors.c |   44 ++--
 2 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/lib/include/libdvbv5/descriptors.h 
b/lib/include/libdvbv5/descriptors.h
index 6f89aeb..36bcc61 100644
--- a/lib/include/libdvbv5/descriptors.h
+++ b/lib/include/libdvbv5/descriptors.h
@@ -78,8 +78,6 @@ void dvb_desc_default_print  (struct dvb_v5_fe_parms *parms, 
const struct dvb_de
for( _struct *_desc = (_struct *) _tbl-descriptor; _desc; _desc = 
(_struct *) _desc-next ) \
if(_desc-type == _type) \
 
-ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc);
-
 uint32_t bcd(uint32_t bcd);
 
 void hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned 
char *buf, int len);
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index a2176b4..626f81d 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -56,12 +56,11 @@
 #include libdvbv5/desc_partial_reception.h
 #include libdvbv5/desc_extension.h
 
-ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc)
+static void dvb_desc_init(uint8_t type, uint8_t length, struct dvb_desc *desc)
 {
-   desc-type   = buf[0];
-   desc-length = buf[1];
+   desc-type   = type;
+   desc-length = length;
desc-next   = NULL;
-   return 2;
 }
 
 void dvb_desc_default_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
struct dvb_desc *desc)
@@ -94,16 +93,27 @@ char *default_charset = iso-8859-1;
 char *output_charset = utf-8;
 
 void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
-  uint16_t section_length, struct dvb_desc **head_desc)
+  uint16_t buflen, struct dvb_desc **head_desc)
 {
-   const uint8_t *ptr = buf;
+   const uint8_t *ptr = buf, *endbuf = buf + buflen;
struct dvb_desc *current = NULL;
struct dvb_desc *last = NULL;
-   while (ptr  buf + section_length) {
-   unsigned desc_type = ptr[0];
-   int desc_len  = ptr[1];
+
+   *head_desc = NULL;
+
+   while (ptr + 2 = endbuf ) {
+   uint8_t desc_type = ptr[0];
+   uint8_t desc_len  = ptr[1];
size_t size;
 
+   ptr += 2; /* skip type and length */
+
+   if (ptr + desc_len  endbuf) {
+   dvb_logerr(short read of %zd/%d bytes parsing 
descriptor %#02x,
+  endbuf - ptr, desc_len, desc_type);
+   return;
+   }
+
switch (parms-verbose) {
case 0:
case 1:
@@ -119,11 +129,6 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, 
const uint8_t *buf,
hexdump(parms, content: , ptr + 2, desc_len);
}
 
-   if (desc_len  section_length - 2) {
-   dvb_logwarn(descriptor type %0x02x is too big,
-  desc_type);
-   return;
-   }
 
dvb_desc_init_func init = dvb_descriptors[desc_type].init;
if (!init) {
@@ -133,21 +138,16 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, 
const uint8_t *buf,
size = dvb_descriptors[desc_type].size;
}
if (!size) {
-   dvb_logwarn(descriptor type 0x%02x has no size 
defined, desc_type);
-   size = 4096;
-   }
-   if (ptr + 2 =  buf + section_length) {
-   dvb_logwarn(descriptor type 0x%02x is truncated: desc 
len %d, section len %zd,
-  desc_type, desc_len, section_length - (ptr - 
buf));
+   dvb_logerr(descriptor type 0x%02x has no size 
defined, desc_type);
return;
}
 
-   current = calloc(1, size);
+   current = malloc(size);
if (!current) {
dvb_perror(Out of memory);
return;
}
-   ptr += dvb_desc_init(ptr, current); /* the standard header was 
read */
+   dvb_desc_init(desc_type, desc_len, current); /* initialize the 
standard header */
init(parms, ptr, current);
if (!*head_desc)
*head_desc = current;
-- 
1.7.10.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


[PATCH 05/11] libdvbv5: fix PMT parser

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/pmt.h |6 +-
 lib/libdvbv5/descriptors/pmt.c |   22 +++---
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/lib/include/libdvbv5/pmt.h b/lib/include/libdvbv5/pmt.h
index f1b7cef..a2183ac 100644
--- a/lib/include/libdvbv5/pmt.h
+++ b/lib/include/libdvbv5/pmt.h
@@ -96,9 +96,13 @@ struct dvb_table_pmt {
uint16_t reserved3:4;
} __attribute__((packed));
} __attribute__((packed));
+   struct dvb_desc *descriptor;
struct dvb_table_pmt_stream *stream;
 } __attribute__((packed));
 
+#define dvb_pmt_field_first header
+#define dvb_pmt_field_last descriptor
+
 #define dvb_pmt_stream_foreach(_stream, _pmt) \
   for (struct dvb_table_pmt_stream *_stream = _pmt-stream; _stream; _stream = 
_stream-next) \
 
@@ -108,7 +112,7 @@ struct dvb_v5_fe_parms;
 extern C {
 #endif
 
-void dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
ssize_t buflen, uint8_t *table, ssize_t *table_length);
+void dvb_table_pmt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t *table_length);
 void dvb_table_pmt_free(struct dvb_table_pmt *pmt);
 void dvb_table_pmt_print(struct dvb_v5_fe_parms *parms, const struct 
dvb_table_pmt *pmt);
 
diff --git a/lib/libdvbv5/descriptors/pmt.c b/lib/libdvbv5/descriptors/pmt.c
index 3915414..5d42eb7 100644
--- a/lib/libdvbv5/descriptors/pmt.c
+++ b/lib/libdvbv5/descriptors/pmt.c
@@ -26,10 +26,9 @@
 #include string.h /* memcpy */
 
 void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
-   ssize_t buflen, uint8_t *table, ssize_t *table_length)
+   ssize_t buflen, struct dvb_table_pmt *pmt, ssize_t 
*table_length)
 {
const uint8_t *p = buf, *endbuf = buf + buflen - 4;
-   struct dvb_table_pmt *pmt = (void *)table;
struct dvb_table_pmt_stream **head = pmt-stream;
size_t size;
 
@@ -38,13 +37,13 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, 
const uint8_t *buf,
while (*head != NULL)
head = (*head)-next;
} else {
-   size = offsetof(struct dvb_table_pmt, stream);
+   size = offsetof(struct dvb_table_pmt, dvb_pmt_field_last);
if (p + size  endbuf) {
dvb_logerr(PMT table was truncated. Need %zu bytes, 
but has only %zu.,
size, buflen);
return;
}
-   memcpy(table, p, size);
+   memcpy(pmt, p, size);
p += size;
*table_length = sizeof(struct dvb_table_pmt);
 
@@ -52,7 +51,8 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, const 
uint8_t *buf,
bswap16(pmt-bitfield2);
pmt-stream = NULL;
 
-   /* skip prog section */
+   dvb_parse_descriptors(parms, p, pmt-prog_length,
+ pmt-descriptor);
p += pmt-prog_length;
}
 
@@ -74,15 +74,22 @@ void dvb_table_pmt_init(struct dvb_v5_fe_parms *parms, 
const uint8_t *buf,
*head = stream;
head = (*head)-next;
 
+   if (stream-section_length  endbuf - p) {
+   dvb_logerr(PMT stream section length  buffer: %zd, 
stream-section_length - (endbuf - p));
+   stream-section_length = endbuf - p;
+   }
/* get the descriptors for each program */
dvb_parse_descriptors(parms, p, stream-section_length,
  stream-descriptor);
 
p += stream-section_length;
}
-   if (endbuf - p)
-   dvb_logerr(PAT table has %zu spurious bytes at the end.,
+   if (p  endbuf)
+   dvb_logerr(PMT table has %zu spurious bytes at the end.,
   endbuf - p);
+   if (p  endbuf)
+   dvb_logerr(PMT oops  %zu ,
+  p - endbuf);
 }
 
 void dvb_table_pmt_free(struct dvb_table_pmt *pmt)
@@ -94,6 +101,7 @@ void dvb_table_pmt_free(struct dvb_table_pmt *pmt)
stream = stream-next;
free(tmp);
}
+   dvb_free_descriptors((struct dvb_desc **) pmt-descriptor);
free(pmt);
 }
 
-- 
1.7.10.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


[PATCH 03/11] libdvbv5: add parser for CAT

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/cat.h |   51 +++
 lib/libdvbv5/Makefile.am   |2 ++
 lib/libdvbv5/descriptors.c |2 ++
 lib/libdvbv5/descriptors/cat.c |   66 
 4 files changed, 121 insertions(+)
 create mode 100644 lib/include/libdvbv5/cat.h
 create mode 100644 lib/libdvbv5/descriptors/cat.c

diff --git a/lib/include/libdvbv5/cat.h b/lib/include/libdvbv5/cat.h
new file mode 100644
index 000..4c442a8
--- /dev/null
+++ b/lib/include/libdvbv5/cat.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 - Andre Roth neol...@gmail.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 version 2
+ * of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to 
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#ifndef _CAT_H
+#define _CAT_H
+
+#include stdint.h
+#include unistd.h /* ssize_t */
+
+#include libdvbv5/header.h
+
+#define DVB_TABLE_CAT  0x01
+#define DVB_TABLE_CAT_PID  0x0001
+
+struct dvb_table_cat {
+   struct dvb_table_header header;
+   struct dvb_desc *descriptor;
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+void dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
ssize_t buflen, uint8_t *table, ssize_t *table_length);
+void dvb_table_cat_free(struct dvb_table_cat *cat);
+void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat 
*t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index 8f89531..0abe42d 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -39,6 +39,7 @@ otherinclude_HEADERS = \
../include/libdvbv5/atsc_header.h \
../include/libdvbv5/mgt.h \
../include/libdvbv5/eit.h \
+   ../include/libdvbv5/cat.h \
../include/libdvbv5/atsc_eit.h \
../include/libdvbv5/desc_service_location.h \
../include/libdvbv5/mpeg_ts.h \
@@ -74,6 +75,7 @@ libdvbv5_la_SOURCES = \
descriptors/vct.c   \
descriptors/mgt.c   \
descriptors/eit.c   \
+   descriptors/cat.c   \
descriptors/atsc_eit.c  \
descriptors/desc_language.c \
descriptors/desc_network_name.c \
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index 626f81d..e888123 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -31,6 +31,7 @@
 #include libdvbv5/dvb-log.h
 
 #include libdvbv5/pat.h
+#include libdvbv5/cat.h
 #include libdvbv5/pmt.h
 #include libdvbv5/nit.h
 #include libdvbv5/sdt.h
@@ -78,6 +79,7 @@ void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, 
const struct dvb_desc
 
 const struct dvb_table_init dvb_table_initializers[] = {
[DVB_TABLE_PAT]  = { dvb_table_pat_init, sizeof(struct 
dvb_table_pat) },
+   [DVB_TABLE_CAT]  = { dvb_table_cat_init, sizeof(struct 
dvb_table_cat) },
[DVB_TABLE_PMT]  = { dvb_table_pmt_init, sizeof(struct 
dvb_table_pmt) },
[DVB_TABLE_NIT]  = { dvb_table_nit_init, sizeof(struct 
dvb_table_nit) },
[DVB_TABLE_SDT]  = { dvb_table_sdt_init, sizeof(struct 
dvb_table_sdt) },
diff --git a/lib/libdvbv5/descriptors/cat.c b/lib/libdvbv5/descriptors/cat.c
new file mode 100644
index 000..e6fc64e
--- /dev/null
+++ b/lib/libdvbv5/descriptors/cat.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 - Andre Roth neol...@gmail.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 version 2
+ * of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to 
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ */
+
+#include libdvbv5/cat.h
+#include 

[PATCH 02/11] libdvbv5: add attribute packed to structs and unions

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/atsc_header.h|2 +-
 lib/include/libdvbv5/desc_atsc_service_location.h |4 ++--
 lib/include/libdvbv5/desc_cable_delivery.h|8 
 lib/include/libdvbv5/desc_event_extended.h|4 ++--
 lib/include/libdvbv5/desc_frequency_list.h|4 ++--
 lib/include/libdvbv5/desc_isdbt_delivery.h|4 ++--
 lib/include/libdvbv5/desc_logical_channel.h   |4 ++--
 lib/include/libdvbv5/desc_sat.h   |4 ++--
 lib/include/libdvbv5/desc_service_location.h  |8 
 lib/include/libdvbv5/desc_t2_delivery.h   |4 ++--
 lib/include/libdvbv5/header.h |4 ++--
 lib/include/libdvbv5/mpeg_es.h|6 +++---
 lib/include/libdvbv5/mpeg_ts.h|2 +-
 lib/include/libdvbv5/nit.h|4 ++--
 lib/include/libdvbv5/pat.h|2 +-
 lib/include/libdvbv5/pmt.h|   16 
 lib/include/libdvbv5/sdt.h|2 +-
 lib/include/libdvbv5/vct.h|4 ++--
 18 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/lib/include/libdvbv5/atsc_header.h 
b/lib/include/libdvbv5/atsc_header.h
index 1e7148e..9685b37 100644
--- a/lib/include/libdvbv5/atsc_header.h
+++ b/lib/include/libdvbv5/atsc_header.h
@@ -36,7 +36,7 @@ struct atsc_table_header {
uint16_t priv:1;
uint16_t syntax:1;
} __attribute__((packed));
-   };
+   } __attribute__((packed));
uint16_t id;
uint8_t  current_next:1;
uint8_t  version:5;
diff --git a/lib/include/libdvbv5/desc_atsc_service_location.h 
b/lib/include/libdvbv5/desc_atsc_service_location.h
index 47113f2..1ff2341 100644
--- a/lib/include/libdvbv5/desc_atsc_service_location.h
+++ b/lib/include/libdvbv5/desc_atsc_service_location.h
@@ -32,7 +32,7 @@ struct atsc_desc_service_location_elementary {
uint16_t elementary_pid:13;
uint16_t reserved:3;
} __attribute__((packed));
-   };
+   } __attribute__((packed));
char ISO_639_language_code[3];
 } __attribute__((packed));
 
@@ -49,7 +49,7 @@ struct atsc_desc_service_location {
uint16_t pcr_pid:13;
uint16_t reserved:3;
} __attribute__((packed));
-   };
+   } __attribute__((packed));
 
uint8_t number_elements;
 } __attribute__((packed));
diff --git a/lib/include/libdvbv5/desc_cable_delivery.h 
b/lib/include/libdvbv5/desc_cable_delivery.h
index 70f5a5b..c2bab5a 100644
--- a/lib/include/libdvbv5/desc_cable_delivery.h
+++ b/lib/include/libdvbv5/desc_cable_delivery.h
@@ -37,16 +37,16 @@ struct dvb_desc_cable_delivery {
struct {
uint16_t fec_outer:4;
uint16_t reserved_future_use:12;
-   };
-   };
+   } __attribute__((packed));
+   } __attribute__((packed));
uint8_t modulation;
union {
uint32_t bitfield2;
struct {
uint32_t fec_inner:4;
uint32_t symbol_rate:28;
-   };
-   };
+   } __attribute__((packed));
+   } __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
diff --git a/lib/include/libdvbv5/desc_event_extended.h 
b/lib/include/libdvbv5/desc_event_extended.h
index a543590..03fb1f1 100644
--- a/lib/include/libdvbv5/desc_event_extended.h
+++ b/lib/include/libdvbv5/desc_event_extended.h
@@ -34,9 +34,9 @@ struct dvb_desc_event_extended {
struct {
uint8_t last_id:4;
uint8_t id:4;
-   };
+   } __attribute__((packed));
uint8_t ids;
-   };
+   } __attribute__((packed));
 
unsigned char language[4];
char *text;
diff --git a/lib/include/libdvbv5/desc_frequency_list.h 
b/lib/include/libdvbv5/desc_frequency_list.h
index e6e7945..55723c7 100644
--- a/lib/include/libdvbv5/desc_frequency_list.h
+++ b/lib/include/libdvbv5/desc_frequency_list.h
@@ -38,8 +38,8 @@ struct dvb_desc_frequency_list {
struct {
uint8_t freq_type:2;
uint8_t reserved:6;
-   };
-   };
+   } __attribute__((packed));
+   } __attribute__((packed));
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
diff --git a/lib/include/libdvbv5/desc_isdbt_delivery.h 
b/lib/include/libdvbv5/desc_isdbt_delivery.h
index 4df30df..5bac178 100644
--- a/lib/include/libdvbv5/desc_isdbt_delivery.h
+++ b/lib/include/libdvbv5/desc_isdbt_delivery.h
@@ -38,8 +38,8 @@ struct isdbt_desc_terrestrial_delivery_system {
uint16_t transmission_mode:2;
  

[PATCH 07/11] libdvbv5: use DVB_DESC_HEADER macro in all descriptors

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/desc_atsc_service_location.h |7 ++-
 lib/include/libdvbv5/desc_ca.h|7 ++-
 lib/include/libdvbv5/desc_ca_identifier.h |7 ++-
 lib/include/libdvbv5/desc_cable_delivery.h|7 ++-
 lib/include/libdvbv5/desc_event_extended.h|7 ++-
 lib/include/libdvbv5/desc_event_short.h   |7 ++-
 lib/include/libdvbv5/desc_extension.h |7 ++-
 lib/include/libdvbv5/desc_frequency_list.h|7 ++-
 lib/include/libdvbv5/desc_hierarchy.h |6 ++
 lib/include/libdvbv5/desc_isdbt_delivery.h|8 +++-
 lib/include/libdvbv5/desc_language.h  |7 ++-
 lib/include/libdvbv5/desc_logical_channel.h   |7 ++-
 lib/include/libdvbv5/desc_network_name.h  |7 ++-
 lib/include/libdvbv5/desc_partial_reception.h |7 ++-
 lib/include/libdvbv5/desc_sat.h   |7 ++-
 lib/include/libdvbv5/desc_service.h   |7 ++-
 lib/include/libdvbv5/desc_service_list.h  |7 ++-
 lib/include/libdvbv5/desc_service_location.h  |7 ++-
 lib/include/libdvbv5/desc_t2_delivery.h   |5 +++--
 lib/include/libdvbv5/desc_terrestrial_delivery.h  |7 ++-
 lib/include/libdvbv5/desc_ts_info.h   |7 ++-
 lib/include/libdvbv5/descriptors.h|9 ++---
 22 files changed, 50 insertions(+), 104 deletions(-)

diff --git a/lib/include/libdvbv5/desc_atsc_service_location.h 
b/lib/include/libdvbv5/desc_atsc_service_location.h
index 1ff2341..ebe11b7 100644
--- a/lib/include/libdvbv5/desc_atsc_service_location.h
+++ b/lib/include/libdvbv5/desc_atsc_service_location.h
@@ -21,8 +21,7 @@
 #ifndef _ATSC_SERVICE_LOCATION_H
 #define _ATSC_SERVICE_LOCATION_H
 
-#include stdint.h
-#include unistd.h /* ssize_t */
+#include libdvbv5/descriptors.h
 
 struct atsc_desc_service_location_elementary {
uint8_t stream_type;
@@ -37,9 +36,7 @@ struct atsc_desc_service_location_elementary {
 } __attribute__((packed));
 
 struct atsc_desc_service_location {
-   uint8_t type;
-   uint8_t length;
-   struct dvb_desc *next;
+   DVB_DESC_HEADER();
 
struct atsc_desc_service_location_elementary *elementary;
 
diff --git a/lib/include/libdvbv5/desc_ca.h b/lib/include/libdvbv5/desc_ca.h
index 12f4ff3..49d346b 100644
--- a/lib/include/libdvbv5/desc_ca.h
+++ b/lib/include/libdvbv5/desc_ca.h
@@ -22,13 +22,10 @@
 #ifndef _CA_H
 #define _CA_H
 
-#include stdint.h
-#include unistd.h /* ssize_t */
+#include libdvbv5/descriptors.h
 
 struct dvb_desc_ca {
-   uint8_t type;
-   uint8_t length;
-   struct dvb_desc *next;
+   DVB_DESC_HEADER();
 
uint16_t ca_id;
union {
diff --git a/lib/include/libdvbv5/desc_ca_identifier.h 
b/lib/include/libdvbv5/desc_ca_identifier.h
index 18df191..1136a84 100644
--- a/lib/include/libdvbv5/desc_ca_identifier.h
+++ b/lib/include/libdvbv5/desc_ca_identifier.h
@@ -22,13 +22,10 @@
 #ifndef _CA_IDENTIFIER_H
 #define _CA_IDENTIFIER_H
 
-#include stdint.h
-#include unistd.h /* ssize_t */
+#include libdvbv5/descriptors.h
 
 struct dvb_desc_ca_identifier {
-   uint8_t type;
-   uint8_t length;
-   struct dvb_desc *next;
+   DVB_DESC_HEADER();
 
uint8_t caid_count;
uint16_t *caids;
diff --git a/lib/include/libdvbv5/desc_cable_delivery.h 
b/lib/include/libdvbv5/desc_cable_delivery.h
index c2bab5a..25d6ab2 100644
--- a/lib/include/libdvbv5/desc_cable_delivery.h
+++ b/lib/include/libdvbv5/desc_cable_delivery.h
@@ -23,13 +23,10 @@
 #ifndef _CABLE_DELIVERY_H
 #define _CABLE_DELIVERY_H
 
-#include stdint.h
-#include unistd.h /* ssize_t */
+#include libdvbv5/descriptors.h
 
 struct dvb_desc_cable_delivery {
-   uint8_t type;
-   uint8_t length;
-   struct dvb_desc *next;
+   DVB_DESC_HEADER();
 
uint32_t frequency;
union {
diff --git a/lib/include/libdvbv5/desc_event_extended.h 
b/lib/include/libdvbv5/desc_event_extended.h
index 03fb1f1..f816a2a 100644
--- a/lib/include/libdvbv5/desc_event_extended.h
+++ b/lib/include/libdvbv5/desc_event_extended.h
@@ -22,13 +22,10 @@
 #ifndef _DESC_EVENT_EXTENDED_H
 #define _DESC_EVENT_EXTENDED_H
 
-#include stdint.h
-#include unistd.h /* ssize_t */
+#include libdvbv5/descriptors.h
 
 struct dvb_desc_event_extended {
-   uint8_t type;
-   uint8_t length;
-   struct dvb_desc *next;
+   DVB_DESC_HEADER();
 
union {
struct {
diff --git a/lib/include/libdvbv5/desc_event_short.h 
b/lib/include/libdvbv5/desc_event_short.h
index 521fbca..68c7f64 100644
--- a/lib/include/libdvbv5/desc_event_short.h
+++ b/lib/include/libdvbv5/desc_event_short.h
@@ -22,13 +22,10 @@
 #ifndef _DESC_EVENT_SHORT_H
 #define _DESC_EVENT_SHORT_H
 
-#include stdint.h
-#include unistd.h /* ssize_t */
+#include libdvbv5/descriptors.h
 
 struct 

[PATCH 04/11] libdvbv5: add parser for ca and ca_identifier descriptors

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/desc_ca.h|   63 
 lib/include/libdvbv5/desc_ca_identifier.h |   55 +
 lib/libdvbv5/Makefile.am  |   10 ++--
 lib/libdvbv5/descriptors.c|   18 +++
 lib/libdvbv5/descriptors/desc_ca.c|   64 +
 lib/libdvbv5/descriptors/desc_ca_identifier.c |   58 ++
 6 files changed, 257 insertions(+), 11 deletions(-)
 create mode 100644 lib/include/libdvbv5/desc_ca.h
 create mode 100644 lib/include/libdvbv5/desc_ca_identifier.h
 create mode 100644 lib/libdvbv5/descriptors/desc_ca.c
 create mode 100644 lib/libdvbv5/descriptors/desc_ca_identifier.c

diff --git a/lib/include/libdvbv5/desc_ca.h b/lib/include/libdvbv5/desc_ca.h
new file mode 100644
index 000..12f4ff3
--- /dev/null
+++ b/lib/include/libdvbv5/desc_ca.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 - Andre Roth neol...@gmail.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 version 2
+ * of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to 
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Described at ETSI EN 300 468 V1.11.1 (2010-04)
+ */
+
+#ifndef _CA_H
+#define _CA_H
+
+#include stdint.h
+#include unistd.h /* ssize_t */
+
+struct dvb_desc_ca {
+   uint8_t type;
+   uint8_t length;
+   struct dvb_desc *next;
+
+   uint16_t ca_id;
+   union {
+   uint16_t bitfield1;
+   struct {
+   uint16_t ca_pid:13;
+   uint16_t reserved:3;
+   } __attribute__((packed));
+   } __attribute__((packed));
+
+   uint8_t *privdata;
+   uint8_t privdata_len;
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#define dvb_desc_ca_field_first ca_id
+#define dvb_desc_ca_field_last  privdata
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+void dvb_desc_ca_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
struct dvb_desc *desc);
+void dvb_desc_ca_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc 
*desc);
+void dvb_desc_ca_free (struct dvb_desc *desc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/include/libdvbv5/desc_ca_identifier.h 
b/lib/include/libdvbv5/desc_ca_identifier.h
new file mode 100644
index 000..18df191
--- /dev/null
+++ b/lib/include/libdvbv5/desc_ca_identifier.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013 - Andre Roth neol...@gmail.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 version 2
+ * of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to 
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Described at ETSI EN 300 468 V1.11.1 (2010-04)
+ */
+
+#ifndef _CA_IDENTIFIER_H
+#define _CA_IDENTIFIER_H
+
+#include stdint.h
+#include unistd.h /* ssize_t */
+
+struct dvb_desc_ca_identifier {
+   uint8_t type;
+   uint8_t length;
+   struct dvb_desc *next;
+
+   uint8_t caid_count;
+   uint16_t *caids;
+
+} __attribute__((packed));
+
+struct dvb_v5_fe_parms;
+
+#define dvb_desc_ca_identifier_field_first ca_id
+#define dvb_desc_ca_identifier_field_last  privdata
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+void dvb_desc_ca_identifier_init (struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc);
+void dvb_desc_ca_identifier_print(struct dvb_v5_fe_parms *parms, const struct 
dvb_desc *desc);
+void dvb_desc_ca_identifier_free (struct dvb_desc *desc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am
index 0abe42d..667a1af 100644
--- a/lib/libdvbv5/Makefile.am
+++ b/lib/libdvbv5/Makefile.am
@@ -33,6 +33,9 @@ otherinclude_HEADERS = \
../include/libdvbv5/desc_logical_channel.h \

[PATCH 06/11] libdvbv5: cleanup printing tables and descriptors

2014-01-04 Thread André Roth
- log hex values where appropriate
- cleanup indents

Signed-off-by: André Roth neol...@gmail.com
---
 lib/libdvbv5/descriptors.c|4 ++--
 lib/libdvbv5/descriptors/cat.c|2 +-
 lib/libdvbv5/descriptors/desc_atsc_service_location.c |1 -
 lib/libdvbv5/descriptors/desc_ca.c|4 ++--
 lib/libdvbv5/descriptors/desc_ca_identifier.c |2 +-
 lib/libdvbv5/descriptors/desc_cable_delivery.c|1 -
 lib/libdvbv5/descriptors/desc_event_extended.c|2 +-
 lib/libdvbv5/descriptors/desc_event_short.c   |6 +++---
 lib/libdvbv5/descriptors/desc_extension.c |2 +-
 lib/libdvbv5/descriptors/desc_frequency_list.c|4 ++--
 lib/libdvbv5/descriptors/desc_hierarchy.c |1 -
 lib/libdvbv5/descriptors/desc_isdbt_delivery.c|1 -
 lib/libdvbv5/descriptors/desc_language.c  |2 +-
 lib/libdvbv5/descriptors/desc_service.c   |7 +++
 lib/libdvbv5/descriptors/desc_t2_delivery.c   |1 -
 lib/libdvbv5/descriptors/desc_terrestrial_delivery.c  |1 -
 lib/libdvbv5/descriptors/desc_ts_info.c   |1 -
 lib/libdvbv5/descriptors/mpeg_pes.c   |   10 +-
 lib/libdvbv5/descriptors/mpeg_ts.c|6 +++---
 lib/libdvbv5/descriptors/nit.c|2 +-
 lib/libdvbv5/descriptors/pat.c|4 ++--
 lib/libdvbv5/descriptors/pmt.c|7 ---
 lib/libdvbv5/descriptors/sdt.c|6 +++---
 23 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index 93239e6..4bf9d59 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -75,8 +75,7 @@ void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, 
const struct dvb_desc
 {
if (!parms)
parms = dvb_fe_dummy();
-   dvb_log(|   %s (%#02x), 
dvb_descriptors[desc-type].name, desc-type);
-   hexdump(parms, |   , desc-data, desc-length);
+   hexdump(parms, |   , desc-data, desc-length);
 }
 
 const struct dvb_table_init dvb_table_initializers[] = {
@@ -168,6 +167,7 @@ void dvb_print_descriptors(struct dvb_v5_fe_parms *parms, 
struct dvb_desc *desc)
dvb_desc_print_func print = dvb_descriptors[desc-type].print;
if (!print)
print = dvb_desc_default_print;
+   dvb_log(|0x%02x: %s, desc-type, 
dvb_descriptors[desc-type].name);
print(parms, desc);
desc = desc-next;
}
diff --git a/lib/libdvbv5/descriptors/cat.c b/lib/libdvbv5/descriptors/cat.c
index e6fc64e..82da031 100644
--- a/lib/libdvbv5/descriptors/cat.c
+++ b/lib/libdvbv5/descriptors/cat.c
@@ -59,7 +59,7 @@ void dvb_table_cat_free(struct dvb_table_cat *cat)
 
 void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat 
*cat)
 {
-   dvb_log(cat);
+   dvb_log(CAT);
dvb_table_header_print(parms, cat-header);
dvb_print_descriptors(parms, cat-descriptor);
 }
diff --git a/lib/libdvbv5/descriptors/desc_atsc_service_location.c 
b/lib/libdvbv5/descriptors/desc_atsc_service_location.c
index 5e3f461..6da43b6 100644
--- a/lib/libdvbv5/descriptors/desc_atsc_service_location.c
+++ b/lib/libdvbv5/descriptors/desc_atsc_service_location.c
@@ -64,7 +64,6 @@ void atsc_desc_service_location_print(struct dvb_v5_fe_parms 
*parms, const struc
struct atsc_desc_service_location_elementary *el = s_loc-elementary;
int i;
 
-   dvb_log(|   service location);
dvb_log(|   pcr PID   %d, s_loc-pcr_pid);
dvb_log(|\\ elementary service - %d elementaries, 
s_loc-number_elements);
for (i = 0; i  s_loc-number_elements; i++) {
diff --git a/lib/libdvbv5/descriptors/desc_ca.c 
b/lib/libdvbv5/descriptors/desc_ca.c
index 6b48175..40edfde 100644
--- a/lib/libdvbv5/descriptors/desc_ca.c
+++ b/lib/libdvbv5/descriptors/desc_ca.c
@@ -48,8 +48,8 @@ void dvb_desc_ca_init(struct dvb_v5_fe_parms *parms, const 
uint8_t *buf, struct
 void dvb_desc_ca_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc 
*desc)
 {
const struct dvb_desc_ca *d = (const struct dvb_desc_ca *) desc;
-   dvb_log(|   ca_id %04x, d-ca_id);
-   dvb_log(|   ca_pid%04x, d-ca_pid);
+   dvb_log(|   ca_id 0x%04x, d-ca_id);
+   dvb_log(|   ca_pid0x%04x, d-ca_pid);
dvb_log(|   privdata length   %d, d-privdata_len);
if (d-privdata)
hexdump(parms, |   privdata  , d-privdata, 
d-privdata_len);
diff --git a/lib/libdvbv5/descriptors/desc_ca_identifier.c 
b/lib/libdvbv5/descriptors/desc_ca_identifier.c
index 4740a01..95e0569 100644
--- 

[PATCH 11/11] libdvbv5: remove unneeded includes

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/libdvbv5/descriptors/desc_atsc_service_location.c |1 -
 lib/libdvbv5/descriptors/desc_ca.c|1 -
 lib/libdvbv5/descriptors/desc_ca_identifier.c |1 -
 lib/libdvbv5/descriptors/desc_cable_delivery.c|1 -
 lib/libdvbv5/descriptors/desc_event_extended.c|1 -
 lib/libdvbv5/descriptors/desc_event_short.c   |1 -
 lib/libdvbv5/descriptors/desc_extension.c |1 -
 lib/libdvbv5/descriptors/desc_frequency_list.c|1 -
 lib/libdvbv5/descriptors/desc_hierarchy.c |1 -
 lib/libdvbv5/descriptors/desc_isdbt_delivery.c|1 -
 lib/libdvbv5/descriptors/desc_language.c  |1 -
 lib/libdvbv5/descriptors/desc_logical_channel.c   |1 -
 lib/libdvbv5/descriptors/desc_network_name.c  |1 -
 lib/libdvbv5/descriptors/desc_partial_reception.c |1 -
 lib/libdvbv5/descriptors/desc_sat.c   |1 -
 lib/libdvbv5/descriptors/desc_service.c   |1 -
 lib/libdvbv5/descriptors/desc_service_list.c  |1 -
 lib/libdvbv5/descriptors/desc_service_location.c  |1 -
 lib/libdvbv5/descriptors/desc_t2_delivery.c   |1 -
 lib/libdvbv5/descriptors/desc_terrestrial_delivery.c  |1 -
 lib/libdvbv5/descriptors/desc_ts_info.c   |1 -
 21 files changed, 21 deletions(-)

diff --git a/lib/libdvbv5/descriptors/desc_atsc_service_location.c 
b/lib/libdvbv5/descriptors/desc_atsc_service_location.c
index d47eee0..a654adc 100644
--- a/lib/libdvbv5/descriptors/desc_atsc_service_location.c
+++ b/lib/libdvbv5/descriptors/desc_atsc_service_location.c
@@ -18,7 +18,6 @@
  *
  */
 
-#include libdvbv5/descriptors.h
 #include libdvbv5/desc_atsc_service_location.h
 #include libdvbv5/dvb-fe.h
 
diff --git a/lib/libdvbv5/descriptors/desc_ca.c 
b/lib/libdvbv5/descriptors/desc_ca.c
index 01d3b8c..791bda2 100644
--- a/lib/libdvbv5/descriptors/desc_ca.c
+++ b/lib/libdvbv5/descriptors/desc_ca.c
@@ -20,7 +20,6 @@
  */
 
 #include libdvbv5/desc_ca.h
-#include libdvbv5/descriptors.h
 #include libdvbv5/dvb-fe.h
 
 int dvb_desc_ca_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct 
dvb_desc *desc)
diff --git a/lib/libdvbv5/descriptors/desc_ca_identifier.c 
b/lib/libdvbv5/descriptors/desc_ca_identifier.c
index c986ac7..3102d01 100644
--- a/lib/libdvbv5/descriptors/desc_ca_identifier.c
+++ b/lib/libdvbv5/descriptors/desc_ca_identifier.c
@@ -20,7 +20,6 @@
  */
 
 #include libdvbv5/desc_ca_identifier.h
-#include libdvbv5/descriptors.h
 #include libdvbv5/dvb-fe.h
 
 int dvb_desc_ca_identifier_init(struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc)
diff --git a/lib/libdvbv5/descriptors/desc_cable_delivery.c 
b/lib/libdvbv5/descriptors/desc_cable_delivery.c
index 5263a56..0b599e6 100644
--- a/lib/libdvbv5/descriptors/desc_cable_delivery.c
+++ b/lib/libdvbv5/descriptors/desc_cable_delivery.c
@@ -21,7 +21,6 @@
  */
 
 #include libdvbv5/desc_cable_delivery.h
-#include libdvbv5/descriptors.h
 #include libdvbv5/dvb-fe.h
 
 int dvb_desc_cable_delivery_init(struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc)
diff --git a/lib/libdvbv5/descriptors/desc_event_extended.c 
b/lib/libdvbv5/descriptors/desc_event_extended.c
index 6689aa2..de20d06 100644
--- a/lib/libdvbv5/descriptors/desc_event_extended.c
+++ b/lib/libdvbv5/descriptors/desc_event_extended.c
@@ -20,7 +20,6 @@
  */
 
 #include libdvbv5/desc_event_extended.h
-#include libdvbv5/descriptors.h
 #include libdvbv5/dvb-fe.h
 #include parse_string.h
 
diff --git a/lib/libdvbv5/descriptors/desc_event_short.c 
b/lib/libdvbv5/descriptors/desc_event_short.c
index a4fb2d0..c4f5efe 100644
--- a/lib/libdvbv5/descriptors/desc_event_short.c
+++ b/lib/libdvbv5/descriptors/desc_event_short.c
@@ -20,7 +20,6 @@
  */
 
 #include libdvbv5/desc_event_short.h
-#include libdvbv5/descriptors.h
 #include libdvbv5/dvb-fe.h
 #include parse_string.h
 
diff --git a/lib/libdvbv5/descriptors/desc_extension.c 
b/lib/libdvbv5/descriptors/desc_extension.c
index 91748bb..0aaeba8 100644
--- a/lib/libdvbv5/descriptors/desc_extension.c
+++ b/lib/libdvbv5/descriptors/desc_extension.c
@@ -18,7 +18,6 @@
  *
  */
 
-#include libdvbv5/descriptors.h
 #include libdvbv5/desc_extension.h
 #include libdvbv5/desc_t2_delivery.h
 #include libdvbv5/dvb-fe.h
diff --git a/lib/libdvbv5/descriptors/desc_frequency_list.c 
b/lib/libdvbv5/descriptors/desc_frequency_list.c
index e1183b9..1ee563c 100644
--- a/lib/libdvbv5/descriptors/desc_frequency_list.c
+++ b/lib/libdvbv5/descriptors/desc_frequency_list.c
@@ -20,7 +20,6 @@
  */
 
 #include libdvbv5/desc_frequency_list.h
-#include libdvbv5/descriptors.h
 #include libdvbv5/dvb-fe.h
 
 int dvb_desc_frequency_list_init(struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc)
diff --git a/lib/libdvbv5/descriptors/desc_hierarchy.c 
b/lib/libdvbv5/descriptors/desc_hierarchy.c
index 0f7675c..a85c8da 

[PATCH 08/11] libdvbv5: make dvb_desc_default_init and dvb_desc_default_print private

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/descriptors.h |   16 
 lib/libdvbv5/descriptors.c |4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/include/libdvbv5/descriptors.h 
b/lib/include/libdvbv5/descriptors.h
index ae33fda..d5feb4f 100644
--- a/lib/include/libdvbv5/descriptors.h
+++ b/lib/include/libdvbv5/descriptors.h
@@ -65,14 +65,6 @@ struct dvb_desc {
uint8_t data[];
 } __attribute__((packed));
 
-void dvb_desc_default_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
struct dvb_desc *desc);
-#ifdef __cplusplus
-extern C {
-#endif
-void dvb_desc_default_print  (struct dvb_v5_fe_parms *parms, const struct 
dvb_desc *desc);
-#ifdef __cplusplus
-}
-#endif
 
 #define dvb_desc_foreach( _desc, _tbl ) \
for( struct dvb_desc *_desc = _tbl-descriptor; _desc; _desc = 
_desc-next ) \
@@ -81,6 +73,10 @@ void dvb_desc_default_print  (struct dvb_v5_fe_parms *parms, 
const struct dvb_de
for( _struct *_desc = (_struct *) _tbl-descriptor; _desc; _desc = 
(_struct *) _desc-next ) \
if(_desc-type == _type) \
 
+#ifdef __cplusplus
+extern C {
+#endif
+
 uint32_t bcd(uint32_t bcd);
 
 void hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned 
char *buf, int len);
@@ -89,6 +85,10 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, 
const uint8_t *buf, ui
 void dvb_free_descriptors(struct dvb_desc **list);
 void dvb_print_descriptors(struct dvb_v5_fe_parms *parms, struct dvb_desc 
*desc);
 
+#ifdef __cplusplus
+}
+#endif
+
 struct dvb_v5_fe_parms;
 
 typedef void (*dvb_desc_init_func) (struct dvb_v5_fe_parms *parms, const 
uint8_t *buf, struct dvb_desc *desc);
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index 4bf9d59..48f3fe7 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -66,12 +66,12 @@ static void dvb_desc_init(uint8_t type, uint8_t length, 
struct dvb_desc *desc)
desc-next   = NULL;
 }
 
-void dvb_desc_default_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
struct dvb_desc *desc)
+static void dvb_desc_default_init(struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc)
 {
memcpy(desc-data, buf, desc-length);
 }
 
-void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, const struct 
dvb_desc *desc)
+static void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, const struct 
dvb_desc *desc)
 {
if (!parms)
parms = dvb_fe_dummy();
-- 
1.7.10.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


[PATCH 10/11] libdvbv5: descriptor parser return int

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/desc_atsc_service_location.h |2 +-
 lib/include/libdvbv5/desc_ca.h|2 +-
 lib/include/libdvbv5/desc_ca_identifier.h |2 +-
 lib/include/libdvbv5/desc_cable_delivery.h|2 +-
 lib/include/libdvbv5/desc_event_extended.h|2 +-
 lib/include/libdvbv5/desc_event_short.h   |2 +-
 lib/include/libdvbv5/desc_extension.h |4 ++--
 lib/include/libdvbv5/desc_frequency_list.h|2 +-
 lib/include/libdvbv5/desc_hierarchy.h |2 +-
 lib/include/libdvbv5/desc_isdbt_delivery.h|2 +-
 lib/include/libdvbv5/desc_language.h  |2 +-
 lib/include/libdvbv5/desc_logical_channel.h   |2 +-
 lib/include/libdvbv5/desc_network_name.h  |2 +-
 lib/include/libdvbv5/desc_partial_reception.h |2 +-
 lib/include/libdvbv5/desc_sat.h   |2 +-
 lib/include/libdvbv5/desc_service.h   |2 +-
 lib/include/libdvbv5/desc_service_list.h  |2 +-
 lib/include/libdvbv5/desc_service_location.h  |2 +-
 lib/include/libdvbv5/desc_t2_delivery.h   |2 +-
 lib/include/libdvbv5/desc_terrestrial_delivery.h  |2 +-
 lib/include/libdvbv5/desc_ts_info.h   |2 +-
 lib/include/libdvbv5/descriptors.h|4 ++--
 lib/libdvbv5/descriptors.c|   16 ++--
 lib/libdvbv5/descriptors/desc_atsc_service_location.c |5 +++--
 lib/libdvbv5/descriptors/desc_ca.c|3 ++-
 lib/libdvbv5/descriptors/desc_ca_identifier.c |5 +++--
 lib/libdvbv5/descriptors/desc_cable_delivery.c|3 ++-
 lib/libdvbv5/descriptors/desc_event_extended.c|3 ++-
 lib/libdvbv5/descriptors/desc_event_short.c   |3 ++-
 lib/libdvbv5/descriptors/desc_extension.c |9 ++---
 lib/libdvbv5/descriptors/desc_frequency_list.c|3 ++-
 lib/libdvbv5/descriptors/desc_hierarchy.c |3 ++-
 lib/libdvbv5/descriptors/desc_isdbt_delivery.c|7 ---
 lib/libdvbv5/descriptors/desc_language.c  |3 ++-
 lib/libdvbv5/descriptors/desc_logical_channel.c   |5 +++--
 lib/libdvbv5/descriptors/desc_network_name.c  |3 ++-
 lib/libdvbv5/descriptors/desc_partial_reception.c |5 +++--
 lib/libdvbv5/descriptors/desc_sat.c   |4 +++-
 lib/libdvbv5/descriptors/desc_service.c   |3 ++-
 lib/libdvbv5/descriptors/desc_service_list.c  |3 ++-
 lib/libdvbv5/descriptors/desc_service_location.c  |3 ++-
 lib/libdvbv5/descriptors/desc_t2_delivery.c   |   11 ++-
 lib/libdvbv5/descriptors/desc_terrestrial_delivery.c  |3 ++-
 lib/libdvbv5/descriptors/desc_ts_info.c   |3 ++-
 44 files changed, 91 insertions(+), 63 deletions(-)

diff --git a/lib/include/libdvbv5/desc_atsc_service_location.h 
b/lib/include/libdvbv5/desc_atsc_service_location.h
index ebe11b7..310efa3 100644
--- a/lib/include/libdvbv5/desc_atsc_service_location.h
+++ b/lib/include/libdvbv5/desc_atsc_service_location.h
@@ -57,7 +57,7 @@ struct dvb_v5_fe_parms;
 extern C {
 #endif
 
-void atsc_desc_service_location_init (struct dvb_v5_fe_parms *parms, const 
uint8_t *buf, struct dvb_desc *desc);
+int atsc_desc_service_location_init (struct dvb_v5_fe_parms *parms, const 
uint8_t *buf, struct dvb_desc *desc);
 void atsc_desc_service_location_print(struct dvb_v5_fe_parms *parms, const 
struct dvb_desc *desc);
 void atsc_desc_service_location_free(struct dvb_desc *desc);
 
diff --git a/lib/include/libdvbv5/desc_ca.h b/lib/include/libdvbv5/desc_ca.h
index 49d346b..34723d7 100644
--- a/lib/include/libdvbv5/desc_ca.h
+++ b/lib/include/libdvbv5/desc_ca.h
@@ -49,7 +49,7 @@ struct dvb_v5_fe_parms;
 extern C {
 #endif
 
-void dvb_desc_ca_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
struct dvb_desc *desc);
+int dvb_desc_ca_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, 
struct dvb_desc *desc);
 void dvb_desc_ca_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc 
*desc);
 void dvb_desc_ca_free (struct dvb_desc *desc);
 
diff --git a/lib/include/libdvbv5/desc_ca_identifier.h 
b/lib/include/libdvbv5/desc_ca_identifier.h
index 1136a84..a4b8537 100644
--- a/lib/include/libdvbv5/desc_ca_identifier.h
+++ b/lib/include/libdvbv5/desc_ca_identifier.h
@@ -41,7 +41,7 @@ struct dvb_v5_fe_parms;
 extern C {
 #endif
 
-void dvb_desc_ca_identifier_init (struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc);
+int dvb_desc_ca_identifier_init (struct dvb_v5_fe_parms *parms, const uint8_t 
*buf, struct dvb_desc *desc);
 void dvb_desc_ca_identifier_print(struct dvb_v5_fe_parms *parms, const struct 
dvb_desc *desc);
 void dvb_desc_ca_identifier_free (struct dvb_desc *desc);
 
diff 

[PATCH 09/11] libdvbv5: use TABLE_INIT macro

2014-01-04 Thread André Roth
Signed-off-by: André Roth neol...@gmail.com
---
 lib/include/libdvbv5/descriptors.h |2 +-
 lib/libdvbv5/descriptors.c |   24 +---
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/include/libdvbv5/descriptors.h 
b/lib/include/libdvbv5/descriptors.h
index d5feb4f..bc80940 100644
--- a/lib/include/libdvbv5/descriptors.h
+++ b/lib/include/libdvbv5/descriptors.h
@@ -35,7 +35,7 @@
 
 struct dvb_v5_fe_parms;
 
-typedef void (*dvb_table_init_func)(struct dvb_v5_fe_parms *parms, const 
uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length);
+typedef void (*dvb_table_init_func)(struct dvb_v5_fe_parms *parms, const 
uint8_t *buf, ssize_t buflen, void *table, ssize_t *table_length);
 
 struct dvb_table_init {
dvb_table_init_func init;
diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
index 48f3fe7..c7d535c 100644
--- a/lib/libdvbv5/descriptors.c
+++ b/lib/libdvbv5/descriptors.c
@@ -78,18 +78,20 @@ static void dvb_desc_default_print(struct dvb_v5_fe_parms 
*parms, const struct d
hexdump(parms, |   , desc-data, desc-length);
 }
 
+#define TABLE_INIT( _x ) { (dvb_table_init_func) _x##_init, sizeof(struct _x) }
+
 const struct dvb_table_init dvb_table_initializers[] = {
-   [DVB_TABLE_PAT]  = { dvb_table_pat_init, sizeof(struct 
dvb_table_pat) },
-   [DVB_TABLE_CAT]  = { dvb_table_cat_init, sizeof(struct 
dvb_table_cat) },
-   [DVB_TABLE_PMT]  = { dvb_table_pmt_init, sizeof(struct 
dvb_table_pmt) },
-   [DVB_TABLE_NIT]  = { dvb_table_nit_init, sizeof(struct 
dvb_table_nit) },
-   [DVB_TABLE_SDT]  = { dvb_table_sdt_init, sizeof(struct 
dvb_table_sdt) },
-   [DVB_TABLE_EIT]  = { dvb_table_eit_init, sizeof(struct 
dvb_table_eit) },
-   [DVB_TABLE_EIT_SCHEDULE] = { dvb_table_eit_init, sizeof(struct 
dvb_table_eit) },
-   [ATSC_TABLE_MGT] = { atsc_table_mgt_init, sizeof(struct 
atsc_table_mgt) },
-   [ATSC_TABLE_EIT] = { atsc_table_eit_init, sizeof(struct 
atsc_table_eit) },
-   [ATSC_TABLE_TVCT]= { atsc_table_vct_init, sizeof(struct 
atsc_table_vct) },
-   [ATSC_TABLE_CVCT]= { atsc_table_vct_init, sizeof(struct 
atsc_table_vct) },
+   [DVB_TABLE_PAT]  = TABLE_INIT(dvb_table_pat),
+   [DVB_TABLE_CAT]  = TABLE_INIT(dvb_table_cat),
+   [DVB_TABLE_PMT]  = TABLE_INIT(dvb_table_pmt),
+   [DVB_TABLE_NIT]  = TABLE_INIT(dvb_table_nit),
+   [DVB_TABLE_SDT]  = TABLE_INIT(dvb_table_sdt),
+   [DVB_TABLE_EIT]  = TABLE_INIT(dvb_table_eit),
+   [DVB_TABLE_EIT_SCHEDULE] = TABLE_INIT(dvb_table_eit),
+   [ATSC_TABLE_MGT] = TABLE_INIT(atsc_table_mgt),
+   [ATSC_TABLE_EIT] = TABLE_INIT(atsc_table_eit),
+   [ATSC_TABLE_TVCT]= TABLE_INIT(atsc_table_vct),
+   [ATSC_TABLE_CVCT]= TABLE_INIT(atsc_table_vct),
 };
 
 char *default_charset = iso-8859-1;
-- 
1.7.10.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


[PATCH v4 19/22] [media] em28xx: cleanup I2C debug messages

2014-01-04 Thread Mauro Carvalho Chehab
The I2C output messages is too polluted. Clean it a little
bit, by:
- use the proper core support for memory dumps;
- hide most stuff under the i2c_debug umbrella;
- add the missing KERN_CONT where needed;
- use 2 levels or verbosity. Only the second one
  will show the I2C transfer data.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 94 +++
 1 file changed, 50 insertions(+), 44 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index c3ba8ace5c94..e030e0b7d645 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -41,7 +41,7 @@ MODULE_PARM_DESC(i2c_scan, scan i2c bus at insmod time);
 
 static unsigned int i2c_debug;
 module_param(i2c_debug, int, 0644);
-MODULE_PARM_DESC(i2c_debug, enable debug messages [i2c]);
+MODULE_PARM_DESC(i2c_debug, i2c debug message level (1: normal debug, 2: show 
I2C transfers));
 
 /*
  * em2800_i2c_send_bytes()
@@ -80,7 +80,9 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, 
u8 *buf, u16 len)
if (ret == 0x80 + len - 1)
return len;
if (ret == 0x94 + len - 1) {
-   em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
+   if (i2c_debug)
+   em28xx_warn(R05 returned 0x%02x: I2C timeout,
+   ret);
return -EREMOTEIO;
}
if (ret  0) {
@@ -90,7 +92,8 @@ static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, 
u8 *buf, u16 len)
}
msleep(5);
}
-   em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
+   if (i2c_debug)
+   em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
return -EREMOTEIO;
 }
 
@@ -124,7 +127,9 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
if (ret == 0x84 + len - 1)
break;
if (ret == 0x94 + len - 1) {
-   em28xx_warn(R05 returned 0x%02x: I2C timeout, ret);
+   if (i2c_debug)
+   em28xx_warn(R05 returned 0x%02x: I2C timeout,
+   ret);
return -EREMOTEIO;
}
if (ret  0) {
@@ -134,8 +139,11 @@ static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 
addr, u8 *buf, u16 len)
}
msleep(5);
}
-   if (ret != 0x84 + len - 1)
-   em28xx_warn(read from i2c device at 0x%x timed out\n, addr);
+   if (ret != 0x84 + len - 1) {
+   if (i2c_debug)
+   em28xx_warn(read from i2c device at 0x%x timed out\n,
+   addr);
+   }
 
/* get the received message */
ret = dev-em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len);
@@ -218,7 +226,8 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
 */
}
 
-   em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
+   if (i2c_debug)
+   em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
return -EREMOTEIO;
 }
 
@@ -263,7 +272,9 @@ static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf, u16 len)
return ret;
}
if (ret == 0x10) {
-   em28xx_warn(I2C transfer timeout on read from addr 0x%02x, 
addr);
+   if (i2c_debug)
+   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x,
+   addr);
return -EREMOTEIO;
}
 
@@ -324,7 +335,9 @@ static int em25xx_bus_B_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
if (!ret)
return len;
else if (ret  0) {
-   em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout, ret);
+   if (i2c_debug)
+   em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout,
+   ret);
return -EREMOTEIO;
}
 
@@ -375,7 +388,9 @@ static int em25xx_bus_B_recv_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
if (!ret)
return len;
else if (ret  0) {
-   em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout, ret);
+   if (i2c_debug)
+   em28xx_warn(Bus B R08 returned 0x%02x: I2C timeout,
+   ret);
return -EREMOTEIO;
}
 
@@ -418,10 +433,6 @@ static inline int i2c_check_for_device(struct 
em28xx_i2c_bus *i2c_bus, u16 addr)
rc = em2800_i2c_check_for_device(dev, addr);
else if (i2c_bus-algo_type == 

[PATCH v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout

2014-01-04 Thread Mauro Carvalho Chehab
At least on HVR-950, sometimes an I2C operation fails.

This seems to be more frequent when the device is connected
into an USB 3.0 port.

Instead of report an error, try to repeat it, for up to
20 ms. That makes the code more reliable.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index 6cd3d909bb3a..35d6808aa9ff 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -189,6 +189,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
 * Zero length reads always succeed, even if no device is connected
 */
 
+retry:
/* Write to i2c device */
ret = dev-em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
if (ret != len) {
@@ -208,26 +209,24 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
addr, u8 *buf,
ret = dev-em28xx_read_reg(dev, 0x05);
if (ret == 0) /* success */
return len;
-   if (ret == 0x10) {
-   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x,
-   addr);
-   return -EREMOTEIO;
-   }
+   if (ret == 0x10)
+   goto retry;
if (ret  0) {
em28xx_warn(failed to get i2c transfer status from 
bridge register (error=%i)\n,
ret);
return ret;
}
msleep(5);
-   /*
-* NOTE: do we really have to wait for success ?
-* Never seen anything else than 0x00 or 0x10
-* (even with high payload) ...
-*/
}
 
-   if (i2c_debug)
-   em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
+   if (ret == 0x10) {
+   if (i2c_debug)
+   em28xx_warn(I2C transfer timeout on writing to addr 
0x%02x,
+   addr);
+   } else {
+   em28xx_warn(write to i2c device at 0x%x timed out 
(ret=0x%02x)\n,
+   addr, ret);
+   }
return -EREMOTEIO;
 }
 
-- 
1.8.3.1

--
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 v4 RFC 2/2] [media] em28xx: USB: adjust for changed 3.8 USB API

2014-01-04 Thread Mauro Carvalho Chehab
The recent changes in the USB API (implement new semantics for
URB_ISO_ASAP) made the former meaning of the URB_ISO_ASAP flag the
default, and changed this flag to mean that URBs can be delayed.
This is not the behaviour wanted by any of the audio drivers because
it leads to discontinuous playback with very small period sizes.
Therefore, our URBs need to be submitted without this flag.

This patch implements the same fix as found at snd-usb-audio driver
(commit c75c5ab575af7db707689cdbb5a5c458e9a034bb)

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-audio.c | 2 +-
 drivers/media/usb/em28xx/em28xx-core.c  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index 30ee389a07f0..084ccb8bbab6 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -705,7 +705,7 @@ static int em28xx_audio_init(struct em28xx *dev)
urb-dev = dev-udev;
urb-context = dev;
urb-pipe = usb_rcvisocpipe(dev-udev, EM28XX_EP_AUDIO);
-   urb-transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+   urb-transfer_flags = URB_NO_TRANSFER_DMA_MAP;
urb-transfer_buffer = dev-adev.transfer_buffer[i];
urb-interval = 1;
urb-complete = em28xx_audio_isocirq;
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 97cc83c3c287..3fae119fc064 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -953,8 +953,7 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode 
mode, int xfer_bulk,
usb_fill_int_urb(urb, dev-udev, pipe,
 usb_bufs-transfer_buffer[i], sb_size,
 em28xx_irq_callback, dev, 1);
-   urb-transfer_flags = URB_ISO_ASAP |
- URB_NO_TRANSFER_DMA_MAP;
+   urb-transfer_flags = URB_NO_TRANSFER_DMA_MAP;
k = 0;
for (j = 0; j  usb_bufs-num_packets; j++) {
urb-iso_frame_desc[j].offset = k;
-- 
1.8.3.1

--
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 v4 14/22] [media] em28xx: unify module version

2014-01-04 Thread Mauro Carvalho Chehab
Use the same module version on all em28xx sub-modules, and use
the same naming convention to describe the driver.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-audio.c | 3 ++-
 drivers/media/usb/em28xx/em28xx-core.c  | 2 --
 drivers/media/usb/em28xx/em28xx-dvb.c   | 4 +++-
 drivers/media/usb/em28xx/em28xx-input.c | 3 ++-
 drivers/media/usb/em28xx/em28xx-video.c | 4 +---
 drivers/media/usb/em28xx/em28xx.h   | 1 +
 6 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c 
b/drivers/media/usb/em28xx/em28xx-audio.c
index 263886adcf26..a6eef06ffdcd 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -747,7 +747,8 @@ static void __exit em28xx_alsa_unregister(void)
 MODULE_LICENSE(GPL);
 MODULE_AUTHOR(Markus Rechberger mrechber...@gmail.com);
 MODULE_AUTHOR(Mauro Carvalho Chehab mche...@redhat.com);
-MODULE_DESCRIPTION(Em28xx Audio driver);
+MODULE_DESCRIPTION(DRIVER_DESC  - audio interface);
+MODULE_VERSION(EM28XX_VERSION);
 
 module_init(em28xx_alsa_register);
 module_exit(em28xx_alsa_unregister);
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 36b2f1ab4474..2ad84ff1fc4f 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -39,8 +39,6 @@
  Mauro Carvalho Chehab mche...@infradead.org,  \
  Sascha Sommer saschasom...@freenet.de
 
-#define DRIVER_DESC Empia em28xx based USB core driver
-
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE(GPL);
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index f72663a9b5c5..7fa1c804c34c 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -54,9 +54,11 @@
 #include m88ds3103.h
 #include m88ts2022.h
 
-MODULE_DESCRIPTION(driver for em28xx based DVB cards);
 MODULE_AUTHOR(Mauro Carvalho Chehab mche...@infradead.org);
 MODULE_LICENSE(GPL);
+MODULE_DESCRIPTION(DRIVER_DESC  - digital TV interface);
+MODULE_VERSION(EM28XX_VERSION);
+
 
 static unsigned int debug;
 module_param(debug, int, 0644);
diff --git a/drivers/media/usb/em28xx/em28xx-input.c 
b/drivers/media/usb/em28xx/em28xx-input.c
index eed7dd79f734..f3b629dd57ae 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -836,7 +836,8 @@ static void __exit em28xx_rc_unregister(void)
 
 MODULE_LICENSE(GPL);
 MODULE_AUTHOR(Mauro Carvalho Chehab mche...@redhat.com);
-MODULE_DESCRIPTION(Em28xx Input driver);
+MODULE_DESCRIPTION(DRIVER_DESC  - input interface);
+MODULE_VERSION(EM28XX_VERSION);
 
 module_init(em28xx_rc_register);
 module_exit(em28xx_rc_unregister);
diff --git a/drivers/media/usb/em28xx/em28xx-video.c 
b/drivers/media/usb/em28xx/em28xx-video.c
index 328d724a13ea..999cbfe766a3 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -50,8 +50,6 @@
  Mauro Carvalho Chehab mche...@infradead.org,  \
  Sascha Sommer saschasom...@freenet.de
 
-#define DRIVER_DESC Empia em28xx based USB video device driver
-
 static unsigned int isoc_debug;
 module_param(isoc_debug, int, 0644);
 MODULE_PARM_DESC(isoc_debug, enable debug messages [isoc transfers]);
@@ -78,7 +76,7 @@ do {\
   } while (0)
 
 MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_DESCRIPTION(DRIVER_DESC  - v4l2 interface);
 MODULE_LICENSE(GPL);
 MODULE_VERSION(EM28XX_VERSION);
 
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index ac79501f5d9f..db47c2236ca4 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -27,6 +27,7 @@
 #define _EM28XX_H
 
 #define EM28XX_VERSION 0.2.1
+#define DRIVER_DESCEmpia em28xx device driver
 
 #include linux/workqueue.h
 #include linux/i2c.h
-- 
1.8.3.1

--
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 v4 RFC 1/2] [media] em28xx: retry I2C write ops if failed by timeout

2014-01-04 Thread Markus Rechberger
Did you trace the i2c messages on the bus? This seems like papering
the actual bug.

USB 3.0 is a disaster with Linux, maybe your hardware or your
controller driver is not okay?
There are other bugreports out there which are USB 3.0 related, some
of our customers reported that since 3.6.0 is okay while 3.7.10 give
them a complete system lock up also with the driver in question here.


On Sat, Jan 4, 2014 at 12:09 PM, Mauro Carvalho Chehab
m.che...@samsung.com wrote:
 At least on HVR-950, sometimes an I2C operation fails.

 This seems to be more frequent when the device is connected
 into an USB 3.0 port.

 Instead of report an error, try to repeat it, for up to
 20 ms. That makes the code more reliable.

 Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
 ---
  drivers/media/usb/em28xx/em28xx-i2c.c | 23 +++
  1 file changed, 11 insertions(+), 12 deletions(-)

 diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
 b/drivers/media/usb/em28xx/em28xx-i2c.c
 index 6cd3d909bb3a..35d6808aa9ff 100644
 --- a/drivers/media/usb/em28xx/em28xx-i2c.c
 +++ b/drivers/media/usb/em28xx/em28xx-i2c.c
 @@ -189,6 +189,7 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 
 addr, u8 *buf,
  * Zero length reads always succeed, even if no device is connected
  */

 +retry:
 /* Write to i2c device */
 ret = dev-em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
 if (ret != len) {
 @@ -208,26 +209,24 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, 
 u16 addr, u8 *buf,
 ret = dev-em28xx_read_reg(dev, 0x05);
 if (ret == 0) /* success */
 return len;
 -   if (ret == 0x10) {
 -   em28xx_warn(I2C transfer timeout on writing to addr 
 0x%02x,
 -   addr);
 -   return -EREMOTEIO;
 -   }
 +   if (ret == 0x10)
 +   goto retry;
 if (ret  0) {
 em28xx_warn(failed to get i2c transfer status from 
 bridge register (error=%i)\n,
 ret);
 return ret;
 }
 msleep(5);
 -   /*
 -* NOTE: do we really have to wait for success ?
 -* Never seen anything else than 0x00 or 0x10
 -* (even with high payload) ...
 -*/
 }

 -   if (i2c_debug)
 -   em28xx_warn(write to i2c device at 0x%x timed out\n, addr);
 +   if (ret == 0x10) {
 +   if (i2c_debug)
 +   em28xx_warn(I2C transfer timeout on writing to addr 
 0x%02x,
 +   addr);
 +   } else {
 +   em28xx_warn(write to i2c device at 0x%x timed out 
 (ret=0x%02x)\n,
 +   addr, ret);
 +   }
 return -EREMOTEIO;
  }

 --
 1.8.3.1

 --
 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
--
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] support for CX23103 Video Grabber USB

2014-01-04 Thread Links (Markus)
From: Links (Markus) help.markus+...@gmail.com

modified:   drivers/media/usb/cx231xx/cx231xx-cards.c

Signed-off-by: Links (Markus) help.markus+...@gmail.com
---
 drivers/media/usb/cx231xx/cx231xx-cards.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 528cce9..2ee03e4 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -709,6 +709,8 @@ const unsigned int cx231xx_bcount = 
ARRAY_SIZE(cx231xx_boards);
 
 /* table of devices that work with this driver */
 struct usb_device_id cx231xx_id_table[] = {
+   {USB_DEVICE(0x1D19, 0x6109),
+   .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
{USB_DEVICE(0x0572, 0x5A3C),
 .driver_info = CX231XX_BOARD_UNKNOWN},
{USB_DEVICE(0x0572, 0x58A2),
-- 
1.7.10.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


cron job: media_tree daily build: ERRORS

2014-01-04 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Sun Jan  5 04:00:27 CET 2014
git branch: test
git hash:   f7d40eea8e3e531f1517ab7eded552e8837ef5da
gcc version:i686-linux-gcc (GCC) 4.8.2
sparse version: 0.4.5-rc1
host hardware:  x86_64
host os:3.12-6.slh.2-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: ERRORS
linux-git-arm-exynos: WARNINGS
linux-git-arm-mx: OK
linux-git-arm-omap: OK
linux-git-arm-omap1: OK
linux-git-arm-pxa: OK
linux-git-blackfin: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.31.14-i686: WARNINGS
linux-2.6.32.27-i686: WARNINGS
linux-2.6.33.7-i686: WARNINGS
linux-2.6.34.7-i686: WARNINGS
linux-2.6.35.9-i686: WARNINGS
linux-2.6.36.4-i686: WARNINGS
linux-2.6.37.6-i686: WARNINGS
linux-2.6.38.8-i686: WARNINGS
linux-2.6.39.4-i686: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.1.10-i686: WARNINGS
linux-3.2.37-i686: OK
linux-3.3.8-i686: OK
linux-3.4.27-i686: WARNINGS
linux-3.5.7-i686: WARNINGS
linux-3.6.11-i686: WARNINGS
linux-3.7.4-i686: WARNINGS
linux-3.8-i686: WARNINGS
linux-3.9.2-i686: WARNINGS
linux-3.10.1-i686: OK
linux-3.11.1-i686: OK
linux-3.12-i686: OK
linux-3.13-rc1-i686: OK
linux-2.6.31.14-x86_64: WARNINGS
linux-2.6.32.27-x86_64: WARNINGS
linux-2.6.33.7-x86_64: WARNINGS
linux-2.6.34.7-x86_64: WARNINGS
linux-2.6.35.9-x86_64: WARNINGS
linux-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-x86_64: WARNINGS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-x86_64: WARNINGS
linux-3.2.37-x86_64: OK
linux-3.3.8-x86_64: OK
linux-3.4.27-x86_64: WARNINGS
linux-3.5.7-x86_64: WARNINGS
linux-3.6.11-x86_64: WARNINGS
linux-3.7.4-x86_64: WARNINGS
linux-3.8-x86_64: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12-x86_64: WARNINGS
linux-3.13-rc1-x86_64: WARNINGS
apps: OK
spec-git: OK
sparse version: 0.4.5-rc1
sparse: ERRORS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Sunday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Sunday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/media.html
--
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


Regression on nxt2004

2014-01-04 Thread Mark Goldberg
Firmware loading fails intermittently on nxt2004 with the fedora
3.12.5-302.fc20.x86_64 kernel.

It appears that this is due to [PATCH 3.11 178/272] [media] dvb-frontends:
Don't use dynamic static allocation.

If I revert the patch for nxt200x.c it works correctly.

See https://bugzilla.redhat.com/show_bug.cgi?id=1047988 for more detail.

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