[RFC linux dev-4.7 1/7] drivers: fsi: Add function to get FSI clock rate

Eddie James eajames at linux.vnet.ibm.com
Fri Mar 24 08:44:33 AEDT 2017


From: "Edward A. James" <eajames at us.ibm.com>

client drivers (I2C, etc) may need to know FSI bus clock rate.

Signed-off-by: Edward A. James <eajames at us.ibm.com>
---
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts |  6 ++++++
 drivers/fsi/fsi-core.c                           | 20 ++++++++++++++++++++
 drivers/fsi/fsi-master.h                         |  1 +
 include/linux/fsi.h                              |  1 +
 4 files changed, 28 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
index 4d26d47..6772b53 100644
--- a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
@@ -57,6 +57,12 @@
 		mux-gpios = <&gpio ASPEED_GPIO(A, 6) GPIO_ACTIVE_HIGH>;
 		enable-gpios = <&gpio ASPEED_GPIO(D, 0) GPIO_ACTIVE_HIGH>;
 		trans-gpios = <&gpio ASPEED_GPIO(R, 2) GPIO_ACTIVE_HIGH>;
+
+		fsi_clock {
+			#clock-cells = <0>;
+			compatible = "fixed-clock";
+			clock-frequency = <8333333>;
+		};
 	};
 };
 
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 3d382e6..43c8636 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -18,6 +18,7 @@
 #include <linux/idr.h>
 #include <linux/kthread.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/delay.h>
@@ -26,6 +27,7 @@
 
 #define DEBUG
 
+#define FSI_DEFAULT_CLK	8333333
 #define FSI_N_SLAVES	4
 #define FSI_BREAK	0xc0de0000
 
@@ -139,6 +141,12 @@ int fsi_device_peek(struct fsi_device *dev, void *val)
 	return fsi_slave_read(dev->slave, addr, val, sizeof(uint32_t));
 }
 
+unsigned long fsi_device_get_clk_rate(struct fsi_device *dev)
+{
+	return dev->slave->master->clk;
+}
+EXPORT_SYMBOL_GPL(fsi_device_get_clk_rate);
+
 static void fsi_device_release(struct device *_device)
 {
 	struct fsi_device *device = to_fsi_dev(_device);
@@ -854,9 +862,21 @@ DEVICE_ATTR(fsi_ipoll_period, S_IRUGO | S_IWUSR, fsi_ipoll_period_show,
 
 int fsi_master_register(struct fsi_master *master)
 {
+	struct device_node *np;
+	u32 clk;
+
 	if (!master || !master->dev)
 		return -EINVAL;
 
+	master->clk = FSI_DEFAULT_CLK;
+
+	for_each_child_of_node(master->dev->of_node, np) {
+		if (of_device_is_compatible(np, "fixed_clock")) {
+			if (!of_property_read_u32(np, "clock-frequency", &clk))
+				master->clk = clk;
+		}
+	}
+
 	master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL);
 	master->slave_list = false;
 	get_device(master->dev);
diff --git a/drivers/fsi/fsi-master.h b/drivers/fsi/fsi-master.h
index 54723a7..f187269 100644
--- a/drivers/fsi/fsi-master.h
+++ b/drivers/fsi/fsi-master.h
@@ -72,6 +72,7 @@ struct fsi_master {
 	int		idx;
 	int		n_links;
 	uint32_t	ipoll;
+	unsigned long	clk;
 	int		(*read)(struct fsi_master *, int link,
 				uint8_t slave, uint32_t addr,
 				void *val, size_t size);
diff --git a/include/linux/fsi.h b/include/linux/fsi.h
index d22d0c5..57c8fdb 100644
--- a/include/linux/fsi.h
+++ b/include/linux/fsi.h
@@ -35,6 +35,7 @@ extern int fsi_device_read(struct fsi_device *dev, uint32_t addr,
 extern int fsi_device_write(struct fsi_device *dev, uint32_t addr,
 		const void *val, size_t size);
 extern int fsi_device_peek(struct fsi_device *dev, void *val);
+extern unsigned long fsi_device_get_clk_rate(struct fsi_device *dev);
 
 struct fsi_device_id {
 	u8	engine_type;
-- 
1.8.3.1



More information about the openbmc mailing list