Joel King | 48ef6d4 | 2013-02-19 16:11:03 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. 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/err.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/smp.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/cpu.h> |
| 22 | #include <linux/sched.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/of_address.h> |
| 25 | #include <mach/msm_mpmctr.h> |
| 26 | |
| 27 | static void __iomem *mpm_timer_base; |
| 28 | |
| 29 | uint32_t msm_mpm_get_count(void) |
| 30 | { |
| 31 | uint32_t count; |
| 32 | if (!mpm_timer_base) |
| 33 | return 0; |
| 34 | |
| 35 | count = __raw_readl_no_log(mpm_timer_base); |
| 36 | pr_debug("mpm sclk sync:(%u)", count); |
| 37 | return count; |
| 38 | } |
| 39 | EXPORT_SYMBOL(msm_mpm_get_count); |
| 40 | |
| 41 | static inline void msm_mpmctr_show_count(void) |
| 42 | { |
| 43 | unsigned long long t; |
| 44 | unsigned long nsec_rem; |
| 45 | |
| 46 | t = sched_clock(); |
| 47 | |
| 48 | nsec_rem = do_div(t, 1000000000)/1000; |
| 49 | |
| 50 | printk(KERN_INFO "mpm_counter: [%5lu.%06lu]:(%u)\n", |
| 51 | (unsigned long)t, nsec_rem, |
| 52 | msm_mpm_get_count()); |
| 53 | |
| 54 | } |
| 55 | |
| 56 | static struct of_device_id msm_mpmctr_of_match[] = { |
Abhimanyu Kapur | 0e17a9c | 2013-03-08 14:14:40 -0800 | [diff] [blame] | 57 | {.compatible = "qcom,mpm2-sleep-counter"}, |
Joel King | 48ef6d4 | 2013-02-19 16:11:03 -0800 | [diff] [blame] | 58 | {} |
| 59 | }; |
| 60 | |
| 61 | static struct platform_driver msm_mpmctr_driver = { |
| 62 | .driver = { |
| 63 | .name = "msm_mpctr", |
| 64 | .owner = THIS_MODULE, |
| 65 | .of_match_table = msm_mpmctr_of_match, |
| 66 | }, |
| 67 | }; |
| 68 | |
| 69 | static int __init mpmctr_set_register(struct device_node *np) |
| 70 | { |
| 71 | if (of_get_address(np, 0, NULL, NULL)) { |
| 72 | mpm_timer_base = of_iomap(np, 0); |
| 73 | if (!mpm_timer_base) { |
| 74 | pr_err("%s: cannot map timer base\n", __func__); |
| 75 | return -ENOMEM; |
| 76 | } |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int __init msm_mpmctr_probe(struct platform_device *pdev) |
| 82 | { |
| 83 | if (!pdev->dev.of_node) |
| 84 | return -ENODEV; |
| 85 | |
| 86 | if (mpmctr_set_register(pdev->dev.of_node)) |
| 87 | return -ENODEV; |
| 88 | |
| 89 | msm_mpmctr_show_count(); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int __init mpmctr_init(void) |
| 95 | { |
| 96 | return platform_driver_probe(&msm_mpmctr_driver, msm_mpmctr_probe); |
| 97 | } |
| 98 | |
| 99 | module_init(mpmctr_init) |