Пример #1
0
static void kp_search_key(struct kp *kp)
{
	int value, i;

	if (key_param[0]) { //virtual key mode
		for (i=2; i<kp->chan_num; i++) {
			value = get_adc_sample(kp->chan[i]);
			if (value < 0) {
				;
			} else {
				if ((value >= 1023 / 2 - ADC_VALUE * 2) && (value <= 1023 / 2 + ADC_VALUE * 2))
					kp->key_valid[i] = 0;
				else
					kp->key_valid[i] = 1;
				kp->key_value[i] = value;
			}
		}
	} else { //normal key mode
		//channel 2
		value = get_adc_sample(kp->chan[2]);
		if (value < 0) {
			;
		} else {
			if (value >= 1023 - ADC_KEY)
				kp->key_code[2] = KEY_RIGHT;
			else if (value <= 0 + ADC_KEY)
				kp->key_code[2] = KEY_LEFT;
			else
				kp->key_code[2] = 0;
		}

		//channel 3
		value = get_adc_sample(kp->chan[3]);
		if (value < 0) {
			;
		} else {
			if (value >= 1023 - ADC_KEY)
				kp->key_code[3] = KEY_DOWN;
			else if (value <= 0 + ADC_KEY)
				kp->key_code[3] = KEY_UP;
			else
				kp->key_code[3] = 0;
		}
	}

	//channel 4
	value = get_adc_sample(kp->chan[4]);
	if (value < 0) {
		;
	} else {
		if (value >= 0 && value <= (9 + 40))
			kp->key_code[4] = KEY_SPACE;
		else if (value >= (392 - 40) && value <= (392 + 40))
			kp->key_code[4] = KEY_ENTER;
		else
			kp->key_code[4] = 0;
	}

	return 0;
}
Пример #2
0
int saradc_ts_service(int cmd)
{
	int value = -1;
	
	switch (cmd) {
	case CMD_GET_X:
		//set_sample_sw(CHAN_YP, X_SW);
		value = get_adc_sample(CHAN_YP);
		set_sample_sw(CHAN_XP, Y_SW); // preset for y
		break;

	case CMD_GET_Y:
		//set_sample_sw(CHAN_XP, Y_SW);
		value = get_adc_sample(CHAN_XP);
		break;

	case CMD_GET_Z1:
		set_sample_sw(CHAN_XP, Z1_SW);
		value = get_adc_sample(CHAN_XP);
		break;

	case CMD_GET_Z2:
		set_sample_sw(CHAN_YN, Z2_SW);
		value = get_adc_sample(CHAN_YN);
		break;

	case CMD_GET_PENDOWN:
		value = !detect_level();
		set_sample_sw(CHAN_YP, X_SW); // preset for x
		break;
	
	case CMD_INIT_PENIRQ:
		enable_detect_pullup();
		enable_detect_sw();
		value = 0;
		printk(KERN_INFO "init penirq ok\n");
		break;

	case CMD_SET_PENIRQ:
		enable_detect_pullup();
		enable_detect_sw();
		value = 0;
		break;
		
	case CMD_CLEAR_PENIRQ:
		disable_detect_pullup();
		disable_detect_sw();
		value = 0;
		break;

	default:
		break;		
	}
	
	return value;
}
Пример #3
0
static void scan_joystick(struct kp *kp, int channel)
{
	int value;
	long int js_value;

	//for (i=0; i<kp->chan_num; i++) {
	value = get_adc_sample(kp->chan[channel]);
	if (value >= 0) {
		if ((value >= 1023 / 2 - ADC_VALUE * 2) && (value <= 1023 / 2 + ADC_VALUE * 2)) {
			kp->js_value[channel] = 0;
		} else {
			js_value = value;
			if (channel == 0) {
				js_value = 1023 - js_value;
			}
			if (channel == 0 || channel == 1 || channel == 2 || channel == 3) {	
				if (js_value < 20)
					js_value = -256;
				else if (js_value > 1000)
					js_value = 255;
				else
					js_value = (js_value - 512) / 2;
				//printk("---------------------- %i js_value = %d -------------------\n", i, js_value);
			}
			kp->js_value[channel] = js_value;
		}
	}
	return 0;
}
Пример #4
0
/*following is test code to test ADC & key pad*/
static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	if(argc > 2)
		goto usage;
	
	u32 nDelay = 0xffff;
	int nKeyVal = 0;
	int nCnt = 0;
	char *endp;
	int nMaxCnt;
	int adc_chan = 0; //m8 adc channel 0;m6 adc channel 4
	if(2 == argc)
		nMaxCnt	= simple_strtoul(argv[1], &endp, 10);
	else
		nMaxCnt = 10;

	saradc_enable();
	while(nCnt < nMaxCnt)
	{
		udelay(nDelay);
		nKeyVal = get_adc_sample(adc_chan);
		if(nKeyVal > 1021)
			continue;
		
		printf("SARADC CH-4 Get key : %d [%d]\n", nKeyVal,(100*nKeyVal)/1024);
		nCnt++;
	}
	saradc_disable();

	return 0;
	
