static int sec_bat_adc_ap_read(unsigned int channel) { int rc, data; struct pm8xxx_adc_chan_result result; switch (channel) { case SEC_BAT_ADC_CHANNEL_TEMP: rc = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_7, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_7, rc); return rc; } /* use measurement, no need to scale */ data = (int)result.measurement; break; case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: rc = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_10, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_10, rc); return rc; } /* use measurement, no need to scale */ data = (int)result.measurement; break; } return data; }
static int sec_bat_adc_ap_read(unsigned int channel) { int rc = -1, data = -1; struct pm8xxx_adc_chan_result result; switch (channel) { case SEC_BAT_ADC_CHANNEL_TEMP: case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: rc = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_3, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_3, rc); return rc; } /* use measurement, no need to scale */ data = (int)result.measurement; break; case SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW: pm8xxx_adc_read(CHANNEL_VBAT, &result); data = (int)result.physical; break; case SEC_BAT_ADC_CHANNEL_CURRENT_NOW: rc = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_7, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_7, rc); return rc; } /* use measurement, no need to scale */ data = (int)result.measurement; /* MPP7 error in discharging */ if (data > biscotto_battery_data[0].adc2current_table[ biscotto_battery_data[0].adc2current_table_size-1].adc) { pr_err("Invalid adc value: %d, %d\n", data, biscotto_battery_data[0].adc2current_table_size); data = 0; } break; default: pr_err("Invalid adc channel: %d\n", channel); break; } return data; }
static int sec_bat_adc_ap_read(unsigned int channel) { int rc = -1, data = -1; struct pm8xxx_adc_chan_result result; /* For HW rev 00, return temporary value */ if (system_rev == 0) return 650000; switch (channel) { case SEC_BAT_ADC_CHANNEL_TEMP: case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: rc = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_4, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_4, rc); return rc; } /* use measurement, no need to scale */ data = (int)result.measurement; break; default: pr_err("Invalid adc channel: %d\n", channel); break; } return data; }
static int sec_bat_adc_ap_read(unsigned int channel) { int rc = -1, data = -1; struct pm8xxx_adc_chan_result result; switch (channel) { case SEC_BAT_ADC_CHANNEL_TEMP: case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: rc = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_3, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_3, rc); return rc; } /* use measurement, no need to scale */ data = (int)result.measurement; break; case SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW: pm8xxx_adc_read(CHANNEL_VBAT, &result); data = (int)result.physical; break; default: pr_err("Invalid adc channel: %d\n", channel); break; } return data; }
unsigned lge_pm_get_cable_type_adc(void) { struct pm8xxx_adc_chan_result result; pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_12, ADC_MPP_1_AMUX6, &result); return result.physical; }
unsigned lge_get_board_revno_adc(void) { struct pm8xxx_adc_chan_result result; pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_3, ADC_MPP_1_AMUX6, &result); return result.physical; }
static int hs_pmic_remote_adc_pm8921(int *adc) { struct pm8xxx_adc_chan_result result; HS_DBG(); result.physical = -EINVAL; pm8xxx_adc_mpp_config_read(hi->pdata.adc_mpp, hi->pdata.adc_amux, &result); *adc = (int) result.physical; *adc = *adc / 1000; HS_LOG("Remote ADC %d (0x%X)", *adc, *adc); return 1; }
void is_oled_temp_check(void) { struct pm8xxx_adc_chan_result result; int rc=0; int try_max=0; do { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_11, ADC_MPP_1_AMUX6, &result); try_max++; }while(rc && try_max<20); printk("[PANTECH_LCD]%s: OLED Panel Temperature %lld(uV)\n ", __func__, result.physical); }
static int sec_therm_get_adc_data(struct sec_therm_info *info) { int rc = 0; int adc_max = 0; int adc_min = 0; int adc_total = 0; int i, adc_data; struct pm8xxx_adc_chan_result result; for (i = 0; i < ADC_SAMPLING_CNT; i++) { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_4, ADC_MPP_1_AMUX6, &result); if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_4, rc); goto err; } adc_data = (int)result.measurement; pr_err("reading PM8XXX_AMUX_MPP_4 [rc = %d] [measurement = %lld]\n", rc,result.measurement); if (i != 0) { if (adc_data > adc_max) adc_max = adc_data; else if (adc_data < adc_min) adc_min = adc_data; } else { adc_max = adc_data; adc_min = adc_data; } adc_total += adc_data; } return (adc_total - adc_max - adc_min) / (ADC_SAMPLING_CNT - 2); err: return rc; }
static int get_cp_thm_value(struct ssp_data *data) { int err = 0; int adc_max = 0; int adc_min = 0; int adc_total = 0; int i; struct pm8xxx_adc_chan_result result; for (i = 0; i < CP_THM_ADC_SAMPLING_CNT; i++) { mutex_lock(&data->cp_temp_adc_lock); err = pm8xxx_adc_mpp_config_read( PM8XXX_AMUX_MPP_4, ADC_MPP_2_AMUX6, &result); mutex_unlock(&data->cp_temp_adc_lock); if (err) { pr_err("%s : error reading mpp %d, rc = %d\n", __func__, PM8XXX_AMUX_MPP_4, err); return err; } if (i != 0) { if ((int)result.measurement > adc_max) adc_max = (int)result.measurement; else if ((int)result.measurement < adc_min) adc_min = (int)result.measurement; } else { adc_max = (int)result.measurement; adc_min = (int)result.measurement; } adc_total += (int)result.measurement; } return ((adc_total - adc_max - adc_min) / (CP_THM_ADC_SAMPLING_CNT - 2)) / 1000; }
int lge_pm_get_cable_info(struct chg_cable_info *cable_info) { char *type_str[] = {"NOT INIT", "MHL 1K", "U_28P7K", "28P7K", "56K", "100K", "130K", "180K", "200K", "220K", "270K", "330K", "620K", "910K", "OPEN"}; struct pm8xxx_adc_chan_result result; struct chg_cable_info *info = cable_info; struct chg_cable_info_table *table; int table_size = ARRAY_SIZE(pm8921_acc_cable_type_data); int acc_read_value = 0; int acc_read_value_data[5] = {0}; int i, j, rc; int count = 5; if (!info) { pr_err("lge_pm_get_cable_info: invalid info parameters\n"); return -1; } for (i = 0; i < count; i++) { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_12, ADC_MPP_1_AMUX6, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { /* reason: adc read timeout, assume it is open cable */ info->cable_type = CABLE_NONE; info->ta_ma = C_NONE_TA_MA; info->usb_ma = C_NONE_USB_MA; pr_err("[DEBUG] lge_pm_get_cable_info : adc read timeout \n"); } else { pr_err("lge_pm_get_cable_info: adc read error - %d\n", rc); } return rc; } acc_read_value_data[i] = (int)result.physical; pr_info("%s: acc_read_value - %d\n", __func__, (int)result.physical); for(j = 0; j < i; j++) { if(abs(acc_read_value_data[i] - acc_read_value_data[i-j-1]) > 100000) { count = 0; acc_read_value = 1800000; pr_info("%s: abnormal acc_read_value\n", __func__); break; } else acc_read_value = (int)result.physical; } mdelay(10); } info->cable_type = NO_INIT_CABLE; info->ta_ma = C_NO_INIT_TA_MA; info->usb_ma = C_NO_INIT_USB_MA; /* assume: adc value must be existed in ascending order */ for (i = 0; i < table_size; i++) { table = &pm8921_acc_cable_type_data[i]; if (acc_read_value <= table->threshhold) { info->cable_type = table->type; info->ta_ma = table->ta_ma; info->usb_ma = table->usb_ma; break; } } pr_info("\n\n[PM]Cable detected: %d(%s)(%d, %d)\n\n", acc_read_value, type_str[info->cable_type], info->ta_ma, info->usb_ma); return 0; }
/* LGE_CHANGE * Implement cable detection * 2011-11-09, [email protected] */ int lge_pm_get_cable_info(struct chg_cable_info *cable_info) { char *type_str[] = {"NOT INIT", "MHL 1K", "U_28P7K", "28P7K", "56K", "100K", "130K", "180K", "200K", "220K", "270K", "330K", "620K", "910K", "OPEN"}; struct pm8xxx_adc_chan_result result; struct chg_cable_info *info = cable_info; struct chg_cable_info_table *table; int table_size = ARRAY_SIZE(pm8921_acc_cable_type_data); int acc_read_value = 0; int i, rc; int count = 5; if (!info) { pr_err("lge_pm_get_cable_info: invalid info parameters\n"); return -1; } for (i = 0; i < count; i++) { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_12, ADC_MPP_1_AMUX6, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { /* reason: adc read timeout, assume it is open cable */ info->cable_type = CABLE_NONE; info->ta_ma = C_NONE_TA_MA; info->usb_ma = C_NONE_USB_MA; } pr_err("lge_pm_get_cable_info: adc read error - %d\n", rc); return rc; } acc_read_value = (int)result.physical; mdelay(10); } pr_info("%s: acc_read_value - %d\n", __func__, (int)result.physical); info->cable_type = NO_INIT_CABLE; info->ta_ma = C_NO_INIT_TA_MA; info->usb_ma = C_NO_INIT_USB_MA; /* assume: adc value must be existed in ascending order */ for (i = 0; i < table_size; i++) { if (lge_get_board_revno() > ADC_CHANGE_REV) table = &pm8921_acc_cable_type_data[i]; else table = &pm8921_acc_cable_type_data2[i]; if (acc_read_value <= table->threshhold) { info->cable_type = table->type; info->ta_ma = table->ta_ma; info->usb_ma = table->usb_ma; /* LGE_CHANGE * add field for debugging. * 2012-06-21 [email protected] */ info->adc = acc_read_value; info->threshould = table->threshhold; break; } } #ifdef CONFIG_SII8334_MHL_TX /* specific case: MHL gender */ if (GetMHLConnectedStatus()) { info->cable_type = CABLE_MHL_1K; info->ta_ma = C_MHL_1K_TA_MA; info->usb_ma = C_MHL_1K_USB_MA; } #endif pr_info("\n\n[PM]Cable detected: %d(%s)(%d, %d)\n\n", acc_read_value, type_str[info->cable_type], info->ta_ma, info->usb_ma); return 0; }
static int lge_hsd_probe(struct platform_device *pdev) { int ret = 0; struct max1462x_platform_data *pdata = pdev->dev.platform_data; struct hsd_info *hi; HSD_DBG("lge_hsd_probe"); hi = kzalloc(sizeof(struct hsd_info), GFP_KERNEL); if (NULL == hi) { HSD_ERR("Failed to allloate headset per device info\n"); return -ENOMEM; } platform_set_drvdata(pdev, hi); // initialize internal variables atomic_set(&hi->btn_state, HEADSET_BTN_INIT); atomic_set(&hi->is_3_pole_or_not, HEADSET_POLE_INIT); // set key code hi->key_code = pdata->key_code; // KEY_RESERVED(0), KEY_MEDIA(226), KEY_VOLUMEUP(115) or KEY_VOLUMEDOWN(114) // set GPIO number for each pin hi->gpio_mode = pdata->gpio_mode; hi->gpio_det = pdata->gpio_det; hi->gpio_swd = pdata->gpio_swd; // set delayed time for latency hi->latency_for_detection = msecs_to_jiffies(pdata->latency_for_detection); HSD_DBG("jiffies of hi->latency_for_detection : %u \n", hi->latency_for_detection); hi->latency_for_key = msecs_to_jiffies(pdata->latency_for_key); HSD_DBG("jiffies of hi->latency_for_key : %u \n", hi->latency_for_key); hi->adc_mpp_num = pdata->adc_mpp_num; HSD_DBG("hi->adc_mpp_num : %u \n", hi->adc_mpp_num); hi->adc_channel = pdata->adc_channel; HSD_DBG("hi->adc_channel : %u \n", hi->adc_channel); //LGE_CHANGE_S 20130710 ilda.jung[Audio] Disable not using GPIO #if !defined(CONFIG_MACH_APQ8064_AWIFI) // set gpio for an external LDO control if( pdata->external_ldo_mic_bias > 0 ) { hi->external_ldo_mic_bias = pdata->external_ldo_mic_bias; HSD_DBG("control an external LDO(GPIO# %u) for MIC BIAS", hi->external_ldo_mic_bias); } else { hi->external_ldo_mic_bias = 0; HSD_DBG("don't control an external LDO for MIC"); } // set callback function for an external LDO control if( pdata->set_headset_mic_bias!= NULL ) { hi->set_headset_mic_bias = pdata->set_headset_mic_bias; HSD_DBG("set a func pointer of an external LDO for MIC"); } else { pdata->set_headset_mic_bias = NULL; HSD_DBG("don't set a func pointer of an external LDO for MIC"); } #endif //LGE_CHANGE_E 20130710 ilda.jung[Audio] Disable not using GPIO mutex_init(&hi->mutex_lock); INIT_DELAYED_WORK(&hi->work, detect_work); INIT_DELAYED_WORK(&hi->work_for_key_pressed, button_pressed); INIT_DELAYED_WORK(&hi->work_for_key_released, button_released); // initialize gpio_mode // set gpio_mode high as a default, and set mode among high,low,high-Z after deciding 3 or 4 polarity ret = gpio_request(hi->gpio_mode, "gpio_mode"); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (gpio_mode) gpio_request\n", hi->gpio_mode); goto error_01; } ret = gpio_direction_output(hi->gpio_mode, 1); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mode) gpio_direction_input\n", hi->gpio_mode); goto error_01; } // initialize gpio_det ret = gpio_request(hi->gpio_det, "gpio_det"); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (gpio_det) gpio_request\n", hi->gpio_det); goto error_02; } ret = gpio_direction_input(hi->gpio_det); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (gpio_det) gpio_direction_input\n", hi->gpio_det); goto error_02; } // initialize gpio_swd ret = gpio_request(hi->gpio_swd, "gpio_swd"); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (gpio_swd) gpio_request\n", hi->gpio_swd); goto error_03; } ret = gpio_direction_input(hi->gpio_swd); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (gpio_swd) gpio_direction_input\n", hi->gpio_swd); goto error_03; } //LGE_CHANGE_S 20130710 ilda.jung[Audio] Disable not using GPIO #if !defined(CONFIG_MACH_APQ8064_AWIFI) // initialize external_ldo_mic_bias if( hi->external_ldo_mic_bias > 0 ) { ret = gpio_request(hi->external_ldo_mic_bias, "external_ldo_mic_bias"); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (external_ldo_mic_bias) gpio_request\n", hi->external_ldo_mic_bias); goto error_04; } ret = gpio_direction_output(hi->external_ldo_mic_bias, 0); if (ret < 0) { HSD_ERR("Failed to configure gpio%u (external_ldo_mic_bias) gpio_direction_input\n", hi->external_ldo_mic_bias); goto error_04; } HSD_DBG("hi->external_ldo_mic_bias value = %d \n", gpio_cansleep(hi->external_ldo_mic_bias) ? gpio_get_value_cansleep(hi->external_ldo_mic_bias) : gpio_get_value(hi->external_ldo_mic_bias)); } #endif //LGE_CHANGE_E 20130710 ilda.jung[Audio] Disable not using GPIO /* initialize irq of detection */ hi->irq_detect = gpio_to_irq(hi->gpio_det); HSD_DBG("hi->irq_detect = %d\n", hi->irq_detect); if (hi->irq_detect < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_detect; goto error_05; } ret = request_threaded_irq(hi->irq_detect, NULL, earjack_det_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq"); goto error_05; } ret = irq_set_irq_wake(hi->irq_detect, 1); if (ret < 0) { HSD_ERR("Failed to set irq_detect interrupt wake\n"); goto error_05; } /* initialize irq of gpio_key */ hi->irq_key = gpio_to_irq(hi->gpio_swd); HSD_DBG("hi->irq_key = %d\n", hi->irq_key); if (hi->irq_key < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_key; goto error_06; } ret = request_threaded_irq(hi->irq_key, NULL, button_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq"); goto error_06; } disable_irq(hi->irq_key); #if 0 ret = irq_set_irq_wake(hi->irq_key, 1); if (ret < 0) { HSD_ERR("Failed to set irq_key interrupt wake\n"); goto error_06; } #endif /* initialize switch device */ hi->sdev.name = pdata->switch_name; hi->sdev.print_state = lge_hsd_print_state; hi->sdev.print_name = lge_hsd_print_name; ret = switch_dev_register(&hi->sdev); if (ret < 0) { HSD_ERR("Failed to register switch device\n"); goto error_06; } /* initialize input device */ hi->input = input_allocate_device(); if (!hi->input) { HSD_ERR("Failed to allocate input device\n"); ret = -ENOMEM; goto error_07; } hi->input->name = pdata->keypad_name; hi->input->id.vendor = 0x0001; hi->input->id.product = 1; hi->input->id.version = 1; // [START] // headset tx noise { struct pm8xxx_adc_chan_result result; int acc_read_value = 0; int i, rc; int count = 3; for (i = 0; i < count; i++) { rc = pm8xxx_adc_mpp_config_read(hi->adc_mpp_num, hi->adc_channel, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { HSD_ERR("[DEBUG]adc read timeout \n"); } else { HSD_ERR("[DEBUG]adc read error - %d\n", rc); } } else { acc_read_value = (int)result.physical; HSD_DBG("%s: acc_read_value - %d\n", __func__, (int)result.physical); break; } } } // [END] /*input_set_capability(hi->input, EV_SW, SW_HEADPHONE_INSERT);*/ set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(EV_SW, hi->input->evbit); set_bit(hi->key_code, hi->input->keybit); set_bit(SW_HEADPHONE_INSERT, hi->input->swbit); set_bit(SW_MICROPHONE_INSERT, hi->input->swbit); input_set_capability(hi->input, EV_KEY, KEY_MEDIA); input_set_capability(hi->input, EV_KEY, KEY_VOLUMEUP); input_set_capability(hi->input, EV_KEY, KEY_VOLUMEDOWN); ret = input_register_device(hi->input); if (ret) { HSD_ERR("Failed to register input device\n"); goto error_08; } // to detect in initialization with eacjack insertion if( gpio_cansleep(hi->gpio_det) ) { if( !gpio_get_value_cansleep(hi->gpio_det) ) { #ifdef CONFIG_MAX1462X_USE_LOCAL_WORK_QUEUE queue_delayed_work(local_max1462x_workqueue, &(hi->work), 0); #else schedule_delayed_work(&(hi->work), 0); #endif } } else { if( !gpio_get_value_cansleep(hi->gpio_det) ) { #ifdef CONFIG_MAX1462X_USE_LOCAL_WORK_QUEUE queue_delayed_work(local_max1462x_workqueue, &(hi->work), 0); #else schedule_delayed_work(&(hi->work), 0); #endif } } return ret; error_08: input_free_device(hi->input); error_07: switch_dev_unregister(&hi->sdev); error_06: free_irq(hi->irq_key, 0); error_05: free_irq(hi->irq_detect, 0); //LGE_CHANGE_S 20130710 ilda.jung[Audio] Disable not using GPIO #if !defined(CONFIG_MACH_APQ8064_AWIFI) error_04: if( hi->external_ldo_mic_bias > 0 ) gpio_free(hi->external_ldo_mic_bias); #endif //LGE_CHANGE_E 20130710 ilda.jung[Audio] Disable not using GPIO error_03: gpio_free(hi->gpio_swd); error_02: gpio_free(hi->gpio_det); error_01: mutex_destroy(&hi->mutex_lock); kfree(hi); return ret; }
static void button_pressed(struct work_struct *work) { struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct hsd_info *hi = container_of(dwork, struct hsd_info, work_for_key_pressed); struct pm8xxx_adc_chan_result result; struct ear_3button_info_table *table; int acc_read_value=0, i=0, rc=0, table_size=ARRAY_SIZE(max1462x_ear_3button_type_data); HSD_DBG("button_pressed begin \n"); if( gpio_cansleep(hi->gpio_det) ) { if( gpio_get_value_cansleep(hi->gpio_det) ) { HSD_ERR("button_pressed but ear jack is plugged out already! just ignore the event.\n"); return; } } else { if( gpio_get_value(hi->gpio_det) ) { HSD_ERR("button_pressed but ear jack is plugged out already! just ignore the event.\n"); return; } } for (i = 0; i < table_size; i++) { rc = pm8xxx_adc_mpp_config_read(hi->adc_mpp_num, hi->adc_channel, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { HSD_ERR("button_pressed : adc read timeout[try count:%d]\n", i+1); } else { HSD_ERR("button_pressed : adc read error - rc:%d[try count:%d]\n", rc, i+1); } } else { acc_read_value = (int)result.physical; HSD_DBG("======= acc_read_value - %d [try count:%d] =======\n", (int)result.physical, i+1); if( acc_read_value > VDOWN_MAX ) { HSD_DBG("********** read again acc_read_value [try count:%d] **********\n", i+1); continue; } // if success, exit from loop break; } } for (i = 0; i < table_size; i++) { table = &max1462x_ear_3button_type_data[i]; // [AUDIO_BSP] 20130110, junday.lee, include min value '=' for 1 button earjack (ADC value= 0) if ((acc_read_value <= table->PERMISS_REANGE_MAX)&&(acc_read_value >= table->PERMISS_REANGE_MIN)) { atomic_set(&hi->btn_state, HEADSET_BTN_PRESSED); switch(table->ADC_HEADSET_BUTTON) { case KEY_MEDIA: input_report_key(hi->input, KEY_MEDIA, 1); HSD_DBG("********** KEY_MEDIA **********\n"); break; case KEY_VOLUMEUP: input_report_key(hi->input, KEY_VOLUMEUP, 1); HSD_DBG("********** KEY_VOLUMEUP **********\n"); break; case KEY_VOLUMEDOWN: input_report_key(hi->input, KEY_VOLUMEDOWN, 1); HSD_DBG("********** KEY_VOLUMEDOWN **********\n"); break; } table->PRESS_OR_NOT = 1; input_sync(hi->input); break; } } HSD_DBG("button_pressed end \n"); }
static long ncdiagd_power_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int ret = 0; void __user *pArg = (void __user *)arg; printk(KERN_INFO "[%s] cmd:%d",__func__, cmd); switch(cmd) { case IOCTL_PW_RG_LP_CTL: { unsigned char enable; unsigned char vreg_id; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; vreg_id = buf.req_buf[1]; printk(KERN_INFO "DIAG_PW_RG_LP_CTL enable:%x vreg_id:%x", enable, vreg_id); ret = nc_pm8xxx_lp_mode_control(PM8XXX_VERSION_8921, vreg_id, enable); } break; case IOCTL_PW_RG_CTL: { unsigned char enable; unsigned char vreg_id; unsigned int min_volt, max_volt; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; vreg_id = buf.req_buf[1]; min_volt = cvt_val(buf.req_buf[3]); min_volt += cvt_val(buf.req_buf[2]) * 100; min_volt *= 1000; max_volt = cvt_val(buf.req_buf[5]); max_volt += cvt_val(buf.req_buf[4]) * 100; max_volt *= 1000; printk(KERN_INFO "DIAG_PW_RG_CTL enable :%x vreg_id :%x", enable, vreg_id); printk(KERN_INFO " min_volt:%x max_volt:%x", min_volt, max_volt); ret = nc_pm8xxx_vreg_control(PM8XXX_VERSION_8921, enable, vreg_id, min_volt, max_volt); } break; case IOCTL_PW_RG_SET_LVL: { unsigned char vreg_id; unsigned int min_volt, max_volt; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } vreg_id = buf.req_buf[0]; min_volt = cvt_val(buf.req_buf[2]); min_volt += cvt_val(buf.req_buf[1]) * 100; min_volt *= 1000; max_volt = cvt_val(buf.req_buf[4]); max_volt += cvt_val(buf.req_buf[3]) * 100; max_volt *= 1000; printk(KERN_INFO "DIAG_PW_RG_SET_LVL vreg_id:%x min_volt:%d max_volt:%d", vreg_id, min_volt, max_volt); ret = nc_pm8xxx_vreg_set_level(PM8XXX_VERSION_8921, vreg_id, min_volt, max_volt); } break; case IOCTL_PW_VT_PLDWN_SW: { unsigned char enable; unsigned char vreg_id; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; vreg_id = buf.req_buf[1]; printk(KERN_INFO "DIAG_PW_RG_SMPS_PSK enable:%x vreg_id:%x", enable, vreg_id); ret = nc_pm8xxx_vreg_pull_down_switch(PM8XXX_VERSION_8921, vreg_id, enable); } break; case IOCTL_PW_CHG_COIN_SW: { struct pm8xxx_coincell_chg param; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } param.state = buf.req_buf[0]; param.voltage = PM8XXX_COINCELL_VOLTAGE_3p2V; param.resistor = PM8XXX_COINCELL_RESISTOR_800_OHMS; ret = pm8xxx_coincell_chg_config(¶m); printk(KERN_INFO "DIAG_PW_CHG_COIN_SW enable:%x", param.state); } break; case IOCTL_PW_CHG_BAT_EBL: { bool enable; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = (buf.req_buf[0]&0x01); ret = nc_pm8921_charger_enable(enable); printk(KERN_INFO "DIAG_PW_CHG_BAT_EBL enable:%x", enable); } break; case IOCTL_PW_CHG_DSBL: { unsigned char enable; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; enable = enable ? 0x00 : 0x01; ret = pm8921_disable_source_current(enable); printk(KERN_INFO "DIAG_PW_CHG_DSBL enable:%x", enable); } break; case IOCTL_PW_CHG_WCG_GET_STATE: { unsigned int rt_id = 0x00; unsigned int rt_status = 0x00; ioctl_pw_value_type buf; rt_id = PM8921_IRQ_BASE + PM8921_CABLE_IRQ; ret = nc_pm8921_get_rt_status(rt_id, &rt_status); if (ret != 0) { printk(KERN_ERR "nc_pm8921_get_rt_status failed \n"); return PM_ERR_FLAG__SBI_OPT_ERR; } buf.rsp_buf[0] = (u8)rt_status; if(copy_to_user((void *)pArg, &buf, sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_to_user failed"); return PM_ERR_FLAG__SBI_OPT_ERR; } printk(KERN_INFO "IOCTL_PW_CHG_WCG_GET_STATE rt_id:%x rt_status:%x", rt_id, rt_status); } break; case IOCTL_PW_CHG_WCG_SW: { ioctl_pw_value_type buf; struct pm_gpio param; int gpio_port; unsigned char enable = 0x00; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__SBI_OPT_ERR; } gpio_port = PM8921_GPIO_PM_TO_SYS(PM_DIAG_GPIO_32); param.direction = PM_GPIO_DIR_OUT; param.output_buffer = PM_GPIO_OUT_BUF_CMOS; param.output_value = 0; param.pull = PM_GPIO_PULL_NO; param.vin_sel = PM_GPIO_VIN_S4; param.out_strength = PM_GPIO_STRENGTH_LOW; param.function = PM_GPIO_FUNC_NORMAL; param.inv_int_pol = 0; param.disable_pin = 0; enable = buf.req_buf[0]; param.output_value = enable ? 0 : 1; ret = pm8xxx_gpio_config(gpio_port, ¶m); if (ret != 0) { printk(KERN_ERR "pm8xxx_gpio_config failed"); return PM_ERR_FLAG__SBI_OPT_ERR; } printk(KERN_INFO "IOCTL_PW_CHG_WCG_SW enable:%x param.output_value:%x ", enable, param.output_value); } break; case IOCTL_PW_CHG_VMAX_SET: { unsigned short voltage; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } voltage = buf.req_buf[1]; voltage += buf.req_buf[0] * 0x100; ret = nc_pm8921_chg_vmaxsel_set(voltage); printk(KERN_INFO "DIAG_PW_CHG_VMAX_SET voltage:%x", voltage); } break; case IOCTL_PW_CHG_IMAX_SET: { unsigned short cur_val; ioctl_pw_value_type buf; int ibat = 0; unsigned int iusb = 0; const int ibat_min = 325; const int ibat_max = 2000; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } cur_val = buf.req_buf[1]; cur_val += buf.req_buf[0] * 0x100; if (cur_val < ibat_min) { ibat = ibat_min; } else if (cur_val > ibat_max) { ibat = ibat_max; } else { ibat = (int)cur_val; } iusb = (unsigned int)(cur_val | PM8921_DIAG_IUSB_SET); pm8921_set_max_battery_charge_current(ibat); pm8921_charger_vbus_draw(iusb); printk(KERN_INFO "DIAG_PW_CHG_IMAX_SET cur_val:0x%04x", cur_val); } break; case IOCTL_PW_CHG_STATE_GET: { unsigned char chg_state = 0x00; ioctl_pw_value_type buf; ret = nc_pm8921_get_fsm_status((u64 *)&chg_state); buf.rsp_buf[0] = chg_state; if(copy_to_user((void *)pArg, &buf, sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_to_user failed"); return PM_ERR_FLAG__INVALID; } printk(KERN_INFO "DIAG_PW_CHG_STATE_GET chg_state:%x", chg_state); } break; case IOCTL_PW_CHG_USB_DSBL: { unsigned char enable; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; enable = enable ? 0x00 : 0x01; ret = nc_pm8921_chg_usb_suspend_enable(enable); printk(KERN_INFO "DIAG_PW_CHG_USB_DSBL enable:%x", enable); } break; case IOCTL_PW_ADC_RD_CHANNEL: { unsigned char analog_chnl, mpp_chnl; struct pm8xxx_adc_chan_result result; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } analog_chnl = buf.req_buf[0]; if (analog_chnl == CHANNEL_BATT_THERM) { analog_chnl = CHANNEL_BATT_THERM_UV; ret = pm8xxx_adc_read(analog_chnl, &result); } else if ((analog_chnl < PM8XXX_CHANNEL_MPP_SCALE1_IDX) || (analog_chnl == ADC_MPP_1_AMUX8 ) || (analog_chnl == ADC_MPP_1_AMUX3 ) || (analog_chnl == ADC_MPP_1_AMUX3_UV)) { ret = pm8xxx_adc_read(analog_chnl, &result); } else if ((analog_chnl >= PM8XXX_CHANNEL_MPP_SCALE1_IDX) && (analog_chnl <= ADC_MPP_1_ATEST_7 ) ) { mpp_chnl = analog_chnl - PM8XXX_CHANNEL_MPP_SCALE1_IDX; ret = pm8xxx_adc_mpp_config_read(mpp_chnl, CHANNEL_MPP_1, &result); } else if ((analog_chnl >= PM8XXX_CHANNEL_MPP_SCALE3_IDX) && (analog_chnl <= ADC_MPP_2_ATEST_7 ) ) { mpp_chnl = analog_chnl - PM8XXX_CHANNEL_MPP_SCALE3_IDX; ret = pm8xxx_adc_mpp_config_read(mpp_chnl, CHANNEL_MPP_2, &result); } else { printk(KERN_ERR "ADC_channel failed"); return PM_ERR_FLAG__FEATURE_NOT_SUPPORTED; } if(ret == PM_ERR_FLAG__SUCCESS) { if ((analog_chnl != CHANNEL_BATT_THERM) && (analog_chnl != ADC_MPP_1_AMUX8 ) && (analog_chnl != CHANNEL_MUXOFF ) && (analog_chnl != ADC_MPP_1_AMUX3 )) { if (result.physical != 0) { result.physical = div_u64(result.physical, 1000); } if (result.physical >= 0xFFFF) { result.physical = 0xFFFF; } } buf.rsp_buf[0] = (result.physical >> 8) & 0xff; buf.rsp_buf[1] = result.physical & 0xff; } if(copy_to_user((void *)pArg, &buf, sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_to_user failed"); return PM_ERR_FLAG__INVALID; } printk(KERN_INFO "DIAG_PW_ADC_RD_CHANNEL analog_chnl :%x", analog_chnl); printk(KERN_INFO " adc_read_val[0]:%x", (int)((result.physical >> 8) & 0xff)); printk(KERN_INFO " adc_read_val[1]:%x", (int)(result.physical & 0xff)); } break; case IOCTL_PW_SP_SMPLD_SW: { unsigned char enable; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; ret = pm8xxx_smpl_control(enable); printk(KERN_INFO "DIAG_PW_SP_SMPLD_SW enable:%x", enable); } break; case IOCTL_PW_SP_SMPLD_TM_SET: { unsigned char timer_set; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } timer_set = buf.req_buf[0]; ret = pm8xxx_smpl_set_delay(timer_set); printk(KERN_INFO "DIAG_PW_SP_SMPLD_TM_SET timer_set:%x", timer_set); } break; case IOCTL_PW_MPP_CNFDG_IPUT: { unsigned char mpp_port; unsigned char logi_level; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; logi_level = buf.req_buf[1]; ret = nc_pm8xxx_mpp_config_digital_in(PM8921_MPP_PM_TO_SYS(mpp_port), logi_level, PM8XXX_MPP_DIN_TO_INT); printk(KERN_INFO "DIAG_PW_MPP_CNFDG_IPUT mpp_port:%x logi_level:%x", mpp_port +1, logi_level); } break; case IOCTL_PW_MPP_CNFDG_OPUT: { unsigned char mpp_port; unsigned char logi_level; unsigned char out_ctl; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; logi_level = buf.req_buf[1]; out_ctl = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_digital_out(PM8921_MPP_PM_TO_SYS(mpp_port), logi_level, out_ctl); printk(KERN_INFO "DIAG_PW_MPP_CNFDG_OPUT mpp_port:%x logi_level:%x out_ctl:%x", mpp_port +1, logi_level, out_ctl); } break; case IOCTL_PW_MPP_CNFDG_IOPUT: { unsigned char mpp_port; unsigned char logi_level; unsigned char pull_set; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; logi_level = buf.req_buf[1]; pull_set = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_bi_dir(PM8921_MPP_PM_TO_SYS(mpp_port), logi_level, pull_set); printk(KERN_INFO "DIAG_PW_MPP_CNFDG_IOPUT mpp_port:%x logi_level:%x pull_set:%x", mpp_port +1, logi_level, pull_set); } break; case IOCTL_PW_MPP_CNFAN_IPUT: { unsigned char mpp_port; unsigned char ain_chn; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; ain_chn = buf.req_buf[1]; ret = nc_pm8xxx_mpp_config_analog_input(PM8921_MPP_PM_TO_SYS(mpp_port), ain_chn, PM8XXX_MPP_AOUT_CTRL_DISABLE); printk(KERN_INFO "DIAG_PW_MPP_CNFAN_IPUT mpp_port:%x ain_chn:%x", mpp_port + 1, ain_chn); } break; case IOCTL_PW_MPP_CNFAN_OPUT: { unsigned char mpp_port; unsigned char aout_level; unsigned char pm_onoff; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; aout_level = buf.req_buf[1]; pm_onoff = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_analog_output(PM8921_MPP_PM_TO_SYS(mpp_port), aout_level, pm_onoff); printk(KERN_INFO "DIAG_PW_MPP_CNFAN_OPUT mpp_port:%x aout_level:%x pm_onoff:%x", mpp_port +1 , aout_level, pm_onoff); } break; case IOCTL_PW_MPP_CNF_I_SINK: { unsigned char mpp_port; unsigned char sink_level; unsigned char pm_onoff; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; sink_level = buf.req_buf[1]; pm_onoff = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_current_sink(PM8921_MPP_PM_TO_SYS(mpp_port), sink_level, pm_onoff); printk(KERN_INFO "DIAG_PW_MPP_CNF_I_SINK mpp_port:%x sink_level:%x pm_onoff:%x", mpp_port + 1, sink_level, pm_onoff); } break; case IOCTL_PW_GPIO_CONFIG_SET: { ioctl_pw_value_type buf; struct pm_gpio param ; int gpio_port; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } gpio_port = PM8921_GPIO_PM_TO_SYS(buf.req_buf[0]); param.direction = buf.req_buf[1]; param.output_buffer = buf.req_buf[2]; param.output_value = buf.req_buf[3]; param.pull = buf.req_buf[4]; param.vin_sel = buf.req_buf[5]; param.out_strength = buf.req_buf[6]; param.function = buf.req_buf[7]; param.inv_int_pol = buf.req_buf[8]; param.disable_pin = buf.req_buf[9]; ret = pm8xxx_gpio_config(gpio_port, ¶m); printk(KERN_INFO "IOCTL_PW_GPIO_CONFIG_SET gpio_port :%x direction:%x output_buffer:%x", gpio_port, param.direction, param.output_buffer); printk(KERN_INFO " output_value:%x pull :%x vin_sel :%x", param.output_value, param.pull, param.vin_sel); printk(KERN_INFO " out_strength:%x function :%x inv_int_pol :%x", param.out_strength, param.function, param.inv_int_pol); printk(KERN_INFO " pin_disable :%x ", param.disable_pin); } break; case IOCTL_PW_GPIO_GET_STATE: { unsigned int gpio_id = 0x00; unsigned int gpio_state = 0x00; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } gpio_id = (unsigned int)buf.req_buf[0]; ret = nc_pm8921_gpio_get_state(gpio_id, &gpio_state); buf.rsp_buf[0] = (u8)gpio_state; if(copy_to_user((void *)pArg, &buf, sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_to_user failed"); return PM_ERR_FLAG__INVALID; } printk(KERN_INFO "DIAG_PW_GPIO_GET_STATE GPIO :%d value :%d", gpio_id+1, gpio_state); } break; case IOCTL_PW_PCT_OTP_STAGE_GET: { unsigned char itemp_stage = 0x00; ioctl_pw_value_type buf; ret = nc_pm8921_itemp_get_stage(&itemp_stage); buf.rsp_buf[0] = itemp_stage; if(copy_to_user((void *)pArg, &buf, sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_to_user failed"); return PM_ERR_FLAG__INVALID; } printk(KERN_INFO "DIAG_PW_PCT_OTP_STAGE_GET itemp_stage:%x", itemp_stage); } break; case IOCTL_PW_PCT_OTP_STG_OVD: { unsigned char enable; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; ret = nc_pm8921_itemp_stage_override(enable); printk(KERN_INFO "DIAG_PW_PCT_OTP_STG_OVD enable:%x", enable); } break; case IOCTL_PW_IR_RT_STATUS_GET: { unsigned int rt_id = 0x00; unsigned int rt_status = 0x00; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } rt_id = (unsigned int)buf.req_buf[0]; rt_id += PM8921_IRQ_BASE; nc_pm8921_get_rt_status(rt_id, &rt_status); buf.rsp_buf[0] = (u8)rt_status; if(copy_to_user((void *)pArg, &buf, sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_to_user failed"); return PM_ERR_FLAG__INVALID; } printk(KERN_INFO "DIAG_PW_IR_RT_STATUS_GET rt_id:%x rt_status:%x", rt_id, rt_status); } break; case IOCTL_PW8821_RG_LP_CTL: { unsigned char enable; unsigned char vreg_id; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; vreg_id = buf.req_buf[1]; printk(KERN_INFO "DIAG_PW8821_RG_LP_CTL enable:%x vreg_id:%x", enable, vreg_id); ret = nc_pm8xxx_lp_mode_control(PM8XXX_VERSION_8821, vreg_id, enable); } break; case IOCTL_PW8821_RG_CTL: { unsigned char enable; unsigned char vreg_id; unsigned int min_volt, max_volt; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; vreg_id = buf.req_buf[1]; min_volt = cvt_val(buf.req_buf[3]); min_volt += cvt_val(buf.req_buf[2]) * 100; min_volt *= 1000; max_volt = cvt_val(buf.req_buf[5]); max_volt += cvt_val(buf.req_buf[4]) * 100; max_volt *= 1000; printk(KERN_INFO "DIAG_PW8821_RG_CTL enable :%x vreg_id :%x", enable, vreg_id); printk(KERN_INFO " min_volt:%x max_volt:%x", min_volt, max_volt); ret = nc_pm8xxx_vreg_control(PM8XXX_VERSION_8821, enable, vreg_id, min_volt, max_volt); } break; case IOCTL_PW8821_RG_SET_LVL: { unsigned char vreg_id; unsigned int min_volt, max_volt; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } vreg_id = buf.req_buf[0]; min_volt = cvt_val(buf.req_buf[2]); min_volt += cvt_val(buf.req_buf[1]) * 100; min_volt *= 1000; max_volt = cvt_val(buf.req_buf[4]); max_volt += cvt_val(buf.req_buf[3]) * 100; max_volt *= 1000; printk(KERN_INFO "DIAG_PW8821_RG_SET_LVL vreg_id:%x min_volt:%x max_volt:%x", vreg_id, min_volt, max_volt); ret = nc_pm8xxx_vreg_set_level(PM8XXX_VERSION_8821, vreg_id, min_volt, max_volt); } break; case IOCTL_PW8821_VT_PLDWN_SW: { unsigned char enable; unsigned char vreg_id; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } enable = buf.req_buf[0]; vreg_id = buf.req_buf[1]; printk(KERN_INFO "DIAG_PW8821_RG_SMPS_PSK enable:%x vreg_id:%x", enable, vreg_id); ret = nc_pm8xxx_vreg_pull_down_switch(PM8XXX_VERSION_8821, vreg_id, enable); } break; case IOCTL_PW8821_MPP_CNFDG_IPUT: { unsigned char mpp_port; unsigned char logi_level; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; logi_level = buf.req_buf[1]; ret = nc_pm8xxx_mpp_config_digital_in(PM8821_MPP_PM_TO_SYS(mpp_port), logi_level, PM8XXX_MPP_DIN_TO_INT); printk(KERN_INFO "DIAG_PW8821_MPP_CNFDG_IPUT mpp_port:%x logi_level:%x", mpp_port, logi_level); } break; case IOCTL_PW8821_MPP_CNFDG_OPUT: { unsigned char mpp_port; unsigned char logi_level; unsigned char out_ctl; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; logi_level = buf.req_buf[1]; out_ctl = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_digital_out(PM8821_MPP_PM_TO_SYS(mpp_port), logi_level, out_ctl); printk(KERN_INFO "DIAG_PW8821_MPP_CNFDG_OPUT mpp_port:%x logi_level:%x out_ctl:%x", mpp_port, logi_level, out_ctl); } break; case IOCTL_PW8821_MPP_CNFDG_IOPUT: { unsigned char mpp_port; unsigned char logi_level; unsigned char pull_set; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; logi_level = buf.req_buf[1]; pull_set = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_bi_dir(PM8821_MPP_PM_TO_SYS(mpp_port), logi_level, pull_set); printk(KERN_INFO "DIAG_PW8821_MPP_CNFDG_IOPUT mpp_port:%x logi_level:%x pull_set:%x", mpp_port, logi_level, pull_set); } break; case IOCTL_PW8821_MPP_CNFAN_IPUT: { unsigned char mpp_port; unsigned char ain_chn; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; ain_chn = buf.req_buf[1]; ret = nc_pm8xxx_mpp_config_analog_input(PM8821_MPP_PM_TO_SYS(mpp_port), ain_chn, PM8XXX_MPP_AOUT_CTRL_DISABLE); printk(KERN_INFO "DIAG_PW8821_MPP_CNFAN_IPUT mpp_port:%x ain_chn:%x", mpp_port, ain_chn); } break; case IOCTL_PW8821_MPP_CNFAN_OPUT: { unsigned char mpp_port; unsigned char aout_level; unsigned char pm_onoff; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; aout_level = buf.req_buf[1]; pm_onoff = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_analog_output(PM8821_MPP_PM_TO_SYS(mpp_port), aout_level, pm_onoff); printk(KERN_INFO "DIAG_PW8821_MPP_CNFAN_OPUT mpp_port:%x aout_level:%x pm_onoff:%x", mpp_port, aout_level, pm_onoff); } break; case IOCTL_PW8821_MPP_CNF_I_SINK: { unsigned char mpp_port; unsigned char sink_level; unsigned char pm_onoff; ioctl_pw_value_type buf; if(copy_from_user(&buf,pArg,sizeof(ioctl_pw_value_type))) { printk(KERN_ERR "copy_from_user failed"); return PM_ERR_FLAG__INVALID; } mpp_port = buf.req_buf[0]; sink_level = buf.req_buf[1]; pm_onoff = buf.req_buf[2]; ret = nc_pm8xxx_mpp_config_current_sink(PM8821_MPP_PM_TO_SYS(mpp_port), sink_level, pm_onoff); printk(KERN_INFO "DIAG_PW8821_MPP_CNF_I_SINK mpp_port:%x sink_level:%x pm_onoff:%x", mpp_port, sink_level, pm_onoff); } break; case IOCTL_PW_HW_RESET: printk(KERN_INFO "DVE005_FACTORY_DIAG_FTM_ONLINE_RESET_MODE"); printk(KERN_DEBUG "[ncdiagd_power.c]%s: Goto arm_pm_restart() in \n", __func__ ); arm_pm_restart(0, NULL); break; default: printk(KERN_ERR "Invalid Parameter"); return PM_ERR_FLAG__INVALID; } return ret; }
void is_mhl_cable(struct work_struct *work) { struct pm8xxx_adc_chan_result result; int rc=0; int try_max=0; do { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_3, ADC_MPP_1_AMUX6, &result); try_max++; }while(rc && try_max<20); #ifdef MHL_DEBUG printk("%s: cable_mv %lld\n ", __func__, result.physical); #endif #if ((BOARD_VER>=TP10 && BOARD_VER<TP20) && (defined(CONFIG_MACH_MSM8960_EF45K) || defined(CONFIG_MACH_MSM8960_EF46L) || defined(CONFIG_MACH_MSM8960_EF47S))) if (!MHL_Get_Cable_State() && (mhlsii9244_adc_value > 15000 && mhlsii9244_adc_value< 50000)) #elif (BOARD_VER>=TP20 && (defined(CONFIG_MACH_MSM8960_EF45K) || defined(CONFIG_MACH_MSM8960_EF46L) || defined(CONFIG_MACH_MSM8960_EF47S))) if (!MHL_Get_Cable_State() && (mhlsii9244_adc_value> 22000 &&mhlsii9244_adc_value < 50000)) #else /*(defined(CONFIG_MACH_MSM8960_VEGAPVW) || defined(CONFIG_MACH_MSM8960_VEGAPKDDI))*/ if (!MHL_Get_Cable_State() && (mhlsii9244_adc_valuel< 300000)) #endif { sii9244_cfg_power(0); pantech_hdmi_cable_detect(1); schedule_delayed_work(&sii9244_cable_connect_work.work, msecs_to_jiffies(100)); mhlsii9244_adc_value = 0; } #if ((BOARD_VER>=TP10 && BOARD_VER<TP20) && (defined(CONFIG_MACH_MSM8960_EF45K) || defined(CONFIG_MACH_MSM8960_EF46L) || defined(CONFIG_MACH_MSM8960_EF47S))) else if (MHL_Get_Cable_State() && (result.physical < 15000 || result.physical > 50000)) #elif (BOARD_VER>=TP20 && (defined(CONFIG_MACH_MSM8960_EF45K) || defined(CONFIG_MACH_MSM8960_EF46L) || defined(CONFIG_MACH_MSM8960_EF47S))) else if (MHL_Get_Cable_State() && (result.physical < 22000 || result.physical > 50000)) #else /*(defined(CONFIG_MACH_MSM8960_VEGAPVW) || defined(CONFIG_MACH_MSM8960_VEGAPKDDI))*/ else if (MHL_Get_Cable_State() && (result.physical > 300000)) #endif { if ( get_mhl_status()== MHL_RSEN_LOW) { pantech_hdmi_cable_detect(0); MHL_On(0); // mhl_power_ctrl(0); MHL_En_Control(0) ;// switch-MHL MHL_Set_Cable_State(MHL_CABLE_DISCONNCET); #ifdef MHL_DEBUG printk(KERN_ERR "[SKY_MHL]%s MHL cable disConnect \n",__func__); #endif sii9244_cfg_power_init(); } } #if (BOARD_VER>=TP20 && (defined(CONFIG_MACH_MSM8960_EF45K) || defined(CONFIG_MACH_MSM8960_EF46L) || defined(CONFIG_MACH_MSM8960_EF47S))) if (!MHL_Get_Cable_State() && (mhlsii9244_adc_value<22000)) { if (is_mhl_mode()) { sii9244_cfg_power(0); pantech_hdmi_cable_detect(1); schedule_delayed_work(&sii9244_cable_connect_work.work, msecs_to_jiffies(100)); mhlsii9244_adc_value = 0; set_flag_mhl_mode(0); } } #endif return ; }
int lge_pm_get_cable_info(struct chg_cable_info *cable_info) { #if defined(CONFIG_MACH_APQ8064_L05E) || defined(CONFIG_MACH_APQ8064_GVAR_CMCC) char *type_str[] = {"NOT INIT", "MHL 1K", "U_28P7K", "28P7K", "56K", "100K", "130K", "180K", "200K", "220K", "270K", "330K", "620K", "910K", "OPEN"}; #else char *type_str[] = {"NOT INIT", "56K", "130K", "330K", "910K", "OPEN"}; #endif struct pm8xxx_adc_chan_result result; struct chg_cable_info *info = cable_info; struct chg_cable_info_table *table; int table_size = ARRAY_SIZE(pm8921_acc_cable_type_data); int acc_read_value = 0; int i, rc; int count = 5; if (!info) { pr_err("lge_pm_get_cable_info: invalid info parameters\n"); return -1; } for (i = 0; i < count; i++) { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_12, ADC_MPP_1_AMUX6, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { /* reason: adc read timeout, assume it is open cable */ info->cable_type = CABLE_OPEN; info->ta_ma = C_OPEN_TA_MA; info->usb_ma = C_OPEN_USB_MA; pr_err("[DEBUG] lge_pm_get_cable_info : adc read timeout \n"); } else { pr_err("lge_pm_get_cable_info: adc read error - %d\n", rc); } return rc; } acc_read_value += (int)result.physical; pr_info("%s: acc_read_value : %d\n", __func__, (int)result.physical); mdelay(10); } acc_read_value /= 5 ; info->cable_type = NO_INIT_CABLE; info->ta_ma = C_NO_INIT_TA_MA; info->usb_ma = C_NO_INIT_USB_MA; /* assume: adc value must be existed in ascending order */ for (i = 0; i < table_size; i++) { table = &pm8921_acc_cable_type_data[i]; #if defined(CONFIG_MACH_APQ8064_L05E) || defined(CONFIG_MACH_APQ8064_GVAR_CMCC) if (acc_read_value <= table->threshhold) #else if (acc_read_value >= table->adc_min && acc_read_value <= table->adc_max) #endif { info->cable_type = table->type; info->ta_ma = table->ta_ma; info->usb_ma = table->usb_ma; #ifdef CONFIG_MACH_APQ8064_GVAR_CMCC if (lge_bd_rev == HW_REV_D) { /* LGE_CHANGE_S, 2013-0314, [email protected] cable is being incorrectly recognized as factory cable */ if (info->cable_type == CABLE_56K || info->cable_type == CABLE_130K || info->cable_type == CABLE_910K) { info->cable_type = CABLE_OPEN; info->ta_ma = C_OPEN_USB_MA; info->usb_ma = C_OPEN_USB_MA; } /* LGE_CHANGE_E, 2013-0314, [email protected], this is temporary code */ } #endif pr_info("\n\n[PM]Cable detected: %d(%s)(%d, %d)\n\n", acc_read_value, type_str[i], info->ta_ma, info->usb_ma); break; } else if(acc_read_value > ADC_CABLE_910K_MAX && acc_read_value < ADC_CABLE_OPEN_MIN) { info->cable_type = CABLE_OPEN; info->ta_ma = C_OPEN_TA_MA; info->usb_ma = C_OPEN_USB_MA; } } #if defined(CONFIG_MACH_APQ8064_AWIFI) // Device will be reset in case of factory cable. // so, need to check again because somtimes the USB connector unstable. if (info->cable_type == CABLE_56K || info->cable_type == CABLE_130K || info->cable_type == CABLE_910K ) { table = &pm8921_acc_cable_type_data[info->cable_type]; for (i = 0; i < 3; i++) { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_12, ADC_MPP_1_AMUX6, &result); if ( rc < 0 ) { info->cable_type = CABLE_OPEN; info->ta_ma = C_OPEN_TA_MA; info->usb_ma = C_OPEN_USB_MA; return rc; } acc_read_value = (int)result.physical; printk(" Factory cable 2nd read adc : %d\n",acc_read_value); // if the ADC range out, cancel the factory cable detection. if ( acc_read_value < table->adc_min || acc_read_value > table->adc_max) { info->cable_type = CABLE_OPEN; info->ta_ma = C_OPEN_TA_MA; info->usb_ma = C_OPEN_USB_MA; return 0; } msleep(20); } } #endif return 0; }
static int sec_therm_get_adc_data(struct sec_therm_info *info) { int rc = 0; int adc_max = 0; int adc_min = 0; int adc_total = 0; int i, adc_data; #if defined (CONFIG_ARCH_MSM8226) struct qpnp_vadc_result results; for (i = 0; i < ADC_SAMPLING_CNT; i++) { rc = qpnp_vadc_read(therm_vadc_dev, P_MUX2_1_1, &results); if (rc) { pr_err("error reading AMUX %d, rc = %d\n", P_MUX2_1_1, rc); goto err; } adc_data = results.adc_code; //pr_err("########## reading P_MUX2_1_1 [rc = %d] [adc_code = %d]\n", rc, results.adc_code); #else struct pm8xxx_adc_chan_result result; #if defined (CONFIG_MACH_LT02) int system_rev = msm8930_get_board_rev(); #endif for (i = 0; i < ADC_SAMPLING_CNT; i++) { #if defined (CONFIG_MACH_LT02) if (system_rev >= 2) rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_3, ADC_MPP_1_AMUX6, &result); else rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_4, ADC_MPP_1_AMUX6, &result); #else rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_4, ADC_MPP_1_AMUX6, &result); #endif if (rc) { pr_err("error reading mpp %d, rc = %d\n", PM8XXX_AMUX_MPP_4, rc); goto err; } adc_data = (int)result.measurement; pr_err("reading PM8XXX_AMUX_MPP_4 [rc = %d] [measurement = %lld]\n", rc,result.measurement); #endif if (i != 0) { if (adc_data > adc_max) adc_max = adc_data; else if (adc_data < adc_min) adc_min = adc_data; } else { adc_max = adc_data; adc_min = adc_data; } adc_total += adc_data; } return (adc_total - adc_max - adc_min) / (ADC_SAMPLING_CNT - 2); err: return rc; } static int convert_adc_to_temper(struct sec_therm_info *info, unsigned int adc) { int low = 0; int high = 0; int mid = 0; int temp = 0; int temp2 = 0; if (!info->pdata->adc_table || !info->pdata->adc_arr_size) { /* using fake temp */ return 300; } high = info->pdata->adc_arr_size - 1; if (info->pdata->adc_table[low].adc >= adc) { temp = info->pdata->adc_table[low].temperature; goto convert_adc_to_temp_goto; } else if (info->pdata->adc_table[high].adc <= adc) { temp = info->pdata->adc_table[high].temperature; goto convert_adc_to_temp_goto; } while (low <= high) { mid = (low + high) / 2; if (info->pdata->adc_table[mid].adc > adc) { high = mid - 1; } else if (info->pdata->adc_table[mid].adc < adc) { low = mid + 1; } else { temp = info->pdata->adc_table[mid].temperature; goto convert_adc_to_temp_goto; } } temp = info->pdata->adc_table[high].temperature; temp2 = (info->pdata->adc_table[low].temperature - info->pdata->adc_table[high].temperature) * (adc - info->pdata->adc_table[high].adc); temp += temp2 / (info->pdata->adc_table[low].adc - info->pdata->adc_table[high].adc); convert_adc_to_temp_goto: return temp; }
int lge_pm_get_cable_info(struct chg_cable_info *cable_info) { char *type_str[] = {"NOT INIT", "MHL 1K", "U_28P7K", "28P7K", "56K", "100K", "130K", "180K", "200K", "220K", "270K", "330K", "620K", "910K", "OPEN"}; struct pm8xxx_adc_chan_result result; struct chg_cable_info *info = cable_info; struct chg_cable_info_table *table; int table_size = ARRAY_SIZE(pm8921_acc_cable_type_data); int acc_read_value = 0; int i, rc; int count = 5; int detected_cable=0; if (!info) { pr_err("lge_pm_get_cable_info: invalid info parameters\n"); return -1; } for (i = 0; i < count; i++) { rc = pm8xxx_adc_mpp_config_read(0x6, ADC_MPP_1_AMUX6, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { /* reason: adc read timeout, assume it is open cable */ info->cable_type = CABLE_NONE; info->ta_ma = C_NONE_TA_MA; info->usb_ma = C_NONE_USB_MA; } pr_err("lge_pm_get_cable_info: adc read error - %d\n", rc); return rc; } acc_read_value = (int)result.physical; pr_info("%s: acc_read_value - %d\n", __func__, (int)result.physical); mdelay(10); } info->cable_type = NO_INIT_CABLE; info->ta_ma = C_NO_INIT_TA_MA; info->usb_ma = C_NO_INIT_USB_MA; /* assume: adc value must be existed in ascending order */ for (i = 0; i < table_size; i++) { table = &pm8921_acc_cable_type_data[i]; if (acc_read_value <= table->threshhold) { info->cable_type = table->type; info->ta_ma = table->ta_ma; info->usb_ma = table->usb_ma; break; } } /* FIXME: Invalid information on cable_check*/ #if 0 detected_cable=get_detected_cable(); table = &pm8921_acc_cable_type_data[detected_cable]; info->cable_type = table->type; info->ta_ma = table->ta_ma; info->usb_ma = table->usb_ma; #endif pr_info("\n\n[PM]Cable detected: %d(%s)(%d, %d, %d)\n\n", acc_read_value, type_str[info->cable_type], info->ta_ma, info->usb_ma, detected_cable); return 0; }
int lge_pm_get_cable_info(struct chg_cable_info *cable_info) { char *type_str[] = {"NOT INIT", "MHL 1K", "U_28P7K", "28P7K", "56K", "100K", "130K", "180K", "200K", "220K", "270K", "330K", "620K", "910K", "OPEN"}; struct pm8xxx_adc_chan_result result; struct chg_cable_info *info = cable_info; struct chg_cable_info_table *table; int table_size = ARRAY_SIZE(pm8921_acc_cable_type_data); int acc_read_value = 0; int i, rc; int count = 5; if (!info) { pr_err("lge_pm_get_cable_info: invalid info parameters\n"); return -1; } for (i = 0; i < count; i++) { rc = pm8xxx_adc_mpp_config_read(PM8XXX_AMUX_MPP_12, ADC_MPP_1_AMUX6, &result); if (rc < 0) { if (rc == -ETIMEDOUT) { /* reason: adc read timeout, assume it is open cable */ info->cable_type = CABLE_NONE; info->ta_ma = C_NONE_TA_MA; info->usb_ma = C_NONE_USB_MA; pr_err("[DEBUG] lge_pm_get_cable_info : adc read timeout \n"); } else { pr_err("lge_pm_get_cable_info: adc read error - %d\n", rc); } return rc; } acc_read_value = (int)result.physical; pr_info("%s: acc_read_value - %d\n", __func__, (int)result.physical); mdelay(10); } info->cable_type = NO_INIT_CABLE; info->ta_ma = C_NO_INIT_TA_MA; info->usb_ma = C_NO_INIT_USB_MA; //[email protected] 20121122 Adc value is changed for Rev A, B, C of GV DCM. #if defined(CONFIG_MACH_APQ8064_GVDCM) if(lge_get_board_revno() <= HW_REV_C) for(i = 0; i <= CABLE_NONE;i++) pm8921_acc_cable_type_data[i].threshhold = pm8921_acc_cable_adc_data_gvdcm[i]; #endif //[email protected] 20121122 Adc value is changed for Rev A, B, C of GV DCM. /* assume: adc value must be existed in ascending order */ for (i = 0; i < table_size; i++) { table = &pm8921_acc_cable_type_data[i]; if (acc_read_value <= table->threshhold) { info->cable_type = table->type; info->ta_ma = table->ta_ma; info->usb_ma = table->usb_ma; break; } } pr_info("\n\n[PM]Cable detected: %d(%s)(%d, %d)\n\n", acc_read_value, type_str[info->cable_type], info->ta_ma, info->usb_ma); return 0; }