w1_search(9)
π w1_search π
okay bestie, gather round, because this is w1_search(9) straight out of the Kernel API Manual and it is, lowkey, one of the prettiest little algorithms in the whole kernel. no cap. let's get into it π¦
β¨ NAME β¨
w1_search β Performs a ROM Search & registers any devices found. that's it, that's the whole job. she searches, she registers, she slays π
π SYNOPSIS π
void w1_search (struct w1_master *dev , u8 search_type ,
w1_slave_found_callback cb );
like, exactly that. copy it character for character, i am begging you π
πΈ ARGUMENTS πΈ
devβ The master device to search. this is your main character, the one doing the looking πsearch_typeβ ok so you got two moods here: passW1_SEARCHto search all devices, or passW1_ALARM_SEARCHto return only devices in the alarmed state. choose your vibe wisely β¨cbβ Function to call when a device is found. like a little notification ping but, you know, a callback π«Ά
π§ DESCRIPTION π§
The 1-wire search is a simple binary tree search. literally a binary tree, bestie, it's giving data structures 101 but make it hardware π
So for each bit of the address, we read two bits and write one bit. the bit we write puts to sleep all the devices that don't match that bit π΄ (not mean, just efficient, i promise).
When the two reads differ, the direction choice is obvious β no thoughts needed, head empty, path chosen π
When both bits are 0, we must choose a path to take. this is the actual decision moment, the main character moment, the "which way do we go" of it all π¦
And when we can scan all 64 bits without having to choose a path, we are done. sixty-four bits. all of them. no choices. finished. periodt β¨
also go read "Application note 187 1-wire search algorithm" at www.maxim-ic.com β it's the source material, the lore, iykyk π
π₯ SEE ALSO π₯
- Kernel file
./drivers/w1/w1.c w1_process_callbacks(9)
okay that's the whole page bestie, go forth and search π
signing off from ./drivers/w1, dated October 2026, filed under w1_search(9) β mwah, love u, bye ππ
π¦ 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