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 6e84aba13SAlbin Tonnerre /* inline functions to translate to/from binary and binary-coded decimal 7e84aba13SAlbin Tonnerre * (frequently found in RTC chips). 8758c037aSStefan Roese */ 9758c037aSStefan Roese 10758c037aSStefan Roese #ifndef _BCD_H 11758c037aSStefan Roese #define _BCD_H 12758c037aSStefan Roese bcd2bin(unsigned int val)13*be47aa65SSimon Glassstatic inline unsigned int bcd2bin(unsigned int val) 14e84aba13SAlbin Tonnerre { 15*be47aa65SSimon Glass return ((val) & 0x0f) + ((val & 0xff) >> 4) * 10; 16e84aba13SAlbin Tonnerre } 17e84aba13SAlbin Tonnerre bin2bcd(unsigned int val)18*be47aa65SSimon Glassstatic inline unsigned int bin2bcd(unsigned int val) 19e84aba13SAlbin Tonnerre { 20e84aba13SAlbin Tonnerre return (((val / 10) << 4) | (val % 10)); 21e84aba13SAlbin Tonnerre } 22758c037aSStefan Roese 23758c037aSStefan Roese #endif /* _BCD_H */ 24