Magnus Damm | 073afdd | 2008-10-16 19:51:47 -0300 | [diff] [blame] | 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 | |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 11 | #ifndef __SOC_CAMERA_H__ |
| 12 | #define __SOC_CAMERA_H__ |
| 13 | |
| 14 | #include <linux/videodev2.h> |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 15 | #include <media/soc_camera.h> |
Guennadi Liakhovetski | 84c760a | 2011-07-27 10:06:09 -0300 | [diff] [blame] | 16 | #include <media/v4l2-mediabus.h> |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 17 | |
Guennadi Liakhovetski | bc1937b | 2009-08-25 11:06:22 -0300 | [diff] [blame] | 18 | struct device; |
| 19 | |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 20 | struct soc_camera_platform_info { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 21 | const char *format_name; |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 22 | unsigned long format_depth; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 23 | struct v4l2_mbus_framefmt format; |
Guennadi Liakhovetski | 84c760a | 2011-07-27 10:06:09 -0300 | [diff] [blame] | 24 | unsigned long mbus_param; |
| 25 | enum v4l2_mbus_type mbus_type; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 26 | struct soc_camera_device *icd; |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 27 | int (*set_capture)(struct soc_camera_platform_info *info, int enable); |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 28 | }; |
| 29 | |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 30 | static inline void soc_camera_platform_release(struct platform_device **pdev) |
| 31 | { |
| 32 | *pdev = NULL; |
| 33 | } |
| 34 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 35 | static inline int soc_camera_platform_add(struct soc_camera_device *icd, |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 36 | struct platform_device **pdev, |
| 37 | struct soc_camera_link *plink, |
| 38 | void (*release)(struct device *dev), |
| 39 | int id) |
| 40 | { |
| 41 | struct soc_camera_platform_info *info = plink->priv; |
| 42 | int ret; |
| 43 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 44 | if (icd->link != plink) |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 45 | return -ENODEV; |
| 46 | |
| 47 | if (*pdev) |
| 48 | return -EBUSY; |
| 49 | |
| 50 | *pdev = platform_device_alloc("soc_camera_platform", id); |
| 51 | if (!*pdev) |
| 52 | return -ENOMEM; |
| 53 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 54 | info->icd = icd; |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 55 | |
| 56 | (*pdev)->dev.platform_data = info; |
| 57 | (*pdev)->dev.release = release; |
| 58 | |
| 59 | ret = platform_device_add(*pdev); |
| 60 | if (ret < 0) { |
| 61 | platform_device_put(*pdev); |
| 62 | *pdev = NULL; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 63 | info->icd = NULL; |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 69 | static inline void soc_camera_platform_del(const struct soc_camera_device *icd, |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 70 | struct platform_device *pdev, |
| 71 | const struct soc_camera_link *plink) |
| 72 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 73 | if (icd->link != plink || !pdev) |
Guennadi Liakhovetski | ec0c8d5 | 2011-03-23 04:14:43 -0300 | [diff] [blame] | 74 | return; |
| 75 | |
| 76 | platform_device_unregister(pdev); |
| 77 | } |
| 78 | |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 79 | #endif /* __SOC_CAMERA_H__ */ |