Skip to content

Commit f60d279

Browse files
Rustam AdilovAndi Shyti
authored andcommitted
i2c: rtl9300: introduce clk struct for upcoming rtl9607 support
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
1 parent 1211ce1 commit f60d279

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/i2c/busses/i2c-rtl9300.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

33
#include <linux/bits.h>
4+
#include <linux/clk.h>
45
#include <linux/i2c.h>
56
#include <linux/i2c-mux.h>
67
#include <linux/mod_devicetable.h>
@@ -28,6 +29,7 @@ struct rtl9300_i2c_chan {
2829
struct rtl9300_i2c *i2c;
2930
enum rtl9300_bus_freq bus_freq;
3031
u8 sda_num;
32+
u32 clk_div;
3133
};
3234

3335
enum rtl9300_i2c_reg_scope {
@@ -54,6 +56,7 @@ enum rtl9300_i2c_reg_fields {
5456
F_SDA_OUT_SEL,
5557
F_SDA_SEL,
5658
F_BUSY,
59+
F_CLK_DIV,
5760

5861
/* keep last */
5962
F_NUM_FIELDS
@@ -85,6 +88,7 @@ struct rtl9300_i2c {
8588
u8 scl_num;
8689
u8 sda_num;
8790
struct mutex lock;
91+
struct clk *clk;
8892
};
8993

9094
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)
432436
if (ret)
433437
return ret;
434438

439+
i2c->clk = devm_clk_get_optional_enabled(dev, NULL);
440+
if (IS_ERR(i2c->clk))
441+
return dev_err_probe(dev, PTR_ERR(i2c->clk), "Failed to enable i2c clock\n");
442+
435443
i = 0;
436444
for_each_child_of_node_scoped(dev->of_node, child) {
437445
struct rtl9300_i2c_chan *chan = &i2c->chans[i];

0 commit comments

Comments
 (0)