Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)     AudioScience HPI driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)     Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) HPI Operating System Specific macros for Linux Kernel driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) (C) Copyright AudioScience Inc. 1997-2003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifndef _HPIOS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define _HPIOS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #undef HPI_OS_LINUX_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define HPI_OS_LINUX_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define HPI_OS_DEFINED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define HPI_BUILD_KERNEL_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define HPI_NO_OS_FILE_OPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /** Details of a memory area allocated with  pci_alloc_consistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) Need all info for parameters to pci_free_consistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct consistent_dma_area {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	/* looks like dma-mapping dma_devres ?! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	void *vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	dma_addr_t dma_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static inline u16 hpios_locked_mem_get_phys_addr(struct consistent_dma_area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	*locked_mem_handle, u32 *p_physical_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	*p_physical_addr = locked_mem_handle->dma_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static inline u16 hpios_locked_mem_get_virt_addr(struct consistent_dma_area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	*locked_mem_handle, void **pp_virtual_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	*pp_virtual_addr = locked_mem_handle->vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static inline u16 hpios_locked_mem_valid(struct consistent_dma_area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	*locked_mem_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return locked_mem_handle->size != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) struct hpi_ioctl_linux {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	void __user *phm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	void __user *phr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /* Conflict?: H is already used by a number of drivers hid, bluetooth hci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)    and some sound drivers sb16, hdsp, emu10k. AFAIK 0xFC is unused command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define HPI_IOCTL_LINUX _IOWR('H', 0xFC, struct hpi_ioctl_linux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define HPI_DEBUG_FLAG_ERROR   KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define HPI_DEBUG_FLAG_WARNING KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define HPI_DEBUG_FLAG_NOTICE  KERN_NOTICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define HPI_DEBUG_FLAG_INFO    KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define HPI_DEBUG_FLAG_DEBUG   KERN_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define HPI_DEBUG_FLAG_VERBOSE KERN_DEBUG	/* kernel has no verbose */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define HPI_LOCKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) struct hpios_spinlock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	spinlock_t lock;	/* SEE hpios_spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int lock_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /* The reason for all this evilness is that ALSA calls some of a drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * operators in atomic context, and some not.  But all our functions channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * through the HPI_Message conduit, so we can't handle the different context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * per function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define IN_LOCK_BH 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define IN_LOCK_IRQ 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static inline void cond_lock(struct hpios_spinlock *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (irqs_disabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		/* NO bh or isr can execute on this processor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		   so ordinary lock will do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		spin_lock(&((l)->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		l->lock_context = IN_LOCK_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		spin_lock_bh(&((l)->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		l->lock_context = IN_LOCK_BH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static inline void cond_unlock(struct hpios_spinlock *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (l->lock_context == IN_LOCK_BH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		spin_unlock_bh(&((l)->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		spin_unlock(&((l)->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define hpios_msgxlock_init(obj)      spin_lock_init(&(obj)->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define hpios_msgxlock_lock(obj)   cond_lock(obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define hpios_msgxlock_unlock(obj) cond_unlock(obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define hpios_dsplock_init(obj)       spin_lock_init(&(obj)->dsp_lock.lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define hpios_dsplock_lock(obj)    cond_lock(&(obj)->dsp_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define hpios_dsplock_unlock(obj)  cond_unlock(&(obj)->dsp_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #ifdef CONFIG_SND_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define HPI_BUILD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define HPI_ALIST_LOCKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define hpios_alistlock_init(obj)    spin_lock_init(&((obj)->list_lock.lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct snd_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /** pci drvdata points to an instance of this struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct hpi_adapter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct hpi_adapter_obj *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct snd_card *snd_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	int interrupt_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	void (*interrupt_callback) (struct hpi_adapter *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/* mutex prevents contention for one card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	   between multiple user programs (via ioctl) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	char *p_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	size_t buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #endif