[PATCH v2 1/8] pinctrl: stm32: fix debug print of uninitialized variable

2019-10-27 Thread Ahmad Fatoum
mode and alt are printed with the dev_dbg before they are initialized.
Remedy this by moving the dev_dbg after them.

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl-stm32.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index 7f04cea50b75..ab121998a37f 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -157,13 +157,13 @@ static int stm32_pinctrl_set_state(struct pinctrl_device 
*pdev, struct device_no
if (offset < 0)
return -ENODEV;
 
+   mode = stm32_gpio_get_mode(func);
+   alt = stm32_gpio_get_alt(func);
+
dev_dbg(pdev->dev, "configuring port %s pin %u 
with:\n\t"
"fn %u, mode %u, alt %u\n",
bank->name, offset, func, mode, alt);
 
-   mode = stm32_gpio_get_mode(func);
-   alt = stm32_gpio_get_alt(func);
-
clk_enable(bank->clk);
 
__stm32_pmx_set_mode(bank->base, offset, mode, alt);
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 5/8] ARM: stm32mp: select ARM_SMCCC always

2019-10-27 Thread Ahmad Fatoum
ARM_SMCCC compiles in the code for issuing ARM secure monitor calls.
We need those on the STM32MP, because barebox runs in non-secure mode
and does some operations like reading the BSEC OTP through SMCs.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d4947cef5c98..f82844a83a5e 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -201,6 +201,7 @@ config ARCH_STM32MP
select GPIOLIB
select ARCH_HAS_RESET_CONTROLLER
select ARM_AMBA
+   select ARM_SMCCC
 
 config ARCH_VERSATILE
bool "ARM Versatile boards (ARM926EJ-S)"
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 2/8] pinctrl: demote dev_info on successful probes to dev_dbg

2019-10-27 Thread Ahmad Fatoum
The SoC's pin controller is virtually always built and probed, so
there's is little information to gain from the fact it was successfully
probed. Have the success message show up as debug message to reduce probe
clutter like this:

NOTICE: stm32-pinctrl soc:pin-control...@50002000.of: pinctrl/gpio 
driver registered
NOTICE: stm32-pinctrl soc:pin-controlle...@54004000.of: pinctrl/gpio 
driver registered

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl-at91-pio4.c | 4 ++--
 drivers/pinctrl/pinctrl-bcm2835.c   | 2 +-
 drivers/pinctrl/pinctrl-stm32.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c 
b/drivers/pinctrl/pinctrl-at91-pio4.c
index 9bc259f84cca..b527114f1ba0 100644
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -260,7 +260,7 @@ static int pinctrl_at91_pio4_gpiochip_add(struct device_d 
*dev,
return ret;
}
 
-   dev_info(dev, "gpio driver registered\n");
+   dev_dbg(dev, "gpio driver registered\n");
 
return 0;
 }
@@ -290,7 +290,7 @@ static int pinctrl_at91_pio4_probe(struct device_d *dev)
if (ret)
return ret;
 
-   dev_info(dev, "pinctrl driver registered\n");
+   dev_dbg(dev, "pinctrl driver registered\n");
 
if (of_get_property(np, "gpio-controller", NULL))
return pinctrl_at91_pio4_gpiochip_add(dev, pinctrl);
diff --git a/drivers/pinctrl/pinctrl-bcm2835.c 
b/drivers/pinctrl/pinctrl-bcm2835.c
index 5fd5740e8184..b8e9b60372e3 100644
--- a/drivers/pinctrl/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/pinctrl-bcm2835.c
@@ -171,7 +171,7 @@ static int bcm2835_gpio_probe(struct device_d *dev)
goto err;
}
 
-   dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, 
bcmgpio->chip.base);
+   dev_dbg(dev, "probed gpiochip%d with base %d\n", dev->id, 
bcmgpio->chip.base);
 
if (IS_ENABLED(CONFIG_PINCTRL)) {
ret = pinctrl_register(>pctl);
diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index ab121998a37f..c199d74846e8 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -401,7 +401,7 @@ static int stm32_pinctrl_probe(struct device_d *dev)
}
}
 
-   dev_info(dev, "pinctrl/gpio driver registered\n");
+   dev_dbg(dev, "pinctrl/gpio driver registered\n");
 
return 0;
 }
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 4/8] ARM: sm: document SMC/PSCI related options

2019-10-27 Thread Ahmad Fatoum
At least to me, the difference between these options were confusing at
first. Clear this up.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/Kconfig | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 725ea12a8c57..d4947cef5c98 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -427,10 +427,14 @@ config ARM_SEMIHOSTING
 
 config ARM_SMCCC
bool
+   help
+ This option enables barebox to invoke ARM secure monitor calls.
 
 config ARM_SECURE_MONITOR
select ARM_SMCCC
bool
+   help
+ This option enables barebox to service ARM secure monitor calls.
 
 config ARM_PSCI_OF
bool
@@ -442,7 +446,7 @@ config ARM_PSCI
select ARM_PSCI_OF
help
  PSCI is used for controlling secondary CPU cores on some systems. Say
- yes here if you have one of these.
+ yes here if you want barebox to service PSCI calls on such systems.
 
 config ARM_PSCI_DEBUG
bool "Enable PSCI debugging"
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 7/8] ARM: stm32mp: dk2: add barebox SD-Card update handler

2019-10-27 Thread Ahmad Fatoum
Now with the SD/MMC controller supported, lets add a bbu handler, so we
can use it to update the second stage boot loader partition.

While doing this, I noticed that making use of the bus-width = <4>
property in the device tree now makes mmc usage fail when reading the
environment:

  ERROR: error SDMMC_STA_DCRCFAIL (0x81042) for cmd 18
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 12 failed, retrying ...
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 12 failed, retrying ...
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 12 failed, retrying ...
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12

We'll want to fix this eventually, but for now force the bus width to 1
and print a notice to the console that we've done so. This is not
enough, however because it then fails at loading the kernel from MMC:

  ERROR: Time out on waiting for SDMMC_STA. cmd 18
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x804) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 18 failed, retrying ...

Fixing the max frequency at 208 MHz fixes this. So do that and print a
notice for it as well.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/boards/stm32mp157c-dk2/board.c  | 14 ++
 arch/arm/dts/stm32mp157a-dk1.dtsi|  4 
 arch/arm/mach-stm32mp/include/mach/bbu.h | 14 ++
 drivers/mci/stm32_sdmmc2.c   | 15 +--
 4 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/bbu.h

diff --git a/arch/arm/boards/stm32mp157c-dk2/board.c 
b/arch/arm/boards/stm32mp157c-dk2/board.c
index 9cb861af85d8..5bc88781c7ba 100644
--- a/arch/arm/boards/stm32mp157c-dk2/board.c
+++ b/arch/arm/boards/stm32mp157c-dk2/board.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static int dk2_mem_init(void)
 {
@@ -15,3 +16,16 @@ static int dk2_mem_init(void)
return 0;
 }
 mem_initcall(dk2_mem_init);
