14 Apr, 2022

1 commit

  • [ Upstream commit 41a92a89eee819298f805c40187ad8b02bb53426 ]

    w1_seq was failing due to several devices responding to the
    CHAIN_DONE at the same time. Now properly selects the current
    device in the chain with MATCH_ROM. Also acknowledgment was
    read twice.

    Signed-off-by: Lucas Denefle
    Link: https://lore.kernel.org/r/20220223113558.232750-1-lucas.denefle@converge.io
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin

    Lucas Denefle
     

27 Jan, 2022

1 commit

  • [ Upstream commit 33dc3e3e99e626ce51f462d883b05856c6c30b1d ]

    sparse warnings: (new ones prefixed by >>)
    >> drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected char [noderef] __user *_pu_addr @@ got char *buf @@
    drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: expected char [noderef] __user *_pu_addr
    drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: got char *buf
    >> drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected char const [noderef] __user *_gu_addr @@ got char const *buf @@
    drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: expected char const [noderef] __user *_gu_addr
    drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: got char const *buf

    The buffer buf is a failsafe buffer in kernel space, it's not user
    memory hence doesn't deserve the use of get_user() or put_user().

    Access 'buf' content directly.

    Link: https://lore.kernel.org/lkml/202111190526.K5vb7NWC-lkp@intel.com/T/
    Reported-by: kernel test robot
    Signed-off-by: Christophe Leroy
    Link: https://lore.kernel.org/r/d14ed8d71ad4372e6839ae427f91441d3ba0e94d.1637946316.git.christophe.leroy@csgroup.eu
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin

    Christophe Leroy
     

26 May, 2021

1 commit

  • The opening comment mark '/**' is used for highlighting the beginning of
    kernel-doc comments.
    The comments for drivers/w1/masters/ds2482.c follows this syntax, but
    the content inside does not comply with kernel-doc.

    Similarly, the syntax for function and arguments declaration as well.

    Fix all such occurrences appropriately.

    Tested-by: Randy Dunlap
    Reviewed-by: Randy Dunlap
    Signed-off-by: Aditya Srivastava
    Link: https://lore.kernel.org/r/20210523150122.21160-1-yashsri421@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Aditya Srivastava
     

21 May, 2021

8 commits

  • Added a sysfs entry to support writing to the offset register on page1.
    This register is used to calibrate the chip canceling offset errors in the
    current ADC. This means that, over time, reading the IAD register will not
    return the correct current measurement, it will have an offset. Writing to
    the offset register if the two's complement of the current register while
    passing zero current to the load will calibrate the measurements. This
    change was tested on real hardware and it was able to calibrate the chip
    correctly.

    Signed-off-by: Luiz Sampaio
    Link: https://lore.kernel.org/r/20210519223046.13798-7-sampaio.ime@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Luiz Sampaio
     
  • Added a sysfs entry to support reading the page1 registers. This registers
    contain Elapsed Time Meter (ETM) data, which shows for how long the chip is
    on, as well as an Offset Register data, which can be used to calibrate the
    current measurement of the chip.

    Signed-off-by: Luiz Sampaio
    Link: https://lore.kernel.org/r/20210519223046.13798-6-sampaio.ime@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Luiz Sampaio
     
  • The purpose of the w1_ds2438_get_page function is to get the register
    values at the page passed as the pageno parameter. However, the page0 was
    hardcoded, such that the function always returned the page0 contents. Fixed
    so that the function can retrieve any page.

    Signed-off-by: Luiz Sampaio
    Link: https://lore.kernel.org/r/20210519223046.13798-5-sampaio.ime@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Luiz Sampaio
     
  • The iad sysfs file has permissions for read and write. Changed to the
    recommended macro BIN_ATTR_RW.

    Signed-off-by: Luiz Sampaio
    Link: https://lore.kernel.org/r/20210519223046.13798-4-sampaio.ime@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Luiz Sampaio
     
  • Since there is only one statement inside the if clause, no brackets are
    required.

    Signed-off-by: Luiz Sampaio
    Link: https://lore.kernel.org/r/20210519223046.13798-3-sampaio.ime@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Luiz Sampaio
     
  • There is an if statement and, if the function goes into it, it returns. So,
    the next else is not required.

    Signed-off-by: Luiz Sampaio
    Link: https://lore.kernel.org/r/20210519223046.13798-2-sampaio.ime@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Luiz Sampaio
     
  • Fix the following build warning:

    drivers/w1/slaves/w1_therm.c: In function ‘w1_seq_show’:
    drivers/w1/slaves/w1_therm.c:2059:6: warning: variable ‘rv’ set but not used [-Wunused-but-set-variable]
    int rv;
    ^~

    Signed-off-by: Yang Yingliang
    Link: https://lore.kernel.org/r/20210518050415.615783-1-yangyingliang@huawei.com
    Signed-off-by: Greg Kroah-Hartman

    Yang Yingliang
     
  • Fix the following make W=1 kernel build warning:

    drivers/w1/slaves/w1_therm.c:843: warning: expecting prototype for support_bulk_read(). Prototype was for bulk_read_support() instead

    Signed-off-by: Yang Yingliang
    Link: https://lore.kernel.org/r/20210518050401.615648-1-yangyingliang@huawei.com
    Signed-off-by: Greg Kroah-Hartman

    Yang Yingliang
     

