Wait until we need the limit register values, instead of pre-reading
them. This saves 544 ms on modprobe on my test system. Obviously this
time is added when first running "sensors" or any other monitoring
application, but I think it is better than slowing down the boot.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Move initial register reads out of probe, to dedicated functions.
This makes the code clearer, and will be needed if we want to delay
calling these functions until they are needed, or want to call them
periodically.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cascaded conditionals are inefficient. Reorder the fields so that
PWM register addresses can be computed more efficiently.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
There is no point in reading registers during initialization if we
will refresh the values in the update function later. This is only
slowing down the driver loading with no benefit, stop doing it.
This change saves 480 ms on driver load on my test system.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
All 3 temperature sensor type sysfs functions (show_temp_mode,
store_temp_mode and show_dts_mode) can be simplified. We don't
create these files when the correponding input isn't in temperature
monitoring mode, so there is no point in handling that case.
Likewise, we don't allow changing inputs from temperature to voltage,
so the code handling this case is dead and can be removed.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
VRLSB_SHIFT is a non-sense, the actual shift depends on the sensor
type (fans need 4, other sensors need 6). Get rid of it to prevent
any confusion. Also get rid of the useless masking, the meaningful
bits are always the MSb so there's nothing to mask out after
shifting.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Shorten driver load time by avoiding duplicate register access during
initialization. This saves 112 ms on modprobe on my test system.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Handle beep_enable just like all other beep bits. It doesn't need
anything special, so let's avoid redundant code. This also saves a
duplicate register read at initialization time.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
The PWM duty cycle frequenty attributes are improperly named
(fanN_div instead of pwmN_div) and contain raw values instead of
actual frequencies. Rename them and fix their contents.
Also improve the logic when the user asks for a new frequency, to
always pick the closest supported frequency. The algorithm could
certainly be optimized, but the operation is infrequent enough that
I don't think it's worth the effort.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
The W83795G can be configured to set the in0, in1 and/or in2 voltage
limits dynamically based on VID input pins. Switch the respective
sysfs attributes to read-only.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Misplaced parentheses caused the wrong register value to be read,
resulting in random LSB for fan speed values and limits.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
* The data structure is zalloc'd, so no need to set individual fields
to 0 explicitly.
* Refactor the handling of pins that can be used for either
temperature or voltage monitoring.
* Misc other clean-ups.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Only create fan[1-8]_target files when the fan in question can be
controlled (PWM output is present.) Also name these files according
to the standard.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Use a dedicated 2D array for PWM attributes. This way, PWM attributes
are handled the same way as other attributes, this is more consistent.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Use 2D arrays for in, fan, temp and dts device attributes. Using
linear arrays is too risky as we have to skip some groups depending
on the device model and configuration. Adding or removing an
attribute would let the driver build silently but then it would crash
at runtime. With 2D arrays, the consistency checking happens at build
time, which is much safer.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Functions w83795_create_files and w83795_remove_files iterate over
the same set of files, just calling a different function. Merge them
into a single function which takes the action as a parameter. This
saves code, and also ensure that file creation and deletion are in
sync.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Function w83795_probe() is way too big, move file creation to a separate
function to make it more readable.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Sysfs files must be removed on device removal but also when device
registration fails. Move the code to a separate function to avoid
code redundancy.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Move the bank selection code to a separate function, to avoid
duplicating it in read and write functions. Improve error reporting
on register access error.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Enum chips and chip_types are redundant, get rid of the former. Fix
the detection code to properly identify the chip variant and name the
client accordingly.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
There is still much work needed, but I wanted to give Wei the credit
he deserves. I've merged some of my own fixes already, to make
gcc and checkpatch happy. Individual fixes and improvements from me
will follow.
[JD: Fix build errors]
[JD: Coding style cleanups]
[JD: Get rid of forward declarations]
[JD: Drop VID support]
[JD: Drop fault output control feature]
[JD: Use lowercase for inline function names]
[JD: Use strict variants of the strtol/ul functions]
[JD: Shorten the read and write function names]
Signed-off-by: Jean Delvare <khali@linux-fr.org>