2 Copyright © 2004-2014, Davy Wentzler. All rights reserved.
6 #include <proto/exec.h>
7 #include <proto/expansion.h>
9 #include "DriverData.h"
13 #include "pci_wrapper.h"
18 static void Phase88_Start(struct CardData
*card
)
22 WriteCCI(card
, CCI_GPIO_DIR
, card
->gpio_dir
| PHASE88_RW
); // prepare for write
23 WriteCCI(card
, CCI_GPIO_MASK
, ~PHASE88_RW
); // prevent RW from switching
27 static void Phase88_Stop(struct CardData
*card
)
29 RestoreGPIOStatus(card
);
34 // Set the direction of the CLK and SDA lines:
35 // For sending, use 1, 1
36 static void Phase88_SetDir_CLK_SDA(struct CardData
*card
, int clock
, int data
)
38 unsigned char mask
= 0;
41 mask
|= PHASE88_CLOCK
; /* write SCL */
43 mask
|= PHASE88_DATA
; /* write SDA */
45 WriteCCI(card
, CCI_GPIO_DIR
, (ReadCCI(card
, CCI_GPIO_DIR
) & ~(PHASE88_CLOCK
| PHASE88_DATA
)) | mask
); // tbd: mag weg?
46 WriteCCI(card
, CCI_GPIO_MASK
, ~mask
);
51 // Write data to the SDA line and clock to the SCL
52 static void Phase88_Write_CLK_SDA(struct CardData
*card
, int clk
, int data
)
54 unsigned char tmp
= 0;
61 WriteCCI(card
, CCI_GPIO_DATA
, tmp
);
67 static int Phase88_GetClock(struct CardData
*card
)
71 tmp
= ReadCCI(card
, CCI_GPIO_DATA
);
73 if (tmp
& PHASE88_CLOCK
)
80 static int Phase88_GetDataBit(struct CardData
*card
, int ack
)
85 WriteCCI(card
, CCI_GPIO_MASK
, ~PHASE88_RW
); // clear rw mask first
86 WriteCCI(card
, CCI_GPIO_DATA
, 0); // set to read
91 // get data bit from the GPIO pines
92 bit
= ReadCCI(card
, CCI_GPIO_DATA
) & PHASE88_DATA
? 1 : 0;
94 /* set RW pin to high */
95 WriteCCI(card
, CCI_GPIO_DATA
, PHASE88_RW
); // set to write
97 /* reset write mask */
98 WriteCCI(card
, CCI_GPIO_MASK
, ~PHASE88_CLOCK
);
105 // ---------------------------------------
112 /* AK4524 chip select; address 0x48 bit 0-3 */
113 static int Phase88_CS(struct CardData
*card
, unsigned char chip_mask
)
115 unsigned char data
, ndata
;
117 if (chip_mask
> 0x0f)
120 if (ReadBytesI2C(card
, card
->i2c_out_addr
, &data
, 1) != 1)
123 ndata
= (data
& 0xf0) | chip_mask
;
125 if (WriteBytesI2C(card
, card
->i2c_out_addr
, &ndata
, 1) != 1)
131 DebugPrintF("AK4524 chip select failed, check cable to the front module\n");
136 /* start callback for PHASE88, needs to select a certain chip mask */
137 void Phase88_ak4524_lock(struct CardData
*card
, int chip
)
141 if (Phase88_CS(card
, ~(1 << chip
) & 0x0f) < 0)
142 DebugPrintF("Can't select chip\n");
144 SaveGPIOStatus(card
);
146 tmp
= PHASE88_DATA
| PHASE88_CLOCK
| PHASE88_RW
;
148 WriteCCI(card
, CCI_GPIO_DIR
, card
->gpio_dir
| tmp
);
149 WriteCCI(card
, CCI_GPIO_MASK
, ~tmp
);
153 /* stop callback for PHASE88, needs to deselect chip mask */
154 void Phase88_ak4524_unlock(struct CardData
*card
, int chip
)
156 RestoreGPIOStatus(card
);
159 Phase88_CS(card
, 0x0f);
163 static struct I2C_bit_ops Phase88_bit_ops
= {
166 Phase88_SetDir_CLK_SDA
,
167 Phase88_Write_CLK_SDA
,
173 int Phase88_Init(struct CardData
*card
)
177 /* create i2c devices */
178 card
->i2c_cs8404
= AllocI2C(0x40 >> 1);
179 card
->i2c_in_addr
= AllocI2C(0x46 >> 1);
180 card
->i2c_out_addr
= AllocI2C(0x48 >> 1);
182 card
->bit_ops
= &Phase88_bit_ops
;
185 /* Check if the front module is connected */
186 if ((err
= Phase88_CS(card
, 0x0f)) < 0) {
187 DebugPrintF("Front module not connected?\n");
192 Init_akm4xxx(card
, AKM4524
, PHASE88
);