blob: 1e5065dab43096c36622afc6cfabd79c9ce6cec5 [file] [log] [blame]
Magnus Damm073afdd2008-10-16 19:51:47 -03001/*
2 * Generic Platform Camera Driver Header
3 *
4 * Copyright (C) 2008 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Magnus Damm326c9862008-07-16 23:02:08 -030011#ifndef __SOC_CAMERA_H__
12#define __SOC_CAMERA_H__
13
14#include <linux/videodev2.h>
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -030015#include <media/soc_camera.h>
Guennadi Liakhovetski84c760a2011-07-27 10:06:09 -030016#include <media/v4l2-mediabus.h>
Magnus Damm326c9862008-07-16 23:02:08 -030017
Guennadi Liakhovetskibc1937b2009-08-25 11:06:22 -030018struct device;
19
Magnus Damm326c9862008-07-16 23:02:08 -030020struct soc_camera_platform_info {
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -030021 const char *format_name;
Magnus Damm326c9862008-07-16 23:02:08 -030022 unsigned long format_depth;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030023 struct v4l2_mbus_framefmt format;
Guennadi Liakhovetski84c760a2011-07-27 10:06:09 -030024 unsigned long mbus_param;
25 enum v4l2_mbus_type mbus_type;
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030026 struct soc_camera_device *icd;
Magnus Damm326c9862008-07-16 23:02:08 -030027 int (*set_capture)(struct soc_camera_platform_info *info, int enable);
Magnus Damm326c9862008-07-16 23:02:08 -030028};
29
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030030static inline void soc_camera_platform_release(struct platform_device **pdev)
31{
32 *pdev = NULL;
33}
34
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030035static inline int soc_camera_platform_add(struct soc_camera_device *icd,
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030036 struct platform_device **pdev,
37 struct soc_camera_link *plink,
38 void (*release)(struct device *dev),
39 int id)
40{
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030041 struct soc_camera_subdev_desc *ssdd =
42 (struct soc_camera_subdev_desc *)plink;
43 struct soc_camera_platform_info *info = ssdd->drv_priv;
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030044 int ret;
45
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030046 if (&icd->sdesc->subdev_desc != ssdd)
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030047 return -ENODEV;
48
49 if (*pdev)
50 return -EBUSY;
51
52 *pdev = platform_device_alloc("soc_camera_platform", id);
53 if (!*pdev)
54 return -ENOMEM;
55
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030056 info->icd = icd;
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030057
58 (*pdev)->dev.platform_data = info;
59 (*pdev)->dev.release = release;
60
61 ret = platform_device_add(*pdev);
62 if (ret < 0) {
63 platform_device_put(*pdev);
64 *pdev = NULL;
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030065 info->icd = NULL;
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030066 }
67
68 return ret;
69}
70
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030071static inline void soc_camera_platform_del(const struct soc_camera_device *icd,
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030072 struct platform_device *pdev,
73 const struct soc_camera_link *plink)
74{
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030075 const struct soc_camera_subdev_desc *ssdd =
76 (const struct soc_camera_subdev_desc *)plink;
77 if (&icd->sdesc->subdev_desc != ssdd || !pdev)
Guennadi Liakhovetskiec0c8d52011-03-23 04:14:43 -030078 return;
79
80 platform_device_unregister(pdev);
81}
82
Magnus Damm326c9862008-07-16 23:02:08 -030083#endif /* __SOC_CAMERA_H__ */