usage:
	return cmd_usage(cmdtp);
}
inline int get_key()
{
    int adc_val = get_adc_sample(4);
    printf("get_adc_sample(4): 0x%x\n", adc_val);
    //return(((adc_val >= 0x320) && (adc_val < 0x370)) ? 1 : 0);
    return((adc_val < 0x60) ? 1 : 0);
}
Пример #6
0
static int  saradc_internal_cal(struct saradc *saradc)
{
	int i;
	int voltage[] = {CAL_VOLTAGE_1, CAL_VOLTAGE_2, CAL_VOLTAGE_3, CAL_VOLTAGE_4, CAL_VOLTAGE_5};
	int nominal[INTERNAL_CAL_NUM] = {0, 256, 512, 768, 1023};
	int val[INTERNAL_CAL_NUM];

//	set_cal_mux(MUX_CAL);
//	enable_cal_res_array();
	for (i=0; i<INTERNAL_CAL_NUM; i++) {
		set_cal_voltage(voltage[i]);
		msleep(20);
		val[i] = get_adc_sample(CHAN_7);
		if (val[i] < 0) {
			return -1;
		}
	}
	saradc->ref_val = val[2];
	saradc->ref_nominal = nominal[2];
	saradc->coef = (nominal[3] - nominal[1]) << 12;
	saradc->coef /= val[3] - val[1];
	printk("saradc calibration: ref_val = %d\n", saradc->ref_val);
	printk("saradc calibration: ref_nominal = %d\n", saradc->ref_nominal);
	printk("saradc calibration: coef = %d\n", saradc->coef);

	return 0;
}
Пример #7
0
static int get_charging_percentage(void)
{
	int adc = get_adc_sample(5);//get_bat_adc_value();
	int table_size = sizeof(bat_charge_value_table)/sizeof(bat_charge_value_table[0]);
	
	return get_bat_percentage(adc, bat_charge_value_table, bat_level_table, table_size);
}
Пример #8
0
static int  saradc_internal_cal(struct calibration *cal)
{
	return -1;
	
	int i;
	int voltage[4] = {CAL_0P55V, CAL_1P10V, CAL_1P65V, CAL_2P20V};

	cal->ref = 0;
	(cal+1)->ref = 170;
	(cal+2)->ref = 341;
	(cal+3)->ref = 511;
	(cal+4)->ref = 684;
	(cal+5)->ref = 1023;
	
	set_cal_mux(MUX_CAL);
	enable_cal_res_array();	
	for (i=1; i<5; i++) {
		set_cal_voltage(voltage[i]);
		(cal+i)->val = get_adc_sample(-1);
		if ((cal+i)->val < 0) {
			printk(KERN_INFO "saradc calibration fail\n");
			return -1;
		}
	}
	
	printk(KERN_INFO "saradc calibration ok\n");
	return 0;
}
Пример #9
0
void keypress_test(void)
{
  /*following is test code to test ADC & key pad*/
  int i;
	int count = sizeof(g_key_K1_info)/sizeof(struct adckey_info);
	int nKeyVal = 0;
	int nCnt = 0;
  printf("waiting for keypress test..\npress key \'sw3\' 3 times please...\n");
	saradc_enable();	
	while(nCnt < 3)
	{
		udelay(KEY_DELAY_US);
		nKeyVal = get_adc_sample(4);
		if(nKeyVal > 1000)
			continue;
		for(i = 0; i < count; i++){
			int v = g_key_K1_info[i].value;
			if(nKeyVal >= v && nKeyVal <= (v + g_key_K1_info[i].tolerance)){
				printf("key:%s pressed.\n",g_key_K1_info[i].key);
				break;
			}
		}
		if(i >= count)
			printf("unknown key pressed. keyvalue=%d\n",nKeyVal);
		nCnt++;
		for(i = 0; i < 100; i++)
			udelay(KEY_DELAY_US);
	}
	saradc_disable();
}
static int get_bat_vol(void)
{
#ifdef CONFIG_SARADC_AM
    return get_adc_sample(5);
#else
        return 0;
#endif
}
Пример #11
0
inline int any_key_pressed()
{
    int adc_val = get_adc_sample(4);
    //printf("get_adc_sample(4): 0x%x\n", adc_val);
    // no key pressed 0x3fd
    //return((((adc_val >= 0x0) && (adc_val < 0x3c0)) | powerkey_scan()) ? 1 : 0);
    return(((adc_val >= 0x0) && (adc_val < 0x3c0)) ? 1 : 0);
}
Пример #12
0
/*
 *	Get Vhigh when BAT_SEL(GPIOA_22) is High.
 *	Get Vlow when BAT_SEL(GPIOA_22) is Low.
 *	I = Vdiff / 0.02R
 *	Vdiff = Vhigh - Vlow
 */
