xref: /openbmc/linux/drivers/soc/qcom/ice.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
12afbf43aSAbel Vesa // SPDX-License-Identifier: GPL-2.0
22afbf43aSAbel Vesa /*
32afbf43aSAbel Vesa  * Qualcomm ICE (Inline Crypto Engine) support.
42afbf43aSAbel Vesa  *
52afbf43aSAbel Vesa  * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
62afbf43aSAbel Vesa  * Copyright (c) 2019, Google LLC
72afbf43aSAbel Vesa  * Copyright (c) 2023, Linaro Limited
82afbf43aSAbel Vesa  */
92afbf43aSAbel Vesa 
102afbf43aSAbel Vesa #include <linux/bitfield.h>
112afbf43aSAbel Vesa #include <linux/clk.h>
122afbf43aSAbel Vesa #include <linux/delay.h>
132afbf43aSAbel Vesa #include <linux/iopoll.h>
14*6484be9dSRob Herring #include <linux/of.h>
152afbf43aSAbel Vesa #include <linux/of_platform.h>
16*6484be9dSRob Herring #include <linux/platform_device.h>
172afbf43aSAbel Vesa 
182afbf43aSAbel Vesa #include <linux/firmware/qcom/qcom_scm.h>
192afbf43aSAbel Vesa 
202afbf43aSAbel Vesa #include <soc/qcom/ice.h>
212afbf43aSAbel Vesa 
222afbf43aSAbel Vesa #define AES_256_XTS_KEY_SIZE			64
232afbf43aSAbel Vesa 
242afbf43aSAbel Vesa /* QCOM ICE registers */
252afbf43aSAbel Vesa #define QCOM_ICE_REG_VERSION			0x0008
262afbf43aSAbel Vesa #define QCOM_ICE_REG_FUSE_SETTING		0x0010
272afbf43aSAbel Vesa #define QCOM_ICE_REG_BIST_STATUS		0x0070
282afbf43aSAbel Vesa #define QCOM_ICE_REG_ADVANCED_CONTROL		0x1000
292afbf43aSAbel Vesa 
302afbf43aSAbel Vesa /* BIST ("built-in self-test") status flags */
312afbf43aSAbel Vesa #define QCOM_ICE_BIST_STATUS_MASK		GENMASK(31, 28)
322afbf43aSAbel Vesa 
332afbf43aSAbel Vesa #define QCOM_ICE_FUSE_SETTING_MASK		0x1
342afbf43aSAbel Vesa #define QCOM_ICE_FORCE_HW_KEY0_SETTING_MASK	0x2
352afbf43aSAbel Vesa #define QCOM_ICE_FORCE_HW_KEY1_SETTING_MASK	0x4
362afbf43aSAbel Vesa 
372afbf43aSAbel Vesa #define qcom_ice_writel(engine, val, reg)	\
382afbf43aSAbel Vesa 	writel((val), (engine)->base + (reg))
392afbf43aSAbel Vesa 
402afbf43aSAbel Vesa #define qcom_ice_readl(engine, reg)	\
412afbf43aSAbel Vesa 	readl((engine)->base + (reg))
422afbf43aSAbel Vesa 
432afbf43aSAbel Vesa struct qcom_ice {
442afbf43aSAbel Vesa 	struct device *dev;
452afbf43aSAbel Vesa 	void __iomem *base;
462afbf43aSAbel Vesa 	struct device_link *link;
472afbf43aSAbel Vesa 
482afbf43aSAbel Vesa 	struct clk *core_clk;
492afbf43aSAbel Vesa };
502afbf43aSAbel Vesa 
qcom_ice_check_supported(struct qcom_ice * ice)512afbf43aSAbel Vesa static bool qcom_ice_check_supported(struct qcom_ice *ice)
522afbf43aSAbel Vesa {
532afbf43aSAbel Vesa 	u32 regval = qcom_ice_readl(ice, QCOM_ICE_REG_VERSION);
542afbf43aSAbel Vesa 	struct device *dev = ice->dev;
552afbf43aSAbel Vesa 	int major = FIELD_GET(GENMASK(31, 24), regval);
562afbf43aSAbel Vesa 	int minor = FIELD_GET(GENMASK(23, 16), regval);
572afbf43aSAbel Vesa 	int step = FIELD_GET(GENMASK(15, 0), regval);
582afbf43aSAbel Vesa 
592afbf43aSAbel Vesa 	/* For now this driver only supports ICE version 3 and 4. */
602afbf43aSAbel Vesa 	if (major != 3 && major != 4) {
612afbf43aSAbel Vesa 		dev_warn(dev, "Unsupported ICE version: v%d.%d.%d\n",
622afbf43aSAbel Vesa 			 major, minor, step);
632afbf43aSAbel Vesa 		return false;
642afbf43aSAbel Vesa 	}
652afbf43aSAbel Vesa 
662afbf43aSAbel Vesa 	dev_info(dev, "Found QC Inline Crypto Engine (ICE) v%d.%d.%d\n",
672afbf43aSAbel Vesa 		 major, minor, step);
682afbf43aSAbel Vesa 
692afbf43aSAbel Vesa 	/* If fuses are blown, ICE might not work in the standard way. */
702afbf43aSAbel Vesa 	regval = qcom_ice_readl(ice, QCOM_ICE_REG_FUSE_SETTING);
712afbf43aSAbel Vesa 	if (regval & (QCOM_ICE_FUSE_SETTING_MASK |
722afbf43aSAbel Vesa 		      QCOM_ICE_FORCE_HW_KEY0_SETTING_MASK |
732afbf43aSAbel Vesa 		      QCOM_ICE_FORCE_HW_KEY1_SETTING_MASK)) {
742afbf43aSAbel Vesa 		dev_warn(dev, "Fuses are blown; ICE is unusable!\n");
752afbf43aSAbel Vesa 		return false;
762afbf43aSAbel Vesa 	}
772afbf43aSAbel Vesa 
782afbf43aSAbel Vesa 	return true;
792afbf43aSAbel Vesa }
802afbf43aSAbel Vesa 
qcom_ice_low_power_mode_enable(struct qcom_ice * ice)812afbf43aSAbel Vesa static void qcom_ice_low_power_mode_enable(struct qcom_ice *ice)
822afbf43aSAbel Vesa {
832afbf43aSAbel Vesa 	u32 regval;
842afbf43aSAbel Vesa 
852afbf43aSAbel Vesa 	regval = qcom_ice_readl(ice, QCOM_ICE_REG_ADVANCED_CONTROL);
862afbf43aSAbel Vesa 
872afbf43aSAbel Vesa 	/* Enable low power mode sequence */
882afbf43aSAbel Vesa 	regval |= 0x7000;
892afbf43aSAbel Vesa 	qcom_ice_writel(ice, regval, QCOM_ICE_REG_ADVANCED_CONTROL);
902afbf43aSAbel Vesa }
912afbf43aSAbel Vesa 
qcom_ice_optimization_enable(struct qcom_ice * ice)922afbf43aSAbel Vesa static void qcom_ice_optimization_enable(struct qcom_ice *ice)
932afbf43aSAbel Vesa {
942afbf43aSAbel Vesa 	u32 regval;
952afbf43aSAbel Vesa 
962afbf43aSAbel Vesa 	/* ICE Optimizations Enable Sequence */
972afbf43aSAbel Vesa 	regval = qcom_ice_readl(ice, QCOM_ICE_REG_ADVANCED_CONTROL);
982afbf43aSAbel Vesa 	regval |= 0xd807100;
992afbf43aSAbel Vesa 	/* ICE HPG requires delay before writing */
1002afbf43aSAbel Vesa 	udelay(5);
1012afbf43aSAbel Vesa 	qcom_ice_writel(ice, regval, QCOM_ICE_REG_ADVANCED_CONTROL);
1022afbf43aSAbel Vesa 	udelay(5);
1032afbf43aSAbel Vesa }
1042afbf43aSAbel Vesa 
1052afbf43aSAbel Vesa /*
1062afbf43aSAbel Vesa  * Wait until the ICE BIST (built-in self-test) has completed.
1072afbf43aSAbel Vesa  *
1082afbf43aSAbel Vesa  * This may be necessary before ICE can be used.
1092afbf43aSAbel Vesa  * Note that we don't really care whether the BIST passed or failed;
1102afbf43aSAbel Vesa  * we really just want to make sure that it isn't still running. This is
1112afbf43aSAbel Vesa  * because (a) the BIST is a FIPS compliance thing that never fails in
1122afbf43aSAbel Vesa  * practice, (b) ICE is documented to reject crypto requests if the BIST
1132afbf43aSAbel Vesa  * fails, so we needn't do it in software too, and (c) properly testing
1142afbf43aSAbel Vesa  * storage encryption requires testing the full storage stack anyway,
1152afbf43aSAbel Vesa  * and not relying on hardware-level self-tests.
1162afbf43aSAbel Vesa  */
qcom_ice_wait_bist_status(struct qcom_ice * ice)1172afbf43aSAbel Vesa static int qcom_ice_wait_bist_status(struct qcom_ice *ice)
1182afbf43aSAbel Vesa {
1192afbf43aSAbel Vesa 	u32 regval;
1202afbf43aSAbel Vesa 	int err;
1212afbf43aSAbel Vesa 
1222afbf43aSAbel Vesa 	err = readl_poll_timeout(ice->base + QCOM_ICE_REG_BIST_STATUS,
1232afbf43aSAbel Vesa 				 regval, !(regval & QCOM_ICE_BIST_STATUS_MASK),
1242afbf43aSAbel Vesa 				 50, 5000);
1252afbf43aSAbel Vesa 	if (err)
1262afbf43aSAbel Vesa 		dev_err(ice->dev, "Timed out waiting for ICE self-test to complete\n");
1272afbf43aSAbel Vesa 
1282afbf43aSAbel Vesa 	return err;
1292afbf43aSAbel Vesa }
1302afbf43aSAbel Vesa 
qcom_ice_enable(struct qcom_ice * ice)1312afbf43aSAbel Vesa int qcom_ice_enable(struct qcom_ice *ice)
1322afbf43aSAbel Vesa {
1332afbf43aSAbel Vesa 	qcom_ice_low_power_mode_enable(ice);
1342afbf43aSAbel Vesa 	qcom_ice_optimization_enable(ice);
1352afbf43aSAbel Vesa 
1362afbf43aSAbel Vesa 	return qcom_ice_wait_bist_status(ice);
1372afbf43aSAbel Vesa }
1382afbf43aSAbel Vesa EXPORT_SYMBOL_GPL(qcom_ice_enable);
1392afbf43aSAbel Vesa 
qcom_ice_resume(struct qcom_ice * ice)1402afbf43aSAbel Vesa int qcom_ice_resume(struct qcom_ice *ice)
1412afbf43aSAbel Vesa {
1422afbf43aSAbel Vesa 	struct device *dev = ice->dev;
1432afbf43aSAbel Vesa 	int err;
1442afbf43aSAbel Vesa 
1452afbf43aSAbel Vesa 	err = clk_prepare_enable(ice->core_clk);
1462afbf43aSAbel Vesa 	if (err) {
1472afbf43aSAbel Vesa 		dev_err(dev, "failed to enable core clock (%d)\n",
1482afbf43aSAbel Vesa 			err);
1492afbf43aSAbel Vesa 		return err;
1502afbf43aSAbel Vesa 	}
1512afbf43aSAbel Vesa 
1522afbf43aSAbel Vesa 	return qcom_ice_wait_bist_status(ice);
1532afbf43aSAbel Vesa }
1542afbf43aSAbel Vesa EXPORT_SYMBOL_GPL(qcom_ice_resume);
1552afbf43aSAbel Vesa 
qcom_ice_suspend(struct qcom_ice * ice)1562afbf43aSAbel Vesa int qcom_ice_suspend(struct qcom_ice *ice)
1572afbf43aSAbel Vesa {
1582afbf43aSAbel Vesa 	clk_disable_unprepare(ice->core_clk);
1592afbf43aSAbel Vesa 
1602afbf43aSAbel Vesa 	return 0;
1612afbf43aSAbel Vesa }
1622afbf43aSAbel Vesa EXPORT_SYMBOL_GPL(qcom_ice_suspend);
1632afbf43aSAbel Vesa 
qcom_ice_program_key(struct qcom_ice * ice,u8 algorithm_id,u8 key_size,const u8 crypto_key[],u8 data_unit_size,int slot)1642afbf43aSAbel Vesa int qcom_ice_program_key(struct qcom_ice *ice,
1652afbf43aSAbel Vesa 			 u8 algorithm_id, u8 key_size,
1662afbf43aSAbel Vesa 			 const u8 crypto_key[], u8 data_unit_size,
1672afbf43aSAbel Vesa 			 int slot)
1682afbf43aSAbel Vesa {
1692afbf43aSAbel Vesa 	struct device *dev = ice->dev;
1702afbf43aSAbel Vesa 	union {
1712afbf43aSAbel Vesa 		u8 bytes[AES_256_XTS_KEY_SIZE];
1722afbf43aSAbel Vesa 		u32 words[AES_256_XTS_KEY_SIZE / sizeof(u32)];
1732afbf43aSAbel Vesa 	} key;
1742afbf43aSAbel Vesa 	int i;
1752afbf43aSAbel Vesa 	int err;
1762afbf43aSAbel Vesa 
1772afbf43aSAbel Vesa 	/* Only AES-256-XTS has been tested so far. */
1782afbf43aSAbel Vesa 	if (algorithm_id != QCOM_ICE_CRYPTO_ALG_AES_XTS ||
1792afbf43aSAbel Vesa 	    key_size != QCOM_ICE_CRYPTO_KEY_SIZE_256) {
1802afbf43aSAbel Vesa 		dev_err_ratelimited(dev,
1812afbf43aSAbel Vesa 				    "Unhandled crypto capability; algorithm_id=%d, key_size=%d\n",
1822afbf43aSAbel Vesa 				    algorithm_id, key_size);
1832afbf43aSAbel Vesa 		return -EINVAL;
1842afbf43aSAbel Vesa 	}
1852afbf43aSAbel Vesa 
1862afbf43aSAbel Vesa 	memcpy(key.bytes, crypto_key, AES_256_XTS_KEY_SIZE);
1872afbf43aSAbel Vesa 
1882afbf43aSAbel Vesa 	/* The SCM call requires that the key words are encoded in big endian */
1892afbf43aSAbel Vesa 	for (i = 0; i < ARRAY_SIZE(key.words); i++)
1902afbf43aSAbel Vesa 		__cpu_to_be32s(&key.words[i]);
1912afbf43aSAbel Vesa 
1922afbf43aSAbel Vesa 	err = qcom_scm_ice_set_key(slot, key.bytes, AES_256_XTS_KEY_SIZE,
1932afbf43aSAbel Vesa 				   QCOM_SCM_ICE_CIPHER_AES_256_XTS,
1942afbf43aSAbel Vesa 				   data_unit_size);
1952afbf43aSAbel Vesa 
1962afbf43aSAbel Vesa 	memzero_explicit(&key, sizeof(key));
1972afbf43aSAbel Vesa 
1982afbf43aSAbel Vesa 	return err;
1992afbf43aSAbel Vesa }
2002afbf43aSAbel Vesa EXPORT_SYMBOL_GPL(qcom_ice_program_key);
2012afbf43aSAbel Vesa 
qcom_ice_evict_key(struct qcom_ice * ice,int slot)2022afbf43aSAbel Vesa int qcom_ice_evict_key(struct qcom_ice *ice, int slot)
2032afbf43aSAbel Vesa {
2042afbf43aSAbel Vesa 	return qcom_scm_ice_invalidate_key(slot);
2052afbf43aSAbel Vesa }
2062afbf43aSAbel Vesa EXPORT_SYMBOL_GPL(qcom_ice_evict_key);
2072afbf43aSAbel Vesa 
qcom_ice_create(struct device * dev,void __iomem * base)2082afbf43aSAbel Vesa static struct qcom_ice *qcom_ice_create(struct device *dev,
2092afbf43aSAbel Vesa 					void __iomem *base)
2102afbf43aSAbel Vesa {
2112afbf43aSAbel Vesa 	struct qcom_ice *engine;
2122afbf43aSAbel Vesa 
2132afbf43aSAbel Vesa 	if (!qcom_scm_is_available())
2142afbf43aSAbel Vesa 		return ERR_PTR(-EPROBE_DEFER);
2152afbf43aSAbel Vesa 
2162afbf43aSAbel Vesa 	if (!qcom_scm_ice_available()) {
2172afbf43aSAbel Vesa 		dev_warn(dev, "ICE SCM interface not found\n");
2182afbf43aSAbel Vesa 		return NULL;
2192afbf43aSAbel Vesa 	}
2202afbf43aSAbel Vesa 
2212afbf43aSAbel Vesa 	engine = devm_kzalloc(dev, sizeof(*engine), GFP_KERNEL);
2222afbf43aSAbel Vesa 	if (!engine)
2232afbf43aSAbel Vesa 		return ERR_PTR(-ENOMEM);
2242afbf43aSAbel Vesa 
2252afbf43aSAbel Vesa 	engine->dev = dev;
2262afbf43aSAbel Vesa 	engine->base = base;
2272afbf43aSAbel Vesa 
2282afbf43aSAbel Vesa 	/*
2292afbf43aSAbel Vesa 	 * Legacy DT binding uses different clk names for each consumer,
2302afbf43aSAbel Vesa 	 * so lets try those first. If none of those are a match, it means
2312afbf43aSAbel Vesa 	 * the we only have one clock and it is part of the dedicated DT node.
2322afbf43aSAbel Vesa 	 * Also, enable the clock before we check what HW version the driver
2332afbf43aSAbel Vesa 	 * supports.
2342afbf43aSAbel Vesa 	 */
2352afbf43aSAbel Vesa 	engine->core_clk = devm_clk_get_optional_enabled(dev, "ice_core_clk");
2362afbf43aSAbel Vesa 	if (!engine->core_clk)
2372afbf43aSAbel Vesa 		engine->core_clk = devm_clk_get_optional_enabled(dev, "ice");
2382afbf43aSAbel Vesa 	if (!engine->core_clk)
2392afbf43aSAbel Vesa 		engine->core_clk = devm_clk_get_enabled(dev, NULL);
2402afbf43aSAbel Vesa 	if (IS_ERR(engine->core_clk))
2412afbf43aSAbel Vesa 		return ERR_CAST(engine->core_clk);
2422afbf43aSAbel Vesa 
2432afbf43aSAbel Vesa 	if (!qcom_ice_check_supported(engine))
2442afbf43aSAbel Vesa 		return ERR_PTR(-EOPNOTSUPP);
2452afbf43aSAbel Vesa 
2462afbf43aSAbel Vesa 	dev_dbg(dev, "Registered Qualcomm Inline Crypto Engine\n");
2472afbf43aSAbel Vesa 
2482afbf43aSAbel Vesa 	return engine;
2492afbf43aSAbel Vesa }
2502afbf43aSAbel Vesa 
2512afbf43aSAbel Vesa /**
2522afbf43aSAbel Vesa  * of_qcom_ice_get() - get an ICE instance from a DT node
2532afbf43aSAbel Vesa  * @dev: device pointer for the consumer device
2542afbf43aSAbel Vesa  *
2552afbf43aSAbel Vesa  * This function will provide an ICE instance either by creating one for the
2562afbf43aSAbel Vesa  * consumer device if its DT node provides the 'ice' reg range and the 'ice'
2572afbf43aSAbel Vesa  * clock (for legacy DT style). On the other hand, if consumer provides a
2582afbf43aSAbel Vesa  * phandle via 'qcom,ice' property to an ICE DT, the ICE instance will already
2592afbf43aSAbel Vesa  * be created and so this function will return that instead.
2602afbf43aSAbel Vesa  *
2612afbf43aSAbel Vesa  * Return: ICE pointer on success, NULL if there is no ICE data provided by the
2622afbf43aSAbel Vesa  * consumer or ERR_PTR() on error.
2632afbf43aSAbel Vesa  */
of_qcom_ice_get(struct device * dev)2642afbf43aSAbel Vesa struct qcom_ice *of_qcom_ice_get(struct device *dev)
2652afbf43aSAbel Vesa {
2662afbf43aSAbel Vesa 	struct platform_device *pdev = to_platform_device(dev);
2672afbf43aSAbel Vesa 	struct qcom_ice *ice;
2682afbf43aSAbel Vesa 	struct device_node *node;
2692afbf43aSAbel Vesa 	struct resource *res;
2702afbf43aSAbel Vesa 	void __iomem *base;
2712afbf43aSAbel Vesa 
2722afbf43aSAbel Vesa 	if (!dev || !dev->of_node)
2732afbf43aSAbel Vesa 		return ERR_PTR(-ENODEV);
2742afbf43aSAbel Vesa 
2752afbf43aSAbel Vesa 	/*
2762afbf43aSAbel Vesa 	 * In order to support legacy style devicetree bindings, we need
2772afbf43aSAbel Vesa 	 * to create the ICE instance using the consumer device and the reg
2782afbf43aSAbel Vesa 	 * range called 'ice' it provides.
2792afbf43aSAbel Vesa 	 */
2802afbf43aSAbel Vesa 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ice");
2812afbf43aSAbel Vesa 	if (res) {
2822afbf43aSAbel Vesa 		base = devm_ioremap_resource(&pdev->dev, res);
2832afbf43aSAbel Vesa 		if (IS_ERR(base))
2842afbf43aSAbel Vesa 			return ERR_CAST(base);
2852afbf43aSAbel Vesa 
2862afbf43aSAbel Vesa 		/* create ICE instance using consumer dev */
2872afbf43aSAbel Vesa 		return qcom_ice_create(&pdev->dev, base);
2882afbf43aSAbel Vesa 	}
2892afbf43aSAbel Vesa 
2902afbf43aSAbel Vesa 	/*
2912afbf43aSAbel Vesa 	 * If the consumer node does not provider an 'ice' reg range
2922afbf43aSAbel Vesa 	 * (legacy DT binding), then it must at least provide a phandle
2932afbf43aSAbel Vesa 	 * to the ICE devicetree node, otherwise ICE is not supported.
2942afbf43aSAbel Vesa 	 */
2952afbf43aSAbel Vesa 	node = of_parse_phandle(dev->of_node, "qcom,ice", 0);
2962afbf43aSAbel Vesa 	if (!node)
2972afbf43aSAbel Vesa 		return NULL;
2982afbf43aSAbel Vesa 
2992afbf43aSAbel Vesa 	pdev = of_find_device_by_node(node);
3002afbf43aSAbel Vesa 	if (!pdev) {
3012afbf43aSAbel Vesa 		dev_err(dev, "Cannot find device node %s\n", node->name);
3022afbf43aSAbel Vesa 		ice = ERR_PTR(-EPROBE_DEFER);
3032afbf43aSAbel Vesa 		goto out;
3042afbf43aSAbel Vesa 	}
3052afbf43aSAbel Vesa 
3062afbf43aSAbel Vesa 	ice = platform_get_drvdata(pdev);
3072afbf43aSAbel Vesa 	if (!ice) {
3082afbf43aSAbel Vesa 		dev_err(dev, "Cannot get ice instance from %s\n",
3092afbf43aSAbel Vesa 			dev_name(&pdev->dev));
3102afbf43aSAbel Vesa 		platform_device_put(pdev);
3112afbf43aSAbel Vesa 		ice = ERR_PTR(-EPROBE_DEFER);
3122afbf43aSAbel Vesa 		goto out;
3132afbf43aSAbel Vesa 	}
3142afbf43aSAbel Vesa 
3152afbf43aSAbel Vesa 	ice->link = device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER);
3162afbf43aSAbel Vesa 	if (!ice->link) {
3172afbf43aSAbel Vesa 		dev_err(&pdev->dev,
3182afbf43aSAbel Vesa 			"Failed to create device link to consumer %s\n",
3192afbf43aSAbel Vesa 			dev_name(dev));
3202afbf43aSAbel Vesa 		platform_device_put(pdev);
3212afbf43aSAbel Vesa 		ice = ERR_PTR(-EINVAL);
3222afbf43aSAbel Vesa 	}
3232afbf43aSAbel Vesa 
3242afbf43aSAbel Vesa out:
3252afbf43aSAbel Vesa 	of_node_put(node);
3262afbf43aSAbel Vesa 
3272afbf43aSAbel Vesa 	return ice;
3282afbf43aSAbel Vesa }
3292afbf43aSAbel Vesa EXPORT_SYMBOL_GPL(of_qcom_ice_get);
3302afbf43aSAbel Vesa 
qcom_ice_probe(struct platform_device * pdev)3312afbf43aSAbel Vesa static int qcom_ice_probe(struct platform_device *pdev)
3322afbf43aSAbel Vesa {
3332afbf43aSAbel Vesa 	struct qcom_ice *engine;
3342afbf43aSAbel Vesa 	void __iomem *base;
3352afbf43aSAbel Vesa 
3362afbf43aSAbel Vesa 	base = devm_platform_ioremap_resource(pdev, 0);
3372afbf43aSAbel Vesa 	if (IS_ERR(base)) {
3382afbf43aSAbel Vesa 		dev_warn(&pdev->dev, "ICE registers not found\n");
3392afbf43aSAbel Vesa 		return PTR_ERR(base);
3402afbf43aSAbel Vesa 	}
3412afbf43aSAbel Vesa 
3422afbf43aSAbel Vesa 	engine = qcom_ice_create(&pdev->dev, base);
3432afbf43aSAbel Vesa 	if (IS_ERR(engine))
3442afbf43aSAbel Vesa 		return PTR_ERR(engine);
3452afbf43aSAbel Vesa 
3462afbf43aSAbel Vesa 	platform_set_drvdata(pdev, engine);
3472afbf43aSAbel Vesa 
3482afbf43aSAbel Vesa 	return 0;
3492afbf43aSAbel Vesa }
3502afbf43aSAbel Vesa 
3512afbf43aSAbel Vesa static const struct of_device_id qcom_ice_of_match_table[] = {
3522afbf43aSAbel Vesa 	{ .compatible = "qcom,inline-crypto-engine" },
3532afbf43aSAbel Vesa 	{ },
3542afbf43aSAbel Vesa };
3552afbf43aSAbel Vesa MODULE_DEVICE_TABLE(of, qcom_ice_of_match_table);
3562afbf43aSAbel Vesa 
3572afbf43aSAbel Vesa static struct platform_driver qcom_ice_driver = {
3582afbf43aSAbel Vesa 	.probe	= qcom_ice_probe,
3592afbf43aSAbel Vesa 	.driver = {
3602afbf43aSAbel Vesa 		.name = "qcom-ice",
3612afbf43aSAbel Vesa 		.of_match_table = qcom_ice_of_match_table,
3622afbf43aSAbel Vesa 	},
3632afbf43aSAbel Vesa };
3642afbf43aSAbel Vesa 
3652afbf43aSAbel Vesa module_platform_driver(qcom_ice_driver);
3662afbf43aSAbel Vesa 
3672afbf43aSAbel Vesa MODULE_DESCRIPTION("Qualcomm Inline Crypto Engine driver");
3682afbf43aSAbel Vesa MODULE_LICENSE("GPL");
369