Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google, Inc. |
| 3 | * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved. |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/ctype.h> |
| 19 | #include <linux/debugfs.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include "clock.h" |
| 22 | #include "clock-pcom.h" |
| 23 | |
| 24 | static int clock_debug_rate_set(void *data, u64 val) |
| 25 | { |
| 26 | struct clk *clock = data; |
| 27 | int ret; |
| 28 | |
| 29 | /* Only increases to max rate will succeed, but that's actually good |
| 30 | * for debugging purposes so we don't check for error. */ |
| 31 | if (clock->flags & CLK_MAX) |
| 32 | clk_set_max_rate(clock, val); |
| 33 | if (clock->flags & CLK_MIN) |
| 34 | ret = clk_set_min_rate(clock, val); |
| 35 | else |
| 36 | ret = clk_set_rate(clock, val); |
| 37 | if (ret != 0) |
| 38 | printk(KERN_ERR "clk_set%s_rate failed (%d)\n", |
| 39 | (clock->flags & CLK_MIN) ? "_min" : "", ret); |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | static int clock_debug_rate_get(void *data, u64 *val) |
| 44 | { |
| 45 | struct clk *clock = data; |
| 46 | *val = clk_get_rate(clock); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get, |
| 51 | clock_debug_rate_set, "%llu\n"); |
| 52 | |
| 53 | static int clock_debug_enable_set(void *data, u64 val) |
| 54 | { |
| 55 | struct clk *clock = data; |
| 56 | int rc = 0; |
| 57 | |
| 58 | if (val) |
| 59 | rc = clock->ops->enable(clock->id); |
| 60 | else |
| 61 | clock->ops->disable(clock->id); |
| 62 | |
| 63 | return rc; |
| 64 | } |
| 65 | |
| 66 | static int clock_debug_enable_get(void *data, u64 *val) |
| 67 | { |
| 68 | struct clk *clock = data; |
| 69 | |
| 70 | *val = clock->ops->is_enabled(clock->id); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get, |
| 76 | clock_debug_enable_set, "%llu\n"); |
| 77 | |
| 78 | static int clock_debug_local_get(void *data, u64 *val) |
| 79 | { |
| 80 | struct clk *clock = data; |
| 81 | |
| 82 | *val = clock->ops != &clk_ops_pcom; |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get, |
| 88 | NULL, "%llu\n"); |
| 89 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 90 | static struct dentry *debugfs_base; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 91 | |
| 92 | int __init clock_debug_init(void) |
| 93 | { |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 94 | debugfs_base = debugfs_create_dir("clk", NULL); |
| 95 | if (!debugfs_base) |
| 96 | return -ENOMEM; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 97 | return 0; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int __init clock_debug_add(struct clk *clock) |
| 101 | { |
| 102 | char temp[50], *ptr; |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 103 | struct dentry *clk_dir; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 104 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 105 | if (!debugfs_base) |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 106 | return -ENOMEM; |
| 107 | |
| 108 | strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1); |
| 109 | for (ptr = temp; *ptr; ptr++) |
| 110 | *ptr = tolower(*ptr); |
| 111 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 112 | clk_dir = debugfs_create_dir(temp, debugfs_base); |
| 113 | if (!clk_dir) |
| 114 | return -ENOMEM; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 115 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 116 | if (!debugfs_create_file("rate", S_IRUGO | S_IWUSR, clk_dir, |
| 117 | clock, &clock_rate_fops)) |
| 118 | goto error; |
| 119 | |
| 120 | if (!debugfs_create_file("enable", S_IRUGO | S_IWUSR, clk_dir, |
| 121 | clock, &clock_enable_fops)) |
| 122 | goto error; |
| 123 | |
| 124 | if (!debugfs_create_file("is_local", S_IRUGO, clk_dir, clock, |
| 125 | &clock_local_fops)) |
| 126 | goto error; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 127 | return 0; |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame^] | 128 | error: |
| 129 | debugfs_remove_recursive(clk_dir); |
| 130 | return -ENOMEM; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 131 | } |