xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/sis7018/Device.h (revision 8e8f7748d39f8407894a5ab79f7b4f93bc4f4652)
1 /*
2  *	SiS 7018, Trident 4D Wave DX/NX, Acer Lab M5451 Sound Driver.
3  *	Copyright (c) 2002, 2008-2011 S.Zharski <imker@gmx.li>
4  *	Distributed under the terms of the MIT license.
5  *
6  */
7 #ifndef _SiS7018_DEVICE_H_
8 #define _SiS7018_DEVICE_H_
9 
10 
11 #include <KernelExport.h>
12 
13 #include "Driver.h"
14 #include "Mixer.h"
15 #include "Registers.h"
16 #include "Settings.h"
17 #include "Stream.h"
18 
19 
20 // card ids for supported audio hardware
21 const uint32 SiS7018	= 0x70181039;
22 const uint32 ALi5451	= 0x545110b9;
23 const uint32 TridentDX	= 0x20001023;
24 const uint32 TridentNX	= 0x20011023;
25 
26 
27 class Device {
28 
29 public:
30 		class Info {
31 		public:
32 			const uint32		fId;
33 			const char*			fName;
34 			inline const char*	Name()		{ return fName; }
35 			inline uint16		DeviceId()	{ return (fId >> 16) & 0xffff; }
36 			inline uint16		VendorId()	{ return (fId) & 0xffff; }
37 			inline uint32		Id()		{ return fId; }
38 		};
39 
40 		uint32				HardwareId() { return fInfo.Id(); }
41 		pci_info&			PCIInfo() { return fPCIInfo; }
42 
43 
44 							Device(Info &DeviceInfo, pci_info &PCIInfo);
45 							~Device();
46 
47 		status_t			Setup();
48 		status_t			InitCheck() { return fStatus; };
49 
50 		status_t			Open(uint32 flags);
51 		status_t			Read(uint8 *buffer, size_t *numBytes);
52 		status_t			Write(const uint8 *buffer, size_t *numBytes);
53 		status_t			Control(uint32 op, void *buffer, size_t length);
54 		status_t			Close();
55 		status_t			Free();
56 
57 static	int32				InterruptHandler(void *interruptParam);
58 		void				SignalReadyBuffers();
59 
60 		class Mixer&		Mixer() { return fMixer; }
61 
62 		cpu_status			Lock();
63 		void				Unlock(cpu_status st);
64 
65 		uint8				ReadPCI8(int offset);
66 		uint16				ReadPCI16(int offset);
67 		uint32				ReadPCI32(int offset);
68 		void				WritePCI8(int offset, uint8 value);
69 		void				WritePCI16(int offset, uint16 value);
70 		void				WritePCI32(int offset, uint32 value);
71 
72 private:
73 		status_t			_ReserveDeviceOnBus(bool reserve);
74 		void				_ResetCard(uint32 resetMask, uint32 releaseMask);
75 
76 		status_t			_MultiGetDescription(multi_description *Description);
77 		status_t			_MultiGetEnabledChannels(multi_channel_enable *Enable);
78 		status_t			_MultiSetEnabledChannels(multi_channel_enable *Enable);
79 		status_t			_MultiGetBuffers(multi_buffer_list* List);
80 		status_t			_MultiGetGlobalFormat(multi_format_info *Format);
81 		status_t			_MultiSetGlobalFormat(multi_format_info *Format);
82 		status_t			_MultiGetMix(multi_mix_value_info *Info);
83 		status_t			_MultiSetMix(multi_mix_value_info *Info);
84 		status_t			_MultiListMixControls(multi_mix_control_info* Info);
85 		status_t			_MultiBufferExchange(multi_buffer_info* Info);
86 
87 		status_t			fStatus;
88 		pci_info			fPCIInfo;
89 		Info&				fInfo;
90 		int					fIOBase;
91 		spinlock			fHWSpinlock;
92 		int32				fInterruptsNest;
93 		sem_id				fBuffersReadySem;
94 
95 		class Mixer			fMixer;
96 		Stream				fPlaybackStream;
97 		Stream				fRecordStream;
98 };
99 
100 #endif // _SiS7018_DEVICE_H_
101 
102