1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018 Linaro Limited, All rights reserved.
4 * Author: Mike Leach <mike.leach@linaro.org>
7 #include <linux/amba/bus.h>
8 #include <linux/atomic.h>
9 #include <linux/bits.h>
10 #include <linux/coresight.h>
11 #include <linux/cpu_pm.h>
12 #include <linux/cpuhotplug.h>
13 #include <linux/device.h>
15 #include <linux/kernel.h>
16 #include <linux/list.h>
17 #include <linux/mutex.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/property.h>
20 #include <linux/spinlock.h>
22 #include "coresight-priv.h"
23 #include "coresight-cti.h"
26 * CTI devices can be associated with a PE, or be connected to CoreSight
27 * hardware. We have a list of all CTIs irrespective of CPU bound or
30 * We assume that the non-CPU CTIs are always powered as we do with sinks etc.
32 * We leave the client to figure out if all the CTIs are interconnected with
33 * the same CTM, in general this is the case but does not always have to be.
36 /* net of CTI devices connected via CTM */
37 static LIST_HEAD(ect_net);
39 /* protect the list */
40 static DEFINE_MUTEX(ect_mutex);
42 #define csdev_to_cti_drvdata(csdev) \
43 dev_get_drvdata(csdev->dev.parent)
45 /* power management handling */
46 static int nr_cti_cpu;
48 /* quick lookup list for CPU bound CTIs when power handling */
49 static struct cti_drvdata *cti_cpu_drvdata[NR_CPUS];
52 * CTI naming. CTI bound to cores will have the name cti_cpu<N> where
53 * N is the CPU ID. System CTIs will have the name cti_sys<I> where I
54 * is an index allocated by order of discovery.
56 * CTI device name list - for CTI not bound to cores.
58 DEFINE_CORESIGHT_DEVLIST(cti_sys_devs, "cti_sys");
60 /* write set of regs to hardware - call with spinlock claimed */
61 void cti_write_all_hw_regs(struct cti_drvdata *drvdata)
63 struct cti_config *config = &drvdata->config;
66 CS_UNLOCK(drvdata->base);
68 /* disable CTI before writing registers */
69 writel_relaxed(0, drvdata->base + CTICONTROL);
71 /* write the CTI trigger registers */
72 for (i = 0; i < config->nr_trig_max; i++) {
73 writel_relaxed(config->ctiinen[i], drvdata->base + CTIINEN(i));
74 writel_relaxed(config->ctiouten[i],
75 drvdata->base + CTIOUTEN(i));
79 writel_relaxed(config->ctigate, drvdata->base + CTIGATE);
80 writel_relaxed(config->asicctl, drvdata->base + ASICCTL);
81 writel_relaxed(config->ctiappset, drvdata->base + CTIAPPSET);
84 writel_relaxed(1, drvdata->base + CTICONTROL);
86 CS_LOCK(drvdata->base);
89 /* write regs to hardware and enable */
90 static int cti_enable_hw(struct cti_drvdata *drvdata)
92 struct cti_config *config = &drvdata->config;
96 spin_lock_irqsave(&drvdata->spinlock, flags);
98 /* no need to do anything if enabled or unpowered*/
99 if (config->hw_enabled || !config->hw_powered)
100 goto cti_state_unchanged;
102 /* claim the device */
103 rc = coresight_claim_device(drvdata->csdev);
105 goto cti_err_not_enabled;
107 cti_write_all_hw_regs(drvdata);
109 config->hw_enabled = true;
110 atomic_inc(&drvdata->config.enable_req_count);
111 spin_unlock_irqrestore(&drvdata->spinlock, flags);
115 atomic_inc(&drvdata->config.enable_req_count);
117 /* cannot enable due to error */
119 spin_unlock_irqrestore(&drvdata->spinlock, flags);
123 /* re-enable CTI on CPU when using CPU hotplug */
124 static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
126 struct cti_config *config = &drvdata->config;
128 spin_lock(&drvdata->spinlock);
129 config->hw_powered = true;
131 /* no need to do anything if no enable request */
132 if (!atomic_read(&drvdata->config.enable_req_count))
133 goto cti_hp_not_enabled;
135 /* try to claim the device */
136 if (coresight_claim_device(drvdata->csdev))
137 goto cti_hp_not_enabled;
139 cti_write_all_hw_regs(drvdata);
140 config->hw_enabled = true;
141 spin_unlock(&drvdata->spinlock);
144 /* did not re-enable due to no claim / no request */
146 spin_unlock(&drvdata->spinlock);
149 /* disable hardware */
150 static int cti_disable_hw(struct cti_drvdata *drvdata)
152 struct cti_config *config = &drvdata->config;
153 struct coresight_device *csdev = drvdata->csdev;
155 spin_lock(&drvdata->spinlock);
157 /* check refcount - disable on 0 */
158 if (atomic_dec_return(&drvdata->config.enable_req_count) > 0)
159 goto cti_not_disabled;
161 /* no need to do anything if disabled or cpu unpowered */
162 if (!config->hw_enabled || !config->hw_powered)
163 goto cti_not_disabled;
165 CS_UNLOCK(drvdata->base);
168 writel_relaxed(0, drvdata->base + CTICONTROL);
169 config->hw_enabled = false;
171 coresight_disclaim_device_unlocked(csdev);
172 CS_LOCK(drvdata->base);
173 spin_unlock(&drvdata->spinlock);
176 /* not disabled this call */
178 spin_unlock(&drvdata->spinlock);
182 void cti_write_single_reg(struct cti_drvdata *drvdata, int offset, u32 value)
184 CS_UNLOCK(drvdata->base);
185 writel_relaxed(value, drvdata->base + offset);
186 CS_LOCK(drvdata->base);
189 void cti_write_intack(struct device *dev, u32 ackval)
191 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
192 struct cti_config *config = &drvdata->config;
194 spin_lock(&drvdata->spinlock);
195 /* write if enabled */
196 if (cti_active(config))
197 cti_write_single_reg(drvdata, CTIINTACK, ackval);
198 spin_unlock(&drvdata->spinlock);
202 * Look at the HW DEVID register for some of the HW settings.
203 * DEVID[15:8] - max number of in / out triggers.
205 #define CTI_DEVID_MAXTRIGS(devid_val) ((int) BMVAL(devid_val, 8, 15))
207 /* DEVID[19:16] - number of CTM channels */
208 #define CTI_DEVID_CTMCHANNELS(devid_val) ((int) BMVAL(devid_val, 16, 19))
210 static void cti_set_default_config(struct device *dev,
211 struct cti_drvdata *drvdata)
213 struct cti_config *config = &drvdata->config;
216 devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
217 config->nr_trig_max = CTI_DEVID_MAXTRIGS(devid);
220 * no current hardware should exceed this, but protect the driver
221 * in case of fault / out of spec hw
223 if (config->nr_trig_max > CTIINOUTEN_MAX) {
225 "Limiting HW MaxTrig value(%d) to driver max(%d)\n",
226 config->nr_trig_max, CTIINOUTEN_MAX);
227 config->nr_trig_max = CTIINOUTEN_MAX;
230 config->nr_ctm_channels = CTI_DEVID_CTMCHANNELS(devid);
232 /* Most regs default to 0 as zalloc'ed except...*/
233 config->trig_filter_enable = true;
234 config->ctigate = GENMASK(config->nr_ctm_channels - 1, 0);
235 atomic_set(&config->enable_req_count, 0);
239 * Add a connection entry to the list of connections for this
242 int cti_add_connection_entry(struct device *dev, struct cti_drvdata *drvdata,
243 struct cti_trig_con *tc,
244 struct coresight_device *csdev,
245 const char *assoc_dev_name)
247 struct cti_device *cti_dev = &drvdata->ctidev;
251 * Prefer actual associated CS device dev name to supplied value -
252 * which is likely to be node name / other conn name.
255 tc->con_dev_name = dev_name(&csdev->dev);
256 else if (assoc_dev_name != NULL) {
257 tc->con_dev_name = devm_kstrdup(dev,
258 assoc_dev_name, GFP_KERNEL);
259 if (!tc->con_dev_name)
262 list_add_tail(&tc->node, &cti_dev->trig_cons);
263 cti_dev->nr_trig_con++;
265 /* add connection usage bit info to overall info */
266 drvdata->config.trig_in_use |= tc->con_in->used_mask;
267 drvdata->config.trig_out_use |= tc->con_out->used_mask;
272 /* create a trigger connection with appropriately sized signal groups */
273 struct cti_trig_con *cti_allocate_trig_con(struct device *dev, int in_sigs,
276 struct cti_trig_con *tc = NULL;
277 struct cti_trig_grp *in = NULL, *out = NULL;
279 tc = devm_kzalloc(dev, sizeof(struct cti_trig_con), GFP_KERNEL);
283 in = devm_kzalloc(dev,
284 offsetof(struct cti_trig_grp, sig_types[in_sigs]),
289 out = devm_kzalloc(dev,
290 offsetof(struct cti_trig_grp, sig_types[out_sigs]),
297 tc->con_in->nr_sigs = in_sigs;
298 tc->con_out->nr_sigs = out_sigs;
303 * Add a default connection if nothing else is specified.
304 * single connection based on max in/out info, no assoc device
306 int cti_add_default_connection(struct device *dev, struct cti_drvdata *drvdata)
309 int n_trigs = drvdata->config.nr_trig_max;
310 u32 n_trig_mask = GENMASK(n_trigs - 1, 0);
311 struct cti_trig_con *tc = NULL;
314 * Assume max trigs for in and out,
315 * all used, default sig types allocated
317 tc = cti_allocate_trig_con(dev, n_trigs, n_trigs);
321 tc->con_in->used_mask = n_trig_mask;
322 tc->con_out->used_mask = n_trig_mask;
323 ret = cti_add_connection_entry(dev, drvdata, tc, NULL, "default");
327 /** cti channel api **/
328 /* attach/detach channel from trigger - write through if enabled. */
329 int cti_channel_trig_op(struct device *dev, enum cti_chan_op op,
330 enum cti_trig_dir direction, u32 channel_idx,
333 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
334 struct cti_config *config = &drvdata->config;
340 /* ensure indexes in range */
341 if ((channel_idx >= config->nr_ctm_channels) ||
342 (trigger_idx >= config->nr_trig_max))
345 trig_bitmask = BIT(trigger_idx);
347 /* ensure registered triggers and not out filtered */
348 if (direction == CTI_TRIG_IN) {
349 if (!(trig_bitmask & config->trig_in_use))
352 if (!(trig_bitmask & config->trig_out_use))
355 if ((config->trig_filter_enable) &&
356 (config->trig_out_filter & trig_bitmask))
360 /* update the local register values */
361 chan_bitmask = BIT(channel_idx);
362 reg_offset = (direction == CTI_TRIG_IN ? CTIINEN(trigger_idx) :
363 CTIOUTEN(trigger_idx));
365 spin_lock(&drvdata->spinlock);
367 /* read - modify write - the trigger / channel enable value */
368 reg_value = direction == CTI_TRIG_IN ? config->ctiinen[trigger_idx] :
369 config->ctiouten[trigger_idx];
370 if (op == CTI_CHAN_ATTACH)
371 reg_value |= chan_bitmask;
373 reg_value &= ~chan_bitmask;
375 /* write local copy */
376 if (direction == CTI_TRIG_IN)
377 config->ctiinen[trigger_idx] = reg_value;
379 config->ctiouten[trigger_idx] = reg_value;
381 /* write through if enabled */
382 if (cti_active(config))
383 cti_write_single_reg(drvdata, reg_offset, reg_value);
384 spin_unlock(&drvdata->spinlock);
388 int cti_channel_gate_op(struct device *dev, enum cti_chan_gate_op op,
391 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
392 struct cti_config *config = &drvdata->config;
397 if (channel_idx >= config->nr_ctm_channels)
400 chan_bitmask = BIT(channel_idx);
402 spin_lock(&drvdata->spinlock);
403 reg_value = config->ctigate;
405 case CTI_GATE_CHAN_ENABLE:
406 reg_value |= chan_bitmask;
409 case CTI_GATE_CHAN_DISABLE:
410 reg_value &= ~chan_bitmask;
418 config->ctigate = reg_value;
419 if (cti_active(config))
420 cti_write_single_reg(drvdata, CTIGATE, reg_value);
422 spin_unlock(&drvdata->spinlock);
426 int cti_channel_setop(struct device *dev, enum cti_chan_set_op op,
429 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
430 struct cti_config *config = &drvdata->config;
436 if (channel_idx >= config->nr_ctm_channels)
439 chan_bitmask = BIT(channel_idx);
441 spin_lock(&drvdata->spinlock);
442 reg_value = config->ctiappset;
445 config->ctiappset |= chan_bitmask;
446 reg_value = config->ctiappset;
447 reg_offset = CTIAPPSET;
451 config->ctiappset &= ~chan_bitmask;
452 reg_value = chan_bitmask;
453 reg_offset = CTIAPPCLEAR;
457 config->ctiappset &= ~chan_bitmask;
458 reg_value = chan_bitmask;
459 reg_offset = CTIAPPPULSE;
467 if ((err == 0) && cti_active(config))
468 cti_write_single_reg(drvdata, reg_offset, reg_value);
469 spin_unlock(&drvdata->spinlock);
474 static bool cti_add_sysfs_link(struct cti_drvdata *drvdata,
475 struct cti_trig_con *tc)
477 struct coresight_sysfs_link link_info;
480 link_info.orig = drvdata->csdev;
481 link_info.orig_name = tc->con_dev_name;
482 link_info.target = tc->con_dev;
483 link_info.target_name = dev_name(&drvdata->csdev->dev);
485 link_err = coresight_add_sysfs_link(&link_info);
487 dev_warn(&drvdata->csdev->dev,
488 "Failed to set CTI sysfs link %s<=>%s\n",
489 link_info.orig_name, link_info.target_name);
493 static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
494 struct cti_trig_con *tc)
496 struct coresight_sysfs_link link_info;
498 link_info.orig = drvdata->csdev;
499 link_info.orig_name = tc->con_dev_name;
500 link_info.target = tc->con_dev;
501 link_info.target_name = dev_name(&drvdata->csdev->dev);
502 coresight_remove_sysfs_link(&link_info);
506 * Look for a matching connection device name in the list of connections.
507 * If found then swap in the csdev name, set trig con association pointer
511 cti_match_fixup_csdev(struct cti_device *ctidev, const char *node_name,
512 struct coresight_device *csdev)
514 struct cti_trig_con *tc;
515 struct cti_drvdata *drvdata = container_of(ctidev, struct cti_drvdata,
518 list_for_each_entry(tc, &ctidev->trig_cons, node) {
519 if (tc->con_dev_name) {
520 if (!strcmp(node_name, tc->con_dev_name)) {
521 /* match: so swap in csdev name & dev */
522 tc->con_dev_name = dev_name(&csdev->dev);
524 /* try to set sysfs link */
525 if (cti_add_sysfs_link(drvdata, tc))
527 /* link failed - remove CTI reference */
537 * Search the cti list to add an associated CTI into the supplied CS device
538 * This will set the association if CTI declared before the CS device.
539 * (called from coresight_register() with coresight_mutex locked).
541 static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
543 struct cti_drvdata *ect_item;
544 struct cti_device *ctidev;
545 const char *node_name = NULL;
547 /* protect the list */
548 mutex_lock(&ect_mutex);
550 /* exit if current is an ECT device.*/
551 if ((csdev->type == CORESIGHT_DEV_TYPE_ECT) || list_empty(&ect_net))
554 /* if we didn't find the csdev previously we used the fwnode name */
555 node_name = cti_plat_get_node_name(dev_fwnode(csdev->dev.parent));
559 /* for each CTI in list... */
560 list_for_each_entry(ect_item, &ect_net, node) {
561 ctidev = &ect_item->ctidev;
562 if (cti_match_fixup_csdev(ctidev, node_name, csdev)) {
564 * if we found a matching csdev then update the ECT
565 * association pointer for the device with this CTI.
567 csdev->ect_dev = ect_item->csdev;
572 mutex_unlock(&ect_mutex);
576 * Removing the associated devices is easier.
577 * A CTI will not have a value for csdev->ect_dev.
579 static void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
581 struct cti_drvdata *ctidrv;
582 struct cti_trig_con *tc;
583 struct cti_device *ctidev;
585 mutex_lock(&ect_mutex);
586 if (csdev->ect_dev) {
587 ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
588 ctidev = &ctidrv->ctidev;
589 list_for_each_entry(tc, &ctidev->trig_cons, node) {
590 if (tc->con_dev == csdev) {
591 cti_remove_sysfs_link(ctidrv, tc);
596 csdev->ect_dev = NULL;
598 mutex_unlock(&ect_mutex);
602 * Operations to add and remove associated CTI.
603 * Register to coresight core driver as call back function.
605 static struct cti_assoc_op cti_assoc_ops = {
606 .add = cti_add_assoc_to_csdev,
607 .remove = cti_remove_assoc_from_csdev
611 * Update the cross references where the associated device was found
612 * while we were building the connection info. This will occur if the
613 * assoc device was registered before the CTI.
615 static void cti_update_conn_xrefs(struct cti_drvdata *drvdata)
617 struct cti_trig_con *tc;
618 struct cti_device *ctidev = &drvdata->ctidev;
620 list_for_each_entry(tc, &ctidev->trig_cons, node) {
622 /* if we can set the sysfs link */
623 if (cti_add_sysfs_link(drvdata, tc))
624 /* set the CTI/csdev association */
625 coresight_set_assoc_ectdev_mutex(tc->con_dev,
628 /* otherwise remove reference from CTI */
634 static void cti_remove_conn_xrefs(struct cti_drvdata *drvdata)
636 struct cti_trig_con *tc;
637 struct cti_device *ctidev = &drvdata->ctidev;
639 list_for_each_entry(tc, &ctidev->trig_cons, node) {
641 coresight_set_assoc_ectdev_mutex(tc->con_dev,
643 cti_remove_sysfs_link(drvdata, tc);
649 /** cti PM callbacks **/
650 static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
653 struct cti_drvdata *drvdata;
654 struct coresight_device *csdev;
655 unsigned int cpu = smp_processor_id();
656 int notify_res = NOTIFY_OK;
658 if (!cti_cpu_drvdata[cpu])
661 drvdata = cti_cpu_drvdata[cpu];
662 csdev = drvdata->csdev;
664 if (WARN_ON_ONCE(drvdata->ctidev.cpu != cpu))
667 spin_lock(&drvdata->spinlock);
671 /* CTI regs all static - we have a copy & nothing to save */
672 drvdata->config.hw_powered = false;
673 if (drvdata->config.hw_enabled)
674 coresight_disclaim_device(csdev);
677 case CPU_PM_ENTER_FAILED:
678 drvdata->config.hw_powered = true;
679 if (drvdata->config.hw_enabled) {
680 if (coresight_claim_device(csdev))
681 drvdata->config.hw_enabled = false;
686 /* write hardware registers to re-enable. */
687 drvdata->config.hw_powered = true;
688 drvdata->config.hw_enabled = false;
690 /* check enable reference count to enable HW */
691 if (atomic_read(&drvdata->config.enable_req_count)) {
692 /* check we can claim the device as we re-power */
693 if (coresight_claim_device(csdev))
694 goto cti_notify_exit;
696 drvdata->config.hw_enabled = true;
697 cti_write_all_hw_regs(drvdata);
702 notify_res = NOTIFY_DONE;
707 spin_unlock(&drvdata->spinlock);
711 static struct notifier_block cti_cpu_pm_nb = {
712 .notifier_call = cti_cpu_pm_notify,
715 /* CPU HP handlers */
716 static int cti_starting_cpu(unsigned int cpu)
718 struct cti_drvdata *drvdata = cti_cpu_drvdata[cpu];
723 cti_cpuhp_enable_hw(drvdata);
727 static int cti_dying_cpu(unsigned int cpu)
729 struct cti_drvdata *drvdata = cti_cpu_drvdata[cpu];
734 spin_lock(&drvdata->spinlock);
735 drvdata->config.hw_powered = false;
736 if (drvdata->config.hw_enabled)
737 coresight_disclaim_device(drvdata->csdev);
738 spin_unlock(&drvdata->spinlock);
742 static int cti_pm_setup(struct cti_drvdata *drvdata)
746 if (drvdata->ctidev.cpu == -1)
753 ret = cpuhp_setup_state_nocalls_cpuslocked(
754 CPUHP_AP_ARM_CORESIGHT_CTI_STARTING,
755 "arm/coresight_cti:starting",
756 cti_starting_cpu, cti_dying_cpu);
762 ret = cpu_pm_register_notifier(&cti_cpu_pm_nb);
765 cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_CTI_STARTING);
771 cti_cpu_drvdata[drvdata->ctidev.cpu] = drvdata;
776 /* release PM registrations */
777 static void cti_pm_release(struct cti_drvdata *drvdata)
779 if (drvdata->ctidev.cpu == -1)
782 cti_cpu_drvdata[drvdata->ctidev.cpu] = NULL;
783 if (--nr_cti_cpu == 0) {
784 cpu_pm_unregister_notifier(&cti_cpu_pm_nb);
785 cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_CTI_STARTING);
789 /** cti ect operations **/
790 int cti_enable(struct coresight_device *csdev)
792 struct cti_drvdata *drvdata = csdev_to_cti_drvdata(csdev);
794 return cti_enable_hw(drvdata);
797 int cti_disable(struct coresight_device *csdev)
799 struct cti_drvdata *drvdata = csdev_to_cti_drvdata(csdev);
801 return cti_disable_hw(drvdata);
804 static const struct coresight_ops_ect cti_ops_ect = {
805 .enable = cti_enable,
806 .disable = cti_disable,
809 static const struct coresight_ops cti_ops = {
810 .ect_ops = &cti_ops_ect,
814 * Free up CTI specific resources
815 * called by dev->release, need to call down to underlying csdev release.
817 static void cti_device_release(struct device *dev)
819 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
820 struct cti_drvdata *ect_item, *ect_tmp;
822 mutex_lock(&ect_mutex);
823 cti_pm_release(drvdata);
825 /* remove from the list */
826 list_for_each_entry_safe(ect_item, ect_tmp, &ect_net, node) {
827 if (ect_item == drvdata) {
828 list_del(&ect_item->node);
832 mutex_unlock(&ect_mutex);
834 if (drvdata->csdev_release)
835 drvdata->csdev_release(dev);
837 static void cti_remove(struct amba_device *adev)
839 struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
841 mutex_lock(&ect_mutex);
842 cti_remove_conn_xrefs(drvdata);
843 mutex_unlock(&ect_mutex);
845 coresight_unregister(drvdata->csdev);
848 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
852 struct device *dev = &adev->dev;
853 struct cti_drvdata *drvdata = NULL;
854 struct coresight_desc cti_desc;
855 struct coresight_platform_data *pdata = NULL;
856 struct resource *res = &adev->res;
859 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
863 /* Validity for the resource is already checked by the AMBA core */
864 base = devm_ioremap_resource(dev, res);
866 return PTR_ERR(base);
868 drvdata->base = base;
869 cti_desc.access = CSDEV_ACCESS_IOMEM(base);
871 dev_set_drvdata(dev, drvdata);
873 /* default CTI device info */
874 drvdata->ctidev.cpu = -1;
875 drvdata->ctidev.nr_trig_con = 0;
876 drvdata->ctidev.ctm_id = 0;
877 INIT_LIST_HEAD(&drvdata->ctidev.trig_cons);
879 spin_lock_init(&drvdata->spinlock);
881 /* initialise CTI driver config values */
882 cti_set_default_config(dev, drvdata);
884 pdata = coresight_cti_get_platform_data(dev);
886 dev_err(dev, "coresight_cti_get_platform_data err\n");
887 return PTR_ERR(pdata);
890 /* default to powered - could change on PM notifications */
891 drvdata->config.hw_powered = true;
893 /* set up device name - will depend if cpu bound or otherwise */
894 if (drvdata->ctidev.cpu >= 0)
895 cti_desc.name = devm_kasprintf(dev, GFP_KERNEL, "cti_cpu%d",
896 drvdata->ctidev.cpu);
898 cti_desc.name = coresight_alloc_device_name(&cti_sys_devs, dev);
902 /* setup CPU power management handling for CPU bound CTI devices. */
903 ret = cti_pm_setup(drvdata);
907 /* create dynamic attributes for connections */
908 ret = cti_create_cons_sysfs(dev, drvdata);
910 dev_err(dev, "%s: create dynamic sysfs entries failed\n",
915 /* set up coresight component description */
916 cti_desc.pdata = pdata;
917 cti_desc.type = CORESIGHT_DEV_TYPE_ECT;
918 cti_desc.subtype.ect_subtype = CORESIGHT_DEV_SUBTYPE_ECT_CTI;
919 cti_desc.ops = &cti_ops;
920 cti_desc.groups = drvdata->ctidev.con_groups;
922 drvdata->csdev = coresight_register(&cti_desc);
923 if (IS_ERR(drvdata->csdev)) {
924 ret = PTR_ERR(drvdata->csdev);
928 /* add to list of CTI devices */
929 mutex_lock(&ect_mutex);
930 list_add(&drvdata->node, &ect_net);
931 /* set any cross references */
932 cti_update_conn_xrefs(drvdata);
933 mutex_unlock(&ect_mutex);
935 /* set up release chain */
936 drvdata->csdev_release = drvdata->csdev->dev.release;
937 drvdata->csdev->dev.release = cti_device_release;
939 /* all done - dec pm refcount */
940 pm_runtime_put(&adev->dev);
941 dev_info(&drvdata->csdev->dev, "CTI initialized\n");
945 cti_pm_release(drvdata);
949 static struct amba_cs_uci_id uci_id_cti[] = {
952 .devarch = 0x47701a14, /* CTI v2 */
953 .devarch_mask = 0xfff0ffff,
954 .devtype = 0x00000014, /* maj(0x4-debug) min(0x1-ECT) */
958 static const struct amba_id cti_ids[] = {
959 CS_AMBA_ID(0x000bb906), /* Coresight CTI (SoC 400), C-A72, C-A57 */
960 CS_AMBA_ID(0x000bb922), /* CTI - C-A8 */
961 CS_AMBA_ID(0x000bb9a8), /* CTI - C-A53 */
962 CS_AMBA_ID(0x000bb9aa), /* CTI - C-A73 */
963 CS_AMBA_UCI_ID(0x000bb9da, uci_id_cti), /* CTI - C-A35 */
964 CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */
968 MODULE_DEVICE_TABLE(amba, cti_ids);
970 static struct amba_driver cti_driver = {
972 .name = "coresight-cti",
973 .owner = THIS_MODULE,
974 .suppress_bind_attrs = true,
977 .remove = cti_remove,
981 static int __init cti_init(void)
985 ret = amba_driver_register(&cti_driver);
987 pr_info("Error registering cti driver\n");
988 coresight_set_cti_ops(&cti_assoc_ops);
992 static void __exit cti_exit(void)
994 coresight_remove_cti_ops();
995 amba_driver_unregister(&cti_driver);
998 module_init(cti_init);
999 module_exit(cti_exit);
1001 MODULE_AUTHOR("Mike Leach <mike.leach@linaro.org>");
1002 MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
1003 MODULE_LICENSE("GPL v2");