########################################################################
# Helper script: /load_kernel_modules.scr/platform/arm/allwinnerH3
# Purpose......: Set the Kernel modules for Hardware Models that use the
#                Allwinner H3 SoC within the Slackware initial RAM disk
#                ('OS initrd') and the Slackware installer.
#                Currently supported Hardware Models:
#                * Orange Pi Plus (H3) v1.1
#                * Orange Pi Plus 2E (H3) v1.1
#                * Orange Pi PC (H3) v1.2
#                This script is sourced from '/load_kernel_modules'
# Author.......: Stuart Winter <mozes@slackware.com>
# Date.........: 30-Mar-2021
# Maintainer...: Stuart Winter <mozes@slackware.com>
#
# Please use this as an example of how to add support for
# a new SoC to Slackware AArch64/ARM.
#
# Important Note:
# * You must _append_ to the module lists (include the variable
#   name within the variable itself), otherwise the base
#   set of modules will not be loaded and would result in
#   a Kernel panic.
# * The initrd uses the 'bash' shell, rather than 'busybox'
#   (as in upstream/x86 Slackware). This allows you (for example)
#   to use 'fallthrough' (case statements terminated with ';&'
#   rather than ';;') within case statements and regular expression
#   matches within 'if' statements.
#   This permits the 'c'-style switch statements where you can
#   'inherit' the previous matches as you move down the cases.
#   This enables you to match on varients of boards, and inherit
#   a 'baseline' of platform modules for that board.
#
# The 'PLATWALK' match is to enable build scripts to process these
# scripts outside of the initrd environment and determine which
# modules will be loaded by a particular Hardware Model.  This must
# remain in place for all scripts.
########################################################################

# For testing directly on the Hardware Model:
#DEVTYPE=$( strings /proc/device-tree/model 2>/dev/null )

case $DEVTYPE in
   *"Xunlong Orange Pi Plus"*|PLATWALK)
      platform_detected=1
      echo "Architecture: ${ARCH}, Hardware model: ${DEVTYPE}"
      # If one of the modules within the base list is causing problems on
      # your platform, here are the options laid out as examples:
      # USB="${USB/ehci_orion/differentmodule}" # Substitute module 'ehci_orion' with 'differentmodule'
      # USB="${USB/ehci_orion/}" # Remove the 'ehci_orion' module from the list
      MOD_GPIO="$MOD_GPIO    "
      MOD_PHY="$MOD_PHY      phy_sun4i_usb"
      MOD_VIDEO="$MOD_VIDEO  "
      MOD_CARDS="$MOD_CARDS  "
      MOD_USB="$MOD_USB      "
      MOD_SATA="$MOD_SATA    ahci-sunxi"
      MOD_NET="$MOD_NET      dwmac-sunxi dwmac_sun8i stmmac" 
      # Example to detect hardware at runtime:
      #{ lspci 2>/dev/null | grep -q 'SATA cont.*ATA' ;} && MOD_XX="$MOD_XX yyy"
      # The following modules do not inherit:
      MOD_RTC=""
      # Modules that aren't (yet) categorised:
      MOD_SOC="sun6i_dma";;
esac

# The '/load_kernel_modules' script will load the modules
# set above.
