Skip to content

Commit 5565111

Browse files
jiegan0107shashim-quic
authored andcommitted
QCLINUX: qcom-dcc: add qcom-dcc dev driver
Create qcom-dcc dev driver for matching the qcom-dcc driver without DT. Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
1 parent 63edcd5 commit 5565111

6 files changed

Lines changed: 153 additions & 72 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
CONFIG_QCOM_DCC=m
2+
CONFIG_QCOM_DCC_DEV=m

drivers/misc/Kconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,19 @@ config QCOM_FASTRPC
311311
module.
312312

313313
config QCOM_DCC
314-
tristate "Qualcomm Technologies, Inc. Data Capture and Compare (DCC) engine driver"
314+
tristate "Qualcomm Data Capture and Compare (DCC) engine driver"
315315
depends on ARCH_QCOM || COMPILE_TEST
316316
help
317317
This option enables the driver for the Data Capture and Compare engine. DCC
318318
driver provides interfaces to configure DCC block and read back the captured
319319
data from the DCC's internal SRAM. The module name for this is qcom-dcc.
320320

321+
config QCOM_DCC_DEV
322+
tristate "Qualcomm Data Capture and Compare (DCC) engine device instance"
323+
depends on QCOM_DCC
324+
help
325+
This is the device instance of the QCOM DCC driver.
326+
321327
config SGI_GRU
322328
tristate "SGI GRU driver"
323329
depends on X86_UV && SMP

drivers/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ obj-y += keba/
7676
obj-y += amd-sbi/
7777
obj-$(CONFIG_MISC_RP1) += rp1/
7878
obj-$(CONFIG_QCOM_DCC) += qcom-dcc.o
79+
obj-$(CONFIG_QCOM_DCC_DEV) += qcom-dcc-dev.o

drivers/misc/qcom-dcc-dev.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
*/
5+
6+
#include <linux/module.h>
7+
#include <linux/platform_device.h>
8+
#include <linux/soc/qcom/smem.h>
9+
#include "qcom-dcc.h"
10+
11+
#define DEV_NAME "qcom-dcc"
12+
13+
static struct platform_device *dcc_pdev;
14+
15+
static const struct dcc_pdata talos_pdata = {
16+
.base = 0x010a2000,
17+
.size = 0x00001000,
18+
.ram_base = 0x010ae000,
19+
.ram_size = 0x00002000,
20+
.dcc_offset = 0x6000,
21+
.map_ver = 0x1,
22+
};
23+
24+
static const struct dcc_pdata lemans_pdata = {
25+
.base = 0x040ff000,
26+
.size = 0x00001000,
27+
.ram_base = 0x040b8800,
28+
.ram_size = 0x00006000,
29+
.dcc_offset = 0x38800,
30+
.map_ver = 0x3,
31+
};
32+
33+
static const struct dcc_pdata kodiak_pdata = {
34+
.base = 0x0117f000,
35+
.size = 0x00001000,
36+
.ram_base = 0x01112000,
37+
.ram_size = 0x00006000,
38+
.dcc_offset = 0x12000,
39+
.map_ver = 0x2,
40+
};
41+
42+
static int __init dcc_dev_init(void)
43+
{
44+
int ret;
45+
u32 soc_id;
46+
47+
dcc_pdev = platform_device_alloc(DEV_NAME, -1);
48+
if (!dcc_pdev)
49+
return -ENOMEM;
50+
51+
ret = qcom_smem_get_soc_id(&soc_id);
52+
if (ret)
53+
goto fail;
54+
55+
switch (soc_id) {
56+
case 475:
57+
case 497:
58+
case 498:
59+
case 515:
60+
ret = platform_device_add_data(dcc_pdev, &kodiak_pdata, sizeof(kodiak_pdata));
61+
if (ret)
62+
goto fail;
63+
64+
break;
65+
case 534:
66+
case 606:
67+
case 667:
68+
case 674:
69+
case 675:
70+
case 676:
71+
ret = platform_device_add_data(dcc_pdev, &lemans_pdata, sizeof(lemans_pdata));
72+
if (ret)
73+
goto fail;
74+
75+
break;
76+
case 377:
77+
case 380:
78+
case 384:
79+
case 401:
80+
case 406:
81+
case 680:
82+
ret = platform_device_add_data(dcc_pdev, &talos_pdata, sizeof(talos_pdata));
83+
if (ret)
84+
goto fail;
85+
86+
break;
87+
default:
88+
pr_err("DCC: Invalid SoC ID\n");
89+
ret = -EINVAL;
90+
goto fail;
91+
}
92+
93+
ret = platform_device_add(dcc_pdev);
94+
if (ret)
95+
goto fail;
96+
97+
pr_info("DCC platform device has registered\n");
98+
99+
return 0;
100+
101+
fail:
102+
pr_err("Failed to register DCC platform device\n");
103+
platform_device_put(dcc_pdev);
104+
105+
return ret;
106+
}
107+
108+
static void __exit dcc_dev_exit(void)
109+
{
110+
platform_device_unregister(dcc_pdev);
111+
}
112+
113+
module_init(dcc_dev_init);
114+
module_exit(dcc_dev_exit);
115+
MODULE_LICENSE("GPL");
116+
MODULE_DESCRIPTION("Qualcomm Technologies Inc. DCC driver, device stub");

