/* * Read a sample from the WM9705 adc in polling mode. */ static int wm9705_poll_sample(struct wm97xx *wm, int adcsel, int *sample) { int timeout = 5 * delay; if (!wm->pen_probably_down) { u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (!(data & WM97XX_PEN_DOWN)) return RC_PENUP; wm->pen_probably_down = 1; } /* set up digitiser */ if (adcsel & 0x8000) adcsel = ((adcsel & 0x7fff) + 3) << 12; if (wm->mach_ops && wm->mach_ops->pre_sample) wm->mach_ops->pre_sample(adcsel); wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay)); /* wait 3 AC97 time slots + delay for conversion */ poll_delay(delay); /* wait for POLL to go low */ while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { udelay(AC97_LINK_FRAME); timeout--; } if (timeout == 0) { /* If PDEN is set, we can get a timeout when pen goes up */ if (is_pden(wm)) wm->pen_probably_down = 0; else dev_dbg(wm->dev, "adc sample timeout"); return RC_PENUP; } *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (wm->mach_ops && wm->mach_ops->post_sample) wm->mach_ops->post_sample(adcsel); /* check we have correct sample */ if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) { dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel, *sample & WM97XX_ADCSEL_MASK); return RC_PENUP; } if (!(*sample & WM97XX_PEN_DOWN)) { wm->pen_probably_down = 0; return RC_PENUP; } return RC_VALID; }
static int wm9712_poll_sample(struct wm97xx *wm, int adcsel, int *sample) { int timeout = 5 * delay; if (!wm->pen_probably_down) { u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (!(data & WM97XX_PEN_DOWN)) return RC_PENUP; wm->pen_probably_down = 1; } if (adcsel & 0x8000) adcsel = ((adcsel & 0x7fff) + 3) << 12; if (wm->mach_ops && wm->mach_ops->pre_sample) wm->mach_ops->pre_sample(adcsel); wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay)); poll_delay(delay); while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { udelay(AC97_LINK_FRAME); timeout--; } if (timeout <= 0) { if (is_pden(wm)) wm->pen_probably_down = 0; else dev_dbg(wm->dev, "adc sample timeout"); return RC_PENUP; } *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (wm->mach_ops && wm->mach_ops->post_sample) wm->mach_ops->post_sample(adcsel); if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) { dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel, *sample & WM97XX_ADCSEL_MASK); return RC_PENUP; } if (!(*sample & WM97XX_PEN_DOWN)) { wm->pen_probably_down = 0; return RC_PENUP; } return RC_VALID; }
static int rt5611_ts_poll_coord(struct rt5611_ts *rt, struct rt5611_ts_data *data) { bool FoundXSample = 0, FoundYSample = 0, FoundPSample = 0; u16 val = 0; u8 i = 0; RT5611_TS_DEBUG("rt5611_ts_poll_coord\n"); data->x = MAX_ADC_VAL; data->y = MAX_ADC_VAL; data->p = MAX_ADC_VAL; poll_delay(delay_sel); for (i = 0; i < MAX_CONVERSIONS; i++) { val = rt5611_ts_reg_read(rt, RT_TP_INDICATION); if (!(val & CB3_PD_STATUS)) return RC_PENUP; if (!FoundXSample && ((val&CB3_ADCSRC_MASK) == CB3_ADCSRC_X)) { data->x = val & CB3_ADC_DATA; /* get X sample */ FoundXSample = 1; } else if (!FoundYSample && ((val&CB3_ADCSRC_MASK) == CB3_ADCSRC_Y)) { data->y = val & CB3_ADC_DATA; /* get Y sample */ FoundYSample = 1; } else if (!FoundPSample && ((val&CB3_ADCSRC_MASK) == CB3_ADCSRC_PRE)) { data->p = val & CB3_ADC_DATA; /* get Presure sample */ FoundPSample = 1; } else if ((val&CB3_ADCSRC_MASK) == CB3_ADCSRC_NON) { //when busy, using a smaller delay udelay(100); continue; } if (FoundXSample && FoundYSample && FoundPSample) break; /*wait some delay- delay for conversion */ poll_delay(delay_sel); } if (i == MAX_CONVERSIONS) return RC_AGAIN; else return RC_VALID; }
static int wm9712_poll_coord(struct wm97xx *wm, struct wm97xx_data *data) { int timeout = 5 * delay; if (!wm->pen_probably_down) { u16 data_rd = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (!(data_rd & WM97XX_PEN_DOWN)) return RC_PENUP; wm->pen_probably_down = 1; } if (wm->mach_ops && wm->mach_ops->pre_sample) wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, WM97XX_COO | WM97XX_POLL | WM97XX_DELAY(delay)); poll_delay(delay); data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { udelay(AC97_LINK_FRAME); timeout--; } if (timeout <= 0) { if (is_pden(wm)) wm->pen_probably_down = 0; else dev_dbg(wm->dev, "adc sample timeout"); return RC_PENUP; } data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (pil) data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); else data->p = DEFAULT_PRESSURE; if (wm->mach_ops && wm->mach_ops->post_sample) wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y)) goto err; if (pil && !(data->p & WM97XX_ADCSEL_PRES)) goto err; if (!(data->x & WM97XX_PEN_DOWN) || !(data->y & WM97XX_PEN_DOWN)) { wm->pen_probably_down = 0; return RC_PENUP; } return RC_VALID; err: return 0; }
/* * Read a coord from the WM9712 adc in polling mode. */ static int wm9712_poll_coord(struct wm97xx *wm, struct wm97xx_data *data) { int timeout = 5 * delay; if (!wm->pen_probably_down) { u16 data_rd = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (!(data_rd & WM97XX_PEN_DOWN)) return RC_PENUP; wm->pen_probably_down = 1; } /* set up digitiser */ if (wm->mach_ops && wm->mach_ops->pre_sample) wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, WM97XX_COO | WM97XX_POLL | WM97XX_DELAY(delay)); /* wait 3 AC97 time slots + delay for conversion and read x */ poll_delay(delay); data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* wait for POLL to go low */ while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) { udelay(AC97_LINK_FRAME); timeout--; } if (timeout <= 0) { /* If PDEN is set, we can get a timeout when pen goes up */ if (is_pden(wm)) wm->pen_probably_down = 0; else dev_dbg(wm->dev, "adc sample timeout"); return RC_PENUP; } /* read back y data */ data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); if (pil) data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); else data->p = DEFAULT_PRESSURE; if (wm->mach_ops && wm->mach_ops->post_sample) wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y); /* check we have correct sample */ if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y)) goto err; if (pil && !(data->p & WM97XX_ADCSEL_PRES)) goto err; if (!(data->x & WM97XX_PEN_DOWN) || !(data->y & WM97XX_PEN_DOWN)) { wm->pen_probably_down = 0; return RC_PENUP; } return RC_VALID; err: return 0; }