Skip to content

Commit 3a6e942

Browse files
committed
platform : show and store example
1 parent be2d39d commit 3a6e942

File tree

4 files changed

+116
-5
lines changed

4 files changed

+116
-5
lines changed

debug/platform_driver_test/Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# DEBUG = y
44

55
# Usage
6-
# make CC=<your_compiler_path> KERNELDIR=<your_kernel_dir>
6+
# make CROSS_COMPILE=<cross_compiler_prefix> KERNEL_DIR=<your_kernel_dir> KERNEL_BUID_OUTPUT=<kernel_buid_output>
77
#
8-
# make CC=/home/zeroway/3288/src/3288_4.4/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-gcc KERNELDIR=/home/zeroway/3288/src/3288_4.4/kernel
8+
# make CROSS_COMPILE=/home/zeroway/3288/51/src/3288_5.1_v2/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi- KERNEL_DIR=/home/zeroway/3288/51/src/3288_5.1_v2/kernel KERNEL_BUID_OUTPUT=/home/zeroway/3288/51/src/3288_5.1_v2/out/target/product/rk3288/obj/KERNEL
99

1010
# Add your debugging flag (or not) to CFLAGS
1111
ifeq ($(DEBUG),y)
@@ -15,12 +15,15 @@ DEBFLAGS = -O2
1515
endif
1616

1717
obj-m := test_pf.o
18-
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
19-
CC ?= gcc
18+
obj-m += show_store_pf.o
19+
KERNEL_DIR ?= /lib/modules/$(shell uname -r)/build
20+
KERNEL_BUID_OUTPUT ?=$(KERNEL_DIR)
21+
CC = $(CROSS_COMPILE)gcc
22+
LD = $(CROSS_COMPILE)ld
2023
PWD := $(shell pwd)
2124

2225
modules:
23-
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
26+
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) O=$(KERNEL_BUID_OUTPUT) modules
2427

2528
clean:
2629
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers

debug/platform_driver_test/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,20 @@
77
在驱动中如何使用下图中的VCC_TP,详见代码
88

99
![VCC_TP](./VCC_TP.png)
10+
11+
# show_store_pf.c
12+
13+
device attr show and store
14+
15+
## usage
16+
17+
把dtsi文件包含到所使用的dts里
18+
19+
#include "show_store_pf.dtsi"
20+
21+
## debug
22+
23+
输入3个值并查看
24+
25+
echo 1 3 4 > /sys/devices/my_test_node.23/BBBBB_debug
26+
cat /sys/devices/my_test_node.23/BBBBB_debug
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <linux/of.h>
2+
#include <linux/init.h>
3+
#include <linux/device.h>
4+
#include <linux/kernel.h>
5+
#include <linux/init.h>
6+
#include <linux/types.h>
7+
#include <linux/module.h>
8+
#include <linux/platform_device.h>
9+
10+
static int g_x = -1;
11+
static int g_y = -1;
12+
static int g_z = -1;
13+
14+
static ssize_t BBBBB_debug_show(struct device *dev, struct device_attribute *attr, char *buf)
15+
{
16+
printk("x = %d y = %d z = %d\n", g_x, g_y, g_z);
17+
return 0;
18+
}
19+
20+
static ssize_t BBBBB_debug_store(struct device *dev,
21+
struct device_attribute *attr, const char *buf, size_t count)
22+
{
23+
sscanf(buf, "%d %d %d", &g_x, &g_y, &g_z);
24+
return count;
25+
}
26+
27+
static DEVICE_ATTR(BBBBB_debug, S_IRUGO | S_IWUSR, BBBBB_debug_show, BBBBB_debug_store);
28+
29+
static struct attribute *BBBBB_attrs[] = {
30+
&dev_attr_BBBBB_debug.attr,
31+
NULL,
32+
};
33+
34+
static const struct attribute_group BBBBB_attr_group = {
35+
.attrs = BBBBB_attrs,
36+
};
37+
38+
static int AAAAA_platform_probe(struct platform_device *pdev)
39+
{
40+
int ret;
41+
42+
ret = sysfs_create_group(&pdev->dev.kobj, &BBBBB_attr_group);
43+
if (ret) {
44+
printk("failed to create sysfs device attributes\n");
45+
return -1;
46+
}
47+
return 0;
48+
}
49+
50+
static const struct of_device_id AAAAA_platform_dt_ids[] = {
51+
{ .compatible = "test_platform", },
52+
{}
53+
};
54+
55+
static int AAAAA_platform_remove(struct platform_device *pdev)
56+
{
57+
int ret;
58+
59+
sysfs_remove_group(&pdev->dev.kobj, &BBBBB_attr_group);
60+
61+
printk("%s, %d\n", __FUNCTION__, __LINE__);
62+
return 0;
63+
}
64+
65+
static struct platform_driver AAAAA_platform_driver = {
66+
.driver = {
67+
.name = "test platform driver",
68+
.owner = THIS_MODULE,
69+
.of_match_table = of_match_ptr(AAAAA_platform_dt_ids),
70+
},
71+
.probe = AAAAA_platform_probe,
72+
};
73+
74+
static int AAAAA_platform_init(void)
75+
{
76+
return platform_driver_register(&AAAAA_platform_driver);
77+
}
78+
79+
static void AAAAA_platform_exit(void)
80+
{
81+
platform_driver_unregister(&AAAAA_platform_driver);
82+
}
83+
84+
module_init(AAAAA_platform_init);
85+
module_exit(AAAAA_platform_exit);
86+
MODULE_LICENSE("GPL");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/ {
2+
my_test_node {
3+
compatible = "test_platform";
4+
};
5+
};

0 commit comments

Comments
 (0)