Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for mt9p017 camera sensor (thanks genokolar)

  • Loading branch information...
commit 9cec33c8d10821ed81505a770f08e069ae306979 1 parent d5cc68b
omegamoon authored
Showing with 434 additions and 115 deletions.
  1. +297 −0 drivers/media/video/msm/mt9p017.c
  2. +137 −115 drivers/media/video/msm/mt9p017_reg.c
297 drivers/media/video/msm/mt9p017.c
View
@@ -389,6 +389,7 @@ static int32_t mt9p017_lens_shading_enable(uint8_t is_enable)
return rc;
}
+#ifndef MT9P017_OTP_SUPPORT
static int32_t mt9p017_set_lc(void)
{
int32_t rc;
@@ -398,6 +399,302 @@ static int32_t mt9p017_set_lc(void)
return rc;
}
+#else
+#define TRUE 1
+#define FALSE 0
+// for reading lens shading from eeprom
+#define LC_TABLE_SIZE 106//equal to the size of mt9p017_lc_tbl - 1.
+static const unsigned short mt9p017_eeprom_table[LC_TABLE_SIZE] = {
+ 0x3800,
+ 0x3802,
+ 0x3804,
+ 0x3806,
+ 0x3808,
+ 0x380A,
+ 0x380C,
+ 0x380E,
+ 0x3810,
+ 0x3812,
+ 0x3814,
+ 0x3816,
+ 0x3818,
+ 0x381A,
+ 0x381C,
+ 0x381E,
+ 0x3820,
+ 0x3822,
+ 0x3824,
+ 0x3826,
+ 0x3828,
+ 0x382A,
+ 0x382C,
+ 0x382E,
+ 0x3830,
+ 0x3832,
+ 0x3834,
+ 0x3836,
+ 0x3838,
+ 0x383A,
+ 0x383C,
+ 0x383E,
+ 0x3840,
+ 0x3842,
+ 0x3844,
+ 0x3846,
+ 0x3848,
+ 0x384A,
+ 0x384C,
+ 0x384E,
+ 0x3850,
+ 0x3852,
+ 0x3854,
+ 0x3856,
+ 0x3858,
+ 0x385A,
+ 0x385C,
+ 0x385E,
+ 0x3860,
+ 0x3862,
+ 0x3864,
+ 0x3866,
+ 0x3868,
+ 0x386A,
+ 0x386C,
+ 0x386E,
+ 0x3870,
+ 0x3872,
+ 0x3874,
+ 0x3876,
+ 0x3878,
+ 0x387A,
+ 0x387C,
+ 0x387E,
+ 0x3880,
+ 0x3882,
+ 0x3884,
+ 0x3886,
+ 0x3888,
+ 0x388A,
+ 0x388C,
+ 0x388E,
+ 0x3890,
+ 0x3892,
+ 0x3894,//===================
+ 0x3898,//===================
+ 0x389A,
+ 0x389C,
+ 0x389E,
+ 0x38A0,
+ 0x38A2,
+ 0x38A4,
+ 0x38A6,
+ 0x38A8,
+ 0x38AA,
+ 0x38AC,//===================
+ 0x38B0,//===================
+ 0x38B2,
+ 0x38B4,
+ 0x38B6,
+ 0x38B8,
+ 0x38BA,
+ 0x38BC,
+ 0x38BE,
+ 0x38C0,
+ 0x38C2,
+ 0x38C4,
+ 0x38C6,
+ 0x38C8,
+ 0x38CA,
+ 0x38CC,
+ 0x38CE,
+ 0x38D0,
+ 0x38D2,
+ 0x38D4,
+ 0x38D6,
+};
+static int32_t mt9p017_set_lc(void)
+{
+ int32_t rc;
+ bool bSuccess = FALSE;
+ bool bRWFinished = FALSE;
+ bool bRWSuccess = FALSE;
+ unsigned short j, i;
+ unsigned short OTPCheckValue = 0;
+ unsigned short DataStartType = 0x3100;
+ unsigned short mt9p017_reg_data[LC_TABLE_SIZE];
+
+ memset(mt9p017_reg_data, 0, sizeof(unsigned short)*LC_TABLE_SIZE);
+
+ CDBG("%s: Before read dataStartType = 0x%x\n", __func__, DataStartType);
+ while(!bSuccess)
+ {
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x301A, 0x0610);//disable Stream
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x3134, 0xCD95);//timing parameters for OTPM read
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x304C, DataStartType);//0x304C [15:8] for record type
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x304A, 0x0200);//Only Read Single Record at a time
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x304A, 0x0210);//auto Read Start
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ bRWFinished = FALSE;
+ bRWSuccess = FALSE;
+
+ for(j = 0; j<10; j++)//POLL Register 0x304A [6:5] = 11 //auto read success
+ {
+ msleep(10);
+ rc = mt9p017_i2c_read_w(mt9p017_client->addr, 0x304A, &OTPCheckValue);//auto Read Start
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ CDBG("%s:read count=%d, CheckValue=0x%x", __func__, j, OTPCheckValue);
+ if(0xFFFF == (OTPCheckValue |0xFFDF))//finish
+ {
+ bRWFinished = TRUE;
+ if(0xFFFF == (OTPCheckValue |0xFFBF))//success
+ {
+ bRWSuccess = TRUE;
+ }
+ break;
+ }
+ }
+ CDBG("%s: read DataStartType = 0x%x, bRWFinished = %d, bRWSuccess = %d", __func__,DataStartType, bRWFinished, bRWSuccess);
+
+ if(!bRWFinished)
+ {
+ CDBG("%s: read DataStartType Fail!", __func__);
+ goto OTPERR;
+ }
+ else
+ {
+ if(bRWSuccess)
+ {
+ switch(DataStartType)
+ {
+ case 0x3000:
+ case 0x3200:
+ bSuccess = TRUE;
+ break;
+
+ case 0x3100:
+ bSuccess = FALSE;
+ DataStartType = 0x3000;
+ break;
+
+ default:
+ break;
+ }
+ }
+ else
+ {
+ switch(DataStartType)
+ {
+ case 0x3200:
+ {
+ bSuccess = FALSE;
+ CDBG("%s: read DataStartType Error Times Twice!", __func__);
+ goto OTPERR;
+ }
+ break;
+ case 0x3100:
+ {
+ bSuccess = FALSE;
+ DataStartType = 0x3200;
+ }
+ break;
+ case 0x3000:
+ {
+ bSuccess = TRUE;
+ DataStartType = 0x3100;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ CDBG("%s: after read DataStartType = 0x%x", __func__,DataStartType);
+
+ //read data
+ bSuccess = FALSE;
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x301A, 0x0610);//disable Stream
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x3134, 0xCD95);//timing parameters for OTPM read
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x304C, DataStartType);//0x304C [15:8] for record type
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x304A, 0x0200);//Only Read Single Record at a time
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x304A, 0x0210);//auto Read Start
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ for(j = 0; j<10; j++)//POLL Register 0x304A [6:5] = 11 //auto read success
+ {
+ msleep(10);
+ rc = mt9p017_i2c_read_w(mt9p017_client->addr, 0x304A, &OTPCheckValue);//auto Read Start
+ //if (rc < 0) goto set_eeprom_lc_fail;
+
+ CDBG("%s:read count=%d, CheckValue=0x%x", __func__, j, OTPCheckValue);
+ if(0xFFFF == (OTPCheckValue |0xFFDF))//finish
+ {
+ bRWFinished = TRUE;
+ if(0xFFFF == (OTPCheckValue |0xFFBF))//success
+ {
+ bRWSuccess = TRUE;
+ }
+ break;
+ }
+ }
+
+ CDBG("%s:: read DataStartType(step2) = 0x%x, bRWFinished = %d, bRWSuccess = %d", __func__,DataStartType, bRWFinished, bRWSuccess);
+ if(!bRWFinished ||!bRWSuccess)
+ {
+ CDBG("%s: read DataStartType Error!Failed!", __func__);
+ goto OTPERR;
+ }
+ else
+ {
+ CDBG("%s:read 0x3800 to 0x39FE for the written data", __func__);
+ for(i = 0; i<LC_TABLE_SIZE; i++)//READ 0x3800 to 0x39FE for the written data
+ {
+ rc = mt9p017_i2c_read_w(mt9p017_client->addr, mt9p017_eeprom_table[i], &OTPCheckValue);
+ mt9p017_reg_data[i] = OTPCheckValue;
+ CDBG("%s:read:mt9p017_eeprom_table[%d]=0x%x,mt9p017_reg_data[%d]=0x%x",__func__,i,mt9p017_eeprom_table[i], i,mt9p017_reg_data[i]);
+ }
+
+ bSuccess = TRUE;
+ }
+OTPERR:
+ if (bSuccess)
+ {
+ //write lens shading to sensor registers
+ for(i=0;i<LC_TABLE_SIZE;i++)
+ {
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, (mt9p017_regs.rftbl + i)->waddr, mt9p017_reg_data[i]);
+ }
+ rc = mt9p017_i2c_write_w(mt9p017_client->addr, 0x3780, 0x8000);
+
+ CDBG("%s: OTP Check OK!!! rc = %d", __func__,rc);
+ }
+ else
+ {
+ CDBG("%s: OTP Check Fail Write Fail!", __func__);
+ rc = mt9p017_i2c_write_w_table(mt9p017_regs.rftbl,mt9p017_regs.rftbl_size);
+ CDBG("%s: OTP Check Fail rc = %d", __func__,rc);
+ }
+ return rc;
+}
+#endif
static int32_t mt9p017_load_pixel_timing(void)
{
252 drivers/media/video/msm/mt9p017_reg.c
View
@@ -49,35 +49,35 @@ struct reg_struct const mt9p017_reg_pat[2] =
0x0111,
/* x_addr_start REG=0x3004 */
- 8,
+ 0,
/* x_addr_end REG=0x3008 */
- 2597,
+ 2605,
/* y_addr_start REG=0x3002 */
- 8,
+ 0,
/* y_addr_end REG=0x3006 */
- 1949,
+ 1957,
/* read_mode REG=0x3040
* Preview 2x2 skipping */
0xC4C3, /* 0x046C 2x2 binning, 14 and 15 bits for flip and mirror */
/* x_output_size REG=0x034C */
- 1296,
+ 1304,
/* y_output_size REG=0x034E */
- 972,
+ 980,
/* line_length_pck REG=0x300C */
3178,
/* frame_length_lines REG=0x300A */
- 1045,
+ 1053,
/* coarse_integration_time REG=0x3012 */
- 1044,
+ 1052,
/* fine_integration_time REG=0x3014 */
2342,
@@ -266,124 +266,146 @@ struct mt9p017_i2c_reg_conf const mt9p017_rolloff_tbl[] =
{0x3780, 0x8000},
};
+/* change the reg from rev3 to rev4 */
struct mt9p017_i2c_reg_conf const mt9p017_ptiming_tbl[] =
{
- {0x3e00, 0x0429},
- {0x3e02, 0xFFFF},
- {0x3e04, 0xFFFF},
- {0x3e06, 0xFFFF},
- {0x3e08, 0x8080},
- {0x3e0a, 0x7180},
- {0x3e0c, 0x7200},
- {0x3e0e, 0x4353},
- {0x3e10, 0x1300},
- {0x3e12, 0x8710},
- {0x3e14, 0x6085},
- {0x3e16, 0x40A2},
- {0x3e18, 0x0018},
- {0x3e1a, 0x9057},
- {0x3e1c, 0xA049},
- {0x3e1e, 0xA649},
- {0x3e20, 0x8846},
- {0x3e22, 0x8142},
- {0x3e24, 0x0082},
- {0x3e26, 0x8B49},
- {0x3e28, 0x9C49},
- {0x3e2a, 0x8E47},
- {0x3e2c, 0x884D},
- {0x3e2e, 0x8010},
- {0x3e30, 0x0C04},
- {0x3e32, 0x0691},
- {0x3e34, 0x100C},
- {0x3e36, 0x8C4D},
- {0x3e38, 0xB94A},
- {0x3e3a, 0x4283},
- {0x3e3c, 0x4181},
- {0x3e3e, 0x4BB2},
- {0x3e40, 0x4B80},
- {0x3e42, 0x5680},
- {0x3e44, 0x001C},
- {0x3e46, 0x8110},
- {0x3e48, 0xE080},
- {0x3e4a, 0x1300},
- {0x3e4c, 0x1C00},
- {0x3e4e, 0x827C},
- {0x3e50, 0x0970},
- {0x3e52, 0x8082},
- {0x3e54, 0x7281},
- {0x3e56, 0x4C40},
- {0x3e58, 0x8E4D},
- {0x3e5a, 0x8110},
- {0x3e5c, 0x0CAF},
- {0x3e5e, 0x4D80},
- {0x3e60, 0x100C},
- {0x3e62, 0x8440},
- {0x3e64, 0x4C81},
- {0x3e66, 0x7C53},
- {0x3e68, 0x7000},
- {0x3e6a, 0x0000},
- {0x3e6c, 0x0000},
- {0x3e6e, 0x0000},
- {0x3e70, 0x0000},
- {0x3e72, 0x0000},
- {0x3e74, 0x0000},
- {0x3e76, 0x0000},
- {0x3e78, 0x7000},
- {0x3e7a, 0x0000},
- {0x3e7c, 0x0000},
- {0x3e7e, 0x0000},
- {0x3e80, 0x0000},
- {0x3e82, 0x0000},
- {0x3e84, 0x0000},
- {0x3e86, 0x0000},
- {0x3e88, 0x0000},
- {0x3e8a, 0x0000},
- {0x3e8c, 0x0000},
- {0x3e8e, 0x0000},
- {0x3e90, 0x0000},
- {0x3e92, 0x0000},
- {0x3e94, 0x0000},
- {0x3e96, 0x0000},
- {0x3e98, 0x0000},
- {0x3e9a, 0x0000},
- {0x3e9c, 0x0000},
- {0x3e9e, 0x0000},
- {0x3ea0, 0x0000},
- {0x3ea2, 0x0000},
- {0x3ea4, 0x0000},
- {0x3ea6, 0x0000},
- {0x3ea8, 0x0000},
- {0x3eaa, 0x0000},
- {0x3eac, 0x0000},
- {0x3eae, 0x0000},
- {0x3eb0, 0x0000},
- {0x3eb2, 0x0000},
- {0x3eb4, 0x0000},
- {0x3eb6, 0x0000},
- {0x3eb8, 0x0000},
- {0x3eba, 0x0000},
- {0x3ebc, 0x0000},
- {0x3ebe, 0x0000},
- {0x3ec0, 0x0000},
- {0x3ec2, 0x0000},
- {0x3ec4, 0x0000},
- {0x3ec6, 0x0000},
- {0x3ec8, 0x0000},
- {0x3eca, 0x0000},
+ {0x3E00, 0x042F},
+ {0x3E02, 0xFFFF},
+ {0x3E04, 0xFFFF},
+ {0x3E06, 0xFFFF},
+ {0x3E08, 0x8071},
+ {0x3E0A, 0x7281},
+ {0x3E0C, 0x4011},
+ {0x3E0E, 0x8010},
+ {0x3E10, 0x60A5},
+ {0x3E12, 0x4080},
+ {0x3E14, 0x4180},
+ {0x3E16, 0x0018},
+ {0x3E18, 0x46B7},
+ {0x3E1A, 0x4994},
+ {0x3E1C, 0x4997},
+ {0x3E1E, 0x4682},
+ {0x3E20, 0x0018},
+ {0x3E22, 0x4241},
+ {0x3E24, 0x8000},
+ {0x3E26, 0x1880},
+ {0x3E28, 0x4785},
+ {0x3E2A, 0x4992},
+ {0x3E2C, 0x4997},
+ {0x3E2E, 0x4780},
+ {0x3E30, 0x4D80},
+ {0x3E32, 0x100C},
+ {0x3E34, 0x8000},
+ {0x3E36, 0x184A},
+ {0x3E38, 0x8042},
+ {0x3E3A, 0x001A},
+ {0x3E3C, 0x9610},
+ {0x3E3E, 0x0C80},
+ {0x3E40, 0x4DC6},
+ {0x3E42, 0x4A80},
+ {0x3E44, 0x0018},
+ {0x3E46, 0x8042},
+ {0x3E48, 0x8041},
+ {0x3E4A, 0x0018},
+ {0x3E4C, 0x804B},
+ {0x3E4E, 0xB74B},
+ {0x3E50, 0x8010},
+ {0x3E52, 0x6056},
+ {0x3E54, 0x001C},
+ {0x3E56, 0x8211},
+ {0x3E58, 0x8056},
+ {0x3E5A, 0x827C},
+ {0x3E5C, 0x0970},
+ {0x3E5E, 0x8082},
+ {0x3E60, 0x7281},
+ {0x3E62, 0x4C40},
+ {0x3E64, 0x8E4D},
+ {0x3E66, 0x8110},
+ {0x3E68, 0x0CAF},
+ {0x3E6A, 0x4D80},
+ {0x3E6C, 0x100C},
+ {0x3E6E, 0x8440},
+ {0x3E70, 0x4C81},
+ {0x3E72, 0x7C5F},
+ {0x3E74, 0x7000},
+ {0x3E76, 0x0000},
+ {0x3E78, 0x0000},
+ {0x3E7A, 0x0000},
+ {0x3E7C, 0x0000},
+ {0x3E7E, 0x0000},
+ {0x3E80, 0x0000},
+ {0x3E82, 0x0000},
+ {0x3E84, 0x0000},
+ {0x3E86, 0x0000},
+ {0x3E88, 0x0000},
+ {0x3E8A, 0x0000},
+ {0x3E8C, 0x0000},
+ {0x3E8E, 0x0000},
+ {0x3E90, 0x0000},
+ {0x3E92, 0x0000},
+ {0x3E94, 0x0000},
+ {0x3E96, 0x0000},
+ {0x3E98, 0x0000},
+ {0x3E9A, 0x0000},
+ {0x3E9C, 0x0000},
+ {0x3E9E, 0x0000},
+ {0x3EA0, 0x0000},
+ {0x3EA2, 0x0000},
+ {0x3EA4, 0x0000},
+ {0x3EA6, 0x0000},
+ {0x3EA8, 0x0000},
+ {0x3EAA, 0x0000},
+ {0x3EAC, 0x0000},
+ {0x3EAE, 0x0000},
+ {0x3EB0, 0x0000},
+ {0x3EB2, 0x0000},
+ {0x3EB4, 0x0000},
+ {0x3EB6, 0x0000},
+ {0x3EB8, 0x0000},
+ {0x3EBA, 0x0000},
+ {0x3EBC, 0x0000},
+ {0x3EBE, 0x0000},
+ {0x3EC0, 0x0000},
+ {0x3EC2, 0x0000},
+ {0x3EC4, 0x0000},
+ {0x3EC6, 0x0000},
+ {0x3EC8, 0x0000},
+ {0x3ECA, 0x0000},
+ {0x3170, 0x2150},
+ {0x317A, 0x0150},
+ {0x3ECC, 0x2200},
+ {0x3174, 0x0000},
+ {0x3176, 0X0000},
+ {0x31B0, 0x00C4},
+ {0x31B2, 0x0064},
+ {0x31B4, 0x0E77},
+ {0x31B6, 0x0D24},
+ {0x31B8, 0x020E},
+ {0x31BA, 0x0710},
+ {0x31BC, 0x2A0D},
+ {0x31BE, 0xC007},
};
struct mt9p017_i2c_reg_conf const mt9p017_recommend_settings[] =
{
- {0x316A, 0x8200},
+ {0x3100, 0x0000},
+ {0x316A, 0x8400},
+ {0x316C, 0x8400},
+ {0x316E, 0x8400},
+ {0x3EFA, 0x1A1F},
{0x3ED2, 0xD965},
{0x3ED8, 0x7F1B},
{0x3EDA, 0xAF11},
- {0x3EDE, 0xCA00},
- {0x3EE2, 0x0068},
+ {0x3EE2, 0x0060},
{0x3EF2, 0xD965},
{0x3EF8, 0x797F},
- {0x3EFC, 0xAFEF},
- {0x3EFE, 0x1308},
+ {0x3EFC, 0xA8EF},
+ {0x30d4, 0x9200},
+ {0x30b2, 0xC000},
+ {0x30bc, 0x0400},
+ {0x306E, 0xB480},
+ {0x3EFE, 0x1F0F},
+ {0x31E0, 0x1F01},
};
struct mt9p017_reg mt9p017_regs =
Please sign in to comment.
Something went wrong with that request. Please try again.