1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * omap-ocp2scp.c - transform ocp interface protocol to scp protocol 4 * 5 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com 6 * Author: Kishon Vijay Abraham I <kishon@ti.com> 7 */ 8 9 #include <linux/io.h> 10 #include <linux/module.h> 11 #include <linux/platform_device.h> 12 #include <linux/err.h> 13 #include <linux/pm_runtime.h> 14 #include <linux/of.h> 15 #include <linux/of_platform.h> 16 17 #define OCP2SCP_TIMING 0x18 18 #define SYNC2_MASK 0xf 19 20 static int omap_ocp2scp_probe(struct platform_device *pdev) 21 { 22 int ret; 23 u32 reg; 24 void __iomem *regs; 25 struct resource *res; 26 struct device_node *np = pdev->dev.of_node; 27 28 if (np) { 29 ret = of_platform_populate(np, NULL, NULL, &pdev->dev); 30 if (ret) { 31 dev_err(&pdev->dev, 32 "failed to add resources for ocp2scp child\n"); 33 goto err0; 34 } 35 } 36 37 pm_runtime_enable(&pdev->dev); 38 /* 39 * As per AM572x TRM: http://www.ti.com/lit/ug/spruhz6/spruhz6.pdf 40 * under section 26.3.2.2, table 26-26 OCP2SCP TIMING Caution; 41 * As per OMAP4430 TRM: http://www.ti.com/lit/ug/swpu231ap/swpu231ap.pdf 42 * under section 23.12.6.2.2 , Table 23-1213 OCP2SCP TIMING Caution; 43 * As per OMAP4460 TRM: http://www.ti.com/lit/ug/swpu235ab/swpu235ab.pdf 44 * under section 23.12.6.2.2, Table 23-1213 OCP2SCP TIMING Caution; 45 * As per OMAP543x TRM http://www.ti.com/lit/pdf/swpu249 46 * under section 27.3.2.2, Table 27-27 OCP2SCP TIMING Caution; 47 * 48 * Read path of OCP2SCP is not working properly due to low reset value 49 * of SYNC2 parameter in OCP2SCP. Suggested reset value is 0x6 or more. 50 */ 51 if (!of_device_is_compatible(np, "ti,am437x-ocp2scp")) { 52 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 53 regs = devm_ioremap_resource(&pdev->dev, res); 54 if (IS_ERR(regs)) { 55 ret = PTR_ERR(regs); 56 goto err1; 57 } 58 59 pm_runtime_get_sync(&pdev->dev); 60 reg = readl_relaxed(regs + OCP2SCP_TIMING); 61 reg &= ~(SYNC2_MASK); 62 reg |= 0x6; 63 writel_relaxed(reg, regs + OCP2SCP_TIMING); 64 pm_runtime_put_sync(&pdev->dev); 65 } 66 67 return 0; 68 69 err1: 70 pm_runtime_disable(&pdev->dev); 71 72 err0: 73 of_platform_depopulate(&pdev->dev); 74 75 return ret; 76 } 77 78 static void omap_ocp2scp_remove(struct platform_device *pdev) 79 { 80 pm_runtime_disable(&pdev->dev); 81 of_platform_depopulate(&pdev->dev); 82 } 83 84 #ifdef CONFIG_OF 85 static const struct of_device_id omap_ocp2scp_id_table[] = { 86 { .compatible = "ti,omap-ocp2scp" }, 87 { .compatible = "ti,am437x-ocp2scp" }, 88 {} 89 }; 90 MODULE_DEVICE_TABLE(of, omap_ocp2scp_id_table); 91 #endif 92 93 static struct platform_driver omap_ocp2scp_driver = { 94 .probe = omap_ocp2scp_probe, 95 .remove = omap_ocp2scp_remove, 96 .driver = { 97 .name = "omap-ocp2scp", 98 .of_match_table = of_match_ptr(omap_ocp2scp_id_table), 99 }, 100 }; 101 102 module_platform_driver(omap_ocp2scp_driver); 103 104 MODULE_ALIAS("platform:omap-ocp2scp"); 105 MODULE_AUTHOR("Texas Instruments Inc."); 106 MODULE_DESCRIPTION("OMAP OCP2SCP driver"); 107 MODULE_LICENSE("GPL v2"); 108