2 * Copyright (C) 2017 Linaro Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include <linux/dma-mapping.h>
16 #include <linux/firmware.h>
17 #include <linux/kernel.h>
19 #include <linux/of_reserved_mem.h>
20 #include <linux/slab.h>
21 #include <linux/qcom_scm.h>
22 #include <linux/soc/qcom/mdt_loader.h>
26 #define VENUS_PAS_ID 9
27 #define VENUS_FW_MEM_SIZE SZ_8M
29 static void device_release_dummy(struct device *dev)
31 of_reserved_mem_device_release(dev);
34 int venus_boot(struct device *parent, struct device *fw_dev, const char *fwname)
36 const struct firmware *mdt;
43 if (!qcom_scm_is_available())
46 fw_dev->parent = parent;
47 fw_dev->release = device_release_dummy;
49 ret = dev_set_name(fw_dev, "%s:%s", dev_name(parent), "firmware");
53 ret = device_register(fw_dev);
57 ret = of_reserved_mem_device_init_by_idx(fw_dev, parent->of_node, 0);
59 goto err_unreg_device;
61 mem_size = VENUS_FW_MEM_SIZE;
63 mem_va = dmam_alloc_coherent(fw_dev, mem_size, &mem_phys, GFP_KERNEL);
66 goto err_unreg_device;
69 ret = request_firmware(&mdt, fwname, fw_dev);
71 goto err_unreg_device;
73 fw_size = qcom_mdt_get_size(mdt);
76 release_firmware(mdt);
77 goto err_unreg_device;
80 ret = qcom_mdt_load(fw_dev, mdt, fwname, VENUS_PAS_ID, mem_va, mem_phys,
83 release_firmware(mdt);
86 goto err_unreg_device;
88 ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID);
90 goto err_unreg_device;
95 device_unregister(fw_dev);
99 int venus_shutdown(struct device *fw_dev)
103 ret = qcom_scm_pas_shutdown(VENUS_PAS_ID);
104 device_unregister(fw_dev);
105 memset(fw_dev, 0, sizeof(*fw_dev));