Пример #1
0
static void uniphier_i2c_hw_init(struct uniphier_i2c_priv *priv,
				 u32 bus_speed, unsigned long clk_rate)
{
	uniphier_i2c_reset(priv, true);

	writel((clk_rate / bus_speed / 2 << 16) | (clk_rate / bus_speed),
	       priv->membase + UNIPHIER_I2C_CLK);

	uniphier_i2c_reset(priv, false);
}
Пример #2
0
static int uniphier_i2c_clk_init(struct device *dev,
				 struct uniphier_i2c_priv *priv)
{
	struct device_node *np = dev->of_node;
	unsigned long clk_rate;
	u32 bus_speed;
	int ret;

	if (of_property_read_u32(np, "clock-frequency", &bus_speed))
		bus_speed = UNIPHIER_I2C_DEFAULT_SPEED;

	if (!bus_speed) {
		dev_err(dev, "clock-frequency should not be zero\n");
		return -EINVAL;
	}

	if (bus_speed > UNIPHIER_I2C_MAX_SPEED)
		bus_speed = UNIPHIER_I2C_MAX_SPEED;

	/* Get input clk rate through clk driver */
	priv->clk = devm_clk_get(dev, NULL);
	if (IS_ERR(priv->clk)) {
		dev_err(dev, "failed to get clock\n");
		return PTR_ERR(priv->clk);
	}

	ret = clk_prepare_enable(priv->clk);
	if (ret)
		return ret;

	clk_rate = clk_get_rate(priv->clk);
	if (!clk_rate) {
		dev_err(dev, "input clock rate should not be zero\n");
		return -EINVAL;
	}

	uniphier_i2c_reset(priv, true);

	writel((clk_rate / bus_speed / 2 << 16) | (clk_rate / bus_speed),
	       priv->membase + UNIPHIER_I2C_CLK);

	uniphier_i2c_reset(priv, false);

	return 0;
}
Пример #3
0
static void uniphier_i2c_unprepare_recovery(struct i2c_adapter *adap)
{
	uniphier_i2c_reset(i2c_get_adapdata(adap), false);
}