+// SPDX-License-Identifier: GPL-2.0+
/*
* Atmel I2C driver.
*
* (C) Copyright 2016 Songjun Wu <songjun.wu@atmel.com>
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <asm/io.h>
#include <common.h>
-#include <clk_client.h>
+#include <clk.h>
#include <dm.h>
#include <errno.h>
#include <fdtdec.h>
} else {
writel(msg->buf[0], ®->thr);
+ ret = at91_wait_for_xfer(bus, TWI_SR_TXRDY);
+
for (i = 1; !ret && (i < msg->len); i++) {
writel(msg->buf[i], ®->thr);
ret = at91_wait_for_xfer(bus, TWI_SR_TXRDY);
static int at91_i2c_enable_clk(struct udevice *dev)
{
struct at91_i2c_bus *bus = dev_get_priv(dev);
- struct udevice *dev_clk;
struct clk clk;
ulong clk_rate;
- int periph;
int ret;
ret = clk_get_by_index(dev, 0, &clk);
if (ret)
return -EINVAL;
- periph = fdtdec_get_uint(gd->fdt_blob, clk.dev->of_offset, "reg", -1);
- if (periph < 0)
- return -EINVAL;
-
- dev_clk = dev_get_parent(clk.dev);
- ret = clk_request(dev_clk, &clk);
- if (ret)
- return ret;
-
- clk.id = periph;
ret = clk_enable(&clk);
if (ret)
return ret;
- ret = clk_get_by_index(dev_clk, 0, &clk);
- if (ret)
- return ret;
-
clk_rate = clk_get_rate(&clk);
if (!clk_rate)
- return -ENODEV;
+ return -EINVAL;
bus->bus_clk_rate = clk_rate;
return 0;
}
-static int at91_i2c_probe(struct udevice *dev, uint chip, uint chip_flags)
-{
- struct at91_i2c_bus *bus = dev_get_priv(dev);
- struct at91_i2c_regs *reg = bus->regs;
- int ret;
-
- ret = at91_i2c_enable_clk(dev);
- if (ret)
- return ret;
-
- writel(TWI_CR_SWRST, ®->cr);
-
- at91_calc_i2c_clock(dev, bus->clock_frequency);
-
- writel(bus->cwgr_val, ®->cwgr);
- writel(TWI_CR_MSEN, ®->cr);
- writel(TWI_CR_SVDIS, ®->cr);
-
- return 0;
-}
-
static int at91_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
{
struct at91_i2c_bus *bus = dev_get_priv(dev);
{
const void *blob = gd->fdt_blob;
struct at91_i2c_bus *bus = dev_get_priv(dev);
- int node = dev->of_offset;
+ int node = dev_of_offset(dev);
- bus->regs = (struct at91_i2c_regs *)dev_get_addr(dev);
+ bus->regs = (struct at91_i2c_regs *)devfdt_get_addr(dev);
bus->pdata = (struct at91_i2c_pdata *)dev_get_driver_data(dev);
bus->clock_frequency = fdtdec_get_int(blob, node,
"clock-frequency", 100000);
static const struct dm_i2c_ops at91_i2c_ops = {
.xfer = at91_i2c_xfer,
- .probe_chip = at91_i2c_probe,
.set_bus_speed = at91_i2c_set_bus_speed,
.get_bus_speed = at91_i2c_get_bus_speed,
};
+static int at91_i2c_probe(struct udevice *dev)
+{
+ struct at91_i2c_bus *bus = dev_get_priv(dev);
+ struct at91_i2c_regs *reg = bus->regs;
+ int ret;
+
+ ret = at91_i2c_enable_clk(dev);
+ if (ret)
+ return ret;
+
+ writel(TWI_CR_SWRST, ®->cr);
+
+ at91_calc_i2c_clock(dev, bus->clock_frequency);
+
+ writel(bus->cwgr_val, ®->cwgr);
+ writel(TWI_CR_MSEN, ®->cr);
+ writel(TWI_CR_SVDIS, ®->cr);
+
+ return 0;
+}
+
static const struct at91_i2c_pdata at91rm9200_config = {
.clk_max_div = 5,
.clk_offset = 3,
.name = "i2c_at91",
.id = UCLASS_I2C,
.of_match = at91_i2c_ids,
+ .probe = at91_i2c_probe,
.ofdata_to_platdata = at91_i2c_ofdata_to_platdata,
.per_child_auto_alloc_size = sizeof(struct dm_i2c_chip),
.priv_auto_alloc_size = sizeof(struct at91_i2c_bus),