Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions device/tegu/CALL-AUDIO-WINDOW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- SPDX-License-Identifier: MIT -->
# Pixel 9a: AoC voice-window audit

2026-11-02, offline. This supports TELEPHONY-PLAN section 1 (PR #360);
no call, memory access or phone operation was performed.

**The firmware voice path has a shared SRAM window; the Linux call-audio
route does not need a new CPU mapping of it.** The checked CPIF and AoC
paths provide no evidence that adding the omitted CPIF region is required
to start a PCIe call. Whether the running firmware's path works remains
unqualified until the attended call test.

Where it comes from:

- MODEM-PLAN F3 records tegu's own stock DT capture: `cp_aoc_rmem` is
12 KiB at AP physical address `0x197fd000`. The stock `cp_shmem` node's
fourth `memory-region` references it; `VSS_AOC` selects `SHMEM_VSS`
(index 1), rmem index 3, offset 0, size `0x3000`, uncached. This is AoC
SRAM, not a buffer for userspace to allocate. Google's
[GPL reservation](https://android.googlesource.com/kernel/devices/google/zuma/+/eb90f2862e78b4c409ff992e116c44e81f836e9e/dts/zuma-rmem.dtsi)
and [shared-memory description](https://android.googlesource.com/kernel/devices/google/zuma/+/b0dfdfc378dd37d7c1662bbd942240d55db83d68/dts/zuma-cp-s5300-sit.dtsi)
describe the same resource; tegu's capture is the board-specific evidence.
- Our tegu `zumapro-reserved-memory.dtsi` already reserves this range as
`cp-aoc@197fd000`, with `no-map`. Omitting the CPIF region from the
bring-up overlay does not remove that reservation.
- In the GPL CPIF port, `init_shmem_maps()` maps VSS only in the
`LINKDEV_SHMEM` case; tegu uses `LINKDEV_PCIE`. Its PCIe path does not
require `vss_base` to start. Google's
[GPL implementation](https://android.googlesource.com/kernel/google-modules/radio/samsung/s5300/+/refs/tags/android-16.0.0_r0.10/link_device.c)
preserves that distinction. Diagnostic accessors/dump support are not
the voice-stream transport.
- `aoc_alsa_voice.c` prepares the voice PCM through `prepare_phonecall()`
in `aoc_alsa_hw.c`. For playback PCM 4 it sends
`CMD_AUDIO_OUTPUT_TELEPHONY_MODEM_START_ID` (256); close sends STOP
(257). Both are header-only AoC commands, with no supplied memory
address (also confirmed in the saved GPL Zuma interface header).
The speech stays between the modem and AoC; sitd owns the PCM handles
and mixers, not the SRAM.

Keep the reservation and leave the window CPU-unmapped. This change adds
no DT region, PCIe translation, S2MPU permission or userspace memory
access. If a later call establishes a missing firmware-side window, trace
the stock tegu firmware/translation setup separately before any kernel
change; do not substitute another board's address or map the SRAM to
inspect it. The first call still needs the plan's gain checks, log stream,
watchdog, stop conditions and attended recovery.
29 changes: 28 additions & 1 deletion device/tegu/MODEM-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2017,11 +2017,38 @@ is a US MVNO on a large LTE network.
(`omamobile-sit sms send`) reached the owner's phone. A text sent to
the palmtop's own number was accepted ("sent") and never came back,
which is common on this network.
- **SIM-10:** no call; the 9a has no audio route.
- **SIM-10:** no call on 11-02; the 9a had no audio route. See "Calls"
below.
- **SIM-11 passed:** radio off, the RIL stopped, an attended reboot
(the unit's stop powered the CP off during shutdown), then M0.1: the
six partitions unchanged, `cpif` not loaded, UFS error handler 0.

#### Calls (2026-11-03)

With `omamobile-modem-sit` 0.3.11 (speakerphone audio for the 9a's AoC
card, omarchy-mobile #367, on #364 and #356) and `[audio] card = auto`:

- **On the daily kernel:** an outgoing call to the owner's phone, answered;
the far end's voice came out of the palmtop's speaker, and the palmtop's
microphone carried it back (heard at the far end as an echo: there is no
echo cancellation yet). A second outgoing call and an incoming call
(`omamobile-sit answer` while it rang) behaved the same. sitd logged
"AoC tegu speakerphone prepared at conservative TAS gain" at each start
and "AoC call routes restored" after each hang-up; UFS error handler 0.
- **On in-tree drivers end to end** (`7.3.0-rc6-omamobile-push1-g253ddb231a89`:
`omamobile` plus the open kernel PRs: the modem link #187 with its PCIe
stack, GNSS #185, and #162's AoC, GSA and Trusty from the device tree):
the AoC up with 93 services and the `google,tegu-aoc-snd-card` card,
CPIF and the in-tree host booted the CP to ONLINE, and then an outgoing
and an incoming call with audio both ways, mobile data over `rmnet0`
(pings, HTTPS 200) and a text that arrived. The TAS gains read back at
-20 dB during the calls, the mixer routes matched their saved state
after, the AoC kept 93 services with nothing in its log, the same boot
throughout, no oops or WARN, no UFS errors.

Left for calls: echo cancellation on speakerphone, an earpiece mode, the
Phone app (through `omamobile-mmd`), and starting the modem at boot.

The run kept the full refused record (292 bytes: status 36, CID 1, the
IPC extension version at 132, an unidentified extension byte at 133, the
suggested retry time at 235-242 as an s64) and the raw indications of the passing run in
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVICES.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ group = wheel
# reports that mode; with earpiece = no, refused unless the service runs at
# stage media or c8 with the top amplifier at analog 6 or less and both
# within the media stage's ceilings (digital 737, analog 10).
# On the Pixel 9a, call audio selects an experimental TAS2572 speakerphone
# route instead, held muted until both gains read back -20 dB after PCM
# startup.
#card = none
earpiece = yes
# Microphone gain above stock's 130 cB during calls: 6 (default, judged
# louder and clean in calls on this phone) or 0 (stock).
# louder and clean in calls on the 7 Pro) or 0 (stock). The 9a always uses
# stock's 130 cB, with no boost.
mic_boost_db = 6
4 changes: 2 additions & 2 deletions packages/omamobile-modem-sit/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from sit import Sit, ModemError
from sms_codec import submit, received_pdu, number
import carrier_manifest
from voice_audio import VoiceAudio, aoc_card
from voice_audio import AudioRefused, VoiceAudio, aoc_card

STATES = {0: 'active', 1: 'held', 2: 'dialing', 3: 'ringing-out', 4: 'ringing-in', 5: 'waiting',
6: 'terminated', 7: 'held', 8: 'active'}
Expand Down Expand Up @@ -580,7 +580,7 @@ def status(self, *, public=False):
received = [r[0] for r in self.db.execute('SELECT id FROM received WHERE consumed=0 ORDER BY rowid')]
return dict(modem=modem, calls=calls, sms=dict(received=['sit:' + i for i in received]),
audio=dict(available=True, running=self.audio is not None, mute=self.muted,
speaker=False, speaker_available=False, error=self.audio_error))
speaker=getattr(self.audio, 'tegu', False) is True, speaker_available=False, error=self.audio_error))

def subscribe(self, connection):
"""Keep an authorised connection for status events; refuse beyond
Expand Down
137 changes: 132 additions & 5 deletions packages/omamobile-modem-sit/lib/voice_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
Uses the AoC card's voice endpoints: PCM 4 playback (EP5) and PCM 11 capture
(EP4), whose numbers are the AoC entry points (AGENTS.md: the card numbers
its PCMs as stock does). AoC and CP exchange audio directly; no host
recording or SRAM mapping. Amplifier protection, calibration and gain stay
with omamobile-audio: the downlink plays through TDM 0, so it needs the
amplifiers set up (stock's TDM 0 format, protection service running).
recording or SRAM mapping. On cheetah, amplifier protection, calibration
and gain stay with omamobile-audio: TDM 0 needs its amplifiers set up and
the protection service running.

TDM 0 feeds both amplifiers, and the top one is the earpiece. With the
protection service's earpiece mode (AOC-PLAN.md C9k) each call runs in that
Expand All @@ -15,7 +15,9 @@
earpiece ceiling (top analog <= 6, AUDIO-PLAN.md section 4) and the media
stage's (digital <= 737, analog <= 10, AGENTS.md). The built-in default
routes no call audio; a device package whose route is verified sets
[audio] card = auto in its defaults (paths.DEVICE_DEFAULTS).
[audio] card = auto in its defaults (paths.DEVICE_DEFAULTS). Tegu instead
uses its TAS2572 speakerphone path, muted until both amplifiers read back a
conservative gain after PCM start.
"""
import ctypes as C
import os
Expand Down Expand Up @@ -44,6 +46,40 @@
# the watchdog stopped, muting the speakers (2026-11-03).
EARPIECE_UNIT = '/usr/lib/systemd/system/omamobile-earpiece@.service'

TEGU_CARD = 'google,tegu-aoc-snd-card'
# tas2x20_dvc_table in include/sound/tas2x20-tlv.h: index 220 is unity,
# index 180 is -20 dB. Use the index, not the control's misleading dB TLV.
TEGU_GAIN = '180'
TEGU_GAINS = ('Top Speaker Digital Volume', 'Bottom Speaker Digital Volume')
TEGU_ROUTE = (
('Incall Sink Mute', '1'),
('TDM_0_RX Chan', 'Four'), ('TDM_0_RX Format', 'S32_LE'),
('TDM_0_RX Sample Rate', 'SR_48K'),
('TDM_0_TX Chan', 'Four'), ('TDM_0_TX Format', 'S32_LE'),
('TDM_0_TX Sample Rate', 'SR_48K'),
('BUILDIN MIC ID CAPTURE LIST', '0,1,-1,-1'), ('MIC DC Blocker', '1'),
('Voice Call Audio Enable', '1'), ('Voice Call Mic Source', '1'),
('Voice Call Mic Mute', '0'), ('Incall Mic Mute', '0'),
('AoC Modem Downlink ASRC Mode', '1'),
('MIC HW Gain At High Power Mode (cB)', '130'),
('MIC Record Soft Gain (dB)', '0'),
('TDM_0_RX Mixer EP5', '1'), ('EP4 TX Mixer INTERNAL_MIC_TX', '1'))


class AudioRefused(RuntimeError):
"""A tegu route was safely unwound; signalling may continue silently."""


def is_tegu_card(card):
try:
for line in Path('/proc/asound/cards').read_text().splitlines():
match = re.match(r'\s*(\d+)\s+\[[^]]+\]:\s*.*? - (\S+)\s*$', line)
if match and int(match[1]) == card:
return match[2] == TEGU_CARD
except OSError:
pass
return False


def aoc_card(setting='auto'):
"""The AoC card's index: the configured one, the card whose ALSA id or
Expand Down Expand Up @@ -77,6 +113,11 @@ def __init__(self, *, mic_boost_db=6, card=None, earpiece=True):
self.earpiece_cmd = shutil.which(EARPIECE_COMMAND) if earpiece else None
if card is not None:
self.card = card
self.tegu = is_tegu_card(self.card)
if self.tegu:
# The protection service's earpiece mode is the 7 Pro's CS35L41
# route; the 9a's TAS2572 route sets its own gains.
self.earpiece_cmd = None
self.saved = []
self.pcms = []
self.alsa = C.CDLL('libasound.so.2')
Expand All @@ -85,6 +126,18 @@ def __init__(self, *, mic_boost_db=6, card=None, earpiece=True):
C.c_uint, C.c_uint, C.c_int, C.c_uint]
for name in ('snd_pcm_prepare', 'snd_pcm_start', 'snd_pcm_drop', 'snd_pcm_close', 'snd_pcm_state'):
getattr(self.alsa, name).argtypes = [C.c_void_p]
if self.tegu:
self.alsa.snd_pcm_hw_params_malloc.argtypes = [C.POINTER(C.c_void_p)]
self.alsa.snd_pcm_hw_params_free.argtypes = [C.c_void_p]
for name in ('snd_pcm_hw_params_any', 'snd_pcm_hw_params'):
getattr(self.alsa, name).argtypes = [C.c_void_p, C.c_void_p]
for name in ('access', 'format', 'channels', 'rate_resample'):
getattr(self.alsa, 'snd_pcm_hw_params_set_' + name).argtypes = [
C.c_void_p, C.c_void_p, C.c_uint]
for name in ('rate', 'periods', 'period_size'):
getattr(self.alsa, 'snd_pcm_hw_params_set_' + name).argtypes = [
C.c_void_p, C.c_void_p, C.c_ulong if name == 'period_size' else C.c_uint,
C.c_int]

def mixer(self, action, name, value=None):
args = ['amixer', '-c', str(self.card), action, 'name='+name]
Expand Down Expand Up @@ -137,6 +190,8 @@ def check_levels(self):
'(the earpiece ceiling needs the top amplifier at analog 6 or less)')

def __enter__(self):
if getattr(self, 'tegu', False):
return self.tegu_enter()
if self.earpiece_cmd:
self.earpiece(True)
try:
Expand Down Expand Up @@ -182,14 +237,86 @@ def __enter__(self):
self.__exit__(None, None, None)
raise

def mixer_value(self, name):
match = re.search(r'^\s*: values=([0-9,\-]+|on|off)$', self.mixer('cget', name), re.M)
if match is None:
raise RuntimeError('voice mixer state unavailable: ' + name)
return match[1]

def tegu_params(self, pcm):
params = C.c_void_p()
self.check(self.alsa.snd_pcm_hw_params_malloc(C.byref(params)), 'params allocation')
try:
self.check(self.alsa.snd_pcm_hw_params_any(pcm, params), 'params reset')
for name, value, direction in (
('access', 3, None), ('format', 2, None), ('channels', 1, None),
('rate_resample', 0, None), ('rate', 8000, 0),
('period_size', 80, 0), ('periods', 2, 0)):
args = (pcm, params, value) + (() if direction is None else (direction,))
self.check(getattr(self.alsa, 'snd_pcm_hw_params_set_' + name)(*args), name)
# hw_params prepares automatically. Never prepare a second time:
# preparing EP5 sends TELEPHONY_MODEM_START to the AoC.
self.check(self.alsa.snd_pcm_hw_params(pcm, params), 'params')
if self.alsa.snd_pcm_state(pcm) != 2:
raise RuntimeError('voice PCM was not prepared by hardware parameters')
finally:
self.alsa.snd_pcm_hw_params_free(params)

def tegu_enter(self):
if self.pcms:
return self
# Read everything before changing anything. Mute is first so its
# original value is restored last, after closing the voice PCMs.
names = [name for name, _ in TEGU_ROUTE] + list(TEGU_GAINS)
saved = [(name, self.mixer_value(name)) for name in names]
self.saved = saved
try:
for name, value in TEGU_ROUTE:
self.mixer('cset', name, value)
if name == 'Incall Sink Mute' and self.mixer_value(name) not in ('1', 'on'):
raise AudioRefused('tegu call audio refused: sink mute read-back mismatch')
# Capture is ready before playback prepare starts the modem.
for device, direction in ((11, 1), (4, 0)):
pcm = C.c_void_p()
self.check(self.alsa.snd_pcm_open(C.byref(pcm), f'hw:{self.card},{device}'.encode(),
direction, 0), 'open')
self.pcms.append(pcm)
self.tegu_params(pcm)
self.check(self.alsa.snd_pcm_start(pcm), 'start')
# The codec profile resets gain at playback start. These must
# happen afterwards, while the modem downlink remains muted.
for name in TEGU_GAINS:
self.mixer('cset', name, TEGU_GAIN)
for name in TEGU_GAINS:
try:
gain = self.mixer_value(name)
except (OSError, RuntimeError, subprocess.TimeoutExpired) as error:
raise AudioRefused('tegu call audio refused: TAS gain read-back unavailable') from error
if gain != TEGU_GAIN:
raise AudioRefused('tegu call audio refused: TAS gain read-back mismatch')
self.mixer('cset', 'Incall Sink Mute', '0')
print('AoC tegu speakerphone prepared at conservative TAS gain', flush=True)
return self
except BaseException:
self.__exit__(None, None, None)
raise

def __exit__(self, *args):
failures = []
if getattr(self, 'tegu', False) and self.saved:
try:
self.mixer('cset', 'Incall Sink Mute', '1')
except (OSError, RuntimeError, subprocess.TimeoutExpired):
failures.append('Incall Sink Mute')
for pcm in reversed(self.pcms):
self.alsa.snd_pcm_drop(pcm)
if self.alsa.snd_pcm_drop(pcm) < 0 and getattr(self, 'tegu', False):
failures.append('PCM drop')
if self.alsa.snd_pcm_close(pcm) < 0:
failures.append('PCM close')
self.pcms.clear()
for name, value in reversed(self.saved):
if getattr(self, 'tegu', False) and name == 'Incall Sink Mute' and failures:
continue # uncertain cleanup must leave the call sink muted
try:
self.mixer('cset', name, value)
except (OSError, RuntimeError, subprocess.TimeoutExpired):
Expand Down
17 changes: 17 additions & 0 deletions packages/omamobile-modem-sit/test/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ def test_restart_does_not_retry_pending_sms(self):
other=app_service.database(self.root/'db')
self.assertEqual(other.execute('SELECT state FROM outgoing').fetchone()[0],'unknown'); other.close()

def test_refused_tegu_gain_does_not_fail_call_signalling(self):
self.service.settings['audio']['card'] = 'auto'
self.client.request.side_effect = [bytes(4), b'']
with patch.object(app_service, 'aoc_card', return_value=3), \
patch.object(app_service, 'VoiceAudio') as route:
route.return_value.__enter__.side_effect = app_service.AudioRefused('gain mismatch')
call = self.service.dispatch(dict(action='dial', number='+12025550123'))
self.assertEqual(self.service.calls[call['call']]['state'], 'dialing')
self.assertEqual([c.args[0] for c in self.client.request.call_args_list], [0x0000, 0x0d00])
self.assertIsNone(self.service.audio)

def test_tegu_route_is_reported_as_speakerphone(self):
self.service.audio = MagicMock(tegu=True)
self.assertTrue(self.service.status()['audio']['speaker'])
self.service.audio.tegu = False
self.assertFalse(self.service.status()['audio']['speaker'])

def test_failed_radio_off_still_requires_reboot_without_claiming_release(self):
self.client.request.side_effect = TimeoutError()
with patch.object(app_service, 'radio', side_effect=OSError()), \
Expand Down
Loading