コード例 #1
0
ファイル: saradc.c プロジェクト: alpha-it/u-boot
int saradc_disable(void)
{
	disable_adc();
	
	disable_sample_engine();
	
	return 0;
}
コード例 #2
0
ファイル: saradc.c プロジェクト: Pivosgroup/buildroot-uboot
int get_adc_sample(int chan)
{
	int count;
	int value = -1;
	int sum;
	
	set_chan_list(chan, 1);
	set_avg_mode(chan, NO_AVG_MODE, SAMPLE_NUM_8);
	set_sample_mux(chan, g_chan_mux[chan]);
	set_detect_mux(g_chan_mux[chan]);
	set_idle_mux(g_chan_mux[chan]); // for revb
	enable_sample_engine();
	start_sample();

	// Read any CBUS register to delay one clock
	// cycle after starting the sampling engine
	// The bus is really fast and we may miss that it started
	{ count = READ_CBUS_REG(ISA_TIMERE); }

	count = 0;
	while (delta_busy() || sample_busy() || avg_busy()){
		if (++count > 10000){
			printf("ADC busy error.\n");
			goto adc_sample_end;
			}
	}
	
    stop_sample();
    
    sum = 0;
    count = 0;
    value = get_fifo_sample();

	while (get_fifo_cnt()){
        value = get_fifo_sample() & 0x3ff;
        if ((value != 0x1fe) && (value != 0x1ff)){
			sum += value & 0x3ff;
            count++;
        }
	}
	value = (count) ? (sum / count) : (-1);

adc_sample_end:
	
#if AML_ADC_SAMPLE_DEBUG
	printf("ch%d = %d, count=%d\n", chan, value, count);
#endif //AML_ADC_SAMPLE_DEBUG

	disable_sample_engine();
	set_sc_phase();
	return value;
}
コード例 #3
0
ファイル: saradc.c プロジェクト: xbai043/zt280-kernel
int get_adc_sample(int chan)
{
	int count;
	int value;
	int sum;
	
	if (!gp_saradc)
		return -1;
		
	spin_lock(&gp_saradc->lock);

	set_chan_list(chan, 1);
	set_avg_mode(chan, NO_AVG_MODE, SAMPLE_NUM_8);
	set_sample_mux(chan, chan_mux[chan]);
	set_detect_mux(chan_mux[chan]);
	set_idle_mux(chan_mux[chan]); // for revb
	enable_sample_engine();
	start_sample();

	// Read any CBUS register to delay one clock cycle after starting the sampling engine
	// The bus is really fast and we may miss that it started
	{ count = get_reg(ISA_TIMERE); }

	count = 0;
	while (delta_busy() || sample_busy() || avg_busy()) {
		if (++count > 10000) {
        			printk(KERN_ERR "ADC busy error.\n");
			goto end;
		}
	}
    stop_sample();
    
    sum = 0;
    count = 0;
    value = get_fifo_sample();
	while (get_fifo_cnt()) {
        value = get_fifo_sample() & 0x3ff;
        if ((value != 0x1fe) && (value != 0x1ff)) {
			sum += value & 0x3ff;
            count++;
        }
	}
	value = (count) ? (sum / count) : (-1);

end:
	//printk("ch%d = %d, count=%d\n", chan, value, count);
	disable_sample_engine();
	spin_unlock(&gp_saradc->lock);
	return value;
}
コード例 #4
0
ファイル: saradc2arc.c プロジェクト: alpha-it/u-boot
int  adc_detect_key()
{
 	int value , i;
	int key_tolerance = CONFIG_SARADC_KEY_TOLERANCE;
	
  value = get_fifo_sample() & 0x3ff;
	disable_sample_engine();
	for(i = 0; i < (sizeof(adc_key_value) / sizeof(unsigned int)); i++){
		if((value >= adc_key_value[i] - key_tolerance)
			&&(value <= adc_key_value[i] + key_tolerance) ){	
			return i+1;
		}
	}
	return 0;
}
コード例 #5
0
ファイル: saradc.c プロジェクト: OpenLD/linux-wetek-3.10.y
static inline void saradc_power_control(int on)
{
	if (on) {
#if MESON_CPU_TYPE >= MESON_CPU_TYPE_MESON8
		enable_bandgap();
		udelay(10);
#endif
		enable_adc();
		udelay(5);
		enable_clock();
		enable_sample_engine();
	}
	else {
		disable_sample_engine();
		disable_clock();
		disable_adc();
#if MESON_CPU_TYPE >= MESON_CPU_TYPE_MESON8
		disable_bandgap();
#endif 			
	}
}