Skip to content

Commit 6af923a

Browse files
committed
sunxi: pinephone: differentiate hw revisions 1.2 and 1.2b
In newer 1.2 PinePhone board revisions LIS3MDL magnetometer was replaced by AF8133J. They use the same PB1 pin in different modes. LIS3MDL uses it as an gpio input to handle interrupt. AF8133J uses it as an gpio output as a reset signal. It wasn't possible at runtime to enable both device tree nodes and detect supported sensor at probe time. As a result new board revision was introduced with AF8133J definition (1.2b). AF8133J has reset pin (PB1) connected to the SoC. By default AF8133J is in a reset state and don't respond to probe request on I2C bus. Extra code would be needed to handle reset signal. Therefore this code uses LIS3MDL magnetometer (1.2) revision instead of AF8133J (1.2b) to detect board revision. Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
1 parent 62109d4 commit 6af923a

4 files changed

Lines changed: 49 additions & 5 deletions

File tree

arch/arm/dts/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ dtb-$(CONFIG_MACH_SUN50I) += \
760760
sun50i-a64-pinephone-1.0.dtb \
761761
sun50i-a64-pinephone-1.1.dtb \
762762
sun50i-a64-pinephone-1.2.dtb \
763+
sun50i-a64-pinephone-1.2b.dtb \
763764
sun50i-a64-pinetab.dtb \
764765
sun50i-a64-sopine-baseboard.dtb \
765766
sun50i-a64-teres-i.dtb
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2+
// Copyright (C) 2020 Ondrej Jirman <megous@megous.com>
3+
4+
/dts-v1/;
5+
6+
#include "sun50i-a64-pinephone-1.2.dts"
7+
8+
/ {
9+
model = "Pine64 PinePhone (1.2b)";
10+
compatible = "pine64,pinephone-1.2b", "pine64,pinephone", "allwinner,sun50i-a64";
11+
};
12+
13+
&lis3mdl {
14+
status = "disabled";
15+
};
16+

board/sunxi/board.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <image.h>
1919
#include <init.h>
2020
#include <log.h>
21+
#include <i2c.h>
2122
#include <mmc.h>
2223
#include <axp_pmic.h>
2324
#include <generic-phy.h>
@@ -52,6 +53,15 @@
5253

5354
DECLARE_GLOBAL_DATA_PTR;
5455

56+
#define PINEPHONE_LIS3MDL_I2C_ADDR 0x1E
57+
58+
/* I2C1 */
59+
#if defined(CONFIG_I2C0_ENABLE)
60+
#define PINEPHONE_LIS3MDL_I2C_BUS 1
61+
#else
62+
#define PINEPHONE_LIS3MDL_I2C_BUS 0
63+
#endif
64+
5565
void i2c_init_board(void)
5666
{
5767
#ifdef CONFIG_I2C0_ENABLE
@@ -968,6 +978,9 @@ int board_fit_config_name_match(const char *name)
968978
{
969979
const char *best_dt_name = get_spl_dt_name();
970980
int ret;
981+
#if CONFIG_IS_ENABLED(DM_I2C)
982+
struct udevice *bus, *dev;
983+
#endif
971984

972985
#ifdef CONFIG_DEFAULT_DEVICE_TREE
973986
if (best_dt_name == NULL)
@@ -994,11 +1007,21 @@ int board_fit_config_name_match(const char *name)
9941007
udelay(100);
9951008

9961009
/* PL6 is pulled low by the modem on v1.2. */
997-
if (gpio_get_value(SUNXI_GPL(6)) == 0)
998-
best_dt_name = "sun50i-a64-pinephone-1.2";
999-
else
1000-
best_dt_name = "sun50i-a64-pinephone-1.1";
1010+
if (gpio_get_value(SUNXI_GPL(6)) == 0) {
1011+
best_dt_name = "sun50i-a64-pinephone-1.2b";
10011012

1013+
/* 1.2 has different I2C magnetometer */
1014+
#if CONFIG_IS_ENABLED(DM_I2C)
1015+
if (!uclass_get_device_by_seq(UCLASS_I2C, PINEPHONE_LIS3MDL_I2C_BUS, &bus))
1016+
if (!dm_i2c_probe(bus, PINEPHONE_LIS3MDL_I2C_ADDR, 0, &dev))
1017+
best_dt_name = "sun50i-a64-pinephone-1.2";
1018+
#else
1019+
if (!i2c_set_bus_num(PINEPHONE_LIS3MDL_I2C_BUS))
1020+
if (!i2c_probe(PINEPHONE_LIS3MDL_I2C_ADDR))
1021+
best_dt_name = "sun50i-a64-pinephone-1.2";
1022+
#endif
1023+
} else
1024+
best_dt_name = "sun50i-a64-pinephone-1.1";
10021025
sunxi_gpio_set_cfgpin(SUNXI_GPL(6), SUNXI_GPIO_DISABLE);
10031026
sunxi_gpio_set_pull(SUNXI_GPL(6), SUNXI_GPIO_PULL_DISABLE);
10041027
prcm_apb0_disable(PRCM_APB0_GATE_PIO);

configs/pinephone_defconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ CONFIG_SUNXI_DRAM_LPDDR3_STOCK=y
99
CONFIG_DRAM_CLK=552
1010
CONFIG_DRAM_ZQ=3881949
1111
CONFIG_MMC_SUNXI_SLOT_EXTRA=2
12+
CONFIG_I2C1_ENABLE=y
1213
CONFIG_PINEPHONE_DT_SELECTION=y
1314
# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
14-
CONFIG_OF_LIST="sun50i-a64-pinephone-1.1 sun50i-a64-pinephone-1.2"
15+
CONFIG_SPL_I2C=y
16+
CONFIG_OF_LIST="sun50i-a64-pinephone-1.1 sun50i-a64-pinephone-1.2 sun50i-a64-pinephone-1.2b"
17+
CONFIG_SPL_SYS_I2C_LEGACY=y
1518
CONFIG_SYS_I2C_SUN8I_RSB=y
19+
CONFIG_SYS_I2C_MVTWSI=y
1620
CONFIG_LED_STATUS=y
1721
CONFIG_LED_STATUS_GPIO=y
1822
CONFIG_LED_STATUS0=y

0 commit comments

Comments
 (0)