On Fri, Jul 04, 2025 at 09:26:16AM +0200, Álvaro Fernández Rojas wrote: > Hi Guenter, > > El vie, 4 jul 2025 a las 2:25, Guenter Roeck (<linux@xxxxxxxxxxxx>) escribió: > > > > On Thu, Jul 03, 2025 at 09:23:41AM +0200, Álvaro Fernández Rojas wrote: > > > > > > > > Add a comment describing what you are protecting here. It looks so far > > > > like you could just use regmap and drop the mutex, but I didn't check > > > > thoroughly. > > > > > > The EMC2101 datasheet is explicit about the Look Up Table registers > > > (REG_FAN_LUT_TEMP and REG_FAN_LUT_SPEED) being RO if FAN_LUT_DISABLE > > > isn't set, so I believe that we need the mutex even if we switch to > > > regmap. > > > I will add an explanation with that in the next version. > > > Should I still switch the implementation to regmap considering that we > > > need a mutex? > > > > > What does r/w vs. r/o register access have to do with locking ? > > FAN_LUT_DISABLE bit can be set or cleared when pwm_enable is modified, > but we need it to be set in order to be able to modify > REG_FAN_LUT_TEMP and REG_FAN_LUT_SPEED registers. > If FAN_LUT_DISABLE bit isn't set, any attempt to modify > REG_FAN_LUT_TEMP and REG_FAN_LUT_SPEED registers won't work because > they would be RO. > Therefore, we need a lock to ensure that FAN_LUT_DISABLE is kept while > modifying those registers. > Please, take a look at emc2101_pwm_enable_write() and > __pwm_auto_point_temp_store(). > Thanks for the clarification. Please add that as comment into the code. Regmap is still valuable even if local locking is needed. It provides caching for non-volatile registers, and it provides various useful API functions (for example for bit value changes) which you otherwise have to implement by hand. Guenter