Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charger smb1360: Increase timeout and current #314

Conversation

Jakko3
Copy link

@Jakko3 Jakko3 commented May 19, 2023

There has been an issue report pmaports #1949 that the charging of device bq-paella with charger smb1360 stops after 3 hours.

This PR disables the charging timeout in the devicetree of the devices using this charger. And additionally increases the charging current of the charger (hard-coded charging current as a temporary solution). More details can be found in the commit messages.

WIP: The changes are currently tested.

@Jakko3 Jakko3 marked this pull request as draft May 19, 2023 23:23
drivers/power/supply/smb1360.c Outdated Show resolved Hide resolved
drivers/power/supply/smb1360.c Show resolved Hide resolved
@Jakko3 Jakko3 force-pushed the msm8916/smb1360_temp_sol_pr branch from 60bd17a to e4dbd09 Compare June 3, 2023 20:52
@Jakko3
Copy link
Author

Jakko3 commented Jun 3, 2023

Changed comment and implementation of "fastcharge current", as discussed further above.

@Jakko3 Jakko3 force-pushed the msm8916/smb1360_temp_sol_pr branch from e4dbd09 to 01aa49a Compare June 3, 2023 21:03
@Jakko3
Copy link
Author

Jakko3 commented Jun 3, 2023

Rebased to msm8916/6.4-rc4.

I'm not very familiar with GitHub, it looks a bit strange with that list of all those commits up above. I hope I've done it correctly.

@Jakko3
Copy link
Author

Jakko3 commented Jun 3, 2023

Hm, nope, doesn't look like I've done the rebasing correctly. I'll try to fix this.

@Jakko3 Jakko3 changed the base branch from msm8916/6.4-rc1 to msm8916/6.4-rc4 June 3, 2023 21:11
@Jakko3
Copy link
Author

Jakko3 commented Jun 3, 2023

Ah, fixed that by changing the base in the GitHub user interface.

@Jakko3 Jakko3 force-pushed the msm8916/smb1360_temp_sol_pr branch from 01aa49a to 80dd6c7 Compare June 3, 2023 22:26
@Jakko3
Copy link
Author

Jakko3 commented Jun 3, 2023

Build failed because "mixing declarations and code". Therefore I moved the declarations to the beginning of function smb1360_hw_init().

@Jakko3 Jakko3 changed the title [WIP] Charger smb1360: Disable timeout and increase current Charger smb1360: Disable timeout and increase current Jun 3, 2023
@Jakko3 Jakko3 marked this pull request as ready for review June 3, 2023 22:59
@Jakko3
Copy link
Author

Jakko3 commented Jun 3, 2023

I removed the "draft" status and resolved the discussions so far.

We could wait a bit longer, maybe Random Modder can add some testing experience.

However, I think the current setting with "input current limit" at 800 mA and default AICL setting is the best compromise in the actual situation.

@stephan-gh
Copy link
Member

I guess the charging timeout might also exist to continue charging a faulty battery forever. Should we really remove it completely? With the higher input current limit, how likely is it that you'd still discharge the device under heavy usage?

@Jakko3
Copy link
Author

Jakko3 commented Jun 4, 2023

My impression was that the charging timeout is an alternative to the recharge cycle, which can be disabled. However, I can't think of a use case where this would be a good choice.

With a charging cable connected, stopping charging and switch to discharging is always a surprise to a user, I'd say.

As switching to (complete) discharging doesn't happen when reaching the recharge cycle, it would only happen if the device is floating between empty and full until the timeout kicks in. Setting the timeout to 13 hours, this is quite unlikely to happen. Hypothetically at weak power supply after e.g. 10 hours of notable computing load and thereafter 3 more hours of charging might not reach the recharge cycle. Although I can't think of a realistic scenario where this would happen. Watching movies at a long flight – but the passenger needs to leave the airplane at some point anyway. Using the phone as a navigation device in the car – but that shouldn't cause a computing load that draws as much power as even a weak power supply would provide. Yet possibly there are use scenarios that are beyond my imagination, I didn't want to risk a user running into an unexpecedly discharged battery in such extreme cases.

Another reason why I tended to disable the charging timeout was because there were some uncertainties about the behavior. One report was about switching to discharing after reaching 100 %. Another one was switching to discharging after several hours of recharging cycle. Both issues were neither understood nor could be reproduced. I wanted to avoid such things being caused by the charging timeout. However, the first issue should become unlikely when setting the timeout to 13 hours. The second one actually shouldn't happen, there is no obvious relation to the charging timeout.