10 Apr, 2021

2 commits


24 Mar, 2021

3 commits


27 Jan, 2021

1 commit

  • DS18B20 device driver returns an incorrect value for negative temperatures
    due to a missing sign-extension in w1_DS18B20_convert_temp().

    Fix by using s16 temperature value when converting to int.

    Fixes: 9ace0b4dab1c (w1: w1_therm: Add support for GXCAS GX20MH01 device.)
    Cc: stable
    Reported-by: Paweł Marciniak
    Signed-off-by: Ivan Zaentsev
    Link: https://lore.kernel.org/r/20210121093021.224764-1-ivan.zaentsev@wirenboard.ru
    Signed-off-by: Greg Kroah-Hartman

    Ivan Zaentsev
     

21 Jan, 2021

2 commits

  • Queue up found IDs in a buffer and run the callback once for each found ID
    at the end. This is necessary because we hold the bus_mutex during the
    whole scan, and some of the "add-device" callbacks deadlock as they
    themselves want to mutex_lock(bus_mutex).

    Acked-by: Evgeniy Polyakov
    Signed-off-by: Christian Vogel
    Link: https://lore.kernel.org/r/20210113195018.7498-3-vogelchr@vogel.cx
    Signed-off-by: Greg Kroah-Hartman

    Christian Vogel
     
  • Onewire addresses are 64bit family(8bit), unique_id(48bit), crc(8bit)
    (LSBt to MSB) and self-consistent: crc = crc8(family, unique).

    DS28E04-100 4096-Bit Addressable 1-Wire EEPROM with PIO have strap pins
    to set 7 LSB of the address, unfortunately without updating the crc
    part of the address. It is only consistent if all strap pins float high.
    [see datasheet 19-6134; Rev 12/11 page 6: 64-bit device id number]

    We therefore introduce a special handling of family 0x1c (DS28E04) to
    check address consistency with 7 LSBs of the unique_id set to 1.

    Acked-by: Evgeniy Polyakov
    Signed-off-by: Christian Vogel
    Link: https://lore.kernel.org/r/20210113195018.7498-2-vogelchr@vogel.cx
    Signed-off-by: Greg Kroah-Hartman

    Christian Vogel
     

12 Nov, 2020

1 commit

  • Duplicate attribute 'eeprom' is defined in:
    1) Documentation/ABI/testing/sysfs-driver-w1_therm
    2) Documentation/ABI/stable/sysfs-driver-w1_ds28e04

    Both drivers define an attribute: /sys/bus/w1/devices/.../eeprom
    with conflicting behavior.

    Fix by renaming the newer one in w1_therm.c to 'eeprom_cmd'.

    Reported-by: Mauro Carvalho Chehab
    Suggested-by: Greg Kroah-Hartman
    Link: https://lore.kernel.org/lkml/20201029152845.6bbb39ce@coco.lan/
    Signed-off-by: Ivan Zaentsev
    Link: https://lore.kernel.org/r/20201112064931.8471-1-ivan.zaentsev@wirenboard.ru
    Signed-off-by: Greg Kroah-Hartman

    Ivan Zaentsev
     

