Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Generic Platform Camera Driver |
| 3 | * |
| 4 | * Copyright (C) 2008 Magnus Damm |
| 5 | * Based on mt9m001 driver, |
| 6 | * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/videodev2.h> |
| 19 | #include <media/v4l2-common.h> |
| 20 | #include <media/soc_camera.h> |
| 21 | |
| 22 | struct soc_camera_platform_info { |
| 23 | int iface; |
| 24 | char *format_name; |
| 25 | unsigned long format_depth; |
| 26 | struct v4l2_pix_format format; |
| 27 | unsigned long bus_param; |
| 28 | int (*set_capture)(struct soc_camera_platform_info *info, int enable); |
| 29 | }; |
| 30 | |
| 31 | struct soc_camera_platform_priv { |
| 32 | struct soc_camera_platform_info *info; |
| 33 | struct soc_camera_device icd; |
| 34 | struct soc_camera_data_format format; |
| 35 | }; |
| 36 | |
| 37 | static struct soc_camera_platform_info * |
| 38 | soc_camera_platform_get_info(struct soc_camera_device *icd) |
| 39 | { |
| 40 | struct soc_camera_platform_priv *priv; |
| 41 | priv = container_of(icd, struct soc_camera_platform_priv, icd); |
| 42 | return priv->info; |
| 43 | } |
| 44 | |
| 45 | static int soc_camera_platform_init(struct soc_camera_device *icd) |
| 46 | { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int soc_camera_platform_release(struct soc_camera_device *icd) |
| 51 | { |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static int soc_camera_platform_start_capture(struct soc_camera_device *icd) |
| 56 | { |
| 57 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); |
| 58 | return p->set_capture(p, 1); |
| 59 | } |
| 60 | |
| 61 | static int soc_camera_platform_stop_capture(struct soc_camera_device *icd) |
| 62 | { |
| 63 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); |
| 64 | return p->set_capture(p, 0); |
| 65 | } |
| 66 | |
| 67 | static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd, |
| 68 | unsigned long flags) |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static unsigned long |
| 74 | soc_camera_platform_query_bus_param(struct soc_camera_device *icd) |
| 75 | { |
| 76 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); |
| 77 | return p->bus_param; |
| 78 | } |
| 79 | |
| 80 | static int soc_camera_platform_set_fmt_cap(struct soc_camera_device *icd, |
| 81 | __u32 pixfmt, struct v4l2_rect *rect) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static int soc_camera_platform_try_fmt_cap(struct soc_camera_device *icd, |
| 87 | struct v4l2_format *f) |
| 88 | { |
| 89 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); |
| 90 | |
| 91 | f->fmt.pix.width = p->format.width; |
| 92 | f->fmt.pix.height = p->format.height; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static int soc_camera_platform_video_probe(struct soc_camera_device *icd) |
| 97 | { |
| 98 | struct soc_camera_platform_priv *priv; |
| 99 | priv = container_of(icd, struct soc_camera_platform_priv, icd); |
| 100 | |
| 101 | priv->format.name = priv->info->format_name; |
| 102 | priv->format.depth = priv->info->format_depth; |
| 103 | priv->format.fourcc = priv->info->format.pixelformat; |
| 104 | priv->format.colorspace = priv->info->format.colorspace; |
| 105 | |
| 106 | icd->formats = &priv->format; |
| 107 | icd->num_formats = 1; |
| 108 | |
| 109 | return soc_camera_video_start(icd); |
| 110 | } |
| 111 | |
| 112 | static void soc_camera_platform_video_remove(struct soc_camera_device *icd) |
| 113 | { |
| 114 | soc_camera_video_stop(icd); |
| 115 | } |
| 116 | |
| 117 | static struct soc_camera_ops soc_camera_platform_ops = { |
| 118 | .owner = THIS_MODULE, |
| 119 | .probe = soc_camera_platform_video_probe, |
| 120 | .remove = soc_camera_platform_video_remove, |
| 121 | .init = soc_camera_platform_init, |
| 122 | .release = soc_camera_platform_release, |
| 123 | .start_capture = soc_camera_platform_start_capture, |
| 124 | .stop_capture = soc_camera_platform_stop_capture, |
| 125 | .set_fmt_cap = soc_camera_platform_set_fmt_cap, |
| 126 | .try_fmt_cap = soc_camera_platform_try_fmt_cap, |
| 127 | .set_bus_param = soc_camera_platform_set_bus_param, |
| 128 | .query_bus_param = soc_camera_platform_query_bus_param, |
| 129 | }; |
| 130 | |
| 131 | static int soc_camera_platform_probe(struct platform_device *pdev) |
| 132 | { |
| 133 | struct soc_camera_platform_priv *priv; |
| 134 | struct soc_camera_platform_info *p; |
| 135 | struct soc_camera_device *icd; |
| 136 | int ret; |
| 137 | |
| 138 | p = pdev->dev.platform_data; |
| 139 | if (!p) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 143 | if (!priv) |
| 144 | return -ENOMEM; |
| 145 | |
| 146 | priv->info = p; |
| 147 | platform_set_drvdata(pdev, priv); |
| 148 | |
| 149 | icd = &priv->icd; |
| 150 | icd->ops = &soc_camera_platform_ops; |
| 151 | icd->control = &pdev->dev; |
| 152 | icd->width_min = 0; |
| 153 | icd->width_max = priv->info->format.width; |
| 154 | icd->height_min = 0; |
| 155 | icd->height_max = priv->info->format.height; |
| 156 | icd->y_skip_top = 0; |
| 157 | icd->iface = priv->info->iface; |
| 158 | |
| 159 | ret = soc_camera_device_register(icd); |
| 160 | if (ret) |
| 161 | kfree(priv); |
| 162 | |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | static int soc_camera_platform_remove(struct platform_device *pdev) |
| 167 | { |
| 168 | struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev); |
| 169 | |
| 170 | soc_camera_device_unregister(&priv->icd); |
| 171 | kfree(priv); |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static struct platform_driver soc_camera_platform_driver = { |
| 176 | .driver = { |
| 177 | .name = "soc_camera_platform", |
| 178 | }, |
| 179 | .probe = soc_camera_platform_probe, |
| 180 | .remove = soc_camera_platform_remove, |
| 181 | }; |
| 182 | |
| 183 | static int __init soc_camera_platform_module_init(void) |
| 184 | { |
| 185 | return platform_driver_register(&soc_camera_platform_driver); |
| 186 | } |
| 187 | |
| 188 | static void __exit soc_camera_platform_module_exit(void) |
| 189 | { |
Paul Mundt | 01c1e4c | 2008-08-01 19:48:51 -0300 | [diff] [blame] | 190 | platform_driver_unregister(&soc_camera_platform_driver); |
Magnus Damm | 326c986 | 2008-07-16 23:02:08 -0300 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | module_init(soc_camera_platform_module_init); |
| 194 | module_exit(soc_camera_platform_module_exit); |
| 195 | |
| 196 | MODULE_DESCRIPTION("SoC Camera Platform driver"); |
| 197 | MODULE_AUTHOR("Magnus Damm"); |
| 198 | MODULE_LICENSE("GPL v2"); |