Re: [PATCH 10/14] media: soc-camera: support OF cameras

2013-04-08 Thread Barry Song
hi Guennadi,

2012/9/27 Guennadi Liakhovetski g.liakhovet...@gmx.de:
 With OF we aren't getting platform data any more. To minimise changes we
 create all the missing data ourselves, including compulsory struct
 soc_camera_link objects. Host-client linking is now done, based on the OF
 data. Media bus numbers also have to be assigned dynamically.

 Signed-off-by: Guennadi Liakhovetski g.liakhovet...@gmx.de

as your V4L2 core DT based supports
[media] Add a V4L2 OF parser
[media] Add common video interfaces OF bindings documentation
have been in media_tree queue for 3.10. i do care about the status of
this patch for soc_camera.

will you have a plan to resend these soc-camera patches based on your
final V4L2 core DT patches? otherwise, we might do some jobs for that.

 ---
  drivers/media/platform/soc_camera/soc_camera.c |  337 
 ++--
  include/media/soc_camera.h |5 +
  2 files changed, 326 insertions(+), 16 deletions(-)

-barry
--
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 10/14] media: soc-camera: support OF cameras

2013-04-08 Thread Guennadi Liakhovetski
Hi Barry

On Mon, 8 Apr 2013, Barry Song wrote:

 hi Guennadi,
 
 2012/9/27 Guennadi Liakhovetski g.liakhovet...@gmx.de:
  With OF we aren't getting platform data any more. To minimise changes we
  create all the missing data ourselves, including compulsory struct
  soc_camera_link objects. Host-client linking is now done, based on the OF
  data. Media bus numbers also have to be assigned dynamically.
 
  Signed-off-by: Guennadi Liakhovetski g.liakhovet...@gmx.de
 
 as your V4L2 core DT based supports
 [media] Add a V4L2 OF parser
 [media] Add common video interfaces OF bindings documentation
 have been in media_tree queue for 3.10. i do care about the status of
 this patch for soc_camera.
 
 will you have a plan to resend these soc-camera patches based on your
 final V4L2 core DT patches? otherwise, we might do some jobs for that.

This patch depends not only on the above two OF patches, that Sylwester 
kindly polished to make them finally suitable for the mainline :-), but 
also on V4L2 (temporary) clock and asynchronous probing patches, which 
I've just re-posted in their v7. Once those patches stabilise, it will be 
possible to re-spin this patch too. However, currently I don't have any 
interested users for this work, so I can only run it as a low priority 
task in my spare time, of which I don't have much.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
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 10/14] media: soc-camera: support OF cameras

2013-04-08 Thread Barry Song
Hi Guennadi,

2013/4/8 Guennadi Liakhovetski g.liakhovet...@gmx.de:
 Hi Barry

 On Mon, 8 Apr 2013, Barry Song wrote:

 hi Guennadi,

 2012/9/27 Guennadi Liakhovetski g.liakhovet...@gmx.de:
  With OF we aren't getting platform data any more. To minimise changes we
  create all the missing data ourselves, including compulsory struct
  soc_camera_link objects. Host-client linking is now done, based on the OF
  data. Media bus numbers also have to be assigned dynamically.
 
  Signed-off-by: Guennadi Liakhovetski g.liakhovet...@gmx.de

 as your V4L2 core DT based supports
 [media] Add a V4L2 OF parser
 [media] Add common video interfaces OF bindings documentation
 have been in media_tree queue for 3.10. i do care about the status of
 this patch for soc_camera.

 will you have a plan to resend these soc-camera patches based on your
 final V4L2 core DT patches? otherwise, we might do some jobs for that.

 This patch depends not only on the above two OF patches, that Sylwester
 kindly polished to make them finally suitable for the mainline :-), but
 also on V4L2 (temporary) clock and asynchronous probing patches, which
 I've just re-posted in their v7. Once those patches stabilise, it will be
 possible to re-spin this patch too. However, currently I don't have any
 interested users for this work, so I can only run it as a low priority
 task in my spare time, of which I don't have much.

as we are considering putting CSR SiRFprimaII/SiRFatlas6/SiRFmarco
soc_camera based drivers in drivers/media/platform/soc_camera, so we
might become your real user. Old imx, omap users might have lost the
loop.
I will take a careful at all these patches and find the way to make
the things happen faster.


 Thanks
 Guennadi
 ---
 Guennadi Liakhovetski, Ph.D.
 Freelance Open-Source Software Developer
 http://www.open-technology.de/

-barry
--
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 10/14] media: soc-camera: support OF cameras

2012-10-08 Thread Guennadi Liakhovetski
Hi Sylwester

On Fri, 5 Oct 2012, Sylwester Nawrocki wrote:

 On 09/27/2012 04:07 PM, Guennadi Liakhovetski wrote:
  With OF we aren't getting platform data any more. To minimise changes we
  create all the missing data ourselves, including compulsory struct
  soc_camera_link objects. Host-client linking is now done, based on the OF
  data. Media bus numbers also have to be assigned dynamically.
  
  Signed-off-by: Guennadi Liakhovetskig.liakhovet...@gmx.de
  ---
 ...
