Pratik Patel | 7492943 | 2011-12-26 12:03:41 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <mach/rpm.h> |
| 22 | |
| 23 | #include "rpm_resources.h" |
| 24 | #include "qdss.h" |
| 25 | |
| 26 | enum { |
| 27 | QDSS_CLK_OFF, |
| 28 | QDSS_CLK_ON_DBG, |
| 29 | QDSS_CLK_ON_HSDBG, |
| 30 | }; |
| 31 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame^] | 32 | struct qdss_ctx { |
| 33 | struct kobject *modulekobj; |
| 34 | uint8_t max_clk; |
| 35 | }; |
| 36 | |
| 37 | static struct qdss_ctx qdss; |
| 38 | |
| 39 | |
| 40 | struct kobject *qdss_get_modulekobj(void) |
| 41 | { |
| 42 | return qdss.modulekobj; |
| 43 | } |
Pratik Patel | 7492943 | 2011-12-26 12:03:41 -0800 | [diff] [blame] | 44 | |
| 45 | int qdss_clk_enable(void) |
| 46 | { |
| 47 | int ret; |
| 48 | |
| 49 | struct msm_rpm_iv_pair iv; |
| 50 | iv.id = MSM_RPM_ID_QDSS_CLK; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame^] | 51 | if (qdss.max_clk) |
| 52 | iv.value = QDSS_CLK_ON_HSDBG; |
| 53 | else |
| 54 | iv.value = QDSS_CLK_ON_DBG; |
Pratik Patel | 7492943 | 2011-12-26 12:03:41 -0800 | [diff] [blame] | 55 | ret = msm_rpmrs_set(MSM_RPM_CTX_SET_0, &iv, 1); |
| 56 | if (WARN(ret, "qdss clks not enabled (%d)\n", ret)) |
| 57 | goto err_clk; |
| 58 | |
| 59 | return 0; |
Pratik Patel | 7492943 | 2011-12-26 12:03:41 -0800 | [diff] [blame] | 60 | err_clk: |
| 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | void qdss_clk_disable(void) |
| 65 | { |
| 66 | int ret; |
| 67 | struct msm_rpm_iv_pair iv; |
| 68 | |
| 69 | iv.id = MSM_RPM_ID_QDSS_CLK; |
| 70 | iv.value = QDSS_CLK_OFF; |
| 71 | ret = msm_rpmrs_set(MSM_RPM_CTX_SET_0, &iv, 1); |
| 72 | WARN(ret, "qdss clks not disabled (%d)\n", ret); |
| 73 | } |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 74 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame^] | 75 | #define QDSS_ATTR(name) \ |
| 76 | static struct kobj_attribute name##_attr = \ |
| 77 | __ATTR(name, S_IRUGO | S_IWUSR, name##_show, name##_store) |
| 78 | |
| 79 | static ssize_t max_clk_store(struct kobject *kobj, |
| 80 | struct kobj_attribute *attr, |
| 81 | const char *buf, size_t n) |
| 82 | { |
| 83 | unsigned long val; |
| 84 | |
| 85 | if (sscanf(buf, "%lx", &val) != 1) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | qdss.max_clk = val; |
| 89 | return n; |
| 90 | } |
| 91 | static ssize_t max_clk_show(struct kobject *kobj, |
| 92 | struct kobj_attribute *attr, |
| 93 | char *buf) |
| 94 | { |
| 95 | unsigned long val = qdss.max_clk; |
| 96 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 97 | } |
| 98 | QDSS_ATTR(max_clk); |
| 99 | |
| 100 | static int __init qdss_sysfs_init(void) |
| 101 | { |
| 102 | int ret; |
| 103 | |
| 104 | qdss.modulekobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 105 | if (!qdss.modulekobj) { |
| 106 | pr_err("failed to find QDSS sysfs module kobject\n"); |
| 107 | ret = -ENOENT; |
| 108 | goto err; |
| 109 | } |
| 110 | |
| 111 | ret = sysfs_create_file(qdss.modulekobj, &max_clk_attr.attr); |
| 112 | if (ret) { |
| 113 | pr_err("failed to create QDSS sysfs max_clk attribute\n"); |
| 114 | goto err; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | err: |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | static void qdss_sysfs_exit(void) |
| 123 | { |
| 124 | sysfs_remove_file(qdss.modulekobj, &max_clk_attr.attr); |
| 125 | } |
| 126 | |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 127 | static int __init qdss_init(void) |
| 128 | { |
| 129 | int ret; |
| 130 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame^] | 131 | ret = qdss_sysfs_init(); |
| 132 | if (ret) |
| 133 | goto err_sysfs; |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 134 | ret = etb_init(); |
| 135 | if (ret) |
| 136 | goto err_etb; |
| 137 | ret = tpiu_init(); |
| 138 | if (ret) |
| 139 | goto err_tpiu; |
| 140 | ret = funnel_init(); |
| 141 | if (ret) |
| 142 | goto err_funnel; |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 143 | ret = etm_init(); |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 144 | if (ret) |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 145 | goto err_etm; |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 146 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 147 | pr_info("QDSS initialized\n"); |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 148 | return 0; |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 149 | err_etm: |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 150 | funnel_exit(); |
| 151 | err_funnel: |
| 152 | tpiu_exit(); |
| 153 | err_tpiu: |
| 154 | etb_exit(); |
| 155 | err_etb: |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame^] | 156 | qdss_sysfs_exit(); |
| 157 | err_sysfs: |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 158 | pr_err("QDSS init failed\n"); |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 159 | return ret; |
| 160 | } |
| 161 | module_init(qdss_init); |
| 162 | |
| 163 | static void __exit qdss_exit(void) |
| 164 | { |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame^] | 165 | qdss_sysfs_exit(); |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 166 | etm_exit(); |
Pratik Patel | 59e2994 | 2011-12-27 10:31:33 -0800 | [diff] [blame] | 167 | funnel_exit(); |
| 168 | tpiu_exit(); |
| 169 | etb_exit(); |
| 170 | } |
| 171 | module_exit(qdss_exit); |
| 172 | |
| 173 | MODULE_LICENSE("GPL v2"); |
| 174 | MODULE_DESCRIPTION("Qualcomm Debug SubSystem Driver"); |