/* write a new value to an AD1843 bitfield and return the old value.  */
static int ad1843_write_bits(lithium_t *lith, const ad1843_bitfield_t *field, int newval)
/* write a new value to an AD1843 bitfield and return the old value.  */
static int ad1843_write_bits(lithium_t *lith, const ad1843_bitfield_t *field, int newval)
{
	int w = li_read_ad1843_reg(lith, field->reg);
	int mask = ((1 << field->nbits) - 1) << field->lo_bit;
	int oldval = (w & mask) >> field->lo_bit;
	int newbits = (newval << field->lo_bit) & mask;
	w = (w & ~mask) | newbits;
	(void) li_write_ad1843_reg(lith, field->reg, w);
	DBGXV("ad1843_write_bits(lith=0x%p, field->{%d %d %d}, val=0x%x) "
	      "returns 0x%x\n",
	      lith, field->reg, field->lo_bit, field->nbits, newval,
	      oldval);
	return oldval;
}