1758c037aSStefan Roese /* Permission is hereby granted to copy, modify and redistribute this code 2758c037aSStefan Roese * in terms of the GNU Library General Public License, Version 2 or later, 3758c037aSStefan Roese * at your option. 4758c037aSStefan Roese */ 5758c037aSStefan Roese 6*e84aba13SAlbin Tonnerre /* inline functions to translate to/from binary and binary-coded decimal 7*e84aba13SAlbin Tonnerre * (frequently found in RTC chips). 8758c037aSStefan Roese */ 9758c037aSStefan Roese 10758c037aSStefan Roese #ifndef _BCD_H 11758c037aSStefan Roese #define _BCD_H 12758c037aSStefan Roese 13*e84aba13SAlbin Tonnerre #include <linux/types.h> 14758c037aSStefan Roese 15*e84aba13SAlbin Tonnerre static inline unsigned int bcd2bin(u8 val) 16*e84aba13SAlbin Tonnerre { 17*e84aba13SAlbin Tonnerre return ((val) & 0x0f) + ((val) >> 4) * 10; 18*e84aba13SAlbin Tonnerre } 19*e84aba13SAlbin Tonnerre 20*e84aba13SAlbin Tonnerre static inline u8 bin2bcd (unsigned int val) 21*e84aba13SAlbin Tonnerre { 22*e84aba13SAlbin Tonnerre return (((val / 10) << 4) | (val % 10)); 23*e84aba13SAlbin Tonnerre } 24758c037aSStefan Roese 25758c037aSStefan Roese #endif /* _BCD_H */ 26