static int soc_camera_i2c_notify(struct notifier_block *nb,
   unsigned long action, void *data)
{
  @@ -1203,13 +1434,20 @@ static int soc_camera_i2c_notify(struct
  notifier_block *nb,
  struct v4l2_subdev *subdev;
  int ret;
  
  -   if (client-addr != icl-board_info-addr ||
  -   client-adapter-nr != icl-i2c_adapter_id)
  +   dev_dbg(dev, %s(%lu): %x on %u\n, __func__, action,
  +   client-addr, client-adapter-nr);
  +
  +   if (!soc_camera_i2c_client_match(icl, client))
  return NOTIFY_DONE;
  
  switch (action) {
  case BUS_NOTIFY_BIND_DRIVER:
  client-dev.platform_data = icl;
  +   if (icl-of_link) {
  +   struct soc_camera_of_client *sofc =
  container_of(icl-of_link,
  +   struct soc_camera_of_client,
  of_link);
  +   soc_camera_of_i2c_ifill(sofc, client);
  +   }
  
  return NOTIFY_OK;
  case BUS_NOTIFY_BOUND_DRIVER:
 
 There is no need for different handling of this event as well ?

There is. The former is entered before the sensor I2C probe method is 
called and prepares the data for probing, the latter is entered after a 
successful sensor I2C probing.

 Further, there is code like:
 
   adap = i2c_get_adapter(icl-i2c_adapter_id);
 
 which is clearly not going to work in OF case.

It does work. See the call to soc_camera_of_i2c_ifill() under 
BUS_NOTIFY_BIND_DRIVER above. In it

icl-i2c_adapter_id = client-adapter-nr;

 Could you clarify how it is supposed to work ?

It is not only supposed to work, it actually does work. Does the above 
explain it sufficiently?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
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 10/14] media: soc-camera: support OF cameras

2012-10-08 Thread Sylwester Nawrocki
Hi Guennadi,

On 10/08/2012 10:37 AM, Guennadi Liakhovetski wrote:
 case BUS_NOTIFY_BOUND_DRIVER:

 There is no need for different handling of this event as well ?
 
 There is. The former is entered before the sensor I2C probe method is 
 called and prepares the data for probing, the latter is entered after a 
 successful sensor I2C probing.
 
 Further, there is code like:

  adap = i2c_get_adapter(icl-i2c_adapter_id);

 which is clearly not going to work in OF case.
 
 It does work. See the call to soc_camera_of_i2c_ifill() under 
 BUS_NOTIFY_BIND_DRIVER above. In it
 
   icl-i2c_adapter_id = client-adapter-nr;
 
 Could you clarify how it is supposed to work ?
 
 It is not only supposed to work, it actually does work. Does the above 
 explain it sufficiently?

Sorry, my fault. Somehow I didn't realize there is being passed
an I2C adapter already assigned by the I2C core. I confused it with
some static adapter nr, which would be -1 for dt case.
Apologies for wasting your time with those non-constructive questions.

--

Thanks,
Sylwester
--
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 10/14] media: soc-camera: support OF cameras

2012-10-05 Thread Sylwester Nawrocki

On 09/27/2012 04:07 PM, Guennadi Liakhovetski wrote:

With OF we aren't getting platform data any more. To minimise changes we
create all the missing data ourselves, including compulsory struct
soc_camera_link objects. Host-client linking is now done, based on the OF
data. Media bus numbers also have to be assigned dynamically.

Signed-off-by: Guennadi Liakhovetskig.liakhovet...@gmx.de
---

...

  static int soc_camera_i2c_notify(struct notifier_block *nb,
 unsigned long action, void *data)
  {
@@ -1203,13 +1434,20 @@ static int soc_camera_i2c_notify(struct notifier_block 
*nb,
struct v4l2_subdev *subdev;
int ret;

-   if (client-addr != icl-board_info-addr ||
-   client-adapter-nr != icl-i2c_adapter_id)
+   dev_dbg(dev, %s(%lu): %x on %u\n, __func__, action,
+   client-addr, client-adapter-nr);
+
+   if (!soc_camera_i2c_client_match(icl, client))
return NOTIFY_DONE;

switch (action) {
case BUS_NOTIFY_BIND_DRIVER:
client-dev.platform_data = icl;
+   if (icl-of_link) {
+   struct soc_camera_of_client *sofc = 
container_of(icl-of_link,
+   struct soc_camera_of_client, 
of_link);
+   soc_camera_of_i2c_ifill(sofc, client);
+   }

return NOTIFY_OK;
case BUS_NOTIFY_BOUND_DRIVER:


There is no need for different handling of this event as well ?
Further, there is code like:

adap = i2c_get_adapter(icl-i2c_adapter_id);

which is clearly not going to work in OF case. Could you clarify how
it is supposed to work ?

--

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


[PATCH 10/14] media: soc-camera: support OF cameras

2012-09-27 Thread Guennadi Liakhovetski
With OF we aren't getting platform data any more. To minimise changes we
create all the missing data ourselves, including compulsory struct
soc_camera_link objects. Host-client linking is now done, based on the OF
data. Media bus numbers also have to be assigned dynamically.

Signed-off-by: Guennadi Liakhovetski g.liakhovet...@gmx.de
---
 drivers/media/platform/soc_camera/soc_camera.c |  337 ++--
 include/media/soc_camera.h |5 +
 2 files changed, 326 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/soc_camera/soc_camera.c 
b/drivers/media/platform/soc_camera/soc_camera.c
index c2a5fa3..2a02215 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -23,6 +23,8 @@
 #include linux/list.h
 #include linux/mutex.h
 #include linux/module.h
+#include linux/of.h
+#include linux/of_i2c.h
 #include linux/platform_device.h
 #include linux/regulator/consumer.h
 #include linux/slab.h
@@ -33,6 +35,7 @@
 #include media/v4l2-common.h
 #include media/v4l2-ioctl.h
 #include media/v4l2-dev.h
+#include media/v4l2-of.h
 #include media/videobuf-core.h
 #include media/videobuf2-core.h
 #include media/soc_mediabus.h
@@ -46,12 +49,32 @@
 (icd)-vb_vidq.streaming : \
 vb2_is_streaming((icd)-vb2_vidq))
 
+#define MAP_MAX_NUM 32
+static DECLARE_BITMAP(host_map, MAP_MAX_NUM);
+static DECLARE_BITMAP(device_map, MAP_MAX_NUM);
 static LIST_HEAD(hosts);
 static LIST_HEAD(devices);
-static DEFINE_MUTEX(list_lock);/* Protects the list of hosts */
+/*
+ * Protects lists and bitmaps of hosts and devices.
+ * Lock nesting: Ok to take -host_lock under list_lock.
+ */
+static DEFINE_MUTEX(list_lock);
+
+struct soc_camera_of_client {
+   struct soc_camera_link *icl;
+   struct v4l2_of_link of_link;
+   struct platform_device *pdev;
+   struct dev_archdata archdata;
+   struct device_node *link_node;
+   union {
+   struct i2c_board_info i2c_info;
+   };
+};
 
 static int soc_camera_video_start(struct soc_camera_device *icd);
 static int video_dev_create(struct soc_camera_device *icd);
+static void soc_camera_of_i2c_info(struct device_node *node,
+  struct soc_camera_of_client *sofc);
 
 static struct soc_camera_device *soc_camera_device_find(struct soc_camera_link 
*icl)
 {
@@ -1099,6 +1122,7 @@ static void scan_add_host(struct soc_camera_host *ici)
 {
struct soc_camera_device *icd;
 
+   mutex_lock(list_lock);
mutex_lock(ici-host_lock);
 
list_for_each_entry(icd, devices, list) {
@@ -1107,10 +1131,146 @@ static void scan_add_host(struct soc_camera_host *ici)
 
icd-parent = ici-v4l2_dev.dev;
ret = soc_camera_probe(icd);
+   /*
+* We could in principle destroy icd in the error case
+* here - it is useless, if it failed to probe
+*/
}
}
 
mutex_unlock(ici-host_lock);
+   mutex_unlock(list_lock);
+}
+
+static struct soc_camera_of_client *soc_camera_of_alloc_client(const struct 
soc_camera_host *ici,
+  struct 
device_node *node)
+{
+   struct soc_camera_of_client *sofc = devm_kzalloc(ici-v4l2_dev.dev,
+   sizeof(*sofc), GFP_KERNEL);
+   struct soc_camera_link icl = {.host_wait = true,};
+   int i, ret;
+
+   if (!sofc)
+   return NULL;
+
+   mutex_lock(list_lock);
+   i = find_first_zero_bit(device_map, MAP_MAX_NUM);
+   if (i  MAP_MAX_NUM)
+   set_bit(i, device_map);
+   mutex_unlock(list_lock);
+   if (i = MAP_MAX_NUM)
+   return NULL;
+   sofc-pdev = platform_device_alloc(soc-camera-pdrv, i);
+   if (!sofc-pdev)
+   return NULL;
+
+   icl.of_link = sofc-of_link;
+   icl.bus_id = ici-nr;
+
+   ret = platform_device_add_data(sofc-pdev, icl, sizeof(icl));
+   if (ret  0)
+   return NULL;
+   sofc-icl = sofc-pdev-dev.platform_data;
+
+   soc_camera_of_i2c_info(node, sofc);
+
+   return sofc;
+}
+
+static int soc_camera_of_register_client(struct soc_camera_of_client *sofc)
+{
+   return platform_device_add(sofc-pdev);
+}
+
+struct soc_camera_wait_pdev {
+   struct notifier_block nb;
+   struct completion complete;
+   struct soc_camera_link *link;
+};
+
+static int wait_complete(struct notifier_block *nb,
+unsigned long action, void *data)
+{
+   struct device *dev = data;
+   struct soc_camera_wait_pdev *wait = container_of(nb,
+   struct soc_camera_wait_pdev, nb);
+
+   if (dev-platform_data == wait-link 
+   action == BUS_NOTIFY_BOUND_DRIVER) {
+