1/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. 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> 21#include <linux/clk.h> 22#include <linux/of.h> 23#include <linux/coresight.h> 24 25#include "coresight-priv.h" 26 27/** 28 * struct replicator_drvdata - specifics associated to a replicator component 29 * @dev: the device entity associated with this component 30 * @csdev: component vitals needed by the framework 31 */ 32struct replicator_drvdata { 33 struct device *dev; 34 struct coresight_device *csdev; 35}; 36 37static int replicator_enable(struct coresight_device *csdev, int inport, 38 int outport) 39{ 40 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); 41 42 dev_info(drvdata->dev, "REPLICATOR enabled\n"); 43 return 0; 44} 45 46static void replicator_disable(struct coresight_device *csdev, int inport, 47 int outport) 48{ 49 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); 50 51 dev_info(drvdata->dev, "REPLICATOR disabled\n"); 52} 53 54static const struct coresight_ops_link replicator_link_ops = { 55 .enable = replicator_enable, 56 .disable = replicator_disable, 57}; 58 59static const struct coresight_ops replicator_cs_ops = { 60 .link_ops = &replicator_link_ops, 61}; 62 63static int replicator_probe(struct platform_device *pdev) 64{ 65 struct device *dev = &pdev->dev; 66 struct coresight_platform_data *pdata = NULL; 67 struct replicator_drvdata *drvdata; 68 struct coresight_desc *desc; 69 struct device_node *np = pdev->dev.of_node; 70 71 if (np) { 72 pdata = of_get_coresight_platform_data(dev, np); 73 if (IS_ERR(pdata)) 74 return PTR_ERR(pdata); 75 pdev->dev.platform_data = pdata; 76 } 77 78 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); 79 if (!drvdata) 80 return -ENOMEM; 81 82 drvdata->dev = &pdev->dev; 83 platform_set_drvdata(pdev, drvdata); 84 85 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); 86 if (!desc) 87 return -ENOMEM; 88 89 desc->type = CORESIGHT_DEV_TYPE_LINK; 90 desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT; 91 desc->ops = &replicator_cs_ops; 92 desc->pdata = pdev->dev.platform_data; 93 desc->dev = &pdev->dev; 94 drvdata->csdev = coresight_register(desc); 95 if (IS_ERR(drvdata->csdev)) 96 return PTR_ERR(drvdata->csdev); 97 98 dev_info(dev, "REPLICATOR initialized\n"); 99 return 0; 100} 101 102static int replicator_remove(struct platform_device *pdev) 103{ 104 struct replicator_drvdata *drvdata = platform_get_drvdata(pdev); 105 106 coresight_unregister(drvdata->csdev); 107 return 0; 108} 109 110static const struct of_device_id replicator_match[] = { 111 {.compatible = "arm,coresight-replicator"}, 112 {} 113}; 114 115static struct platform_driver replicator_driver = { 116 .probe = replicator_probe, 117 .remove = replicator_remove, 118 .driver = { 119 .name = "coresight-replicator", 120 .of_match_table = replicator_match, 121 }, 122}; 123 124static int __init replicator_init(void) 125{ 126 return platform_driver_register(&replicator_driver); 127} 128module_init(replicator_init); 129 130static void __exit replicator_exit(void) 131{ 132 platform_driver_unregister(&replicator_driver); 133} 134module_exit(replicator_exit); 135 136MODULE_LICENSE("GPL v2"); 137MODULE_DESCRIPTION("CoreSight Replicator driver"); 138