162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Apple Onboard Audio GPIO definitions 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __AOA_GPIO_H 962306a36Sopenharmony_ci#define __AOA_GPIO_H 1062306a36Sopenharmony_ci#include <linux/workqueue.h> 1162306a36Sopenharmony_ci#include <linux/mutex.h> 1262306a36Sopenharmony_ci#include <asm/prom.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_citypedef void (*notify_func_t)(void *data); 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_cienum notify_type { 1762306a36Sopenharmony_ci AOA_NOTIFY_HEADPHONE, 1862306a36Sopenharmony_ci AOA_NOTIFY_LINE_IN, 1962306a36Sopenharmony_ci AOA_NOTIFY_LINE_OUT, 2062306a36Sopenharmony_ci}; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistruct gpio_runtime; 2362306a36Sopenharmony_cistruct gpio_methods { 2462306a36Sopenharmony_ci /* for initialisation/de-initialisation of the GPIO layer */ 2562306a36Sopenharmony_ci void (*init)(struct gpio_runtime *rt); 2662306a36Sopenharmony_ci void (*exit)(struct gpio_runtime *rt); 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci /* turn off headphone, speakers, lineout */ 2962306a36Sopenharmony_ci void (*all_amps_off)(struct gpio_runtime *rt); 3062306a36Sopenharmony_ci /* turn headphone, speakers, lineout back to previous setting */ 3162306a36Sopenharmony_ci void (*all_amps_restore)(struct gpio_runtime *rt); 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci void (*set_headphone)(struct gpio_runtime *rt, int on); 3462306a36Sopenharmony_ci void (*set_speakers)(struct gpio_runtime *rt, int on); 3562306a36Sopenharmony_ci void (*set_lineout)(struct gpio_runtime *rt, int on); 3662306a36Sopenharmony_ci void (*set_master)(struct gpio_runtime *rt, int on); 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci int (*get_headphone)(struct gpio_runtime *rt); 3962306a36Sopenharmony_ci int (*get_speakers)(struct gpio_runtime *rt); 4062306a36Sopenharmony_ci int (*get_lineout)(struct gpio_runtime *rt); 4162306a36Sopenharmony_ci int (*get_master)(struct gpio_runtime *rt); 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci void (*set_hw_reset)(struct gpio_runtime *rt, int on); 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci /* use this to be notified of any events. The notification 4662306a36Sopenharmony_ci * function is passed the data, and is called in process 4762306a36Sopenharmony_ci * context by the use of schedule_work. 4862306a36Sopenharmony_ci * The interface for it is that setting a function to NULL 4962306a36Sopenharmony_ci * removes it, and they return 0 if the operation succeeded, 5062306a36Sopenharmony_ci * and -EBUSY if the notification is already assigned by 5162306a36Sopenharmony_ci * someone else. */ 5262306a36Sopenharmony_ci int (*set_notify)(struct gpio_runtime *rt, 5362306a36Sopenharmony_ci enum notify_type type, 5462306a36Sopenharmony_ci notify_func_t notify, 5562306a36Sopenharmony_ci void *data); 5662306a36Sopenharmony_ci /* returns 0 if not plugged in, 1 if plugged in 5762306a36Sopenharmony_ci * or a negative error code */ 5862306a36Sopenharmony_ci int (*get_detect)(struct gpio_runtime *rt, 5962306a36Sopenharmony_ci enum notify_type type); 6062306a36Sopenharmony_ci}; 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_cistruct gpio_notification { 6362306a36Sopenharmony_ci struct delayed_work work; 6462306a36Sopenharmony_ci notify_func_t notify; 6562306a36Sopenharmony_ci void *data; 6662306a36Sopenharmony_ci void *gpio_private; 6762306a36Sopenharmony_ci struct mutex mutex; 6862306a36Sopenharmony_ci}; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_cistruct gpio_runtime { 7162306a36Sopenharmony_ci /* to be assigned by fabric */ 7262306a36Sopenharmony_ci struct device_node *node; 7362306a36Sopenharmony_ci /* since everyone needs this pointer anyway... */ 7462306a36Sopenharmony_ci struct gpio_methods *methods; 7562306a36Sopenharmony_ci /* to be used by the gpio implementation */ 7662306a36Sopenharmony_ci int implementation_private; 7762306a36Sopenharmony_ci struct gpio_notification headphone_notify; 7862306a36Sopenharmony_ci struct gpio_notification line_in_notify; 7962306a36Sopenharmony_ci struct gpio_notification line_out_notify; 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#endif /* __AOA_GPIO_H */ 83