STRUCT FF_DEVICE(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… struct ff_device(9) โ€” the kernel API manual, but make it make sense

okay so bestie, welcome to the struct ff_device page from the Kernel API Manual โœจ this is literally the force-feedback part of an input device โ€” rumble, shake, the whole vibe ๐ŸŽฎ๐Ÿ’ฅ let's get into it.


๐ŸŒธ NAME ๐ŸŒธ

struct ff_device โ€” the force-feedback part of an input device. that's it, that's the whole thing, she's the haptic main character ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

struct ff_device {
    int (*upload)(struct input_dev *dev, struct ff_effect *effect,
struct ff_effect *old);
    int (*erase)(struct input_dev *dev, int effect_id);
    int (*playback)(struct input_dev *dev, int effect_id, int value);
    void (*set_gain)(struct input_dev *dev, u16 gain);
    void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
    void (*destroy)(struct ff_device *);
    void (*stop)(struct ff_device *);
    void *private;
    unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
    struct mutex mutex;
    int max_effects;
    struct ff_effect *effects;
    struct file *effect_owners[];
};

๐ŸŽ€ Members ๐ŸŽ€

  • upload โ€” called to upload a new effect into the device. yeah, this one's on the must-have list, no skipping ๐Ÿซถ
  • erase โ€” called to erase an effect from the device. optional but honestly iconic of her
  • playback โ€” called to request the device start playing the specified effect. also mandatory, bestie
  • set_gain โ€” called to set the specified gain
  • set_autocenter โ€” called to auto-center the device
  • destroy โ€” called by the input core when the parent input device is being destroyed ๐Ÿ’€
  • stop โ€” called by the input core when the parent input device is being unregistered
  • private โ€” driver-specific data, and it gets freed automatically, so don't you dare double-free it ๐Ÿ™ˆ
  • ffbit โ€” bitmap of force-feedback capabilities truly supported by the device (not emulated like the ones in input_dev->ffbit). yes, truly. she's not pretending ๐Ÿ’…
  • mutex โ€” mutex for serializing access to the device. one at a time, besties
  • max_effects โ€” maximum number of effects supported by the device
  • effects โ€” pointer to an array of effects currently loaded into the device
  • effect_owners โ€” array of effect owners; when the file handle owning an effect gets closed, the effect is automatically erased. self-cleaning queen โœจ

๐Ÿฆ‹ Description ๐Ÿฆ‹

Every force-feedback device must implement upload and playback methods โ€” those two are non-negotiable, periodt. erase is optional. And set_gain and set_autocenter only need to be implemented if the driver sets up the FF_GAIN and FF_AUTOCENTER bits.

โš ๏ธ okay this part is so important: note that playback, set_gain and set_autocenter are called with dev->event_lock spinlock held and interrupts off, which means they may not sleep. not even a lil nap. don't do it ๐Ÿ˜ญ

๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

  • Kernel file ./include/linux/input.h
  • struct input_value(9)
  • struct input_dev(9)
  • struct input_handler(9)
  • struct input_handle(9)
  • input_set_events_per_packet(9)

go read those too, iykyk ๐Ÿ“š๐Ÿ’œ


and that's the whole page, bestie ๐ŸŒˆ this livable little doc lives at ./include/linux and it's dated October 2026 โ€” so like, future vibes fr fr. stay hydrated, don't sleep in a spinlock, and slay ๐Ÿ’…๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from