diff options
author | nsouch <nsouch@FreeBSD.org> | 2002-03-23 15:49:15 +0000 |
---|---|---|
committer | nsouch <nsouch@FreeBSD.org> | 2002-03-23 15:49:15 +0000 |
commit | 82395b7295123f4d9a786ebd89495ef101103a61 (patch) | |
tree | f78e24d69b8d02162ae886a610fb85cac8989741 /sys/dev/ppbus/lpbb.c | |
parent | 0dcefe7b55beecbfaeba7c0b20e4b1277b781733 (diff) | |
download | FreeBSD-src-82395b7295123f4d9a786ebd89495ef101103a61.zip FreeBSD-src-82395b7295123f4d9a786ebd89495ef101103a61.tar.gz |
Major rework of the iicbus/smbus framework:
- VIA chipset SMBus controllers added
- alpm driver updated
- Support for dynamic modules added
- bktr FreeBSD smbus updated but not tested
- cleanup
Diffstat (limited to 'sys/dev/ppbus/lpbb.c')
-rw-r--r-- | sys/dev/ppbus/lpbb.c | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/sys/dev/ppbus/lpbb.c b/sys/dev/ppbus/lpbb.c index 5fd99df..0284f07 100644 --- a/sys/dev/ppbus/lpbb.c +++ b/sys/dev/ppbus/lpbb.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998 Nicolas Souchu, Marc Bouget + * Copyright (c) 1998, 2001 Nicolas Souchu, Marc Bouget * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -75,19 +75,12 @@ lpbb_probe(device_t dev) static int lpbb_attach(device_t dev) { - device_t bitbang, iicbus; + device_t bitbang; /* add generic bit-banging code */ bitbang = device_add_child(dev, "iicbb", -1); - - /* add the iicbus to the tree */ - iicbus = iicbus_alloc_bus(bitbang); - device_probe_and_attach(bitbang); - /* XXX should be in iicbb_attach! */ - device_probe_and_attach(iicbus); - return (0); } @@ -124,24 +117,30 @@ lpbb_callback(device_t dev, int index, caddr_t *data) #define ALIM 0x20 #define I2CKEY 0x50 -static int getSDA(device_t ppbus) +static int lpbb_getscl(device_t dev) +{ + return ((ppb_rstr(device_get_parent(dev)) & SCL_in) == SCL_in); +} + +static int lpbb_getsda(device_t dev) { - if((ppb_rstr(ppbus)&SDA_in)==SDA_in) - return 1; - else - return 0; + return ((ppb_rstr(device_get_parent(dev)) & SDA_in) == SDA_in); } -static void setSDA(device_t ppbus, char val) +static void lpbb_setsda(device_t dev, char val) { + device_t ppbus = device_get_parent(dev); + if(val==0) ppb_wdtr(ppbus, (u_char)SDA_out); else ppb_wdtr(ppbus, (u_char)~SDA_out); } -static void setSCL(device_t ppbus, unsigned char val) +static void lpbb_setscl(device_t dev, unsigned char val) { + device_t ppbus = device_get_parent(dev); + if(val==0) ppb_wctr(ppbus, (u_char)(ppb_rctr(ppbus)&~SCL_out)); else @@ -158,8 +157,8 @@ static int lpbb_detect(device_t dev) } /* reset bus */ - setSDA(ppbus, 1); - setSCL(ppbus, 1); + lpbb_setsda(dev, 1); + lpbb_setscl(dev, 1); if ((ppb_rstr(ppbus) & I2CKEY) || ((ppb_rstr(ppbus) & ALIM) != ALIM)) { @@ -178,28 +177,18 @@ lpbb_reset(device_t dev, u_char speed, u_char addr, u_char * oldaddr) { device_t ppbus = device_get_parent(dev); - /* reset bus */ - setSDA(ppbus, 1); - setSCL(ppbus, 1); - - return (IIC_ENOADDR); -} - -static void -lpbb_setlines(device_t dev, int ctrl, int data) -{ - device_t ppbus = device_get_parent(dev); + if (ppb_request_bus(ppbus, dev, PPB_DONTWAIT)) { + device_printf(dev, "can't allocate ppbus\n"); + return (0); + } - setSCL(ppbus, ctrl); - setSDA(ppbus, data); -} + /* reset bus */ + lpbb_setsda(dev, 1); + lpbb_setscl(dev, 1); -static int -lpbb_getdataline(device_t dev) -{ - device_t ppbus = device_get_parent(dev); + ppb_release_bus(ppbus, dev); - return (getSDA(ppbus)); + return (IIC_ENOADDR); } static devclass_t lpbb_devclass; @@ -215,8 +204,10 @@ static device_method_t lpbb_methods[] = { /* iicbb interface */ DEVMETHOD(iicbb_callback, lpbb_callback), - DEVMETHOD(iicbb_setlines, lpbb_setlines), - DEVMETHOD(iicbb_getdataline, lpbb_getdataline), + DEVMETHOD(iicbb_setsda, lpbb_setsda), + DEVMETHOD(iicbb_setscl, lpbb_setscl), + DEVMETHOD(iicbb_getsda, lpbb_getsda), + DEVMETHOD(iicbb_getscl, lpbb_getscl), DEVMETHOD(iicbb_reset, lpbb_reset), { 0, 0 } @@ -229,3 +220,5 @@ static driver_t lpbb_driver = { }; DRIVER_MODULE(lpbb, ppbus, lpbb_driver, lpbb_devclass, 0, 0); +MODULE_DEPEND(lpbb, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER); +MODULE_VERSION(lpbb, 1); |