BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / ac97 / es1370 / io.c
blobf7617c545bd295df4acb179e4f08e1a8b541a96a
1 /*
2 * ES1370 Haiku Driver for ES1370 audio
4 * Copyright 2002-2007, Haiku, Inc.
5 * Distributed under the terms of the MIT License.
7 * Authors:
8 * Marcus Overhagen, marcus@overhagen.de
9 * Jerome Duval, jerome.duval@free.fr
11 #include <KernelExport.h>
12 #include <OS.h>
13 #include "io.h"
14 #include "es1370reg.h"
15 #include "debug.h"
16 #include <PCI.h>
18 extern pci_module_info *pci;
20 uint8
21 es1370_reg_read_8(device_config *config, int regno)
23 ASSERT(regno >= 0);
24 return pci->read_io_8(config->base + regno);
27 uint16
28 es1370_reg_read_16(device_config *config, int regno)
30 ASSERT(regno >= 0);
31 return pci->read_io_16(config->base + regno);
34 uint32
35 es1370_reg_read_32(device_config *config, int regno)
37 ASSERT(regno >= 0);
38 return pci->read_io_32(config->base + regno);
41 void
42 es1370_reg_write_8(device_config *config, int regno, uint8 value)
44 ASSERT(regno >= 0);
45 pci->write_io_8(config->base + regno, value);
48 void
49 es1370_reg_write_16(device_config *config, int regno, uint16 value)
51 ASSERT(regno >= 0);
52 pci->write_io_16(config->base + regno, value);
55 void
56 es1370_reg_write_32(device_config *config, int regno, uint32 value)
58 ASSERT(regno >= 0);
59 pci->write_io_32(config->base + regno, value);
62 /* codec */
63 static int
64 es1370_codec_wait(device_config *config)
66 int i;
67 for (i = 0; i < 1100; i++) {
68 if ((es1370_reg_read_32(config, ES1370_REG_STATUS) & STAT_CWRIP) == 0)
69 return B_OK;
70 if (i > 100)
71 spin(1);
73 return B_TIMED_OUT;
76 uint16
77 es1370_codec_read(device_config *config, int regno)
79 ASSERT(regno >= 0);
80 if(es1370_codec_wait(config)!=B_OK) {
81 PRINT(("codec busy (2)\n"));
82 return -1;
85 return pci->read_io_32(config->base + ES1370_REG_CODEC);
88 void
89 es1370_codec_write(device_config *config, int regno, uint16 value)
91 ASSERT(regno >= 0);
92 if(es1370_codec_wait(config)!=B_OK) {
93 PRINT(("codec busy (4)\n"));
94 return;
96 pci->write_io_32(config->base + ES1370_REG_CODEC, (regno << 8) | value);