I'm writing a linux driver for a DS2484 I2C one wire master, and an accompanying one-wire slave driver for a DS28E84 "DeepCover Radiation-Resistant, High-Capacity, 1-Wire Authenticator". The slaves in our system are hot-pluggable but only slave one may be attached to a one-wire master at any time. There are multiple masters in our system, so there could be more than 1 active slave present at a time.
I have written a "search" function in the master driver that successfully detects when a slave has been attached to the system, and that information is getting properly passed to the "wire" driver so the correct slave driver is associated with a slave device when the search function detects that new slave is present.
I'm unclear how to indicate back to the "wire" driver that the unplugged slave is no longer present. It isn't something the slave device can signal by itself because slaves can get unplugged without warning at any time. The master can determine when the slave has been unplugged, but I'm not sure how the master driver signals to the "wire" driver that the slave should be removed.
I've tried adding a check in the "search" function to see if a previously present device is no longer present, and if so clearing the "W1_SLAVE_ACTIVE" bit in the flags for that missing slave. I was hoping that would trigger the w1_slave_detach() function in the "wire" driver, but that didn't work.
By reading through the code for the "wire" driver, I discovered that the "wire" driver does automatically remove a slave when that slave doesn't report present from the master's search function. However, that removal doesn't necessarily happen the first time the slave isn't present in a search. Instead there is a counter that keeps track of how many times the slave didn't report present. The slave has to miss reporting present for more than a certain number of searches before the "wire" driver removes it.
In my case I was able to change my master driver's parameters so that it sets that "time to live" (ttl) parameter to 1 instead of the default value, and that forced the slave's removal the first time it didn't report present during a search.