#include <media/v4l2-chip-ident.h>
#include <media/soc_camera.h>
+#ifdef CONFIG_MT9M001_PCA9536_SWITCH
#include <asm/gpio.h>
+#endif
/* mt9m001 i2c address 0x5d
* The platform has to define i2c_board_info
#define MT9M001_CHIP_ENABLE 0xF1
static const struct soc_camera_data_format mt9m001_colour_formats[] = {
+ /* Order important: first natively supported,
+ * second supported with a GPIO extender */
{
- .name = "RGB Bayer (sRGB)",
- .depth = 16,
+ .name = "Bayer (sRGB) 10 bit",
+ .depth = 10,
+ .fourcc = V4L2_PIX_FMT_SBGGR16,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+ }, {
+ .name = "Bayer (sRGB) 8 bit",
+ .depth = 8,
.fourcc = V4L2_PIX_FMT_SBGGR8,
.colorspace = V4L2_COLORSPACE_SRGB,
}
};
static const struct soc_camera_data_format mt9m001_monochrome_formats[] = {
+ /* Order important - see above */
{
.name = "Monochrome 10 bit",
.depth = 10,
int ret;
/* Disable chip, synchronous option update */
- dev_dbg(icd->vdev->dev, "%s\n", __FUNCTION__);
+ dev_dbg(icd->vdev->dev, "%s\n", __func__);
ret = reg_write(icd, MT9M001_RESET, 1);
if (ret >= 0)
#endif
}
-static int mt9m001_set_capture_format(struct soc_camera_device *icd,
- __u32 pixfmt, struct v4l2_rect *rect, unsigned int flags)
+static int bus_switch_possible(struct mt9m001 *mt9m001)
+{
+#ifdef CONFIG_MT9M001_PCA9536_SWITCH
+ return gpio_is_valid(mt9m001->switch_gpio);
+#else
+ return 0;
+#endif
+}
+
+static int mt9m001_set_bus_param(struct soc_camera_device *icd,
+ unsigned long flags)
{
struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
- unsigned int width_flag = flags & (IS_DATAWIDTH_10 | IS_DATAWIDTH_9 |
- IS_DATAWIDTH_8);
+ unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
int ret;
- const u16 hblank = 9, vblank = 25;
- /* MT9M001 has all capture_format parameters fixed */
- if (!(flags & IS_MASTER) ||
- !(flags & IS_PCLK_SAMPLE_RISING) ||
- !(flags & IS_HSYNC_ACTIVE_HIGH) ||
- !(flags & IS_VSYNC_ACTIVE_HIGH))
- return -EINVAL;
-
- /* Only one width bit may be set */
- if (!is_power_of_2(width_flag))
- return -EINVAL;
-
- if ((mt9m001->datawidth != 10 && (width_flag == IS_DATAWIDTH_10)) ||
- (mt9m001->datawidth != 9 && (width_flag == IS_DATAWIDTH_9)) ||
- (mt9m001->datawidth != 8 && (width_flag == IS_DATAWIDTH_8))) {
- /* data width switch requested */
- if (!gpio_is_valid(mt9m001->switch_gpio))
- return -EINVAL;
+ /* Flags validity verified in test_bus_param */
+ if ((mt9m001->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) ||
+ (mt9m001->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) ||
+ (mt9m001->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) {
/* Well, we actually only can do 10 or 8 bits... */
- if (width_flag == IS_DATAWIDTH_9)
+ if (width_flag == SOCAM_DATAWIDTH_9)
return -EINVAL;
ret = bus_switch_act(mt9m001,
- width_flag == IS_DATAWIDTH_8);
+ width_flag == SOCAM_DATAWIDTH_8);
if (ret < 0)
return ret;
- mt9m001->datawidth = width_flag == IS_DATAWIDTH_8 ? 8 : 10;
+ mt9m001->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
}
+ return 0;
+}
+
+static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
+{
+ struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+ unsigned int width_flag = SOCAM_DATAWIDTH_10;
+
+ if (bus_switch_possible(mt9m001))
+ width_flag |= SOCAM_DATAWIDTH_8;
+
+ /* MT9M001 has all capture_format parameters fixed */
+ return SOCAM_PCLK_SAMPLE_RISING |
+ SOCAM_HSYNC_ACTIVE_HIGH |
+ SOCAM_VSYNC_ACTIVE_HIGH |
+ SOCAM_MASTER |
+ width_flag;
+}
+
+static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
+ __u32 pixfmt, struct v4l2_rect *rect)
+{
+ struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+ int ret;
+ const u16 hblank = 9, vblank = 25;
+
/* Blanking and start values - default... */
ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank);
if (ret >= 0)
}
#endif
-static unsigned int mt9m001_get_datawidth(struct soc_camera_device *icd)
-{
- struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
- return mt9m001->datawidth;
-}
-
-const struct v4l2_queryctrl mt9m001_controls[] = {
+static const struct v4l2_queryctrl mt9m001_controls[] = {
{
.id = V4L2_CID_VFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN,
}
};
-static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl);
-static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl);
+static int mt9m001_video_probe(struct soc_camera_device *);
+static void mt9m001_video_remove(struct soc_camera_device *);
+static int mt9m001_get_control(struct soc_camera_device *, struct v4l2_control *);
+static int mt9m001_set_control(struct soc_camera_device *, struct v4l2_control *);
static struct soc_camera_ops mt9m001_ops = {
.owner = THIS_MODULE,
+ .probe = mt9m001_video_probe,
+ .remove = mt9m001_video_remove,
.init = mt9m001_init,
.release = mt9m001_release,
.start_capture = mt9m001_start_capture,
.stop_capture = mt9m001_stop_capture,
- .set_capture_format = mt9m001_set_capture_format,
+ .set_fmt_cap = mt9m001_set_fmt_cap,
.try_fmt_cap = mt9m001_try_fmt_cap,
- .formats = NULL, /* Filled in later depending on the */
- .num_formats = 0, /* camera type and data widths */
- .get_datawidth = mt9m001_get_datawidth,
+ .set_bus_param = mt9m001_set_bus_param,
+ .query_bus_param = mt9m001_query_bus_param,
.controls = mt9m001_controls,
.num_controls = ARRAY_SIZE(mt9m001_controls),
.get_control = mt9m001_get_control,
case 0x8411:
case 0x8421:
mt9m001->model = V4L2_IDENT_MT9M001C12ST;
- mt9m001_ops.formats = mt9m001_colour_formats;
- mt9m001_ops.num_formats = ARRAY_SIZE(mt9m001_colour_formats);
+ icd->formats = mt9m001_colour_formats;
+ if (mt9m001->client->dev.platform_data)
+ icd->num_formats = ARRAY_SIZE(mt9m001_colour_formats);
+ else
+ icd->num_formats = 1;
break;
case 0x8431:
mt9m001->model = V4L2_IDENT_MT9M001C12STM;
- mt9m001_ops.formats = mt9m001_monochrome_formats;
+ icd->formats = mt9m001_monochrome_formats;
if (mt9m001->client->dev.platform_data)
- mt9m001_ops.num_formats = ARRAY_SIZE(mt9m001_monochrome_formats);
+ icd->num_formats = ARRAY_SIZE(mt9m001_monochrome_formats);
else
- mt9m001_ops.num_formats = 1;
+ icd->num_formats = 1;
break;
default:
ret = -ENODEV;
soc_camera_video_stop(&mt9m001->icd);
}
-static int mt9m001_probe(struct i2c_client *client)
+static int mt9m001_probe(struct i2c_client *client,
+ const struct i2c_device_id *did)
{
struct mt9m001 *mt9m001;
struct soc_camera_device *icd;
/* Second stage probe - when a capture adapter is there */
icd = &mt9m001->icd;
- icd->probe = mt9m001_video_probe;
- icd->remove = mt9m001_video_remove;
icd->ops = &mt9m001_ops;
icd->control = &client->dev;
icd->x_min = 20;
return 0;
}
+static const struct i2c_device_id mt9m001_id[] = {
+ { "mt9m001", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, mt9m001_id);
+
static struct i2c_driver mt9m001_i2c_driver = {
.driver = {
.name = "mt9m001",
},
.probe = mt9m001_probe,
.remove = mt9m001_remove,
+ .id_table = mt9m001_id,
};
static int __init mt9m001_mod_init(void)