1/*
2 * Copyright 2007-2012, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Ithamar Adema, ithamar AT unet DOT nl
7 */
8
9
10#include "driver.h"
11
12
13static status_t
14hda_open(const char* name, uint32 flags, void** cookie)
15{
16	hda_controller* controller = NULL;
17
18	for (uint32 i = 0; i < gNumCards; i++) {
19		if (strcmp(gCards[i].devfs_path, name) == 0) {
20			controller = &gCards[i];
21			break;
22		}
23	}
24
25	if (controller == NULL)
26		return ENODEV;
27
28	if (atomic_get(&controller->opened) != 0)
29		return B_BUSY;
30
31	status_t status = hda_hw_init(controller);
32	if (status != B_OK)
33		return status;
34
35	atomic_add(&controller->opened, 1);
36
37	*cookie = controller;
38
39	// optional user-settable buffer frames and count
40	get_settings_from_file();
41
42	return B_OK;
43}
44
45
46static status_t
47hda_read(void* cookie, off_t position, void* buffer, size_t* numBytes)
48{
49	*numBytes = 0;
50	return B_IO_ERROR;
51}
52
53
54static status_t
55hda_write(void* cookie, off_t position, const void* buffer, size_t* numBytes)
56{
57	*numBytes = 0;
58	return B_IO_ERROR;
59}
60
61
62static status_t
63hda_control(void* cookie, uint32 op, void* arg, size_t length)
64{
65	hda_controller* controller = (hda_controller*)cookie;
66	if (controller->active_codec != NULL)
67		return multi_audio_control(controller->active_codec, op, arg, length);
68
69	return B_BAD_VALUE;
70}
71
72
73static status_t
74hda_close(void* cookie)
75{
76	hda_controller* controller = (hda_controller*)cookie;
77	hda_hw_stop(controller);
78	atomic_add(&controller->opened, -1);
79
80	return B_OK;
81}
82
83
84static status_t
85hda_free(void* cookie)
86{
87	hda_controller* controller = (hda_controller*)cookie;
88	hda_hw_uninit(controller);
89
90	return B_OK;
91}
92
93
94device_hooks gDriverHooks = {
95	hda_open,
96	hda_close,
97	hda_free,
98	hda_control,
99	hda_read,
100	hda_write
101};
102