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 13 static status_t 14 hda_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 return B_OK; 39 } 40 41 42 static status_t 43 hda_read(void* cookie, off_t position, void* buffer, size_t* numBytes) 44 { 45 *numBytes = 0; 46 return B_IO_ERROR; 47 } 48 49 50 static status_t 51 hda_write(void* cookie, off_t position, const void* buffer, size_t* numBytes) 52 { 53 *numBytes = 0; 54 return B_IO_ERROR; 55 } 56 57 58 static status_t 59 hda_control(void* cookie, uint32 op, void* arg, size_t length) 60 { 61 hda_controller* controller = (hda_controller*)cookie; 62 if (controller->active_codec != NULL) 63 return multi_audio_control(controller->active_codec, op, arg, length); 64 65 return B_BAD_VALUE; 66 } 67 68 69 static status_t 70 hda_close(void* cookie) 71 { 72 hda_controller* controller = (hda_controller*)cookie; 73 hda_hw_stop(controller); 74 atomic_add(&controller->opened, -1); 75 76 return B_OK; 77 } 78 79 80 static status_t 81 hda_free(void* cookie) 82 { 83 hda_controller* controller = (hda_controller*)cookie; 84 hda_hw_uninit(controller); 85 86 return B_OK; 87 } 88 89 90 device_hooks gDriverHooks = { 91 hda_open, 92 hda_close, 93 hda_free, 94 hda_control, 95 hda_read, 96 hda_write 97 }; 98