static int max14688_read_left_impedence (struct device *dev)
{
    struct max14688 *me = dev_get_drvdata(dev);
    u8 adcconversion = 0;
    u8 adcstatus = 0;

    int rc;

    rc = max14688_read(me, ADCCONVERSION, &adcconversion);
    if (unlikely(rc)) {
	    log_err("ADCCONVERSION read error [%d]\n", rc);
	    goto out;
    }

    log_dbg("%s[adc value = %d]\n", __func__, adcconversion);

    /* Greater than 2.69k(ohm) resistor is connected, read the EOC bit in the ADCSTATUS address */
    max14688_read(me, ADCSTATUS, &adcstatus);
    if (!(BITS_GET(adcstatus, ADCSTATUS_EOC))) {
	    log_dbg("%s[ADC_VAL_MAX = %d]\n", __func__, (int)ADC_VAL_MAX);
	    rc = (int)ADC_VAL_MAX;
    } else {
	    rc = (int)adcconversion;
    }
out:
    return rc;
}
/**
*******************************************************************************
*
* @brief
*  Reads next numbits number of bits from the bitstream  this updates the
* bitstream offset and consumes the bits
*
* @par Description:
*  Extract required number of bits from cur_word & nxt_word  return these
* bits
*
* @param[in] ps_bitstrm
*  Pointer to bitstream structure
*
* @param[in] u4_numbits
*  Number of bits
*
* @returns  Bits read
*
* @remarks
*
*
*******************************************************************************
*/
UWORD32 ihevcd_bits_get(bitstrm_t *ps_bitstrm, UWORD32 u4_numbits)
{
    UWORD32 u4_bits_read;

    BITS_GET(u4_bits_read,
             ps_bitstrm->pu4_buf,
             ps_bitstrm->u4_bit_ofst,
             ps_bitstrm->u4_cur_word,
             ps_bitstrm->u4_nxt_word,
             u4_numbits);
    return u4_bits_read;

}
static int max14688_read_device_id (struct max14688 *me, u8 *id, u8 *rev)
{
    u8 deviceid = 0;
    int rc;

    rc = max14688_read(me, DEVICEID, &deviceid);
    if (unlikely(rc)) {
	    log_err("DEVICEID read error [%d]\n", rc);
	    goto out;
    }

    if (likely(id)) {
	    *id = BITS_GET(deviceid, DEVICEID_CHIPID);
    }

    if (likely(rev)) {
	    *rev = BITS_GET(deviceid, DEVICEID_CHIPREV);
    }

out:
    return rc;
}
Exemple #4
0
static void __UsartIsr(UsartCtrl* usartCtrl)
{
  USART_TypeDef* usart = usartCtrl->usart;

  /* Check for RX interrupt flag. */
  if (BITS_GET(usart->SR, USART_SR_RXNE))
  {
    /* Read the received data. */
    usartCtrl->rxBuffer[usartCtrl->rxBufferEnd] = usart->DR;
    usartCtrl->rxBufferEnd = ((usartCtrl->rxBufferEnd + 1U) % usartCtrl->rxBufferSize);
    /* Clear the interrupt flag. */
    BITS_CLEAR(usart->SR, USART_SR_RXNE);
  }

  /*
   * NOTE: The other interrupts should not occur since they are never enabled by this driver.
   */
}
static int max14688_read_mode1 (struct max14688 *me, int *mode1)
{
    u8 pincontrol1 = 0;
    int rc;

    rc = max14688_read(me, PINCONTROL1, &pincontrol1);
    if (unlikely(rc)) {
	    log_err("PINCONTROL1 read error [%d]\n", rc);
	    goto out;
    }

    if (likely(mode1)) {
	    *mode1 = BITS_GET(pincontrol1, PINCONTROL1_MODE1);
    }

out:
    return rc;
}
/**
*******************************************************************************
*
* @brief
*  Reads signed integer 0-th order exp-golomb-coded syntax  element from the
* bitstream. Function similar to get_uev  Section: 9.2.1
*
* @par Description:
*  Extract required number of bits from cur_word & nxt_word  return these
* bits
*
* @param[in] ps_bitstrm
*  Pointer to bitstream structure
*
* @returns  UEV decoded syntax element
*
* @remarks
*
*
*******************************************************************************
*/
WORD32 ihevcd_sev(bitstrm_t *ps_bitstrm)
{
    UWORD32 u4_bits_read;
    UWORD32 u4_clz;
    UWORD32 u4_abs_val;


    /***************************************************************/
    /* Find leading zeros in next 32 bits                          */
    /***************************************************************/
    BITS_NXT32(u4_bits_read,
               ps_bitstrm->pu4_buf,
               ps_bitstrm->u4_bit_ofst,
               ps_bitstrm->u4_cur_word,
               ps_bitstrm->u4_nxt_word);


    u4_clz = CLZ(u4_bits_read);

    BITS_FLUSH(ps_bitstrm->pu4_buf,
               ps_bitstrm->u4_bit_ofst,
               ps_bitstrm->u4_cur_word,
               ps_bitstrm->u4_nxt_word,
               (u4_clz + 1));

    u4_bits_read = 0;
    if(u4_clz)
    {
        BITS_GET(u4_bits_read,
                 ps_bitstrm->pu4_buf,
                 ps_bitstrm->u4_bit_ofst,
                 ps_bitstrm->u4_cur_word,
                 ps_bitstrm->u4_nxt_word,
                 u4_clz);
    }
    u4_abs_val = ((1 << u4_clz) + u4_bits_read) >> 1;
    if(u4_bits_read & 0x1)
        return (-(WORD32)u4_abs_val);
    else
        return (u4_abs_val);
}
/**
*******************************************************************************
*
* @brief
*  Reads unsigned integer 0-th order exp-golomb-coded syntax element from
* the bitstream  Section: 9.2
*
* @par Description:
*  Extract required number of bits from cur_word & nxt_word  return these
* bits
*
* @param[in] ps_bitstrm
*  Pointer to bitstream structure
*
* @returns  UEV decoded syntax element
*
* @remarks
*
*
*******************************************************************************
*/
UWORD32 ihevcd_uev(bitstrm_t *ps_bitstrm)
{
    UWORD32 u4_bits_read;
    UWORD32 u4_clz;


    /***************************************************************/
    /* Find leading zeros in next 32 bits                          */
    /***************************************************************/
    BITS_NXT32(u4_bits_read,
               ps_bitstrm->pu4_buf,
               ps_bitstrm->u4_bit_ofst,
               ps_bitstrm->u4_cur_word,
               ps_bitstrm->u4_nxt_word);


    u4_clz = CLZ(u4_bits_read);

    BITS_FLUSH(ps_bitstrm->pu4_buf,
               ps_bitstrm->u4_bit_ofst,
               ps_bitstrm->u4_cur_word,
               ps_bitstrm->u4_nxt_word,
               (u4_clz + 1));

    u4_bits_read = 0;
    if(u4_clz)
    {
        BITS_GET(u4_bits_read,
                 ps_bitstrm->pu4_buf,
                 ps_bitstrm->u4_bit_ofst,
                 ps_bitstrm->u4_cur_word,
                 ps_bitstrm->u4_nxt_word,
                 u4_clz);
    }
    return ((1 << u4_clz) + u4_bits_read - 1);

}
static ssize_t max14688_monitor_show (struct device *dev,
    struct device_attribute *devattr, char *buf)
{
	struct max14688 *me = dev_get_drvdata(dev);
	unsigned long flags;
	u8 irq_unmask, irq_saved, reg_val;
	int rc = 0;

