PabloPL / linux

Linux kernel source tree
Other
17 stars 0 forks source link

Modem support #23

Open xc-racer99 opened 5 years ago

xc-racer99 commented 5 years ago

Branch created called not-for-upstream/modem

Has been tested on Fascinate4G with ipc-modem from https://git.replicant.us/replicant/external_libsamsung-ipc/tree/?h=replicant-6.0 and the patches from https://github.com/xc-racer99/android_patches/blob/8e410ce0996bb3170865a4b7ea375726bf804c1c/external_libsamsung-ipc.patch applied

Modem boots and registers on network - nothing else tested. Requires the modem.bin to be in /radio/modem.bin plus that the EFS is present at /efs

PabloPL commented 5 years ago

https://github.com/fourkbomb/linux/tree/modem There is some rewritten samsung ipc driver for mainline. We would need to implement onedram driver.

xc-racer99 commented 5 years ago

Do you really think it's worthwhile trying to shoehorn the onedram bits into the i9300 driver? I suppose we'd need an equivalent of https://github.com/fourkbomb/linux/commit/459dd2c610c44d90683953f8e9dcb68df2c91807 for onedram. The branch I created uses the Nexus S (crespo) driver with forward-ported to 4.20 plus support for the modem in the Fascinate 4G.

Do you know if https://github.com/fourkbomb/linux/tree/modem was ever submitted to mainline and what the reaction was?

PabloPL commented 5 years ago

Probably it wasn't submited to upstream.

At first it would be great to have old driver working (like You did), but later i think we could try to make it work with fourkbomb driver (since it was designed for mainline, not for 2.6/3.0 kernels) - having old, working code as base would make it easier to develop (like freedreno/lima/panfrost/etc are doing). I think it would be very hard to put old samsung_ctl code into mainline. But it's up to You, this is just my sugestion ;).

xc-racer99 commented 5 years ago

Ok, sounds good, I think I'll leave it like it is for now as there's no guarantee that fourkbomb's driver will ever see mainline either. The issue with fourkbomb's driver is that you still need a separate modem control driver for power states such as https://github.com/fourkbomb/linux/commit/913bdb1ad530a3c32f9d0ae3aef5c9afaabfd567

The fact that it works as-is with userspace is one of the reasons I chose it. To me, whether or not it makes it into mainline is rather beside the point.

And the main reason I worked on this at all was so that I could return to the audio driver and make sure I've actually setup the clocking for the modem part correctly.

xc-racer99 commented 5 years ago

It should also be noted that there are two 2.6.35/3.0 onedram/modemctl drivers - one that is used on the SGS series, one that is used for the Nexus S. I chose the Nexus S driver as it is much, much simpler plus has a full history of commits - it was worked on primarily by Google and not by Samsung. I also didn't bother choosing the CDMA commits as there's no free userspace anyways.

PabloPL commented 5 years ago

Yes, Nexus S has much better drivers (looking at code) than other aries devices.

PabloPL commented 5 years ago

libsamsung-ipc has switched to gpl2 some time ago (that was preventing it from being supported by ofono). https://lists.ofono.org/pipermail/ofono/2012-September/013777.html Maybe we could update those patches and send them again.

xc-racer99 commented 5 years ago

Maybe we could update those patches and send them again.

Unfortunately, libsamsung-ipc has also undergone a fairly substantial rewrite since then. There is a WIP set for libsamsung-ipc v0.3 at https://github.com/fourkbomb/ofono

I have no experience with Glib, so I'm not sure if I could do this at this point. Additionally, my device needs the RFS layer setup before anything else, so I would need to implement that as well.

xc-racer99 commented 5 years ago

Note that the libsamsung-ipc ofono patches have external projects located at https://github.com/morphis/samsung-rfs-mgr and https://github.com/morphis/samsung-modem-mgr

Edit: On second thought, those may not be necessary as some were written before the initial submission of the patches to ofono.

Edit 2: They are necessary, ofono calls samsung-modem-mgr via dbus and samsung-modem-mgr calls samsung-rfs-mgr. I don't think I'll try using them, I'll see if I can start things directly from ofono. I wish ofono was actually documented...

I'm working my way through rebasing the original ofono patches on the latest master, fixing the build as I go along. Work is at https://github.com/xc-racer99/ofono but it untested as of writing.

xc-racer99 commented 5 years ago

