blob: ceb9bcd2969d2db5a5f2266042d5820a1d7e368c [file] [log] [blame]
Stephen Boyd7b973de2012-03-09 12:26:16 -08001/* 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
23struct vidc_data {
24 struct clk *smmu_iface;
25 struct clk *core;
26 struct pil_device *pil;
27};
28
29static 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
35static 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);
49err_core:
50 clk_disable_unprepare(drv->smmu_iface);
51err_smmu:
52 return ret;
53}
54
55static int pil_vidc_shutdown(struct pil_desc *pil)
56{
57 return pas_shutdown(PAS_VIDC);
58}
59
60static 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
66static int __devinit pil_vidc_driver_probe(struct platform_device *pdev)
67{
68 struct pil_desc *desc;
69 struct vidc_data *drv;
70 int ret;
71
72 if (pas_supported(PAS_VIDC) < 0)
73 return -ENOSYS;
74
75 desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
76 if (!desc)
77 return -ENOMEM;
78
79 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
80 if (!drv)
81 return -ENOMEM;
82 platform_set_drvdata(pdev, drv);
83 drv->smmu_iface = clk_get(&pdev->dev, "smmu_iface_clk");
84 if (IS_ERR(drv->smmu_iface)) {
85 dev_err(&pdev->dev, "failed to get smmu interface clock\n");
86 ret = PTR_ERR(drv->smmu_iface);
87 goto err_smmu;
88 }
89 drv->core = clk_get(&pdev->dev, "core_clk");
90 if (IS_ERR(drv->core)) {
91 dev_err(&pdev->dev, "failed to get core clock\n");
92 ret = PTR_ERR(drv->core);
93 goto err_core;
94 }
95
96 desc->name = "vidc";
97 desc->dev = &pdev->dev;
98 desc->ops = &pil_vidc_ops;
99 desc->owner = THIS_MODULE;
100 drv->pil = msm_pil_register(desc);
101 if (IS_ERR(drv->pil)) {
102 ret = PTR_ERR(drv->pil);
103 goto err_register;
104 }
105 return 0;
106
107err_register:
108 clk_put(drv->core);
109err_core:
110 clk_put(drv->smmu_iface);
111err_smmu:
112 return ret;
113}
114
115static int __devexit pil_vidc_driver_exit(struct platform_device *pdev)
116{
117 struct vidc_data *drv = platform_get_drvdata(pdev);
118 msm_pil_unregister(drv->pil);
119 clk_put(drv->smmu_iface);
120 clk_put(drv->core);
121 return 0;
122}
123
124static struct platform_driver pil_vidc_driver = {
125 .probe = pil_vidc_driver_probe,
126 .remove = __devexit_p(pil_vidc_driver_exit),
127 .driver = {
128 .name = "pil_vidc",
129 .owner = THIS_MODULE,
130 },
131};
132
133static int __init pil_vidc_init(void)
134{
135 return platform_driver_register(&pil_vidc_driver);
136}
137module_init(pil_vidc_init);
138
139static void __exit pil_vidc_exit(void)
140{
141 platform_driver_unregister(&pil_vidc_driver);
142}
143module_exit(pil_vidc_exit);
144
145MODULE_DESCRIPTION("Support for secure booting vidc images");
146MODULE_LICENSE("GPL v2");