blob: eba11283bea375640d2307f0a1ec9dc074d01530 [file] [log] [blame]
Lingutla Chandrasekharbe48b072017-09-25 19:07:12 +05301/* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Channagoud Kadabi7e8d55a2016-08-23 14:04:44 -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
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/of.h>
18#include <linux/of_device.h>
19#include <linux/dma-mapping.h>
20#include <linux/slab.h>
21#include <soc/qcom/memory_dump.h>
22
23static int cpuss_dump_probe(struct platform_device *pdev)
24{
25 struct device_node *child_node, *dump_node;
26 const struct device_node *node = pdev->dev.of_node;
27 static dma_addr_t dump_addr;
28 static void *dump_vaddr;
29 struct msm_dump_data *dump_data;
30 struct msm_dump_entry dump_entry;
31 int ret;
32 u32 size, id;
33
34 for_each_available_child_of_node(node, child_node) {
35 dump_node = of_parse_phandle(child_node, "qcom,dump-node", 0);
36
37 if (!dump_node) {
38 dev_err(&pdev->dev, "Unable to find node for %s\n",
39 child_node->name);
40 continue;
41 }
42
43 ret = of_property_read_u32(dump_node, "qcom,dump-size", &size);
44 if (ret) {
45 dev_err(&pdev->dev, "Unable to find size for %s\n",
46 dump_node->name);
47 continue;
48 }
49
50 ret = of_property_read_u32(child_node, "qcom,dump-id", &id);
51 if (ret) {
52 dev_err(&pdev->dev, "Unable to find id for %s\n",
53 child_node->name);
54 continue;
55 }
56
57 dump_vaddr = (void *) dma_alloc_coherent(&pdev->dev, size,
58 &dump_addr, GFP_KERNEL);
59
60 if (!dump_vaddr) {
61 dev_err(&pdev->dev, "Couldn't get memory for dumping\n");
62 continue;
63 }
64
65 memset(dump_vaddr, 0x0, size);
66
67 dump_data = devm_kzalloc(&pdev->dev,
68 sizeof(struct msm_dump_data), GFP_KERNEL);
69 if (!dump_data) {
70 dma_free_coherent(&pdev->dev, size, dump_vaddr,
71 dump_addr);
72 continue;
73 }
74
75 dump_data->addr = dump_addr;
76 dump_data->len = size;
Lingutla Chandrasekharbe48b072017-09-25 19:07:12 +053077 scnprintf(dump_data->name, sizeof(dump_data->name),
78 "KCPUSS%X", id);
Channagoud Kadabi7e8d55a2016-08-23 14:04:44 -070079 dump_entry.id = id;
80 dump_entry.addr = virt_to_phys(dump_data);
81 ret = msm_dump_data_register(MSM_DUMP_TABLE_APPS, &dump_entry);
82 if (ret) {
83 dev_err(&pdev->dev, "Data dump setup failed, id = %d\n",
84 id);
85 dma_free_coherent(&pdev->dev, size, dump_vaddr,
86 dump_addr);
87 devm_kfree(&pdev->dev, dump_data);
88 }
89
90 }
91 return 0;
92}
93
94static int cpuss_dump_remove(struct platform_device *pdev)
95{
96 return 0;
97}
98
99static const struct of_device_id cpuss_dump_match_table[] = {
100 { .compatible = "qcom,cpuss-dump", },
101 {}
102};
103
104static struct platform_driver cpuss_dump_driver = {
105 .probe = cpuss_dump_probe,
106 .remove = cpuss_dump_remove,
107 .driver = {
108 .name = "msm_cpuss_dump",
109 .owner = THIS_MODULE,
110 .of_match_table = cpuss_dump_match_table,
111 },
112};
113
114static int __init cpuss_dump_init(void)
115{
116 return platform_driver_register(&cpuss_dump_driver);
117}
118
119static void __exit cpuss_dump_exit(void)
120{
121 platform_driver_unregister(&cpuss_dump_driver);
122}
123
124subsys_initcall(cpuss_dump_init);
125module_exit(cpuss_dump_exit)
126