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 | |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 20 | #include <mach/subsystem_restart.h> |
| 21 | |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 22 | #include "peripheral-loader.h" |
| 23 | #include "scm-pas.h" |
| 24 | |
| 25 | struct vidc_data { |
| 26 | struct clk *smmu_iface; |
| 27 | struct clk *core; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 28 | struct pil_desc pil_desc; |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 29 | struct subsys_device *subsys; |
| 30 | struct subsys_desc subsys_desc; |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | static int pil_vidc_init_image(struct pil_desc *pil, const u8 *metadata, |
| 34 | size_t size) |
| 35 | { |
| 36 | return pas_init_image(PAS_VIDC, metadata, size); |
| 37 | } |
| 38 | |
| 39 | static int pil_vidc_reset(struct pil_desc *pil) |
| 40 | { |
| 41 | int ret; |
| 42 | struct vidc_data *drv = dev_get_drvdata(pil->dev); |
| 43 | |
| 44 | ret = clk_prepare_enable(drv->smmu_iface); |
| 45 | if (ret) |
| 46 | goto err_smmu; |
| 47 | ret = clk_prepare_enable(drv->core); |
| 48 | if (ret) |
| 49 | goto err_core; |
| 50 | ret = pas_auth_and_reset(PAS_VIDC); |
| 51 | |
| 52 | clk_disable_unprepare(drv->core); |
| 53 | err_core: |
| 54 | clk_disable_unprepare(drv->smmu_iface); |
| 55 | err_smmu: |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | static int pil_vidc_shutdown(struct pil_desc *pil) |
| 60 | { |
| 61 | return pas_shutdown(PAS_VIDC); |
| 62 | } |
| 63 | |
| 64 | static struct pil_reset_ops pil_vidc_ops = { |
| 65 | .init_image = pil_vidc_init_image, |
| 66 | .auth_and_reset = pil_vidc_reset, |
| 67 | .shutdown = pil_vidc_shutdown, |
| 68 | }; |
| 69 | |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 70 | #define subsys_to_drv(d) container_of(d, struct vidc_data, subsys_desc) |
| 71 | |
| 72 | static int vidc_start(const struct subsys_desc *desc) |
| 73 | { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 74 | struct vidc_data *drv = subsys_to_drv(desc); |
| 75 | return pil_boot(&drv->pil_desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static void vidc_stop(const struct subsys_desc *desc) |
| 79 | { |
| 80 | struct vidc_data *drv = subsys_to_drv(desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 81 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 84 | static int __devinit pil_vidc_driver_probe(struct platform_device *pdev) |
| 85 | { |
| 86 | struct pil_desc *desc; |
| 87 | struct vidc_data *drv; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 88 | int ret; |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 89 | |
| 90 | if (pas_supported(PAS_VIDC) < 0) |
| 91 | return -ENOSYS; |
| 92 | |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 93 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 94 | if (!drv) |
| 95 | return -ENOMEM; |
| 96 | platform_set_drvdata(pdev, drv); |
Stephen Boyd | 46e51b5 | 2012-06-27 13:29:47 -0700 | [diff] [blame] | 97 | |
| 98 | drv->smmu_iface = devm_clk_get(&pdev->dev, "smmu_iface_clk"); |
| 99 | if (IS_ERR(drv->smmu_iface)) |
| 100 | return PTR_ERR(drv->smmu_iface); |
| 101 | |
| 102 | drv->core = devm_clk_get(&pdev->dev, "core_clk"); |
| 103 | if (IS_ERR(drv->core)) |
| 104 | return PTR_ERR(drv->core); |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 105 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 106 | desc = &drv->pil_desc; |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 107 | desc->name = "vidc"; |
| 108 | desc->dev = &pdev->dev; |
| 109 | desc->ops = &pil_vidc_ops; |
| 110 | desc->owner = THIS_MODULE; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 111 | ret = pil_desc_init(desc); |
| 112 | if (ret) |
| 113 | return ret; |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 114 | |
| 115 | drv->subsys_desc.name = "vidc"; |
| 116 | drv->subsys_desc.dev = &pdev->dev; |
| 117 | drv->subsys_desc.owner = THIS_MODULE; |
| 118 | drv->subsys_desc.start = vidc_start; |
| 119 | drv->subsys_desc.stop = vidc_stop; |
| 120 | |
| 121 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 122 | if (IS_ERR(drv->subsys)) { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 123 | pil_desc_release(desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 124 | return PTR_ERR(drv->subsys); |
| 125 | } |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 126 | return 0; |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static int __devexit pil_vidc_driver_exit(struct platform_device *pdev) |
| 130 | { |
| 131 | struct vidc_data *drv = platform_get_drvdata(pdev); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 132 | subsys_unregister(drv->subsys); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame^] | 133 | pil_desc_release(&drv->pil_desc); |
Stephen Boyd | 7b973de | 2012-03-09 12:26:16 -0800 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static struct platform_driver pil_vidc_driver = { |
| 138 | .probe = pil_vidc_driver_probe, |
| 139 | .remove = __devexit_p(pil_vidc_driver_exit), |
| 140 | .driver = { |
| 141 | .name = "pil_vidc", |
| 142 | .owner = THIS_MODULE, |
| 143 | }, |
| 144 | }; |
| 145 | |
| 146 | static int __init pil_vidc_init(void) |
| 147 | { |
| 148 | return platform_driver_register(&pil_vidc_driver); |
| 149 | } |
| 150 | module_init(pil_vidc_init); |
| 151 | |
| 152 | static void __exit pil_vidc_exit(void) |
| 153 | { |
| 154 | platform_driver_unregister(&pil_vidc_driver); |
| 155 | } |
| 156 | module_exit(pil_vidc_exit); |
| 157 | |
| 158 | MODULE_DESCRIPTION("Support for secure booting vidc images"); |
| 159 | MODULE_LICENSE("GPL v2"); |