Skip to content

Commit

Permalink
net: txgbe: Register fixed rate clock
Browse files Browse the repository at this point in the history
In order for I2C to be able to work in standard mode, register a fixed
rate clock for each I2C device.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Jiawen Wu authored and Paolo Abeni committed Jun 8, 2023
1 parent c3e382a commit b63f204
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/wangxun/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ config NGBE
config TXGBE
tristate "Wangxun(R) 10GbE PCI Express adapters support"
depends on PCI
depends on COMMON_CLK
select LIBWX
help
This driver supports Wangxun(R) 10GbE PCI Express family of
Expand Down
41 changes: 41 additions & 0 deletions drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* Copyright (c) 2015 - 2023 Beijing WangXun Technology Co., Ltd. */

#include <linux/gpio/property.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
#include <linux/i2c.h>
#include <linux/pci.h>

Expand Down Expand Up @@ -70,6 +72,32 @@ static int txgbe_swnodes_register(struct txgbe *txgbe)
return software_node_register_node_group(nodes->group);
}

static int txgbe_clock_register(struct txgbe *txgbe)
{
struct pci_dev *pdev = txgbe->wx->pdev;
struct clk_lookup *clock;
char clk_name[32];
struct clk *clk;

snprintf(clk_name, sizeof(clk_name), "i2c_designware.%d",
(pdev->bus->number << 8) | pdev->devfn);

clk = clk_register_fixed_rate(NULL, clk_name, NULL, 0, 156250000);
if (IS_ERR(clk))
return PTR_ERR(clk);

clock = clkdev_create(clk, NULL, clk_name);
if (!clock) {
clk_unregister(clk);
return -ENOMEM;
}

txgbe->clk = clk;
txgbe->clock = clock;

return 0;
}

int txgbe_init_phy(struct txgbe *txgbe)
{
int ret;
Expand All @@ -80,10 +108,23 @@ int txgbe_init_phy(struct txgbe *txgbe)
return ret;
}

ret = txgbe_clock_register(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to register clock: %d\n", ret);
goto err_unregister_swnode;
}

return 0;

err_unregister_swnode:
software_node_unregister_node_group(txgbe->nodes.group);

return ret;
}

void txgbe_remove_phy(struct txgbe *txgbe)
{
clkdev_drop(txgbe->clock);
clk_unregister(txgbe->clk);
software_node_unregister_node_group(txgbe->nodes.group);
}
2 changes: 2 additions & 0 deletions drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct txgbe_nodes {
struct txgbe {
struct wx *wx;
struct txgbe_nodes nodes;
struct clk_lookup *clock;
struct clk *clk;
};

#endif /* _TXGBE_TYPE_H_ */

0 comments on commit b63f204

Please sign in to comment.