-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial build for create device node
- Loading branch information
Showing
12 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"env": { | ||
"KERNEL_VERSION":"6.10.4-200.fc40.x86_64" | ||
}, | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"/lib/modules/${KERNEL_VERSION}/build/include/", | ||
"/lib/modules/${KERNEL_VERSION}/build/arch/x86/include/", | ||
"/lib/modules/${KERNEL_VERSION}/build/arch/x86/include/generated" | ||
], | ||
"defines": [ | ||
"__GNUC__", | ||
"__KERNEL__", | ||
"MODULE", | ||
"KBUILD_MODNAME=\"UniversalIO\"" | ||
], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "linux-gcc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"files.associations": { | ||
"kernel.h": "c", | ||
"slab.h": "c", | ||
"i2c.h": "c", | ||
"i2c_engine.h": "c", | ||
"module.h": "c", | ||
"spi_engine.h": "c", | ||
"spi.h": "c", | ||
"i2c-smbus.h": "c", | ||
"i2c-dev.h": "c", | ||
"compiler.h": "c", | ||
"input.h": "c", | ||
"init.h": "c", | ||
"lib.h": "c", | ||
"uart_engine.h": "c" | ||
}, | ||
"C_Cpp.clang_format_style": "{ BasedOnStyle: Google, UseTab: Always, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Linux, AllowShortIfStatementsOnASingleLine: true, IndentCaseLabels: false, ColumnLimit: 120}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Binaries and objects generated from goodbye.c | ||
*.cmd | ||
*.ko | ||
*.mod.c | ||
*.o | ||
*.mod | ||
Module.symvers | ||
modules.order | ||
.tmp_versions/ | ||
|
||
# Babel artifacts | ||
babel_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
obj-m += UniversalIO.o | ||
UniversalIO-objs += ./src/main.o ./src/i2c_engine.o ./src/spi_engine.o ./src/uart_engine.o | ||
CONFIG_MODULE_SIG=n | ||
EXTRA_CFLAGS := -I$(src)/include | ||
I2C_BUS = 4 | ||
|
||
reload: build | ||
@-sudo rmmod UniversalIO.ko | ||
@sudo insmod UniversalIO.ko | ||
@sudo dmesg | grep "UniversalIO" | tail -n 5 | ||
|
||
build: | ||
@make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules | ||
|
||
clean: | ||
@make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | ||
|
||
sendTest: | ||
sudo i2ctransfer -y $(I2C_BUS) w6500@0x50 0x64- | ||
|
||
style: | ||
@/lib/modules/$(shell uname -r)/build/scripts/checkpatch.pl -q --no-tree -f src/*.c include/*.h | ||
|
||
dmesg: | ||
@sudo dmesg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* SPDX-License-Identifier: <SPDX License Expression> */ | ||
#pragma once | ||
#include "lib.h" | ||
#include <linux/i2c.h> | ||
extern struct i2c_algorithm algo; | ||
extern struct i2c_adapter adapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* SPDX-License-Identifier: <SPDX License Expression> */ | ||
#pragma once | ||
#include <linux/module.h> | ||
|
||
#ifdef pr_fmt | ||
#undef pr_fmt | ||
#endif | ||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* SPDX-License-Identifier: <SPDX License Expression> */ | ||
#pragma once | ||
#include "lib.h" | ||
#include <linux/spi/spi.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* SPDX-License-Identifier: <SPDX License Expression> */ | ||
#pragma once | ||
#include "lib.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include "i2c_engine.h" | ||
// static int i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); | ||
// static u32 i2c_func(struct i2c_adapter *adap); | ||
|
||
static int i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | ||
{ | ||
pr_info("[i2c-%d] xfer!\n", adap->nr); | ||
pr_info("[i2c-%d] xfer num %d!\n", adap->nr, num); | ||
pr_info("[i2c-%d] xfer len %d!\n", adap->nr, msgs->len); | ||
// int len = msgs->len; | ||
return 1; | ||
} | ||
|
||
static u32 i2c_func(struct i2c_adapter *adap) | ||
{ | ||
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL_ALL; | ||
} | ||
|
||
struct i2c_algorithm algo = { | ||
.functionality = i2c_func, | ||
.master_xfer = i2c_xfer, | ||
.smbus_xfer = NULL}; | ||
|
||
struct i2c_adapter adapter = { | ||
.class = I2C_CLASS_HWMON, | ||
.owner = THIS_MODULE, | ||
.algo = &algo}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include "lib.h" | ||
#include "i2c_engine.h" | ||
#include "spi_engine.h" | ||
#include "uart_engine.h" | ||
|
||
static int __init my_i2c_init(void) | ||
{ | ||
snprintf(adapter.name, sizeof(adapter.name), "My I2C Adapter"); | ||
|
||
if (i2c_add_adapter(&adapter)) { | ||
// i2c_put_adapter(&adapter); | ||
return -ENODEV; | ||
} | ||
pr_info("hello i2c-%d!\n", adapter.nr); | ||
|
||
return 0; | ||
} | ||
|
||
static void __exit my_i2c_exit(void) | ||
{ | ||
pr_info("goodbye i2c-%d!\n", adapter.nr); | ||
i2c_del_adapter(&adapter); | ||
} | ||
|
||
module_init(my_i2c_init); | ||
module_exit(my_i2c_exit); | ||
|
||
MODULE_LICENSE("GPL"); | ||
MODULE_AUTHOR("Author"); | ||
MODULE_DESCRIPTION("A simple I2C adapter driver"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include "spi_engine.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include "uart_engine.h" |