// SPDX-License-Identifier: GPL-2.0 #include #include #include #include #include #include #include #include #include "eip123.h" #define ENDIAN_OFFSET 0x4c #define ENDIAN_E123_MB BIT(3) static struct class *eip_class; static int eip123_slave_endian_setup(struct regmap *map) { const u32 reg = FIELD_PREP(ENDIAN_E123_MB, 0); return regmap_update_bits(map, ENDIAN_OFFSET, ENDIAN_E123_MB, reg); } static int eip123_probe(struct platform_device *pdev) { struct device *const dev = &pdev->dev; struct device_node *np = dev->of_node; struct regmap *syscon; struct resource *res; struct eip123 *eip; void __iomem *reg; int ret; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); reg = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(reg)) return PTR_ERR(reg); syscon = syscon_regmap_lookup_by_phandle(np, "intel,syscon"); if (IS_ERR(syscon)) return PTR_ERR(syscon); ret = eip123_slave_endian_setup(syscon); if (ret) return ret; eip = devm_kzalloc(dev, sizeof(*eip), GFP_KERNEL); if (!eip) return -ENOMEM; eip->hw = eip123_hw_init(dev, reg); if (IS_ERR(eip->hw)) return PTR_ERR(eip->hw); eip->dev = dev; dev->driver_data = eip; ret = eip123_rng_init(eip); if (ret) return ret; ret = eip123_char_init(eip, eip_class); if (ret) return ret; /* bootcore surrenders hw to interaptive */ #ifdef CONFIG_SOC_TYPE_GRX500_TEP eip123_hw_exit(eip->hw); eip->hw = NULL; ngi_surrender_eip123(); #endif return 0; } static int eip123_remove(struct platform_device *pdev) { struct eip123 *eip = pdev->dev.driver_data; eip123_char_exit(eip, eip_class); /* bootcore already has deinited the hw at this point */ if (eip->hw) eip123_hw_exit(eip->hw); return 0; } const static struct of_device_id eip123_ids[] = { { .compatible = "verimatrix,eip123", }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, eip123_ids); static struct platform_driver eip123_driver = { .probe = eip123_probe, .remove = eip123_remove, .driver = { .name = KBUILD_MODNAME, .of_match_table = eip123_ids, .owner = THIS_MODULE, } }; static int __init eip123_init(void) { eip_class = class_create(THIS_MODULE, MODULE_NAME); if (IS_ERR(eip_class)) return PTR_ERR(eip_class); return platform_driver_register(&eip123_driver); } module_init(eip123_init); static void __exit eip123_exit(void) { platform_driver_unregister(&eip123_driver); class_destroy(eip_class); } module_exit(eip123_exit); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Alexander Theißen "); MODULE_DESCRIPTION("Driver for the eip123 crypto chip.");