diff options
| -rw-r--r-- | recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-mt9p031-sensor-driver.patch | 918 | ||||
| -rw-r--r-- | recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-support-for-mt9p031-Aptina-Micron-sensor.patch | 773 | ||||
| -rw-r--r-- | recipes-kernel/linux/linux-omap-2.6.39/camera/0002-OMAP3BEAGLE-Add-support-for-mt9p031-sensor-driver.patch | 142 | ||||
| -rw-r--r-- | recipes-kernel/linux/linux-omap-2.6.39/camera/0002-v4l-Add-mt9v032-sensor-driver.patch (renamed from recipes-kernel/linux/linux-omap-2.6.39/camera/0004-v4l-Add-mt9v032-sensor-driver.patch) | 4 | ||||
| -rw-r--r-- | recipes-kernel/linux/linux-omap-2.6.39/camera/0003-Add-support-for-mt9p031-LI-5M03-module-in-Beagleboar.patch | 158 | ||||
| -rw-r--r-- | recipes-kernel/linux/linux-omap-2.6.39/camera/0003-OMAP3-beagle-only-init-camera-on-3630.patch | 34 | ||||
| -rw-r--r-- | recipes-kernel/linux/linux-omap_2.6.39.bb | 9 |
7 files changed, 937 insertions, 1101 deletions
diff --git a/recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-mt9p031-sensor-driver.patch b/recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-mt9p031-sensor-driver.patch deleted file mode 100644 index 9746415f..00000000 --- a/recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-mt9p031-sensor-driver.patch +++ /dev/null | |||
| @@ -1,918 +0,0 @@ | |||
| 1 | From 327e65fc0d86911bda7c1f37fb5c3534d1b2c849 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Javier Martin <javier.martin@vista-silicon.com> | ||
| 3 | Date: Thu, 26 May 2011 07:20:53 +0000 | ||
| 4 | Subject: [PATCH 1/4] Add mt9p031 sensor driver. | ||
| 5 | |||
| 6 | This patch applies on 2.6.39 (commit 61c4f2c81c61f73549928dfd9f3e8f26aa36a8cf). | ||
| 7 | It has some power management issue which causes horizontal random lines on | ||
| 8 | the image. If we do not disable 1v8 regulator, the problem disappears. | ||
| 9 | I would like to get some help on fixing whatever the problem with power | ||
| 10 | management is. | ||
| 11 | |||
| 12 | Signed-off-by: Javier Martin <javier.martin@vista-silicon.com> | ||
| 13 | --- | ||
| 14 | drivers/media/video/Kconfig | 7 + | ||
| 15 | drivers/media/video/Makefile | 1 + | ||
| 16 | drivers/media/video/mt9p031.c | 841 +++++++++++++++++++++++++++++++++++++++++ | ||
| 17 | include/media/mt9p031.h | 11 + | ||
| 18 | 4 files changed, 860 insertions(+), 0 deletions(-) | ||
| 19 | create mode 100644 drivers/media/video/mt9p031.c | ||
| 20 | create mode 100644 include/media/mt9p031.h | ||
| 21 | |||
| 22 | diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig | ||
| 23 | index 00f51dd..cb87e35 100644 | ||
| 24 | --- a/drivers/media/video/Kconfig | ||
| 25 | +++ b/drivers/media/video/Kconfig | ||
| 26 | @@ -329,6 +329,13 @@ config VIDEO_OV7670 | ||
| 27 | OV7670 VGA camera. It currently only works with the M88ALP01 | ||
| 28 | controller. | ||
| 29 | |||
| 30 | +config VIDEO_MT9P031 | ||
| 31 | + tristate "Aptina MT9P031 support" | ||
| 32 | + depends on I2C && VIDEO_V4L2 | ||
| 33 | + ---help--- | ||
| 34 | + This is a Video4Linux2 sensor-level driver for the Aptina | ||
| 35 | + (Micron) mt9p031 5 Mpixel camera. | ||
| 36 | + | ||
| 37 | config VIDEO_MT9V011 | ||
| 38 | tristate "Micron mt9v011 sensor support" | ||
| 39 | depends on I2C && VIDEO_V4L2 | ||
| 40 | diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile | ||
| 41 | index ace5d8b..912b29b 100644 | ||
| 42 | --- a/drivers/media/video/Makefile | ||
| 43 | +++ b/drivers/media/video/Makefile | ||
| 44 | @@ -65,6 +65,7 @@ obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o | ||
| 45 | obj-$(CONFIG_VIDEO_OV7670) += ov7670.o | ||
| 46 | obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o | ||
| 47 | obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o | ||
| 48 | +obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o | ||
| 49 | obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o | ||
| 50 | obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o | ||
| 51 | obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o | ||
| 52 | diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c | ||
| 53 | new file mode 100644 | ||
| 54 | index 0000000..242bea9 | ||
| 55 | --- /dev/null | ||
| 56 | +++ b/drivers/media/video/mt9p031.c | ||
| 57 | @@ -0,0 +1,841 @@ | ||
| 58 | +/* | ||
| 59 | + * Driver for MT9P031 CMOS Image Sensor from Aptina | ||
| 60 | + * | ||
| 61 | + * Copyright (C) 2011, Javier Martin <javier.martin@vista-silicon.com> | ||
| 62 | + * | ||
| 63 | + * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de> | ||
| 64 | + * | ||
| 65 | + * Based on the MT9V032 driver and Bastian Hecht's code. | ||
| 66 | + * | ||
| 67 | + * This program is free software; you can redistribute it and/or modify | ||
| 68 | + * it under the terms of the GNU General Public License version 2 as | ||
| 69 | + * published by the Free Software Foundation. | ||
| 70 | + */ | ||
| 71 | + | ||
| 72 | +#include <linux/delay.h> | ||
| 73 | +#include <linux/device.h> | ||
| 74 | +#include <linux/i2c.h> | ||
| 75 | +#include <linux/log2.h> | ||
| 76 | +#include <linux/pm.h> | ||
| 77 | +#include <linux/regulator/consumer.h> | ||
| 78 | +#include <linux/slab.h> | ||
| 79 | +#include <media/v4l2-subdev.h> | ||
| 80 | +#include <linux/videodev2.h> | ||
| 81 | + | ||
| 82 | +#include <media/mt9p031.h> | ||
| 83 | +#include <media/v4l2-chip-ident.h> | ||
| 84 | +#include <media/v4l2-subdev.h> | ||
| 85 | +#include <media/v4l2-device.h> | ||
| 86 | + | ||
| 87 | +#define MT9P031_PIXCLK_FREQ 54000000 | ||
| 88 | + | ||
| 89 | +/* mt9p031 selected register addresses */ | ||
| 90 | +#define MT9P031_CHIP_VERSION 0x00 | ||
| 91 | +#define MT9P031_CHIP_VERSION_VALUE 0x1801 | ||
| 92 | +#define MT9P031_ROW_START 0x01 | ||
| 93 | +#define MT9P031_ROW_START_DEF 54 | ||
| 94 | +#define MT9P031_COLUMN_START 0x02 | ||
| 95 | +#define MT9P031_COLUMN_START_DEF 16 | ||
| 96 | +#define MT9P031_WINDOW_HEIGHT 0x03 | ||
| 97 | +#define MT9P031_WINDOW_WIDTH 0x04 | ||
| 98 | +#define MT9P031_H_BLANKING 0x05 | ||
| 99 | +#define MT9P031_H_BLANKING_VALUE 0 | ||
| 100 | +#define MT9P031_V_BLANKING 0x06 | ||
| 101 | +#define MT9P031_V_BLANKING_VALUE 25 | ||
| 102 | +#define MT9P031_OUTPUT_CONTROL 0x07 | ||
| 103 | +#define MT9P031_OUTPUT_CONTROL_CEN 2 | ||
| 104 | +#define MT9P031_OUTPUT_CONTROL_SYN 1 | ||
| 105 | +#define MT9P031_SHUTTER_WIDTH_UPPER 0x08 | ||
| 106 | +#define MT9P031_SHUTTER_WIDTH 0x09 | ||
| 107 | +#define MT9P031_PIXEL_CLOCK_CONTROL 0x0a | ||
| 108 | +#define MT9P031_FRAME_RESTART 0x0b | ||
| 109 | +#define MT9P031_SHUTTER_DELAY 0x0c | ||
| 110 | +#define MT9P031_RST 0x0d | ||
| 111 | +#define MT9P031_RST_ENABLE 1 | ||
| 112 | +#define MT9P031_RST_DISABLE 0 | ||
| 113 | +#define MT9P031_READ_MODE_1 0x1e | ||
| 114 | +#define MT9P031_READ_MODE_2 0x20 | ||
| 115 | +#define MT9P031_READ_MODE_2_ROW_MIR 0x8000 | ||
| 116 | +#define MT9P031_READ_MODE_2_COL_MIR 0x4000 | ||
| 117 | +#define MT9P031_ROW_ADDRESS_MODE 0x22 | ||
| 118 | +#define MT9P031_COLUMN_ADDRESS_MODE 0x23 | ||
| 119 | +#define MT9P031_GLOBAL_GAIN 0x35 | ||
| 120 | + | ||
| 121 | +#define MT9P031_WINDOW_HEIGHT_MAX 1944 | ||
| 122 | +#define MT9P031_WINDOW_WIDTH_MAX 2592 | ||
| 123 | +#define MT9P031_WINDOW_HEIGHT_MIN 2 | ||
| 124 | +#define MT9P031_WINDOW_WIDTH_MIN 18 | ||
| 125 | + | ||
| 126 | +struct mt9p031 { | ||
| 127 | + struct v4l2_subdev subdev; | ||
| 128 | + struct media_pad pad; | ||
| 129 | + struct v4l2_rect rect; /* Sensor window */ | ||
| 130 | + struct v4l2_mbus_framefmt format; | ||
| 131 | + struct mt9p031_platform_data *pdata; | ||
| 132 | + struct mutex power_lock; /* lock to protect power_count */ | ||
| 133 | + int power_count; | ||
| 134 | + u16 xskip; | ||
| 135 | + u16 yskip; | ||
| 136 | + /* cache register values */ | ||
| 137 | + u16 output_control; | ||
| 138 | + u16 h_blanking; | ||
| 139 | + u16 v_blanking; | ||
| 140 | + u16 column_address_mode; | ||
| 141 | + u16 row_address_mode; | ||
| 142 | + u16 column_start; | ||
| 143 | + u16 row_start; | ||
| 144 | + u16 window_width; | ||
| 145 | + u16 window_height; | ||
| 146 | + struct regulator *reg_1v8; | ||
| 147 | + struct regulator *reg_2v8; | ||
| 148 | +}; | ||
| 149 | + | ||
| 150 | +static struct mt9p031 *to_mt9p031(const struct i2c_client *client) | ||
| 151 | +{ | ||
| 152 | + return container_of(i2c_get_clientdata(client), struct mt9p031, subdev); | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +static int reg_read(struct i2c_client *client, const u8 reg) | ||
| 156 | +{ | ||
| 157 | + s32 data = i2c_smbus_read_word_data(client, reg); | ||
| 158 | + return data < 0 ? data : swab16(data); | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +static int reg_write(struct i2c_client *client, const u8 reg, | ||
| 162 | + const u16 data) | ||
| 163 | +{ | ||
| 164 | + return i2c_smbus_write_word_data(client, reg, swab16(data)); | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +static int reg_write_cached(struct i2c_client *client, const u8 reg, | ||
| 168 | + const u16 data, u16 *cache) | ||
| 169 | +{ | ||
| 170 | + int ret; | ||
| 171 | + | ||
| 172 | + ret = reg_write(client, reg, data); | ||
| 173 | + if (ret < 0) | ||
| 174 | + return ret; | ||
| 175 | + *cache = data; | ||
| 176 | + return 0; | ||
| 177 | +} | ||
| 178 | + | ||
| 179 | +static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear, | ||
| 180 | + u16 set) | ||
| 181 | +{ | ||
| 182 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 183 | + u16 value = (mt9p031->output_control & ~clear) | set; | ||
| 184 | + | ||
| 185 | + return reg_write_cached(client, MT9P031_OUTPUT_CONTROL, value, | ||
| 186 | + &mt9p031->output_control); | ||
| 187 | +} | ||
| 188 | + | ||
| 189 | +static int restore_registers(struct i2c_client *client) | ||
| 190 | +{ | ||
| 191 | + int ret; | ||
| 192 | + struct mt9p031 *mt9p031 = to_mt9p031(client); | ||
| 193 | + | ||
| 194 | + /* Disable register update, reconfigure atomically */ | ||
| 195 | + ret = mt9p031_set_output_control(mt9p031, 0, | ||
| 196 | + MT9P031_OUTPUT_CONTROL_SYN); | ||
| 197 | + if (ret < 0) | ||
| 198 | + return ret; | ||
| 199 | + | ||
| 200 | + /* Blanking and start values - default... */ | ||
| 201 | + ret = reg_write(client, MT9P031_H_BLANKING, mt9p031->h_blanking); | ||
| 202 | + if (ret < 0) | ||
| 203 | + return ret; | ||
| 204 | + | ||
| 205 | + ret = reg_write(client, MT9P031_V_BLANKING, mt9p031->v_blanking); | ||
| 206 | + if (ret < 0) | ||
| 207 | + return ret; | ||
| 208 | + | ||
| 209 | + ret = reg_write(client, MT9P031_COLUMN_ADDRESS_MODE, | ||
| 210 | + mt9p031->column_address_mode); | ||
| 211 | + if (ret < 0) | ||
| 212 | + return ret; | ||
| 213 | + | ||
| 214 | + ret = reg_write(client, MT9P031_ROW_ADDRESS_MODE, | ||
| 215 | + mt9p031->row_address_mode); | ||
| 216 | + if (ret < 0) | ||
| 217 | + return ret; | ||
| 218 | + | ||
| 219 | + ret = reg_write(client, MT9P031_COLUMN_START, | ||
| 220 | + mt9p031->column_start); | ||
| 221 | + if (ret < 0) | ||
| 222 | + return ret; | ||
| 223 | + | ||
| 224 | + ret = reg_write(client, MT9P031_ROW_START, | ||
| 225 | + mt9p031->row_start); | ||
| 226 | + if (ret < 0) | ||
| 227 | + return ret; | ||
| 228 | + | ||
| 229 | + ret = reg_write(client, MT9P031_WINDOW_WIDTH, | ||
| 230 | + mt9p031->window_width); | ||
| 231 | + if (ret < 0) | ||
| 232 | + return ret; | ||
| 233 | + | ||
| 234 | + ret = reg_write(client, MT9P031_WINDOW_HEIGHT, | ||
| 235 | + mt9p031->window_height); | ||
| 236 | + if (ret < 0) | ||
| 237 | + return ret; | ||
| 238 | + | ||
| 239 | + /* Re-enable register update, commit all changes */ | ||
| 240 | + ret = mt9p031_set_output_control(mt9p031, | ||
| 241 | + MT9P031_OUTPUT_CONTROL_SYN, 0); | ||
| 242 | + if (ret < 0) | ||
| 243 | + return ret; | ||
| 244 | + return 0; | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | +static int mt9p031_reset(struct i2c_client *client) | ||
| 248 | +{ | ||
| 249 | + struct mt9p031 *mt9p031 = to_mt9p031(client); | ||
| 250 | + int ret; | ||
| 251 | + | ||
| 252 | + /* Disable chip output, synchronous option update */ | ||
| 253 | + ret = reg_write(client, MT9P031_RST, MT9P031_RST_ENABLE); | ||
| 254 | + if (ret < 0) | ||
| 255 | + return ret; | ||
| 256 | + ret = reg_write(client, MT9P031_RST, MT9P031_RST_DISABLE); | ||
| 257 | + if (ret < 0) | ||
| 258 | + return ret; | ||
| 259 | + return mt9p031_set_output_control(mt9p031, | ||
| 260 | + MT9P031_OUTPUT_CONTROL_CEN, 0); | ||
| 261 | +} | ||
| 262 | + | ||
| 263 | +static int mt9p031_power_on(struct mt9p031 *mt9p031) | ||
| 264 | +{ | ||
| 265 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 266 | + int ret; | ||
| 267 | + | ||
| 268 | + /* Ensure RESET_BAR is low */ | ||
| 269 | + if (mt9p031->pdata->reset) | ||
| 270 | + mt9p031->pdata->reset(&mt9p031->subdev, 1); | ||
| 271 | + /* turn on digital supply first */ | ||
| 272 | + ret = regulator_enable(mt9p031->reg_1v8); | ||
| 273 | + if (ret) { | ||
| 274 | + dev_err(&client->dev, | ||
| 275 | + "Failed to enable 1.8v regulator: %d\n", ret); | ||
| 276 | + goto err_1v8; | ||
| 277 | + } | ||
| 278 | + /* now turn on analog supply */ | ||
| 279 | + ret = regulator_enable(mt9p031->reg_2v8); | ||
| 280 | + if (ret) { | ||
| 281 | + dev_err(&client->dev, | ||
| 282 | + "Failed to enable 2.8v regulator: %d\n", ret); | ||
| 283 | + goto err_rst; | ||
| 284 | + } | ||
| 285 | + /* Now RESET_BAR must be high */ | ||
| 286 | + if (mt9p031->pdata->reset) | ||
| 287 | + mt9p031->pdata->reset(&mt9p031->subdev, 0); | ||
| 288 | + | ||
| 289 | + if (mt9p031->pdata->set_xclk) | ||
| 290 | + mt9p031->pdata->set_xclk(&mt9p031->subdev, MT9P031_PIXCLK_FREQ); | ||
| 291 | + | ||
| 292 | + /* soft reset */ | ||
| 293 | + ret = mt9p031_reset(client); | ||
| 294 | + if (ret < 0) { | ||
| 295 | + dev_err(&client->dev, "Failed to reset the camera\n"); | ||
| 296 | + goto err_rst; | ||
| 297 | + } | ||
| 298 | + | ||
| 299 | + ret = restore_registers(client); | ||
| 300 | + if (ret < 0) { | ||
| 301 | + dev_err(&client->dev, "Failed to restore registers\n"); | ||
| 302 | + goto err_rst; | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + return 0; | ||
| 306 | +err_rst: | ||
| 307 | + regulator_disable(mt9p031->reg_1v8); | ||
| 308 | +err_1v8: | ||
| 309 | + return ret; | ||
| 310 | + | ||
| 311 | +} | ||
| 312 | + | ||
| 313 | +static void mt9p031_power_off(struct mt9p031 *mt9p031) | ||
| 314 | +{ | ||
| 315 | + if (mt9p031->pdata->set_xclk) | ||
| 316 | + mt9p031->pdata->set_xclk(&mt9p031->subdev, 0); | ||
| 317 | + if (mt9p031->pdata->reset) | ||
| 318 | + mt9p031->pdata->reset(&mt9p031->subdev, 1); | ||
| 319 | + regulator_disable(mt9p031->reg_1v8); | ||
| 320 | + regulator_disable(mt9p031->reg_2v8); | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | +static int mt9p031_enum_mbus_code(struct v4l2_subdev *sd, | ||
| 324 | + struct v4l2_subdev_fh *fh, | ||
| 325 | + struct v4l2_subdev_mbus_code_enum *code) | ||
| 326 | +{ | ||
| 327 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 328 | + | ||
| 329 | + if (code->pad || code->index) | ||
| 330 | + return -EINVAL; | ||
| 331 | + | ||
| 332 | + code->code = mt9p031->format.code; | ||
| 333 | + | ||
| 334 | + return 0; | ||
| 335 | +} | ||
| 336 | + | ||
| 337 | +static struct v4l2_mbus_framefmt *mt9p031_get_pad_format( | ||
| 338 | + struct mt9p031 *mt9p031, | ||
| 339 | + struct v4l2_subdev_fh *fh, | ||
| 340 | + unsigned int pad, u32 which) | ||
| 341 | +{ | ||
| 342 | + switch (which) { | ||
| 343 | + case V4L2_SUBDEV_FORMAT_TRY: | ||
| 344 | + return v4l2_subdev_get_try_format(fh, pad); | ||
| 345 | + case V4L2_SUBDEV_FORMAT_ACTIVE: | ||
| 346 | + return &mt9p031->format; | ||
| 347 | + default: | ||
| 348 | + return NULL; | ||
| 349 | + } | ||
| 350 | +} | ||
| 351 | + | ||
| 352 | +static struct v4l2_rect *mt9p031_get_pad_crop(struct mt9p031 *mt9p031, | ||
| 353 | + struct v4l2_subdev_fh *fh, unsigned int pad, u32 which) | ||
| 354 | +{ | ||
| 355 | + switch (which) { | ||
| 356 | + case V4L2_SUBDEV_FORMAT_TRY: | ||
| 357 | + return v4l2_subdev_get_try_crop(fh, pad); | ||
| 358 | + case V4L2_SUBDEV_FORMAT_ACTIVE: | ||
| 359 | + return &mt9p031->rect; | ||
| 360 | + default: | ||
| 361 | + return NULL; | ||
| 362 | + } | ||
| 363 | +} | ||
| 364 | + | ||
| 365 | +static int mt9p031_get_crop(struct v4l2_subdev *sd, | ||
| 366 | + struct v4l2_subdev_fh *fh, | ||
| 367 | + struct v4l2_subdev_crop *crop) | ||
| 368 | +{ | ||
| 369 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 370 | + struct v4l2_rect *rect = mt9p031_get_pad_crop(mt9p031, fh, crop->pad, | ||
| 371 | + crop->which); | ||
| 372 | + if (!rect) | ||
| 373 | + return -EINVAL; | ||
| 374 | + | ||
| 375 | + crop->rect = *rect; | ||
| 376 | + | ||
| 377 | + return 0; | ||
| 378 | +} | ||
| 379 | + | ||
| 380 | +static u16 mt9p031_skip_for_crop(s32 source, s32 *target, s32 max_skip) | ||
| 381 | +{ | ||
| 382 | + unsigned int skip; | ||
| 383 | + | ||
| 384 | + if (source - source / 4 < *target) { | ||
| 385 | + *target = source; | ||
| 386 | + return 1; | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + skip = DIV_ROUND_CLOSEST(source, *target); | ||
| 390 | + if (skip > max_skip) | ||
| 391 | + skip = max_skip; | ||
| 392 | + *target = 2 * DIV_ROUND_UP(source, 2 * skip); | ||
| 393 | + | ||
| 394 | + return skip; | ||
| 395 | +} | ||
| 396 | + | ||
| 397 | +static int mt9p031_set_params(struct i2c_client *client, | ||
| 398 | + struct v4l2_rect *rect, u16 xskip, u16 yskip) | ||
| 399 | +{ | ||
| 400 | + struct mt9p031 *mt9p031 = to_mt9p031(client); | ||
| 401 | + int ret; | ||
| 402 | + u16 xbin, ybin; | ||
| 403 | + const u16 hblank = MT9P031_H_BLANKING_VALUE, | ||
| 404 | + vblank = MT9P031_V_BLANKING_VALUE; | ||
| 405 | + __s32 left, top, width, height; | ||
| 406 | + | ||
| 407 | + /* | ||
| 408 | + * TODO: Attention! When implementing horizontal flipping, adjust | ||
| 409 | + * alignment according to R2 "Column Start" description in the datasheet | ||
| 410 | + */ | ||
| 411 | + if (xskip & 1) { | ||
| 412 | + xbin = 1; | ||
| 413 | + left = rect->left & (~3); | ||
| 414 | + } else if (xskip & 2) { | ||
| 415 | + xbin = 2; | ||
| 416 | + left = rect->left & (~7); | ||
| 417 | + } else { | ||
| 418 | + xbin = 4; | ||
| 419 | + left = rect->left & (~15); | ||
| 420 | + } | ||
| 421 | + top = rect->top & (~1); | ||
| 422 | + width = rect->width; | ||
| 423 | + height = rect->height; | ||
| 424 | + | ||
| 425 | + ybin = min(yskip, (u16)4); | ||
| 426 | + | ||
| 427 | + /* Disable register update, reconfigure atomically */ | ||
| 428 | + ret = mt9p031_set_output_control(mt9p031, 0, | ||
| 429 | + MT9P031_OUTPUT_CONTROL_SYN); | ||
| 430 | + if (ret < 0) | ||
| 431 | + return ret; | ||
| 432 | + | ||
| 433 | + dev_dbg(&client->dev, "skip %u:%u, rect %ux%u@%u:%u\n", | ||
| 434 | + xskip, yskip, rect->width, rect->height, rect->left, rect->top); | ||
| 435 | + | ||
| 436 | + /* Blanking and start values - default... */ | ||
| 437 | + ret = reg_write_cached(client, MT9P031_H_BLANKING, hblank, | ||
| 438 | + &mt9p031->h_blanking); | ||
| 439 | + if (ret < 0) | ||
| 440 | + return ret; | ||
| 441 | + ret = reg_write_cached(client, MT9P031_V_BLANKING, vblank, | ||
| 442 | + &mt9p031->v_blanking); | ||
| 443 | + if (ret < 0) | ||
| 444 | + return ret; | ||
| 445 | + | ||
| 446 | + ret = reg_write_cached(client, MT9P031_COLUMN_ADDRESS_MODE, | ||
| 447 | + ((xbin - 1) << 4) | (xskip - 1), | ||
| 448 | + &mt9p031->column_address_mode); | ||
| 449 | + if (ret < 0) | ||
| 450 | + return ret; | ||
| 451 | + ret = reg_write_cached(client, MT9P031_ROW_ADDRESS_MODE, | ||
| 452 | + ((ybin - 1) << 4) | (yskip - 1), | ||
| 453 | + &mt9p031->row_address_mode); | ||
| 454 | + if (ret < 0) | ||
| 455 | + return ret; | ||
| 456 | + | ||
| 457 | + dev_dbg(&client->dev, "new physical left %u, top %u\n", | ||
| 458 | + rect->left, rect->top); | ||
| 459 | + | ||
| 460 | + ret = reg_write_cached(client, MT9P031_COLUMN_START, | ||
| 461 | + rect->left + MT9P031_COLUMN_START_DEF, | ||
| 462 | + &mt9p031->column_start); | ||
| 463 | + if (ret < 0) | ||
| 464 | + return ret; | ||
| 465 | + ret = reg_write_cached(client, MT9P031_ROW_START, | ||
| 466 | + rect->top + MT9P031_ROW_START_DEF, | ||
| 467 | + &mt9p031->row_start); | ||
| 468 | + if (ret < 0) | ||
| 469 | + return ret; | ||
| 470 | + ret = reg_write_cached(client, MT9P031_WINDOW_WIDTH, | ||
| 471 | + rect->width - 1, | ||
| 472 | + &mt9p031->window_width); | ||
| 473 | + if (ret < 0) | ||
| 474 | + return ret; | ||
| 475 | + ret = reg_write_cached(client, MT9P031_WINDOW_HEIGHT, | ||
| 476 | + rect->height - 1, | ||
| 477 | + &mt9p031->window_height); | ||
| 478 | + if (ret < 0) | ||
| 479 | + return ret; | ||
| 480 | + | ||
| 481 | + /* Re-enable register update, commit all changes */ | ||
| 482 | + ret = mt9p031_set_output_control(mt9p031, | ||
| 483 | + MT9P031_OUTPUT_CONTROL_SYN, 0); | ||
| 484 | + if (ret < 0) | ||
| 485 | + return ret; | ||
| 486 | + | ||
| 487 | + mt9p031->xskip = xskip; | ||
| 488 | + mt9p031->yskip = yskip; | ||
| 489 | + return ret; | ||
| 490 | +} | ||
| 491 | + | ||
| 492 | +static int mt9p031_set_crop(struct v4l2_subdev *sd, | ||
| 493 | + struct v4l2_subdev_fh *fh, | ||
| 494 | + struct v4l2_subdev_crop *crop) | ||
| 495 | +{ | ||
| 496 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 497 | + struct v4l2_mbus_framefmt *f; | ||
| 498 | + struct v4l2_rect *c; | ||
| 499 | + struct v4l2_rect rect; | ||
| 500 | + u16 xskip, yskip; | ||
| 501 | + s32 width, height; | ||
| 502 | + | ||
| 503 | + dev_dbg(mt9p031->subdev.v4l2_dev->dev, "%s(%ux%u@%u:%u : %u)\n", | ||
| 504 | + __func__, crop->rect.width, crop->rect.height, | ||
| 505 | + crop->rect.left, crop->rect.top, crop->which); | ||
| 506 | + | ||
| 507 | + /* | ||
| 508 | + * Clamp the crop rectangle boundaries and align them to a multiple of 2 | ||
| 509 | + * pixels. | ||
| 510 | + */ | ||
| 511 | + rect.width = ALIGN(clamp(crop->rect.width, | ||
| 512 | + MT9P031_WINDOW_WIDTH_MIN, MT9P031_WINDOW_WIDTH_MAX), 2); | ||
| 513 | + rect.height = ALIGN(clamp(crop->rect.height, | ||
| 514 | + MT9P031_WINDOW_HEIGHT_MIN, MT9P031_WINDOW_HEIGHT_MAX), 2); | ||
| 515 | + rect.left = ALIGN(clamp(crop->rect.left, | ||
| 516 | + 0, MT9P031_WINDOW_WIDTH_MAX - rect.width), 2); | ||
| 517 | + rect.top = ALIGN(clamp(crop->rect.top, | ||
| 518 | + 0, MT9P031_WINDOW_HEIGHT_MAX - rect.height), 2); | ||
| 519 | + | ||
| 520 | + c = mt9p031_get_pad_crop(mt9p031, fh, crop->pad, crop->which); | ||
| 521 | + | ||
| 522 | + if (rect.width != c->width || rect.height != c->height) { | ||
| 523 | + /* | ||
| 524 | + * Reset the output image size if the crop rectangle size has | ||
| 525 | + * been modified. | ||
| 526 | + */ | ||
| 527 | + f = mt9p031_get_pad_format(mt9p031, fh, crop->pad, | ||
| 528 | + crop->which); | ||
| 529 | + width = f->width; | ||
| 530 | + height = f->height; | ||
| 531 | + | ||
| 532 | + xskip = mt9p031_skip_for_crop(rect.width, &width, 7); | ||
| 533 | + yskip = mt9p031_skip_for_crop(rect.height, &height, 8); | ||
| 534 | + } else { | ||
| 535 | + xskip = mt9p031->xskip; | ||
| 536 | + yskip = mt9p031->yskip; | ||
| 537 | + f = NULL; | ||
| 538 | + } | ||
| 539 | + if (f) { | ||
| 540 | + f->width = width; | ||
| 541 | + f->height = height; | ||
| 542 | + } | ||
| 543 | + | ||
| 544 | + *c = rect; | ||
| 545 | + crop->rect = rect; | ||
| 546 | + | ||
| 547 | + mt9p031->xskip = xskip; | ||
| 548 | + mt9p031->yskip = yskip; | ||
| 549 | + mt9p031->rect = *c; | ||
| 550 | + return 0; | ||
| 551 | +} | ||
| 552 | + | ||
| 553 | +static int mt9p031_get_format(struct v4l2_subdev *sd, | ||
| 554 | + struct v4l2_subdev_fh *fh, | ||
| 555 | + struct v4l2_subdev_format *fmt) | ||
| 556 | +{ | ||
| 557 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 558 | + | ||
| 559 | + fmt->format = | ||
| 560 | + *mt9p031_get_pad_format(mt9p031, fh, fmt->pad, fmt->which); | ||
| 561 | + return 0; | ||
| 562 | +} | ||
| 563 | + | ||
| 564 | +static u16 mt9p031_skip_for_scale(s32 *source, s32 target, | ||
| 565 | + s32 max_skip, s32 max) | ||
| 566 | +{ | ||
| 567 | + unsigned int skip; | ||
| 568 | + | ||
| 569 | + if (*source - *source / 4 < target) { | ||
| 570 | + *source = target; | ||
| 571 | + return 1; | ||
| 572 | + } | ||
| 573 | + | ||
| 574 | + skip = min(max, *source + target / 2) / target; | ||
| 575 | + if (skip > max_skip) | ||
| 576 | + skip = max_skip; | ||
| 577 | + *source = target * skip; | ||
| 578 | + | ||
| 579 | + return skip; | ||
| 580 | +} | ||
| 581 | + | ||
| 582 | +static int mt9p031_fmt_validate(struct v4l2_subdev *sd, | ||
| 583 | + struct v4l2_subdev_format *fmt) | ||
| 584 | +{ | ||
| 585 | + struct v4l2_mbus_framefmt *format = &fmt->format; | ||
| 586 | + | ||
| 587 | + /* Hardcode code and colorspace as sensor only supports one */ | ||
| 588 | + format->code = V4L2_MBUS_FMT_SGRBG12_1X12; | ||
| 589 | + format->colorspace = V4L2_COLORSPACE_SRGB; | ||
| 590 | + | ||
| 591 | + format->width = clamp_t(int, ALIGN(format->width, 2), 2, | ||
| 592 | + MT9P031_WINDOW_WIDTH_MAX); | ||
| 593 | + format->height = clamp_t(int, ALIGN(format->height, 2), 2, | ||
| 594 | + MT9P031_WINDOW_HEIGHT_MAX); | ||
| 595 | + format->field = V4L2_FIELD_NONE; | ||
| 596 | + | ||
| 597 | + return 0; | ||
| 598 | +} | ||
| 599 | + | ||
| 600 | +static int mt9p031_set_format(struct v4l2_subdev *sd, | ||
| 601 | + struct v4l2_subdev_fh *fh, | ||
| 602 | + struct v4l2_subdev_format *format) | ||
| 603 | +{ | ||
| 604 | + struct v4l2_subdev_format sdf = *format; | ||
| 605 | + struct v4l2_mbus_framefmt *__format, *format_bak = &sdf.format; | ||
| 606 | + struct v4l2_rect *__crop, rect; | ||
| 607 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 608 | + u16 xskip, yskip; | ||
| 609 | + int ret; | ||
| 610 | + | ||
| 611 | + __crop = mt9p031_get_pad_crop(mt9p031, fh, format->pad, format->which); | ||
| 612 | + | ||
| 613 | + ret = mt9p031_fmt_validate(sd, &sdf); | ||
| 614 | + if (ret < 0) | ||
| 615 | + return ret; | ||
| 616 | + rect.width = __crop->width; | ||
| 617 | + rect.height = __crop->height; | ||
| 618 | + | ||
| 619 | + xskip = mt9p031_skip_for_scale(&rect.width, format_bak->width, 7, | ||
| 620 | + MT9P031_WINDOW_WIDTH_MAX); | ||
| 621 | + if (rect.width + __crop->left > MT9P031_WINDOW_WIDTH_MAX) | ||
| 622 | + rect.left = (MT9P031_WINDOW_WIDTH_MAX - rect.width) / 2; | ||
| 623 | + else | ||
| 624 | + rect.left = __crop->left; | ||
| 625 | + yskip = mt9p031_skip_for_scale(&rect.height, format_bak->height, 8, | ||
| 626 | + MT9P031_WINDOW_HEIGHT_MAX); | ||
| 627 | + if (rect.height + __crop->top > MT9P031_WINDOW_HEIGHT_MAX) | ||
| 628 | + rect.top = (MT9P031_WINDOW_HEIGHT_MAX - rect.height) / 2; | ||
| 629 | + else | ||
| 630 | + rect.top = __crop->top; | ||
| 631 | + | ||
| 632 | + dev_dbg(mt9p031->subdev.v4l2_dev->dev, "%s(%ux%u : %u)\n", __func__, | ||
| 633 | + format_bak->width, format_bak->height, format->which); | ||
| 634 | + if (__crop) | ||
| 635 | + *__crop = rect; | ||
| 636 | + | ||
| 637 | + __format = mt9p031_get_pad_format(mt9p031, fh, format->pad, format->which); | ||
| 638 | + *__format = *format_bak; | ||
| 639 | + format->format = *format_bak; | ||
| 640 | + | ||
| 641 | + mt9p031->xskip = xskip; | ||
| 642 | + mt9p031->yskip = yskip; | ||
| 643 | + mt9p031->rect = *__crop; | ||
| 644 | + return 0; | ||
| 645 | +} | ||
| 646 | + | ||
| 647 | +static int mt9p031_s_stream(struct v4l2_subdev *sd, int enable) | ||
| 648 | +{ | ||
| 649 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 650 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 651 | + struct v4l2_rect rect = mt9p031->rect; | ||
| 652 | + u16 xskip = mt9p031->xskip; | ||
| 653 | + u16 yskip = mt9p031->yskip; | ||
| 654 | + int ret; | ||
| 655 | + | ||
| 656 | + if (enable) { | ||
| 657 | + ret = mt9p031_set_params(client, &rect, xskip, yskip); | ||
| 658 | + if (ret < 0) | ||
| 659 | + return ret; | ||
| 660 | + /* Switch to master "normal" mode */ | ||
| 661 | + ret = mt9p031_set_output_control(mt9p031, 0, | ||
| 662 | + MT9P031_OUTPUT_CONTROL_CEN); | ||
| 663 | + } else { | ||
| 664 | + /* Stop sensor readout */ | ||
| 665 | + ret = mt9p031_set_output_control(mt9p031, | ||
| 666 | + MT9P031_OUTPUT_CONTROL_CEN, 0); | ||
| 667 | + } | ||
| 668 | + return ret; | ||
| 669 | +} | ||
| 670 | + | ||
| 671 | +static int mt9p031_video_probe(struct i2c_client *client) | ||
| 672 | +{ | ||
| 673 | + s32 data; | ||
| 674 | + | ||
| 675 | + /* Read out the chip version register */ | ||
| 676 | + data = reg_read(client, MT9P031_CHIP_VERSION); | ||
| 677 | + if (data != MT9P031_CHIP_VERSION_VALUE) { | ||
| 678 | + dev_err(&client->dev, | ||
| 679 | + "No MT9P031 chip detected, register read %x\n", data); | ||
| 680 | + return -ENODEV; | ||
| 681 | + } | ||
| 682 | + | ||
| 683 | + dev_info(&client->dev, "Detected a MT9P031 chip ID %x\n", data); | ||
| 684 | + | ||
| 685 | + return 0; | ||
| 686 | +} | ||
| 687 | + | ||
| 688 | +static int mt9p031_set_power(struct v4l2_subdev *sd, int on) | ||
| 689 | +{ | ||
| 690 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 691 | + int ret = 0; | ||
| 692 | + | ||
| 693 | + mutex_lock(&mt9p031->power_lock); | ||
| 694 | + | ||
| 695 | + /* | ||
| 696 | + * If the power count is modified from 0 to != 0 or from != 0 to 0, | ||
| 697 | + * update the power state. | ||
| 698 | + */ | ||
| 699 | + if (mt9p031->power_count == !on) { | ||
| 700 | + if (on) { | ||
| 701 | + ret = mt9p031_power_on(mt9p031); | ||
| 702 | + if (ret) { | ||
| 703 | + dev_err(mt9p031->subdev.v4l2_dev->dev, | ||
| 704 | + "Failed to enable 2.8v regulator: %d\n", ret); | ||
| 705 | + goto out; | ||
| 706 | + } | ||
| 707 | + } else { | ||
| 708 | + mt9p031_power_off(mt9p031); | ||
| 709 | + } | ||
| 710 | + } | ||
| 711 | + | ||
| 712 | + /* Update the power count. */ | ||
| 713 | + mt9p031->power_count += on ? 1 : -1; | ||
| 714 | + WARN_ON(mt9p031->power_count < 0); | ||
| 715 | + | ||
| 716 | +out: | ||
| 717 | + mutex_unlock(&mt9p031->power_lock); | ||
| 718 | + return ret; | ||
| 719 | +} | ||
| 720 | + | ||
| 721 | +static int mt9p031_registered(struct v4l2_subdev *sd) | ||
| 722 | +{ | ||
| 723 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 724 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 725 | + int ret; | ||
| 726 | + | ||
| 727 | + ret = mt9p031_set_power(&mt9p031->subdev, 1); | ||
| 728 | + if (ret) { | ||
| 729 | + dev_err(&client->dev, | ||
| 730 | + "Failed to power on device: %d\n", ret); | ||
| 731 | + goto err_pwron; | ||
| 732 | + } | ||
| 733 | + | ||
| 734 | + ret = mt9p031_video_probe(client); | ||
| 735 | + if (ret) | ||
| 736 | + goto err_evprobe; | ||
| 737 | + | ||
| 738 | + mt9p031->pad.flags = MEDIA_PAD_FL_SOURCE; | ||
| 739 | + ret = media_entity_init(&mt9p031->subdev.entity, 1, &mt9p031->pad, 0); | ||
| 740 | + if (ret) | ||
| 741 | + goto err_evprobe; | ||
| 742 | + | ||
| 743 | + mt9p031->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; | ||
| 744 | + mt9p031_set_power(&mt9p031->subdev, 0); | ||
| 745 | + | ||
| 746 | + return 0; | ||
| 747 | +err_evprobe: | ||
| 748 | + mt9p031_set_power(&mt9p031->subdev, 0); | ||
| 749 | +err_pwron: | ||
| 750 | + return ret; | ||
| 751 | +} | ||
| 752 | + | ||
| 753 | +static int mt9p031_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) | ||
| 754 | +{ | ||
| 755 | + struct mt9p031 *mt9p031; | ||
| 756 | + mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 757 | + | ||
| 758 | + mt9p031->rect.width = MT9P031_WINDOW_WIDTH_MAX; | ||
| 759 | + mt9p031->rect.height = MT9P031_WINDOW_HEIGHT_MAX; | ||
| 760 | + mt9p031->rect.left = MT9P031_COLUMN_START_DEF; | ||
| 761 | + mt9p031->rect.top = MT9P031_ROW_START_DEF; | ||
| 762 | + | ||
| 763 | + mt9p031->format.code = V4L2_MBUS_FMT_SGRBG12_1X12; | ||
| 764 | + mt9p031->format.width = MT9P031_WINDOW_WIDTH_MAX; | ||
| 765 | + mt9p031->format.height = MT9P031_WINDOW_HEIGHT_MAX; | ||
| 766 | + mt9p031->format.field = V4L2_FIELD_NONE; | ||
| 767 | + mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; | ||
| 768 | + | ||
| 769 | + mt9p031->xskip = 1; | ||
| 770 | + mt9p031->yskip = 1; | ||
| 771 | + return mt9p031_set_power(sd, 1); | ||
| 772 | +} | ||
| 773 | + | ||
| 774 | +static int mt9p031_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) | ||
| 775 | +{ | ||
| 776 | + return mt9p031_set_power(sd, 0); | ||
| 777 | +} | ||
| 778 | + | ||
| 779 | +static struct v4l2_subdev_core_ops mt9p031_subdev_core_ops = { | ||
| 780 | + .s_power = mt9p031_set_power, | ||
| 781 | +}; | ||
| 782 | + | ||
| 783 | +static struct v4l2_subdev_video_ops mt9p031_subdev_video_ops = { | ||
| 784 | + .s_stream = mt9p031_s_stream, | ||
| 785 | +}; | ||
| 786 | + | ||
| 787 | +static struct v4l2_subdev_pad_ops mt9p031_subdev_pad_ops = { | ||
| 788 | + .enum_mbus_code = mt9p031_enum_mbus_code, | ||
| 789 | + .get_fmt = mt9p031_get_format, | ||
| 790 | + .set_fmt = mt9p031_set_format, | ||
| 791 | + .get_crop = mt9p031_get_crop, | ||
| 792 | + .set_crop = mt9p031_set_crop, | ||
| 793 | +}; | ||
| 794 | + | ||
| 795 | +static struct v4l2_subdev_ops mt9p031_subdev_ops = { | ||
| 796 | + .core = &mt9p031_subdev_core_ops, | ||
| 797 | + .video = &mt9p031_subdev_video_ops, | ||
| 798 | + .pad = &mt9p031_subdev_pad_ops, | ||
| 799 | +}; | ||
| 800 | + | ||
| 801 | +static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { | ||
| 802 | + .registered = mt9p031_registered, | ||
| 803 | + .open = mt9p031_open, | ||
| 804 | + .close = mt9p031_close, | ||
| 805 | +}; | ||
| 806 | + | ||
| 807 | +static int mt9p031_probe(struct i2c_client *client, | ||
| 808 | + const struct i2c_device_id *did) | ||
| 809 | +{ | ||
| 810 | + struct mt9p031 *mt9p031; | ||
| 811 | + struct mt9p031_platform_data *pdata = client->dev.platform_data; | ||
| 812 | + struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | ||
| 813 | + int ret; | ||
| 814 | + | ||
| 815 | + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) { | ||
| 816 | + dev_warn(&adapter->dev, | ||
| 817 | + "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n"); | ||
| 818 | + return -EIO; | ||
| 819 | + } | ||
| 820 | + | ||
| 821 | + mt9p031 = kzalloc(sizeof(struct mt9p031), GFP_KERNEL); | ||
| 822 | + if (!mt9p031) | ||
| 823 | + return -ENOMEM; | ||
| 824 | + | ||
| 825 | + mutex_init(&mt9p031->power_lock); | ||
| 826 | + v4l2_i2c_subdev_init(&mt9p031->subdev, client, &mt9p031_subdev_ops); | ||
| 827 | + mt9p031->subdev.internal_ops = &mt9p031_subdev_internal_ops; | ||
| 828 | + | ||
| 829 | + mt9p031->pdata = pdata; | ||
| 830 | + | ||
| 831 | + mt9p031->reg_1v8 = regulator_get(NULL, "cam_1v8"); | ||
| 832 | + if (IS_ERR(mt9p031->reg_1v8)) { | ||
| 833 | + ret = PTR_ERR(mt9p031->reg_1v8); | ||
| 834 | + dev_err(mt9p031->subdev.v4l2_dev->dev, | ||
| 835 | + "Failed 1.8v regulator: %d\n", ret); | ||
| 836 | + goto err_e1v8; | ||
| 837 | + } | ||
| 838 | + | ||
| 839 | + mt9p031->reg_2v8 = regulator_get(NULL, "cam_2v8"); | ||
| 840 | + if (IS_ERR(mt9p031->reg_2v8)) { | ||
| 841 | + ret = PTR_ERR(mt9p031->reg_2v8); | ||
| 842 | + dev_err(mt9p031->subdev.v4l2_dev->dev, | ||
| 843 | + "Failed 2.8v regulator: %d\n", ret); | ||
| 844 | + goto err_e2v8; | ||
| 845 | + } | ||
| 846 | + return 0; | ||
| 847 | +err_e2v8: | ||
| 848 | + regulator_put(mt9p031->reg_1v8); | ||
| 849 | +err_e1v8: | ||
| 850 | + kfree(mt9p031); | ||
| 851 | + return ret; | ||
| 852 | +} | ||
| 853 | + | ||
| 854 | +static int mt9p031_remove(struct i2c_client *client) | ||
| 855 | +{ | ||
| 856 | + struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
| 857 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 858 | + | ||
| 859 | + v4l2_device_unregister_subdev(sd); | ||
| 860 | + media_entity_cleanup(&sd->entity); | ||
| 861 | + regulator_put(mt9p031->reg_2v8); | ||
| 862 | + regulator_put(mt9p031->reg_1v8); | ||
| 863 | + kfree(mt9p031); | ||
| 864 | + | ||
| 865 | + return 0; | ||
| 866 | +} | ||
| 867 | + | ||
| 868 | +static const struct i2c_device_id mt9p031_id[] = { | ||
| 869 | + { "mt9p031", 0 }, | ||
| 870 | + { } | ||
| 871 | +}; | ||
| 872 | +MODULE_DEVICE_TABLE(i2c, mt9p031_id); | ||
| 873 | + | ||
| 874 | +static struct i2c_driver mt9p031_i2c_driver = { | ||
| 875 | + .driver = { | ||
| 876 | + .name = "mt9p031", | ||
| 877 | + }, | ||
| 878 | + .probe = mt9p031_probe, | ||
| 879 | + .remove = mt9p031_remove, | ||
| 880 | + .id_table = mt9p031_id, | ||
| 881 | +}; | ||
| 882 | + | ||
| 883 | +static int __init mt9p031_mod_init(void) | ||
| 884 | +{ | ||
| 885 | + return i2c_add_driver(&mt9p031_i2c_driver); | ||
| 886 | +} | ||
| 887 | + | ||
| 888 | +static void __exit mt9p031_mod_exit(void) | ||
| 889 | +{ | ||
| 890 | + i2c_del_driver(&mt9p031_i2c_driver); | ||
| 891 | +} | ||
| 892 | + | ||
| 893 | +module_init(mt9p031_mod_init); | ||
| 894 | +module_exit(mt9p031_mod_exit); | ||
| 895 | + | ||
| 896 | +MODULE_DESCRIPTION("Aptina MT9P031 Camera driver"); | ||
| 897 | +MODULE_AUTHOR("Bastian Hecht <hechtb@gmail.com>"); | ||
| 898 | +MODULE_LICENSE("GPL v2"); | ||
| 899 | diff --git a/include/media/mt9p031.h b/include/media/mt9p031.h | ||
| 900 | new file mode 100644 | ||
| 901 | index 0000000..7ee9733 | ||
| 902 | --- /dev/null | ||
| 903 | +++ b/include/media/mt9p031.h | ||
| 904 | @@ -0,0 +1,11 @@ | ||
| 905 | +#ifndef MT9P031_H | ||
| 906 | +#define MT9P031_H | ||
| 907 | + | ||
| 908 | +struct v4l2_subdev; | ||
| 909 | + | ||
| 910 | +struct mt9p031_platform_data { | ||
| 911 | + int (*set_xclk)(struct v4l2_subdev *subdev, int hz); | ||
| 912 | + int (*reset)(struct v4l2_subdev *subdev, int active); | ||
| 913 | +}; | ||
| 914 | + | ||
| 915 | +#endif | ||
| 916 | -- | ||
| 917 | 1.6.6.1 | ||
| 918 | |||
diff --git a/recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-support-for-mt9p031-Aptina-Micron-sensor.patch b/recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-support-for-mt9p031-Aptina-Micron-sensor.patch new file mode 100644 index 00000000..7f68de40 --- /dev/null +++ b/recipes-kernel/linux/linux-omap-2.6.39/camera/0001-Add-support-for-mt9p031-Aptina-Micron-sensor.patch | |||
| @@ -0,0 +1,773 @@ | |||
| 1 | From 244f96b15afbd73942762e2c07523d6c5cf68a7e Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Javier Martin <javier.martin@vista-silicon.com> | ||
| 3 | Date: Tue, 31 May 2011 11:46:49 +0200 | ||
| 4 | Subject: [PATCH 1/3] Add support for mt9p031 Aptina (Micron) sensor. | ||
| 5 | |||
| 6 | This patch adds basic support (no controls) for | ||
| 7 | mt9p031 sensor. It applies on kernel 2.6.39. | ||
| 8 | |||
| 9 | Signed-off-by: Javier Martin <javier.martin@vista-silicon.com> | ||
| 10 | --- | ||
| 11 | drivers/media/video/Kconfig | 7 + | ||
| 12 | drivers/media/video/Makefile | 1 + | ||
| 13 | drivers/media/video/mt9p031.c | 699 +++++++++++++++++++++++++++++++++++++++++ | ||
| 14 | include/media/mt9p031.h | 11 + | ||
| 15 | 4 files changed, 718 insertions(+), 0 deletions(-) | ||
| 16 | create mode 100644 drivers/media/video/mt9p031.c | ||
| 17 | create mode 100644 include/media/mt9p031.h | ||
| 18 | |||
| 19 | diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig | ||
| 20 | index 00f51dd..cb87e35 100644 | ||
| 21 | --- a/drivers/media/video/Kconfig | ||
| 22 | +++ b/drivers/media/video/Kconfig | ||
| 23 | @@ -329,6 +329,13 @@ config VIDEO_OV7670 | ||
| 24 | OV7670 VGA camera. It currently only works with the M88ALP01 | ||
| 25 | controller. | ||
| 26 | |||
| 27 | +config VIDEO_MT9P031 | ||
| 28 | + tristate "Aptina MT9P031 support" | ||
| 29 | + depends on I2C && VIDEO_V4L2 | ||
| 30 | + ---help--- | ||
| 31 | + This is a Video4Linux2 sensor-level driver for the Aptina | ||
| 32 | + (Micron) mt9p031 5 Mpixel camera. | ||
| 33 | + | ||
| 34 | config VIDEO_MT9V011 | ||
| 35 | tristate "Micron mt9v011 sensor support" | ||
| 36 | depends on I2C && VIDEO_V4L2 | ||
| 37 | diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile | ||
| 38 | index ace5d8b..912b29b 100644 | ||
| 39 | --- a/drivers/media/video/Makefile | ||
| 40 | +++ b/drivers/media/video/Makefile | ||
| 41 | @@ -65,6 +65,7 @@ obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o | ||
| 42 | obj-$(CONFIG_VIDEO_OV7670) += ov7670.o | ||
| 43 | obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o | ||
| 44 | obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o | ||
| 45 | +obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o | ||
| 46 | obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o | ||
| 47 | obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o | ||
| 48 | obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o | ||
| 49 | diff --git a/drivers/media/video/mt9p031.c b/drivers/media/video/mt9p031.c | ||
| 50 | new file mode 100644 | ||
| 51 | index 0000000..61b46a0 | ||
| 52 | --- /dev/null | ||
| 53 | +++ b/drivers/media/video/mt9p031.c | ||
| 54 | @@ -0,0 +1,699 @@ | ||
| 55 | +/* | ||
| 56 | + * Driver for MT9P031 CMOS Image Sensor from Aptina | ||
| 57 | + * | ||
| 58 | + * Copyright (C) 2011, Javier Martin <javier.martin@vista-silicon.com> | ||
| 59 | + * | ||
| 60 | + * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de> | ||
| 61 | + * | ||
| 62 | + * Based on the MT9V032 driver and Bastian Hecht's code. | ||
| 63 | + * | ||
| 64 | + * This program is free software; you can redistribute it and/or modify | ||
| 65 | + * it under the terms of the GNU General Public License version 2 as | ||
| 66 | + * published by the Free Software Foundation. | ||
| 67 | + */ | ||
| 68 | + | ||
| 69 | +#include <linux/delay.h> | ||
| 70 | +#include <linux/device.h> | ||
| 71 | +#include <linux/i2c.h> | ||
| 72 | +#include <linux/log2.h> | ||
| 73 | +#include <linux/pm.h> | ||
| 74 | +#include <linux/slab.h> | ||
| 75 | +#include <media/v4l2-subdev.h> | ||
| 76 | +#include <linux/videodev2.h> | ||
| 77 | + | ||
| 78 | +#include <media/mt9p031.h> | ||
| 79 | +#include <media/v4l2-chip-ident.h> | ||
| 80 | +#include <media/v4l2-subdev.h> | ||
| 81 | +#include <media/v4l2-device.h> | ||
| 82 | + | ||
| 83 | +#define MT9P031_PIXCLK_FREQ 54000000 | ||
| 84 | + | ||
| 85 | +#define MT9P031_CHIP_VERSION 0x00 | ||
| 86 | +#define MT9P031_CHIP_VERSION_VALUE 0x1801 | ||
| 87 | +#define MT9P031_ROW_START 0x01 | ||
| 88 | +#define MT9P031_ROW_START_MIN 1 | ||
| 89 | +#define MT9P031_ROW_START_MAX 2004 | ||
| 90 | +#define MT9P031_ROW_START_DEF 54 | ||
| 91 | +#define MT9P031_COLUMN_START 0x02 | ||
| 92 | +#define MT9P031_COLUMN_START_MIN 1 | ||
| 93 | +#define MT9P031_COLUMN_START_MAX 2750 | ||
| 94 | +#define MT9P031_COLUMN_START_DEF 16 | ||
| 95 | +#define MT9P031_WINDOW_HEIGHT 0x03 | ||
| 96 | +#define MT9P031_WINDOW_HEIGHT_MIN 2 | ||
| 97 | +#define MT9P031_WINDOW_HEIGHT_MAX 2003 | ||
| 98 | +#define MT9P031_WINDOW_HEIGHT_DEF 2003 | ||
| 99 | +#define MT9P031_WINDOW_WIDTH 0x04 | ||
| 100 | +#define MT9P031_WINDOW_WIDTH_MIN 18 | ||
| 101 | +#define MT9P031_WINDOW_WIDTH_MAX 2751 | ||
| 102 | +#define MT9P031_WINDOW_WIDTH_DEF 2751 | ||
| 103 | +#define MT9P031_H_BLANKING 0x05 | ||
| 104 | +#define MT9P031_H_BLANKING_VALUE 0 | ||
| 105 | +#define MT9P031_V_BLANKING 0x06 | ||
| 106 | +#define MT9P031_V_BLANKING_VALUE 25 | ||
| 107 | +#define MT9P031_OUTPUT_CONTROL 0x07 | ||
| 108 | +#define MT9P031_OUTPUT_CONTROL_CEN 2 | ||
| 109 | +#define MT9P031_OUTPUT_CONTROL_SYN 1 | ||
| 110 | +#define MT9P031_SHUTTER_WIDTH_UPPER 0x08 | ||
| 111 | +#define MT9P031_SHUTTER_WIDTH 0x09 | ||
| 112 | +#define MT9P031_PIXEL_CLOCK_CONTROL 0x0a | ||
| 113 | +#define MT9P031_FRAME_RESTART 0x0b | ||
| 114 | +#define MT9P031_SHUTTER_DELAY 0x0c | ||
| 115 | +#define MT9P031_RST 0x0d | ||
| 116 | +#define MT9P031_RST_ENABLE 1 | ||
| 117 | +#define MT9P031_RST_DISABLE 0 | ||
| 118 | +#define MT9P031_READ_MODE_1 0x1e | ||
| 119 | +#define MT9P031_READ_MODE_2 0x20 | ||
| 120 | +#define MT9P031_READ_MODE_2_ROW_MIR 0x8000 | ||
| 121 | +#define MT9P031_READ_MODE_2_COL_MIR 0x4000 | ||
| 122 | +#define MT9P031_ROW_ADDRESS_MODE 0x22 | ||
| 123 | +#define MT9P031_COLUMN_ADDRESS_MODE 0x23 | ||
| 124 | +#define MT9P031_GLOBAL_GAIN 0x35 | ||
| 125 | + | ||
| 126 | + | ||
| 127 | + | ||
| 128 | + | ||
| 129 | +struct mt9p031 { | ||
| 130 | + struct v4l2_subdev subdev; | ||
| 131 | + struct media_pad pad; | ||
| 132 | + struct v4l2_rect rect; /* Sensor window */ | ||
| 133 | + struct v4l2_mbus_framefmt format; | ||
| 134 | + struct mt9p031_platform_data *pdata; | ||
| 135 | + struct mutex power_lock; /* lock to protect power_count */ | ||
| 136 | + int power_count; | ||
| 137 | + u16 xskip; | ||
| 138 | + u16 yskip; | ||
| 139 | + /* cache register values */ | ||
| 140 | + u16 output_control; | ||
| 141 | +}; | ||
| 142 | + | ||
| 143 | +static struct mt9p031 *to_mt9p031(const struct i2c_client *client) | ||
| 144 | +{ | ||
| 145 | + return container_of(i2c_get_clientdata(client), struct mt9p031, subdev); | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +static int reg_read(struct i2c_client *client, const u8 reg) | ||
| 149 | +{ | ||
| 150 | + s32 data = i2c_smbus_read_word_data(client, reg); | ||
| 151 | + return data < 0 ? data : swab16(data); | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +static int reg_write(struct i2c_client *client, const u8 reg, | ||
| 155 | + const u16 data) | ||
| 156 | +{ | ||
| 157 | + return i2c_smbus_write_word_data(client, reg, swab16(data)); | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear, | ||
| 161 | + u16 set) | ||
| 162 | +{ | ||
| 163 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 164 | + u16 value = (mt9p031->output_control & ~clear) | set; | ||
| 165 | + int ret; | ||
| 166 | + | ||
| 167 | + ret = reg_write(client, MT9P031_OUTPUT_CONTROL, value); | ||
| 168 | + if (ret < 0) | ||
| 169 | + return ret; | ||
| 170 | + mt9p031->output_control = value; | ||
| 171 | + return 0; | ||
| 172 | +} | ||
| 173 | + | ||
| 174 | +static int mt9p031_reset(struct i2c_client *client) | ||
| 175 | +{ | ||
| 176 | + struct mt9p031 *mt9p031 = to_mt9p031(client); | ||
| 177 | + int ret; | ||
| 178 | + | ||
| 179 | + /* Disable chip output, synchronous option update */ | ||
| 180 | + ret = reg_write(client, MT9P031_RST, MT9P031_RST_ENABLE); | ||
| 181 | + if (ret < 0) | ||
| 182 | + return ret; | ||
| 183 | + ret = reg_write(client, MT9P031_RST, MT9P031_RST_DISABLE); | ||
| 184 | + if (ret < 0) | ||
| 185 | + return ret; | ||
| 186 | + return mt9p031_set_output_control(mt9p031, | ||
| 187 | + MT9P031_OUTPUT_CONTROL_CEN, 0); | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +static int mt9p031_power_on(struct mt9p031 *mt9p031) | ||
| 191 | +{ | ||
| 192 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 193 | + int ret; | ||
| 194 | + | ||
| 195 | + /* Ensure RESET_BAR is low */ | ||
| 196 | + if (mt9p031->pdata->reset) { | ||
| 197 | + mt9p031->pdata->reset(&mt9p031->subdev, 1); | ||
| 198 | + msleep(1); | ||
| 199 | + } | ||
| 200 | + /* Emable clock */ | ||
| 201 | + if (mt9p031->pdata->set_xclk) | ||
| 202 | + mt9p031->pdata->set_xclk(&mt9p031->subdev, MT9P031_PIXCLK_FREQ); | ||
| 203 | + /* Now RESET_BAR must be high */ | ||
| 204 | + if (mt9p031->pdata->reset) { | ||
| 205 | + mt9p031->pdata->reset(&mt9p031->subdev, 0); | ||
| 206 | + msleep(1); | ||
| 207 | + } | ||
| 208 | + /* soft reset */ | ||
| 209 | + ret = mt9p031_reset(client); | ||
| 210 | + if (ret < 0) { | ||
| 211 | + dev_err(&client->dev, "Failed to reset the camera\n"); | ||
| 212 | + return ret; | ||
| 213 | + } | ||
| 214 | + return 0; | ||
| 215 | +} | ||
| 216 | + | ||
| 217 | +static void mt9p031_power_off(struct mt9p031 *mt9p031) | ||
| 218 | +{ | ||
| 219 | + if (mt9p031->pdata->reset) { | ||
| 220 | + mt9p031->pdata->reset(&mt9p031->subdev, 1); | ||
| 221 | + msleep(1); | ||
| 222 | + } | ||
| 223 | + if (mt9p031->pdata->set_xclk) | ||
| 224 | + mt9p031->pdata->set_xclk(&mt9p031->subdev, 0); | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +static int mt9p031_enum_mbus_code(struct v4l2_subdev *sd, | ||
| 228 | + struct v4l2_subdev_fh *fh, | ||
| 229 | + struct v4l2_subdev_mbus_code_enum *code) | ||
| 230 | +{ | ||
| 231 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 232 | + | ||
| 233 | + if (code->pad || code->index) | ||
| 234 | + return -EINVAL; | ||
| 235 | + | ||
| 236 | + code->code = mt9p031->format.code; | ||
| 237 | + return 0; | ||
| 238 | +} | ||
| 239 | + | ||
| 240 | +static struct v4l2_mbus_framefmt *mt9p031_get_pad_format( | ||
| 241 | + struct mt9p031 *mt9p031, | ||
| 242 | + struct v4l2_subdev_fh *fh, | ||
| 243 | + unsigned int pad, u32 which) | ||
| 244 | +{ | ||
| 245 | + switch (which) { | ||
| 246 | + case V4L2_SUBDEV_FORMAT_TRY: | ||
| 247 | + return v4l2_subdev_get_try_format(fh, pad); | ||
| 248 | + case V4L2_SUBDEV_FORMAT_ACTIVE: | ||
| 249 | + return &mt9p031->format; | ||
| 250 | + default: | ||
| 251 | + return NULL; | ||
| 252 | + } | ||
| 253 | +} | ||
| 254 | + | ||
| 255 | +static struct v4l2_rect *mt9p031_get_pad_crop(struct mt9p031 *mt9p031, | ||
| 256 | + struct v4l2_subdev_fh *fh, unsigned int pad, u32 which) | ||
| 257 | +{ | ||
| 258 | + switch (which) { | ||
| 259 | + case V4L2_SUBDEV_FORMAT_TRY: | ||
| 260 | + return v4l2_subdev_get_try_crop(fh, pad); | ||
| 261 | + case V4L2_SUBDEV_FORMAT_ACTIVE: | ||
| 262 | + return &mt9p031->rect; | ||
| 263 | + default: | ||
| 264 | + return NULL; | ||
| 265 | + } | ||
| 266 | +} | ||
| 267 | + | ||
| 268 | +static int mt9p031_get_crop(struct v4l2_subdev *sd, | ||
| 269 | + struct v4l2_subdev_fh *fh, | ||
| 270 | + struct v4l2_subdev_crop *crop) | ||
| 271 | +{ | ||
| 272 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 273 | + struct v4l2_rect *rect = mt9p031_get_pad_crop(mt9p031, fh, crop->pad, | ||
| 274 | + crop->which); | ||
| 275 | + if (!rect) | ||
| 276 | + return -EINVAL; | ||
| 277 | + | ||
| 278 | + crop->rect = *rect; | ||
| 279 | + | ||
| 280 | + return 0; | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +static u16 mt9p031_skip_for_crop(s32 source, s32 *target, s32 max_skip) | ||
| 284 | +{ | ||
| 285 | + unsigned int skip; | ||
| 286 | + | ||
| 287 | + if (source - source / 4 < *target) { | ||
| 288 | + *target = source; | ||
| 289 | + return 1; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + skip = DIV_ROUND_CLOSEST(source, *target); | ||
| 293 | + if (skip > max_skip) | ||
| 294 | + skip = max_skip; | ||
| 295 | + *target = 2 * DIV_ROUND_UP(source, 2 * skip); | ||
| 296 | + | ||
| 297 | + return skip; | ||
| 298 | +} | ||
| 299 | + | ||
| 300 | +static int mt9p031_set_params(struct i2c_client *client, | ||
| 301 | + struct v4l2_rect *rect, u16 xskip, u16 yskip) | ||
| 302 | +{ | ||
| 303 | + struct mt9p031 *mt9p031 = to_mt9p031(client); | ||
| 304 | + int ret; | ||
| 305 | + u16 xbin, ybin; | ||
| 306 | + const u16 hblank = MT9P031_H_BLANKING_VALUE, | ||
| 307 | + vblank = MT9P031_V_BLANKING_VALUE; | ||
| 308 | + __s32 left; | ||
| 309 | + | ||
| 310 | + /* | ||
| 311 | + * TODO: Attention! When implementing horizontal flipping, adjust | ||
| 312 | + * alignment according to R2 "Column Start" description in the datasheet | ||
| 313 | + */ | ||
| 314 | + if (xskip & 1) { | ||
| 315 | + xbin = 1; | ||
| 316 | + left = rect->left & (~3); | ||
| 317 | + } else if (xskip & 2) { | ||
| 318 | + xbin = 2; | ||
| 319 | + left = rect->left & (~7); | ||
| 320 | + } else { | ||
| 321 | + xbin = 4; | ||
| 322 | + left = rect->left & (~15); | ||
| 323 | + } | ||
| 324 | + ybin = min(yskip, (u16)4); | ||
| 325 | + | ||
| 326 | + /* Disable register update, reconfigure atomically */ | ||
| 327 | + ret = mt9p031_set_output_control(mt9p031, 0, | ||
| 328 | + MT9P031_OUTPUT_CONTROL_SYN); | ||
| 329 | + if (ret < 0) | ||
| 330 | + return ret; | ||
| 331 | + | ||
| 332 | + dev_dbg(&client->dev, "skip %u:%u, rect %ux%u@%u:%u\n", | ||
| 333 | + xskip, yskip, rect->width, rect->height, rect->left, rect->top); | ||
| 334 | + | ||
| 335 | + /* Blanking and start values - default... */ | ||
| 336 | + ret = reg_write(client, MT9P031_H_BLANKING, hblank); | ||
| 337 | + if (ret < 0) | ||
| 338 | + return ret; | ||
| 339 | + ret = reg_write(client, MT9P031_V_BLANKING, vblank); | ||
| 340 | + if (ret < 0) | ||
| 341 | + return ret; | ||
| 342 | + | ||
| 343 | + ret = reg_write(client, MT9P031_COLUMN_ADDRESS_MODE, | ||
| 344 | + ((xbin - 1) << 4) | (xskip - 1)); | ||
| 345 | + if (ret < 0) | ||
| 346 | + return ret; | ||
| 347 | + ret = reg_write(client, MT9P031_ROW_ADDRESS_MODE, | ||
| 348 | + ((ybin - 1) << 4) | (yskip - 1)); | ||
| 349 | + if (ret < 0) | ||
| 350 | + return ret; | ||
| 351 | + | ||
| 352 | + dev_dbg(&client->dev, "new physical left %u, top %u\n", | ||
| 353 | + rect->left, rect->top); | ||
| 354 | + | ||
| 355 | + ret = reg_write(client, MT9P031_COLUMN_START, | ||
| 356 | + rect->left); | ||
| 357 | + if (ret < 0) | ||
| 358 | + return ret; | ||
| 359 | + ret = reg_write(client, MT9P031_ROW_START, | ||
| 360 | + rect->top); | ||
| 361 | + if (ret < 0) | ||
| 362 | + return ret; | ||
| 363 | + | ||
| 364 | + ret = reg_write(client, MT9P031_WINDOW_WIDTH, | ||
| 365 | + rect->width - 1); | ||
| 366 | + if (ret < 0) | ||
| 367 | + return ret; | ||
| 368 | + ret = reg_write(client, MT9P031_WINDOW_HEIGHT, | ||
| 369 | + rect->height - 1); | ||
| 370 | + if (ret < 0) | ||
| 371 | + return ret; | ||
| 372 | + | ||
| 373 | + /* Re-enable register update, commit all changes */ | ||
| 374 | + ret = mt9p031_set_output_control(mt9p031, | ||
| 375 | + MT9P031_OUTPUT_CONTROL_SYN, 0); | ||
| 376 | + if (ret < 0) | ||
| 377 | + return ret; | ||
| 378 | + | ||
| 379 | + mt9p031->xskip = xskip; | ||
| 380 | + mt9p031->yskip = yskip; | ||
| 381 | + return ret; | ||
| 382 | +} | ||
| 383 | + | ||
| 384 | +static int mt9p031_set_crop(struct v4l2_subdev *sd, | ||
| 385 | + struct v4l2_subdev_fh *fh, | ||
| 386 | + struct v4l2_subdev_crop *crop) | ||
| 387 | +{ | ||
| 388 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 389 | + struct v4l2_mbus_framefmt *f; | ||
| 390 | + struct v4l2_rect *c; | ||
| 391 | + struct v4l2_rect rect; | ||
| 392 | + u16 xskip, yskip; | ||
| 393 | + s32 width, height; | ||
| 394 | + | ||
| 395 | + dev_dbg(mt9p031->subdev.v4l2_dev->dev, "%s(%ux%u@%u:%u : %u)\n", | ||
| 396 | + __func__, crop->rect.width, crop->rect.height, | ||
| 397 | + crop->rect.left, crop->rect.top, crop->which); | ||
| 398 | + | ||
| 399 | + /* | ||
| 400 | + * Clamp the crop rectangle boundaries and align them to a multiple of 2 | ||
| 401 | + * pixels. | ||
| 402 | + */ | ||
| 403 | + rect.width = ALIGN(clamp(crop->rect.width, | ||
| 404 | + MT9P031_WINDOW_WIDTH_MIN, | ||
| 405 | + MT9P031_WINDOW_WIDTH_MAX), 2); | ||
| 406 | + rect.height = ALIGN(clamp(crop->rect.height, | ||
| 407 | + MT9P031_WINDOW_HEIGHT_MIN, | ||
| 408 | + MT9P031_WINDOW_HEIGHT_MAX), 2); | ||
| 409 | + rect.left = ALIGN(clamp(crop->rect.left, | ||
| 410 | + MT9P031_COLUMN_START_MIN, | ||
| 411 | + MT9P031_COLUMN_START_MAX), 2); | ||
| 412 | + rect.top = ALIGN(clamp(crop->rect.top, | ||
| 413 | + MT9P031_ROW_START_MIN, | ||
| 414 | + MT9P031_ROW_START_MAX), 2); | ||
| 415 | + | ||
| 416 | + c = mt9p031_get_pad_crop(mt9p031, fh, crop->pad, crop->which); | ||
| 417 | + | ||
| 418 | + if (rect.width != c->width || rect.height != c->height) { | ||
| 419 | + /* | ||
| 420 | + * Reset the output image size if the crop rectangle size has | ||
| 421 | + * been modified. | ||
| 422 | + */ | ||
| 423 | + f = mt9p031_get_pad_format(mt9p031, fh, crop->pad, | ||
| 424 | + crop->which); | ||
| 425 | + width = f->width; | ||
| 426 | + height = f->height; | ||
| 427 | + | ||
| 428 | + xskip = mt9p031_skip_for_crop(rect.width, &width, 7); | ||
| 429 | + yskip = mt9p031_skip_for_crop(rect.height, &height, 8); | ||
| 430 | + } else { | ||
| 431 | + xskip = mt9p031->xskip; | ||
| 432 | + yskip = mt9p031->yskip; | ||
| 433 | + f = NULL; | ||
| 434 | + } | ||
| 435 | + if (f) { | ||
| 436 | + f->width = width; | ||
| 437 | + f->height = height; | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + *c = rect; | ||
| 441 | + crop->rect = rect; | ||
| 442 | + | ||
| 443 | + mt9p031->xskip = xskip; | ||
| 444 | + mt9p031->yskip = yskip; | ||
| 445 | + mt9p031->rect = *c; | ||
| 446 | + return 0; | ||
| 447 | +} | ||
| 448 | + | ||
| 449 | +static int mt9p031_get_format(struct v4l2_subdev *sd, | ||
| 450 | + struct v4l2_subdev_fh *fh, | ||
| 451 | + struct v4l2_subdev_format *fmt) | ||
| 452 | +{ | ||
| 453 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 454 | + | ||
| 455 | + fmt->format = | ||
| 456 | + *mt9p031_get_pad_format(mt9p031, fh, fmt->pad, fmt->which); | ||
| 457 | + return 0; | ||
| 458 | +} | ||
| 459 | + | ||
| 460 | +static u16 mt9p031_skip_for_scale(s32 *source, s32 target, | ||
| 461 | + s32 max_skip, s32 max) | ||
| 462 | +{ | ||
| 463 | + unsigned int skip; | ||
| 464 | + | ||
| 465 | + if (*source - *source / 4 < target) { | ||
| 466 | + *source = target; | ||
| 467 | + return 1; | ||
| 468 | + } | ||
| 469 | + | ||
| 470 | + skip = min(max, *source + target / 2) / target; | ||
| 471 | + if (skip > max_skip) | ||
| 472 | + skip = max_skip; | ||
| 473 | + *source = target * skip; | ||
| 474 | + | ||
| 475 | + return skip; | ||
| 476 | +} | ||
| 477 | + | ||
| 478 | +static int mt9p031_set_format(struct v4l2_subdev *sd, | ||
| 479 | + struct v4l2_subdev_fh *fh, | ||
| 480 | + struct v4l2_subdev_format *format) | ||
| 481 | +{ | ||
| 482 | + struct v4l2_mbus_framefmt *__format; | ||
| 483 | + struct v4l2_rect *__crop, rect; | ||
| 484 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 485 | + unsigned int width; | ||
| 486 | + unsigned int height; | ||
| 487 | + u16 xskip, yskip; | ||
| 488 | + | ||
| 489 | + __crop = mt9p031_get_pad_crop(mt9p031, fh, format->pad, format->which); | ||
| 490 | + | ||
| 491 | + width = clamp_t(int, ALIGN(format->format.width, 2), 2, | ||
| 492 | + MT9P031_WINDOW_WIDTH_MAX); | ||
| 493 | + height = clamp_t(int, ALIGN(format->format.height, 2), 2, | ||
| 494 | + MT9P031_WINDOW_HEIGHT_MAX); | ||
| 495 | + | ||
| 496 | + rect.width = __crop->width; | ||
| 497 | + rect.height = __crop->height; | ||
| 498 | + | ||
| 499 | + xskip = mt9p031_skip_for_scale(&rect.width, width, 7, | ||
| 500 | + MT9P031_WINDOW_WIDTH_MAX); | ||
| 501 | + if (rect.width + __crop->left > MT9P031_WINDOW_WIDTH_MAX) | ||
| 502 | + rect.left = (MT9P031_WINDOW_WIDTH_MAX - rect.width) / 2; | ||
| 503 | + else | ||
| 504 | + rect.left = __crop->left; | ||
| 505 | + yskip = mt9p031_skip_for_scale(&rect.height, height, 8, | ||
| 506 | + MT9P031_WINDOW_HEIGHT_MAX); | ||
| 507 | + if (rect.height + __crop->top > MT9P031_WINDOW_HEIGHT_MAX) | ||
| 508 | + rect.top = (MT9P031_WINDOW_HEIGHT_MAX - rect.height) / 2; | ||
| 509 | + else | ||
| 510 | + rect.top = __crop->top; | ||
| 511 | + | ||
| 512 | + dev_dbg(mt9p031->subdev.v4l2_dev->dev, "%s(%ux%u : %u)\n", __func__, | ||
| 513 | + width, height, format->which); | ||
| 514 | + if (__crop) | ||
| 515 | + *__crop = rect; | ||
| 516 | + | ||
| 517 | + __format = mt9p031_get_pad_format(mt9p031, fh, format->pad, | ||
| 518 | + format->which); | ||
| 519 | + __format->width = width; | ||
| 520 | + __format->height = height; | ||
| 521 | + format->format = *__format; | ||
| 522 | + | ||
| 523 | + mt9p031->xskip = xskip; | ||
| 524 | + mt9p031->yskip = yskip; | ||
| 525 | + mt9p031->rect = *__crop; | ||
| 526 | + return 0; | ||
| 527 | +} | ||
| 528 | + | ||
| 529 | +static int mt9p031_s_stream(struct v4l2_subdev *sd, int enable) | ||
| 530 | +{ | ||
| 531 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 532 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 533 | + struct v4l2_rect rect = mt9p031->rect; | ||
| 534 | + u16 xskip = mt9p031->xskip; | ||
| 535 | + u16 yskip = mt9p031->yskip; | ||
| 536 | + int ret; | ||
| 537 | + | ||
| 538 | + if (enable) { | ||
| 539 | + ret = mt9p031_set_params(client, &rect, xskip, yskip); | ||
| 540 | + if (ret < 0) | ||
| 541 | + return ret; | ||
| 542 | + /* Switch to master "normal" mode */ | ||
| 543 | + ret = mt9p031_set_output_control(mt9p031, 0, | ||
| 544 | + MT9P031_OUTPUT_CONTROL_CEN); | ||
| 545 | + } else { | ||
| 546 | + /* Stop sensor readout */ | ||
| 547 | + ret = mt9p031_set_output_control(mt9p031, | ||
| 548 | + MT9P031_OUTPUT_CONTROL_CEN, 0); | ||
| 549 | + } | ||
| 550 | + return ret; | ||
| 551 | +} | ||
| 552 | + | ||
| 553 | +static int mt9p031_video_probe(struct i2c_client *client) | ||
| 554 | +{ | ||
| 555 | + s32 data; | ||
| 556 | + | ||
| 557 | + /* Read out the chip version register */ | ||
| 558 | + data = reg_read(client, MT9P031_CHIP_VERSION); | ||
| 559 | + if (data != MT9P031_CHIP_VERSION_VALUE) { | ||
| 560 | + dev_err(&client->dev, | ||
| 561 | + "No MT9P031 chip detected, register read %x\n", data); | ||
| 562 | + return -ENODEV; | ||
| 563 | + } | ||
| 564 | + | ||
| 565 | + dev_info(&client->dev, "Detected a MT9P031 chip ID %x\n", data); | ||
| 566 | + | ||
| 567 | + return 0; | ||
| 568 | +} | ||
| 569 | + | ||
| 570 | +static int mt9p031_set_power(struct v4l2_subdev *sd, int on) | ||
| 571 | +{ | ||
| 572 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 573 | + int ret = 0; | ||
| 574 | + | ||
| 575 | + mutex_lock(&mt9p031->power_lock); | ||
| 576 | + | ||
| 577 | + /* | ||
| 578 | + * If the power count is modified from 0 to != 0 or from != 0 to 0, | ||
| 579 | + * update the power state. | ||
| 580 | + */ | ||
| 581 | + if (mt9p031->power_count == !on) { | ||
| 582 | + if (on) { | ||
| 583 | + ret = mt9p031_power_on(mt9p031); | ||
| 584 | + if (ret) { | ||
| 585 | + dev_err(mt9p031->subdev.v4l2_dev->dev, | ||
| 586 | + "Failed to power on: %d\n", ret); | ||
| 587 | + goto out; | ||
| 588 | + } | ||
| 589 | + } else { | ||
| 590 | + mt9p031_power_off(mt9p031); | ||
| 591 | + } | ||
| 592 | + } | ||
| 593 | + | ||
| 594 | + /* Update the power count. */ | ||
| 595 | + mt9p031->power_count += on ? 1 : -1; | ||
| 596 | + WARN_ON(mt9p031->power_count < 0); | ||
| 597 | + | ||
| 598 | +out: | ||
| 599 | + mutex_unlock(&mt9p031->power_lock); | ||
| 600 | + return ret; | ||
| 601 | +} | ||
| 602 | + | ||
| 603 | +static int mt9p031_registered(struct v4l2_subdev *sd) | ||
| 604 | +{ | ||
| 605 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 606 | + struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); | ||
| 607 | + int ret; | ||
| 608 | + | ||
| 609 | + ret = mt9p031_set_power(&mt9p031->subdev, 1); | ||
| 610 | + if (ret) { | ||
| 611 | + dev_err(&client->dev, | ||
| 612 | + "Failed to power on device: %d\n", ret); | ||
| 613 | + return ret; | ||
| 614 | + } | ||
| 615 | + | ||
| 616 | + ret = mt9p031_video_probe(client); | ||
| 617 | + | ||
| 618 | + mt9p031_set_power(&mt9p031->subdev, 0); | ||
| 619 | + | ||
| 620 | + return ret; | ||
| 621 | +} | ||
| 622 | + | ||
| 623 | +static int mt9p031_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) | ||
| 624 | +{ | ||
| 625 | + struct mt9p031 *mt9p031; | ||
| 626 | + mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 627 | + | ||
| 628 | + mt9p031->rect.width = MT9P031_WINDOW_WIDTH_DEF; | ||
| 629 | + mt9p031->rect.height = MT9P031_WINDOW_HEIGHT_DEF; | ||
| 630 | + mt9p031->rect.left = MT9P031_COLUMN_START_DEF; | ||
| 631 | + mt9p031->rect.top = MT9P031_ROW_START_DEF; | ||
| 632 | + | ||
| 633 | + mt9p031->format.code = V4L2_MBUS_FMT_SGRBG12_1X12; | ||
| 634 | + mt9p031->format.width = MT9P031_WINDOW_WIDTH_DEF; | ||
| 635 | + mt9p031->format.height = MT9P031_WINDOW_HEIGHT_DEF; | ||
| 636 | + mt9p031->format.field = V4L2_FIELD_NONE; | ||
| 637 | + mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; | ||
| 638 | + | ||
| 639 | + mt9p031->xskip = 1; | ||
| 640 | + mt9p031->yskip = 1; | ||
| 641 | + return mt9p031_set_power(sd, 1); | ||
| 642 | +} | ||
| 643 | + | ||
| 644 | +static int mt9p031_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) | ||
| 645 | +{ | ||
| 646 | + return mt9p031_set_power(sd, 0); | ||
| 647 | +} | ||
| 648 | + | ||
| 649 | +static struct v4l2_subdev_core_ops mt9p031_subdev_core_ops = { | ||
| 650 | + .s_power = mt9p031_set_power, | ||
| 651 | +}; | ||
| 652 | + | ||
| 653 | +static struct v4l2_subdev_video_ops mt9p031_subdev_video_ops = { | ||
| 654 | + .s_stream = mt9p031_s_stream, | ||
| 655 | +}; | ||
| 656 | + | ||
| 657 | +static struct v4l2_subdev_pad_ops mt9p031_subdev_pad_ops = { | ||
| 658 | + .enum_mbus_code = mt9p031_enum_mbus_code, | ||
| 659 | + .get_fmt = mt9p031_get_format, | ||
| 660 | + .set_fmt = mt9p031_set_format, | ||
| 661 | + .get_crop = mt9p031_get_crop, | ||
| 662 | + .set_crop = mt9p031_set_crop, | ||
| 663 | +}; | ||
| 664 | + | ||
| 665 | +static struct v4l2_subdev_ops mt9p031_subdev_ops = { | ||
| 666 | + .core = &mt9p031_subdev_core_ops, | ||
| 667 | + .video = &mt9p031_subdev_video_ops, | ||
| 668 | + .pad = &mt9p031_subdev_pad_ops, | ||
| 669 | +}; | ||
| 670 | + | ||
| 671 | +static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { | ||
| 672 | + .registered = mt9p031_registered, | ||
| 673 | + .open = mt9p031_open, | ||
| 674 | + .close = mt9p031_close, | ||
| 675 | +}; | ||
| 676 | + | ||
| 677 | +static int mt9p031_probe(struct i2c_client *client, | ||
| 678 | + const struct i2c_device_id *did) | ||
| 679 | +{ | ||
| 680 | + int ret; | ||
| 681 | + struct mt9p031 *mt9p031; | ||
| 682 | + struct mt9p031_platform_data *pdata = client->dev.platform_data; | ||
| 683 | + struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | ||
| 684 | + | ||
| 685 | + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) { | ||
| 686 | + dev_warn(&adapter->dev, | ||
| 687 | + "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n"); | ||
| 688 | + return -EIO; | ||
| 689 | + } | ||
| 690 | + | ||
| 691 | + mt9p031 = kzalloc(sizeof(struct mt9p031), GFP_KERNEL); | ||
| 692 | + if (!mt9p031) | ||
| 693 | + return -ENOMEM; | ||
| 694 | + | ||
| 695 | + mutex_init(&mt9p031->power_lock); | ||
| 696 | + v4l2_i2c_subdev_init(&mt9p031->subdev, client, &mt9p031_subdev_ops); | ||
| 697 | + mt9p031->subdev.internal_ops = &mt9p031_subdev_internal_ops; | ||
| 698 | + | ||
| 699 | + mt9p031->pdata = pdata; | ||
| 700 | + | ||
| 701 | + mt9p031->pad.flags = MEDIA_PAD_FL_SOURCE; | ||
| 702 | + ret = media_entity_init(&mt9p031->subdev.entity, 1, &mt9p031->pad, 0); | ||
| 703 | + if (ret) | ||
| 704 | + return ret; | ||
| 705 | + | ||
| 706 | + mt9p031->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; | ||
| 707 | + | ||
| 708 | + return 0; | ||
| 709 | +} | ||
| 710 | + | ||
| 711 | +static int mt9p031_remove(struct i2c_client *client) | ||
| 712 | +{ | ||
| 713 | + struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
| 714 | + struct mt9p031 *mt9p031 = container_of(sd, struct mt9p031, subdev); | ||
| 715 | + | ||
| 716 | + v4l2_device_unregister_subdev(sd); | ||
| 717 | + media_entity_cleanup(&sd->entity); | ||
| 718 | + kfree(mt9p031); | ||
| 719 | + | ||
| 720 | + return 0; | ||
| 721 | +} | ||
| 722 | + | ||
| 723 | +static const struct i2c_device_id mt9p031_id[] = { | ||
| 724 | + { "mt9p031", 0 }, | ||
| 725 | + { } | ||
| 726 | +}; | ||
| 727 | +MODULE_DEVICE_TABLE(i2c, mt9p031_id); | ||
| 728 | + | ||
| 729 | +static struct i2c_driver mt9p031_i2c_driver = { | ||
| 730 | + .driver = { | ||
| 731 | + .name = "mt9p031", | ||
| 732 | + }, | ||
| 733 | + .probe = mt9p031_probe, | ||
| 734 | + .remove = mt9p031_remove, | ||
| 735 | + .id_table = mt9p031_id, | ||
| 736 | +}; | ||
| 737 | + | ||
| 738 | +static int __init mt9p031_mod_init(void) | ||
| 739 | +{ | ||
| 740 | + return i2c_add_driver(&mt9p031_i2c_driver); | ||
| 741 | +} | ||
| 742 | + | ||
| 743 | +static void __exit mt9p031_mod_exit(void) | ||
| 744 | +{ | ||
| 745 | + i2c_del_driver(&mt9p031_i2c_driver); | ||
| 746 | +} | ||
| 747 | + | ||
| 748 | +module_init(mt9p031_mod_init); | ||
| 749 | +module_exit(mt9p031_mod_exit); | ||
| 750 | + | ||
| 751 | +MODULE_DESCRIPTION("Aptina MT9P031 Camera driver"); | ||
| 752 | +MODULE_AUTHOR("Bastian Hecht <hechtb@gmail.com>"); | ||
| 753 | +MODULE_LICENSE("GPL v2"); | ||
| 754 | diff --git a/include/media/mt9p031.h b/include/media/mt9p031.h | ||
| 755 | new file mode 100644 | ||
| 756 | index 0000000..ad37eb3 | ||
| 757 | --- /dev/null | ||
| 758 | +++ b/include/media/mt9p031.h | ||
| 759 | @@ -0,0 +1,11 @@ | ||
| 760 | +#ifndef MT9P031_H | ||
| 761 | +#define MT9P031_H | ||
| 762 | + | ||
| 763 | +struct v4l2_subdev; | ||
| 764 | + | ||
| 765 | +struct mt9p031_platform_data { | ||
| 766 | + int (*set_xclk)(struct v4l2_subdev *subdev, int hz); | ||
| 767 | + int (*reset)(struct v4l2_subdev *subdev, int active); | ||
| 768 | +}; | ||
| 769 | + | ||
| 770 | +#endif | ||
| 771 | -- | ||
| 772 | 1.6.6.1 | ||
| 773 | |||
diff --git a/recipes-kernel/linux/linux-omap-2.6.39/camera/0002-OMAP3BEAGLE-Add-support-for-mt9p031-sensor-driver.patch b/recipes-kernel/linux/linux-omap-2.6.39/camera/0002-OMAP3BEAGLE-Add-support-for-mt9p031-sensor-driver.patch deleted file mode 100644 index 68a762b2..00000000 --- a/recipes-kernel/linux/linux-omap-2.6.39/camera/0002-OMAP3BEAGLE-Add-support-for-mt9p031-sensor-driver.patch +++ /dev/null | |||
| @@ -1,142 +0,0 @@ | |||
| 1 | From 186ab3a6cd3f1751b4e60044d8207eb95c4b224a Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Javier Martin <javier.martin@vista-silicon.com> | ||
| 3 | Date: Wed, 25 May 2011 10:09:23 +0200 | ||
| 4 | Subject: [PATCH 2/4] OMAP3BEAGLE: Add support for mt9p031 sensor driver. | ||
| 5 | |||
| 6 | isp.h file has to be included as a temporal measure | ||
| 7 | since clocks of the isp are not exposed yet. | ||
| 8 | |||
| 9 | Signed-off-by: Javier Martin <javier.martin@vista-silicon.com> | ||
| 10 | --- | ||
| 11 | arch/arm/mach-omap2/board-omap3beagle.c | 73 ++++++++++++++++++++++++++++++- | ||
| 12 | 1 files changed, 72 insertions(+), 1 deletions(-) | ||
| 13 | |||
| 14 | diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 15 | index 221bfda..9af1cf8 100644 | ||
| 16 | --- a/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 17 | +++ b/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 18 | @@ -25,15 +25,21 @@ | ||
| 19 | #include <linux/input.h> | ||
| 20 | #include <linux/gpio_keys.h> | ||
| 21 | #include <linux/opp.h> | ||
| 22 | +#include <linux/i2c.h> | ||
| 23 | +#include <linux/mm.h> | ||
| 24 | +#include <linux/videodev2.h> | ||
| 25 | |||
| 26 | #include <linux/mtd/mtd.h> | ||
| 27 | #include <linux/mtd/partitions.h> | ||
| 28 | #include <linux/mtd/nand.h> | ||
| 29 | #include <linux/mmc/host.h> | ||
| 30 | |||
| 31 | +#include <linux/gpio.h> | ||
| 32 | #include <linux/regulator/machine.h> | ||
| 33 | #include <linux/i2c/twl.h> | ||
| 34 | |||
| 35 | +#include <media/mt9p031.h> | ||
| 36 | + | ||
| 37 | #include <mach/hardware.h> | ||
| 38 | #include <asm/mach-types.h> | ||
| 39 | #include <asm/mach/arch.h> | ||
| 40 | @@ -48,11 +54,17 @@ | ||
| 41 | #include <plat/nand.h> | ||
| 42 | #include <plat/usb.h> | ||
| 43 | #include <plat/omap_device.h> | ||
| 44 | +#include <plat/i2c.h> | ||
| 45 | |||
| 46 | #include "mux.h" | ||
| 47 | #include "hsmmc.h" | ||
| 48 | #include "timer-gp.h" | ||
| 49 | #include "pm.h" | ||
| 50 | +#include "devices.h" | ||
| 51 | +#include "../../../drivers/media/video/omap3isp/isp.h" | ||
| 52 | + | ||
| 53 | +#define MT9P031_RESET_GPIO 98 | ||
| 54 | +#define MT9P031_XCLK ISP_XCLK_A | ||
| 55 | |||
| 56 | #define NAND_BLOCK_SIZE SZ_128K | ||
| 57 | |||
| 58 | @@ -734,7 +746,7 @@ static int __init omap3_beagle_i2c_init(void) | ||
| 59 | { | ||
| 60 | omap_register_i2c_bus(1, 2600, beagle_i2c1_boardinfo, | ||
| 61 | ARRAY_SIZE(beagle_i2c1_boardinfo)); | ||
| 62 | - omap_register_i2c_bus(2, 400, beagle_i2c2_boardinfo, | ||
| 63 | + omap_register_i2c_bus(2, 100, beagle_i2c2_boardinfo, | ||
| 64 | ARRAY_SIZE(beagle_i2c2_boardinfo)); | ||
| 65 | /* Bus 3 is attached to the DVI port where devices like the pico DLP | ||
| 66 | * projector don't work reliably with 400kHz */ | ||
| 67 | @@ -935,6 +947,60 @@ static void __init beagle_opp_init(void) | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | |||
| 71 | +static int beagle_cam_set_xclk(struct v4l2_subdev *subdev, int hz) | ||
| 72 | +{ | ||
| 73 | + struct isp_device *isp = v4l2_dev_to_isp_device(subdev->v4l2_dev); | ||
| 74 | + int ret; | ||
| 75 | + | ||
| 76 | + ret = isp->platform_cb.set_xclk(isp, hz, MT9P031_XCLK); | ||
| 77 | + return 0; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +static int beagle_cam_reset(struct v4l2_subdev *subdev, int active) | ||
| 81 | +{ | ||
| 82 | + /* Set RESET_BAR to !active */ | ||
| 83 | + gpio_set_value(MT9P031_RESET_GPIO, !active); | ||
| 84 | + | ||
| 85 | + return 0; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +static struct mt9p031_platform_data beagle_mt9p031_platform_data = { | ||
| 89 | + .set_xclk = beagle_cam_set_xclk, | ||
| 90 | + .reset = beagle_cam_reset, | ||
| 91 | +}; | ||
| 92 | + | ||
| 93 | +static struct i2c_board_info mt9p031_camera_i2c_device = { | ||
| 94 | + I2C_BOARD_INFO("mt9p031", 0x48), | ||
| 95 | + .platform_data = &beagle_mt9p031_platform_data, | ||
| 96 | +}; | ||
| 97 | + | ||
| 98 | +static struct isp_subdev_i2c_board_info mt9p031_camera_subdevs[] = { | ||
| 99 | + { | ||
| 100 | + .board_info = &mt9p031_camera_i2c_device, | ||
| 101 | + .i2c_adapter_id = 2, | ||
| 102 | + }, | ||
| 103 | + { NULL, 0, }, | ||
| 104 | +}; | ||
| 105 | + | ||
| 106 | +static struct isp_v4l2_subdevs_group beagle_camera_subdevs[] = { | ||
| 107 | + { | ||
| 108 | + .subdevs = mt9p031_camera_subdevs, | ||
| 109 | + .interface = ISP_INTERFACE_PARALLEL, | ||
| 110 | + .bus = { | ||
| 111 | + .parallel = { | ||
| 112 | + .data_lane_shift = 0, | ||
| 113 | + .clk_pol = 1, | ||
| 114 | + .bridge = ISPCTRL_PAR_BRIDGE_DISABLE, | ||
| 115 | + } | ||
| 116 | + }, | ||
| 117 | + }, | ||
| 118 | + { }, | ||
| 119 | +}; | ||
| 120 | + | ||
| 121 | +static struct isp_platform_data beagle_isp_platform_data = { | ||
| 122 | + .subdevs = beagle_camera_subdevs, | ||
| 123 | +}; | ||
| 124 | + | ||
| 125 | static void __init omap3_beagle_init(void) | ||
| 126 | { | ||
| 127 | omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); | ||
| 128 | @@ -1024,6 +1090,11 @@ static void __init omap3_beagle_init(void) | ||
| 129 | |||
| 130 | beagle_display_init(); | ||
| 131 | beagle_opp_init(); | ||
| 132 | + | ||
| 133 | + /* Enable camera */ | ||
| 134 | + gpio_request(MT9P031_RESET_GPIO, "cam_rst"); | ||
| 135 | + gpio_direction_output(MT9P031_RESET_GPIO, 0); | ||
| 136 | + omap3_init_camera(&beagle_isp_platform_data); | ||
| 137 | } | ||
| 138 | |||
| 139 | early_param("buddy", expansionboard_setup); | ||
| 140 | -- | ||
| 141 | 1.6.6.1 | ||
| 142 | |||
diff --git a/recipes-kernel/linux/linux-omap-2.6.39/camera/0004-v4l-Add-mt9v032-sensor-driver.patch b/recipes-kernel/linux/linux-omap-2.6.39/camera/0002-v4l-Add-mt9v032-sensor-driver.patch index 48e41a54..2b7e9557 100644 --- a/recipes-kernel/linux/linux-omap-2.6.39/camera/0004-v4l-Add-mt9v032-sensor-driver.patch +++ b/recipes-kernel/linux/linux-omap-2.6.39/camera/0002-v4l-Add-mt9v032-sensor-driver.patch | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | From 9b0b5f99896549524c8f88a70f6cf0c0271d730e Mon Sep 17 00:00:00 2001 | 1 | From 78fdfee2f749cdcdfa69a008b70c4e5629b9c9df Mon Sep 17 00:00:00 2001 |
| 2 | From: Detlev Casanova <detlev.casanova@gmail.com> | 2 | From: Detlev Casanova <detlev.casanova@gmail.com> |
| 3 | Date: Sun, 28 Nov 2010 19:07:20 +0100 | 3 | Date: Sun, 28 Nov 2010 19:07:20 +0100 |
| 4 | Subject: [PATCH 4/4] v4l: Add mt9v032 sensor driver | 4 | Subject: [PATCH 2/3] v4l: Add mt9v032 sensor driver |
| 5 | 5 | ||
| 6 | The MT9V032 is a parallel wide VGA sensor from Aptina (formerly Micron) | 6 | The MT9V032 is a parallel wide VGA sensor from Aptina (formerly Micron) |
| 7 | controlled through I2C. | 7 | controlled through I2C. |
diff --git a/recipes-kernel/linux/linux-omap-2.6.39/camera/0003-Add-support-for-mt9p031-LI-5M03-module-in-Beagleboar.patch b/recipes-kernel/linux/linux-omap-2.6.39/camera/0003-Add-support-for-mt9p031-LI-5M03-module-in-Beagleboar.patch new file mode 100644 index 00000000..9f7fb006 --- /dev/null +++ b/recipes-kernel/linux/linux-omap-2.6.39/camera/0003-Add-support-for-mt9p031-LI-5M03-module-in-Beagleboar.patch | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | From 6cce194e3d1fbc5d746b192b4d1ff78aef6099cf Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Javier Martin <javier.martin@vista-silicon.com> | ||
| 3 | Date: Mon, 30 May 2011 10:37:17 +0200 | ||
| 4 | Subject: [PATCH 3/3] Add support for mt9p031 (LI-5M03 module) in Beagleboard xM. | ||
| 5 | |||
| 6 | Since isp clocks have not been exposed yet, this patch | ||
| 7 | includes a temporal solution for testing mt9p031 driver | ||
| 8 | in Beagleboard xM. | ||
| 9 | |||
| 10 | Signed-off-by: Javier Martin <javier.martin@vista-silicon.com> | ||
| 11 | --- | ||
| 12 | arch/arm/mach-omap2/Makefile | 1 + | ||
| 13 | arch/arm/mach-omap2/board-omap3beagle-camera.c | 91 ++++++++++++++++++++++++ | ||
| 14 | arch/arm/mach-omap2/board-omap3beagle.c | 5 ++ | ||
| 15 | 3 files changed, 97 insertions(+), 0 deletions(-) | ||
| 16 | create mode 100644 arch/arm/mach-omap2/board-omap3beagle-camera.c | ||
| 17 | |||
| 18 | diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile | ||
| 19 | index 512b152..05cd983 100644 | ||
| 20 | --- a/arch/arm/mach-omap2/Makefile | ||
| 21 | +++ b/arch/arm/mach-omap2/Makefile | ||
| 22 | @@ -179,6 +179,7 @@ obj-$(CONFIG_MACH_OMAP_2430SDP) += board-2430sdp.o \ | ||
| 23 | hsmmc.o | ||
| 24 | obj-$(CONFIG_MACH_OMAP_APOLLON) += board-apollon.o | ||
| 25 | obj-$(CONFIG_MACH_OMAP3_BEAGLE) += board-omap3beagle.o \ | ||
| 26 | + board-omap3beagle-camera.o \ | ||
| 27 | hsmmc.o | ||
| 28 | obj-$(CONFIG_MACH_DEVKIT8000) += board-devkit8000.o \ | ||
| 29 | hsmmc.o | ||
| 30 | diff --git a/arch/arm/mach-omap2/board-omap3beagle-camera.c b/arch/arm/mach-omap2/board-omap3beagle-camera.c | ||
| 31 | new file mode 100644 | ||
| 32 | index 0000000..8387951 | ||
| 33 | --- /dev/null | ||
| 34 | +++ b/arch/arm/mach-omap2/board-omap3beagle-camera.c | ||
| 35 | @@ -0,0 +1,91 @@ | ||
| 36 | +#include <linux/gpio.h> | ||
| 37 | +#include <linux/regulator/machine.h> | ||
| 38 | + | ||
| 39 | +#include <plat/i2c.h> | ||
| 40 | + | ||
| 41 | +#include <media/mt9p031.h> | ||
| 42 | + | ||
| 43 | +#include "devices.h" | ||
| 44 | +#include "../../../drivers/media/video/omap3isp/isp.h" | ||
| 45 | + | ||
| 46 | +#define MT9P031_RESET_GPIO 98 | ||
| 47 | +#define MT9P031_XCLK ISP_XCLK_A | ||
| 48 | + | ||
| 49 | +static struct regulator *reg_1v8, *reg_2v8; | ||
| 50 | + | ||
| 51 | +static int beagle_cam_set_xclk(struct v4l2_subdev *subdev, int hz) | ||
| 52 | +{ | ||
| 53 | + struct isp_device *isp = v4l2_dev_to_isp_device(subdev->v4l2_dev); | ||
| 54 | + int ret; | ||
| 55 | + | ||
| 56 | + ret = isp->platform_cb.set_xclk(isp, hz, MT9P031_XCLK); | ||
| 57 | + return 0; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +static int beagle_cam_reset(struct v4l2_subdev *subdev, int active) | ||
| 61 | +{ | ||
| 62 | + /* Set RESET_BAR to !active */ | ||
| 63 | + gpio_set_value(MT9P031_RESET_GPIO, !active); | ||
| 64 | + | ||
| 65 | + return 0; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +static struct mt9p031_platform_data beagle_mt9p031_platform_data = { | ||
| 69 | + .set_xclk = beagle_cam_set_xclk, | ||
| 70 | + .reset = beagle_cam_reset, | ||
| 71 | +}; | ||
| 72 | + | ||
| 73 | +static struct i2c_board_info mt9p031_camera_i2c_device = { | ||
| 74 | + I2C_BOARD_INFO("mt9p031", 0x48), | ||
| 75 | + .platform_data = &beagle_mt9p031_platform_data, | ||
| 76 | +}; | ||
| 77 | + | ||
| 78 | +static struct isp_subdev_i2c_board_info mt9p031_camera_subdevs[] = { | ||
| 79 | + { | ||
| 80 | + .board_info = &mt9p031_camera_i2c_device, | ||
| 81 | + .i2c_adapter_id = 2, | ||
| 82 | + }, | ||
| 83 | + { NULL, 0, }, | ||
| 84 | +}; | ||
| 85 | + | ||
| 86 | +static struct isp_v4l2_subdevs_group beagle_camera_subdevs[] = { | ||
| 87 | + { | ||
| 88 | + .subdevs = mt9p031_camera_subdevs, | ||
| 89 | + .interface = ISP_INTERFACE_PARALLEL, | ||
| 90 | + .bus = { | ||
| 91 | + .parallel = { | ||
| 92 | + .data_lane_shift = 0, | ||
| 93 | + .clk_pol = 1, | ||
| 94 | + .bridge = ISPCTRL_PAR_BRIDGE_DISABLE, | ||
| 95 | + } | ||
| 96 | + }, | ||
| 97 | + }, | ||
| 98 | + { }, | ||
| 99 | +}; | ||
| 100 | + | ||
| 101 | +static struct isp_platform_data beagle_isp_platform_data = { | ||
| 102 | + .subdevs = beagle_camera_subdevs, | ||
| 103 | +}; | ||
| 104 | + | ||
| 105 | +static int __init beagle_camera_init(void) { | ||
| 106 | + if(cpu_is_omap3630()){ | ||
| 107 | + reg_1v8 = regulator_get(NULL, "cam_1v8"); | ||
| 108 | + if (IS_ERR(reg_1v8)) | ||
| 109 | + pr_err("%s: cannot get cam_1v8 regulator\n", __func__); | ||
| 110 | + else | ||
| 111 | + regulator_enable(reg_1v8); | ||
| 112 | + | ||
| 113 | + reg_2v8 = regulator_get(NULL, "cam_2v8"); | ||
| 114 | + if (IS_ERR(reg_2v8)) | ||
| 115 | + pr_err("%s: cannot get cam_2v8 regulator\n", __func__); | ||
| 116 | + else | ||
| 117 | + regulator_enable(reg_2v8); | ||
| 118 | + | ||
| 119 | + omap_register_i2c_bus(2, 100, NULL, 0); | ||
| 120 | + gpio_request(MT9P031_RESET_GPIO, "cam_rst"); | ||
| 121 | + gpio_direction_output(MT9P031_RESET_GPIO, 0); | ||
| 122 | + omap3_init_camera(&beagle_isp_platform_data); | ||
| 123 | + } | ||
| 124 | + return 0; | ||
| 125 | +} | ||
| 126 | +late_initcall(beagle_camera_init); | ||
| 127 | diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 128 | index 221bfda..dd6e31f 100644 | ||
| 129 | --- a/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 130 | +++ b/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 131 | @@ -25,12 +25,16 @@ | ||
| 132 | #include <linux/input.h> | ||
| 133 | #include <linux/gpio_keys.h> | ||
| 134 | #include <linux/opp.h> | ||
| 135 | +#include <linux/i2c.h> | ||
| 136 | +#include <linux/mm.h> | ||
| 137 | +#include <linux/videodev2.h> | ||
| 138 | |||
| 139 | #include <linux/mtd/mtd.h> | ||
| 140 | #include <linux/mtd/partitions.h> | ||
| 141 | #include <linux/mtd/nand.h> | ||
| 142 | #include <linux/mmc/host.h> | ||
| 143 | |||
| 144 | +#include <linux/gpio.h> | ||
| 145 | #include <linux/regulator/machine.h> | ||
| 146 | #include <linux/i2c/twl.h> | ||
| 147 | |||
| 148 | @@ -48,6 +52,7 @@ | ||
| 149 | #include <plat/nand.h> | ||
| 150 | #include <plat/usb.h> | ||
| 151 | #include <plat/omap_device.h> | ||
| 152 | +#include <plat/i2c.h> | ||
| 153 | |||
| 154 | #include "mux.h" | ||
| 155 | #include "hsmmc.h" | ||
| 156 | -- | ||
| 157 | 1.6.6.1 | ||
| 158 | |||
diff --git a/recipes-kernel/linux/linux-omap-2.6.39/camera/0003-OMAP3-beagle-only-init-camera-on-3630.patch b/recipes-kernel/linux/linux-omap-2.6.39/camera/0003-OMAP3-beagle-only-init-camera-on-3630.patch deleted file mode 100644 index b7efa4e5..00000000 --- a/recipes-kernel/linux/linux-omap-2.6.39/camera/0003-OMAP3-beagle-only-init-camera-on-3630.patch +++ /dev/null | |||
| @@ -1,34 +0,0 @@ | |||
| 1 | From 014b3e447a0a9bbed5e238873fefb1a6c660c6a0 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Koen Kooi <koen@dominion.thruhere.net> | ||
| 3 | Date: Wed, 25 May 2011 10:28:29 +0200 | ||
| 4 | Subject: [PATCH 3/4] OMAP3: beagle: only init camera on 3630 | ||
| 5 | |||
| 6 | Signed-off-by: Koen Kooi <koen@dominion.thruhere.net> | ||
| 7 | --- | ||
| 8 | arch/arm/mach-omap2/board-omap3beagle.c | 10 ++++++---- | ||
| 9 | 1 files changed, 6 insertions(+), 4 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 12 | index 9af1cf8..80f8ece 100644 | ||
| 13 | --- a/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 14 | +++ b/arch/arm/mach-omap2/board-omap3beagle.c | ||
| 15 | @@ -1091,10 +1091,12 @@ static void __init omap3_beagle_init(void) | ||
| 16 | beagle_display_init(); | ||
| 17 | beagle_opp_init(); | ||
| 18 | |||
| 19 | - /* Enable camera */ | ||
| 20 | - gpio_request(MT9P031_RESET_GPIO, "cam_rst"); | ||
| 21 | - gpio_direction_output(MT9P031_RESET_GPIO, 0); | ||
| 22 | - omap3_init_camera(&beagle_isp_platform_data); | ||
| 23 | + if (cpu_is_omap3630()) { | ||
| 24 | + /* Enable camera */ | ||
| 25 | + gpio_request(MT9P031_RESET_GPIO, "cam_rst"); | ||
| 26 | + gpio_direction_output(MT9P031_RESET_GPIO, 0); | ||
| 27 | + omap3_init_camera(&beagle_isp_platform_data); | ||
| 28 | + } | ||
| 29 | } | ||
| 30 | |||
| 31 | early_param("buddy", expansionboard_setup); | ||
| 32 | -- | ||
| 33 | 1.6.6.1 | ||
| 34 | |||
diff --git a/recipes-kernel/linux/linux-omap_2.6.39.bb b/recipes-kernel/linux/linux-omap_2.6.39.bb index af99e037..8c9461ea 100644 --- a/recipes-kernel/linux/linux-omap_2.6.39.bb +++ b/recipes-kernel/linux/linux-omap_2.6.39.bb | |||
| @@ -7,7 +7,7 @@ COMPATIBLE_MACHINE = "(beagleboard)" | |||
| 7 | 7 | ||
| 8 | # The main PR is now using MACHINE_KERNEL_PR, for omap3 see conf/machine/include/omap3.inc | 8 | # The main PR is now using MACHINE_KERNEL_PR, for omap3 see conf/machine/include/omap3.inc |
| 9 | SRCREV_pn-${PN} = "v2.6.39" | 9 | SRCREV_pn-${PN} = "v2.6.39" |
| 10 | MACHINE_KERNEL_PR_append = "f" | 10 | MACHINE_KERNEL_PR_append = "g" |
| 11 | 11 | ||
| 12 | FILESPATHPKG_prepend = "linux-omap-2.6.39:" | 12 | FILESPATHPKG_prepend = "linux-omap-2.6.39:" |
| 13 | 13 | ||
| @@ -53,10 +53,9 @@ SRC_URI_append = " \ | |||
| 53 | file://beagle/0004-OMAP3-beagle-add-regulators-for-camera-interface.patch \ | 53 | file://beagle/0004-OMAP3-beagle-add-regulators-for-camera-interface.patch \ |
| 54 | file://beagle/0005-OMAP3-beagle-HACK-add-in-1GHz-OPP.patch \ | 54 | file://beagle/0005-OMAP3-beagle-HACK-add-in-1GHz-OPP.patch \ |
| 55 | \ | 55 | \ |
| 56 | file://camera/0001-Add-mt9p031-sensor-driver.patch \ | 56 | file://camera/0001-Add-support-for-mt9p031-Aptina-Micron-sensor.patch \ |
| 57 | file://camera/0002-OMAP3BEAGLE-Add-support-for-mt9p031-sensor-driver.patch \ | 57 | file://camera/0002-v4l-Add-mt9v032-sensor-driver.patch \ |
| 58 | file://camera/0003-OMAP3-beagle-only-init-camera-on-3630.patch \ | 58 | file://camera/0003-Add-support-for-mt9p031-LI-5M03-module-in-Beagleboar.patch \ |
| 59 | file://camera/0004-v4l-Add-mt9v032-sensor-driver.patch \ | ||
| 60 | \ | 59 | \ |
| 61 | file://pm/linux-omap-2.6.39-ti-pm/0001-OMAP3-voltage-remove-spurious-pr_notice-for-debugfs.patch \ | 60 | file://pm/linux-omap-2.6.39-ti-pm/0001-OMAP3-voltage-remove-spurious-pr_notice-for-debugfs.patch \ |
| 62 | file://pm/linux-omap-2.6.39-ti-pm/0002-OMAP4-PM-remove-redundant-ifdef-CONFIG_PM.patch \ | 61 | file://pm/linux-omap-2.6.39-ti-pm/0002-OMAP4-PM-remove-redundant-ifdef-CONFIG_PM.patch \ |
