Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/elf.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/clk.h> |
| 19 | |
| 20 | #include "peripheral-loader.h" |
| 21 | #include "scm-pas.h" |
| 22 | |
| 23 | struct vidc_data { |
| 24 | struct clk *smmu_iface; |
| 25 | struct clk *core; |
| 26 | struct pil_device *pil; |
| 27 | }; |
| 28 | |
| 29 | static int pil_vidc_init_image(struct pil_desc *pil, const u8 *metadata, |
| 30 | size_t size) |
| 31 | { |
| 32 | return pas_init_image(PAS_VIDC, metadata, size); |
| 33 | } |
| 34 | |
| 35 | static int pil_vidc_reset(struct pil_desc *pil) |
| 36 | { |
| 37 | int ret; |
| 38 | struct vidc_data *drv = dev_get_drvdata(pil->dev); |
| 39 | |
| 40 | ret = clk_prepare_enable(drv->smmu_iface); |
| 41 | if (ret) |
| 42 | goto err_smmu; |
| 43 | ret = clk_prepare_enable(drv->core); |
| 44 | if (ret) |
| 45 | goto err_core; |
| 46 | ret = pas_auth_and_reset(PAS_VIDC); |
| 47 | |
| 48 | clk_disable_unprepare(drv->core); |
| 49 | err_core: |
| 50 | clk_disable_unprepare(drv->smmu_iface); |
| 51 | err_smmu: |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | static int pil_vidc_shutdown(struct pil_desc *pil) |
| 56 | { |
| 57 | return pas_shutdown(PAS_VIDC); |
| 58 | } |
| 59 | |
| 60 | static struct pil_reset_ops pil_vidc_ops = { |
| 61 | .init_image = pil_vidc_init_image, |
| 62 | .auth_and_reset = pil_vidc_reset, |
| 63 | .shutdown = pil_vidc_shutdown, |
| 64 | }; |
| 65 | |
| 66 | static int __devinit pil_vidc_driver_probe(struct platform_device *pdev) |
| 67 | { |
| 68 | struct pil_desc *desc; |
| 69 | struct vidc_data *drv; |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 70 | |
| 71 | if (pas_supported(PAS_VIDC) < 0) |
| 72 | return -ENOSYS; |
| 73 | |
| 74 | desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); |
| 75 | if (!desc) |
| 76 | return -ENOMEM; |
| 77 | |
| 78 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 79 | if (!drv) |
| 80 | return -ENOMEM; |
| 81 | platform_set_drvdata(pdev, drv); |
Stephen Boyd | 46e51b5 | 2012-06-27 13:29:47 -0700 | [diff] [blame] | 82 | |
| 83 | drv->smmu_iface = devm_clk_get(&pdev->dev, "smmu_iface_clk"); |
| 84 | if (IS_ERR(drv->smmu_iface)) |
| 85 | return PTR_ERR(drv->smmu_iface); |
| 86 | |
| 87 | drv->core = devm_clk_get(&pdev->dev, "core_clk"); |
| 88 | if (IS_ERR(drv->core)) |
| 89 | return PTR_ERR(drv->core); |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 90 | |
| 91 | desc->name = "vidc"; |
| 92 | desc->dev = &pdev->dev; |
| 93 | desc->ops = &pil_vidc_ops; |
| 94 | desc->owner = THIS_MODULE; |
| 95 | drv->pil = msm_pil_register(desc); |
Stephen Boyd | 46e51b5 | 2012-06-27 13:29:47 -0700 | [diff] [blame] | 96 | if (IS_ERR(drv->pil)) |
| 97 | return PTR_ERR(drv->pil); |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 98 | return 0; |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static int __devexit pil_vidc_driver_exit(struct platform_device *pdev) |
| 102 | { |
| 103 | struct vidc_data *drv = platform_get_drvdata(pdev); |
| 104 | msm_pil_unregister(drv->pil); |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static struct platform_driver pil_vidc_driver = { |
| 109 | .probe = pil_vidc_driver_probe, |
| 110 | .remove = __devexit_p(pil_vidc_driver_exit), |
| 111 | .driver = { |
| 112 | .name = "pil_vidc", |
| 113 | .owner = THIS_MODULE, |
| 114 | }, |
| 115 | }; |
| 116 | |
| 117 | static int __init pil_vidc_init(void) |
| 118 | { |
| 119 | return platform_driver_register(&pil_vidc_driver); |
| 120 | } |
| 121 | module_init(pil_vidc_init); |
| 122 | |
| 123 | static void __exit pil_vidc_exit(void) |
| 124 | { |
| 125 | platform_driver_unregister(&pil_vidc_driver); |
| 126 | } |
| 127 | module_exit(pil_vidc_exit); |
| 128 | |
| 129 | MODULE_DESCRIPTION("Support for secure booting vidc images"); |
| 130 | MODULE_LICENSE("GPL v2"); |