static inline int measure_current(void)
{
	int val, Vh, Vl, Vdiff;
	set_gpio_mode(GPIOA_bank_bit0_27(22), GPIOA_bit_bit0_27(22), GPIO_OUTPUT_MODE);
	set_gpio_val(GPIOA_bank_bit0_27(22), GPIOA_bit_bit0_27(22), 1);
	msleep(2);
	Vl = get_adc_sample(5) * (2 * 2500000 / 1023);
	printf("%s: Vh is %duV.\n", __FUNCTION__, Vh);
	set_gpio_mode(GPIOA_bank_bit0_27(22), GPIOA_bit_bit0_27(22), GPIO_OUTPUT_MODE);
	set_gpio_val(GPIOA_bank_bit0_27(22), GPIOA_bit_bit0_27(22), 0);
	msleep(2);
	Vh = get_adc_sample(5) * (2 * 2500000 / 1023);
	printf("%s: Vl is %duV.\n", __FUNCTION__, Vl);
	Vdiff = Vh - Vl;
	val = Vdiff * 50;
	printf("%s: get from adc is %duA.\n", __FUNCTION__, val);
	return val;
}
Пример #13
0
unsigned int get_cpu_temp(int tsc,int flag)
{
    if (flag)
        set_trimming(tsc & 0x0f);
    else
        set_trimming(8);
    if(!IS_MESON_M8_CPU)
        set_trimming1(tsc>>4);
    return  get_adc_sample(6);
}
Пример #14
0
/*
 *	When BAT_SEL(GPIOA_22) is High Vbat=Vadc*2
 */
