Device Drivers logo

Device Drivers

Community
mohitmishra786
device-drivers

Linux device driver skill for kernel driver development. Use when writing platform/i2c/spi drivers, char device lifecycle, IRQ handling, DMA engine API, regmap, power management, or udev rules. Activates on queries about platform_driver, request_irq, dma_alloc_coherent, regmap, pm_runtime, or char devices.

Overview

Publishermohitmishra786
Repositorylow-level-dev-skills
Skill namedevice-drivers
Stars
266
Forks
31
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by mohitmishra786 on GitHub. Read the source before you install it.

Installation

Install the Device Drivers AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/mohitmishra786/low-level-dev-skills/tree/main/skills/kernel/device-drivers
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mohitmishra786/low-level-dev-skills.git /tmp/low-level-dev-skills
mkdir -p .claude/skills
cp -r /tmp/low-level-dev-skills/skills/kernel/device-drivers .claude/skills/device-drivers
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Device Drivers in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Device Drivers on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Device Drivers is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Device Drivers

Purpose

Guide agents through Linux kernel device driver development: the driver model (platform_driver, i2c_driver, spi_driver), character device lifecycle, IRQ handling including threaded IRQs, DMA engine API, regmap for register abstraction, runtime power management, and udev rules for userspace device nodes.

When to Use

  • Writing a platform driver for memory-mapped hardware
  • Implementing a character device with read/write/ioctl
  • Handling hardware interrupts (hard IRQ vs threaded)
  • Setting up DMA coherent or streaming mappings
  • Abstracting register access with regmap
  • Configuring udev rules for /dev node permissions

Workflow

1. Driver model overview

Device tree / ACPI → bus (platform, i2c, spi, pci)
    → struct device → struct device_driver
        → probe() / remove()
c
// platform_driver.c — minimal platform driver
#include <linux/module.h>
#include <linux/platform_device.h>

static int my_probe(struct platform_device *pdev)
{
    struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    void __iomem *base = devm_ioremap_resource(&pdev->dev, res);
    if (IS_ERR(base))
        return PTR_ERR(base);
    dev_info(&pdev->dev, "probed at %pa\n", &res->start);
    return 0;
}

static void my_remove(struct platform_device *pdev)
{
    dev_info(&pdev->dev, "removed\n");
}

static struct platform_driver my_driver = {
    .probe  = my_probe,
    .remove = my_remove,
    .driver = { .name = "my-device", .owner = THIS_MODULE },
};

module_platform_driver(my_driver);
MODULE_LICENSE("GPL");

2. Character device lifecycle

c
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>

#define DEVICE_NAME "mydev"
#define MINOR_BASE  0
#define MINOR_COUNT 1

static dev_t dev_num;
static struct cdev my_cdev;
static struct class *dev_class;

static ssize_t my_read(struct file *filp, char __user *buf,
                       size_t count, loff_t *ppos)
{
    char kbuf[64] = "hello from kernel\n";
    size_t len = strlen(kbuf);
    if (*ppos >= len)
        return 0;
    if (count > len - *ppos)
        count = len - *ppos;
    if (copy_to_user(buf, kbuf + *ppos, count))
        return -EFAULT;
    *ppos += count;
    return count;
}

static const struct file_operations my_fops = {
    .owner = THIS_MODULE,
    .read  = my_read,
};

static int __init mydev_init(void)
{
    int ret;
    ret = alloc_chrdev_region(&dev_num, MINOR_BASE, MINOR_COUNT, DEVICE_NAME);
    if (ret)
        return ret;

    cdev_init(&my_cdev, &my_fops);
    my_cdev.owner = THIS_MODULE;
    ret = cdev_add(&my_cdev, dev_num, MINOR_COUNT);
    if (ret)
        goto err_cdev;

    dev_class = class_create(DEVICE_NAME);
    device_create(dev_class, NULL, dev_num, NULL, DEVICE_NAME);
    return 0;

err_cdev:
    unregister_chrdev_region(dev_num, MINOR_COUNT);
    return ret;
}
bash
# After loading module
ls -l /dev/mydev
cat /dev/mydev

3. IRQ handling

c
#include <linux/interrupt.h>

static irqreturn_t my_hardirq(int irq, void *dev_id)
{
    // Minimal work: acknowledge, schedule bottom half
    return IRQ_WAKE_THREAD;
}

static irqreturn_t my_threaded(int irq, void *dev_id)
{
    // Process data — can sleep
    process_ring_buffer();
    return IRQ_HANDLED;
}

static int request_device_irq(struct device *dev, int irq)
{
    return devm_request_threaded_irq(dev, irq, my_hardirq, my_threaded,
                                     IRQF_ONESHOT, "mydev", dev);
}
PatternUse when
Hard IRQ onlyMicrosecond work, no blocking
Threaded IRQI2C/SPI reads, scheduling, mutex
IRQF_ONESHOTLevel-triggered; IRQ masked until threaded handler returns