In the downstream devicetrees, some timeouts were set to 0 and some to 768 minutes. That doesn't help for the decision neither.

Another guideline could be the default setting of the chip. In the second code review discussion above I did a fastboot oem smb1360-reload and the dmesg dump thereafter shows the timeout setting before and after the driver applies its settings. The timeout is set in register 0x0a CFG_SFY_TIMER_CTRL_REG. The default value of that register seems to be 0x0a (00001010). After the driver probed, it was set to 0x2a (00101010). The SAFETY_TIME_DISABLE_BIT is BIT(5), this disable bit is not set by default (timeout enabled) and later got set by the testing driver as currently intended by this pull request (timeout disabled). The time is defined in bits[3:2], which are "10" in both cases. The possible times are 192, 384, 768, and 1536 minutes, so these bits at "10" are 768 minutes (approx. 13 hours). Therefore the default setting of the chip is to enable the timeout at 768 minutes.

I now also realize that the name of this feature in the register is actually "safety time" and not "charging timeout".

Summing up, it looks reasonable to set the "safety time" to 768 minutes. I'll change the pull request within the next days.

@Jakko3 Jakko3 force-pushed the msm8916/smb1360_temp_sol_pr branch from 80dd6c7 to cae4101 Compare June 5, 2023 19:37
@Jakko3 Jakko3 changed the title Charger smb1360: Disable timeout and increase current Charger smb1360: Increase timeout and current Jun 5, 2023
@Jakko3
Copy link
Author

Jakko3 commented Jun 5, 2023

As discussed, I enabled the charging timeout, set it to 768 minutes (approx. 13 hours) and adapted the commit message.

The charging currents are not yet handled. Actually they should be set in
runtime based on connector type detection (like an extcon device but for
smb1360 a more complicated mechanism in USB PHY layer is needed, e.g. like
in downstream [1]). The upper limits for the charging currents should be read
from the devicetree.

As a temporary solution, set hard-coded charging currents in the
smb1360_hw_init() function.

[1] https://github.com/bq/aquaris-X5/blob/aquaris-X5_5.x/drivers/usb/phy/phy-msm-usb.c#L2959-L3112

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
The currently implemented charging timeout of 192 minutes (approx. 3 hours)
turned out to be too short. When reaching the timeout, the device starts
to discharge even though the charging cable is still attached.

Therefore increase the charging timeout to 768 minutes (approx. 13 hours).
This is the default setting in the smb1360 chip and also the value of some of
the downstream devicetrees.

Disabling the charging timeout entirely was considered but discarded in
favor of safety. The timeout could avoid charging a faulty battery for too
long. On the other hand, the probability of reaching the timeout of 13 hours
by regular usage is considered very low – the timeout doesn't apply when
the battery is reaching full state and the charger switches to recharge cycle.

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
@Jakko3 Jakko3 force-pushed the msm8916/smb1360_temp_sol_pr branch from cae4101 to 2bd3740 Compare June 25, 2023 09:13
@Jakko3
Copy link
Author

Jakko3 commented Jun 25, 2023

From my point of view smb1360_hw_init() is the right place to do the initial setup. It's the function where the basic settings are processed. Also, &smb->delayed_init_work gets scheduled at the end of smb1360_probe() [1], after smb1360_hw_init() has been performed [2] and the power supply registred [3].

[1] https://github.com/msm8916-mainline/linux/blob/msm8916/6.4-rc4/drivers/power/supply/smb1360.c#L1729-L1730
[2] https://github.com/msm8916-mainline/linux/blob/msm8916/6.4-rc4/drivers/power/supply/smb1360.c#L1680-L1684
[3] https://github.com/msm8916-mainline/linux/blob/msm8916/6.4-rc4/drivers/power/supply/smb1360.c#L1708-L1714

On the USB_500 quirk: I couldn't confirm the issue on my device. I'm on smb1360 chip rev. 3, device bq-paella. I also tried fastboot oem smb1360-reload and USB_100 before going to USB_AC, haven't noticed anything strange. Therefore I would skip the quirk for now, not adding a quirk without knowing why. If it later turns out that under certain circumstances or on other chip revisions the input current limit gets stuck at a low level, we still can add the quirk later on.

