1 #ifndef _LINUX_SPI_TSC2301_H
2 #define _LINUX_SPI_TSC2301_H
4 #include <linux/types.h>
5 #include <linux/timer.h>
7 struct tsc2301_platform_data {
13 s16 keymap[16]; /* Set a key to a negative value if not used */
14 unsigned kp_rep:1; /* Enable keypad repeating */
21 u32 ts_stab_time; /* voltage settling time */
22 u8 ts_hw_avg; /* HW assiseted averaging. Can be
23 0, 4, 8, 16 samples per reading */
24 u32 ts_max_pressure;/* Samples with bigger pressure value will
25 be ignored, since the corresponding X, Y
26 values are unreliable */
27 u32 ts_touch_pressure; /* Pressure limit until we report a
28 touch event. After that we switch
29 to ts_max_pressure. */
30 unsigned ts_ignore_last : 1;
31 u32 ts_pressure_fudge;
43 unsigned pll_output:1; /* Output PLL on GPIO_0 */
45 unsigned mclk_ratio:2;
46 unsigned i2s_sample_rate:4;
47 unsigned i2s_format:2;
48 /* Mask for audio blocks to be powered down */
49 u16 power_down_blocks;
51 /* Called after codec has been initialized, can be NULL */
52 int (* codec_init)(struct device *tsc2301_dev);
53 /* Called when codec is being removed, can be NULL */
54 void (* codec_cleanup)(struct device *tsc2301_dev);
55 int (*enable_clock)(struct device *dev);
56 void (*disable_clock)(struct device *dev);
57 int (*get_keyb_irq_state)(struct device *dev);
59 const struct tsc2301_mixer_gpio {
63 unsigned def_enable:1; /* enable by default */
64 unsigned deactivate_on_pd:1; /* power-down flag */
74 struct spi_device *spi;
79 struct tsc2301_kp *kp;
80 struct tsc2301_ts *ts;
81 struct tsc2301_mixer *mixer;
83 int (*enable_clock)(struct device *dev);
84 void (*disable_clock)(struct device *dev);
88 #define TSC2301_HZ 33000000
90 #define TSC2301_REG(page, addr) (((page) << 11) | ((addr) << 5))
91 #define TSC2301_REG_TO_PAGE(reg) (((reg) >> 11) & 0x03)
92 #define TSC2301_REG_TO_ADDR(reg) (((reg) >> 5) & 0x1f)
94 #define TSC2301_REG_X TSC2301_REG(0, 0)
95 #define TSC2301_REG_Y TSC2301_REG(0, 1)
96 #define TSC2301_REG_Z1 TSC2301_REG(0, 2)
97 #define TSC2301_REG_Z2 TSC2301_REG(0, 3)
98 #define TSC2301_REG_KPDATA TSC2301_REG(0, 4)
99 #define TSC2301_REG_ADC TSC2301_REG(1, 0)
100 #define TSC2301_REG_KEY TSC2301_REG(1, 1)
101 #define TSC2301_REG_DAC TSC2301_REG(1, 2)
102 #define TSC2301_REG_REF TSC2301_REG(1, 3)
103 #define TSC2301_REG_RESET TSC2301_REG(1, 4)
104 #define TSC2301_REG_CONFIG TSC2301_REG(1, 5)
105 #define TSC2301_REG_CONFIG2 TSC2301_REG(1, 6)
106 #define TSC2301_REG_KPMASK TSC2301_REG(1, 16)
107 #define TSC2301_REG_AUDCNTL TSC2301_REG(2, 0)
108 #define TSC2301_REG_ADCVOL TSC2301_REG(2, 1)
109 #define TSC2301_REG_DACVOL TSC2301_REG(2, 2)
110 #define TSC2301_REG_BPVOL TSC2301_REG(2, 3)
111 #define TSC2301_REG_KEYCTL TSC2301_REG(2, 4)
112 #define TSC2301_REG_PD_MISC TSC2301_REG(2, 5)
113 #define TSC2301_REG_GPIO TSC2301_REG(2, 6)
114 #define TSC2301_REG_ADCLKCFG TSC2301_REG(2, 27)
116 #define TSC2301_REG_PD_MISC_APD (1 << 15)
117 #define TSC2301_REG_PD_MISC_AVPD (1 << 14)
118 #define TSC2301_REG_PD_MISC_ABPD (1 << 13)
119 #define TSC2301_REG_PD_MISC_HAPD (1 << 12)
120 #define TSC2301_REG_PD_MISC_MOPD (1 << 11)
121 #define TSC2301_REG_PD_MISC_DAPD (1 << 10)
122 #define TSC2301_REG_PD_MISC_ADPDL (1 << 9)
123 #define TSC2301_REG_PD_MISC_ADPDR (1 << 8)
124 #define TSC2301_REG_PD_MISC_PDSTS (1 << 7)
125 #define TSC2301_REG_PD_MISC_MIBPD (1 << 6)
126 #define TSC2301_REG_PD_MISC_OTSYN (1 << 2)
128 /* I2S sample rate */
129 #define TSC2301_I2S_SR_48000 0x00
130 #define TSC2301_I2S_SR_44100 0x01
131 #define TSC2301_I2S_SR_32000 0x02
132 #define TSC2301_I2S_SR_24000 0x03
133 #define TSC2301_I2S_SR_22050 0x04
134 #define TSC2301_I2S_SR_16000 0x05
135 #define TSC2301_I2S_SR_12000 0x06
136 #define TSC2301_I2S_SR_11050 0x07
137 #define TSC2301_I2S_SR_8000 0x08
139 /* 16-bit, MSB-first. DAC Right-Justified, ADC Left-Justified */
140 #define TSC2301_I2S_FORMAT0 0x00
141 /* 20-bit, MSB-first. DAC Right-Justified, ADC Left-Justified */
142 #define TSC2301_I2S_FORMAT1 0x01
143 /* 20-bit, MSB-first. DAC Left-Justified, ADC Left-Justified */
144 #define TSC2301_I2S_FORMAT2 0x02
145 /* 20-bit, MSB-first */
146 #define TSC2301_I2S_FORMAT3 0x03
148 /* Master Clock Ratio */
149 #define TSC2301_MCLK_256xFS 0x00 /* default */
150 #define TSC2301_MCLK_384xFS 0x01
151 #define TSC2301_MCLK_512xFS 0x02
154 extern u16 tsc2301_read_reg(struct tsc2301 *tsc, int reg);
155 extern void tsc2301_write_reg(struct tsc2301 *tsc, int reg, u16 val);
156 extern void tsc2301_write_kbc(struct tsc2301 *tsc, int val);
157 extern void tsc2301_write_pll(struct tsc2301 *tsc, int pll_n, int pll_a,
158 int pll_pdc, int pct_e, int pll_o);
159 extern void tsc2301_read_buf(struct tsc2301 *tsc, int reg, u16 *buf, int len);
161 #define TSC2301_DECL_MOD(module) \
162 extern int tsc2301_##module##_init(struct tsc2301 *tsc, \
163 struct tsc2301_platform_data *pdata); \
164 extern void tsc2301_##module##_exit(struct tsc2301 *tsc); \
165 extern int tsc2301_##module##_suspend(struct tsc2301 *tsc); \
166 extern void tsc2301_##module##_resume(struct tsc2301 *tsc);
168 #define TSC2301_DECL_EMPTY_MOD(module) \
169 static inline int tsc2301_##module##_init(struct tsc2301 *tsc, \
170 struct tsc2301_platform_data *pdata) \
174 static inline void tsc2301_##module##_exit(struct tsc2301 *tsc) {} \
175 static inline int tsc2301_##module##_suspend(struct tsc2301 *tsc) \
179 static inline void tsc2301_##module##_resume(struct tsc2301 *tsc) {}
181 #ifdef CONFIG_KEYBOARD_TSC2301
183 void tsc2301_kp_restart(struct tsc2301 *tsc);
185 TSC2301_DECL_EMPTY_MOD(kp)
186 static inline void tsc2301_kp_restart(struct tsc2301 *tsc) {}
189 #ifdef CONFIG_TOUCHSCREEN_TSC2301
192 TSC2301_DECL_EMPTY_MOD(ts)
195 #ifdef CONFIG_SPI_TSC2301_AUDIO
196 TSC2301_DECL_MOD(mixer)
197 extern void tsc2301_mixer_set_power(struct device *tsc_dev, int dac, int adc);
200 extern int tsc2301_mixer_register_controls(struct device *tsc_dev,
201 struct snd_card *card);
203 TSC2301_DECL_EMPTY_MOD(mixer)
206 extern void tsc2301_mixer_enable_mclk(struct device *tsc_dev);
207 extern void tsc2301_mixer_disable_mclk(struct device *tsc_dev);