mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-27 20:48:22 +00:00
(Phil) A sync of the keywest driver from what the PPC people are
apparently using these days. At least it's claimed to work partially.
Here's the info:
2001/7/14 Paul Harrison:
- got write working sufficient to bring Tumbler audio up,
read still untested
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@1203 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
e836047a83
commit
4bc8bc2b96
1 file changed
+445
-309
+445
-309
@@ -19,6 +19,12 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
2001/7/14 Paul Harrison:
|
||||||
|
- got write working sufficient to bring Tumbler audio up,
|
||||||
|
read still untested
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
@@ -29,33 +35,31 @@
|
|||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
|
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
|
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
|
|
||||||
#include <asm/prom.h>
|
#include <asm/prom.h>
|
||||||
// #include <asm/dbdma.h>
|
|
||||||
// #include <asm/cuda.h>
|
|
||||||
// #include <asm/pmu.h>
|
|
||||||
#include <asm/feature.h>
|
#include <asm/feature.h>
|
||||||
#include <linux/nvram.h>
|
#include <linux/nvram.h>
|
||||||
// #include <linux/vt_kern.h>
|
|
||||||
|
|
||||||
#ifdef MODULE_LICENSE
|
/* The Tumbler audio equalizer can be really slow sometimes */
|
||||||
MODULE_LICENSE("GPL");
|
#define POLL_SANITY 10000
|
||||||
#endif
|
|
||||||
|
|
||||||
#define POLL_SANITY 100
|
|
||||||
|
|
||||||
/* PCI device */
|
/* PCI device */
|
||||||
#define VENDOR 0x106b
|
#define VENDOR 0x106b
|
||||||
#define DEVICE 0x22
|
#define DEVICE 0x22
|
||||||
|
|
||||||
/***** Protos ******/
|
/***** Protos ******/
|
||||||
s32 keywest_access(struct i2c_adapter * adap, u16 addr,
|
|
||||||
unsigned short flags, char read_write,
|
s32 keywest_access(struct i2c_adapter *adap, u16 addr,
|
||||||
u8 command, int size, union i2c_smbus_data * data);
|
unsigned short flags, char read_write,
|
||||||
|
u8 command, int size, union i2c_smbus_data *data);
|
||||||
u32 keywest_func(struct i2c_adapter *adapter);
|
u32 keywest_func(struct i2c_adapter *adapter);
|
||||||
/**/
|
|
||||||
|
/**/
|
||||||
|
|
||||||
struct keywest_iface {
|
struct keywest_iface {
|
||||||
void *base;
|
void *base;
|
||||||
@@ -73,361 +77,493 @@ struct keywest_iface {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct i2c_algorithm smbus_algorithm = {
|
static struct i2c_algorithm smbus_algorithm = {
|
||||||
/* name */ "Non-I2C SMBus adapter",
|
/* name */ "Non-I2C SMBus adapter",
|
||||||
/* id */ I2C_ALGO_SMBUS,
|
/* id */ I2C_ALGO_SMBUS,
|
||||||
/* master_xfer */ NULL,
|
/* master_xfer */ NULL,
|
||||||
/* smbus_access */ keywest_access,
|
/* smbus_access */ keywest_access,
|
||||||
/* slave_send */ NULL,
|
/* slave_send */ NULL,
|
||||||
/* slave_rcv */ NULL,
|
/* slave_rcv */ NULL,
|
||||||
/* algo_control */ NULL,
|
/* algo_control */ NULL,
|
||||||
/* functionality */ keywest_func,
|
/* functionality */ keywest_func,
|
||||||
};
|
};
|
||||||
|
|
||||||
void dump_ifaces (struct keywest_iface **ifaces);
|
void dump_ifaces(struct keywest_iface **ifaces);
|
||||||
|
int cleanup(struct keywest_iface **ifaces);
|
||||||
|
|
||||||
/***** End of Protos ******/
|
/***** End of Protos ******/
|
||||||
|
|
||||||
|
|
||||||
/** Vars **/
|
/** Vars **/
|
||||||
struct keywest_iface *ifaces=NULL;
|
|
||||||
|
struct keywest_iface *ifaces = NULL;
|
||||||
|
|
||||||
|
|
||||||
/** Functions **/
|
/** Functions **/
|
||||||
|
|
||||||
int poll_interrupt(void *ISR) {
|
/* keywest needs a small delay to defuddle itself after changing a setting */
|
||||||
int i,res;
|
void writeb_wait(int value, void *addr)
|
||||||
for (i=0; i < POLL_SANITY; i++) {
|
{
|
||||||
udelay(100);
|
writeb(value, addr);
|
||||||
if (res=readb(ISR) & 0x0F > 0) { /*printk("i2c-keywest: received interrupt: 0x%02X\n",res);*/ return res; }
|
udelay(10);
|
||||||
}
|
}
|
||||||
if (i == POLL_SANITY) { printk("i2c-keywest: Sanity check failed! Expected interrupt never happened.\n"); return -1; }
|
|
||||||
return -1; /* Should never get here */
|
int poll_interrupt(void *ISR)
|
||||||
|
{
|
||||||
|
int i, res;
|
||||||
|
for (i = 0; i < POLL_SANITY; i++) {
|
||||||
|
udelay(100);
|
||||||
|
|
||||||
|
res = readb(ISR) & 0x0F;
|
||||||
|
if (res > 0) {
|
||||||
|
/* printk("i2c-keywest: received interrupt: 0x%02X\n",res); */
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == POLL_SANITY) {
|
||||||
|
printk("i2c-keywest: Sanity check failed! Expected interrupt never happened.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1; /* Should never get here */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void keywest_reset(struct keywest_iface *ifaceptr) {
|
void keywest_reset(struct keywest_iface *ifaceptr)
|
||||||
int i;
|
{
|
||||||
int interrupt_state=1;
|
int interrupt_state;
|
||||||
|
|
||||||
/* Let's see if we can clear some busy conditions */
|
/* Clear all past interrupts */
|
||||||
// writeb(0xFF,ifaceptr->status);
|
interrupt_state = readb(ifaceptr->ISR) & 0x0F;
|
||||||
writeb(0x04,ifaceptr->control);
|
if (interrupt_state)
|
||||||
writeb(0xFF,ifaceptr->ISR);
|
writeb(interrupt_state,ifaceptr->ISR);
|
||||||
// printk("Initalizing. Ignore: ");
|
|
||||||
for (i=0;(i<10) & (interrupt_state > 0);i++) {
|
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
|
||||||
if (interrupt_state) writeb(interrupt_state,ifaceptr->ISR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 keywest_access(struct i2c_adapter * adap, u16 addr,
|
s32 keywest_access(struct i2c_adapter *adap, u16 addr,
|
||||||
unsigned short flags, char read_write,
|
unsigned short flags, char read_write,
|
||||||
u8 command, int size, union i2c_smbus_data * data) {
|
u8 command, int size, union i2c_smbus_data *data)
|
||||||
|
{
|
||||||
|
|
||||||
struct keywest_iface *ifaceptr;
|
struct keywest_iface *ifaceptr;
|
||||||
int interrupt_state=1;
|
int interrupt_state = 1;
|
||||||
int ack;
|
int ack;
|
||||||
int error_state=0;
|
int error_state = 0;
|
||||||
int len,i; /* for block transfers */
|
int len, i; /* for block transfers */
|
||||||
|
|
||||||
ifaceptr=(struct keywest_iface *)adap->data;
|
ifaceptr = (struct keywest_iface *) adap->data;
|
||||||
// printk("Keywest access called with ref to iface: 0x%X\n",ifaceptr->base);
|
|
||||||
// printk("Access request: addr:%X flags:%X rw:%X command:%X size:%X\n",
|
|
||||||
// addr, flags, read_write, command, size);
|
|
||||||
|
|
||||||
keywest_reset(ifaceptr);
|
keywest_reset(ifaceptr);
|
||||||
printk("start of transaction\n");
|
|
||||||
dump_ifaces(&ifaces);
|
|
||||||
|
|
||||||
/* see if bus is busy */
|
/* Set up address and r/w bit */
|
||||||
if ((readb(ifaceptr->status) & 1) > 0) {
|
writeb_wait(((addr << 1) | (read_write == I2C_SMBUS_READ ?1:0)),
|
||||||
printk("i2c-keywest: Busy!\n");
|
(void *) ifaceptr->addr);
|
||||||
dump_ifaces(&ifaces);
|
|
||||||
return -1;
|
/* Set up 'sub address' which I'm guessing is the command field? */
|
||||||
}
|
writeb_wait(command, (void *) ifaceptr->subaddr);
|
||||||
/* Set up address and r/w bit */
|
|
||||||
writeb(((addr << 1) | (read_write == I2C_SMBUS_READ)),(void *)ifaceptr->addr);
|
/* Start sending address */
|
||||||
/* Set up 'sub address' which I'm guessing is the command field? */
|
writeb_wait(readb(ifaceptr->control) | 2, ifaceptr->control);
|
||||||
writeb(command,(void *)ifaceptr->subaddr);
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
/* Start sending address */
|
ack = readb(ifaceptr->status) & 0x0F;
|
||||||
writeb(readb(ifaceptr->control) | 2,ifaceptr->control);
|
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
if ((ack & 0x02) == 0) {
|
||||||
ack=readb(ifaceptr->status) & 0x0F;
|
printk("i2c-keywest: Ack Status on addr expected but got: 0x%02X on addr: 0x%02X\n",
|
||||||
// printk("status:0x%02X ack:0x%02X\n",ack,interrupt_state);
|
ack, addr);
|
||||||
if ((ack & 0x02)==0) {
|
return -1;
|
||||||
printk("i2c-keywest: Ack Status on addr expected but got: 0x%02X on addr: 0x%02X\n",ack,addr);
|
}
|
||||||
return -1;
|
|
||||||
} else {
|
/* Set ACK if reading */
|
||||||
if (size & (I2C_FUNC_SMBUS_BYTE_DATA |
|
if (read_write == I2C_SMBUS_READ)
|
||||||
I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA)) {
|
writeb_wait(1 | readb(ifaceptr->control), ifaceptr->control);
|
||||||
if (read_write == I2C_SMBUS_READ)
|
|
||||||
writeb(1 | readb(ifaceptr->control),ifaceptr->control); /* Set ACK if reading */
|
switch (size) {
|
||||||
switch (size) {
|
case I2C_SMBUS_BYTE_DATA:
|
||||||
case I2C_SMBUS_BYTE_DATA:
|
if (read_write == I2C_SMBUS_WRITE) {
|
||||||
if (read_write == I2C_SMBUS_WRITE) {
|
writeb_wait(data->byte, ifaceptr->data);
|
||||||
writeb(data->byte,ifaceptr->data);
|
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
/* Clear interrupt and go */
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
if ((readb(ifaceptr->status) & 0x02) == 0) { printk("i2c-keywest: Ack Expected by not received(2)!\n"); error_state=-1; }
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
writeb(readb(ifaceptr->control) | 4,ifaceptr->control); /* Send stop */
|
if (interrupt_state < 0)
|
||||||
} else {
|
error_state = -1;
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
if ((readb(ifaceptr->status) & 0x02) == 0) {
|
||||||
data->byte=readb(ifaceptr->data);
|
printk("i2c-keywest: Ack Expected by not received(2)!\n");
|
||||||
writeb(0,ifaceptr->control); /* End read: clear ack */
|
error_state = -1;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case I2C_SMBUS_WORD_DATA:
|
/* Send stop */
|
||||||
if (read_write == I2C_SMBUS_WRITE) {
|
writeb_wait(readb(ifaceptr->control) | 4, ifaceptr->control);
|
||||||
writeb(data->word & 0x0ff,ifaceptr->data);
|
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
writeb_wait(interrupt_state, ifaceptr->control);
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
|
||||||
if ((readb(ifaceptr->status) & 0x02) == 0) { printk("i2c-keywest: Ack Expected by not received(2)!\n"); error_state=-1; }
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
writeb((data->word & 0x0ff00) >> 8,ifaceptr->data);
|
if (interrupt_state < 0)
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
error_state = -1;
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
if ((readb(ifaceptr->status) & 0x02) == 0) { printk("i2c-keywest: Ack Expected by not received(3)!\n"); error_state=-1; }
|
} else {
|
||||||
writeb(readb(ifaceptr->control) | 4,ifaceptr->control); /* Send stop */
|
/* Clear interrupt and go */
|
||||||
} else {
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
data->byte = readb(ifaceptr->data);
|
||||||
data->word=(readb(ifaceptr->data) << 8);
|
|
||||||
writeb(1,ifaceptr->control); /* Send ack */
|
/* End read: clear ack */
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
writeb_wait(0, ifaceptr->control);
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
}
|
||||||
data->word|=(readb(ifaceptr->data));
|
break;
|
||||||
writeb(0,ifaceptr->control); /* End read: clear ack */
|
|
||||||
}
|
case I2C_SMBUS_WORD_DATA:
|
||||||
break;
|
if (read_write == I2C_SMBUS_WRITE) {
|
||||||
case I2C_SMBUS_BLOCK_DATA:
|
writeb_wait(data->word & 0x0ff, ifaceptr->data);
|
||||||
if (read_write == I2C_SMBUS_WRITE) {
|
|
||||||
len = data->block[0];
|
/* Clear interrupt and go */
|
||||||
if (len < 0) len = 0;
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
if (len > 32) len = 32;
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
for (i = 1; i <= len; i++) {
|
if (interrupt_state < 0)
|
||||||
writeb(data->byte,ifaceptr->data);
|
error_state = -1;
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
if ((readb(ifaceptr->status) & 0x02) == 0) {
|
||||||
if ((readb(ifaceptr->status) & 0x02) == 0) { printk("i2c-keywest: Ack Expected by not received(block)!\n"); error_state=-1; }
|
printk("i2c-keywest: Ack Expected by not received(2)!\n");
|
||||||
}
|
error_state = -1;
|
||||||
writeb(readb(ifaceptr->control) | 4,ifaceptr->control); /* Send stop */
|
}
|
||||||
} else {
|
|
||||||
for (i = 1; i <= data->block[0]; i++) {
|
writeb_wait((data->word & 0x0ff00) >> 8,
|
||||||
writeb(1,ifaceptr->control); /* Send ack */
|
ifaceptr->data);
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
|
||||||
interrupt_state=poll_interrupt(ifaceptr->ISR);
|
/* Clear interrupt and go */
|
||||||
data->block[i] =readb(ifaceptr->data);
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
}
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
}
|
if (interrupt_state < 0)
|
||||||
break;
|
error_state = -1;
|
||||||
} /* switch */
|
|
||||||
} /* if size */
|
if ((readb(ifaceptr->status) & 0x02) == 0) {
|
||||||
} /* if ack */
|
printk("i2c-keywest: Ack Expected by not received(3)!\n");
|
||||||
writeb(0,ifaceptr->control); /* End read: clear ack */
|
error_state = -1;
|
||||||
writeb(readb(ifaceptr->control) | 4,ifaceptr->control); /* Send stop */
|
}
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt and go */
|
|
||||||
if (((interrupt_state=poll_interrupt(ifaceptr->ISR)) & 0x04) > 0)
|
/* Send stop */
|
||||||
printk("i2c-keywest: Expected stop interrupt but got: 0x%02X\n",interrupt_state);
|
writeb_wait(readb(ifaceptr->control) | 4, ifaceptr->control);
|
||||||
error_state=-1;
|
|
||||||
writeb(interrupt_state,ifaceptr->ISR); /* Clear interrupt*/
|
writeb_wait(interrupt_state, ifaceptr->control);
|
||||||
printk("Transaction complete.\n");
|
|
||||||
dump_ifaces(&ifaces);
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
return error_state;
|
if (interrupt_state < 0)
|
||||||
|
error_state = -1;
|
||||||
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
|
} else {
|
||||||
|
/* Clear interrupt and go */
|
||||||
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
|
interrupt_state =
|
||||||
|
poll_interrupt(ifaceptr->ISR);
|
||||||
|
data->word =
|
||||||
|
(readb(ifaceptr->data) << 8);
|
||||||
|
|
||||||
|
/* Send ack */
|
||||||
|
writeb_wait(1, ifaceptr->control);
|
||||||
|
|
||||||
|
/* Clear interrupt and go */
|
||||||
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
|
data->word |= (readb(ifaceptr->data));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case I2C_SMBUS_BLOCK_DATA:
|
||||||
|
if (read_write == I2C_SMBUS_WRITE) {
|
||||||
|
len = data->block[0];
|
||||||
|
if (len < 0)
|
||||||
|
len = 0;
|
||||||
|
if (len > 32)
|
||||||
|
len = 32;
|
||||||
|
|
||||||
|
for(i=1; i<=len; i++) {
|
||||||
|
writeb_wait(data->block[i],
|
||||||
|
ifaceptr->data);
|
||||||
|
|
||||||
|
/* Clear interrupt and go */
|
||||||
|
writeb_wait(interrupt_state,ifaceptr->ISR);
|
||||||
|
|
||||||
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
|
if ((readb(ifaceptr->status) & 0x02) == 0) {
|
||||||
|
printk("i2c-keywest: Ack Expected by not received(block)!\n");
|
||||||
|
error_state = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send stop */
|
||||||
|
writeb_wait(readb(ifaceptr->control) | 4, ifaceptr->control);
|
||||||
|
|
||||||
|
writeb_wait(interrupt_state, ifaceptr->control);
|
||||||
|
|
||||||
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
|
if (interrupt_state < 0)
|
||||||
|
error_state = -1;
|
||||||
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
|
} else {
|
||||||
|
for(i=1; i<=data->block[0]; i++) {
|
||||||
|
/* Send ack */
|
||||||
|
writeb_wait(1, ifaceptr->control);
|
||||||
|
|
||||||
|
/* Clear interrupt and go */
|
||||||
|
writeb_wait(interrupt_state, ifaceptr->ISR);
|
||||||
|
interrupt_state = poll_interrupt(ifaceptr->ISR);
|
||||||
|
data->block[i] = readb(ifaceptr->data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printk("i2c-keywest: operation not supported\n");
|
||||||
|
error_state = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End read: clear ack */
|
||||||
|
if (read_write == I2C_SMBUS_READ)
|
||||||
|
writeb_wait(0, ifaceptr->control);
|
||||||
|
|
||||||
|
return error_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 keywest_func(struct i2c_adapter *adapter){
|
u32 keywest_func(struct i2c_adapter * adapter)
|
||||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
{
|
||||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||||
|
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
void keywest_inc(struct i2c_adapter *adapter)
|
void keywest_inc(struct i2c_adapter *adapter)
|
||||||
{
|
{
|
||||||
MOD_INC_USE_COUNT;
|
MOD_INC_USE_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void keywest_dec(struct i2c_adapter *adapter)
|
void keywest_dec(struct i2c_adapter *adapter)
|
||||||
{
|
{
|
||||||
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**** Internal Functions ****/
|
/**** Internal Functions ****/
|
||||||
|
|
||||||
int init_iface (void *base,void *steps,struct keywest_iface **ifaces) {
|
int init_iface(void *base, void *steps, struct keywest_iface **ifaces)
|
||||||
struct i2c_adapter *keywest_adapter;
|
{
|
||||||
char *name;
|
struct i2c_adapter *keywest_adapter;
|
||||||
struct keywest_iface **temp_hdl=ifaces;
|
struct keywest_iface **temp_hdl = ifaces;
|
||||||
int res,temp;
|
int res;
|
||||||
|
|
||||||
if (ifaces == NULL) {
|
if (ifaces == NULL) {
|
||||||
printk("Ah! Passed a null handle to init_iface");
|
printk("Ah! Passed a null handle to init_iface");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while ((*temp_hdl) != NULL) {
|
|
||||||
printk("found an entry, skipping.\n");
|
|
||||||
temp_hdl=&(*temp_hdl)->next;
|
|
||||||
}
|
|
||||||
*temp_hdl=(struct keywest_iface *)kmalloc(sizeof(struct keywest_iface),GFP_KERNEL);
|
|
||||||
if (*temp_hdl == NULL) { printk("kmalloc failed on temp_hdl!"); return -1; }
|
|
||||||
(*temp_hdl)->next=NULL;
|
|
||||||
base=ioremap((int)base,(int)steps*8);
|
|
||||||
(*temp_hdl)->base=base;
|
|
||||||
(*temp_hdl)->steps=steps;
|
|
||||||
(*temp_hdl)->mode=(void *)base;
|
|
||||||
(*temp_hdl)->control=(void *)((__u32)base+(__u32)steps);
|
|
||||||
(*temp_hdl)->status=(void *)((__u32)base+(__u32)steps*2);
|
|
||||||
(*temp_hdl)->ISR=(void *)((__u32)base+(__u32)steps*3);
|
|
||||||
(*temp_hdl)->IER=(void *)((__u32)base+(__u32)steps*4);
|
|
||||||
(*temp_hdl)->addr=(void *)((__u32)base+(__u32)steps*5);
|
|
||||||
(*temp_hdl)->subaddr=(void *)((__u32)base+(__u32)steps*6);
|
|
||||||
(*temp_hdl)->data=(void *)((__u32)base+(__u32)steps*7);
|
|
||||||
keywest_adapter=(struct i2c_adapter*)kmalloc(sizeof(struct i2c_adapter),GFP_KERNEL);
|
|
||||||
memset((void *)keywest_adapter,0,(sizeof(struct i2c_adapter)));
|
|
||||||
if (keywest_adapter == NULL) { printk("kmalloc failed on keywest_adapter!"); return -1; }
|
|
||||||
strcpy(keywest_adapter->name,"keywest i2c\0");
|
|
||||||
keywest_adapter->id=I2C_ALGO_SMBUS;
|
|
||||||
keywest_adapter->algo=&smbus_algorithm;
|
|
||||||
keywest_adapter->algo_data=NULL;
|
|
||||||
keywest_adapter->inc_use=keywest_inc;
|
|
||||||
keywest_adapter->dec_use=keywest_dec;
|
|
||||||
keywest_adapter->client_register=NULL;
|
|
||||||
keywest_adapter->client_unregister=NULL;
|
|
||||||
keywest_adapter->data=(void *)(*temp_hdl);
|
|
||||||
(*temp_hdl)->i2c_adapt=keywest_adapter;
|
|
||||||
if (res=i2c_add_adapter((*temp_hdl)->i2c_adapt)) {
|
|
||||||
printk
|
|
||||||
("i2c-keywest.o: Adapter registration failed, module not inserted.\n");
|
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
/* Now actually do the initialization of the device */
|
|
||||||
writeb(0x08,(*temp_hdl)->mode); /* So-called 'standard sub-mode' */
|
|
||||||
writeb(0,(*temp_hdl)->status);
|
|
||||||
writeb(0x0FF,(*temp_hdl)->ISR);
|
|
||||||
printk("Done creating iface entry\n");
|
|
||||||
|
|
||||||
keywest_reset(*temp_hdl);
|
while ((*temp_hdl) != NULL) {
|
||||||
|
temp_hdl = &(*temp_hdl)->next;
|
||||||
|
}
|
||||||
|
|
||||||
// Test access to SDA and SCK
|
*temp_hdl =
|
||||||
printk("Serial settings: control:%02X status:%02X\n",readb((*temp_hdl)->control),readb((*temp_hdl)->status));
|
(struct keywest_iface *) kmalloc(sizeof(struct keywest_iface),
|
||||||
writeb( 0x10,(*temp_hdl)->control);
|
GFP_KERNEL);
|
||||||
temp=readb((*temp_hdl)->control);
|
if (*temp_hdl == NULL) {
|
||||||
printk("Serial settings: %02X\n",temp);
|
printk("kmalloc failed on temp_hdl!");
|
||||||
udelay(10);
|
return -1;
|
||||||
keywest_reset(*temp_hdl);
|
}
|
||||||
|
|
||||||
writeb(0x10,(*temp_hdl)->control);
|
|
||||||
temp=readb((*temp_hdl)->control);
|
|
||||||
printk("Serial settings: control:%02X status:%02X\n",readb((*temp_hdl)->control),readb((*temp_hdl)->status));
|
|
||||||
udelay(10);
|
|
||||||
keywest_reset(*temp_hdl);
|
|
||||||
|
|
||||||
writeb(0x08,(*temp_hdl)->control);
|
(*temp_hdl)->next = NULL;
|
||||||
temp=readb((*temp_hdl)->control);
|
base = ioremap((int) base, (int) steps * 8);
|
||||||
printk("Serial settings: control:%02X status:%02X\n",readb((*temp_hdl)->control),readb((*temp_hdl)->status));
|
(*temp_hdl)->base = base;
|
||||||
udelay(10);
|
(*temp_hdl)->steps = steps;
|
||||||
keywest_reset(*temp_hdl);
|
(*temp_hdl)->mode = (void *) base;
|
||||||
|
(*temp_hdl)->control = (void *) ((__u32) base + (__u32) steps);
|
||||||
|
(*temp_hdl)->status = (void *) ((__u32) base + (__u32) steps * 2);
|
||||||
|
(*temp_hdl)->ISR = (void *) ((__u32) base + (__u32) steps * 3);
|
||||||
|
(*temp_hdl)->IER = (void *) ((__u32) base + (__u32) steps * 4);
|
||||||
|
(*temp_hdl)->addr = (void *) ((__u32) base + (__u32) steps * 5);
|
||||||
|
(*temp_hdl)->subaddr = (void *) ((__u32) base + (__u32) steps * 6);
|
||||||
|
(*temp_hdl)->data = (void *) ((__u32) base + (__u32) steps * 7);
|
||||||
|
|
||||||
|
keywest_adapter =
|
||||||
|
(struct i2c_adapter *) kmalloc(sizeof(struct i2c_adapter),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (keywest_adapter == NULL) {
|
||||||
|
printk("kmalloc failed on keywest_adapter!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset((void *) keywest_adapter, 0, (sizeof(struct i2c_adapter)));
|
||||||
|
|
||||||
|
strcpy(keywest_adapter->name, "keywest i2c\0");
|
||||||
|
keywest_adapter->id = I2C_ALGO_SMBUS;
|
||||||
|
keywest_adapter->algo = &smbus_algorithm;
|
||||||
|
keywest_adapter->algo_data = NULL;
|
||||||
|
keywest_adapter->inc_use = keywest_inc;
|
||||||
|
keywest_adapter->dec_use = keywest_dec;
|
||||||
|
keywest_adapter->client_register = NULL;
|
||||||
|
keywest_adapter->client_unregister = NULL;
|
||||||
|
keywest_adapter->data = (void *) (*temp_hdl);
|
||||||
|
|
||||||
|
(*temp_hdl)->i2c_adapt = keywest_adapter;
|
||||||
|
|
||||||
|
if ((res = i2c_add_adapter((*temp_hdl)->i2c_adapt)) != 0) {
|
||||||
|
printk("i2c-keywest.o: Adapter registration failed, module not inserted.\n");
|
||||||
|
/* cleanup(); */
|
||||||
|
}
|
||||||
|
|
||||||
writeb(0x08,(*temp_hdl)->control);
|
/* Now actually do the initialization of the device */
|
||||||
temp=readb((*temp_hdl)->control);
|
|
||||||
printk("Serial settings: control:%02X status:%02X\n",readb((*temp_hdl)->control),readb((*temp_hdl)->status));
|
|
||||||
|
|
||||||
return res;
|
/* Select standard sub mode
|
||||||
|
|
||||||
|
ie for <Address><Ack><Command><Ack><data><Ack>... style transactions
|
||||||
|
*/
|
||||||
|
writeb_wait(0x08, (*temp_hdl)->mode);
|
||||||
|
|
||||||
|
/* Enable interrupts */
|
||||||
|
writeb_wait(1 + 2 + 4 + 8, (*temp_hdl)->IER);
|
||||||
|
|
||||||
|
keywest_reset(*temp_hdl);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_ifaces (struct keywest_iface **ifaces) {
|
void dump_ifaces(struct keywest_iface **ifaces)
|
||||||
if (ifaces == NULL) { printk("Ah! Passed null handle to dump!\n"); return; }
|
{
|
||||||
if (*ifaces != NULL) {
|
if (ifaces == NULL) {
|
||||||
printk("Interface @%X,%X Locations:\n",(*ifaces)->base,(*ifaces)->steps);
|
printk("Ah! Passed null handle to dump!\n");
|
||||||
printk(" mode:%X control:%X status:%X ISR:%X IER:%X addr:%X subaddr:%X data:%X\n",
|
return;
|
||||||
(*ifaces)->mode,(*ifaces)->control,(*ifaces)->status,(*ifaces)->ISR,
|
}
|
||||||
(*ifaces)->IER,(*ifaces)->addr,(*ifaces)->subaddr,(*ifaces)->data);
|
if (*ifaces != NULL) {
|
||||||
printk("Contents:\n");
|
printk("Interface @%X,%X Locations:\n", (u32) (*ifaces)->base,
|
||||||
printk(" mode:0x%02X control: 0x%02X status:0x%02X ISR:0x%02X IER:0x%02X addr:0x%02X subaddr:0x%02X data:0x%02X\n",
|
(u32) (*ifaces)->steps);
|
||||||
readb((*ifaces)->mode),readb((*ifaces)->control),readb((*ifaces)->status),readb((*ifaces)->ISR),
|
printk(" mode:%X control:%X status:%X ISR:%X IER:%X addr:%X subaddr:%X data:%X\n",
|
||||||
readb((*ifaces)->IER),readb((*ifaces)->addr),readb((*ifaces)->subaddr),
|
(u32) (*ifaces)->mode, (u32) (*ifaces)->control,
|
||||||
readb((*ifaces)->data));
|
(u32) (*ifaces)->status, (u32) (*ifaces)->ISR, (u32) (*ifaces)->IER,
|
||||||
printk("I2C-Adapter:\n");
|
(u32) (*ifaces)->addr, (u32) (*ifaces)->subaddr, (u32) (*ifaces)->data);
|
||||||
printk(" name:%s\n",(*ifaces)->i2c_adapt->name);
|
printk("Contents:\n");
|
||||||
dump_ifaces(&(*ifaces)->next);
|
printk(" mode:0x%02X control: 0x%02X status:0x%02X ISR:0x%02X IER:0x%02X addr:0x%02X subaddr:0x%02X data:0x%02X\n",
|
||||||
} else { printk("End of ifaces.\n"); }
|
readb((*ifaces)->mode), readb((*ifaces)->control),
|
||||||
|
readb((*ifaces)->status), readb((*ifaces)->ISR),
|
||||||
|
readb((*ifaces)->IER), readb((*ifaces)->addr),
|
||||||
|
readb((*ifaces)->subaddr), readb((*ifaces)->data));
|
||||||
|
printk("I2C-Adapter:\n");
|
||||||
|
printk(" name:%s\n", (*ifaces)->i2c_adapt->name);
|
||||||
|
dump_ifaces(&(*ifaces)->next);
|
||||||
|
} else {
|
||||||
|
printk("End of ifaces.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cleanup (struct keywest_iface **ifaces) {
|
int cleanup(struct keywest_iface **ifaces)
|
||||||
int res=0;
|
{
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
if (ifaces == NULL) { printk("Ah! Passed null handle to cleanup!\n"); return; }
|
if (ifaces == NULL) {
|
||||||
if (*ifaces != NULL) {
|
printk("Ah! Passed null handle to cleanup!\n");
|
||||||
printk("Cleaning up interface @%X,%X\n",(*ifaces)->base,(*ifaces)->steps);
|
return 0;
|
||||||
cleanup(&(*ifaces)->next);
|
}
|
||||||
if (res = i2c_del_adapter((*ifaces)->i2c_adapt)) {
|
|
||||||
printk ("i2c-keywest.o: i2c_del_adapter failed, module not removed\n");
|
if (*ifaces != NULL) {
|
||||||
}
|
if (cleanup(&(*ifaces)->next) != 0)
|
||||||
kfree(*ifaces);
|
res = -1;
|
||||||
iounmap((*ifaces)->base);
|
|
||||||
(*ifaces)=NULL;
|
printk("Cleaning up interface @%X,%X\n", (u32) (*ifaces)->base,
|
||||||
}
|
(u32) (*ifaces)->steps);
|
||||||
return res;
|
|
||||||
|
if (i2c_del_adapter((*ifaces)->i2c_adapt) != 0) {
|
||||||
|
printk("i2c-keywest.o: i2c_del_adapter failed, module not removed\n");
|
||||||
|
res = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
kfree(*ifaces);
|
||||||
|
iounmap((*ifaces)->base);
|
||||||
|
(*ifaces) = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
static void scan_of(char *dev_type)
|
||||||
|
{
|
||||||
|
struct device_node *np = NULL;
|
||||||
|
struct property *dp = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
static void scan_of(char *dev_type) {
|
np = find_devices(dev_type);
|
||||||
struct device_node *np=NULL;
|
|
||||||
struct property *dp=NULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
np = find_devices(dev_type);
|
if (np == 0) {
|
||||||
if (np == 0) { printk("No %s devices found.\n",dev_type); }
|
printk("No %s devices found.\n", dev_type);
|
||||||
while (np != 0 ) {
|
}
|
||||||
printk("%s found: %s, with properties:\n",dev_type,np->full_name);
|
|
||||||
dp=np->properties;
|
while (np != 0) {
|
||||||
while (dp != 0) {
|
printk("%s found: %s, with properties:\n", dev_type,
|
||||||
printk(" %s = %s [ ",dp->name,dp->value);
|
np->full_name);
|
||||||
for (i=0; i < dp->length; i++) {
|
dp = np->properties;
|
||||||
printk("%02X",(char)dp->value[i]);
|
while (dp != 0) {
|
||||||
if (((i+1) % 4) == 0) { printk(" "); }
|
printk(" %s = %s [ ", dp->name, dp->value);
|
||||||
}
|
for (i = 0; i < dp->length; i++) {
|
||||||
printk("] (length=%d)\n",dp->length);
|
printk("%02X", (char) dp->value[i]);
|
||||||
dp=dp->next;
|
if (((i + 1) % 4) == 0) {
|
||||||
}
|
printk(" ");
|
||||||
np=np->next;
|
}
|
||||||
}
|
}
|
||||||
|
printk("] (length=%d)\n", dp->length);
|
||||||
|
dp = dp->next;
|
||||||
|
}
|
||||||
|
np = np->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int find_keywest(void)
|
static int find_keywest(void)
|
||||||
{
|
{
|
||||||
struct pci_dev *s_bridge;
|
|
||||||
u8 rev;
|
|
||||||
struct device_node *i2c_device;
|
struct device_node *i2c_device;
|
||||||
struct device_node *np;
|
|
||||||
struct property *dp;
|
|
||||||
void **temp;
|
void **temp;
|
||||||
int i;
|
void *base = NULL;
|
||||||
void *base=NULL;
|
void *steps = NULL;
|
||||||
void *steps=NULL;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
scan_of("i2c");
|
scan_of("i2c");
|
||||||
#endif
|
#endif
|
||||||
// scan_of("backlight");
|
|
||||||
// scan_of("sound");
|
i2c_device = find_compatible_devices("i2c", "keywest");
|
||||||
// scan_of("ethernet");
|
|
||||||
scan_of("i2c");
|
if (i2c_device == 0) {
|
||||||
i2c_device = find_compatible_devices("i2c","keywest");
|
printk("No Keywest i2c devices found.\n");
|
||||||
if (i2c_device == 0) { printk("No Keywest i2c devices found.\n"); return -1; }
|
return -1;
|
||||||
while (i2c_device != 0) {
|
}
|
||||||
printk("Keywest device found: %s\n",i2c_device->full_name);
|
|
||||||
temp=(void **)get_property(i2c_device, "AAPL,address", NULL);
|
while (i2c_device != 0) {
|
||||||
if (temp != NULL) {base=*temp;} else {printk("no 'address' prop!\n");}
|
printk("Keywest device found: %s\n",
|
||||||
// printk("address= [%X]\n",base);
|
i2c_device->full_name);
|
||||||
temp=(void **)get_property(i2c_device, "AAPL,address-step", NULL);
|
temp =
|
||||||
if (temp != NULL) {steps=*temp;} else {printk("no 'address-step' prop!\n");}
|
(void **) get_property(i2c_device, "AAPL,address",
|
||||||
printk("Device found. base: %X steps: %X\n",base,steps);
|
NULL);
|
||||||
if (init_iface(base,steps,&ifaces) !=0 ) {
|
if (temp != NULL) {
|
||||||
cleanup(&ifaces); return -ENODEV;
|
base = *temp;
|
||||||
}
|
} else {
|
||||||
i2c_device=i2c_device->next;
|
printk("no 'address' prop!\n");
|
||||||
}
|
}
|
||||||
if (ifaces == NULL) { printk("ifaces null! :'("); }
|
|
||||||
dump_ifaces(&ifaces);
|
temp =
|
||||||
|
(void **) get_property(i2c_device, "AAPL,address-step",
|
||||||
|
NULL);
|
||||||
|
if (temp != NULL) {
|
||||||
|
steps = *temp;
|
||||||
|
} else {
|
||||||
|
printk("no 'address-step' prop!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* printk("Device found. base: %X steps: %X\n", base, steps); */
|
||||||
|
|
||||||
|
if (init_iface(base, steps, &ifaces) != 0) {
|
||||||
|
cleanup(&ifaces);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_device = i2c_device->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ifaces == NULL) {
|
||||||
|
printk("ifaces null! :'(");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dump_ifaces(&ifaces); */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user