The other suggestions I have implemented:

  • Moved setting the fastcharge current into a separate function.
  • Corrected multi-line comment style.
  • Applied same order as downstream: input current limit, fastcharge current, USB speed bit.

I changed and extended the comments on the fastcharge currrent and hope it's ok that way. Otherwise let me know if you have suggestion for improvement.

Additionally, in the comments I changed wording "extcon cable type" to a more general "connector type detection", as you explained further above in the second collapsed review the diffiulties on detecting the extcon cable type and the need of implemeting it in the USB PHY layer. And in the commit message I added a more specific hint to USB PHY layer incl. the downstream example (for bq-paella).

@stephan-gh
Copy link
Member

Integrated this into wip/msm8916/6.5-rc4, thanks again for making the changes :)

@stephan-gh stephan-gh closed this Aug 2, 2023
M0Rf30 pushed a commit to msm8953-mainline/linux that referenced this pull request Feb 17, 2024
[ Upstream commit 5d1935a ]

When we online resize an ext4 filesystem with a oversized flexbg_size,

     mkfs.ext4 -F -G 67108864 $dev -b 4096 100M
     mount $dev $dir
     resize2fs $dev 16G

the following WARN_ON is triggered:
==================================================================
WARNING: CPU: 0 PID: 427 at mm/page_alloc.c:4402 __alloc_pages+0x411/0x550
Modules linked in: sg(E)
CPU: 0 PID: 427 Comm: resize2fs Tainted: G  E  6.6.0-rc5+ msm8916-mainline#314
RIP: 0010:__alloc_pages+0x411/0x550
Call Trace:
 <TASK>
 __kmalloc_large_node+0xa2/0x200
 __kmalloc+0x16e/0x290
 ext4_resize_fs+0x481/0xd80
 __ext4_ioctl+0x1616/0x1d90
 ext4_ioctl+0x12/0x20
 __x64_sys_ioctl+0xf0/0x150
 do_syscall_64+0x3b/0x90
==================================================================

This is because flexbg_size is too large and the size of the new_group_data
array to be allocated exceeds MAX_ORDER. Currently, the minimum value of
MAX_ORDER is 8, the minimum value of PAGE_SIZE is 4096, the corresponding
maximum number of groups that can be allocated is:

 (PAGE_SIZE << MAX_ORDER) / sizeof(struct ext4_new_group_data) ≈ 21845

And the value that is down-aligned to the power of 2 is 16384. Therefore,
this value is defined as MAX_RESIZE_BG, and the number of groups added
each time does not exceed this value during resizing, and is added multiple
times to complete the online resizing. The difference is that the metadata
in a flex_bg may be more dispersed.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20231023013057.2117948-4-libaokun1@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
M0Rf30 pushed a commit to M0Rf30/linux that referenced this pull request Apr 13, 2024
[ Upstream commit a51cd6b ]

In case when is64 == 1 in emit(A64_REV32(is64, dst, dst), ctx) the
generated insn reverses byte order for both high and low 32-bit words,
resuling in an incorrect swap as indicated by the jit test:

[ 9757.262607] test_bpf: msm8916-mainline#312 BSWAP 16: 0x0123456789abcdef -> 0xefcd jited:1 8 PASS
[ 9757.264435] test_bpf: msm8916-mainline#313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 ret 1460850314 != -271733879 (0x5712ce8a != 0xefcdab89)FAIL (1 times)
[ 9757.266260] test_bpf: msm8916-mainline#314 BSWAP 64: 0x0123456789abcdef -> 0x67452301 jited:1 8 PASS
[ 9757.268000] test_bpf: msm8916-mainline#315 BSWAP 64: 0x0123456789abcdef >> 32 -> 0xefcdab89 jited:1 8 PASS
[ 9757.269686] test_bpf: msm8916-mainline#316 BSWAP 16: 0xfedcba9876543210 -> 0x1032 jited:1 8 PASS
[ 9757.271380] test_bpf: msm8916-mainline#317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 ret -1460850316 != 271733878 (0xa8ed3174 != 0x10325476)FAIL (1 times)
[ 9757.273022] test_bpf: msm8916-mainline#318 BSWAP 64: 0xfedcba9876543210 -> 0x98badcfe jited:1 7 PASS
[ 9757.274721] test_bpf: msm8916-mainline#319 BSWAP 64: 0xfedcba9876543210 >> 32 -> 0x10325476 jited:1 9 PASS

