drivers/input/joystick/qwiic-joystick.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/qwiic-joystick.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/qwiic-joystick.c- Extension
.c- Size
- 3601 bytes
- Lines
- 147
- Domain
- Driver Families
- Bucket
- drivers/input
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/i2c.hlinux/input.hlinux/kernel.hlinux/module.h
Detected Declarations
struct qwiic_jskstruct qwiic_verstruct qwiic_datafunction qwiic_pollfunction qwiic_probe
Annotated Snippet
struct qwiic_jsk {
char phys[32];
struct input_dev *dev;
struct i2c_client *client;
};
struct qwiic_ver {
u8 major;
u8 minor;
};
struct qwiic_data {
__be16 x;
__be16 y;
u8 thumb;
};
static void qwiic_poll(struct input_dev *input)
{
struct qwiic_jsk *priv = input_get_drvdata(input);
struct qwiic_data data;
int err;
err = i2c_smbus_read_i2c_block_data(priv->client, QWIIC_JSK_REG_DATA,
sizeof(data), (u8 *)&data);
if (err != sizeof(data))
return;
input_report_abs(input, ABS_X, be16_to_cpu(data.x) >> 6);
input_report_abs(input, ABS_Y, be16_to_cpu(data.y) >> 6);
input_report_key(input, BTN_THUMBL, !data.thumb);
input_sync(input);
}
static int qwiic_probe(struct i2c_client *client)
{
struct qwiic_jsk *priv;
struct qwiic_ver vers;
int err;
err = i2c_smbus_read_i2c_block_data(client, QWIIC_JSK_REG_VERS,
sizeof(vers), (u8 *)&vers);
if (err < 0)
return err;
if (err != sizeof(vers))
return -EIO;
dev_dbg(&client->dev, "SparkFun Qwiic Joystick, FW: %u.%u\n",
vers.major, vers.minor);
priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->client = client;
snprintf(priv->phys, sizeof(priv->phys),
"i2c/%s", dev_name(&client->dev));
i2c_set_clientdata(client, priv);
priv->dev = devm_input_allocate_device(&client->dev);
if (!priv->dev)
return -ENOMEM;
priv->dev->id.bustype = BUS_I2C;
priv->dev->name = "SparkFun Qwiic Joystick";
priv->dev->phys = priv->phys;
input_set_drvdata(priv->dev, priv);
input_set_abs_params(priv->dev, ABS_X, 0, QWIIC_JSK_MAX_AXIS,
QWIIC_JSK_FUZZ, QWIIC_JSK_FLAT);
input_set_abs_params(priv->dev, ABS_Y, 0, QWIIC_JSK_MAX_AXIS,
QWIIC_JSK_FUZZ, QWIIC_JSK_FLAT);
input_set_capability(priv->dev, EV_KEY, BTN_THUMBL);
err = input_setup_polling(priv->dev, qwiic_poll);
if (err) {
dev_err(&client->dev, "failed to set up polling: %d\n", err);
return err;
}
input_set_poll_interval(priv->dev, QWIIC_JSK_POLL_INTERVAL);
input_set_min_poll_interval(priv->dev, QWIIC_JSK_POLL_MIN);
input_set_max_poll_interval(priv->dev, QWIIC_JSK_POLL_MAX);
err = input_register_device(priv->dev);
if (err) {
dev_err(&client->dev, "failed to register joystick: %d\n", err);
return err;
}
return 0;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/i2c.h`, `linux/input.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct qwiic_jsk`, `struct qwiic_ver`, `struct qwiic_data`, `function qwiic_poll`, `function qwiic_probe`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.