xref: /haiku/src/add-ons/kernel/drivers/audio/null/driver.c (revision 1b8f7f13a3dc70e0e903cb94248220b40b732204)
1 /*
2  * Copyright 2007 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *              Bek, host.haiku@gmx.de
7  */
8 #include "driver.h"
9 
10 int32 api_version = B_CUR_DRIVER_API_VERSION;
11 device_t device;
12 
13 
14 status_t
15 init_hardware(void)
16 {
17 	dprintf("null_audio: %s\n", __func__);
18 	return B_OK;
19 }
20 
21 
22 status_t
23 init_driver(void)
24 {
25 	dprintf("null_audio: %s\n", __func__);
26 	device.running = false;
27 	return B_OK;
28 }
29 
30 
31 void
32 uninit_driver(void)
33 {
34 }
35 
36 
37 const char**
38 publish_devices(void)
39 {
40 	static const char* published_paths[] = {
41 		MULTI_AUDIO_DEV_PATH "/null/0",
42 		NULL
43 	};
44 	dprintf("null_audio: %s\n", __func__);
45 
46 	return published_paths;
47 }
48 
49 
50 static status_t
51 null_audio_open (const char *name, uint32 flags, void** cookie)
52 {
53 	dprintf("null_audio: %s\n" , __func__ );
54 	*cookie = &device;
55     return B_OK;
56 }
57 
58 
59 static status_t
60 null_audio_read (void* cookie, off_t a, void* b, size_t* num_bytes)
61 {
62 	dprintf("null_audio: %s\n" , __func__ );
63 	// Audio drivers are not supposed to return anything
64 	// inside here
65 	*num_bytes = 0;
66 	return B_IO_ERROR;
67 }
68 
69 
70 static status_t
71 null_audio_write (void* cookie, off_t a, const void* b, size_t* num_bytes)
72 {
73 	dprintf("null_audio: %s\n" , __func__ );
74 	// Audio drivers are not supposed to return anything
75 	// inside here
76 	*num_bytes = 0;
77 	return B_IO_ERROR;
78 }
79 
80 
81 static status_t
82 null_audio_control (void* cookie, uint32 op, void* arg, size_t len)
83 {
84 	//dprintf("null_audio: %s\n" , __func__ );
85 	// In case we have a valid cookie, initialized
86 	// the driver and hardware connection properly
87 	// Simply pass through to the multi audio hooks
88 	if (cookie)
89 		return multi_audio_control(cookie, op, arg, len);
90 	else
91 		dprintf("null_audio: %s called without cookie\n" , __func__);
92 
93 	// Return error in case we have no valid setup
94 	return B_BAD_VALUE;
95 }
96 
97 
98 static status_t
99 null_audio_close (void* cookie)
100 {
101 	device_t* device = (device_t*) cookie;
102 	dprintf("null_audio: %s\n" , __func__ );
103 	if (device && device->running)
104 		null_stop_hardware(device);
105 	return B_OK;
106 }
107 
108 
109 static status_t
110 null_audio_free (void* cookie)
111 {
112 	dprintf("null_audio: %s\n" , __func__ );
113 	return B_OK;
114 }
115 
116 
117 device_hooks driver_hooks = {
118         null_audio_open,
119         null_audio_close,
120         null_audio_free,
121         null_audio_control,
122         null_audio_read,
123         null_audio_write
124 };
125 
126 
127 device_hooks*
128 find_device(const char* name)
129 {
130 	return &driver_hooks;
131 }
132 
133