Skip to content

Commit 86097c8

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 b64b403 commit 86097c8

4 files changed

Lines changed: 45 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: 21 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,9 @@
5253

5354
DECLARE_GLOBAL_DATA_PTR;
5455

56+
#define PINEPHONE_LIS3MDL_I2C_ADDR 0x1E
57+
#define PINEPHONE_LIS3MDL_I2C_BUS 1 /* I2C1 */
58+
5559
void i2c_init_board(void)
5660
{
5761
#ifdef CONFIG_I2C0_ENABLE
@@ -968,6 +972,9 @@ int board_fit_config_name_match(const char *name)
968972
{
969973
const char *best_dt_name = get_spl_dt_name();
970974
int ret;
975+
#if CONFIG_IS_ENABLED(DM_I2C)
976+
struct udevice *bus, *dev;
977+
#endif
971978

972979
#ifdef CONFIG_DEFAULT_DEVICE_TREE
973980
if (best_dt_name == NULL)
@@ -994,11 +1001,21 @@ int board_fit_config_name_match(const char *name)
9941001
udelay(100);
9951002

9961003
/* 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";
1004+
if (gpio_get_value(SUNXI_GPL(6)) == 0) {
1005+
best_dt_name = "sun50i-a64-pinephone-1.2b";
10011006

1007+
/* 1.2 has different I2C magnetometer */
1008+
#if CONFIG_IS_ENABLED(DM_I2C)
1009+
if (!uclass_get_device_by_seq(UCLASS_I2C, PINEPHONE_LIS3MDL_I2C_BUS, &bus))
1010+
if (!dm_i2c_probe(bus, PINEPHONE_LIS3MDL_I2C_ADDR, 0, &dev))
1011+
best_dt_name = "sun50i-a64-pinephone-1.2";
1012+
#else
1013+
if (!i2c_set_bus_num(PINEPHONE_LIS3MDL_I2C_BUS))
1014+
if (!i2c_probe(PINEPHONE_LIS3MDL_I2C_ADDR))
1015+
best_dt_name = "sun50i-a64-pinephone-1.2";
1016+
#endif
1017+
} else
1018+
best_dt_name = "sun50i-a64-pinephone-1.1";
10021019
sunxi_gpio_set_cfgpin(SUNXI_GPL(6), SUNXI_GPIO_DISABLE);
10031020
sunxi_gpio_set_pull(SUNXI_GPL(6), SUNXI_GPIO_PULL_DISABLE);
10041021
prcm_apb0_disable(PRCM_APB0_GATE_PIO);

configs/pinephone_defconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ 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_I2C0_ENABLE=y
13+
CONFIG_I2C1_ENABLE=y
14+
CONFIG_R_I2C_ENABLE=y
1215
CONFIG_PINEPHONE_DT_SELECTION=y
1316
# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
14-
CONFIG_OF_LIST="sun50i-a64-pinephone-1.1 sun50i-a64-pinephone-1.2"
17+
CONFIG_SPL_I2C=y
18+
CONFIG_OF_LIST="sun50i-a64-pinephone-1.1 sun50i-a64-pinephone-1.2 sun50i-a64-pinephone-1.2b"
19+
CONFIG_SPL_SYS_I2C_LEGACY=y
1520
CONFIG_SYS_I2C_SUN8I_RSB=y
21+
CONFIG_SYS_I2C_MVTWSI=y
1622
CONFIG_LED_STATUS=y
1723
CONFIG_LED_STATUS_GPIO=y
1824
CONFIG_LED_STATUS0=y

0 commit comments

Comments
 (0)