/* Returns 0 if all field numbers and values are in the correct range, else returns -1.  */
int davinci_configure_pin_mux(const struct pinmux_config *pins, const int n_pins)
/* Returns 0 if all field numbers and values are in the correct range, else returns -1.  */
int davinci_configure_pin_mux(const struct pinmux_config *pins, const int n_pins)
{
	int i;
	for (i = 0; i < n_pins; i++) {
		if (pins[i].field >= PIN_MUX_NUM_FIELDS ||
		    (pins[i].value & ~PIN_MUX_FIELD_MASK) != 0)
			return -1;
	}
	for (i = 0; i < n_pins; i++) {
		const int offset = pins[i].field * PIN_MUX_FIELD_SIZE;
		const unsigned int value = pins[i].value << offset;
		const unsigned int mask = PIN_MUX_FIELD_MASK << offset;
		const dv_reg *mux = pins[i].mux;
		writel(value | (readl(mux) & (~mask)), mux);
	}
	return 0;
}