PageRenderTime 83ms CodeModel.GetById 17ms app.highlight 56ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/media/video/sun4i_csi/device/mt9m112.c

https://bitbucket.org/ndreys/linux-sunxi
C | 2056 lines | 1529 code | 272 blank | 255 comment | 97 complexity | 4a1a6ce1e3a8ff10cbabd17db3664c2c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

   1/*
   2 * drivers/media/video/sun4i_csi/device/mt9m112.c
   3 *
   4 * (C) Copyright 2007-2012
   5 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
   6 *
   7 * This program is free software; you can redistribute it and/or
   8 * modify it under the terms of the GNU General Public License as
   9 * published by the Free Software Foundation; either version 2 of
  10 * the License, or (at your option) any later version.
  11 *
  12 * This program is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
  15 * GNU General Public License for more details.
  16 *
  17 * You should have received a copy of the GNU General Public License
  18 * along with this program; if not, write to the Free Software
  19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20 * MA 02111-1307 USA
  21 */
  22
  23/*
  24 * A V4L2 driver for Micron mt9m112 cameras.
  25 *
  26 */
  27#include <linux/init.h>
  28#include <linux/module.h>
  29#include <linux/slab.h>
  30#include <linux/i2c.h>
  31#include <linux/delay.h>
  32#include <linux/videodev2.h>
  33#include <linux/clk.h>
  34#include <media/v4l2-device.h>
  35#include <media/v4l2-chip-ident.h>
  36#include <media/v4l2-mediabus.h>//linux-3.0
  37#include <linux/io.h>
  38//#include <mach/gpio_v2.h>
  39#include <mach/sys_config.h>
  40#include <linux/regulator/consumer.h>
  41#include <mach/system.h>
  42#include "../include/sun4i_csi_core.h"
  43#include "../include/sun4i_dev_csi.h"
  44
  45MODULE_AUTHOR("raymonxiu");
  46MODULE_DESCRIPTION("A low-level driver for Micron mt9m112 sensors");
  47MODULE_LICENSE("GPL");
  48
  49//for internel driver debug
  50#define DEV_DBG_EN   		0 
  51#if(DEV_DBG_EN == 1)		
  52#define csi_dev_dbg(x,arg...) printk(KERN_INFO"[CSI_DEBUG][MT9M112]"x,##arg)
  53#else
  54#define csi_dev_dbg(x,arg...) 
  55#endif
  56#define csi_dev_err(x,arg...) printk(KERN_INFO"[CSI_ERR][MT9M112]"x,##arg)
  57#define csi_dev_print(x,arg...) printk(KERN_INFO"[CSI][MT9M112]"x,##arg)
  58
  59#define MCLK (24*1000*1000)
  60//#define MCLK (49.5*1000*1000)
  61#define VREF_POL	CSI_HIGH
  62#define HREF_POL	CSI_HIGH
  63#define CLK_POL		CSI_RISING
  64#define IO_CFG		0						//0 for csi0
  65
  66//define the voltage level of control signal
  67#define CSI_STBY_ON			1
  68#define CSI_STBY_OFF 		0
  69#define CSI_RST_ON			0
  70#define CSI_RST_OFF			1
  71#define CSI_PWR_ON			1
  72#define CSI_PWR_OFF			0
  73
  74
  75#define V4L2_IDENT_SENSOR 0x1320
  76
  77#define REG_TERM 0xff
  78#define VAL_TERM 0xff
  79
  80
  81#define REG_ADDR_STEP 1
  82#define REG_DATA_STEP 2
  83#define REG_STEP 			(REG_ADDR_STEP+REG_DATA_STEP)
  84
  85
  86/*
  87 * Basic window sizes.  These probably belong somewhere more globally
  88 * useful.
  89 */
  90#define SXGA_WIDTH	1280
  91#define SXGA_HEIGHT	1024
  92#define VGA_WIDTH		640
  93#define VGA_HEIGHT	480
  94#define QVGA_WIDTH	320
  95#define QVGA_HEIGHT	240
  96#define CIF_WIDTH		352
  97#define CIF_HEIGHT	288
  98#define QCIF_WIDTH	176
  99#define	QCIF_HEIGHT	144
 100
 101/*
 102 * Our nominal (default) frame rate.
 103 */
 104#define SENSOR_FRAME_RATE 25
 105
 106/*
 107 * The Micron mt9m112 sits on i2c with ID 0xBA
 108 */
 109#define I2C_ADDR 0xBA
 110
 111/* Registers */
 112
 113
 114/*
 115 * Information we maintain about a known sensor.
 116 */
 117struct sensor_format_struct;  /* coming later */
 118__csi_subdev_info_t ccm_info_con = 
 119{
 120	.mclk 	= MCLK,
 121	.vref 	= VREF_POL,
 122	.href 	= HREF_POL,
 123	.clock	= CLK_POL,
 124	.iocfg	= IO_CFG,
 125};
 126
 127struct sensor_info {
 128	struct v4l2_subdev sd;
 129	struct sensor_format_struct *fmt;  /* Current format */
 130	__csi_subdev_info_t *ccm_info;
 131	int	width;
 132	int	height;
 133	int brightness;
 134	int	contrast;
 135	int saturation;
 136	int hue;
 137	int hflip;
 138	int vflip;
 139	int gain;
 140	int autogain;
 141	int exp;
 142	enum v4l2_exposure_auto_type autoexp;
 143	int autowb;
 144	enum v4l2_whiteblance wb;
 145	enum v4l2_colorfx clrfx;
 146	enum v4l2_flash_mode flash_mode;
 147	u8 clkrc;			/* Clock divider value */
 148};
 149
 150static inline struct sensor_info *to_state(struct v4l2_subdev *sd)
 151{
 152	return container_of(sd, struct sensor_info, sd);
 153}
 154
 155
 156struct regval_list {
 157	unsigned char reg_num[REG_ADDR_STEP];
 158	unsigned char value[REG_DATA_STEP];
 159};
 160
 161
 162/*
 163 * The default register settings
 164 *
 165 */
 166
 167static struct regval_list sensor_default_regs[] = {
 168#if 1 //MCLK == 24M
 169{{0xf0},{0x00,0x00}},
 170{{0x66},{0x10,0x01}},
 171{{0x67},{0x05,0x01}},
 172{{0x65},{0xa0,0x00}},
 173{{0xff},{0x00,0x64}},
 174{{0x65},{0x20,0x00}},
 175{{0xff},{0x00,0x64}},
 176#endif 
 177{{0xf0},{0x00,0x00}},
 178{{0x0d},{0x00,0x09}},
 179{{0xff},{0x00,0x20}},
 180{{0x0d},{0x00,0x08}},
 181{{0xf0},{0x00,0x00}},
 182{{0x01},{0x00,0x24}},
 183{{0x03},{0x04,0x00}},// default value
 184{{0x30},{0x04,0x2a}},
 185{{0xf0},{0x00,0x01}},
 186{{0x05},{0x00,0x0f}},
 187{{0x25},{0x00,0x4d}},// saturation adjustment, default value  0x4d
 188{{0x3b},{0x04,0x30}},//0x0436
 189{{0x3c},{0x04,0x00}},
 190{{0x47},{0x32,0x2e}},
 191{{0x9d},{0x3c,0xe0}},
 192
 193{{0xf0},{0x00,0x02}},
 194{{0x28},{0xef,0x02}},//0xef3e
 195{{0x06},{0x74,0x8e}},
 196{{0x02},{0x00,0xee}},// base matrix signs
 197{{0x15},{0x00,0xd9}},// delta coefficients signs
 198{{0x09},{0x00,0x67}},//k1
 199{{0x0a},{0x00,0x9a}},//k2
 200{{0x0b},{0x00,0x28}},//k3
 201{{0x0c},{0x00,0x30}},//k4
 202{{0x0d},{0x00,0xca}},//k5
 203{{0x0e},{0x00,0x37}},//k6
 204{{0x0f},{0x00,0x1a}},//k7
 205{{0x10},{0x00,0x65}},//k8
 206{{0x11},{0x00,0x86}},//k9
 207{{0x16},{0x00,0x5e}},//d1  0x0062
 208{{0x17},{0x00,0x84}},//d2
 209{{0x18},{0x00,0x4d}},//d3
 210{{0x19},{0x00,0x24}},//d4
 211{{0x1a},{0x00,0x1f}},//d5
 212{{0x1b},{0x00,0x2f}},//d6
 213{{0x1c},{0x00,0x04}},//d7
 214{{0x1d},{0x00,0x23}},//d8
 215{{0x1e},{0x00,0x10}},//d9
 216{{0x03},{0x39,0x22}},// base matrix scale k1-k5
 217{{0x04},{0x05,0x24}},// base matrix scale k6-k9 0x04e4
 218{{0xf0},{0x00,0x02}},
 219{{0x1f},{0x01,0x80}},
 220{{0x20},{0xc8,0x14}},//0xdc0c
 221{{0x21},{0x80,0x80}},
 222{{0x22},{0x90,0x80}},
 223{{0x23},{0x88,0x78}},
 224{{0x26},{0x80,0x00}},
 225{{0x27},{0x80,0x08}},
 226{{0x2e},{0x0c,0x44}},// 0x0d20
 227{{0x3e},{0x1c,0xff}},
 228{{0x46},{0x00,0xb0}},
 229{{0x5b},{0x80,0x02}},
 230{{0x5c},{0x11,0x0c}},
 231{{0x5d},{0x15,0x10}},
 232{{0x5e},{0x53,0x4c}},
 233{{0x5f},{0x2b,0x21}},
 234{{0x24},{0x7f,0x40}},
 235{{0x60},{0x00,0x02}},
 236{{0x62},{0x10,0x10}},
 237{{0x65},{0x00,0x00}},
 238{{0xdc},{0x0f,0xf8}},
 239{{0xdd},{0x0c,0xe0}},
 240{{0xf0},{0x00,0x01}},
 241{{0x47},{0x20,0x2e}},
 242{{0x80},{0x00,0x06}},// lens correction control   
 243{{0x81},{0x00,0x00}},// vertical red knee 0 and initial value  0x0009
 244{{0x82},{0xfe,0x05}},// vertical red knees 2 and 1
 245{{0x83},{0x00,0x00}},// vertical red knees 4 and 30x00ff
 246{{0x84},{0x0c,0x00}},// vertical green knee 0 and initial value
 247{{0x85},{0xfe,0x02}},// vertical green knees 2 and 1
 248{{0x86},{0x00,0xff}},// vertical green knees 4 and 3
 249{{0x87},{0x07,0x01}},// vertical blue knee 0 and initial value 1003
 250{{0x88},{0xfc,0x06}},// vertical blue knees 2 and 1
 251{{0x89},{0x00,0xff}},// vertical blue knees 4 and 3
 252{{0x8a},{0x08,0x01}},// horizontal red knee 0 and initial value
 253{{0x8b},{0x03,0x0e}},// horizontal red knees 2 and 1
 254{{0x8c},{0xfe,0xfd}},// horizontal red knees 4 and 3
 255{{0x8d},{0x00,0xff}},// horizontal red knee 5
 256{{0x8e},{0x06,0x01}},// horizontal green knee 0 and initial value
 257{{0x8f},{0x04,0x0b}},// horizontal green knees 2 and 1 
 258{{0x90},{0xfe,0xfb}},// horizontal green knees 4 and 3
 259{{0x91},{0x00,0xfe}},// horizontal green knee 5
 260{{0x92},{0x06,0x00}},// horizontal blue knee 0 and initial value
 261{{0x93},{0x04,0x0b}},// horizontal blue knees 2 and 1 
 262{{0x94},{0xfe,0xfd}},// horizontal blue knees 4 and 3
 263{{0x95},{0x00,0xff}},// horizontal blue knees 5
 264{{0xb6},{0x02,0x04}},// lens vertical red knees 6 and 5
 265{{0xb7},{0xfb,0xfa}},// lens vertical red knees 8 and 7
 266{{0xb8},{0x05,0x03}},// lens vertical green knees 6 and 5
 267{{0xb9},{0xfa,0xf8}},// lens vertical green knees 8 and 7
 268{{0xba},{0x04,0x01}},// lens vertical blue knees 6 and 5
 269{{0xbb},{0xfe,0xf8}},// lens vertical blue knees 8 and 7
 270{{0xbc},{0xff,0x01}},// lens horizontal red knees 7 and 6
 271{{0xbd},{0xf4,0xff}},// lens horizontal red knees 9 and 8
 272{{0xbe},{0x00,0xfb}},// lens horizontal red knee 10
 273{{0xbf},{0x00,0x00}},// lens horizontal green knees 7 and 6
 274{{0xc0},{0xf8,0xfd}},// lens horizontal green knees 9 and 8
 275{{0xc1},{0x00,0xf7}},// lens horizontal green knee 10
 276{{0xc2},{0x01,0xff}},// lens horizontal blue knees 7 and 6
 277{{0xc3},{0xf5,0xfc}},// lens horizontal blue knees 9 and 8
 278{{0xc4},{0x00,0xfa}},// lens horizontal blue knee 10
 279{{0x06},{0x74,0x8e}},
 280{{0x9d},{0x3c,0xe0}},// defect correction control
 281{{0xf0},{0x00,0x02}},
 282{{0x2e},{0x0d,0x3a}},// 0x0d32
 283{{0x37},{0x00,0x81}},
 284{{0x36},{0x78,0x10}},
 285{{0xf0},{0x00,0x01}},
 286{{0x06},{0xf4,0x8e}},
 287{{0xf0},{0x00,0x01}},
 288{{0x06},{0x64,0x8e}},
 289{{0xf0},{0x00,0x02}},
 290{{0x5b},{0x00,0x01}},//0x0003
 291
 292{{0xf0},{0x00,0x00}},
 293{{0x20},{0x01,0x00}},
 294{{0x21},{0x80,0x00}},
 295{{0x22},{0x09,0x0d}},
 296};
 297
 298static struct regval_list sensor_oe_disable_regs[] = {
 299{{0xf0},{0x00,0x00}},
 300{{0x0d},{0x00,0x18}},
 301};
 302
 303static struct regval_list sensor_sxga_regs[] = {
 304{{0xf0},{0x00,0x00}},
 305{{0x05},{0x01,0x40}},// horizontal blank
 306{{0x06},{0x00,0x0d}},
 307{{0xf0},{0x00,0x02}},
 308{{0xc8},{0x1f,0x0b}},
 309{{0x9c},{0xd1,0x00}},// auto exposure speed B
 310{{0x59},{0x02,0x71}},
 311{{0x5a},{0x02,0x71}},
 312{{0xf0},{0x00,0x00}},
 313//{{0x20},{0x01,0x00}},
 314//{{0x22},{0x09,0x0d}},
 315{{0x68},{0x00,0x70}},
 316{{0xf0},{0x00,0x01}},
 317{{0xa1},{0x05,0x00}},// horizontal output size B
 318{{0xa4},{0x04,0x00}},// vertical output size B
 319{{0x9b},{0x02,0x02}},
 320{{0xdc},{0x11,0x05}},// gamma start B
 321{{0xdd},{0x5d,0x33}},
 322{{0xde},{0xad,0x8d}},
 323{{0xdf},{0xd6,0xc4}},
 324{{0xe0},{0xf3,0xe6}},
 325{{0xe1},{0xff,0x00}},// gamma end B
 326{{0xf0},{0x00,0x00}},
 327};
 328
 329static struct regval_list sensor_vga_regs[] = {
 330{{0xf0},{0x00,0x00}},
 331{{0x07},{0x03,0x74}},   //horizontal blank
 332{{0x08},{0x00,0x09}},
 333{{0xf0},{0x00,0x02}},
 334{{0xc8},{0x00,0x00}},
 335{{0x2f},{0xd1,0x00}},// auto exposure speed A
 336{{0x57},{0x02,0x71}},
 337{{0x58},{0x02,0x71}},
 338{{0xf0},{0x00,0x00}},
 339//{{0x21},{0x80,0x00}},
 340//{{0x22},{0x09,0x0d}},
 341{{0x68},{0x00,0x70}},
 342{{0xf0},{0x00,0x01}},
 343{{0xa7},{0x02,0x80}},// horizontal output size A
 344{{0xaa},{0x02,0x00}},// vertical output size A
 345{{0x3a},{0x02,0x02}},
 346{{0x53},{0x11,0x05}},// gamma start A
 347{{0x54},{0x5d,0x33}},
 348{{0x55},{0xad,0x8d}},
 349{{0x56},{0xd6,0xc4}},
 350{{0x57},{0xf3,0xe6}},
 351{{0x58},{0xff,0x00}},// gamma end A
 352{{0xf0},{0x00,0x00}},
 353};
 354
 355/*
 356 * The white balance settings
 357 * Here only tune the R G B channel gain. 
 358 * The white balance enalbe bit is modified in sensor_s_autowb and sensor_s_wb
 359 */
 360//static struct regval_list sensor_wb_auto_regs[] = {
 361//	//NULL
 362//};
 363
 364static struct regval_list sensor_wb_cloud_regs[] = {
 365	//NULL
 366};
 367
 368static struct regval_list sensor_wb_daylight_regs[] = {
 369	//tai yang guang
 370	//NULL
 371};
 372
 373static struct regval_list sensor_wb_incandescence_regs[] = {
 374	//bai re guang
 375	//NULL
 376};
 377
 378static struct regval_list sensor_wb_fluorescent_regs[] = {
 379	//ri guang deng
 380	//NULL
 381};
 382
 383static struct regval_list sensor_wb_tungsten_regs[] = {
 384	//wu si deng
 385	//NULL
 386};
 387
 388/*
 389 * The color effect settings
 390 */
 391static struct regval_list sensor_colorfx_none_regs[] = {
 392{{0xf0},{0x00,0x01}},
 393{{0xe2},{0x70,0x00}},
 394};
 395
 396static struct regval_list sensor_colorfx_bw_regs[] = {
 397{{0xf0},{0x00,0x01}},
 398{{0xe2},{0x70,0x01}},
 399};
 400
 401static struct regval_list sensor_colorfx_sepia_regs[] = {
 402{{0xf0},{0x00,0x01}},
 403{{0xe2},{0x70,0x02}},
 404};
 405
 406static struct regval_list sensor_colorfx_negative_regs[] = {
 407{{0xf0},{0x00,0x01}},
 408{{0xe2},{0x70,0x03}},
 409};
 410
 411static struct regval_list sensor_colorfx_emboss_regs[] = {
 412	//NULL
 413};
 414
 415static struct regval_list sensor_colorfx_sketch_regs[] = {
 416	//NULL
 417};
 418
 419static struct regval_list sensor_colorfx_sky_blue_regs[] = {
 420	//NULL
 421};
 422
 423static struct regval_list sensor_colorfx_grass_green_regs[] = {
 424	//NULL
 425};
 426
 427static struct regval_list sensor_colorfx_skin_whiten_regs[] = {
 428	//NULL
 429};
 430
 431static struct regval_list sensor_colorfx_vivid_regs[] = {
 432	//NULL
 433};
 434
 435/*
 436 * The brightness setttings
 437 */
 438static struct regval_list sensor_brightness_neg4_regs[] = {
 439	//NULL
 440};
 441
 442static struct regval_list sensor_brightness_neg3_regs[] = {
 443	//NULL
 444};
 445
 446static struct regval_list sensor_brightness_neg2_regs[] = {
 447	//NULL
 448};
 449
 450static struct regval_list sensor_brightness_neg1_regs[] = {
 451	//NULL
 452};
 453
 454static struct regval_list sensor_brightness_zero_regs[] = {
 455	//NULL
 456};
 457
 458static struct regval_list sensor_brightness_pos1_regs[] = {
 459	//NULL
 460};
 461
 462static struct regval_list sensor_brightness_pos2_regs[] = {
 463	//NULL
 464};
 465
 466static struct regval_list sensor_brightness_pos3_regs[] = {
 467	//NULL
 468};
 469
 470static struct regval_list sensor_brightness_pos4_regs[] = {
 471	//NULL
 472};
 473
 474/*
 475 * The contrast setttings
 476 */
 477static struct regval_list sensor_contrast_neg4_regs[] = {
 478	//NULL
 479};
 480
 481static struct regval_list sensor_contrast_neg3_regs[] = {
 482	//NULL
 483};
 484
 485static struct regval_list sensor_contrast_neg2_regs[] = {
 486	//NULL
 487};
 488
 489static struct regval_list sensor_contrast_neg1_regs[] = {
 490	//NULL
 491};
 492
 493static struct regval_list sensor_contrast_zero_regs[] = {
 494	//NULL
 495};
 496
 497static struct regval_list sensor_contrast_pos1_regs[] = {
 498	//NULL
 499};
 500
 501static struct regval_list sensor_contrast_pos2_regs[] = {
 502	//NULL
 503};
 504
 505static struct regval_list sensor_contrast_pos3_regs[] = {
 506	//NULL
 507};
 508
 509static struct regval_list sensor_contrast_pos4_regs[] = {
 510	//NULL
 511};
 512
 513/*
 514 * The saturation setttings
 515 */
 516static struct regval_list sensor_saturation_neg4_regs[] = {
 517	//NULL
 518};
 519
 520static struct regval_list sensor_saturation_neg3_regs[] = {
 521	//NULL
 522};
 523
 524static struct regval_list sensor_saturation_neg2_regs[] = {
 525	//NULL
 526};
 527
 528static struct regval_list sensor_saturation_neg1_regs[] = {
 529	//NULL
 530};
 531
 532static struct regval_list sensor_saturation_zero_regs[] = {
 533	//NULL
 534};
 535
 536static struct regval_list sensor_saturation_pos1_regs[] = {
 537	//NULL
 538};
 539
 540static struct regval_list sensor_saturation_pos2_regs[] = {
 541	//NULL
 542};
 543
 544static struct regval_list sensor_saturation_pos3_regs[] = {
 545	//NULL
 546};
 547
 548static struct regval_list sensor_saturation_pos4_regs[] = {
 549	//NULL
 550};
 551
 552/*
 553 * The exposure target setttings
 554 */
 555static struct regval_list sensor_ev_neg4_regs[] = {
 556	//NULL
 557};
 558
 559static struct regval_list sensor_ev_neg3_regs[] = {
 560	//NULL
 561};
 562
 563static struct regval_list sensor_ev_neg2_regs[] = {
 564	//NULL
 565};
 566
 567static struct regval_list sensor_ev_neg1_regs[] = {
 568	//NULL
 569};
 570
 571static struct regval_list sensor_ev_zero_regs[] = {
 572	//NULL
 573};
 574
 575static struct regval_list sensor_ev_pos1_regs[] = {
 576	//NULL
 577};
 578
 579static struct regval_list sensor_ev_pos2_regs[] = {
 580	//NULL
 581};
 582
 583static struct regval_list sensor_ev_pos3_regs[] = {
 584	//NULL
 585};
 586
 587static struct regval_list sensor_ev_pos4_regs[] = {
 588	//NULL
 589};
 590
 591
 592/*
 593 * Here we'll try to encapsulate the changes for just the output
 594 * video format.
 595 * 
 596 */
 597
 598
 599static struct regval_list sensor_fmt_yuv422_yuyv[] = {
 600	{{0xf0},{0x00,0x01}},   //Page 1
 601	{{0x9b},{0x02,0x02}},   //Context B YCbYCr 
 602	{{0x3a},{0x02,0x02}},   //Context A YCbYCr
 603};
 604
 605
 606static struct regval_list sensor_fmt_yuv422_yvyu[] = {
 607	{{0xf0},{0x00,0x01}},   //Page 1
 608	{{0x9b},{0x02,0x03}},   //Context B YCrYCb 
 609	{{0x3a},{0x02,0x03}},   //Context A YCrYCb
 610};
 611
 612static struct regval_list sensor_fmt_yuv422_vyuy[] = {
 613	{{0xf0},{0x00,0x01}},   //Page 1
 614	{{0x9b},{0x02,0x01}},   //Context B CrYCbY 
 615	{{0x3a},{0x02,0x01}},   //Context A CrYCbY
 616};
 617
 618static struct regval_list sensor_fmt_yuv422_uyvy[] = {
 619	{{0xf0},{0x00,0x01}},   //Page 1
 620	{{0x9b},{0x02,0x00}},   //Context B CbYCrY 
 621	{{0x3a},{0x02,0x00}},   //Context A CbYCrY
 622};
 623
 624//static struct regval_list sensor_fmt_raw[] = {
 625//	
 626//};
 627
 628
 629
 630/*
 631 * Low-level register I/O.
 632 *
 633 */
 634
 635
 636/*
 637 * On most platforms, we'd rather do straight i2c I/O.
 638 */
 639static int sensor_read(struct v4l2_subdev *sd, unsigned char *reg,
 640		unsigned char *value)
 641{
 642	struct i2c_client *client = v4l2_get_subdevdata(sd);
 643	u8 data[REG_STEP];
 644	struct i2c_msg msg;
 645	int ret,i;
 646	
 647	for(i = 0; i < REG_ADDR_STEP; i++)
 648		data[i] = reg[i];
 649	
 650	data[REG_ADDR_STEP] = 0xff;
 651	/*
 652	 * Send out the register address...
 653	 */
 654	msg.addr = client->addr;
 655	msg.flags = 0;
 656	msg.len = REG_ADDR_STEP;
 657	msg.buf = data;
 658	ret = i2c_transfer(client->adapter, &msg, 1);
 659	if (ret < 0) {
 660		csi_dev_err("Error %d on register write\n", ret);
 661		return ret;
 662	}
 663	/*
 664	 * ...then read back the result.
 665	 */
 666	
 667	msg.flags = I2C_M_RD;
 668	msg.len = REG_DATA_STEP;
 669	msg.buf = &data[REG_ADDR_STEP];
 670	
 671	ret = i2c_transfer(client->adapter, &msg, 1);
 672	if (ret >= 0) {
 673		for(i = 0; i < REG_DATA_STEP; i++)
 674			value[i] = data[i+REG_ADDR_STEP];
 675		ret = 0;
 676	}
 677	else {
 678		csi_dev_err("Error %d on register read\n", ret);
 679	}
 680	return ret;
 681}
 682
 683
 684static int sensor_write(struct v4l2_subdev *sd, unsigned char *reg,
 685		unsigned char *value)
 686{
 687	struct i2c_client *client = v4l2_get_subdevdata(sd);
 688	struct i2c_msg msg;
 689	unsigned char data[REG_STEP];
 690	int ret,i;
 691	
 692	for(i = 0; i < REG_ADDR_STEP; i++)
 693			data[i] = reg[i];
 694	for(i = REG_ADDR_STEP; i < REG_STEP; i++)
 695			data[i] = value[i-REG_ADDR_STEP];
 696	
 697	msg.addr = client->addr;
 698	msg.flags = 0;
 699	msg.len = REG_STEP;
 700	msg.buf = data;
 701
 702	
 703	ret = i2c_transfer(client->adapter, &msg, 1);
 704	if (ret > 0) {
 705		ret = 0;
 706	}
 707	else if (ret < 0) {
 708		csi_dev_err("sensor_write error!\n");
 709	}
 710	return ret;
 711}
 712
 713
 714/*
 715 * Write a list of register settings;
 716 */
 717static int sensor_write_array(struct v4l2_subdev *sd, struct regval_list *vals , uint size)
 718{
 719	int i,ret;
 720
 721	if (size == 0)
 722		return -EINVAL;
 723	
 724	for(i = 0; i < size ; i++)
 725	{
 726		if(vals->reg_num[0] == 0xff)
 727			msleep(vals->value[0] * 256 + vals->value[1]);
 728		else {	
 729			ret = sensor_write(sd, vals->reg_num, vals->value);
 730			if (ret < 0)
 731				{
 732					csi_dev_err("sensor_write_err!\n");
 733					return ret;
 734				}
 735		}	
 736		vals++;
 737	}
 738
 739	return 0;
 740}
 741
 742
 743/*
 744 * Stuff that knows about the sensor.
 745 */
 746 
 747static int sensor_power(struct v4l2_subdev *sd, int on)
 748{
 749	struct csi_dev *dev=(struct csi_dev *)dev_get_drvdata(sd->v4l2_dev->dev);
 750	struct sensor_info *info = to_state(sd);
 751	char csi_stby_str[32],csi_power_str[32],csi_reset_str[32];
 752	int ret;
 753	
 754	if(info->ccm_info->iocfg == 0) {
 755		strcpy(csi_stby_str,"csi_stby");
 756		strcpy(csi_power_str,"csi_power_en");
 757		strcpy(csi_reset_str,"csi_reset");
 758	} else if(info->ccm_info->iocfg == 1) {
 759	  strcpy(csi_stby_str,"csi_stby_b");
 760	  strcpy(csi_power_str,"csi_power_en_b");
 761	  strcpy(csi_reset_str,"csi_reset_b");
 762	}
 763  
 764  switch(on)
 765	{
 766		case CSI_SUBDEV_STBY_ON:
 767			csi_dev_dbg("CSI_SUBDEV_STBY_ON\n");
 768			//reset off io
 769			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 770			msleep(10);
 771			//active mclk before stadby in
 772			clk_enable(dev->csi_module_clk);
 773			msleep(100);
 774			//disable io oe
 775			csi_dev_print("disalbe oe!\n");
 776			ret = sensor_write_array(sd, sensor_oe_disable_regs , ARRAY_SIZE(sensor_oe_disable_regs));
 777			if(ret < 0)
 778				csi_dev_err("disalbe oe falied!\n");
 779			//standby on io
 780			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_ON,csi_stby_str);
 781			msleep(100);
 782//			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_OFF,csi_stby_str);
 783//			msleep(100);
 784//			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_ON,csi_stby_str);
 785//			msleep(100);
 786			//inactive mclk after stadby in
 787			clk_disable(dev->csi_module_clk);
 788	
 789//			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
 790//			msleep(10);
 791			break;
 792		case CSI_SUBDEV_STBY_OFF:
 793			csi_dev_dbg("CSI_SUBDEV_STBY_OFF\n");
 794			//active mclk before stadby out
 795			clk_enable(dev->csi_module_clk);
 796			msleep(10);
 797			//reset off io
 798			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 799			msleep(10);
 800			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
 801			msleep(100);
 802			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 803			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_OFF,csi_stby_str);
 804			msleep(10);
 805			break;
 806		case CSI_SUBDEV_PWR_ON:
 807			csi_dev_dbg("CSI_SUBDEV_PWR_ON\n");
 808			//inactive mclk before power on
 809			clk_disable(dev->csi_module_clk);
 810			//power on reset
 811			gpio_set_one_pin_io_status(dev->csi_pin_hd,1,csi_stby_str);//set the gpio to output
 812			gpio_set_one_pin_io_status(dev->csi_pin_hd,1,csi_reset_str);//set the gpio to output
 813			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_ON,csi_stby_str);
 814			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
 815			msleep(1);
 816			//power supply
 817			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_PWR_ON,csi_power_str);
 818			msleep(10);
 819			if(dev->dvdd) {
 820				regulator_enable(dev->dvdd);
 821				msleep(10);
 822			}
 823			if(dev->avdd) {
 824				regulator_enable(dev->avdd);
 825				msleep(10);
 826			}
 827			if(dev->iovdd) {
 828				regulator_enable(dev->iovdd);
 829				msleep(10);
 830			}
 831			//active mclk before power on
 832			clk_enable(dev->csi_module_clk);
 833			//reset after power on
 834			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 835			msleep(10);
 836			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
 837			msleep(100);
 838			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 839			msleep(100);
 840			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_STBY_OFF,csi_stby_str);
 841			msleep(10);
 842			break;
 843			
 844		case CSI_SUBDEV_PWR_OFF:
 845			csi_dev_dbg("CSI_SUBDEV_PWR_OFF\n");
 846			//power supply off
 847			if(dev->iovdd) {
 848				regulator_disable(dev->iovdd);
 849				msleep(10);
 850			}
 851			if(dev->avdd) {
 852				regulator_disable(dev->avdd);
 853				msleep(10);
 854			}
 855			if(dev->dvdd) {
 856				regulator_disable(dev->dvdd);
 857				msleep(10);	
 858			}
 859			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_PWR_OFF,csi_power_str);
 860			msleep(10);
 861			
 862			//inactive mclk after power off
 863			clk_disable(dev->csi_module_clk);
 864			
 865			//set the io to hi-z
 866			gpio_set_one_pin_io_status(dev->csi_pin_hd,0,csi_reset_str);//set the gpio to input
 867			gpio_set_one_pin_io_status(dev->csi_pin_hd,0,csi_stby_str);//set the gpio to input
 868			break;
 869		default:
 870			return -EINVAL;
 871	}		
 872
 873	return 0;
 874}
 875 
 876static int sensor_reset(struct v4l2_subdev *sd, u32 val)
 877{
 878	struct csi_dev *dev=(struct csi_dev *)dev_get_drvdata(sd->v4l2_dev->dev);
 879	struct sensor_info *info = to_state(sd);
 880	char csi_reset_str[32];
 881  
 882	if(info->ccm_info->iocfg == 0) {
 883		strcpy(csi_reset_str,"csi_reset");
 884	} else if(info->ccm_info->iocfg == 1) {
 885	  strcpy(csi_reset_str,"csi_reset_b");
 886	}
 887	
 888	switch(val)
 889	{
 890		case CSI_SUBDEV_RST_OFF:
 891			csi_dev_dbg("CSI_SUBDEV_RST_OFF\n");
 892			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 893			msleep(10);
 894			break;
 895		case CSI_SUBDEV_RST_ON:
 896			csi_dev_dbg("CSI_SUBDEV_RST_ON\n");
 897			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
 898			msleep(10);
 899			break;
 900		case CSI_SUBDEV_RST_PUL:
 901			csi_dev_dbg("CSI_SUBDEV_RST_PUL\n");
 902			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 903			msleep(10);
 904			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_ON,csi_reset_str);
 905			msleep(100);
 906			gpio_write_one_pin_value(dev->csi_pin_hd,CSI_RST_OFF,csi_reset_str);
 907			msleep(10);
 908			break;
 909		default:
 910			return -EINVAL;
 911	}
 912		
 913	return 0;
 914}
 915
 916static int sensor_detect(struct v4l2_subdev *sd)
 917{
 918	int ret;
 919	struct regval_list regs;
 920	
 921	regs.reg_num[0] = 0xfe;
 922	regs.value[0] = 0x00; //PAGE 0x00
 923	regs.value[1] = 0x00;
 924	
 925	ret = sensor_write(sd, regs.reg_num, regs.value);
 926	if (ret < 0) {
 927		csi_dev_err("sensor_write err at sensor_detect!\n");
 928		return ret;
 929	}
 930	
 931	regs.reg_num[0] = 0x00;
 932	regs.reg_num[1] = 0x00;
 933	ret = sensor_read(sd, regs.reg_num, regs.value);
 934	if (ret < 0) {
 935		csi_dev_err("sensor_read err at sensor_detect!\n");
 936		return ret;
 937	}
 938
 939	if(regs.value[0] != 0x14)
 940		return -ENODEV;
 941	
 942	return 0;
 943}
 944
 945static int sensor_init(struct v4l2_subdev *sd, u32 val)
 946{
 947	int ret;
 948	csi_dev_dbg("sensor_init\n");
 949	/*Make sure it is a target sensor*/
 950	ret = sensor_detect(sd);
 951	if (ret) {
 952		csi_dev_err("chip found is not an target chip.\n");
 953		return ret;
 954	}
 955	
 956	return sensor_write_array(sd, sensor_default_regs , ARRAY_SIZE(sensor_default_regs));
 957}
 958
 959static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 960{
 961	int ret=0;
 962	
 963	switch(cmd){
 964		case CSI_SUBDEV_CMD_GET_INFO: 
 965		{
 966			struct sensor_info *info = to_state(sd);
 967			__csi_subdev_info_t *ccm_info = arg;
 968			
 969			csi_dev_dbg("CSI_SUBDEV_CMD_GET_INFO\n");
 970			ccm_info->mclk 	=	info->ccm_info->mclk ;
 971			ccm_info->vref 	=	info->ccm_info->vref ;
 972			ccm_info->href 	=	info->ccm_info->href ;
 973			ccm_info->clock	=	info->ccm_info->clock;
 974			ccm_info->iocfg	=	info->ccm_info->iocfg;
 975			csi_dev_dbg("ccm_info.mclk=%x\n ",info->ccm_info->mclk);
 976			csi_dev_dbg("ccm_info.vref=%x\n ",info->ccm_info->vref);
 977			csi_dev_dbg("ccm_info.href=%x\n ",info->ccm_info->href);
 978			csi_dev_dbg("ccm_info.clock=%x\n ",info->ccm_info->clock);
 979			csi_dev_dbg("ccm_info.iocfg=%x\n ",info->ccm_info->iocfg);
 980			break;
 981		}
 982		case CSI_SUBDEV_CMD_SET_INFO:
 983		{
 984			struct sensor_info *info = to_state(sd);
 985			__csi_subdev_info_t *ccm_info = arg;
 986			
 987			csi_dev_dbg("CSI_SUBDEV_CMD_SET_INFO\n");
 988			info->ccm_info->mclk 	=	ccm_info->mclk 	;
 989			info->ccm_info->vref 	=	ccm_info->vref 	;
 990			info->ccm_info->href 	=	ccm_info->href 	;
 991			info->ccm_info->clock	=	ccm_info->clock	;
 992			info->ccm_info->iocfg	=	ccm_info->iocfg	;
 993			csi_dev_dbg("ccm_info.mclk=%x\n ",info->ccm_info->mclk);
 994			csi_dev_dbg("ccm_info.vref=%x\n ",info->ccm_info->vref);
 995			csi_dev_dbg("ccm_info.href=%x\n ",info->ccm_info->href);
 996			csi_dev_dbg("ccm_info.clock=%x\n ",info->ccm_info->clock);
 997			csi_dev_dbg("ccm_info.iocfg=%x\n ",info->ccm_info->iocfg);
 998			break;
 999		}
1000		default:
1001			return -EINVAL;
1002	}		
1003		return ret;
1004}
1005
1006
1007/*
1008 * Store information about the video data format. 
1009 */
1010static struct sensor_format_struct {
1011	__u8 *desc;
1012	//__u32 pixelformat;
1013	enum v4l2_mbus_pixelcode mbus_code;//linux-3.0
1014	struct regval_list *regs;
1015	int	regs_size;
1016	int bpp;   /* Bytes per pixel */
1017} sensor_formats[] = {
1018	{
1019		.desc		= "YUYV 4:2:2",
1020		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,//linux-3.0
1021		.regs 		= sensor_fmt_yuv422_yuyv,
1022		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_yuyv),
1023		.bpp		= 2,
1024	},
1025	{
1026		.desc		= "YVYU 4:2:2",
1027		.mbus_code	= V4L2_MBUS_FMT_YVYU8_2X8,//linux-3.0
1028		.regs 		= sensor_fmt_yuv422_yvyu,
1029		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_yvyu),
1030		.bpp		= 2,
1031	},
1032	{
1033		.desc		= "UYVY 4:2:2",
1034		.mbus_code	= V4L2_MBUS_FMT_UYVY8_2X8,//linux-3.0
1035		.regs 		= sensor_fmt_yuv422_uyvy,
1036		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_uyvy),
1037		.bpp		= 2,
1038	},
1039	{
1040		.desc		= "VYUY 4:2:2",
1041		.mbus_code	= V4L2_MBUS_FMT_VYUY8_2X8,//linux-3.0
1042		.regs 		= sensor_fmt_yuv422_vyuy,
1043		.regs_size = ARRAY_SIZE(sensor_fmt_yuv422_vyuy),
1044		.bpp		= 2,
1045	},
1046//	{
1047//		.desc		= "Raw RGB Bayer",
1048//		.mbus_code	= V4L2_MBUS_FMT_SBGGR8_1X8,//linux-3.0
1049//		.regs 		= sensor_fmt_raw,
1050//		.regs_size = ARRAY_SIZE(sensor_fmt_raw),
1051//		.bpp		= 1
1052//	},
1053};
1054#define N_FMTS ARRAY_SIZE(sensor_formats)
1055
1056
1057/*
1058 * Then there is the issue of window sizes.  Try to capture the info here.
1059 */
1060
1061
1062static struct sensor_win_size {
1063	int	width;
1064	int	height;
1065	int	hstart;		/* Start/stop values for the camera.  Note */
1066	int	hstop;		/* that they do not always make complete */
1067	int	vstart;		/* sense to humans, but evidently the sensor */
1068	int	vstop;		/* will do the right thing... */
1069	struct regval_list *regs; /* Regs to tweak */
1070	int regs_size;
1071	int (*set_size) (struct v4l2_subdev *sd);
1072/* h/vref stuff */
1073} sensor_win_sizes[] = {
1074	/* SXGA */
1075	{
1076		.width		= SXGA_WIDTH,
1077		.height		= SXGA_HEIGHT,
1078		.regs 		= sensor_sxga_regs,
1079		.regs_size	= ARRAY_SIZE(sensor_sxga_regs),
1080		.set_size		= NULL,
1081	},
1082	/* VGA */
1083	{
1084		.width		= VGA_WIDTH,
1085		.height		= VGA_HEIGHT,
1086		.regs 		= sensor_vga_regs,
1087		.regs_size	= ARRAY_SIZE(sensor_vga_regs),
1088		.set_size		= NULL,
1089	}
1090};
1091
1092#define N_WIN_SIZES (ARRAY_SIZE(sensor_win_sizes))
1093
1094 
1095 
1096 
1097static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned index,
1098                 enum v4l2_mbus_pixelcode *code)//linux-3.0
1099{
1100//	struct sensor_format_struct *ofmt;
1101
1102	if (index >= N_FMTS)//linux-3.0
1103		return -EINVAL;
1104
1105	*code = sensor_formats[index].mbus_code;//linux-3.0
1106//	ofmt = sensor_formats + fmt->index;
1107//	fmt->flags = 0;
1108//	strcpy(fmt->description, ofmt->desc);
1109//	fmt->pixelformat = ofmt->pixelformat;
1110	return 0;
1111}
1112
1113
1114static int sensor_try_fmt_internal(struct v4l2_subdev *sd,
1115		//struct v4l2_format *fmt,
1116		struct v4l2_mbus_framefmt *fmt,//linux-3.0
1117		struct sensor_format_struct **ret_fmt,
1118		struct sensor_win_size **ret_wsize)
1119{
1120	int index;
1121	struct sensor_win_size *wsize;
1122//	struct v4l2_pix_format *pix = &fmt->fmt.pix;//linux-3.0
1123	csi_dev_dbg("sensor_try_fmt_internal\n");
1124	for (index = 0; index < N_FMTS; index++)
1125		if (sensor_formats[index].mbus_code == fmt->code)//linux-3.0
1126			break;
1127	
1128	if (index >= N_FMTS) {
1129		/* default to first format */
1130		index = 0;
1131		fmt->code = sensor_formats[0].mbus_code;//linux-3.0
1132	}
1133	
1134	if (ret_fmt != NULL)
1135		*ret_fmt = sensor_formats + index;
1136		
1137	/*
1138	 * Fields: the sensor devices claim to be progressive.
1139	 */
1140	fmt->field = V4L2_FIELD_NONE;//linux-3.0
1141	
1142	
1143	/*
1144	 * Round requested image size down to the nearest
1145	 * we support, but not below the smallest.
1146	 */
1147	for (wsize = sensor_win_sizes; wsize < sensor_win_sizes + N_WIN_SIZES;
1148	     wsize++)
1149		if (fmt->width >= wsize->width && fmt->height >= wsize->height)//linux-3.0
1150			break;
1151	
1152	if (wsize >= sensor_win_sizes + N_WIN_SIZES)
1153		wsize--;   /* Take the smallest one */
1154		
1155	if (ret_wsize != NULL)
1156		*ret_wsize = wsize;
1157	/*
1158	 * Note the size we'll actually handle.
1159	 */
1160	fmt->width = wsize->width;//linux-3.0
1161	fmt->height = wsize->height;//linux-3.0
1162	//pix->bytesperline = pix->width*sensor_formats[index].bpp;//linux-3.0
1163	//pix->sizeimage = pix->height*pix->bytesperline;//linux-3.0
1164	
1165	return 0;
1166}
1167
1168static int sensor_try_fmt(struct v4l2_subdev *sd, 
1169             struct v4l2_mbus_framefmt *fmt)//linux-3.0
1170{
1171	return sensor_try_fmt_internal(sd, fmt, NULL, NULL);
1172}
1173
1174/*
1175 * Set a format.
1176 */
1177static int sensor_s_fmt(struct v4l2_subdev *sd, 
1178             struct v4l2_mbus_framefmt *fmt)//linux-3.0
1179{
1180	int ret;
1181	struct sensor_format_struct *sensor_fmt;
1182	struct sensor_win_size *wsize;
1183	struct sensor_info *info = to_state(sd);
1184	csi_dev_dbg("sensor_s_fmt\n");
1185	ret = sensor_try_fmt_internal(sd, fmt, &sensor_fmt, &wsize);
1186	if (ret)
1187		return ret;
1188	
1189		
1190	sensor_write_array(sd, sensor_fmt->regs , sensor_fmt->regs_size);
1191	
1192	ret = 0;
1193	if (wsize->regs)
1194	{
1195		ret = sensor_write_array(sd, wsize->regs , wsize->regs_size);
1196		if (ret < 0)
1197			return ret;
1198	}
1199	
1200	if (wsize->set_size)
1201	{
1202		ret = wsize->set_size(sd);
1203		if (ret < 0)
1204			return ret;
1205	}
1206	
1207	info->fmt = sensor_fmt;
1208	info->width = wsize->width;
1209	info->height = wsize->height;
1210	
1211	return 0;
1212}
1213
1214/*
1215 * Implement G/S_PARM.  There is a "high quality" mode we could try
1216 * to do someday; for now, we just do the frame rate tweak.
1217 */
1218static int sensor_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
1219{
1220	struct v4l2_captureparm *cp = &parms->parm.capture;
1221	//struct sensor_info *info = to_state(sd);
1222
1223	if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1224		return -EINVAL;
1225
1226	memset(cp, 0, sizeof(struct v4l2_captureparm));
1227	cp->capability = V4L2_CAP_TIMEPERFRAME;
1228	cp->timeperframe.numerator = 1;
1229	cp->timeperframe.denominator = SENSOR_FRAME_RATE;
1230	
1231	return 0;
1232}
1233
1234static int sensor_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
1235{
1236	return -EINVAL;
1237}
1238
1239
1240/* 
1241 * Code for dealing with controls.
1242 * fill with different sensor module
1243 * different sensor module has different settings here
1244 * if not support the follow function ,retrun -EINVAL
1245 */
1246
1247/* *********************************************begin of ******************************************** */
1248static int sensor_queryctrl(struct v4l2_subdev *sd,
1249		struct v4l2_queryctrl *qc)
1250{
1251	/* Fill in min, max, step and default value for these controls. */
1252	/* see include/linux/videodev2.h for details */
1253	/* see sensor_s_parm and sensor_g_parm for the meaning of value */
1254	
1255	switch (qc->id) {
1256//	case V4L2_CID_BRIGHTNESS:
1257//		return v4l2_ctrl_query_fill(qc, -4, 4, 1, 1);
1258//	case V4L2_CID_CONTRAST:
1259//		return v4l2_ctrl_query_fill(qc, -4, 4, 1, 1);
1260//	case V4L2_CID_SATURATION:
1261//		return v4l2_ctrl_query_fill(qc, -4, 4, 1, 1);
1262//	case V4L2_CID_HUE:
1263//		return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0);
1264	case V4L2_CID_VFLIP:
1265	case V4L2_CID_HFLIP:
1266		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1267//	case V4L2_CID_GAIN:
1268//		return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1269//	case V4L2_CID_AUTOGAIN:
1270//		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1271//	case V4L2_CID_EXPOSURE:
1272//		return v4l2_ctrl_query_fill(qc, -4, 4, 1, 0);
1273//	case V4L2_CID_EXPOSURE_AUTO:
1274//		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1275//	case V4L2_CID_DO_WHITE_BALANCE:
1276//		return v4l2_ctrl_query_fill(qc, 0, 5, 1, 0);
1277//	case V4L2_CID_AUTO_WHITE_BALANCE:
1278//		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1279	case V4L2_CID_COLORFX:
1280		return v4l2_ctrl_query_fill(qc, 0, 9, 1, 0);
1281	case V4L2_CID_CAMERA_FLASH_MODE:
1282	  return v4l2_ctrl_query_fill(qc, 0, 4, 1, 0);	
1283	}
1284	return -EINVAL;
1285}
1286
1287static int sensor_g_hflip(struct v4l2_subdev *sd, __s32 *value)
1288{
1289	int ret;
1290	struct sensor_info *info = to_state(sd);
1291	struct regval_list regs;
1292	
1293	regs.reg_num[0] = 0xf0;
1294	regs.value[0] = 0x00; //PAGEMODE 0x00
1295	regs.value[1] = 0x00;
1296	
1297	ret = sensor_write(sd, regs.reg_num, regs.value);
1298	if (ret < 0) {
1299		csi_dev_err("sensor_write err at sensor_g_hflip!\n");
1300		return ret;
1301	}
1302	
1303	regs.reg_num[0] = 0x20;
1304	ret = sensor_read(sd, regs.reg_num, regs.value);
1305	if (ret < 0) {
1306		csi_dev_err("sensor_read err at sensor_g_hflip!\n");
1307		return ret;
1308	}
1309	
1310	regs.value[1] &= (1<<1);
1311	regs.value[1] = regs.value[1]>>1;		//0x20 bit1 is hflip enable
1312	
1313	*value = regs.value[1];
1314	info->hflip = *value;
1315	return 0;
1316}
1317
1318static int sensor_s_hflip(struct v4l2_subdev *sd, int value)
1319{
1320	int ret;
1321	struct sensor_info *info = to_state(sd);
1322	struct regval_list regs;
1323	
1324	regs.reg_num[0] = 0xf0;
1325	regs.value[0] = 0x00; //PAGEMODE 0x00
1326	regs.value[1] = 0x00; 
1327	
1328	ret = sensor_write(sd, regs.reg_num, regs.value);
1329	if (ret < 0) {
1330		csi_dev_err("sensor_write err at sensor_s_hflip!\n");
1331		return ret;
1332	}
1333	
1334	regs.reg_num[0] = 0x20;
1335	ret = sensor_read(sd, regs.reg_num, regs.value);
1336	if (ret < 0) {
1337		csi_dev_err("sensor_read err at sensor_s_hflip!\n");
1338		return ret;
1339	}
1340	
1341	switch(value) {
1342	case 0:
1343		regs.value[1] &= 0xfd;
1344		break;
1345	case 1:
1346		regs.value[1] |= 0x02;
1347		break;
1348	default:
1349			return -EINVAL;
1350	}	
1351	
1352	ret = sensor_write(sd, regs.reg_num, regs.value);
1353	if (ret < 0) {
1354		csi_dev_err("sensor_write err at sensor_s_hflip!\n");
1355		return ret;
1356	}
1357	msleep(100);
1358	info->hflip = value;
1359	return 0;
1360}
1361
1362static int sensor_g_vflip(struct v4l2_subdev *sd, __s32 *value)
1363{
1364	int ret;
1365	struct sensor_info *info = to_state(sd);
1366	struct regval_list regs;
1367	
1368	regs.reg_num[0] = 0xf0;
1369	regs.value[0] = 0x00; //PAGEMODE 0x00
1370	regs.value[1] = 0x00;
1371	
1372	ret = sensor_write(sd, regs.reg_num, regs.value);
1373	if (ret < 0) {
1374		csi_dev_err("sensor_write err at sensor_g_vflip!\n");
1375		return ret;
1376	}
1377	
1378	regs.reg_num[0] = 0x20;
1379	ret = sensor_read(sd, regs.reg_num, regs.value);
1380	if (ret < 0) {
1381		csi_dev_err("sensor_read err at sensor_g_vflip!\n");
1382		return ret;
1383	}
1384
1385	regs.value[1] &= (1<<0);
1386	regs.value[1] = regs.value[0]>>0;		//0x20 bit0 is vflip enable
1387	
1388	*value = regs.value[1];
1389	info->hflip = *value;
1390	return 0;
1391}
1392
1393static int sensor_s_vflip(struct v4l2_subdev *sd, int value)
1394{
1395	int ret;
1396	struct sensor_info *info = to_state(sd);
1397	struct regval_list regs;
1398	
1399	regs.reg_num[0] = 0xf0;
1400	regs.value[0] = 0x00; //PAGEMODE 0x00
1401	regs.value[1] = 0x00;
1402	
1403	ret = sensor_write(sd, regs.reg_num, regs.value);
1404	if (ret < 0) {
1405		csi_dev_err("sensor_write err at sensor_s_vflip!\n");
1406		return ret;
1407	}
1408	
1409	regs.reg_num[0] = 0x20;
1410	ret = sensor_read(sd, regs.reg_num, regs.value);
1411	if (ret < 0) {
1412		csi_dev_err("sensor_read err at sensor_s_vflip!\n");
1413		return ret;
1414	}
1415	
1416	switch(value) {
1417	case 0:
1418		regs.value[1] &= 0xfe;
1419		break;
1420	case 1:
1421		regs.value[1] |= 0x01;
1422		break;
1423	default:
1424			return -EINVAL;
1425	}	
1426	
1427	ret = sensor_write(sd, regs.reg_num, regs.value);
1428	if (ret < 0) {
1429		csi_dev_err("sensor_write err at sensor_s_vflip!\n");
1430		return ret;
1431	}
1432	msleep(100);
1433	info->vflip = value;
1434	return 0;
1435}
1436
1437static int sensor_g_autogain(struct v4l2_subdev *sd, __s32 *value)
1438{
1439	return -EINVAL;
1440}
1441
1442static int sensor_s_autogain(struct v4l2_subdev *sd, int value)
1443{
1444	return -EINVAL;
1445}
1446
1447static int sensor_g_autoexp(struct v4l2_subdev *sd, __s32 *value)
1448{
1449	return -EINVAL;
1450}
1451
1452static int sensor_s_autoexp(struct v4l2_subdev *sd,
1453		enum v4l2_exposure_auto_type value)
1454{
1455	return -EINVAL;
1456}
1457
1458static int sensor_g_autowb(struct v4l2_subdev *sd, int *value)
1459{
1460	return -EINVAL;
1461}
1462
1463static int sensor_s_autowb(struct v4l2_subdev *sd, int value)
1464{
1465	return -EINVAL;
1466}
1467
1468static int sensor_g_hue(struct v4l2_subdev *sd, __s32 *value)
1469{
1470	return -EINVAL;
1471}
1472
1473static int sensor_s_hue(struct v4l2_subdev *sd, int value)
1474{
1475	return -EINVAL;
1476}
1477
1478static int sensor_g_gain(struct v4l2_subdev *sd, __s32 *value)
1479{
1480	return -EINVAL;
1481}
1482
1483static int sensor_s_gain(struct v4l2_subdev *sd, int value)
1484{
1485	return -EINVAL;
1486}
1487/* *********************************************end of ******************************************** */
1488
1489static int sensor_g_brightness(struct v4l2_subdev *sd, __s32 *value)
1490{
1491	struct sensor_info *info = to_state(sd);
1492	
1493	*value = info->brightness;
1494	return 0;
1495}
1496
1497static int sensor_s_brightness(struct v4l2_subdev *sd, int value)
1498{
1499	int ret;
1500	struct sensor_info *info = to_state(sd);
1501	
1502	switch (value) {
1503		case -4:
1504		  ret = sensor_write_array(sd, sensor_brightness_neg4_regs, ARRAY_SIZE(sensor_brightness_neg4_regs));
1505			break;
1506		case -3:
1507			ret = sensor_write_array(sd, sensor_brightness_neg3_regs, ARRAY_SIZE(sensor_brightness_neg3_regs));
1508			break;
1509		case -2:
1510			ret = sensor_write_array(sd, sensor_brightness_neg2_regs, ARRAY_SIZE(sensor_brightness_neg2_regs));
1511			break;   
1512		case -1:
1513			ret = sensor_write_array(sd, sensor_brightness_neg1_regs, ARRAY_SIZE(sensor_brightness_neg1_regs));
1514			break;
1515		case 0:   
1516			ret = sensor_write_array(sd, sensor_brightness_zero_regs, ARRAY_SIZE(sensor_brightness_zero_regs));
1517			break;
1518		case 1:
1519			ret = sensor_write_array(sd, sensor_brightness_pos1_regs, ARRAY_SIZE(sensor_brightness_pos1_regs));
1520			break;
1521		case 2:
1522			ret = sensor_write_array(sd, sensor_brightness_pos2_regs, ARRAY_SIZE(sensor_brightness_pos2_regs));
1523			break;	
1524		case 3:
1525			ret = sensor_write_array(sd, sensor_brightness_pos3_regs, ARRAY_SIZE(sensor_brightness_pos3_regs));
1526			break;
1527		case 4:
1528			ret = sensor_write_array(sd, sensor_brightness_pos4_regs, ARRAY_SIZE(sensor_brightness_pos4_regs));
1529			break;
1530		default:
1531			return -EINVAL;
1532	}
1533	
1534	if (ret < 0) {
1535		csi_dev_err("sensor_write_array err at sensor_s_brightness!\n");
1536		return ret;
1537	}
1538	msleep(10);
1539	info->brightness = value;
1540	return 0;
1541}
1542
1543static int sensor_g_contrast(struct v4l2_subdev *sd, __s32 *value)
1544{
1545	struct sensor_info *info = to_state(sd);
1546	
1547	*value = info->contrast;
1548	return 0;
1549}
1550
1551static int sensor_s_contrast(struct v4l2_subdev *sd, int value)
1552{
1553	int ret;
1554	struct sensor_info *info = to_state(sd);
1555	
1556	switch (value) {
1557		case -4:
1558		  ret = sensor_write_array(sd, sensor_contrast_neg4_regs, ARRAY_SIZE(sensor_contrast_neg4_regs));
1559			break;
1560		case -3:
1561			ret = sensor_write_array(sd, sensor_contrast_neg3_regs, ARRAY_SIZE(sensor_contrast_neg3_regs));
1562			break;
1563		case -2:
1564			ret = sensor_write_array(sd, sensor_contrast_neg2_regs, ARRAY_SIZE(sensor_contrast_neg2_regs));
1565			break;   
1566		case -1:
1567			ret = sensor_write_array(sd, sensor_contrast_neg1_regs, ARRAY_SIZE(sensor_contrast_neg1_regs));
1568			break;
1569		case 0:   
1570			ret = sensor_write_array(sd, sensor_contrast_zero_regs, ARRAY_SIZE(sensor_contrast_zero_regs));
1571			break;
1572		case 1:
1573			ret = sensor_write_array(sd, sensor_contrast_pos1_regs, ARRAY_SIZE(sensor_contrast_pos1_regs));
1574			break;
1575		case 2:
1576			ret = sensor_write_array(sd, sensor_contrast_pos2_regs, ARRAY_SIZE(sensor_contrast_pos2_regs));
1577			break;	
1578		case 3:
1579			ret = sensor_write_array(sd, sensor_contrast_pos3_regs, ARRAY_SIZE(sensor_contrast_pos3_regs));
1580			break;
1581		case 4:
1582			ret = sensor_write_array(sd, sensor_contrast_pos4_regs, ARRAY_SIZE(sensor_contrast_pos4_regs));
1583			break;
1584		default:
1585			return -EINVAL;
1586	}
1587	
1588	if (ret < 0) {
1589		csi_dev_err("sensor_write_array err at sensor_s_contrast!\n");
1590		return ret;
1591	}
1592	msleep(10);
1593	info->contrast = value;
1594	return 0;
1595}
1596
1597static int sensor_g_saturation(struct v4l2_subdev *sd, __s32 *value)
1598{
1599	struct sensor_info *info = to_state(sd);
1600	
1601	*value = info->saturation;
1602	return 0;
1603}
1604
1605static int sensor_s_saturation(struct v4l2_subdev *sd, int value)
1606{
1607	int ret;
1608	struct sensor_info *info = to_state(sd);
1609	
1610	switch (value) {
1611		case -4:
1612		  ret = sensor_write_array(sd, sensor_saturation_neg4_regs, ARRAY_SIZE(sensor_saturation_neg4_regs));
1613			break;
1614		case -3:
1615			ret = sensor_write_array(sd, sensor_saturation_neg3_regs, ARRAY_SIZE(sensor_saturation_neg3_regs));
1616			break;
1617		case -2:
1618			ret = sensor_write_array(sd, sensor_saturation_neg2_regs, ARRAY_SIZE(sensor_saturation_neg2_regs));
1619			break;   
1620		case -1:
1621			ret = sensor_write_array(sd, sensor_saturation_neg1_regs, ARRAY_SIZE(sensor_saturation_neg1_regs));
1622			break;
1623		case 0:   
1624			ret = sensor_write_array(sd, sensor_saturation_zero_regs, ARRAY_SIZE(sensor_saturation_zero_regs));
1625			break;
1626		case 1:
1627			ret = sensor_write_array(sd, sensor_saturation_pos1_regs, ARRAY_SIZE(sensor_saturation_pos1_regs));
1628			break;
1629		case 2:
1630			ret = sensor_write_array(sd, sensor_saturation_pos2_regs, ARRAY_SIZE(sensor_saturation_pos2_regs));
1631			break;	
1632		case 3:
1633			ret = sensor_write_array(sd, sensor_saturation_pos3_regs, ARRAY_SIZE(sensor_saturation_pos3_regs));
1634			break;
1635		case 4:
1636			ret = sensor_write_array(sd, sensor_saturation_pos4_regs, ARRAY_SIZE(sensor_saturation_pos4_regs));
1637			break;
1638		default:
1639			return -EINVAL;
1640	}
1641	
1642	if (ret < 0) {
1643		csi_dev_err("sensor_write_array err at sensor_s_saturation!\n");
1644		return ret;
1645	}
1646	msleep(10);
1647	info->saturation = value;
1648	return 0;
1649}
1650
1651static int sensor_g_exp(struct v4l2_subdev *sd, __s32 *value)
1652{
1653	struct sensor_info *info = to_state(sd);
1654	
1655	*value = info->exp;
1656	return 0;
1657}
1658
1659static int sensor_s_exp(struct v4l2_subdev *sd, int value)
1660{
1661	int ret;
1662	struct sensor_info *info = to_state(sd);
1663	
1664	switch (value) {
1665		case -4:
1666		  ret = sensor_write_array(sd, sensor_ev_neg4_regs, ARRAY_SIZE(sensor_ev_neg4_regs));
1667			break;
1668		case -3:
1669			ret = sensor_write_array(sd, sensor_ev_neg3_regs, ARRAY_SIZE(sensor_ev_neg3_regs));
1670			break;
1671		case -2:
1672			ret = sensor_write_array(sd, sensor_ev_neg2_regs, ARRAY_SIZE(sensor_ev_neg2_regs));
1673			break;   
1674		case -1:
1675			ret = sensor_write_array(sd, sensor_ev_neg1_regs, ARRAY_SIZE(sensor_ev_neg1_regs));
1676			break;
1677		case 0:   
1678			ret = sensor_write_array(sd, sensor_ev_zero_regs, ARRAY_SIZE(sensor_ev_zero_regs));
1679			break;
1680		case 1:
1681			ret = sensor_write_array(sd, sensor_ev_pos1_regs, ARRAY_SIZE(sensor_ev_pos1_regs));
1682			break;
1683		case 2:
1684			ret = sensor_write_array(sd, sensor_ev_pos2_regs, ARRAY_SIZE(sensor_ev_pos2_regs));
1685			break;	
1686		case 3:
1687			ret = sensor_write_array(sd, sensor_ev_pos3_regs, ARRAY_SIZE(sensor_ev_pos3_regs));
1688			break;
1689		case 4:
1690			ret = sensor_write_array(sd, sensor_ev_pos4_regs, ARRAY_SIZE(sensor_ev_pos4_regs));
1691			break;
1692		default:
1693			return -EINVAL;
1694	}
1695	
1696	if (ret < 0) {
1697		csi_dev_err("sensor_write_array err at sensor_s_exp!\n");
1698		return ret;
1699	}
1700	msleep(10);
1701	info->exp = value;
1702	return 0;
1703}
1704
1705static int sensor_g_wb(struct v4l2_subdev *sd, int *value)
1706{
1707	struct sensor_info *info = to_state(sd);
1708	enum v4l2_whiteblance *wb_type = (enum v4l2_whiteblance*)value;
1709	
1710	*wb_type = info->wb;
1711	
1712	return 0;
1713}
1714
1715static int sensor_s_wb(struct v4l2_subdev *sd,
1716		enum v4l2_whiteblance value)
1717{
1718	int ret;
1719	struct sensor_info *info = to_state(sd);
1720	
1721	if (value == V4L2_WB_AUTO) {
1722		ret = sensor_s_autowb(sd, 1);
1723		return ret;
1724	} 
1725	else {
1726		ret = sensor_s_autowb(sd, 0);
1727		if(ret < 0) {
1728			csi_dev_err("sensor_s_autowb error, return %x!\n",ret);
1729			return ret;
1730		}
1731		
1732		switch (value) {
1733			case V4L2_WB_CLOUD:
1734			  ret = sensor_write_array(sd, sensor_wb_cloud_regs, ARRAY_SIZE(sensor_wb_cloud_regs));
1735				break;
1736			case V4L2_WB_DAYLIGHT:
1737				ret = sensor_write_array(sd, sensor_wb_daylight_regs, ARRAY_SIZE(sensor_wb_daylight_regs));
1738				break;
1739			case V4L2_WB_INCANDESCENCE:
1740				ret = sensor_write_array(sd, sensor_wb_incandescence_regs, ARRAY_SIZE(sensor_wb_incandescence_regs));
1741				break;    
1742			case V4L2_WB_FLUORESCENT:
1743				ret = sensor_write_array(sd, sensor_wb_fluorescent_regs, ARRAY_SIZE(sensor_wb_fluorescent_regs));
1744				break;
1745			case V4L2_WB_TUNGSTEN:   
1746				ret = sensor_write_array(sd, sensor_wb_tungsten_regs, ARRAY_SIZE(sensor_wb_tungsten_regs));
1747				break;
1748			default:
1749				return -EINVAL;
1750		} 
1751	}
1752	
1753	if (ret < 0) {
1754		csi_dev_err("sensor_s_wb error, return %x!\n",ret);
1755		return ret;
1756	}
1757	msleep(10);
1758	info->wb = value;
1759	return 0;
1760}
1761
1762static int sensor_g_colorfx(struct v4l2_subdev *sd,
1763		__s32 *value)
1764{
1765	struct sensor_info *info = to_state(sd);
1766	enum v4l2_colorfx *clrfx_type = (enum v4l2_colorfx*)value;
1767	
1768	*clrfx_type = info->clrfx;
1769	return 0;
1770}
1771
1772static int sensor_s_colorfx(struct v4l2_subdev *sd,
1773		enum v4l2_colorfx value)
1774{
1775	int ret;
1776	struct sensor_info *info = to_state(sd);
1777	
1778	switch (value) {
1779	case V4L2_COLORFX_NONE:
1780	  ret = sensor_write_array(sd, sensor_colorfx_none_regs, ARRAY_SIZE(sensor_colorfx_none_regs));
1781		break;
1782	case V4L2_COLORFX_BW:
1783		ret = sensor_write_array(sd, sensor_colorfx_bw_regs, ARRAY_SIZE(sensor_colorfx_bw_regs));
1784		break;  
1785	case V4L2_COLORFX_SEPIA:
1786		ret = sensor_write_array(sd, sensor_colorfx_sepia_regs, ARRAY_SIZE(sensor_colorfx_sepia_regs));
1787		break;   
1788	case V4L2_COLORFX_NEGATIVE:
1789		ret = sensor_write_array(sd, sensor_colorfx_negative_regs, ARRAY_SIZE(sensor_colorfx_negative_regs));
1790		break;
1791	case V4L2_COLORFX_EMBOSS:   
1792		ret = sensor_write_array(sd, sensor_colorfx_emboss_regs, ARRAY_SIZE(sensor_colorfx_emboss_regs));
1793		break;
1794	case V4L2_COLORFX_SKETCH:     
1795		ret = sensor_write_array(sd, sensor_colorfx_sketch_regs, ARRAY_SIZE(sensor_colorfx_sketch_regs));
1796		break;
1797	case V4L2_COLORFX_SKY_BLUE:
1798		ret = sensor_write_array(sd, sensor_colorfx_sky_blue_regs, ARRAY_SIZE(sensor_colorfx_sky_blue_regs));
1799		break;
1800	case V4L2_COLORFX_GRASS_GREEN:
1801		ret = sensor_write_array(sd, sensor_colorfx_grass_green_regs, ARRAY_SIZE(sensor_colorfx_grass_green_regs));
1802		break;
1803	case V4L2_COLORFX_SKIN_WHITEN:
1804		ret = sensor_write_array(sd, sensor_colorfx_skin_whiten_regs, ARRAY_SIZE(sensor_colorfx_skin_whiten_regs));
1805		break;
1806	case V4L2_COLORFX_VIVID:
1807		ret = sensor_write_array(sd, sensor_colorfx_vivid_regs, ARRAY_SIZE(sensor_colorfx_vivid_regs));
1808		break;
1809	default:
1810		return -EINVAL;
1811	}
1812	
1813	if (ret < 0) {
1814		csi_dev_err("sensor_s_colorfx error, return %x!\n",ret);
1815		return ret;
1816	}
1817	msleep(10);
1818	info->clrfx = value;
1819	return 0;
1820}
1821
1822static int sensor_g_flash_mode(struct v4l2_subdev *sd,
1823    __s32 *value)
1824{
1825	struct sensor_info *info = to_state(sd);
1826	enum v4l2_flash_mode *flash_mode = (enum v4l2_flash_mode*)value;
1827	
1828	*flash_mode = info->flash_mode;
1829	return 0;
1830}
1831
1832static int sensor_s_flash_mode(struct v4l2_subdev *sd,
1833    enum v4l2_flash_mode value)
1834{
1835	struct sensor_info *info = to_state(sd);
1836	struct csi_dev *dev=(struct csi_dev *)dev_get_drvdata(sd->v4l2_dev->dev);
1837	char csi_flash_str[32];
1838	int flash_on,flash_off;
1839	
1840	if(info->ccm_info->iocfg == 0) {
1841		strcpy(csi_flash_str,"csi_flash");
1842	} else if(info->ccm_info->iocfg == 1) {
1843	  strcpy(csi_flash_str,"csi_flash_b");
1844	}
1845	
1846	flash_on = (dev->flash_pol!=0)?1:0;
1847	flash_off = (flash_on==1)?0:1;
1848	
1849	switch (value) {
1850	case V4L2_FLASH_MODE_OFF:
1851	  gpio_write_one_pin_value(dev->csi_pin_hd,flash_off,csi_flash_str);
1852		break;
1853	case V4L2_FLASH_MODE_AUTO:
1854		return -EINVAL;
1855		break;  
1856	case V4L2_FLASH_MODE_ON:
1857		gpio_write_one_pin_value(dev->csi_pin_hd,flash_on,csi_flash_str);
1858		break;   
1859	case V4L2_FLASH_MODE_TORCH:
1860		return -EINVAL;
1861		break;
1862	case V4L2_FLASH_MODE_RED_EYE:   
1863		return -EINVAL;
1864		break;
1865	default:
1866		return -EINVAL;
1867	}
1868	
1869	info->flash_mode = value;
1870	return 0;
1871}
1872
1873static int sensor_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1874{
1875	switch (ctrl->id) {
1876	case V4L2_CID_BRIGHTNESS:
1877		return sensor_g_brightness(sd, &ctrl->value);
1878	case V4L2_CID_CONTRAST:
1879		return sensor_g_contrast(sd, &ctrl->value);
1880	case V4L2_CID_SATURATION:
1881		return sensor_g_saturation(sd, &ctrl->value);
1882	case V4L2_CID_HUE:
1883		return sensor_g_hue(sd, &ctrl->value);	
1884	case V4L2_CID_VFLIP:
1885		return sensor_g_vflip(sd, &ctrl->value);
1886	case V4L2_CID_HFLIP:
1887		return sensor_g_hflip(sd, &ctrl->value);
1888	case V4L2_CID_GAIN:
1889		return sensor_g_gain(sd, &ctrl->value);
1890	case V4L2_CID_AUTOGAIN:
1891		return sensor_g_autogain(sd, &ctrl->value);
1892	case V4L2_CID_EXPOSURE:
1893		return sensor_g_exp(sd, &ctrl->value);
1894	case V4L2_CID_EXPOSURE_AUTO:
1895		return sensor_g_autoexp(sd, &ctrl->value);
1896	case V4L2_CID_DO_WHITE_BALANCE:
1897		return sensor_g_wb(sd, &ctrl->value);
1898	case V4L2_CID_AUTO_WHITE_BALANCE:
1899		return sensor_g_autowb(sd, &ctrl->value);
1900	case V4L2_CID_COLORFX:
1901		return sensor_g_colorfx(sd,	&ctrl->value);
1902	case V4L2_CID_CAMERA_FLASH_MODE:
1903		return sensor_g_flash_mode(sd, &ctrl->value);
1904	}
1905	return -EINVAL;
1906}
1907
1908static int sensor_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1909{
1910	switch (ctrl->id) {
1911	case V4L2_CID_BRIGHTNESS:
1912		return sensor_s_brightness(sd, ctrl->value);
1913	case V4L2_CID_CONTRAST:
1914		return sensor_s_contrast(sd, ctrl->value);
1915	case V4L2_CID_SATURATION:
1916		return sensor_s_saturation(sd, ctrl->value);
1917	case V4L2_CID_HUE:
1918		return sensor_s_hue(sd, ctrl->value);		
1919	case V4L2_CID_VFLIP:
1920		return sensor_s_vflip(sd, ctrl->value);
1921	case V4L2_CID_HFLIP:
1922		return sensor_s_hflip(sd, ctrl->value);
1923	case V4L2_CID_GAIN:
1924		return sensor_s_gain(sd, ctrl->value);
1925	case V4L2_CID_AUTOGAIN:
1926		return sensor_s_autogain(sd, ctrl->value);
1927	case V4L2_CID_EXPOSURE:
1928		return sensor_s_exp(sd, ctrl->value);
1929	case V4L2_CID_EXPOSURE_AUTO:
1930		return sensor_s_autoexp(sd,
1931				(enum v4l2_exposure_auto_type) ctrl->value);
1932	case V4L2_CID_DO_WHITE_BALANCE:
1933		return sensor_s_wb(sd,
1934				(enum v4l2_whiteblance) ctrl->value);	
1935	case V4L2_CID_AUTO_WHITE_BALANCE:
1936		return sensor_s_autowb(sd, ctrl->value);
1937	case V4L2_CID_COLORFX:
1938		return sensor_s_colorfx(sd,
1939				(enum v4l2_colorfx) ctrl->value);
1940	case V4L2_CID_CAMERA_FLASH_MODE:
1941	  return sensor_s_flash_mode(sd,
1942	      (enum v4l2_flash_mode) ctrl->value);
1943	}
1944	return -EINVAL;
1945}
1946
1947static int sensor_g_chip_ident(struct v4l2_subdev *sd,
1948		struct v4l2_dbg_chip_ident *chip)
1949{
1950	struct i2c_client *client = v4l2_get_subdevdata(sd);
1951
1952	return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SENSOR, 0);
1953}
1954
1955
1956/* ----------------------------------------------------------------------- */
1957
1958static const struct v4l2_subdev_core_ops sensor_core_ops = {
1959	.g_chip_ident = sensor_g_chip_ident,
1960	.g_ctrl = sensor_g_ctrl,
1961	.s_ctrl = sensor_s_ctrl,
1962	.queryctrl = sensor_queryctrl,
1963	.reset = sensor_reset,
1964	.init = sensor_init,
1965	.s_power = sensor_power,
1966	.ioctl = sensor_ioctl,
1967};
1968
1969static const struct v4l2_subdev_video_ops sensor_video_ops = {
1970	.enum_mbus_fmt = sensor_enum_fmt,//linux-3.0
1971	.try_mbus_fmt = sensor_try_fmt,//linux-3.0
1972	.s_mbus_fmt = sensor_s_fmt,//linux-3.0
1973	.s_parm = sensor_s_parm,//linux-3.0
1974	.g_parm = sensor_g_parm,//linux-3.0
1975};
1976
1977static const struct v4l2_subdev_ops sensor

Large files files are truncated, but you can click here to view the full file