]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Amlogic: meson-g12: integrate busio for G12A, G12B, and SM1
authorHyeonki Hong <hhk7734@gmail.com>
Tue, 21 Apr 2020 05:27:15 +0000 (14:27 +0900)
committerHyeonki Hong <hhk7734@gmail.com>
Tue, 21 Apr 2020 05:27:15 +0000 (14:27 +0900)
src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py
src/adafruit_blinka/microcontroller/amlogic/s905x3/pin.py
src/adafruit_blinka/microcontroller/amlogic/s922x/pin.py

index a6a9be1c6ed5ed3543cd1929153a3d31a273402c..635d816a32f0ec01b91afac0510a9a533287cb6a 100644 (file)
@@ -1,5 +1,6 @@
 from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
 import gpiod
+import re
 
 # G12A, G12B, and SM1
 # Ref:
@@ -7,6 +8,7 @@ import gpiod
 #     linux/include/dt-bindings/gpio/meson-g12a-gpio.h
 # Linux kernel 5.4.y (mainline)
 #     linux/include/dt-bindings/gpio/meson-g12a-gpio.h
+#     linux/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi
 
 chip0 = gpiod.Chip("0")
 chip1 = gpiod.Chip("1")
@@ -87,3 +89,48 @@ GPIOX_16 = GPIO492 = Pin((periphs, 81 + periphs_offset))
 GPIOX_17 = GPIO493 = Pin((periphs, 82 + periphs_offset))
 GPIOX_18 = GPIO494 = Pin((periphs, 83 + periphs_offset))
 GPIOX_19 = GPIO495 = Pin((periphs, 84 + periphs_offset))
+
+SPI0_SCLK = GPIOX_11
+SPI0_MISO = GPIOX_9
+SPI0_MOSI = GPIOX_8
+SPI0_CS0 = GPIOX_10
+
+# ordered as spiId, sckId, mosiId, misoId
+spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO), )
+
+UART1_TX = GPIOX_12
+UART1_RX = GPIOX_13
+
+# ordered as uartId, txId, rxId
+uartPorts = ((1, UART1_TX, UART1_RX), )
+
+
+def get_dts_alias(device: str) -> str:
+    uevent_path = "/sys/bus/platform/devices/" + device + "/uevent"
+    with open(uevent_path, 'r') as fd:
+        pattern = r"^OF_ALIAS_0=(.*)$"
+        uevent = fd.read().split('\n')
+        for line in uevent:
+            match = re.search(pattern, line)
+            if match:
+                return match.group(1).upper()
+
+        return None
+
+
+# ordered as i2cId, sclId, sdaId
+i2cPorts = []
+
+alias = get_dts_alias("ffd1d000.i2c")
+if alias is not None:
+    globals()[alias + "_SCL"] = GPIOX_18
+    globals()[alias + "_SDA"] = GPIOX_17
+    i2cPorts.append((int(alias[3]), GPIOX_18, GPIOX_17))
+
+alias = get_dts_alias("ffd1c000.i2c")
+if alias is not None:
+    globals()[alias + "_SCL"] = GPIOA_15
+    globals()[alias + "_SDA"] = GPIOA_14
+    i2cPorts.append((int(alias[3]), GPIOA_15, GPIOA_14))
+
+i2cPorts = tuple(i2cPorts)
index b8f93e5ab9e18be7159a057f00db9d757c2378f0..0f576e614bf484882952b3bb4ab2022ced4250ea 100644 (file)
@@ -1,21 +1 @@
 from adafruit_blinka.microcontroller.amlogic.meson_g12_common.pin import *
-
-
-I2C1_SDA = GPIOX_17
-I2C1_SCL = GPIOX_18
-I2C2_SDA = GPIOA_14
-I2C2_SCL = GPIOA_15
-
-UART1_TX = GPIOX_12
-UART1_RX = GPIOX_13
-
-SPI0_SCLK = GPIOX_11
-SPI0_MISO = GPIOX_9
-SPI0_MOSI = GPIOX_8
-SPI0_CS0 = GPIOX_10
-
-i2cPorts = ((1, I2C1_SCL, I2C1_SDA), (2, I2C2_SCL, I2C2_SDA), )
-# ordered as spiId, sckId, mosiId, misoId
-spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO), )
-# ordered as uartId, txId, rxId
-uartPorts = ((1, UART1_TX, UART1_RX), )
index d544e8044683e2791570bfc8b44e7b44b1e9d4d5..0f576e614bf484882952b3bb4ab2022ced4250ea 100644 (file)
@@ -1,20 +1 @@
 from adafruit_blinka.microcontroller.amlogic.meson_g12_common.pin import *
-
-
-I2C2_SDA = GPIO493
-I2C2_SCL = GPIO494
-I2C3_SDA = GPIO474
-I2C3_SCL = GPIO475
-
-UART1_TX = GPIO488
-UART1_RX = GPIO489
-
-SPI0_SCLK = GPIO487
-SPI0_MISO = GPIO485
-SPI0_MOSI = GPIO484
-
-i2cPorts = ((2, I2C2_SCL, I2C2_SDA), (3, I2C3_SCL, I2C3_SDA), )
-# ordered as spiId, sckId, mosiId, misoId
-spiPorts = ((0, SPI0_SCLK, SPI0_MOSI, SPI0_MISO), )
-# ordered as uartId, txId, rxId
-uartPorts = ((1, UART1_TX, UART1_RX), )