+
+static int dk2_postcore_init(void)
+{
+   if (!of_machine_is_compatible("st,stm32mp157c-dk2"))
+   return 0;
+
+   stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl",
+BBU_HANDLER_FLAG_DEFAULT);
+
+   return 0;
+}
+
+postcore_initcall(dk2_postcore_init);
diff --git a/arch/arm/dts/stm32mp157a-dk1.dtsi 
b/arch/arm/dts/stm32mp157a-dk1.dtsi
index 7f3b6fcf55ae..05a39d32e2fa 100644
--- a/arch/arm/dts/stm32mp157a-dk1.dtsi
+++ b/arch/arm/dts/stm32mp157a-dk1.dtsi
@@ -8,6 +8,10 @@
 #include 
 
 / {
+   aliases {
+   mmc0 = 
+   };
+
chosen {
environment {
compatible = "barebox,environment";
diff --git a/arch/arm/mach-stm32mp/include/mach/bbu.h 
b/arch/arm/mach-stm32mp/include/mach/bbu.h
new file mode 100644
index ..8b9504400e9e
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/bbu.h
@@ -0,0 +1,14 @@
+#ifndef MACH_STM32MP_BBU_H_
+#define MACH_STM32MP_BBU_H_
+
+#include 
+
+static inline int stm32mp_bbu_mmc_register_handler(const char *name,
+  const char *devicefile,
+  unsigned long flags)
+{
+   return bbu_register_std_file_update(name, flags, devicefile,
+   filetype_stm32_image_v1);
+}
+
+#endif /* MACH_STM32MP_BBU_H_ */
diff --git a/drivers/mci/stm32_sdmmc2.c b/drivers/mci/stm32_sdmmc2.c
index 7346c8a3f5d6..3f0fff1258c0 100644
--- a/drivers/mci/stm32_sdmmc2.c
+++ b/drivers/mci/stm32_sdmmc2.c
@@ -627,11 +627,22 @@ static int stm32_sdmmc2_probe(struct amba_device *adev,
if (IS_ERR(priv->reset_ctl))
priv->reset_ctl = NULL;
 
+   mci_of_parse(>mci);
+
mci->f_min = 40;
-   /* f_max is taken from kernel v5.3 variant_stm32_sdmmc */
-   mci->f_max = 20800;
mci->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
 
+   if (mci->f_max != 20800) {
+   /* f_max is taken from kernel v5.3 variant_stm32_sdmmc */
+   dev_notice(dev, "Fixing max-frequency to 208 MHz due to driver 
limitation\n");
+   mci->f_max = 20800;
+   }
+
+   if (mci->host_caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
+   dev_notice(dev, "Fixing bus-width to 1 due to driver 
limitation\n");
+   mci->host_caps &= ~(MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA);
+   }
+
return mci_register(>mci);
 
 priv_free:
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 8/8] ARM: stm32mp: implement SoC and boot source identification

2019-10-27 Thread Ahmad Fatoum
The BSEC OTP holds information about SoC type and package.
The Tamp registers hold information from the BootROM about boot
source. Add support for both.

Additionally, the tamp registers can also hold a request from the
operating system about what mode to enter after boot, e.g.
boot-into-recovery. A global function is exported for this, but
unused so far.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/mach-stm32mp/Makefile|   3 +-
 .../mach-stm32mp/include/mach/bootsource.h|  33 +++
 arch/arm/mach-stm32mp/include/mach/revision.h |  32 +++
 arch/arm/mach-stm32mp/init.c  | 260 ++
 4 files changed, 327 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/bootsource.h
 create mode 100644 arch/arm/mach-stm32mp/include/mach/revision.h
 create mode 100644 arch/arm/mach-stm32mp/init.c

diff --git a/arch/arm/mach-stm32mp/Makefile b/arch/arm/mach-stm32mp/Makefile
index 204cad608f56..6f495288923a 100644
--- a/arch/arm/mach-stm32mp/Makefile
+++ b/arch/arm/mach-stm32mp/Makefile
@@ -1 +1,2 @@
-obj-$(CONFIG_BOOTM) := stm32image.o
+obj-y := init.o
+obj-$(CONFIG_BOOTM) += stm32image.o
diff --git a/arch/arm/mach-stm32mp/include/mach/bootsource.h 
b/arch/arm/mach-stm32mp/include/mach/bootsource.h
new file mode 100644
index ..1b6f562ac301
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/bootsource.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ */
+
+#ifndef __MACH_STM32_BOOTSOURCE_H__
+#define __MACH_STM32_BOOTSOURCE_H__
+
+enum stm32mp_boot_device {
+   STM32MP_BOOT_FLASH_SD   = 0x10, /* .. 0x13 */
+   STM32MP_BOOT_FLASH_EMMC = 0x20, /* .. 0x23 */
+   STM32MP_BOOT_FLASH_NAND = 0x30,
+   STM32MP_BOOT_FLASH_NAND_FMC = 0x31,
+   STM32MP_BOOT_FLASH_NOR  = 0x40,
+   STM32MP_BOOT_FLASH_NOR_QSPI = 0x41,
+   STM32MP_BOOT_SERIAL_UART= 0x50, /* .. 0x58 */
+   STM32MP_BOOT_SERIAL_USB = 0x60,
+   STM32MP_BOOT_SERIAL_USB_OTG = 0x62,
+};
+
+enum stm32mp_forced_boot_mode {
+   STM32MP_BOOT_NORMAL = 0x00,
+   STM32MP_BOOT_FASTBOOT   = 0x01,
+   STM32MP_BOOT_RECOVERY   = 0x02,
+   STM32MP_BOOT_STM32PROG  = 0x03,
+   STM32MP_BOOT_UMS_MMC0   = 0x10,
+   STM32MP_BOOT_UMS_MMC1   = 0x11,
+   STM32MP_BOOT_UMS_MMC2   = 0x12,
+};
+
+enum stm32mp_forced_boot_mode st32mp_get_forced_boot_mode(void);
+
+#endif
diff --git a/arch/arm/mach-stm32mp/include/mach/revision.h 
b/arch/arm/mach-stm32mp/include/mach/revision.h
new file mode 100644
index ..387201421de7
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/revision.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/*
+ * Copyright (C) 2015-2017, STMicroelectronics - All Rights Reserved
+ */
+
+#ifndef __MACH_CPUTYPE_H__
+#define __MACH_CPUTYPE_H__
+
+/* ID = Device Version (bit31:16) + Device Part Number (RPN) (bit15:0)*/
+#define CPU_STM32MP157Cxx  0x0500
+#define CPU_STM32MP157Axx  0x0501
+#define CPU_STM32MP153Cxx  0x0524
+#define CPU_STM32MP153Axx  0x0525
+#define CPU_STM32MP151Cxx  0x052E
+#define CPU_STM32MP151Axx  0x052F
+
+/* silicon revisions */
+#define CPU_REV_A  0x1000
+#define CPU_REV_B  0x2000
+
+int stm32mp_silicon_revision(void);
+int stm32mp_cputype(void);
+int stm32mp_package(void);
+
+#define cpu_is_stm32mp157c() (stm32mp_cputype() == CPU_STM32MP157Cxx)
+#define cpu_is_stm32mp157a() (stm32mp_cputype() == CPU_STM32MP157Axx)
+#define cpu_is_stm32mp153c() (stm32mp_cputype() == CPU_STM32MP153Cxx)
+#define cpu_is_stm32mp153a() (stm32mp_cputype() == CPU_STM32MP153Axx)
+#define cpu_is_stm32mp151c() (stm32mp_cputype() == CPU_STM32MP151Cxx)
+#define cpu_is_stm32mp151a() (stm32mp_cputype() == CPU_STM32MP151Axx)
+
+#endif /* __MACH_CPUTYPE_H__ */
diff --git a/arch/arm/mach-stm32mp/init.c b/arch/arm/mach-stm32mp/init.c
new file mode 100644
index ..7bad989a609b
--- /dev/null
+++ b/arch/arm/mach-stm32mp/init.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ * Copyright (C) 2019 Ahmad Fatoum, Pengutronix
+ */
+
+#define pr_fmt(fmt) "stm32mp-init: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* DBGMCU register */
+#define DBGMCU_IDC (STM32_DBGMCU_BASE + 0x00)
+#define DBGMCU_APB4FZ1 (STM32_DBGMCU_BASE + 0x2C)
+#define DBGMCU_APB4FZ1_IWDG2   BIT(2)
+#define DBGMCU_IDC_DEV_ID_MASK GENMASK(11, 0)
+#define DBGMCU_IDC_DEV_ID_SHIFT0
+#define DBGMCU_IDC_REV_ID_MASK GENMASK(31, 16)
+#define DBGMCU_IDC_REV_ID_SHIFT16
+
+#define RCC_DBGCFGR(STM32_RCC_BASE + 0x080C)
+#define RCC_DBGCFGR_DBGCKENBIT(8)
+
+/* BSEC OTP index */
+#define BSEC_OTP_RPN   1
+#define BSEC_OTP_PKG   16
+
+/* Device Part 

[PATCH v2 6/8] nvmem: add read support for STM32MP1 bsec OTP

2019-10-27 Thread Ahmad Fatoum
The bsec on the STM32MP157C provides a 380 byte OTP. Add initial support
for reading and writing the shadow copy of the fuses. Direct fuse
access is not yet supported.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/dts/stm32mp157c.dtsi |   4 +
 arch/arm/mach-stm32mp/include/mach/bsec.h |  41 
 arch/arm/mach-stm32mp/include/mach/smc.h  |  28 +++
 drivers/nvmem/Kconfig |   8 +
 drivers/nvmem/Makefile|   5 +-
 drivers/nvmem/bsec.c  | 221 ++
 6 files changed, 306 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/bsec.h
 create mode 100644 arch/arm/mach-stm32mp/include/mach/smc.h
 create mode 100644 drivers/nvmem/bsec.c

diff --git a/arch/arm/dts/stm32mp157c.dtsi b/arch/arm/dts/stm32mp157c.dtsi
index 8d9c84a04785..771139c28af0 100644
--- a/arch/arm/dts/stm32mp157c.dtsi
+++ b/arch/arm/dts/stm32mp157c.dtsi
@@ -20,3 +20,7 @@
gpio25 = 
};
 };
+
+ {
+   barebox,provide-mac-address = < 0x39>;
+};
diff --git a/arch/arm/mach-stm32mp/include/mach/bsec.h 
b/arch/arm/mach-stm32mp/include/mach/bsec.h
new file mode 100644
index ..559faaa2bac3
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/bsec.h
@@ -0,0 +1,41 @@
+#ifndef __MACH_STM32_BSEC_H__
+#define __MACH_STM32_BSEC_H__
+
+#include 
+
+/* Return status */
+enum bsec_smc {
+   BSEC_SMC_OK = 0,
+   BSEC_SMC_ERROR  = -1,
+   BSEC_SMC_DISTURBED  = -2,
+   BSEC_SMC_INVALID_PARAM  = -3,
+   BSEC_SMC_PROG_FAIL  = -4,
+   BSEC_SMC_LOCK_FAIL  = -5,
+   BSEC_SMC_WRITE_FAIL = -6,
+   BSEC_SMC_SHADOW_FAIL= -7,
+   BSEC_SMC_TIMEOUT= -8,
+};
+
+/* Service for BSEC */
+enum bsec_field {
+   BSEC_SMC_READ_SHADOW= 1,
+   BSEC_SMC_PROG_OTP   = 2,
+   BSEC_SMC_WRITE_SHADOW   = 3,
+   BSEC_SMC_READ_OTP   = 4,
+   BSEC_SMC_READ_ALL   = 5,
+   BSEC_SMC_WRITE_ALL  = 6,
+};
+
+static inline enum bsec_smc bsec_read_field(enum bsec_field field, unsigned 
*val)
+{
+   return stm32mp_smc(STM32_SMC_BSEC, BSEC_SMC_READ_SHADOW,
+  field, 0, val);
+}
+
+static inline enum bsec_smc bsec_write_field(enum bsec_field field, unsigned 
val)
+{
+   return stm32mp_smc(STM32_SMC_BSEC, BSEC_SMC_WRITE_SHADOW,
+  field, val, NULL);
+}
+
+#endif
diff --git a/arch/arm/mach-stm32mp/include/mach/smc.h 
b/arch/arm/mach-stm32mp/include/mach/smc.h
new file mode 100644
index ..6b8e62bd5302
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/smc.h
@@ -0,0 +1,28 @@
+#ifndef __MACH_STM32_SMC_H__
+#define __MACH_STM32_SMC_H__
+
+#include 
+
+/* Secure Service access from Non-secure */
+#define STM32_SMC_RCC   0x82001000
+#define STM32_SMC_PWR   0x82001001
+#define STM32_SMC_RTC   0x82001002
+#define STM32_SMC_BSEC  0x82001003
+
+/* Register access service use for RCC/RTC/PWR */
+#define STM32_SMC_REG_WRITE 0x1
+#define STM32_SMC_REG_SET   0x2
+#define STM32_SMC_REG_CLEAR 0x3
+
+static inline int stm32mp_smc(u32 svc, u8 op, u32 data1, u32 data2, u32 *val)
+{
+struct arm_smccc_res res;
+
+arm_smccc_smc(svc, op, data1, data2, 0, 0, 0, 0, );
+if (val)
+*val = res.a1;
+
+return (int)res.a0;
+}
+
+#endif
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index c28a6d4e43c8..968342b281ad 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -51,4 +51,12 @@ config EEPROM_93XX46
  supports both read and write commands and also the command to
  erase the whole EEPROM.
 
+config STM32_BSEC
+   tristate "STM32 Boot and security and OTP control"
+   depends on ARCH_STM32MP
+   depends on OFDEVICE
+   help
+ This adds support for the STM32 OTP controller. Reads and writes
+ to will go to the shadow RAM, not the OTP fuses themselvers.
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index abf9dae429e2..7101c5aca44c 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -16,4 +16,7 @@ obj-$(CONFIG_RAVE_SP_EEPROM)  += nvmem-rave-sp-eeprom.o
 nvmem-rave-sp-eeprom-y := rave-sp-eeprom.o
 
 obj-$(CONFIG_EEPROM_93XX46)+= nvmem_eeprom_93xx46.o
-nvmem_eeprom_93xx46-y  := eeprom_93xx46.o
\ No newline at end of file
+nvmem_eeprom_93xx46-y  := eeprom_93xx46.o
+
+obj-$(CONFIG_STM32_BSEC)   += nvmem_bsec.o
+nvmem_bsec-y   := bsec.o
diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
new file mode 100644
index ..8235d468d16d
--- /dev/null
+++ b/drivers/nvmem/bsec.c
@@ -0,0 +1,221 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ * Copyright (c) 2019 Ahmad Fatoum, Pengutronix
+ */
+
+#include 
+#include 
+#include 

[PATCH v2 3/8] pinctrl: stm32: parse pinctrl nodes without subnodes as well

2019-10-27 Thread Ahmad Fatoum
The bindings allow the pinmux node to occur directly in the node under
the pin controller as well. Check for this and support both types of
pinctrl specification.

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl-stm32.c | 180 ++--
 1 file changed, 99 insertions(+), 81 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index c199d74846e8..cdaed510c564 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -87,110 +87,128 @@ static inline u32 stm32_gpio_get_alt(u32 function)
return 0;
 }
 
-static int stm32_pinctrl_set_state(struct pinctrl_device *pdev, struct 
device_node *group)
+static int __stm32_pinctrl_set_state(struct device_d *dev, struct device_node 
*pins)
 {
-   struct stm32_pinctrl *pinctrl = to_stm32_pinctrl(pdev);
-   struct device_node *pins;
int ret;
 
-   ret = hwspinlock_lock_timeout(>hws, 10);
-   if (ret == -ETIMEDOUT) {
-   dev_err(pdev->dev, "hw spinlock timeout\n");
-   return ret;
+   int num_pins = 0, i;
+   u32 slew_rate;
+   bool adjust_slew_rate = false;
+   enum stm32_pin_bias bias = -1;
+   enum stm32_pin_out_type out_type = -1;
+   enum { PIN_INPUT, PIN_OUTPUT_LOW, PIN_OUTPUT_HIGH } dir = -1;
+
+   of_get_property(pins, "pinmux", _pins);
+   num_pins /= sizeof(__be32);
+   if (!num_pins) {
+   dev_err(dev, "Invalid pinmux property in %s\n",
+   pins->full_name);
+   return -EINVAL;
}
 
-   for_each_child_of_node(group, pins) {
-   int num_pins = 0, i;
-   u32 slew_rate;
-   bool adjust_slew_rate = false;
-   enum stm32_pin_bias bias = -1;
-   enum stm32_pin_out_type out_type = -1;
-   enum { PIN_INPUT, PIN_OUTPUT_LOW, PIN_OUTPUT_HIGH } dir = -1;
-
-   of_get_property(pins, "pinmux", _pins);
-   num_pins /= sizeof(__be32);
-   if (!num_pins) {
-   dev_err(pdev->dev, "Invalid pinmux property in %s\n",
-   pins->full_name);
-   return -EINVAL;
-   }
-
-   ret = of_property_read_u32(pins, "slew-rate", _rate);
-   if (!ret)
-   adjust_slew_rate = true;
-
-   if (of_get_property(pins, "bias-disable", NULL))
-   bias = STM32_PIN_NO_BIAS;
-   else if (of_get_property(pins, "bias-pull-up", NULL))
-   bias = STM32_PIN_PULL_UP;
-   else if (of_get_property(pins, "bias-pull-down", NULL))
-   bias = STM32_PIN_PULL_DOWN;
+   ret = of_property_read_u32(pins, "slew-rate", _rate);
+   if (!ret)
+   adjust_slew_rate = true;
+
+   if (of_get_property(pins, "bias-disable", NULL))
+   bias = STM32_PIN_NO_BIAS;
+   else if (of_get_property(pins, "bias-pull-up", NULL))
+   bias = STM32_PIN_PULL_UP;
+   else if (of_get_property(pins, "bias-pull-down", NULL))
+   bias = STM32_PIN_PULL_DOWN;
+
+   if (of_get_property(pins, "drive-push-pull", NULL))
+   out_type = STM32_PIN_OUT_PUSHPULL;
+   else if (of_get_property(pins, "drive-open-drain", NULL))
+   out_type = STM32_PIN_OUT_OPENDRAIN;
+
+   if (of_get_property(pins, "input-enable", NULL))
+   dir = PIN_INPUT;
+   else if (of_get_property(pins, "output-low", NULL))
+   dir = PIN_OUTPUT_LOW;
+   else if (of_get_property(pins, "output-high", NULL))
+   dir = PIN_OUTPUT_HIGH;
+
+   dev_dbg(dev, "%s: multiplexing %d pins\n", pins->full_name, num_pins);
+
+   for (i = 0; i < num_pins; i++) {
+   struct stm32_gpio_bank *bank = NULL;
+   u32 pinfunc, mode, alt;
+   unsigned func;
+   int offset;
+
+   ret = of_property_read_u32_index(pins, "pinmux",
+   i, );
+   if (ret)
+   return ret;
 
-   if (of_get_property(pins, "drive-push-pull", NULL))
-   out_type = STM32_PIN_OUT_PUSHPULL;
-   else if (of_get_property(pins, "drive-open-drain", NULL))
-   out_type = STM32_PIN_OUT_OPENDRAIN;
+   func = STM32_GET_PIN_FUNC(pinfunc);
+   offset = stm32_gpio_pin(STM32_GET_PIN_NO(pinfunc), );
+   if (offset < 0)
+   return -ENODEV;
 
-   if (of_get_property(pins, "input-enable", NULL))
-   dir = PIN_INPUT;
-   else if (of_get_property(pins, "output-low", NULL))
-   dir = PIN_OUTPUT_LOW;
-   else if (of_get_property(pins, "output-high", NULL))
-   dir = PIN_OUTPUT_HIGH;
+   mode = 

[PATCH 5/8] ARM: stm32mp: select ARM_SMCCC always

2019-10-27 Thread Ahmad Fatoum
ARM_SMCCC compiles in the code for issuing ARM secure monitor calls.
We need those on the STM32MP, because barebox runs in non-secure mode
and does some operations like reading the BSEC OTP through SMCs.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d4947cef5c98..f82844a83a5e 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -201,6 +201,7 @@ config ARCH_STM32MP
select GPIOLIB
select ARCH_HAS_RESET_CONTROLLER
select ARM_AMBA
+   select ARM_SMCCC
 
 config ARCH_VERSATILE
bool "ARM Versatile boards (ARM926EJ-S)"
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 7/8] ARM: stm32mp: dk2: add barebox SD-Card update handler

2019-10-27 Thread Ahmad Fatoum
Now with the SD/MMC controller supported, lets add a bbu handler, so we
can use it to update the second stage boot loader partition.

While doing this, I noticed that making use of the bus-width = <4>
property in the device tree now makes mmc usage fail when reading the
environment:

  ERROR: error SDMMC_STA_DCRCFAIL (0x81042) for cmd 18
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 12 failed, retrying ...
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 12 failed, retrying ...
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 12 failed, retrying ...
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x4) for cmd 12

We'll want to fix this eventually, but for now force the bus width to 1
and print a notice to the console that we've done so. This is not
enough, however because it then fails at loading the kernel from MMC:

  ERROR: Time out on waiting for SDMMC_STA. cmd 18
  ERROR: stm32_sdmmc2_end_cmd: error SDMMC_STA_CTIMEOUT (0x804) for cmd 12
  WARNING: stm32_sdmmc2_send_cmd: cmd 18 failed, retrying ...

Fixing the max frequency at 208 MHz fixes this. So do that and print a
notice for it as well.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/boards/stm32mp157c-dk2/board.c  | 14 ++
 arch/arm/dts/stm32mp157a-dk1.dtsi|  4 
 arch/arm/mach-stm32mp/include/mach/bbu.h | 14 ++
 drivers/mci/stm32_sdmmc2.c   | 15 +--
 4 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/bbu.h

diff --git a/arch/arm/boards/stm32mp157c-dk2/board.c 
b/arch/arm/boards/stm32mp157c-dk2/board.c
index 9cb861af85d8..5bc88781c7ba 100644
--- a/arch/arm/boards/stm32mp157c-dk2/board.c
+++ b/arch/arm/boards/stm32mp157c-dk2/board.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static int dk2_mem_init(void)
 {
@@ -15,3 +16,16 @@ static int dk2_mem_init(void)
return 0;
 }
 mem_initcall(dk2_mem_init);
+
+static int dk2_postcore_init(void)
+{
+   if (!of_machine_is_compatible("st,stm32mp157c-dk2"))
+   return 0;
+
+   stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl",
+BBU_HANDLER_FLAG_DEFAULT);
+
+   return 0;
+}
+
+postcore_initcall(dk2_postcore_init);
diff --git a/arch/arm/dts/stm32mp157a-dk1.dtsi 
b/arch/arm/dts/stm32mp157a-dk1.dtsi
index 7f3b6fcf55ae..05a39d32e2fa 100644
--- a/arch/arm/dts/stm32mp157a-dk1.dtsi
+++ b/arch/arm/dts/stm32mp157a-dk1.dtsi
@@ -8,6 +8,10 @@
 #include 
 
 / {
+   aliases {
+   mmc0 = 
+   };
+
chosen {
environment {
compatible = "barebox,environment";
diff --git a/arch/arm/mach-stm32mp/include/mach/bbu.h 
b/arch/arm/mach-stm32mp/include/mach/bbu.h
new file mode 100644
index ..8b9504400e9e
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/bbu.h
@@ -0,0 +1,14 @@
+#ifndef MACH_STM32MP_BBU_H_
+#define MACH_STM32MP_BBU_H_
+
+#include 
+
+static inline int stm32mp_bbu_mmc_register_handler(const char *name,
+  const char *devicefile,
+  unsigned long flags)
+{
+   return bbu_register_std_file_update(name, flags, devicefile,
+   filetype_stm32_image_v1);
+}
+
+#endif /* MACH_STM32MP_BBU_H_ */
diff --git a/drivers/mci/stm32_sdmmc2.c b/drivers/mci/stm32_sdmmc2.c
index 7346c8a3f5d6..3f0fff1258c0 100644
--- a/drivers/mci/stm32_sdmmc2.c
+++ b/drivers/mci/stm32_sdmmc2.c
@@ -627,11 +627,22 @@ static int stm32_sdmmc2_probe(struct amba_device *adev,
if (IS_ERR(priv->reset_ctl))
priv->reset_ctl = NULL;
 
+   mci_of_parse(>mci);
+
mci->f_min = 40;
-   /* f_max is taken from kernel v5.3 variant_stm32_sdmmc */
-   mci->f_max = 20800;
mci->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
 
+   if (mci->f_max != 20800) {
+   /* f_max is taken from kernel v5.3 variant_stm32_sdmmc */
+   dev_notice(dev, "Fixing max-frequency to 208 MHz due to driver 
limitation\n");
+   mci->f_max = 20800;
+   }
+
+   if (mci->host_caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
+   dev_notice(dev, "Fixing bus-width to 1 due to driver 
limitation\n");
+   mci->host_caps &= ~(MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA);
+   }
+
return mci_register(>mci);
 
 priv_free:
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


rom 3eed5e64521bacd6f8e84326aa98db7402ffc6fd Mon Sep 17 00:00:00 2001

2019-10-27 Thread Ahmad Fatoum
mode and alt are printed with the dev_dbg before they are initialized.
Remedy this by moving the dev_dbg after them.

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl-stm32.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index 7f04cea50b75..ab121998a37f 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -157,13 +157,13 @@ static int stm32_pinctrl_set_state(struct pinctrl_device 
*pdev, struct device_no
if (offset < 0)
return -ENODEV;
 
+   mode = stm32_gpio_get_mode(func);
+   alt = stm32_gpio_get_alt(func);
+
dev_dbg(pdev->dev, "configuring port %s pin %u 
with:\n\t"
"fn %u, mode %u, alt %u\n",
bank->name, offset, func, mode, alt);
 
-   mode = stm32_gpio_get_mode(func);
-   alt = stm32_gpio_get_alt(func);
-
clk_enable(bank->clk);
 
__stm32_pmx_set_mode(bank->base, offset, mode, alt);
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 8/8] ARM: stm32mp: implement SoC and boot source identification

2019-10-27 Thread Ahmad Fatoum
The BSEC OTP holds information about SoC type and package.
The Tamp registers hold information from the BootROM about boot
source. Add support for both.

Additionally, the tamp registers can also hold a request from the
operating system about what mode to enter after boot, e.g.
boot-into-recovery. A global function is exported for this, but
unused so far.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/mach-stm32mp/Makefile|   3 +-
 .../mach-stm32mp/include/mach/bootsource.h|  33 +++
 arch/arm/mach-stm32mp/include/mach/revision.h |  32 +++
 arch/arm/mach-stm32mp/init.c  | 260 ++
 4 files changed, 327 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/bootsource.h
 create mode 100644 arch/arm/mach-stm32mp/include/mach/revision.h
 create mode 100644 arch/arm/mach-stm32mp/init.c

diff --git a/arch/arm/mach-stm32mp/Makefile b/arch/arm/mach-stm32mp/Makefile
index 204cad608f56..6f495288923a 100644
--- a/arch/arm/mach-stm32mp/Makefile
+++ b/arch/arm/mach-stm32mp/Makefile
@@ -1 +1,2 @@
-obj-$(CONFIG_BOOTM) := stm32image.o
+obj-y := init.o
+obj-$(CONFIG_BOOTM) += stm32image.o
diff --git a/arch/arm/mach-stm32mp/include/mach/bootsource.h 
b/arch/arm/mach-stm32mp/include/mach/bootsource.h
new file mode 100644
index ..1b6f562ac301
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/bootsource.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ */
+
+#ifndef __MACH_STM32_BOOTSOURCE_H__
+#define __MACH_STM32_BOOTSOURCE_H__
+
+enum stm32mp_boot_device {
+   STM32MP_BOOT_FLASH_SD   = 0x10, /* .. 0x13 */
+   STM32MP_BOOT_FLASH_EMMC = 0x20, /* .. 0x23 */
+   STM32MP_BOOT_FLASH_NAND = 0x30,
+   STM32MP_BOOT_FLASH_NAND_FMC = 0x31,
+   STM32MP_BOOT_FLASH_NOR  = 0x40,
+   STM32MP_BOOT_FLASH_NOR_QSPI = 0x41,
+   STM32MP_BOOT_SERIAL_UART= 0x50, /* .. 0x58 */
+   STM32MP_BOOT_SERIAL_USB = 0x60,
+   STM32MP_BOOT_SERIAL_USB_OTG = 0x62,
+};
+
+enum stm32mp_forced_boot_mode {
+   STM32MP_BOOT_NORMAL = 0x00,
+   STM32MP_BOOT_FASTBOOT   = 0x01,
+   STM32MP_BOOT_RECOVERY   = 0x02,
+   STM32MP_BOOT_STM32PROG  = 0x03,
+   STM32MP_BOOT_UMS_MMC0   = 0x10,
+   STM32MP_BOOT_UMS_MMC1   = 0x11,
+   STM32MP_BOOT_UMS_MMC2   = 0x12,
+};
+
+enum stm32mp_forced_boot_mode st32mp_get_forced_boot_mode(void);
+
+#endif
diff --git a/arch/arm/mach-stm32mp/include/mach/revision.h 
b/arch/arm/mach-stm32mp/include/mach/revision.h
new file mode 100644
index ..387201421de7
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/revision.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/*
+ * Copyright (C) 2015-2017, STMicroelectronics - All Rights Reserved
+ */
+
+#ifndef __MACH_CPUTYPE_H__
+#define __MACH_CPUTYPE_H__
+
+/* ID = Device Version (bit31:16) + Device Part Number (RPN) (bit15:0)*/
+#define CPU_STM32MP157Cxx  0x0500
+#define CPU_STM32MP157Axx  0x0501
+#define CPU_STM32MP153Cxx  0x0524
+#define CPU_STM32MP153Axx  0x0525
+#define CPU_STM32MP151Cxx  0x052E
+#define CPU_STM32MP151Axx  0x052F
+
+/* silicon revisions */
+#define CPU_REV_A  0x1000
+#define CPU_REV_B  0x2000
+
+int stm32mp_silicon_revision(void);
+int stm32mp_cputype(void);
+int stm32mp_package(void);
+
+#define cpu_is_stm32mp157c() (stm32mp_cputype() == CPU_STM32MP157Cxx)
+#define cpu_is_stm32mp157a() (stm32mp_cputype() == CPU_STM32MP157Axx)
+#define cpu_is_stm32mp153c() (stm32mp_cputype() == CPU_STM32MP153Cxx)
+#define cpu_is_stm32mp153a() (stm32mp_cputype() == CPU_STM32MP153Axx)
+#define cpu_is_stm32mp151c() (stm32mp_cputype() == CPU_STM32MP151Cxx)
+#define cpu_is_stm32mp151a() (stm32mp_cputype() == CPU_STM32MP151Axx)
+
+#endif /* __MACH_CPUTYPE_H__ */
diff --git a/arch/arm/mach-stm32mp/init.c b/arch/arm/mach-stm32mp/init.c
new file mode 100644
index ..7bad989a609b
--- /dev/null
+++ b/arch/arm/mach-stm32mp/init.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ * Copyright (C) 2019 Ahmad Fatoum, Pengutronix
+ */
+
+#define pr_fmt(fmt) "stm32mp-init: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* DBGMCU register */
+#define DBGMCU_IDC (STM32_DBGMCU_BASE + 0x00)
+#define DBGMCU_APB4FZ1 (STM32_DBGMCU_BASE + 0x2C)
+#define DBGMCU_APB4FZ1_IWDG2   BIT(2)
+#define DBGMCU_IDC_DEV_ID_MASK GENMASK(11, 0)
+#define DBGMCU_IDC_DEV_ID_SHIFT0
+#define DBGMCU_IDC_REV_ID_MASK GENMASK(31, 16)
+#define DBGMCU_IDC_REV_ID_SHIFT16
+
+#define RCC_DBGCFGR(STM32_RCC_BASE + 0x080C)
+#define RCC_DBGCFGR_DBGCKENBIT(8)
+
+/* BSEC OTP index */
+#define BSEC_OTP_RPN   1
+#define BSEC_OTP_PKG   16
+
+/* Device Part 

[PATCH 3/8] pinctrl: stm32: parse pinctrl nodes without subnodes as well

2019-10-27 Thread Ahmad Fatoum
The bindings allow the pinmux node to occur directly in the node under
the pin controller as well. Check for this and support both types of
pinctrl specification.

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl-stm32.c | 180 ++--
 1 file changed, 99 insertions(+), 81 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index c199d74846e8..cdaed510c564 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -87,110 +87,128 @@ static inline u32 stm32_gpio_get_alt(u32 function)
return 0;
 }
 
-static int stm32_pinctrl_set_state(struct pinctrl_device *pdev, struct 
device_node *group)
+static int __stm32_pinctrl_set_state(struct device_d *dev, struct device_node 
*pins)
 {
-   struct stm32_pinctrl *pinctrl = to_stm32_pinctrl(pdev);
-   struct device_node *pins;
int ret;
 
-   ret = hwspinlock_lock_timeout(>hws, 10);
-   if (ret == -ETIMEDOUT) {
-   dev_err(pdev->dev, "hw spinlock timeout\n");
-   return ret;
+   int num_pins = 0, i;
+   u32 slew_rate;
+   bool adjust_slew_rate = false;
+   enum stm32_pin_bias bias = -1;
+   enum stm32_pin_out_type out_type = -1;
+   enum { PIN_INPUT, PIN_OUTPUT_LOW, PIN_OUTPUT_HIGH } dir = -1;
+
+   of_get_property(pins, "pinmux", _pins);
+   num_pins /= sizeof(__be32);
+   if (!num_pins) {
+   dev_err(dev, "Invalid pinmux property in %s\n",
+   pins->full_name);
+   return -EINVAL;
}
 
-   for_each_child_of_node(group, pins) {
-   int num_pins = 0, i;
-   u32 slew_rate;
-   bool adjust_slew_rate = false;
-   enum stm32_pin_bias bias = -1;
-   enum stm32_pin_out_type out_type = -1;
-   enum { PIN_INPUT, PIN_OUTPUT_LOW, PIN_OUTPUT_HIGH } dir = -1;
-
-   of_get_property(pins, "pinmux", _pins);
-   num_pins /= sizeof(__be32);
-   if (!num_pins) {
-   dev_err(pdev->dev, "Invalid pinmux property in %s\n",
-   pins->full_name);
-   return -EINVAL;
-   }
-
-   ret = of_property_read_u32(pins, "slew-rate", _rate);
-   if (!ret)
-   adjust_slew_rate = true;
-
-   if (of_get_property(pins, "bias-disable", NULL))
-   bias = STM32_PIN_NO_BIAS;
-   else if (of_get_property(pins, "bias-pull-up", NULL))
-   bias = STM32_PIN_PULL_UP;
-   else if (of_get_property(pins, "bias-pull-down", NULL))
-   bias = STM32_PIN_PULL_DOWN;
+   ret = of_property_read_u32(pins, "slew-rate", _rate);
+   if (!ret)
+   adjust_slew_rate = true;
+
+   if (of_get_property(pins, "bias-disable", NULL))
+   bias = STM32_PIN_NO_BIAS;
+   else if (of_get_property(pins, "bias-pull-up", NULL))
+   bias = STM32_PIN_PULL_UP;
+   else if (of_get_property(pins, "bias-pull-down", NULL))
+   bias = STM32_PIN_PULL_DOWN;
+
+   if (of_get_property(pins, "drive-push-pull", NULL))
+   out_type = STM32_PIN_OUT_PUSHPULL;
+   else if (of_get_property(pins, "drive-open-drain", NULL))
+   out_type = STM32_PIN_OUT_OPENDRAIN;
+
+   if (of_get_property(pins, "input-enable", NULL))
+   dir = PIN_INPUT;
+   else if (of_get_property(pins, "output-low", NULL))
+   dir = PIN_OUTPUT_LOW;
+   else if (of_get_property(pins, "output-high", NULL))
+   dir = PIN_OUTPUT_HIGH;
+
+   dev_dbg(dev, "%s: multiplexing %d pins\n", pins->full_name, num_pins);
+
+   for (i = 0; i < num_pins; i++) {
+   struct stm32_gpio_bank *bank = NULL;
+   u32 pinfunc, mode, alt;
+   unsigned func;
+   int offset;
+
+   ret = of_property_read_u32_index(pins, "pinmux",
+   i, );
+   if (ret)
+   return ret;
 
-   if (of_get_property(pins, "drive-push-pull", NULL))
-   out_type = STM32_PIN_OUT_PUSHPULL;
-   else if (of_get_property(pins, "drive-open-drain", NULL))
-   out_type = STM32_PIN_OUT_OPENDRAIN;
+   func = STM32_GET_PIN_FUNC(pinfunc);
+   offset = stm32_gpio_pin(STM32_GET_PIN_NO(pinfunc), );
+   if (offset < 0)
+   return -ENODEV;
 
-   if (of_get_property(pins, "input-enable", NULL))
-   dir = PIN_INPUT;
-   else if (of_get_property(pins, "output-low", NULL))
-   dir = PIN_OUTPUT_LOW;
-   else if (of_get_property(pins, "output-high", NULL))
-   dir = PIN_OUTPUT_HIGH;
+   mode = 

[PATCH 4/8] ARM: sm: document SMC/PSCI related options

2019-10-27 Thread Ahmad Fatoum
At least to me, the difference between these options were confusing at
first. Clear this up.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/Kconfig | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 725ea12a8c57..d4947cef5c98 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -427,10 +427,14 @@ config ARM_SEMIHOSTING
 
 config ARM_SMCCC
bool
+   help
+ This option enables barebox to invoke ARM secure monitor calls.
 
 config ARM_SECURE_MONITOR
select ARM_SMCCC
bool
+   help
+ This option enables barebox to service ARM secure monitor calls.
 
 config ARM_PSCI_OF
bool
@@ -442,7 +446,7 @@ config ARM_PSCI
select ARM_PSCI_OF
help
  PSCI is used for controlling secondary CPU cores on some systems. Say
- yes here if you have one of these.
+ yes here if you want barebox to service PSCI calls on such systems.
 
 config ARM_PSCI_DEBUG
bool "Enable PSCI debugging"
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 6/8] nvmem: add read support for STM32MP1 bsec OTP

2019-10-27 Thread Ahmad Fatoum
The bsec on the STM32MP157C provides a 380 byte OTP. Add initial support
for reading and writing the shadow copy of the fuses. Direct fuse
access is not yet supported.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/dts/stm32mp157c.dtsi |   4 +
 arch/arm/mach-stm32mp/include/mach/bsec.h |  41 
 arch/arm/mach-stm32mp/include/mach/smc.h  |  28 +++
 drivers/nvmem/Kconfig |   8 +
 drivers/nvmem/Makefile|   5 +-
 drivers/nvmem/bsec.c  | 221 ++
 6 files changed, 306 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/bsec.h
 create mode 100644 arch/arm/mach-stm32mp/include/mach/smc.h
 create mode 100644 drivers/nvmem/bsec.c

diff --git a/arch/arm/dts/stm32mp157c.dtsi b/arch/arm/dts/stm32mp157c.dtsi
index 8d9c84a04785..771139c28af0 100644
--- a/arch/arm/dts/stm32mp157c.dtsi
+++ b/arch/arm/dts/stm32mp157c.dtsi
@@ -20,3 +20,7 @@
gpio25 = 
};
 };
+
+ {
+   barebox,provide-mac-address = < 0x39>;
+};
diff --git a/arch/arm/mach-stm32mp/include/mach/bsec.h 
b/arch/arm/mach-stm32mp/include/mach/bsec.h
new file mode 100644
index ..559faaa2bac3
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/bsec.h
@@ -0,0 +1,41 @@
+#ifndef __MACH_STM32_BSEC_H__
+#define __MACH_STM32_BSEC_H__
+
+#include 
+
+/* Return status */
+enum bsec_smc {
+   BSEC_SMC_OK = 0,
+   BSEC_SMC_ERROR  = -1,
+   BSEC_SMC_DISTURBED  = -2,
+   BSEC_SMC_INVALID_PARAM  = -3,
+   BSEC_SMC_PROG_FAIL  = -4,
+   BSEC_SMC_LOCK_FAIL  = -5,
+   BSEC_SMC_WRITE_FAIL = -6,
+   BSEC_SMC_SHADOW_FAIL= -7,
+   BSEC_SMC_TIMEOUT= -8,
+};
+
+/* Service for BSEC */
+enum bsec_field {
+   BSEC_SMC_READ_SHADOW= 1,
+   BSEC_SMC_PROG_OTP   = 2,
+   BSEC_SMC_WRITE_SHADOW   = 3,
+   BSEC_SMC_READ_OTP   = 4,
+   BSEC_SMC_READ_ALL   = 5,
+   BSEC_SMC_WRITE_ALL  = 6,
+};
+
+static inline enum bsec_smc bsec_read_field(enum bsec_field field, unsigned 
*val)
+{
+   return stm32mp_smc(STM32_SMC_BSEC, BSEC_SMC_READ_SHADOW,
+  field, 0, val);
+}
+
+static inline enum bsec_smc bsec_write_field(enum bsec_field field, unsigned 
val)
+{
+   return stm32mp_smc(STM32_SMC_BSEC, BSEC_SMC_WRITE_SHADOW,
+  field, val, NULL);
+}
+
+#endif
diff --git a/arch/arm/mach-stm32mp/include/mach/smc.h 
b/arch/arm/mach-stm32mp/include/mach/smc.h
new file mode 100644
index ..6b8e62bd5302
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/smc.h
@@ -0,0 +1,28 @@
+#ifndef __MACH_STM32_SMC_H__
+#define __MACH_STM32_SMC_H__
+
+#include 
+
+/* Secure Service access from Non-secure */
+#define STM32_SMC_RCC   0x82001000
+#define STM32_SMC_PWR   0x82001001
+#define STM32_SMC_RTC   0x82001002
+#define STM32_SMC_BSEC  0x82001003
+
+/* Register access service use for RCC/RTC/PWR */
+#define STM32_SMC_REG_WRITE 0x1
+#define STM32_SMC_REG_SET   0x2
+#define STM32_SMC_REG_CLEAR 0x3
+
+static inline int stm32mp_smc(u32 svc, u8 op, u32 data1, u32 data2, u32 *val)
+{
+struct arm_smccc_res res;
+
+arm_smccc_smc(svc, op, data1, data2, 0, 0, 0, 0, );
+if (val)
+*val = res.a1;
+
+return (int)res.a0;
+}
+
+#endif
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index c28a6d4e43c8..968342b281ad 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -51,4 +51,12 @@ config EEPROM_93XX46
  supports both read and write commands and also the command to
  erase the whole EEPROM.
 
+config STM32_BSEC
+   tristate "STM32 Boot and security and OTP control"
+   depends on ARCH_STM32MP
+   depends on OFDEVICE
+   help
+ This adds support for the STM32 OTP controller. Reads and writes
+ to will go to the shadow RAM, not the OTP fuses themselvers.
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index abf9dae429e2..7101c5aca44c 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -16,4 +16,7 @@ obj-$(CONFIG_RAVE_SP_EEPROM)  += nvmem-rave-sp-eeprom.o
 nvmem-rave-sp-eeprom-y := rave-sp-eeprom.o
 
 obj-$(CONFIG_EEPROM_93XX46)+= nvmem_eeprom_93xx46.o
-nvmem_eeprom_93xx46-y  := eeprom_93xx46.o
\ No newline at end of file
+nvmem_eeprom_93xx46-y  := eeprom_93xx46.o
+
+obj-$(CONFIG_STM32_BSEC)   += nvmem_bsec.o
+nvmem_bsec-y   := bsec.o
diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
new file mode 100644
index ..8235d468d16d
--- /dev/null
+++ b/drivers/nvmem/bsec.c
@@ -0,0 +1,221 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ * Copyright (c) 2019 Ahmad Fatoum, Pengutronix
+ */
+
+#include 
+#include 
+#include 

[PATCH 2/8] pinctrl: demote dev_info on successful probes to dev_dbg

2019-10-27 Thread Ahmad Fatoum
The SoC's pin controller is virtually always built and probed, so
there's is little information to gain from the fact it was successfully
probed. Have the success message show up as debug message to reduce probe
clutter like this:

NOTICE: stm32-pinctrl soc:pin-control...@50002000.of: pinctrl/gpio 
driver registered
NOTICE: stm32-pinctrl soc:pin-controlle...@54004000.of: pinctrl/gpio 
driver registered

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl-at91-pio4.c | 4 ++--
 drivers/pinctrl/pinctrl-bcm2835.c   | 2 +-
 drivers/pinctrl/pinctrl-stm32.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c 
b/drivers/pinctrl/pinctrl-at91-pio4.c
index 9bc259f84cca..b527114f1ba0 100644
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -260,7 +260,7 @@ static int pinctrl_at91_pio4_gpiochip_add(struct device_d 
*dev,
return ret;
}
 
-   dev_info(dev, "gpio driver registered\n");
+   dev_dbg(dev, "gpio driver registered\n");
 
return 0;
 }
@@ -290,7 +290,7 @@ static int pinctrl_at91_pio4_probe(struct device_d *dev)
if (ret)
return ret;
 
-   dev_info(dev, "pinctrl driver registered\n");
+   dev_dbg(dev, "pinctrl driver registered\n");
 
if (of_get_property(np, "gpio-controller", NULL))
return pinctrl_at91_pio4_gpiochip_add(dev, pinctrl);
diff --git a/drivers/pinctrl/pinctrl-bcm2835.c 
b/drivers/pinctrl/pinctrl-bcm2835.c
index 5fd5740e8184..b8e9b60372e3 100644
--- a/drivers/pinctrl/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/pinctrl-bcm2835.c
@@ -171,7 +171,7 @@ static int bcm2835_gpio_probe(struct device_d *dev)
goto err;
}
 
-   dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, 
bcmgpio->chip.base);
+   dev_dbg(dev, "probed gpiochip%d with base %d\n", dev->id, 
bcmgpio->chip.base);
 
if (IS_ENABLED(CONFIG_PINCTRL)) {
ret = pinctrl_register(>pctl);
diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index ab121998a37f..c199d74846e8 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -401,7 +401,7 @@ static int stm32_pinctrl_probe(struct device_d *dev)
}
}
 
-   dev_info(dev, "pinctrl/gpio driver registered\n");
+   dev_dbg(dev, "pinctrl/gpio driver registered\n");
 
return 0;
 }
-- 
2.23.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox