^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Apple Onboard Audio GPIO definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef __AOA_GPIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define __AOA_GPIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) typedef void (*notify_func_t)(void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) enum notify_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) AOA_NOTIFY_HEADPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) AOA_NOTIFY_LINE_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) AOA_NOTIFY_LINE_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct gpio_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct gpio_methods {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* for initialisation/de-initialisation of the GPIO layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) void (*init)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void (*exit)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* turn off headphone, speakers, lineout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) void (*all_amps_off)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* turn headphone, speakers, lineout back to previous setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void (*all_amps_restore)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void (*set_headphone)(struct gpio_runtime *rt, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void (*set_speakers)(struct gpio_runtime *rt, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) void (*set_lineout)(struct gpio_runtime *rt, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) void (*set_master)(struct gpio_runtime *rt, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int (*get_headphone)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int (*get_speakers)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int (*get_lineout)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int (*get_master)(struct gpio_runtime *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void (*set_hw_reset)(struct gpio_runtime *rt, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* use this to be notified of any events. The notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * function is passed the data, and is called in process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * context by the use of schedule_work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * The interface for it is that setting a function to NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * removes it, and they return 0 if the operation succeeded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * and -EBUSY if the notification is already assigned by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * someone else. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int (*set_notify)(struct gpio_runtime *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) enum notify_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) notify_func_t notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* returns 0 if not plugged in, 1 if plugged in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * or a negative error code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int (*get_detect)(struct gpio_runtime *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) enum notify_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct gpio_notification {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) notify_func_t notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) void *gpio_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct gpio_runtime {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* to be assigned by fabric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* since everyone needs this pointer anyway... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct gpio_methods *methods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* to be used by the gpio implementation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int implementation_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct gpio_notification headphone_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct gpio_notification line_in_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct gpio_notification line_out_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #endif /* __AOA_GPIO_H */