Fix this by forcing 32bit variant of rev32.

Fixes: 1104247 ("bpf, arm64: Support unconditional bswap")
Signed-off-by: Artem Savkov <asavkov@redhat.com>
Tested-by: Puranjay Mohan <puranjay12@gmail.com>
Acked-by: Puranjay Mohan <puranjay12@gmail.com>
Acked-by: Xu Kuohai <xukuohai@huawei.com>
Message-ID: <20240321081809.158803-1-asavkov@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
barni2000 pushed a commit to msm8953-mainline/linux that referenced this pull request Jun 21, 2024
[ Upstream commit 8ecf3c1 ]

Recent additions in BPF like cpu v4 instructions, test_bpf module
exhibits the following failures:

  test_bpf: #82 ALU_MOVSX | BPF_B jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
  test_bpf: #83 ALU_MOVSX | BPF_H jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
  test_bpf: #84 ALU64_MOVSX | BPF_B jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
  test_bpf: #85 ALU64_MOVSX | BPF_H jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
  test_bpf: #86 ALU64_MOVSX | BPF_W jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)

  test_bpf: #165 ALU_SDIV_X: -6 / 2 = -3 jited:1 ret 2147483645 != -3 (0x7ffffffd != 0xfffffffd)FAIL (1 times)
  test_bpf: #166 ALU_SDIV_K: -6 / 2 = -3 jited:1 ret 2147483645 != -3 (0x7ffffffd != 0xfffffffd)FAIL (1 times)

  test_bpf: #169 ALU_SMOD_X: -7 % 2 = -1 jited:1 ret 1 != -1 (0x1 != 0xffffffff)FAIL (1 times)
  test_bpf: #170 ALU_SMOD_K: -7 % 2 = -1 jited:1 ret 1 != -1 (0x1 != 0xffffffff)FAIL (1 times)

  test_bpf: #172 ALU64_SMOD_K: -7 % 2 = -1 jited:1 ret 1 != -1 (0x1 != 0xffffffff)FAIL (1 times)

  test_bpf: msm8916-mainline#313 BSWAP 16: 0x0123456789abcdef -> 0xefcd
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 301 PASS
  test_bpf: msm8916-mainline#314 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 555 PASS
  test_bpf: msm8916-mainline#315 BSWAP 64: 0x0123456789abcdef -> 0x67452301
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 268 PASS
  test_bpf: msm8916-mainline#316 BSWAP 64: 0x0123456789abcdef >> 32 -> 0xefcdab89
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 269 PASS
  test_bpf: msm8916-mainline#317 BSWAP 16: 0xfedcba9876543210 -> 0x1032
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 460 PASS
  test_bpf: msm8916-mainline#318 BSWAP 32: 0xfedcba9876543210 -> 0x10325476
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 320 PASS
  test_bpf: msm8916-mainline#319 BSWAP 64: 0xfedcba9876543210 -> 0x98badcfe
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 222 PASS
  test_bpf: msm8916-mainline#320 BSWAP 64: 0xfedcba9876543210 >> 32 -> 0x10325476
  eBPF filter opcode 00d7 (@2) unsupported
  jited:0 273 PASS

  test_bpf: msm8916-mainline#344 BPF_LDX_MEMSX | BPF_B
  eBPF filter opcode 0091 (@5) unsupported
  jited:0 432 PASS
  test_bpf: msm8916-mainline#345 BPF_LDX_MEMSX | BPF_H
  eBPF filter opcode 0089 (@5) unsupported
  jited:0 381 PASS
  test_bpf: msm8916-mainline#346 BPF_LDX_MEMSX | BPF_W
  eBPF filter opcode 0081 (@5) unsupported
  jited:0 505 PASS

  test_bpf: torvalds#490 JMP32_JA: Unconditional jump: if (true) return 1
  eBPF filter opcode 0006 (@1) unsupported
  jited:0 261 PASS

  test_bpf: Summary: 1040 PASSED, 10 FAILED, [924/1038 JIT'ed]

Fix them by adding missing processing.

Fixes: daabb2b ("bpf/tests: add tests for cpuv4 instructions")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/91de862dda99d170697eb79ffb478678af7e0b27.1709652689.git.christophe.leroy@csgroup.eu
Signed-off-by: Sasha Levin <sashal@kernel.org>
@Jakko3 Jakko3 deleted the msm8916/smb1360_temp_sol_pr branch October 14, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants