Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 /*
0004  * Register bits and API for Wolfson WM97xx series of codecs
0005  */
0006 
0007 #ifndef _LINUX_WM97XX_H
0008 #define _LINUX_WM97XX_H
0009 
0010 #include <sound/core.h>
0011 #include <sound/pcm.h>
0012 #include <sound/ac97_codec.h>
0013 #include <sound/initval.h>
0014 #include <linux/types.h>
0015 #include <linux/list.h>
0016 #include <linux/input.h>    /* Input device layer */
0017 #include <linux/platform_device.h>
0018 
0019 /*
0020  * WM97xx variants
0021  */
0022 #define WM97xx_GENERIC          0x0000
0023 #define WM97xx_WM1613           0x1613
0024 
0025 /*
0026  * WM97xx AC97 Touchscreen registers
0027  */
0028 #define AC97_WM97XX_DIGITISER1      0x76
0029 #define AC97_WM97XX_DIGITISER2      0x78
0030 #define AC97_WM97XX_DIGITISER_RD    0x7a
0031 #define AC97_WM9713_DIG1        0x74
0032 #define AC97_WM9713_DIG2        AC97_WM97XX_DIGITISER1
0033 #define AC97_WM9713_DIG3        AC97_WM97XX_DIGITISER2
0034 
0035 /*
0036  * WM97xx register bits
0037  */
0038 #define WM97XX_POLL     0x8000  /* initiate a polling measurement */
0039 #define WM97XX_ADCSEL_X     0x1000  /* x coord measurement */
0040 #define WM97XX_ADCSEL_Y     0x2000  /* y coord measurement */
0041 #define WM97XX_ADCSEL_PRES  0x3000  /* pressure measurement */
0042 #define WM97XX_AUX_ID1      0x4000
0043 #define WM97XX_AUX_ID2      0x5000
0044 #define WM97XX_AUX_ID3      0x6000
0045 #define WM97XX_AUX_ID4      0x7000
0046 #define WM97XX_ADCSEL_MASK  0x7000  /* ADC selection mask */
0047 #define WM97XX_COO      0x0800  /* enable coordinate mode */
0048 #define WM97XX_CTC      0x0400  /* enable continuous mode */
0049 #define WM97XX_CM_RATE_93   0x0000  /* 93.75Hz continuous rate */
0050 #define WM97XX_CM_RATE_187  0x0100  /* 187.5Hz continuous rate */
0051 #define WM97XX_CM_RATE_375  0x0200  /* 375Hz continuous rate */
0052 #define WM97XX_CM_RATE_750  0x0300  /* 750Hz continuous rate */
0053 #define WM97XX_CM_RATE_8K   0x00f0  /* 8kHz continuous rate */
0054 #define WM97XX_CM_RATE_12K  0x01f0  /* 12kHz continuous rate */
0055 #define WM97XX_CM_RATE_24K  0x02f0  /* 24kHz continuous rate */
0056 #define WM97XX_CM_RATE_48K  0x03f0  /* 48kHz continuous rate */
0057 #define WM97XX_CM_RATE_MASK 0x03f0
0058 #define WM97XX_RATE(i)      (((i & 3) << 8) | ((i & 4) ? 0xf0 : 0))
0059 #define WM97XX_DELAY(i)     ((i << 4) & 0x00f0) /* sample delay times */
0060 #define WM97XX_DELAY_MASK   0x00f0
0061 #define WM97XX_SLEN     0x0008  /* slot read back enable */
0062 #define WM97XX_SLT(i)       ((i - 5) & 0x7) /* panel slot (5-11) */
0063 #define WM97XX_SLT_MASK     0x0007
0064 #define WM97XX_PRP_DETW     0x4000  /* detect on, digitise off, wake */
0065 #define WM97XX_PRP_DET      0x8000  /* detect on, digitise off, no wake */
0066 #define WM97XX_PRP_DET_DIG  0xc000  /* setect on, digitise on */
0067 #define WM97XX_RPR      0x2000  /* wake up on pen down */
0068 #define WM97XX_PEN_DOWN     0x8000  /* pen is down */
0069 
0070 /* WM9712 Bits */
0071 #define WM9712_45W      0x1000  /* set for 5-wire touchscreen */
0072 #define WM9712_PDEN     0x0800  /* measure only when pen down */
0073 #define WM9712_WAIT     0x0200  /* wait until adc is read before next sample */
0074 #define WM9712_PIL      0x0100  /* current used for pressure measurement. set 400uA else 200uA */
0075 #define WM9712_MASK_HI      0x0040  /* hi on mask pin (47) stops conversions */
0076 #define WM9712_MASK_EDGE    0x0080  /* rising/falling edge on pin delays sample */
0077 #define WM9712_MASK_SYNC    0x00c0  /* rising/falling edge on mask initiates sample */
0078 #define WM9712_RPU(i)       (i&0x3f)    /* internal pull up on pen detect (64k / rpu) */
0079 #define WM9712_PD(i)        (0x1 << i)  /* power management */
0080 
0081 /* WM9712 Registers */
0082 #define AC97_WM9712_POWER   0x24
0083 #define AC97_WM9712_REV     0x58
0084 
0085 /* WM9705 Bits */
0086 #define WM9705_PDEN     0x1000  /* measure only when pen is down */
0087 #define WM9705_PINV     0x0800  /* inverts sense of pen down output */
0088 #define WM9705_BSEN     0x0400  /* BUSY flag enable, pin47 is 1 when busy */
0089 #define WM9705_BINV     0x0200  /* invert BUSY (pin47) output */
0090 #define WM9705_WAIT     0x0100  /* wait until adc is read before next sample */
0091 #define WM9705_PIL      0x0080  /* current used for pressure measurement. set 400uA else 200uA */
0092 #define WM9705_PHIZ     0x0040  /* set PHONE and PCBEEP inputs to high impedance */
0093 #define WM9705_MASK_HI      0x0010  /* hi on mask stops conversions */
0094 #define WM9705_MASK_EDGE    0x0020  /* rising/falling edge on pin delays sample */
0095 #define WM9705_MASK_SYNC    0x0030  /* rising/falling edge on mask initiates sample */
0096 #define WM9705_PDD(i)       (i & 0x000f)    /* pen detect comparator threshold */
0097 
0098 
0099 /* WM9713 Bits */
0100 #define WM9713_PDPOL        0x0400  /* Pen down polarity */
0101 #define WM9713_POLL     0x0200  /* initiate a polling measurement */
0102 #define WM9713_CTC      0x0100  /* enable continuous mode */
0103 #define WM9713_ADCSEL_X     0x0002  /* X measurement */
0104 #define WM9713_ADCSEL_Y     0x0004  /* Y measurement */
0105 #define WM9713_ADCSEL_PRES  0x0008  /* Pressure measurement */
0106 #define WM9713_COO      0x0001  /* enable coordinate mode */
0107 #define WM9713_45W      0x1000  /* set for 5 wire panel */
0108 #define WM9713_PDEN     0x0800  /* measure only when pen down */
0109 #define WM9713_ADCSEL_MASK  0x00fe  /* ADC selection mask */
0110 #define WM9713_WAIT     0x0200  /* coordinate wait */
0111 
0112 /* AUX ADC ID's */
0113 #define TS_COMP1        0x0
0114 #define TS_COMP2        0x1
0115 #define TS_BMON         0x2
0116 #define TS_WIPER        0x3
0117 
0118 /* ID numbers */
0119 #define WM97XX_ID1      0x574d
0120 #define WM9712_ID2      0x4c12
0121 #define WM9705_ID2      0x4c05
0122 #define WM9713_ID2      0x4c13
0123 
0124 /* Codec GPIO's */
0125 #define WM97XX_MAX_GPIO     16
0126 #define WM97XX_GPIO_1       (1 << 1)
0127 #define WM97XX_GPIO_2       (1 << 2)
0128 #define WM97XX_GPIO_3       (1 << 3)
0129 #define WM97XX_GPIO_4       (1 << 4)
0130 #define WM97XX_GPIO_5       (1 << 5)
0131 #define WM97XX_GPIO_6       (1 << 6)
0132 #define WM97XX_GPIO_7       (1 << 7)
0133 #define WM97XX_GPIO_8       (1 << 8)
0134 #define WM97XX_GPIO_9       (1 << 9)
0135 #define WM97XX_GPIO_10      (1 << 10)
0136 #define WM97XX_GPIO_11      (1 << 11)
0137 #define WM97XX_GPIO_12      (1 << 12)
0138 #define WM97XX_GPIO_13      (1 << 13)
0139 #define WM97XX_GPIO_14      (1 << 14)
0140 #define WM97XX_GPIO_15      (1 << 15)
0141 
0142 
0143 #define AC97_LINK_FRAME     21  /* time in uS for AC97 link frame */
0144 
0145 
0146 /*---------------- Return codes from sample reading functions ---------------*/
0147 
0148 /* More data is available; call the sample gathering function again */
0149 #define RC_AGAIN            0x00000001
0150 /* The returned sample is valid */
0151 #define RC_VALID            0x00000002
0152 /* The pen is up (the first RC_VALID without RC_PENUP means pen is down) */
0153 #define RC_PENUP            0x00000004
0154 /* The pen is down (RC_VALID implies RC_PENDOWN, but sometimes it is helpful
0155    to tell the handler that the pen is down but we don't know yet his coords,
0156    so the handler should not sleep or wait for pendown irq) */
0157 #define RC_PENDOWN          0x00000008
0158 
0159 /*
0160  * The wm97xx driver provides a private API for writing platform-specific
0161  * drivers.
0162  */
0163 
0164 /* The structure used to return arch specific sampled data into */
0165 struct wm97xx_data {
0166     int x;
0167     int y;
0168     int p;
0169 };
0170 
0171 /*
0172  * Codec GPIO status
0173  */
0174 enum wm97xx_gpio_status {
0175     WM97XX_GPIO_HIGH,
0176     WM97XX_GPIO_LOW
0177 };
0178 
0179 /*
0180  * Codec GPIO direction
0181  */
0182 enum wm97xx_gpio_dir {
0183     WM97XX_GPIO_IN,
0184     WM97XX_GPIO_OUT
0185 };
0186 
0187 /*
0188  * Codec GPIO polarity
0189  */
0190 enum wm97xx_gpio_pol {
0191     WM97XX_GPIO_POL_HIGH,
0192     WM97XX_GPIO_POL_LOW
0193 };
0194 
0195 /*
0196  * Codec GPIO sticky
0197  */
0198 enum wm97xx_gpio_sticky {
0199     WM97XX_GPIO_STICKY,
0200     WM97XX_GPIO_NOTSTICKY
0201 };
0202 
0203 /*
0204  * Codec GPIO wake
0205  */
0206 enum wm97xx_gpio_wake {
0207     WM97XX_GPIO_WAKE,
0208     WM97XX_GPIO_NOWAKE
0209 };
0210 
0211 /*
0212  * Digitiser ioctl commands
0213  */
0214 #define WM97XX_DIG_START    0x1
0215 #define WM97XX_DIG_STOP     0x2
0216 #define WM97XX_PHY_INIT     0x3
0217 #define WM97XX_AUX_PREPARE  0x4
0218 #define WM97XX_DIG_RESTORE  0x5
0219 
0220 struct wm97xx;
0221 
0222 extern struct wm97xx_codec_drv wm9705_codec;
0223 extern struct wm97xx_codec_drv wm9712_codec;
0224 extern struct wm97xx_codec_drv wm9713_codec;
0225 
0226 /*
0227  * Codec driver interface - allows mapping to WM9705/12/13 and newer codecs
0228  */
0229 struct wm97xx_codec_drv {
0230     u16 id;
0231     char *name;
0232 
0233     /* read 1 sample */
0234     int (*poll_sample) (struct wm97xx *, int adcsel, int *sample);
0235 
0236     /* read X,Y,[P] in poll */
0237     int (*poll_touch) (struct wm97xx *, struct wm97xx_data *);
0238 
0239     int (*acc_enable) (struct wm97xx *, int enable);
0240     void (*phy_init) (struct wm97xx *);
0241     void (*dig_enable) (struct wm97xx *, int enable);
0242     void (*dig_restore) (struct wm97xx *);
0243     void (*aux_prepare) (struct wm97xx *);
0244 };
0245 
0246 
0247 /* Machine specific and accelerated touch operations */
0248 struct wm97xx_mach_ops {
0249 
0250     /* accelerated touch readback - coords are transmited on AC97 link */
0251     int acc_enabled;
0252     void (*acc_pen_up) (struct wm97xx *);
0253     int (*acc_pen_down) (struct wm97xx *);
0254     int (*acc_startup) (struct wm97xx *);
0255     void (*acc_shutdown) (struct wm97xx *);
0256 
0257     /* GPIO pin used for accelerated operation */
0258     int irq_gpio;
0259 
0260     /* pre and post sample - can be used to minimise any analog noise */
0261     void (*pre_sample) (int);  /* function to run before sampling */
0262     void (*post_sample) (int);  /* function to run after sampling */
0263 };
0264 
0265 struct wm97xx {
0266     u16 dig[3], id, gpio[6], misc;  /* Cached codec registers */
0267     u16 dig_save[3];        /* saved during aux reading */
0268     struct wm97xx_codec_drv *codec; /* attached codec driver*/
0269     struct input_dev *input_dev;    /* touchscreen input device */
0270     struct snd_ac97 *ac97;      /* ALSA codec access */
0271     struct device *dev;     /* ALSA device */
0272     struct platform_device *battery_dev;
0273     struct platform_device *touch_dev;
0274     struct wm97xx_mach_ops *mach_ops;
0275     struct mutex codec_mutex;
0276     struct delayed_work ts_reader;  /* Used to poll touchscreen */
0277     unsigned long ts_reader_interval; /* Current interval for timer */
0278     unsigned long ts_reader_min_interval; /* Minimum interval */
0279     unsigned int pen_irq;       /* Pen IRQ number in use */
0280     struct workqueue_struct *ts_workq;
0281     u16 acc_slot;           /* AC97 slot used for acc touch data */
0282     u16 acc_rate;           /* acc touch data rate */
0283     unsigned pen_is_down:1;     /* Pen is down */
0284     unsigned aux_waiting:1;     /* aux measurement waiting */
0285     unsigned pen_probably_down:1;   /* used in polling mode */
0286     u16 variant;            /* WM97xx chip variant */
0287     u16 suspend_mode;               /* PRP in suspend mode */
0288 };
0289 
0290 struct wm97xx_batt_pdata {
0291     int batt_aux;
0292     int temp_aux;
0293     int min_voltage;
0294     int max_voltage;
0295     int batt_div;
0296     int batt_mult;
0297     int temp_div;
0298     int temp_mult;
0299     int batt_tech;
0300     char    *batt_name;
0301 };
0302 
0303 struct wm97xx_pdata {
0304     struct wm97xx_batt_pdata    *batt_pdata;    /* battery data */
0305 };
0306 
0307 /*
0308  * Codec GPIO access (not supported on WM9705)
0309  * This can be used to set/get codec GPIO and Virtual GPIO status.
0310  */
0311 enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio);
0312 void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
0313               enum wm97xx_gpio_status status);
0314 void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio,
0315                      enum wm97xx_gpio_dir dir,
0316                      enum wm97xx_gpio_pol pol,
0317                      enum wm97xx_gpio_sticky sticky,
0318                      enum wm97xx_gpio_wake wake);
0319 
0320 void wm97xx_set_suspend_mode(struct wm97xx *wm, u16 mode);
0321 
0322 /* codec AC97 IO access */
0323 int wm97xx_reg_read(struct wm97xx *wm, u16 reg);
0324 void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val);
0325 
0326 /* aux adc readback */
0327 int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel);
0328 
0329 /* machine ops */
0330 int wm97xx_register_mach_ops(struct wm97xx *, struct wm97xx_mach_ops *);
0331 void wm97xx_unregister_mach_ops(struct wm97xx *);
0332 
0333 #endif