The kernel supplies succinct and superb documentation on using the debugfs API (courtesy of Jonathan Corbet, LWN) here: https://www.kernel.org/doc/Documentation/filesystems/debugfs.txt (of course, you can also look it up directly within the kernel codebase).
I urge you to refer to this document to learn how to use the debugfs APIs, since it's easy to read and understand; this way, you can avoid unnecessarily repeating the same information here. In addition to the aforementioned document, the modern kernel documentation system (the "Sphinx"-based one) also provides quite detailed debugfs API pages: https://www.kernel.org/doc/html/latest/filesystems/api-summary.html?highlight=debugfs#the-debugfs-filesystem.
Note that all debugfs APIs are exported as GPL-only to kernel modules (thus necessitating the module being released under the "GPL" license (this can be dual licensed, but one must be "GPL")).