	__lock(me);

	spin_lock_irqsave(&me->irq_lock, flags);
	irq_unmask = me->irq_unmask;
	irq_saved  = me->irq_saved;
	spin_unlock_irqrestore(&me->irq_lock, flags);

	/**************************************************************************/
	reg_val = 0;
	max14688_read(me, ADCCONVERSION, &reg_val);

	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"Latest ADC conversion   %u (code %02Xh)\n", reg_val, reg_val);

	/**************************************************************************/
	reg_val = 0;
	max14688_read(me, ADCSTATUS, &reg_val);

	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"ADCSTATUS register      %02Xh\n", reg_val);

	/**************************************************************************/
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"Saved Status            %02Xh\n", me->status);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  Headset is %s\n",
			BITS_GET(me->status, STATUS_DET) ? "not detected" : "detected");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  Swtich is %s\n",
			BITS_GET(me->status, STATUS_SWD) ? "pressed" : "not pressed");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  INT output is %s\n",
			BITS_GET(me->status, STATUS_INT) ? "driven high" : "not driven");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  MICIN switch is %s\n",
			BITS_GET(me->status, STATUS_MICIN) ? "closed" : "open");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  DETIN is %s\n",
			BITS_GET(me->status, STATUS_DETIN) ? "detected" : "not detected");

	/**************************************************************************/
	reg_val = 0;
	max14688_read(me, MASK, &reg_val);

	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"MASK register           %02Xh\n", reg_val);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  EOC %u DET %u SWD %u INT %u MICIN %u DETIN %u\n",
			!!(reg_val & IRQ_EOC),
			!!(reg_val & IRQ_DET),
			!!(reg_val & IRQ_SWD),
			!!(reg_val & IRQ_INT),
			!!(reg_val & IRQ_MICIN),
			!!(reg_val & IRQ_DETIN));

	/**************************************************************************/
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"Saved interrupt flags   %02Xh\n", irq_saved);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  EOC %u DET %u SWD %u INT %u MICIN %u DETIN %u\n",
			!!(irq_saved & IRQ_EOC),
			!!(irq_saved & IRQ_DET),
			!!(irq_saved & IRQ_SWD),
			!!(irq_saved & IRQ_INT),
			!!(irq_saved & IRQ_MICIN),
			!!(irq_saved & IRQ_DETIN));

	/**************************************************************************/
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"Enabled interrupt flags %02Xh\n", irq_unmask);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  EOC %u DET %u SWD %u INT %u MICIN %u DETIN %u\n",
			!!(irq_unmask & IRQ_EOC),
			!!(irq_unmask & IRQ_DET),
			!!(irq_unmask & IRQ_SWD),
			!!(irq_unmask & IRQ_INT),
			!!(irq_unmask & IRQ_MICIN),
			!!(irq_unmask & IRQ_DETIN));

	/**************************************************************************/
	reg_val = 0;
	max14688_read(me, PINCONTROL1, &reg_val);

	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"Pin control 1           %02Xh\n", reg_val);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  INT follows %s %s\n",
			BITS_GET(reg_val, PINCONTROL1_MANUALINT) ?
			"Force INT bit" : "the chip-internal decision",
			BITS_GET(reg_val, PINCONTROL1_MANUALINT) ?
			BITS_GET(reg_val, PINCONTROL1_FORCEINT) ?
			"INT is low" : "INT is high" :
			"");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  MIC_SW follows %s %s\n",
			BITS_GET(reg_val, PINCONTROL1_MANUALMICSW) ?
			"Force MIC_SW bit" : "the chip-internal decision",
			BITS_GET(reg_val, PINCONTROL1_MANUALINT) ?
			BITS_GET(reg_val, PINCONTROL1_FORCEINT) ?
			"MIC_SW is open" : "MIC_SW is closed" :
			"");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  MODE1 (Accessory Power) is %s\n",
			BITS_GET(reg_val, PINCONTROL1_MODE1) == 0b00 ? "low" :
			BITS_GET(reg_val, PINCONTROL1_MODE1) == 0b11 ? "high" :
			"in high Z");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  MODE0 (Microphone Bias) is %s\n",
			BITS_GET(reg_val, PINCONTROL1_MODE0) == 0b00 ? "low" :
			BITS_GET(reg_val, PINCONTROL1_MODE0) == 0b11 ? "high" :
			"in high Z");

	reg_val = 0;
	max14688_read(me, PINCONTROL2, &reg_val);

	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"Pin control 2           %02Xh\n", reg_val);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  INT %s\n",
			BITS_GET(reg_val, PINCONTROL2_INTAUTO) ?
			"is forced high during Z detection regardless of MODE0/1" :
			"follows the chip-internal decision");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  MIC bias output %s\n",
			BITS_GET(reg_val, PINCONTROL2_MICOUTDELAY) ?
			"delayed until Z detection after DET going low" :
			"follows the MODE0/1 after DET going low");

	/**************************************************************************/
	reg_val = 0;
	max14688_read(me, ADCCONTROL, &reg_val);

	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"ADC control             %02Xh\n", reg_val);
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  Manual control of ADC is %s\n",
			(u8)BITS_GET(reg_val, ADCCONTROL_MANUALADC) ? "on" : "off");
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  Force ADC start bit is %u\n",
			(u8)BITS_GET(reg_val, ADCCONTROL_FORCEADC));
	rc += (int)snprintf(buf+rc, PAGE_SIZE,
			"  ADC control mode is %u\n",
			(u8)BITS_GET(reg_val, ADCCONTROL_ADCCTL));

	__unlock(me);
	return (ssize_t)rc;
}
static ssize_t max14688_adc_refresh_store (struct device *dev,
    struct device_attribute *devattr, const char *buf, size_t count)
{
	struct max14688 *me = dev_get_drvdata(dev);
	unsigned long timeout;
	unsigned int delay;
	u8 adcstatus, adccontrol_save, adccontrol;
	int rc;

