blob: 9924b52326dccd9d86861406f866d62135d76446 [file] [log] [blame]
Joonwoo Park4a14a552012-08-02 11:03:21 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/err.h>
18#include <linux/delay.h>
19#include <linux/platform_device.h>
20#include <mach/peripheral-loader.h>
21#include <mach/qdsp6v2/apr.h>
22
23#define Q6_PIL_GET_DELAY_MS 100
24
25struct adsp_loader_private {
26 void *pil_h;
27};
28
29static int adsp_loader_probe(struct platform_device *pdev)
30{
31 struct adsp_loader_private *priv;
32 int rc = 0;
33
34 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
35 if (!priv)
36 return -ENOMEM;
37
38 platform_set_drvdata(pdev, priv);
39
40 priv->pil_h = pil_get("adsp");
41 if (IS_ERR(priv->pil_h)) {
42 pr_err("%s: pil get adsp failed, error:%d\n", __func__, rc);
43 devm_kfree(&pdev->dev, priv);
44 goto fail;
45 }
46
47 /* Query the DSP to check if resources are available */
48 msleep(Q6_PIL_GET_DELAY_MS);
49
50 /* Set the state of the ADSP in APR driver */
51 apr_set_q6_state(APR_SUBSYS_LOADED);
52
53 /* Query for MMPM API */
54
55 pr_info("%s: Q6/ADSP image is loaded\n", __func__);
56fail:
57 return rc;
58}
59
60static int adsp_loader_remove(struct platform_device *pdev)
61{
62 struct adsp_loader_private *priv;
63
64 priv = platform_get_drvdata(pdev);
65 pil_put(priv->pil_h);
66 pr_info("%s: Q6/ADSP image is unloaded\n", __func__);
67
68 return 0;
69}
70
71static const struct of_device_id adsp_loader_dt_match[] = {
72 { .compatible = "qcom,adsp-loader" },
73 { }
74};
75MODULE_DEVICE_TABLE(of, adsp_loader_dt_match);
76
77static struct platform_driver adsp_loader_driver = {
78 .driver = {
79 .name = "adsp-loader",
80 .owner = THIS_MODULE,
81 .of_match_table = adsp_loader_dt_match,
82 },
83 .probe = adsp_loader_probe,
84 .remove = __devexit_p(adsp_loader_remove),
85};
86
87static int __init adsp_loader_init(void)
88{
89 return platform_driver_register(&adsp_loader_driver);
90}
91module_init(adsp_loader_init);
92
93static void __exit adsp_loader_exit(void)
94{
95 platform_driver_unregister(&adsp_loader_driver);
96}
97module_exit(adsp_loader_exit);
98
99MODULE_DESCRIPTION("ADSP Loader module");
100MODULE_LICENSE("GPL v2");