xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/sis7018/Device.h (revision 07910542fd067906c6028cfc48f5ad38b32181fd)
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 		cpu_status			Lock();
61 		void				Unlock(cpu_status st);
62 
63 		uint8				ReadPCI8(int offset);
64 		uint16				ReadPCI16(int offset);
65 		uint32				ReadPCI32(int offset);
66 		void				WritePCI8(int offset, uint8 value);
67 		void				WritePCI16(int offset, uint16 value);
68 		void				WritePCI32(int offset, uint32 value);
69 
70 private:
71 		status_t			_ReserveDeviceOnBus(bool reserve);
72 		void				_ResetCard(uint32 resetMask, uint32 releaseMask);
73 
74 		status_t			_MultiGetDescription(multi_description *Description);
75 		status_t			_MultiGetEnabledChannels(multi_channel_enable *Enable);
76 		status_t			_MultiSetEnabledChannels(multi_channel_enable *Enable);
77 		status_t			_MultiGetBuffers(multi_buffer_list* List);
78 		status_t			_MultiGetGlobalFormat(multi_format_info *Format);
79 		status_t			_MultiSetGlobalFormat(multi_format_info *Format);
80 		status_t			_MultiGetMix(multi_mix_value_info *Info);
81 		status_t			_MultiSetMix(multi_mix_value_info *Info);
82 		status_t			_MultiListMixControls(multi_mix_control_info* Info);
83 		status_t			_MultiBufferExchange(multi_buffer_info* Info);
84 
85 		status_t			fStatus;
86 		pci_info			fPCIInfo;
87 		Info&				fInfo;
88 		int					fIOBase;
89 		int32				fHWSpinlock;
90 		int32				fInterruptsNest;
91 		sem_id				fBuffersReadySem;
92 
93 		Mixer				fMixer;
94 		Stream				fPlaybackStream;
95 		Stream				fRecordStream;
96 };
97 
98 #endif // _SiS7018_DEVICE_H_
99 
100