Path: blob/master/arch/mips/jz4740/clock-debugfs.c
10817 views
/*1* Copyright (C) 2010, Lars-Peter Clausen <[email protected]>2* JZ4740 SoC clock support debugfs entries3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License as published by the6* Free Software Foundation; either version 2 of the License, or (at your7* option) any later version.8*9* You should have received a copy of the GNU General Public License along10* with this program; if not, write to the Free Software Foundation, Inc.,11* 675 Mass Ave, Cambridge, MA 02139, USA.12*13*/1415#include <linux/kernel.h>16#include <linux/module.h>17#include <linux/clk.h>18#include <linux/err.h>1920#include <linux/debugfs.h>21#include <linux/uaccess.h>2223#include <asm/mach-jz4740/clock.h>24#include "clock.h"2526static struct dentry *jz4740_clock_debugfs;2728static int jz4740_clock_debugfs_show_enabled(void *data, uint64_t *value)29{30struct clk *clk = data;31*value = clk_is_enabled(clk);3233return 0;34}3536static int jz4740_clock_debugfs_set_enabled(void *data, uint64_t value)37{38struct clk *clk = data;3940if (value)41return clk_enable(clk);42else43clk_disable(clk);4445return 0;46}4748DEFINE_SIMPLE_ATTRIBUTE(jz4740_clock_debugfs_ops_enabled,49jz4740_clock_debugfs_show_enabled,50jz4740_clock_debugfs_set_enabled,51"%llu\n");5253static int jz4740_clock_debugfs_show_rate(void *data, uint64_t *value)54{55struct clk *clk = data;56*value = clk_get_rate(clk);5758return 0;59}6061DEFINE_SIMPLE_ATTRIBUTE(jz4740_clock_debugfs_ops_rate,62jz4740_clock_debugfs_show_rate,63NULL,64"%llu\n");6566void jz4740_clock_debugfs_add_clk(struct clk *clk)67{68if (!jz4740_clock_debugfs)69return;7071clk->debugfs_entry = debugfs_create_dir(clk->name, jz4740_clock_debugfs);72debugfs_create_file("rate", S_IWUGO | S_IRUGO, clk->debugfs_entry, clk,73&jz4740_clock_debugfs_ops_rate);74debugfs_create_file("enabled", S_IRUGO, clk->debugfs_entry, clk,75&jz4740_clock_debugfs_ops_enabled);7677if (clk->parent) {78char parent_path[100];79snprintf(parent_path, 100, "../%s", clk->parent->name);80clk->debugfs_parent_entry = debugfs_create_symlink("parent",81clk->debugfs_entry,82parent_path);83}84}8586/* TODO: Locking */87void jz4740_clock_debugfs_update_parent(struct clk *clk)88{89if (clk->debugfs_parent_entry)90debugfs_remove(clk->debugfs_parent_entry);9192if (clk->parent) {93char parent_path[100];94snprintf(parent_path, 100, "../%s", clk->parent->name);95clk->debugfs_parent_entry = debugfs_create_symlink("parent",96clk->debugfs_entry,97parent_path);98} else {99clk->debugfs_parent_entry = NULL;100}101}102103void jz4740_clock_debugfs_init(void)104{105jz4740_clock_debugfs = debugfs_create_dir("jz4740-clock", NULL);106if (IS_ERR(jz4740_clock_debugfs))107jz4740_clock_debugfs = NULL;108}109110111