static inline int measure_voltage(void)
{
	int val;
	msleep(2);
	set_gpio_mode(GPIOA_bank_bit0_27(22), GPIOA_bit_bit0_27(22), GPIO_OUTPUT_MODE);
	set_gpio_val(GPIOA_bank_bit0_27(22), GPIOA_bit_bit0_27(22), 1);
	val = get_adc_sample(5) * (2 * 2500000 / 1023);
	printf("%s: get from adc is %duV.\n", __FUNCTION__, val);
	return val;
}
Пример #15
0
inline int get_key()
{
    int adc_val = get_adc_sample(4);
    int ret=-1;
    printf("get_adc_sample(4): 0x%x\n", adc_val);
    if(0x60<adc_val&&adc_val<0xb0)
    	ret=1; //vol-
    else if(0xe0<adc_val&&adc_val<0x130)
    	ret=2;//vol+
    return ret;
    //return(((adc_val >= 0x50) && (adc_val < 0x100)) ? 1 : 0);
}
Пример #16
0
static void scan_joystick_touchmapping(struct kp *kp, int channel)
{
	int value;

	value = get_adc_sample(kp->chan[channel]);
	if (value >= 0) {
		if ((value >= 1023 / 2 - MID_BLIND) && (value <= 1023 / 2 + MID_BLIND)) {
			kp->key_valid[channel] = 0;
		} else {
			kp->key_valid[channel] = 1;
		}
		kp->key_value[channel] = value;
	}

	return 0;
}
Пример #17
0
static void scan_android_key(struct kp *kp)
{
	int value;

	//channel 4
	value = get_adc_sample(kp->chan[4]);
	if (value >= 0) {
		if (value >= (150 - 40) && value <= (150 + 40))
			kp->key_code[4] = KEY_VOLUMEDOWN;
		else if (value >= (275 - 40) && value <= (275 + 40))
			kp->key_code[4] = KEY_VOLUMEUP;
		else
			kp->key_code[4] = 0;
	}

	return 0;
}
Пример #18
0
static void light_sensor_dev_poll(struct input_polled_dev *dev)
{
    struct input_dev *input_dev = dev->input;
    int adc_val, i;

    adc_val = get_adc_sample(6);
    for (i = 0; i < LUX_LEVEL; i++) {
        if (adc_val < sAdcValues[i])
            break;
    }

    if (ls_info.lux_level != i) {
        ls_info.lux_level = i;
        input_report_abs(input_dev, ABS_X, ls_info.lux_level);
        input_sync(input_dev);

        //printk(KERN_INFO "light_sensor: light_sensor_dev_poll lux_level=%d adc_val=%d\n", ls_info.lux_level, adc_val);
    }
}
Пример #19
0
static int hp_det_adc_value(struct aml_audio_private_data *p_aml_audio)
{
    int ret,hp_value,hp_val_sum,loop_num;
    hp_val_sum = 0;
    loop_num = 0;
    unsigned int mic_ret = 0;

    while(loop_num < 8){
        hp_value = get_adc_sample(p_aml_audio->hp_adc_ch);
        if(hp_value <0){
            printk("hp detect get error adc value!\n");
            continue;
        }
        hp_val_sum += hp_value;
        loop_num ++;
        msleep(15);
    }
    hp_val_sum = hp_val_sum >> 3;

    if(hp_val_sum >= p_aml_audio->hp_val_h){
        ret = 0;
    }else if((hp_val_sum <= (p_aml_audio->hp_val_l))&& hp_val_sum >=0){
        ret = 1;
        if(p_aml_audio->mic_det){
            if(hp_val_sum <=  p_aml_audio->mic_val){
                mic_ret = 8;
                ret |= mic_ret;
            }
        }
    }else{
        ret = 2;
        if(p_aml_audio->mic_det){
            ret = 0;
            mic_ret = 8;
            ret |= mic_ret;
        }

    }

    return ret;
}
Пример #20
0
static void scan_joystick(struct kp *kp, int channel)
{
	int value;
	long int js_value;

	//for (i=0; i<kp->chan_num; i++) {
	value = get_adc_sample(kp->chan[channel]);
	if (value >= 0) {
		if ((value >= 1023 / 2 - MID_BLIND) && (value <= 1023 / 2 + MID_BLIND)) {
			kp->js_value[channel] = 0;
		} else {
			js_value = value;
			if (channel == 1 || channel == 2 || channel == 3) {
				js_value = 1023 - js_value;
			}
			if (channel == 0 || channel == 1 || channel == 2 || channel == 3) {	
				if (js_value >= 512)
					js_value = (((js_value - JX2) * JX1 / 100 + JX2) - 512) / 2;
				else
					js_value = -((((1023 - js_value) - JX2) * JX1 / 100 + JX2) - 512) / 2;
				if (js_value <= -256)
					js_value = -256;
				else if (js_value >= 255)
					js_value = 255;
				/*
				if (js_value <= MINEDG_BLIND)
					js_value = -256;
				else if (js_value >= MAXEDG_BLIND)
					js_value = 255;
				else
					js_value = (js_value - 512) / 2;
				*/
				//printk("---------------------- %i js_value = %d -------------------\n", i, js_value);
			}
			kp->js_value[channel] = js_value;
		}
	}
	return 0;
}
Пример #21
0
static int kp_search_key(struct kp *kp)
{
	struct adc_key *key;
	int value, i, j;

	for (i=0; i<kp->chan_num; i++) {
		value = get_adc_sample(kp->chan[i]);
		if (value < 0) {
			continue;
		}
		key = kp->key;
		for (j=0; j<kp->key_num; j++) {
			if ((key->chan == kp->chan[i])
			&& (value >= key->value - key->tolerance)
			&& (value <= key->value + key->tolerance)) {
				return key->code;
			}
			key++;
		}
	}

	return 0;
}
Пример #22
0
	case CMD_CLEAR_PENIRQ:
		disable_detect_pullup();
		disable_detect_sw();
		value = 0;
		break;

	default:
		break;		
	}
	
	return value;
}

