162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Apple Onboard Audio definitions
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __AOA_H
962306a36Sopenharmony_ci#define __AOA_H
1062306a36Sopenharmony_ci#include <asm/prom.h>
1162306a36Sopenharmony_ci#include <linux/module.h>
1262306a36Sopenharmony_ci#include <sound/core.h>
1362306a36Sopenharmony_ci#include <sound/asound.h>
1462306a36Sopenharmony_ci#include <sound/control.h>
1562306a36Sopenharmony_ci#include "aoa-gpio.h"
1662306a36Sopenharmony_ci#include "soundbus/soundbus.h"
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define MAX_CODEC_NAME_LEN	32
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct aoa_codec {
2162306a36Sopenharmony_ci	char	name[MAX_CODEC_NAME_LEN];
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci	struct module *owner;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	/* called when the fabric wants to init this codec.
2662306a36Sopenharmony_ci	 * Do alsa card manipulations from here. */
2762306a36Sopenharmony_ci	int (*init)(struct aoa_codec *codec);
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci	/* called when the fabric is done with the codec.
3062306a36Sopenharmony_ci	 * The alsa card will be cleaned up so don't bother. */
3162306a36Sopenharmony_ci	void (*exit)(struct aoa_codec *codec);
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci	/* May be NULL, but can be used by the fabric.
3462306a36Sopenharmony_ci	 * Refcounting is the codec driver's responsibility */
3562306a36Sopenharmony_ci	struct device_node *node;
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci	/* assigned by fabric before init() is called, points
3862306a36Sopenharmony_ci	 * to the soundbus device. Cannot be NULL. */
3962306a36Sopenharmony_ci	struct soundbus_dev *soundbus_dev;
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	/* assigned by the fabric before init() is called, points
4262306a36Sopenharmony_ci	 * to the fabric's gpio runtime record for the relevant
4362306a36Sopenharmony_ci	 * device. */
4462306a36Sopenharmony_ci	struct gpio_runtime *gpio;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci	/* assigned by the fabric before init() is called, contains
4762306a36Sopenharmony_ci	 * a codec specific bitmask of what outputs and inputs are
4862306a36Sopenharmony_ci	 * actually connected */
4962306a36Sopenharmony_ci	u32 connected;
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	/* data the fabric can associate with this structure */
5262306a36Sopenharmony_ci	void *fabric_data;
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci	/* private! */
5562306a36Sopenharmony_ci	struct list_head list;
5662306a36Sopenharmony_ci	struct aoa_fabric *fabric;
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/* return 0 on success */
6062306a36Sopenharmony_ciextern int
6162306a36Sopenharmony_ciaoa_codec_register(struct aoa_codec *codec);
6262306a36Sopenharmony_ciextern void
6362306a36Sopenharmony_ciaoa_codec_unregister(struct aoa_codec *codec);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define MAX_LAYOUT_NAME_LEN	32
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cistruct aoa_fabric {
6862306a36Sopenharmony_ci	char	name[MAX_LAYOUT_NAME_LEN];
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci	struct module *owner;
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	/* once codecs register, they are passed here after.
7362306a36Sopenharmony_ci	 * They are of course not initialised, since the
7462306a36Sopenharmony_ci	 * fabric is responsible for initialising some fields
7562306a36Sopenharmony_ci	 * in the codec structure! */
7662306a36Sopenharmony_ci	int (*found_codec)(struct aoa_codec *codec);
7762306a36Sopenharmony_ci	/* called for each codec when it is removed,
7862306a36Sopenharmony_ci	 * also in the case that aoa_fabric_unregister
7962306a36Sopenharmony_ci	 * is called and all codecs are removed
8062306a36Sopenharmony_ci	 * from this fabric.
8162306a36Sopenharmony_ci	 * Also called if found_codec returned 0 but
8262306a36Sopenharmony_ci	 * the codec couldn't initialise. */
8362306a36Sopenharmony_ci	void (*remove_codec)(struct aoa_codec *codec);
8462306a36Sopenharmony_ci	/* If found_codec returned 0, and the codec
8562306a36Sopenharmony_ci	 * could be initialised, this is called. */
8662306a36Sopenharmony_ci	void (*attached_codec)(struct aoa_codec *codec);
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/* return 0 on success, -EEXIST if another fabric is
9062306a36Sopenharmony_ci * registered, -EALREADY if the same fabric is registered.
9162306a36Sopenharmony_ci * Passing NULL can be used to test for the presence
9262306a36Sopenharmony_ci * of another fabric, if -EALREADY is returned there is
9362306a36Sopenharmony_ci * no other fabric present.
9462306a36Sopenharmony_ci * In the case that the function returns -EALREADY
9562306a36Sopenharmony_ci * and the fabric passed is not NULL, all codecs
9662306a36Sopenharmony_ci * that are not assigned yet are passed to the fabric
9762306a36Sopenharmony_ci * again for reconsideration. */
9862306a36Sopenharmony_ciextern int
9962306a36Sopenharmony_ciaoa_fabric_register(struct aoa_fabric *fabric, struct device *dev);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* it is vital to call this when the fabric exits!
10262306a36Sopenharmony_ci * When calling, the remove_codec will be called
10362306a36Sopenharmony_ci * for all codecs, unless it is NULL. */
10462306a36Sopenharmony_ciextern void
10562306a36Sopenharmony_ciaoa_fabric_unregister(struct aoa_fabric *fabric);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/* if for some reason you want to get rid of a codec
10862306a36Sopenharmony_ci * before the fabric is removed, use this.
10962306a36Sopenharmony_ci * Note that remove_codec is called for it! */
11062306a36Sopenharmony_ciextern void
11162306a36Sopenharmony_ciaoa_fabric_unlink_codec(struct aoa_codec *codec);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* alsa help methods */
11462306a36Sopenharmony_cistruct aoa_card {
11562306a36Sopenharmony_ci	struct snd_card *alsa_card;
11662306a36Sopenharmony_ci};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ciextern int aoa_snd_device_new(enum snd_device_type type,
11962306a36Sopenharmony_ci	void *device_data, const struct snd_device_ops *ops);
12062306a36Sopenharmony_ciextern struct snd_card *aoa_get_card(void);
12162306a36Sopenharmony_ciextern int aoa_snd_ctl_add(struct snd_kcontrol* control);
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/* GPIO stuff */
12462306a36Sopenharmony_ciextern struct gpio_methods *pmf_gpio_methods;
12562306a36Sopenharmony_ciextern struct gpio_methods *ftr_gpio_methods;
12662306a36Sopenharmony_ci/* extern struct gpio_methods *map_gpio_methods; */
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci#endif /* __AOA_H */
129