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