memory: tegra: Add EMC frequency debugfs entry
authorMikko Perttunen <mperttunen@nvidia.com>
Thu, 12 Mar 2015 14:48:06 +0000 (15:48 +0100)
committerThierry Reding <treding@nvidia.com>
Tue, 5 May 2015 09:39:48 +0000 (11:39 +0200)
This file in debugfs can be used to get or set the EMC frequency.
Reading the file will return the currently set frequency in Hz, while
writing the file sets the specified frequency rounded to the next
highest frequency supported by the board.

Will be very useful when tuning memory scaling.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
[treding@nvidia.com: add "emc" debugfs directory]
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/memory/tegra/tegra124-emc.c

index 900504c01a64559e23cf581c61d0b1d99ce65d49..8620355776fe0485a452bb6a28a23cbcfb6410b3 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/clk-provider.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
+#include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
@@ -1005,6 +1006,50 @@ tegra_emc_find_node_by_ram_code(struct device_node *node, u32 ram_code)
        return NULL;
 }
 
+/* Debugfs entry */
+
+static int emc_debug_rate_get(void *data, u64 *rate)
+{
+       struct clk *c = data;
+
+       *rate = clk_get_rate(c);
+
+       return 0;
+}
+
+static int emc_debug_rate_set(void *data, u64 rate)
+{
+       struct clk *c = data;
+
+       return clk_set_rate(c, rate);
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(emc_debug_rate_fops, emc_debug_rate_get,
+                       emc_debug_rate_set, "%lld\n");
+
+static void emc_debugfs_init(struct device *dev)
+{
+       struct dentry *root, *file;
+       struct clk *clk;
+
+       root = debugfs_create_dir("emc", NULL);
+       if (!root) {
+               dev_err(dev, "failed to create debugfs directory\n");
+               return;
+       }
+
+       clk = clk_get_sys("tegra-clk-debug", "emc");
+       if (IS_ERR(clk)) {
+               dev_err(dev, "failed to get debug clock: %ld\n", PTR_ERR(clk));
+               return;
+       }
+
+       file = debugfs_create_file("rate", S_IRUGO | S_IWUSR, root, clk,
+                                  &emc_debug_rate_fops);
+       if (!file)
+               dev_err(dev, "failed to create debugfs entry\n");
+}
+
 static int tegra_emc_probe(struct platform_device *pdev)
 {
        struct platform_device *mc;
@@ -1073,6 +1118,9 @@ static int tegra_emc_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, emc);
 
+       if (IS_ENABLED(CONFIG_DEBUG_FS))
+               emc_debugfs_init(&pdev->dev);
+
        return 0;
 };