05 Oct, 2020

3 commits

  • kernel test robot rightly points out that w1_poll_completion() should be
    static, so mark it as such.

    Cc: Ivan Zaentsev
    Reported-by: kernel test robot
    Link: https://lore.kernel.org/r/20201005123703.GA800532@kroah.com
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     
  • The only usage of these structs is to assign their address to the fops
    field in the w1_family struct, which is a const pointer. Make them const
    to allow the compiler to put them in read-only memory.

    This was done with the following Coccinelle semantic patch
    (http://coccinelle.lip6.fr/):

    //
    @r1 disable optional_qualifier @
    identifier i;
    position p;
    @@
    static struct w1_family_ops i@p = {...};

    @ok1@
    identifier r1.i;
    position p;
    identifier s;
    @@
    static struct w1_family s = {
    .fops=&i@p,
    };

    @bad1@
    position p!={r1.p,ok1.p};
    identifier r1.i;
    @@
    i@p

    @depends on !bad1 disable optional_qualifier@
    identifier r1.i;
    @@
    static
    +const
    struct w1_family_ops i={};
    //

    Signed-off-by: Rikard Falkeborn
    Link: https://lore.kernel.org/r/20201004193202.4044-3-rikard.falkeborn@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Rikard Falkeborn
     
  • The fops field in the w1_family struct is never modified. Make it const
    to indicate that. Constifying the pointer makes it possible for drivers
    to declare static w1_family_ops structs const, which in turn will allow
    the compiler to put it in read-only memory.

    Reviewed-by: Sebastian Reichel
    Signed-off-by: Rikard Falkeborn
    Link: https://lore.kernel.org/r/20201004193202.4044-2-rikard.falkeborn@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Rikard Falkeborn
     

02 Oct, 2020

3 commits

  • On my platform (i.MX53) bus access sometimes fails with
    w1_search: max_slave_count 64 reached, will continue next search.

    The reason is the use of jiffies to implement a 200us timeout in
    mxc_w1_ds2_touch_bit().
    On some platforms the jiffies timer resolution is insufficient for this.

    Fix by replacing jiffies by ktime_get().

    For consistency apply the same change to the other use of jiffies in
    mxc_w1_ds2_reset_bus().

    Fixes: f80b2581a706 ("w1: mxc_w1: Optimize mxc_w1_ds2_touch_bit()")
    Cc: stable
    Signed-off-by: Martin Fuzzey
    Link: https://lore.kernel.org/r/1601455030-6607-1-git-send-email-martin.fuzzey@flowbird.group
    Signed-off-by: Greg Kroah-Hartman

    Martin Fuzzey
     
  • GX20MH01 device shares family number 0x28 with DS18B20. The device
    is generally compatible with DS18B20. Added are the lowest 2^-5, 2^-6
    temperature bits in Config register; R2 bit in Config register
    enabling 13 and 14 bit resolutions. It is powered up in 14 bit mode.

    Signed-off-by: Ivan Zaentsev
    Link: https://lore.kernel.org/r/20200904160004.87710-2-ivan.zaentsev@wirenboard.ru
    Acked-by: Evgeniy Polyakov
    Signed-off-by: Greg Kroah-Hartman

    Ivan Zaentsev
     
  • The conversion time of common DS18B20 clones deviates from
    datasheet specs. Allow adjustment and automatic measure of the
    conversion time.

    Add 'conv_time' sysfs attribute:
    *read*: Current conversion time in milliseconds.
    *write*:
    '0': Set default conversion time.
    '1': Measure and set the conversion time. Make a
    single temperature conversion, poll and measure
    an actual value. Measured value is increased
    by 20% for temperature drift. A new conversion
    time is returned by reading the same attribute.
    other positive value:
    Set the conversion time in milliseconds.

    The setting is active until a resolution change. Then it is reset to
    default conversion time for a new resolution.

    Add 'features' sysfs attribute to control optional driver settings
    per device. Bit masks to read/write (logical OR):
    1: Enable check for conversion success. If byte 6 of
    scratchpad memory is 0xC after conversion, and
    temperature reads 85.00 (powerup value) or 127.94
    (insufficient power) - return a conversion error.

    2: Enable poll for conversion completion. Generate read cycles
    after the conversion start and wait for 1's. In parasite
    power mode this feature is not available.

    There are some clones of DS18B20 with fixed 12 bit resolution. Make the
    driver verify the resolution by reading back the device after resolution
    change.

    Signed-off-by: Ivan Zaentsev
    Acked-by: Evgeniy Polyakov
    Link: https://lore.kernel.org/r/20200904160004.87710-1-ivan.zaentsev@wirenboard.ru
    Signed-off-by: Greg Kroah-Hartman

    Ivan Zaentsev
     

16 Jun, 2020

1 commit

  • There is a regular need in the kernel to provide a way to declare having a
    dynamically sized set of trailing elements in a structure. Kernel code should
    always use “flexible array members”[1] for these cases. The older style of
    one-element or zero-length arrays should no longer be used[2].

    [1] https://en.wikipedia.org/wiki/Flexible_array_member
    [2] https://github.com/KSPP/linux/issues/21

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

14 Jun, 2020

1 commit

  • Since commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
    '---help---'"), the number of '---help---' has been gradually
    decreasing, but there are still more than 2400 instances.

    This commit finishes the conversion. While I touched the lines,
    I also fixed the indentation.

    There are a variety of indentation styles found.

    a) 4 spaces + '---help---'
    b) 7 spaces + '---help---'
    c) 8 spaces + '---help---'
    d) 1 space + 1 tab + '---help---'
    e) 1 tab + '---help---' (correct indentation)
    f) 1 tab + 1 space + '---help---'
    g) 1 tab + 2 spaces + '---help---'

    In order to convert all of them to 1 tab + 'help', I ran the
    following commend:

    $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

