This repository was archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRevo51.cpp
More file actions
113 lines (80 loc) · 2.23 KB
/
Revo51.cpp
File metadata and controls
113 lines (80 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "misc.h"
#include "DriverData.h"
#include "regs.h"
#include "ak_codec.h"
#include "Revo51.h"
#include <IOKit/IOLib.h>
static void Revo51_Start(struct CardData *card)
{
SaveGPIO(card->pci_dev, card);
}
static void Revo51_Stop(struct CardData *card)
{
RestoreGPIO(card->pci_dev, card);
}
// Set the direction of the CLK and SDA lines:
// For sending, use 1, 1
static void Revo51_SetDir_CLK_SDA(struct CardData *card, int clock, int data)
{
unsigned int mask = 0, val;
val = 0;
if (clock)
val = REVO51_I2C_CLOCK; /* write SCL */
if (data)
val |= REVO51_I2C_DATA; /* write SDA */
mask = REVO51_I2C_CLOCK | REVO51_I2C_DATA;
card->gpio_dir &= ~mask;
card->gpio_dir |= val;
SetGPIODir(card->pci_dev, card, card->gpio_dir);
SetGPIOMask(card->pci_dev, card->iobase, ~mask);
}
// Write data to the SDA line and clock to the SCL
static void Revo51_Write_CLK_SDA(struct CardData *card, int clk, int data)
{
unsigned int val = 0, mask = REVO51_I2C_CLOCK | REVO51_I2C_DATA;;
if (clk)
val |= REVO51_I2C_CLOCK;
if (data)
val |= REVO51_I2C_DATA;
card->gpio_dir |= mask;
SetGPIODir(card->pci_dev, card, card->gpio_dir);
SetGPIOMask(card->pci_dev, card->iobase, ~mask);
SetGPIOData(card->pci_dev, card->iobase, mask & val);
MicroDelay(5);
}
static int Revo51_GetDataBit(struct CardData *card, int ack)
{
int bit;
if (ack)
MicroDelay(5);
// get data bit from the GPIO pines
card->gpio_dir &= ~REVO51_I2C_DATA;
SetGPIODir(card->pci_dev, card, card->gpio_dir);
bit = GetGPIOData(card->pci_dev, card->iobase) & REVO51_I2C_DATA ? 1 : 0;
return bit;
}
static struct I2C_bit_ops Revo51_bit_ops = {
Revo51_Start,
Revo51_Stop,
Revo51_SetDir_CLK_SDA,
Revo51_Write_CLK_SDA,
Revo51_GetDataBit,
};
void Revo51_Init(struct CardData *card)
{
unsigned char bytes[4];
/* create i2c devices */
card->i2c = AllocI2C(0x40);
card->i2c->bit = &Revo51_bit_ops;
card->bit_ops = &Revo51_bit_ops;
// step 1: clear reg 0xC0
bytes[0] = 0xC0;
WriteBytesI2C(card, card->i2c, bytes, 1);
// unmute all channels
bytes[0] = REVO51_2258_UNMUTE;
WriteBytesI2C(card, card->i2c, bytes, 1);
// set all 6 channels to no attenuation (0dB)
bytes[0] = 0xD0;
bytes[1] = 0xE0;
WriteBytesI2C(card, card->i2c, bytes, 2);
}