drivers/misc/qcom-dcc.c

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
#include <linux/slab.h>
136136
#include <linux/uaccess.h>
137137

138+
#include "qcom-dcc.h"
139+
138140
#define STATUS_READY_TIMEOUT 5000 /* microseconds */
139141

140142
/* DCC registers */
@@ -1423,57 +1425,6 @@ static ssize_t dcc_sram_read(struct file *file, char __user *data,
14231425
return len;
14241426
}
14251427

1426-
static void dcc_configure_list(struct dcc_drvdata *drvdata, struct device_node *np)
1427-
{
1428-
const char *prop;
1429-
int ret, curr_list, index = 0;
1430-
char *token, *bufp;
1431-
char *delim = " ";
1432-
u32 len, processed_len = 0;
1433-
1434-
ret = of_property_read_u32(np, "qcom,curr-link-list",
1435-
&curr_list);
1436-
if (ret)
1437-
return;
1438-
1439-
if(!of_get_property(np, "qcom,link-list", &len))
1440-
return;
1441-
1442-
bufp = kzalloc(len+1, GFP_KERNEL);
1443-
if (!bufp)
1444-
return;
1445-
1446-
while (!of_property_read_string_index(np, "qcom,link-list", index, &prop)) {
1447-
strncpy(bufp, prop, strlen(prop));
1448-
bufp[strlen(prop)] = '\0';
1449-
1450-
processed_len += strlen(bufp) + 1;
1451-
1452-
token = strsep(&bufp, delim);
1453-
1454-
if (!strcmp("R", token)) {
1455-
ret = dcc_config_add_read(drvdata, bufp, curr_list);
1456-
} else if (!strcmp("W", token)) {
1457-
ret = dcc_config_add_write(drvdata, bufp, curr_list);
1458-
} else if (!strcmp("RW", token)) {
1459-
ret = dcc_config_add_read_write(drvdata, bufp, curr_list);
1460-
} else if (!strcmp("L", token)) {
1461-
ret = dcc_config_add_loop(drvdata, bufp, curr_list);
1462-
} else {
1463-
dev_err(drvdata->dev, "%s is not a correct input\n", token);
1464-
ret = -EINVAL;
1465-
}
1466-
1467-
if (ret < 0)
1468-
dev_err(drvdata->dev, "Configure line %s failed\n", prop);
1469-
1470-
index++;
1471-
}
1472-
1473-
dcc_enable(drvdata, curr_list);
1474-
kfree(bufp);
1475-
}
1476-
14771428
static const struct file_operations dcc_sram_fops = {
14781429
.owner = THIS_MODULE,
14791430
.read = dcc_sram_read,
@@ -1499,7 +1450,7 @@ static int dcc_probe(struct platform_device *pdev)
14991450
int ret = 0, i;
15001451
struct device *dev = &pdev->dev;
15011452
struct dcc_drvdata *drvdata;
1502-
struct resource *res;
1453+
const struct dcc_pdata *pdata = dev_get_platdata(dev);
15031454

15041455
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
15051456
if (!drvdata)
@@ -1508,21 +1459,17 @@ static int dcc_probe(struct platform_device *pdev)
15081459
drvdata->dev = &pdev->dev;
15091460
platform_set_drvdata(pdev, drvdata);
15101461

1511-
drvdata->base = devm_platform_ioremap_resource(pdev, 0);
1462+
drvdata->base = devm_ioremap(dev, pdata->base, pdata->size);
15121463
if (IS_ERR(drvdata->base))
15131464
return PTR_ERR(drvdata->base);
15141465

1515-
drvdata->ram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
1466+
drvdata->ram_base = devm_ioremap(dev, pdata->ram_base, pdata->ram_size);
15161467
if (IS_ERR(drvdata->ram_base))
15171468
return PTR_ERR(drvdata->ram_base);
15181469

1519-
drvdata->ram_size = resource_size(res);
1520-
ret = of_property_read_u32(pdev->dev.of_node, "qcom,dcc-offset",
1521-
&drvdata->ram_offset);
1522-
if (ret)
1523-
return -EINVAL;
1524-
1525-
drvdata->mem_map_ver = (u64)of_device_get_match_data(&pdev->dev);
1470+
drvdata->ram_size = pdata->ram_size;
1471+
drvdata->ram_offset = pdata->dcc_offset;
1472+
drvdata->mem_map_ver = pdata->map_ver;
15261473

15271474
switch (drvdata->mem_map_ver) {
15281475
case MEM_MAP_VER3:
@@ -1573,7 +1520,6 @@ static int dcc_probe(struct platform_device *pdev)
15731520
}
15741521

15751522
dcc_create_debug_dir(drvdata);
1576-
dcc_configure_list(drvdata, pdev->dev.of_node);
15771523

15781524
return 0;
15791525
}
@@ -1587,20 +1533,11 @@ static void dcc_remove(struct platform_device *pdev)
15871533
dcc_config_reset(drvdata);
15881534
}
15891535

