Re: [PATCH v6 06/11] cec: add HDMI CEC framework

2015-05-13 Thread Sean Young
On Mon, May 04, 2015 at 07:32:59PM +0200, Kamil Debski wrote:
 From: Hans Verkuil hansv...@cisco.com
 
 The added HDMI CEC framework provides a generic kernel interface for
 HDMI CEC devices.
 
 Signed-off-by: Hans Verkuil hansv...@cisco.com

-snip-

 +int cec_create_adapter(struct cec_adapter *adap, const char *name, u32 caps)
 +{
 + int res = 0;
 +
 + adap-state = CEC_ADAP_STATE_DISABLED;
 + adap-name = name;
 + adap-phys_addr = 0x;
 + adap-capabilities = caps;
 + adap-version = CEC_VERSION_1_4;
 + adap-sequence = 0;
 + mutex_init(adap-lock);
 + adap-kthread = kthread_run(cec_thread_func, adap, name);
 + init_waitqueue_head(adap-kthread_waitq);
 + init_waitqueue_head(adap-waitq);
 + if (IS_ERR(adap-kthread)) {
 + pr_err(cec-%s: kernel_thread() failed\n, name);
 + return PTR_ERR(adap-kthread);
 + }
 + if (caps) {
 + res = cec_devnode_register(adap-devnode, adap-owner);
 + if (res)
 + kthread_stop(adap-kthread);
 + }
 + adap-recv_notifier = cec_receive_notify;
 +
 + /* Prepare the RC input device */
 + adap-rc = rc_allocate_device();
 + if (!adap-rc) {
 + pr_err(cec-%s: failed to allocate memory for rc_dev\n, name);
 + cec_devnode_unregister(adap-devnode);
 + kthread_stop(adap-kthread);
 + return -ENOMEM;
 + }
 +
 + snprintf(adap-input_name, sizeof(adap-input_name), RC for %s, name);
 + snprintf(adap-input_phys, sizeof(adap-input_phys), %s/input0, name);
 + strncpy(adap-input_drv, name, sizeof(adap-input_drv));
 +
 + adap-rc-input_name = adap-input_name;
 + adap-rc-input_phys = adap-input_phys;
 + adap-rc-dev.parent = adap-devnode.dev;
 + adap-rc-driver_name = adap-input_drv;
 + adap-rc-driver_type = RC_DRIVER_CEC;
 + adap-rc-allowed_protocols = RC_BIT_CEC;
 + adap-rc-priv = adap;
 + adap-rc-map_name = RC_MAP_CEC;
 + adap-rc-timeout = MS_TO_NS(100);
 +

rc-input_id is not populated. It would be nice if input_phys has some 
resemblance to a physical path (like the output of usb_make_path() if it
is a usb device).

 + res = rc_register_device(adap-rc);
 +
 + if (res) {
 + pr_err(cec-%s: failed to prepare input device\n, name);
 + cec_devnode_unregister(adap-devnode);
 + rc_free_device(adap-rc);
 + kthread_stop(adap-kthread);
 + }
 +
 + return res;
 +}
 +EXPORT_SYMBOL_GPL(cec_create_adapter);
 +
 +void cec_delete_adapter(struct cec_adapter *adap)
 +{
 + if (adap-kthread == NULL)
 + return;
 + kthread_stop(adap-kthread);
 + if (adap-kthread_config)
 + kthread_stop(adap-kthread_config);
 + adap-state = CEC_ADAP_STATE_DISABLED;
 + if (cec_devnode_is_registered(adap-devnode))
 + cec_devnode_unregister(adap-devnode);

I think you're missing a rc_unregister_device() here.

 +}
 +EXPORT_SYMBOL_GPL(cec_delete_adapter);


Sean
--
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: rtl2832_sdr: move from staging to media

2015-05-13 Thread Dan Carpenter
Hello Antti Palosaari,

The patch 77bbb2b049c1: rtl2832_sdr: move from staging to media
from Jul 15, 2014, leads to the following static checker warning:

drivers/media/dvb-frontends/rtl2832_sdr.c:1265 rtl2832_sdr_s_ctrl()
warn: test_bit() bitwise op in bit number

This is harmless but messy.

drivers/media/dvb-frontends/rtl2832_sdr.c
   109  
   110  struct rtl2832_sdr_dev {
   111  #define POWER_ON   (1  1)
   112  #define URB_BUF(1  2)

We were supposed to use these to set -flags on the next line.

   113  unsigned long flags;
   114  
   115  struct platform_device *pdev;
   116  
   117  struct video_device vdev;
   118  struct v4l2_device v4l2_dev;
   119  

[ snip ]

   389  dev_dbg(pdev-dev, alloc buf=%d %p (dma %llu)\n,
   390  dev-buf_num, dev-buf_list[dev-buf_num],
   391  (long long)dev-dma_addr[dev-buf_num]);
   392  dev-flags |= USB_STATE_URB_BUF;
  ^
But we use USB_STATE_URB_BUF (0x1) instead of URB_BUF.

   393  }

[ snip ]

  1263  c-bandwidth_hz = dev-bandwidth-val;
  1264  
  1265  if (!test_bit(POWER_ON, dev-flags))
  
The original intent of the code was we test if (dev-flags  POWER_ON)
but really what this is doing is if (dev-flags  (1  POWER_ON))
which is fine because we do it consistently, but it's not pretty and it
causes static checkers to complain (and rightfully so).

  1266  return 0;
  1267  
  1268  if (fe-ops.tuner_ops.set_params)
  1269  ret = fe-ops.tuner_ops.set_params(fe);
  1270  else
  1271  ret = 0;
  1272  break;
  1273  default:

regards,
dan carpenter
--
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:hallo

2015-05-13 Thread niyrscyio
Sehr geehrter Herr
gute Nachrichten für Sie
laptop, moto, mobile, gultar,iphone 6 plus,390euro
si te:  lyuuoaa. com

Disappearing dvb-usb stick IT9137FN (Kworld 499-2T)

2015-05-13 Thread Mike Martin
Hi

I have the above usb stick (dual frontend) which works fine for a
while then just vanishes.
ie: frontend just goes
 eg

ls /dev/dvb (I have a permanent DVB card as well)
/dev/dvb/adapter0
/dev/dvb/adapter1
/dev/dvb/adapter2

goes to

ls /dev/dvb (I have a permanent DVB card as well)
/dev/dvb/adapter0

To get it back I have plug/unplug several times (rebooting the box
seems to make no difference)

I am currently on fedora 21, but this seems to be a continual issue ,
through at least fedora 18 to date

I cant see anything obvious in dmesg or the logs

Any ideas
--
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 v6 06/11] cec: add HDMI CEC framework

2015-05-13 Thread Hans Verkuil
Typo and question:

On 05/04/15 19:32, Kamil Debski wrote:
 +static long cec_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 +{
 + struct cec_devnode *cecdev = cec_devnode_data(filp);
 + struct cec_adapter *adap = to_cec_adapter(cecdev);
 + void __user *parg = (void __user *)arg;
 + int err;
 +
 + if (!cec_devnode_is_registered(cecdev))
 + return -EIO;
 +
 + switch (cmd) {

snip

 + case CEC_G_ADAP_STATE: {
 + u32 state = adap-state != CEC_ADAP_STATE_DISABLED;
 +
 + if (copy_to_user(parg, state, sizeof(state)))
 + return -EFAULT;
 + break;
 + }
 +
 + case CEC_S_ADAP_STATE: {
 + u32 state;
 +
 + if (!(adap-capabilities  CEC_CAP_STATE))
 + return -ENOTTY;
 + if (copy_from_user(state, parg, sizeof(state)))
 + return -EFAULT;
 + if (!state  adap-state == CEC_ADAP_STATE_DISABLED)
 + return 0;
 + if (state  adap-state != CEC_ADAP_STATE_DISABLED)
 + return 0;
 + cec_enable(adap, !!state);
 + break;
 + }
 +
 + case CEC_G_ADAP_PHYS_ADDR:
 + if (copy_to_user(parg, adap-phys_addr,
 + sizeof(adap-phys_addr)))
 + return -EFAULT;

If the adapter requires that userspace sets up the phys addr, then what
should this return if no such address has been set up?

I see two options: either 0x (which should be used if the HDMI cable
is disconnected), or return an error (perhaps ENODATA).

I think 0x might be best. This will still allow the unregistered
logical address.

Note that the comment in uapi/linux/cec.h for G_ADAP_LOG_ADDRS says that it
will return an error if the physical address is not set. That's not true
as far as I can tell, and if we go for 0x as the default in a case like
that, then it isn't necessary either to return an error.

cec_create_adapter already initialized the physical address to 0x, so
that looks good. But it should be documented in cec-ioc-g-adap-phys-addr.xml.

 + break;
 +
 + case CEC_S_ADAP_PHYS_ADDR: {
 + u16 phys_addr;
 +
 + if (!(adap-capabilities  CEC_CAP_PHYS_ADDR))
 + return -ENOTTY;
 + if (copy_from_user(phys_addr, parg, sizeof(phys_addr)))
 + return -EFAULT;
 + adap-phys_addr = phys_addr;
 + break;
 + }
 +
 + case CEC_G_ADAP_LOG_ADDRS: {
 + struct cec_log_addrs log_addrs;
 +
 + log_addrs.cec_version = adap-version;
 + log_addrs.num_log_addrs = adap-num_log_addrs;
 + memcpy(log_addrs.primary_device_type, adap-prim_device,
 + CEC_MAX_LOG_ADDRS);
 + memcpy(log_addrs.log_addr_type, adap-log_addr_type,
 + CEC_MAX_LOG_ADDRS);
 + memcpy(log_addrs.log_addr, adap-log_addr,
 + CEC_MAX_LOG_ADDRS);
 +
 + if (copy_to_user(parg, log_addrs, sizeof(log_addrs)))
 + return -EFAULT;
 + break;
 + }
 +
 + case CEC_S_ADAP_LOG_ADDRS: {
 + struct cec_log_addrs log_addrs;
 +
 + if (!(adap-capabilities  CEC_CAP_LOG_ADDRS))
 + return -ENOTTY;
 + if (copy_from_user(log_addrs, parg, sizeof(log_addrs)))
 + return -EFAULT;
 + err = cec_claim_log_addrs(adap, log_addrs,
 + !(filp-f_flags  O_NONBLOCK));
 + if (err)
 + return err;
 +
 + if (copy_to_user(parg, log_addrs, sizeof(log_addrs)))
 + return -EFAULT;
 + break;
 + }
 +
 + case CEC_G_VENDOR_ID:
 + if (copy_to_user(parg, adap-vendor_id,
 + sizeof(adap-vendor_id)))
 + return -EFAULT;

I've been reading up on this. If I understand it correctly, then this is
optional (only if a device supports vendor commands does it have to implement
this).

So if the VENDOR capability is set, then userspace *may* change it. If it is
left undefined, then no vendor commands are allowed.

I think this should be redesigned:

One CEC_CAP_VENDOR_CMDS: if set, then vendor commands are allowed.
One CEC_CAP_VENDOR_ID: userspace may set the Vendor ID. No vendor commands are
allowed as long as no vendor ID was set.

So if VENDOR_CMDS is set and VENDOR_ID isn't, then that means that the driver
will have set the vendor ID and the application can retrieve it with 
G_VENDOR_ID.
If both are set, then userspace has to provide a vendor ID before vendor 
commands
will be allowed.

That leaves the problem of determining that no vendor ID was set. 

Re: [PATCH v6 06/11] cec: add HDMI CEC framework

2015-05-13 Thread Hans Verkuil
Hi Kamil,

Here is the first cec-compliance bug report:

CEC_G_CAPS doesn't zero the reserved field!

cec.c needs a memset there.

I think this is missing in cec.c for all structs with a reserved
field in them. Only G_EVENT looks to be OK.

Regards,

Hans
--
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] dma-mapping: Use tab instead of spaces for indenting.

2015-05-13 Thread Mauro Carvalho Chehab
I wouldn't mind about this, if it won't be caused lots of smatch
warnings (one for each file that includes this header)
when the media drivers are compiled:

./arch/x86/include/asm/dma-mapping.h:125 dma_alloc_coherent_gfp_flags() warn: 
inconsistent indenting

That makes harder to identify real troubles pointed by smatch.

Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com

diff --git a/arch/x86/include/asm/dma-mapping.h 
b/arch/x86/include/asm/dma-mapping.h
index 808dae63eeea..d6e6da39d75c 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -122,7 +122,7 @@ static inline gfp_t dma_alloc_coherent_gfp_flags(struct 
device *dev, gfp_t gfp)
if (dma_mask = DMA_BIT_MASK(32)  !(gfp  GFP_DMA))
gfp |= GFP_DMA32;
 #endif
-   return gfp;
+   return gfp;
 }
 
 #define dma_alloc_coherent(d,s,h,f)dma_alloc_attrs(d,s,h,f,NULL)
-- 
2.1.0

--
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 0/9 v5] Helper to abstract vma handling in media layer

2015-05-13 Thread Jan Kara
  Hello,

I'm sending the fifth version of my patch series to abstract vma handling
from the various media drivers. The patches got some review from mm people and
testing from device driver guys so unless someone objects, patches will be
queued in media tree for the next merge window.

After this patch set drivers have to know much less details about vmas, their
types, and locking. Also quite some code is removed from them. As a bonus
drivers get automatically VM_FAULT_RETRY handling. The primary motivation for
this series is to remove knowledge about mmap_sem locking from as many places a
possible so that we can change it with reasonable effort.

The core of the series is the new helper get_vaddr_frames() which is given a
virtual address and it fills in PFNs / struct page pointers (depending on VMA
type) into the provided array. If PFNs correspond to normal pages it also grabs
references to these pages. The difference from get_user_pages() is that this
function can also deal with pfnmap, and io mappings which is what the media
drivers need.

I have tested the patches with vivid driver so at least vb2 code got some
exposure. Conversion of other drivers was just compile-tested (for x86 so e.g.
exynos driver which is only for Samsung platform is completely untested).

Honza
Changes since v4:
* Minor cleanups and fixes pointed out by Mel and Vlasta
* Added Acked-by tags

Changes since v3:
* Added include linux/vmalloc.h into mm/gup.c as it's needed for some archs
* Fixed error path for exynos driver

Changes since v2:
* Renamed functions and structures as Mel suggested
* Other minor changes suggested by Mel
* Rebased on top of 4.1-rc2
* Changed functions to get pointer to array of pages / pfns to perform
  conversion if necessary. This fixes possible issue in the omap I may have
  introduced in v2 and generally makes the API less errorprone.
--
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 6/9] media: vb2: Convert vb2_vmalloc_get_userptr() to use frame vector

2015-05-13 Thread Jan Kara
Convert vb2_vmalloc_get_userptr() to use frame vector infrastructure.
When we are doing that there's no need to allocate page array and some
code can be simplified.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-vmalloc.c | 94 +++--
 1 file changed, 36 insertions(+), 58 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c 
