blob: 1410117db948e6728df6adaadc3f149008431170 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
Stephen Boydd89eebe2011-09-28 23:28:11 -07002 *
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>
Stephen Boydd89eebe2011-09-28 23:28:11 -070016#include <linux/err.h>
17
Stephen Boyd046013f2012-06-28 20:24:17 -070018#include <mach/subsystem_restart.h>
19
Stephen Boydd89eebe2011-09-28 23:28:11 -070020#include "peripheral-loader.h"
21#include "scm-pas.h"
22
Stephen Boyd046013f2012-06-28 20:24:17 -070023struct tzapps_data {
Stephen Boyde83a0a22012-06-29 13:51:27 -070024 struct pil_desc pil_desc;
Stephen Boyd046013f2012-06-28 20:24:17 -070025 struct subsys_device *subsys;
26 struct subsys_desc subsys_desc;
27};
28
Stephen Boydd89eebe2011-09-28 23:28:11 -070029static int pil_tzapps_init_image(struct pil_desc *pil, const u8 *metadata,
30 size_t size)
31{
32 return pas_init_image(PAS_TZAPPS, metadata, size);
33}
34
35static int pil_tzapps_reset(struct pil_desc *pil)
36{
37 return pas_auth_and_reset(PAS_TZAPPS);
38}
39
40static int pil_tzapps_shutdown(struct pil_desc *pil)
41{
42 return pas_shutdown(PAS_TZAPPS);
43}
44
45static struct pil_reset_ops pil_tzapps_ops = {
46 .init_image = pil_tzapps_init_image,
Stephen Boydd89eebe2011-09-28 23:28:11 -070047 .auth_and_reset = pil_tzapps_reset,
48 .shutdown = pil_tzapps_shutdown,
49};
50
Stephen Boyd046013f2012-06-28 20:24:17 -070051#define subsys_to_drv(d) container_of(d, struct tzapps_data, subsys_desc)
52
53static int tzapps_start(const struct subsys_desc *desc)
54{
Stephen Boyde83a0a22012-06-29 13:51:27 -070055 struct tzapps_data *drv = subsys_to_drv(desc);
Stephen Boyd046013f2012-06-28 20:24:17 -070056
Stephen Boyde83a0a22012-06-29 13:51:27 -070057 return pil_boot(&drv->pil_desc);
Stephen Boyd046013f2012-06-28 20:24:17 -070058}
59
60static void tzapps_stop(const struct subsys_desc *desc)
61{
62 struct tzapps_data *drv = subsys_to_drv(desc);
Stephen Boyde83a0a22012-06-29 13:51:27 -070063 pil_shutdown(&drv->pil_desc);
Stephen Boyd046013f2012-06-28 20:24:17 -070064}
65
Stephen Boydd89eebe2011-09-28 23:28:11 -070066static int __devinit pil_tzapps_driver_probe(struct platform_device *pdev)
67{
68 struct pil_desc *desc;
Stephen Boyd046013f2012-06-28 20:24:17 -070069 struct tzapps_data *drv;
Stephen Boyde83a0a22012-06-29 13:51:27 -070070 int ret;
Stephen Boydd89eebe2011-09-28 23:28:11 -070071
72 if (pas_supported(PAS_TZAPPS) < 0)
73 return -ENOSYS;
74
Stephen Boyd046013f2012-06-28 20:24:17 -070075 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
76 if (!drv)
77 return -ENOMEM;
78 platform_set_drvdata(pdev, drv);
79
Stephen Boyde83a0a22012-06-29 13:51:27 -070080 desc = &drv->pil_desc;
Stephen Boydd89eebe2011-09-28 23:28:11 -070081 desc->name = "tzapps";
82 desc->dev = &pdev->dev;
83 desc->ops = &pil_tzapps_ops;
Stephen Boyd6d67d252011-09-27 11:50:05 -070084 desc->owner = THIS_MODULE;
Stephen Boyde83a0a22012-06-29 13:51:27 -070085 ret = pil_desc_init(desc);
86 if (ret)
87 return ret;
Stephen Boyd046013f2012-06-28 20:24:17 -070088
89 drv->subsys_desc.name = "tzapps";
90 drv->subsys_desc.dev = &pdev->dev;
91 drv->subsys_desc.owner = THIS_MODULE;
92 drv->subsys_desc.start = tzapps_start;
93 drv->subsys_desc.stop = tzapps_stop;
94
95 drv->subsys = subsys_register(&drv->subsys_desc);
96 if (IS_ERR(drv->subsys)) {
Stephen Boyde83a0a22012-06-29 13:51:27 -070097 pil_desc_release(desc);
Stephen Boyd046013f2012-06-28 20:24:17 -070098 return PTR_ERR(drv->subsys);
99 }
Stephen Boydd89eebe2011-09-28 23:28:11 -0700100 return 0;
101}
102
103static int __devexit pil_tzapps_driver_exit(struct platform_device *pdev)
104{
Stephen Boyd046013f2012-06-28 20:24:17 -0700105 struct tzapps_data *drv = platform_get_drvdata(pdev);
106 subsys_unregister(drv->subsys);
Stephen Boyde83a0a22012-06-29 13:51:27 -0700107 pil_desc_release(&drv->pil_desc);
Stephen Boydd89eebe2011-09-28 23:28:11 -0700108 return 0;
109}
110
111static struct platform_driver pil_tzapps_driver = {
112 .probe = pil_tzapps_driver_probe,
113 .remove = __devexit_p(pil_tzapps_driver_exit),
114 .driver = {
115 .name = "pil_tzapps",
116 .owner = THIS_MODULE,
117 },
118};
119
120static int __init pil_tzapps_init(void)
121{
122 return platform_driver_register(&pil_tzapps_driver);
123}
124module_init(pil_tzapps_init);
125
126static void __exit pil_tzapps_exit(void)
127{
128 platform_driver_unregister(&pil_tzapps_driver);
129}
130module_exit(pil_tzapps_exit);
131
132MODULE_DESCRIPTION("Support for booting TZApps images");
133MODULE_LICENSE("GPL v2");