1590-
static const struct of_device_id dcc_match_table[] = {
1591-
{ .compatible = "qcom,dcc-v1", .data = (void *)MEM_MAP_VER1 },
1592-
{ .compatible = "qcom,dcc-v2", .data = (void *)MEM_MAP_VER2 },
1593-
{ .compatible = "qcom,dcc-v3", .data = (void *)MEM_MAP_VER3 },
1594-
{ }
1595-
};
1596-
MODULE_DEVICE_TABLE(of, dcc_match_table);
1597-
15981536
static struct platform_driver dcc_driver = {
15991537
.probe = dcc_probe,
16001538
.remove = dcc_remove,
16011539
.driver = {
16021540
.name = "qcom-dcc",
1603-
.of_match_table = dcc_match_table,
16041541
},
16051542
};
16061543

drivers/misc/qcom-dcc.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
*/
5+
6+
#ifndef _QCOM_DCC_H
7+
#define _QCOM_DCC_H
8+
9+
#include <linux/platform_device.h>
10+
11+
struct dcc_pdata {
12+
phys_addr_t base;
13+
resource_size_t size;
14+
phys_addr_t ram_base;
15+
resource_size_t ram_size;
16+
u32 dcc_offset;
17+
u8 map_ver;
18+
};
19+
20+
#endif

0 commit comments

Comments
 (0)