If mains fails and my device is working in battery mode I would like to disable Ethernet, USB, HDMI, turn off the LCD backlight etc. Is it possible to disable these modules? My device battery is discharging very quickly, and I am looking for anyway to save power. This is first time working in power management.
As is the Raspberry Pi doesn't support a Deep Sleep mode as you describe it. Most of these modules can all be disabled, but the savings are minimal and they will all require a restart to toggle on or off.
Turning down the brightness will surely help (presuming it's powered from the RPi), but how and if you can do that will depend entirely on the screen you're using. Check its documentation for information on that.
As is, the RPi uses remarkably little power. The SOC (CPU, RAM, GPU, etc) is going to be eating the vast majority of your power. If you need your device to last longer on a battery, the best answer is to simply provided it with a bigger battery.
You can disable many of the onboard devices to reduce the power footprint as described here, here, or here. The largest power reduction (100mA) can be made by disabling the USB/LAN chip (
echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind).
Some other settings can either be changed at runtime (such as Bluetooth and WiFi using
rfkill) or boot time by configuring devicetree (e.g. Adding
/boot/cmdline.txt). With WiFi it's also possible to control the power_save mode on the device (e.g.
iw wlan0 set power_save on) - though this is usually enabled.
There are some others that can only be done at boot time such disabling the LEDs (e.g. disable the activity LED add:
/boot/cmdline.txt). The HDMI port can be disabled (
sudo /opt/vc/bin/tvservice -o) though it usually disabled unless a HDMI device is connected at boot time.
There are also various power management options in the Linux kernel such as the CPU frequency and voltage scaling options. The default frequency governor is set to
ondemand by the
raspi-config systemctl service (otherwise it defaults to
powersave). On the Pi4 there are some additional configuration options to control the Dynamic Voltage and Frequency Scaling (DVFS) settings at boot time. But one needs to balance the performance and energy aspects with thermal control so the device doesn't get physically damaged.