Changeset 3750

Show
Ignore:
Timestamp:
12/29/02 22:56:44 (10 years ago)
Author:
kmalkki
Message:

(Kyösti) Moved code sections from .h to .c as there was no reason to

keep them inlined.

Fix protocol byte dump. Compile bit-level protocol dump in by default.

Location:
i2c/trunk/kernel
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • i2c/trunk/kernel/i2c-algo-biths.c

    r3749 r3750  
    5151#define ALL_MSG         4 
    5252#define ALL_PROTOCOL    5 
     53#define BIT_LEVEL       9 
    5354 
    5455#define DEB1(x)         if (i2c_debug>=MODULE_STATUS) (x); 
     
    5657static void proto_x(char *d, const char *x, unsigned char y) { while (*d) d++; sprintf(d, x, y); } 
    5758#define PROTO_S(x)      if (adap->dstr) proto_s(adap->dstr, x) 
     59#define PROTO_B(x)      if ((adap->dstr) && (i2c_debug>=BIT_LEVEL)) proto_s(adap->dstr, x) 
    5860#define PROTO_X(x,y)    if (adap->dstr) proto_x(adap->dstr, x, y) 
    5961 
    60 #if 1 
    61 #define PROTO_B(x) 
    62 #define PROTO_MAX_DUMP 512  // upto 50 x " [xx] [xx]" 
    63 #else 
    64 #define PROTO_B(x) PROTO_S(x) 
    6562#define PROTO_MAX_DUMP 1024  // 50 x ".oooooooo [xx] .i[xx]" 
    66 #endif 
    6763 
    6864/* ----- global variables --------------------------------------------- */ 
     
    8379#define _sf(a)          adap->ctrl|=(a) 
    8480#define _cf(a)          adap->ctrl&=~(a) 
    85 #define ___setscl(b)    if (b) _sf(_HS_SCL); else _cf(_HS_SCL);\ 
    86                         adap->setstate(adap); adap->setscl(adap)  
    87 #define ___setsda(b)    if (b) _sf(_HS_SDA); else _cf(_HS_SDA);\ 
    88                         adap->setstate(adap); adap->setsda(adap) 
     81#define ___setscl(b)    if (b) _sf(_HS_SCL); else _cf(_HS_SCL); i2c_setscl(adap) 
     82#define ___setsda(b)    if (b) _sf(_HS_SDA); else _cf(_HS_SDA); i2c_setsda(adap) 
    8983 
    9084#define __setdt(x,dt)   if (dt) _sf(dt); x; if (dt) _cf(dt) 
    91 #define __setscl(b,dt)  __setdt(___setscl(b),dt); 
    92 #define __setsda(b,dt)  __setdt(___setsda(b),dt); 
    93 #define __getscl()      adap->getscl(adap) 
    94 #define __getsda()      adap->getsda(adap) 
    95  
     85#define __setscl(b,dt)  __setdt(___setscl(b),dt) 
     86#define __setsda(b,dt)  __setdt(___setsda(b),dt) 
     87#define __getscl()      i2c_getscl(adap) 
     88#define __getsda()      i2c_getsda(adap) 
    9689 
    9790#define RETURN_ON_FAILURE(x)            x; if (adap->errors) return 
     
    108101#define _sdalo(dt)      _setsda(0,dt) 
    109102 
    110 /* --- other auxiliary functions -------------------------------------- */ 
     103/* --- setting states on the bus with the right timing: --------------- */ 
     104 
     105static int i2c_sda_set(struct i2c_algo_biths_data *adap, int rdcount) 
     106{ 
     107    int sda; 
     108    /* allow some rise/fall time */ 
     109    while ( rdcount-- ) { 
     110        sda = adap->getsda(adap->hw_data); 
     111        if (adap->ctrl & _HS_SDA) { 
     112            if (sda) 
     113                return 0; 
     114            if (!rdcount) { 
     115                adap->errors |= _HS_SDA_ARB; 
     116                return -1; 
     117            } 
     118        } else { /* !(adap->ctrl & _HS_SDA) */ 
     119            if (!sda) 
     120                return 0; 
     121            if (!rdcount) { 
     122                adap->errors |= _HS_HW_FAIL; 
     123                return -1; 
     124            } 
     125        } 
     126    } 
     127    return 0; 
     128} 
     129 
     130static void i2c_setsda(struct i2c_algo_biths_data *adap) 
     131{ 
     132    adap->setstate(adap);  
     133    adap->setsda(adap->hw_data, adap->hw_state); 
     134    if ( !(adap->ctrl & _HS_SDA_FREE) && ! i2c_sda_set(adap, 10)) { 
     135        return; 
     136    } 
     137    adap->set_timer(adap); 
     138    adap->run_timer(adap); 
     139} 
     140 
     141static int i2c_getscl(struct i2c_algo_biths_data *adap) 
     142{ 
     143    return adap->getscl(adap->hw_data); 
     144} 
     145 
     146static int i2c_getsda(struct i2c_algo_biths_data *adap) 
     147{ 
     148    return adap->getsda(adap->hw_data); 
     149} 
     150/* 
     151 * Raise scl line, and do check for delays. This is necessary for slower 
     152 * devices. 
     153 */ 
     154 
     155static void i2c_setscl(struct i2c_algo_biths_data *adap) 
     156{ 
     157#ifndef HW_CANNOT_READ_SCL /* Not all adapters have scl sense line... */ 
     158    int rdcount = 10; 
     159    adap->setstate(adap); 
     160    adap->setscl(adap->hw_data, adap->hw_state); 
     161    if (adap->ctrl & _HS_SCL) { 
     162        unsigned long start; 
     163        /* allow some rise time */ 
     164        while (rdcount && !adap->getscl(adap->hw_data)) rdcount--; 
     165        /* else clock synchronisation, give more time */ 
     166        start = jiffies; 
     167        while (!rdcount && !adap->getscl(adap->hw_data)) { 
     168            if ( time_after(jiffies, start+adap->timeout) ) { 
     169                adap->errors |= _HS_TIMEOUT; /* scl undef */ 
     170                return; 
     171            } 
     172#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 
     173            if (current->need_resched) 
     174                schedule(); 
     175#else 
     176            cond_resched(); 
     177#endif 
     178        } 
     179        adap->set_timer(adap); 
     180        /* test for SDA arbitration when SCL is high */ 
     181        if ( !(adap->ctrl & _HS_SDA_FREE) && ! i2c_sda_set(adap, 1)) { 
     182            return; 
     183        } 
     184    } else { 
     185        /* allow some fall time */ 
     186        while (rdcount && adap->getscl(adap->hw_data)) rdcount--; 
     187        if ( !rdcount ) { 
     188            adap->errors |= _HS_HW_FAIL; 
     189            return; 
     190        } 
     191        adap->set_timer(adap); 
     192    } 
     193#else 
     194    adap->setstate(adap); 
     195    adap->setscl(adap->hw_data, adap->hw_state); 
     196    adap->set_timer(adap); 
     197#endif /* HW_CANNOT_READ_SCL */ 
     198    adap->run_timer(adap); 
     199} 
     200 
     201 
    111202/* start, repstart */ 
    112203static void i2c_start(struct i2c_algo_biths_data *adap) 
     
    175266{ 
    176267        while (*count) { 
    177             adap->shiftreg = *buf++; 
     268            adap->shiftreg = *buf; 
    178269            TRY(i2c_outbits(adap, 8)); 
    179             PROTO_X(" %02X ", adap->shiftreg); 
     270            PROTO_X(" %02X ", *buf); 
     271            buf++; 
    180272             
    181273            /* read ack: SDA should be pulled down by slave */ 
     
    200292        while (*count) { 
    201293            TRY(i2c_inbits(adap, 8)); 
    202             *buf++ = adap->shiftreg; 
    203             PROTO_X(" [%02X] ", adap->shiftreg); 
     294            *buf = adap->shiftreg; 
     295            PROTO_X(" [%02X] ", *buf); 
     296            buf++; 
    204297             
    205298            if (! (flags & I2C_M_NO_RD_ACK)) { 
     
    512605#include "i2c-algo-bit.h" 
    513606 
    514 static inline void _hw_setscl(struct i2c_algo_bit_data *old, int state) 
    515 { 
    516         old->setscl(old->data, state & _HS_SCL); 
    517 } 
    518  
    519 static inline void _hw_setsda(struct i2c_algo_bit_data *old, int state) 
    520 { 
    521         old->setsda(old->data, state & _HS_SDA); 
    522 } 
    523  
    524 static inline int _hw_getscl(struct i2c_algo_bit_data *old) 
    525 { 
     607static _HS_ATTR_ void _old_setscl(void *hw_data, int hw_state) 
     608{ 
     609        struct i2c_algo_bit_data *old = hw_data; 
     610        old->setscl(old->data, hw_state & _HS_SCL); 
     611} 
     612static _HS_ATTR_ void _old_setsda(void *hw_data, int hw_state) 
     613{ 
     614        struct i2c_algo_bit_data *old = hw_data; 
     615        old->setsda(old->data, hw_state & _HS_SDA); 
     616} 
     617static _HS_ATTR_ int _old_getscl(void *hw_data) 
     618{ 
     619        struct i2c_algo_bit_data *old = hw_data; 
    526620        return old->getscl(old->data); 
    527621} 
    528  
    529 static inline int _hw_getsda(struct i2c_algo_bit_data *old) 
    530 { 
     622static _HS_ATTR_ int _old_getsda(void *hw_data) 
     623{ 
     624        struct i2c_algo_bit_data *old = hw_data; 
    531625        return old->getsda(old->data); 
    532626} 
    533627 
    534 #define INCLUDE_BITHS_INLINES 
    535 #include "i2c-algo-biths.h" 
    536 static  _HS_ATTR_ void _old_setstate(struct i2c_algo_biths_data *adap) 
     628static _HS_ATTR_ void _old_setstate(struct i2c_algo_biths_data *adap) 
    537629{ 
    538630        adap->hw_state = adap->ctrl; 
    539 } 
    540  
    541 static _HS_ATTR_ void _old_setscl(struct i2c_algo_biths_data *adap) 
    542 { 
    543         i2c_bit_setscl(adap); 
    544 } 
    545 static _HS_ATTR_ void _old_setsda(struct i2c_algo_biths_data *adap) 
    546 { 
    547         i2c_bit_setsda(adap); 
    548 } 
    549 static _HS_ATTR_ int _old_getscl(struct i2c_algo_biths_data *adap) 
    550 { 
    551         return i2c_bit_getscl(adap); 
    552 } 
    553 static _HS_ATTR_ int _old_getsda(struct i2c_algo_biths_data *adap) 
    554 { 
    555         return i2c_bit_getsda(adap); 
    556631} 
    557632 
  • i2c/trunk/kernel/i2c-algo-biths.h

    r3749 r3750  
    5151        void *hw_data;          /* private data for lowlevel routines */ 
    5252        int hw_state; 
    53         void (*setscl)(struct i2c_algo_biths_data *adap) _HS_ATTR_ ; 
    54         void (*setsda)(struct i2c_algo_biths_data *adap) _HS_ATTR_ ; 
    55         int (*getscl) (struct i2c_algo_biths_data *adap) _HS_ATTR_ ; 
    56         int (*getsda) (struct i2c_algo_biths_data *adap) _HS_ATTR_ ; 
     53        void (*setscl)(void *hw_data, int hw_state) _HS_ATTR_ ; 
     54        void (*setsda)(void *hw_data, int hw_state) _HS_ATTR_ ; 
     55        int (*getscl) (void *hw_data) _HS_ATTR_ ; 
     56        int (*getsda) (void *hw_data) _HS_ATTR_ ; 
    5757 
    5858        void (*setstate)(struct i2c_algo_biths_data *adap) _HS_ATTR_ ; 
     
    9191 
    9292#endif /* I2C_ALGO_BITHS_H */ 
    93  
    94 #ifdef INCLUDE_BITHS_INLINES 
    95  
    96 /* --- setting states on the bus with the right timing: --------------- */ 
    97  
    98 #define _hw_timer_set(adap) adap->set_timer(adap) 
    99 #define _hw_timer_run(adap) adap->run_timer(adap) 
    100  
    101 static inline int sda_not_set(struct i2c_algo_biths_data *adap, int rdcount) 
    102 { 
    103     int sda; 
    104     /* allow some rise/fall time */ 
    105     while ( rdcount-- ) { 
    106         sda = _hw_getsda(adap->hw_data); 
    107         if (adap->ctrl & _HS_SDA) { 
    108             if (sda) 
    109                 return 0; 
    110             if (!rdcount) { 
    111                 adap->errors |= _HS_SDA_ARB; 
    112                 return -1; 
    113             } 
    114         } else { /* !(adap->ctrl & _HS_SDA) */ 
    115             if (!sda) 
    116                 return 0; 
    117             if (!rdcount) { 
    118                 adap->errors |= _HS_HW_FAIL; 
    119                 return -1; 
    120             } 
    121         } 
    122     } 
    123     return 0; 
    124 } 
    125  
    126 static inline void i2c_bit_setsda(struct i2c_algo_biths_data *adap) 
    127 { 
    128     _hw_setsda(adap->hw_data, adap->hw_state); 
    129     if ( !(adap->ctrl & _HS_SDA_FREE) && sda_not_set(adap, 10)) { 
    130         return; 
    131     } 
    132     _hw_timer_set(adap); 
    133     _hw_timer_run(adap); 
    134 } 
    135  
    136 /* 
    137  * Raise scl line, and do check for delays. This is necessary for slower 
    138  * devices. 
    139  */ 
    140  
    141 static inline void i2c_bit_setscl(struct i2c_algo_biths_data *adap) 
    142 { 
    143 #ifndef HW_CANNOT_READ_SCL /* Not all adapters have scl sense line... */ 
    144     int rdcount = 10; 
    145     _hw_setscl(adap->hw_data, adap->hw_state); 
    146     if (adap->ctrl & _HS_SCL) { 
    147         unsigned long start; 
    148         /* allow some rise time */ 
    149         while (rdcount && !_hw_getscl(adap->hw_data)) rdcount--; 
    150         /* else clock synchronisation, give more time */ 
    151         start = jiffies; 
    152         while (!rdcount && !_hw_getscl(adap->hw_data)) { 
    153             if ( time_after(jiffies, start+adap->timeout) ) { 
    154                 adap->errors |= _HS_TIMEOUT; /* scl undef */ 
    155                 return; 
    156             } 
    157 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 
    158             if (current->need_resched) 
    159                 schedule(); 
    160 #else 
    161             cond_resched(); 
    162 #endif 
    163         } 
    164         _hw_timer_set(adap); 
    165         /* test for SDA arbitration when SCL is high */ 
    166         if ( !(adap->ctrl & _HS_SDA_FREE) && sda_not_set(adap, 1)) { 
    167             return; 
    168         } 
    169     } else { 
    170         /* allow some fall time */ 
    171         while (rdcount && _hw_getscl(adap->hw_data)) rdcount--; 
    172         if ( !rdcount ) { 
    173             adap->errors |= _HS_HW_FAIL; 
    174             return; 
    175         } 
    176         _hw_timer_set(adap); 
    177     } 
    178 #else 
    179     _hw_setscl(adap->hw_data, adap->hw_state); 
    180     _hw_timer_set(adap); 
    181 #endif /* HW_CANNOT_READ_SCL */ 
    182     _hw_timer_run(adap); 
    183 } 
    184  
    185 static inline int i2c_bit_getscl(struct i2c_algo_biths_data *adap) 
    186 { 
    187     return _hw_getscl(adap->hw_data); 
    188 } 
    189  
    190 static inline int i2c_bit_getsda(struct i2c_algo_biths_data *adap) 
    191 { 
    192     return _hw_getsda(adap->hw_data); 
    193 } 
    194  
    195 #endif