18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Apple Onboard Audio definitions 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __AOA_H 98c2ecf20Sopenharmony_ci#define __AOA_H 108c2ecf20Sopenharmony_ci#include <asm/prom.h> 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <sound/core.h> 138c2ecf20Sopenharmony_ci#include <sound/asound.h> 148c2ecf20Sopenharmony_ci#include <sound/control.h> 158c2ecf20Sopenharmony_ci#include "aoa-gpio.h" 168c2ecf20Sopenharmony_ci#include "soundbus/soundbus.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define MAX_CODEC_NAME_LEN 32 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct aoa_codec { 218c2ecf20Sopenharmony_ci char name[MAX_CODEC_NAME_LEN]; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci struct module *owner; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci /* called when the fabric wants to init this codec. 268c2ecf20Sopenharmony_ci * Do alsa card manipulations from here. */ 278c2ecf20Sopenharmony_ci int (*init)(struct aoa_codec *codec); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci /* called when the fabric is done with the codec. 308c2ecf20Sopenharmony_ci * The alsa card will be cleaned up so don't bother. */ 318c2ecf20Sopenharmony_ci void (*exit)(struct aoa_codec *codec); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci /* May be NULL, but can be used by the fabric. 348c2ecf20Sopenharmony_ci * Refcounting is the codec driver's responsibility */ 358c2ecf20Sopenharmony_ci struct device_node *node; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci /* assigned by fabric before init() is called, points 388c2ecf20Sopenharmony_ci * to the soundbus device. Cannot be NULL. */ 398c2ecf20Sopenharmony_ci struct soundbus_dev *soundbus_dev; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci /* assigned by the fabric before init() is called, points 428c2ecf20Sopenharmony_ci * to the fabric's gpio runtime record for the relevant 438c2ecf20Sopenharmony_ci * device. */ 448c2ecf20Sopenharmony_ci struct gpio_runtime *gpio; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci /* assigned by the fabric before init() is called, contains 478c2ecf20Sopenharmony_ci * a codec specific bitmask of what outputs and inputs are 488c2ecf20Sopenharmony_ci * actually connected */ 498c2ecf20Sopenharmony_ci u32 connected; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci /* data the fabric can associate with this structure */ 528c2ecf20Sopenharmony_ci void *fabric_data; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci /* private! */ 558c2ecf20Sopenharmony_ci struct list_head list; 568c2ecf20Sopenharmony_ci struct aoa_fabric *fabric; 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* return 0 on success */ 608c2ecf20Sopenharmony_ciextern int 618c2ecf20Sopenharmony_ciaoa_codec_register(struct aoa_codec *codec); 628c2ecf20Sopenharmony_ciextern void 638c2ecf20Sopenharmony_ciaoa_codec_unregister(struct aoa_codec *codec); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define MAX_LAYOUT_NAME_LEN 32 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistruct aoa_fabric { 688c2ecf20Sopenharmony_ci char name[MAX_LAYOUT_NAME_LEN]; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci struct module *owner; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* once codecs register, they are passed here after. 738c2ecf20Sopenharmony_ci * They are of course not initialised, since the 748c2ecf20Sopenharmony_ci * fabric is responsible for initialising some fields 758c2ecf20Sopenharmony_ci * in the codec structure! */ 768c2ecf20Sopenharmony_ci int (*found_codec)(struct aoa_codec *codec); 778c2ecf20Sopenharmony_ci /* called for each codec when it is removed, 788c2ecf20Sopenharmony_ci * also in the case that aoa_fabric_unregister 798c2ecf20Sopenharmony_ci * is called and all codecs are removed 808c2ecf20Sopenharmony_ci * from this fabric. 818c2ecf20Sopenharmony_ci * Also called if found_codec returned 0 but 828c2ecf20Sopenharmony_ci * the codec couldn't initialise. */ 838c2ecf20Sopenharmony_ci void (*remove_codec)(struct aoa_codec *codec); 848c2ecf20Sopenharmony_ci /* If found_codec returned 0, and the codec 858c2ecf20Sopenharmony_ci * could be initialised, this is called. */ 868c2ecf20Sopenharmony_ci void (*attached_codec)(struct aoa_codec *codec); 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* return 0 on success, -EEXIST if another fabric is 908c2ecf20Sopenharmony_ci * registered, -EALREADY if the same fabric is registered. 918c2ecf20Sopenharmony_ci * Passing NULL can be used to test for the presence 928c2ecf20Sopenharmony_ci * of another fabric, if -EALREADY is returned there is 938c2ecf20Sopenharmony_ci * no other fabric present. 948c2ecf20Sopenharmony_ci * In the case that the function returns -EALREADY 958c2ecf20Sopenharmony_ci * and the fabric passed is not NULL, all codecs 968c2ecf20Sopenharmony_ci * that are not assigned yet are passed to the fabric 978c2ecf20Sopenharmony_ci * again for reconsideration. */ 988c2ecf20Sopenharmony_ciextern int 998c2ecf20Sopenharmony_ciaoa_fabric_register(struct aoa_fabric *fabric, struct device *dev); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* it is vital to call this when the fabric exits! 1028c2ecf20Sopenharmony_ci * When calling, the remove_codec will be called 1038c2ecf20Sopenharmony_ci * for all codecs, unless it is NULL. */ 1048c2ecf20Sopenharmony_ciextern void 1058c2ecf20Sopenharmony_ciaoa_fabric_unregister(struct aoa_fabric *fabric); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* if for some reason you want to get rid of a codec 1088c2ecf20Sopenharmony_ci * before the fabric is removed, use this. 1098c2ecf20Sopenharmony_ci * Note that remove_codec is called for it! */ 1108c2ecf20Sopenharmony_ciextern void 1118c2ecf20Sopenharmony_ciaoa_fabric_unlink_codec(struct aoa_codec *codec); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* alsa help methods */ 1148c2ecf20Sopenharmony_cistruct aoa_card { 1158c2ecf20Sopenharmony_ci struct snd_card *alsa_card; 1168c2ecf20Sopenharmony_ci}; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ciextern int aoa_snd_device_new(enum snd_device_type type, 1198c2ecf20Sopenharmony_ci void *device_data, const struct snd_device_ops *ops); 1208c2ecf20Sopenharmony_ciextern struct snd_card *aoa_get_card(void); 1218c2ecf20Sopenharmony_ciextern int aoa_snd_ctl_add(struct snd_kcontrol* control); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* GPIO stuff */ 1248c2ecf20Sopenharmony_ciextern struct gpio_methods *pmf_gpio_methods; 1258c2ecf20Sopenharmony_ciextern struct gpio_methods *ftr_gpio_methods; 1268c2ecf20Sopenharmony_ci/* extern struct gpio_methods *map_gpio_methods; */ 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#endif /* __AOA_H */ 129