On Tue, Jul 30, 2024 at 07:16:10PM +0530, Sai Kumar Cholleti wrote: Please, refer to the functions in the text as func(), e.g. exar_set_value(). Use proper acronym, i.e. GPIO (capitalised). > Setting gpio direction = high, sometimes results in gpio value = 0. > > If a gpio is pulled high, the following construction results in the > value being 0 when the desired value is 1: > > $ echo "high" > /sys/class/gpio/gpio336/direction > $ cat /sys/class/gpio/gpio336/value > 0 > > Before the gpio direction is changed from input to output, > exar_set_value is set to 1, but since direction is input when > exar_set_value is called, _regmap_update_bits reads a 1 due to an > external pull-up. When force_write is not set (regmap_set_bits has > force_write = false), the value is not written. When the direction is > then changed, the gpio becomes an output with the value of 0 (the > hardware default). > > regmap_write_bits sets force_write = true, so the value is always > written by exar_set_value and an external pull-up doesn't affect the > outcome of setting direction = high. > > > The same can happen when a gpio is pulled low, but the scenario is a > little more complicated. > > $ echo high > /sys/class/gpio/gpio351/direction > $ cat /sys/class/gpio/gpio351/value > 1 > > $ echo in > /sys/class/gpio/gpio351/direction > $ cat /sys/class/gpio/gpio351/value > 0 > > $ echo low > /sys/class/gpio/gpio351/direction > $ cat /sys/class/gpio/gpio351/value > 1 Okay, shouldn't you instead mark the respective registers as volatile or so? I believe regmap has some settings for this case. But I haven't checked myself. -- With Best Regards, Andy Shevchenko