25 static int headphone_mute_gpio;
26 static int master_mute_gpio;
27 static int amp_mute_gpio;
28 static int lineout_mute_gpio;
29 static int hw_reset_gpio;
30 static int lineout_detect_gpio;
31 static int headphone_detect_gpio;
32 static int linein_detect_gpio;
35 static int headphone_mute_gpio_activestate;
36 static int master_mute_gpio_activestate;
37 static int amp_mute_gpio_activestate;
38 static int lineout_mute_gpio_activestate;
39 static int hw_reset_gpio_activestate;
40 static int lineout_detect_gpio_activestate;
41 static int headphone_detect_gpio_activestate;
42 static int linein_detect_gpio_activestate;
50 static int lineout_detect_irq;
51 static int linein_detect_irq;
52 static int headphone_detect_irq;
61 const char *audio_gpio;
79 if (
strcmp(audio_gpio, name) == 0)
81 if (altname && (
strcmp(audio_gpio, altname) == 0))
110 *gpioactiveptr = *
reg;
124 #define SWITCH_GPIO(name, v, on) \
126 (name##_gpio_activestate==0?4:5): \
127 (name##_gpio_activestate==0?5:4)))
129 #define FTR_GPIO(name, bit) \
130 static void ftr_gpio_set_##name(struct gpio_runtime *rt, int on)\
134 if (unlikely(!rt)) return; \
136 if (name##_mute_gpio < 0) \
139 v = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, \
144 v = SWITCH_GPIO(name##_mute, v, !on); \
146 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, \
147 name##_mute_gpio, v); \
149 rt->implementation_private &= ~(1<<bit); \
150 rt->implementation_private |= (!!on << bit); \
152 static int ftr_gpio_get_##name(struct gpio_runtime *rt) \
154 if (unlikely(!rt)) return 0; \
155 return (rt->implementation_private>>bit)&1; \
163 static void ftr_gpio_set_hw_reset(
struct gpio_runtime *rt,
int on)
168 if (hw_reset_gpio < 0)
171 v = pmac_call_feature(PMAC_FTR_READ_GPIO,
NULL,
174 pmac_call_feature(PMAC_FTR_WRITE_GPIO,
NULL,
180 static void ftr_gpio_all_amps_off(
struct gpio_runtime *rt)
186 ftr_gpio_set_headphone(rt, 0);
187 ftr_gpio_set_amp(rt, 0);
188 ftr_gpio_set_lineout(rt, 0);
190 ftr_gpio_set_master(rt, 0);
194 static void ftr_gpio_all_amps_restore(
struct gpio_runtime *rt)
200 ftr_gpio_set_headphone(rt, (s>>0)&1);
201 ftr_gpio_set_amp(rt, (s>>1)&1);
202 ftr_gpio_set_lineout(rt, (s>>2)&1);
204 ftr_gpio_set_master(rt, (s>>3)&1);
218 static void gpio_enable_dual_edge(
int gpio)
224 v = pmac_call_feature(PMAC_FTR_READ_GPIO,
NULL, gpio, 0);
226 pmac_call_feature(PMAC_FTR_WRITE_GPIO,
NULL, gpio, v);
231 get_gpio(
"headphone-mute",
NULL,
232 &headphone_mute_gpio,
233 &headphone_mute_gpio_activestate);
234 get_gpio(
"amp-mute",
NULL,
236 &_mute_gpio_activestate);
237 get_gpio(
"lineout-mute",
NULL,
239 &lineout_mute_gpio_activestate);
240 get_gpio(
"hw-reset",
"audio-hw-reset",
242 &hw_reset_gpio_activestate);
243 if (get_gpio(
"master-mute",
NULL,
245 &master_mute_gpio_activestate)) {
246 methods.set_master = ftr_gpio_set_master;
247 methods.get_master = ftr_gpio_get_master;
250 headphone_detect_node = get_gpio(
"headphone-detect",
NULL,
251 &headphone_detect_gpio,
252 &headphone_detect_gpio_activestate);
255 lineout_detect_node = get_gpio(
"lineout-detect",
"line-output-detect",
256 &lineout_detect_gpio,
257 &lineout_detect_gpio_activestate);
258 linein_detect_node = get_gpio(
"linein-detect",
"line-input-detect",
260 &linein_detect_gpio_activestate);
262 gpio_enable_dual_edge(headphone_detect_gpio);
263 gpio_enable_dual_edge(lineout_detect_gpio);
264 gpio_enable_dual_edge(linein_detect_gpio);
266 get_irq(headphone_detect_node, &headphone_detect_irq);
267 get_irq(lineout_detect_node, &lineout_detect_irq);
268 get_irq(linein_detect_node, &linein_detect_irq);
270 ftr_gpio_all_amps_off(rt);
282 ftr_gpio_all_amps_off(rt);
321 name =
"headphone-detect";
322 irq = headphone_detect_irq;
326 name =
"linein-detect";
327 irq = linein_detect_irq;
331 name =
"lineout-detect";
332 irq = lineout_detect_irq;
345 if (!old && !notify) {
351 if (old == notify && notif->
data == data)
359 if (!old && notify) {
360 err =
request_irq(irq, ftr_handle_notify_irq, 0, name, notif);
381 gpio = headphone_detect_gpio;
382 active = headphone_detect_gpio_activestate;
385 gpio = linein_detect_gpio;
386 active = linein_detect_gpio_activestate;
389 gpio = lineout_detect_gpio;
390 active = lineout_detect_gpio_activestate;
399 ret = pmac_call_feature(PMAC_FTR_READ_GPIO,
NULL, gpio, 0);
402 return ((ret >> 1) & 1) ==
active;
406 .init = ftr_gpio_init,
407 .exit = ftr_gpio_exit,
408 .all_amps_off = ftr_gpio_all_amps_off,
409 .all_amps_restore = ftr_gpio_all_amps_restore,
410 .set_headphone = ftr_gpio_set_headphone,
411 .set_speakers = ftr_gpio_set_amp,
412 .set_lineout = ftr_gpio_set_lineout,
413 .set_hw_reset = ftr_gpio_set_hw_reset,
414 .get_headphone = ftr_gpio_get_headphone,
415 .get_speakers = ftr_gpio_get_amp,
416 .get_lineout = ftr_gpio_get_lineout,
417 .set_notify = ftr_set_notify,
418 .get_detect = ftr_get_detect,