static int adp5587_input_device_init(struct i2c_client *client) { struct adp5587_data *client_data = NULL; int i = 0; int rc = 0; int keynum = 0; client_data = i2c_get_clientdata(client); //Allocate input device client_data->input_dev = input_allocate_device(); if (!client_data->input_dev) { rc = -ENOMEM; printk(KERN_ERR "adp5587_input_device_init: Failed to allocate input device\n"); goto exit_input_dev_alloc_failed; } if(machine_is_msm7x25_u8300()) { client_data->keymap = keypad_keymap_u8300; keynum = sizeof(keypad_keymap_u8300)/sizeof(keypad_keymap_u8300[0]); KEYPAD_DEBUG("%s: keynum %d \n", __FUNCTION__,keynum); }else{ client_data->keymap = NULL; goto exit_input_register_device_failed; } //Configure the accepted event type set_bit(EV_KEY, client_data->input_dev->evbit); //Configure the accepted keycodes for (i = 0; i < keynum; i++) { if (client_data->keymap[i]) set_bit(client_data->keymap[i] & KEY_MAX,client_data->input_dev->keybit); } client_data->input_dev->name = ADP5587_I2C_NAME; //Register input device rc = input_register_device(client_data->input_dev); if (rc) { printk(KERN_ERR"adp5587_input_device_init: Unable to register input device: %s\n", client_data->input_dev->name); goto exit_input_register_device_failed; } exit_input_register_device_failed: input_free_device(client_data->input_dev); exit_input_dev_alloc_failed: return rc; }
int32_t msm_camera_flash_set_led_state(unsigned led_state) { int32_t rc; #ifdef CONFIG_HUAWEI_CAMERA static int init = 0; if(!init) { init = 1; INIT_WORK(&flash_work, flash_on); hrtimer_init(&flash_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); flash_timer.function= flash_timer_func; } #endif CDBG("flash_set_led_state: %d\n", led_state); switch (led_state) { case MSM_CAMERA_LED_OFF: #ifdef CONFIG_HUAWEI_CAMERA hrtimer_cancel(&flash_timer); #endif rc = pmic_flash_led_set_current(0); rc = msm_camera_flash_disable_vreg(); break; case MSM_CAMERA_LED_LOW: #ifndef CONFIG_HUAWEI_CAMERA rc = pmic_flash_led_set_current(30); #else hrtimer_cancel(&flash_timer); rc = msm_camera_flash_enable_vreg(); if(machine_is_msm7x25_u8300()) { rc = pmic_flash_led_set_current(FLASH_HIGH_DRIVE_CURRENT_MA); } else { rc = pmic_flash_led_set_current(FLASH_LOW_DRIVE_CURRENT_MA); } #endif break; case MSM_CAMERA_LED_HIGH: #ifndef CONFIG_HUAWEI_CAMERA rc = pmic_flash_led_set_current(100); #else hrtimer_cancel(&flash_timer); flash_state = 0; //It takes time to eanble voltage regulator. So the voltage regulator should be enabled in advance before turning on flash LED. msm_camera_flash_enable_vreg(); hrtimer_start(&flash_timer, ktime_set(FLASH_HIGH_DRIVE_CURRENT_DELAY_MS / 1000, (FLASH_HIGH_DRIVE_CURRENT_DELAY_MS % 1000) * 1000000), HRTIMER_MODE_REL); rc = 0; #endif break; default: rc = -EFAULT; break; } CDBG("flash_set_led_state: return %d\n", rc); #ifdef CONFIG_HUAWEI_EVALUATE_POWER_CONSUMPTION switch (led_state) { case MSM_CAMERA_LED_OFF: huawei_rpc_current_consuem_notify(EVENT_CAMERA_FLASH_NOTIFY, 0); break; #ifndef CONFIG_HUAWEI_CAMERA case MSM_CAMERA_LED_LOW: huawei_rpc_current_consuem_notify(EVENT_CAMERA_FLASH_NOTIFY, (30/CAMERA_FLASH_CUR_DIV)); break; case MSM_CAMERA_LED_HIGH: huawei_rpc_current_consuem_notify(EVENT_CAMERA_FLASH_NOTIFY, (100/CAMERA_FLASH_CUR_DIV)); break; #else case MSM_CAMERA_LED_LOW: huawei_rpc_current_consuem_notify(EVENT_CAMERA_FLASH_NOTIFY, (FLASH_LOW_DRIVE_CURRENT_MA/CAMERA_FLASH_CUR_DIV)); break; case MSM_CAMERA_LED_HIGH: break; #endif default: break; } #endif return rc; }
static int aps_12d_probe( struct i2c_client *client, const struct i2c_device_id *id) { int ret; struct aps_data *aps; int i; printk(KERN_INFO "aps_12d_probe enter\n "); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { printk(KERN_ERR "aps_12d_probe: need I2C_FUNC_I2C\n"); ret = -ENODEV; goto err_check_functionality_failed; } if(machine_is_msm7x25_u8150() || machine_is_msm7x25_c8150()) { if((get_hw_sub_board_id() == HW_VER_SUB_VA) || ((get_hw_sub_board_id() == HW_VER_SUB_VB))) { printk(KERN_ERR "aps_12d_probe: aps is not supported in c8150 and u8150 T1 board!\n"); ret = -ENODEV; goto err_check_functionality_failed; } } aps = kzalloc(sizeof(*aps), GFP_KERNEL); if (aps == NULL) { ret = -ENOMEM; goto err_alloc_data_failed; } mutex_init(&aps->mlock); INIT_WORK(&aps->work, aps_12d_work_func); aps->client = client; i2c_set_clientdata(client, aps); printk(KERN_INFO "aps_12d_probe send command 2\n "); /* Command 2 register: 25mA,DC,12bit,Range1 */ ret = aps_i2c_reg_write(aps, APS_12D_REG_CMD2, \ (uint8_t)(APS_12D_IRDR_SEL_50MA << 6 | \ APS_12D_FREQ_SEL_DC << 4 | \ APS_12D_RES_SEL_12 << 2 | \ APS_12D_RANGE_SEL_ALS_1000)); if (ret < 0) { goto err_detect_failed; } if( machine_is_msm7x25_u8150() || machine_is_msm7x25_c8150() || machine_is_msm7x25_u8159()\ || machine_is_msm7x25_u8160() || machine_is_msm7x25_u8130() || machine_is_msm7x25_c8510()) { range_index = 0; high_threshold = high_threshold_value[range_index]; low_threshold = low_threshold_value[range_index]; for(i = 0; i < TOTAL_RANGE_NUM; i++) { /* NOTE: do NOT use the last one */ up_range_value[i] = MAX_ADC_OUTPUT - high_threshold_value[i] - UP_RANGE_FIX; #ifdef DEBUG_AUTO_RANGE_ADJUST printk("up_range_value[%d] = %d.\n",i, up_range_value[i]); #endif } down_range_value[0] = 0; for(i = 1; i < TOTAL_RANGE_NUM; i++) { /* NOTE: do not use the first one */ down_range_value[i] = (MAX_ADC_OUTPUT - high_threshold_value[i-1] - (MAX_ADC_OUTPUT / ADJUST_GATE)) / 4; #ifdef DEBUG_AUTO_RANGE_ADJUST printk("down_range_value[%d] = %d\n",i, down_range_value[i]); #endif } } else if( machine_is_msm7x25_u8500() || machine_is_msm7x25_um840()) { high_threshold = 300; low_threshold = 280; } else if( machine_is_msm7x25_u8300() ) { /* set shutter value for u8300 */ high_threshold = 710; low_threshold = 650; } else { high_threshold = 780; low_threshold = 730; } if (sensor_dev == NULL) { aps->input_dev = input_allocate_device(); if (aps->input_dev == NULL) { ret = -ENOMEM; printk(KERN_ERR "aps_12d_probe: Failed to allocate input device\n"); goto err_input_dev_alloc_failed; } aps->input_dev->name = "sensors"; aps->input_dev->id.bustype = BUS_I2C; input_set_drvdata(aps->input_dev, aps); ret = input_register_device(aps->input_dev); if (ret) { printk(KERN_ERR "aps_probe: Unable to register %s input device\n", aps->input_dev->name); goto err_input_register_device_failed; } sensor_dev = aps->input_dev; } else { aps->input_dev = sensor_dev; } set_bit(EV_ABS, aps->input_dev->evbit); input_set_abs_params(aps->input_dev, ABS_LIGHT, 0, 10240, 0, 0); input_set_abs_params(aps->input_dev, ABS_DISTANCE, 0, 1, 0, 0); ret = misc_register(&light_device); if (ret) { printk(KERN_ERR "aps_12d_probe: light_device register failed\n"); goto err_light_misc_device_register_failed; } ret = misc_register(&proximity_device); if (ret) { printk(KERN_ERR "aps_12d_probe: proximity_device register failed\n"); goto err_proximity_misc_device_register_failed; } if( light_device.minor != MISC_DYNAMIC_MINOR ){ light_device_minor = light_device.minor; } if( proximity_device.minor != MISC_DYNAMIC_MINOR ){ proximity_device_minor = proximity_device.minor ; } wake_lock_init(&proximity_wake_lock, WAKE_LOCK_SUSPEND, "proximity"); hrtimer_init(&aps->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); aps->timer.function = aps_timer_func; aps_wq = create_singlethread_workqueue("aps_wq"); if (!aps_wq) { ret = -ENOMEM; goto err_create_workqueue_failed; } this_aps_data =aps; #ifdef CONFIG_HAS_EARLYSUSPEND aps->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; aps->early_suspend.suspend = aps_12d_early_suspend; aps->early_suspend.resume = aps_12d_early_resume; register_early_suspend(&aps->early_suspend); #endif #ifdef CONFIG_HUAWEI_HW_DEV_DCT /* detect current device successful, set the flag as present */ set_hw_dev_flag(DEV_I2C_APS); #endif printk(KERN_INFO "aps_12d_probe: Start Proximity Sensor APS-12D\n"); #ifdef CONFIG_MELFAS_UPDATE_TS_FIRMWARE TS_updateFW_aps_data = this_aps_data; TS_updateFW_aps_wq = aps_wq; #endif return 0; err_create_workqueue_failed: misc_deregister(&proximity_device); err_proximity_misc_device_register_failed: misc_deregister(&light_device); err_light_misc_device_register_failed: err_input_register_device_failed: input_free_device(aps->input_dev); err_input_dev_alloc_failed: err_detect_failed: kfree(aps); err_alloc_data_failed: err_check_functionality_failed: return ret; }
static int adp5587_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adp5587_data *client_data = NULL; int rc = 0; uint8_t device_id; KEYPAD_DEBUG("%s:client->addr=0x%x \n",__FUNCTION__,client->addr); //if board is u8300 board,write actual addreee.else return. //if((HW_VER_SUB_SURF == get_hw_sub_board_id()) && machine_is_msm7x25_u8300()) if(machine_is_msm7x25_u8300()) { client->addr = 0x34;//actual address,see board-msm7x25.c,line 914 }else{ rc = -ENODEV; printk(KERN_INFO "%s:Deivice is not u8300 \n",__FUNCTION__); return rc; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { rc = -ENODEV; return rc; } adp5587_wq = create_singlethread_workqueue("adp5587_wq"); if (!adp5587_wq) { KEYPAD_DEBUG("create adp5587_wq error\n"); rc = -ENOMEM; goto exit_chip_init_failed; } client_data = kzalloc(sizeof(struct adp5587_data), GFP_KERNEL); if (!client_data) { rc = -ENOMEM; return rc; } //INIT_WORK(&client_data->work, adp5587_work_func); client_data->client = client; i2c_set_clientdata(client, client_data); INIT_WORK(&client_data->work, adp5587_work_fuc); adp5587_chip_reset(); device_id = i2c_smbus_read_byte_data(client, DEV_ID); KEYPAD_DEBUG("dveice id=%d \n",device_id); device_id = i2c_smbus_read_byte_data(client, INT_STAT); KEYPAD_DEBUG("ok dveice id=%d \n",device_id); rc = adp5587_chip_init(client_data); if (rc < 0) { KEYPAD_DEBUG("adp5587_chip_init=%d \n",rc); goto exit_chip_init_failed; } rc = adp5587_setup_irq(client); rc = set_irq_wake(client->irq, 1); if (rc < 0) { KEYPAD_DEBUG("adp5587_chip_irq rc=%d \n",rc); goto exit_reqeust_irq_failed; } rc = adp5587_input_device_init(client); if (rc < 0){ KEYPAD_DEBUG("adp5587_init rc=%d \n",rc); goto exit_input_device_init_failed; } /*delete some lines */ return 0; exit_input_device_init_failed: free_irq(client->irq, client_data); exit_reqeust_irq_failed: exit_chip_init_failed: kfree(client_data); return rc; }
static void gs_work_func(struct work_struct *work) { int ret,i; struct gs_data *gs = container_of(work, struct gs_data, work); unsigned char dataX_low = 0; unsigned char dataX_high = 0; uint16 dataX = 0; unsigned char dataY_low = 0; unsigned char dataY_high = 0; uint16 dataY = 0; unsigned char dataZ_low = 0; unsigned char dataZ_high = 0; uint16 dataZ = 0; boolean data_is_err = 0; int x,y,z; uint8_t buf[6]; uint8_t start_reg; struct i2c_msg msg[2]; int sesc = accel_delay/1000; int nsesc = (accel_delay%1000)*1000000; msg[0].addr = gs->client->addr; msg[0].flags = 0; msg[0].len = 1; msg[0].buf = &start_reg; start_reg = 0x32; msg[1].addr = gs->client->addr; msg[1].flags = I2C_M_RD; msg[1].len = sizeof(buf); msg[1].buf = buf; #if 0 /************************************************************************** ADI345X#8451849PHIL of PP1 phone need set offset, but ADI345B can't set offset value, if set the value will work MMITest fail ***************************************************************************/ ret = gs_set_offset(); if (ret < 0) { printk(KERN_ERR "gs_set_offset faild\n"); /* fail? */ goto restart_timer; } #endif ret = reg_read(gs, GS_ADI_REG_INT_SOURCE); /* read IRQ STATUS */ if (ret < 0) { printk(KERN_ERR "i2c_smbus_read_int status_0X30 failed\n"); /* fail? */ goto restart_timer; } if((ret&0x20))//double tap { // printk(KERN_DEBUG"double tap\n"); } else if((ret&0x40))//sigle tap { // printk(KERN_DEBUG"sigle tap\n"); } else if((ret&0x80)) { //printk(KERN_DEBUG"data ready\n"); for (i = 0; i < 10; i++) { ret = i2c_transfer(gs->client->adapter, msg, 2); if (ret < 0) { printk(KERN_ERR "gs_ts_work_func: i2c_transfer failed\n"); data_is_err = 1; } else { data_is_err = 0; break; } } } else { printk(KERN_ERR"data err\n"); data_is_err = 1; } dataX_low = msg[1].buf[0]; dataX_high = msg[1].buf[1]; dataY_low = msg[1].buf[2]; dataY_high = msg[1].buf[3]; dataZ_low = msg[1].buf[4]; dataZ_high = msg[1].buf[5]; if(!data_is_err) { dataX = ((dataX_high&0x1f) <<8) |dataX_low; dataY = ((dataY_high&0x1f) <<8) |dataY_low; dataZ = ((dataZ_high&0x1f) <<8) |dataZ_low; if(dataX&0x1000)/*负值*/ { x=dataX -8192; /*13 bit is sign bit, */ } else { x = dataX; } if(dataY&0x1000)/*负值*/ { y=dataY - 8192; /*13 bit is sign bit, */ } else { y = dataY; } if(dataZ&0x1000)/*负值*/ { z =dataZ -8192; /*13 bit is sign bit, */ } else { z = dataZ; } /* change the x,y,z for u8300 because orientation of accelerometer of u8300 is different.*/ if(machine_is_msm7x25_u8300()) { int x1,y1,z1; x1 = y * (-1); y1 = x * (-1); z1 = z * (-1); x = x1; y = y1; z = z1; } sensor_data[0] = (s16)x; sensor_data[1] = (s16)y; sensor_data[2] = (s16)z; x = (MG_PER_SAMPLE * (s16)x)/FILTER_SAMPLE_NUMBER; y = (MG_PER_SAMPLE * (s16)y)/FILTER_SAMPLE_NUMBER; z = (MG_PER_SAMPLE * (s16)z)/FILTER_SAMPLE_NUMBER; x *=(-1); input_report_abs(gs->input_dev, ABS_X, x); input_report_abs(gs->input_dev, ABS_Y, y); input_report_abs(gs->input_dev, ABS_Z, z); input_sync(gs->input_dev); } restart_timer: if (gs->use_irq) enable_irq(gs->client->irq); else hrtimer_start(&gs->timer, ktime_set(sesc, nsesc), HRTIMER_MODE_REL); }
static void gs_work_func(struct work_struct *work) { int status; int x,y,z; struct gs_data *gs = container_of(work, struct gs_data, work); int sesc = accel_delay/1000; int nsesc = (accel_delay%1000)*1000000; status = reg_read(gs, GS_ST_REG_STATUS ); /* read status */ if(status & (1<<3)) { u8 u8x = reg_read(gs,GS_ST_REG_OUT_X); u8 u8y= reg_read(gs,GS_ST_REG_OUT_Y); u8 u8z = reg_read(gs,GS_ST_REG_OUT_Z); #if 0 x = MG_PER_SAMPLE *(s8)u8y ; y = MG_PER_SAMPLE * (s8)u8x ; z = MG_PER_SAMPLE * (s8)u8z; #endif if(u8x&0x80)/*负值*/ { x= u8x-256; /*负数按照补码计算 */ } else { x = u8x; } if(u8y&0x80)/*负值*/ { y=u8y-256; /*负数按照补码计算 */ } else { y = u8y; } if(u8z&0x80)/*负值*/ { z=u8z-256; /*负数按照补码计算 */ } else { z = u8z; } /* change the x,y,z for u8300 because orientation of accelerometer of u8300 is different.*/ if(machine_is_msm7x25_u8300()) { int x1,y1,z1; x1 = y * (-1); y1 = x * (-1); z1 = z * (-1); x = x1; y = y1; z = z1; } memset(sensor_data, 0, 3 ); sensor_data[0]= 46*(s16)x/10; sensor_data[1]= 46*(s16)y/10 ; sensor_data[2]= 46*(s16)z/10; /*(Decimal value/ 256) * 4.6 g,For (0g ~+2.3g)*/ x = (MG_PER_SAMPLE*46*(s16)x)/FILTER_SAMPLE_NUMBER/10; y = (MG_PER_SAMPLE*46*(s16)y)/FILTER_SAMPLE_NUMBER/10; z = (MG_PER_SAMPLE*46*(s16)z)/FILTER_SAMPLE_NUMBER/10; x *=(-1); input_report_abs(gs->input_dev, ABS_X, x); input_report_abs(gs->input_dev, ABS_Y, y); input_report_abs(gs->input_dev, ABS_Z, z); input_sync(gs->input_dev); } if (gs->use_irq) enable_irq(gs->client->irq); else hrtimer_start(&gs->timer, ktime_set(sesc, nsesc), HRTIMER_MODE_REL); }