Linux Device Drivers

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.


Table of Contents

1. Driver Basics
Driver Entry and Exit points
Atomic and pointer manipulation
Delaying, scheduling, and timer routines
Wait queues and Wake events
High-resolution timers
Workqueues and Kevents
Internal Functions
Kernel objects manipulation
Kernel utility functions
Device Resource Management
2. Device drivers infrastructure
The Basic Device Driver-Model Structures
Device Drivers Base
Buffer Sharing and Synchronization
dma-buf
reservation
fence
Device Drivers DMA Management
Device Drivers Power Management
Device Drivers ACPI Support
Device drivers PnP support
Userspace IO devices
3. Parallel Port Devices
parport_yield — relinquish a parallel port temporarily
parport_yield_blocking — relinquish a parallel port temporarily
parport_wait_event — wait for an event on a parallel port
parport_wait_peripheral — wait for status lines to change in 35ms
parport_negotiate — negotiate an IEEE 1284 mode
parport_write — write a block of data to a parallel port
parport_read — read a block of data from a parallel port
parport_set_timeout — set the inactivity timeout for a device
__parport_register_driver — register a parallel port device driver
parport_unregister_driver — deregister a parallel port device driver
parport_get_port — increment a port's reference count
parport_put_port — decrement a port's reference count
parport_register_port — register a parallel port
parport_announce_port — tell device drivers about a parallel port
parport_remove_port — deregister a parallel port
parport_register_device — register a device on a parallel port
parport_unregister_device — deregister a device on a parallel port
parport_find_number — find a parallel port by number
parport_find_base — find a parallel port by base address
parport_claim — claim access to a parallel port device
parport_claim_or_block — claim access to a parallel port device
parport_release — give up access to a parallel port device
parport_open — find a device by canonical device number
parport_close close a device opened with parport_open
4. Message-based devices
Fusion message devices
5. Sound Devices
snd_printk — printk wrapper
snd_printd — debug printk
snd_BUG — give a BUG warning message and stack trace
snd_printd_ratelimit
snd_BUG_ON — debugging check macro
snd_printdd — debug printk
register_sound_special_device — register a special sound node
register_sound_mixer — register a mixer device
register_sound_midi — register a midi device
register_sound_dsp — register a DSP device
unregister_sound_special — unregister a special sound device
unregister_sound_mixer — unregister a mixer
unregister_sound_midi — unregister a midi device
unregister_sound_dsp — unregister a DSP device
snd_pcm_stream_linked — Check whether the substream is linked with others
snd_pcm_stream_lock_irqsave — Lock the PCM stream
snd_pcm_group_for_each_entry — iterate over the linked substreams
snd_pcm_running — Check whether the substream is in a running state
bytes_to_samples — Unit conversion of the size from bytes to samples
bytes_to_frames — Unit conversion of the size from bytes to frames
samples_to_bytes — Unit conversion of the size from samples to bytes
frames_to_bytes — Unit conversion of the size from frames to bytes
frame_aligned — Check whether the byte size is aligned to frames
snd_pcm_lib_buffer_bytes — Get the buffer size of the current PCM in bytes
snd_pcm_lib_period_bytes — Get the period size of the current PCM in bytes
snd_pcm_playback_avail — Get the available (writable) space for playback
snd_pcm_capture_avail — Get the available (readable) space for capture
snd_pcm_playback_hw_avail — Get the queued space for playback
snd_pcm_capture_hw_avail — Get the free space for capture
snd_pcm_playback_ready — check whether the playback buffer is available
snd_pcm_capture_ready — check whether the capture buffer is available
snd_pcm_playback_data — check whether any data exists on the playback buffer
snd_pcm_playback_empty — check whether the playback buffer is empty
snd_pcm_capture_empty — check whether the capture buffer is empty
snd_pcm_trigger_done — Mark the master substream
params_channels — Get the number of channels from the hw params
params_rate — Get the sample rate from the hw params
params_period_size — Get the period size (in frames) from the hw params
params_periods — Get the number of periods from the hw params
params_buffer_size — Get the buffer size (in frames) from the hw params
params_buffer_bytes — Get the buffer size (in bytes) from the hw params
snd_pcm_hw_constraint_single — Constrain parameter to a single value
snd_pcm_format_cpu_endian — Check the PCM format is CPU-endian
snd_pcm_set_runtime_buffer — Set the PCM runtime buffer
snd_pcm_gettime — Fill the timespec depending on the timestamp mode
snd_pcm_lib_alloc_vmalloc_buffer — allocate virtual DMA buffer
snd_pcm_lib_alloc_vmalloc_32_buffer — allocate 32-bit-addressable buffer
snd_pcm_sgbuf_get_addr — Get the DMA address at the corresponding offset
snd_pcm_sgbuf_get_ptr — Get the virtual address at the corresponding offset
snd_pcm_sgbuf_get_chunk_size — Compute the max size that fits within the contig. page from the given size
snd_pcm_mmap_data_open — increase the mmap counter
snd_pcm_mmap_data_close — decrease the mmap counter
snd_pcm_limit_isa_dma_size — Get the max size fitting with ISA DMA transfer
snd_pcm_stream_str — Get a string naming the direction of a stream
snd_pcm_chmap_substream — get the PCM substream assigned to the given chmap info
pcm_format_to_bits — Strong-typed conversion of pcm_format to bitwise
snd_pcm_format_name — Return a name string for the given PCM format
snd_pcm_new_stream — create a new PCM stream
snd_pcm_new — create a new PCM instance
snd_pcm_new_internal — create a new internal PCM instance
snd_pcm_notify — Add/remove the notify list
snd_device_new — create an ALSA device component
snd_device_disconnect — disconnect the device
snd_device_free — release the device from the card
snd_device_register — register the device
snd_info_get_line — read one line from the procfs buffer
snd_info_get_str — parse a string token
snd_info_create_module_entry — create an info entry for the given module
snd_info_create_card_entry — create an info entry for the given card
snd_info_free_entry — release the info entry
snd_info_register — register the info entry
snd_rawmidi_receive — receive the input data from the device
snd_rawmidi_transmit_empty — check whether the output buffer is empty
__snd_rawmidi_transmit_peek — copy data from the internal buffer
snd_rawmidi_transmit_peek — copy data from the internal buffer
__snd_rawmidi_transmit_ack — acknowledge the transmission
snd_rawmidi_transmit_ack — acknowledge the transmission
snd_rawmidi_transmit — copy from the buffer to the device
snd_rawmidi_new — create a rawmidi instance
snd_rawmidi_set_ops — set the rawmidi operators
snd_request_card — try to load the card module
snd_lookup_minor_data — get user data of a registered device
snd_register_device — Register the ALSA device file for the card
snd_unregister_device — unregister the device on the given card
copy_to_user_fromio — copy data from mmio-space to user-space
copy_from_user_toio — copy data from user-space to mmio-space
snd_pcm_lib_preallocate_free_for_all — release all pre-allocated buffers on the pcm
snd_pcm_lib_preallocate_pages — pre-allocation for the given DMA type
snd_pcm_lib_preallocate_pages_for_all — pre-allocation for continuous memory type (all substreams)
snd_pcm_sgbuf_ops_page — get the page struct at the given offset
snd_pcm_lib_malloc_pages — allocate the DMA buffer
snd_pcm_lib_free_pages — release the allocated DMA buffer.
snd_pcm_lib_free_vmalloc_buffer — free vmalloc buffer
snd_pcm_lib_get_vmalloc_page — map vmalloc buffer offset to page struct
snd_device_initialize — Initialize struct device for sound devices
snd_card_new — create and initialize a soundcard structure
snd_card_disconnect — disconnect all APIs from the file-operations (user space)
snd_card_free_when_closed — Disconnect the card, free it later eventually
snd_card_free — frees given soundcard structure
snd_card_set_id — set card identification name
snd_card_add_dev_attr — Append a new sysfs attribute group to card
snd_card_register — register the soundcard
snd_component_add — add a component string
snd_card_file_add — add the file to the file list of the card
snd_card_file_remove — remove the file from the file list
snd_power_wait — wait until the power-state is changed.
snd_dma_program — program an ISA DMA transfer
snd_dma_disable — stop the ISA DMA transfer
snd_dma_pointer — return the current pointer to DMA transfer buffer in bytes
snd_ctl_notify — Send notification to user-space for a control change
snd_ctl_new1 — create a control instance from the template
snd_ctl_free_one — release the control instance
snd_ctl_add — add the control instance to the card
snd_ctl_replace — replace the control instance of the card
snd_ctl_remove — remove the control from the card and release it
snd_ctl_remove_id — remove the control of the given id and release it
snd_ctl_activate_id — activate/inactivate the control of the given id
snd_ctl_rename_id — replace the id of a control on the card
snd_ctl_find_numid — find the control instance with the given number-id
snd_ctl_find_id — find the control instance with the given id
snd_ctl_register_ioctl — register the device-specific control-ioctls
snd_ctl_register_ioctl_compat — register the device-specific 32bit compat control-ioctls
snd_ctl_unregister_ioctl — de-register the device-specific control-ioctls
snd_ctl_unregister_ioctl_compat — de-register the device-specific compat 32bit control-ioctls
snd_ctl_boolean_mono_info — Helper function for a standard boolean info callback with a mono channel
snd_ctl_boolean_stereo_info — Helper function for a standard boolean info callback with stereo two channels
snd_ctl_enum_info — fills the info structure for an enumerated control
snd_pcm_set_ops — set the PCM operators
snd_pcm_set_sync — set the PCM sync id
snd_interval_refine — refine the interval value of configurator
snd_interval_ratnum — refine the interval value
snd_interval_list — refine the interval value from the list
snd_interval_ranges — refine the interval value from the list of ranges
snd_pcm_hw_rule_add — add the hw-constraint rule
snd_pcm_hw_constraint_mask64 — apply the given bitmap mask constraint
snd_pcm_hw_constraint_integer — apply an integer constraint to an interval
snd_pcm_hw_constraint_minmax — apply a min/max range constraint to an interval
snd_pcm_hw_constraint_list — apply a list of constraints to a parameter
snd_pcm_hw_constraint_ranges — apply list of range constraints to a parameter
snd_pcm_hw_constraint_ratnums — apply ratnums constraint to a parameter
snd_pcm_hw_constraint_ratdens — apply ratdens constraint to a parameter
snd_pcm_hw_constraint_msbits — add a hw constraint msbits rule
snd_pcm_hw_constraint_step — add a hw constraint step rule
snd_pcm_hw_constraint_pow2 — add a hw constraint power-of-2 rule
snd_pcm_hw_rule_noresample — add a rule to allow disabling hw resampling
snd_pcm_hw_param_value — return params field var value
snd_pcm_hw_param_first — refine config space and return minimum value
snd_pcm_hw_param_last — refine config space and return maximum value
snd_pcm_lib_ioctl — a generic PCM ioctl callback
snd_pcm_period_elapsed — update the pcm status for the next period
snd_pcm_add_chmap_ctls — create channel-mapping control elements
snd_hwdep_new — create a new hwdep instance
snd_pcm_stream_lock — Lock the PCM stream
snd_pcm_stream_unlock — Unlock the PCM stream
snd_pcm_stream_lock_irq — Lock the PCM stream
snd_pcm_stream_unlock_irq — Unlock the PCM stream
snd_pcm_stream_unlock_irqrestore — Unlock the PCM stream
snd_pcm_stop — try to stop all running streams in the substream group
snd_pcm_stop_xrun — stop the running streams as XRUN
snd_pcm_suspend — trigger SUSPEND to all linked streams
snd_pcm_suspend_all — trigger SUSPEND to all substreams in the given pcm
snd_pcm_lib_default_mmap — Default PCM data mmap function
snd_pcm_lib_mmap_iomem — Default PCM data mmap function for I/O mem
snd_malloc_pages — allocate pages with the given size
snd_free_pages — release the pages
snd_dma_alloc_pages — allocate the buffer area according to the given type
snd_dma_alloc_pages_fallback — allocate the buffer area according to the given type with fallback
snd_dma_free_pages — release the allocated buffer
6. Media Devices
Video2Linux devices
Digital TV (DVB) devices
Remote Controller devices
Media Controller devices
Consumer Electronics Control devices
7. 16x50 UART Driver
uart_update_timeout — update per-port FIFO timeout.
uart_get_baud_rate — return baud rate for a particular port
uart_get_divisor — return uart clock divisor
uart_console_write — write a console message to a serial port
uart_parse_earlycon — Parse earlycon options
uart_parse_options — Parse serial port baud/parity/bits/flow control.
uart_set_options — setup the serial console parameters
uart_register_driver — register a driver with the uart core layer
uart_unregister_driver — remove a driver from the uart core layer
uart_add_one_port — attach a driver-defined port structure
uart_remove_one_port — detach a driver defined port structure
uart_handle_dcd_change — handle a change of carrier detect state
uart_handle_cts_change — handle a change of clear-to-send state
uart_insert_char — push a char to the uart layer
serial8250_get_port — retrieve struct uart_8250_port
serial8250_suspend_port — suspend one serial port
serial8250_resume_port — resume one serial port
serial8250_register_8250_port — register a serial port
serial8250_unregister_port — remove a 16x50 serial port at runtime
8. Frame Buffer Library
Frame Buffer Memory
Frame Buffer Colormap
Frame Buffer Video Mode Database
Frame Buffer Macintosh Video Mode Database
Frame Buffer Fonts
9. Input Subsystem
Input core
Multitouch Library
Polled input devices
Matrix keyboards/keypads
Sparse keymap support
10. Serial Peripheral Interface (SPI)
struct spi_statistics — statistics for spi transfers
struct spi_device — Master side proxy for an SPI slave device
struct spi_driver — Host side protocol driver
spi_unregister_driver — reverse effect of spi_register_driver
module_spi_driver — Helper macro for registering a SPI driver
struct spi_master — interface to SPI master controller
struct spi_res — spi resource management structure
struct spi_transfer — a read/write buffer pair
struct spi_message — one multi-segment SPI transaction
spi_message_init_with_transfers — Initialize spi_message and append transfers
struct spi_replaced_transfers — structure describing the spi_transfer replacements that have occurred so that they can get reverted
spi_write — SPI synchronous write
spi_read — SPI synchronous read
spi_sync_transfer — synchronous SPI data transfer
spi_w8r8 — SPI synchronous 8 bit write followed by 8 bit read
spi_w8r16 — SPI synchronous 8 bit write followed by 16 bit read
spi_w8r16be — SPI synchronous 8 bit write followed by 16 bit big-endian read
struct spi_flash_read_message — flash specific information for spi-masters that provide accelerated flash read interfaces
struct spi_board_info — board-specific template for a SPI device
spi_register_board_info — register SPI devices for a given board
__spi_register_driver — register a SPI driver
spi_alloc_device — Allocate a new SPI device
spi_add_device — Add spi_device allocated with spi_alloc_device
spi_new_device — instantiate one new SPI device
spi_unregister_device — unregister a single SPI device
spi_finalize_current_transfer — report completion of a transfer
spi_get_next_queued_message — called by driver to check for queued messages
spi_finalize_current_message — the current message is complete
spi_alloc_master — allocate SPI master controller
spi_register_master — register SPI master controller
devm_spi_register_master — register managed SPI master controller
spi_unregister_master — unregister SPI master controller
spi_busnum_to_master — look up master associated with bus_num
spi_res_alloc — allocate a spi resource that is life-cycle managed during the processing of a spi_message while using spi_transfer_one
spi_res_free — free an spi resource
spi_res_add — add a spi_res to the spi_message
spi_res_release — release all spi resources for this message
spi_replace_transfers — replace transfers with several transfers and register change with spi_message.resources
spi_split_transfers_maxsize — split spi transfers into multiple transfers when an individual transfer exceeds a certain size
spi_setup — setup SPI mode and clock rate
spi_async — asynchronous SPI transfer
spi_async_locked — version of spi_async with exclusive bus usage
spi_sync — blocking/synchronous SPI data transfers
spi_sync_locked — version of spi_sync with exclusive bus usage
spi_bus_lock — obtain a lock for exclusive SPI bus usage
spi_bus_unlock — release the lock for exclusive SPI bus usage
spi_write_then_read — SPI synchronous write followed by read
11. I2C and SMBus Subsystem
struct i2c_driver — represent an I2C device driver
struct i2c_client — represent an I2C slave device
struct i2c_board_info — template for device creation
I2C_BOARD_INFO — macro used to list an i2c device and its address
struct i2c_algorithm — represent I2C transfer method
struct i2c_timings — I2C timing information
struct i2c_bus_recovery_info — I2C bus recovery information
struct i2c_adapter_quirks — describe flaws of an i2c adapter
i2c_lock_bus — Get exclusive access to an I2C bus segment
i2c_unlock_bus — Release exclusive access to an I2C bus segment
i2c_check_quirks — Function for checking the quirk flags in an i2c adapter
module_i2c_driver — Helper macro for registering a modular I2C driver
builtin_i2c_driver — Helper macro for registering a builtin I2C driver
i2c_register_board_info — statically declare I2C devices
i2c_verify_client — return parameter as i2c_client, or NULL
i2c_new_device — instantiate an i2c device
i2c_unregister_device reverse effect of i2c_new_device
i2c_new_dummy — return a new i2c device bound to a dummy driver
i2c_verify_adapter — return parameter as i2c_adapter or NULL
i2c_add_adapter — declare i2c adapter, use dynamic bus number
i2c_add_numbered_adapter — declare i2c adapter, use static bus number
i2c_del_adapter — unregister I2C adapter
i2c_parse_fw_timings — get I2C related timing parameters from firmware
i2c_del_driver — unregister I2C driver
i2c_use_client — increments the reference count of the i2c client structure
i2c_release_client — release a use of the i2c client structure
__i2c_transfer — unlocked flavor of i2c_transfer
i2c_transfer — execute a single or combined I2C message
i2c_master_send — issue a single I2C message in master transmit mode
i2c_master_recv — issue a single I2C message in master receive mode
i2c_smbus_read_byte — SMBus receive byte protocol
i2c_smbus_write_byte — SMBus send byte protocol
i2c_smbus_read_byte_data — SMBus read byte protocol
i2c_smbus_write_byte_data — SMBus write byte protocol
i2c_smbus_read_word_data — SMBus read word protocol
i2c_smbus_write_word_data — SMBus write word protocol
i2c_smbus_read_block_data — SMBus block read protocol
i2c_smbus_write_block_data — SMBus block write protocol
i2c_smbus_xfer — execute SMBus protocol operations
i2c_smbus_read_i2c_block_data_or_emulated — read block or emulate
12. High Speed Synchronous Serial Interface (HSI)
struct hsi_channel — channel resource used by the hsi clients
struct hsi_config — Configuration for RX/TX HSI modules
struct hsi_board_info — HSI client board info
struct hsi_client — HSI client attached to an HSI port
struct hsi_client_driver — Driver associated to an HSI client
struct hsi_msg — HSI message descriptor
struct hsi_port — HSI port device
struct hsi_controller — HSI controller device
hsi_id — Get HSI controller ID associated to a client
hsi_port_id — Gets the port number a client is attached to
hsi_setup — Configure the client's port
hsi_flush — Flush all pending transactions on the client's port
hsi_async_read — Submit a read transfer
hsi_async_write — Submit a write transfer
hsi_start_tx — Signal the port that the client wants to start a TX
hsi_stop_tx — Signal the port that the client no longer wants to transmit
hsi_port_unregister_clients — Unregister an HSI port
hsi_unregister_controller — Unregister an HSI controller
hsi_register_controller — Register an HSI controller and its ports
hsi_register_client_driver — Register an HSI client to the HSI bus
hsi_put_controller — Free an HSI controller
hsi_alloc_controller — Allocate an HSI controller and its ports
hsi_free_msg — Free an HSI message
hsi_alloc_msg — Allocate an HSI message
hsi_async — Submit an HSI transfer to the controller
hsi_claim_port — Claim the HSI client's port
hsi_release_port — Release the HSI client's port
hsi_register_port_event — Register a client to receive port events
hsi_unregister_port_event — Stop receiving port events for a client
hsi_event — Notifies clients about port events
hsi_get_channel_id_by_name — acquire channel id by channel name
13. Pulse-Width Modulation (PWM)
enum pwm_polarity — polarity of a PWM signal
struct pwm_args — board-dependent PWM arguments
struct pwm_device — PWM channel object
pwm_get_state — retrieve the current PWM state
struct pwm_ops — PWM controller operations
struct pwm_chip — abstract a PWM controller
pwm_config — change a PWM device configuration
pwm_set_polarity — configure the polarity of a PWM signal
pwm_enable — start a PWM output toggling
pwm_disable — stop a PWM output toggling
pwm_set_chip_data — set private chip data for a PWM
pwm_get_chip_data — get private chip data for a PWM
pwmchip_add_with_polarity — register a new PWM chip
pwmchip_add — register a new PWM chip
pwmchip_remove — remove a PWM chip
pwm_request — request a PWM device
pwm_request_from_chip — request a PWM device relative to a PWM chip
pwm_free — free a PWM device
pwm_apply_state — atomically apply a new state to a PWM device
pwm_adjust_config — adjust the current PWM config to the PWM arguments
of_pwm_get — request a PWM via the PWM framework
pwm_get — look up and request a PWM device
pwm_put — release a PWM device
devm_pwm_get resource managed pwm_get
devm_of_pwm_get resource managed of_pwm_get
devm_pwm_put resource managed pwm_put
pwm_can_sleep — report whether PWM access will sleep