Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / Envy24HT / Revo51.c
blob4795918766b1d192b1b8f0a0d99c25f2ba16b5ee
1 /*
2 Copyright © 2005-2013, Davy Wentzler. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/expansion.h>
8 #include "misc.h"
9 #include "DriverData.h"
10 #include "regs.h"
11 #include "ak_codec.h"
12 #include "Revo51.h"
15 static void Revo51_Start(struct CardData *card)
17 SaveGPIO(card->pci_dev, card);
21 static void Revo51_Stop(struct CardData *card)
23 RestoreGPIO(card->pci_dev, card);
28 // Set the direction of the CLK and SDA lines:
29 // For sending, use 1, 1
30 static void Revo51_SetDir_CLK_SDA(struct CardData *card, int clock, int data)
32 unsigned int mask = 0, val;
34 val = 0;
35 if (clock)
36 val = REVO51_I2C_CLOCK; /* write SCL */
37 if (data)
38 val |= REVO51_I2C_DATA; /* write SDA */
40 mask = REVO51_I2C_CLOCK | REVO51_I2C_DATA;
41 card->gpio_dir &= ~mask;
42 card->gpio_dir |= val;
43 SetGPIODir(card->pci_dev, card, card->gpio_dir);
44 SetGPIOMask(card, card->iobase, ~mask);
50 // Write data to the SDA line and clock to the SCL
51 static void Revo51_Write_CLK_SDA(struct CardData *card, int clk, int data)
53 unsigned int val = 0, mask = REVO51_I2C_CLOCK | REVO51_I2C_DATA;;
55 if (clk)
56 val |= REVO51_I2C_CLOCK;
57 if (data)
58 val |= REVO51_I2C_DATA;
60 card->gpio_dir |= mask;
61 SetGPIODir(card->pci_dev, card, card->gpio_dir);
62 SetGPIOMask(card, card->iobase, ~mask);
63 SetGPIOData(card, card->iobase, mask & val);
65 MicroDelay(5);
69 static int Revo51_GetDataBit(struct CardData *card, int ack)
71 int bit;
73 if (ack)
74 MicroDelay(5);
76 // get data bit from the GPIO pines
77 card->gpio_dir &= ~REVO51_I2C_DATA;
78 SetGPIODir(card->pci_dev, card, card->gpio_dir);
79 bit = GetGPIOData(card, card->iobase) & REVO51_I2C_DATA ? 1 : 0;
81 return bit;
85 static struct I2C_bit_ops Revo51_bit_ops = {
86 Revo51_Start,
87 Revo51_Stop,
88 Revo51_SetDir_CLK_SDA,
89 Revo51_Write_CLK_SDA,
90 Revo51_GetDataBit,
94 void Revo51_Init(struct CardData *card)
96 unsigned char bytes[4];
98 /* create i2c devices */
99 card->i2c = AllocI2C(0x40);
100 card->i2c->bit = &Revo51_bit_ops;
102 card->bit_ops = &Revo51_bit_ops;
104 //DEBUGPRINTF("Resetting PT2258\n");
106 // step 1: clear reg 0xC0
107 bytes[0] = 0xC0;
108 WriteBytesI2C(card, card->i2c, bytes, 1);
110 // unmute all channels
111 bytes[0] = REVO51_2258_UNMUTE;
112 WriteBytesI2C(card, card->i2c, bytes, 1);
114 // set all 6 channels to no attenuation (0dB)
115 bytes[0] = 0xD0;
116 bytes[1] = 0xE0;
117 WriteBytesI2C(card, card->i2c, bytes, 2);