b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 0ba40be21ebd..d2ce81fa2cdf 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -23,11 +23,9 @@
 
 struct vb2_vmalloc_buf {
void*vaddr;
-   struct page **pages;
-   struct vm_area_struct   *vma;
+   struct frame_vector *vec;
enum dma_data_direction dma_dir;
unsigned long   size;
-   unsigned intn_pages;
atomic_trefcount;
struct vb2_vmarea_handler   handler;
struct dma_buf  *dbuf;
@@ -76,10 +74,8 @@ static void *vb2_vmalloc_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
 enum dma_data_direction dma_dir)
 {
struct vb2_vmalloc_buf *buf;
-   unsigned long first, last;
-   int n_pages, offset;
-   struct vm_area_struct *vma;
-   dma_addr_t physp;
+   struct frame_vector *vec;
+   int n_pages, offset, i;
 
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
@@ -88,53 +84,36 @@ static void *vb2_vmalloc_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
buf-dma_dir = dma_dir;
offset = vaddr  ~PAGE_MASK;
buf-size = size;
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(current-mm, vaddr);
-   if (vma  (vma-vm_flags  VM_PFNMAP)  (vma-vm_pgoff)) {
-   if (vb2_get_contig_userptr(vaddr, size, vma, physp))
-   goto fail_pages_array_alloc;
-   buf-vma = vma;
-   buf-vaddr = (__force void *)ioremap_nocache(physp, size);
-   if (!buf-vaddr)
-   goto fail_pages_array_alloc;
+   vec = vb2_create_framevec(vaddr, size, dma_dir == DMA_FROM_DEVICE);
+   if (IS_ERR(vec))
+   goto fail_pfnvec_create;
+   buf-vec = vec;
+   n_pages = frame_vector_count(vec);
+   if (frame_vector_to_pages(vec)  0) {
+   unsigned long *nums = frame_vector_pfns(vec);
+
+   /*
+* We cannot get page pointers for these pfns. Check memory is
+* physically contiguous and use direct mapping.
+*/
+   for (i = 1; i  n_pages; i++)
+   if (nums[i-1] + 1 != nums[i])
+   goto fail_map;
+   buf-vaddr = (__force void *)
+   ioremap_nocache(nums[0]  PAGE_SHIFT, size);
} else {
-   first = vaddr  PAGE_SHIFT;
-   last  = (vaddr + size - 1)  PAGE_SHIFT;
-   buf-n_pages = last - first + 1;
-   buf-pages = kzalloc(buf-n_pages * sizeof(struct page *),
-GFP_KERNEL);
-   if (!buf-pages)
-   goto fail_pages_array_alloc;
-
-   /* current-mm-mmap_sem is taken by videobuf2 core */
-   n_pages = get_user_pages(current, current-mm,
-vaddr  PAGE_MASK, buf-n_pages,
-dma_dir == DMA_FROM_DEVICE,
-1, /* force */
-buf-pages, NULL);
-   if (n_pages != buf-n_pages)
-   goto fail_get_user_pages;
-
-   buf-vaddr = vm_map_ram(buf-pages, buf-n_pages, -1,
+   buf-vaddr = vm_map_ram(frame_vector_pages(vec), n_pages, -1,
PAGE_KERNEL);
-   if (!buf-vaddr)
-   goto fail_get_user_pages;
}
-   up_read(current-mm-mmap_sem);
 
+   if (!buf-vaddr)
+   goto fail_map;
buf-vaddr += offset;
return buf;
 
-fail_get_user_pages:
-   pr_debug(get_user_pages requested/got: %d/%d]\n, n_pages,
-buf-n_pages);
-   while (--n_pages = 0)
-   put_page(buf-pages[n_pages]);
-   kfree(buf-pages);
-
-fail_pages_array_alloc:
-   up_read(current-mm-mmap_sem);
+fail_map:
+   vb2_destroy_framevec(vec);
+fail_pfnvec_create:
kfree(buf);
 
return NULL;
@@ -145,22 +124,21 @@ static void vb2_vmalloc_put_userptr(void *buf_priv)
struct vb2_vmalloc_buf *buf = buf_priv;
unsigned long vaddr = (unsigned long)buf-vaddr  PAGE_MASK;
unsigned int i;
+  

[PATCH 5/9] media: vb2: Convert vb2_dma_sg_get_userptr() to use frame vector

2015-05-13 Thread Jan Kara
Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 97 +-
 1 file changed, 15 insertions(+), 82 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index afd4b514affc..4ee1b3fbfe2a 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -38,6 +38,7 @@ struct vb2_dma_sg_buf {
struct device   *dev;
void*vaddr;
struct page **pages;
+   struct frame_vector *vec;
int offset;
enum dma_data_direction dma_dir;
struct sg_table sg_table;
@@ -51,7 +52,6 @@ struct vb2_dma_sg_buf {
unsigned intnum_pages;
atomic_trefcount;
struct vb2_vmarea_handler   handler;
-   struct vm_area_struct   *vma;
 
struct dma_buf_attachment   *db_attach;
 };
@@ -224,25 +224,17 @@ static void vb2_dma_sg_finish(void *buf_priv)
dma_sync_sg_for_cpu(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
 }
 
-static inline int vma_is_io(struct vm_area_struct *vma)
-{
-   return !!(vma-vm_flags  (VM_IO | VM_PFNMAP));
-}
-
 static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
unsigned long size,
enum dma_data_direction dma_dir)
 {
struct vb2_dma_sg_conf *conf = alloc_ctx;
struct vb2_dma_sg_buf *buf;
-   unsigned long first, last;
-   int num_pages_from_user;
-   struct vm_area_struct *vma;
struct sg_table *sgt;
DEFINE_DMA_ATTRS(attrs);
+   struct frame_vector *vec;
 
dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs);
-
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
return NULL;
@@ -253,63 +245,19 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
buf-offset = vaddr  ~PAGE_MASK;
buf-size = size;
buf-dma_sgt = buf-sg_table;
+   vec = vb2_create_framevec(vaddr, size, buf-dma_dir == DMA_FROM_DEVICE);
+   if (IS_ERR(vec))
+   goto userptr_fail_pfnvec;
+   buf-vec = vec;
 
-   first = (vaddrPAGE_MASK)  PAGE_SHIFT;
-   last  = ((vaddr + size - 1)  PAGE_MASK)  PAGE_SHIFT;
-   buf-num_pages = last - first + 1;
-
-   buf-pages = kzalloc(buf-num_pages * sizeof(struct page *),
-GFP_KERNEL);
-   if (!buf-pages)
-   goto userptr_fail_alloc_pages;
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(current-mm, vaddr);
-   if (!vma) {
-   dprintk(1, no vma for address %lu\n, vaddr);
-   goto userptr_fail_find_vma;
-   }
-
-   if (vma-vm_end  vaddr + size) {
-   dprintk(1, vma at %lu is too small for %lu bytes\n,
-   vaddr, size);
-   goto userptr_fail_find_vma;
-   }
-
-   buf-vma = vb2_get_vma(vma);
-   if (!buf-vma) {
-   dprintk(1, failed to copy vma\n);
-   goto userptr_fail_find_vma;
-   }
-
-   if (vma_is_io(buf-vma)) {
-   for (num_pages_from_user = 0;
-num_pages_from_user  buf-num_pages;
-++num_pages_from_user, vaddr += PAGE_SIZE) {
-   unsigned long pfn;
-
-   if (follow_pfn(vma, vaddr, pfn)) {
-   dprintk(1, no page for address %lu\n, vaddr);
-   break;
-   }
-   buf-pages[num_pages_from_user] = pfn_to_page(pfn);
-   }
-   } else
-   num_pages_from_user = get_user_pages(current, current-mm,
-vaddr  PAGE_MASK,
-buf-num_pages,
-buf-dma_dir == DMA_FROM_DEVICE,
-1, /* force */
-buf-pages,
-NULL);
-   up_read(current-mm-mmap_sem);
-
-   if (num_pages_from_user != buf-num_pages)
-   goto userptr_fail_get_user_pages;
+   buf-pages = frame_vector_pages(vec);
+   if (IS_ERR(buf-pages))
+   goto userptr_fail_sgtable;
+   buf-num_pages = frame_vector_count(vec);
 
if (sg_alloc_table_from_pages(buf-dma_sgt, buf-pages,
buf-num_pages, buf-offset, size, 0))
-   goto userptr_fail_alloc_table_from_pages;
+   goto userptr_fail_sgtable;
 
sgt = buf-sg_table;
/*
@@ -323,19 +271,9 @@ 

[PATCH 7/9] media: vb2: Convert vb2_dc_get_userptr() to use frame vector

2015-05-13 Thread Jan Kara
Convert vb2_dc_get_userptr() to use frame vector infrastructure. When we
are doing that there's no need to allocate page array and some code can
be simplified.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 214 -
 1 file changed, 34 insertions(+), 180 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 620c4aa78881..e6cea452302b 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -32,15 +32,13 @@ struct vb2_dc_buf {
dma_addr_t  dma_addr;
enum dma_data_direction dma_dir;
struct sg_table *dma_sgt;
+   struct frame_vector *vec;
 
/* MMAP related */
struct vb2_vmarea_handler   handler;
atomic_trefcount;
struct sg_table *sgt_base;
 
-   /* USERPTR related */
-   struct vm_area_struct   *vma;
-
/* DMABUF related */
struct dma_buf_attachment   *db_attach;
 };
@@ -49,24 +47,6 @@ struct vb2_dc_buf {
 /*scatterlist table functions*/
 /*/
 
-
-static void vb2_dc_sgt_foreach_page(struct sg_table *sgt,
-   void (*cb)(struct page *pg))
-{
-   struct scatterlist *s;
-   unsigned int i;
-
-   for_each_sg(sgt-sgl, s, sgt-orig_nents, i) {
-   struct page *page = sg_page(s);
-   unsigned int n_pages = PAGE_ALIGN(s-offset + s-length)
-PAGE_SHIFT;
-   unsigned int j;
-
-   for (j = 0; j  n_pages; ++j, ++page)
-   cb(page);
-   }
-}
-
 static unsigned long vb2_dc_get_contiguous_size(struct sg_table *sgt)
 {
struct scatterlist *s;
@@ -429,92 +409,12 @@ static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv, 
unsigned long flags)
 /*   callbacks for USERPTR buffers   */
 /*/
 
-static inline int vma_is_io(struct vm_area_struct *vma)
-{
-   return !!(vma-vm_flags  (VM_IO | VM_PFNMAP));
-}
-
-static int vb2_dc_get_user_pfn(unsigned long start, int n_pages,
-   struct vm_area_struct *vma, unsigned long *res)
-{
-   unsigned long pfn, start_pfn, prev_pfn;
-   unsigned int i;
-   int ret;
-
-   if (!vma_is_io(vma))
-   return -EFAULT;
-
-   ret = follow_pfn(vma, start, pfn);
-   if (ret)
-   return ret;
-
-   start_pfn = pfn;
-   start += PAGE_SIZE;
-
-   for (i = 1; i  n_pages; ++i, start += PAGE_SIZE) {
-   prev_pfn = pfn;
-   ret = follow_pfn(vma, start, pfn);
-
-   if (ret) {
-   pr_err(no page for address %lu\n, start);
-   return ret;
-   }
-   if (pfn != prev_pfn + 1)
-   return -EINVAL;
-   }
-
-   *res = start_pfn;
-   return 0;
-}
-
-static int vb2_dc_get_user_pages(unsigned long start, struct page **pages,
-   int n_pages, struct vm_area_struct *vma,
-   enum dma_data_direction dma_dir)
-{
-   if (vma_is_io(vma)) {
-   unsigned int i;
-
-   for (i = 0; i  n_pages; ++i, start += PAGE_SIZE) {
-   unsigned long pfn;
-   int ret = follow_pfn(vma, start, pfn);
-
-   if (!pfn_valid(pfn))
-   return -EINVAL;
-
-   if (ret) {
-   pr_err(no page for address %lu\n, start);
-   return ret;
-   }
-   pages[i] = pfn_to_page(pfn);
-   }
-   } else {
-   int n;
-
-   n = get_user_pages(current, current-mm, start  PAGE_MASK,
-   n_pages, dma_dir == DMA_FROM_DEVICE, 1, pages, NULL);
-   /* negative error means that no page was pinned */
-   n = max(n, 0);
-   if (n != n_pages) {
-   pr_err(got only %d of %d user pages\n, n, n_pages);
-   while (n)
-   put_page(pages[--n]);
-   return -EFAULT;
-   }
-   }
-
-   return 0;
-}
-
-static void vb2_dc_put_dirty_page(struct page *page)
-{
-   set_page_dirty_lock(page);
-   put_page(page);
-}
-
 static void vb2_dc_put_userptr(void *buf_priv)
 {
struct vb2_dc_buf *buf = buf_priv;
struct sg_table *sgt = buf-dma_sgt;
+   int i;
+   struct page **pages;
 
if (sgt) {
DEFINE_DMA_ATTRS(attrs);
@@ -526,15 +426,15 @@ static void vb2_dc_put_userptr(void *buf_priv)
 */

[PATCH 8/9] media: vb2: Remove unused functions

2015-05-13 Thread Jan Kara
Conversion to the use of pinned pfns made some functions unused. Remove
them. Also there's no need to lock mmap_sem in __buf_prepare() anymore.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-memops.c | 114 -
 include/media/videobuf2-memops.h   |   6 --
 2 files changed, 120 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-memops.c 
b/drivers/media/v4l2-core/videobuf2-memops.c
index 0ec186d41b9b..48c6a49c4928 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -23,120 +23,6 @@
 #include media/videobuf2-memops.h
 
 /**
- * vb2_get_vma() - acquire and lock the virtual memory area
- * @vma:   given virtual memory area
- *
- * This function attempts to acquire an area mapped in the userspace for
- * the duration of a hardware operation. The area is locked by performing
- * the same set of operation that are done when process calls fork() and
- * memory areas are duplicated.
- *
- * Returns a copy of a virtual memory region on success or NULL.
- */
-struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma)
-{
-   struct vm_area_struct *vma_copy;
-
-   vma_copy = kmalloc(sizeof(*vma_copy), GFP_KERNEL);
-   if (vma_copy == NULL)
-   return NULL;
-
-   if (vma-vm_ops  vma-vm_ops-open)
-   vma-vm_ops-open(vma);
-
-   if (vma-vm_file)
-   get_file(vma-vm_file);
-
-   memcpy(vma_copy, vma, sizeof(*vma));
-
-   vma_copy-vm_mm = NULL;
-   vma_copy-vm_next = NULL;
-   vma_copy-vm_prev = NULL;
-
-   return vma_copy;
-}
-EXPORT_SYMBOL_GPL(vb2_get_vma);
-
-/**
- * vb2_put_userptr() - release a userspace virtual memory area
- * @vma:   virtual memory region associated with the area to be released
- *
- * This function releases the previously acquired memory area after a hardware
- * operation.
- */
-void vb2_put_vma(struct vm_area_struct *vma)
-{
-   if (!vma)
-   return;
-
-   if (vma-vm_ops  vma-vm_ops-close)
-   vma-vm_ops-close(vma);
-
-   if (vma-vm_file)
-   fput(vma-vm_file);
-
-   kfree(vma);
-}
-EXPORT_SYMBOL_GPL(vb2_put_vma);
-
-/**
- * vb2_get_contig_userptr() - lock physically contiguous userspace mapped 
memory
- * @vaddr: starting virtual address of the area to be verified
- * @size:  size of the area
- * @res_paddr: will return physical address for the given vaddr
- * @res_vma:   will return locked copy of struct vm_area for the given area
- *
- * This function will go through memory area of size @size mapped at @vaddr and
- * verify that the underlying physical pages are contiguous. If they are
- * contiguous the virtual memory area is locked and a @res_vma is filled with
- * the copy and @res_pa set to the physical address of the buffer.
- *
- * Returns 0 on success.
- */
-int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
-  struct vm_area_struct **res_vma, dma_addr_t *res_pa)
-{
-   struct mm_struct *mm = current-mm;
-   struct vm_area_struct *vma;
-   unsigned long offset, start, end;
-   unsigned long this_pfn, prev_pfn;
-   dma_addr_t pa = 0;
-
-   start = vaddr;
-   offset = start  ~PAGE_MASK;
-   end = start + size;
-
-   vma = find_vma(mm, start);
-
-   if (vma == NULL || vma-vm_end  end)
-   return -EFAULT;
-
-   for (prev_pfn = 0; start  end; start += PAGE_SIZE) {
-   int ret = follow_pfn(vma, start, this_pfn);
-   if (ret)
-   return ret;
-
-   if (prev_pfn == 0)
-   pa = this_pfn  PAGE_SHIFT;
-   else if (this_pfn != prev_pfn + 1)
-   return -EFAULT;
-
-   prev_pfn = this_pfn;
-   }
-
-   /*
-* Memory is contigous, lock vma and return to the caller
-*/
-   *res_vma = vb2_get_vma(vma);
-   if (*res_vma == NULL)
-   return -ENOMEM;
-
-   *res_pa = pa + offset;
-   return 0;
-}
-EXPORT_SYMBOL_GPL(vb2_get_contig_userptr);
-
-/**
  * vb2_create_framevec() - map virtual addresses to pfns
  * @start: Virtual user address where we start mapping
  * @length:Length of a range to map
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index 2f0564ff5f31..830b5239fd8b 100644
--- a/include/media/videobuf2-memops.h
+++ b/include/media/videobuf2-memops.h
@@ -31,12 +31,6 @@ struct vb2_vmarea_handler {
 
 extern const struct vm_operations_struct vb2_common_vm_ops;
 
-int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
-  struct vm_area_struct **res_vma, dma_addr_t *res_pa);
-
-struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma);
-void vb2_put_vma(struct vm_area_struct *vma);
-
 

[PATCH 2/9] mm: Provide new get_vaddr_frames() helper

2015-05-13 Thread Jan Kara
Provide new function get_vaddr_frames().  This function maps virtual
addresses from given start and fills given array with page frame numbers of
the corresponding pages. If given start belongs to a normal vma, the function
grabs reference to each of the pages to pin them in memory. If start
belongs to VM_IO | VM_PFNMAP vma, we don't touch page structures. Caller
must make sure pfns aren't reused for anything else while he is using
them.

This function is created for various drivers to simplify handling of
their buffers.

Acked-by: Mel Gorman mgor...@suse.de
Acked-by: Vlastimil Babka vba...@suse.cz
Signed-off-by: Jan Kara j...@suse.cz
---
 include/linux/mm.h |  44 +++
 mm/gup.c   | 226 +
 2 files changed, 270 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 0755b9fd03a7..dcd1f02a78e9 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -20,6 +20,7 @@
 #include linux/shrinker.h
 #include linux/resource.h
 #include linux/page_ext.h
+#include linux/err.h
 
 struct mempolicy;
 struct anon_vma;
@@ -1197,6 +1198,49 @@ long get_user_pages_unlocked(struct task_struct *tsk, 
struct mm_struct *mm,
int write, int force, struct page **pages);
 int get_user_pages_fast(unsigned long start, int nr_pages, int write,
struct page **pages);
+
+/* Container for pinned pfns / pages */
+struct frame_vector {
+   unsigned int nr_allocated;  /* Number of frames we have space for */
+   unsigned int nr_frames; /* Number of frames stored in ptrs array */
+   bool got_ref;   /* Did we pin pages by getting page ref? */
+   bool is_pfns;   /* Does array contain pages or pfns? */
+   void *ptrs[0];  /* Array of pinned pfns / pages. Use
+* pfns_vector_pages() or pfns_vector_pfns()
+* for access */
+};
+
+struct frame_vector *frame_vector_create(unsigned int nr_frames);
+void frame_vector_destroy(struct frame_vector *vec);
+int get_vaddr_frames(unsigned long start, unsigned int nr_pfns,
+bool write, bool force, struct frame_vector *vec);
+void put_vaddr_frames(struct frame_vector *vec);
+int frame_vector_to_pages(struct frame_vector *vec);
+void frame_vector_to_pfns(struct frame_vector *vec);
+
+static inline unsigned int frame_vector_count(struct frame_vector *vec)
+{
+   return vec-nr_frames;
+}
+
+static inline struct page **frame_vector_pages(struct frame_vector *vec)
+{
+   if (vec-is_pfns) {
+   int err = frame_vector_to_pages(vec);
+
+   if (err)
+   return ERR_PTR(err);
+   }
+   return (struct page **)(vec-ptrs);
+}
+
+static inline unsigned long *frame_vector_pfns(struct frame_vector *vec)
+{
+   if (!vec-is_pfns)
+   frame_vector_to_pfns(vec);
+   return (unsigned long *)(vec-ptrs);
+}
+
 struct kvec;
 int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
