/* Enter/Exit CAN Initialization mode @prv: stm32 can private @in: 1 - enter Init; 0 - exit Init  */
static int stm32_chip_init(struct stm32_prv *prv, int in)
/* Enter/Exit CAN Initialization mode @prv: stm32 can private @in: 1 - enter Init; 0 - exit Init  */
static int stm32_chip_init(struct stm32_prv *prv, int in)
{
	u32 val;
	int i;
	val = readl(prv->reg + STM_CAN_MCR_BASE);
	if (in)
		val |= STM_CAN_MCR_INRQ;
	else
		val &= ~STM_CAN_MCR_INRQ;
	writel(val, prv->reg + STM_CAN_MCR_BASE);
	for (i = 0; i < STM_CAN_INIT_TOUT; i++) {
		val = readl(prv->reg + STM_CAN_MSR_BASE) & STM_CAN_MSR_INAK;
		if (in) {
			if (val)
				break;
		} else {
			if (!val)
				break;
		}
		usleep_range(1000, 1000);
	}
	val = readl(prv->reg + STM_CAN_MSR_BASE) & STM_CAN_MSR_INAK;
	return in ? (val ? 0 : -ETIMEDOUT) : (!val ? 0 : -ETIMEDOUT);
}