2010年9月9日星期四

S3C ADC API


data struct

  46struct s3c_adc_client {
  47        struct platform_device  *pdev;
  48        struct list_head         pend;
  49        wait_queue_head_t       *wait;
  50
  51        unsigned int             nr_samples;
  52        int                      result;
  53        unsigned char            is_ts;
  54        unsigned char            channel;
  55
  56        void    (*select_cb)(struct s3c_adc_client *c, unsigned selected);
  57        void    (*convert_cb)(struct s3c_adc_client *c,
  58                              unsigned val1, unsigned val2,
  59                              unsigned *samples_left); 
60}; 
API

Register and unregister function:
 24extern struct s3c_adc_client *
  25        s3c_adc_register(struct platform_device *pdev,
  26                         void (*select)(struct s3c_adc_client *client,
  27                                        unsigned selected),       /*********Called when the ADC core selects (or deslects) us as a client.**********/

  28                         void (*conv)(struct s3c_adc_client *client,
  29                                      unsigned d0, unsigned d1,
  30                                      unsigned *samples_left),    /*****Called when a conversion has finished.**************/
31 unsigned int is_ts);  /***whether to used for touch screen.***/

--usually be used in the driver's probe() function.

release:
33extern void s3c_adc_release(struct s3c_adc_client *client);
To use ADC

  19extern int s3c_adc_start(struct s3c_adc_client *client
20 unsigned int channel, unsigned int nr_samples); 

--just call this function when using touchscreen mode, and convert will be accomplished in the interrupt handle.


or another way :
extern int s3c_adc_read(struct s3c_adc_client *client, unsigned int ch);
this function is useful when using normal ADC mode.
example for two function: select and conv
/**
 187 * s3c24xx_ts_conversion - ADC conversion callback
 188 * @client: The client that was registered with the ADC core.
 189 * @data0: The reading from ADCDAT0.
 190 * @data1: The reading from ADCDAT1.
 191 * @left: The number of samples left.
 192 *
 193 * Called when a conversion has finished.
 194 */
 195static void s3c24xx_ts_conversion(struct s3c_adc_client *client,
 196                                  unsigned data0, unsigned data1,
 197                                  unsigned *left)
 198{
 199        dev_dbg(ts.dev, "%s: %d,%d\n", __func__, data0, data1);
 200
 201        ts.xp += data0;
 202        ts.yp += data1;
 203
 204        ts.count++;
 205
 206        /* From tests, it seems that it is unlikely to get a pen-up
 207         * event during the conversion process which means we can
 208         * ignore any pen-up events with less than the requisite
 209         * count done.
 210         *
 211         * In several thousand conversions, no pen-ups where detected
 212         * before count completed.
 213         */
 214}
 215
 216/**
 217 * s3c24xx_ts_select - ADC selection callback.
 218 * @client: The client that was registered with the ADC core.
 219 * @select: The reason for select.
 220 *
 221 * Called when the ADC core selects (or deslects) us as a client.
 222 */
 223static void s3c24xx_ts_select(struct s3c_adc_client *client, unsigned select)
 224{
 225        if (select) {
 226                writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST,
 227                       ts.io + S3C2410_ADCTSC);
 228        } else {
 229                mod_timer(&touch_timer, jiffies+1);
 230                writel(WAIT4INT | INT_UP, ts.io + S3C2410_ADCTSC);
 231
232} 

没有评论:

发表评论