__spi_alloc_controller(9)
π __spi_alloc_controller(9) π
okay so bestie, we're in the Kernel API Manual and this is the page for __spi_alloc_controller(9) β the little function that gets you an SPI host or target controller. yes it's a double-underscore name, no I don't know why, we don't ask questions, we just read the docs. π
β¨ NAME β¨
__spi_alloc_controller β allocate an SPI host or target controller πΈ
π¦ SYNOPSIS π¦
struct spi_controller * __spi_alloc_controller (struct device *dev ,
unsigned int size , bool target );
π ARGUMENTS π
devβ the controller, possibly using theplatform_bus. that's your device bestie π«Άsizeβ how much zeroed driver-private data to allocate. the pointer to this memory lives in thedriver_datafield of the returned device, and you get at it withspi_controller_get_devdata. the memory is cacheline aligned. and listen β if you're a driver granting DMA access to portions of your private data, you gotta round up the size usingALIGN(size, dma_get_cache_alignment). do not skip that step, it's giving important β¨targetβ flag saying whether to allocate an SPI host controller (false) or an SPI target controller (true). pick your fighter π
π΄ CONTEXT π΄
can sleep. like, it's allowed to sleep. nap-friendly function, we love to see it ππ€
π DESCRIPTION π
k so this call is only used by SPI controller drivers β the ones that are literally the only ones directly touching chip registers. it's how they allocate an spi_controller structure, before they call spi_register_controller. main character energy but in a "you had to be there" way π«
this must be called from context that can sleep. no cap. π₯
the caller is responsible for:
- assigning the bus number
- initializing the controller's methods
β¦before calling spi_register_controller. and also for calling spi_controller_put to prevent a memory leak when you're done with the controller. yes, you. memory leaks are not cute, bestie ππ
π RETURN π
the SPI controller structure on success β else NULL. that's it. that's the whole vibe check π§
π SEE ALSO π
the Kernel file ./drivers/spi/spi.c, plus literally this whole friend group:
__spi_register_driver(9)spi_alloc_device(9)spi_add_device(9)spi_new_device(9)spi_unregister_device(9)spi_register_board_info(9)spi_res_alloc(9)spi_res_free(9)spi_res_add(9)spi_res_release(9)spi_finalize_current_transfer(9)__spi_pump_messages(9)spi_pump_messages(9)spi_take_timestamp_pre(9)spi_take_timestamp_post(9)spi_set_thread_rt(9)spi_get_next_queued_message(9)spi_finalize_current_message(9)spi_queued_transfer(9)spi_flush_queue(9)of_register_spi_devices(9)spi_new_ancillary_device(9)devm_spi_new_ancillary_device(9)acpi_spi_count_resources(9)acpi_spi_device_alloc(9)spi_target_abort(9)__devm_spi_alloc_controller(9)spi_get_gpio_descs(9)spi_register_controller(9)devm_spi_register_controller(9)spi_unregister_controller(9)spi_replace_transfers(9)spi_split_transfers_maxsize(9)spi_split_transfers_maxwords(9)spi_set_cs_timing(9)spi_setup(9)spi_optimize_message(9)spi_unoptimize_message(9)devm_spi_optimize_message(9)spi_async(9)spi_sync(9)spi_sync_locked(9)spi_bus_lock(9)spi_bus_unlock(9)spi_write_then_read(9)
iykyk π
anyway that's the page!! sourced from ./drivers/spi, dated October 2026, filed under __spi_alloc_controller(9) β love that for us, mwah, go allocate responsibly ππβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms