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