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