]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/spi/tsc2301.h
SPI: Add support for TSC2301 protocol driver
[linux-2.6-omap-h63xx.git] / include / linux / spi / tsc2301.h
1 #ifndef _LINUX_SPI_TSC2301_H
2 #define _LINUX_SPI_TSC2301_H
3
4 #include <linux/types.h>
5 #include <linux/timer.h>
6
7 struct tsc2301_platform_data {
8         /*
9          * Keypad
10          */
11         s16     reset_gpio;
12         s16     keyb_int;
13         s16     keymap[16];     /* Set a key to a negative value if not used */
14         unsigned kp_rep:1;      /* Enable keypad repeating */
15
16         /*
17          * Touchscreen
18          */
19         s16     dav_gpio;
20         s16     pen_int_gpio;
21         u16     ts_x_plate_ohm;
22         u32     ts_stab_time;   /* voltage settling time */
23         u8      ts_hw_avg;      /* HW assiseted averaging. Can be
24                                    0, 4, 8, 16 samples per reading */
25         u32     ts_max_pressure;/* Samples with bigger pressure value will
26                                    be ignored, since the corresponding X, Y
27                                    values are unreliable */
28         u32     ts_touch_pressure;      /* Pressure limit until we report a
29                                            touch event. After that we switch
30                                            to ts_max_pressure. */
31         unsigned ts_ignore_last : 1;
32
33         /*
34          * Audio
35          */
36         unsigned        pll_pdc:4;
37         unsigned        pll_a:4;
38         unsigned        pll_n:4;
39         unsigned        pll_output:1; /* Output PLL on GPIO_0 */
40
41         unsigned        mclk_ratio:2;
42         unsigned        i2s_sample_rate:4;
43         unsigned        i2s_format:2;
44         /* Mask for audio blocks to be powered down */
45         u16             power_down_blocks;
46
47         /* Called after codec has been initialized, can be NULL */
48         int (* codec_init)(struct device *tsc2301_dev);
49         /* Called when codec is being removed, can be NULL */
50         void (* codec_cleanup)(struct device *tsc2301_dev);
51         int     (*enable_clock)(struct device *dev);
52         void    (*disable_clock)(struct device *dev);
53         int     (*get_keyb_irq_state)(struct device *dev);
54
55         const struct tsc2301_mixer_gpio {
56                 const char      *name;
57                 unsigned        gpio:4;
58                 unsigned        inverted:1;
59                 unsigned        def_enable:1; /* enable by default */
60                 unsigned        deactivate_on_pd:1; /* power-down flag */
61         } *mixer_gpios;
62         int     n_mixer_gpios;
63 };
64
65 struct tsc2301_kp;
66 struct tsc2301_ts;
67 struct tsc2301_mixer;
68
69 struct tsc2301 {
70         struct spi_device       *spi;
71
72         s16                     reset_gpio;
73         u16                     config2_shadow;
74
75         struct tsc2301_kp       *kp;
76         struct tsc2301_ts       *ts;
77         struct tsc2301_mixer    *mixer;
78
79         int                     (*enable_clock)(struct device *dev);
80         void                    (*disable_clock)(struct device *dev);
81 };
82
83
84 #define TSC2301_HZ      33000000
85
86 #define TSC2301_REG(page, addr)  (((page) << 11) | ((addr) << 5))
87 #define TSC2301_REG_TO_PAGE(reg) (((reg) >> 11) & 0x03)
88 #define TSC2301_REG_TO_ADDR(reg) (((reg) >> 5)  & 0x1f)
89
90 #define TSC2301_REG_X           TSC2301_REG(0, 0)
91 #define TSC2301_REG_Y           TSC2301_REG(0, 1)
92 #define TSC2301_REG_Z1          TSC2301_REG(0, 2)
93 #define TSC2301_REG_Z2          TSC2301_REG(0, 3)
94 #define TSC2301_REG_KPDATA      TSC2301_REG(0, 4)
95 #define TSC2301_REG_ADC         TSC2301_REG(1, 0)
96 #define TSC2301_REG_KEY         TSC2301_REG(1, 1)
97 #define TSC2301_REG_DAC         TSC2301_REG(1, 2)
98 #define TSC2301_REG_REF         TSC2301_REG(1, 3)
99 #define TSC2301_REG_RESET       TSC2301_REG(1, 4)
100 #define TSC2301_REG_CONFIG      TSC2301_REG(1, 5)
101 #define TSC2301_REG_CONFIG2     TSC2301_REG(1, 6)
102 #define TSC2301_REG_KPMASK      TSC2301_REG(1, 16)
103 #define TSC2301_REG_AUDCNTL     TSC2301_REG(2, 0)
104 #define TSC2301_REG_ADCVOL      TSC2301_REG(2, 1)
105 #define TSC2301_REG_DACVOL      TSC2301_REG(2, 2)
106 #define TSC2301_REG_BPVOL       TSC2301_REG(2, 3)
107 #define TSC2301_REG_KEYCTL      TSC2301_REG(2, 4)
108 #define TSC2301_REG_PD_MISC     TSC2301_REG(2, 5)
109 #define TSC2301_REG_GPIO        TSC2301_REG(2, 6)
110 #define TSC2301_REG_ADCLKCFG    TSC2301_REG(2, 27)
111
112 #define TSC2301_REG_PD_MISC_APD         (1 << 15)
113 #define TSC2301_REG_PD_MISC_AVPD        (1 << 14)
114 #define TSC2301_REG_PD_MISC_ABPD        (1 << 13)
115 #define TSC2301_REG_PD_MISC_HAPD        (1 << 12)
116 #define TSC2301_REG_PD_MISC_MOPD        (1 << 11)
117 #define TSC2301_REG_PD_MISC_DAPD        (1 << 10)
118 #define TSC2301_REG_PD_MISC_ADPDL       (1 << 9)
119 #define TSC2301_REG_PD_MISC_ADPDR       (1 << 8)
120 #define TSC2301_REG_PD_MISC_PDSTS       (1 << 7)
121 #define TSC2301_REG_PD_MISC_MIBPD       (1 << 6)
122 #define TSC2301_REG_PD_MISC_OTSYN       (1 << 2)
123
124 /* I2S sample rate */
125 #define TSC2301_I2S_SR_48000    0x00
126 #define TSC2301_I2S_SR_44100    0x01
127 #define TSC2301_I2S_SR_32000    0x02
128 #define TSC2301_I2S_SR_24000    0x03
129 #define TSC2301_I2S_SR_22050    0x04
130 #define TSC2301_I2S_SR_16000    0x05
131 #define TSC2301_I2S_SR_12000    0x06
132 #define TSC2301_I2S_SR_11050    0x07
133 #define TSC2301_I2S_SR_8000     0x08
134
135 /* 16-bit, MSB-first. DAC Right-Justified, ADC Left-Justified */
136 #define TSC2301_I2S_FORMAT0     0x00
137 /* 20-bit, MSB-first. DAC Right-Justified, ADC Left-Justified */
138 #define TSC2301_I2S_FORMAT1     0x01
139 /* 20-bit, MSB-first. DAC Left-Justified, ADC Left-Justified */
140 #define TSC2301_I2S_FORMAT2     0x02
141 /* 20-bit, MSB-first */
142 #define TSC2301_I2S_FORMAT3     0x03
143
144 /* Master Clock Ratio */
145 #define TSC2301_MCLK_256xFS     0x00 /* default */
146 #define TSC2301_MCLK_384xFS     0x01
147 #define TSC2301_MCLK_512xFS     0x02
148
149
150 extern u16 tsc2301_read_reg(struct tsc2301 *tsc, int reg);
151 extern void tsc2301_write_reg(struct tsc2301 *tsc, int reg, u16 val);
152 extern void tsc2301_write_kbc(struct tsc2301 *tsc, int val);
153 extern void tsc2301_write_pll(struct tsc2301 *tsc, int pll_n, int pll_a,
154                               int pll_pdc, int pct_e, int pll_o);
155 extern void tsc2301_read_buf(struct tsc2301 *tsc, int reg, u16 *buf, int len);
156
157 #define TSC2301_DECL_MOD(module)                                        \
158 extern int  tsc2301_##module##_init(struct tsc2301 *tsc,                \
159                            struct tsc2301_platform_data *pdata);        \
160 extern void tsc2301_##module##_exit(struct tsc2301 *tsc);               \
161 extern int  tsc2301_##module##_suspend(struct tsc2301 *tsc);            \
162 extern void tsc2301_##module##_resume(struct tsc2301 *tsc);
163
164 #define TSC2301_DECL_EMPTY_MOD(module)                                  \
165 static inline int tsc2301_##module##_init(struct tsc2301 *tsc,          \
166                            struct tsc2301_platform_data *pdata)         \
167 {                                                                       \
168         return 0;                                                       \
169 }                                                                       \
170 static inline void tsc2301_##module##_exit(struct tsc2301 *tsc) {}      \
171 static inline int  tsc2301_##module##_suspend(struct tsc2301 *tsc)      \
172 {                                                                       \
173         return 0;                                                       \
174 }                                                                       \
175 static inline void tsc2301_##module##_resume(struct tsc2301 *tsc) {}
176
177 #ifdef CONFIG_KEYBOARD_TSC2301
178 TSC2301_DECL_MOD(kp)
179 void tsc2301_kp_restart(struct tsc2301 *tsc);
180 #else
181 TSC2301_DECL_EMPTY_MOD(kp)
182 static inline void tsc2301_kp_restart(struct tsc2301 *tsc) {}
183 #endif
184
185 #ifdef CONFIG_TOUCHSCREEN_TSC2301
186 TSC2301_DECL_MOD(ts)
187 #else
188 TSC2301_DECL_EMPTY_MOD(ts)
189 #endif
190
191 #ifdef CONFIG_SPI_TSC2301_AUDIO
192 TSC2301_DECL_MOD(mixer)
193 extern void tsc2301_mixer_set_power(struct device *tsc_dev, int dac, int adc);
194
195 struct snd_card;
196 extern int tsc2301_mixer_register_controls(struct device *tsc_dev,
197                                            struct snd_card *card);
198 #else
199 TSC2301_DECL_EMPTY_MOD(mixer)
200 #endif
201
202 extern void tsc2301_mixer_enable_mclk(struct device *tsc_dev);
203 extern void tsc2301_mixer_disable_mclk(struct device *tsc_dev);
204
205 #endif