4. DMA engine API

c
#include <linux/dma-mapping.h>

// Coherent (consistent) mapping — CPU and device see same memory
void *cpu_addr;
dma_addr_t dma_handle;
cpu_addr = dma_alloc_coherent(dev, size, &dma_handle, GFP_KERNEL);

// Streaming (single) mapping for already-allocated buffers
dma_addr_t dma = dma_map_single(dev, kernel_buf, size, DMA_TO_DEVICE);
dma_sync_single_for_device(dev, dma, size, DMA_TO_DEVICE);
// ... device reads ...
dma_unmap_single(dev, dma, size, DMA_TO_DEVICE);
bash
# Debug DMA mappings
cat /sys/kernel/debug/dma_buf/bufinfo 2>/dev/null

5. regmap abstraction

c
#include <linux/regmap.h>

static const struct regmap_config my_regmap_config = {
    .reg_bits   = 8,
    .val_bits   = 8,
    .max_register = 0xFF,
};

// I2C regmap (typical for sensors)
static struct regmap *regmap;

regmap_write(regmap, 0x01, 0x80);  // set config register
regmap_read(regmap, 0x02, &val);   // read status
regmap_update_bits(regmap, 0x03, MASK, VALUE);

regmap handles locking, caching, and bulk access — prefer over raw i2c_smbus_* in new drivers.

6. Power management

c
#include <linux/pm_runtime.h>

static int my_runtime_suspend(struct device *dev)
{
    // Gate clocks, put hardware in low-power state
    return 0;
}

static int my_runtime_resume(struct device *dev)
{
    // Restore registers, enable clocks
    return 0;
}

static const struct dev_pm_ops my_pm_ops = {
    .runtime_suspend = my_runtime_suspend,
    .runtime_resume  = my_runtime_resume,
};

// In probe:
pm_runtime_enable(&pdev->dev);
pm_runtime_get_sync(&pdev->dev);  // ensure powered on

7. udev rules

bash
# /etc/udev/rules.d/99-mydev.rules
KERNEL=="mydev", MODE="0666", GROUP="plugdev"
SUBSYSTEM=="i2c-dev", KERNEL=="i2c-1", GROUP="i2c", MODE="0660"
bash
sudo udevadm control --reload-rules
sudo udevadm trigger
udevadm info -a -n /dev/mydev

8. I2C and SPI driver stubs

c
// i2c_driver
static const struct i2c_device_id my_i2c_id[] = {
    { "sensor-chip", 0 },
    { }
};
MODULE_DEVICE_TABLE(i2c, my_i2c_id);

static struct i2c_driver my_i2c_driver = {
    .driver = { .name = "sensor-chip" },
    .probe  = my_i2c_probe,
    .remove = my_i2c_remove,
    .id_table = my_i2c_id,
};
module_i2c_driver(my_i2c_driver);

Common Problems

SymptomCauseFix
probe failed with -EBUSYResource conflict or double probeCheck device tree status; devm_* cleanup
IRQ stormMissing acknowledge in handlerACK interrupt in hardirq; use IRQF_ONESHOT
DMA coherency bugWrong sync directiondma_sync_single_for_cpu/device at boundaries
/dev/node missingclass_create/device_create failedCheck dmesg; verify cdev_add return
copy_to_user faultInvalid userspace pointerValidate with access_ok
Runtime PM hangMissing pm_runtime_putBalance get/put; use devm_pm_runtime_enable

Related Skills

  • skills/kernel/kernel-internals — VFS, memory allocators underlying drivers
  • skills/low-level-programming/linux-kernel-modules — Kbuild, module loading, signing
  • skills/kernel/kernel-debugging — kgdb, ftrace for driver bugs
  • skills/embedded/zephyr — embedded RTOS driver model comparison
  • skills/observability/ebpf — trace driver events without modifying kernel
  • skills/kernel/kernel-testing — KUnit tests for driver logic

Frequently asked questions

What does the Device Drivers AI skill do?

Linux device driver skill for kernel driver development. Use when writing platform/i2c/spi drivers, char device lifecycle, IRQ handling, DMA engine API, regmap, power management, or udev rules. Activates on queries about platform_driver, request_irq, dma_alloc_coherent, regmap, pm_runtime, or char devices.

Why use Device Drivers on TypingMind?

Because you install it once and use it with any model. Device Drivers is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Device Drivers in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/mohitmishra786/low-level-dev-skills/tree/main/skills/kernel/device-drivers. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Device Drivers?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Device Drivers?

As many as you like. As long as a model supports skills, you can use Device Drivers with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Device Drivers AI skill free?

Yes. It is published on GitHub by mohitmishra786 under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