/* * * pmu_client.c * Description: * pmu mrpc client driver * * * GPL LICENSE SUMMARY * * Copyright(c) 2018 Intel Corporation. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * The full GNU General Public License is included in this distribution * in the file called LICENSE.GPL. * * Contact Information: * Intel Corporation * 2200 Mission College Blvd. * Santa Clara, CA 97052 */ #define pr_fmt(fmt) KBUILD_MODNAME ":%s:%d " fmt "\n", __func__, __LINE__ /************************************************/ /** Includes */ /************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEBUG #define DBG(fmt, ...) pr_err(fmt, ##__VA_ARGS__) #else #define DBG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__) #endif /* driver private database */ struct pmu_private { struct platform_device *pdev; /* platform device */ struct mrpc_client *mrpc; /* mrpc client handle */ }; static struct pmu_private *this; struct mrpc_puma7_sram_ctrl_args { Puma7PmuSram_e sram_id; int to_power_on; }; enum { PMU_PUMA7_SRAM_CTRL, }; static inline int pmu_mrpc_call(__u8 procid, void *args, ssize_t args_size) { struct pmu_private *priv = this; int ret, errcode; Uint32 rep; if (!priv) { pr_err("ERROR: mrpc pmu not initialized"); return -EFAULT; } ret = mrpc_call(priv->mrpc, procid, args, args_size, &rep, sizeof(rep), 0, &errcode); if (ret || errcode) { pr_err("ERROR: ret=%d, errcode=%d", ret, errcode); return errcode; } return be32_to_cpu(rep); } int PUMA7_SRAM_Ctrl(Puma7PmuSram_e sram_id, unsigned int power_on) { struct mrpc_puma7_sram_ctrl_args args = { .sram_id = cpu_to_be32(sram_id), .to_power_on = cpu_to_be32(power_on) }; pr_info("call PUMA7_SRAM_Ctrl(sram_id=%d, to_power_on=%d)", args.sram_id, args.to_power_on); return pmu_mrpc_call(PMU_PUMA7_SRAM_CTRL, &args, sizeof(args)); } EXPORT_SYMBOL(PUMA7_SRAM_Ctrl); /* sysfs for future use */ static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pmu_private *priv = dev_get_drvdata(dev); if (!priv) return -EINVAL; return scnprintf(buf, PAGE_SIZE, "status ok"); } static DEVICE_ATTR(status, S_IRUGO, status_show, NULL); static struct attribute *pmu_attrs[] = { &dev_attr_status.attr, NULL }; static struct attribute_group pmu_attrs_group = { .attrs = pmu_attrs, }; /** * pmu_mrpc_probe * * @param pdev platform device * * @return 0 for success, error code otherwise */ static int pmu_mrpc_probe(struct platform_device *pdev) { struct pmu_private *priv; int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { pr_err("memory allocation failed"); return -ENOMEM; } dev_set_drvdata(&pdev->dev, priv); priv->pdev = pdev; ret = sysfs_create_group(&priv->pdev->dev.kobj, &pmu_attrs_group); if (ret) { pr_err("sysfs_create_group failed (ret=%d)", ret); return ret; } priv->mrpc = mrpc_client_register(MRPC_RESERVED_ID_PMU, "pmu"); if (!priv->mrpc) { pr_err("failed to register pmu"); ret = -ENODEV; goto out_remove_group; } this = priv; return 0; out_remove_group: sysfs_remove_group(&priv->pdev->dev.kobj, &pmu_attrs_group); return ret; } /** * pmu_mrpc_remove * * This function is called when the pmu mrpc driver is * removed. * * @param pdev platform device * * @return 0 for success, error code otherwise */ static int pmu_mrpc_remove(struct platform_device *pdev) { struct pmu_private *priv = platform_get_drvdata(pdev); mrpc_client_unregister(priv->mrpc); sysfs_remove_group(&priv->pdev->dev.kobj, &pmu_attrs_group); dev_set_drvdata(&pdev->dev, NULL); this = NULL; return 0; } static struct platform_driver pmu_driver = { .driver = { .name = "pmu_client", }, .probe = pmu_mrpc_probe, .remove = pmu_mrpc_remove, }; static struct platform_device *pmu_device; static int pmu_mrpc_init(void) { int ret; ret = platform_driver_register(&pmu_driver); if (ret < 0) { pr_err("Failed to register pmu platform driver: %d\n", ret); return ret; } pr_debug("pmu client platform driver is registered"); pmu_device = platform_device_register_simple("pmu_client", -1, NULL, 0); if (IS_ERR(pmu_device)) { pr_err("Failed to register pmu platform device\n"); platform_driver_unregister(&pmu_driver); return PTR_ERR(pmu_device); } dev_info(&pmu_device->dev, "platform device is registered\n"); return 0; } static void __exit pmu_mrpc_exit(void) { platform_device_unregister(pmu_device); platform_driver_unregister(&pmu_driver); } /******************************************************/ /** Module Declarations **/ /******************************************************/ static_notifier_module_init(mrpc_ready, pmu_mrpc_init); module_exit(pmu_mrpc_exit); MODULE_AUTHOR("Intel Corporation"); MODULE_DESCRIPTION("pmu mrpc client"); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0");