linux-ti33x-psp 3.2: LCD7 A3 support, eMMC cape support, camera cape improvements
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / beaglebone / 0084-beaglebone-cssp_camera-driver-cleanup.patch
1 From b9f772af6c2b9116bad19371e4547af86b4ac18d Mon Sep 17 00:00:00 2001
2 From: Dan Aizenstros <daizenstros@quicklogic.com>
3 Date: Thu, 26 Jul 2012 21:57:12 -0400
4 Subject: [PATCH 84/84] beaglebone: cssp_camera driver cleanup
6 fix v4l2_buf.sequence to use frame count
7 fix enum/g/s_input functions
8 remove pointless g/s_std support
9 change the driver to use dev_err and dev_info instead of printk
11 Signed-off-by: Dan Aizenstros <daizenstros@quicklogic.com>
12 Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
13 ---
14  drivers/media/video/cssp_camera/cssp_camera.c |   98 +++++++++++--------------
15  drivers/media/video/cssp_camera/cssp_camera.h |    7 +-
16  2 files changed, 44 insertions(+), 61 deletions(-)
18 diff --git a/drivers/media/video/cssp_camera/cssp_camera.c b/drivers/media/video/cssp_camera/cssp_camera.c
19 index fca199b..4d86bf4 100644
20 --- a/drivers/media/video/cssp_camera/cssp_camera.c
21 +++ b/drivers/media/video/cssp_camera/cssp_camera.c
22 @@ -51,6 +51,7 @@
23  #define PCLK_POL               BIT(14) /* PCLK polarity (0 - rising edge, 1 - falling edge */
24  #define HS_EN                  BIT(13) /* High speed bus (0 =< 50 MHz, 1 > 50 MHz) */
25  #define ENABLE                 BIT(12)
26 +#define REV                    0xFF    /* Chip Revision mask */
27  
28  
29  static struct cssp_cam_fmt formats[] = {
30 @@ -123,7 +124,7 @@ static int reset_cssp(struct cssp_cam_dev *cam)
31  
32         err = configure_gpio(cam->reset_pin, 0, "cssp_reset");
33         if (err) {
34 -               printk(KERN_ERR "[%s]: failed to configure cssp reset pin\n", pdev->name);
35 +               dev_err(&pdev->dev, "failed to configure cssp reset pin\n");
36                 return -1;
37         }
38  
39 @@ -190,7 +191,6 @@ static void dma_callback(unsigned lch, u16 ch_status, void *data)
40  
41         if (ch_status == DMA_COMPLETE) {
42                 struct vb2_buffer *vb = dev->current_vb;
43 -               struct timeval ts;
44                 struct edmacc_param dma_tr_params;
45  
46                 edma_read_slot(dev->dma_ch, &dma_tr_params);
47 @@ -208,13 +208,10 @@ static void dma_callback(unsigned lch, u16 ch_status, void *data)
48                 }
49  
50                 vb->v4l2_buf.field = dev->field;
51 -               dev->field_count++;
52 -               vb->v4l2_buf.sequence = dev->field_count >> 1;
53 -               do_gettimeofday(&ts);
54 -               vb->v4l2_buf.timestamp = ts;
55 +               vb->v4l2_buf.sequence = dev->frame_cnt++;
56 +               do_gettimeofday(&vb->v4l2_buf.timestamp);
57                 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
58                 dev->current_vb = NULL;
59 -               dev->frame_cnt++;
60  
61                 /* check if we have new buffer queued */
62                 dequeue_buffer_for_dma(dev);
63 @@ -237,16 +234,16 @@ static int configure_edma(struct cssp_cam_dev *cam)
64         pdev->dev.coherent_dma_mask = (u32)~0;
65  
66         if (dma_set_mask(&pdev->dev, (u32)~0)) {
67 -               printk(KERN_ERR "[%s]: failed setting mask for DMA\n", pdev->name);
68 +               dev_err(&pdev->dev, "failed setting mask for DMA\n");
69                 return -1;
70         }
71  
72         cam->dma_ch = edma_alloc_channel(dma_channel, dma_callback, cam, EVENTQ_0);
73         if (cam->dma_ch < 0) {
74 -               printk(KERN_ERR "[%s]: allocating channel for DMA failed\n", pdev->name);
75 +               dev_err(&pdev->dev, "allocating channel for DMA failed\n");
76                 return -EBUSY;
77         } else {
78 -               printk(KERN_ERR "[%s]: allocating channel for DMA succeeded, chan=%d\n", pdev->name, cam->dma_ch);
79 +               dev_info(&pdev->dev, "allocating channel for DMA succeeded, chan=%d\n", cam->dma_ch);
80         }
81  
82         cam->dma_tr_params.opt = TCINTEN | TCC(cam->dma_ch);
83 @@ -273,7 +270,7 @@ static int configure_cssp(struct cssp_cam_dev *cam)
84  
85         res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gpmc_phys_mem_slot");
86         if (res == NULL) {
87 -               printk(KERN_ERR "[%s]: failed to get gpmc_phys_mem_slot resource\n", pdev->name);
88 +               dev_err(&pdev->dev, "failed to get gpmc_phys_mem_slot resource\n");
89                 return -ENODEV;
90         }
91  
92 @@ -289,15 +286,16 @@ static int configure_cssp(struct cssp_cam_dev *cam)
93  
94         cam->reg_base_virt = (unsigned int)ioremap(cam->reg_base_phys, cam->reg_size);
95         if (cam->reg_base_virt == 0) {
96 -               printk(KERN_ERR "[%s]: ioremap of registers region failed\n", pdev->name);
97 +               dev_err(&pdev->dev, "ioremap of registers region failed\n");
98                 release_mem_region(cam->reg_base_phys, cam->reg_size);
99                 return -ENOMEM;
100         }
101  
102 -       printk(KERN_INFO "[%s]: reg_base_virt = 0x%x\n", pdev->name, cam->reg_base_virt);
103 +       dev_info(&pdev->dev, "reg_base_virt = 0x%x\n", cam->reg_base_virt);
104  
105         val = readw(cam->reg_base_virt + REG_MODE);
106 -       printk(KERN_INFO "[%s]: reading register address=0x0 returns 0x%x\n", pdev->name, val);
107 +       cam->rev = val & REV;
108 +       dev_info(&pdev->dev, "CSSP Revision %c%d\n", 'A' + ((cam->rev & 0xf0) >> 4), cam->rev & 0x0f);
109  
110         return 0;
111  }
112 @@ -322,7 +320,7 @@ static int configure_camera_sensor(struct cssp_cam_dev *cam)
113  
114         adapter = i2c_get_adapter(((struct soc_camera_link *)(info->platform_data))->i2c_adapter_id);
115         if (!adapter) {
116 -               printk(KERN_INFO "[%s]: failed to get adapter...\n", __func__);
117 +               dev_err(&cam->pdev->dev, "failed to get i2c adapter...\n");
118                 return -ENODEV;
119         }
120  
121 @@ -333,7 +331,7 @@ static int configure_camera_sensor(struct cssp_cam_dev *cam)
122                 return -ENODEV;
123         }
124  
125 -       printk(KERN_INFO "[%s]: client's name is: %s\n", __func__, client->name);
126 +       dev_info(&cam->pdev->dev, "client's name is: %s\n", client->name);
127  
128         subdev = (struct v4l2_subdev *)i2c_get_clientdata(client);
129         if (subdev == NULL) {
130 @@ -417,6 +415,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
131  
132         alloc_ctxs[0] = dev->dma_cont_ctx;
133  
134 +       dev->frame_cnt = 0;
136         dprintk(dev, 1, "%s, count=%d, size=%ld\n", __func__, *nbuffers, size);
137  
138         return 0;
139 @@ -659,6 +659,20 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
140         pix->bytesperline = (pix->width * fmt->depth) >> 3;
141         pix->sizeimage = pix->height * pix->bytesperline;
142  
143 +       if ((pix->sizeimage % BYTES_PER_DMA_EVT) != 0)
144 +               return -EINVAL;
146 +       switch (mbus_fmt.field) {
147 +       case V4L2_FIELD_ANY:
148 +               pix->field = V4L2_FIELD_NONE;
149 +               break;
150 +       case V4L2_FIELD_NONE:
151 +               break;
152 +       default:
153 +               dev_err(&dev->pdev->dev, "Field type %d unsupported.\n", mbus_fmt.field);
154 +               return -EINVAL;
155 +       }
157         return 0;
158  }
159  
160 @@ -744,42 +758,29 @@ static int vidioc_log_status(struct file *file, void *priv)
161         return 0;
162  }
163  
164 -static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
165 -{
166 -       return 0;
167 -}
169 -/* only one input in this sample driver */
170  static int vidioc_enum_input(struct file *file, void *priv,
171                                 struct v4l2_input *inp)
172  {
173 -       return -EINVAL;
174 +       if (inp->index > 0)
175 +               return -EINVAL;
176  
177         inp->type = V4L2_INPUT_TYPE_CAMERA;
178 -       inp->std = V4L2_STD_525_60;
179         sprintf(inp->name, "Camera %u", inp->index);
181         return 0;
182  }
183  
184  static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
185  {
186 -       struct cssp_cam_dev *dev = video_drvdata(file);
188 -       *i = dev->input;
189 +       *i = 0;
190  
191         return 0;
192  }
193  
194  static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
195  {
196 -       struct cssp_cam_dev *dev = video_drvdata(file);
198 -       return -EINVAL;
200 -       if (i == dev->input)
201 -               return 0;
203 -       dev->input = i;
204 +       if (i > 0)
205 +               return -EINVAL;
206  
207         return 0;
208  }
209 @@ -805,7 +806,6 @@ static const struct v4l2_ioctl_ops cssp_cam_ioctl_ops = {
210         .vidioc_querybuf                = vidioc_querybuf,
211         .vidioc_qbuf                    = vidioc_qbuf,
212         .vidioc_dqbuf                   = vidioc_dqbuf,
213 -       .vidioc_s_std                   = vidioc_s_std,
214         .vidioc_enum_input              = vidioc_enum_input,
215         .vidioc_g_input                 = vidioc_g_input,
216         .vidioc_s_input                 = vidioc_s_input,
217 @@ -894,8 +894,6 @@ static struct video_device cssp_cam_template = {
218         .ioctl_ops      = &cssp_cam_ioctl_ops,
219         .minor          = -1,
220         .release        = video_device_release,
221 -       .tvnorms        = V4L2_STD_525_60,
222 -       .current_norm   = V4L2_STD_NTSC_M,
223  };
224  
225  static int __init  video_probe(struct cssp_cam_dev *cam_dev)
226 @@ -1006,12 +1004,12 @@ static int __init  cssp_cam_probe(struct platform_device *pdev)
227  
228         cssp_cam_platform_data = (struct cssp_cam_platform_data *) pdev->dev.platform_data;
229         if (cssp_cam_platform_data == NULL) {
230 -               printk(KERN_ERR "[%s]: missing platform data\n", pdev->name);
231 +               dev_err(&pdev->dev, "missing platform data\n");
232                 return -ENODEV;
233         }
234  
235         if (cssp_cam_platform_data->cam_i2c_board_info == NULL) {
236 -               printk(KERN_ERR "[%s]: missing camera i2c board info\n", pdev->name);
237 +               dev_err(&pdev->dev, "missing camera i2c board info\n");
238                 return -ENODEV;
239         }
240  
241 @@ -1027,7 +1025,7 @@ static int __init  cssp_cam_probe(struct platform_device *pdev)
242         cam_dev->camera_clk = clk_get(&pdev->dev, cssp_cam_platform_data->cam_clk_name);
243         if (IS_ERR(cam_dev->camera_clk)) {
244                 ret = PTR_ERR(cam_dev->camera_clk);
245 -               printk(KERN_ERR "[%s]: cannot clk_get %s\n", pdev->name, cssp_cam_platform_data->cam_clk_name);
246 +               dev_err(&pdev->dev, "cannot clk_get %s\n", cssp_cam_platform_data->cam_clk_name);
247                 goto fail0;
248         }
249  
250 @@ -1043,7 +1041,7 @@ static int __init  cssp_cam_probe(struct platform_device *pdev)
251  
252         ret = configure_camera_sensor(cam_dev);
253         if (ret) {
254 -               printk(KERN_ERR "[%s]: camera sensor configuration failed\n", pdev->name);
255 +               dev_err(&pdev->dev, "camera sensor configuration failed\n");
256                 goto fail3;
257         }
258  
259 @@ -1097,7 +1095,7 @@ static int cssp_cam_remove(struct platform_device *pdev)
260  
261         kfree(cam);
262  
263 -       printk(KERN_INFO "[%s]: removed\n", pdev->name);
264 +       dev_info(&pdev->dev, "removed\n");
265  
266         return 0;
267  }
268 @@ -1112,20 +1110,8 @@ static struct platform_driver cssp_cam_driver = {
269         },
270  };
271  
272 +module_platform_driver(cssp_cam_driver);
273  
274 -static int __init cssp_cam_init(void)
275 -{
276 -       return platform_driver_register(&cssp_cam_driver);
277 -}
279 -static void __exit cssp_cam_exit(void)
280 -{
281 -       platform_driver_unregister(&cssp_cam_driver);
282 -}
285 -module_init(cssp_cam_init);
286 -module_exit(cssp_cam_exit);
287  
288  /*
289   * Macros sets license, author and description
290 diff --git a/drivers/media/video/cssp_camera/cssp_camera.h b/drivers/media/video/cssp_camera/cssp_camera.h
291 index 8eb5f83..3bb6ea4 100644
292 --- a/drivers/media/video/cssp_camera/cssp_camera.h
293 +++ b/drivers/media/video/cssp_camera/cssp_camera.h
294 @@ -111,9 +111,6 @@ struct cssp_cam_dev {
295         int                             streaming_started;
296         struct vb2_buffer               *current_vb;
297  
298 -       /* Input Number */
299 -       int                             input;
301         /* video capture */
302         struct cssp_cam_fmt             *fmt;
303         u32                             width;
304 @@ -123,8 +120,6 @@ struct cssp_cam_dev {
305         enum v4l2_colorspace            colorspace;
306         struct vb2_queue                vb_vidq;
307         enum v4l2_field                 field;
308 -       unsigned int                    field_count;
310  
311         /* Camera Sensor */
312         struct i2c_board_info           *camera_board_info;
313 @@ -142,6 +137,8 @@ struct cssp_cam_dev {
314         int                             frame_cnt;
315  
316         int                             reset_pin;
318 +       int                             rev;
319  };
320  
321  
322 -- 
323 1.7.7.6