1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
5 * Description: CoreSight System Trace Macrocell driver
7 * Initial implementation by Pratik Patel
8 * (C) 2014-2015 Pratik Patel <pratikp@codeaurora.org>
10 * Serious refactoring, code cleanup and upgrading to the Coresight upstream
11 * framework by Mathieu Poirier
12 * (C) 2015-2016 Mathieu Poirier <mathieu.poirier@linaro.org>
14 * Guaranteed timing and support for various packet type coming from the
15 * generic STM API by Chunyan Zhang
16 * (C) 2015-2016 Chunyan Zhang <zhang.chunyan@linaro.org>
18 #include <asm/local.h>
19 #include <linux/acpi.h>
20 #include <linux/amba/bus.h>
21 #include <linux/bitmap.h>
22 #include <linux/clk.h>
23 #include <linux/coresight.h>
24 #include <linux/coresight-stm.h>
25 #include <linux/err.h>
26 #include <linux/kernel.h>
27 #include <linux/moduleparam.h>
28 #include <linux/of_address.h>
29 #include <linux/perf_event.h>
30 #include <linux/pm_runtime.h>
31 #include <linux/stm.h>
33 #include "coresight-priv.h"
34 #include "coresight-trace-id.h"
36 #define STMDMASTARTR 0xc04
37 #define STMDMASTOPR 0xc08
38 #define STMDMASTATR 0xc0c
39 #define STMDMACTLR 0xc10
40 #define STMDMAIDR 0xcfc
42 #define STMHETER 0xd20
43 #define STMHEBSR 0xd60
44 #define STMHEMCR 0xd64
45 #define STMHEMASTR 0xdf4
46 #define STMHEFEAT1R 0xdf8
47 #define STMHEIDR 0xdfc
49 #define STMSPTER 0xe20
50 #define STMPRIVMASKR 0xe40
51 #define STMSPSCR 0xe60
52 #define STMSPMSCR 0xe64
53 #define STMSPOVERRIDER 0xe68
54 #define STMSPMOVERRIDER 0xe6c
55 #define STMSPTRIGCSR 0xe70
57 #define STMTSSTIMR 0xe84
58 #define STMTSFREQR 0xe8c
59 #define STMSYNCR 0xe90
60 #define STMAUXCR 0xe94
61 #define STMSPFEAT1R 0xea0
62 #define STMSPFEAT2R 0xea4
63 #define STMSPFEAT3R 0xea8
64 #define STMITTRIGGER 0xee8
65 #define STMITATBDATA0 0xeec
66 #define STMITATBCTR2 0xef0
67 #define STMITATBID 0xef4
68 #define STMITATBCTR0 0xef8
70 #define STM_32_CHANNEL 32
71 #define BYTES_PER_CHANNEL 256
72 #define STM_TRACE_BUF_SIZE 4096
73 #define STM_SW_MASTER_END 127
75 /* Register bit definition */
76 #define STMTCSR_BUSY_BIT 23
77 /* Reserve the first 10 channels for kernel usage */
78 #define STM_CHANNEL_OFFSET 0
81 STM_PKT_TYPE_DATA = 0x98,
82 STM_PKT_TYPE_FLAG = 0xE8,
83 STM_PKT_TYPE_TRIG = 0xF8,
86 #define stm_channel_addr(drvdata, ch) (drvdata->chs.base + \
87 (ch * BYTES_PER_CHANNEL))
88 #define stm_channel_off(type, opts) (type & ~opts)
90 static int boot_nr_channel;
93 * Not really modular but using module_param is the easiest way to
94 * remain consistent with existing use cases for now.
97 boot_nr_channel, boot_nr_channel, int, S_IRUGO
101 * struct channel_space - central management entity for extended ports
102 * @base: memory mapped base address where channels start.
103 * @phys: physical base address of channel region.
104 * @guaraneed: is the channel delivery guaranteed.
106 struct channel_space {
109 unsigned long *guaranteed;
112 DEFINE_CORESIGHT_DEVLIST(stm_devs, "stm");
115 * struct stm_drvdata - specifics associated to an STM component
116 * @base: memory mapped base address for this component.
117 * @atclk: optional clock for the core parts of the STM.
118 * @csdev: component vitals needed by the framework.
119 * @spinlock: only one at a time pls.
120 * @chs: the channels accociated to this STM.
121 * @stm: structure associated to the generic STM interface.
122 * @traceid: value of the current ID for this component.
123 * @write_bytes: Maximus bytes this STM can write at a time.
124 * @stmsper: settings for register STMSPER.
125 * @stmspscr: settings for register STMSPSCR.
126 * @numsp: the total number of stimulus port support by this STM.
127 * @stmheer: settings for register STMHEER.
128 * @stmheter: settings for register STMHETER.
129 * @stmhebsr: settings for register STMHEBSR.
134 struct coresight_device *csdev;
136 struct channel_space chs;
148 static void stm_hwevent_enable_hw(struct stm_drvdata *drvdata)
150 CS_UNLOCK(drvdata->base);
152 writel_relaxed(drvdata->stmhebsr, drvdata->base + STMHEBSR);
153 writel_relaxed(drvdata->stmheter, drvdata->base + STMHETER);
154 writel_relaxed(drvdata->stmheer, drvdata->base + STMHEER);
155 writel_relaxed(0x01 | /* Enable HW event tracing */
156 0x04, /* Error detection on event tracing */
157 drvdata->base + STMHEMCR);
159 CS_LOCK(drvdata->base);
162 static void stm_port_enable_hw(struct stm_drvdata *drvdata)
164 CS_UNLOCK(drvdata->base);
165 /* ATB trigger enable on direct writes to TRIG locations */
167 drvdata->base + STMSPTRIGCSR);
168 writel_relaxed(drvdata->stmspscr, drvdata->base + STMSPSCR);
169 writel_relaxed(drvdata->stmsper, drvdata->base + STMSPER);
171 CS_LOCK(drvdata->base);
174 static void stm_enable_hw(struct stm_drvdata *drvdata)
176 if (drvdata->stmheer)
177 stm_hwevent_enable_hw(drvdata);
179 stm_port_enable_hw(drvdata);
181 CS_UNLOCK(drvdata->base);
183 /* 4096 byte between synchronisation packets */
184 writel_relaxed(0xFFF, drvdata->base + STMSYNCR);
185 writel_relaxed((drvdata->traceid << 16 | /* trace id */
186 0x02 | /* timestamp enable */
187 0x01), /* global STM enable */
188 drvdata->base + STMTCSR);
190 CS_LOCK(drvdata->base);
193 static int stm_enable(struct coresight_device *csdev, struct perf_event *event,
197 struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
199 if (mode != CS_MODE_SYSFS)
202 val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode);
204 /* Someone is already using the tracer */
208 pm_runtime_get_sync(csdev->dev.parent);
210 spin_lock(&drvdata->spinlock);
211 stm_enable_hw(drvdata);
212 spin_unlock(&drvdata->spinlock);
214 dev_dbg(&csdev->dev, "STM tracing enabled\n");
218 static void stm_hwevent_disable_hw(struct stm_drvdata *drvdata)
220 CS_UNLOCK(drvdata->base);
222 writel_relaxed(0x0, drvdata->base + STMHEMCR);
223 writel_relaxed(0x0, drvdata->base + STMHEER);
224 writel_relaxed(0x0, drvdata->base + STMHETER);
226 CS_LOCK(drvdata->base);
229 static void stm_port_disable_hw(struct stm_drvdata *drvdata)
231 CS_UNLOCK(drvdata->base);
233 writel_relaxed(0x0, drvdata->base + STMSPER);
234 writel_relaxed(0x0, drvdata->base + STMSPTRIGCSR);
236 CS_LOCK(drvdata->base);
239 static void stm_disable_hw(struct stm_drvdata *drvdata)
243 CS_UNLOCK(drvdata->base);
245 val = readl_relaxed(drvdata->base + STMTCSR);
246 val &= ~0x1; /* clear global STM enable [0] */
247 writel_relaxed(val, drvdata->base + STMTCSR);
249 CS_LOCK(drvdata->base);
251 stm_port_disable_hw(drvdata);
252 if (drvdata->stmheer)
253 stm_hwevent_disable_hw(drvdata);
256 static void stm_disable(struct coresight_device *csdev,
257 struct perf_event *event)
259 struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
260 struct csdev_access *csa = &csdev->access;
263 * For as long as the tracer isn't disabled another entity can't
264 * change its status. As such we can read the status here without
265 * fearing it will change under us.
267 if (local_read(&csdev->mode) == CS_MODE_SYSFS) {
268 spin_lock(&drvdata->spinlock);
269 stm_disable_hw(drvdata);
270 spin_unlock(&drvdata->spinlock);
272 /* Wait until the engine has completely stopped */
273 coresight_timeout(csa, STMTCSR, STMTCSR_BUSY_BIT, 0);
275 pm_runtime_put(csdev->dev.parent);
277 local_set(&csdev->mode, CS_MODE_DISABLED);
278 dev_dbg(&csdev->dev, "STM tracing disabled\n");
282 static const struct coresight_ops_source stm_source_ops = {
283 .enable = stm_enable,
284 .disable = stm_disable,
287 static const struct coresight_ops stm_cs_ops = {
288 .source_ops = &stm_source_ops,
291 static inline bool stm_addr_unaligned(const void *addr, u8 write_bytes)
293 return ((unsigned long)addr & (write_bytes - 1));
296 static void stm_send(void __iomem *addr, const void *data,
297 u32 size, u8 write_bytes)
301 if (stm_addr_unaligned(data, write_bytes)) {
302 memcpy(paload, data, size);
306 /* now we are 64bit/32bit aligned */
310 writeq_relaxed(*(u64 *)data, addr);
314 writel_relaxed(*(u32 *)data, addr);
317 writew_relaxed(*(u16 *)data, addr);
320 writeb_relaxed(*(u8 *)data, addr);
327 static int stm_generic_link(struct stm_data *stm_data,
328 unsigned int master, unsigned int channel)
330 struct stm_drvdata *drvdata = container_of(stm_data,
331 struct stm_drvdata, stm);
332 if (!drvdata || !drvdata->csdev)
335 return coresight_enable(drvdata->csdev);
338 static void stm_generic_unlink(struct stm_data *stm_data,
339 unsigned int master, unsigned int channel)
341 struct stm_drvdata *drvdata = container_of(stm_data,
342 struct stm_drvdata, stm);
343 if (!drvdata || !drvdata->csdev)
346 coresight_disable(drvdata->csdev);
350 stm_mmio_addr(struct stm_data *stm_data, unsigned int master,
351 unsigned int channel, unsigned int nr_chans)
353 struct stm_drvdata *drvdata = container_of(stm_data,
354 struct stm_drvdata, stm);
357 addr = drvdata->chs.phys + channel * BYTES_PER_CHANNEL;
359 if (offset_in_page(addr) ||
360 offset_in_page(nr_chans * BYTES_PER_CHANNEL))
366 static long stm_generic_set_options(struct stm_data *stm_data,
368 unsigned int channel,
369 unsigned int nr_chans,
370 unsigned long options)
372 struct stm_drvdata *drvdata = container_of(stm_data,
373 struct stm_drvdata, stm);
374 if (!(drvdata && local_read(&drvdata->csdev->mode)))
377 if (channel >= drvdata->numsp)
381 case STM_OPTION_GUARANTEED:
382 set_bit(channel, drvdata->chs.guaranteed);
385 case STM_OPTION_INVARIANT:
386 clear_bit(channel, drvdata->chs.guaranteed);
396 static ssize_t notrace stm_generic_packet(struct stm_data *stm_data,
398 unsigned int channel,
402 const unsigned char *payload)
404 void __iomem *ch_addr;
405 struct stm_drvdata *drvdata = container_of(stm_data,
406 struct stm_drvdata, stm);
407 unsigned int stm_flags;
409 if (!(drvdata && local_read(&drvdata->csdev->mode)))
412 if (channel >= drvdata->numsp)
415 ch_addr = stm_channel_addr(drvdata, channel);
417 stm_flags = (flags & STP_PACKET_TIMESTAMPED) ?
418 STM_FLAG_TIMESTAMPED : 0;
419 stm_flags |= test_bit(channel, drvdata->chs.guaranteed) ?
420 STM_FLAG_GUARANTEED : 0;
422 if (size > drvdata->write_bytes)
423 size = drvdata->write_bytes;
425 size = rounddown_pow_of_two(size);
428 case STP_PACKET_FLAG:
429 ch_addr += stm_channel_off(STM_PKT_TYPE_FLAG, stm_flags);
432 * The generic STM core sets a size of '0' on flag packets.
433 * As such send a flag packet of size '1' and tell the
436 stm_send(ch_addr, payload, 1, drvdata->write_bytes);
440 case STP_PACKET_DATA:
441 stm_flags |= (flags & STP_PACKET_MARKED) ? STM_FLAG_MARKED : 0;
442 ch_addr += stm_channel_off(STM_PKT_TYPE_DATA, stm_flags);
443 stm_send(ch_addr, payload, size,
444 drvdata->write_bytes);
454 static ssize_t hwevent_enable_show(struct device *dev,
455 struct device_attribute *attr, char *buf)
457 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
458 unsigned long val = drvdata->stmheer;
460 return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
463 static ssize_t hwevent_enable_store(struct device *dev,
464 struct device_attribute *attr,
465 const char *buf, size_t size)
467 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
471 ret = kstrtoul(buf, 16, &val);
475 drvdata->stmheer = val;
476 /* HW event enable and trigger go hand in hand */
477 drvdata->stmheter = val;
481 static DEVICE_ATTR_RW(hwevent_enable);
483 static ssize_t hwevent_select_show(struct device *dev,
484 struct device_attribute *attr, char *buf)
486 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
487 unsigned long val = drvdata->stmhebsr;
489 return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
492 static ssize_t hwevent_select_store(struct device *dev,
493 struct device_attribute *attr,
494 const char *buf, size_t size)
496 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
500 ret = kstrtoul(buf, 16, &val);
504 drvdata->stmhebsr = val;
508 static DEVICE_ATTR_RW(hwevent_select);
510 static ssize_t port_select_show(struct device *dev,
511 struct device_attribute *attr, char *buf)
513 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
516 if (!local_read(&drvdata->csdev->mode)) {
517 val = drvdata->stmspscr;
519 spin_lock(&drvdata->spinlock);
520 val = readl_relaxed(drvdata->base + STMSPSCR);
521 spin_unlock(&drvdata->spinlock);
524 return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
527 static ssize_t port_select_store(struct device *dev,
528 struct device_attribute *attr,
529 const char *buf, size_t size)
531 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
532 unsigned long val, stmsper;
535 ret = kstrtoul(buf, 16, &val);
539 spin_lock(&drvdata->spinlock);
540 drvdata->stmspscr = val;
542 if (local_read(&drvdata->csdev->mode)) {
543 CS_UNLOCK(drvdata->base);
544 /* Process as per ARM's TRM recommendation */
545 stmsper = readl_relaxed(drvdata->base + STMSPER);
546 writel_relaxed(0x0, drvdata->base + STMSPER);
547 writel_relaxed(drvdata->stmspscr, drvdata->base + STMSPSCR);
548 writel_relaxed(stmsper, drvdata->base + STMSPER);
549 CS_LOCK(drvdata->base);
551 spin_unlock(&drvdata->spinlock);
555 static DEVICE_ATTR_RW(port_select);
557 static ssize_t port_enable_show(struct device *dev,
558 struct device_attribute *attr, char *buf)
560 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
563 if (!local_read(&drvdata->csdev->mode)) {
564 val = drvdata->stmsper;
566 spin_lock(&drvdata->spinlock);
567 val = readl_relaxed(drvdata->base + STMSPER);
568 spin_unlock(&drvdata->spinlock);
571 return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
574 static ssize_t port_enable_store(struct device *dev,
575 struct device_attribute *attr,
576 const char *buf, size_t size)
578 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
582 ret = kstrtoul(buf, 16, &val);
586 spin_lock(&drvdata->spinlock);
587 drvdata->stmsper = val;
589 if (local_read(&drvdata->csdev->mode)) {
590 CS_UNLOCK(drvdata->base);
591 writel_relaxed(drvdata->stmsper, drvdata->base + STMSPER);
592 CS_LOCK(drvdata->base);
594 spin_unlock(&drvdata->spinlock);
598 static DEVICE_ATTR_RW(port_enable);
600 static ssize_t traceid_show(struct device *dev,
601 struct device_attribute *attr, char *buf)
604 struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
606 val = drvdata->traceid;
607 return sprintf(buf, "%#lx\n", val);
609 static DEVICE_ATTR_RO(traceid);
611 static struct attribute *coresight_stm_attrs[] = {
612 &dev_attr_hwevent_enable.attr,
613 &dev_attr_hwevent_select.attr,
614 &dev_attr_port_enable.attr,
615 &dev_attr_port_select.attr,
616 &dev_attr_traceid.attr,
620 static struct attribute *coresight_stm_mgmt_attrs[] = {
621 coresight_simple_reg32(tcsr, STMTCSR),
622 coresight_simple_reg32(tsfreqr, STMTSFREQR),
623 coresight_simple_reg32(syncr, STMSYNCR),
624 coresight_simple_reg32(sper, STMSPER),
625 coresight_simple_reg32(spter, STMSPTER),
626 coresight_simple_reg32(privmaskr, STMPRIVMASKR),
627 coresight_simple_reg32(spscr, STMSPSCR),
628 coresight_simple_reg32(spmscr, STMSPMSCR),
629 coresight_simple_reg32(spfeat1r, STMSPFEAT1R),
630 coresight_simple_reg32(spfeat2r, STMSPFEAT2R),
631 coresight_simple_reg32(spfeat3r, STMSPFEAT3R),
632 coresight_simple_reg32(devid, CORESIGHT_DEVID),
636 static const struct attribute_group coresight_stm_group = {
637 .attrs = coresight_stm_attrs,
640 static const struct attribute_group coresight_stm_mgmt_group = {
641 .attrs = coresight_stm_mgmt_attrs,
645 static const struct attribute_group *coresight_stm_groups[] = {
646 &coresight_stm_group,
647 &coresight_stm_mgmt_group,
652 static int of_stm_get_stimulus_area(struct device *dev, struct resource *res)
654 const char *name = NULL;
655 int index = 0, found = 0;
656 struct device_node *np = dev->of_node;
658 while (!of_property_read_string_index(np, "reg-names", index, &name)) {
659 if (strcmp("stm-stimulus-base", name)) {
664 /* We have a match and @index is where it's at */
672 return of_address_to_resource(np, index, res);
675 static inline int of_stm_get_stimulus_area(struct device *dev,
676 struct resource *res)
683 static int acpi_stm_get_stimulus_area(struct device *dev, struct resource *res)
686 bool found_base = false;
687 struct resource_entry *rent;
690 struct acpi_device *adev = ACPI_COMPANION(dev);
692 rc = acpi_dev_get_resources(adev, &res_list, NULL, NULL);
697 * The stimulus base for STM device must be listed as the second memory
698 * resource, followed by the programming base address as described in
699 * "Section 2.3 Resources" in ACPI for CoreSightTM 1.0 Platform Design
700 * document (DEN0067).
703 list_for_each_entry(rent, &res_list, node) {
704 if (resource_type(rent->res) != IORESOURCE_MEM)
715 acpi_dev_free_resource_list(&res_list);
719 static inline int acpi_stm_get_stimulus_area(struct device *dev,
720 struct resource *res)
726 static int stm_get_stimulus_area(struct device *dev, struct resource *res)
728 struct fwnode_handle *fwnode = dev_fwnode(dev);
730 if (is_of_node(fwnode))
731 return of_stm_get_stimulus_area(dev, res);
732 else if (is_acpi_node(fwnode))
733 return acpi_stm_get_stimulus_area(dev, res);
737 static u32 stm_fundamental_data_size(struct stm_drvdata *drvdata)
741 if (!IS_ENABLED(CONFIG_64BIT))
744 stmspfeat2r = readl_relaxed(drvdata->base + STMSPFEAT2R);
747 * bit[15:12] represents the fundamental data size
751 return BMVAL(stmspfeat2r, 12, 15) ? 8 : 4;
754 static u32 stm_num_stimulus_port(struct stm_drvdata *drvdata)
758 numsp = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
760 * NUMPS in STMDEVID is 17 bit long and if equal to 0x0,
761 * 32 stimulus ports are supported.
765 numsp = STM_32_CHANNEL;
769 static void stm_init_default_data(struct stm_drvdata *drvdata)
771 /* Don't use port selection */
772 drvdata->stmspscr = 0x0;
774 * Enable all channel regardless of their number. When port
775 * selection isn't used (see above) STMSPER applies to all
776 * 32 channel group available, hence setting all 32 bits to 1
778 drvdata->stmsper = ~0x0;
780 /* Set invariant transaction timing on all channels */
781 bitmap_clear(drvdata->chs.guaranteed, 0, drvdata->numsp);
784 static void stm_init_generic_data(struct stm_drvdata *drvdata,
787 drvdata->stm.name = name;
790 * MasterIDs are assigned at HW design phase. As such the core is
791 * using a single master for interaction with this device.
793 drvdata->stm.sw_start = 1;
794 drvdata->stm.sw_end = 1;
795 drvdata->stm.hw_override = true;
796 drvdata->stm.sw_nchannels = drvdata->numsp;
797 drvdata->stm.sw_mmiosz = BYTES_PER_CHANNEL;
798 drvdata->stm.packet = stm_generic_packet;
799 drvdata->stm.mmio_addr = stm_mmio_addr;
800 drvdata->stm.link = stm_generic_link;
801 drvdata->stm.unlink = stm_generic_unlink;
802 drvdata->stm.set_options = stm_generic_set_options;
805 static int stm_probe(struct amba_device *adev, const struct amba_id *id)
809 struct device *dev = &adev->dev;
810 struct coresight_platform_data *pdata = NULL;
811 struct stm_drvdata *drvdata;
812 struct resource *res = &adev->res;
813 struct resource ch_res;
814 struct coresight_desc desc = { 0 };
816 desc.name = coresight_alloc_device_name(&stm_devs, dev);
820 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
824 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
825 if (!IS_ERR(drvdata->atclk)) {
826 ret = clk_prepare_enable(drvdata->atclk);
830 dev_set_drvdata(dev, drvdata);
832 base = devm_ioremap_resource(dev, res);
834 return PTR_ERR(base);
835 drvdata->base = base;
836 desc.access = CSDEV_ACCESS_IOMEM(base);
838 ret = stm_get_stimulus_area(dev, &ch_res);
841 drvdata->chs.phys = ch_res.start;
843 base = devm_ioremap_resource(dev, &ch_res);
845 return PTR_ERR(base);
846 drvdata->chs.base = base;
848 drvdata->write_bytes = stm_fundamental_data_size(drvdata);
851 drvdata->numsp = boot_nr_channel;
853 drvdata->numsp = stm_num_stimulus_port(drvdata);
855 drvdata->chs.guaranteed = devm_bitmap_zalloc(dev, drvdata->numsp,
857 if (!drvdata->chs.guaranteed)
860 spin_lock_init(&drvdata->spinlock);
862 stm_init_default_data(drvdata);
863 stm_init_generic_data(drvdata, desc.name);
865 if (stm_register_device(dev, &drvdata->stm, THIS_MODULE)) {
867 "%s : stm_register_device failed, probing deferred\n",
869 return -EPROBE_DEFER;
872 pdata = coresight_get_platform_data(dev);
874 ret = PTR_ERR(pdata);
877 adev->dev.platform_data = pdata;
879 desc.type = CORESIGHT_DEV_TYPE_SOURCE;
880 desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE;
881 desc.ops = &stm_cs_ops;
884 desc.groups = coresight_stm_groups;
885 drvdata->csdev = coresight_register(&desc);
886 if (IS_ERR(drvdata->csdev)) {
887 ret = PTR_ERR(drvdata->csdev);
891 trace_id = coresight_trace_id_get_system_id();
896 drvdata->traceid = (u8)trace_id;
898 pm_runtime_put(&adev->dev);
900 dev_info(&drvdata->csdev->dev, "%s initialized\n",
901 (char *)coresight_get_uci_data(id));
905 coresight_unregister(drvdata->csdev);
908 stm_unregister_device(&drvdata->stm);
912 static void stm_remove(struct amba_device *adev)
914 struct stm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
916 coresight_trace_id_put_system_id(drvdata->traceid);
917 coresight_unregister(drvdata->csdev);
919 stm_unregister_device(&drvdata->stm);
923 static int stm_runtime_suspend(struct device *dev)
925 struct stm_drvdata *drvdata = dev_get_drvdata(dev);
927 if (drvdata && !IS_ERR(drvdata->atclk))
928 clk_disable_unprepare(drvdata->atclk);
933 static int stm_runtime_resume(struct device *dev)
935 struct stm_drvdata *drvdata = dev_get_drvdata(dev);
937 if (drvdata && !IS_ERR(drvdata->atclk))
938 clk_prepare_enable(drvdata->atclk);
944 static const struct dev_pm_ops stm_dev_pm_ops = {
945 SET_RUNTIME_PM_OPS(stm_runtime_suspend, stm_runtime_resume, NULL)
948 static const struct amba_id stm_ids[] = {
949 CS_AMBA_ID_DATA(0x000bb962, "STM32"),
950 CS_AMBA_ID_DATA(0x000bb963, "STM500"),
954 MODULE_DEVICE_TABLE(amba, stm_ids);
956 static struct amba_driver stm_driver = {
958 .name = "coresight-stm",
959 .owner = THIS_MODULE,
960 .pm = &stm_dev_pm_ops,
961 .suppress_bind_attrs = true,
964 .remove = stm_remove,
968 module_amba_driver(stm_driver);
970 MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
971 MODULE_DESCRIPTION("Arm CoreSight System Trace Macrocell driver");
972 MODULE_LICENSE("GPL v2");