struct page **pages);
diff --git a/mm/gup.c b/mm/gup.c
index 6297f6bccfb1..9d7f4fde30cb 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -8,6 +8,7 @@
 #include linux/rmap.h
 #include linux/swap.h
 #include linux/swapops.h
+#include linux/vmalloc.h
 
 #include linux/sched.h
 #include linux/rwsem.h
@@ -936,6 +937,231 @@ int __mm_populate(unsigned long start, unsigned long len, 
int ignore_errors)
return ret; /* 0 or negative error code */
 }
 
+/*
+ * get_vaddr_frames() - map virtual addresses to pfns
+ * @start: starting user address
+ * @nr_frames: number of pages / pfns from start to map
+ * @write: whether pages will be written to by the caller
+ * @force: whether to force write access even if user mapping is
+ * readonly. See description of the same argument of
+   get_user_pages().
+ * @vec:   structure which receives pages / pfns of the addresses mapped.
+ * It should have space for at least nr_frames entries.
+ *
+ * This function maps virtual addresses from @start and fills @vec structure
+ * with page frame numbers or page pointers to corresponding pages (choice
+ * depends on the type of the vma underlying the virtual address). If @start
+ * belongs to a normal vma, the function grabs reference to each of the pages
+ * to pin them in memory. If @start belongs to VM_IO | VM_PFNMAP vma, we don't
+ * touch page structures and the caller must make sure pfns aren't reused for
+ * anything else while he is using them.
+ *
+ * The function returns number of pages mapped which may be less than
+ * @nr_frames. In particular we stop mapping if there are more vmas of
+ * different type underlying the specified range of virtual addresses.
+ * When the function isn't able to map a single page, it returns error.
+ *
+ * This function takes care of grabbing mmap_sem as necessary.
+ */
+int get_vaddr_frames(unsigned long start, unsigned int 

[PATCH 9/9] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames()

2015-05-13 Thread Jan Kara
Convert g2d_userptr_get_dma_addr() to pin pages using get_vaddr_frames().
This removes the knowledge about vmas and mmap_sem locking from exynos
driver. Also it fixes a problem that the function has been mapping user
provided address without holding mmap_sem.

Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 89 ++
 drivers/gpu/drm/exynos/exynos_drm_gem.c | 97 -
 2 files changed, 29 insertions(+), 157 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c 
b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index 81a250830808..265519c0fe2d 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -190,10 +190,8 @@ struct g2d_cmdlist_userptr {
dma_addr_t  dma_addr;
unsigned long   userptr;
unsigned long   size;
-   struct page **pages;
-   unsigned intnpages;
+   struct frame_vector *vec;
struct sg_table *sgt;
-   struct vm_area_struct   *vma;
atomic_trefcount;
boolin_pool;
boolout_of_list;
@@ -363,6 +361,7 @@ static void g2d_userptr_put_dma_addr(struct drm_device 
*drm_dev,
 {
struct g2d_cmdlist_userptr *g2d_userptr =
(struct g2d_cmdlist_userptr *)obj;
+   struct page **pages;
 
if (!obj)
return;
@@ -382,19 +381,21 @@ out:
exynos_gem_unmap_sgt_from_dma(drm_dev, g2d_userptr-sgt,
DMA_BIDIRECTIONAL);
 
-   exynos_gem_put_pages_to_userptr(g2d_userptr-pages,
-   g2d_userptr-npages,
-   g2d_userptr-vma);
+   pages = frame_vector_pages(g2d_userptr-vec);
+   if (!IS_ERR(pages)) {
+   int i;
 
-   exynos_gem_put_vma(g2d_userptr-vma);
+   for (i = 0; i  frame_vector_count(g2d_userptr-vec); i++)
+   set_page_dirty_lock(pages[i]);
+   }
+   put_vaddr_frames(g2d_userptr-vec);
+   frame_vector_destroy(g2d_userptr-vec);
 
if (!g2d_userptr-out_of_list)
list_del_init(g2d_userptr-list);
 
sg_free_table(g2d_userptr-sgt);
kfree(g2d_userptr-sgt);
-
-   drm_free_large(g2d_userptr-pages);
kfree(g2d_userptr);
 }
 
@@ -413,6 +414,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
drm_device *drm_dev,
struct vm_area_struct *vma;
unsigned long start, end;
unsigned int npages, offset;
+   struct frame_vector *vec;
int ret;
 
if (!size) {
@@ -456,65 +458,37 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
drm_device *drm_dev,
return ERR_PTR(-ENOMEM);
 
atomic_set(g2d_userptr-refcount, 1);
+   g2d_userptr-size = size;
 
start = userptr  PAGE_MASK;
offset = userptr  ~PAGE_MASK;
end = PAGE_ALIGN(userptr + size);
npages = (end - start)  PAGE_SHIFT;
-   g2d_userptr-npages = npages;
-
-   pages = drm_calloc_large(npages, sizeof(struct page *));
-   if (!pages) {
-   DRM_ERROR(failed to allocate pages.\n);
-   ret = -ENOMEM;
+   vec = g2d_userptr-vec = frame_vector_create(npages);
+   if (!vec)
goto err_free;
-   }
 
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(current-mm, userptr);
-   if (!vma) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(failed to get vm region.\n);
+   ret = get_vaddr_frames(start, npages, 1, 1, vec);
+   if (ret != npages) {
+   DRM_ERROR(failed to get user pages from userptr.\n);
+   if (ret  0)
+   goto err_destroy_framevec;
ret = -EFAULT;
-   goto err_free_pages;
+   goto err_put_framevec;
}
-
-   if (vma-vm_end  userptr + size) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(vma is too small.\n);
+   if (frame_vector_to_pages(vec)  0) {
ret = -EFAULT;
-   goto err_free_pages;
+   goto err_put_framevec;
}
 
-   g2d_userptr-vma = exynos_gem_get_vma(vma);
-   if (!g2d_userptr-vma) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(failed to copy vma.\n);
-   ret = -ENOMEM;
-   goto err_free_pages;
-   }
-
-   g2d_userptr-size = size;
-
-   ret = exynos_gem_get_pages_from_userptr(start  PAGE_MASK,
-   npages, pages, vma);
-   if (ret  0) {
-   up_read(current-mm-mmap_sem);
-   DRM_ERROR(failed to get user pages from userptr.\n);
-   goto err_put_vma;
-   }
-
-   up_read(current-mm-mmap_sem);
-   g2d_userptr-pages = 

[PATCH 4/9] vb2: Provide helpers for mapping virtual addresses

2015-05-13 Thread Jan Kara
Provide simple helper functions to map virtual address range into an
array of pfns / pages.

Acked-by: Marek Szyprowski m.szyprow...@samsung.com
Tested-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-memops.c | 58 ++
 include/media/videobuf2-memops.h   |  5 +++
 2 files changed, 63 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-memops.c 
b/drivers/media/v4l2-core/videobuf2-memops.c
index 81c1ad8b2cf1..0ec186d41b9b 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -137,6 +137,64 @@ int vb2_get_contig_userptr(unsigned long vaddr, unsigned 
long size,
 EXPORT_SYMBOL_GPL(vb2_get_contig_userptr);
 
 /**
+ * vb2_create_framevec() - map virtual addresses to pfns
+ * @start: Virtual user address where we start mapping
+ * @length:Length of a range to map
+ * @write: Should we map for writing into the area
+ *
+ * This function allocates and fills in a vector with pfns corresponding to
+ * virtual address range passed in arguments. If pfns have corresponding pages,
+ * page references are also grabbed to pin pages in memory. The function
+ * returns pointer to the vector on success and error pointer in case of
+ * failure. Returned vector needs to be freed via vb2_destroy_pfnvec().
+ */
+struct frame_vector *vb2_create_framevec(unsigned long start,
+unsigned long length,
+bool write)
+{
+   int ret;
+   unsigned long first, last;
+   unsigned long nr;
+   struct frame_vector *vec;
+
+   first = start  PAGE_SHIFT;
+   last = (start + length - 1)  PAGE_SHIFT;
+   nr = last - first + 1;
+   vec = frame_vector_create(nr);
+   if (!vec)
+   return ERR_PTR(-ENOMEM);
+   ret = get_vaddr_frames(start, nr, write, 1, vec);
+   if (ret  0)
+   goto out_destroy;
+   /* We accept only complete set of PFNs */
+   if (ret != nr) {
+   ret = -EFAULT;
+   goto out_release;
+   }
+   return vec;
+out_release:
+   put_vaddr_frames(vec);
+out_destroy:
+   frame_vector_destroy(vec);
+   return ERR_PTR(ret);
+}
+EXPORT_SYMBOL(vb2_create_framevec);
+
+/**
+ * vb2_destroy_framevec() - release vector of mapped pfns
+ * @vec:   vector of pfns / pages to release
+ *
+ * This releases references to all pages in the vector @vec (if corresponding
+ * pfns are backed by pages) and frees the passed vector.
+ */
+void vb2_destroy_framevec(struct frame_vector *vec)
+{
+   put_vaddr_frames(vec);
+   frame_vector_destroy(vec);
+}
+EXPORT_SYMBOL(vb2_destroy_framevec);
+
+/**
  * vb2_common_vm_open() - increase refcount of the vma
  * @vma:   virtual memory region for the mapping
  *
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index f05444ca8c0c..2f0564ff5f31 100644
--- a/include/media/videobuf2-memops.h
+++ b/include/media/videobuf2-memops.h
@@ -15,6 +15,7 @@
 #define _MEDIA_VIDEOBUF2_MEMOPS_H
 
 #include media/videobuf2-core.h
+#include linux/mm.h
 
 /**
  * vb2_vmarea_handler - common vma refcount tracking handler
@@ -36,5 +37,9 @@ int vb2_get_contig_userptr(unsigned long vaddr, unsigned long 
size,
 struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma);
 void vb2_put_vma(struct vm_area_struct *vma);
 
+struct frame_vector *vb2_create_framevec(unsigned long start,
+unsigned long length,
+bool write);
+void vb2_destroy_framevec(struct frame_vector *vec);
 
 #endif
-- 
2.1.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 3/9] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns()

2015-05-13 Thread Jan Kara
Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() instead of
hand made mapping of virtual address to physical address. Also the
function leaked page reference from get_user_pages() so fix that by
properly release the reference when omap_vout_buffer_release() is
called.

Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/platform/omap/omap_vout.c | 67 +++--
 1 file changed, 31 insertions(+), 36 deletions(-)

diff --git a/drivers/media/platform/omap/omap_vout.c 
b/drivers/media/platform/omap/omap_vout.c
index 17b189a81ec5..0e4b3cfacc5d 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -195,46 +195,34 @@ static int omap_vout_try_format(struct v4l2_pix_format 
*pix)
 }
 
 /*
- * omap_vout_uservirt_to_phys: This inline function is used to convert user
- * space virtual address to physical address.
+ * omap_vout_get_userptr: Convert user space virtual address to physical
+ * address.
  */
-static unsigned long omap_vout_uservirt_to_phys(unsigned long virtp)
+static int omap_vout_get_userptr(struct videobuf_buffer *vb, u32 virtp,
+u32 *physp)
 {
-   unsigned long physp = 0;
-   struct vm_area_struct *vma;
-   struct mm_struct *mm = current-mm;
+   struct frame_vector *vec;
+   int ret;
 
/* For kernel direct-mapped memory, take the easy way */
-   if (virtp = PAGE_OFFSET)
-   return virt_to_phys((void *) virtp);
-
-   down_read(current-mm-mmap_sem);
-   vma = find_vma(mm, virtp);
-   if (vma  (vma-vm_flags  VM_IO)  vma-vm_pgoff) {
-   /* this will catch, kernel-allocated, mmaped-to-usermode
-  addresses */
-   physp = (vma-vm_pgoff  PAGE_SHIFT) + (virtp - vma-vm_start);
-   up_read(current-mm-mmap_sem);
-   } else {
-   /* otherwise, use get_user_pages() for general userland pages */
-   int res, nr_pages = 1;
-   struct page *pages;
+   if (virtp = PAGE_OFFSET) {
+   *physp = virt_to_phys((void *)virtp);
+   return 0;
+   }
 
-   res = get_user_pages(current, current-mm, virtp, nr_pages, 1,
-   0, pages, NULL);
-   up_read(current-mm-mmap_sem);
+   vec = frame_vector_create(1);
+   if (!vec)
+   return -ENOMEM;
 
-   if (res == nr_pages) {
-   physp =  __pa(page_address(pages[0]) +
-   (virtp  ~PAGE_MASK));
-   } else {
-   printk(KERN_WARNING VOUT_NAME
-   get_user_pages failed\n);
-   return 0;
-   }
+   ret = get_vaddr_frames(virtp, 1, true, false, vec);
+   if (ret != 1) {
+   frame_vector_destroy(vec);
+   return -EINVAL;
}
+   *physp = __pfn_to_phys(frame_vector_pfns(vec)[0]);
+   vb-priv = vec;
 
-   return physp;
+   return 0;
 }
 
 /*
@@ -788,11 +776,15 @@ static int omap_vout_buffer_prepare(struct videobuf_queue 
*q,
 * address of the buffer
 */
if (V4L2_MEMORY_USERPTR == vb-memory) {
+   int ret;
+
if (0 == vb-baddr)
return -EINVAL;
/* Physical address */
-   vout-queued_buf_addr[vb-i] = (u8 *)
-   omap_vout_uservirt_to_phys(vb-baddr);
+   ret = omap_vout_get_userptr(vb, vb-baddr,
+   (u32 *)vout-queued_buf_addr[vb-i]);
+   if (ret  0)
+   return ret;
} else {
unsigned long addr, dma_addr;
unsigned long size;
@@ -841,9 +833,12 @@ static void omap_vout_buffer_release(struct videobuf_queue 
*q,
struct omap_vout_device *vout = q-priv_data;
 
vb-state = VIDEOBUF_NEEDS_INIT;
+   if (vb-memory == V4L2_MEMORY_USERPTR  vb-priv) {
+   struct frame_vector *vec = vb-priv;
 
-   if (V4L2_MEMORY_MMAP != vout-memory)
-   return;
+   put_vaddr_frames(vec);
+   frame_vector_destroy(vec);
+   }
 }
 
 /*
-- 
2.1.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 1/9] [media] vb2: Push mmap_sem down to memops

2015-05-13 Thread Jan Kara
Currently vb2 core acquires mmap_sem just around call to
__qbuf_userptr(). However since commit f035eb4e976ef5 (videobuf2: fix
lockdep warning) it isn't necessary to acquire it so early as we no
longer have to drop queue mutex before acquiring mmap_sem. So push
acquisition of mmap_sem down into .get_userptr and .put_userptr memops
so that the semaphore is acquired for a shorter time and it is clearer
what it is needed for.

Signed-off-by: Jan Kara j...@suse.cz
---
 drivers/media/v4l2-core/videobuf2-core.c   | 2 --
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 7 +++
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 6 ++
 drivers/media/v4l2-core/videobuf2-vmalloc.c| 6 +-
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 66ada01c796c..20cdbc0900ea 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1657,9 +1657,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
ret = __qbuf_mmap(vb, b);
break;
case V4L2_MEMORY_USERPTR:
-   down_read(current-mm-mmap_sem);
ret = __qbuf_userptr(vb, b);
-   up_read(current-mm-mmap_sem);
break;
case V4L2_MEMORY_DMABUF:
ret = __qbuf_dmabuf(vb, b);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 644dec73d220..620c4aa78881 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -532,7 +532,9 @@ static void vb2_dc_put_userptr(void *buf_priv)
sg_free_table(sgt);
kfree(sgt);
}
+   down_read(current-mm-mmap_sem);
vb2_put_vma(buf-vma);
+   up_read(current-mm-mmap_sem);
kfree(buf);
 }
 
@@ -616,6 +618,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned 
long vaddr,
goto fail_buf;
}
 
+   down_read(current-mm-mmap_sem);
/* current-mm-mmap_sem is taken by videobuf2 core */
vma = find_vma(current-mm, vaddr);
if (!vma) {
@@ -642,6 +645,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned 
long vaddr,
if (ret) {
unsigned long pfn;
if (vb2_dc_get_user_pfn(start, n_pages, vma, pfn) == 0) {
+   up_read(current-mm-mmap_sem);
buf-dma_addr = vb2_dc_pfn_to_dma(buf-dev, pfn);
buf-size = size;
kfree(pages);
@@ -651,6 +655,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned 
long vaddr,
pr_err(failed to get user pages\n);
goto fail_vma;
}
+   up_read(current-mm-mmap_sem);
 
sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
if (!sgt) {
@@ -713,10 +718,12 @@ fail_get_user_pages:
while (n_pages)
put_page(pages[--n_pages]);
 
+   down_read(current-mm-mmap_sem);
 fail_vma:
vb2_put_vma(buf-vma);
 
 fail_pages:
+   up_read(current-mm-mmap_sem);
kfree(pages); /* kfree is NULL-proof */
 
 fail_buf:
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 45c708e463b9..afd4b514affc 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -263,6 +263,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
if (!buf-pages)
goto userptr_fail_alloc_pages;
 
+   down_read(current-mm-mmap_sem);
vma = find_vma(current-mm, vaddr);
if (!vma) {
dprintk(1, no vma for address %lu\n, vaddr);
@@ -301,6 +302,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
 1, /* force */
 buf-pages,
 NULL);
+   up_read(current-mm-mmap_sem);
 
if (num_pages_from_user != buf-num_pages)
goto userptr_fail_get_user_pages;
@@ -328,8 +330,10 @@ userptr_fail_get_user_pages:
if (!vma_is_io(buf-vma))
while (--num_pages_from_user = 0)
put_page(buf-pages[num_pages_from_user]);
+   down_read(current-mm-mmap_sem);
vb2_put_vma(buf-vma);
 userptr_fail_find_vma:
+   up_read(current-mm-mmap_sem);
kfree(buf-pages);
 userptr_fail_alloc_pages:
kfree(buf);
@@ -362,7 +366,9 @@ static void vb2_dma_sg_put_userptr(void *buf_priv)
put_page(buf-pages[i]);
}
kfree(buf-pages);
+   down_read(current-mm-mmap_sem);
vb2_put_vma(buf-vma);
+   up_read(current-mm-mmap_sem);
kfree(buf);
 }
 
diff --git 

Re: rtl2832_sdr: move from staging to media

2015-05-13 Thread Antti Palosaari

Moikka!

On 05/13/2015 02:11 PM, Dan Carpenter wrote:

Hello Antti Palosaari,

The patch 77bbb2b049c1: rtl2832_sdr: move from staging to media
from Jul 15, 2014, leads to the following static checker warning:

drivers/media/dvb-frontends/rtl2832_sdr.c:1265 rtl2832_sdr_s_ctrl()
warn: test_bit() bitwise op in bit number

This is harmless but messy.

drivers/media/dvb-frontends/rtl2832_sdr.c
109
110  struct rtl2832_sdr_dev {
111  #define POWER_ON   (1  1)
112  #define URB_BUF(1  2)

We were supposed to use these to set -flags on the next line.

113  unsigned long flags;
114
115  struct platform_device *pdev;
116
117  struct video_device vdev;
118  struct v4l2_device v4l2_dev;
119

[ snip ]

389  dev_dbg(pdev-dev, alloc buf=%d %p (dma %llu)\n,
390  dev-buf_num, dev-buf_list[dev-buf_num],
391  (long long)dev-dma_addr[dev-buf_num]);
392  dev-flags |= USB_STATE_URB_BUF;
   ^
But we use USB_STATE_URB_BUF (0x1) instead of URB_BUF.

393  }

[ snip ]

   1263  c-bandwidth_hz = dev-bandwidth-val;
   1264
   1265  if (!test_bit(POWER_ON, dev-flags))
   
The original intent of the code was we test if (dev-flags  POWER_ON)
but really what this is doing is if (dev-flags  (1  POWER_ON))
which is fine because we do it consistently, but it's not pretty and it
causes static checkers to complain (and rightfully so).

   1266  return 0;
   1267
   1268  if (fe-ops.tuner_ops.set_params)
   1269  ret = fe-ops.tuner_ops.set_params(fe);
   1270  else
   1271  ret = 0;
   1272  break;
   1273  default:



If you wish, you could fix those. Otherwise I will check issues pointed 
and correct. Lets say I will wait at least one week your patch.


[At the some point I am going to rewrote that USB streaming code as I am 
not happy with it. Also I have one device which needs to stream data 
both ways, from device to computer and from computer to device, which 
should be take into account.]


regards
Antti

--
http://palosaari.fi/
--
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: Disappearing dvb-usb stick IT9137FN (Kworld 499-2T)

2015-05-13 Thread Antti Palosaari

On 05/13/2015 12:26 PM, Mike Martin wrote:

Hi

I have the above usb stick (dual frontend) which works fine for a
while then just vanishes.
ie: frontend just goes
  eg

ls /dev/dvb (I have a permanent DVB card as well)
/dev/dvb/adapter0
/dev/dvb/adapter1
/dev/dvb/adapter2

goes to

ls /dev/dvb (I have a permanent DVB card as well)
/dev/dvb/adapter0

To get it back I have plug/unplug several times (rebooting the box
seems to make no difference)

I am currently on fedora 21, but this seems to be a continual issue ,
through at least fedora 18 to date

I cant see anything obvious in dmesg or the logs

Any ideas


Could you still post that dmesg, just those texts appeared after plugin.

Antti
--
http://palosaari.fi/
--
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] si2165 - Add DVB-C Support

2015-05-13 Thread Mauro Carvalho Chehab
Em Thu, 16 Apr 2015 15:37:46 +0200
beta992 beta...@gmail.com escreveu:

 From: beta990

Well, first of all you need to identify yourself with your real name.

 Subject: [PATCH] si2165 - Add DVB-C Support
 
 This patch is based of the work of ZZram.

The best here would be to either get the ZZram patch or to have
his ack, as you're submitting part of somebody's else work.

 I clean-up his patch and removed double code (e.g. double resets,
 actions, etc.):
 
 // -- init?
 ret = si2165_readreg8(state, 0x00e0, val); /* returned 0x00 */
 if (ret  0)
 return ret;
 ret = si2165_writereg32(state, 0x00e8, 0x02db6db6);
 if (ret  0)
 return ret;
 -- //
 
 Remember this is the first time I submit a patch, please be gentle. ;P
 
 Patch contents:
 
 diff --git a/drivers/media/dvb-frontends/si2165.c
 b/drivers/media/dvb-frontends/si2165.c
 index 4cc5d10..d283d68 100644
 --- a/drivers/media/dvb-frontends/si2165.c
 +++ b/drivers/media/dvb-frontends/si2165.c
 @@ -704,7 +704,7 @@ static int si2165_read_status(struct dvb_frontend
 *fe, fe_status_t *status)

The patch is completely broken by your email: lines broken at the wrong
places, spaces removed, etc.

So, it doesn't apply.

Please be sure to use an email client that won't mangle the patch,
e. g. don't use Gmail's web interface ;)

Regards,
Mauro

   u8 fec_lock = 0;
   struct si2165_state *state = fe-demodulator_priv;
 
 - if (!state-has_dvbt)
 + if (!state-has_dvbt || !state-has_dvbc)
   return -EINVAL;
 
   /* check fec_lock */
 @@ -777,131 +777,272 @@ static int si2165_set_parameters(struct
 dvb_frontend *fe)
   return -EINVAL;
   }
 
 - if (!state-has_dvbt)
 + if (!state-has_dvbt || !state-has_dvbc)
   return -EINVAL;
 
 - if (p-bandwidth_hz  0) {
 - dvb_rate = p-bandwidth_hz * 8 / 7;
 - bw10k = p-bandwidth_hz / 1;
 - } else {
 - dvb_rate = 8 * 8 / 7;
 - bw10k = 800;
 - }
 + if (p-delivery_system == SYS_DVBT) {
 + if (p-bandwidth_hz  0) {
 + dvb_rate = p-bandwidth_hz * 8 / 7;
 + bw10k = p-bandwidth_hz / 1;
 + } else {
 + dvb_rate = 8 * 8 / 7;
 + bw10k = 800;
 + }
 
 - /* standard = DVB-T */
 - ret = si2165_writereg8(state, 0x00ec, 0x01);
 - if (ret  0)
 - return ret;
 - ret = si2165_adjust_pll_divl(state, 12);
 - if (ret  0)
 - return ret;
 + /* DVB-T */
 + ret = si2165_writereg8(state, 0x00ec, 0x01);
 + if (ret  0)
 + return ret;
 + ret = si2165_adjust_pll_divl(state, 12);
 + if (ret  0)
 + return ret;
 
 - fe-ops.tuner_ops.get_if_frequency(fe, IF);
 - ret = si2165_set_if_freq_shift(state, IF);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x08f8, 0x00);
 - if (ret  0)
 - return ret;
 - /* ts output config */
 - ret = si2165_writereg8(state, 0x04e4, 0x20);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg16(state, 0x04ef, 0x00fe);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg24(state, 0x04f4, 0x55);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x04e5, 0x01);
 - if (ret  0)
 - return ret;
 - /* bandwidth in 10KHz steps */
 - ret = si2165_writereg16(state, 0x0308, bw10k);
 - if (ret  0)
 - return ret;
 - ret = si2165_set_oversamp(state, dvb_rate);
 - if (ret  0)
 - return ret;
 - /* impulsive_noise_remover */
 - ret = si2165_writereg8(state, 0x031c, 0x01);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x00cb, 0x00);
 - if (ret  0)
 - return ret;
 - /* agc2 */
 - ret = si2165_writereg8(state, 0x016e, 0x41);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x016c, 0x0e);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x016d, 0x10);
 - if (ret  0)
 - return ret;
 - /* agc */
 - ret = si2165_writereg8(state, 0x015b, 0x03);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x0150, 0x78);
 - if (ret  0)
 - return ret;
 - /* agc */
 - ret = si2165_writereg8(state, 0x01a0, 0x78);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x01c8, 0x68);
 - if (ret  0)
 - return ret;
 - /* freq_sync_range */
 - ret = si2165_writereg16(state, 0x030c, 0x0064);
 - if (ret  0)
 - return ret;
 - /* gp_reg0 */
 - ret = si2165_readreg8(state, 0x0387, val);
 - if (ret  0)
 - return ret;
 - ret = si2165_writereg8(state, 0x0387, 0x00);
 - if (ret  0)
 - return ret;
 - /* dsp_addr_jump */
 - ret = si2165_writereg32(state, 0x0348, 0xf400);
 - if (ret  0)
 - return ret;
 + fe-ops.tuner_ops.get_if_frequency(fe, IF);
 + ret = si2165_set_if_freq_shift(state, IF);
 + if (ret  0)
 + return ret;
 + ret = si2165_writereg8(state, 0x08f8, 0x00);
 + if (ret  0)
 + return ret;
 + /* ts output config */
 + ret = si2165_writereg8(state, 0x04e4, 0x20);
 + if (ret  0)
 + return ret;
 + ret = si2165_writereg16(state, 0x04ef, 0x00fe);
 + if (ret  0)
 + return ret;
 + ret = si2165_writereg24(state, 0x04f4, 0x55);
 + if (ret  0)
 + return ret;
 + ret = si2165_writereg8(state, 0x04e5, 0x01);
 + if (ret  0)
 + return ret;
 + /* bandwidth in 10KHz steps */
 + ret = si2165_writereg16(state, 0x0308, bw10k);
 + if (ret  0)
 + return ret;
 + ret = si2165_set_oversamp(state, 

Re: v4.1-rcX regression in v4l2 build

2015-05-13 Thread Robert Jarzmik
Guennadi Liakhovetski g.liakhovet...@gmx.de writes:
...zip...

First, a question for Russell :
  Given that the current PXA architecture is not implementing the
  clk_round_rate() function, while implementing clk_get(), etc..., is it correct
  to say that it is betraying the clk API by doing so ?

And now the answers to your mail Guennadi :
 I've seen some patches on ALKML for PXA CCF, is it in the mainline now? 
 Could that have been the reason? Is CONFIG_COMMON_CLK defined in your 
 .config? Although, no, it's not PXA CCF, it's most probably this
No it's not in clock common framework yet.
PXA will switch to CCF in 4.2, as it missed the 4.1 merge window.

 I think I know how this is possible. PXA uses arch/arm/mach-pxa/clock.c 
 for clk ops, and clk_round_rate() isn't defined there... Can we add a 
 dummy for PXA? It won't be used anyway as long as PXA doesn't support CCF.
I could do it. I'm a bit reluctant because I already prepared my pull request
which fully shifts PXA to CCF, and adding a dummy function will create a merge
issue.

But is PXA the only one in this case ?
From a first sight there are 5 ARM architectures in the same case :
rj@belgarion:~/mio_linux/kernel/arch/arm$ grep -rsl 
'EXPORT_SYMBOL(clk_round_rate' *
mach-davinci/clock.c
mach-lpc32xx/clock.c
mach-omap1/clock.c
plat-versatile/clock.c
rj@belgarion:~/mio_linux/kernel/arch/arm$ grep -rsl 
'EXPORT_SYMBOL(clk_get_rate' *
mach-davinci/clock.c
mach-ep93xx/clock.c
mach-lpc32xx/clock.c
mach-mmp/clock.c
mach-omap1/clock.c
mach-pxa/clock.c
mach-sa1100/clock.c
mach-w90x900/clock.c
plat-versatile/clock.c

Cheers.

-- 
Robert
--
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: [Y2038] [PATCH v3] Staging: media: Replace timeval with ktime_t

2015-05-13 Thread John Stultz
On Wed, May 13, 2015 at 2:10 PM, Mauro Carvalho Chehab
mche...@osg.samsung.com wrote:
 Em Wed, 13 May 2015 21:53:07 +0200
 Arnd Bergmann a...@arndb.de escreveu:

 On Wednesday 13 May 2015 10:04:48 John Stultz wrote:
  On Wed, May 13, 2015 at 9:57 AM, Ksenija Stanojevic
  ksenija.stanoje...@gmail.com wrote:
   'struct timeval last_tv' is used to get the time of last signal change
   and 'struct timeval last_intr_tv' is used to get the time of last UART
   interrupt.
   32-bit systems using 'struct timeval' will break in the year 2038, so we
   have to replace that code with more appropriate types.
   Here struct timeval is replaced with ktime_t.
  
   Signed-off-by: Ksenija Stanojevic ksenija.stanoje...@gmail.com

 An additional comment: as drivers/staging/media refers to a whole subsystem
 with mutually independent drivers, the subject line should mention 'lirc',
 either in addition to, or instead of 'media'.

   -static long delta(struct timeval *tv1, struct timeval *tv2)
   +static inline long delta(ktime_t t1, ktime_t t2)
{
   -   unsigned long deltv;
   -
   -   deltv = tv2-tv_sec - tv1-tv_sec;
   -   if (deltv  15)
   -   deltv = 0xFF;
   -   else
   -   deltv = deltv*100 +
   -   tv2-tv_usec -
   -   tv1-tv_usec;
   -   return deltv;
   +   /* return the delta in 32bit usecs, but cap to UINTMAX in case 
   the
   +* delta is greater then 32bits */
   +   return (long) min((unsigned int) ktime_us_delta(t1, t2), 
   UINT_MAX);
}
 
  This probably needs some close review from the media folks. Thinking
  about it more, I'm really not certain the 15sec cap was to avoid a
  32bit overflow or if there's some other subtle undocumented reason.

 The new code is clearly wrong, as the cast to 'unsigned int' already 
 truncates
 the value to at most UINT_MAX, and the min() does not have any effect.

 The correct way to write what was intended here is

   return min_t(long long, ktime_us_delta(t1, t2), UINT_MAX);

 which will truncate delta to an unsigned integer. The return type of the
 delta() function would need to be changed to 'unsigned long' as well to
 make this work.

 However, I think you are right that we should probably not change the
 behavior, unless someone who understands the purpose better can say
 what it really should be.

 Inside the remote controller code, we have measurements for pulse/space
 encodings on a IR transmission. The duration of a pulse or space is
 generally in the other of microseconds. On the standard protocols, the
 maximum duration is on NEC protocol, where a pulse of 9 ms is sent at
 the beginning:
 http://www.sbprojects.com/knowledge/ir/nec.php

 It should be noticed that bigger time intervals can be used to indicate
 key repeat. Again, in the NEC protocol, the space between key repeats
 are 110 ms.

 So, everything above 110 ms is actually an infinite time.

 As the Kernel implementation was built to be generic enough, we consider
 (u32)-1 (e. g. about 4 seconds) as the maximum possible time.

So that's ~4 seconds of nanoseconds, but since we're talking usecs,
UINT_MAX is something like 70-some minutes.


 This is due to the fact that some IR protocols use u32 for the pulse/space
 time shifts. So, any duration bigger than that could actually be
 rounded to (u32)-1.

Sure. The part that confused me is that the delta function is checking
if the second delta is larger then 15 seconds, and I couldn't quite
understand the significance of that check. If it really is just to
make sure the timeval - usec conversion doesn't overflow, then that's
easy enough to solve. But if the 15 second check has some other
meaning, we'd want to understand before changing this.

 That's said, I really don't see the need of fixing it on the y2038
 patchset. All that it is needed is to warrant that the time difference
 will be positive.

 I would, instead, remove the delta function, and replace:

 do_gettimeofday(curr_tv);
 deltv = delta(last_tv, curr_tv);

 (and other equivalent parts)

 By an equivalent logic that would be reading the timestamp from a
 high precision clock.

 That's said, I suspect that this driver is broken, as I doubt that
 do_gettimeofday() gets enough precision needed for IR decoding. Also,
 as this returns a non-monotonic timestamp, it will break if one adjusts
 the clock while IR keys are being pressed.

Yep. Moving to ktime_get should help since it uses the monotonic clock.

thanks
-john
--
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: [Y2038] [PATCH v3] Staging: media: Replace timeval with ktime_t

2015-05-13 Thread Arnd Bergmann
On Wednesday 13 May 2015 10:04:48 John Stultz wrote:
 On Wed, May 13, 2015 at 9:57 AM, Ksenija Stanojevic
 ksenija.stanoje...@gmail.com wrote:
  'struct timeval last_tv' is used to get the time of last signal change
  and 'struct timeval last_intr_tv' is used to get the time of last UART
  interrupt.
  32-bit systems using 'struct timeval' will break in the year 2038, so we
  have to replace that code with more appropriate types.
  Here struct timeval is replaced with ktime_t.
 
  Signed-off-by: Ksenija Stanojevic ksenija.stanoje...@gmail.com

An additional comment: as drivers/staging/media refers to a whole subsystem
with mutually independent drivers, the subject line should mention 'lirc',
either in addition to, or instead of 'media'.

  -static long delta(struct timeval *tv1, struct timeval *tv2)
  +static inline long delta(ktime_t t1, ktime_t t2)
   {
  -   unsigned long deltv;
  -
  -   deltv = tv2-tv_sec - tv1-tv_sec;
  -   if (deltv  15)
  -   deltv = 0xFF;
  -   else
  -   deltv = deltv*100 +
  -   tv2-tv_usec -
  -   tv1-tv_usec;
  -   return deltv;
  +   /* return the delta in 32bit usecs, but cap to UINTMAX in case the
  +* delta is greater then 32bits */
  +   return (long) min((unsigned int) ktime_us_delta(t1, t2), UINT_MAX);
   }
 
 This probably needs some close review from the media folks. Thinking
 about it more, I'm really not certain the 15sec cap was to avoid a
 32bit overflow or if there's some other subtle undocumented reason.

The new code is clearly wrong, as the cast to 'unsigned int' already truncates
the value to at most UINT_MAX, and the min() does not have any effect.

The correct way to write what was intended here is

return min_t(long long, ktime_us_delta(t1, t2), UINT_MAX);

which will truncate delta to an unsigned integer. The return type of the
delta() function would need to be changed to 'unsigned long' as well to
make this work.

However, I think you are right that we should probably not change the
behavior, unless someone who understands the purpose better can say
what it really should be. I'd probably change teh above to

long delta_us = ktime_us_delta(t1, t2);
return min(delta_us, PULSE_MASK);

Arnd
--
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: v4.1-rcX regression in v4l2 build

2015-05-13 Thread Russell King - ARM Linux
On Wed, May 13, 2015 at 09:26:03PM +0200, Robert Jarzmik wrote:
 First, a question for Russell :
   Given that the current PXA architecture is not implementing the
   clk_round_rate() function, while implementing clk_get(), etc..., is it 
 correct
   to say that it is betraying the clk API by doing so ?

Really, yes.  PXA used to be self-contained as far as clk API usage, and
so it only ever implemented what it needed from the API to support the
SoC.  Now that things are getting more complicated then the other
functions will probably be needed.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
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: [Y2038] [PATCH v3] Staging: media: Replace timeval with ktime_t

2015-05-13 Thread Mauro Carvalho Chehab
Em Wed, 13 May 2015 21:53:07 +0200
Arnd Bergmann a...@arndb.de escreveu:

 On Wednesday 13 May 2015 10:04:48 John Stultz wrote:
  On Wed, May 13, 2015 at 9:57 AM, Ksenija Stanojevic
  ksenija.stanoje...@gmail.com wrote:
   'struct timeval last_tv' is used to get the time of last signal change
   and 'struct timeval last_intr_tv' is used to get the time of last UART
   interrupt.
   32-bit systems using 'struct timeval' will break in the year 2038, so we
   have to replace that code with more appropriate types.
   Here struct timeval is replaced with ktime_t.
  
   Signed-off-by: Ksenija Stanojevic ksenija.stanoje...@gmail.com
 
 An additional comment: as drivers/staging/media refers to a whole subsystem
 with mutually independent drivers, the subject line should mention 'lirc',
 either in addition to, or instead of 'media'.
 
   -static long delta(struct timeval *tv1, struct timeval *tv2)
   +static inline long delta(ktime_t t1, ktime_t t2)
{
   -   unsigned long deltv;
   -
   -   deltv = tv2-tv_sec - tv1-tv_sec;
   -   if (deltv  15)
   -   deltv = 0xFF;
   -   else
   -   deltv = deltv*100 +
   -   tv2-tv_usec -
   -   tv1-tv_usec;
   -   return deltv;
   +   /* return the delta in 32bit usecs, but cap to UINTMAX in case the
   +* delta is greater then 32bits */
   +   return (long) min((unsigned int) ktime_us_delta(t1, t2), 
   UINT_MAX);
}
  
  This probably needs some close review from the media folks. Thinking
  about it more, I'm really not certain the 15sec cap was to avoid a
  32bit overflow or if there's some other subtle undocumented reason.
 
 The new code is clearly wrong, as the cast to 'unsigned int' already truncates
 the value to at most UINT_MAX, and the min() does not have any effect.
 
 The correct way to write what was intended here is
 
   return min_t(long long, ktime_us_delta(t1, t2), UINT_MAX);
 
 which will truncate delta to an unsigned integer. The return type of the
 delta() function would need to be changed to 'unsigned long' as well to
 make this work.
 
 However, I think you are right that we should probably not change the
 behavior, unless someone who understands the purpose better can say
 what it really should be. 

Inside the remote controller code, we have measurements for pulse/space
encodings on a IR transmission. The duration of a pulse or space is
generally in the other of microseconds. On the standard protocols, the
maximum duration is on NEC protocol, where a pulse of 9 ms is sent at
the beginning:
http://www.sbprojects.com/knowledge/ir/nec.php

It should be noticed that bigger time intervals can be used to indicate
key repeat. Again, in the NEC protocol, the space between key repeats
are 110 ms.

So, everything above 110 ms is actually an infinite time.

As the Kernel implementation was built to be generic enough, we consider
(u32)-1 (e. g. about 4 seconds) as the maximum possible time.

This is due to the fact that some IR protocols use u32 for the pulse/space
time shifts. So, any duration bigger than that could actually be
rounded to (u32)-1.

That's said, I really don't see the need of fixing it on the y2038
patchset. All that it is needed is to warrant that the time difference
will be positive.

I would, instead, remove the delta function, and replace:

do_gettimeofday(curr_tv);
deltv = delta(last_tv, curr_tv);

(and other equivalent parts)

By an equivalent logic that would be reading the timestamp from a
high precision clock.

That's said, I suspect that this driver is broken, as I doubt that
do_gettimeofday() gets enough precision needed for IR decoding. Also,
as this returns a non-monotonic timestamp, it will break if one adjusts
the clock while IR keys are being pressed.

Regards,
Mauro


 I'd probably change teh above to
 
   long delta_us = ktime_us_delta(t1, t2);
   return min(delta_us, PULSE_MASK);
 
   Arnd
 --
 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


Re: v4.1-rcX regression in v4l2 build

2015-05-13 Thread Robert Jarzmik
Russell King - ARM Linux li...@arm.linux.org.uk writes:

 On Wed, May 13, 2015 at 09:26:03PM +0200, Robert Jarzmik wrote:
 First, a question for Russell :
   Given that the current PXA architecture is not implementing the
   clk_round_rate() function, while implementing clk_get(), etc..., is it 
 correct
   to say that it is betraying the clk API by doing so ?

 Really, yes.  PXA used to be self-contained as far as clk API usage, and
 so it only ever implemented what it needed from the API to support the
 SoC.  Now that things are getting more complicated then the other
 functions will probably be needed.
So I thought, thanks.

Cheers.

-- 
Robert
--
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 2/4] dw2102: remove unnecessary newline from log printouts

