18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Apple Onboard Audio GPIO definitions
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __AOA_GPIO_H
98c2ecf20Sopenharmony_ci#define __AOA_GPIO_H
108c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
118c2ecf20Sopenharmony_ci#include <linux/mutex.h>
128c2ecf20Sopenharmony_ci#include <asm/prom.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_citypedef void (*notify_func_t)(void *data);
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cienum notify_type {
178c2ecf20Sopenharmony_ci	AOA_NOTIFY_HEADPHONE,
188c2ecf20Sopenharmony_ci	AOA_NOTIFY_LINE_IN,
198c2ecf20Sopenharmony_ci	AOA_NOTIFY_LINE_OUT,
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistruct gpio_runtime;
238c2ecf20Sopenharmony_cistruct gpio_methods {
248c2ecf20Sopenharmony_ci	/* for initialisation/de-initialisation of the GPIO layer */
258c2ecf20Sopenharmony_ci	void (*init)(struct gpio_runtime *rt);
268c2ecf20Sopenharmony_ci	void (*exit)(struct gpio_runtime *rt);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	/* turn off headphone, speakers, lineout */
298c2ecf20Sopenharmony_ci	void (*all_amps_off)(struct gpio_runtime *rt);
308c2ecf20Sopenharmony_ci	/* turn headphone, speakers, lineout back to previous setting */
318c2ecf20Sopenharmony_ci	void (*all_amps_restore)(struct gpio_runtime *rt);
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	void (*set_headphone)(struct gpio_runtime *rt, int on);
348c2ecf20Sopenharmony_ci	void (*set_speakers)(struct gpio_runtime *rt, int on);
358c2ecf20Sopenharmony_ci	void (*set_lineout)(struct gpio_runtime *rt, int on);
368c2ecf20Sopenharmony_ci	void (*set_master)(struct gpio_runtime *rt, int on);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	int (*get_headphone)(struct gpio_runtime *rt);
398c2ecf20Sopenharmony_ci	int (*get_speakers)(struct gpio_runtime *rt);
408c2ecf20Sopenharmony_ci	int (*get_lineout)(struct gpio_runtime *rt);
418c2ecf20Sopenharmony_ci	int (*get_master)(struct gpio_runtime *rt);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	void (*set_hw_reset)(struct gpio_runtime *rt, int on);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	/* use this to be notified of any events. The notification
468c2ecf20Sopenharmony_ci	 * function is passed the data, and is called in process
478c2ecf20Sopenharmony_ci	 * context by the use of schedule_work.
488c2ecf20Sopenharmony_ci	 * The interface for it is that setting a function to NULL
498c2ecf20Sopenharmony_ci	 * removes it, and they return 0 if the operation succeeded,
508c2ecf20Sopenharmony_ci	 * and -EBUSY if the notification is already assigned by
518c2ecf20Sopenharmony_ci	 * someone else. */
528c2ecf20Sopenharmony_ci	int (*set_notify)(struct gpio_runtime *rt,
538c2ecf20Sopenharmony_ci			  enum notify_type type,
548c2ecf20Sopenharmony_ci			  notify_func_t notify,
558c2ecf20Sopenharmony_ci			  void *data);
568c2ecf20Sopenharmony_ci	/* returns 0 if not plugged in, 1 if plugged in
578c2ecf20Sopenharmony_ci	 * or a negative error code */
588c2ecf20Sopenharmony_ci	int (*get_detect)(struct gpio_runtime *rt,
598c2ecf20Sopenharmony_ci			  enum notify_type type);
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct gpio_notification {
638c2ecf20Sopenharmony_ci	struct delayed_work work;
648c2ecf20Sopenharmony_ci	notify_func_t notify;
658c2ecf20Sopenharmony_ci	void *data;
668c2ecf20Sopenharmony_ci	void *gpio_private;
678c2ecf20Sopenharmony_ci	struct mutex mutex;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct gpio_runtime {
718c2ecf20Sopenharmony_ci	/* to be assigned by fabric */
728c2ecf20Sopenharmony_ci	struct device_node *node;
738c2ecf20Sopenharmony_ci	/* since everyone needs this pointer anyway... */
748c2ecf20Sopenharmony_ci	struct gpio_methods *methods;
758c2ecf20Sopenharmony_ci	/* to be used by the gpio implementation */
768c2ecf20Sopenharmony_ci	int implementation_private;
778c2ecf20Sopenharmony_ci	struct gpio_notification headphone_notify;
788c2ecf20Sopenharmony_ci	struct gpio_notification line_in_notify;
798c2ecf20Sopenharmony_ci	struct gpio_notification line_out_notify;
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#endif /* __AOA_GPIO_H */
83