27 May, 2020

4 commits

  • If irq flags are not cleared for certain operations we
    print an error message.

    Since this should never occur in normal operation, this
    patch is an optional safety-net and debugging tool.

    Signed-off-by: H. Nikolaus Schaller
    Link: https://lore.kernel.org/r/2de305d3046c7281a7123347899abbaa64c54fb8.1590255176.git.hns@goldelico.com
    Signed-off-by: Greg Kroah-Hartman

    H. Nikolaus Schaller
     
  • Since

    commit 27d13da8782a ("w1: omap-hdq: Simplify driver with PM runtime autosuspend")

    was applied,

    I did see timeouts and wrong values when reading a bq27000 connected
    to hdq of the omap3. This occurred mainly after boot but remained and
    only sometimes settled down after several reads.

    root@letux:~# time cat /sys/class/power_supply/bq27000-battery/uevent
    POWER_SUPPLY_NAME=bq27000-battery
    POWER_SUPPLY_STATUS=Discharging
    POWER_SUPPLY_PRESENT=1
    POWER_SUPPLY_VOLTAGE_NOW=0
    POWER_SUPPLY_CURRENT_NOW=0
    POWER_SUPPLY_CAPACITY=0
    POWER_SUPPLY_CAPACITY_LEVEL=Normal
    POWER_SUPPLY_TEMP=-2731
    POWER_SUPPLY_TIME_TO_EMPTY_NOW=0
    POWER_SUPPLY_TIME_TO_EMPTY_AVG=0
    POWER_SUPPLY_TIME_TO_FULL_NOW=0
    POWER_SUPPLY_TECHNOLOGY=Li-ion
    POWER_SUPPLY_CHARGE_FULL=0
    POWER_SUPPLY_CHARGE_NOW=0
    POWER_SUPPLY_CHARGE_FULL_DESIGN=0
    POWER_SUPPLY_CYCLE_COUNT=0
    POWER_SUPPLY_ENERGY_NOW=0
    POWER_SUPPLY_POWER_AVG=0
    POWER_SUPPLY_HEALTH=Good
    POWER_SUPPLY_MANUFACTURER=Texas Instruments

    real    0m15.761s
    user    0m0.001s
    sys     0m0.025s
    root@letux:~#

    Sometimes the effect did disappear after accessing
    the device multiple times, speed went up and results
    became correct.

    All this indicates that some interrupts from the hdq
    controller are lost by the driver.

    Enabling debugging revealed that there were spurious tx
    and rx timeouts, i.e. the driver does not always recognise
    interrupts. The main problem is that rx and tx interrupts
    share a single variable which was sometimes reset to
    0 wiping out other interrupts. And it was overwritten
    by a second interrupt, independent of whether the
    previous interrupt was already processed or not.

    This patch improves interrupt handling to avoid such
    races and loss of interrupt flags.

    The ideas are:
    * only the hdq_isr() sets bits in hdq_status
    * it does not reset any bits
    * it does wake_up() if any interrupt is pending
    * bits are only reset by the read/write/break functions
    if they were waited for
    * this makes sure that no interrupts can be lost
    * rx/tx/timeout bits are completely decoupled from each
    other (and not reset all after waiting for any of them)
    * which bits to reset is now specified by a new parameter
    to hdq_reset_irqstatus()
    * hdq_reset_irqstatus() also returns the state before
    resetting so that we can encapsulate the spinlock
    * this should now handle the case that the write and read
    are both already finished quickly before the hdq_write_byte()
    ends.
    * Or that two interrupts occur in succession before
    they are processed by the driver.
    Old code may have reset all status bits making the next
    hdq_read_byte() timeout.
    * the spinlock now always protects changing of bits in function
    hdq_reset_irqstatus() which could become a read-write-modify
    problem if the interrupt handler tries to read-modify-write
    exactly at the same moment
    * we add mutex protection also for hdq_write_byte() just to
    be safe to not to disturb a hdq_read_byte() triggered by
    some other thread/process.

    This patch was tested on a GTA04 and results in no
    boot problems any more. And first read after boot is now ok:

    root@letux:~# time cat /sys/class/power_supply/bq27000-battery/uevent
    POWER_SUPPLY_NAME=bq27000-battery
    POWER_SUPPLY_STATUS=Discharging
    POWER_SUPPLY_PRESENT=1
    POWER_SUPPLY_VOLTAGE_NOW=3970000
    POWER_SUPPLY_CURRENT_NOW=354144
    POWER_SUPPLY_CAPACITY=82
    POWER_SUPPLY_CAPACITY_LEVEL=Normal
    POWER_SUPPLY_TEMP=266
    POWER_SUPPLY_TIME_TO_EMPTY_NOW=7680
    POWER_SUPPLY_TIME_TO_EMPTY_AVG=7380
    POWER_SUPPLY_TECHNOLOGY=Li-ion
    POWER_SUPPLY_CHARGE_FULL=934856
    POWER_SUPPLY_CHARGE_NOW=763976
    POWER_SUPPLY_CHARGE_FULL_DESIGN=1233792
    POWER_SUPPLY_CYCLE_COUNT=82
    POWER_SUPPLY_ENERGY_NOW=2852840
    POWER_SUPPLY_POWER_AVG=1392840
    POWER_SUPPLY_HEALTH=Good
    POWER_SUPPLY_MANUFACTURER=Texas Instruments

    real 0m0.233s
    user 0m0.000s
    sys 0m0.025s
    root@letux:~#

    It was also tested with dev_dbg enabled and more
    printk that all activities behave correctly, especially
    hdq_write_byte(), hdq_read_byte(), omap_hdq_break().

    Not tested is omap_w1_triplet().

    Fixes: 27d13da8782a ("w1: omap-hdq: Simplify driver with PM runtime autosuspend")
    Cc: stable@vger.kernel.org # v5.6+
    Signed-off-by: H. Nikolaus Schaller
    Link: https://lore.kernel.org/r/68fc8623ae741878beef049273696d2377526165.1590255176.git.hns@goldelico.com
    Signed-off-by: Greg Kroah-Hartman

    H. Nikolaus Schaller
     
  • omap_w1_read_byte() should return -1 (or 0xff) in case of
    error (e.g. missing battery).

    The code accidentially overwrites the variable ret and not val,
    which is returned. So it will return the initial value 0 instead
    of -1.

    Fixes: 27d13da8782a ("w1: omap-hdq: Simplify driver with PM runtime autosuspend")
    Cc: stable@vger.kernel.org # v5.6+
    Acked-by: Tony Lindgren
    Signed-off-by: H. Nikolaus Schaller
    Link: https://lore.kernel.org/r/b2c2192b461fbb9b8e9bea4ad514a49557a7210b.1590255176.git.hns@goldelico.com
    Signed-off-by: Greg Kroah-Hartman

    H. Nikolaus Schaller
     
  • Otherwise it will corrupt the console log during debugging.

    Fixes: 7b5362a603a1 ("w1: omap_hdq: Fix some error/debug handling.")
    Cc: stable@vger.kernel.org
    Acked-by: Tony Lindgren
    Signed-off-by: H. Nikolaus Schaller
    Link: https://lore.kernel.org/r/cd0d55749a091214106575f6e1d363c6db56622f.1590255176.git.hns@goldelico.com
    Signed-off-by: Greg Kroah-Hartman

    H. Nikolaus Schaller
     

