static void type_work_func(struct work_struct *work) { #ifdef REG_DEBUG unsigned long val_anacr2, val_cmc, val_auxen; #endif int adc = auxadc_access(2); if(adc>=KEY_3POLE_THRESHOLD) { if(FactoryMode == DISABLE) board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE | SYSCFG_DISABLE); if (mic.headset_pd->check_hs_state) board_sysconfig(SYSCFG_HEADSET, SYSCFG_ENABLE); mic.headset_state = HEADSET_4_POLE; printk("%s: 4-pole inserted : ear_adc=%d\n", __func__, adc); } else { board_sysconfig(SYSCFG_AUXMIC, SYSCFG_DISABLE); mic.headset_state = HEADSET_3_POLE; printk("%s: 3-pole inserted : ear_adc=%d\n", __func__, adc); } switch_set_state(&(mic.switch_data.sdev), mic.headset_state); if(FactoryMode == DISABLE) sync_use_mic = DISABLE; #ifdef REG_DEBUG val_anacr2 = readl(io_p2v(REG_ANACR2)); val_cmc = readl(io_p2v(REG_AUXMIC_CMC)); val_auxen = readl(io_p2v(REG_AUXMIC_AUXEN)); printk("%s: REG_ANACR2=%x, REG_AUXMIC_CMC=%x, REG_AUXMIC_AUXEN=%x\n", __func__, val_anacr2, val_cmc, val_auxen); #endif }
static ssize_t hs_Show(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t ret = 0; const ptrdiff_t off = attr - hs_Attrs; volatile int adc = 0; switch (off) { case ATTR_ADC: ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%d\n", adc = auxadc_access(2)); break; case ATTR_THRESHOLD: ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%d\n%d\n%d\n%d\n%d\n%d\n%d\n", \ (int)KEY_3POLE_THRESHOLD, (int)KEY1_THRESHOLD_L, (int)KEY1_THRESHOLD_U,\ (int)KEY2_THRESHOLD_L, (int)KEY2_THRESHOLD_U, (int)KEY3_THRESHOLD_L,\ (int)KEY3_THRESHOLD_U); break; default : break; } return ret; }
static void type_work_func(struct work_struct *work) { int adc = 0; if(mic.headset_state) { adc = auxadc_access(2); if(adc >= KEY_3POLE_THRESHOLD) { if(FactoryMode == DISABLE) board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE | SYSCFG_DISABLE); board_sysconfig(SYSCFG_HEADSET, SYSCFG_ENABLE); mic.headset_state = HEADSET_4_POLE; mic.hsbtime = ktime_get(); ENABLE_IRQ_MICON; printk("%s: 4-pole inserted : ear_adc=%d\n", __func__, adc); } else { if(FactoryMode == DISABLE) board_sysconfig(SYSCFG_AUXMIC, SYSCFG_DISABLE); mic.headset_state = HEADSET_3_POLE; printk("%s: 3-pole inserted : ear_adc=%d\n", __func__, adc); } mic.pluging = DISABLE; if(FactoryMode == DISABLE) sync_use_mic = DISABLE; switch_set_state(&mic.sdev, mic.headset_state); } }
static void input_work_func(struct work_struct *work) { int adc_value = -1; int val = 0; ktime_t temptime; adc_value = auxadc_access(2); val = readl(io_p2v(REG_ANACR12)); // printk("%s: REG_ANACR2=%d, REG_ANACR12=%d\n", __func__,adc_value , val); if(val >= KEY_PRESS_THRESHOLD && adc_value >= KEY1_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U) { temptime = ktime_get(); temptime = ktime_sub(temptime, mic.hsbtime); if(temptime.tv.nsec < VALID_RELEASE_REF_TIME && mic.keypressing == PRESS) { if ( adc_value >= KEY1_THRESHOLD_L && adc_value < KEY1_THRESHOLD_U ) { mic.key_count[0]++; printk ("KEY_BCM_HEADSET_BUTTON \n"); } else if ( adc_value >= KEY2_THRESHOLD_L && adc_value < KEY2_THRESHOLD_U ) { mic.key_count[1]++; printk ("KEY_VOLUMEUP \n"); } else if ( adc_value >= KEY3_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U ) { mic.key_count[2]++; printk ("KEY_VOLUMEDOWN \n"); } } else { if(mic.keypressing == PRESS && (mic.key_count[0] + mic.key_count[1] + mic.key_count[2])) { input_report_key(mic.headset_button_idev, Return_valid_key(mic.key_count), PRESS); input_sync(mic.headset_button_idev); set_button(1); mic.keypressing = RELEASE; } } cancel_delayed_work(&(mic.input_work)); queue_delayed_work(mic.headset_workqueue, &(mic.input_work), KEY_PRESS_REF_TIME); } else { if(mic.keypressing == RELEASE && (mic.key_count[0] + mic.key_count[1] + mic.key_count[2])) { printk ("%s: RELEASE key_count [%d, %d, %d] \n", __func__, mic.key_count[0], mic.key_count[1], mic.key_count[2]); input_report_key(mic.headset_button_idev, Return_valid_key(mic.key_count), RELEASE); input_sync(mic.headset_button_idev); } else { printk("%s: NO PRESS\n", __func__); } if(FactoryMode == DISABLE) { board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE | SYSCFG_DISABLE); sync_use_mic = DISABLE; } set_button(0); mic.keypressing = NONE; } }
static void input_work_func(struct work_struct *work) { int adc_value = -1; int val = 0; ktime_t temptime; adc_value = auxadc_access(2); val = readl(io_p2v(REG_ANACR12)); // printk("%s: REG_ANACR2=%d, REG_ANACR12=%d\n", __func__,adc_value , val); #ifdef USE_SERVICEMODE if(val >= KEY_PRESS_THRESHOLD && adc_value >= Min_threshold && adc_value < Max_threshold) { #else if(val >= KEY_PRESS_THRESHOLD && adc_value >= KEY1_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U) { #endif temptime = ktime_get(); temptime = ktime_sub(temptime, mic.hsbtime); if(temptime.tv.nsec < VALID_RELEASE_REF_TIME && mic.keypressing == PRESS) { if ( adc_value >= KEY1_THRESHOLD_L && adc_value < KEY1_THRESHOLD_U ) { mic.key_count[0]++; printk ("KEY_BCM_HEADSET_BUTTON \n"); } else if ( adc_value >= KEY2_THRESHOLD_L && adc_value < KEY2_THRESHOLD_U ) { mic.key_count[1]++; printk ("KEY_VOLUMEUP \n"); } else if ( adc_value >= KEY3_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U ) { mic.key_count[2]++; printk ("KEY_VOLUMEDOWN \n"); } } else { if(mic.keypressing == PRESS && (mic.key_count[0] + mic.key_count[1] + mic.key_count[2])) { input_report_key(mic.headset_button_idev, Return_valid_key(mic.key_count), PRESS); input_sync(mic.headset_button_idev); set_button(1); mic.keypressing = RELEASE; } } cancel_delayed_work(&(mic.input_work)); queue_delayed_work(mic.headset_workqueue, &(mic.input_work), KEY_PRESS_REF_TIME); } else { if(mic.keypressing == RELEASE && (mic.key_count[0] + mic.key_count[1] + mic.key_count[2])) { printk ("%s: RELEASE key_count [%d, %d, %d] \n", __func__, mic.key_count[0], mic.key_count[1], mic.key_count[2]); input_report_key(mic.headset_button_idev, Return_valid_key(mic.key_count), RELEASE); input_sync(mic.headset_button_idev); } else { printk("%s: NO PRESS\n", __func__); } if(FactoryMode == DISABLE) { board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE | SYSCFG_DISABLE); sync_use_mic = DISABLE; } set_button(0); mic.keypressing = NONE; } } /*------------------------------------------------------------------------------ Function name : hs_buttonisr Description : interrupt handler Return type : irqreturn_t ------------------------------------------------------------------------------*/ irqreturn_t hs_buttonisr(int irq, void *dev_id) { struct mic_t *p = &mic; int val = 0; ktime_t temptime; #ifdef USE_SERVICEMODE if(TestMode == ENABLE) { if(p->headset_state == HEADSET_4_POLE) board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE); return IRQ_NONE; } #endif if(mic.keypressing == INIT) { temptime = ktime_get(); temptime = ktime_sub(temptime, mic.hsbtime); if(temptime.tv.sec >= 1 || temptime.tv.nsec >= KEY_INTERRUPT_REF_TIME) mic.keypressing = NONE; else { printk("%s: Initializing HSB ISR\n", __func__ ); return IRQ_NONE; } } if(p->pluging == ENABLE || p->keypressing != NONE) { printk("%s: Headset pluging OR keypressing\n", __func__ ); return IRQ_NONE; } val = readl(io_p2v(REG_ANACR12)); if(val < KEY_PRESS_THRESHOLD) { printk("%s: False button interrupt\n", __func__ ); return IRQ_NONE; } if (p->headset_state == HEADSET_4_POLE) { p->hsbtime = ktime_get(); board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE); memset(mic.key_count, 0, sizeof(mic.key_count)); p->keypressing = PRESS; sync_use_mic = ENABLE; cancel_delayed_work(&(mic.input_work)); queue_delayed_work(mic.headset_workqueue, &(p->input_work), KEY_BEFORE_PRESS_REF_TIME); } return IRQ_HANDLED; } /* 1 : SIM_DUAL_FIRST, 2 : SIM_DUAL_SECOND */ static void getIMSI_work_func(struct work_struct *work) { SIMLOCK_SIM_DATA_t* simdata = NULL; int first = DISABLE; int second = DISABLE; simdata = GetSIMData(SIM_DUAL_FIRST); first = ((simdata == NULL) || (strncmp(simdata->imsi_string, TEST_SIM_IMSI, IMSI_DIGITS) != 0)) ? DISABLE : ENABLE; simdata = GetSIMData(SIM_DUAL_SECOND); second = ((simdata == NULL) || (strncmp(simdata->imsi_string, TEST_SIM_IMSI, IMSI_DIGITS) != 0)) ? DISABLE : ENABLE; FactoryMode = (first == ENABLE || second == ENABLE) ? ENABLE : DISABLE; printk("%s: Factorymode %d\n", __func__, FactoryMode); if(FactoryMode == ENABLE) { if(mic.headset_state == HEADSET_4_POLE) board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE); } }
static void input_work_func(struct work_struct *work) { int delta = 0; unsigned long val = 0; #ifdef REG_DEBUG unsigned long val_anacr2, val_cmc, val_auxen; #endif static int key_status = RELEASE; int adc_value = auxadc_access(2); printk("%s: input_work adc_value=%d\n", __func__, adc_value); /* If the key_status is 0, send the event for a key press */ if(key_status == RELEASE) { delta = check_delta(mic.hsbtime,mic.hstime); if((mic.headset_state == HEADSET_4_POLE) && (delta == 0)) { if (!key_resolved) { if ( adc_value >= KEY1_THRESHOLD_L && adc_value < KEY1_THRESHOLD_U ) { key_count[0]++; if (key_count[0] >= KEYCOUNT_THRESHOLD) key_resolved = 1; key_type = KEY_BCM_HEADSET_BUTTON; printk ("KEY_BCM_HEADSET_BUTTON \n"); } if ( adc_value >= KEY2_THRESHOLD_L && adc_value < KEY2_THRESHOLD_U ) { key_count[1]++; if (key_count[1] >= KEYCOUNT_THRESHOLD) key_resolved = 1; key_type = KEY_VOLUMEUP; printk ("KEY_VOLUMEUP \n"); } if ( adc_value >= KEY3_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U ) { key_count[2]++; if (key_count[2] >= KEYCOUNT_THRESHOLD) key_resolved = 1; key_type = KEY_VOLUMEDOWN; printk ("KEY_VOLUMEDOWN \n"); } } else input_report_key(mic.headset_button_idev, key_type, PRESS); input_sync(mic.headset_button_idev); printk("%s: set_button => PRESS\n", __func__); set_button(PRESS); printk("%s: button pressed : ear_adc=%d\n", __func__, adc_value); } } /* Check if the value read from ANACR12 is greater than the * threshold. If so, the key is still pressed and schedule the work * queue till the value is less than the threshold */ val = readl(io_p2v(REG_ANACR12)); printk("%s: REG_ANACR12=%x\n", __func__,val); if (val >= KEY_PRESS_THRESHOLD && (adc_value >= KEY1_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U)) { key_status = PRESS; if (!key_resolved) { if ( adc_value >= KEY1_THRESHOLD_L && adc_value < KEY1_THRESHOLD_U ) { key_count[0]++; if (key_count[0] >= KEYCOUNT_THRESHOLD) key_resolved = 1; key_type = KEY_BCM_HEADSET_BUTTON; printk ("KEY_BCM_HEADSET_BUTTON\n"); } if ( adc_value >= KEY2_THRESHOLD_L && adc_value < KEY2_THRESHOLD_U ) { key_count[1]++; if (key_count[1] >= KEYCOUNT_THRESHOLD) key_resolved = 1; key_type = KEY_VOLUMEUP; printk ("KEY_VOLUMEUP\n"); } if ( adc_value >= KEY3_THRESHOLD_L && adc_value < KEY3_THRESHOLD_U ) { key_count[2]++; if (key_count[2] >= KEYCOUNT_THRESHOLD) key_resolved = 1; key_type = KEY_VOLUMEDOWN; printk ("KEY_VOLUMEDOWN\n"); } } else input_report_key(mic.headset_button_idev, key_type, PRESS); schedule_delayed_work(&(mic.input_work), KEY_PRESS_REF_TIME); printk("%s: set_button => PRESS\n", __func__); set_button(PRESS); } /* Once the value read from ANACR12 is less than the threshold, send * the event for a button release */ else { key_status = RELEASE; printk ("%s: key_count [%d, %d, %d] \n", __func__, key_count[0], key_count[1], key_count[2]); if ( key_count[0] >= KEYCOUNT_THRESHOLD ) { printk("SEND/END RELEASE\n"); input_report_key(mic.headset_button_idev, KEY_BCM_HEADSET_BUTTON, RELEASE); input_sync(mic.headset_button_idev); } else if ( key_count[1] >= KEYCOUNT_THRESHOLD ) { printk("VOLUP RELEASE\n"); input_report_key(mic.headset_button_idev, KEY_VOLUMEUP, RELEASE); input_sync(mic.headset_button_idev); } else if ( key_count[2] >= KEYCOUNT_THRESHOLD ) { printk("VOLDOWN RELEASE\n"); input_report_key(mic.headset_button_idev, KEY_VOLUMEDOWN, RELEASE); input_sync(mic.headset_button_idev); } printk("%s: set_button => RELEASE\n", __func__); set_button(RELEASE); key_resolved = 0; key_count[0] = key_count[1] = key_count[2] = 0; if(FactoryMode == DISABLE) { board_sysconfig(SYSCFG_AUXMIC, SYSCFG_ENABLE | SYSCFG_DISABLE); sync_use_mic = DISABLE; } #ifdef REG_DEBUG val_anacr2 = readl(io_p2v(REG_ANACR2)); val_cmc = readl(io_p2v(REG_AUXMIC_CMC)); val_auxen = readl(io_p2v(REG_AUXMIC_AUXEN)); printk("%s: REG_ANACR2=%x, REG_AUXMIC_CMC=%x, REG_AUXMIC_AUXEN=%x\n", __func__, val_anacr2, val_cmc, val_auxen); #endif } }