Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 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> |
Pratik Patel | cf41862 | 2011-09-22 11:15:11 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/err.h> |
| 20 | |
Pratik Patel | b27a935 | 2012-03-17 22:37:21 -0700 | [diff] [blame] | 21 | #include "qdss-priv.h" |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 22 | |
| 23 | #define tpiu_writel(tpiu, val, off) __raw_writel((val), tpiu.base + off) |
| 24 | #define tpiu_readl(tpiu, off) __raw_readl(tpiu.base + off) |
| 25 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 26 | #define TPIU_SUPP_PORTSZ (0x000) |
| 27 | #define TPIU_CURR_PORTSZ (0x004) |
| 28 | #define TPIU_SUPP_TRIGMODES (0x100) |
| 29 | #define TPIU_TRIG_CNTRVAL (0x104) |
| 30 | #define TPIU_TRIG_MULT (0x108) |
| 31 | #define TPIU_SUPP_TESTPATM (0x200) |
| 32 | #define TPIU_CURR_TESTPATM (0x204) |
| 33 | #define TPIU_TEST_PATREPCNTR (0x208) |
| 34 | #define TPIU_FFSR (0x300) |
| 35 | #define TPIU_FFCR (0x304) |
| 36 | #define TPIU_FSYNC_CNTR (0x308) |
| 37 | #define TPIU_EXTCTL_INPORT (0x400) |
| 38 | #define TPIU_EXTCTL_OUTPORT (0x404) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 39 | #define TPIU_ITTRFLINACK (0xEE4) |
| 40 | #define TPIU_ITTRFLIN (0xEE8) |
| 41 | #define TPIU_ITATBDATA0 (0xEEC) |
| 42 | #define TPIU_ITATBCTR2 (0xEF0) |
| 43 | #define TPIU_ITATBCTR1 (0xEF4) |
| 44 | #define TPIU_ITATBCTR0 (0xEF8) |
| 45 | |
| 46 | |
| 47 | #define TPIU_LOCK() \ |
| 48 | do { \ |
| 49 | mb(); \ |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 50 | tpiu_writel(tpiu, 0x0, CS_LAR); \ |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 51 | } while (0) |
| 52 | #define TPIU_UNLOCK() \ |
| 53 | do { \ |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 54 | tpiu_writel(tpiu, CS_UNLOCK_MAGIC, CS_LAR); \ |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 55 | mb(); \ |
| 56 | } while (0) |
| 57 | |
| 58 | struct tpiu_ctx { |
| 59 | void __iomem *base; |
| 60 | bool enabled; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 61 | struct device *dev; |
| 62 | }; |
| 63 | |
| 64 | static struct tpiu_ctx tpiu; |
| 65 | |
| 66 | static void __tpiu_disable(void) |
| 67 | { |
| 68 | TPIU_UNLOCK(); |
| 69 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 70 | tpiu_writel(tpiu, 0x3000, TPIU_FFCR); |
| 71 | tpiu_writel(tpiu, 0x3040, TPIU_FFCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 72 | |
| 73 | TPIU_LOCK(); |
| 74 | } |
| 75 | |
| 76 | void tpiu_disable(void) |
| 77 | { |
| 78 | __tpiu_disable(); |
| 79 | tpiu.enabled = false; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 80 | dev_info(tpiu.dev, "TPIU disabled\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static int __devinit tpiu_probe(struct platform_device *pdev) |
| 84 | { |
| 85 | int ret; |
| 86 | struct resource *res; |
| 87 | |
| 88 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 89 | if (!res) { |
| 90 | ret = -EINVAL; |
| 91 | goto err_res; |
| 92 | } |
| 93 | |
| 94 | tpiu.base = ioremap_nocache(res->start, resource_size(res)); |
| 95 | if (!tpiu.base) { |
| 96 | ret = -EINVAL; |
| 97 | goto err_ioremap; |
| 98 | } |
| 99 | |
| 100 | tpiu.dev = &pdev->dev; |
| 101 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 102 | dev_info(tpiu.dev, "TPIU initialized\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 103 | return 0; |
| 104 | |
| 105 | err_ioremap: |
| 106 | err_res: |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 107 | dev_err(tpiu.dev, "TPIU init failed\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 108 | return ret; |
| 109 | } |
| 110 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 111 | static int __devexit tpiu_remove(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 112 | { |
| 113 | if (tpiu.enabled) |
| 114 | tpiu_disable(); |
| 115 | iounmap(tpiu.base); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static struct platform_driver tpiu_driver = { |
| 121 | .probe = tpiu_probe, |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 122 | .remove = __devexit_p(tpiu_remove), |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 123 | .driver = { |
| 124 | .name = "msm_tpiu", |
| 125 | }, |
| 126 | }; |
| 127 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 128 | static int __init tpiu_init(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 129 | { |
| 130 | return platform_driver_register(&tpiu_driver); |
| 131 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 132 | module_init(tpiu_init); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 133 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 134 | static void __exit tpiu_exit(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 135 | { |
| 136 | platform_driver_unregister(&tpiu_driver); |
| 137 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 138 | module_exit(tpiu_exit); |
| 139 | |
| 140 | MODULE_LICENSE("GPL v2"); |
| 141 | MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver"); |