21 May, 2020

2 commits

  • The variable ret is being initialized with a value that is never read
    and it is being updated later with a new value. The initialization
    is redundant and can be removed.

    Addresses-Coverity: ("Unused value")
    Signed-off-by: Colin Ian King
    Link: https://lore.kernel.org/r/20200519154553.873413-1-colin.king@canonical.com
    Signed-off-by: Greg Kroah-Hartman

    Colin Ian King
     
  • The problem is that we change "p_args" to point to the middle of the
    string so when we free it at the end of the function it's not freeing
    the same pointer that we originally allocated.

    Fixes: e2c94d6f5720 ("w1_therm: adding alarm sysfs entry")
    Signed-off-by: Dan Carpenter
    Link: https://lore.kernel.org/r/20200520120019.GA172354@mwanda
    Signed-off-by: Greg Kroah-Hartman

    Dan Carpenter
     

15 May, 2020

6 commits

  • Adding bulk read support:
    Sending a 'trigger' command in the dedicated sysfs entry of bus master
    device send a conversion command for all the slaves on the bus. The sysfs
    entry is added as soon as at least one device supporting this feature
    is detected on the bus.

    The behavior of the sysfs reading temperature on the device is as follow:
    * If no bulk read pending, trigger a conversion on the device, wait for
    the conversion to be done, read the temperature in device RAM
    * If a bulk read has been trigger, access directly the device RAM
    This behavior is the same on the 2 sysfs entries ('temperature' and
    'w1_slave').

    Reading the therm_bulk_read sysfs give the status of bulk operations:
    * '-1': conversion in progress on at least 1 sensor
    * '1': conversion complete but at least one sensor has not been read yet
    * '0': no bulk operation. Reading temperature on ecah device will trigger
    a conversion

    As not all devices support bulk read feature, it has been added in device
    family structure.

    The attribute is set at master level as soon as a supporting device is
    discover. It is removed when the last supported device leave the bus.
    The count of supported device is kept with the static counter
    bulk_read_device_counter.

    A strong pull up is apply on the line if at least one device required it.
    The duration of the pull up is the max time required by a device on the
    line, which depends on the resolution settings of each device. The strong
    pull up could be adjust with the a module parameter.

    Updating documentation in Documentation/ABI/testing/sysfs-driver-w1_therm
    and Documentation/w1/slaves/w1_therm.rst accordingly.

    Signed-off-by: Akira Shimahara
    Link: https://lore.kernel.org/r/20200511203820.411483-1-akira215corp@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Akira Shimahara
     
  • Adding device alarms settings by a dedicated sysfs entry alarms (RW):
    read or write TH and TL in the device RAM. Checking devices in alarm
    state could be performed using the master search command.

    As alarms temperature level are store in a 8 bit register on the device
    and are signed values, a safe cast shall be performed using the min and
    max temperature that device are able to measure. This is done by
    int_to_short inline function.

    A 'write_data' field is added in the device structure, to bind the
    correct writing function, as some devices may have 2 or 3 bytes RAM.

    Updating Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

    Signed-off-by: Akira Shimahara
    Link: https://lore.kernel.org/r/20200511203801.411253-1-akira215corp@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Akira Shimahara
     
  • Optimizing temperature reading by reducing waiting conversion time
    according to device resolution settings, as per device specification.
    This is device dependent as not all the devices supports resolution
    setting, so it has been added in device family structures.

    The process to read the temperature on the device has been adapted in a
    new function 'convert_t()', which replace the former 'read_therm()', is
    introduce to deal with this timing. Strong pull up is also applied during
    the required time, according to device power status needs and
    'strong_pullup' module parameter.

    'temperature_from_RAM()' function is introduced to get the correct
    temperature computation (device dependent) from device RAM data.

    An new sysfs entry has been added to ouptut only temperature. The old
    entry w1_slave has been kept for compatibility, without changing its
    output format.

    Updating Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

    Signed-off-by: Akira Shimahara
    Link: https://lore.kernel.org/r/20200511203742.411039-1-akira215corp@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Akira Shimahara
     
  • The driver implement 2 hardware functions to access device RAM:
    * copy_scratchpad
    * recall_scratchpad
    They act according to device specifications.

    As EEPROM operations are not device dependent (all w1_therm can perform
    EEPROM read/write operation following the same protocol), it is removed
    from device families structures.

    Updating Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

    Signed-off-by: Akira Shimahara
    Link: https://lore.kernel.org/r/20200511203725.410844-1-akira215corp@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Akira Shimahara
     
  • Adding resolution sysfs entry (RW) to get or set the device resolution
    Write values are managed as follow:
    * '9..12': resolution to set in bit
    * Anything else: do nothing
    Read values are :
    * '9..12': device resolution in bit
    * '-xx': xx is kernel error when reading the resolution

    Only supported devices will show the sysfs entry. A new family has been
    created for DS18S20 devices as they do not implement resolution feature.

    The resolution of each device is check when the device is
    discover by the bus master, in 'w1_therm_add_slave(struct w1_slave *)'.
    The status is stored in the device structure w1_therm_family_data so
    that the driver always knows the resolution of each device, which could
    be used later to determine the required conversion duration (resolution
    dependent).

    The resolution is re evaluate each time a user read or write the sysfs
    entry.

    To avoid looping through the w1_therm_families at run time, the pointer
    'specific_functions' is set up to the correct 'w1_therm_family_converter'
    when the slave is added (which mean when it is discovered by the master).
    This initialization is done by a helper function
    'device_family(struct w1_slave *sl)', and a dedicated macro
    'SLAVE_SPECIFIC_FUNC(sl)' allow the access to the specific function of the
    slave device.

    'read_scratchpad' and 'write_scratchpad' are the hardware functions to
    access the device RAM, as per protocol specification.

    It cancel the former 'precision' functions, which was only set and never
    read (so not stored in the device struct).

    Updating Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

    Signed-off-by: Akira Shimahara
    Link: https://lore.kernel.org/r/20200511203708.410649-1-akira215corp@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Akira Shimahara
     
  • Adding ext_power sysfs entry (RO). Return the power status of the device:
    - 0: device parasite powered
    - 1: device externally powered
    - xx: xx is kernel error

    The power status of each device is check when the device is
    discover by the bus master, in 'w1_therm_add_slave(struct w1_slave *)'.
    The status is stored in the device structure w1_therm_family_data so
    that the driver always knows the power state of each device, which could
    be used later to determine the required strong pull up to apply on the
    line.

    The power status is re evaluate each time the sysfs ext_power read by
    a user.

    The hardware function 'read_powermode(struct w1_slave *sl)' act just as
    per device specifications, sending W1_READ_PSUPPLY command on the bus,
    and issue a read time slot, reading only one bit.

    A helper function 'bool bus_mutex_lock(struct mutex *lock)' is introduced.
    It try to aquire the bus mutex several times (W1_THERM_MAX_TRY), waiting
    W1_THERM_RETRY_DELAY between two attempt.

    Updating Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

    Signed-off-by: Akira Shimahara
    Link: https://lore.kernel.org/r/20200511203650.410439-1-akira215corp@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Akira Shimahara