* (C) Copyright 2017 STMicroelectronics
*/
+#define LOG_CATEGORY UCLASS_I2C
+
#include <common.h>
#include <clk.h>
#include <dm.h>
#include <regmap.h>
#include <reset.h>
#include <syscon.h>
+#include <dm/device.h>
+#include <dm/device_compat.h>
#include <linux/bitops.h>
#include <linux/delay.h>
-
-#include <dm/device.h>
#include <linux/err.h>
#include <linux/io.h>
*status = readl(®s->isr);
while (!(*status & flags)) {
if (get_timer(time_start) > CONFIG_SYS_HZ) {
- debug("%s: i2c timeout\n", __func__);
+ log_debug("i2c timeout\n");
return -ETIMEDOUT;
}
return ret;
if (status & STM32_I2C_ISR_BERR) {
- debug("%s: Bus error\n", __func__);
+ log_debug("Bus error\n");
/* Clear BERR flag */
setbits_le32(®s->icr, STM32_I2C_ICR_BERRCF);
}
if (status & STM32_I2C_ISR_ARLO) {
- debug("%s: Arbitration lost\n", __func__);
+ log_debug("Arbitration lost\n");
/* Clear ARLO flag */
setbits_le32(®s->icr, STM32_I2C_ICR_ARLOCF);
}
if (status & STM32_I2C_ISR_NACKF) {
- debug("%s: Receive NACK\n", __func__);
+ log_debug("Receive NACK\n");
/* Clear NACK flag */
setbits_le32(®s->icr, STM32_I2C_ICR_NACKCF);
if (sdadel_max < 0)
sdadel_max = 0;
- debug("%s: SDADEL(min/max): %i/%i, SCLDEL(Min): %i\n", __func__,
- sdadel_min, sdadel_max, scldel_min);
+ log_debug("SDADEL(min/max): %i/%i, SCLDEL(Min): %i\n",
+ sdadel_min, sdadel_max, scldel_min);
/* Compute possible values for PRESC, SCLDEL and SDADEL */
for (p = 0; p < STM32_PRESC_MAX; p++) {
}
if (list_empty(solutions)) {
- pr_err("%s: no Prescaler solution\n", __func__);
+ log_err("no Prescaler solution\n");
ret = -EPERM;
}
}
if (!sol_found) {
- pr_err("%s: no solution at all\n", __func__);
+ log_err("no solution at all\n");
ret = -EPERM;
}
specs = get_specs(setup->speed_freq);
if (specs == ERR_PTR(-EINVAL)) {
- pr_err("%s: speed out of bound {%d}\n", __func__,
- setup->speed_freq);
+ log_err("speed out of bound {%d}\n",
+ setup->speed_freq);
return -EINVAL;
}
if (setup->rise_time > specs->rise_max ||
setup->fall_time > specs->fall_max) {
- pr_err("%s :timings out of bound Rise{%d>%d}/Fall{%d>%d}\n",
- __func__,
- setup->rise_time, specs->rise_max,
- setup->fall_time, specs->fall_max);
+ log_err("timings out of bound Rise{%d>%d}/Fall{%d>%d}\n",
+ setup->rise_time, specs->rise_max,
+ setup->fall_time, specs->fall_max);
return -EINVAL;
}
if (setup->dnf > STM32_I2C_DNF_MAX) {
- pr_err("%s: DNF out of bound %d/%d\n", __func__,
- setup->dnf, STM32_I2C_DNF_MAX);
+ log_err("DNF out of bound %d/%d\n",
+ setup->dnf, STM32_I2C_DNF_MAX);
return -EINVAL;
}
if (ret)
goto exit;
- debug("%s: Presc: %i, scldel: %i, sdadel: %i, scll: %i, sclh: %i\n",
- __func__, output->presc,
- output->scldel, output->sdadel,
- output->scll, output->sclh);
+ log_debug("Presc: %i, scldel: %i, sdadel: %i, scll: %i, sclh: %i\n",
+ output->presc,
+ output->scldel, output->sdadel,
+ output->scll, output->sclh);
exit:
/* Release list and memory */
setup->clock_src = clk_get_rate(&i2c_priv->clk);
if (!setup->clock_src) {
- pr_err("%s: clock rate is 0\n", __func__);
+ log_err("clock rate is 0\n");
return -EINVAL;
}
do {
ret = stm32_i2c_compute_timing(i2c_priv, setup, timing);
if (ret) {
- debug("%s: failed to compute I2C timings.\n",
- __func__);
+ log_debug("failed to compute I2C timings.\n");
if (setup->speed_freq > I2C_SPEED_STANDARD_RATE) {
setup->speed_freq =
get_lower_rate(setup->speed_freq);
- debug("%s: downgrade I2C Speed Freq to (%i)\n",
- __func__, setup->speed_freq);
+ log_debug("downgrade I2C Speed Freq to (%i)\n",
+ setup->speed_freq);
} else {
break;
}
} while (ret);
if (ret) {
- pr_err("%s: impossible to compute I2C timings.\n", __func__);
+ log_err("impossible to compute I2C timings.\n");
return ret;
}
- debug("%s: I2C Freq(%i), Clk Source(%i)\n", __func__,
- setup->speed_freq, setup->clock_src);
- debug("%s: I2C Rise(%i) and Fall(%i) Time\n", __func__,
- setup->rise_time, setup->fall_time);
- debug("%s: I2C Analog Filter(%s), DNF(%i)\n", __func__,
- setup->analog_filter ? "On" : "Off", setup->dnf);
+ log_debug("I2C Freq(%i), Clk Source(%i)\n",
+ setup->speed_freq, setup->clock_src);
+ log_debug("I2C Rise(%i) and Fall(%i) Time\n",
+ setup->rise_time, setup->fall_time);
+ log_debug("I2C Analog Filter(%s), DNF(%i)\n",
+ setup->analog_filter ? "On" : "Off", setup->dnf);
i2c_priv->speed = setup->speed_freq;
return 0;
}
-static int stm32_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
+static int stm32_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
{
- struct stm32_i2c_priv *i2c_priv = dev_get_priv(bus);
+ struct stm32_i2c_priv *i2c_priv = dev_get_priv(dev);
if (speed > I2C_SPEED_FAST_PLUS_RATE) {
- debug("%s: Speed %d not supported\n", __func__, speed);
+ dev_dbg(dev, "Speed %d not supported\n", speed);
return -EINVAL;
}