Commit | Line | Data |
---|---|---|
073afdd7 MD |
1 | /* |
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 | ||
326c9862 MD |
11 | #ifndef __SOC_CAMERA_H__ |
12 | #define __SOC_CAMERA_H__ | |
13 | ||
14 | #include <linux/videodev2.h> | |
c41debaf | 15 | #include <media/soc_camera.h> |
84c760a5 | 16 | #include <media/v4l2-mediabus.h> |
326c9862 | 17 | |
bc1937b4 GL |
18 | struct device; |
19 | ||
326c9862 | 20 | struct soc_camera_platform_info { |
40e2e092 | 21 | const char *format_name; |
326c9862 | 22 | unsigned long format_depth; |
760697be | 23 | struct v4l2_mbus_framefmt format; |
84c760a5 GL |
24 | unsigned long mbus_param; |
25 | enum v4l2_mbus_type mbus_type; | |
7dfff953 | 26 | struct soc_camera_device *icd; |
326c9862 MD |
27 | int (*set_capture)(struct soc_camera_platform_info *info, int enable); |
28 | }; | |
29 | ||
ec0c8d55 GL |
30 | static inline void soc_camera_platform_release(struct platform_device **pdev) |
31 | { | |
32 | *pdev = NULL; | |
33 | } | |
34 | ||
7dfff953 | 35 | static inline int soc_camera_platform_add(struct soc_camera_device *icd, |
ec0c8d55 GL |
36 | struct platform_device **pdev, |
37 | struct soc_camera_link *plink, | |
38 | void (*release)(struct device *dev), | |
39 | int id) | |
40 | { | |
25a34811 GL |
41 | struct soc_camera_subdev_desc *ssdd = |
42 | (struct soc_camera_subdev_desc *)plink; | |
43 | struct soc_camera_platform_info *info = ssdd->drv_priv; | |
ec0c8d55 GL |
44 | int ret; |
45 | ||
25a34811 | 46 | if (&icd->sdesc->subdev_desc != ssdd) |
ec0c8d55 GL |
47 | 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 | ||
7dfff953 | 56 | info->icd = icd; |
ec0c8d55 GL |
57 | |
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; | |
7dfff953 | 65 | info->icd = NULL; |
ec0c8d55 GL |
66 | } |
67 | ||
68 | return ret; | |
69 | } | |
70 | ||
7dfff953 | 71 | static inline void soc_camera_platform_del(const struct soc_camera_device *icd, |
ec0c8d55 GL |
72 | struct platform_device *pdev, |
73 | const struct soc_camera_link *plink) | |
74 | { | |
25a34811 GL |
75 | const struct soc_camera_subdev_desc *ssdd = |
76 | (const struct soc_camera_subdev_desc *)plink; | |
77 | if (&icd->sdesc->subdev_desc != ssdd || !pdev) | |
ec0c8d55 GL |
78 | return; |
79 | ||
80 | platform_device_unregister(pdev); | |
81 | } | |
82 | ||
326c9862 | 83 | #endif /* __SOC_CAMERA_H__ */ |