	__lock(me);

	adccontrol = 0;
	rc = max14688_read(me, ADCCONTROL, &adccontrol);
	if (unlikely(rc)) {
		log_err("ADCCONTROL read error [%d]\n", rc);
		goto out;
	}

	/* Save original ADCCONTROL value */
	adccontrol_save = adccontrol;

	delay = (unsigned int)simple_strtoul(buf, NULL, 10);
	if (likely(delay > 0)) {
		__msleep(delay);
	}

	adccontrol |= ADCCONTROL_FORCEADC;
	adccontrol |= ADCCONTROL_MANUALADC;

	rc = max14688_write(me, ADCCONTROL, adccontrol);
	if (unlikely(rc)) {
		log_err("ADCCONTROL write error [%d]\n", rc);
		goto out;
	}

	timeout = jiffies +
		usecs_to_jiffies(MAX14688_IDETIN_RISE_TIME) +
		usecs_to_jiffies(MAX14688_IDETIN_FALL_TIME) +
		usecs_to_jiffies(MAX14688_IDETIN_ON_TIME);

	do {
		if (unlikely(time_after(jiffies, timeout))) {
			log_err("AD conversion timed out\n");
			goto out;
		}

		__msleep(1);

		adcstatus = 0;
		max14688_read(me, ADCSTATUS, &adcstatus);

	} while (likely(!BITS_GET(adcstatus, ADCSTATUS_EOC)));

	/* Restore ADCCONTROL value and make sure FORCEADC bit cleared */
	adccontrol_save &= ~ADCCONTROL_FORCEADC;
	rc = max14688_write(me, ADCCONTROL, adccontrol_save);
	if (unlikely(rc)) {
		log_err("ADCCONTROL write error [%d]\n", rc);
		goto out;
	}

out:
	__unlock(me);
	return (ssize_t)count;
}