/* Calculates a clock divider (
ISO7816 clock calculation:  */
static int usart_set_iso7816_clock(volatile avr32_usart_t *usart, unsigned int clock, unsigned long pba_hz)
/* Calculates a clock divider (
ISO7816 clock calculation:  */
static int usart_set_iso7816_clock(volatile avr32_usart_t *usart, unsigned int clock, unsigned long pba_hz)
{
  unsigned int cd = (pba_hz + clock / 2) / clock;
  if (cd < 1 || cd > (1 << AVR32_USART_BRGR_CD_SIZE) - 1)
    return USART_INVALID_INPUT;
  usart->mr = (usart->mr & ~(AVR32_USART_MR_USCLKS_MASK |
                             AVR32_USART_MR_SYNC_MASK |
                             AVR32_USART_MR_OVER_MASK)) |
              AVR32_USART_MR_USCLKS_MCK << AVR32_USART_MR_USCLKS_OFFSET |
              AVR32_USART_MR_OVER_X16 << AVR32_USART_MR_OVER_OFFSET;
  usart->brgr = cd << AVR32_USART_BRGR_CD_OFFSET;
  return USART_SUCCESS;
}