static ssize_t saradc_ch0_show(struct class *cla, struct class_attribute *attr, char *buf)
{
    return sprintf(buf, "%d\n", get_adc_sample(0));
}
static ssize_t saradc_ch1_show(struct class *cla, struct class_attribute *attr, char *buf)
{
    return sprintf(buf, "%d\n", get_adc_sample(1));
}
static ssize_t saradc_ch2_show(struct class *cla, struct class_attribute *attr, char *buf)
{
    return sprintf(buf, "%d\n", get_adc_sample(2));
}
static ssize_t saradc_ch3_show(struct class *cla, struct class_attribute *attr, char *buf)
{
    return sprintf(buf, "%d\n", get_adc_sample(3));
}
static ssize_t saradc_ch4_show(struct class *cla, struct class_attribute *attr, char *buf)
{
Пример #23
0
inline int get_key_value(void)
{
	return get_adc_sample(4);
}
Пример #24
0
inline int get_key()
{
    int adc_val = get_adc_sample(4);
    //printf("get_adc_sample(4): 0x%x\n", adc_val);
    return(((adc_val >= 0) && (adc_val < 900)) ? 1 : 0);
}
void kp_timer_sr(unsigned long data)
{
    struct kp *kp_data=(struct kp *)data;

#if 1
    kp_work(kp_data);

    if (kp_data->led_control ){
	if (timer_count>0)
	{
		timer_count++;
	}
	if (50 == timer_count){
		kp_data->led_control_param[0] = 0;
		timer_count = kp_data->led_control(kp_data->led_control_param);
	}
    }
#else
    unsigned int result;
    result = get_adc_sample();
    if (result>=0x3e0){
        if (kp_data->cur_keycode != 0){
            input_report_key(kp_data->input,kp_data->cur_keycode, 0);	
            kp_data->cur_keycode = 0;
		        printk("adc ch4 sample = %x, keypad released.\n", result);
        }
    }
	else if (result>=0x0 && result<0x60 ) {
		if (kp_data->cur_keycode!=KEY_HOME){
    	  kp_data->cur_keycode = KEY_HOME;
    	  input_report_key(kp_data->input,kp_data->cur_keycode, 1);	
    	  printk("adc ch4 sample = %x, keypad pressed.\n", result);
		}
    }
	else if (result>=0x110 && result<0x170 ) {
		if (kp_data->cur_keycode!=KEY_ENTER){
    	  kp_data->cur_keycode = KEY_ENTER;
    	  input_report_key(kp_data->input,kp_data->cur_keycode, 1);	
    	  printk("adc ch4 sample = %x, keypad pressed.\n", result);
		}
    }
	else if (result>=0x240 && result<0x290 ) {
		if (kp_data->cur_keycode!= KEY_LEFTMETA ){
    	  kp_data->cur_keycode = KEY_LEFTMETA;
    	  input_report_key(kp_data->input,kp_data->cur_keycode, 1);	
    	  printk("adc ch4 sample = %x, keypad pressed.\n", result);
		}
    }
	else if (result>=0x290 && result<0x380 ) {
		if (kp_data->cur_keycode!= KEY_TAB ){
    	  kp_data->cur_keycode = KEY_TAB;
    	  input_report_key(kp_data->input,kp_data->cur_keycode, 1);	
    	  printk("adc ch4 sample = %x, keypad pressed.\n", result);
    }
    }
    else{
		printk("adc ch4 sample = unknown key %x, pressed.\n", result);
    }
#endif
    mod_timer(&kp_data->timer,jiffies+msecs_to_jiffies(25));
}
Пример #26
0
static inline int get_bat_vol(void)
{
    return get_adc_sample(5);
}
Пример #27
0
static int tomtomgo_decide_battery(void)
{
	struct clk *clk;
	int i;
	unsigned long adctsc, adccon;
	unsigned long battery, reference, voltage;

	/* cannot check battery when charging... */
	if (IO_GetInput(ACPWR)) return 1;

	clk = clk_get(NULL, "adc");
	if (!clk)
		return 1;

	/* Save touch screen & ADC registers */
	adctsc = __raw_readl(S3C2410_ADCTSC);
	adccon = __raw_readl(S3C2410_ADCCON);

	/* Activate reference voltage source */
	if (IO_HaveADCAIN4Ref())
	IO_Activate(AIN4_PWR);

	/* Enable clock and let it settle a bit */
	clk_enable(clk);
	mdelay(10);

	/* Write my values */
	__raw_writel(my_adctsc, S3C2410_ADCTSC);
	__raw_writel(my_adccon, S3C2410_ADCCON);

	/* Battery and reference voltages are averaged over 10 samples. */
	battery = reference = 0;

	for (i = 0; i < NUM_VOLTAGE_SAMPLES; i++) 
	{
		battery += get_adc_sample(0);

		if (IO_HaveADCAIN4Ref())
			reference += get_adc_sample(4);
	}

	/* Calculate real battery voltage */
	// 10 + 12 = 22 bits, within range
	if (IO_HaveADCAIN4Ref())
		battery = (battery * ain4_refraw_calc) / (reference);
	else
		battery = battery / NUM_VOLTAGE_SAMPLES;

#ifdef BASIC_BATTERY_ADC_CALIBRATION
	if ( use_basic_battery_adc_calibration ) {
		voltage = CALIBRATE_SAMPLE(battery, adc_cal_offset, BATT_ADC_CAL_DIFF_VOLTAGE, adc_cal_diff, BATT_ADC_CAL_LOW_VOLTAGE);
	}
	else {
		// 12 + 12 = 24 bits, in range
		voltage = (battery * IO_GetADCREFVoltage()) / IO_GetADCRange(); // fast divide by 2^ number
		// 12 + 14 + 5 = 31 bits, in range
		voltage = (voltage * adc_factor * IO_GetBattVoltNumerator()) / (4000 * IO_GetBattVoltDenomenator());
		voltage += adc_offset;
	}
	//printk("%s: battery=%lu, reference=%lu, voltage=%lu", __func__, battery, reference, voltage);
#else
	// 12 + 12 = 24 bits, in range
	voltage = (battery * IO_GetADCREFVoltage()) / IO_GetADCRange(); // fast divide by 2^ number
	// 12 + 14 + 5 = 31 bits, in range
	voltage = (voltage * adc_factor * IO_GetBattVoltNumerator()) / (4000 * IO_GetBattVoltDenomenator());
	voltage += adc_offset;
#endif

	DBG("battery=%lu, reference=%lu, voltage=%lu", battery, reference, voltage);

	/* disable clock and restore original register contents */
	__raw_writel(adccon, S3C2410_ADCCON);
	__raw_writel(adctsc, S3C2410_ADCTSC);

	clk_disable(clk);
	clk_put(clk);

	if (IO_HaveADCAIN4Ref())
	IO_Deactivate(AIN4_PWR);

	if (IO_HaveBatteryCalibration()) {
		/* factory battery calibration allows a lower margin */
		return (voltage >= (3500 + 50)) ? 1 : 0;
	} else {
		if ( IO_GetModelId() == GOTYPE_RIDER5 ) {
			return (voltage >= (3500 + 50)) ? 1 : 0;
		}
		/* older devices have a wider measurement margin */
		return (voltage >= (3500 + 150)) ? 1 : 0;
	}
}
inline int get_source_key()
{
    int adc_val = get_adc_sample(1);
    printf("get_source_key: 0x%x\n", adc_val);
    return (((adc_val > 270) && (adc_val < 380)) ? 1 : 0);
}
Пример #29
0
static inline int get_bat_adc_value()
{
    return get_adc_sample(5);
}
Пример #30
0
inline int get_burner_key()//cvt
{
    int adc_val = get_adc_sample(4);
    printf("get_burner_key: 0x%x\n", adc_val);
    return(((adc_val >= 0x80) && (adc_val < 0x120)) ? 1 : 0);
}