]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i2c: rtl9300: introduce clk struct for upcoming rtl9607 support
authorRustam Adilov <adilov@disroot.org>
Wed, 1 Apr 2026 18:06:46 +0000 (23:06 +0500)
committerAndi Shyti <andi.shyti@kernel.org>
Wed, 1 Apr 2026 22:09:27 +0000 (00:09 +0200)
In RTL9607C i2c controller, there is 10 bit CLK_DIV field for
setting the clock of i2c interface which depends on the rate
of i2c clk (which seems be fixed to 62.5MHz according to Realtek SDK).

Introduce the clk struct and the respective F_CLK_DIV and clk_div
which are going to be used in the upcoming patch for rtl9607c i2c
controller support addition.

devm_clk_get_optional_enabled() function was used for cleaner code
as it automatically returns NULL if the clk is not present, which is
going to be the case for RTL9300 and RTL9310 i2c controllers.

Signed-off-by: Rustam Adilov <adilov@disroot.org>
Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20260401180648.337834-7-adilov@disroot.org
drivers/i2c/busses/i2c-rtl9300.c

index ffbc6c52861b80a3c070118483935d3cca570cc8..16af49ccd1dd310db2314258457e8a79acd8aeb2 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/bits.h>
+#include <linux/clk.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
 #include <linux/mod_devicetable.h>
@@ -28,6 +29,7 @@ struct rtl9300_i2c_chan {
        struct rtl9300_i2c *i2c;
        enum rtl9300_bus_freq bus_freq;
        u8 sda_num;
+       u32 clk_div;
 };
 
 enum rtl9300_i2c_reg_scope {
@@ -54,6 +56,7 @@ enum rtl9300_i2c_reg_fields {
        F_SDA_OUT_SEL,
        F_SDA_SEL,
        F_BUSY,
+       F_CLK_DIV,
 
        /* keep last */
        F_NUM_FIELDS
@@ -85,6 +88,7 @@ struct rtl9300_i2c {
        u8 scl_num;
        u8 sda_num;
        struct mutex lock;
+       struct clk *clk;
 };
 
 DEFINE_GUARD(rtl9300_i2c, struct rtl9300_i2c *, mutex_lock(&_T->lock), mutex_unlock(&_T->lock))
@@ -432,6 +436,10 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
+       i2c->clk = devm_clk_get_optional_enabled(dev, NULL);
+       if (IS_ERR(i2c->clk))
+               return dev_err_probe(dev, PTR_ERR(i2c->clk), "Failed to enable i2c clock\n");
+
        i = 0;
        for_each_child_of_node_scoped(dev->of_node, child) {
                struct rtl9300_i2c_chan *chan = &i2c->chans[i];