1. Disconnect the negative battery cable.
2. Remove the headliner.
3. Disconnect the connector.
4. Remove the screws, and then remove the sunroof motor.

Sunroof unit disassembly/assembly
Sunroof motor installationMazda 6 Service Manual: Locking, Unlocking the Doors
NOTE
The system may not operate if you are too close to the windows or door
handles.
If the key is left in the following areas and you leave the vehicle,
the doors may be locked depending on the radio wave conditions even if the key
is left in the vehicle.
Around the dashboard
...
Mazda 6 Service Manual: Combine sensor initialization procedure
1. Set the SST (WDS or equivalent) to the DLC-2
2. Access the active command mode and select the YAWRATE, then follow the
indication on the monitor.
3. Select the LATACCEL and follow the indication on the monitor.
STEERING ANGLE SENSOR REMOVAL/INSTALLATION
(See COMBINATION SWITCH DISASSEMBLY ...