I do not have a developer environment in the rPi (it runs from an SD card), but I can do it in the Mac. I will try to modify the driver following your advice, but it may take longer to test.
In the meantime, yesterday night I switched to the Polynomial algorithm and the autofocus process (I ran it three times) worked without timeouts. Perhaps it has to do with how the Linear algorithm works? well, anyway, it is a positive change.
I will go on with my tests and update this thread with my results. If you have any other suggestions, they will be very welcome!