static void msg_ind_set_blink(struct msg_ind_led_data *msg_ind_data, bool enable) { unsigned short led_reg; unsigned int i; if (enable) { if (!(msg_ind_data->regulator_state&LD_LED_BLINK)) { cpcap_uc_start(msg_ind_data->cpcap, CPCAP_BANK_PRIMARY, CPCAP_MACRO_6); printk_cpcap("%s: cpcap_uc_start(CPCAP_MACRO_6)\n", __func__); if (msg_ind_data->cpcap_leds->rgb_led.regulator_macro_controlled) { /* Wait for the macro to start. */ cpcap_regacc_read(msg_ind_data->cpcap, CPCAP_REG_REDC, &led_reg); i = 21; while ((!(led_reg & LD_MSG_IND_CPCAP_BLINK_ON)) && (--i > 0)) { cpcap_uc_start(msg_ind_data->cpcap, CPCAP_BANK_PRIMARY, CPCAP_MACRO_6); msleep(10); cpcap_regacc_read(msg_ind_data->cpcap, CPCAP_REG_REDC, &led_reg); } if (i == 0) printk(KERN_ERR "%s: Unable to sync CPCAP blink on macro.\n", __func__); printk_cpcap("%s: Blink macro started.\n", __func__); /* Shutdown the regulator since the macro handles the regulator. */ msg_ind_set_regulator(msg_ind_data, false, true); } msg_ind_data->regulator_state |= LD_LED_BLINK; } } else { if (msg_ind_data->regulator_state&LD_LED_BLINK) { cpcap_uc_stop(msg_ind_data->cpcap, CPCAP_BANK_PRIMARY, CPCAP_MACRO_6); printk_cpcap("%s: cpcap_uc_stop(CPCAP_MACRO_6)\n", __func__); if (msg_ind_data->cpcap_leds->rgb_led.regulator_macro_controlled) { /* Wait for the macro to be stopped before moving on. */ cpcap_regacc_read(msg_ind_data->cpcap, CPCAP_REG_REDC, &led_reg); i = 21; while ((led_reg & LD_MSG_IND_CPCAP_BLINK_ON) && (--i > 0)) { cpcap_uc_stop(msg_ind_data->cpcap, CPCAP_BANK_PRIMARY, CPCAP_MACRO_6); msleep(10); cpcap_regacc_read(msg_ind_data->cpcap, CPCAP_REG_REDC, &led_reg); } if (i == 0) printk(KERN_ERR "%s: Unable to sync CPCAP blink off macro.\n", __func__); printk_cpcap("%s: Blink macro stopped.\n", __func__); /* If any LED's are on re-enable the regulator. */ if (msg_ind_data->regulator_state&(LD_LED_RED|LD_LED_GREEN|LD_LED_BLUE)) msg_ind_set_regulator(msg_ind_data, true, false); } msg_ind_data->regulator_state &= ~LD_LED_BLINK; } } }
static void hs_handler(enum cpcap_irqs irq, void *data) { struct cpcap_3mm5_data *data_3mm5 = data; int new_state = NO_DEVICE; if (irq != CPCAP_IRQ_HS) return; /* HS sense of 1 means no headset present, 0 means headset attached. */ if (cpcap_irq_sense(data_3mm5->cpcap, CPCAP_IRQ_HS, 1) == 1) { cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_TXI, 0, (CPCAP_BIT_MB_ON2 | CPCAP_BIT_PTT_CMP_EN)); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_RXOA, 0, CPCAP_BIT_ST_HS_CP_EN); audio_low_power_set(data_3mm5, &data_3mm5->audio_low_pwr_det); cpcap_irq_mask(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_mask(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_HS); send_key_event(data_3mm5, 0); /* Config mux switch to accy detection. */ cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_GPIO2, 0, CPCAP_BIT_GPIO2DRV); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_GPIO4, 0, CPCAP_BIT_GPIO4DRV); cpcap_uc_stop(data_3mm5->cpcap, CPCAP_MACRO_5); } else { /* Config mux switch to pass headset mic. */ cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_GPIO2, 0, CPCAP_BIT_GPIO2DRV); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_GPIO4, CPCAP_BIT_GPIO4DRV, CPCAP_BIT_GPIO4DRV); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_TXI, (CPCAP_BIT_MB_ON2 | CPCAP_BIT_PTT_CMP_EN), (CPCAP_BIT_MB_ON2 | CPCAP_BIT_PTT_CMP_EN)); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_RXOA, CPCAP_BIT_ST_HS_CP_EN, CPCAP_BIT_ST_HS_CP_EN); audio_low_power_clear(data_3mm5, &data_3mm5->audio_low_pwr_det); /* Give PTTS time to settle 10ms */ msleep(11); if (cpcap_irq_sense(data_3mm5->cpcap, CPCAP_IRQ_PTT, 1) <= 0) { /* Headset without mic and MFB is detected. (May also * be a headset with the MFB pressed.) */ new_state = HEADSET_WITHOUT_MIC; } else { new_state = HEADSET_WITH_MIC; /* Config mux switch to pass headset mic. */ cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_GPIO2, 0, CPCAP_BIT_GPIO2DRV); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_GPIO4, CPCAP_BIT_GPIO4DRV, CPCAP_BIT_GPIO4DRV); } cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_HS); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_uc_start(data_3mm5->cpcap, CPCAP_MACRO_5); headset_in_stamp = jiffies; } switch_set_state(&data_3mm5->sdev, new_state); if (data_3mm5->cpcap->h2w_new_state) data_3mm5->cpcap->h2w_new_state(new_state); dev_info(&data_3mm5->cpcap->spi->dev, "New headset state: %d\n", new_state); }
static void hs_handler(enum cpcap_irqs irq, void *data) { struct cpcap_3mm5_data *data_3mm5 = data; int new_state = NO_DEVICE; if (irq != CPCAP_IRQ_HS) return; /* HS sense of 1 means no headset present, 0 means headset attached. */ if (cpcap_irq_sense(data_3mm5->cpcap, CPCAP_IRQ_HS, 1) == 1) { cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_TXI, 0, (CPCAP_BIT_MB_ON2 | CPCAP_BIT_PTT_CMP_EN)); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_RXOA, 0, CPCAP_BIT_ST_HS_CP_EN); audio_low_power_set(data_3mm5, &data_3mm5->audio_low_pwr_det); cpcap_irq_mask(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_mask(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_HS); send_key_event(data_3mm5, 0); data_3mm5->unsupported_headset=0; cpcap_uc_stop(data_3mm5->cpcap, CPCAP_BANK_PRIMARY, CPCAP_MACRO_5); } else { cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_TXI, (CPCAP_BIT_MB_ON2 | CPCAP_BIT_PTT_CMP_EN), (CPCAP_BIT_MB_ON2 | CPCAP_BIT_PTT_CMP_EN)); cpcap_regacc_write(data_3mm5->cpcap, CPCAP_REG_RXOA, CPCAP_BIT_ST_HS_CP_EN, CPCAP_BIT_ST_HS_CP_EN); audio_low_power_clear(data_3mm5, &data_3mm5->audio_low_pwr_det); /* Give PTTS time to settle */ mdelay(2); if (cpcap_irq_sense(data_3mm5->cpcap, CPCAP_IRQ_PTT, 1) <= 0) { /* Headset without mic and MFB is detected. (May also * be a headset with the MFB pressed.) */ new_state = HEADSET_WITHOUT_MIC; } else { if(cpcap_irq_sense(data_3mm5->cpcap, CPCAP_IRQ_MB2, 1) == 0) { /*cvk011c: This is an Apple HS and its microphone will not work with CPCAP due to HW problem. Detect it as HS without mic to avoid problems with HS BTN detection and MIC audio */ new_state = HEADSET_WITHOUT_MIC; dev_info(&data_3mm5->cpcap->spi->dev, "Unsupported headset detected\n"); data_3mm5->unsupported_headset=1; }else new_state = HEADSET_WITH_MIC; } cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_HS); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_MB2); cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5); cpcap_uc_start(data_3mm5->cpcap, CPCAP_BANK_PRIMARY, CPCAP_MACRO_5); } switch_set_state(&data_3mm5->sdev, new_state); if (data_3mm5->cpcap->h2w_new_state) data_3mm5->cpcap->h2w_new_state(new_state); dev_info(&data_3mm5->cpcap->spi->dev, "New headset state: %d\n", new_state); }