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;
93 struct device *dev = &drvdata->csdev->dev;
97 pm_runtime_get_sync(dev->parent);
98 spin_lock_irqsave(&drvdata->spinlock, flags);
100 /* no need to do anything if enabled or unpowered*/
101 if (config->hw_enabled || !config->hw_powered)
102 goto cti_state_unchanged;
104 /* claim the device */
105 rc = coresight_claim_device(drvdata->csdev);
107 goto cti_err_not_enabled;
109 cti_write_all_hw_regs(drvdata);
111 config->hw_enabled = true;
112 atomic_inc(&drvdata->config.enable_req_count);
113 spin_unlock_irqrestore(&drvdata->spinlock, flags);
117 atomic_inc(&drvdata->config.enable_req_count);
119 /* cannot enable due to error */
121 spin_unlock_irqrestore(&drvdata->spinlock, flags);
122 pm_runtime_put(dev->parent);
126 /* re-enable CTI on CPU when using CPU hotplug */
127 static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
129 struct cti_config *config = &drvdata->config;
131 spin_lock(&drvdata->spinlock);
132 config->hw_powered = true;
134 /* no need to do anything if no enable request */
135 if (!atomic_read(&drvdata->config.enable_req_count))
136 goto cti_hp_not_enabled;
138 /* try to claim the device */
139 if (coresight_claim_device(drvdata->csdev))
140 goto cti_hp_not_enabled;
142 cti_write_all_hw_regs(drvdata);
143 config->hw_enabled = true;
144 spin_unlock(&drvdata->spinlock);
147 /* did not re-enable due to no claim / no request */
149 spin_unlock(&drvdata->spinlock);
152 /* disable hardware */
153 static int cti_disable_hw(struct cti_drvdata *drvdata)
155 struct cti_config *config = &drvdata->config;
156 struct device *dev = &drvdata->csdev->dev;
157 struct coresight_device *csdev = drvdata->csdev;
159 spin_lock(&drvdata->spinlock);
161 /* check refcount - disable on 0 */
162 if (atomic_dec_return(&drvdata->config.enable_req_count) > 0)
163 goto cti_not_disabled;
165 /* no need to do anything if disabled or cpu unpowered */
166 if (!config->hw_enabled || !config->hw_powered)
167 goto cti_not_disabled;
169 CS_UNLOCK(drvdata->base);
172 writel_relaxed(0, drvdata->base + CTICONTROL);
173 config->hw_enabled = false;
175 coresight_disclaim_device_unlocked(csdev);
176 CS_LOCK(drvdata->base);
177 spin_unlock(&drvdata->spinlock);
178 pm_runtime_put(dev->parent);
181 /* not disabled this call */
183 spin_unlock(&drvdata->spinlock);
187 void cti_write_single_reg(struct cti_drvdata *drvdata, int offset, u32 value)
189 CS_UNLOCK(drvdata->base);
190 writel_relaxed(value, drvdata->base + offset);
191 CS_LOCK(drvdata->base);
194 void cti_write_intack(struct device *dev, u32 ackval)
196 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
197 struct cti_config *config = &drvdata->config;
199 spin_lock(&drvdata->spinlock);
200 /* write if enabled */
201 if (cti_active(config))
202 cti_write_single_reg(drvdata, CTIINTACK, ackval);
203 spin_unlock(&drvdata->spinlock);
207 * Look at the HW DEVID register for some of the HW settings.
208 * DEVID[15:8] - max number of in / out triggers.
210 #define CTI_DEVID_MAXTRIGS(devid_val) ((int) BMVAL(devid_val, 8, 15))
212 /* DEVID[19:16] - number of CTM channels */
213 #define CTI_DEVID_CTMCHANNELS(devid_val) ((int) BMVAL(devid_val, 16, 19))
215 static void cti_set_default_config(struct device *dev,
216 struct cti_drvdata *drvdata)
218 struct cti_config *config = &drvdata->config;
221 devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
222 config->nr_trig_max = CTI_DEVID_MAXTRIGS(devid);
225 * no current hardware should exceed this, but protect the driver
226 * in case of fault / out of spec hw
228 if (config->nr_trig_max > CTIINOUTEN_MAX) {
230 "Limiting HW MaxTrig value(%d) to driver max(%d)\n",
231 config->nr_trig_max, CTIINOUTEN_MAX);
232 config->nr_trig_max = CTIINOUTEN_MAX;
235 config->nr_ctm_channels = CTI_DEVID_CTMCHANNELS(devid);
237 /* Most regs default to 0 as zalloc'ed except...*/
238 config->trig_filter_enable = true;
239 config->ctigate = GENMASK(config->nr_ctm_channels - 1, 0);
240 atomic_set(&config->enable_req_count, 0);
244 * Add a connection entry to the list of connections for this
247 int cti_add_connection_entry(struct device *dev, struct cti_drvdata *drvdata,
248 struct cti_trig_con *tc,
249 struct coresight_device *csdev,
250 const char *assoc_dev_name)
252 struct cti_device *cti_dev = &drvdata->ctidev;
256 * Prefer actual associated CS device dev name to supplied value -
257 * which is likely to be node name / other conn name.
260 tc->con_dev_name = dev_name(&csdev->dev);
261 else if (assoc_dev_name != NULL) {
262 tc->con_dev_name = devm_kstrdup(dev,
263 assoc_dev_name, GFP_KERNEL);
264 if (!tc->con_dev_name)
267 list_add_tail(&tc->node, &cti_dev->trig_cons);
268 cti_dev->nr_trig_con++;
270 /* add connection usage bit info to overall info */
271 drvdata->config.trig_in_use |= tc->con_in->used_mask;
272 drvdata->config.trig_out_use |= tc->con_out->used_mask;
277 /* create a trigger connection with appropriately sized signal groups */
278 struct cti_trig_con *cti_allocate_trig_con(struct device *dev, int in_sigs,
281 struct cti_trig_con *tc = NULL;
282 struct cti_trig_grp *in = NULL, *out = NULL;
284 tc = devm_kzalloc(dev, sizeof(struct cti_trig_con), GFP_KERNEL);
288 in = devm_kzalloc(dev,
289 offsetof(struct cti_trig_grp, sig_types[in_sigs]),
294 out = devm_kzalloc(dev,
295 offsetof(struct cti_trig_grp, sig_types[out_sigs]),
302 tc->con_in->nr_sigs = in_sigs;
303 tc->con_out->nr_sigs = out_sigs;
308 * Add a default connection if nothing else is specified.
309 * single connection based on max in/out info, no assoc device
311 int cti_add_default_connection(struct device *dev, struct cti_drvdata *drvdata)
314 int n_trigs = drvdata->config.nr_trig_max;
315 u32 n_trig_mask = GENMASK(n_trigs - 1, 0);
316 struct cti_trig_con *tc = NULL;
319 * Assume max trigs for in and out,
320 * all used, default sig types allocated
322 tc = cti_allocate_trig_con(dev, n_trigs, n_trigs);
326 tc->con_in->used_mask = n_trig_mask;
327 tc->con_out->used_mask = n_trig_mask;
328 ret = cti_add_connection_entry(dev, drvdata, tc, NULL, "default");
332 /** cti channel api **/
333 /* attach/detach channel from trigger - write through if enabled. */
334 int cti_channel_trig_op(struct device *dev, enum cti_chan_op op,
335 enum cti_trig_dir direction, u32 channel_idx,
338 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
339 struct cti_config *config = &drvdata->config;
345 /* ensure indexes in range */
346 if ((channel_idx >= config->nr_ctm_channels) ||
347 (trigger_idx >= config->nr_trig_max))
350 trig_bitmask = BIT(trigger_idx);
352 /* ensure registered triggers and not out filtered */
353 if (direction == CTI_TRIG_IN) {
354 if (!(trig_bitmask & config->trig_in_use))
357 if (!(trig_bitmask & config->trig_out_use))
360 if ((config->trig_filter_enable) &&
361 (config->trig_out_filter & trig_bitmask))
365 /* update the local register values */
366 chan_bitmask = BIT(channel_idx);
367 reg_offset = (direction == CTI_TRIG_IN ? CTIINEN(trigger_idx) :
368 CTIOUTEN(trigger_idx));
370 spin_lock(&drvdata->spinlock);
372 /* read - modify write - the trigger / channel enable value */
373 reg_value = direction == CTI_TRIG_IN ? config->ctiinen[trigger_idx] :
374 config->ctiouten[trigger_idx];
375 if (op == CTI_CHAN_ATTACH)
376 reg_value |= chan_bitmask;
378 reg_value &= ~chan_bitmask;
380 /* write local copy */
381 if (direction == CTI_TRIG_IN)
382 config->ctiinen[trigger_idx] = reg_value;
384 config->ctiouten[trigger_idx] = reg_value;
386 /* write through if enabled */
387 if (cti_active(config))
388 cti_write_single_reg(drvdata, reg_offset, reg_value);
389 spin_unlock(&drvdata->spinlock);
393 int cti_channel_gate_op(struct device *dev, enum cti_chan_gate_op op,
396 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
397 struct cti_config *config = &drvdata->config;
402 if (channel_idx >= config->nr_ctm_channels)
405 chan_bitmask = BIT(channel_idx);
407 spin_lock(&drvdata->spinlock);
408 reg_value = config->ctigate;
410 case CTI_GATE_CHAN_ENABLE:
411 reg_value |= chan_bitmask;
414 case CTI_GATE_CHAN_DISABLE:
415 reg_value &= ~chan_bitmask;
423 config->ctigate = reg_value;
424 if (cti_active(config))
425 cti_write_single_reg(drvdata, CTIGATE, reg_value);
427 spin_unlock(&drvdata->spinlock);
431 int cti_channel_setop(struct device *dev, enum cti_chan_set_op op,
434 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
435 struct cti_config *config = &drvdata->config;
441 if (channel_idx >= config->nr_ctm_channels)
444 chan_bitmask = BIT(channel_idx);
446 spin_lock(&drvdata->spinlock);
447 reg_value = config->ctiappset;
450 config->ctiappset |= chan_bitmask;
451 reg_value = config->ctiappset;
452 reg_offset = CTIAPPSET;
456 config->ctiappset &= ~chan_bitmask;
457 reg_value = chan_bitmask;
458 reg_offset = CTIAPPCLEAR;
462 config->ctiappset &= ~chan_bitmask;
463 reg_value = chan_bitmask;
464 reg_offset = CTIAPPPULSE;
472 if ((err == 0) && cti_active(config))
473 cti_write_single_reg(drvdata, reg_offset, reg_value);
474 spin_unlock(&drvdata->spinlock);
479 static bool cti_add_sysfs_link(struct cti_drvdata *drvdata,
480 struct cti_trig_con *tc)
482 struct coresight_sysfs_link link_info;
485 link_info.orig = drvdata->csdev;
486 link_info.orig_name = tc->con_dev_name;
487 link_info.target = tc->con_dev;
488 link_info.target_name = dev_name(&drvdata->csdev->dev);
490 link_err = coresight_add_sysfs_link(&link_info);
492 dev_warn(&drvdata->csdev->dev,
493 "Failed to set CTI sysfs link %s<=>%s\n",
494 link_info.orig_name, link_info.target_name);
498 static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
499 struct cti_trig_con *tc)
501 struct coresight_sysfs_link link_info;
503 link_info.orig = drvdata->csdev;
504 link_info.orig_name = tc->con_dev_name;
505 link_info.target = tc->con_dev;
506 link_info.target_name = dev_name(&drvdata->csdev->dev);
507 coresight_remove_sysfs_link(&link_info);
511 * Look for a matching connection device name in the list of connections.
512 * If found then swap in the csdev name, set trig con association pointer
516 cti_match_fixup_csdev(struct cti_device *ctidev, const char *node_name,
517 struct coresight_device *csdev)
519 struct cti_trig_con *tc;
520 struct cti_drvdata *drvdata = container_of(ctidev, struct cti_drvdata,
523 list_for_each_entry(tc, &ctidev->trig_cons, node) {
524 if (tc->con_dev_name) {
525 if (!strcmp(node_name, tc->con_dev_name)) {
526 /* match: so swap in csdev name & dev */
527 tc->con_dev_name = dev_name(&csdev->dev);
529 /* try to set sysfs link */
530 if (cti_add_sysfs_link(drvdata, tc))
532 /* link failed - remove CTI reference */
542 * Search the cti list to add an associated CTI into the supplied CS device
543 * This will set the association if CTI declared before the CS device.
544 * (called from coresight_register() without coresight_mutex locked).
546 static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
548 struct cti_drvdata *ect_item;
549 struct cti_device *ctidev;
550 const char *node_name = NULL;
552 /* protect the list */
553 mutex_lock(&ect_mutex);
555 /* exit if current is an ECT device.*/
556 if ((csdev->type == CORESIGHT_DEV_TYPE_ECT) || list_empty(&ect_net))
559 /* if we didn't find the csdev previously we used the fwnode name */
560 node_name = cti_plat_get_node_name(dev_fwnode(csdev->dev.parent));
564 /* for each CTI in list... */
565 list_for_each_entry(ect_item, &ect_net, node) {
566 ctidev = &ect_item->ctidev;
567 if (cti_match_fixup_csdev(ctidev, node_name, csdev)) {
569 * if we found a matching csdev then update the ECT
570 * association pointer for the device with this CTI.
572 coresight_set_assoc_ectdev_mutex(csdev->ect_dev,
578 mutex_unlock(&ect_mutex);
582 * Removing the associated devices is easier.
583 * A CTI will not have a value for csdev->ect_dev.
585 static void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
587 struct cti_drvdata *ctidrv;
588 struct cti_trig_con *tc;
589 struct cti_device *ctidev;
591 mutex_lock(&ect_mutex);
592 if (csdev->ect_dev) {
593 ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
594 ctidev = &ctidrv->ctidev;
595 list_for_each_entry(tc, &ctidev->trig_cons, node) {
596 if (tc->con_dev == csdev) {
597 cti_remove_sysfs_link(ctidrv, tc);
602 csdev->ect_dev = NULL;
604 mutex_unlock(&ect_mutex);
608 * Operations to add and remove associated CTI.
609 * Register to coresight core driver as call back function.
611 static struct cti_assoc_op cti_assoc_ops = {
612 .add = cti_add_assoc_to_csdev,
613 .remove = cti_remove_assoc_from_csdev
617 * Update the cross references where the associated device was found
618 * while we were building the connection info. This will occur if the
619 * assoc device was registered before the CTI.
621 static void cti_update_conn_xrefs(struct cti_drvdata *drvdata)
623 struct cti_trig_con *tc;
624 struct cti_device *ctidev = &drvdata->ctidev;
626 list_for_each_entry(tc, &ctidev->trig_cons, node) {
628 /* if we can set the sysfs link */
629 if (cti_add_sysfs_link(drvdata, tc))
630 /* set the CTI/csdev association */
631 coresight_set_assoc_ectdev_mutex(tc->con_dev,
634 /* otherwise remove reference from CTI */
640 static void cti_remove_conn_xrefs(struct cti_drvdata *drvdata)
642 struct cti_trig_con *tc;
643 struct cti_device *ctidev = &drvdata->ctidev;
645 list_for_each_entry(tc, &ctidev->trig_cons, node) {
647 coresight_set_assoc_ectdev_mutex(tc->con_dev,
649 cti_remove_sysfs_link(drvdata, tc);
655 /** cti PM callbacks **/
656 static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
659 struct cti_drvdata *drvdata;
660 struct coresight_device *csdev;
661 unsigned int cpu = smp_processor_id();
662 int notify_res = NOTIFY_OK;
664 if (!cti_cpu_drvdata[cpu])
667 drvdata = cti_cpu_drvdata[cpu];
668 csdev = drvdata->csdev;
670 if (WARN_ON_ONCE(drvdata->ctidev.cpu != cpu))
673 spin_lock(&drvdata->spinlock);
677 /* CTI regs all static - we have a copy & nothing to save */
678 drvdata->config.hw_powered = false;
679 if (drvdata->config.hw_enabled)
680 coresight_disclaim_device(csdev);
683 case CPU_PM_ENTER_FAILED:
684 drvdata->config.hw_powered = true;
685 if (drvdata->config.hw_enabled) {
686 if (coresight_claim_device(csdev))
687 drvdata->config.hw_enabled = false;
692 /* write hardware registers to re-enable. */
693 drvdata->config.hw_powered = true;
694 drvdata->config.hw_enabled = false;
696 /* check enable reference count to enable HW */
697 if (atomic_read(&drvdata->config.enable_req_count)) {
698 /* check we can claim the device as we re-power */
699 if (coresight_claim_device(csdev))
700 goto cti_notify_exit;
702 drvdata->config.hw_enabled = true;
703 cti_write_all_hw_regs(drvdata);
708 notify_res = NOTIFY_DONE;
713 spin_unlock(&drvdata->spinlock);
717 static struct notifier_block cti_cpu_pm_nb = {
718 .notifier_call = cti_cpu_pm_notify,
721 /* CPU HP handlers */
722 static int cti_starting_cpu(unsigned int cpu)
724 struct cti_drvdata *drvdata = cti_cpu_drvdata[cpu];
729 cti_cpuhp_enable_hw(drvdata);
733 static int cti_dying_cpu(unsigned int cpu)
735 struct cti_drvdata *drvdata = cti_cpu_drvdata[cpu];
740 spin_lock(&drvdata->spinlock);
741 drvdata->config.hw_powered = false;
742 if (drvdata->config.hw_enabled)
743 coresight_disclaim_device(drvdata->csdev);
744 spin_unlock(&drvdata->spinlock);
748 static int cti_pm_setup(struct cti_drvdata *drvdata)
752 if (drvdata->ctidev.cpu == -1)
759 ret = cpuhp_setup_state_nocalls_cpuslocked(
760 CPUHP_AP_ARM_CORESIGHT_CTI_STARTING,
761 "arm/coresight_cti:starting",
762 cti_starting_cpu, cti_dying_cpu);
768 ret = cpu_pm_register_notifier(&cti_cpu_pm_nb);
771 cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_CTI_STARTING);
777 cti_cpu_drvdata[drvdata->ctidev.cpu] = drvdata;
782 /* release PM registrations */
783 static void cti_pm_release(struct cti_drvdata *drvdata)
785 if (drvdata->ctidev.cpu == -1)
788 cti_cpu_drvdata[drvdata->ctidev.cpu] = NULL;
789 if (--nr_cti_cpu == 0) {
790 cpu_pm_unregister_notifier(&cti_cpu_pm_nb);
791 cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_CTI_STARTING);
795 /** cti ect operations **/
796 int cti_enable(struct coresight_device *csdev)
798 struct cti_drvdata *drvdata = csdev_to_cti_drvdata(csdev);
800 return cti_enable_hw(drvdata);
803 int cti_disable(struct coresight_device *csdev)
805 struct cti_drvdata *drvdata = csdev_to_cti_drvdata(csdev);
807 return cti_disable_hw(drvdata);
810 static const struct coresight_ops_ect cti_ops_ect = {
811 .enable = cti_enable,
812 .disable = cti_disable,
815 static const struct coresight_ops cti_ops = {
816 .ect_ops = &cti_ops_ect,
820 * Free up CTI specific resources
821 * called by dev->release, need to call down to underlying csdev release.
823 static void cti_device_release(struct device *dev)
825 struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
826 struct cti_drvdata *ect_item, *ect_tmp;
828 mutex_lock(&ect_mutex);
829 cti_pm_release(drvdata);
831 /* remove from the list */
832 list_for_each_entry_safe(ect_item, ect_tmp, &ect_net, node) {
833 if (ect_item == drvdata) {
834 list_del(&ect_item->node);
838 mutex_unlock(&ect_mutex);
840 if (drvdata->csdev_release)
841 drvdata->csdev_release(dev);
843 static void cti_remove(struct amba_device *adev)
845 struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
847 mutex_lock(&ect_mutex);
848 cti_remove_conn_xrefs(drvdata);
849 mutex_unlock(&ect_mutex);
851 coresight_unregister(drvdata->csdev);
854 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
858 struct device *dev = &adev->dev;
859 struct cti_drvdata *drvdata = NULL;
860 struct coresight_desc cti_desc;
861 struct coresight_platform_data *pdata = NULL;
862 struct resource *res = &adev->res;
865 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
869 /* Validity for the resource is already checked by the AMBA core */
870 base = devm_ioremap_resource(dev, res);
872 return PTR_ERR(base);
874 drvdata->base = base;
875 cti_desc.access = CSDEV_ACCESS_IOMEM(base);
877 dev_set_drvdata(dev, drvdata);
879 /* default CTI device info */
880 drvdata->ctidev.cpu = -1;
881 drvdata->ctidev.nr_trig_con = 0;
882 drvdata->ctidev.ctm_id = 0;
883 INIT_LIST_HEAD(&drvdata->ctidev.trig_cons);
885 spin_lock_init(&drvdata->spinlock);
887 /* initialise CTI driver config values */
888 cti_set_default_config(dev, drvdata);
890 pdata = coresight_cti_get_platform_data(dev);
892 dev_err(dev, "coresight_cti_get_platform_data err\n");
893 return PTR_ERR(pdata);
896 /* default to powered - could change on PM notifications */
897 drvdata->config.hw_powered = true;
899 /* set up device name - will depend if cpu bound or otherwise */
900 if (drvdata->ctidev.cpu >= 0)
901 cti_desc.name = devm_kasprintf(dev, GFP_KERNEL, "cti_cpu%d",
902 drvdata->ctidev.cpu);
904 cti_desc.name = coresight_alloc_device_name(&cti_sys_devs, dev);
908 /* setup CPU power management handling for CPU bound CTI devices. */
909 ret = cti_pm_setup(drvdata);
913 /* create dynamic attributes for connections */
914 ret = cti_create_cons_sysfs(dev, drvdata);
916 dev_err(dev, "%s: create dynamic sysfs entries failed\n",
921 /* set up coresight component description */
922 cti_desc.pdata = pdata;
923 cti_desc.type = CORESIGHT_DEV_TYPE_ECT;
924 cti_desc.subtype.ect_subtype = CORESIGHT_DEV_SUBTYPE_ECT_CTI;
925 cti_desc.ops = &cti_ops;
926 cti_desc.groups = drvdata->ctidev.con_groups;
928 drvdata->csdev = coresight_register(&cti_desc);
929 if (IS_ERR(drvdata->csdev)) {
930 ret = PTR_ERR(drvdata->csdev);
934 /* add to list of CTI devices */
935 mutex_lock(&ect_mutex);
936 list_add(&drvdata->node, &ect_net);
937 /* set any cross references */
938 cti_update_conn_xrefs(drvdata);
939 mutex_unlock(&ect_mutex);
941 /* set up release chain */
942 drvdata->csdev_release = drvdata->csdev->dev.release;
943 drvdata->csdev->dev.release = cti_device_release;
945 /* all done - dec pm refcount */
946 pm_runtime_put(&adev->dev);
947 dev_info(&drvdata->csdev->dev, "CTI initialized\n");
951 cti_pm_release(drvdata);
955 static struct amba_cs_uci_id uci_id_cti[] = {
958 .devarch = 0x47701a14, /* CTI v2 */
959 .devarch_mask = 0xfff0ffff,
960 .devtype = 0x00000014, /* maj(0x4-debug) min(0x1-ECT) */
964 static const struct amba_id cti_ids[] = {
965 CS_AMBA_ID(0x000bb906), /* Coresight CTI (SoC 400), C-A72, C-A57 */
966 CS_AMBA_ID(0x000bb922), /* CTI - C-A8 */
967 CS_AMBA_ID(0x000bb9a8), /* CTI - C-A53 */
968 CS_AMBA_ID(0x000bb9aa), /* CTI - C-A73 */
969 CS_AMBA_UCI_ID(0x000bb9da, uci_id_cti), /* CTI - C-A35 */
970 CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */
974 MODULE_DEVICE_TABLE(amba, cti_ids);
976 static struct amba_driver cti_driver = {
978 .name = "coresight-cti",
979 .owner = THIS_MODULE,
980 .suppress_bind_attrs = true,
983 .remove = cti_remove,
987 static int __init cti_init(void)
991 ret = amba_driver_register(&cti_driver);
993 pr_info("Error registering cti driver\n");
994 coresight_set_cti_ops(&cti_assoc_ops);
998 static void __exit cti_exit(void)
1000 coresight_remove_cti_ops();
1001 amba_driver_unregister(&cti_driver);
1004 module_init(cti_init);
1005 module_exit(cti_exit);
1007 MODULE_AUTHOR("Mike Leach <mike.leach@linaro.org>");
1008 MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
1009 MODULE_LICENSE("GPL v2");