e8e3c311eff3b35ecf5754b9b53cddd5fcbb2de9
[oweals/openwrt.git] /
1 From a6646e496feed4fd7affe3fc5d4fc3e2591046d6 Mon Sep 17 00:00:00 2001
2 From: Stefan Wahren <stefan.wahren@i2se.com>
3 Date: Sun, 21 Oct 2018 18:40:07 +0200
4 Subject: [PATCH 235/703] staging: bcm2835-camera: Provide more specific probe
5  error messages
6
7 Currently there is only a catch-all info message which print the
8 relevant error code without any context. So add more specific error
9 messages in order to narrow down possible issues.
10
11 Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
12 ---
13  .../bcm2835-camera/bcm2835-camera.c           | 58 +++++++++++++------
14  1 file changed, 39 insertions(+), 19 deletions(-)
15
16 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
17 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
18 @@ -1539,8 +1539,11 @@ static int mmal_init(struct bm2835_mmal_
19         struct vchiq_mmal_component  *camera;
20  
21         ret = vchiq_mmal_init(&dev->instance);
22 -       if (ret < 0)
23 +       if (ret < 0) {
24 +               v4l2_err(&dev->v4l2_dev, "%s: vchiq mmal init failed %d\n",
25 +                        __func__, ret);
26                 return ret;
27 +       }
28  
29         /* get the camera component ready */
30         ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
31 @@ -1549,7 +1552,9 @@ static int mmal_init(struct bm2835_mmal_
32                 goto unreg_mmal;
33  
34         camera = dev->component[MMAL_COMPONENT_CAMERA];
35 -       if (camera->outputs <  MMAL_CAMERA_PORT_COUNT) {
36 +       if (camera->outputs < MMAL_CAMERA_PORT_COUNT) {
37 +               v4l2_err(&dev->v4l2_dev, "%s: too few camera outputs %d needed %d\n",
38 +                        __func__, camera->outputs, MMAL_CAMERA_PORT_COUNT);
39                 ret = -EINVAL;
40                 goto unreg_camera;
41         }
42 @@ -1557,8 +1562,11 @@ static int mmal_init(struct bm2835_mmal_
43         ret = set_camera_parameters(dev->instance,
44                                     camera,
45                                     dev);
46 -       if (ret < 0)
47 +       if (ret < 0) {
48 +               v4l2_err(&dev->v4l2_dev, "%s: unable to set camera parameters: %d\n",
49 +                        __func__, ret);
50                 goto unreg_camera;
51 +       }
52  
53         /* There was an error in the firmware that meant the camera component
54          * produced BGR instead of RGB.
55 @@ -1647,8 +1655,8 @@ static int mmal_init(struct bm2835_mmal_
56  
57         if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
58                 ret = -EINVAL;
59 -               pr_debug("too few input ports %d needed %d\n",
60 -                        dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
61 +               v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
62 +                        __func__, dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
63                 goto unreg_preview;
64         }
65  
66 @@ -1661,8 +1669,8 @@ static int mmal_init(struct bm2835_mmal_
67  
68         if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
69                 ret = -EINVAL;
70 -               v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
71 -                        dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
72 +               v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
73 +                        __func__, dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
74                          1);
75                 goto unreg_image_encoder;
76         }
77 @@ -1676,8 +1684,8 @@ static int mmal_init(struct bm2835_mmal_
78  
79         if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
80                 ret = -EINVAL;
81 -               v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
82 -                        dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
83 +               v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
84 +                        __func__, dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
85                          1);
86                 goto unreg_vid_encoder;
87         }
88 @@ -1706,8 +1714,11 @@ static int mmal_init(struct bm2835_mmal_
89                                               sizeof(enable));
90         }
91         ret = bm2835_mmal_set_all_camera_controls(dev);
92 -       if (ret < 0)
93 +       if (ret < 0) {
94 +               v4l2_err(&dev->v4l2_dev, "%s: failed to set all camera controls: %d\n",
95 +                        __func__, ret);
96                 goto unreg_vid_encoder;
97 +       }
98  
99         return 0;
100  
101 @@ -1867,21 +1878,29 @@ static int bcm2835_mmal_probe(struct pla
102                 snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
103                          "%s", BM2835_MMAL_MODULE_NAME);
104                 ret = v4l2_device_register(NULL, &dev->v4l2_dev);
105 -               if (ret)
106 +               if (ret) {
107 +                       dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
108 +                               __func__, ret);
109                         goto free_dev;
110 +               }
111  
112                 /* setup v4l controls */
113                 ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
114 -               if (ret < 0)
115 +               if (ret < 0) {
116 +                       v4l2_err(&dev->v4l2_dev, "%s: could not init controls: %d\n",
117 +                               __func__, ret);
118                         goto unreg_dev;
119 +               }
120                 dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
121  
122                 /* mmal init */
123                 dev->instance = instance;
124                 ret = mmal_init(dev);
125 -               if (ret < 0)
126 +               if (ret < 0) {
127 +                       v4l2_err(&dev->v4l2_dev, "%s: mmal init failed: %d\n",
128 +                               __func__, ret);
129                         goto unreg_dev;
130 -
131 +               }
132                 /* initialize queue */
133                 q = &dev->capture.vb_vidq;
134                 memset(q, 0, sizeof(*q));
135 @@ -1899,16 +1918,19 @@ static int bcm2835_mmal_probe(struct pla
136  
137                 /* initialise video devices */
138                 ret = bm2835_mmal_init_device(dev, &dev->vdev);
139 -               if (ret < 0)
140 +               if (ret < 0) {
141 +                       v4l2_err(&dev->v4l2_dev, "%s: could not init device: %d\n",
142 +                               __func__, ret);
143                         goto unreg_dev;
144 +               }
145  
146                 /* Really want to call vidioc_s_fmt_vid_cap with the default
147                  * format, but currently the APIs don't join up.
148                  */
149                 ret = mmal_setup_components(dev, &default_v4l2_format);
150                 if (ret < 0) {
151 -                       v4l2_err(&dev->v4l2_dev,
152 -                                "%s: could not setup components\n", __func__);
153 +                       v4l2_err(&dev->v4l2_dev, "%s: could not setup components: %d\n",
154 +                               __func__, ret);
155                         goto unreg_dev;
156                 }
157  
158 @@ -1932,8 +1954,6 @@ cleanup_gdev:
159                 bcm2835_cleanup_instance(gdev[i]);
160                 gdev[i] = NULL;
161         }
162 -       pr_info("%s: error %d while loading driver\n",
163 -               BM2835_MMAL_MODULE_NAME, ret);
164  
165         return ret;
166  }