libera/#maemo-leste/ Thursday, 2022-11-10

freemangordonuvos: well, it seems that batd always starts with 1800 mA when a charger is detected08:27
freemangordonthis is logcat for a Nokia wall charger (AC 10E) https://pastebin.com/9wRX7kfH08:29
uvosfreemangordon: thats correct a "dumb" charger (ie data pins tied) is assumed to be able to handle at least 2A this isent a spec but was common practice when the d4 was designed. this we can implement fairly easy10:09
uvosthe greater problem from a safty perspective is that on a smart port10:09
uvosd4 dosent negotiate for power, either via usb2.0 spec to get 500mA or using one of the qc specs for more10:10
uvos(In leste here, the d4 negotiates for power in android via 2.0 spec)10:10
uvosatm for instance pluging in a d4 into my xt1602 make it resett it because it can only output 30mA10:11
uvoscould cause damage alos10:11
Wizzupuvos: this week or weekend I'll have time for droid 3 tests, do you have a refresher on what you needed me to do?10:22
Wizzuprather what to dump/analyse10:22
Wizzupbtw: got a mail from a happy d4 user11:17
Wizzupsomething about the modem in the US, but also:11:17
WizzupSo i have a week testing the Motorola Moserati and Mameo Leste then i really like how so good feeling. Thank you for the work!11:17
uvos__Wizzup: so we need: full cpcap dumps, while loaded and while idle11:22
uvos__we need a dump of the emif registers (see omap4 trm)11:22
uvos__also loaded and idle11:22
uvos__we need dumps of the led cpcap registers at different keyboard and display brightnesses11:22
uvos__we require a dump of the lm i forget the number led controller too but that might be hard to pull off on android11:23
uvos__that should be a start11:23
uvos__nice @ user11:25
uvos__probubly a d3 would be good for him, being in us11:25
uvos__or bionic11:25
WizzupI did mention the bionic11:33
Wizzupcheck @ data11:43
freemangordonuvos__: detecting usb/charger should be easy11:43
freemangordondetecting the type of USB I am not sure11:46
uvos__right unfortinatly dumb chargers are getting a bit rare, usally you get qc implementing smat ports these days11:46
uvos__*smart11:46
uvos__but detecting tied usb data pins is a start11:46
uvos__no doubt11:46
freemangordonare you sure d4 ever draws more than 500mA from USB port?11:47
uvos__you cant draw 500mA from a usb port is the problem11:47
uvos__you have to ask the port11:47
uvos__500mA is just the max you could ask for in usb2.011:47
freemangordonI see11:47
freemangordondoes d4 android fullows that?11:47
uvos__yes11:47
freemangordonok11:48
freemangordonstill, I will start with dumb/fast charger detection11:48
uvos__also no android dosent implement usb qc11:49
uvos__that wasent around at the time11:49
uvos__it could tho11:49
freemangordondo you know how wall charger (d+d- short) can be distinguished from 2.4 A charger?11:49
uvos__but this is soemthing for later11:49
freemangordonlike, is there some difference in resistance, or ID pi or something?11:49
uvos__not sure what you mean, the dumb chargers cant be identified11:50
uvos__you just have to assume something11:50
uvos__this was a huge issue11:50
uvos__and is the reason why usb qc exists11:50
uvos__its usualy safe to assume 2a11:50
uvos__this seams to have been most common practivce11:51
uvos__*practice11:51
freemangordonI am not sure 2.4A charger I have here is a dumb one11:51
uvos__it  might implement usb qc11:51
uvos__of some kind11:51
freemangordonbecause it has 2 outputs, one marker as "1A", which is wallcharger for sure11:51
uvos__this allows you to negotate up to 65W or so11:51
freemangordon*marked11:51
freemangordonisn;t that USB C?11:52
uvos__no thats usb pd11:52
freemangordonBC1.2?11:52
uvos__yes 65w might be over usb c only not sure11:52
uvos__anyhow you can negotiate more than 500mA after usb2.011:52
uvos__3.0 base spec supports 1a allready i think and then theres more extensions11:53
uvos__it gets pretty complicated ;)11:53
freemangordonsomething with d lines resistance?11:53
uvos__no, same protocoll as used in 2.0 to negotiate for 500mA11:53
uvos__at least for 3.0 base11:53
uvos__idk how the more advance stuff works11:53
uvos__where you can ask for different voltages too etc11:54
freemangordonah, this is something that is out of control of SW, I guess11:54
uvos__no idea11:54
uvos__i pretty much checked out after usb 3.011:54
uvos__:P11:54
uvos__usb spec: USB devices shall limit the power they consume from VBUS to one unit load or less until configured.11:57
uvos__thats 100uA11:57
freemangordonright11:57
freemangordonbut, this is what musb shall already do, no?11:58
sicelouvos__: freemangordon: you call the chargers dumb? anyway "the dumb chargers cant be identified" ... can't be exactly correct. in some cases at least, the identification of the 'dumb charger' as you call it happens in the pmic. there's no assumption. it knows when the d-pins are shorted11:58
freemangordonsicelo: I call it "wall charger" :)11:59
freemangordonand yes, we can detect d lines shortened11:59
siceloi'd call it that too :-)11:59
uvos__sicelo: dumb charges cant be idenfied in terms of capapbiliy11:59
uvos__there are 1A devices with pins shorted and 3A11:59
freemangordonright12:00
freemangordonI think originally it was 1A12:00
sicelookay. that's a different statement now12:00
freemangordonI wonder how android managed to correctly identify 1200 mA12:00
freemangordonthis is what nokia charger is capable of12:01
freemangordonstill I am not sure that cpcap-charger is responsible for any USB negotiation12:02
freemangordonIIUC it shall ask usb driver for remote port parameters and adhere to it, no?12:02
uvos__no12:02
uvos__the slave supplies the host with a series of configurations12:03
uvos__and the host chooses one12:03
freemangordonok12:03
freemangordonbut this is not that charger driver job to do it12:03
freemangordonbut usb driver12:03
uvos__sure but they must communicate somehow obv12:04
freemangordonright12:04
freemangordonlemme see what gets negotiated here12:04
freemangordonbut usb driver12:04
freemangordon*by12:04
sicelofreemangordon: just wild guess ... i see 11-10 09:26:00.633   177   177 I BATTD   : set_charge_current=130012:05
sicelo11-10 09:26:01.642   177   177 I BATTD   : set_charge_current=120012:05
uvos__so on some usb chips12:05
uvos__just takling form expieriance working embedded stuff12:05
siceloso maybe it just adjusts what it can pull vs what it can get ... and thus ends up at 120012:05
uvos__the usb chip dose everything in hw/fw12:05
uvos__wrt negotation with host12:05
uvos__dont know how typical this is on smartphones12:06
siceloat least on N900 it is12:06
sicelothe negotiation is done by the phy (isp1707)12:06
freemangordonsicelo: ok, but how does it know that it can't draw 1800?12:06
sicelodoes it ever do 1800 (assuming an 1800-capable charger)?12:08
freemangordonI guess yes12:08
uvos__eh 1800 is aufully close to 1c12:08
uvos__the reccomended speed to charge a lipo....12:09
uvos__since the d4 has 1750mah batt 1800 is esentally 1c12:09
freemangordonuvos__: this is the current drawn from the charger, not charging current ;)12:09
uvos__right12:09
uvos__still they may have done this to ensure charging speed never exceeds 1c12:09
uvos__possibly12:09
sicelofreemangordon: so yes, as you stated, it starts by attempting to pull 1800. evidently it notices this fails, then switches to 1300, etc. until it lands on the highest that it can really pull12:09
freemangordonno12:10
freemangordonI doubt it can load to 1800mA by will12:10
uvos__on dumb chargers i dont12:10
uvos__phones breaking weak dumb chargers was common and the reason for better specs with usb 3+12:11
uvos__it might really be just monitoring votlage drop12:11
uvos__if a dumb charger is detected12:11
uvos__on a smart port however, yes, no it negotiates12:11
freemangordonvoltage drop?12:11
uvos__if vbus drops below a threshold cpcap generates an irq12:12
freemangordonhmm, hmm12:12
freemangordonbut still, we need to load12:12
freemangordonor, it sets to max, if irq comes , it reduces max current, etc12:12
freemangordondo you think it wokrs like that?12:13
uvos__i hope it goes the other way12:13
uvos__but yes this might be what it dose on a dumb charger12:13
freemangordonnot really, by looking at batd code and logcat12:13
uvos__ok12:13
freemangordonit seems to always set ititial max to 180012:14
freemangordon*initial12:14
uvos__are you using a motorola charger btw12:15
uvos__or a random one12:15
uvos__its possible motorola did soemthing totaly cusom on stock chargers12:15
uvos__samsung for sure did12:15
uvos__(some codeing with voltage deviders on data pins)12:15
uvos__but this was not wide spread12:15
freemangordonsamsung/iqos/nokia/cellularline/asus battery pack :)12:16
uvos__ok what vintage are we talking here?12:16
sicelotbh it's interesting for this one to start with 1800 and work its way down. N900/bq24150 starts with 100mA, then 500, and finally 180012:16
freemangordonsicelo: it starts with 1800 when it detects wall charger12:17
freemangordonuvos__: what do you mean "vintage". only Nokia one is really old12:17
freemangordonI am testing with different ones to see how it works12:17
uvos__ie before usb 3.0 and qc specs12:17
uvos__ie is just a dumb charger with pins tied12:18
freemangordonI bet most of the charger I have here are qc ones12:18
freemangordon*chargers12:18
freemangordonfor sure cellularline and battery pack are12:18
uvos__ok12:18
freemangordonnot that they are detected by d4 though12:19
freemangordonthey are treated like wall chargers if you ask me12:19
uvos__not sure how it knows to do that12:19
freemangordoncpcap does it12:19
freemangordonthere are several interrupts12:19
uvos__sure but how it knows that a qc port is not a normal usb port12:19
uvos__ie is to be handled like a dumb charger12:20
freemangordonah12:20
freemangordonwell, seems some kind of handshake happens12:20
uvos__hmm have to look at specs12:20
freemangordonlook at MC13783UG.pdf12:21
freemangordonchapter 812:21
uvos__ok12:21
freemangordonuvos__: seems 200k on ID pin means "Type 1 charger" and 442k "Type 2 Charger"12:38
uvos__non universal extension12:40
uvos__since you dont even have the id pin12:40
uvos__on most chargers12:40
freemangordonthe point is that ID pin can be used to detect carkit accessories12:41
uvos__sure12:41
freemangordonand there are 2 types of carckit chargers it seems12:41
freemangordon*carkit12:41
uvos__also lapdock is special probubly12:41
uvos__but most chargers have just a usba so the id pin dosent help there12:41
freemangordonhmm, right12:41
freemangordonok, so, lets assume d4 cannot detect anything but wall charger and move on12:42
uvos__well and usb 2.0 power12:42
freemangordonright12:42
freemangordonthough, I wonder where is that data available (max port current)12:43
uvos__the usb driver must send a (or list) of configureattions supported12:44
uvos__this incl power draw12:44
uvos__and if the host reqjects the configureation the device dosent charge, this works ok if i connect d4 to xt1602 while running12:44
freemangordonyeah, maybe, I just have to find where it sends that data12:44
uvos__while running android12:44
freemangordonok12:44
freemangordonbut still, max port current should be available somewhere12:45
uvos__sure you can query for it too12:45
uvos__i dosent seam like android dose this tho12:45
freemangordonwhere?12:45
uvos__from the host i mean12:45
uvos__android dosent seam to obay anything but the host rejecting the configuration tho12:46
freemangordonah12:46
uvos__since it just dosent charge12:46
uvos__instead of taking less12:46
uvos__then again maybe 30mA is just to little for it to bother with12:46
uvos__it might when offered 100mA12:46
freemangordonok, but I wonder how cpcap-charger can get that info12:47
uvos__no idea12:48
uvos__maybe its just cpcap-uc's doing12:48
uvos__i would make some sense to put this safty critical feature (dont charge if host rejects) into fw12:48
freemangordonI doubt we cannot get USB port max current draw12:48
uvos__sure but maybe the motorola driver dosent12:49
uvos__(idk just speculateing)12:49
uvos__if you cant find it12:49
freemangordonwell, I don't know where it is supposed to be, to start with :)12:49
freemangordontmlind: ping12:51
freemangordonhmm, I think configurations are done via gadgetfs13:01
freemangordonright now we ahve only one configuration with maxPower of 2mA, IIUC13:01
freemangordonuvos__: so, in order to do what android does, I think we shall set CONFIG_USB_GADGET_VBUS_DRAW=50013:03
freemangordonthat way your XT_whatever will reject the configuration13:04
freemangordonat least you can try it13:04
freemangordonbut I am almost sure this will fix we breaking the specs13:05
uvos__how would cpcap-charger (mainline) here know to not acctivate charging when the configuration is rejected13:05
freemangordonI think if configuration is rejected, there will be no USB interrupt13:06
uvos__the device has to avoid taking current when rejected the host dosent turn off power or anything like that13:06
uvos__freemangordon: ok13:06
freemangordonstill, wild guess, but we can at least try13:07
freemangordonhmm, lemme check what is the max port current of the hubs I have around13:07
uvos__aside from otg ports and some laptops13:07
uvos__i think <500mA ports are pretty rare13:08
uvos__you could use another mapphone as the host13:08
uvos__its also dose 30mA max i think13:08
uvos__or something like that13:08
freemangordonwell, 4 ports non-powered hub should not report 500 mA/port, no?13:09
uvos__it can13:09
freemangordonI know13:09
uvos__if just one slave is connected13:09
freemangordonbut it should not13:09
uvos__ok13:09
freemangordonI am checking what my reports13:09
freemangordonMaxPower              100mA13:12
freemangordon:)13:12
freemangordonalso, I am sure I hade some tool around that I was able to switch individual ports o/off13:13
uvos__some fancy hubs can do that13:14
uvos__yeah13:14
freemangordonID 05e3:0608 Genesys Logic, Inc. Hub13:14
uvos__no idea :P13:14
freemangordona couple of years ago I was playing with it13:15
freemangordonjust have to remember what I did back then13:15
freemangordonIIRC I was also able to control max power13:15
freemangordonuhubctrl ;)13:16
freemangordonuvos__: ok, so far I was able to find this: https://elixir.bootlin.com/linux/v5.18.19/source/drivers/usb/musb/musb_gadget.c#L162417:09
freemangordonprintk() there shows that it is called, with correct mA17:09
freemangordonant it turn it calls   usb_phy_set_power()17:10
freemangordon*and17:10
sicelofreemangordon: while there, how would one use printk (or some other facility) to see if *gadget contains correct parameters (using that function as an example)17:12
freemangordonnot sure I understand the question17:13
freemangordonprintk is like printf, more or less17:13
siceloi guess in that function, you can see the mA is correct because it's passed as an int already. how would you inspect *gadget, since that's a struct?17:13
freemangordonjust dereference the structure17:13
freemangordongadget->struct_member17:13
freemangordonfor example:17:14
freemangordonprintk("%s %s\n",  __FUNCTION__, gadget->name);17:15
siceloalright. thanks. i guess i was doing it correctly then ... but i suppose i must spend more time with the struct17:17
sicelobasically i wanted to see what *dev really contains in https://elixir.bootlin.com/linux/v5.18.19/source/drivers/base/platform.c#L43517:17
freemangordonif you expect things like js "console.log(JSON.stringify(object))"17:17
freemangordonthere is no such thing :)17:17
freemangordonyou must print meber by member17:17
freemangordon*member17:17
uvos__THIS IS C17:17
freemangordonmhm17:17
uvos__:P17:17
uvos__you could run a debugger on the kernel and have gdb print the struct17:18
uvos__but not on d417:18
sicelofreemangordon: because the error is "[    1.389648] musb-hdrc musb-hdrc.0.auto: error -ENXIO: IRQ mc not found" ... it's that function which should find this 'mc' IRQ17:19
uvos__dose the n900 debug kit have jtag?17:19
uvos__btw17:19
uvos__just curious17:20
freemangordonsicelo: something is missing in the DTS17:20
siceloif i hardcore the IRQ from DTS in musb/musb_core.c, it works, so i think this is what i should follow until i find out why the function can't get it correctly17:20
sicelofreemangordon: the mc interrupt is there in dts, and it's correct.17:20
freemangordoncould it be that DTB is too big?17:21
freemangordonI remember there were some issues with attached DTBs17:21
freemangordonalso, do you see that irq in /sys/firmware where it is expected?17:21
sicelohttps://elixir.bootlin.com/linux/v5.18.19/source/arch/arm/boot/dts/omap3.dtsi#L90317:24
freemangordonok, but do you see the same on the device17:24
freemangordonin /sys/firmware/...17:24
sicelo sys firmware? mmm, i can check.17:25
freemangordonyes, you have DTB there visible on a booted system17:25
freemangordonalso, if you decompile the DTB, doo you see that interrupt there?17:26
siceloat least with decompiled dtb, it's there17:31
sicelo                        interrupts = <0x5c 0x5d>;17:31
sicelo                        interrupt-names = "mc\0dma";17:31
freemangordoncheck on the device17:32
freemangordoncould be broken attached DTB17:32
buZzsicelo: mc\0dma might be wrong?17:33
buZzshouldnt it be just 'mc'17:34
freemangordonuvos__: ugh, this is what is bugging us, for start https://elixir.bootlin.com/linux/v5.18.19/source/drivers/usb/musb/musb_gadget.c#L162817:34
freemangordonbuZz: there are 2 interrupts, see dts17:34
buZzoh, right, but \0 as seperator?17:35
freemangordonyep, that17:35
freemangordon's fine17:35
buZzi see stuff like ; interrupt-names = "rx", "tx";17:36
uvos__freemangordon: and who shal support that? omap phy?17:36
buZzon https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/resource-names.txt17:36
freemangordonuvos__: the point is that this function must not check for  set_power()17:36
freemangordonsee https://elixir.bootlin.com/linux/v5.18.19/source/include/linux/usb/phy.h#L28817:37
freemangordonthe check is there, but after usb_phy_set_charger_current() is called17:37
freemangordonusb_phy_set_charger_current() calls notifiers17:38
freemangordon(in theory)17:38
freemangordonI registered in cpcap_charger, but callback is not called, besides for VBUS17:38
buZzwe cant set the constant charging voltage above 4.2v yet, can we?17:39
freemangordonyes, we can17:39
buZzi only succeeded in setting it below, not above17:39
buZzwithout kernel mods?17:39
freemangordonyes17:39
freemangordonbut you have to set ti in /usb, not in /battery17:39
freemangordonsome bug I guess17:39
buZz:O what am i doing wrong then,  shouldnt it be > 1651429464 <uvos> echo 4300000 > constant_charge_voltage17:39
buZzwell, if i set it above 4200000 it doesnt stick , but 4100000 works17:40
* buZz tries again :P17:40
sicelo " but you have to set ti in /usb, not in /battery" .. isn't it correct? /usb is the charger17:42
buZzfreemangordon: see; http://space.nurdspace.nl/~buzz/maemo/2022-11-10-174316_960x540_scrot.png17:44
buZzits not taking17:44
freemangordonno idea then, maybe there is some hard limit to be fixed17:44
buZzyeah i guess, should i check my diff for my 'explosive droid4' kernel? :P17:45
uvos__yes it being in usb makes perfect sense17:46
uvos__that is the charger17:46
uvos__it should work, it worked on my device before17:47
uvos__its possible you also have to ajust something in battery17:47
buZzdoes it currently on the latest -devel ?17:47
uvos__cant check rn17:47
buZzah ok17:47
uvos__i dont have a battery it would detect as 4.3517:47
buZzAHA!17:49
buZzi need to do '4300000' > /sys/class/power_supply/battery/constant_charge_voltage -first-17:49
uvos__right17:49
uvos__thats expected17:49
buZz-then- '4300000' > /sys/class/power_supply/usb/constant_charge_voltage works :D17:49
uvos__the charger and the battery have to agnolage17:50
uvos__er acknowledge17:50
uvos__atho maybe we should make that sync automaticly17:51
buZzhmmm, it doesnt take '4349000' as my battery reports, limits to 4330000 in /usb17:51
buZzbut, i guess fine for now17:51
uvos__not sure how the kernel interfaces expect this to happen17:51
freemangordonthere is code to do that, but it seems to be broken17:51
* buZz charges17:51
uvos__buZz: cpcap has limited register resolution17:52
uvos__id have to check if its that17:52
uvos__or if there is a < check where there should be <=17:52
buZzah, possibly yeah17:52
sicelofreemangordon: in /sys/firmware, the interrupt numbers are not there. but interrupt names is there.17:54
freemangordonnot good17:54
freemangordonhow big is DTB?17:54
freemangordonyou may try to enable thumb2 kernel, to see if reduced size is going to help17:55
siceloit's thumb217:58
freemangordonhmm17:59
freemangordonwell17:59
freemangordonmove something out of the kernel, into a module17:59
freemangordonor, change the compression17:59
freemangordoncan't think of anything better17:59
uvos__if we are significantly space limited on n900 we might have to start building a special kernel for it again18:00
sicelodtb is 78632 bytes18:00
uvos__since rn theres lots of stuff built in we really only need on mapphones/omap418:00
freemangordonugh18:00
siceloi'm quite sure the dtb didn't change size18:00
freemangordonhow big is kernel+dtb?18:00
sicelo5517960 Nov  5 00:04 zImage18:01
freemangordonugh18:01
freemangordonwhy so big?18:02
freemangordonmove some stuff to modules18:02
uvos__really why so big18:02
uvos__current kernel on my d4 is 498277618:03
uvos__why is it 500kb bigger18:03
freemangordonmhm18:03
sicelomajority of stuff is in modules actually18:05
freemangordongnome crashed :(18:09
freemangordonuvos__: so, after the fix, I see  usb_phy_set_charger_current() called, but usb_phy->chg_type is UNKNOWN_TYPE, as expected18:11
freemangordonTBH, I have no idea which exactly phy it is about, maybe I shall trace it18:12
freemangordonalso, I am not sure where shall charger detection be implemented18:12
freemangordonit seems extcon driver is the correct option18:13
freemangordonbut, I think we need tmlind here to help18:13
sicelofor completeness, here's the kernel config (extracted from /proc/config.gz)18:52
sicelohttp://li.nux.co.za/6.1.0-rc318:58
sicelofreemangordon: uvos: https://paste.debian.net/1260284/ ... this makes it all work just fine22:44
siceloof course it's a super ugly hack22:44
sicelo < freemangordon> I remember there were some issues with attached DTBs ... <-- would you remember the source of this info? i would like to investigate further22:54

Generated by irclog2html.py 2.17.0 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!