mohitmishra786/low-level-dev-skills

bus-drivers-i2c-spi

I2C and SPI bus driver skill for Linux client drivers.

Ver código-fonte

Como usar

  1. Copie o comando e verifique o pacote antes de instalar no seu ambiente de agente.
  2. Consulte no original as ferramentas, credenciais e ambientes necessários.
  3. Descreva os dados de entrada e a entrega esperada; confira a saída com as fontes.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill bus-drivers-i2c-spi

Antes de começar

  • A instalação não inclui assinatura de modelo, franquia API ou acesso aos seus arquivos.
  • Estrelas e instalações indicam atividade, não um teste independente de qualidade ou segurança.
Documento original do Skill

Renderizado do repositório de origem, preservando títulos, exemplos, código, tabelas, links e imagens.

Bus Drivers (I2C and SPI)

Purpose

Guide agents through Linux I2C and SPI client drivers: bus registration, i2c_transfer / spi_sync, regmap abstraction, DT compatible on bus children, and probe patterns — complementing platform MMIO drivers in skills/kernel/device-drivers.

When to Use

  • Sensor or PMIC on I2C/SPI bus
  • Converting bare-metal SPI register reads to kernel driver
  • Using regmap for multi-byte register access
  • Debugging -EREMOTEIO or missing ACK

Workflow

1. I2C client driver

c
#include <linux/i2c.h>
#include <linux/mod_devicetable.h>

static int my_probe(struct i2c_client *client)
{
    struct regmap *map;

    map = devm_regmap_init_i2c(client, &my_regmap_config);
    if (IS_ERR(map))
        return PTR_ERR(map);

    dev_info(&client->dev, "probed at 0x%02x\n", client->addr);
    return 0;
}

static const struct of_device_id my_of_id[] = {
    { .compatible = "vendor,sensor" },
    { }
};
MODULE_DEVICE_TABLE(of, my_of_id);

static const struct i2c_device_id my_id[] = {
    { "mysensor", 0 },
    { }
};
MODULE_DEVICE_TABLE(i2c, my_id);

static struct i2c_driver my_driver = {
    .probe    = my_probe,
    .remove   = my_remove,
    .driver   = { .name = "mysensor", .of_match_table = my_of_id },
    .id_table = my_id,
};
module_i2c_driver(my_driver);

DT child:

dts
i2c1 {
    sensor@48 {
        compatible = "vendor,sensor";
        reg = <0x48>;
    };
};

2. Raw I2C transfer

c
u8 reg = 0x0F, val;
struct i2c_msg msgs[] = {
    { .addr = client->addr, .flags = 0,       .len = 1, .buf = &reg },
    { .addr = client->addr, .flags = I2C_M_RD, .len = 1, .buf = &val },
};
ret = i2c_transfer(client->adapter, msgs, 2);

3. SPI driver

c
static int spi_probe(struct spi_device *spi)
{
    spi->mode = SPI_MODE_0;
    spi->bits_per_word = 8;
    spi_setup(spi);

    struct spi_transfer t = {
        .tx_buf = tx,
        .rx_buf = rx,
        .len    = len,
    };
    struct spi_message m;
    spi_message_init(&m);
    spi_message_add_tail(&t, &m);
    return spi_sync(spi, &m);
}

static struct spi_driver spi_drv = {
    .probe  = spi_probe,
    .driver = { .name = "my-spi", .of_match_table = my_of_match },
};
module_spi_driver(spi_drv);

4. regmap (preferred for register maps)

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

regmap_read(map, REG_STATUS, &val);
regmap_write(map, REG_CTRL, CTRL_ENABLE);
regmap_update_bits(map, REG_CTRL, MASK, ENABLE);

5. Debug

bash
i2cdetect -y 1
i2cdump -y 1 0x48
cat /sys/bus/i2c/devices/i2c-1/1-0048/name

6. Agent usage

/bus-drivers-i2c-spi Write regmap-based driver for I2C PMIC at 0x58

Common Problems

SymptomCauseFix
-EREMOTEIONACK — wrong addressi2cdetect; check reg in DT
SPI mode wrongCPOL/CPHA mismatchMatch datasheet + spi->mode
Probe deferRegulator/clock supplierReturn -EPROBE_DEFER
regmap -EIO16-bit vs 8-bit regSet reg_bits, val_bits
DMA not usedSmall spi_sync OKspi_sync_transfer for bulk

Related Skills

  • skills/kernel/device-drivers — IRQ, DMA, PM runtime
  • skills/kernel-dev/device-tree — bus child nodes
  • skills/baremetal/spi-i2c-baremetal — register-level protocol
  • skills/kernel-dev/platform-device-model — driver model parallels
  • skills/kernel-dev/writing-char-drivers — expose sensor via char dev

Relacionados por tarefa

do mesmo repositório

Mais Skills

Todos os Skills
mohitmishra786
Comunidade

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.
mohitmishra786
Comunidade

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.
mohitmishra786
Comunidade

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.
mohitmishra786
Comunidade

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

instalações
2
GitHub Stars
267
Atualizado
27 de jun.