You are not logged in.

#1 2023-06-13 23:43:15

train__wreck
Member
Registered: 2020-08-23
Posts: 32

[SOLVED] Set /sys var for USB device on plugin fails first time

I am trying to set up my Arch system so that fast charging is always enabled for my iphone. By default on boot it is not. Enabling it involves writing the string "Fast" to the file  /sys/class/power_supply/apple_mfi_fastcharge/charge_type. My first attempt at this was to use a udev rule that outputs "Fast" to the file. The rule is below:

SUBSYSTEM=="usb", ACTION=="add", ENV{ID_MODEL}=="iPhone", RUN+="/usr/bin/echo Fast > /sys/class/power_supply/apple_mfi_fastcharge/charge_type"

The problem is that when the system is (re)booted and the phone is plugged in, the  /sys/class/power_supply/apple_mfi_fastcharge directory doesn't exist, so the command fails and the phone charges slower than a turtle. If I unplug and replug, command works fine since the directory has already been created, and the fast charging proceeds as expected.

What would be an ideal way to solve this? I tried making a 2-line script that would mkdir -p the folder and then write the file, but I got the error "operation not permitted".  If nothing else I would just write an infinite bash loop script that periodically checks for the directory and writes the file, but this feels dumb. Thanks for any suggestions.

Last edited by train__wreck (2023-06-14 08:01:04)

Offline

#2 2023-06-14 07:07:44

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,659

Re: [SOLVED] Set /sys var for USB device on plugin fails first time

I tried making a 2-line script that would mkdir -p the folder

sysfs is a pseudo-filesystem, you're talking to the kernel this way. You cannot just create files and directories there, resp. it wouldn't make any sense.
The directory is created by the apple_mfi_fastcharge module, so I'd try to move that into the initramfs to hopefully load it early (before the udev rule for your iPhone hits)

Offline

#3 2023-06-14 08:00:25

train__wreck
Member
Registered: 2020-08-23
Posts: 32

Re: [SOLVED] Set /sys var for USB device on plugin fails first time

Yes putting the apple_mfi_fastcharge in MODULES in mkinitcpio.conf made the command work, though i did have to run it from a script (so the RUN string is "/usr/bin/bash /etc/fastcharge.sh", with the script having the echo command).

Thanks as always.

Offline

Board footer

Powered by FluxBB