1/*
2 * Copyright 2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *	J��r��me Duval (korli@users.berlios.de)
7 */
8
9
10#include "driver.h"
11
12
13static status_t
14geode_open(const char *name, uint32 flags, void** cookie)
15{
16	geode_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 (controller->opened)
29		return B_BUSY;
30
31	status_t status = geode_hw_init(controller);
32	if (status != B_OK)
33		return status;
34
35	atomic_add(&controller->opened, 1);
36
37	*cookie = controller;
38	return B_OK;
39}
40
41
42static status_t
43geode_read(void* cookie, off_t position, void *buf, size_t* numBytes)
44{
45	*numBytes = 0;
46		/* tell caller nothing was read */
47	return B_IO_ERROR;
48}
49
50
51static status_t
52geode_write(void* cookie, off_t position, const void* buffer, size_t* numBytes)
53{
54	*numBytes = 0;
55		/* tell caller nothing was written */
56	return B_IO_ERROR;
57}
58
59
60static status_t
61geode_control(void* cookie, uint32 op, void* arg, size_t length)
62{
63	geode_controller* controller = (geode_controller*)cookie;
64	return multi_audio_control(controller, op, arg, length);
65}
66
67
68static status_t
69geode_close(void* cookie)
70{
71	geode_controller* controller = (geode_controller*)cookie;
72	geode_hw_stop(controller);
73	atomic_add(&controller->opened, -1);
74
75	return B_OK;
76}
77
78
79static status_t
80geode_free(void* cookie)
81{
82	geode_controller* controller = (geode_controller*)cookie;
83	geode_hw_uninit(controller);
84
85	return B_OK;
86}
87
88
89device_hooks gDriverHooks = {
90	geode_open, 		/* -> open entry point */
91	geode_close, 		/* -> close entry point */
92	geode_free,		/* -> free cookie */
93	geode_control, 	/* -> control entry point */
94	geode_read,		/* -> read entry point */
95	geode_write		/* -> write entry point */
96};
97