Ok, I now have all the ofono patches building. Unfortunately, there is zero chance it works. Previously, you could get the fd that the libsamsung-ipc driver was internally using its "poll" function, but you can no longer do so. The ofono patches relied on this (using g_io_channel_unix_new() which was then listened on). Since this is no longer the case, there's a few things we could try: 1) Create a separate daemon that is responsible for direct interaction with the libsamsung-ipc. It would create a socket and the ofono code would connect to this socket. 2) Create a custom GIOChannel wrapper around the libsamsung-ipc poll function 3) Re-add some sort of fd listening to libsamsung-ipc 4) Create a separate thread inside ofono for one of the above

Considering I've never done any GLib programming, this might be beyond me. I think I'll try implementing option 2 first as it would involve the least amount of changes to the pre-existing patches.

Edit: Looks like there is an example of such a thing in ofono/gatchat/gatmux.c

herbsmn commented 4 years ago

@scintill is working with Replicant to add oFono support on the i317 modem: https://redmine.replicant.us/issues/1945

Also, just today GNUtoo got the i9300 modem booting in Android9: https://redmine.replicant.us/issues/1954

herbsmn commented 4 years ago

Also, i found out that one of the S3 modems is in mainline here: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/drivers/clk/qcom/gcc-mdm9615.c

xc-racer99 commented 4 years ago

@scintill is working with Replicant to add oFono support on the i317 modem: https://redmine.replicant.us/issues/1945

Also, just today GNUtoo got the i9300 modem booting in Android9: https://redmine.replicant.us/issues/1954

Cool. Do you know if there's any plans to upstream the Samsung IPC driver in any form? If so, then I'd work on porting the s5pc110 interface to it, otherwise I'll probably just stick around with the Crespo (Nexus S) driver which seems to be working quite well - it boots no problem, I've used libsamsung-ipc's ipc-modem utility and had functional voice calls. I've been working on an ofono driver for Samsung-IPC (at https://github.com/xc-racer99/libsamsung-ipc and https://github.com/xc-racer99/ofono/), have most of the base laid; it registers just fine on the network. Need to do some accounting for when sending IPC commands when the modem is in LPM mode then the modem (or at least mine) discards these command silently leaving userspace to be waiting forever for something that's never going to complete.

Also, i found out that one of the S3 modems is in mainline here: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/drivers/clk/qcom/gcc-mdm9615.c

I take it this doesn't use the Samsung IPC protocol as it's a Qualcomm CPU? I don't have any of the S3 series and am not very familiar with them.

herbsmn commented 4 years ago

I think we are planning on upstreaming the Samsung IPC driver, but I'd have to ask GNUtoo. Here's some more documentation about Replicant's Android9 work: https://redmine.replicant.us/projects/replicant/wiki/PortingToAndroid9/220#TODO

herbsmn commented 4 years ago

Have you looked at the oFono-based Java RIL for Android that Replicant is planning to use? https://github.com/scintill/android_frameworks_opt_telephony_ril_ofono

There are many Galaxy S3 versions that use Qualcomm CPUs, but Replicant is only working with the S3 versions that use the Exynos SoC.

GNUtoo said that there are plans to upstream the Samsung IPC driver and that the first driver will probably be the firmware loading code.

I think that this is where you can follow GNUtoo's progress: https://git.replicant.us/contrib/GNUtoo/hardware_replicant_libsamsung-ipc/log/?h=GNUtoo/modem-i9300

xc-racer99 commented 4 years ago

Have you looked at the oFono-based Java RIL for Android that Replicant is planning to use? https://github.com/scintill/android_frameworks_opt_telephony_ril_ofono

I've noticed it was around, but haven't really looked at it at all. I'm more interested in the pmOS/more traditional linux distro side of things than Android right now which doesn't need the Java or RIL layer. I've been using the tests that ship with ofono for testing things.

There are many Galaxy S3 versions that use Qualcomm CPUs, but Replicant is only working with the S3 versions that use the Exynos SoC.

GNUtoo said that there are plans to upstream the Samsung IPC driver and that the first driver will probably be the firmware loading code.

I think that this is where you can follow GNUtoo's progress: https://git.replicant.us/contrib/GNUtoo/hardware_replicant_libsamsung-ipc/log/?h=GNUtoo/modem-i9300

Good to know I've been watching in the right place :) If we can have a proper firmware loading code abstraction in the kernel, that would be great. Right now, the two (known) modems used in the first-gen Galaxy S series (XMM6160 and STE M5730) use different initialization procedures but substantially the same communication method once they're booted.