2015-05-13 Thread Mauro Carvalho Chehab
Em Tue,  5 May 2015 19:33:53 +0300
Olli Salonen olli.salo...@iki.fi escreveu:

 The info and warn functions already add a newline to the end of the
 log printouts, so remove the extra newline from the printouts.

Hi Olli,

The best here would be to convert this driver to use dvb-usb2, and replace
the usage of warn()/info()/dprintk() by the standard driver printk macros:
dev_info()/dev_warn()/...

Regards,
Mauro

 
 Signed-off-by: Olli Salonen olli.salo...@iki.fi
 ---
  drivers/media/usb/dvb-usb/dw2102.c | 60 
 +++---
  1 file changed, 30 insertions(+), 30 deletions(-)
 
 diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
 b/drivers/media/usb/dvb-usb/dw2102.c
 index 4ad6bb2..b1f8a3f 100644
 --- a/drivers/media/usb/dvb-usb/dw2102.c
 +++ b/drivers/media/usb/dvb-usb/dw2102.c
 @@ -307,7 +307,7 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter 
 *adap, struct i2c_msg ms
   u8 ibuf[MAX_XFER_SIZE], obuf[3];
  
   if (2 + msg[1].len  sizeof(ibuf)) {
 - warn(i2c rd: len=%d is too big!\n,
 + warn(i2c rd: len=%d is too big!,
msg[1].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -332,7 +332,7 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter 
 *adap, struct i2c_msg ms
   u8 obuf[MAX_XFER_SIZE];
  
   if (2 + msg[0].len  sizeof(obuf)) {
 - warn(i2c wr: len=%d is too big!\n,
 + warn(i2c wr: len=%d is too big!,
msg[1].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -350,7 +350,7 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter 
 *adap, struct i2c_msg ms
   u8 obuf[MAX_XFER_SIZE];
  
   if (2 + msg[0].len  sizeof(obuf)) {
 - warn(i2c wr: len=%d is too big!\n,
 + warn(i2c wr: len=%d is too big!,
msg[1].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -426,7 +426,7 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, 
 struct i2c_msg msg[], i
   u8  ibuf[MAX_XFER_SIZE];
  
   if (2 + msg[j].len  sizeof(ibuf)) {
 - warn(i2c rd: len=%d is too big!\n,
 + warn(i2c rd: len=%d is too big!,
msg[j].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -463,7 +463,7 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, 
 struct i2c_msg msg[], i
   u8 obuf[MAX_XFER_SIZE];
  
   if (2 + msg[j].len  sizeof(obuf)) {
 - warn(i2c wr: len=%d is too big!\n,
 + warn(i2c wr: len=%d is too big!,
msg[j].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -507,7 +507,7 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, 
 struct i2c_msg msg[],
   u8 ibuf[MAX_XFER_SIZE], obuf[3];
  
   if (2 + msg[1].len  sizeof(ibuf)) {
 - warn(i2c rd: len=%d is too big!\n,
 + warn(i2c rd: len=%d is too big!,
msg[1].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -532,7 +532,7 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, 
 struct i2c_msg msg[],
   u8 obuf[MAX_XFER_SIZE];
  
   if (2 + msg[0].len  sizeof(obuf)) {
 - warn(i2c wr: len=%d is too big!\n,
 + warn(i2c wr: len=%d is too big!,
msg[0].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -623,7 +623,7 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, 
 struct i2c_msg msg[],
   u8 ibuf[MAX_XFER_SIZE];
  
   if (msg[j].len  sizeof(ibuf)) {
 - warn(i2c rd: len=%d is too big!\n,
 + warn(i2c rd: len=%d is too big!,
msg[j].len);
   ret = -EOPNOTSUPP;
   goto unlock;
 @@ -658,7 +658,7 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, 
 struct i2c_msg msg[],
   u8 obuf[MAX_XFER_SIZE];
  
   if (2 + msg[j].len  sizeof(obuf)) {
 - 

[PATCH] [media] dib0700: avoid the risk of forgetting to add the adapter's size

2015-05-13 Thread Mauro Carvalho Chehab
For every frontend entry, we need to add the adapter's size. There
are already two patches fixing it. So, it doesn't seem trivial to
keep it there at the right place.

Also, currently, the indentation is wrong on all places.

So, it seems that keeping it right is not too trivial.

Better to use a macro that would do it for us, at least while
this is not converted to dvb-usb-v2.

Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com

diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index e87ce835dcbd..5a3dbb8c7658 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -3821,6 +3821,10 @@ MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
} \
}
 
+#define DIB0700_NUM_FRONTENDS(n) \
+   .num_frontends = n, \
+   .size_of_priv = sizeof(struct dib0700_adapter_state)
+
 struct dvb_usb_device_properties dib0700_devices[] = {
{
DIB0700_DEFAULT_DEVICE_PROPERTIES,
@@ -3828,7 +3832,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
.num_adapters = 1,
.adapter = {
{
-   .num_frontends = 1,
+   DIB0700_NUM_FRONTENDS(1),
.fe = {{
.caps = DVB_USB_ADAP_HAS_PID_FILTER | 
DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
.pid_filter_count = 32,
@@ -3839,7 +3843,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
 
DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
}},
-   .size_of_priv = sizeof(struct 
dib0700_adapter_state),
},
},
 
@@ -3893,7 +3896,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
.num_adapters = 2,
.adapter = {
{
-   .num_frontends = 1,
+   DIB0700_NUM_FRONTENDS(1),
.fe = {{
.frontend_attach  = bristol_frontend_attach,
.tuner_attach = bristol_tuner_attach,
@@ -3901,7 +3904,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
}},
}, {
-   .num_frontends = 1,
+   DIB0700_NUM_FRONTENDS(1),
.fe = {{
.frontend_attach  = bristol_frontend_attach,
.tuner_attach = bristol_tuner_attach,
@@ -3933,7 +3936,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
.num_adapters = 2,
.adapter = {
{
-   .num_frontends = 1,
+   DIB0700_NUM_FRONTENDS(1),
.fe = {{
.caps = DVB_USB_ADAP_HAS_PID_FILTER | 
DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
.pid_filter_count = 32,
@@ -3944,10 +3947,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
 
DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
}},
-   .size_of_priv = sizeof(struct
-   dib0700_adapter_state),
}, {
-   .num_frontends = 1,
+   DIB0700_NUM_FRONTENDS(1),
.fe = {{
.caps = DVB_USB_ADAP_HAS_PID_FILTER | 
DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
.pid_filter_count = 32,
@@ -3958,8 +3959,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
 
DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
}},
-   .size_of_priv = sizeof(struct
-   dib0700_adapter_state),
}
},
 
@@ -4002,7 +4001,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
.num_adapters = 1,
.adapter = {
{
-   .num_frontends = 1,
+   DIB0700_NUM_FRONTENDS(1),
.fe = {{
.caps = DVB_USB_ADAP_HAS_PID_FILTER | 
DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
.pid_filter_count = 32,
@@ -4013,8 +4012,6 @@ struct dvb_usb_device_properties dib0700_devices[] = {
 
DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
}},
-   .size_of_priv = sizeof(struct
-   dib0700_adapter_state),
  

Re: [Y2038] [PATCH v3] Staging: media: Replace timeval with ktime_t

2015-05-13 Thread Mauro Carvalho Chehab
Em Wed, 13 May 2015 14:45:38 -0700
John Stultz john.stu...@linaro.org escreveu:

 On Wed, May 13, 2015 at 2:10 PM, Mauro Carvalho Chehab
 mche...@osg.samsung.com wrote:
  Em Wed, 13 May 2015 21:53:07 +0200
  Arnd Bergmann a...@arndb.de escreveu:
 
  On Wednesday 13 May 2015 10:04:48 John Stultz wrote:
   On Wed, May 13, 2015 at 9:57 AM, Ksenija Stanojevic
   ksenija.stanoje...@gmail.com wrote:
'struct timeval last_tv' is used to get the time of last signal change
and 'struct timeval last_intr_tv' is used to get the time of last UART
interrupt.
32-bit systems using 'struct timeval' will break in the year 2038, so 
we
have to replace that code with more appropriate types.
Here struct timeval is replaced with ktime_t.
   
Signed-off-by: Ksenija Stanojevic ksenija.stanoje...@gmail.com
 
  An additional comment: as drivers/staging/media refers to a whole subsystem
  with mutually independent drivers, the subject line should mention 'lirc',
  either in addition to, or instead of 'media'.
 
-static long delta(struct timeval *tv1, struct timeval *tv2)
+static inline long delta(ktime_t t1, ktime_t t2)
 {
-   unsigned long deltv;
-
-   deltv = tv2-tv_sec - tv1-tv_sec;
-   if (deltv  15)
-   deltv = 0xFF;
-   else
-   deltv = deltv*100 +
-   tv2-tv_usec -
-   tv1-tv_usec;
-   return deltv;
+   /* return the delta in 32bit usecs, but cap to UINTMAX in case 
the
+* delta is greater then 32bits */
+   return (long) min((unsigned int) ktime_us_delta(t1, t2), 
UINT_MAX);
 }
  
   This probably needs some close review from the media folks. Thinking
   about it more, I'm really not certain the 15sec cap was to avoid a
   32bit overflow or if there's some other subtle undocumented reason.
 
  The new code is clearly wrong, as the cast to 'unsigned int' already 
  truncates
  the value to at most UINT_MAX, and the min() does not have any effect.
 
  The correct way to write what was intended here is
 
return min_t(long long, ktime_us_delta(t1, t2), UINT_MAX);
 
  which will truncate delta to an unsigned integer. The return type of the
  delta() function would need to be changed to 'unsigned long' as well to
  make this work.
 
  However, I think you are right that we should probably not change the
  behavior, unless someone who understands the purpose better can say
  what it really should be.
 
  Inside the remote controller code, we have measurements for pulse/space
  encodings on a IR transmission. The duration of a pulse or space is
  generally in the other of microseconds. On the standard protocols, the
  maximum duration is on NEC protocol, where a pulse of 9 ms is sent at
  the beginning:
  http://www.sbprojects.com/knowledge/ir/nec.php
 
  It should be noticed that bigger time intervals can be used to indicate
  key repeat. Again, in the NEC protocol, the space between key repeats
  are 110 ms.
 
  So, everything above 110 ms is actually an infinite time.
 
  As the Kernel implementation was built to be generic enough, we consider
  (u32)-1 (e. g. about 4 seconds) as the maximum possible time.
 
 So that's ~4 seconds of nanoseconds, but since we're talking usecs,
 UINT_MAX is something like 70-some minutes.

Well this is a staging driver. The ones outside staging use nanoseconds
internally.

Btw, on almost all non-staging drivers, the timer is provided by the
hardware, and not measured using do_gettimeofday (or similar).

The drivers at staging are actually for the older legacy remote
controllers. Those drivers are there basically because nobody
cared enough to convert them to use the Remote Controller subsystem.

I wouldn't mind if we decide to remove those drivers due to Y2038
changes ;)

  This is due to the fact that some IR protocols use u32 for the pulse/space
  time shifts. So, any duration bigger than that could actually be
  rounded to (u32)-1.
 
 Sure. The part that confused me is that the delta function is checking
 if the second delta is larger then 15 seconds, and I couldn't quite
 understand the significance of that check. If it really is just to
 make sure the timeval - usec conversion doesn't overflow, then that's
 easy enough to solve. But if the 15 second check has some other
 meaning, we'd want to understand before changing this.

It is likely some maximum time. As I said, we're using ~4 second
checks internally at the Kernel.

I can't find any usage for a remote controller that would have a 15
seconds of timeout... actually, even 4 seconds is a long time ;)

  That's said, I really don't see the need of fixing it on the y2038
  patchset. All that it is needed is to warrant that the time difference
  will be positive.
 
  I would, instead, remove the delta function, and replace:
 
  do_gettimeofday(curr_tv);
  deltv = delta(last_tv, curr_tv);
 
  (and 

cron job: media_tree daily build: ERRORS

2015-05-13 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:   Thu May 14 04:00:16 CEST 2015
git branch: test
git hash:   e989a73ebd09d22c22ead51fa363a2f56f70f28a
gcc version:i686-linux-gcc (GCC) 5.1.0
sparse version: v0.5.0-44-g40791b9
smatch version: 0.4.1-3153-g7d56ab3
host hardware:  x86_64
host os:4.0.0-1.slh.2-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: WARNINGS
linux-git-arm-exynos: OK
linux-git-arm-mx: OK
linux-git-arm-omap: OK
linux-git-arm-omap1: OK
linux-git-arm-pxa: OK
linux-git-blackfin-bf561: 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.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: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.12.23-i686: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.16.7-i686: WARNINGS
linux-3.17.8-i686: WARNINGS
linux-3.18.7-i686: WARNINGS
linux-3.19-i686: WARNINGS
linux-4.0-i686: WARNINGS
linux-4.1-rc1-i686: 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.23-x86_64: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.7-x86_64: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.7-x86_64: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0-x86_64: WARNINGS
linux-4.1-rc1-x86_64: WARNINGS
apps: OK
spec-git: OK
sparse: ERRORS
smatch: ERRORS

Detailed results are available here:

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

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.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


[PATCH v3] Staging: media: Replace timeval with ktime_t

2015-05-13 Thread Ksenija Stanojevic
'struct timeval last_tv' is used to get the time of last signal change
and 'struct timeval last_intr_tv' is used to get the time of last UART
interrupt.
32-bit systems using 'struct timeval' will break in the year 2038, so we
have to replace that code with more appropriate types.
Here struct timeval is replaced with ktime_t.

Signed-off-by: Ksenija Stanojevic ksenija.stanoje...@gmail.com
---
Changes in v3:
- as John suggested delta function is changed to inline function,
checkpatch signals a warning to change min to min_t. Is it a false 
positive?
- change variable names.

Changes in v2:
- change subject line

 drivers/staging/media/lirc/lirc_sir.c | 51 +--
 1 file changed, 18 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/media/lirc/lirc_sir.c 
b/drivers/staging/media/lirc/lirc_sir.c
index 29087f6..c98c486 100644
--- a/drivers/staging/media/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
@@ -44,7 +44,7 @@
 #include linux/ioport.h
 #include linux/kernel.h
 #include linux/serial_reg.h
-#include linux/time.h
+#include linux/ktime.h
 #include linux/string.h
 #include linux/types.h
 #include linux/wait.h
@@ -127,9 +127,9 @@ static int threshold = 3;
 static DEFINE_SPINLOCK(timer_lock);
 static struct timer_list timerlist;
 /* time of last signal change detected */
-static struct timeval last_tv = {0, 0};
+static ktime_t last;
 /* time of last UART data ready interrupt */
-static struct timeval last_intr_tv = {0, 0};
+static ktime_t last_intr_time;
 static int last_value;
 
 static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
@@ -400,18 +400,11 @@ static void drop_chrdev(void)
 }
 
 /* SECTION: Hardware */
-static long delta(struct timeval *tv1, struct timeval *tv2)
+static inline long delta(ktime_t t1, ktime_t t2)
 {
-   unsigned long deltv;
-
-   deltv = tv2-tv_sec - tv1-tv_sec;
-   if (deltv  15)
-   deltv = 0xFF;
-   else
-   deltv = deltv*100 +
-   tv2-tv_usec -
-   tv1-tv_usec;
-   return deltv;
+   /* return the delta in 32bit usecs, but cap to UINTMAX in case the
+* delta is greater then 32bits */
+   return (long) min((unsigned int) ktime_us_delta(t1, t2), UINT_MAX);
 }
 
 static void sir_timeout(unsigned long data)
@@ -432,12 +425,12 @@ static void sir_timeout(unsigned long data)
/* clear unread bits in UART and restart */
outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
/* determine 'virtual' pulse end: */
-   pulse_end = delta(last_tv, last_intr_tv);
+   pulse_end = delta(last, last_intr_time);
dev_dbg(driver.dev, timeout add %d for %lu usec\n,
last_value, pulse_end);
add_read_queue(last_value, pulse_end);
last_value = 0;
-   last_tv = last_intr_tv;
+   last = last_intr_time;
}
spin_unlock_irqrestore(timer_lock, flags);
 }
@@ -445,7 +438,7 @@ static void sir_timeout(unsigned long data)
 static irqreturn_t sir_interrupt(int irq, void *dev_id)
 {
unsigned char data;
-   struct timeval curr_tv;
+   ktime_t curr_time;
static unsigned long deltv;
unsigned long deltintrtv;
unsigned long flags;
@@ -471,9 +464,9 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
do {
del_timer(timerlist);
data = inb(io + UART_RX);
-   do_gettimeofday(curr_tv);
-   deltv = delta(last_tv, curr_tv);
-   deltintrtv = delta(last_intr_tv, curr_tv);
+   curr_time = ktime_get();
+   deltv = delta(last, curr_time);
+   deltintrtv = delta(last_intr_time, curr_time);
dev_dbg(driver.dev, t %lu, d %d\n,
deltintrtv, (int)data);
/*
@@ -488,10 +481,7 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
   deltv -
   deltintrtv);
last_value = 0;
-   last_tv.tv_sec =
-   last_intr_tv.tv_sec;
-   last_tv.tv_usec =
-   last_intr_tv.tv_usec;
+   last = last_intr_time;
deltv = deltintrtv;
}
}
@@ -504,16 +494,11 @@ static 

Re: [PATCH v3] Staging: media: Replace timeval with ktime_t

2015-05-13 Thread John Stultz
On Wed, May 13, 2015 at 9:57 AM, Ksenija Stanojevic
ksenija.stanoje...@gmail.com wrote:
 'struct timeval last_tv' is used to get the time of last signal change
 and 'struct timeval last_intr_tv' is used to get the time of last UART
 interrupt.
 32-bit systems using 'struct timeval' will break in the year 2038, so we
 have to replace that code with more appropriate types.
 Here struct timeval is replaced with ktime_t.

 Signed-off-by: Ksenija Stanojevic ksenija.stanoje...@gmail.com
 ---
 Changes in v3:
 - as John suggested delta function is changed to inline function,
 checkpatch signals a warning to change min to min_t. Is it a false
 positive?
 - change variable names.

 Changes in v2:
 - change subject line

  drivers/staging/media/lirc/lirc_sir.c | 51 
 +--
  1 file changed, 18 insertions(+), 33 deletions(-)

 diff --git a/drivers/staging/media/lirc/lirc_sir.c 
 b/drivers/staging/media/lirc/lirc_sir.c
 index 29087f6..c98c486 100644
 --- a/drivers/staging/media/lirc/lirc_sir.c
 +++ b/drivers/staging/media/lirc/lirc_sir.c
 @@ -44,7 +44,7 @@
  #include linux/ioport.h
  #include linux/kernel.h
  #include linux/serial_reg.h
 -#include linux/time.h
 +#include linux/ktime.h
  #include linux/string.h
  #include linux/types.h
  #include linux/wait.h
 @@ -127,9 +127,9 @@ static int threshold = 3;
  static DEFINE_SPINLOCK(timer_lock);
  static struct timer_list timerlist;
  /* time of last signal change detected */
 -static struct timeval last_tv = {0, 0};
 +static ktime_t last;
  /* time of last UART data ready interrupt */
 -static struct timeval last_intr_tv = {0, 0};
 +static ktime_t last_intr_time;
  static int last_value;

  static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
 @@ -400,18 +400,11 @@ static void drop_chrdev(void)
  }

  /* SECTION: Hardware */
 -static long delta(struct timeval *tv1, struct timeval *tv2)
 +static inline long delta(ktime_t t1, ktime_t t2)
  {
 -   unsigned long deltv;
 -
 -   deltv = tv2-tv_sec - tv1-tv_sec;
 -   if (deltv  15)
 -   deltv = 0xFF;
 -   else
 -   deltv = deltv*100 +
 -   tv2-tv_usec -
 -   tv1-tv_usec;
 -   return deltv;
 +   /* return the delta in 32bit usecs, but cap to UINTMAX in case the
 +* delta is greater then 32bits */
 +   return (long) min((unsigned int) ktime_us_delta(t1, t2), UINT_MAX);
  }

This probably needs some close review from the media folks. Thinking
about it more, I'm really not certain the 15sec cap was to avoid a
32bit overflow or if there's some other subtle undocumented reason.

thanks
-john
--
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 2/2] [media] saa7134: fix CodingStyle issues on the lines touched by pr_foo refactor

2015-05-13 Thread Mauro Carvalho Chehab
Several lines touched by the pr_foo refactoring patches are not
following the Linux Coding style.

While we won't be fixing the style globally at the driver, we should,
at least, fix on the lines we touched.

Basically, this patch add (or remove) whitespaces and blank lines
where needed.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com

diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c 
b/drivers/media/pci/saa7134/saa7134-alsa.c
index 4199fbf9bc44..1d2c310ce838 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -161,7 +161,8 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
}
 
if (dev-dmasound.read_count = dev-dmasound.blksize * 
(dev-dmasound.blocks-2)) {
-   pr_debug(irq: overrun [full=%d/%d] - Blocks in 
%d\n,dev-dmasound.read_count,
+   pr_debug(irq: overrun [full=%d/%d] - Blocks in %d\n,
+   dev-dmasound.read_count,
dev-dmasound.bufsize, dev-dmasound.blocks);
spin_unlock(dev-slock);
snd_pcm_stop_xrun(dev-dmasound.substream);
@@ -173,7 +174,8 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
saa_writel(reg,next_blk * dev-dmasound.blksize);
pr_debug(irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, 
read=%u\n,
(status  0x1000) ? even : odd , next_blk,
-   next_blk * dev-dmasound.blksize, dev-dmasound.blocks, 
dev-dmasound.blksize, dev-dmasound.read_count);
+next_blk * dev-dmasound.blksize, dev-dmasound.blocks,
+dev-dmasound.blksize, dev-dmasound.read_count);
 
/* update status  wake waiting readers */
dev-dmasound.dma_blk = (dev-dmasound.dma_blk + 1) % 
dev-dmasound.blocks;
@@ -1186,7 +1188,8 @@ static int alsa_card_saa7134_create(struct saa7134_dev 
*dev, int devnum)
sprintf(card-longname, %s at 0x%lx irq %d,
chip-dev-name, chip-iobase, chip-irq);
 
-   pr_info(%s/alsa: %s registered as card 
%d\n,dev-name,card-longname,index[devnum]);
+   pr_info(%s/alsa: %s registered as card %d\n,
+   dev-name, card-longname, index[devnum]);
 
if ((err = snd_card_register(card)) == 0) {
snd_saa7134_cards[devnum] = card;
diff --git a/drivers/media/pci/saa7134/saa7134-cards.c 
b/drivers/media/pci/saa7134/saa7134-cards.c
index abbeeb923114..9fac6a9b7937 100644
--- a/drivers/media/pci/saa7134/saa7134-cards.c
+++ b/drivers/media/pci/saa7134/saa7134-cards.c
@@ -7516,7 +7516,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
pr_warn(%s: seems there are two different versions of the 
MD5044\n
%s: (with the same ID) out there.  If sound doesn't 
work for\n
%s: you try the audio_clock_override=0x20 insmod 
option.\n,
-   dev-name,dev-name,dev-name);
+   dev-name, dev-name, dev-name);
break;
case SAA7134_BOARD_CINERGY400_CARDBUS:
/* power-up tuner chip */
@@ -7644,7 +7644,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
pr_warn(%s: %s: dual saa713x broadcast decoders\n
%s: Sorry, none of the inputs to this chip are 
supported yet.\n
%s: Dual decoder functionality is disabled for now, 
use the other chip.\n,
-   dev-name,card(dev).name,dev-name,dev-name);
+   dev-name, card(dev).name, dev-name, dev-name);
break;
case SAA7134_BOARD_AVERMEDIA_M102:
/* enable tuner */
@@ -7826,7 +7826,8 @@ int saa7134_board_init2(struct saa7134_dev *dev)
dev-tuner_type = TUNER_PHILIPS_FM1216ME_MK3;
break;
default:
-   pr_err(%s Can't determine tuner type %x from 
EEPROM\n, dev-name, tuner_t);
+   pr_err(%s Can't determine tuner type %x from 
EEPROM\n,
+  dev-name, tuner_t);
}
} else if ((data[1] != 0)  (data[1] != 0xff)) {
/* new config structure */
@@ -7847,7 +7848,8 @@ int saa7134_board_init2(struct saa7134_dev *dev)
   dev-name);
break;
default:
-   pr_err(%s Can't determine tuner type %x from 
EEPROM\n, dev-name, tuner_t);
+   pr_err(%s Can't determine tuner type %x from 
EEPROM\n,
+  dev-name, tuner_t);
}
} else {
pr_err(%s unexpected config structure\n, dev-name);
diff --git a/drivers/media/pci/saa7134/saa7134-core.c 
b/drivers/media/pci/saa7134/saa7134-core.c
index 

[PATCH 1/2] [media] saa7134: avoid complex macro warnings

2015-05-13 Thread Mauro Carvalho Chehab
The debug macros are not properly defined, as they generate warnings
like:

ERROR: Macros with complex values should be enclosed in parentheses
+#define core_dbg(fmt, arg...)if (core_debug) \
+   printk(KERN_DEBUG pr_fmt(core:  fmt), ## arg)

Use do { } while (0) for those macros.

Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com

diff --git a/drivers/media/pci/saa7134/saa7134-core.c 
b/drivers/media/pci/saa7134/saa7134-core.c
index e88e4ec8c0ee..02a08770507d 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -102,11 +102,15 @@ static unsigned int saa7134_devcount;
 int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
 int (*saa7134_dmasound_exit)(struct saa7134_dev *dev);
 
-#define core_dbg(fmt, arg...)if (core_debug) \
-   printk(KERN_DEBUG pr_fmt(core:  fmt), ## arg)
+#define core_dbg(fmt, arg...) do { \
+   if (core_debug) \
+   printk(KERN_DEBUG pr_fmt(core:  fmt), ## arg); \
+   } while (0)
 
-#define irq_dbg(level, fmt, arg...)if (irq_debug  level) \
-   printk(KERN_DEBUG pr_fmt(irq:  fmt), ## arg)
+#define irq_dbg(level, fmt, arg...)  do {\
+   if (irq_debug  level) \
+   printk(KERN_DEBUG pr_fmt(irq:  fmt), ## arg); \
+   } while (0)
 
 void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
 {
diff --git a/drivers/media/pci/saa7134/saa7134-i2c.c 
b/drivers/media/pci/saa7134/saa7134-i2c.c
index d04fbdb49158..b90434b41efe 100644
--- a/drivers/media/pci/saa7134/saa7134-i2c.c
+++ b/drivers/media/pci/saa7134/saa7134-i2c.c
@@ -41,11 +41,15 @@ static unsigned int i2c_scan;
 module_param(i2c_scan, int, 0444);
 MODULE_PARM_DESC(i2c_scan,scan i2c bus at insmod time);
 
-#define i2c_dbg(level, fmt, arg...)if (i2c_debug == level) \
-   printk(KERN_DEBUG pr_fmt(i2c:  fmt), ## arg)
+#define i2c_dbg(level, fmt, arg...) do { \
+   if (i2c_debug == level) \
+   printk(KERN_DEBUG pr_fmt(i2c:  fmt), ## arg); \
+   } while (0)
 
-#define i2c_cont(level, fmt, arg...)if (i2c_debug == level) \
-   pr_cont(fmt, ## arg)
+#define i2c_cont(level, fmt, arg...) do { \
+   if (i2c_debug == level) \
+   pr_cont(fmt, ## arg); \
+   } while (0)
 
 #define I2C_WAIT_DELAY  32
 #define I2C_WAIT_RETRY  16
diff --git a/drivers/media/pci/saa7134/saa7134-input.c 
b/drivers/media/pci/saa7134/saa7134-input.c
index c6036557b468..e92bcfe9bbcb 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -41,10 +41,14 @@ static int pinnacle_remote;
 module_param(pinnacle_remote, int, 0644);/* Choose Pinnacle PCTV remote */
 MODULE_PARM_DESC(pinnacle_remote, Specify Pinnacle PCTV remote: 0=coloured, 
1=grey (defaults to 0));
 
-#define input_dbg(fmt, arg...) if (ir_debug) \
-   printk(KERN_DEBUG pr_fmt(input:  fmt), ## arg)
-#define ir_dbg(ir, fmt, arg...)if (ir_debug) \
-   printk(KERN_DEBUG pr_fmt(ir %s:  fmt), ir-name, ## arg)
+#define input_dbg(fmt, arg...) do { \
+   if (ir_debug) \
+   printk(KERN_DEBUG pr_fmt(input:  fmt), ## arg); \
+   } while (0)
+#define ir_dbg(ir, fmt, arg...) do { \
+   if (ir_debug) \
+   printk(KERN_DEBUG pr_fmt(ir %s:  fmt), ir-name, ## arg); \
+   } while (0)
 
 /* Helper function for raw decoding at GPIO16 or GPIO18 */
 static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c 
b/drivers/media/pci/saa7134/saa7134-ts.c
index 5d7c4afac8e6..07ca32f1b6d9 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -35,8 +35,10 @@ static unsigned int ts_debug;
 module_param(ts_debug, int, 0644);
 MODULE_PARM_DESC(ts_debug,enable debug messages [ts]);
 
-#define ts_dbg(fmt, arg...)if (ts_debug) \
-   printk(KERN_DEBUG pr_fmt(ts:  fmt), ## arg)
+#define ts_dbg(fmt, arg...) do { \
+   if (ts_debug) \
+   printk(KERN_DEBUG pr_fmt(ts:  fmt), ## arg); \
+   } while (0)
 
 /* -- */
 static int buffer_activate(struct saa7134_dev *dev,
diff --git a/drivers/media/pci/saa7134/saa7134-tvaudio.c 
b/drivers/media/pci/saa7134/saa7134-tvaudio.c
index 6320b64d3528..1a960a1b07b5 100644
--- a/drivers/media/pci/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/pci/saa7134/saa7134-tvaudio.c
@@ -49,8 +49,10 @@ static int audio_clock_tweak;
 module_param(audio_clock_tweak, int, 0644);
 MODULE_PARM_DESC(audio_clock_tweak, Audio clock tick fine tuning for cards 
with audio crystal that's slightly off (range [-1024 .. 1024]));
 
-#define audio_dbg(level, fmt, arg...)if (audio_debug = level) \
-   printk(KERN_DEBUG pr_fmt(audio:  fmt), ## arg)
+#define audio_dbg(level, fmt, arg...) do { \
+   if (audio_debug = level) \
+   printk(KERN_DEBUG pr_fmt(audio:  fmt), ## arg); \
+   } while (0)
 
 /* msecs */
 #define SCAN_INITIAL_DELAY 1000
diff 

[PATCH] s5p-mfc: fix state check from encoder queue_setup

2015-05-13 Thread Seung-Woo Kim
MFCINST_GOT_INST state is set to encoder context with set_format
only for catpure buffer. In queue_setup of encoder called during
reqbufs, it is checked MFCINST_GOT_INST state for both capture
and output buffer. So this patch fixes to encoder to check
MFCINST_GOT_INST state only for capture buffer from queue_setup.

Signed-off-by: Seung-Woo Kim sw0312@samsung.com
---
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c |9 +
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c 
b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index e65993f..2e57e9f 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1819,11 +1819,12 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
struct s5p_mfc_ctx *ctx = fh_to_ctx(vq-drv_priv);
struct s5p_mfc_dev *dev = ctx-dev;
 
-   if (ctx-state != MFCINST_GOT_INST) {
-   mfc_err(inavlid state: %d\n, ctx-state);
-   return -EINVAL;
-   }
if (vq-type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+   if (ctx-state != MFCINST_GOT_INST) {
+   mfc_err(inavlid state: %d\n, ctx-state);
+   return -EINVAL;
+   }
+
if (ctx-dst_fmt)
*plane_count = ctx-dst_fmt-num_planes;
else
-- 
1.7.4.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: [PATCHv2 0/5] cobalt: new HDMI Rx/Tx PCIe driver

2015-05-13 Thread Hans Verkuil
Oops, I forgot to mention that patches 1-4 are unchanged from v1. Also,
if there are no comments about this driver, then I intend to make a pull
request on Monday.

Regards,

Hans


On 05/13/15 09:22, Hans Verkuil wrote:
 From: Hans Verkuil hans.verk...@cisco.com
 
 Changes since v1:
 
 - Fixed a lockdep bug in the alsa driver
 - Moved the DMA descriptor allocation/freeing to buf_init and buf_cleanup,
   which is where it belongs.
 - Rebased to the latest media_tree master.
 
 Hi all,
 
 This driver is for the Cisco Cobalt card, which is a PCIe device with four
 HDMI inputs (adv7604) and optionally one fifth input (adv7842) or one output
 (adv7511).
 
 This board is not for sale (sadly) but it is used internally for testing and
 prototyping. Many of the HDMI/Digital Video related features that I have added
 to V4L2 over the last few years have been prototyped using this driver and I
 am planning more new features based on this board.
 
 During the ELC in San Jose a month back I discussed whether it would be OK to
 upstream this driver, even though the hardware is not for sale. Mauro had no
 problem with this and given the fact that this driver is a good starting
 point for similar HDMI hardware, and that this allows me to upstream new
 API additions showing them off in this driver (so ensuring that they are
 actually used somewhere), I've decided to go ahead with this.
 
 This patch series starts off with a few improvements to other drivers:
 
 The adv7842 now makes the output pixel port format configurable, just like
 its cousin adv7604. Note that there is one user of adv7842_platform_data:
 arch/blackfin/mach-bf609/boards/ezkit.c. However, this board code has been
 broken from the beginning and nobody noticed since gcc doesn't support the
 bf609. You need a custom toolchain to compile this 
 
 I can't do anything about this, someone (Scott Jiang?) will need to fix
 this.
 
 The next patch makes it possible to requeue buffers in vb2 from the driver.
 It's a very small change, but the cobalt driver uses that while it is
 waiting for a stable video signal.
 
 The next patch is from Jean-Michel Hautbois which hasn't been merged yet
 since no driver used that event, but in the next patch I implement it.
 
 The final patch is the cobalt driver itself.
 
 Note that the m00* headers are generated from our FPGA code (slightly
 cleaned up by hand), which is why there are many lines  80 columns.
 It makes sense in this case and it does not affect the readability, and
 I don't want to edit them too much since that would make it hard to handle
 when they are regenerated due to FPGA changes.
 
 And there are also a lot of volatile __iomem pointers: the memory-mapped
 registers are written and read directly using struct pointers, so you really
 need volatile __iomem there.
 
 In the near future I plan on added CEC support (once the CEC framework has
 been merged), colorspace conversion support, possibly deep color support and
 more. But let's try to get this driver in first.
 
 Regards,
 
   Hans
   
 Hans Verkuil (4):
   adv7842: Make output format configurable through pad format operations
   vb2: allow requeuing buffers while streaming
   adv7604/adv7842: replace FMT_CHANGED by V4L2_DEVICE_NOTIFY_EVENT
   cobalt: add new driver
 
 jean-michel.hautb...@vodalys.com (1):
   v4l2-subdev: allow subdev to send an event to the v4l2_device notify
 function
 
  Documentation/video4linux/v4l2-framework.txt   |4 +
  MAINTAINERS|8 +
  drivers/media/i2c/adv7604.c|   12 +-
  drivers/media/i2c/adv7842.c|  280 -
  drivers/media/pci/Kconfig  |1 +
  drivers/media/pci/Makefile |1 +
  drivers/media/pci/cobalt/Kconfig   |   18 +
  drivers/media/pci/cobalt/Makefile  |5 +
  drivers/media/pci/cobalt/cobalt-alsa-main.c|  162 +++
  drivers/media/pci/cobalt/cobalt-alsa-pcm.c |  603 ++
  drivers/media/pci/cobalt/cobalt-alsa-pcm.h |   22 +
  drivers/media/pci/cobalt/cobalt-alsa.h |   41 +
  drivers/media/pci/cobalt/cobalt-cpld.c |  341 ++
  drivers/media/pci/cobalt/cobalt-cpld.h |   29 +
  drivers/media/pci/cobalt/cobalt-driver.c   |  821 +
  drivers/media/pci/cobalt/cobalt-driver.h   |  377 ++
  drivers/media/pci/cobalt/cobalt-flash.c|  132 ++
  drivers/media/pci/cobalt/cobalt-flash.h|   29 +
  drivers/media/pci/cobalt/cobalt-i2c.c  |  396 ++
  drivers/media/pci/cobalt/cobalt-i2c.h  |   25 +
  drivers/media/pci/cobalt/cobalt-irq.c  |  254 
  drivers/media/pci/cobalt/cobalt-irq.h  |   25 +
  drivers/media/pci/cobalt/cobalt-omnitek.c  |  341 ++
  drivers/media/pci/cobalt/cobalt-omnitek.h  |   62 +
  

[PATCHv2 3/5] v4l2-subdev: allow subdev to send an event to the v4l2_device notify function

2015-05-13 Thread Hans Verkuil
From: jean-michel.hautb...@vodalys.com jean-michel.hautb...@vodalys.com

All drivers use custom notifications, in particular when source changes.
The bridge only has to map the subdev that sends it to whatever video node it 
is connected to.

Signed-off-by: Jean-Michel Hautbois jean-michel.hautb...@vodalys.com
---
 Documentation/video4linux/v4l2-framework.txt | 4 
 include/media/v4l2-subdev.h  | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/Documentation/video4linux/v4l2-framework.txt 
b/Documentation/video4linux/v4l2-framework.txt
index 59e619f..75d5c18 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -1129,6 +1129,10 @@ available event type is 'class base + 1'.
 An example on how the V4L2 events may be used can be found in the OMAP
 3 ISP driver (drivers/media/platform/omap3isp).
 
+A subdev can directly send an event to the v4l2_device notify function with
+V4L2_DEVICE_NOTIFY_EVENT. This allows the bridge to map the subdev that sends
+the event to the video node(s) associated with the subdev that need to be
+informed about such an event.
 
 V4L2 clocks
 ---
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 8f5da73..dc20102 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -40,6 +40,8 @@
 #define V4L2_SUBDEV_IR_TX_NOTIFY   _IOW('v', 1, u32)
 #define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x0001
 
+#defineV4L2_DEVICE_NOTIFY_EVENT_IOW('v', 2, struct 
v4l2_event)
+
 struct v4l2_device;
 struct v4l2_ctrl_handler;
 struct v4l2_event_subscription;
-- 
2.1.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


[PATCHv2 2/5] vb2: allow requeuing buffers while streaming

2015-05-13 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

vb2_buffer_done() already allows STATE_QUEUED, but currently only when not
streaming. It is useful to allow it while streaming as well, as this makes
it possible for drivers to requeue buffers while waiting for a stable
video signal.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 552d7e1..1a096a6 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -182,6 +182,7 @@ module_param(debug, int, 0644);
 V4L2_BUF_FLAG_KEYFRAME | 
V4L2_BUF_FLAG_TIMECODE)
 
 static void __vb2_queue_cancel(struct vb2_queue *q);
+static void __enqueue_in_driver(struct vb2_buffer *vb);
 
 /**
  * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
@@ -1153,8 +1154,9 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
 /**
  * vb2_buffer_done() - inform videobuf that an operation on a buffer is 
finished
  * @vb:vb2_buffer returned from the driver
- * @state: either VB2_BUF_STATE_DONE if the operation finished successfully
- * or VB2_BUF_STATE_ERROR if the operation finished with an error.
+ * @state: either VB2_BUF_STATE_DONE if the operation finished 
successfully,
+ * VB2_BUF_STATE_ERROR if the operation finished with an error or
+ * VB2_BUF_STATE_QUEUED if the driver wants to requeue buffers.
  * If start_streaming fails then it should return buffers with 
state
  * VB2_BUF_STATE_QUEUED to put them back into the queue.
  *
@@ -1205,8 +1207,11 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum 
vb2_buffer_state state)
atomic_dec(q-owned_by_drv_count);
spin_unlock_irqrestore(q-done_lock, flags);
 
-   if (state == VB2_BUF_STATE_QUEUED)
+   if (state == VB2_BUF_STATE_QUEUED) {
+   if (q-start_streaming_called)
+   __enqueue_in_driver(vb);
return;
+   }
 
/* Inform any processes that may be waiting for buffers */
wake_up(q-done_wq);
-- 
2.1.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


[PATCHv2 4/5] adv7604/adv7842: replace FMT_CHANGED by V4L2_DEVICE_NOTIFY_EVENT

2015-05-13 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This makes it easier for the bridge driver to just passthrough such
events to the corresponding device node.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/i2c/adv7604.c | 12 +---
 drivers/media/i2c/adv7842.c | 11 +--
 include/media/adv7604.h |  1 -
 include/media/adv7842.h |  3 ---
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index be3f866..aaa37b0 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -341,6 +341,11 @@ static const struct adv76xx_video_standards 
adv76xx_prim_mode_hdmi_gr[] = {
{ },
 };
 
+static const struct v4l2_event adv76xx_ev_fmt = {
+   .type = V4L2_EVENT_SOURCE_CHANGE,
+   .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
+};
+
 /* --- */
 
 static inline struct adv76xx_state *to_state(struct v4l2_subdev *sd)
@@ -1744,11 +1749,11 @@ static int adv76xx_s_routing(struct v4l2_subdev *sd,
state-selected_input = input;
 
disable_input(sd);
-
select_input(sd);
-
enable_input(sd);
 
+   v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
+  (void *)adv76xx_ev_fmt);
return 0;
 }
 
@@ -1915,7 +1920,8 @@ static int adv76xx_isr(struct v4l2_subdev *sd, u32 
status, bool *handled)
%s: fmt_change = 0x%x, fmt_change_digital = 0x%x\n,
__func__, fmt_change, fmt_change_digital);
 
-   v4l2_subdev_notify(sd, ADV76XX_FMT_CHANGE, NULL);
+   v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
+  (void *)adv76xx_ev_fmt);
 
if (handled)
*handled = true;
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index dceabc2..f5248ba 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -242,6 +242,11 @@ static const struct adv7842_video_standards 
adv7842_prim_mode_hdmi_gr[] = {
{ },
 };
 
+static const struct v4l2_event adv7842_ev_fmt = {
+   .type = V4L2_EVENT_SOURCE_CHANGE,
+   .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
+};
+
 /* --- */
 
 static inline struct adv7842_state *to_state(struct v4l2_subdev *sd)
@@ -1975,7 +1980,8 @@ static int adv7842_s_routing(struct v4l2_subdev *sd,
select_input(sd, state-vid_std_select);
enable_input(sd);
 
-   v4l2_subdev_notify(sd, ADV7842_FMT_CHANGE, NULL);
+   v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
+  (void *)adv7842_ev_fmt);
 
return 0;
 }
@@ -2208,7 +2214,8 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 
status, bool *handled)
 %s: fmt_change_cp = 0x%x, fmt_change_digital = 0x%x, 
fmt_change_sdp = 0x%x\n,
 __func__, fmt_change_cp, fmt_change_digital,
 fmt_change_sdp);
-   v4l2_subdev_notify(sd, ADV7842_FMT_CHANGE, NULL);
+   v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT,
+  (void *)adv7842_ev_fmt);
if (handled)
*handled = true;
}
diff --git a/include/media/adv7604.h b/include/media/adv7604.h
index 9ecf353..a913859 100644
--- a/include/media/adv7604.h
+++ b/include/media/adv7604.h
@@ -168,6 +168,5 @@ enum adv76xx_pad {
 
 /* notify events */
 #define ADV76XX_HOTPLUG1
-#define ADV76XX_FMT_CHANGE 2
 
 #endif
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index 64a66d0..1f38db8 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -230,9 +230,6 @@ struct adv7842_platform_data {
 #define V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL  (V4L2_CID_DV_CLASS_BASE + 
0x1001)
 #define V4L2_CID_ADV_RX_FREE_RUN_COLOR (V4L2_CID_DV_CLASS_BASE + 
0x1002)
 
-/* notify events */
-#define ADV7842_FMT_CHANGE 1
-
 /* custom ioctl, used to test the external RAM that's used by the
  * deinterlacer. */
 #define ADV7842_CMD_RAM_TEST _IO('V', BASE_VIDIOC_PRIVATE)
-- 
2.1.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


[PATCHv2 0/5] cobalt: new HDMI Rx/Tx PCIe driver

2015-05-13 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Changes since v1:

- Fixed a lockdep bug in the alsa driver
- Moved the DMA descriptor allocation/freeing to buf_init and buf_cleanup,
  which is where it belongs.
- Rebased to the latest media_tree master.

Hi all,

This driver is for the Cisco Cobalt card, which is a PCIe device with four
HDMI inputs (adv7604) and optionally one fifth input (adv7842) or one output
(adv7511).

This board is not for sale (sadly) but it is used internally for testing and
prototyping. Many of the HDMI/Digital Video related features that I have added
to V4L2 over the last few years have been prototyped using this driver and I
am planning more new features based on this board.

During the ELC in San Jose a month back I discussed whether it would be OK to
upstream this driver, even though the hardware is not for sale. Mauro had no
problem with this and given the fact that this driver is a good starting
point for similar HDMI hardware, and that this allows me to upstream new
API additions showing them off in this driver (so ensuring that they are
actually used somewhere), I've decided to go ahead with this.

This patch series starts off with a few improvements to other drivers:

The adv7842 now makes the output pixel port format configurable, just like
its cousin adv7604. Note that there is one user of adv7842_platform_data:
arch/blackfin/mach-bf609/boards/ezkit.c. However, this board code has been
broken from the beginning and nobody noticed since gcc doesn't support the
bf609. You need a custom toolchain to compile this 

I can't do anything about this, someone (Scott Jiang?) will need to fix
this.

The next patch makes it possible to requeue buffers in vb2 from the driver.
It's a very small change, but the cobalt driver uses that while it is
waiting for a stable video signal.

The next patch is from Jean-Michel Hautbois which hasn't been merged yet
since no driver used that event, but in the next patch I implement it.

The final patch is the cobalt driver itself.

Note that the m00* headers are generated from our FPGA code (slightly
cleaned up by hand), which is why there are many lines  80 columns.
It makes sense in this case and it does not affect the readability, and
I don't want to edit them too much since that would make it hard to handle
when they are regenerated due to FPGA changes.

And there are also a lot of volatile __iomem pointers: the memory-mapped
registers are written and read directly using struct pointers, so you really
need volatile __iomem there.

In the near future I plan on added CEC support (once the CEC framework has
been merged), colorspace conversion support, possibly deep color support and
more. But let's try to get this driver in first.

Regards,

Hans

Hans Verkuil (4):
  adv7842: Make output format configurable through pad format operations
  vb2: allow requeuing buffers while streaming
  adv7604/adv7842: replace FMT_CHANGED by V4L2_DEVICE_NOTIFY_EVENT
  cobalt: add new driver

jean-michel.hautb...@vodalys.com (1):
  v4l2-subdev: allow subdev to send an event to the v4l2_device notify
function

 Documentation/video4linux/v4l2-framework.txt   |4 +
 MAINTAINERS|8 +
 drivers/media/i2c/adv7604.c|   12 +-
 drivers/media/i2c/adv7842.c|  280 -
 drivers/media/pci/Kconfig  |1 +
 drivers/media/pci/Makefile |1 +
 drivers/media/pci/cobalt/Kconfig   |   18 +
 drivers/media/pci/cobalt/Makefile  |5 +
 drivers/media/pci/cobalt/cobalt-alsa-main.c|  162 +++
 drivers/media/pci/cobalt/cobalt-alsa-pcm.c |  603 ++
 drivers/media/pci/cobalt/cobalt-alsa-pcm.h |   22 +
 drivers/media/pci/cobalt/cobalt-alsa.h |   41 +
 drivers/media/pci/cobalt/cobalt-cpld.c |  341 ++
 drivers/media/pci/cobalt/cobalt-cpld.h |   29 +
 drivers/media/pci/cobalt/cobalt-driver.c   |  821 +
 drivers/media/pci/cobalt/cobalt-driver.h   |  377 ++
 drivers/media/pci/cobalt/cobalt-flash.c|  132 ++
 drivers/media/pci/cobalt/cobalt-flash.h|   29 +
 drivers/media/pci/cobalt/cobalt-i2c.c  |  396 ++
 drivers/media/pci/cobalt/cobalt-i2c.h  |   25 +
 drivers/media/pci/cobalt/cobalt-irq.c  |  254 
 drivers/media/pci/cobalt/cobalt-irq.h  |   25 +
 drivers/media/pci/cobalt/cobalt-omnitek.c  |  341 ++
 drivers/media/pci/cobalt/cobalt-omnitek.h  |   62 +
 drivers/media/pci/cobalt/cobalt-v4l2.c | 1260 
 drivers/media/pci/cobalt/cobalt-v4l2.h |   22 +
 .../cobalt/m00233_video_measure_memmap_package.h   |  115 ++
 .../pci/cobalt/m00235_fdma_packer_memmap_package.h |   44 +
 .../media/pci/cobalt/m00389_cvi_memmap_package.h   |   59 +
 

[PATCHv2 1/5] adv7842: Make output format configurable through pad format operations

2015-05-13 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Replace the dummy video format operations by pad format operations that
configure the output format.

Copied from the adv7604 driver.

Note: while arch/blackfin/mach-bf609/boards/ezkit.c uses adv7842_platform_data
this source has not been updated because it is broken since the very
beginning. It depends on a struct adv7842_output_format that does not
exist.

And besides that gcc has no support for bf609 so nobody can compile it
except by installing a toolchain from ADI.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Cc: Scott Jiang scott.jiang.li...@gmail.com
---
 drivers/media/i2c/adv7842.c | 269 +++-
 include/media/adv7842.h |  89 ++-
 2 files changed, 276 insertions(+), 82 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 86e65a8..dceabc2 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -56,6 +56,28 @@ MODULE_LICENSE(GPL);
 /* ADV7842 system clock frequency */
 #define ADV7842_fsc (28636360)
 
+#define ADV7842_RGB_OUT(1  1)
+
+#define ADV7842_OP_FORMAT_SEL_8BIT (0  0)
+#define ADV7842_OP_FORMAT_SEL_10BIT(1  0)
+#define ADV7842_OP_FORMAT_SEL_12BIT(2  0)
+
+#define ADV7842_OP_MODE_SEL_SDR_422(0  5)
+#define ADV7842_OP_MODE_SEL_DDR_422(1  5)
+#define ADV7842_OP_MODE_SEL_SDR_444(2  5)
+#define ADV7842_OP_MODE_SEL_DDR_444(3  5)
+#define ADV7842_OP_MODE_SEL_SDR_422_2X (4  5)
+#define ADV7842_OP_MODE_SEL_ADI_CM (5  5)
+
+#define ADV7842_OP_CH_SEL_GBR  (0  5)
+#define ADV7842_OP_CH_SEL_GRB  (1  5)
+#define ADV7842_OP_CH_SEL_BGR  (2  5)
+#define ADV7842_OP_CH_SEL_RGB  (3  5)
+#define ADV7842_OP_CH_SEL_BRG  (4  5)
+#define ADV7842_OP_CH_SEL_RBG  (5  5)
+
+#define ADV7842_OP_SWAP_CB_CR  (1  0)
+
 /*
 **
 *
@@ -64,6 +86,14 @@ MODULE_LICENSE(GPL);
 **
 */
 
+struct adv7842_format_info {
+   u32 code;
+   u8 op_ch_sel;
+   bool rgb_out;
+   bool swap_cb_cr;
+   u8 op_format_sel;
+};
+
 struct adv7842_state {
struct adv7842_platform_data pdata;
struct v4l2_subdev sd;
@@ -72,6 +102,9 @@ struct adv7842_state {
enum adv7842_mode mode;
struct v4l2_dv_timings timings;
enum adv7842_vid_std_select vid_std_select;
+
+   const struct adv7842_format_info *format;
+
v4l2_std_id norm;
struct {
u8 edid[256];
@@ -221,11 +254,21 @@ static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl 
*ctrl)
return container_of(ctrl-handler, struct adv7842_state, hdl)-sd;
 }
 
+static inline unsigned hblanking(const struct v4l2_bt_timings *t)
+{
+   return V4L2_DV_BT_BLANKING_WIDTH(t);
+}
+
 static inline unsigned htotal(const struct v4l2_bt_timings *t)
 {
return V4L2_DV_BT_FRAME_WIDTH(t);
 }
 
+static inline unsigned vblanking(const struct v4l2_bt_timings *t)
+{
+   return V4L2_DV_BT_BLANKING_HEIGHT(t);
+}
+
 static inline unsigned vtotal(const struct v4l2_bt_timings *t)
 {
return V4L2_DV_BT_FRAME_HEIGHT(t);
@@ -335,6 +378,12 @@ static inline int io_write_and_or(struct v4l2_subdev *sd, 
u8 reg, u8 mask, u8 va
return io_write(sd, reg, (io_read(sd, reg)  mask) | val);
 }
 
+static inline int io_write_clr_set(struct v4l2_subdev *sd,
+  u8 reg, u8 mask, u8 val)
+{
+   return io_write(sd, reg, (io_read(sd, reg)  ~mask) | val);
+}
+
 static inline int avlink_read(struct v4l2_subdev *sd, u8 reg)
 {
struct adv7842_state *state = to_state(sd);
@@ -535,6 +584,64 @@ static void main_reset(struct v4l2_subdev *sd)
mdelay(5);
 }
 
+/* 
-
+ * Format helpers
+ */
+
+static const struct adv7842_format_info adv7842_formats[] = {
+   { MEDIA_BUS_FMT_RGB888_1X24, ADV7842_OP_CH_SEL_RGB, true, false,
+ ADV7842_OP_MODE_SEL_SDR_444 | ADV7842_OP_FORMAT_SEL_8BIT },
+   { MEDIA_BUS_FMT_YUYV8_2X8, ADV7842_OP_CH_SEL_RGB, false, false,
+ ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_8BIT },
+   { MEDIA_BUS_FMT_YVYU8_2X8, ADV7842_OP_CH_SEL_RGB, false, true,
+ ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_8BIT },
+   { MEDIA_BUS_FMT_YUYV10_2X10, ADV7842_OP_CH_SEL_RGB, false, false,
+ ADV7842_OP_MODE_SEL_SDR_422 | ADV7842_OP_FORMAT_SEL_10BIT },
+   { MEDIA_BUS_FMT_YVYU10_2X10, ADV7842_OP_CH_SEL_RGB, false, true,
+ ADV7842_OP_MODE_SEL_SDR_422 | 

$200,000 USD

2015-05-13 Thread Gloria Mackenzie

We are donating the sum of $200,000 USD to you.




--
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 v6 06/11] cec: add HDMI CEC framework

2015-05-13 Thread Hans Verkuil
Hi Kamil,

I've started work on a cec-compliance utility and while doing that I
noticed a confusing name:

On 05/04/15 19:32, Kamil Debski wrote:
 +struct cec_caps {
 + __u32 available_log_addrs;
 + __u32 capabilities;
 + __u32 vendor_id;
 + __u8  version;
 + __u8  reserved[35];
 +};

I think 'version' should be renamed to 'cec_version' to indicate that we
are talking about the CEC version that the adapter supports, and not about
the driver version.

Regards,

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


[GIT PULL 4.2] msi2500 / msi001 enhancements

2015-05-13 Thread Antti Palosaari

The following changes since commit 356484cabe44984d2dc66a90bd5e3465ba1f64fb:

  [media] dw2102: resync fifo when demod locks (2015-05-13 17:12:42 -0300)

are available in the git repository at:

  git://linuxtv.org/anttip/media_tree.git mirics_pull

for you to fetch changes up to d86c4b050488c08397bec61da971f9223a881b10:

  msi2500: cleanups (2015-05-13 23:22:15 +0300)


Antti Palosaari (4):
  msi001: revise synthesizer calculation
  msi001: cleanups / renames
  msi2500: revise synthesizer calculation
  msi2500: cleanups

 drivers/media/tuners/msi001.c   | 267 

 drivers/media/usb/msi2500/msi2500.c | 655 
++-

 2 files changed, 482 insertions(+), 440 deletions(-)

--
http://palosaari.fi/
--
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