Pratik Patel | 50cd217 | 2013-01-14 22:19:25 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -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> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/slab.h> |
Pratik Patel | 50cd217 | 2013-01-14 22:19:25 -0800 | [diff] [blame] | 21 | #include <linux/of.h> |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 22 | #include <linux/of_coresight.h> |
| 23 | #include <linux/coresight.h> |
| 24 | |
| 25 | #include "coresight-priv.h" |
| 26 | |
| 27 | #define csr_writel(drvdata, val, off) __raw_writel((val), drvdata->base + off) |
| 28 | #define csr_readl(drvdata, off) __raw_readl(drvdata->base + off) |
| 29 | |
| 30 | #define CSR_LOCK(drvdata) \ |
| 31 | do { \ |
| 32 | mb(); \ |
| 33 | csr_writel(drvdata, 0x0, CORESIGHT_LAR); \ |
| 34 | } while (0) |
| 35 | #define CSR_UNLOCK(drvdata) \ |
| 36 | do { \ |
| 37 | csr_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ |
| 38 | mb(); \ |
| 39 | } while (0) |
| 40 | |
| 41 | #define CSR_SWDBGPWRCTRL (0x000) |
| 42 | #define CSR_SWDBGPWRACK (0x004) |
| 43 | #define CSR_SWSPADREG0 (0x008) |
| 44 | #define CSR_SWSPADREG1 (0x00C) |
| 45 | #define CSR_STMTRANSCTRL (0x010) |
| 46 | #define CSR_STMAWIDCTRL (0x014) |
| 47 | #define CSR_STMCHNOFST0 (0x018) |
| 48 | #define CSR_STMCHNOFST1 (0x01C) |
| 49 | #define CSR_STMEXTHWCTRL0 (0x020) |
| 50 | #define CSR_STMEXTHWCTRL1 (0x024) |
| 51 | #define CSR_STMEXTHWCTRL2 (0x028) |
| 52 | #define CSR_STMEXTHWCTRL3 (0x02C) |
| 53 | #define CSR_USBBAMCTRL (0x030) |
| 54 | #define CSR_USBFLSHCTRL (0x034) |
| 55 | #define CSR_TIMESTAMPCTRL (0x038) |
| 56 | #define CSR_AOTIMEVAL0 (0x03C) |
| 57 | #define CSR_AOTIMEVAL1 (0x040) |
| 58 | #define CSR_QDSSTIMEVAL0 (0x044) |
| 59 | #define CSR_QDSSTIMEVAL1 (0x048) |
| 60 | #define CSR_QDSSTIMELOAD0 (0x04C) |
| 61 | #define CSR_QDSSTIMELOAD1 (0x050) |
| 62 | #define CSR_DAPMSAVAL (0x054) |
| 63 | #define CSR_QDSSCLKVOTE (0x058) |
| 64 | #define CSR_QDSSCLKIPI (0x05C) |
| 65 | #define CSR_QDSSPWRREQIGNORE (0x060) |
| 66 | #define CSR_QDSSSPARE (0x064) |
| 67 | #define CSR_IPCAT (0x068) |
| 68 | |
| 69 | #define BLKSIZE_256 0 |
| 70 | #define BLKSIZE_512 1 |
| 71 | #define BLKSIZE_1024 2 |
| 72 | #define BLKSIZE_2048 3 |
| 73 | |
| 74 | struct csr_drvdata { |
| 75 | void __iomem *base; |
| 76 | struct device *dev; |
| 77 | struct coresight_device *csdev; |
Pratik Patel | 50cd217 | 2013-01-14 22:19:25 -0800 | [diff] [blame] | 78 | uint32_t blksize; |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static struct csr_drvdata *csrdrvdata; |
| 82 | |
| 83 | void msm_qdss_csr_enable_bam_to_usb(void) |
| 84 | { |
| 85 | struct csr_drvdata *drvdata = csrdrvdata; |
| 86 | uint32_t usbbamctrl, usbflshctrl; |
| 87 | |
| 88 | CSR_UNLOCK(drvdata); |
| 89 | |
| 90 | usbbamctrl = csr_readl(drvdata, CSR_USBBAMCTRL); |
Pratik Patel | 50cd217 | 2013-01-14 22:19:25 -0800 | [diff] [blame] | 91 | usbbamctrl = (usbbamctrl & ~0x3) | drvdata->blksize; |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 92 | csr_writel(drvdata, usbbamctrl, CSR_USBBAMCTRL); |
| 93 | |
| 94 | usbflshctrl = csr_readl(drvdata, CSR_USBFLSHCTRL); |
| 95 | usbflshctrl = (usbflshctrl & ~0x3FFFC) | (0x1000 << 2); |
| 96 | csr_writel(drvdata, usbflshctrl, CSR_USBFLSHCTRL); |
| 97 | usbflshctrl |= 0x2; |
| 98 | csr_writel(drvdata, usbflshctrl, CSR_USBFLSHCTRL); |
| 99 | |
| 100 | usbbamctrl |= 0x4; |
| 101 | csr_writel(drvdata, usbbamctrl, CSR_USBBAMCTRL); |
| 102 | |
| 103 | CSR_LOCK(drvdata); |
| 104 | } |
| 105 | EXPORT_SYMBOL_GPL(msm_qdss_csr_enable_bam_to_usb); |
| 106 | |
| 107 | void msm_qdss_csr_disable_bam_to_usb(void) |
| 108 | { |
| 109 | struct csr_drvdata *drvdata = csrdrvdata; |
| 110 | uint32_t usbbamctrl; |
| 111 | |
| 112 | CSR_UNLOCK(drvdata); |
| 113 | |
| 114 | usbbamctrl = csr_readl(drvdata, CSR_USBBAMCTRL); |
| 115 | usbbamctrl &= (~0x4); |
| 116 | csr_writel(drvdata, usbbamctrl, CSR_USBBAMCTRL); |
| 117 | |
| 118 | CSR_LOCK(drvdata); |
| 119 | } |
| 120 | EXPORT_SYMBOL_GPL(msm_qdss_csr_disable_bam_to_usb); |
| 121 | |
Pratik Patel | bfd2de6 | 2013-01-26 12:14:59 -0800 | [diff] [blame] | 122 | void msm_qdss_csr_disable_flush(void) |
| 123 | { |
| 124 | struct csr_drvdata *drvdata = csrdrvdata; |
| 125 | uint32_t usbflshctrl; |
| 126 | |
| 127 | CSR_UNLOCK(drvdata); |
| 128 | |
| 129 | usbflshctrl = csr_readl(drvdata, CSR_USBFLSHCTRL); |
| 130 | usbflshctrl &= ~0x2; |
| 131 | csr_writel(drvdata, usbflshctrl, CSR_USBFLSHCTRL); |
| 132 | |
| 133 | CSR_LOCK(drvdata); |
| 134 | } |
| 135 | EXPORT_SYMBOL_GPL(msm_qdss_csr_disable_flush); |
| 136 | |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 137 | static int __devinit csr_probe(struct platform_device *pdev) |
| 138 | { |
Pratik Patel | 50cd217 | 2013-01-14 22:19:25 -0800 | [diff] [blame] | 139 | int ret; |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 140 | struct device *dev = &pdev->dev; |
| 141 | struct coresight_platform_data *pdata; |
| 142 | struct csr_drvdata *drvdata; |
| 143 | struct resource *res; |
| 144 | struct coresight_desc *desc; |
| 145 | |
| 146 | if (pdev->dev.of_node) { |
| 147 | pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node); |
| 148 | if (IS_ERR(pdata)) |
| 149 | return PTR_ERR(pdata); |
| 150 | pdev->dev.platform_data = pdata; |
| 151 | } |
| 152 | |
| 153 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
| 154 | if (!drvdata) |
| 155 | return -ENOMEM; |
| 156 | /* Store the driver data pointer for use in exported functions */ |
| 157 | csrdrvdata = drvdata; |
| 158 | drvdata->dev = &pdev->dev; |
| 159 | platform_set_drvdata(pdev, drvdata); |
| 160 | |
| 161 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 162 | if (!res) |
| 163 | return -ENODEV; |
| 164 | |
| 165 | drvdata->base = devm_ioremap(dev, res->start, resource_size(res)); |
| 166 | if (!drvdata->base) |
| 167 | return -ENOMEM; |
| 168 | |
Pratik Patel | 50cd217 | 2013-01-14 22:19:25 -0800 | [diff] [blame] | 169 | if (pdev->dev.of_node) { |
| 170 | ret = of_property_read_u32(pdev->dev.of_node, "qcom,blk-size", |
| 171 | &drvdata->blksize); |
| 172 | if (ret) |
| 173 | drvdata->blksize = BLKSIZE_256; |
| 174 | } |
| 175 | |
Pratik Patel | b8bb403 | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 176 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); |
| 177 | if (!desc) |
| 178 | return -ENOMEM; |
| 179 | desc->type = CORESIGHT_DEV_TYPE_NONE; |
| 180 | desc->pdata = pdev->dev.platform_data; |
| 181 | desc->dev = &pdev->dev; |
| 182 | desc->owner = THIS_MODULE; |
| 183 | drvdata->csdev = coresight_register(desc); |
| 184 | if (IS_ERR(drvdata->csdev)) |
| 185 | return PTR_ERR(drvdata->csdev); |
| 186 | |
| 187 | dev_info(dev, "CSR initialized\n"); |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static int __devexit csr_remove(struct platform_device *pdev) |
| 192 | { |
| 193 | struct csr_drvdata *drvdata = platform_get_drvdata(pdev); |
| 194 | |
| 195 | coresight_unregister(drvdata->csdev); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static struct of_device_id csr_match[] = { |
| 200 | {.compatible = "qcom,coresight-csr"}, |
| 201 | {} |
| 202 | }; |
| 203 | |
| 204 | static struct platform_driver csr_driver = { |
| 205 | .probe = csr_probe, |
| 206 | .remove = __devexit_p(csr_remove), |
| 207 | .driver = { |
| 208 | .name = "coresight-csr", |
| 209 | .owner = THIS_MODULE, |
| 210 | .of_match_table = csr_match, |
| 211 | }, |
| 212 | }; |
| 213 | |
| 214 | static int __init csr_init(void) |
| 215 | { |
| 216 | return platform_driver_register(&csr_driver); |
| 217 | } |
| 218 | module_init(csr_init); |
| 219 | |
| 220 | static void __exit csr_exit(void) |
| 221 | { |
| 222 | platform_driver_unregister(&csr_driver); |
| 223 | } |
| 224 | module_exit(csr_exit); |
| 225 | |
| 226 | MODULE_LICENSE("GPL v2"); |
| 227 | MODULE_DESCRIPTION("CoreSight CSR driver"); |