Re: [PATCH 1/2] firmware: zynqmp: Mask expected and show unexpected warning

2023-04-25 Thread Stefan Herbrechtsmeier

Hi Michal,

Am 24.04.2023 um 15:43 schrieb Michal Simek:



On 4/21/23 13:39, Stefan Herbrechtsmeier wrote:

Am 21.04.2023 um 12:08 schrieb Michal Simek:

On 4/21/23 11:56, Stefan Herbrechtsmeier wrote:

Hi Michal,

Am 20.04.2023 um 14:39 schrieb Michal Simek:


On 4/20/23 14:30, Stefan Herbrechtsmeier wrote:

Am 20.04.2023 um 14:11 schrieb Michal Simek:

On 4/20/23 14:03, Stefan Herbrechtsmeier wrote:

Hi Michal,

Am 20.04.2023 um 13:06 schrieb Michal Simek:

Hi,

On 4/19/23 09:58, Stefan Herbrechtsmeier wrote:

Hi Michal,

Am 17.04.2023 um 12:16 schrieb Michal Simek:


On 4/3/23 15:34, Stefan Herbrechtsmeier wrote:

From: Stefan Herbrechtsmeier


Mask the expected and show the unexpected warning "No 
permission to

change config object" for NODE_OCM_BANK_0 because this node is
used to
detect if further zynqmp_pmufw_node function calls should be
skipped.

Signed-off-by: Stefan Herbrechtsmeier

---

  drivers/firmware/firmware-zynqmp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/firmware-zynqmp.c
b/drivers/firmware/firmware-zynqmp.c
index dc8e3ad2b9..8435b58ef9 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -251,7 +251,7 @@ int 
zynqmp_pmufw_load_config_object(const void

*cfg_obj, size_t size)
 err = xilinx_pm_request(PM_SET_CONFIGURATION,
(u32)(u64)cfg_obj, 0, 0,
 0, ret_payload);
 if (err == XST_PM_NO_ACCESS) {
-   if (((u32 *)cfg_obj)[NODE_ID_LOCATION] ==
NODE_OCM_BANK_0) {
+   if (((u32 *)cfg_obj)[NODE_ID_LOCATION] !=
NODE_OCM_BANK_0) {
 printf("PMUFW:  No permission to 
change

config object\n");
 return err;
 }


First of all we should very likely create a macro for 
NODE_OCM_BANK_0
to cover that dependency that it is used in 3 different 
locations

which have to match.


Okay, I will add a PMUFW_CFG_OBJ_SUPPORT_NODE macro.

The second is the change you have in 2/2 should be the part 
of this

patch because when only 1/2 is applied you change behavior.


The patches should be independent, and the behavior change is
intended.
The message should be printed if you don’t heave the 
permission for a
specific config object and not if the driver checks for 
support of
config objects. The NODE_OCM_BANK_0 call should never fail if 
load of

config objects is supported.


And changes in 2/2 makes sense.

I would be even fine to move skip_config out of 
zynqmp_pmufw_node()


The zynqmp_pmufw_node() function doesn't return an error and the
skip_config variable is static inside the function.

and setting up skip_config value directly in 
zynqmp_power_probe() not

to check in every call.


We still need to check the skip_config variable inside
zynqmp_pmufw_node
to skip the load of the config object if the pmufw doesn't 
support it.




 85 if (ret == XST_PM_NO_ACCESS && id == 
NODE_OCM_BANK_0)

 86 skip_config = true;


Without testing on HW I though to change it like this that 
skip_config

is configured and checked only once at probe time.

What do you think?


Patch looks okay except the printf. Is this really necessary? 
Could we

use a debug instead?


It is feature which you need to explicitly enable in PMUFW to work.


Is this information really necessary for a production build?


For production build no. But there are other messages which are 
likely not needed. Like a silicon version (production is only one 
version) for example.


Could we use log_info instead of printf?


That should be fine that you can filter it out if you like.




It means having information in boot log is quite worth.


Either we should print a message in any case or only if the 
feature is

disabled because in this case the zynqmp_pmufw_node() is a nop.


By default that feature should be disabled in standard pmufw build.
I don't have a preference but I want to see that message only 
once, disabled or enabled.


Is it possible to call the zynqmp_pmufw_node() in the probe() for 
the other platforms?


Not sure what you mean by other platforms.
If you mean different xilinx SoCs then no.
If you mean other then SOM. You can enable that feature and use it 
but it is only tested and enabled by default on SOMs.


I was confused by the `IS_ENABLED(CONFIG_ARCH_ZYNQMP)`. Why is this 
needed?


Because driver is used by other Xilinx/AMD SOCs but pmufw is only 
ZynqMP specific firmware. Newer one are using PLM.


The source file contains two drivers:
- zynqmp_firmware
- zynqmp_power

Isn't the zynqmp_power driver zynqmp specific and thereby the 
zynqmp_power_probe function which contains the 
`IS_ENABLED(CONFIG_ARCH_ZYNQMP)` check?






Actually maybe even we should create variable based on it to be 
able

to use it in scripts.
Because it is everybody decision if you want to let OS to send that
config fragments to PMUFW or just close that doors (right now 
you can

do it via command).

Also thinki

Re: [PATCH v3 03/19] ti: sysfw: tiboot3: Add support for packaging sysfw.itb and tiboot3.bin

2023-04-25 Thread Neha Malcom Francis

Hi Simon

On 25/04/23 01:12, Simon Glass wrote:

Hi Neha,

On Fri, 21 Apr 2023 at 06:32, Neha Malcom Francis  wrote:


Board config binary artifacts must be populated in the R5 output
directory to be used by binman to package sysfw.itb and tiboot3.bin.

For devices that follow combined flow, these board configuration
binaries must again be packaged into a combined board configuration
blobs to be used by binman to package tiboot3.bin.

Modify config.mk to generate all the board configuration binaries
needed.

Signed-off-by: Neha Malcom Francis 
---
  arch/arm/mach-k3/config.mk | 50 ++
  1 file changed, 50 insertions(+)


Reviewed-by: Simon Glass 

For follow-up: it would be nice if binman could just pick up these
files from where they are, e.g. by having the filenames in the .dts
description. It seems odd to have to copy them in a config.mk file.



Yes I believe that is possible, I'll do that.


Regards,
Simon


--
Thanking You
Neha Malcom Francis


Re: [PATCH v3 09/19] am65: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin, u-boot.img

2023-04-25 Thread Neha Malcom Francis

Hi Simon,

On 25/04/23 01:12, Simon Glass wrote:

Hi Neha,

On Fri, 21 Apr 2023 at 06:32, Neha Malcom Francis  wrote:


Support added for HS and GP boot binaries for AM65x.

tiboot3.bin, sysfw.itb, tispl.bin and u-boot.img: For HS devices
tiboot3.bin_unsigned, sysfw.itb, tispl.bin_unsigned,
u-boot.img_unsigned: For GP devices

Note that the bootflow followed by AM65x requires:

tiboot3.bin:
 * R5 SPL
 * R5 SPL dtbs
sysfw.itb:
 * sysfw
 * board-cfg
 * pm-cfg
 * sec-cfg
 * rm-cfg

tispl.bin:
 * ATF
 * OPTEE
 * A53 SPL
 * A53 SPL dtbs

u-boot.img:
 * A53 U-Boot
 * A53 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
---
  arch/arm/dts/k3-am654-base-board-u-boot.dtsi  |   1 +
  .../dts/k3-am654-r5-base-board-u-boot.dtsi|   1 +
  arch/arm/dts/k3-am65x-binman.dtsi | 551 ++
  board/ti/am65x/Kconfig|   2 +
  4 files changed, 555 insertions(+)
  create mode 100644 arch/arm/dts/k3-am65x-binman.dtsi


Reviewed-by: Simon Glass 

Is there any way that these boards could share a .dtsi with just the
different bits in each board's dtsi? There seems to be a lot of
duplicate.



Maybe a common k3-binman.dtsi, but the common nodes (where the filenames 
of both the generated file as well as component files are all common) 
would be the ti-board-config ones... and if we change that as per last 
review comment to point to board/ti//config.bin then we'd have 
that particular to each device as well right?


Or do you mean to say we use #defines for all?


Regards,
Simon


--
Thanking You
Neha Malcom Francis


Re: [PATCH v3 11/19] am64x: dts: binman: Package tiboot3.bin, tispl.bin u-boot.img

2023-04-25 Thread Neha Malcom Francis

Hi Simon

On 25/04/23 01:12, Simon Glass wrote:

Hi Neha,

On Fri, 21 Apr 2023 at 06:32, Neha Malcom Francis  wrote:


Support added for HS and GP boot binaries for AM64x.

tiboot3.bin, tispl.bin and u-boot.img: For HS-SE devices
tiboot3.bin_fs, tispl.bin and u-boot.img: For HS-FS devices
tiboot3.bin_unsigned, tispl.bin_unsigned, u-boot.img_unsigned: For GP
devices

Note that the bootflow followed by AM64x requires:

tiboot3.bin:
 * R5 SPL
 * R5 SPL dtbs
 * sysfw
 * board-cfg
 * pm-cfg
 * sec-cfg
 * rm-cfg

tispl.bin:
 * ATF
 * OPTEE
 * A53 SPL
 * A53 SPL dtbs

u-boot.img:
 * A53 U-Boot
 * A53 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
---
  arch/arm/dts/k3-am642-evm-u-boot.dtsi |   2 +
  arch/arm/dts/k3-am642-r5-evm.dts  |   1 +
  arch/arm/dts/k3-am64x-binman.dtsi | 569 ++
  board/ti/am64x/Kconfig|   2 +
  4 files changed, 574 insertions(+)
  create mode 100644 arch/arm/dts/k3-am64x-binman.dtsi


Reviewed-by: Simon Glass 

I notice that some of the entries are optional. Do you actual make use
of this (i.e. that when they are missing binman removes the entries)?



So right now the build generates binaries for all three types: HS-FS, 
HS-SE and GP devices. It's not necessary for the user to provide 
component binaries for all three of them, say they only have GP SYSFW 
binaries available with them. So that was the reasoning behind putting 
those binaries as optional, we should not have a failed build in those 
cases. However binaries like DM and board-config binaries that are 
common between all three needs to be there so it's not optional.



Regards,
Simon


--
Thanking You
Neha Malcom Francis


Re: [PATCH v3 19/19] doc: board: ti: Update documentation for binman flow

2023-04-25 Thread Neha Malcom Francis

Hi Heinrich

On 25/04/23 11:08, Heinrich Schuchardt wrote:

On 4/24/23 22:49, Tom Rini wrote:

On Mon, Apr 24, 2023 at 01:42:17PM -0600, Simon Glass wrote:

Hi Neha,

On Fri, 21 Apr 2023 at 06:33, Neha Malcom Francis  
wrote:


Earlier documentation specified builds for generating bootloader images
using an external TI repository k3-image-gen and core-secdev-k3. Modify
this to using the binman flow so that user understands how to build the
final boot images.

Signed-off-by: Neha Malcom Francis 
---
  doc/board/ti/am62x_sk.rst  | 20 
  doc/board/ti/j721e_evm.rst | 37 -
  doc/board/ti/k3.rst    | 67 
++

  3 files changed, 36 insertions(+), 88 deletions(-)


Reviewed-by: Simon Glass 



diff --git a/doc/board/ti/am62x_sk.rst b/doc/board/ti/am62x_sk.rst
index b1b7d99bef..f5e0774899 100644
--- a/doc/board/ti/am62x_sk.rst
+++ b/doc/board/ti/am62x_sk.rst
@@ -115,23 +115,19 @@ Below is the pictorial representation of boot 
flow:


  Sources:
  
-1. SYSFW:
-   Tree: git://git.ti.com/k3-image-gen/k3-image-gen.git
-   Branch: master
-
-2. ATF:
+1. ATF:
 Tree: https://github.com/ARM-software/arm-trusted-firmware.git
 Branch: master

-3. OPTEE:
+2. OPTEE:
 Tree: https://github.com/OP-TEE/optee_os.git
 Branch: master

-4. U-Boot:
+3. U-Boot:
 Tree: https://source.denx.de/u-boot/u-boot
 Branch: master

-5. TI Linux Firmware:
+4. TI Linux Firmware:
 Tree: 
git://git.ti.com/processor-firmware/ti-linux-firmware.git

 Branch: ti-linux-firmware

@@ -156,18 +152,14 @@ Build procedure:
  .. code-block:: text

   $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- 
am62x_evm_r5_defconfig O=/tmp/r5

- $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- O=/tmp/r5
- $ cd 
- $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- SOC=am62x 
SBL=/tmp/r5/spl/u-boot-spl.bin SYSFW_PATH=ti-linux-firmware>/ti-sysfw/ti-fs-firmware-am62x-gp.bin

-
-Use the tiboot3.bin generated from last command
+ $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- O=/tmp/r5 
BINMAN_INDIRS=


  * 3.2 A53:

  .. code-block:: text

   $ make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu- 
am62x_evm_a53_defconfig O=/tmp/a53
- $ make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu- ATF=ATF dir>/build/k3/lite/release/bl31.bin TEE=dir>/out/arm-plat-k3/core/tee-pager_v2.bin DM=ti-linux-firmware>/ti-dm/am62xx/ipc_echo_testb_mcu1_0_release_strip.xer5f O=/tmp/a53
+ $ make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu- BL31=to ATF dir>/build/k3/lite/release/bl31.bin TEE=dir>/out/arm-plat-k3/core/tee-pager_v2.bin 
BINMAN_INDIRS=


  Target Images
  --
diff --git a/doc/board/ti/j721e_evm.rst b/doc/board/ti/j721e_evm.rst
index e898601c41..c90e2b8279 100644
--- a/doc/board/ti/j721e_evm.rst
+++ b/doc/board/ti/j721e_evm.rst
@@ -130,67 +130,56 @@ support. Below is the pictorial representation 
of boot flow:


  Sources:
  
-1. SYSFW:
-   Tree: git://git.ti.com/k3-image-gen/k3-image-gen.git
-   Branch: master
-
-2. ATF:
+1. ATF:
 Tree: https://github.com/ARM-software/arm-trusted-firmware.git
 Branch: master

-3. OPTEE:
+2. OPTEE:
 Tree: https://github.com/OP-TEE/optee_os.git
 Branch: master

-4. DM Firmware:
-   Tree: git://git.ti.com/processor-firmware/ti-linux-firmware.git
-   Branch: ti-linux-firmware
-
-5. U-Boot:
+3. U-Boot:
 Tree: https://source.denx.de/u-boot/u-boot
 Branch: master

+4. TI Linux Firmware:
+   Tree: git://git.ti.com/processor-firmware/ti-linux-firmware.git
+   Branch: ti-linux-firmware
+
  Build procedure:
  
-1. SYSFW:
-
-.. code-block:: bash
-
-    make CROSS_COMPILE=arm-linux-gnueabihf- SOC=j721e
-
-2. ATF:
+1. ATF:

  .. code-block:: bash

  make CROSS_COMPILE=aarch64-linux-gnu- ARCH=aarch64 PLAT=k3 
TARGET_BOARD=generic SPD=opteed


-3. OPTEE:
+2. OPTEE:

  .. code-block:: bash

  make PLATFORM=k3-j721e CFG_ARM64_core=y

-4. U-Boot:
+3. U-Boot:

  * 4.1 R5:

  .. code-block:: bash

  make CROSS_COMPILE=arm-linux-gnueabihf- j721e_evm_r5_defconfig 
O=build/r5


CROSS_COMPILE is superfluous here.


-    make CROSS_COMPILE=arm-linux-gnueabihf- O=build/r5
+    make CROSS_COMPILE=arm-linux-gnueabihf- O=build/r5 
BINMAN_INDIRS=


Don't we have to indicate the locations of the TF-A binary and SYSFW_PATH?



R5 builds do not require ATF. As for SYSFW_PATH, ti-linux-firmware 
contains those within ti-sysfw/ which is picked up by binman.


  * 4.2 A72:

  .. code-block:: bash

  make CROSS_COMPILE=aarch64-linux-gnu- j721e_evm_a72_defconfig 
O=build/a72


CROSS_COMPILE is superfluous here.

-    make CROSS_COMPILE=aarch64-linux-gnu- ATF=dir>/build/k3/generic/release/bl31.bin TEE=dir>/out/arm-plat-k3/core/tee-pager_v2.bin DM=firmware>/ti-dm/j721e/ipc_echo_testb_mcu1_0_release_strip.xer5f 
O=build/a72
+    make CROSS_COMPILE=aarch64-linux-gnu- BL31=dir>/build/k3/generic/release/b

[PATCH v3 0/6] Add video drivers for endeavoru and p880/p895

2023-04-25 Thread Svyatoslav Ryhel
This patchset contains mostly generic drivers used by endeavoru
and p895/p880 (which are currently in the process of merging).
Drivers do not contain any device specific parts and mostly can
be used by any device with supported hardware.

LG P880\P895 related drivers:
- lm3533 backlight driver implements only backlight part for
bank A. Unfortunately, I can not test and set up bank B since
my device does not use it.
- Solomon ssd2825 bridge is fully implemented for 3wire-9bit
mode. It uses SPI interface and is wrapped into panel DM for
wider compatibility.
- 2 DSI panels which use Renesas R61307 and R69328 controllers
are fully implemented as well.

HTC One X (endeavoru) related drivers:
- backlight driver which uses a PWM source provided by the display
controller.
- endeavoru uses panels made by 3 different vendors but the command
sequence seems to be generally the same. Endeavoru panel driver
is set to support all 3 variants of this panel.

---
Changes from v2:
- added comments to panel drivers
- fixed typo in ssd2825 driver

Changes from v1:
- used lower-case hex for command sequences
- ssd2825 switched to dm_spi_xfer
- used log_* instead of printf
- tweaked lm3533 help description

---

Svyatoslav Ryhel (6):
  video: add lm3533 backlight driver
  video: bridge: add Solomon SSD2825 DSI/LVDS driver
  video: panel: add Renesas R61307 MIPI DSI panel driver
  video: panel: add Renesas R69328 MIPI DSI panel driver
  video: tegra: add DC based PWM backlight driver
  video: panel: add generic endeavoru panel

 drivers/video/Kconfig   |  38 ++
 drivers/video/Makefile  |   4 +
 drivers/video/bridge/Kconfig|   7 +
 drivers/video/bridge/Makefile   |   1 +
 drivers/video/bridge/ssd2825.c  | 520 
 drivers/video/endeavoru-panel.c | 252 ++
 drivers/video/lm3533_backlight.c| 134 +
 drivers/video/renesas-r61307.c  | 302 
 drivers/video/renesas-r69328.c  | 238 +
 drivers/video/tegra20/Kconfig   |   7 +
 drivers/video/tegra20/Makefile  |   1 +
 drivers/video/tegra20/tegra-pwm-backlight.c | 155 ++
 12 files changed, 1659 insertions(+)
 create mode 100644 drivers/video/bridge/ssd2825.c
 create mode 100644 drivers/video/endeavoru-panel.c
 create mode 100644 drivers/video/lm3533_backlight.c
 create mode 100644 drivers/video/renesas-r61307.c
 create mode 100644 drivers/video/renesas-r69328.c
 create mode 100644 drivers/video/tegra20/tegra-pwm-backlight.c

-- 
2.39.2



[PATCH v3 1/6] video: add lm3533 backlight driver

2023-04-25 Thread Svyatoslav Ryhel
This is basic lm3533 driver only with bank A and backlight cell
support.

Tested-by: Andreas Westman Dorcsak  # LG P880 T30
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 drivers/video/Kconfig|   9 +++
 drivers/video/Makefile   |   1 +
 drivers/video/lm3533_backlight.c | 134 +++
 3 files changed, 144 insertions(+)
 create mode 100644 drivers/video/lm3533_backlight.c

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 334d64c948..60048ad86a 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -606,6 +606,15 @@ config ATMEL_HLCD
help
   HLCDC supports video output to an attached LCD panel.
 
+config BACKLIGHT_LM3533
+   bool "Backlight Driver for LM3533"
+   depends on BACKLIGHT
+   select DM_I2C
+   help
+ Say Y to enable the backlight driver for National Semiconductor / TI
+ LM3533 Lighting Power chip. Only Bank A is supported as for now.
+ Supported backlight level range is from 2 to 255 with step of 1.
+
 source "drivers/video/ti/Kconfig"
 
 source "drivers/video/exynos/Kconfig"
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 4d75771745..05fb063105 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_VIDEO_LOGO) += u_boot_logo.o
 
 endif
 
+obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_backlight.o
 obj-${CONFIG_EXYNOS_FB} += exynos/
 obj-${CONFIG_VIDEO_ROCKCHIP} += rockchip/
 obj-${CONFIG_VIDEO_STM32} += stm32/
diff --git a/drivers/video/lm3533_backlight.c b/drivers/video/lm3533_backlight.c
new file mode 100644
index 00..00297a09b7
--- /dev/null
+++ b/drivers/video/lm3533_backlight.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#define LOG_CATEGORY UCLASS_PANEL_BACKLIGHT
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define LM3533_BL_MIN_BRIGHTNESS   0x02
+#define LM3533_BL_MAX_BRIGHTNESS   0xFF
+
+#define LM3533_SINK_OUTPUT_CONFIG_10x10
+#define LM3533_CONTROL_BANK_A_PWM  0x14
+#define LM3533_CONTROL_BANK_AB_BRIGHTNESS  0x1A
+#define LM3533_CONTROL_BANK_A_FULLSCALE_CURRENT0x1F
+#define LM3533_CONTROL_BANK_ENABLE 0x27
+#define LM3533_OVP_FREQUENCY_PWM_POLARITY  0x2C
+#define LM3533_BRIGHTNESS_REGISTER_A   0x40
+
+struct lm3533_backlight_priv {
+   struct gpio_desc enable_gpio;
+   u32 def_bl_lvl;
+};
+
+static int lm3533_backlight_enable(struct udevice *dev)
+{
+   struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   dm_gpio_set_value(&priv->enable_gpio, 1);
+   mdelay(5);
+
+   /* HVLED 1 & 2 are controlled by Bank A */
+   ret = dm_i2c_reg_write(dev, LM3533_SINK_OUTPUT_CONFIG_1, 0x00);
+   if (ret)
+   return ret;
+
+   /* PWM input is disabled for CABC */
+   ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_A_PWM, 0x00);
+   if (ret)
+   return ret;
+
+   /* Linear & Control Bank A is configured for register Current control */
+   ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_AB_BRIGHTNESS, 0x02);
+   if (ret)
+   return ret;
+
+   /* Full-Scale Current (20.2mA) */
+   ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_A_FULLSCALE_CURRENT, 
0x13);
+   if (ret)
+   return ret;
+
+   /* Control Bank A is enable */
+   ret = dm_i2c_reg_write(dev, LM3533_CONTROL_BANK_ENABLE, 0x01);
+   if (ret)
+   return ret;
+
+   ret = dm_i2c_reg_write(dev, LM3533_OVP_FREQUENCY_PWM_POLARITY, 0x0A);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static int lm3533_backlight_set_brightness(struct udevice *dev, int percent)
+{
+   struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   if (percent == BACKLIGHT_DEFAULT)
+   percent = priv->def_bl_lvl;
+
+   if (percent < LM3533_BL_MIN_BRIGHTNESS)
+   percent = LM3533_BL_MIN_BRIGHTNESS;
+
+   if (percent > LM3533_BL_MAX_BRIGHTNESS)
+   percent = LM3533_BL_MAX_BRIGHTNESS;
+
+   /* Set brightness level */
+   ret = dm_i2c_reg_write(dev, LM3533_BRIGHTNESS_REGISTER_A,
+  percent);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static int lm3533_backlight_probe(struct udevice *dev)
+{
+   struct lm3533_backlight_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   if (device_get_uclass_id(dev->parent) != UCLASS_I2C)
+   return -EPROTONOSUPPORT;
+
+   ret = gpio_request_by_name(dev, "enable-gpios", 0,
+  &priv->enable_gpio, GPIOD_IS_OUT);
+   if (ret) {
+   log_err("Could no

[PATCH v3 2/6] video: bridge: add Solomon SSD2825 DSI/LVDS driver

2023-04-25 Thread Svyatoslav Ryhel
SSD2825 is an innovative and cost-effective MIPI Bridge Chip solution
targeting high resolution smartphones. It can convert 24bit RGB
interface into 4-lane MIPI-DSI interface to drive extremely high
resolution display modules of up to 800 x 1366, while supporting AMOLED,
a-si LCD or LTPS advanced panel technologies for smartphone applications.

Bridge is wrapped in panel uClass model for wider compatibility.

Tested-by: Andreas Westman Dorcsak  # LG P880 T30
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
---
 drivers/video/bridge/Kconfig   |   7 +
 drivers/video/bridge/Makefile  |   1 +
 drivers/video/bridge/ssd2825.c | 520 +
 3 files changed, 528 insertions(+)
 create mode 100644 drivers/video/bridge/ssd2825.c

diff --git a/drivers/video/bridge/Kconfig b/drivers/video/bridge/Kconfig
index 765f7380b8..2311ca2d1a 100644
--- a/drivers/video/bridge/Kconfig
+++ b/drivers/video/bridge/Kconfig
@@ -33,3 +33,10 @@ config VIDEO_BRIDGE_ANALOGIX_ANX6345
help
 The Analogix ANX6345 is RGB-to-DP converter. It enables an eDP LCD
 panel to be connected to an parallel LCD interface.
+
+config VIDEO_BRIDGE_SOLOMON_SSD2825
+   bool "Solomon SSD2825 bridge driver"
+   depends on PANEL && DM_GPIO
+   select VIDEO_MIPI_DSI
+   help
+ Solomon SSD2824 SPI RGB-DSI bridge driver wrapped into panel uClass.
diff --git a/drivers/video/bridge/Makefile b/drivers/video/bridge/Makefile
index 45e54ac176..22625c8bc6 100644
--- a/drivers/video/bridge/Makefile
+++ b/drivers/video/bridge/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_VIDEO_BRIDGE) += video-bridge-uclass.o
 obj-$(CONFIG_VIDEO_BRIDGE_PARADE_PS862X) += ps862x.o
 obj-$(CONFIG_VIDEO_BRIDGE_NXP_PTN3460) += ptn3460.o
 obj-$(CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345) += anx6345.o
+obj-$(CONFIG_VIDEO_BRIDGE_SOLOMON_SSD2825) += ssd2825.o
diff --git a/drivers/video/bridge/ssd2825.c b/drivers/video/bridge/ssd2825.c
new file mode 100644
index 00..cea20dcffa
--- /dev/null
+++ b/drivers/video/bridge/ssd2825.c
@@ -0,0 +1,520 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SSD2825_DEVICE_ID_REG  0xB0
+#define SSD2825_RGB_INTERFACE_CTRL_REG_1   0xB1
+#define SSD2825_RGB_INTERFACE_CTRL_REG_2   0xB2
+#define SSD2825_RGB_INTERFACE_CTRL_REG_3   0xB3
+#define SSD2825_RGB_INTERFACE_CTRL_REG_4   0xB4
+#define SSD2825_RGB_INTERFACE_CTRL_REG_5   0xB5
+#define SSD2825_RGB_INTERFACE_CTRL_REG_6   0xB6
+#define   SSD2825_NON_BURSTBIT(2)
+#define   SSD2825_BURSTBIT(3)
+#define   SSD2825_PCKL_HIGHBIT(13)
+#define   SSD2825_HSYNC_HIGH   BIT(14)
+#define   SSD2825_VSYNC_HIGH   BIT(15)
+#define SSD2825_CONFIGURATION_REG  0xB7
+#define   SSD2825_CONF_REG_HS  BIT(0)
+#define   SSD2825_CONF_REG_CKE BIT(1)
+#define   SSD2825_CONF_REG_SLP BIT(2)
+#define   SSD2825_CONF_REG_VEN BIT(3)
+#define   SSD2825_CONF_REG_HCLKBIT(4)
+#define   SSD2825_CONF_REG_CSS BIT(5)
+#define   SSD2825_CONF_REG_DCS BIT(6)
+#define   SSD2825_CONF_REG_REN BIT(7)
+#define   SSD2825_CONF_REG_ECD BIT(8)
+#define   SSD2825_CONF_REG_EOT BIT(9)
+#define   SSD2825_CONF_REG_LPE BIT(10)
+#define SSD2825_VC_CTRL_REG0xB8
+#define SSD2825_PLL_CTRL_REG   0xB9
+#define SSD2825_PLL_CONFIGURATION_REG  0xBA
+#define SSD2825_CLOCK_CTRL_REG 0xBB
+#define SSD2825_PACKET_SIZE_CTRL_REG_1 0xBC
+#define SSD2825_PACKET_SIZE_CTRL_REG_2 0xBD
+#define SSD2825_PACKET_SIZE_CTRL_REG_3 0xBE
+#define SSD2825_PACKET_DROP_REG0xBF
+#define SSD2825_OPERATION_CTRL_REG 0xC0
+#define SSD2825_MAX_RETURN_SIZE_REG0xC1
+#define SSD2825_RETURN_DATA_COUNT_REG  0xC2
+#define SSD2825_ACK_RESPONSE_REG   0xC3
+#define SSD2825_LINE_CTRL_REG  0xC4
+#define SSD2825_INTERRUPT_CTRL_REG 0xC5
+#define SSD2825_INTERRUPT_STATUS_REG   0xC6
+#define SSD2825_ERROR_STATUS_REG   0xC7
+#define SSD2825_DATA_FORMAT_REG0xC8
+#define SSD2825_DELAY_ADJ_REG_10xC9
+#define SSD2825_DELAY_ADJ_REG_20xCA
+#define SSD2825_DELAY_ADJ_REG_30xCB
+#define SSD2825_DELAY_ADJ_REG_40xCC
+#define SSD2825_DELAY_ADJ_REG_50xCD
+#define SSD2825_DELAY_ADJ_REG_60xCE
+#define SSD2825_HS_TX_TIMER_REG_1  0xCF
+#define SSD2825_HS_TX_TI

[PATCH v3 3/6] video: panel: add Renesas R61307 MIPI DSI panel driver

2023-04-25 Thread Svyatoslav Ryhel
R61307 is liquid crystal driver for high-definition
amorphous silicon (a-Si) panels and is ideal for
tablets and smartphones.

Supported compatibles are:
- koe,tx13d100vm0eaa
- hitachi,tx13d100vm0eaa

Tested-by: Andreas Westman Dorcsak  # LG P880 T30
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 drivers/video/Kconfig  |   9 +
 drivers/video/Makefile |   1 +
 drivers/video/renesas-r61307.c | 302 +
 3 files changed, 312 insertions(+)
 create mode 100644 drivers/video/renesas-r61307.c

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 60048ad86a..44f21be166 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -480,6 +480,15 @@ config VIDEO_LCD_RAYDIUM_RM68200
Say Y here if you want to enable support for Raydium RM68200
720x1280 DSI video mode panel.
 
+config VIDEO_LCD_RENESAS_R61307
+   tristate "Renesas R61307 DSI video mode panel"
+   depends on PANEL && BACKLIGHT
+   select VIDEO_MIPI_DSI
+   help
+ Say Y here if you want to enable support for KOE tx13d100vm0eaa
+ IPS-LCD module with Renesas R69328 IC. The panel has a 1024x768
+ resolution and uses 24 bit RGB per pixel.
+
 config VIDEO_LCD_SSD2828
bool "SSD2828 bridge chip"
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 05fb063105..9ab5de8858 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_VIDEO_LCD_ANX9804) += anx9804.o
 obj-$(CONFIG_VIDEO_LCD_HITACHI_TX18D42VM) += hitachi_tx18d42vm_lcd.o
 obj-$(CONFIG_VIDEO_LCD_ORISETECH_OTM8009A) += orisetech_otm8009a.o
 obj-$(CONFIG_VIDEO_LCD_RAYDIUM_RM68200) += raydium-rm68200.o
+obj-$(CONFIG_VIDEO_LCD_RENESAS_R61307) += renesas-r61307.o
 obj-$(CONFIG_VIDEO_LCD_SSD2828) += ssd2828.o
 obj-$(CONFIG_VIDEO_LCD_TDO_TL070WSH30) += tdo-tl070wsh30.o
 obj-$(CONFIG_VIDEO_MCDE_SIMPLE) += mcde_simple.o
diff --git a/drivers/video/renesas-r61307.c b/drivers/video/renesas-r61307.c
new file mode 100644
index 00..426fdc6224
--- /dev/null
+++ b/drivers/video/renesas-r61307.c
@@ -0,0 +1,302 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Renesas R61307 panel driver
+ *
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The datasheet is not publicly??available, all values are
+ * taken from the downstream. If you have access to datasheets,
+ * corrections are welcome.
+ */
+
+#define R61307_MACP0xB0 /* Manufacturer CMD Protect */
+
+#define R61307_INVERSION   0xC1
+#define R61307_GAMMA_SET_A 0xC8 /* Gamma Setting A */
+#define R61307_GAMMA_SET_B 0xC9 /* Gamma Setting B */
+#define R61307_GAMMA_SET_C 0xCA /* Gamma Setting C */
+#define R61307_CONTRAST_SET0xCC
+
+struct renesas_r61307_priv {
+   struct udevice *vcc;
+   struct udevice *iovcc;
+
+   struct udevice *backlight;
+
+   struct gpio_desc reset_gpio;
+
+   bool dig_cont_adj;
+   bool inversion;
+   u32 gamma;
+};
+
+static const u8 macp_on[] = {
+   R61307_MACP, 0x03
+};
+
+static const u8 macp_off[] = {
+   R61307_MACP, 0x04
+};
+
+static const u8 address_mode[] = {
+   MIPI_DCS_SET_ADDRESS_MODE
+};
+
+static const u8 contrast_setting[] = {
+   R61307_CONTRAST_SET,
+   0xdc, 0xb4, 0xff
+};
+
+static const u8 column_inversion[] = {
+   R61307_INVERSION,
+   0x00, 0x50, 0x03, 0x22,
+   0x16, 0x06, 0x60, 0x11
+};
+
+static const u8 line_inversion[] = {
+   R61307_INVERSION,
+   0x00, 0x10, 0x03, 0x22,
+   0x16, 0x06, 0x60, 0x01
+};
+
+static const u8 gamma_setting[][25] = {
+   {},
+   {
+   R61307_GAMMA_SET_A,
+   0x00, 0x06, 0x0a, 0x0f,
+   0x14, 0x1f, 0x1f, 0x17,
+   0x12, 0x0c, 0x09, 0x06,
+   0x00, 0x06, 0x0a, 0x0f,
+   0x14, 0x1f, 0x1f, 0x17,
+   0x12, 0x0c, 0x09, 0x06
+   },
+   {
+   R61307_GAMMA_SET_A,
+   0x00, 0x05, 0x0b, 0x0f,
+   0x11, 0x1d, 0x20, 0x18,
+   0x18, 0x09, 0x07, 0x06,
+   0x00, 0x05, 0x0b, 0x0f,
+   0x11, 0x1d, 0x20, 0x18,
+   0x18, 0x09, 0x07, 0x06
+   },
+   {
+   R61307_GAMMA_SET_A,
+   0x0b, 0x0d, 0x10, 0x14,
+   0x13, 0x1d, 0x20, 0x18,
+   0x12, 0x09, 0x07, 0x06,
+   0x0a, 0x0c, 0x10, 0x14,
+   0x13, 0x1d, 0x20, 0x18,
+   0x12, 0x09, 0x07, 0x06
+   },
+};
+
+static struct display_timing default_timing = {
+   .pixelclock.typ = 6200,
+   .hactive.typ= 768,
+   .hfront_porch.typ   = 116,
+   .hback_porch.typ= 81,
+   .hsync_len.typ  = 5,
+   .vactive.typ= 1024,
+   .

[PATCH v3 5/6] video: tegra: add DC based PWM backlight driver

2023-04-25 Thread Svyatoslav Ryhel
DC based PWM backlight is found on some T20 and T30 devices
(HTC One X). This backlight is controlled by Tegra DC and
is adjustable by the DC PM0 or PM1 signal.

Tested-by: Andreas Westman Dorcsak  # HTC One X T30
Tested-by: Svyatoslav Ryhel  # HTC One X T30
Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 drivers/video/tegra20/Kconfig   |   7 +
 drivers/video/tegra20/Makefile  |   1 +
 drivers/video/tegra20/tegra-pwm-backlight.c | 155 
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/video/tegra20/tegra-pwm-backlight.c

diff --git a/drivers/video/tegra20/Kconfig b/drivers/video/tegra20/Kconfig
index 5b1dfbfbbe..f5c4843e11 100644
--- a/drivers/video/tegra20/Kconfig
+++ b/drivers/video/tegra20/Kconfig
@@ -15,3 +15,10 @@ config VIDEO_DSI_TEGRA30
help
   T30 has native support for DSI panels. This option enables support
   for such panels which can be used on endeavoru and tf600t.
+
+config TEGRA_BACKLIGHT_PWM
+   bool "Enable Tegra DC PWM backlight support"
+   depends on BACKLIGHT
+   select VIDEO_TEGRA20
+   help
+  Tegra DC dependent backlight.
diff --git a/drivers/video/tegra20/Makefile b/drivers/video/tegra20/Makefile
index e82ee96962..f0b534c579 100644
--- a/drivers/video/tegra20/Makefile
+++ b/drivers/video/tegra20/Makefile
@@ -2,3 +2,4 @@
 
 obj-$(CONFIG_VIDEO_TEGRA20) += tegra-dc.o
 obj-$(CONFIG_VIDEO_DSI_TEGRA30) += tegra-dsi.o mipi-phy.o
+obj-$(CONFIG_TEGRA_BACKLIGHT_PWM) += tegra-pwm-backlight.o
diff --git a/drivers/video/tegra20/tegra-pwm-backlight.c 
b/drivers/video/tegra20/tegra-pwm-backlight.c
new file mode 100644
index 00..f3d7025fbb
--- /dev/null
+++ b/drivers/video/tegra20/tegra-pwm-backlight.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#define LOG_CATEGORY UCLASS_PANEL_BACKLIGHT
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define TEGRA_DISPLAY_A_BASE   0x5420
+#define TEGRA_DISPLAY_B_BASE   0x5424
+
+#define TEGRA_PWM_BL_MIN_BRIGHTNESS0x10
+#define TEGRA_PWM_BL_MAX_BRIGHTNESS0xFF
+
+#define TEGRA_PWM_BL_PERIOD0xFF
+#define TEGRA_PWM_BL_CLK_DIV   0x14
+#define TEGRA_PWM_BL_CLK_SELECT0x00
+
+#define PM_PERIOD_SHIFT 18
+#define PM_CLK_DIVIDER_SHIFT   4
+
+#define TEGRA_PWM_PM0  0
+#define TEGRA_PWM_PM1  1
+
+struct tegra_pwm_backlight_priv {
+   struct dc_ctlr *dc; /* Display controller regmap */
+
+   u32 pwm_source;
+   u32 period;
+   u32 clk_div;
+   u32 clk_select;
+   u32 dft_brightness;
+};
+
+static int tegra_pwm_backlight_set_brightness(struct udevice *dev, int percent)
+{
+   struct tegra_pwm_backlight_priv *priv = dev_get_priv(dev);
+   struct dc_cmd_reg *cmd = &priv->dc->cmd;
+   struct dc_com_reg *com = &priv->dc->com;
+   unsigned int ctrl;
+   unsigned long out_sel;
+   unsigned long cmd_state;
+
+   if (percent == BACKLIGHT_DEFAULT)
+   percent = priv->dft_brightness;
+
+   if (percent < TEGRA_PWM_BL_MIN_BRIGHTNESS)
+   percent = TEGRA_PWM_BL_MIN_BRIGHTNESS;
+
+   if (percent > TEGRA_PWM_BL_MAX_BRIGHTNESS)
+   percent = TEGRA_PWM_BL_MAX_BRIGHTNESS;
+
+   ctrl = ((priv->period << PM_PERIOD_SHIFT) |
+   (priv->clk_div << PM_CLK_DIVIDER_SHIFT) |
+priv->clk_select);
+
+   /* The new value should be effected immediately */
+   cmd_state = readl(&cmd->state_access);
+   writel((cmd_state | (1 << 2)), &cmd->state_access);
+
+   switch (priv->pwm_source) {
+   case TEGRA_PWM_PM0:
+   /* Select the LM0 on PM0 */
+   out_sel = readl(&com->pin_output_sel[5]);
+   out_sel &= ~(7 << 0);
+   out_sel |= (3 << 0);
+   writel(out_sel, &com->pin_output_sel[5]);
+   writel(ctrl, &com->pm0_ctrl);
+   writel(percent, &com->pm0_duty_cycle);
+   break;
+   case TEGRA_PWM_PM1:
+   /* Select the LM1 on PM1 */
+   out_sel = readl(&com->pin_output_sel[5]);
+   out_sel &= ~(7 << 4);
+   out_sel |= (3 << 4);
+   writel(out_sel, &com->pin_output_sel[5]);
+   writel(ctrl, &com->pm1_ctrl);
+   writel(percent, &com->pm1_duty_cycle);
+   break;
+   default:
+   break;
+   }
+
+   writel(cmd_state, &cmd->state_access);
+   return 0;
+}
+
+static int tegra_pwm_backlight_enable(struct udevice *dev)
+{
+   struct tegra_pwm_backlight_priv *priv = dev_get_priv(dev);
+   return tegra_pwm_backlight_set_brightness(dev, priv->dft_brightness);
+}
+
+static int tegra_pwm_backlight_probe(struct udevice *dev)
+{
+   struct tegra_pwm_backlight_priv *

[PATCH v3 4/6] video: panel: add Renesas R69328 MIPI DSI panel driver

2023-04-25 Thread Svyatoslav Ryhel
Driver adds support for panels with Renesas R69328 IC

Currently supported compatible is:
- jdi,dx12d100vm0eaa

Tested-by: Andreas Westman Dorcsak  # LG P880 T30
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 drivers/video/Kconfig  |   9 ++
 drivers/video/Makefile |   1 +
 drivers/video/renesas-r69328.c | 238 +
 3 files changed, 248 insertions(+)
 create mode 100644 drivers/video/renesas-r69328.c

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 44f21be166..f5e3c713e5 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -489,6 +489,15 @@ config VIDEO_LCD_RENESAS_R61307
  IPS-LCD module with Renesas R69328 IC. The panel has a 1024x768
  resolution and uses 24 bit RGB per pixel.
 
+config VIDEO_LCD_RENESAS_R69328
+   tristate "Renesas R69328 720x1280 DSI video mode panel"
+   depends on PANEL && BACKLIGHT
+   select VIDEO_MIPI_DSI
+   help
+ Say Y here if you want to enable support for JDI dx12d100vm0eaa
+ IPS-LCD module with Renesas R69328 IC. The panel has a 720x1280
+ resolution and uses 24 bit RGB per pixel.
+
 config VIDEO_LCD_SSD2828
bool "SSD2828 bridge chip"
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 9ab5de8858..cddfc8fd33 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -57,6 +57,7 @@ obj-$(CONFIG_VIDEO_LCD_HITACHI_TX18D42VM) += 
hitachi_tx18d42vm_lcd.o
 obj-$(CONFIG_VIDEO_LCD_ORISETECH_OTM8009A) += orisetech_otm8009a.o
 obj-$(CONFIG_VIDEO_LCD_RAYDIUM_RM68200) += raydium-rm68200.o
 obj-$(CONFIG_VIDEO_LCD_RENESAS_R61307) += renesas-r61307.o
+obj-$(CONFIG_VIDEO_LCD_RENESAS_R69328) += renesas-r69328.o
 obj-$(CONFIG_VIDEO_LCD_SSD2828) += ssd2828.o
 obj-$(CONFIG_VIDEO_LCD_TDO_TL070WSH30) += tdo-tl070wsh30.o
 obj-$(CONFIG_VIDEO_MCDE_SIMPLE) += mcde_simple.o
diff --git a/drivers/video/renesas-r69328.c b/drivers/video/renesas-r69328.c
new file mode 100644
index 00..d2f7169468
--- /dev/null
+++ b/drivers/video/renesas-r69328.c
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Renesas R69328 panel driver
+ *
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The datasheet is not publicly??available, all values are
+ * taken from the downstream. If you have access to datasheets,
+ * corrections are welcome.
+ */
+
+#define R69328_MACP0xB0 /* Manufacturer Command Access Protect */
+
+#define R69328_GAMMA_SET_A 0xC8 /* Gamma Setting A */
+#define R69328_GAMMA_SET_B 0xC9 /* Gamma Setting B */
+#define R69328_GAMMA_SET_C 0xCA /* Gamma Setting C */
+
+#define R69328_POWER_SET   0xD1
+
+struct renesas_r69328_priv {
+   struct udevice *backlight;
+
+   struct gpio_desc enable_gpio;
+   struct gpio_desc reset_gpio;
+};
+
+static const u8 address_mode[] = {
+   MIPI_DCS_SET_ADDRESS_MODE
+};
+
+#define dsi_generic_write_seq(dsi, cmd, seq...) do {   \
+   static const u8 b[] = { cmd, seq }; \
+   int ret;\
+   ret = mipi_dsi_dcs_write_buffer(dsi, b, ARRAY_SIZE(b)); \
+   if (ret < 0)\
+   return ret; \
+   } while (0)
+
+static struct display_timing default_timing = {
+   .pixelclock.typ = 6800,
+   .hactive.typ= 720,
+   .hfront_porch.typ   = 92,
+   .hback_porch.typ= 62,
+   .hsync_len.typ  = 4,
+   .vactive.typ= 1280,
+   .vfront_porch.typ   = 6,
+   .vback_porch.typ= 3,
+   .vsync_len.typ  = 1,
+};
+
+static int renesas_r69328_enable_backlight(struct udevice *dev)
+{
+   struct renesas_r69328_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = dm_gpio_set_value(&priv->enable_gpio, 1);
+   if (ret) {
+   log_err("error changing enable-gpios (%d)\n", ret);
+   return ret;
+   }
+   mdelay(5);
+
+   ret = dm_gpio_set_value(&priv->reset_gpio, 0);
+   if (ret) {
+   log_err("error changing reset-gpios (%d)\n", ret);
+   return ret;
+   }
+   mdelay(5);
+
+   ret = dm_gpio_set_value(&priv->reset_gpio, 1);
+   if (ret) {
+   log_err("error changing reset-gpios (%d)\n", ret);
+   return ret;
+   }
+
+   mdelay(5);
+
+   return 0;
+}
+
+static int renesas_r69328_set_backlight(struct udevice *dev, int percent)
+{
+   struct renesas_r69328_priv *priv = dev_get_priv(dev);
+   struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
+   struct mipi_dsi_device *dsi = plat->device;
+ 

[PATCH v3 6/6] video: panel: add generic endeavoru panel

2023-04-25 Thread Svyatoslav Ryhel
Family of panels used by HTC in One X. Though were used variants
at least from 3 vendors, this driver provides generic support for
all of them.

Tested-by: Ion Agorria  # HTC One X T30 Sony
Tested-by: Svyatoslav Ryhel  # HTC One X T30 Sharp
Signed-off-by: Svyatoslav Ryhel 
---
 drivers/video/Kconfig   |  11 ++
 drivers/video/Makefile  |   1 +
 drivers/video/endeavoru-panel.c | 252 
 3 files changed, 264 insertions(+)
 create mode 100644 drivers/video/endeavoru-panel.c

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f5e3c713e5..86603342a3 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -466,6 +466,17 @@ config VIDEO_BCM2835
  that same resolution (or as near as possible) and 32bpp depth, so
  that U-Boot can access it with full colour depth.
 
+config VIDEO_LCD_ENDEAVORU
+   tristate "Endeavoru 720x1280 DSI video mode panel"
+   depends on PANEL && BACKLIGHT
+   select VIDEO_MIPI_DSI
+   help
+ Say Y here if you want to enable support for the IPS-LCD panel
+ module for HTC One X. Driver supports a family of panels,
+ made at least by 3 vendors (Sharp, Sony and AUO), but set up
+ using the same DSI command sequence. The panel has a 720x1280
+ resolution and uses 24 bit RGB per pixel.
+
 config VIDEO_LCD_ORISETECH_OTM8009A
bool "OTM8009A DSI LCD panel support"
select VIDEO_MIPI_DSI
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index cddfc8fd33..4aff7771a8 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_VIDEO_EFI) += efi.o
 obj-$(CONFIG_VIDEO_IPUV3) += imx/
 obj-$(CONFIG_VIDEO_IVYBRIDGE_IGD) += ivybridge_igd.o
 obj-$(CONFIG_VIDEO_LCD_ANX9804) += anx9804.o
+obj-$(CONFIG_VIDEO_LCD_ENDEAVORU) += endeavoru-panel.o
 obj-$(CONFIG_VIDEO_LCD_HITACHI_TX18D42VM) += hitachi_tx18d42vm_lcd.o
 obj-$(CONFIG_VIDEO_LCD_ORISETECH_OTM8009A) += orisetech_otm8009a.o
 obj-$(CONFIG_VIDEO_LCD_RAYDIUM_RM68200) += raydium-rm68200.o
diff --git a/drivers/video/endeavoru-panel.c b/drivers/video/endeavoru-panel.c
new file mode 100644
index 00..2fbfc72ca6
--- /dev/null
+++ b/drivers/video/endeavoru-panel.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct endeavoru_panel_priv {
+   struct udevice *vdd;
+   struct udevice *vddio;
+
+   struct udevice *backlight;
+
+   struct gpio_desc reset_gpio;
+};
+
+static struct display_timing default_timing = {
+   .pixelclock.typ = 6320,
+   .hactive.typ= 720,
+   .hfront_porch.typ   = 55,
+   .hback_porch.typ= 29,
+   .hsync_len.typ  = 16,
+   .vactive.typ= 1280,
+   .vfront_porch.typ   = 2,
+   .vback_porch.typ= 1,
+   .vsync_len.typ  = 1,
+};
+
+static void dcs_write_one(struct mipi_dsi_device *dsi, u8 cmd, u8 data)
+{
+   mipi_dsi_dcs_write(dsi, cmd, &data, 1);
+}
+
+/*
+ * This panel is not able to auto-increment all cmd addresses so for some of
+ * them, we need to send them one by one...
+ */
+#define dcs_write_seq(dsi, cmd, seq...)\
+({ \
+   static const u8 d[] = { seq };  \
+   unsigned int i; \
+   \
+   for (i = 0; i < ARRAY_SIZE(d) ; i++)\
+   dcs_write_one(dsi, cmd + i, d[i]);  \
+})
+
+static int endeavoru_panel_enable_backlight(struct udevice *dev)
+{
+   struct endeavoru_panel_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = dm_gpio_set_value(&priv->reset_gpio, 1);
+   if (ret) {
+   log_err("error changing reset-gpios (%d)\n", ret);
+   return ret;
+   }
+   mdelay(5);
+
+   ret = regulator_set_enable_if_allowed(priv->vddio, 1);
+   if (ret) {
+   log_err("error enabling iovcc-supply (%d)\n", ret);
+   return ret;
+   }
+   mdelay(1);
+
+   ret = regulator_set_enable_if_allowed(priv->vdd, 1);
+   if (ret) {
+   log_err("error enabling vcc-supply (%d)\n", ret);
+   return ret;
+   }
+   mdelay(20);
+
+   ret = dm_gpio_set_value(&priv->reset_gpio, 0);
+   if (ret) {
+   log_err("error changing reset-gpios (%d)\n", ret);
+   return ret;
+   }
+   mdelay(2);
+
+   /* Reset panel */
+   ret = dm_gpio_set_value(&priv->reset_gpio, 1);
+   if (ret) {
+   log_err("error changing reset-gpios (%d)\n", ret);
+   return ret;
+   }
+   mdelay(1);
+
+   ret = dm_gpio_set_value(&priv->reset_gpio, 0);
+  

[PATCH v4 0/3] Add MAX14526 MUIC driver

2023-04-25 Thread Svyatoslav Ryhel
MAX14526 MUIC is used by LG P880/P895 which are currently
in the process of merging.

MAX14526 is a powerful extcon device which has the ability to
accurately determine plugged devices. In this implementation
muic can be configured to represent 3 modes: CP-USB/UART and
AP-USB. Unfortunately AP-UART was disabled on P880/P895.
Additionally the driver configures some stuff required by
the charger.

Extcon class has empty platform struct and ops, all configuration
is performed in the probe. Filling of struct and ops is welcomed.

---
Changes from v3:
- fix typo in commit title
- added reviewed-by

Changes from v2:
- created a new simple extcon uclass

Changes from v1:
- used log_* instead of printf
- log messages made simpler
---

Svyatoslav Ryhel (3):
  dm: extcon: add an uclass for extcon
  test: Add tests for the extcon
  extcon: add MAX14526 MUIC support

 arch/sandbox/dts/test.dts|   4 +
 drivers/Kconfig  |   2 +
 drivers/Makefile |   1 +
 drivers/extcon/Kconfig   |  31 +++
 drivers/extcon/Makefile  |   7 ++
 drivers/extcon/extcon-max14526.c | 151 +++
 drivers/extcon/extcon-sandbox.c  |  17 
 drivers/extcon/extcon-uclass.c   |  16 
 include/dm/uclass-id.h   |   1 +
 include/extcon.h |  19 
 test/dm/Makefile |   1 +
 test/dm/extcon.c |  21 +
 12 files changed, 271 insertions(+)
 create mode 100644 drivers/extcon/Kconfig
 create mode 100644 drivers/extcon/Makefile
 create mode 100644 drivers/extcon/extcon-max14526.c
 create mode 100644 drivers/extcon/extcon-sandbox.c
 create mode 100644 drivers/extcon/extcon-uclass.c
 create mode 100644 include/extcon.h
 create mode 100644 test/dm/extcon.c

-- 
2.39.2



[PATCH v4 1/3] dm: extcon: add an uclass for extcon

2023-04-25 Thread Svyatoslav Ryhel
Add a new simple uclass for extcon. Currently all setup is done
in the probe. Uclass struct and ops are empty for now.

Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 drivers/Kconfig|  2 ++
 drivers/Makefile   |  1 +
 drivers/extcon/Kconfig | 15 +++
 drivers/extcon/Makefile|  5 +
 drivers/extcon/extcon-uclass.c | 16 
 include/dm/uclass-id.h |  1 +
 include/extcon.h   | 19 +++
 7 files changed, 59 insertions(+)
 create mode 100644 drivers/extcon/Kconfig
 create mode 100644 drivers/extcon/Makefile
 create mode 100644 drivers/extcon/extcon-uclass.c
 create mode 100644 include/extcon.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 9101e538b0..75937fbb6d 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -36,6 +36,8 @@ source "drivers/dfu/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/extcon/Kconfig"
+
 source "drivers/fastboot/Kconfig"
 
 source "drivers/firmware/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 58be410135..ed1e71c4d6 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_$(SPL_TPL_)DM) += core/
 obj-$(CONFIG_$(SPL_TPL_)DMA) += dma/
 obj-$(CONFIG_$(SPL_TPL_)DMA_LEGACY) += dma/
 obj-$(CONFIG_$(SPL_TPL_)DFU) += dfu/
+obj-$(CONFIG_$(SPL_TPL_)EXTCON) += extcon/
 obj-$(CONFIG_$(SPL_TPL_)GPIO) += gpio/
 obj-$(CONFIG_$(SPL_TPL_)DRIVERS_MISC) += misc/
 obj-$(CONFIG_$(SPL_TPL_)SYSRESET) += sysreset/
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
new file mode 100644
index 00..8a50250d21
--- /dev/null
+++ b/drivers/extcon/Kconfig
@@ -0,0 +1,15 @@
+menu "Extcon Support"
+
+config EXTCON
+   bool "External Connector Class (extcon) support"
+   depends on DM
+   help
+ Say Y here to enable external connector class (extcon) support.
+ This allows monitoring external connectors and supports external
+ connectors with multiple states; i.e., an extcon that may have
+ multiple cables attached. For example, an external connector
+ of a device may be used to connect an HDMI cable and a AC adaptor,
+ and to host USB ports. Many of 30-pin connectors including PDMI
+ are also good examples.
+
+endmenu
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
new file mode 100644
index 00..2510e91c07
--- /dev/null
+++ b/drivers/extcon/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2023 Svyatoslav Ryhel 
+
+obj-$(CONFIG_EXTCON) += extcon-uclass.o
diff --git a/drivers/extcon/extcon-uclass.c b/drivers/extcon/extcon-uclass.c
new file mode 100644
index 00..9dd22b5762
--- /dev/null
+++ b/drivers/extcon/extcon-uclass.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Svyatoslav Ryhel 
+ */
+
+#define LOG_CATEGORY UCLASS_EXTCON
+
+#include 
+#include 
+#include 
+
+UCLASS_DRIVER(extcon) = {
+   .id = UCLASS_EXTCON,
+   .name   = "extcon",
+   .per_device_plat_auto   = sizeof(struct extcon_uc_plat),
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 576237b954..94ab46c5ba 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -56,6 +56,7 @@ enum uclass_id {
UCLASS_EFI_MEDIA,   /* Devices provided by UEFI firmware */
UCLASS_ETH, /* Ethernet device */
UCLASS_ETH_PHY, /* Ethernet PHY device */
+   UCLASS_EXTCON,  /* External Connector Class */
UCLASS_FIRMWARE,/* Firmware */
UCLASS_FPGA,/* FPGA device */
UCLASS_FUZZING_ENGINE,  /* Fuzzing engine */
diff --git a/include/extcon.h b/include/extcon.h
new file mode 100644
index 00..d060f5a3c1
--- /dev/null
+++ b/include/extcon.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2023 Svyatoslav Ryhel 
+ */
+
+#ifndef __EXTCON_H
+#define __EXTCON_H
+
+struct udevice;
+
+/**
+ * struct extcon_uc_plat - Platform data the uclass stores about each device
+ *
+ * To be filled
+ */
+struct extcon_uc_plat {
+};
+
+#endif
-- 
2.39.2



[PATCH v4 2/3] test: Add tests for the extcon

2023-04-25 Thread Svyatoslav Ryhel
Provide tests to the simple extcon device.

Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 arch/sandbox/dts/test.dts   |  4 
 drivers/extcon/Kconfig  |  7 +++
 drivers/extcon/Makefile |  1 +
 drivers/extcon/extcon-sandbox.c | 17 +
 test/dm/Makefile|  1 +
 test/dm/extcon.c| 21 +
 6 files changed, 51 insertions(+)
 create mode 100644 drivers/extcon/extcon-sandbox.c
 create mode 100644 test/dm/extcon.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 7c1ee71cb7..731b48459d 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1802,6 +1802,10 @@
compatible = "u-boot,fwu-mdata-gpt";
fwu-mdata-store = <&mmc0>;
};
+
+   extcon {
+   compatible = "sandbox,extcon";
+   };
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 8a50250d21..6fd3d2b97b 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -12,4 +12,11 @@ config EXTCON
  and to host USB ports. Many of 30-pin connectors including PDMI
  are also good examples.
 
+config EXTCON_SANDBOX
+   bool "Sandbox extcon"
+   depends on EXTCON
+   help
+ Enable extcon support for sandbox. This is an emulation of a real
+ extcon. Currectly all configuration is done in the probe.
+
 endmenu
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 2510e91c07..c4223d97d1 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -3,3 +3,4 @@
 # Copyright (C) 2023 Svyatoslav Ryhel 
 
 obj-$(CONFIG_EXTCON) += extcon-uclass.o
+obj-$(CONFIG_EXTCON_SANDBOX) += extcon-sandbox.o
diff --git a/drivers/extcon/extcon-sandbox.c b/drivers/extcon/extcon-sandbox.c
new file mode 100644
index 00..ab6a6c1cfd
--- /dev/null
+++ b/drivers/extcon/extcon-sandbox.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#include 
+
+static const struct udevice_id sandbox_extcon_ids[] = {
+   { .compatible = "sandbox,extcon" },
+   { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(extcon_sandbox) = {
+   .name   = "extcon_sandbox",
+   .id = UCLASS_EXTCON,
+   .of_match   = sandbox_extcon_ids,
+};
diff --git a/test/dm/Makefile b/test/dm/Makefile
index e15bdbf04b..5ada659974 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_DM_DSA) += dsa.o
 obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o
 obj-$(CONFIG_EFI_MEDIA_SANDBOX) += efi_media.o
 obj-$(CONFIG_DM_ETH) += eth.o
+obj-$(CONFIG_EXTCON) += extcon.o
 ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
diff --git a/test/dm/extcon.c b/test/dm/extcon.c
new file mode 100644
index 00..6a4e22bfdc
--- /dev/null
+++ b/test/dm/extcon.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int dm_test_extcon(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+
+   ut_assertok(uclass_get_device_by_name(UCLASS_EXTCON, "extcon", &dev));
+
+   return 0;
+}
+
+DM_TEST(dm_test_extcon, UT_TESTF_SCAN_FDT);
-- 
2.39.2



[PATCH v4 3/3] extcon: add MAX14526 MUIC support

2023-04-25 Thread Svyatoslav Ryhel
MAX14526 is a powerful extcon chip which allows detection of various
plugs like usb, mhl, uart, headset etc. This version of driver
implements support of AP-usb and CP-usb/uart paths.

Tested-by: Andreas Westman Dorcsak  # LG P880 T30
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
Reviewed-by: Simon Glass 
---
 drivers/extcon/Kconfig   |   9 ++
 drivers/extcon/Makefile  |   1 +
 drivers/extcon/extcon-max14526.c | 151 +++
 3 files changed, 161 insertions(+)
 create mode 100644 drivers/extcon/extcon-max14526.c

diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6fd3d2b97b..fbb73354aa 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -19,4 +19,13 @@ config EXTCON_SANDBOX
  Enable extcon support for sandbox. This is an emulation of a real
  extcon. Currectly all configuration is done in the probe.
 
+config EXTCON_MAX14526
+   bool "Maxim MAX14526 EXTCON Support"
+   depends on DM_I2C
+   depends on EXTCON
+   help
+ If you say yes here you get support for the MUIC device of
+ Maxim MAX14526. The MAX14526 MUIC is a USB port accessory
+ detector and switch.
+
 endmenu
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index c4223d97d1..3309f2aac2 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_EXTCON) += extcon-uclass.o
 obj-$(CONFIG_EXTCON_SANDBOX) += extcon-sandbox.o
+obj-$(CONFIG_EXTCON_MAX14526) += extcon-max14526.o
diff --git a/drivers/extcon/extcon-max14526.c b/drivers/extcon/extcon-max14526.c
new file mode 100644
index 00..a33b5ef919
--- /dev/null
+++ b/drivers/extcon/extcon-max14526.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define CONTROL_1  0x01
+#define SW_CONTROL 0x03
+
+#define ID_200 0x10
+#define ADC_EN 0x02
+#define CP_EN  0x01
+
+#define DP_USB 0x00
+#define DP_UART0x08
+#define DP_AUDIO   0x10
+#define DP_OPEN0x38
+
+#define DM_USB 0x00
+#define DM_UART0x01
+#define DM_AUDIO   0x02
+#define DM_OPEN0x07
+
+#define AP_USB BIT(0)
+#define CP_USB BIT(1)
+#define CP_UARTBIT(2)
+
+struct max14526_priv {
+   struct gpio_desc usif_gpio;
+   struct gpio_desc dp2t_gpio;
+   struct gpio_desc ifx_usb_vbus_gpio;
+};
+
+static void max14526_set_mode(struct udevice *dev, int mode)
+{
+   struct max14526_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   if ((mode & AP_USB) || (mode & CP_USB)) {
+   /* Connect CP UART signals to AP */
+   ret = dm_gpio_set_value(&priv->usif_gpio, 0);
+   if (ret)
+   log_debug("cp-uart > ap failed (%d)\n", ret);
+   }
+
+   if (mode & CP_UART) {
+   /* Connect CP UART signals to DP2T */
+   ret = dm_gpio_set_value(&priv->usif_gpio, 1);
+   if (ret)
+   log_debug("cp-uart > dp2t failed (%d)\n", ret);
+   }
+
+   if (mode & CP_USB) {
+   /* Connect CP USB to MUIC UART */
+   ret = dm_gpio_set_value(&priv->ifx_usb_vbus_gpio, 1);
+   if (ret)
+   log_debug("usb-vbus-gpio enable failed (%d)\n", ret);
+
+   ret = dm_gpio_set_value(&priv->dp2t_gpio, 1);
+   if (ret)
+   log_debug("cp-usb > muic-uart failed (%d)\n", ret);
+   }
+
+   if ((mode & AP_USB) || (mode & CP_UART)) {
+   /* Connect CP UART to MUIC UART */
+   ret = dm_gpio_set_value(&priv->dp2t_gpio, 0);
+   if (ret)
+   log_debug("cp-uart > muic-uart failed (%d)\n", ret);
+   }
+
+   if (mode & AP_USB) {
+   /* Enables USB Path */
+   ret = dm_i2c_reg_write(dev, SW_CONTROL, DP_USB | DM_USB);
+   if (ret)
+   log_debug("USB path set failed: %d\n", ret);
+   }
+
+   if ((mode & CP_USB) || (mode & CP_UART)) {
+   /* Enables UART Path */
+   ret = dm_i2c_reg_write(dev, SW_CONTROL, DP_UART | DM_UART);
+   if (ret)
+   log_debug("UART path set failed: %d\n", ret);
+   }
+
+   /* Enables 200K, Charger Pump, and ADC */
+   ret = dm_i2c_reg_write(dev, CONTROL_1, ID_200 | ADC_EN | CP_EN);
+   if (ret)
+   log_debug("200K, Charger Pump, and ADC set failed: %d\n", ret);
+}
+
+static int max14526_probe(struct udevice *dev)
+{
+   struct max14526_priv *priv = dev_get_priv(dev);
+   int ret, mode = 0;
+
+   ret = gpio_request_by_name(dev, "usif-gpios", 0,
+  &priv->usif_gpio, GPIOD_IS_OUT);
+  

Re: [PATCH 1/2] arm: dts: rk3399: rock-pi-4: sync with Linux 6.3-rc5

2023-04-25 Thread FUKAUMI Naoki

hi,

On 4/13/23 11:18, Kever Yang wrote:


On 2023/4/8 17:11, FUKAUMI Naoki wrote:

sync *.dts{,i} files for Radxa ROCK Pi 4 series with Linux 6.3-rc5.

Signed-off-by: FUKAUMI Naoki 

Reviewed-by: Kever Yang 


this is not merged yet, right?
I want to modify this change.

Best regards,

--
FUKAUMI Naoki


Thanks,
- Kever

---
  arch/arm/dts/Makefile |   2 +
  arch/arm/dts/rk3399-rock-pi-4.dtsi    | 229 --
  .../dts/rk3399-rock-pi-4a-plus-u-boot.dtsi    |   5 +
  arch/arm/dts/rk3399-rock-pi-4a-plus.dts   |  25 ++
  arch/arm/dts/rk3399-rock-pi-4a-u-boot.dtsi    |   6 +
  .../dts/rk3399-rock-pi-4b-plus-u-boot.dtsi    |   5 +
  arch/arm/dts/rk3399-rock-pi-4b-plus.dts   |  61 +
  arch/arm/dts/rk3399-rock-pi-4b.dts    |   9 +-
  arch/arm/dts/rk3399-rock-pi-4c.dts    |  20 +-
  9 files changed, 284 insertions(+), 78 deletions(-)
  create mode 100644 arch/arm/dts/rk3399-rock-pi-4a-plus-u-boot.dtsi
  create mode 100644 arch/arm/dts/rk3399-rock-pi-4a-plus.dts
  create mode 100644 arch/arm/dts/rk3399-rock-pi-4a-u-boot.dtsi
  create mode 100644 arch/arm/dts/rk3399-rock-pi-4b-plus-u-boot.dtsi
  create mode 100644 arch/arm/dts/rk3399-rock-pi-4b-plus.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index c160e884bf..8a5eb6225c 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -157,7 +157,9 @@ dtb-$(CONFIG_ROCKCHIP_RK3399) += \
  rk3399-puma-haikou.dtb \
  rk3399-roc-pc.dtb \
  rk3399-roc-pc-mezzanine.dtb \
+    rk3399-rock-pi-4a-plus.dtb \
  rk3399-rock-pi-4a.dtb \
+    rk3399-rock-pi-4b-plus.dtb \
  rk3399-rock-pi-4b.dtb \
  rk3399-rock-pi-4c.dtb \
  rk3399-rock960.dtb \
diff --git a/arch/arm/dts/rk3399-rock-pi-4.dtsi 
b/arch/arm/dts/rk3399-rock-pi-4.dtsi

index b2ea92..907071d4fe 100644
--- a/arch/arm/dts/rk3399-rock-pi-4.dtsi
+++ b/arch/arm/dts/rk3399-rock-pi-4.dtsi
@@ -6,14 +6,15 @@
  /dts-v1/;
  #include 
+#include 
  #include 
  #include "rk3399.dtsi"
  #include "rk3399-opp.dtsi"
  / {
  aliases {
-    mmc0 = &sdmmc;
-    mmc1 = &sdhci;
+    mmc0 = &sdhci;
+    mmc1 = &sdmmc;
  };
  chosen {
@@ -27,6 +28,20 @@
  #clock-cells = <0>;
  };
+    leds {
+    compatible = "gpio-leds";
+    pinctrl-names = "default";
+    pinctrl-0 = <&user_led2>;
+
+    /* USER_LED2 */
+    led-0 {
+    function = LED_FUNCTION_STATUS;
+    color = ;
+    gpios = <&gpio3 RK_PD5 GPIO_ACTIVE_HIGH>;
+    linux,default-trigger = "heartbeat";
+    };
+    };
+
  sdio_pwrseq: sdio-pwrseq {
  compatible = "mmc-pwrseq-simple";
  clocks = <&rk808 1>;
@@ -36,32 +51,56 @@
  reset-gpios = <&gpio0 RK_PB2 GPIO_ACTIVE_LOW>;
  };
-    vcc12v_dcin: dc-12v {
+    sound: sound {
+    compatible = "audio-graph-card";
+    label = "Analog";
+    dais = <&i2s0_p0>;
+    };
+
+    sound-dit {
+    compatible = "audio-graph-card";
+    label = "SPDIF";
+    dais = <&spdif_p0>;
+    };
+
+    spdif-dit {
+    compatible = "linux,spdif-dit";
+    #sound-dai-cells = <0>;
+
+    port {
+    dit_p0_0: endpoint {
+    remote-endpoint = <&spdif_p0_0>;
+    };
+    };
+    };
+
+    vbus_typec: vbus-typec-regulator {
  compatible = "regulator-fixed";
-    regulator-name = "vcc12v_dcin";
+    enable-active-high;
+    gpio = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>;
+    pinctrl-names = "default";
+    pinctrl-0 = <&vcc5v0_typec_en>;
+    regulator-name = "vbus_typec";
  regulator-always-on;
-    regulator-boot-on;
-    regulator-min-microvolt = <1200>;
-    regulator-max-microvolt = <1200>;
+    vin-supply = <&vcc5v0_sys>;
  };
-    vcc5v0_sys: vcc-sys {
+    vcc12v_dcin: dc-12v {
  compatible = "regulator-fixed";
-    regulator-name = "vcc5v0_sys";
+    regulator-name = "vcc12v_dcin";
  regulator-always-on;
  regulator-boot-on;
-    regulator-min-microvolt = <500>;
-    regulator-max-microvolt = <500>;
-    vin-supply = <&vcc12v_dcin>;
+    regulator-min-microvolt = <1200>;
+    regulator-max-microvolt = <1200>;
  };
-    vcc_0v9: vcc-0v9 {
+    vcc3v3_lan: vcc3v3-lan-regulator {
  compatible = "regulator-fixed";
-    regulator-name = "vcc_0v9";
+    regulator-name = "vcc3v3_lan";
  regulator-always-on;
  regulator-boot-on;
-    regulator-min-microvolt = <90>;
-    regulator-max-microvolt = <90>;
+    regulator-min-microvolt = <330>;
+    regulator-max-microvolt = <330>;
  vin-supply = <&vcc3v3_sys>;
  };
@@ -98,35 +137,35 @@
  vin-supply = <&vcc5v0_sys>;
  };
-    vcc5v0_typec: vcc5v0-typec-regulator {
+    vcc5v0_sys: vcc-sys {
  compatible = "regulator-fixed";
-    enable-active-high;
-    gpio = <&gpio1 R

[PATCH v4 0/7] Tegra: add ASUS/Google Nexus 7 (2012) support

2023-04-25 Thread Svyatoslav Ryhel
This patchset adds support for native use of U-Boot on:
- ASUS T30 Transformers (7 devices, all models);
- ASUS/Google Nexus 7 (2012), both grouper and tilapia
- LG Optimus 4X HD (P880) and Optimus Vu (P895)
- HTC One X (endeavoru)
as a replacement for the vendor bootloader.

Current commits are designed to work on re-crypted devices but can
be used on clean unmodified devices with slight restrictions (like
no booting/mounting emmc and no self updating feature).

All device setup commits fall under the same pattern. Alongside device
bringup tegra requires few small patches:
 - add gpio keyboard as stdin device
 - make networking boot options optional
 - add a small tool to generate SoC UID

Commits passed './tools/buildman/buildman tegra' (30 boards) without
errors.

---
Changes from v3:
- extended amount of devices supported

Changes from v2:
 - fuse build is excluded for T186 (it is not supported in it anyway)

Changes from v1:
 - fix fuse headers for newer Tegra generations
 - allow grouper_common_defconfig to pass without fragments
---

Jonas Schwöbel (1):
  configs: tegra-common-post: make PXE and DHCP boot targets optional

Svyatoslav Ryhel (6):
  configs: tegra-common-post: add GPIO keyboard as STDIN device
  ARM: tegra: add SoC UID calculation function
  board: asus: transformer: add ASUS Transformer T30 family support
  board: asus: grouper: add Google Nexus 7 (2012) support
  board: lg: x3: add Optimus 4X HD and Optimus Vu support
  board: htc: endeavoru: add One X support

 arch/arm/dts/Makefile |  12 +
 arch/arm/dts/tegra30-asus-grouper-common.dtsi | 157 ++
 .../dts/tegra30-asus-nexus7-grouper-E1565.dts |  43 ++
 .../dts/tegra30-asus-nexus7-grouper-PM269.dts |  36 ++
 .../dts/tegra30-asus-nexus7-tilapia-E1565.dts |  62 +++
 arch/arm/dts/tegra30-asus-p1801-t.dts |  17 +
 arch/arm/dts/tegra30-asus-tf201.dts   |   9 +
 arch/arm/dts/tegra30-asus-tf300t.dts  |  18 +
 arch/arm/dts/tegra30-asus-tf300tg.dts |   9 +
 arch/arm/dts/tegra30-asus-tf300tl.dts |   9 +
 arch/arm/dts/tegra30-asus-tf600t.dts  |  89 
 arch/arm/dts/tegra30-asus-tf700t.dts  |  13 +
 arch/arm/dts/tegra30-asus-transformer.dtsi| 211 
 arch/arm/dts/tegra30-htc-endeavoru.dts| 166 +++
 arch/arm/dts/tegra30-lg-p880.dts  |  40 ++
 arch/arm/dts/tegra30-lg-p895.dts  |  50 ++
 arch/arm/dts/tegra30-lg-x3.dtsi   | 180 +++
 arch/arm/include/asm/arch-tegra/fuse.h|   7 +
 arch/arm/mach-tegra/Makefile  |   4 +
 arch/arm/mach-tegra/fuse.c| 151 ++
 arch/arm/mach-tegra/tegra30/Kconfig   |  20 +
 board/asus/grouper/Kconfig|  22 +
 board/asus/grouper/MAINTAINERS|   6 +
 board/asus/grouper/Makefile   |  14 +
 board/asus/grouper/grouper-spl-max.c  |  45 ++
 board/asus/grouper/grouper-spl-ti.c   |  41 ++
 board/asus/grouper/grouper.c  | 202 
 board/asus/grouper/pinmux-config-grouper.h| 362 ++
 board/asus/transformer-t30/Kconfig|  35 ++
 board/asus/transformer-t30/MAINTAINERS|   6 +
 board/asus/transformer-t30/Makefile   |  11 +
 .../pinmux-config-transformer.h   | 365 ++
 .../transformer-t30/transformer-t30-spl.c |  41 ++
 board/asus/transformer-t30/transformer-t30.c  | 201 
 board/htc/endeavoru/Kconfig   |  12 +
 board/htc/endeavoru/MAINTAINERS   |   6 +
 board/htc/endeavoru/Makefile  |  11 +
 board/htc/endeavoru/endeavoru-spl.c   |  47 ++
 board/htc/endeavoru/endeavoru.c   | 116 +
 board/htc/endeavoru/pinmux-config-endeavoru.h | 362 ++
 board/lg/x3-t30/Kconfig   |  26 +
 board/lg/x3-t30/MAINTAINERS   |   6 +
 board/lg/x3-t30/Makefile  |  11 +
 board/lg/x3-t30/pinmux-config-x3.h| 449 ++
 board/lg/x3-t30/x3-t30-spl.c  |  48 ++
 board/lg/x3-t30/x3-t30.c  | 176 +++
 configs/endeavoru_defconfig   |  82 
 configs/grouper_E1565.config  |   2 +
 configs/grouper_PM269.config  |   2 +
 configs/grouper_common_defconfig  |  82 
 configs/p1801-t.config|   2 +
 configs/p880.config   |   4 +
 configs/p895.config   |   4 +
 configs/tf201.config  |   2 +
 configs/tf300t.config |   2 +
 configs/tf300tg.config|   2 +
 configs/tf300tl.config|   2 +
 configs/tf600t.config |   5 +
 configs/tf700t.config |   2 +
 configs/tilapia.config|   3 +
 configs/transformer_t30_defconfig |  83 
 c

[PATCH v4 1/7] configs: tegra-common-post: add GPIO keyboard as STDIN device

2023-04-25 Thread Svyatoslav Ryhel
GPIO keyboard is used on many newly upstreamed devices.

Tested-by: Andreas Westman Dorcsak  # ASUS Grouper E1565
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
---
 include/configs/tegra-common-post.h | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/configs/tegra-common-post.h 
b/include/configs/tegra-common-post.h
index 991ffbb7df..2d5095639a 100644
--- a/include/configs/tegra-common-post.h
+++ b/include/configs/tegra-common-post.h
@@ -35,6 +35,12 @@
 #define STDIN_KBD_USB ""
 #endif
 
+#ifdef CONFIG_BUTTON_KEYBOARD
+#define STDIN_BTN_KBD ",button-kbd"
+#else
+#define STDIN_BTN_KBD ""
+#endif
+
 #ifdef CONFIG_VIDEO
 #define STDOUT_VIDEO ",vidconsole"
 #else
@@ -48,7 +54,7 @@
 #endif
 
 #define TEGRA_DEVICE_SETTINGS \
-   "stdin=serial" STDIN_KBD_KBC STDIN_KBD_USB STDOUT_CROS_EC "\0" \
+   "stdin=serial" STDIN_KBD_KBC STDIN_KBD_USB STDOUT_CROS_EC STDIN_BTN_KBD 
"\0" \
"stdout=serial" STDOUT_VIDEO "\0" \
"stderr=serial" STDOUT_VIDEO "\0" \
""
-- 
2.39.2



[PATCH v4 3/7] ARM: tegra: add SoC UID calculation function

2023-04-25 Thread Svyatoslav Ryhel
This is a small tool for calculation of SoC UID based on the same
Linux function. It can be further used for generation of device
unique data like mac address or exposing it as serial number.

Tested-by: Andreas Westman Dorcsak  # ASUS Grouper E1565
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
---
 arch/arm/include/asm/arch-tegra/fuse.h |   7 ++
 arch/arm/mach-tegra/Makefile   |   4 +
 arch/arm/mach-tegra/fuse.c | 151 +
 3 files changed, 162 insertions(+)
 create mode 100644 arch/arm/mach-tegra/fuse.c

diff --git a/arch/arm/include/asm/arch-tegra/fuse.h 
b/arch/arm/include/asm/arch-tegra/fuse.h
index 5b8e0bd8d1..f3f2ad8e3f 100644
--- a/arch/arm/include/asm/arch-tegra/fuse.h
+++ b/arch/arm/include/asm/arch-tegra/fuse.h
@@ -19,4 +19,11 @@ struct fuse_regs {
u32 security_mode;  /* 0x1A0: FUSE_SECURITY_MODE */
 };
 
+/**
+ * Calculate SoC UID
+ *
+ * Return: uid if ok, 0 on error
+ */
+unsigned long long tegra_chip_uid(void);
+
 #endif /* ifndef _FUSE_H_ */
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index 9147050b32..a5733b0bf6 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -32,6 +32,10 @@ endif
 obj-$(CONFIG_DISPLAY_CPUINFO) += sys_info.o
 obj-y += pmc.o
 
+ifndef CONFIG_TEGRA186
+obj-y += fuse.o
+endif
+
 obj-$(CONFIG_TEGRA20) += tegra20/
 obj-$(CONFIG_TEGRA30) += tegra30/
 obj-$(CONFIG_TEGRA114) += tegra114/
diff --git a/arch/arm/mach-tegra/fuse.c b/arch/arm/mach-tegra/fuse.c
new file mode 100644
index 00..83bd505538
--- /dev/null
+++ b/arch/arm/mach-tegra/fuse.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  (C) Copyright 2012-2013
+ *  NVIDIA Corporation 
+ *
+ *  (C) Copyright 2022
+ *  Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "cpu.h"
+
+#define FUSE_UID_LOW   0x108
+#define FUSE_UID_HIGH  0x10c
+
+#define FUSE_VENDOR_CODE   0x200
+#define FUSE_FAB_CODE  0x204
+#define FUSE_LOT_CODE_00x208
+#define FUSE_LOT_CODE_10x20c
+#define FUSE_WAFER_ID  0x210
+#define FUSE_X_COORDINATE  0x214
+#define FUSE_Y_COORDINATE  0x218
+
+#define FUSE_VENDOR_CODE_MASK  0xf
+#define FUSE_FAB_CODE_MASK 0x3f
+#define FUSE_WAFER_ID_MASK 0x3f
+#define FUSE_X_COORDINATE_MASK 0x1ff
+#define FUSE_Y_COORDINATE_MASK 0x1ff
+
+static u32 tegra_fuse_readl(unsigned long offset)
+{
+   return readl(NV_PA_FUSE_BASE + offset);
+}
+
+static void tegra_fuse_init(void)
+{
+   u32 reg;
+
+   /*
+* Performed by downstream and is not
+* documented by TRM. Whithout setting
+* this bit fuse region will not work.
+*/
+   reg = readl_relaxed(NV_PA_CLK_RST_BASE + 0x48);
+   reg |= BIT(28);
+   writel(reg, NV_PA_CLK_RST_BASE + 0x48);
+
+   clock_enable(PERIPH_ID_FUSE);
+   udelay(2);
+   reset_set_enable(PERIPH_ID_FUSE, 0);
+}
+
+unsigned long long tegra_chip_uid(void)
+{
+   u64 uid = 0ull;
+   u32 reg;
+   u32 cid;
+   u32 vendor;
+   u32 fab;
+   u32 lot;
+   u32 wafer;
+   u32 x;
+   u32 y;
+   u32 i;
+
+   tegra_fuse_init();
+
+   /* This used to be so much easier in prior chips. Unfortunately, there
+  is no one-stop shopping for the unique id anymore. It must be
+  constructed from various bits of information burned into the fuses
+  during the manufacturing process. The 64-bit unique id is formed
+  by concatenating several bit fields. The notation used for the
+  various fields is  with the UID composed
+  thusly:
+  
+  Where:
+   FieldBits  Position Data
+   ---     
+   CID4 60 Chip id
+   VENDOR 4 56 Vendor code
+   FAB6 50 FAB code
+   LOT   26 24 Lot code (5-digit base-36-coded-decimal,
+   re-encoded to 26 bits binary)
+   WAFER  6 18 Wafer id
+   X  9  9 Wafer X-coordinate
+   Y  9  0 Wafer Y-coordinate
+   ---  
+   Total 64
+   */
+
+   switch (tegra_get_chip()) {
+   case CHIPID_TEGRA20:
+   /* T20 has simple calculation */
+   return ((unsigned long long)tegra_fuse_readl(FUSE_UID_HIGH) << 
32ull) |
+   (unsigned long long)tegra_fuse_readl(FUSE_UID_LOW);
+   case CHIPID_TEGRA30:
+   /* T30 chip id is 0 */
+   cid = 0;
+   break;
+   case CHIPID_TEGRA114:
+   /* T11x chip id is 1 */
+   cid = 1;
+   break;
+   case CHIPID_TEGRA124:
+   /* 

[PATCH v4 2/7] configs: tegra-common-post: make PXE and DHCP boot targets optional

2023-04-25 Thread Svyatoslav Ryhel
From: Jonas Schwöbel 

Disabling the network related features in defconfig causes build to
fail so make them optional.

Tested-by: Andreas Westman Dorcsak  # ASUS Grouper E1565
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Jonas Schwöbel 
Signed-off-by: Svyatoslav Ryhel 
---
 include/configs/tegra-common-post.h | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/configs/tegra-common-post.h 
b/include/configs/tegra-common-post.h
index 2d5095639a..0d0965ecce 100644
--- a/include/configs/tegra-common-post.h
+++ b/include/configs/tegra-common-post.h
@@ -8,9 +8,21 @@
 #define __TEGRA_COMMON_POST_H
 
 #if IS_ENABLED(CONFIG_CMD_USB)
-# define BOOT_TARGET_USB(func) func(USB, usb, 0)
+#define BOOT_TARGET_USB(func) func(USB, usb, 0)
 #else
-# define BOOT_TARGET_USB(func)
+#define BOOT_TARGET_USB(func)
+#endif
+
+#if CONFIG_IS_ENABLED(CMD_DHCP) && CONFIG_IS_ENABLED(CMD_PXE)
+#define BOOT_TARGET_PXE(func) func(PXE, pxe, na)
+#else
+#define BOOT_TARGET_PXE(func)
+#endif
+
+#if CONFIG_IS_ENABLED(CMD_DHCP)
+#define BOOT_TARGET_DHCP(func) func(DHCP, dhcp, na)
+#else
+#define BOOT_TARGET_DHCP(func)
 #endif
 
 #ifndef BOOT_TARGET_DEVICES
@@ -18,8 +30,8 @@
func(MMC, mmc, 1) \
func(MMC, mmc, 0) \
BOOT_TARGET_USB(func) \
-   func(PXE, pxe, na) \
-   func(DHCP, dhcp, na)
+   BOOT_TARGET_PXE(func) \
+   BOOT_TARGET_DHCP(func)
 #endif
 #include 
 
-- 
2.39.2



[PATCH v4 4/7] board: asus: transformer: add ASUS Transformer T30 family support

2023-04-25 Thread Svyatoslav Ryhel
The Asus Transformer T30 family are 2-in-1 detachable tablets
and AiO developed by Asus that run the Android operating system
(TF600T runs Windows RT and P1801-T runs Android and Windows).
The T30 Transformers feature a 10.1-inch display (apart P1801-T),
an Nvidia Tegra 3 quad-core chip, 1/2 GB of RAM, and 16/32 GB of storage.
Transformers board derives from Nvidia Cardhu development board.

This patch brings support for 7 known Transformer devices:
- ASUS Transformer Prime TF201
- ASUS Transformer Pad TF300T/TF300TG/TF300TL
- ASUS VivoTab RT TF600T (Windows RT based)
- ASUS Transformer Infinity TF700T
- ASUS Transformer AiO P1801-T

Tested-by: Andreas Westman Dorcsak  # all devices
Signed-off-by: Svyatoslav Ryhel 
---
 arch/arm/dts/Makefile |   7 +
 arch/arm/dts/tegra30-asus-p1801-t.dts |  17 +
 arch/arm/dts/tegra30-asus-tf201.dts   |   9 +
 arch/arm/dts/tegra30-asus-tf300t.dts  |  18 +
 arch/arm/dts/tegra30-asus-tf300tg.dts |   9 +
 arch/arm/dts/tegra30-asus-tf300tl.dts |   9 +
 arch/arm/dts/tegra30-asus-tf600t.dts  |  89 +
 arch/arm/dts/tegra30-asus-tf700t.dts  |  13 +
 arch/arm/dts/tegra30-asus-transformer.dtsi| 211 ++
 arch/arm/mach-tegra/tegra30/Kconfig   |   5 +
 board/asus/transformer-t30/Kconfig|  35 ++
 board/asus/transformer-t30/MAINTAINERS|   6 +
 board/asus/transformer-t30/Makefile   |  11 +
 .../pinmux-config-transformer.h   | 365 ++
 .../transformer-t30/transformer-t30-spl.c |  41 ++
 board/asus/transformer-t30/transformer-t30.c  | 201 ++
 configs/p1801-t.config|   2 +
 configs/tf201.config  |   2 +
 configs/tf300t.config |   2 +
 configs/tf300tg.config|   2 +
 configs/tf300tl.config|   2 +
 configs/tf600t.config |   5 +
 configs/tf700t.config |   2 +
 configs/transformer_t30_defconfig |  83 
 doc/board/asus/index.rst  |   9 +
 doc/board/asus/transformer_t30.rst|  96 +
 include/configs/transformer-common.h  |  94 +
 include/configs/transformer-t30.h |  46 +++
 28 files changed, 1391 insertions(+)
 create mode 100644 arch/arm/dts/tegra30-asus-p1801-t.dts
 create mode 100644 arch/arm/dts/tegra30-asus-tf201.dts
 create mode 100644 arch/arm/dts/tegra30-asus-tf300t.dts
 create mode 100644 arch/arm/dts/tegra30-asus-tf300tg.dts
 create mode 100644 arch/arm/dts/tegra30-asus-tf300tl.dts
 create mode 100644 arch/arm/dts/tegra30-asus-tf600t.dts
 create mode 100644 arch/arm/dts/tegra30-asus-tf700t.dts
 create mode 100644 arch/arm/dts/tegra30-asus-transformer.dtsi
 create mode 100644 board/asus/transformer-t30/Kconfig
 create mode 100644 board/asus/transformer-t30/MAINTAINERS
 create mode 100644 board/asus/transformer-t30/Makefile
 create mode 100644 board/asus/transformer-t30/pinmux-config-transformer.h
 create mode 100644 board/asus/transformer-t30/transformer-t30-spl.c
 create mode 100644 board/asus/transformer-t30/transformer-t30.c
 create mode 100644 configs/p1801-t.config
 create mode 100644 configs/tf201.config
 create mode 100644 configs/tf300t.config
 create mode 100644 configs/tf300tg.config
 create mode 100644 configs/tf300tl.config
 create mode 100644 configs/tf600t.config
 create mode 100644 configs/tf700t.config
 create mode 100644 configs/transformer_t30_defconfig
 create mode 100644 doc/board/asus/index.rst
 create mode 100644 doc/board/asus/transformer_t30.rst
 create mode 100644 include/configs/transformer-common.h
 create mode 100644 include/configs/transformer-t30.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 3385948d22..aae0568682 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -235,6 +235,13 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
tegra20-ventana.dtb \
tegra20-colibri.dtb \
tegra30-apalis.dtb \
+   tegra30-asus-p1801-t.dtb \
+   tegra30-asus-tf201.dtb \
+   tegra30-asus-tf300t.dtb \
+   tegra30-asus-tf300tg.dtb \
+   tegra30-asus-tf300tl.dtb \
+   tegra30-asus-tf600t.dtb \
+   tegra30-asus-tf700t.dtb \
tegra30-beaver.dtb \
tegra30-cardhu.dtb \
tegra30-colibri.dtb \
diff --git a/arch/arm/dts/tegra30-asus-p1801-t.dts 
b/arch/arm/dts/tegra30-asus-p1801-t.dts
new file mode 100644
index 00..879373a5e8
--- /dev/null
+++ b/arch/arm/dts/tegra30-asus-p1801-t.dts
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+
+#include "tegra30-asus-transformer.dtsi"
+
+/ {
+   model = "ASUS Transformer AiO P1801-T";
+   compatible = "asus,p1801-t", "nvidia,tegra30";
+
+   /delete-node/ host1x@5000;
+
+   /delete-node/ backlight;
+   /delete-node/ panel;
+
+   /delete-node/ regulator-pnl;
+   /delete-node/ regulator

[PATCH v4 6/7] board: lg: x3: add Optimus 4X HD and Optimus Vu support

2023-04-25 Thread Svyatoslav Ryhel
LG X3 is a development board based on Nvidia Tegra 3 SoC
on base of which Optimus 4X HD and Optimus Vu were created.
Both smartphones feature a 4.7" and 5" panels respectively,
an Nvidia Tegra 3 quad-core chip, 1 GB of RAM and 16/32 GB
of internal storage. Optimux 4X HD additionally has a micro
SD slot.

Tested-by: Andreas Westman Dorcsak  # LG P880 T30
Tested-by: Svyatoslav Ryhel  # LG P895 T30
Signed-off-by: Svyatoslav Ryhel 
---
 arch/arm/dts/Makefile   |   2 +
 arch/arm/dts/tegra30-lg-p880.dts|  40 +++
 arch/arm/dts/tegra30-lg-p895.dts|  50 
 arch/arm/dts/tegra30-lg-x3.dtsi | 180 +++
 arch/arm/mach-tegra/tegra30/Kconfig |   5 +
 board/lg/x3-t30/Kconfig |  26 ++
 board/lg/x3-t30/MAINTAINERS |   6 +
 board/lg/x3-t30/Makefile|  11 +
 board/lg/x3-t30/pinmux-config-x3.h  | 449 
 board/lg/x3-t30/x3-t30-spl.c|  48 +++
 board/lg/x3-t30/x3-t30.c| 176 +++
 configs/p880.config |   4 +
 configs/p895.config |   4 +
 configs/x3_t30_defconfig|  86 ++
 doc/board/lg/index.rst  |   9 +
 doc/board/lg/x3_t30.rst |  93 ++
 include/configs/x3-t30.h|  85 ++
 17 files changed, 1274 insertions(+)
 create mode 100644 arch/arm/dts/tegra30-lg-p880.dts
 create mode 100644 arch/arm/dts/tegra30-lg-p895.dts
 create mode 100644 arch/arm/dts/tegra30-lg-x3.dtsi
 create mode 100644 board/lg/x3-t30/Kconfig
 create mode 100644 board/lg/x3-t30/MAINTAINERS
 create mode 100644 board/lg/x3-t30/Makefile
 create mode 100644 board/lg/x3-t30/pinmux-config-x3.h
 create mode 100644 board/lg/x3-t30/x3-t30-spl.c
 create mode 100644 board/lg/x3-t30/x3-t30.c
 create mode 100644 configs/p880.config
 create mode 100644 configs/p895.config
 create mode 100644 configs/x3_t30_defconfig
 create mode 100644 doc/board/lg/index.rst
 create mode 100644 doc/board/lg/x3_t30.rst
 create mode 100644 include/configs/x3-t30.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 4e3367836a..3335e25b73 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -248,6 +248,8 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
tegra30-beaver.dtb \
tegra30-cardhu.dtb \
tegra30-colibri.dtb \
+   tegra30-lg-p880.dtb \
+   tegra30-lg-p895.dtb \
tegra30-tec-ng.dtb \
tegra114-dalmore.dtb \
tegra124-apalis.dtb \
diff --git a/arch/arm/dts/tegra30-lg-p880.dts b/arch/arm/dts/tegra30-lg-p880.dts
new file mode 100644
index 00..81d364310d
--- /dev/null
+++ b/arch/arm/dts/tegra30-lg-p880.dts
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+
+#include "tegra30-lg-x3.dtsi"
+
+/ {
+   model = "LG Optimus 4X HD";
+   compatible = "lge,p880", "nvidia,tegra30";
+
+   aliases {
+   mmc1 = &sdmmc3; /* uSD slot */
+   };
+
+   sdmmc3: sdhci@78000400  {
+   status = "okay";
+   bus-width = <4>;
+
+   cd-gpios = <&gpio TEGRA_GPIO(W, 5) GPIO_ACTIVE_LOW>;
+
+   vmmc-supply = <&vdd_usd>;
+   vqmmc-supply = <&vdd_1v8_vio>;
+   };
+
+   gpio-keys {
+   key-volume-up {
+   label = "Volume Up";
+   gpios = <&gpio TEGRA_GPIO(O, 7) GPIO_ACTIVE_LOW>;
+   linux,code = ;
+   };
+   };
+
+   panel: panel {
+   compatible = "jdi,dx12d100vm0eaa";
+
+   enable-gpios = <&gpio TEGRA_GPIO(Y, 0) GPIO_ACTIVE_HIGH>;
+   reset-gpios = <&gpio TEGRA_GPIO(W, 0) GPIO_ACTIVE_HIGH>;
+
+   backlight = <&backlight>;
+   };
+};
diff --git a/arch/arm/dts/tegra30-lg-p895.dts b/arch/arm/dts/tegra30-lg-p895.dts
new file mode 100644
index 00..074205d5a9
--- /dev/null
+++ b/arch/arm/dts/tegra30-lg-p895.dts
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+
+#include "tegra30-lg-x3.dtsi"
+
+/ {
+   model = "LG Optimus Vu";
+   compatible = "lge,p895", "nvidia,tegra30";
+
+   gpio-keys {
+   key-volume-up {
+   label = "Volume Up";
+   gpios = <&gpio TEGRA_GPIO(I, 6) GPIO_ACTIVE_LOW>;
+   linux,code = ;
+   };
+   };
+
+   panel: panel {
+   compatible = "hitachi,tx13d100vm0eaa";
+
+   reset-gpios = <&gpio TEGRA_GPIO(W, 0) GPIO_ACTIVE_HIGH>;
+
+   renesas,gamma = <3>;
+   renesas,inversion;
+   renesas,contrast;
+
+   vcc-supply = <&vcc_3v0_lcd>;
+   iovcc-supply = <&iovcc_1v8_lcd>;
+
+   backlight = <&backlight>;
+   };
+
+   vcc_3v0_lcd: regulator-lcd {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc_3v0_lcd";
+   regulator-min-microvolt = <300>;
+   regulator-max-microvolt = <300>;
+   

[PATCH v4 7/7] board: htc: endeavoru: add One X support

2023-04-25 Thread Svyatoslav Ryhel
The HTC One X is a touchscreen-based, slate-sized smartphone
designed and manufactured by HTC that runs the Android operating
system. The One X features a 4.7" display, an Nvidia Tegra 3
quad-core chip, 1 GB of RAM and non-extendable 32 GB of internal
storage. UART-A is default debug port.

Tested-by: Andreas Westman Dorcsak 
Tested-by: Ion Agorria 
Tested-by: Svyatoslav Ryhel 
Signed-off-by: Svyatoslav Ryhel 
---
 arch/arm/dts/tegra30-htc-endeavoru.dts| 166 
 arch/arm/mach-tegra/tegra30/Kconfig   |   5 +
 board/htc/endeavoru/Kconfig   |  12 +
 board/htc/endeavoru/MAINTAINERS   |   6 +
 board/htc/endeavoru/Makefile  |  11 +
 board/htc/endeavoru/endeavoru-spl.c   |  47 +++
 board/htc/endeavoru/endeavoru.c   | 116 ++
 board/htc/endeavoru/pinmux-config-endeavoru.h | 362 ++
 configs/endeavoru_defconfig   |  82 
 doc/board/htc/endeavoru.rst   |  90 +
 doc/board/htc/index.rst   |   9 +
 include/configs/endeavoru.h   |  72 
 12 files changed, 978 insertions(+)
 create mode 100644 arch/arm/dts/tegra30-htc-endeavoru.dts
 create mode 100644 board/htc/endeavoru/Kconfig
 create mode 100644 board/htc/endeavoru/MAINTAINERS
 create mode 100644 board/htc/endeavoru/Makefile
 create mode 100644 board/htc/endeavoru/endeavoru-spl.c
 create mode 100644 board/htc/endeavoru/endeavoru.c
 create mode 100644 board/htc/endeavoru/pinmux-config-endeavoru.h
 create mode 100644 configs/endeavoru_defconfig
 create mode 100644 doc/board/htc/endeavoru.rst
 create mode 100644 doc/board/htc/index.rst
 create mode 100644 include/configs/endeavoru.h

diff --git a/arch/arm/dts/tegra30-htc-endeavoru.dts 
b/arch/arm/dts/tegra30-htc-endeavoru.dts
new file mode 100644
index 00..c55e193d1d
--- /dev/null
+++ b/arch/arm/dts/tegra30-htc-endeavoru.dts
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+
+/* This dts file describes the HTC One X smartphone */
+/* CPU Speedo ID 4, Soc Speedo ID 1, CPU Process: 1, Core Process: 0 */
+
+#include 
+
+#include "tegra30.dtsi"
+
+/ {
+   model = "HTC One X";
+   compatible = "htc,endeavoru", "nvidia,tegra30";
+
+   chosen {
+   stdout-path = &uarta;
+   };
+
+   aliases {
+   i2c0 = &pwr_i2c;
+
+   mmc0 = &sdmmc4; /* eMMC */
+
+   rtc0 = &pmic;
+   rtc1 = "/rtc@7000e000";
+
+   usb0 = µ_usb;
+   };
+
+   memory {
+   device_type = "memory";
+   reg = <0x8000 0x4000>;
+   };
+
+   host1x@5000 {
+   dc@5420 {
+   clocks = <&tegra_car TEGRA30_CLK_DISP1>,
+<&tegra_car TEGRA30_CLK_PLL_D_OUT0>;
+
+   rgb {
+   status = "okay";
+
+   nvidia,panel = <&dsia>;
+   };
+   };
+
+   dsia: dsi@5430 {
+   status = "okay";
+
+   avdd-dsi-csi-supply = <&avdd_dsi_csi>;
+
+   panel = <&panel>;
+   };
+   };
+
+   uarta: serial@70006000 {
+   status = "okay";
+   };
+
+   pwr_i2c: i2c@7000d000 {
+   status = "okay";
+   clock-frequency = <10>;
+
+   /* Texas Instruments TPS80032 PMIC */
+   pmic: tps80032@48 {
+   compatible = "ti,tps80032";
+   reg = <0x48>;
+
+   regulators {
+   /* DSI VDD */
+   avdd_dsi_csi: ldo1 {
+   regulator-name = "avdd_dsi_csi";
+   regulator-min-microvolt = <120>;
+   regulator-max-microvolt = <120>;
+   regulator-always-on;
+   };
+   };
+   };
+   };
+
+   sdmmc4: sdhci@78000600 {
+   status = "okay";
+   bus-width = <8>;
+   non-removable;
+   };
+
+   micro_usb: usb@7d00 {
+   status = "okay";
+   dr_mode = "otg";
+   };
+
+   backlight: backlight {
+   compatible = "nvidia,tegra-pwm-backlight";
+
+   nvidia,pwm-source = <1>;
+   nvidia,default-brightness = <0x8E>;
+   };
+
+   /* PMIC has a built-in 32KHz oscillator which is used by PMC */
+   clk32k_in: clock-32k {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <32768>;
+   clock-output-names = "pmic-oscillator";
+   };
+
+   gpio-keys {
+   compatible = "gpio-keys";
+
+   key-power {
+   

[PATCH v4 5/7] board: asus: grouper: add Google Nexus 7 (2012) support

2023-04-25 Thread Svyatoslav Ryhel
Nexus 7 is a mini tablet computer co-developed by Google and Asus
that runs the Android operating system. The Nexus 7 features a 7"
display, an Nvidia Tegra 3 quad-core chip, 1 GB of RAM and 8/16 GB
of internal storage.

This patch brings support for all 3 known ASUS/Google devices:
- Nexus 7 (2012) E1565
- Nexus 7 (2012) PM269
- Nexus 7 (2012) 3G - tilapia

Tested-by: Andreas Westman Dorcsak  # ASUS Grouper E1565
Tested-by: Svyatoslav Ryhel  # ASUS Grouper E1565
Signed-off-by: Svyatoslav Ryhel 
---
 arch/arm/dts/Makefile |   3 +
 arch/arm/dts/tegra30-asus-grouper-common.dtsi | 157 
 .../dts/tegra30-asus-nexus7-grouper-E1565.dts |  43 +++
 .../dts/tegra30-asus-nexus7-grouper-PM269.dts |  36 ++
 .../dts/tegra30-asus-nexus7-tilapia-E1565.dts |  62 +++
 arch/arm/mach-tegra/tegra30/Kconfig   |   5 +
 board/asus/grouper/Kconfig|  22 ++
 board/asus/grouper/MAINTAINERS|   6 +
 board/asus/grouper/Makefile   |  14 +
 board/asus/grouper/grouper-spl-max.c  |  45 +++
 board/asus/grouper/grouper-spl-ti.c   |  41 ++
 board/asus/grouper/grouper.c  | 202 ++
 board/asus/grouper/pinmux-config-grouper.h| 362 ++
 configs/grouper_E1565.config  |   2 +
 configs/grouper_PM269.config  |   2 +
 configs/grouper_common_defconfig  |  82 
 configs/tilapia.config|   3 +
 doc/board/asus/grouper_common.rst |  95 +
 doc/board/asus/index.rst  |   1 +
 include/configs/grouper.h |  68 
 20 files changed, 1251 insertions(+)
 create mode 100644 arch/arm/dts/tegra30-asus-grouper-common.dtsi
 create mode 100644 arch/arm/dts/tegra30-asus-nexus7-grouper-E1565.dts
 create mode 100644 arch/arm/dts/tegra30-asus-nexus7-grouper-PM269.dts
 create mode 100644 arch/arm/dts/tegra30-asus-nexus7-tilapia-E1565.dts
 create mode 100644 board/asus/grouper/Kconfig
 create mode 100644 board/asus/grouper/MAINTAINERS
 create mode 100644 board/asus/grouper/Makefile
 create mode 100644 board/asus/grouper/grouper-spl-max.c
 create mode 100644 board/asus/grouper/grouper-spl-ti.c
 create mode 100644 board/asus/grouper/grouper.c
 create mode 100644 board/asus/grouper/pinmux-config-grouper.h
 create mode 100644 configs/grouper_E1565.config
 create mode 100644 configs/grouper_PM269.config
 create mode 100644 configs/grouper_common_defconfig
 create mode 100644 configs/tilapia.config
 create mode 100644 doc/board/asus/grouper_common.rst
 create mode 100644 include/configs/grouper.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index aae0568682..4e3367836a 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -235,6 +235,9 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
tegra20-ventana.dtb \
tegra20-colibri.dtb \
tegra30-apalis.dtb \
+   tegra30-asus-nexus7-grouper-PM269.dtb \
+   tegra30-asus-nexus7-grouper-E1565.dtb \
+   tegra30-asus-nexus7-tilapia-E1565.dtb \
tegra30-asus-p1801-t.dtb \
tegra30-asus-tf201.dtb \
tegra30-asus-tf300t.dtb \
diff --git a/arch/arm/dts/tegra30-asus-grouper-common.dtsi 
b/arch/arm/dts/tegra30-asus-grouper-common.dtsi
new file mode 100644
index 00..4fa980f24f
--- /dev/null
+++ b/arch/arm/dts/tegra30-asus-grouper-common.dtsi
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+
+#include "tegra30.dtsi"
+
+/ {
+   chosen {
+   stdout-path = &uarta;
+   };
+
+   aliases {
+   i2c0 = &pwr_i2c;
+
+   mmc0 = &sdmmc4; /* eMMC */
+
+   rtc0 = &pmic;
+   rtc1 = "/rtc@7000e000";
+
+   usb0 = &usb1;
+   };
+
+   memory {
+   device_type = "memory";
+   reg = <0x8000 0x4000>;
+   };
+
+   host1x@5000 {
+   dc@5420 {
+   nvidia,180-rotation;
+   rgb {
+   status = "okay";
+
+   nvidia,panel = <&panel>;
+   };
+   };
+   };
+
+   gpio@6000d000 {
+   volume-buttons-hog {
+   gpio-hog;
+   gpios = ,
+   ;
+   output-low;
+   };
+   };
+
+   uarta: serial@70006000 {
+   status = "okay";
+   };
+
+   pwm: pwm@7000a000 {
+   status = "okay";
+   };
+
+   pwr_i2c: i2c@7000d000 {
+   status = "okay";
+   clock-frequency = <40>;
+   };
+
+   sdmmc4: sdhci@78000600 {
+   status = "okay";
+   bus-width = <8>;
+   non-removable;
+   };
+
+   usb1: usb@7d00 {
+   status = "okay";
+   dr_mode = "otg";
+   };
+
+   backlight: backl

[PATCH v2] cosmetic:fix typo in 'mmc write' example

2023-04-25 Thread Alexander Shirokov
In the 'mmc write' command example, it writes 16 blocks (0x10). But the
output contains 256 (0x100) blocks. This patch fixes the mismatch.

Signed-off-by: Alexander Shirokov 
---
 doc/usage/cmd/mmc.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/usage/cmd/mmc.rst b/doc/usage/cmd/mmc.rst
index 55e3f9cf98..2ca1a5cf0c 100644
--- a/doc/usage/cmd/mmc.rst
+++ b/doc/usage/cmd/mmc.rst
@@ -216,7 +216,7 @@ The raw data can be read/written via 'mmc read/write' 
command:
 => mmc read 0x4000 0x5000 0x100
 MMC read: dev # 0, block # 20480, count 256 ... 256 blocks read: OK
 
-=> mmc write 0x4000 0x5000 0x10
+=> mmc write 0x4000 0x5000 100
 MMC write: dev # 0, block # 20480, count 256 ... 256 blocks written: OK
 
 The partition list can be shown via 'mmc part' command:
-- 
2.40.0



Re: [PATCH 00/31] Allow building sandbox with MSYS2

2023-04-25 Thread Heinrich Schuchardt



Am 25. April 2023 01:08:05 MESZ schrieb Simon Glass :
>This expands the existing work to allow sandbox to build and run on
>Windows using MSYS2.

Why do we need this?
Wouldn't a developer on Windows be much better served using WSL 
(https://learn.microsoft.com/en-us/windows/wsl/install)?

Best regards

Heinrich

>
>It also fixes a few issues so that binman can be used.
>
>There are various limitations and some features do not work fully yet. In
>particular, weak functions are not well supported on Windows so these are
>disabled. Various minor compiler-flag and filename adjustments are also
>needed.
>
>This does not support SDL, so U-Boot has no display. This is potentially
>possible, but requires using minggw instead of the base toolchain [1] so
>needs to be dealt with separately.
>
>[1] https://gist.github.com/thales17/fb2e4cff60890a51d94c6e832ad2
>
>
>Simon Glass (31):
>  patman: Declare the future Series memory
>  u_boot_pylib: Correct name of readme
>  u_boot_pylib: Make pty optional
>  binman: Avoid using a symlink
>  binman: Don't require a HOME directory
>  pylibfdt: Allow building on Windows
>  Fix Makefile warning about parallel targets
>  mkimage: Correct checking of configuration node
>  Kbuild: Detect including an MSYS2 path
>  sandbox: Provide a linker script for MSYS2
>  sandbox: Provide an EFI link script for PE
>  sandbox: Drop dead code from Makefile
>  sandbox: Disable raw Ethernet on MSYS2
>  sandbox: Drop signal handling for MSYS2
>  sandbox: Correct SDL.h header inclusion
>  sandbox: Include errno.h in the test header
>  sandbox: Allow weak symbols to be dropped
>  sections: Drop use of linux/types.h
>  sandbox: Drop incorrect inclusion of linux/types.h
>  sandbox: Drop inclusion of os.h in sscanf.c
>  test: Avoid strange symbols in the assembler file
>  sandbox: Fix up setting of monitor_len on MSYS2
>  ctype: Avoid using a symlink
>  build: Disable weak symbols for MSYS2
>  Makefile: Disable unsupported compiler options with PE
>  Makefile: Correct the ans1_compiler rule for MSYS2
>  Makefile: Disable LTO when building with MSYS2
>  doc: Update the MSYS2 packages and versions
>  doc: Show how to build sandbox for MSYS2
>  Makefile: Drop unwind tables
>  CI: Enable sandbox build for Windows
>
> .azure-pipelines.yml  |  27 ++
> Kconfig   |  15 +
> Makefile  |  27 +-
> arch/sandbox/Makefile |   7 -
> arch/sandbox/config.mk|   8 +-
> arch/sandbox/cpu/Makefile |   2 +
> arch/sandbox/cpu/os.c |   3 +-
> arch/sandbox/cpu/sdl.c|   2 +-
> arch/sandbox/cpu/u-boot-pe.lds| 447 ++
> arch/sandbox/include/asm/test.h   |   1 +
> arch/x86/lib/crt0_x86_64_efi.S|   2 +
> arch/x86/lib/pe_x86_64_efi.lds|  83 +
> cmd/bootefi.c |   3 +-
> cmd/bootz.c   |   3 +
> common/board_f.c  |   2 +-
> common/usb.c  |   3 +
> doc/build/gcc.rst |  35 ++
> doc/build/tools.rst   |  20 +-
> drivers/core/root.c   |   3 +
> drivers/net/Makefile  |   2 +
> drivers/spi/sandbox_spi.c |   3 +
> env/env.c |   6 +
> include/asm-generic/sections.h|  16 +-
> include/ctype.h   |   7 +-
> include/linux/compiler_attributes.h   |   4 +
> include/os.h  |   2 -
> include/test/test.h   |   4 +-
> lib/efi_loader/Makefile   |   8 +
> lib/efi_loader/efi_image_loader.c |   3 +
> lib/efi_loader/efi_runtime.c  |   4 +
> lib/lmb.c |   4 +-
> lib/sscanf.c  |   1 -
> lib/time.c|   3 +
> scripts/Kbuild.include|   3 +-
> scripts/Makefile.build|   2 +-
> scripts/Makefile.lib  |   9 +-
> scripts/dtc/pylibfdt/Makefile |  16 +-
> scripts/make_pip.sh   |   9 +-
> tools/Makefile|  14 +-
> tools/binman/binman   |  11 +-
> tools/binman/cmdline.py   |   2 +-
> tools/image-host.c|   4 +-
> tools/patman/commit.py|   3 +
> tools/u_boot_pylib/README.rst |   2 +-
> tools/u_boot_pylib/cros_subprocess.py |  28 +-
> tools/u_boot_pylib/pyproject.toml |   2 +-
> 46 files changed, 803 insertions(+), 62 deletions(-)
> create mode 100644 arch/sandbox/cpu/u-boot-pe.lds
> create mode 100644 arch/x86/lib/pe_x86_64_efi.lds
> mode change 12 => 100644 include/ctype.h
> mode change 12 => 100755 tools/binman/binman
>


Re: [PATCH] doc:fix typo in 'mmc write' example

2023-04-25 Thread Shirokov Alexander
> Hi Shirokov,
>
> On Fri, 21 Apr 2023 at 22:48, Shirokov Alexander
>  wrote:
> >
> > Hello Simon,
> >
> > Thanks for your answer.Using 0x explicitly shows that we are working
> with HEX.
> > But without the prefix, it looks like a decimal number. And it's more
> confusing
> > when the number of blocks looks like a decimal but is interpreted as HEX.
> >
> > Here is an example:
> >
> > mmc write 0x4000 0x5000 16
> > MMC write: dev # 1, block # 20480, count 22 ... 22 blocks written: OK
> >
> > This looks better. If we know that all number is HEX by default
> > mmc write 4000 5000 16
> >
> > Do we have to use something like this?
>
> The convention in U-Boot is to use hex, since it is a bootloader. So
> when you add 0x prefixes it confuses people into thinking that
> otherwise it would be decimal.
>
> BTW we did discuss adding a decimal prefix but they did not get much
> support at the time.
>
> Regards,
> Simon
>
> [1]
> https://patchwork.ozlabs.org/project/uboot/patch/20210720132940.1171011-13-...@chromium.org/
> [2]
> https://patchwork.ozlabs.org/project/uboot/patch/20210724150341.243074-13-...@chromium.org/
>

Thanks a lot, Simon

I prepared the patch without 0x prefix:
http://patchwork.ozlabs.org/project/uboot/patch/20230425100030.22403-1-shirokoval...@gmail.com/

-- 
Regards,
Alexander


Re: Unable to implement board fdt-fixup for imx8m CPU

2023-04-25 Thread Rasmus Villemoes
On 25/04/2023 04.17, Hugo Villeneuve wrote:

> I need to detect at runtime the SOM configuration from an EEPROM, and based 
> on that information adjust the ethernet PHY property inside the device tree.
> 
> I have already done that with success, it works great and as a temporary 
> workaround I simply call my own function imx8m_board_fix_fdt() at the end of 
> the function board_fix_fdt() of arch/arm/mach-imx/imx8m/soc.c.
> 
> But I don't think that a "board" level function should have been put in a 
> SOC/arch source file in arch/arm/mach-imx/imx8m/soc.c in the first place. If 
> it were not for that, there wouldn't be any need to define something new 
> (event or other).
> 
> Maybe we should try to remove that board level function from 
> arch/arm/mach-imx/imx8m/soc.c and use some other already existing mechanism 
> for SOC-level device tree fixups?

AFAICT, you/we can just nuke that function completely.

(1) As you say, it's not appropriate for arch/SOC to provide that in the
first place.
(2) It's completely dead and useless code:
(2a) No in-tree imx8m-based board seems to set CONFIG_OF_BOARD_FIXUP
(2b) The nodes which that function wants to disable don't even exist in
the U-Boot copy of imx8mp.dtsi.

Commit 35bb60787b88 should never have been applied in mainline U-Boot,
it's some random import of code from downstream NXP U-Boot, with a
commit message that makes no sense in upstream context.

Rasmus



[PATCH v3 0/2] Add support to fetch baudrate from dtb

2023-04-25 Thread Venkatesh Yadav Abbarapu
From: Algapally Santosh Sagar 

In this patch series
- Fetch baudrate from the dtb and update
- Add support in Kconfig and convert for armada boards


Changes in v3:
- Moved filler changes from zynqmp.h to generic file env_default.h
- Removed ENV_RW_FILLER and added padding in the generic file env_default.h.
- Print baudrate parameter properly when SERIAL_DT is enabled.
- Add SERIAL_DT_BAUD to Kconfig
- Moved DEFAULT_ENV_IS_RW to Kconfig also updated armada files

Changes in v2:
- Changed to #ifdef from #if CONFIG_IS_ENABLED to enable patching in
spl.
- Added SPL_ENV_SUPPORT dependency in SERIAL_DT_BAUD to allow SPL
compilation.
- Moved DEFAULT_ENV_IS_RW to Kconfig also updated armada files
- Moved ENV_RW_FILLER to generic file env_default.h.
- Increased the ENV_RW_FILLER padding to support 800 baud.

Algapally Santosh Sagar (2):
  serial: zynqmp: Fetch baudrate from dtb and update
  configs: Add support in Kconfig and convert for armada boards

 configs/mvebu_db-88f3720_defconfig  |  1 +
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/mvebu_mcbin-88f8040_defconfig   |  1 +
 drivers/serial/Kconfig  | 16 +
 drivers/serial/serial-uclass.c  | 32 +
 include/configs/mvebu_armada-37xx.h |  1 -
 include/env_default.h   |  7 ++--
 include/env_internal.h  |  2 +-
 include/fdtdec.h|  8 +
 include/serial.h|  1 +
 lib/fdtdec.c| 40 +
 11 files changed, 106 insertions(+), 4 deletions(-)

-- 
2.25.1



[PATCH v3 2/2] configs: Add support in Kconfig and convert for armada boards

2023-04-25 Thread Venkatesh Yadav Abbarapu
From: Algapally Santosh Sagar 

The SERIAL_DT_BAUD is added to Kconfig and the DEFAULT_ENV_IS_RW is moved
to the Kconfig for easier configuration.
Hence, the CONFIG_DEFAULT_ENV_IS_RW config is added to the defconfig files
to allow enabling them for armada boards.

Signed-off-by: Algapally Santosh Sagar 
Signed-off-by: Venkatesh Yadav Abbarapu 
---
 configs/mvebu_db-88f3720_defconfig  |  1 +
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/mvebu_mcbin-88f8040_defconfig   |  1 +
 drivers/serial/Kconfig  | 16 
 include/configs/mvebu_armada-37xx.h |  1 -
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/configs/mvebu_db-88f3720_defconfig 
b/configs/mvebu_db-88f3720_defconfig
index ed0d28fd7d..e3bbaa2173 100644
--- a/configs/mvebu_db-88f3720_defconfig
+++ b/configs/mvebu_db-88f3720_defconfig
@@ -21,6 +21,7 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_ARCH_EARLY_INIT_R=y
 CONFIG_BOARD_EARLY_INIT_F=y
diff --git a/configs/mvebu_espressobin-88f3720_defconfig 
b/configs/mvebu_espressobin-88f3720_defconfig
index ce696787e8..a06eb2dd42 100644
--- a/configs/mvebu_espressobin-88f3720_defconfig
+++ b/configs/mvebu_espressobin-88f3720_defconfig
@@ -22,6 +22,7 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_ARCH_EARLY_INIT_R=y
 CONFIG_BOARD_EARLY_INIT_F=y
diff --git a/configs/mvebu_mcbin-88f8040_defconfig 
b/configs/mvebu_mcbin-88f8040_defconfig
index 058c04333a..4ee5f242f7 100644
--- a/configs/mvebu_mcbin-88f8040_defconfig
+++ b/configs/mvebu_mcbin-88f8040_defconfig
@@ -22,6 +22,7 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_ARCH_EARLY_INIT_R=y
 CONFIG_BOARD_EARLY_INIT_F=y
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 10d07daf27..96cea87f45 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -24,6 +24,22 @@ config BAUDRATE
  in the SPL stage (most drivers) or for choosing a default baudrate
  in the absence of an environment setting (serial_mxc.c).
 
+config SERIAL_DT_BAUD
+   bool "Fetch serial baudrate from device tree"
+   depends on DM_SERIAL && SPL_ENV_SUPPORT
+   select DEFAULT_ENV_IS_RW
+   help
+ Select this to enable fetching and setting of the baudrate
+ configured in the DT. Replace the default baudrate with the DT
+ baudrate and also set it to the environment.
+
+config DEFAULT_ENV_IS_RW
+   bool "Make default environment as writable"
+   depends on DM_SERIAL
+   help
+ Select this to enable to make default environment writable. This
+ allows modifying the default environment.
+
 config REQUIRE_SERIAL_CONSOLE
bool "Require a serial port for console"
# Running without a serial console is not supported by the
diff --git a/include/configs/mvebu_armada-37xx.h 
b/include/configs/mvebu_armada-37xx.h
index 76e148f55e..18b55be0d8 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -30,7 +30,6 @@
 /*
  * Environment
  */
-#define DEFAULT_ENV_IS_RW  /* required for configuring default 
fdtfile= */
 
 #ifdef CONFIG_MMC
 #define BOOT_TARGET_DEVICES_MMC(func, i) func(MMC, mmc, i)
-- 
2.17.1



[PATCH v3 1/2] serial: zynqmp: Fetch baudrate from dtb and update

2023-04-25 Thread Venkatesh Yadav Abbarapu
From: Algapally Santosh Sagar 

The baudrate configured in .config is taken by default by serial. If
change of baudrate is required then the .config needs to changed and
u-boot recompilation is required or the u-boot environment needs to be
updated.

To avoid this, support is added to fetch the baudrate directly from the
device tree file and update.
The serial, prints the log with the configured baudrate in the dtb.
The commit c4df0f6f315c ("arm: mvebu: Espressobin: Set default value for
$fdtfile env variable") is taken as reference for changing the default
environment variable.

The default environment stores the default baudrate value, When default
baudrate and dtb baudrate are not same glitches are seen on the serial.
So, the environment also needs to be updated with the dtb baudrate to
avoid the glitches on the serial.

Signed-off-by: Algapally Santosh Sagar 
Signed-off-by: Venkatesh Yadav Abbarapu 
---
 drivers/serial/serial-uclass.c | 32 +++
 include/env_default.h  |  7 --
 include/env_internal.h |  2 +-
 include/fdtdec.h   |  8 +++
 include/serial.h   |  1 +
 lib/fdtdec.c   | 40 ++
 6 files changed, 87 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 067fae2614..d77d3bda36 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -154,12 +154,44 @@ static void serial_find_console_or_panic(void)
 }
 #endif /* CONFIG_SERIAL_PRESENT */
 
+#ifdef CONFIG_SERIAL_DT_BAUD
+int serial_get_valid_baudrate(int baud)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) {
+   if (baud == baudrate_table[i])
+   return 0;
+   }
+
+   return -EINVAL;
+}
+#endif
+
 /* Called prior to relocation */
 int serial_init(void)
 {
 #if CONFIG_IS_ENABLED(SERIAL_PRESENT)
serial_find_console_or_panic();
gd->flags |= GD_FLG_SERIAL_READY;
+#ifdef CONFIG_SERIAL_DT_BAUD
+   int ret = 0;
+   char *ptr = &default_environment[0];
+
+   /*
+* Fetch the baudrate from the dtb and update the value in the
+* default environment.
+*/
+   ret = fdtdec_get_baud_from_dtb(gd->fdt_blob);
+   if (ret != -EINVAL && ret != -EFAULT) {
+   gd->baudrate = ret;
+
+   while (*ptr != '\0' && *(ptr + 1) != '\0')
+   ptr++;
+   ptr += 2;
+   sprintf(ptr, "baudrate=%d", gd->baudrate);
+   }
+#endif
serial_setbrg();
 #endif
 
diff --git a/include/env_default.h b/include/env_default.h
index c0df39d62f..4f286ffc9e 100644
--- a/include/env_default.h
+++ b/include/env_default.h
@@ -23,7 +23,7 @@ env_t embedded_environment __UBOOT_ENV_SECTION__(environment) 
= {
{
 #elif defined(DEFAULT_ENV_INSTANCE_STATIC)
 static char default_environment[] = {
-#elif defined(DEFAULT_ENV_IS_RW)
+#elif defined(CONFIG_DEFAULT_ENV_IS_RW)
 char default_environment[] = {
 #else
 const char default_environment[] = {
@@ -44,7 +44,7 @@ const char default_environment[] = {
 #if defined(CONFIG_BOOTDELAY)
"bootdelay="__stringify(CONFIG_BOOTDELAY)   "\0"
 #endif
-#if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
+#if !defined(CONFIG_SERIAL_DT_BAUD) && defined(CONFIG_BAUDRATE) && 
(CONFIG_BAUDRATE >= 0)
"baudrate=" __stringify(CONFIG_BAUDRATE)"\0"
 #endif
 #ifdef CONFIG_LOADS_ECHO
@@ -120,6 +120,9 @@ const char default_environment[] = {
 #endif
 #ifdef CFG_EXTRA_ENV_SETTINGS
CFG_EXTRA_ENV_SETTINGS
+#endif
+#ifdef CONFIG_SERIAL_DT_BAUD
+   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
 #endif
"\0"
 #else /* CONFIG_USE_DEFAULT_ENV_FILE */
diff --git a/include/env_internal.h b/include/env_internal.h
index 6a69494646..fcb464263f 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -89,7 +89,7 @@ typedef struct environment_s {
 extern env_t embedded_environment;
 #endif /* ENV_IS_EMBEDDED */
 
-#ifdef DEFAULT_ENV_IS_RW
+#ifdef CONFIG_DEFAULT_ENV_IS_RW
 extern char default_environment[];
 #else
 extern const char default_environment[];
diff --git a/include/fdtdec.h b/include/fdtdec.h
index aa61a0fca1..48937a7a46 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -657,6 +657,14 @@ int fdtdec_get_alias_seq(const void *blob, const char 
*base, int node,
  */
 int fdtdec_get_alias_highest_id(const void *blob, const char *base);
 
+/**
+ * Get baudrate from the dtb
+ *
+ * @param blob Device tree blob (if NULL, then error is returned)
+ * @return Baud rate value, or -ve error .
+ */
+int fdtdec_get_baud_from_dtb(const void *blob);
+
 /**
  * Get a property from the /chosen node
  *
diff --git a/include/serial.h b/include/serial.h
index 42bdf3759c..48834b517c 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -337,6 +337,7 @@ int serial_setconfig(struct udevice *dev, uint config);
  */
 int serial_getinfo(struct 

Re: [PATCH v3] console: usb: kbd: Limit poll frequency to improve performance

2023-04-25 Thread Filip Žaludek




Hi Simon,


On 4/19/23 03:49, Simon Glass wrote:

Hi Filip,

On Tue, 11 Apr 2023 at 14:24, Filip Žaludek  wrote:




On 2/8/23 20:01, Mark Kettenis wrote:

Date: Wed, 8 Feb 2023 19:45:36 +0100
From: Michal Suchánek 

Hello,

On Wed, Jan 18, 2023 at 05:01:12PM +0100, Filip Žaludek wrote:



Hi Michal,

   thanks for testing! Do you consider keyboard as working once it is detected 
without
'usb_kbd usb_kbd: Timeout poll on interrupt endpoint', or judging from 
subsequent
typing? Note that issue is reproducible only in about 20% of reboots.


I rely on keyboard input to boot so if it was 20% broken I would notice.
I don't use the rPi all that much so if it was broken only a few
% of the time there is a chance I would miss it.

However, for me not typing on the keyboard during usb detection it is
100% not detected, typing on it during usb detection it is 100%
detected.

The timeout is limitation of the dwc2 controller handling of usb hubs.

There might be a possibility to improve the driver so that it handles
the condition but it might be that the Linux driver relies on a separate
thread handling the controller which is not acceptable for u-boot.

I am not usb expert and definitely not dwc2 expert so I cannot do more
than workaround the current driver limitation.


For me I can always enter 'U-Boot>' shell, but then keyboard usually does not 
work.
And yes, resetting the usb controller with pressing a key afterwards will
finally break the keyboard. ('usb reset' typed from keyboard)
If you are Prague located I am ready to demonstrate what I am talking about.

   Simon's keyboard detection is somewhat interfered by 'SanDisk USB Extreme 
Pro' detection,
printed complaints but keyboard still works..
'usb_kbd usb_kbd: Timeout poll on interrupt endpoint' and 'Failed to get 
keyboard state from device 0c40:8000'
Btw. why from 0c40:8000 (ELMCU 2.4GHz receiver) when wired keyboard is 
046d:c31c (Logitech Keyboard K120)?

   What is supposed scenario for RPi3/u-boot/grub usb keyboard equipped users 
wanting to boot non-default?
Enter 'U-Boot>' shell to detect keyboard; type boot; select desired grub 
entry..?

Reverting either from the two makes it non issue for me:
'dwc2: use the nonblock argument in submit_int_msg'
commit 9dcab2c4d2cb50ab1864c818b82a72393c160236


Without this booting from USB is not feasible because reading every
block from the USB drive waits for the keyboard to time out.


'console: usb: kbd: Limit poll frequency to improve performance'
commit 96991e652f541323a03c5b7e075d54a117091618


No idea about this one, for me it doea not give any substantial
difference in behavior.


Reverting that commit leads to a significant slowdown loading a kernel
from disk with a usb keyboard connected.  The slowdown is somewhat
hardware dependent but on some systems loading the OpenBSD/arm64
kernel would take minutes instead of seconds.



Hello,
I am about to dig more into this issue with proper tools, but failed to
configure/compile trace functionality on RPi3 due to missing references
to timer_early_get_count() and timer_early_get_rate().


You could implement a proper timer driver for rpi.



   Is it possible/feasible to implement calls in CONFIG_SYS_ARCH_TIMER
and/or CONFIG_SP804_TIMER?


Yes



 I am little bit missing here secret sauce, timer_early_get_count() and 
timer_early_get_rate()
are not supposed to be implemented in arch/arm/cpu/armv8/generic_timer.c? But 
predestined for
drivers/timer/sp804_timer.c?

TIMER is required for common/board_f.c and common/board_r.c but it disables 
generic_timer..
%< -
ifndef CONFIG_$(SPL_TPL_)TIMER
obj-$(CONFIG_SYS_ARCH_TIMER) += generic_timer.o
endif
%< -
And obviously multiple definition of get_tbclk and get_ticks when forced to 
compile/link.






   I would be grateful even for trace to generate function traces without
timestamps. Is such nasty hack without timestamping supposed to work?
Basically my intention is to trace 'usb reset'.

Appreciate any hints/outlines how to proceed.


I assume you mean CONFIG_TRACE. Yes, you could update it to support
writing a zero timestamp. See the add_ftrace() function.

But better to add a driver if you can. It should not be difficult.

Regards,
Simon


 I am already happily timestamp tracing with borrowed functionality from 
generic_timer.c,
albeit bypassing kbuild mechanism. It did not yet answered my usb polling 
questions,
tracing report is polluted/overfilled.



Instrumenting code thoughts:
* It would be handy to -finstrument-functions only for desired objects.
* It would be handy to have macro inverse to 'notrace' to mark only desired 
functions. Feasible?
* gcc -finstrument-functions-exclude-file-list still pollutes tracing buffer.

More Tracing in U-Boot thoughts:
* There is proftool options discrepancy, documented {-c, -f, -m, -o, -t, -v}, 
implemented {-m, -p, -t, -v}.
* Both types FUNCF_ENTRY and FUNCF_EXIT are marked as " <- " by 

[PATCH 1/2] net: rtl8169: add minimal support for 8125B variant

2023-04-25 Thread Eugen Hristev
Add minimal support for 8125B version.
Changes are based on the Linux driver.
Tested on Radxa Rock 5B Rk3588 board.

Connection to a laptop worked fine in 100 Mbps mode.
1000 Mbps mode is not working at the moment.

Signed-off-by: Eugen Hristev 
---
 drivers/net/rtl8169.c | 52 ++-
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index c9c07a5a8ffe..2276a465e787 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -118,9 +118,9 @@ enum RTL8169_registers {
FLASH = 0x30,
ERSR = 0x36,
ChipCmd = 0x37,
-   TxPoll = 0x38,
-   IntrMask = 0x3C,
-   IntrStatus = 0x3E,
+   TxPoll_8169 = 0x38,
+   IntrMask_8169 = 0x3C,
+   IntrStatus_8169 = 0x3E,
TxConfig = 0x40,
RxConfig = 0x44,
RxMissed = 0x4C,
@@ -148,6 +148,12 @@ enum RTL8169_registers {
FuncForceEvent = 0xFC,
 };
 
+enum RTL8125_registers {
+   IntrMask_8125 = 0x38,
+   IntrStatus_8125 = 0x3C,
+   TxPoll_8125 = 0x90,
+};
+
 enum RTL8169_register_content {
/*InterruptStatusBits */
SYSErr = 0x8000,
@@ -263,6 +269,7 @@ static struct {
{"RTL-8101e",   0x34, 0xff7e1880,},
{"RTL-8100e",   0x32, 0xff7e1880,},
{"RTL-8168h/8111h", 0x54, 0xff7e1880,},
+   {"RTL-8125B",   0x64, 0xff7e1880,},
 };
 
 enum _DescStatusBit {
@@ -347,6 +354,7 @@ static struct pci_device_id supported[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169) },
+   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) },
{}
 };
 
@@ -517,6 +525,7 @@ static int rtl_recv_common(struct udevice *dev, unsigned 
long dev_iobase,
/* return true if there's an ethernet packet ready to read */
/* nic->packet should contain data on return */
/* nic->packetlen should contain length of data */
+   struct pci_child_plat *pplat = dev_get_parent_plat(dev);
int cur_rx;
int length = 0;
 
@@ -558,6 +567,10 @@ static int rtl_recv_common(struct udevice *dev, unsigned 
long dev_iobase,
return length;
 
} else {
+   u32 IntrStatus = IntrStatus_8169;
+
+   if (pplat->device == 0x8125)
+   IntrStatus = IntrStatus_8125;
ushort sts = RTL_R8(IntrStatus);
RTL_W8(IntrStatus, sts & ~(TxErr | RxErr | SYSErr));
udelay(100);/* wait */
@@ -582,6 +595,7 @@ static int rtl_send_common(struct udevice *dev, unsigned 
long dev_iobase,
 {
/* send the packet to destination */
 
+   struct pci_child_plat *pplat = dev_get_parent_plat(dev);
u32 to;
u8 *ptxb;
int entry = tpc->cur_tx % NUM_TX_DESC;
@@ -618,7 +632,10 @@ static int rtl_send_common(struct udevice *dev, unsigned 
long dev_iobase,
((len > ETH_ZLEN) ? len : ETH_ZLEN));
}
rtl_flush_tx_desc(&tpc->TxDescArray[entry]);
-   RTL_W8(TxPoll, 0x40);   /* set polling bit */
+   if (pplat->device == 0x8125)
+   RTL_W8(TxPoll_8125, 0x1);   /* set polling bit */
+   else
+   RTL_W8(TxPoll_8169, 0x40);  /* set polling bit */
 
tpc->cur_tx++;
to = currticks() + TX_TIMEOUT;
@@ -824,21 +841,26 @@ static int rtl8169_eth_start(struct udevice *dev)
return 0;
 }
 
-static void rtl_halt_common(unsigned long dev_iobase)
+static void rtl_halt_common(struct udevice *dev)
 {
+   struct rtl8169_private *priv = dev_get_priv(dev);
+   struct pci_child_plat *pplat = dev_get_parent_plat(dev);
int i;
 
 #ifdef DEBUG_RTL8169
printf ("%s\n", __FUNCTION__);
 #endif
 
-   ioaddr = dev_iobase;
+   ioaddr = priv->iobase;
 
/* Stop the chip's Tx and Rx DMA processes. */
RTL_W8(ChipCmd, 0x00);
 
/* Disable interrupts by clearing the interrupt mask. */
-   RTL_W16(IntrMask, 0x);
+   if (pplat->device == 0x8125)
+   RTL_W16(IntrMask_8125, 0x);
+   else
+   RTL_W16(IntrMask_8169, 0x);
 
RTL_W32(RxMissed, 0);
 
@@ -849,9 +871,7 @@ static void rtl_halt_common(unsigned long dev_iobase)
 
 void rtl8169_eth_stop(struct udevice *dev)
 {
-   struct rtl8169_private *priv = dev_get_priv(dev);
-
-   rtl_halt_common(priv->iobase);
+   rtl_halt_common(dev);
 }
 
 static int rtl8169_write_hwaddr(struct udevice *dev)
@@ -1025,23 +1045,25 @@ static int rtl8169_eth_probe(struct udevice *dev)
struct pci_child_plat *pplat = dev_get_parent_plat(dev);
struct rtl8169_private *priv = dev_get_priv(dev);
struct eth_pdata *plat = dev_get_plat(dev);
-   u32 iobase;
int region;
int ret;
 
-   debug("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
switch (pplat->device) {
case

[PATCH 2/2] configs: rock5b-rk3588: add rtl8169 driver

2023-04-25 Thread Eugen Hristev
Add the rtl8169 driver, which supports the rtl8125b device, which is
connected on the pciE bus on this board.
Enable also CONFIG_SYS_HAS_NONCACHED_MEMORY to have the descriptors stored.

Signed-off-by: Eugen Hristev 
---
 configs/rock5b-rk3588_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/rock5b-rk3588_defconfig b/configs/rock5b-rk3588_defconfig
index a14fcd2ee924..bfa48227aee2 100644
--- a/configs/rock5b-rk3588_defconfig
+++ b/configs/rock5b-rk3588_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
+CONFIG_SYS_HAS_NONCACHED_MEMORY=y
 CONFIG_COUNTER_FREQUENCY=2400
 CONFIG_ARCH_ROCKCHIP=y
 CONFIG_TEXT_BASE=0x00a0
@@ -71,6 +72,7 @@ CONFIG_MMC_SDHCI_SDMA=y
 CONFIG_MMC_SDHCI_ROCKCHIP=y
 CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_ETH_DESIGNWARE=y
+CONFIG_RTL8169=y
 CONFIG_GMAC_ROCKCHIP=y
 CONFIG_PCI=y
 CONFIG_PCIE_DW_ROCKCHIP=y
-- 
2.34.1



[PATCH 0/2] Update DDR configs to latest tested version

2023-04-25 Thread Neha Malcom Francis
This series aims to update the DDR dtsi files that are generated by the
Jacinto 7 DDRSS Configuration tool. 

It updates J721E and J7200 to generated files of two different versions
of the same tool as these are the latest ones that have been thoroughly
tested with U-Boot on each device internally. Thus it is best to update to
that version for each instead of: A. sticking with the current old version
or B. updating to the very latest version that hasn't been tested on
U-Boot.

Neha Malcom Francis (2):
  arm: dts: k3-j721e: ddr: Update to 0.9.1 version of DDR config tool
  arm: dts: k3-j7200: ddr: Update to 0.6 version of DDR config tool

 arch/arm/dts/k3-j7200-ddr-evm-lp4-2666.dtsi | 120 
 arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi | 149 ++--
 2 files changed, 135 insertions(+), 134 deletions(-)

-- 
2.34.1



[PATCH 1/2] arm: dts: k3-j721e: ddr: Update to 0.9.1 version of DDR config tool

2023-04-25 Thread Neha Malcom Francis
Update the DDR settings to those generated using 0.9.1 version of
Jacinto 7 DDRSS Register Configuration tool.

Signed-off-by: Neha Malcom Francis 
---
 arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi | 149 ++--
 1 file changed, 75 insertions(+), 74 deletions(-)

diff --git a/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi 
b/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi
index ca05e06e93..5a6f9b11b8 100644
--- a/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi
+++ b/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
- * This file was generated by the Jacinto7_DDRSS_RegConfigTool, Revision: 0.5.0
- * This file was generated on 09/25/2020
+ * This file was generated by the Jacinto7_DDRSS_RegConfigTool, Revision: 0.9.1
+ * This file was generated on 07/17/2022
 */
 
 #define DDRSS_PLL_FHS_CNT 10
+#define DDRSS_PLL_FREQUENCY_0 2750
 #define DDRSS_PLL_FREQUENCY_1 106650
 #define DDRSS_PLL_FREQUENCY_2 106650
 
@@ -16,10 +17,10 @@
 #define DDRSS_CTL_04_DATA 0x
 #define DDRSS_CTL_05_DATA 0x
 #define DDRSS_CTL_06_DATA 0x
-#define DDRSS_CTL_07_DATA 0x2710
-#define DDRSS_CTL_08_DATA 0x000186A0
+#define DDRSS_CTL_07_DATA 0x2AF8
+#define DDRSS_CTL_08_DATA 0x0001ADAF
 #define DDRSS_CTL_09_DATA 0x0005
-#define DDRSS_CTL_10_DATA 0x0064
+#define DDRSS_CTL_10_DATA 0x006E
 #define DDRSS_CTL_11_DATA 0x000681C8
 #define DDRSS_CTL_12_DATA 0x004111C9
 #define DDRSS_CTL_13_DATA 0x0005
@@ -32,11 +33,11 @@
 #define DDRSS_CTL_20_DATA 0x02011001
 #define DDRSS_CTL_21_DATA 0x0201
 #define DDRSS_CTL_22_DATA 0x00020100
-#define DDRSS_CTL_23_DATA 0x000A
-#define DDRSS_CTL_24_DATA 0x0019
+#define DDRSS_CTL_23_DATA 0x000B
+#define DDRSS_CTL_24_DATA 0x001C
 #define DDRSS_CTL_25_DATA 0x
 #define DDRSS_CTL_26_DATA 0x
-#define DDRSS_CTL_27_DATA 0x02020200
+#define DDRSS_CTL_27_DATA 0x03020200
 #define DDRSS_CTL_28_DATA 0x5656
 #define DDRSS_CTL_29_DATA 0x0010
 #define DDRSS_CTL_30_DATA 0x
@@ -53,7 +54,7 @@
 #define DDRSS_CTL_41_DATA 0x1B60008B
 #define DDRSS_CTL_42_DATA 0x2000422B
 #define DDRSS_CTL_43_DATA 0x000A0A09
-#define DDRSS_CTL_44_DATA 0x040006DB
+#define DDRSS_CTL_44_DATA 0x0400078A
 #define DDRSS_CTL_45_DATA 0x1E161104
 #define DDRSS_CTL_46_DATA 0x10012458
 #define DDRSS_CTL_47_DATA 0x1E161110
@@ -61,7 +62,7 @@
 #define DDRSS_CTL_49_DATA 0x02030410
 #define DDRSS_CTL_50_DATA 0x2C040500
 #define DDRSS_CTL_51_DATA 0x082D2C2D
-#define DDRSS_CTL_52_DATA 0x14000D0A
+#define DDRSS_CTL_52_DATA 0x14000E0A
 #define DDRSS_CTL_53_DATA 0x04010A0A
 #define DDRSS_CTL_54_DATA 0x01010004
 #define DDRSS_CTL_55_DATA 0x04585808
@@ -69,15 +70,15 @@
 #define DDRSS_CTL_57_DATA 0x3131
 #define DDRSS_CTL_58_DATA 0x00010100
 #define DDRSS_CTL_59_DATA 0x0301
-#define DDRSS_CTL_60_DATA 0x0E08
-#define DDRSS_CTL_61_DATA 0x00BB
+#define DDRSS_CTL_60_DATA 0x1008
+#define DDRSS_CTL_61_DATA 0x00CE
 #define DDRSS_CTL_62_DATA 0x0256
 #define DDRSS_CTL_63_DATA 0x2073
 #define DDRSS_CTL_64_DATA 0x0256
 #define DDRSS_CTL_65_DATA 0x2073
 #define DDRSS_CTL_66_DATA 0x0005
-#define DDRSS_CTL_67_DATA 0x0003
-#define DDRSS_CTL_68_DATA 0x00950010
+#define DDRSS_CTL_67_DATA 0x0004
+#define DDRSS_CTL_68_DATA 0x00950012
 #define DDRSS_CTL_69_DATA 0x00950408
 #define DDRSS_CTL_70_DATA 0x00400408
 #define DDRSS_CTL_71_DATA 0x00120103
@@ -88,7 +89,7 @@
 #define DDRSS_CTL_76_DATA 0x041E100B
 #define DDRSS_CTL_77_DATA 0x100B0401
 #define DDRSS_CTL_78_DATA 0x0001041E
-#define DDRSS_CTL_79_DATA 0x000F000F
+#define DDRSS_CTL_79_DATA 0x00100010
 #define DDRSS_CTL_80_DATA 0x02660266
 #define DDRSS_CTL_81_DATA 0x02660266
 #define DDRSS_CTL_82_DATA 0x03050505
@@ -111,13 +112,13 @@
 #define DDRSS_CTL_99_DATA 0x
 #define DDRSS_CTL_100_DATA 0x00040005
 #define DDRSS_CTL_101_DATA 0x
-#define DDRSS_CTL_102_DATA 0x2EC0
-#define DDRSS_CTL_103_DATA 0x2EC0
-#define DDRSS_CTL_104_DATA 0x2EC0
-#define DDRSS_CTL_105_DATA 0x2EC0
-#define DDRSS_CTL_106_DATA 0x2EC0
+#define DDRSS_CTL_102_DATA 0x3380
+#define DDRSS_CTL_103_DATA 0x3380
+#define DDRSS_CTL_104_DATA 0x3380
+#define DDRSS_CTL_105_DATA 0x3380
+#define DDRSS_CTL_106_DATA 0x3380
 #define DDRSS_CTL_107_DATA 0x
-#define DDRSS_CTL_108_DATA 0x051D
+#define DDRSS_CTL_108_DATA 0x05A2
 #define DDRSS_CTL_109_DATA 0x00081CC0
 #define DDRSS_CTL_110_DATA 0x00081CC0
 #define DDRSS_CTL_111_DATA 0x00081CC0
@@ -173,9 +174,9 @@
 #define DDRSS_CTL_161_DATA 0x
 #define DDRSS_CTL_162_DATA 0x
 #define DDRSS_CTL_163_DATA 0x
-#define DDRSS_CTL_164_DATA 0x000A
-#define DDRSS_CTL_165_DATA 0x000D0005
-#define DDRSS_CTL_166_DATA 0x000D0404
+#define DDRSS_CTL_164_DATA 0x000B
+#define DDRSS_CTL_165_DATA 0x000E0006
+#define DDRSS_CTL_166_DATA 0x000E0404
 #define DDRSS_CTL_167_DATA 0x00D

[PATCH 2/2] arm: dts: k3-j7200: ddr: Update to 0.6 version of DDR config tool

2023-04-25 Thread Neha Malcom Francis
Update the DDR settings to those generated using 0.6 version of
Jacinto 7 DDRSS Register Configuration tool.

Signed-off-by: Neha Malcom Francis 
---
 arch/arm/dts/k3-j7200-ddr-evm-lp4-2666.dtsi | 120 ++--
 1 file changed, 60 insertions(+), 60 deletions(-)

diff --git a/arch/arm/dts/k3-j7200-ddr-evm-lp4-2666.dtsi 
b/arch/arm/dts/k3-j7200-ddr-evm-lp4-2666.dtsi
index 42ac8c5c89..9ec8dff44b 100644
--- a/arch/arm/dts/k3-j7200-ddr-evm-lp4-2666.dtsi
+++ b/arch/arm/dts/k3-j7200-ddr-evm-lp4-2666.dtsi
@@ -1,12 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
- * This file was generated by the Jacinto7_DDRSS_RegConfigTool, Revision: 0.5.0
- * This file was generated on 08/07/2020
- * Includes hand-edits
- */
+ * This file was generated by the Jacinto7_DDRSS_RegConfigTool, Revision: 0.6.0
+ * This file was generated on 06/01/2021
+*/
 
 #define DDRSS_PLL_FHS_CNT 10
+#define DDRSS_PLL_FREQUENCY_0 2750
 #define DDRSS_PLL_FREQUENCY_1 66650
 #define DDRSS_PLL_FREQUENCY_2 66650
 
@@ -17,10 +17,10 @@
 #define DDRSS_CTL_04_DATA 0x
 #define DDRSS_CTL_05_DATA 0x
 #define DDRSS_CTL_06_DATA 0x
-#define DDRSS_CTL_07_DATA 0x2710
-#define DDRSS_CTL_08_DATA 0x000186A0
+#define DDRSS_CTL_07_DATA 0x2AF8
+#define DDRSS_CTL_08_DATA 0x0001ADAF
 #define DDRSS_CTL_09_DATA 0x0005
-#define DDRSS_CTL_10_DATA 0x0064
+#define DDRSS_CTL_10_DATA 0x006E
 #define DDRSS_CTL_11_DATA 0x000411AB
 #define DDRSS_CTL_12_DATA 0x0028B0AB
 #define DDRSS_CTL_13_DATA 0x0005
@@ -33,11 +33,11 @@
 #define DDRSS_CTL_20_DATA 0x02011001
 #define DDRSS_CTL_21_DATA 0x0201
 #define DDRSS_CTL_22_DATA 0x00020100
-#define DDRSS_CTL_23_DATA 0x000A
-#define DDRSS_CTL_24_DATA 0x0019
+#define DDRSS_CTL_23_DATA 0x000B
+#define DDRSS_CTL_24_DATA 0x001C
 #define DDRSS_CTL_25_DATA 0x
 #define DDRSS_CTL_26_DATA 0x
-#define DDRSS_CTL_27_DATA 0x02020200
+#define DDRSS_CTL_27_DATA 0x03020200
 #define DDRSS_CTL_28_DATA 0x3636
 #define DDRSS_CTL_29_DATA 0x0010
 #define DDRSS_CTL_30_DATA 0x
@@ -54,7 +54,7 @@
 #define DDRSS_CTL_41_DATA 0x113C0057
 #define DDRSS_CTL_42_DATA 0x2000291B
 #define DDRSS_CTL_43_DATA 0x000A0A09
-#define DDRSS_CTL_44_DATA 0x040006DB
+#define DDRSS_CTL_44_DATA 0x0400078A
 #define DDRSS_CTL_45_DATA 0x130E0B04
 #define DDRSS_CTL_46_DATA 0x0A00B6D0
 #define DDRSS_CTL_47_DATA 0x130E0B0A
@@ -62,7 +62,7 @@
 #define DDRSS_CTL_49_DATA 0x0203040A
 #define DDRSS_CTL_50_DATA 0x1C040500
 #define DDRSS_CTL_51_DATA 0x081D1C1D
-#define DDRSS_CTL_52_DATA 0x14000D0A
+#define DDRSS_CTL_52_DATA 0x14000E0A
 #define DDRSS_CTL_53_DATA 0x02010A0A
 #define DDRSS_CTL_54_DATA 0x01010002
 #define DDRSS_CTL_55_DATA 0x04383808
@@ -70,15 +70,15 @@
 #define DDRSS_CTL_57_DATA 0x1F1F
 #define DDRSS_CTL_58_DATA 0x00010100
 #define DDRSS_CTL_59_DATA 0x0301
-#define DDRSS_CTL_60_DATA 0x0E08
-#define DDRSS_CTL_61_DATA 0x00BB
+#define DDRSS_CTL_60_DATA 0x1008
+#define DDRSS_CTL_61_DATA 0x00CE
 #define DDRSS_CTL_62_DATA 0x0176
 #define DDRSS_CTL_63_DATA 0x1448
 #define DDRSS_CTL_64_DATA 0x0176
 #define DDRSS_CTL_65_DATA 0x1448
 #define DDRSS_CTL_66_DATA 0x0005
-#define DDRSS_CTL_67_DATA 0x0003
-#define DDRSS_CTL_68_DATA 0x005D0010
+#define DDRSS_CTL_67_DATA 0x0004
+#define DDRSS_CTL_68_DATA 0x005D0012
 #define DDRSS_CTL_69_DATA 0x005D0282
 #define DDRSS_CTL_70_DATA 0x00400282
 #define DDRSS_CTL_71_DATA 0x00120103
@@ -89,7 +89,7 @@
 #define DDRSS_CTL_76_DATA 0x03130A07
 #define DDRSS_CTL_77_DATA 0x0A070301
 #define DDRSS_CTL_78_DATA 0x00010313
-#define DDRSS_CTL_79_DATA 0x000F000F
+#define DDRSS_CTL_79_DATA 0x00100010
 #define DDRSS_CTL_80_DATA 0x01800180
 #define DDRSS_CTL_81_DATA 0x01800180
 #define DDRSS_CTL_82_DATA 0x03050505
@@ -112,13 +112,13 @@
 #define DDRSS_CTL_99_DATA 0x
 #define DDRSS_CTL_100_DATA 0x00040005
 #define DDRSS_CTL_101_DATA 0x
-#define DDRSS_CTL_102_DATA 0x2EC0
-#define DDRSS_CTL_103_DATA 0x2EC0
-#define DDRSS_CTL_104_DATA 0x2EC0
-#define DDRSS_CTL_105_DATA 0x2EC0
-#define DDRSS_CTL_106_DATA 0x2EC0
+#define DDRSS_CTL_102_DATA 0x3380
+#define DDRSS_CTL_103_DATA 0x3380
+#define DDRSS_CTL_104_DATA 0x3380
+#define DDRSS_CTL_105_DATA 0x3380
+#define DDRSS_CTL_106_DATA 0x3380
 #define DDRSS_CTL_107_DATA 0x
-#define DDRSS_CTL_108_DATA 0x051D
+#define DDRSS_CTL_108_DATA 0x05A2
 #define DDRSS_CTL_109_DATA 0x00051200
 #define DDRSS_CTL_110_DATA 0x00051200
 #define DDRSS_CTL_111_DATA 0x00051200
@@ -174,9 +174,9 @@
 #define DDRSS_CTL_161_DATA 0x
 #define DDRSS_CTL_162_DATA 0x
 #define DDRSS_CTL_163_DATA 0x
-#define DDRSS_CTL_164_DATA 0x000A
-#define DDRSS_CTL_165_DATA 0x000D0005
-#define DDRSS_CTL_166_DATA 0x000D0404
+#define DDRSS_CTL_164_DATA 0x000B
+#define DDRSS_CTL_165_DATA 0x000E0006
+#define DDRSS_CTL_166_DATA 0x000E0404
 #define

Re: [PATCH v3 2/2] configs: Add support in Kconfig and convert for armada boards

2023-04-25 Thread Michal Simek




On 4/25/23 14:04, Venkatesh Yadav Abbarapu wrote:

From: Algapally Santosh Sagar 

The SERIAL_DT_BAUD is added to Kconfig and the DEFAULT_ENV_IS_RW is moved
to the Kconfig for easier configuration.
Hence, the CONFIG_DEFAULT_ENV_IS_RW config is added to the defconfig files
to allow enabling them for armada boards.

Signed-off-by: Algapally Santosh Sagar 
Signed-off-by: Venkatesh Yadav Abbarapu 
---
  configs/mvebu_db-88f3720_defconfig  |  1 +
  configs/mvebu_espressobin-88f3720_defconfig |  1 +
  configs/mvebu_mcbin-88f8040_defconfig   |  1 +
  drivers/serial/Kconfig  | 16 
  include/configs/mvebu_armada-37xx.h |  1 -
  5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/configs/mvebu_db-88f3720_defconfig 
b/configs/mvebu_db-88f3720_defconfig
index ed0d28fd7d..e3bbaa2173 100644
--- a/configs/mvebu_db-88f3720_defconfig
+++ b/configs/mvebu_db-88f3720_defconfig
@@ -21,6 +21,7 @@ CONFIG_USE_PREBOOT=y
  CONFIG_SYS_CONSOLE_INFO_QUIET=y
  # CONFIG_DISPLAY_CPUINFO is not set
  # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
  CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_ARCH_EARLY_INIT_R=y
  CONFIG_BOARD_EARLY_INIT_F=y
diff --git a/configs/mvebu_espressobin-88f3720_defconfig 
b/configs/mvebu_espressobin-88f3720_defconfig
index ce696787e8..a06eb2dd42 100644
--- a/configs/mvebu_espressobin-88f3720_defconfig
+++ b/configs/mvebu_espressobin-88f3720_defconfig
@@ -22,6 +22,7 @@ CONFIG_USE_PREBOOT=y
  CONFIG_SYS_CONSOLE_INFO_QUIET=y
  # CONFIG_DISPLAY_CPUINFO is not set
  # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
  CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_ARCH_EARLY_INIT_R=y
  CONFIG_BOARD_EARLY_INIT_F=y
diff --git a/configs/mvebu_mcbin-88f8040_defconfig 
b/configs/mvebu_mcbin-88f8040_defconfig
index 058c04333a..4ee5f242f7 100644
--- a/configs/mvebu_mcbin-88f8040_defconfig
+++ b/configs/mvebu_mcbin-88f8040_defconfig
@@ -22,6 +22,7 @@ CONFIG_USE_PREBOOT=y
  CONFIG_SYS_CONSOLE_INFO_QUIET=y
  # CONFIG_DISPLAY_CPUINFO is not set
  # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
  CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_ARCH_EARLY_INIT_R=y
  CONFIG_BOARD_EARLY_INIT_F=y
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 10d07daf27..96cea87f45 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -24,6 +24,22 @@ config BAUDRATE
  in the SPL stage (most drivers) or for choosing a default baudrate
  in the absence of an environment setting (serial_mxc.c).
  
+config SERIAL_DT_BAUD

+   bool "Fetch serial baudrate from device tree"
+   depends on DM_SERIAL && SPL_ENV_SUPPORT
+   select DEFAULT_ENV_IS_RW
+   help
+ Select this to enable fetching and setting of the baudrate
+ configured in the DT. Replace the default baudrate with the DT
+ baudrate and also set it to the environment.


This should be in 1/2.

And the whole patch itself should be the first one in this series.

M


Re: [PATCH 1/2] net: rtl8169: add minimal support for 8125B variant

2023-04-25 Thread Eugen Hristev

On 4/25/23 16:06, Eugen Hristev wrote:

Add minimal support for 8125B version.
Changes are based on the Linux driver.
Tested on Radxa Rock 5B Rk3588 board.

Connection to a laptop worked fine in 100 Mbps mode.
1000 Mbps mode is not working at the moment.

Signed-off-by: Eugen Hristev 
---


The one thing that impacts all the rtl chips is the way the pci BAR is 
now mapped.
I could not test this on another platform so help on this matter is 
appreciated.


Thanks!
Eugen


  drivers/net/rtl8169.c | 52 ++-
  1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index c9c07a5a8ffe..2276a465e787 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -118,9 +118,9 @@ enum RTL8169_registers {
FLASH = 0x30,
ERSR = 0x36,
ChipCmd = 0x37,
-   TxPoll = 0x38,
-   IntrMask = 0x3C,
-   IntrStatus = 0x3E,
+   TxPoll_8169 = 0x38,
+   IntrMask_8169 = 0x3C,
+   IntrStatus_8169 = 0x3E,
TxConfig = 0x40,
RxConfig = 0x44,
RxMissed = 0x4C,
@@ -148,6 +148,12 @@ enum RTL8169_registers {
FuncForceEvent = 0xFC,
  };
  
+enum RTL8125_registers {

+   IntrMask_8125 = 0x38,
+   IntrStatus_8125 = 0x3C,
+   TxPoll_8125 = 0x90,
+};
+
  enum RTL8169_register_content {
/*InterruptStatusBits */
SYSErr = 0x8000,
@@ -263,6 +269,7 @@ static struct {
{"RTL-8101e", 0x34, 0xff7e1880,},
{"RTL-8100e", 0x32, 0xff7e1880,},
{"RTL-8168h/8111h",   0x54, 0xff7e1880,},
+   {"RTL-8125B", 0x64, 0xff7e1880,},
  };
  
  enum _DescStatusBit {

@@ -347,6 +354,7 @@ static struct pci_device_id supported[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169) },
+   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) },
{}
  };
  
@@ -517,6 +525,7 @@ static int rtl_recv_common(struct udevice *dev, unsigned long dev_iobase,

/* return true if there's an ethernet packet ready to read */
/* nic->packet should contain data on return */
/* nic->packetlen should contain length of data */
+   struct pci_child_plat *pplat = dev_get_parent_plat(dev);
int cur_rx;
int length = 0;
  
@@ -558,6 +567,10 @@ static int rtl_recv_common(struct udevice *dev, unsigned long dev_iobase,

return length;
  
  	} else {

+   u32 IntrStatus = IntrStatus_8169;
+
+   if (pplat->device == 0x8125)
+   IntrStatus = IntrStatus_8125;
ushort sts = RTL_R8(IntrStatus);
RTL_W8(IntrStatus, sts & ~(TxErr | RxErr | SYSErr));
udelay(100);/* wait */
@@ -582,6 +595,7 @@ static int rtl_send_common(struct udevice *dev, unsigned 
long dev_iobase,
  {
/* send the packet to destination */
  
+	struct pci_child_plat *pplat = dev_get_parent_plat(dev);

u32 to;
u8 *ptxb;
int entry = tpc->cur_tx % NUM_TX_DESC;
@@ -618,7 +632,10 @@ static int rtl_send_common(struct udevice *dev, unsigned 
long dev_iobase,
((len > ETH_ZLEN) ? len : ETH_ZLEN));
}
rtl_flush_tx_desc(&tpc->TxDescArray[entry]);
-   RTL_W8(TxPoll, 0x40);   /* set polling bit */
+   if (pplat->device == 0x8125)
+   RTL_W8(TxPoll_8125, 0x1);   /* set polling bit */
+   else
+   RTL_W8(TxPoll_8169, 0x40);  /* set polling bit */
  
  	tpc->cur_tx++;

to = currticks() + TX_TIMEOUT;
@@ -824,21 +841,26 @@ static int rtl8169_eth_start(struct udevice *dev)
return 0;
  }
  
-static void rtl_halt_common(unsigned long dev_iobase)

+static void rtl_halt_common(struct udevice *dev)
  {
+   struct rtl8169_private *priv = dev_get_priv(dev);
+   struct pci_child_plat *pplat = dev_get_parent_plat(dev);
int i;
  
  #ifdef DEBUG_RTL8169

printf ("%s\n", __FUNCTION__);
  #endif
  
-	ioaddr = dev_iobase;

+   ioaddr = priv->iobase;
  
  	/* Stop the chip's Tx and Rx DMA processes. */

RTL_W8(ChipCmd, 0x00);
  
  	/* Disable interrupts by clearing the interrupt mask. */

-   RTL_W16(IntrMask, 0x);
+   if (pplat->device == 0x8125)
+   RTL_W16(IntrMask_8125, 0x);
+   else
+   RTL_W16(IntrMask_8169, 0x);
  
  	RTL_W32(RxMissed, 0);
  
@@ -849,9 +871,7 @@ static void rtl_halt_common(unsigned long dev_iobase)
  
  void rtl8169_eth_stop(struct udevice *dev)

  {
-   struct rtl8169_private *priv = dev_get_priv(dev);
-
-   rtl_halt_common(priv->iobase);
+   rtl_halt_common(dev);
  }
  
  static int rtl8169_write_hwaddr(struct udevice *dev)

@@ -1025,23 +1045,25 @@ static int rtl8169_eth_probe(struct udevice *dev)
struct pci_child_plat *pplat = dev_get_parent_plat(dev);
struct rtl8169_private *priv = dev_get_

[PATCH] common/Kconfig: fix comments syntax error

2023-04-25 Thread Hugo Villeneuve
From: Hugo Villeneuve 

Fix comments error in EVENT_DEBUG description:
usefui -> useful

Signed-off-by: Hugo Villeneuve 
---
 common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index f2783ee65d..8c5b672cdf 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -626,7 +626,7 @@ config EVENT_DEBUG
bool "Enable event debugging assistance"
default y if SANDBOX
help
- Enable this get usefui features for seeing what is happening with
+ Enable this get useful features for seeing what is happening with
  events, such as event-type names. This adds to the code size of
  U-Boot so can be turned off for production builds.
 
-- 
2.30.2



[PATCH] event: fix comments syntax error

2023-04-25 Thread Hugo Villeneuve
From: Hugo Villeneuve 

Fix comments syntax error in event description:
creasted -> created

Signed-off-by: Hugo Villeneuve 
---
 doc/develop/event.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/develop/event.rst b/doc/develop/event.rst
index 4ff5934837..e60cbf6569 100644
--- a/doc/develop/event.rst
+++ b/doc/develop/event.rst
@@ -12,7 +12,7 @@ Rather than using weak functions and direct calls across 
subsystemss, it is
 often easier to use an event.
 
 An event consists of a type (e.g. EVT_DM_POST_INIT) and some optional data,
-in `union event_data`. An event spy can be creasted to watch for events of a
+in `union event_data`. An event spy can be created to watch for events of a
 particular type. When the event is created, it is sent to each spy in turn.
 
 
-- 
2.30.2



Re: [PATCH] docs: fix wrong proftool usage

2023-04-25 Thread Pavel Skripkin

Hi Simon,

Simon Glass  says:

On Wed, 12 Apr 2023 at 13:05, Pavel Skripkin  wrote:


Guide shows incorrect usage of proftool, which is confusing. If proftool
is used w/o '-o' argument it complains like following

$ ./sandbox/tools/proftool -m sandbox/System.map -t trace dump-ftrace > 
trace.dat
Must provide trace data, System.map file and output file
Usage: proftool [-cmtv]  

s/>/-o/ fixes it and proftool outputs decoded data to trace.dat

Signed-off-by: Pavel Skripkin 
---
 doc/develop/trace.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Simon Glass 


Thank you for review!

+Tom, I guess?

@Tom, could you, please, pick following patch?


https://lists.denx.de/pipermail/u-boot/2023-April/515194.html




With regards,
Pavel Skripkin


Re: [PATCH] sandbox: disable tracing before unmapping RAM

2023-04-25 Thread Pavel Skripkin

Hi Simon,

Simon Glass  says:

On Wed, 12 Apr 2023 at 12:55, Pavel Skripkin  wrote:


Currently doing 'reset' command in sandbox with tracing enabled causes
SIGSEV

```
Hit any key to stop autoboot:  0
=>
=>
=> reset
resetting ...
Segmentation fault (core dumped)

```

Tracing callback uses RAM buffer for storing tracing reports, but
state_uninit() function unmaps whole RAM, which causes SIGSEV on umapped
memory inside tracing subsystem.

Fix it by disabling tracing before unmapping memory

Signed-off-by: Pavel Skripkin 
---
 arch/sandbox/cpu/state.c | 4 
 1 file changed, 4 insertions(+)


Reviewed-by: Simon Glass 


Thank you for review!

+Tom, I guess?

@Tom, could you, please, pick following patch?


https://lists.denx.de/pipermail/u-boot/2023-April/515192.html




With regards,
Pavel Skripkin


Re: [PATCH] docs: fix wrong proftool usage

2023-04-25 Thread Tom Rini
On Tue, Apr 25, 2023 at 04:41:52PM +0300, Pavel Skripkin wrote:
> Hi Simon,
> 
> Simon Glass  says:
> > On Wed, 12 Apr 2023 at 13:05, Pavel Skripkin  wrote:
> > > 
> > > Guide shows incorrect usage of proftool, which is confusing. If proftool
> > > is used w/o '-o' argument it complains like following
> > > 
> > > $ ./sandbox/tools/proftool -m sandbox/System.map -t trace dump-ftrace > 
> > > trace.dat
> > > Must provide trace data, System.map file and output file
> > > Usage: proftool [-cmtv]  
> > > 
> > > s/>/-o/ fixes it and proftool outputs decoded data to trace.dat
> > > 
> > > Signed-off-by: Pavel Skripkin 
> > > ---
> > >  doc/develop/trace.rst | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > Reviewed-by: Simon Glass 
> 
> Thank you for review!
> 
> +Tom, I guess?
> 
> @Tom, could you, please, pick following patch?
> 
> 
> https://lists.denx.de/pipermail/u-boot/2023-April/515194.html

Heinrich takes doc patches and I've assigned it to him in patchwork,
thanks for posting.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] sandbox: disable tracing before unmapping RAM

2023-04-25 Thread Tom Rini
On Tue, Apr 25, 2023 at 04:43:19PM +0300, Pavel Skripkin wrote:
> Hi Simon,
> 
> Simon Glass  says:
> > On Wed, 12 Apr 2023 at 12:55, Pavel Skripkin  wrote:
> > > 
> > > Currently doing 'reset' command in sandbox with tracing enabled causes
> > > SIGSEV
> > > 
> > > ```
> > > Hit any key to stop autoboot:  0
> > > =>
> > > =>
> > > => reset
> > > resetting ...
> > > Segmentation fault (core dumped)
> > > 
> > > ```
> > > 
> > > Tracing callback uses RAM buffer for storing tracing reports, but
> > > state_uninit() function unmaps whole RAM, which causes SIGSEV on umapped
> > > memory inside tracing subsystem.
> > > 
> > > Fix it by disabling tracing before unmapping memory
> > > 
> > > Signed-off-by: Pavel Skripkin 
> > > ---
> > >  arch/sandbox/cpu/state.c | 4 
> > >  1 file changed, 4 insertions(+)
> > 
> > Reviewed-by: Simon Glass 
> 
> Thank you for review!
> 
> +Tom, I guess?
> 
> @Tom, could you, please, pick following patch?
> 
> 
> https://lists.denx.de/pipermail/u-boot/2023-April/515192.html

Simon takes sandbox patches himself and I've assigned this to him in
patchwork, thanks for submitting the patch.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] sandbox: disable tracing before unmapping RAM

2023-04-25 Thread Pavel Skripkin

Hi Tom,

Tom Rini  says:

Simon takes sandbox patches himself and I've assigned this to him in
patchwork, thanks for submitting the patch.



Ah, sorry for noise then. I am just unfamiliar with u-boot development 
process.


Thank you!


With regards,
Pavel Skripkin


Re: Unable to implement board fdt-fixup for imx8m CPU

2023-04-25 Thread Hugo Villeneuve
On Tue, 25 Apr 2023 14:19:14 +0200
Rasmus Villemoes  wrote:

> On 25/04/2023 04.17, Hugo Villeneuve wrote:
> 
> > I need to detect at runtime the SOM configuration from an EEPROM, and based 
> > on that information adjust the ethernet PHY property inside the device tree.
> > 
> > I have already done that with success, it works great and as a temporary 
> > workaround I simply call my own function imx8m_board_fix_fdt() at the end 
> > of the function board_fix_fdt() of arch/arm/mach-imx/imx8m/soc.c.
> > 
> > But I don't think that a "board" level function should have been put in a 
> > SOC/arch source file in arch/arm/mach-imx/imx8m/soc.c in the first place. 
> > If it were not for that, there wouldn't be any need to define something new 
> > (event or other).
> > 
> > Maybe we should try to remove that board level function from 
> > arch/arm/mach-imx/imx8m/soc.c and use some other already existing mechanism 
> > for SOC-level device tree fixups?
> 
> AFAICT, you/we can just nuke that function completely.
> 
> (1) As you say, it's not appropriate for arch/SOC to provide that in the
> first place.
> (2) It's completely dead and useless code:
> (2a) No in-tree imx8m-based board seems to set CONFIG_OF_BOARD_FIXUP
> (2b) The nodes which that function wants to disable don't even exist in
> the U-Boot copy of imx8mp.dtsi.
> 
> Commit 35bb60787b88 should never have been applied in mainline U-Boot,
> it's some random import of code from downstream NXP U-Boot, with a
> commit message that makes no sense in upstream context.
> 
> Rasmus

Hi Rasmus,
I agree with your analysis, and I will submit a patch to remove that code.

Thank you.

-- 
Hugo Villeneuve


[PATCH] arm: imx8m: remove unused and obsolete board_fix_fdt() in SOC context

2023-04-25 Thread Hugo Villeneuve
From: Hugo Villeneuve 

It doesn't seem appropriate for arch/SOC to use a board-level
functionality (CONFIG_OF_BOARD_FIXUP), because this prevents boards
that need to do FDT fixup from using that feature.

Also, this code is completely dead and useless (from comments by
Rasmus Villemoes on the mailing list):

  - No in-tree imx8m-based board seems to set CONFIG_OF_BOARD_FIXUP
  - The nodes which that function wants to disable don't even exist in
the U-Boot copy of imx8mp.dtsi.

This code was introduced in commit 35bb60787b88. It seems to be some
random import of code from downstream NXP U-Boot, with a commit
message that makes no sense in upstream context.

Signed-off-by: Hugo Villeneuve 
---
 arch/arm/mach-imx/imx8m/soc.c | 34 --
 1 file changed, 34 deletions(-)

diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c
index df865e997d..2ec5c3dc43 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -1395,40 +1395,6 @@ usb_modify_speed:
 }
 #endif
 
-#ifdef CONFIG_OF_BOARD_FIXUP
-#ifndef CONFIG_SPL_BUILD
-int board_fix_fdt(void *fdt)
-{
-   if (is_imx8mpul()) {
-   int i = 0;
-   int nodeoff, ret;
-   const char *status = "disabled";
-   static const char * const dsi_nodes[] = {
-   "/soc@0/bus@32c0/mipi_dsi@32e6",
-   "/soc@0/bus@32c0/lcd-controller@32e8",
-   "/dsi-host"
-   };
-
-   for (i = 0; i < ARRAY_SIZE(dsi_nodes); i++) {
-   nodeoff = fdt_path_offset(fdt, dsi_nodes[i]);
-   if (nodeoff > 0) {
-set_status:
-   ret = fdt_setprop(fdt, nodeoff, "status", 
status,
- strlen(status) + 1);
-   if (ret == -FDT_ERR_NOSPACE) {
-   ret = fdt_increase_size(fdt, 512);
-   if (!ret)
-   goto set_status;
-   }
-   }
-   }
-   }
-
-   return 0;
-}
-#endif
-#endif
-
 #if !CONFIG_IS_ENABLED(SYSRESET)
 void reset_cpu(void)
 {
-- 
2.30.2



Re: [PATCH 00/30] ide: Clean up code and fix a few bugs

2023-04-25 Thread Tom Rini
On Tue, Mar 28, 2023 at 08:06:47AM +1300, Simon Glass wrote:

> This code was converted to driver model a long time again but it was a
> pretty rough conversion. It introduced a few minor bugs, e.g. the device
> capacity is incorrect and some flags are lost (such as lba48).
> 
> This series tidies up the code and fixes these bugs. This involves quite
> a bit of refactoring, so it is done one patch at a time for easier
> review.

This doesn't apply cleanly currently, and my first attempt at applying
resulted in fails to build, please rebase and resend, thanks.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] .mailmap: Map all Xilinx users mail ids to AMD

2023-04-25 Thread Tom Rini
On Mon, Apr 24, 2023 at 12:44:12AM -0600, Ashok Reddy Soma wrote:
> From: Algapally Santosh Sagar 
> 
> The mail ids of all the current Xilinx users are to be mapped to AMD
> following the merger with AMD. The mailmap file is updated accordingly.
> 
> The ids of Marek Behún and Michal Simek are taken as reference.
> 
> Signed-off-by: Algapally Santosh Sagar 
> Signed-off-by: Ashok Reddy Soma 
> ---
> 
>  .mailmap | 54 +++---
>  1 file changed, 51 insertions(+), 3 deletions(-)
> 
> diff --git a/.mailmap b/.mailmap
> index 80076f7206..46a8619d78 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -17,27 +17,46 @@
>  
>  Alexander Graf  
>  Allen Martin 
> +Amanda Baze  
> +Amit Kumar Mahapatra  
> 
>  Andreas Bießmann 
>  Andreas Bießmann 
>  Aneesh V 
>  Anup Patel  
> +Anurag Kumar Vulisha  
> 
> +Appana Durga Kedareswara rao  
> 
> +Ashok Reddy Soma  
>  Atish Patra  
> +Bharat Kumar Gogada  
> 
> +Bharat Kumar Gogada  

You've added a space before the '>' in the new email here.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 03/31] u_boot_pylib: Make pty optional

2023-04-25 Thread Tom Rini
On Mon, Apr 24, 2023 at 05:08:08PM -0600, Simon Glass wrote:
> This library is not available on Windows. Detect this and work around it
> by using a normal pipe.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  scripts/make_pip.sh   |  9 +++--
>  tools/u_boot_pylib/cros_subprocess.py | 28 ++-
>  2 files changed, 30 insertions(+), 7 deletions(-)
> 
> diff --git a/scripts/make_pip.sh b/scripts/make_pip.sh
> index 4602dcf61c88..bcff65240ba1 100755
> --- a/scripts/make_pip.sh
> +++ b/scripts/make_pip.sh
> @@ -91,7 +91,12 @@ find ${dest} -name __pycache__ -type f -exec rm {} \;
>  find ${dest} -depth -name __pycache__ -exec rmdir 112 \;
>  
>  # Remove test files
> -rm -rf ${dest}/*test*
> +for path in ${dest}/*test*; do
> + echo ${path}
> + if ! [[ "${path}" =~ .*test_util.* ]]; then
> + rm -rf ${path}
> + fi
> +done
>  
>  mkdir ${dir}/tests
>  cd ${dir}
> @@ -108,7 +113,7 @@ echo "Completed build of ${tool}"
>  # Use --skip-existing to work even if the version is already present
>  if [ -n "${upload}" ]; then
>   echo "Uploading from ${dir}"
> - python3 -m twine upload ${repo} -u __token__ dist/*
> + python3 -m twine upload ${repo} --verbose -u __token__ dist/*
>   echo "Completed upload of ${tool}"
>  fi

The verbose here is I assume a debugging left-over.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 25/31] Makefile: Disable unsupported compiler options with PE

2023-04-25 Thread Tom Rini
On Mon, Apr 24, 2023 at 05:08:30PM -0600, Simon Glass wrote:
> The MSYS2 compiler does not support some of these options. Drop them to
> avoid build errors.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  Makefile | 2 ++
>  scripts/Makefile.lib | 5 -
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 0aa97a2c3b48..773260b81d5d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -818,7 +818,9 @@ KBUILD_CPPFLAGS += $(KCPPFLAGS)
>  KBUILD_AFLAGS += $(KAFLAGS)
>  KBUILD_CFLAGS += $(KCFLAGS)
>  
> +ifeq ($(MSYS_VERSION),0)
>  KBUILD_LDFLAGS  += -z noexecstack
> +endif
>  KBUILD_LDFLAGS  += $(call ld-option,--no-warn-rwx-segments)
>  
>  KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g)
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 7b27224b5d44..d309e26aaec8 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -425,7 +425,10 @@ cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j 
> .sdata -j .data -j \
>  $(obj)/%.efi: $(obj)/%_efi.so
>   $(call cmd,efi_objcopy)
>  
> -KBUILD_EFILDFLAGS = -nostdlib -zexecstack -znocombreloc -znorelro
> +KBUILD_EFILDFLAGS = -nostdlib
> +ifeq ($(MSYS_VERSION),0)
> +KBUILD_EFILDFLAGS += -zexecstack -znocombreloc -znorelro
> +endif
>  KBUILD_EFILDFLAGS += $(call ld-option,--no-warn-rwx-segments)
>  quiet_cmd_efi_ld = LD  $@
>  cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -T $(EFI_LDS_PATH) \

We should use $(call ld-option,...) here instead.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 00/31] Allow building sandbox with MSYS2

2023-04-25 Thread Tom Rini
On Tue, Apr 25, 2023 at 04:59:53AM +0200, Heinrich Schuchardt wrote:
> 
> 
> Am 25. April 2023 01:08:05 MESZ schrieb Simon Glass :
> >This expands the existing work to allow sandbox to build and run on
> >Windows using MSYS2.
> 
> Why do we need this?
> Wouldn't a developer on Windows be much better served using WSL 
> (https://learn.microsoft.com/en-us/windows/wsl/install)?

Depending on corporate rules that may or may not be allowed. But I too
am interested in the use case driving these changes. Sandbox is
essentially a test platform. We test that we can do host tools on
Windows via MSYS2 for semi-reasonable reasons, since those tools can be
used in a number of places. We do the same on macOS in Azure as a check
on building regular targets there too (which should work and I believe
people do, both from macOS and from *BSD which this is a stand-in for,
as we can't get free VMs for them today). What's the end goal of this
series?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 06/31] pylibfdt: Allow building on Windows

2023-04-25 Thread Pali Rohár
On Monday 24 April 2023 17:08:11 Simon Glass wrote:
> Handle the different shared-object extension with MSYS2 by creating a new
> SOEXT variable.

LIBEXT would be a better name as "SO" name refers to ELF.
I saw that variable LIBEXT is used in more projects for this purpose.

> Signed-off-by: Simon Glass 
> ---
> 
>  Makefile  | 11 +++
>  scripts/dtc/pylibfdt/Makefile | 16 +---
>  2 files changed, 20 insertions(+), 7 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index eaaf7d267d31..dd3fcd1782e5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -39,6 +39,17 @@ else ifeq ("riscv64", $(MK_ARCH))
>  endif
>  undefine MK_ARCH
>  
> +# Building on Windows with MSYS2
> +export MSYS_VERSION = $(if $(findstring Msys, $(shell uname -o)),$(word 1, 
> $(subst ., ,$(shell uname -r))),0)
> +# $(info The version of MSYS you are running is $(MSYS_VERSION) (0 meaning 
> not MSYS at all))
> +
> +# Sets the extension to use for shared-object files
> +ifeq ($(MSYS_VERSION),0)
> +export SOEXT := so
> +else
> +export SOEXT := dll
> +endif
> +
>  # Avoid funny character set dependencies
>  unexport LC_ALL
>  LC_COLLATE=C
> diff --git a/scripts/dtc/pylibfdt/Makefile b/scripts/dtc/pylibfdt/Makefile
> index e442d5c24201..feca0bb9abb1 100644
> --- a/scripts/dtc/pylibfdt/Makefile
> +++ b/scripts/dtc/pylibfdt/Makefile
> @@ -7,6 +7,8 @@ LIBFDT_srcdir = $(abspath $(srctree)/$(src)/../libfdt)
>  
>  include $(LIBFDT_srcdir)/Makefile.libfdt
>  
> +LIBFILE := _libfdt.$(SOEXT)
> +
>  # Unfortunately setup.py (or actually the Python distutil implementation) 
> puts
>  # files into the same directory as the .i file. We cannot touch the source
>  # directory, so we "ship" .i file into the objtree.
> @@ -29,16 +31,16 @@ quiet_cmd_pymod = PYMOD   $@
>  rebuild: $(src)/setup.py $(PYLIBFDT_srcs)
>   @# Remove the library since otherwise Python doesn't seem to regenerate
>   @# the libfdt.py file if it is missing.
> - @rm -f $(obj)/_libfdt*.so
> + @rm -f $(obj)/_libfdt*.$(SOEXT)
>   $(call if_changed,pymod)
> - @# Rename the file to _libfdt.so so this Makefile doesn't run every time
> - @if [ ! -e $(obj)/_libfdt.so ]; then \
> - mv $(obj)/_libfdt*.so $(obj)/_libfdt.so; \
> + @# Rename the file to $(LIBFILE) so this Makefile doesn't run every time
> + @if [ ! -e $(obj)/$(LIBFILE) ]; then \
> + mv $(obj)/_libfdt*.$(SOEXT) $(obj)/$(LIBFILE); \
>   fi
>  
> -$(obj)/_libfdt.so $(obj)/libfdt.py &: rebuild
> +$(obj)/$(LIBFILE) $(obj)/libfdt.py &: rebuild
>   @:
>  
> -always += _libfdt.so libfdt.py
> +always += $(LIBFILE) libfdt.py
>  
> -clean-files += libfdt.i _libfdt.so libfdt.py libfdt_wrap.c
> +clean-files += libfdt.i $(LIBFILE) libfdt.py libfdt_wrap.c
> -- 
> 2.40.0.634.g4ca3ef3211-goog
> 


[PATCH] environment: ti: Add get_fit_config command to get FIT config string

2023-04-25 Thread Andrew Davis
When OE is packaging a dtb file into the FIT image it names the node based
on the dtb filename. Node names can't have "/" so it is turned into "_".
We select our FIT config using the "fdtfile" env var so we don't duplicate
the board_name to fdt logic. Result is fdtfile needs mangled when used to
select a config node from OE made FIT image. Do this here.

Signed-off-by: Andrew Davis 
---
 include/configs/ti_armv7_common.h  | 3 ++-
 include/environment/ti/ti_armv7_common.env | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/configs/ti_armv7_common.h 
b/include/configs/ti_armv7_common.h
index d54c208ef66..149a74d98e8 100644
--- a/include/configs/ti_armv7_common.h
+++ b/include/configs/ti_armv7_common.h
@@ -55,7 +55,8 @@
"do;" \
"setenv overlaystring ${overlaystring}'#'${overlay};" \
"done;\0" \
-   "run_fit=bootm ${addr_fit}#conf-${fdtfile}${overlaystring}\0" \
+   "get_fit_config=setexpr name_fit_config gsub / _ conf-${fdtfile}\0" \
+   "run_fit=run get_fit_config; bootm 
${addr_fit}#${name_fit_config}${overlaystring}\0" \
 
 /*
  * DDR information.  If the CONFIG_NR_DRAM_BANKS is not defined,
diff --git a/include/environment/ti/ti_armv7_common.env 
b/include/environment/ti/ti_armv7_common.env
index 4d334648c05..0c0929d8628 100644
--- a/include/environment/ti/ti_armv7_common.env
+++ b/include/environment/ti/ti_armv7_common.env
@@ -20,5 +20,6 @@ get_overlaystring=
do;
setenv overlaystring ${overlaystring}'#'${overlay};
done;
-run_fit=bootm ${addr_fit}#conf-${fdtfile}${overlaystring}
+get_fit_config=setexpr name_fit_config gsub / _ conf-${fdtfile}
+run_fit=run get_fit_config; bootm 
${addr_fit}#${name_fit_config}${overlaystring}
 
-- 
2.39.2



Re: [PATCH 24/31] build: Disable weak symbols for MSYS2

2023-04-25 Thread Pali Rohár
On Monday 24 April 2023 17:08:29 Simon Glass wrote:
> Weak symbols are not well supported by the PE format, so disable them.

They are supported by PE format. This is likely issue of (older)
toolchain. What about rather requiring better toolchain version and
fix special cases of weak functions do not work correctly?

> We need to manually ensure that only one function is present in the source
> code.
> 
> Add a Kconfig option to control this and enable it when building for
> Windows.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  Kconfig | 15 +++
>  include/linux/compiler_attributes.h |  4 
>  2 files changed, 19 insertions(+)
> 
> diff --git a/Kconfig b/Kconfig
> index f24e4f0a331e..ca1402d09d10 100644
> --- a/Kconfig
> +++ b/Kconfig
> @@ -72,6 +72,21 @@ config CLANG_VERSION
>   int
>   default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
>  
> +config CC_IS_MSYS
> + def_bool $(success,uname -o | grep -q Msys)
> +
> +config WEAK_SYMBOLS
> + bool "Enable use of weak symbols"
> + default y if !CC_IS_MSYS
> + help
> +   The Portable Executable (PE) format used by Windows does not support
> +   weak symbols very well. Even where it can be made to work, the __weak
> +   function attribute cannot be made to work with PE. Supporting weak
> +   symbols would involve changing the source code in undesirable ways.
> +
> +   This option controls whether weak symbols are used, or not. When
> +   disabled, the __weak function attribute does nothing.
> +
>  choice
>   prompt "Optimization level"
>   default CC_OPTIMIZE_FOR_SIZE
> diff --git a/include/linux/compiler_attributes.h 
> b/include/linux/compiler_attributes.h
> index 44c9a08d7346..c954109a065b 100644
> --- a/include/linux/compiler_attributes.h
> +++ b/include/linux/compiler_attributes.h
> @@ -268,6 +268,10 @@
>   *   gcc: 
> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute
>   *   gcc: 
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-weak-variable-attribute
>   */
> +#ifdef CONFIG_WEAK_SYMBOLS
>  #define __weak  __attribute__((__weak__))
> +#else
> +#define __weak
> +#endif
>  
>  #endif /* __LINUX_COMPILER_ATTRIBUTES_H */
> -- 
> 2.40.0.634.g4ca3ef3211-goog
> 


Re: [PATCH 10/31] sandbox: Provide a linker script for MSYS2

2023-04-25 Thread Pali Rohár
On Monday 24 April 2023 17:08:15 Simon Glass wrote:
> Add a script to allow the U-Boot sandbox executable to be built for
> Windows. Add a note as to why this seems to be necessary for now.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  Makefile   |  11 +-
>  arch/sandbox/config.mk |   4 +
>  arch/sandbox/cpu/u-boot-pe.lds | 447 +
>  3 files changed, 460 insertions(+), 2 deletions(-)
>  create mode 100644 arch/sandbox/cpu/u-boot-pe.lds
> 
> diff --git a/Makefile b/Makefile
> index dd3fcd1782e5..0aa97a2c3b48 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1730,6 +1730,13 @@ else
>  u-boot-keep-syms-lto :=
>  endif
>  
> +ifeq ($(MSYS_VERSION),0)
> +add_ld_script := -T u-boot.lds
> +else
> +add_ld_script := u-boot.lds
> +$(warning msys)
> +endif
> +
>  # Rule to link u-boot
>  # May be overridden by arch/$(ARCH)/config.mk
>  ifeq ($(LTO_ENABLE),y)
> @@ -1738,7 +1745,7 @@ quiet_cmd_u-boot__ ?= LTO $@
>   $(CC) -nostdlib -nostartfiles   
> \
>   $(LTO_FINAL_LDFLAGS) $(c_flags) 
> \
>   $(KBUILD_LDFLAGS:%=-Wl,%) $(LDFLAGS_u-boot:%=-Wl,%) -o $@   
> \
> - -T u-boot.lds $(u-boot-init)
> \
> + $(add_ld_script) $(u-boot-init) 
> \
>   -Wl,--whole-archive 
> \
>   $(u-boot-main)  
> \
>   $(u-boot-keep-syms-lto) 
> \
> @@ -1749,7 +1756,7 @@ quiet_cmd_u-boot__ ?= LTO $@
>  else
>  quiet_cmd_u-boot__ ?= LD  $@
>cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@
> \
> - -T u-boot.lds $(u-boot-init)
> \
> + $(add_ld_script) $(u-boot-init) 
> \
>   --whole-archive 
> \
>   $(u-boot-main)  
> \
>   --no-whole-archive  
> \
> diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
> index 2d184c5f652a..e05daf57ef8e 100644
> --- a/arch/sandbox/config.mk
> +++ b/arch/sandbox/config.mk
> @@ -71,3 +71,7 @@ EFI_CRT0 := crt0_sandbox_efi.o
>  EFI_RELOC := reloc_sandbox_efi.o
>  AFLAGS_crt0_sandbox_efi.o += -DHOST_ARCH="$(HOST_ARCH)"
>  CFLAGS_reloc_sandbox_efi.o += -DHOST_ARCH="$(HOST_ARCH)"
> +
> +ifneq ($(MSYS_VERSION),0)
> +LDSCRIPT = $(srctree)/arch/sandbox/cpu/u-boot-pe.lds
> +endif
> diff --git a/arch/sandbox/cpu/u-boot-pe.lds b/arch/sandbox/cpu/u-boot-pe.lds
> new file mode 100644
> index ..031e70fafd03
> --- /dev/null
> +++ b/arch/sandbox/cpu/u-boot-pe.lds
> @@ -0,0 +1,447 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * U-Boot note: This was obtained by using the -verbose linker option. The
> + * U-Boot additions are marked below.
> + *
> + * Ideally we would add sections to the executable, as is done with the Linux
> + * build. But PE executables do not appear to work correctly if unexpected
> + * sections are present:
> + *
> + *   $ /tmp/b/sandbox/u-boot.exe
> + *   -bash: /tmp/b/sandbox/u-boot.exe: cannot execute binary file: Exec 
> format error
> + *
> + * So we take a approach of rewriting the whole file, for now. This will 
> likely
> + * break in the future when a toolchain change is made.

Why not rather provide "layer" linker script which does this "rewriting"
on top of the default linker script? With this way it is not needed to
update linker script when a toolchain change it.

> + */
> +
> +/* Default linker script, for normal executables */
> +/* Copyright (C) 2014-2023 Free Software Foundation, Inc.
> +   Copying and distribution of this script, with or without modification,
> +   are permitted in any medium without royalty provided the copyright
> +   notice and this notice are preserved.  */
> +
> +OUTPUT_FORMAT(pei-x86-64)
> +SEARCH_DIR("/usr/x86_64-pc-msys/lib"); SEARCH_DIR("/usr/lib"); 
> SEARCH_DIR("/usr/lib/w32api");
> +SECTIONS
> +{
> +  /* Make the virtual address and file offset synced if the alignment is
> + lower than the target page size. */
> +  . = SIZEOF_HEADERS;
> +  . = ALIGN(__section_alignment__);
> +  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : 
> __section_alignment__ ) :
> +  {
> +KEEP (*(SORT_NONE(.init)))
> +*(.text)
> +*(SORT(.text$*))
> + *(.text.*)
> + *(.gnu.linkonce.t.*)
> +*(.glue_7t)
> +*(.glue_7)
> +. = ALIGN(8);
> +   /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
> +  we do not PROVIDE them.  This is because the ctors.o startup
> +   code in libgcc defines them as common symbols, with the
> +  expectation that they will be over

Re: [PATCH 25/31] Makefile: Disable unsupported compiler options with PE

2023-04-25 Thread Pali Rohár
On Monday 24 April 2023 17:08:30 Simon Glass wrote:
> The MSYS2 compiler does not support some of these options. Drop them to
> avoid build errors.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  Makefile | 2 ++
>  scripts/Makefile.lib | 5 -
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 0aa97a2c3b48..773260b81d5d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -818,7 +818,9 @@ KBUILD_CPPFLAGS += $(KCPPFLAGS)
>  KBUILD_AFLAGS += $(KAFLAGS)
>  KBUILD_CFLAGS += $(KCFLAGS)
>  
> +ifeq ($(MSYS_VERSION),0)
>  KBUILD_LDFLAGS  += -z noexecstack

What about rather using $(call ...) instead of ifeq?

> +endif
>  KBUILD_LDFLAGS  += $(call ld-option,--no-warn-rwx-segments)
>  
>  KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g)
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 7b27224b5d44..d309e26aaec8 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -425,7 +425,10 @@ cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j 
> .sdata -j .data -j \
>  $(obj)/%.efi: $(obj)/%_efi.so
>   $(call cmd,efi_objcopy)
>  
> -KBUILD_EFILDFLAGS = -nostdlib -zexecstack -znocombreloc -znorelro
> +KBUILD_EFILDFLAGS = -nostdlib
> +ifeq ($(MSYS_VERSION),0)
> +KBUILD_EFILDFLAGS += -zexecstack -znocombreloc -znorelro
> +endif
>  KBUILD_EFILDFLAGS += $(call ld-option,--no-warn-rwx-segments)
>  quiet_cmd_efi_ld = LD  $@
>  cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -T $(EFI_LDS_PATH) \
> -- 
> 2.40.0.634.g4ca3ef3211-goog
> 


Re: [PATCH 26/31] Makefile: Correct the ans1_compiler rule for MSYS2

2023-04-25 Thread Pali Rohár
On Monday 24 April 2023 17:08:31 Simon Glass wrote:
> Add the required extension to the Makefile rule.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  Makefile   | 1 +
>  scripts/Makefile.build | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 773260b81d5d..08eab87d0a11 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -48,6 +48,7 @@ ifeq ($(MSYS_VERSION),0)
>  export SOEXT := so
>  else
>  export SOEXT := dll
> +export ELFEXT := .exe

.EXE is not extension for ELF format :-)

Autotools and also other tools use EXEEXT Makefile variable for this.
What about following this de-factor standard variable name?

>  endif
>  
>  # Avoid funny character set dependencies
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 97dd4a64f6ef..547dc039ceb4 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -309,7 +309,7 @@ quiet_cmd_asn1_compiler = ASN.1   $@
>cmd_asn1_compiler = $(objtree)/tools/asn1_compiler $< \
>   $(subst .h,.c,$@) $(subst .c,.h,$@)
>  
> -$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/tools/asn1_compiler
> +$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 
> $(objtree)/tools/asn1_compiler$(ELFEXT)
>   $(call cmd,asn1_compiler)
>  
>  # Build the compiled-in targets
> -- 
> 2.40.0.634.g4ca3ef3211-goog
> 


[PATCH] fdt: Indicate that people should use the ofnode API

2023-04-25 Thread Simon Glass
Add a note to the comment at the top of this file.

Signed-off-by: Simon Glass 
---

 lib/fdtdec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 0827e16859f..55cc95db5d0 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1,6 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
+ *
+ * NOTE: Please do not add new devicetree-reading functionality into this file.
+ * Add it to the ofnode API instead, since that is compatible with livetree.
  */
 
 #ifndef USE_HOSTCC
-- 
2.40.0.634.g4ca3ef3211-goog



Re: [PATCH 27/31] Makefile: Disable LTO when building with MSYS2

2023-04-25 Thread Pali Rohár
On Monday 24 April 2023 17:08:32 Simon Glass wrote:
> This creates a lot of errors of the form:
> 
> `__stack_chk_fail' referenced in section `.text' of ...ltrans.o: defined
>in discarded section `.text' of common/stackprot.o (symbol from plugin)

This issue should be rather fixed...

> Drop LTO for now.

... and until it happens is not CONFIG_LTO for disabling enough?

LTO does not work for more other boards / platforms and it is just _not_
enabled via CONFIG_LTO in those cases...

> Signed-off-by: Simon Glass 
> ---
> 
>  Makefile | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index 08eab87d0a11..3a35d14a4497 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -658,9 +658,11 @@ export EFI_TARGET# binutils target if EFI is 
> natively supported
>  export LTO_ENABLE
>  
>  # This is y if LTO is enabled for this build. See NO_LTO=1 to disable LTO
> +ifeq ($(MSYS_VERSION),0)
>  ifeq ($(NO_LTO),)
>  LTO_ENABLE=$(if $(CONFIG_LTO),y)
>  endif
> +endif
>  
>  # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
>  # that (or fail if absent).  Otherwise, search for a linker script in a
> -- 
> 2.40.0.634.g4ca3ef3211-goog
> 


Re: [PATCH 17/31] sandbox: Allow weak symbols to be dropped

2023-04-25 Thread Pali Rohár
On Tuesday 25 April 2023 10:44:17 Bin Meng wrote:
> Hi Simon,
> 
> On Tue, Apr 25, 2023 at 7:09 AM Simon Glass  wrote:
> >
> > The sandbox build makes use of a small number of weak symbols. Allow these
> > to be dropped when building for the PE format, since its support for weak
> > symbols is poor.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  cmd/bootefi.c | 3 ++-
> >  cmd/bootz.c   | 3 +++
> >  common/usb.c  | 3 +++
> >  drivers/core/root.c   | 3 +++
> >  drivers/spi/sandbox_spi.c | 3 +++
> >  env/env.c | 6 ++
> >  lib/efi_loader/efi_image_loader.c | 3 +++
> >  lib/efi_loader/efi_runtime.c  | 4 
> >  lib/lmb.c | 4 +++-
> >  lib/time.c| 3 +++
> >  10 files changed, 33 insertions(+), 2 deletions(-)
> >
> 
> You probably need to use:
> 
> __declspec(selectany)
> 
> to replace __weak in the ELF for the *nix world.
> 
> Note this Microsoft bizarre does not provide the "strong override
> weak" effect but I suspect what you only need is to get the build pass
> on Windows so it should be okay.
> 
> Regards,
> Bin

You have selectany and external weaks support in PE format. For the
majority of weak function cases, this is enough. Cannot we use them?


[PATCH v2 00/30] ide: Clean up code and fix a few bugs

2023-04-25 Thread Simon Glass
This code was converted to driver model a long time again but it was a
pretty rough conversion. It introduced a few minor bugs, e.g. the device
capacity is incorrect and some flags are lost (such as lba48).

This series tidies up the code and fixes these bugs. This involves quite
a bit of refactoring, so it is done one patch at a time for easier
review.

Changes in v2:
- Drop [] in patch subject
- Rebase to master

Simon Glass (30):
  ide: Move ATA_CURR_BASE to C file
  ide: Use mdelay() for long delays
  ide: Drop CONFIG_START_IDE
  ide: Drop init for not using BLK
  ide: Move ide_init() into probing
  ide: Drop ide_device_present()
  ide: Move a few functions further up the file
  ide: Drop weak functions
  ide: Create a prototype for ide_set_reset()
  ide: Correct use of ATAPI
  ide: Make function static
  ide: Change the retries variable
  ide: Refactor confusing loop code
  ide: Simplify success condition
  ide: Avoid preprocessor for CONFIG_ATAPI
  ide: Avoid preprocessor for CONFIG_LBA48
  ide: Move bus init into a function
  ide: Make ide_bus_ok a local variable
  ide: Move setting of vendor strings into ide_probe()
  ide: Move ide_init() entirely within ide_probe()
  ide: Combine the two loops in ide_probe()
  ide: Use desc consistently for struct blk_desc
  ide: Make ide_ident() return an error code
  ide: Move all blk_desc init into ide_ident()
  ide: Use a single local blk_desc for ide_ident()
  ide: Correct LBA setting
  ide: Tidy up ide_reset()
  ide: Convert to use log_debug()
  ide: Simplify expressions and hex values
  ide: Make use of U-Boot types

 cmd/ide.c   |  22 +-
 common/board_r.c|  17 -
 drivers/block/ide.c | 841 
 include/blk.h   |   5 +-
 include/ide.h   |  48 +--
 test/boot/bootdev.c |   2 -
 6 files changed, 415 insertions(+), 520 deletions(-)

-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 01/30] ide: Move ATA_CURR_BASE to C file

2023-04-25 Thread Simon Glass
This is not used outside one C file. Move it out of the header to
reduce its visbility.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 3 +++
 include/ide.h   | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 1ad9b6c1267..f36bec8b3a8 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -36,6 +36,9 @@ ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
 #endif
 };
 
+#define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR + \
+   ide_bus_offset[IDE_BUS(dev)])
+
 static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
 
 struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
diff --git a/include/ide.h b/include/ide.h
index 426cef4e39e..58f6640c61b 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -11,9 +11,6 @@
 
 #define IDE_BUS(dev)   (dev / (CONFIG_SYS_IDE_MAXDEVICE / 
CONFIG_SYS_IDE_MAXBUS))
 
-#defineATA_CURR_BASE(dev)  
(CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)])
-extern ulong ide_bus_offset[];
-
 /*
  * Function Prototypes
  */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 02/30] ide: Use mdelay() for long delays

2023-04-25 Thread Simon Glass
Rather than using very large numbers with udelay(), use mdelay(), which
is easier to follow.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 25 +++--
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index f36bec8b3a8..6f601bcf864 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -71,9 +71,7 @@ static void ide_reset(void)
/* de-assert RESET signal */
ide_set_reset(0);
 
-   /* wait 250 ms */
-   for (i = 0; i < 250; ++i)
-   udelay(1000);
+   mdelay(250);
 }
 #else
 #define ide_reset()/* dummy */
@@ -237,7 +235,7 @@ unsigned char atapi_issue(int device, unsigned char *ccb, 
int ccblen,
ide_output_data_shorts(device, (unsigned short *)ccb, ccblen / 2);
 
/* ATAPI Command written wait for completition */
-   udelay(5000);   /* device must set bsy */
+   mdelay(5);  /* device must set bsy */
 
mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR;
/*
@@ -293,7 +291,7 @@ unsigned char atapi_issue(int device, unsigned char *ccb, 
int ccblen,
  n);
}
}
-   udelay(5000);   /* seems that some CD ROMs need this... */
+   mdelay(5);  /* seems that some CD ROMs need this... */
mask = ATA_STAT_BUSY | ATA_STAT_ERR;
res = 0;
c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
@@ -357,7 +355,7 @@ retry:
 
if ((key == 6) || (asc == 0x29) || (asc == 0x28)) { /* Unit Attention */
if (unitattn-- > 0) {
-   udelay(200 * 1000);
+   mdelay(200);
goto retry;
}
printf("Unit Attention, tried %d\n", ATAPI_UNIT_ATTN);
@@ -366,7 +364,7 @@ retry:
if ((asc == 0x4) && (ascq == 0x1)) {
/* not ready, but will be ready soon */
if (notready-- > 0) {
-   udelay(200 * 1000);
+   mdelay(200);
goto retry;
}
printf("Drive not ready, tried %d times\n",
@@ -586,9 +584,9 @@ static void ide_ident(struct blk_desc *dev_desc)
debug("Retrying...\n");
ide_outb(device, ATA_DEV_HD,
 ATA_LBA | ATA_DEVICE(device));
-   udelay(10);
+   mdelay(100);
ide_outb(device, ATA_COMMAND, 0x08);
-   udelay(50); /* 500 ms */
+   mdelay(500);
}
/*
 * Select device
@@ -715,14 +713,13 @@ void ide_init(void)
 
ide_bus_ok[bus] = 0;
 
-   /* Select device
-*/
-   udelay(10); /* 100 ms */
+   /* Select device */
+   mdelay(100);
ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
-   udelay(10); /* 100 ms */
+   mdelay(100);
i = 0;
do {
-   udelay(1);  /* 10 ms */
+   mdelay(10);
 
c = ide_inb(dev, ATA_STATUS);
i++;
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 03/30] ide: Drop CONFIG_START_IDE

2023-04-25 Thread Simon Glass
This is not used by any board. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/board_r.c | 5 -
 include/ide.h| 7 ---
 2 files changed, 12 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index 6b4180b3ecd..7076af64f5d 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -523,12 +523,7 @@ static int initr_post(void)
 static int initr_ide(void)
 {
puts("IDE:   ");
-#if defined(CONFIG_START_IDE)
-   if (board_start_ide())
-   ide_init();
-#else
ide_init();
-#endif
return 0;
 }
 #endif
diff --git a/include/ide.h b/include/ide.h
index 58f6640c61b..9c0d40364a8 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -47,11 +47,4 @@ void ide_output_data_shorts(int dev, ushort *sect_buf, int 
shorts);
 
 void ide_led(uchar led, uchar status);
 
-/**
- * board_start_ide() - Start up the board IDE interfac
- *
- * Return: 0 if ok
- */
-int board_start_ide(void);
-
 #endif /* _IDE_H */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 04/30] ide: Drop init for not using BLK

2023-04-25 Thread Simon Glass
ALl boards use CONFIG_BLK now so this code is not used. Drop it and the
header-file #ifdef

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/board_r.c | 12 
 include/ide.h|  7 ---
 2 files changed, 19 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index 7076af64f5d..d798c00a80a 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -519,15 +519,6 @@ static int initr_post(void)
 }
 #endif
 
-#if defined(CONFIG_IDE) && !defined(CONFIG_BLK)
-static int initr_ide(void)
-{
-   puts("IDE:   ");
-   ide_init();
-   return 0;
-}
-#endif
-
 #if defined(CFG_PRAM)
 /*
  * Export available size of memory for Linux, taking into account the
@@ -778,9 +769,6 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_POST
initr_post,
 #endif
-#if defined(CONFIG_IDE) && !defined(CONFIG_BLK)
-   initr_ide,
-#endif
 #ifdef CONFIG_LAST_STAGE_INIT
INIT_FUNC_WATCHDOG_RESET
/*
diff --git a/include/ide.h b/include/ide.h
index 9c0d40364a8..457f275c61b 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -18,17 +18,10 @@
 void ide_init(void);
 struct blk_desc;
 struct udevice;
-#ifdef CONFIG_BLK
 ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
   void *buffer);
 ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
const void *buffer);
-#else
-ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
-  void *buffer);
-ulong ide_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
-   const void *buffer);
-#endif
 
 #if defined(CONFIG_OF_IDE_FIXUP)
 int ide_device_present(int dev);
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 06/30] ide: Drop ide_device_present()

2023-04-25 Thread Simon Glass
This function is not used anymore. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 9 -
 include/ide.h   | 4 
 2 files changed, 13 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 13770484b36..b5be022a067 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1012,15 +1012,6 @@ WR_OUT:
return n;
 }
 
-#if defined(CONFIG_OF_IDE_FIXUP)
-int ide_device_present(int dev)
-{
-   if (dev >= CONFIG_SYS_IDE_MAXBUS)
-   return 0;
-   return ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1;
-}
-#endif
-
 static int ide_blk_probe(struct udevice *udev)
 {
struct blk_desc *desc = dev_get_uclass_plat(udev);
diff --git a/include/ide.h b/include/ide.h
index 3f36b4340d0..09b0117879f 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -22,10 +22,6 @@ ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t 
blkcnt,
 ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
const void *buffer);
 
-#if defined(CONFIG_OF_IDE_FIXUP)
-int ide_device_present(int dev);
-#endif
-
 /*
  * I/O function overrides
  */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 05/30] ide: Move ide_init() into probing

2023-04-25 Thread Simon Glass
At present the code does ide_init() as a separate operation, then calls
device_probe() to copy over the information. We can call ide_init() from
probe just as easily.

The only difference is that using 'ide init' twice will do nothing.
However it already fails to copy over the new data in that case, so the
effect is the same. For now, unbind the block devices and remove the IDE
device, which causes the bus to be probed again. Later patches will fix
this up fully, so that all blk_desc data is copied across.

Since ide_reset() is only called from ide_init(), there is no need to init
the ide_dev_desc[] array. This is already done at the end of ide_init() so
drop this code.

The call to uclass_first_device() is now within the probe() function of
the same device, so does nothing. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/ide.c   | 22 +-
 drivers/block/ide.c | 13 ++---
 include/ide.h   |  1 -
 test/boot/bootdev.c |  2 --
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/cmd/ide.c b/cmd/ide.c
index 6739f0b12d1..ddc87d3a0bb 100644
--- a/cmd/ide.c
+++ b/cmd/ide.c
@@ -10,12 +10,15 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -31,8 +34,25 @@ int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
 {
if (argc == 2) {
if (strncmp(argv[1], "res", 3) == 0) {
+   struct udevice *dev;
+   int ret;
+
puts("\nReset IDE: ");
-   ide_init();
+   ret = uclass_find_first_device(UCLASS_IDE, &dev);
+   ret = device_remove(dev, DM_REMOVE_NORMAL);
+   if (!ret)
+   ret = device_chld_unbind(dev, NULL);
+   if (ret) {
+   printf("Cannot remove IDE (err=%dE)\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   ret = uclass_first_device_err(UCLASS_IDE, &dev);
+   if (ret) {
+   printf("Init failed (err=%dE)\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
return 0;
}
}
diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 6f601bcf864..13770484b36 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -58,8 +58,6 @@ static void ide_reset(void)
 
for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i)
ide_bus_ok[i] = 0;
-   for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i)
-   ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
 
ide_set_reset(1);   /* assert reset */
 
@@ -689,9 +687,8 @@ __weak unsigned char ide_inb(int dev, int port)
return val;
 }
 
-void ide_init(void)
+static void ide_init(void)
 {
-   struct udevice *dev;
unsigned char c;
int i, bus;
 
@@ -764,8 +761,6 @@ void ide_init(void)
dev_print(&ide_dev_desc[i]);
}
schedule();
-
-   uclass_first_device(UCLASS_IDE, &dev);
 }
 
 __weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
@@ -1067,7 +1062,9 @@ static int ide_bootdev_bind(struct udevice *dev)
 
 static int ide_bootdev_hunt(struct bootdev_hunter *info, bool show)
 {
-   ide_init();
+   struct udevice *dev;
+
+   uclass_first_device(UCLASS_IDE, &dev);
 
return 0;
 }
@@ -1104,6 +1101,8 @@ static int ide_probe(struct udevice *udev)
int i;
int ret;
 
+   ide_init();
+
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
sprintf(name, "blk#%d", i);
diff --git a/include/ide.h b/include/ide.h
index 457f275c61b..3f36b4340d0 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -15,7 +15,6 @@
  * Function Prototypes
  */
 
-void ide_init(void);
 struct blk_desc;
 struct udevice;
 ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index 4fe9fd72208..365b7f518ab 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -376,7 +376,6 @@ static int bootdev_test_cmd_hunt(struct unit_test_state 
*uts)
ut_assert_nextline("Hunting with: simple_bus");
ut_assert_nextline("Found 2 extension board(s).");
ut_assert_nextline("Hunting with: ide");
-   ut_assert_nextline("Bus 0: not available  ");
 
/* mmc hunter has already been used so should not run again */
 
@@ -487,7 +486,6 @@ static int bootdev_test_hunt_prio(struct unit_test_state 
*uts)
/* now try a different priority, verbosely */
ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true));
ut_assert_nextline("Hunting with: ide");
-   ut_assert_nextline("

[PATCH v2 07/30] ide: Move a few functions further up the file

2023-04-25 Thread Simon Glass
Move these functions so they appear before they are used.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 68 ++---
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index b5be022a067..58f1ef8f177 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -75,6 +75,40 @@ static void ide_reset(void)
 #define ide_reset()/* dummy */
 #endif /* CONFIG_IDE_RESET */
 
+__weak void ide_outb(int dev, int port, unsigned char val)
+{
+   debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
+ dev, port, val, ATA_CURR_BASE(dev) + port);
+
+   outb(val, ATA_CURR_BASE(dev) + port);
+}
+
+__weak unsigned char ide_inb(int dev, int port)
+{
+   uchar val;
+
+   val = inb(ATA_CURR_BASE(dev) + port);
+
+   debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
+ dev, port, ATA_CURR_BASE(dev) + port, val);
+   return val;
+}
+
+__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+   uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+   ushort *dbuf = (ushort *)sect_buf;
+
+   debug("in input swap data base for read is %p\n", (void *)paddr);
+
+   while (words--) {
+   EIEIO;
+   *dbuf++ = be16_to_cpu(inw(paddr));
+   EIEIO;
+   *dbuf++ = be16_to_cpu(inw(paddr));
+   }
+}
+
 /*
  * Wait until Busy bit is off, or timeout (in ms)
  * Return last status
@@ -668,25 +702,6 @@ static void ide_ident(struct blk_desc *dev_desc)
 #endif
 }
 
-__weak void ide_outb(int dev, int port, unsigned char val)
-{
-   debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
- dev, port, val, ATA_CURR_BASE(dev) + port);
-
-   outb(val, ATA_CURR_BASE(dev) + port);
-}
-
-__weak unsigned char ide_inb(int dev, int port)
-{
-   uchar val;
-
-   val = inb(ATA_CURR_BASE(dev) + port);
-
-   debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
- dev, port, ATA_CURR_BASE(dev) + port, val);
-   return val;
-}
-
 static void ide_init(void)
 {
unsigned char c;
@@ -763,21 +778,6 @@ static void ide_init(void)
schedule();
 }
 
-__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
-{
-   uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-   ushort *dbuf = (ushort *)sect_buf;
-
-   debug("in input swap data base for read is %p\n", (void *)paddr);
-
-   while (words--) {
-   EIEIO;
-   *dbuf++ = be16_to_cpu(inw(paddr));
-   EIEIO;
-   *dbuf++ = be16_to_cpu(inw(paddr));
-   }
-}
-
 __weak void ide_output_data(int dev, const ulong *sect_buf, int words)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 08/30] ide: Drop weak functions

2023-04-25 Thread Simon Glass
These are not used from outside this file anymore. Make them static and
remove them from the header file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 14 +++---
 include/ide.h   | 13 -
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 58f1ef8f177..46e110fec5e 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -75,7 +75,7 @@ static void ide_reset(void)
 #define ide_reset()/* dummy */
 #endif /* CONFIG_IDE_RESET */
 
-__weak void ide_outb(int dev, int port, unsigned char val)
+static void ide_outb(int dev, int port, unsigned char val)
 {
debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
  dev, port, val, ATA_CURR_BASE(dev) + port);
@@ -83,7 +83,7 @@ __weak void ide_outb(int dev, int port, unsigned char val)
outb(val, ATA_CURR_BASE(dev) + port);
 }
 
-__weak unsigned char ide_inb(int dev, int port)
+static unsigned char ide_inb(int dev, int port)
 {
uchar val;
 
@@ -94,7 +94,7 @@ __weak unsigned char ide_inb(int dev, int port)
return val;
 }
 
-__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+static void ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
ushort *dbuf = (ushort *)sect_buf;
@@ -164,7 +164,7 @@ OUT:
 
 /* since ATAPI may use commands with not 4 bytes alligned length
  * we have our own transfer functions, 2 bytes alligned */
-__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+static void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
ushort *dbuf;
@@ -179,7 +179,7 @@ __weak void ide_output_data_shorts(int dev, ushort 
*sect_buf, int shorts)
}
 }
 
-__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+static void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
ushort *dbuf;
@@ -778,7 +778,7 @@ static void ide_init(void)
schedule();
 }
 
-__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
+static void ide_output_data(int dev, const ulong *sect_buf, int words)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
ushort *dbuf;
@@ -792,7 +792,7 @@ __weak void ide_output_data(int dev, const ulong *sect_buf, 
int words)
}
 }
 
-__weak void ide_input_data(int dev, ulong *sect_buf, int words)
+static void ide_input_data(int dev, ulong *sect_buf, int words)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
ushort *dbuf;
diff --git a/include/ide.h b/include/ide.h
index 09b0117879f..8c0eb2a022f 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -22,17 +22,4 @@ ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t 
blkcnt,
 ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
const void *buffer);
 
-/*
- * I/O function overrides
- */
-unsigned char ide_inb(int dev, int port);
-void ide_outb(int dev, int port, unsigned char val);
-void ide_input_swap_data(int dev, ulong *sect_buf, int words);
-void ide_input_data(int dev, ulong *sect_buf, int words);
-void ide_output_data(int dev, const ulong *sect_buf, int words);
-void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts);
-void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts);
-
-void ide_led(uchar led, uchar status);
-
 #endif /* _IDE_H */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 09/30] ide: Create a prototype for ide_set_reset()

2023-04-25 Thread Simon Glass
This is used by a board so should be in the header file. Add it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c |  2 --
 include/ide.h   | 10 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 46e110fec5e..fa5f68ffeb0 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -50,8 +50,6 @@ struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
 #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
 
 #ifdef CONFIG_IDE_RESET
-extern void ide_set_reset(int idereset);
-
 static void ide_reset(void)
 {
int i;
diff --git a/include/ide.h b/include/ide.h
index 8c0eb2a022f..b586ba3df4b 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -22,4 +22,14 @@ ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t 
blkcnt,
 ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
const void *buffer);
 
+/**
+ * ide_set_reset() - Assert or de-assert reset for the IDE device
+ *
+ * This is provided by boards which need to reset the device through another
+ * means, e.g. a GPIO.
+ *
+ * @idereset: 1 to assert reset, 0 to de-assert it
+ */
+void ide_set_reset(int idereset);
+
 #endif /* _IDE_H */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 10/30] ide: Correct use of ATAPI

2023-04-25 Thread Simon Glass
The use of atapi_read() was incorrect dropped. Fix this so that it will
be used when needed. Use a udevice for the first argument of atapi_read()
so it is consistent with ide_read().

This requires much of the ATAPI code to be brought out from behind the
existing #ifdef. It will still be removed by the compiler if it is not
needed.

Add an atapi flag to struct blk_desc so the information can be retained.

Fixes: 145df842b44 ("dm: ide: Add support for driver-model block devices")
Fixes: d0075059e4d ("ide: Drop non-DM code for BLK")
Reviewed-by: Mattijs Korpershoek 

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 20 +---
 include/blk.h   |  1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index fa5f68ffeb0..875192cba16 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -155,7 +155,6 @@ OUT:
*last = '\0';
 }
 
-#ifdef CONFIG_ATAPI
 /
  * ATAPI Support
  */
@@ -422,9 +421,10 @@ error:
 #define ATAPI_READ_BLOCK_SIZE  2048/* assuming CD part */
 #define ATAPI_READ_MAX_BLOCK   (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
 
-ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 void *buffer)
 {
+   struct blk_desc *block_dev = dev_get_uclass_plat(dev);
int device = block_dev->devnum;
ulong n = 0;
unsigned char ccb[12];  /* Command descriptor block */
@@ -466,6 +466,8 @@ ulong atapi_read(struct blk_desc *block_dev, lbaint_t 
blknr, lbaint_t blkcnt,
return n;
 }
 
+#ifdef CONFIG_ATAPI
+
 static void atapi_inquiry(struct blk_desc *dev_desc)
 {
unsigned char ccb[12];  /* Command descriptor block */
@@ -653,6 +655,7 @@ static void ide_ident(struct blk_desc *dev_desc)
 
 #ifdef CONFIG_ATAPI
if (is_atapi) {
+   dev_desc->atapi = true;
atapi_inquiry(dev_desc);
return;
}
@@ -1010,6 +1013,17 @@ WR_OUT:
return n;
 }
 
+ulong ide_or_atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
+   void *buffer)
+{
+   struct blk_desc *desc = dev_get_uclass_plat(dev);
+
+   if (IS_ENABLED(CONFIG_ATAPI) && desc->atapi)
+   return atapi_read(dev, blknr, blkcnt, buffer);
+
+   return ide_read(dev, blknr, blkcnt, buffer);
+}
+
 static int ide_blk_probe(struct udevice *udev)
 {
struct blk_desc *desc = dev_get_uclass_plat(udev);
@@ -1029,7 +1043,7 @@ static int ide_blk_probe(struct udevice *udev)
 }
 
 static const struct blk_ops ide_blk_ops = {
-   .read   = ide_read,
+   .read   = ide_or_atapi_read,
.write  = ide_write,
 };
 
diff --git a/include/blk.h b/include/blk.h
index 1db203c1bab..871922dcde0 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -66,6 +66,7 @@ struct blk_desc {
/* device can use 48bit addr (ATA/ATAPI v7) */
unsigned char   lba48;
 #endif
+   unsigned char   atapi;  /* Use ATAPI protocol */
lbaint_tlba;/* number of blocks */
unsigned long   blksz;  /* block size */
int log2blksz;  /* for convenience: log2(blksz) */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 12/30] ide: Change the retries variable

2023-04-25 Thread Simon Glass
Use a 'tries' variable which starts at the number of tries we want to do,
rather than a 'retries' one that stops at either 1 or 2. This will make it
easier to refactor the code to avoid the horrible #ifdefs

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 1d5e54d6eb9..782780fd302 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -557,7 +557,7 @@ static void ide_ident(struct blk_desc *dev_desc)
hd_driveid_t iop;
 #ifdef CONFIG_ATAPI
bool is_atapi = false;
-   int retries = 0;
+   int tries = 1;
 #endif
int device;
 
@@ -570,10 +570,10 @@ static void ide_ident(struct blk_desc *dev_desc)
dev_desc->uclass_id = UCLASS_IDE;
 #ifdef CONFIG_ATAPI
 
-   retries = 0;
+   tries = 2;
 
/* Warning: This will be tricky to read */
-   while (retries <= 1) {
+   while (tries) {
/* check signature */
if ((ide_inb(device, ATA_SECT_CNT) == 0x01) &&
(ide_inb(device, ATA_SECT_NUM) == 0x01) &&
@@ -624,7 +624,7 @@ static void ide_ident(struct blk_desc *dev_desc)
 */
ide_outb(device, ATA_DEV_HD,
 ATA_LBA | ATA_DEVICE(device));
-   retries++;
+   tries--;
 #else
return;
 #endif
@@ -634,7 +634,7 @@ static void ide_ident(struct blk_desc *dev_desc)
break;
}   /* see above - ugly to read */
 
-   if (retries == 2)   /* Not found */
+   if (!tries) /* Not found */
return;
 #endif
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 11/30] ide: Make function static

2023-04-25 Thread Simon Glass
Only one function is called from outside this file. Make all the others
static.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 23 +++
 include/ide.h   | 11 ---
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 875192cba16..1d5e54d6eb9 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -219,8 +219,8 @@ static uchar atapi_wait_mask(int dev, ulong t, uchar mask, 
uchar res)
 /*
  * issue an atapi command
  */
-unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
- unsigned char *buffer, int buflen)
+static unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
+unsigned char *buffer, int buflen)
 {
unsigned char c, err, mask, res;
int n;
@@ -343,10 +343,9 @@ AI_OUT:
 #define ATAPI_DRIVE_NOT_READY  100
 #define ATAPI_UNIT_ATTN10
 
-unsigned char atapi_issue_autoreq(int device,
- unsigned char *ccb,
- int ccblen,
- unsigned char *buffer, int buflen)
+static unsigned char atapi_issue_autoreq(int device, unsigned char *ccb,
+int ccblen,
+unsigned char *buffer, int buflen)
 {
unsigned char sense_data[18], sense_ccb[12];
unsigned char res, key, asc, ascq;
@@ -421,8 +420,8 @@ error:
 #define ATAPI_READ_BLOCK_SIZE  2048/* assuming CD part */
 #define ATAPI_READ_MAX_BLOCK   (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
 
-ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
-void *buffer)
+static ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
+   void *buffer)
 {
struct blk_desc *block_dev = dev_get_uclass_plat(dev);
int device = block_dev->devnum;
@@ -810,8 +809,8 @@ static void ide_input_data(int dev, ulong *sect_buf, int 
words)
}
 }
 
-ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
-  void *buffer)
+static ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
+ void *buffer)
 {
struct blk_desc *block_dev = dev_get_uclass_plat(dev);
int device = block_dev->devnum;
@@ -930,8 +929,8 @@ IDE_READ_E:
return n;
 }
 
-ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
-   const void *buffer)
+static ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
+  const void *buffer)
 {
struct blk_desc *block_dev = dev_get_uclass_plat(dev);
int device = block_dev->devnum;
diff --git a/include/ide.h b/include/ide.h
index b586ba3df4b..2c25e74ede0 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -11,17 +11,6 @@
 
 #define IDE_BUS(dev)   (dev / (CONFIG_SYS_IDE_MAXDEVICE / 
CONFIG_SYS_IDE_MAXBUS))
 
-/*
- * Function Prototypes
- */
-
-struct blk_desc;
-struct udevice;
-ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
-  void *buffer);
-ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
-   const void *buffer);
-
 /**
  * ide_set_reset() - Assert or de-assert reset for the IDE device
  *
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 13/30] ide: Refactor confusing loop code

2023-04-25 Thread Simon Glass
This code is hard to follow as it uses #ifdef in a strange way. Adjust
it to avoid the preprocessor. Drop the special return for the non-ATAPI
case since we can rely on tries becoming 0 and exiting the loop.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 43 +++
 1 file changed, 15 insertions(+), 28 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 782780fd302..2f45bb6bffb 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -555,10 +555,8 @@ static void ide_ident(struct blk_desc *dev_desc)
 {
unsigned char c;
hd_driveid_t iop;
-#ifdef CONFIG_ATAPI
bool is_atapi = false;
int tries = 1;
-#endif
int device;
 
device = dev_desc->devnum;
@@ -568,17 +566,16 @@ static void ide_ident(struct blk_desc *dev_desc)
 */
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
dev_desc->uclass_id = UCLASS_IDE;
-#ifdef CONFIG_ATAPI
+   if (IS_ENABLED(CONFIG_ATAPI))
+   tries = 2;
 
-   tries = 2;
-
-   /* Warning: This will be tricky to read */
while (tries) {
/* check signature */
-   if ((ide_inb(device, ATA_SECT_CNT) == 0x01) &&
-   (ide_inb(device, ATA_SECT_NUM) == 0x01) &&
-   (ide_inb(device, ATA_CYL_LOW) == 0x14) &&
-   (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) {
+   if (IS_ENABLED(CONFIG_ATAPI) &&
+   ide_inb(device, ATA_SECT_CNT) == 0x01 &&
+   ide_inb(device, ATA_SECT_NUM) == 0x01 &&
+   ide_inb(device, ATA_CYL_LOW) == 0x14 &&
+   ide_inb(device, ATA_CYL_HIGH) == 0xeb) {
/* ATAPI Signature found */
is_atapi = true;
/*
@@ -590,9 +587,7 @@ static void ide_ident(struct blk_desc *dev_desc)
 * to become ready
 */
c = ide_wait(device, ATAPI_TIME_OUT);
-   } else
-#endif
-   {
+   } else {
/*
 * Start Ident Command
 */
@@ -606,8 +601,7 @@ static void ide_ident(struct blk_desc *dev_desc)
 
if (((c & ATA_STAT_DRQ) == 0) ||
((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) {
-#ifdef CONFIG_ATAPI
-   {
+   if (IS_ENABLED(CONFIG_ATAPI)) {
/*
 * Need to soft reset the device
 * in case it's an ATAPI...
@@ -618,25 +612,18 @@ static void ide_ident(struct blk_desc *dev_desc)
mdelay(100);
ide_outb(device, ATA_COMMAND, 0x08);
mdelay(500);
+   /* Select device */
+   ide_outb(device, ATA_DEV_HD,
+ATA_LBA | ATA_DEVICE(device));
}
-   /*
-* Select device
-*/
-   ide_outb(device, ATA_DEV_HD,
-ATA_LBA | ATA_DEVICE(device));
tries--;
-#else
-   return;
-#endif
-   }
-#ifdef CONFIG_ATAPI
-   else
+   } else {
break;
-   }   /* see above - ugly to read */
+   }
+   }
 
if (!tries) /* Not found */
return;
-#endif
 
ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 14/30] ide: Simplify success condition

2023-04-25 Thread Simon Glass
Change the if() to remove extra brackets and check for the positive case
first, i.e. when a device is found. Exit the loop in that case, with the
retry logic in the 'else' part.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 36 +---
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 2f45bb6bffb..a51a0008cae 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -599,27 +599,25 @@ static void ide_ident(struct blk_desc *dev_desc)
c = ide_wait(device, IDE_TIME_OUT);
}
 
-   if (((c & ATA_STAT_DRQ) == 0) ||
-   ((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) {
-   if (IS_ENABLED(CONFIG_ATAPI)) {
-   /*
-* Need to soft reset the device
-* in case it's an ATAPI...
-*/
-   debug("Retrying...\n");
-   ide_outb(device, ATA_DEV_HD,
-ATA_LBA | ATA_DEVICE(device));
-   mdelay(100);
-   ide_outb(device, ATA_COMMAND, 0x08);
-   mdelay(500);
-   /* Select device */
-   ide_outb(device, ATA_DEV_HD,
-ATA_LBA | ATA_DEVICE(device));
-   }
-   tries--;
-   } else {
+   if ((c & ATA_STAT_DRQ) &&
+   !(c & (ATA_STAT_FAULT | ATA_STAT_ERR))) {
break;
+   } else if (IS_ENABLED(CONFIG_ATAPI)) {
+   /*
+* Need to soft reset the device
+* in case it's an ATAPI...
+*/
+   debug("Retrying...\n");
+   ide_outb(device, ATA_DEV_HD,
+ATA_LBA | ATA_DEVICE(device));
+   mdelay(100);
+   ide_outb(device, ATA_COMMAND, 0x08);
+   mdelay(500);
+   /* Select device */
+   ide_outb(device, ATA_DEV_HD,
+ATA_LBA | ATA_DEVICE(device));
}
+   tries--;
}
 
if (!tries) /* Not found */
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 16/30] ide: Avoid preprocessor for CONFIG_LBA48

2023-04-25 Thread Simon Glass
Use IS_ENABLED() instead for all conditions. Add the 'lba48' flag into
struct blk_desc always, since it uses very little space. Use a bool so
the meaning is clearer.

Signed-off-by: Simon Glass 
Reviewed-by: Mattijs Korpershoek 
---

(no changes since v1)

 drivers/block/ide.c | 57 -
 include/blk.h   |  4 +---
 2 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 6c5227a5c0e..45201333c3c 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -540,11 +540,9 @@ static void atapi_inquiry(struct blk_desc *dev_desc)
((unsigned long) iobuf[5] << 16) +
((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
dev_desc->log2blksz = LOG2(dev_desc->blksz);
-#ifdef CONFIG_LBA48
+
/* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
-   dev_desc->lba48 = 0;
-#endif
-   return;
+   dev_desc->lba48 = false;
 }
 
 static void ide_ident(struct blk_desc *dev_desc)
@@ -645,9 +643,9 @@ static void ide_ident(struct blk_desc *dev_desc)
((unsigned long)iop.lba_capacity[0]) |
((unsigned long)iop.lba_capacity[1] << 16);
 
-#ifdef CONFIG_LBA48
-   if (iop.command_set_2 & 0x0400) {   /* LBA 48 support */
-   dev_desc->lba48 = 1;
+   if (IS_ENABLED(CONFIG_LBA48) && (iop.command_set_2 & 0x0400)) {
+   /* LBA 48 support */
+   dev_desc->lba48 = true;
for (int i = 0; i < 4; i++)
iop.lba48_capacity[i] = 
be16_to_cpu(iop.lba48_capacity[i]);
dev_desc->lba =
@@ -656,9 +654,9 @@ static void ide_ident(struct blk_desc *dev_desc)
((unsigned long long)iop.lba48_capacity[2] << 32) |
((unsigned long long)iop.lba48_capacity[3] << 48));
} else {
-   dev_desc->lba48 = 0;
+   dev_desc->lba48 = false;
}
-#endif /* CONFIG_LBA48 */
+
/* assuming HD */
dev_desc->type = DEV_TYPE_HARDDISK;
dev_desc->blksz = ATA_BLOCKSIZE;
@@ -795,15 +793,13 @@ static ulong ide_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
ulong n = 0;
unsigned char c;
unsigned char pwrsave = 0;  /* power save */
+   bool lba48 = false;
 
-#ifdef CONFIG_LBA48
-   unsigned char lba48 = 0;
-
-   if (blknr & 0xf000ULL) {
+   if (IS_ENABLED(CONFIG_LBA48) && (blknr & 0xf000ULL)) {
/* more than 28 bits used, use 48bit mode */
-   lba48 = 1;
+   lba48 = true;
}
-#endif
+
debug("ide_read dev %d start " LBAF ", blocks " LBAF " buffer at %lX\n",
  device, blknr, blkcnt, (ulong) buffer);
 
@@ -845,8 +841,7 @@ static ulong ide_read(struct udevice *dev, lbaint_t blknr, 
lbaint_t blkcnt,
printf("IDE read: device %d not ready\n", device);
break;
}
-#ifdef CONFIG_LBA48
-   if (lba48) {
+   if (IS_ENABLED(CONFIG_LBA48) && lba48) {
/* write high bits */
ide_outb(device, ATA_SECT_CNT, 0);
ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF);
@@ -858,21 +853,17 @@ static ulong ide_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
ide_outb(device, ATA_LBA_HIGH, 0);
 #endif
}
-#endif
ide_outb(device, ATA_SECT_CNT, 1);
ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF);
ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF);
ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF);
 
-#ifdef CONFIG_LBA48
-   if (lba48) {
+   if (IS_ENABLED(CONFIG_LBA48) && lba48) {
ide_outb(device, ATA_DEV_HD,
 ATA_LBA | ATA_DEVICE(device));
ide_outb(device, ATA_COMMAND, ATA_CMD_PIO_READ_EXT);
 
-   } else
-#endif
-   {
+   } else {
ide_outb(device, ATA_DEV_HD, ATA_LBA |
 ATA_DEVICE(device) | ((blknr >> 24) & 0xF));
ide_outb(device, ATA_COMMAND, ATA_CMD_PIO_READ);
@@ -914,15 +905,12 @@ static ulong ide_write(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
int device = block_dev->devnum;
ulong n = 0;
unsigned char c;
+   bool lba48 = false;
 
-#ifdef CONFIG_LBA48
-   unsigned char lba48 = 0;
-
-   if (blknr & 0xf000ULL) {
+   if (IS_ENABLED(CONFIG_LBA48) && (blknr & 0xf000ULL)) {
/* more than 28 bits used, use 48bit mode */
-   lba48 = 1;
+   lba48 = true;
}
-#endif
 
/* Select device
 */
@@ -935,8 +923,7 @@ static ulong ide_write(

[PATCH v2 17/30] ide: Move bus init into a function

2023-04-25 Thread Simon Glass
Move this code into a separate function which returns whether the bus was
found, or not.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 87 +
 1 file changed, 48 insertions(+), 39 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 45201333c3c..aac4462f57b 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -679,9 +679,55 @@ static void ide_ident(struct blk_desc *dev_desc)
 #endif
 }
 
+/**
+ * ide_init_one() - Init one IDE device
+ *
+ * @bus: Bus to use
+ * Return: 0 iuf OK, -EIO if not available, -ETIMEDOUT if timed out
+ */
+static int ide_init_one(int bus)
+{
+   int dev = bus * CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS;
+   int i;
+   u8 c;
+
+   printf("Bus %d: ", bus);
+
+   /* Select device */
+   mdelay(100);
+   ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
+   mdelay(100);
+   i = 0;
+   do {
+   mdelay(10);
+
+   c = ide_inb(dev, ATA_STATUS);
+   i++;
+   if (i > (ATA_RESET_TIME * 100)) {
+   puts("** Timeout **\n");
+   return -ETIMEDOUT;
+   }
+   if (i >= 100 && !(i % 100))
+   putc('.');
+   } while (c & ATA_STAT_BUSY);
+
+   if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
+   puts("not available  ");
+   debug("Status = 0x%02X ", c);
+   return -EIO;
+   } else if (IS_ENABLED(CONFIG_ATAPI) && !(c & ATA_STAT_READY)) {
+   /* ATAPI Devices do not set DRDY */
+   puts("not available  ");
+   debug("Status = 0x%02X ", c);
+   return -EIO;
+   }
+   puts("OK ");
+
+   return 0;
+}
+
 static void ide_init(void)
 {
-   unsigned char c;
int i, bus;
 
schedule();
@@ -694,44 +740,7 @@ static void ide_init(void)
 * According to spec, this can take up to 31 seconds!
 */
for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
-   int dev =
-   bus * (CONFIG_SYS_IDE_MAXDEVICE /
-  CONFIG_SYS_IDE_MAXBUS);
-
-   printf("Bus %d: ", bus);
-
-   ide_bus_ok[bus] = 0;
-
-   /* Select device */
-   mdelay(100);
-   ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev));
-   mdelay(100);
-   i = 0;
-   do {
-   mdelay(10);
-
-   c = ide_inb(dev, ATA_STATUS);
-   i++;
-   if (i > (ATA_RESET_TIME * 100)) {
-   puts("** Timeout **\n");
-   return;
-   }
-   if ((i >= 100) && ((i % 100) == 0))
-   putc('.');
-
-   } while (c & ATA_STAT_BUSY);
-
-   if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
-   puts("not available  ");
-   debug("Status = 0x%02X ", c);
-   } else if (IS_ENABLED(CONFIG_ATAPI) && !(c & ATA_STAT_READY)) {
-   /* ATAPI Devices do not set DRDY */
-   puts("not available  ");
-   debug("Status = 0x%02X ", c);
-   } else {
-   puts("OK ");
-   ide_bus_ok[bus] = 1;
-   }
+   ide_bus_ok[bus] = !ide_init_one(bus);
schedule();
}
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 15/30] ide: Avoid preprocessor for CONFIG_ATAPI

2023-04-25 Thread Simon Glass
Use IS_ENABLED() instead for all conditions.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index a51a0008cae..6c5227a5c0e 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -465,8 +465,6 @@ static ulong atapi_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
return n;
 }
 
-#ifdef CONFIG_ATAPI
-
 static void atapi_inquiry(struct blk_desc *dev_desc)
 {
unsigned char ccb[12];  /* Command descriptor block */
@@ -549,8 +547,6 @@ static void atapi_inquiry(struct blk_desc *dev_desc)
return;
 }
 
-#endif /* CONFIG_ATAPI */
-
 static void ide_ident(struct blk_desc *dev_desc)
 {
unsigned char c;
@@ -637,13 +633,11 @@ static void ide_ident(struct blk_desc *dev_desc)
else
dev_desc->removable = 0;
 
-#ifdef CONFIG_ATAPI
-   if (is_atapi) {
+   if (IS_ENABLED(CONFIG_ATAPI) && is_atapi) {
dev_desc->atapi = true;
atapi_inquiry(dev_desc);
return;
}
-#endif /* CONFIG_ATAPI */
 
iop.lba_capacity[0] = be16_to_cpu(iop.lba_capacity[0]);
iop.lba_capacity[1] = be16_to_cpu(iop.lba_capacity[1]);
@@ -732,11 +726,10 @@ static void ide_init(void)
if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) {
puts("not available  ");
debug("Status = 0x%02X ", c);
-#ifndef CONFIG_ATAPI   /* ATAPI Devices do not set DRDY */
-   } else if ((c & ATA_STAT_READY) == 0) {
+   } else if (IS_ENABLED(CONFIG_ATAPI) && !(c & ATA_STAT_READY)) {
+   /* ATAPI Devices do not set DRDY */
puts("not available  ");
debug("Status = 0x%02X ", c);
-#endif
} else {
puts("OK ");
ide_bus_ok[bus] = 1;
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 18/30] ide: Make ide_bus_ok a local variable

2023-04-25 Thread Simon Glass
This is only used in one place now, so make it a local variable.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop [] in patch subject

 drivers/block/ide.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index aac4462f57b..36c726225d0 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -39,8 +39,6 @@ ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
 #define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR + \
ide_bus_offset[IDE_BUS(dev)])
 
-static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
-
 struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
 
 #define IDE_TIME_OUT   2000/* 2 sec timeout */
@@ -52,11 +50,6 @@ struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
 #ifdef CONFIG_IDE_RESET
 static void ide_reset(void)
 {
-   int i;
-
-   for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i)
-   ide_bus_ok[i] = 0;
-
ide_set_reset(1);   /* assert reset */
 
/* the reset signal shall be asserted for et least 25 us */
@@ -728,6 +721,7 @@ static int ide_init_one(int bus)
 
 static void ide_init(void)
 {
+   bool bus_ok[CONFIG_SYS_IDE_MAXBUS];
int i, bus;
 
schedule();
@@ -740,7 +734,7 @@ static void ide_init(void)
 * According to spec, this can take up to 31 seconds!
 */
for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
-   ide_bus_ok[bus] = !ide_init_one(bus);
+   bus_ok[bus] = !ide_init_one(bus);
schedule();
}
 
@@ -755,7 +749,7 @@ static void ide_init(void)
ide_dev_desc[i].log2blksz =
LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
ide_dev_desc[i].lba = 0;
-   if (!ide_bus_ok[IDE_BUS(i)])
+   if (!bus_ok[IDE_BUS(i)])
continue;
ide_ident(&ide_dev_desc[i]);
dev_print(&ide_dev_desc[i]);
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 19/30] ide: Move setting of vendor strings into ide_probe()

2023-04-25 Thread Simon Glass
The current implementation adds this information in the block device's
probe() function, which is called in the blk_probe_or_unbind() in
ide_probe().

It is simpler to do this in ide_probe() itself, since the effect is the
same. This helps to consolidate use of ide_dev_desc[] which we would like
to remove.

Use strlcpy() to keep checkpatch happy.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 42 ++
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 36c726225d0..ecac8b6cfd5 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -987,24 +987,6 @@ ulong ide_or_atapi_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
return ide_read(dev, blknr, blkcnt, buffer);
 }
 
-static int ide_blk_probe(struct udevice *udev)
-{
-   struct blk_desc *desc = dev_get_uclass_plat(udev);
-
-   /* fill in device vendor/product/rev strings */
-   strncpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
-   BLK_VEN_SIZE);
-   desc->vendor[BLK_VEN_SIZE] = '\0';
-   strncpy(desc->product, ide_dev_desc[desc->devnum].product,
-   BLK_PRD_SIZE);
-   desc->product[BLK_PRD_SIZE] = '\0';
-   strncpy(desc->revision, ide_dev_desc[desc->devnum].revision,
-   BLK_REV_SIZE);
-   desc->revision[BLK_REV_SIZE] = '\0';
-
-   return 0;
-}
-
 static const struct blk_ops ide_blk_ops = {
.read   = ide_or_atapi_read,
.write  = ide_write,
@@ -1014,7 +996,6 @@ U_BOOT_DRIVER(ide_blk) = {
.name   = "ide_blk",
.id = UCLASS_BLK,
.ops= &ide_blk_ops,
-   .probe  = ide_blk_probe,
 };
 
 static int ide_bootdev_bind(struct udevice *dev)
@@ -1060,17 +1041,19 @@ BOOTDEV_HUNTER(ide_bootdev_hunter) = {
 
 static int ide_probe(struct udevice *udev)
 {
-   struct udevice *blk_dev;
-   char name[20];
-   int blksz;
-   lbaint_t size;
int i;
-   int ret;
 
ide_init();
 
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
+   struct udevice *blk_dev;
+   struct blk_desc *desc;
+   lbaint_t size;
+   char name[20];
+   int blksz;
+   int ret;
+
sprintf(name, "blk#%d", i);
 
blksz = ide_dev_desc[i].blksz;
@@ -1095,6 +1078,17 @@ static int ide_probe(struct udevice *udev)
ret = bootdev_setup_for_dev(udev, "ide_bootdev");
if (ret)
return log_msg_ret("bootdev", ret);
+
+   /* fill in device vendor/product/rev strings */
+   desc = dev_get_uclass_plat(blk_dev);
+   strlcpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
+   BLK_VEN_SIZE);
+   strlcpy(desc->product,
+   ide_dev_desc[desc->devnum].product,
+   BLK_PRD_SIZE);
+   strlcpy(desc->revision,
+   ide_dev_desc[desc->devnum].revision,
+   BLK_REV_SIZE);
}
}
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 21/30] ide: Combine the two loops in ide_probe()

2023-04-25 Thread Simon Glass
The two loops in this function operate on the same ide_dev_desc[] array.
Combine them to reduce duplication.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 5fbf144da9d..d682d6ad9e6 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1021,7 +1021,12 @@ static int ide_probe(struct udevice *udev)
 
putc('\n');
 
-   for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
+   schedule();
+
+   for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
+   if (!bus_ok[IDE_BUS(i)])
+   continue;
+
ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
ide_dev_desc[i].uclass_id = UCLASS_IDE;
ide_dev_desc[i].devnum = i;
@@ -1030,14 +1035,9 @@ static int ide_probe(struct udevice *udev)
ide_dev_desc[i].log2blksz =
LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
ide_dev_desc[i].lba = 0;
-   if (!bus_ok[IDE_BUS(i)])
-   continue;
ide_ident(&ide_dev_desc[i]);
dev_print(&ide_dev_desc[i]);
-   }
-   schedule();
 
-   for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
struct udevice *blk_dev;
struct blk_desc *desc;
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 20/30] ide: Move ide_init() entirely within ide_probe()

2023-04-25 Thread Simon Glass
Now that ide_probe() is the only caller of ide_init(), move all the code
into the probe function, so it is easier to refactor it.

Move ide_dev_desc[] into ide_probe() to, since it is the only user.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 84 -
 1 file changed, 38 insertions(+), 46 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index ecac8b6cfd5..5fbf144da9d 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -39,8 +39,6 @@ ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
 #define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR + \
ide_bus_offset[IDE_BUS(dev)])
 
-struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
-
 #define IDE_TIME_OUT   2000/* 2 sec timeout */
 
 #define ATAPI_TIME_OUT 7000/* 7 sec timeout (5 sec seems to work...) */
@@ -719,44 +717,6 @@ static int ide_init_one(int bus)
return 0;
 }
 
-static void ide_init(void)
-{
-   bool bus_ok[CONFIG_SYS_IDE_MAXBUS];
-   int i, bus;
-
-   schedule();
-
-   /* ATAPI Drives seems to need a proper IDE Reset */
-   ide_reset();
-
-   /*
-* Wait for IDE to get ready.
-* According to spec, this can take up to 31 seconds!
-*/
-   for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
-   bus_ok[bus] = !ide_init_one(bus);
-   schedule();
-   }
-
-   putc('\n');
-
-   for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
-   ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
-   ide_dev_desc[i].uclass_id = UCLASS_IDE;
-   ide_dev_desc[i].devnum = i;
-   ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
-   ide_dev_desc[i].blksz = 0;
-   ide_dev_desc[i].log2blksz =
-   LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
-   ide_dev_desc[i].lba = 0;
-   if (!bus_ok[IDE_BUS(i)])
-   continue;
-   ide_ident(&ide_dev_desc[i]);
-   dev_print(&ide_dev_desc[i]);
-   }
-   schedule();
-}
-
 static void ide_output_data(int dev, const ulong *sect_buf, int words)
 {
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
@@ -1041,9 +1001,41 @@ BOOTDEV_HUNTER(ide_bootdev_hunter) = {
 
 static int ide_probe(struct udevice *udev)
 {
-   int i;
+   struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
+   bool bus_ok[CONFIG_SYS_IDE_MAXBUS];
+   int i, bus;
+
+   schedule();
+
+   /* ATAPI Drives seems to need a proper IDE Reset */
+   ide_reset();
+
+   /*
+* Wait for IDE to get ready.
+* According to spec, this can take up to 31 seconds!
+*/
+   for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) {
+   bus_ok[bus] = !ide_init_one(bus);
+   schedule();
+   }
 
-   ide_init();
+   putc('\n');
+
+   for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
+   ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
+   ide_dev_desc[i].uclass_id = UCLASS_IDE;
+   ide_dev_desc[i].devnum = i;
+   ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
+   ide_dev_desc[i].blksz = 0;
+   ide_dev_desc[i].log2blksz =
+   LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
+   ide_dev_desc[i].lba = 0;
+   if (!bus_ok[IDE_BUS(i)])
+   continue;
+   ide_ident(&ide_dev_desc[i]);
+   dev_print(&ide_dev_desc[i]);
+   }
+   schedule();
 
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
@@ -1075,10 +1067,6 @@ static int ide_probe(struct udevice *udev)
if (ret)
return ret;
 
-   ret = bootdev_setup_for_dev(udev, "ide_bootdev");
-   if (ret)
-   return log_msg_ret("bootdev", ret);
-
/* fill in device vendor/product/rev strings */
desc = dev_get_uclass_plat(blk_dev);
strlcpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
@@ -1089,6 +1077,10 @@ static int ide_probe(struct udevice *udev)
strlcpy(desc->revision,
ide_dev_desc[desc->devnum].revision,
BLK_REV_SIZE);
+
+   ret = bootdev_setup_for_dev(udev, "ide_bootdev");
+   if (ret)
+   return log_msg_ret("bootdev", ret);
}
}
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 23/30] ide: Make ide_ident() return an error code

2023-04-25 Thread Simon Glass
Update ide_ident() to indicate whether it finds a device or not. Use
that to decide whether to create a block device for it, rather than
looking DEV_TYPE_UNKNOWN.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 101 +++-
 1 file changed, 53 insertions(+), 48 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 835e781fccb..16b119ecbe1 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -534,15 +534,21 @@ static void atapi_inquiry(struct blk_desc *desc)
desc->lba48 = false;
 }
 
-static void ide_ident(struct blk_desc *desc)
+/**
+ * ide_ident() - Identify an IDE device
+ *
+ * @device: Device number to use
+ * @desc: Block descriptor to fill in
+ * Returns: 0 if OK, -ENOENT if no device is found
+ */
+static int ide_ident(int device, struct blk_desc *desc)
 {
unsigned char c;
hd_driveid_t iop;
bool is_atapi = false;
int tries = 1;
-   int device;
 
-   device = desc->devnum;
+   desc->devnum = device;
printf("  Device %d: ", device);
 
/* Select device
@@ -604,7 +610,7 @@ static void ide_ident(struct blk_desc *desc)
}
 
if (!tries) /* Not found */
-   return;
+   return -ENOENT;
 
ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
 
@@ -620,7 +626,7 @@ static void ide_ident(struct blk_desc *desc)
if (IS_ENABLED(CONFIG_ATAPI) && is_atapi) {
desc->atapi = true;
atapi_inquiry(desc);
-   return;
+   return 0;
}
 
iop.lba_capacity[0] = be16_to_cpu(iop.lba_capacity[0]);
@@ -661,6 +667,8 @@ static void ide_ident(struct blk_desc *desc)
udelay(50);
c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */
 #endif
+
+   return 0;
 }
 
 /**
@@ -1017,64 +1025,61 @@ static int ide_probe(struct udevice *udev)
schedule();
 
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
+   struct blk_desc *desc;
+   struct udevice *blk;
+   lbaint_t size;
+   char name[20];
+   int blksz;
+   int ret;
+
if (!bus_ok[IDE_BUS(i)])
continue;
 
ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
ide_dev_desc[i].uclass_id = UCLASS_IDE;
-   ide_dev_desc[i].devnum = i;
ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
ide_dev_desc[i].blksz = 0;
ide_dev_desc[i].log2blksz =
LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
ide_dev_desc[i].lba = 0;
-   ide_ident(&ide_dev_desc[i]);
+   ret = ide_ident(i, &ide_dev_desc[i]);
dev_print(&ide_dev_desc[i]);
 
-   if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) {
-   struct udevice *blk_dev;
-   struct blk_desc *desc;
-   lbaint_t size;
-   char name[20];
-   int blksz;
-   int ret;
+   if (ret)
+   continue;
 
-   sprintf(name, "blk#%d", i);
+   sprintf(name, "blk#%d", i);
 
-   blksz = ide_dev_desc[i].blksz;
-   size = blksz * ide_dev_desc[i].lba;
+   blksz = ide_dev_desc[i].blksz;
+   size = blksz * ide_dev_desc[i].lba;
 
-   /*
-* With CDROM, if there is no CD inserted, blksz will
-* be zero, don't bother to create IDE block device.
-*/
-   if (!blksz)
-   continue;
-   ret = blk_create_devicef(udev, "ide_blk", name,
-UCLASS_IDE, i,
-blksz, size, &blk_dev);
-   if (ret)
-   return ret;
-
-   ret = blk_probe_or_unbind(blk_dev);
-   if (ret)
-   return ret;
-
-   /* fill in device vendor/product/rev strings */
-   desc = dev_get_uclass_plat(blk_dev);
-   strlcpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
-   BLK_VEN_SIZE);
-   strlcpy(desc->product,
-   ide_dev_desc[desc->devnum].product,
-   BLK_PRD_SIZE);
-   strlcpy(desc->revision,
-   ide_dev_desc[desc->devnum].revision,
-   BLK_REV_SIZE);
-
-   ret = bootdev_setup_for_dev(udev, "ide_bootdev");
-   if (ret)
- 

[PATCH v2 26/30] ide: Correct LBA setting

2023-04-25 Thread Simon Glass
Fix a longstanding bug where the LBA is calculated as the size of the
media instead of the number of blocks. This was perhaps not noticed
earlier since it prints the correct value first, before setting the wrong
value.

Drop the unnecessary blksz variable while we are here.

Signed-off-by: Simon Glass 
Fixes: 68e6f221ed0 ("block: ide: Fix block read/write with driver model")
---

(no changes since v1)

 drivers/block/ide.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 4c2a6a8e530..72216540d04 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1029,9 +1029,7 @@ static int ide_probe(struct udevice *udev)
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
struct blk_desc *desc, pdesc;
struct udevice *blk;
-   lbaint_t size;
char name[20];
-   int blksz;
int ret;
 
if (!bus_ok[IDE_BUS(i)])
@@ -1045,17 +1043,14 @@ static int ide_probe(struct udevice *udev)
 
sprintf(name, "blk#%d", i);
 
-   blksz = pdesc.blksz;
-   size = blksz * pdesc.lba;
-
/*
 * With CDROM, if there is no CD inserted, blksz will
 * be zero, don't bother to create IDE block device.
 */
-   if (!blksz)
+   if (!pdesc.blksz)
continue;
ret = blk_create_devicef(udev, "ide_blk", name, UCLASS_IDE, i,
-blksz, size, &blk);
+pdesc.blksz, pdesc.lba, &blk);
if (ret)
return ret;
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 25/30] ide: Use a single local blk_desc for ide_ident()

2023-04-25 Thread Simon Glass
We only use one member of the ide_dev_desc[] array at a time and it does
not stick around outside ide_probe(). Use a single element instead.

Copy over the missing members of blk_desc at the same, since this was
missing from the previous code.

Signed-off-by: Simon Glass 
Fixes: 68e6f221ed0 ("block: ide: Fix block read/write with driver model")
---

(no changes since v1)

 drivers/block/ide.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index b1c897d6a41..4c2a6a8e530 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1005,7 +1005,6 @@ BOOTDEV_HUNTER(ide_bootdev_hunter) = {
 
 static int ide_probe(struct udevice *udev)
 {
-   struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
bool bus_ok[CONFIG_SYS_IDE_MAXBUS];
int i, bus;
 
@@ -1028,7 +1027,7 @@ static int ide_probe(struct udevice *udev)
schedule();
 
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
-   struct blk_desc *desc;
+   struct blk_desc *desc, pdesc;
struct udevice *blk;
lbaint_t size;
char name[20];
@@ -1038,16 +1037,16 @@ static int ide_probe(struct udevice *udev)
if (!bus_ok[IDE_BUS(i)])
continue;
 
-   ret = ide_ident(i, &ide_dev_desc[i]);
-   dev_print(&ide_dev_desc[i]);
+   ret = ide_ident(i, &pdesc);
+   dev_print(&pdesc);
 
if (ret)
continue;
 
sprintf(name, "blk#%d", i);
 
-   blksz = ide_dev_desc[i].blksz;
-   size = blksz * ide_dev_desc[i].lba;
+   blksz = pdesc.blksz;
+   size = blksz * pdesc.lba;
 
/*
 * With CDROM, if there is no CD inserted, blksz will
@@ -1066,12 +1065,13 @@ static int ide_probe(struct udevice *udev)
 
/* fill in device vendor/product/rev strings */
desc = dev_get_uclass_plat(blk);
-   strlcpy(desc->vendor, ide_dev_desc[desc->devnum].vendor,
-   BLK_VEN_SIZE);
-   strlcpy(desc->product, ide_dev_desc[desc->devnum].product,
-   BLK_PRD_SIZE);
-   strlcpy(desc->revision, ide_dev_desc[desc->devnum].revision,
-   BLK_REV_SIZE);
+   strlcpy(desc->vendor, pdesc.vendor, BLK_VEN_SIZE);
+   strlcpy(desc->product, pdesc.product, BLK_PRD_SIZE);
+   strlcpy(desc->revision, pdesc.revision, BLK_REV_SIZE);
+   desc->removable = pdesc.removable;
+   desc->atapi = pdesc.atapi;
+   desc->lba48 = pdesc.lba48;
+   desc->type = pdesc.type;
 
ret = bootdev_setup_for_dev(udev, "ide_bootdev");
if (ret)
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 27/30] ide: Tidy up ide_reset()

2023-04-25 Thread Simon Glass
Avoid using #ifdef and use a single function declaration, so it is easier
to read.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 72216540d04..fb409338783 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -45,24 +45,23 @@ ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = {
 
 #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
 
-#ifdef CONFIG_IDE_RESET
 static void ide_reset(void)
 {
-   ide_set_reset(1);   /* assert reset */
+   if (IS_ENABLED(CONFIG_IDE_RESET)) {
+   /* assert reset */
+   ide_set_reset(1);
 
-   /* the reset signal shall be asserted for et least 25 us */
-   udelay(25);
+   /* the reset signal shall be asserted for et least 25 us */
+   udelay(25);
 
-   schedule();
+   schedule();
 
-   /* de-assert RESET signal */
-   ide_set_reset(0);
+   /* de-assert RESET signal */
+   ide_set_reset(0);
 
-   mdelay(250);
+   mdelay(250);
+   }
 }
-#else
-#define ide_reset()/* dummy */
-#endif /* CONFIG_IDE_RESET */
 
 static void ide_outb(int dev, int port, unsigned char val)
 {
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 28/30] ide: Convert to use log_debug()

2023-04-25 Thread Simon Glass
Avoid the use of the function name in a few of the debug() calls, since
this causes a checkpatch warning. Convert all other calls too.

Use lower-case hex consistently.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 80 ++---
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index fb409338783..37236f6058b 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -65,8 +65,8 @@ static void ide_reset(void)
 
 static void ide_outb(int dev, int port, unsigned char val)
 {
-   debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
- dev, port, val, ATA_CURR_BASE(dev) + port);
+   log_debug("(dev= %d, port= %#x, val= 0x%02x) : @ 0x%08lx\n",
+ dev, port, val, ATA_CURR_BASE(dev) + port);
 
outb(val, ATA_CURR_BASE(dev) + port);
 }
@@ -77,8 +77,8 @@ static unsigned char ide_inb(int dev, int port)
 
val = inb(ATA_CURR_BASE(dev) + port);
 
-   debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
- dev, port, ATA_CURR_BASE(dev) + port, val);
+   log_debug("(dev= %d, port= %#x) : @ 0x%08lx -> 0x%02x\n",
+ dev, port, ATA_CURR_BASE(dev) + port, val);
return val;
 }
 
@@ -87,7 +87,7 @@ static void ide_input_swap_data(int dev, ulong *sect_buf, int 
words)
uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
ushort *dbuf = (ushort *)sect_buf;
 
-   debug("in input swap data base for read is %p\n", (void *)paddr);
+   log_debug("in input swap data base for read is %p\n", (void *)paddr);
 
while (words--) {
EIEIO;
@@ -158,7 +158,7 @@ static void ide_output_data_shorts(int dev, ushort 
*sect_buf, int shorts)
 
dbuf = (ushort *)sect_buf;
 
-   debug("in output data shorts base for read is %p\n", (void *)paddr);
+   log_debug("in output data shorts base for read is %p\n", (void *)paddr);
 
while (shorts--) {
EIEIO;
@@ -173,7 +173,7 @@ static void ide_input_data_shorts(int dev, ushort 
*sect_buf, int shorts)
 
dbuf = (ushort *)sect_buf;
 
-   debug("in input data shorts base for read is %p\n", (void *)paddr);
+   log_debug("in input data shorts base for read is %p\n", (void *)paddr);
 
while (shorts--) {
EIEIO;
@@ -222,7 +222,7 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
if ((c & mask) != res) {
-   printf("ATAPI_ISSUE: device %d not ready status %X\n", device,
+   printf("ATAPI_ISSUE: device %d not ready status %x\n", device,
   c);
err = 0xFF;
goto AI_OUT;
@@ -268,8 +268,8 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
if ((c & mask) != res) {
if (c & ATA_STAT_ERR) {
err = (ide_inb(device, ATA_ERROR_REG)) >> 4;
-   debug("atapi_issue 1 returned sense key %X status 
%02X\n",
- err, c);
+   log_debug("1 returned sense key %x status %02x\n",
+ err, c);
} else {
printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x)  
status 0x%02x\n",
   ccb[0], c);
@@ -292,20 +292,21 @@ static unsigned char atapi_issue(int device, unsigned 
char *ccb, int ccblen,
goto AI_OUT;
}
if (n != buflen) {
-   debug("WARNING, transfer bytes %d not equal with requested 
%d\n",
- n, buflen);
+   log_debug("WARNING, transfer bytes %d not equal with requested 
%d\n",
+ n, buflen);
}
if (n != 0) {   /* data transfer */
-   debug("ATAPI_ISSUE: %d Bytes to transfer\n", n);
+   log_debug("ATAPI_ISSUE: %d Bytes to transfer\n", n);
/* we transfer shorts */
n >>= 1;
/* ok now decide if it is an in or output */
if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) {
-   debug("Write to device\n");
+   log_debug("Write to device\n");
ide_output_data_shorts(device, (unsigned short *)buffer,
   n);
} else {
-   debug("Read from device @ %p shorts %d\n", buffer, n);
+   log_debug("Read from device @ %p shorts %d\n", buffer,
+ n);
ide_input_data_shorts(device, (unsigned short *)buffer,
  n);
}
@@ -316,8 +317,7 @@ static unsigned ch

[PATCH v2 29/30] ide: Simplify expressions and hex values

2023-04-25 Thread Simon Glass
The code has quite a few unnecessary brackets and comparisons to zero,
etc. Fix these up as well as some upper-case hex values and use of 0x in
printf() strings.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 115 +---
 1 file changed, 56 insertions(+), 59 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 37236f6058b..af0c951eb89 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -108,7 +108,7 @@ static uchar ide_wait(int dev, ulong t)
 
while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) {
udelay(100);
-   if (delay-- == 0)
+   if (!delay--)
break;
}
return c;
@@ -153,7 +153,7 @@ OUT:
  * we have our own transfer functions, 2 bytes alligned */
 static void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
-   uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+   uintptr_t paddr = ATA_CURR_BASE(dev) + ATA_DATA_REG;
ushort *dbuf;
 
dbuf = (ushort *)sect_buf;
@@ -168,7 +168,7 @@ static void ide_output_data_shorts(int dev, ushort 
*sect_buf, int shorts)
 
 static void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
-   uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+   uintptr_t paddr = ATA_CURR_BASE(dev) + ATA_DATA_REG;
ushort *dbuf;
 
dbuf = (ushort *)sect_buf;
@@ -195,12 +195,12 @@ static uchar atapi_wait_mask(int dev, ulong t, uchar 
mask, uchar res)
/* prevents to read the status before valid */
c = ide_inb(dev, ATA_DEV_CTL);
 
-   while (((c = ide_inb(dev, ATA_STATUS)) & mask) != res) {
+   while (c = ide_inb(dev, ATA_STATUS) & mask, c != res) {
/* break if error occurs (doesn't make sense to wait more) */
if ((c & ATA_STAT_ERR) == ATA_STAT_ERR)
break;
udelay(100);
-   if (delay-- == 0)
+   if (!delay--)
break;
}
return c;
@@ -224,16 +224,15 @@ static unsigned char atapi_issue(int device, unsigned 
char *ccb, int ccblen,
if ((c & mask) != res) {
printf("ATAPI_ISSUE: device %d not ready status %x\n", device,
   c);
-   err = 0xFF;
+   err = 0xff;
goto AI_OUT;
}
/* write taskfile */
ide_outb(device, ATA_ERROR_REG, 0); /* no DMA, no overlaped */
ide_outb(device, ATA_SECT_CNT, 0);
ide_outb(device, ATA_SECT_NUM, 0);
-   ide_outb(device, ATA_CYL_LOW, (unsigned char) (buflen & 0xFF));
-   ide_outb(device, ATA_CYL_HIGH,
-(unsigned char) ((buflen >> 8) & 0xFF));
+   ide_outb(device, ATA_CYL_LOW, (unsigned char)(buflen & 0xff));
+   ide_outb(device, ATA_CYL_HIGH, (unsigned char)((buflen >> 8) & 0xff));
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
 
ide_outb(device, ATA_COMMAND, ATA_CMD_PACKET);
@@ -244,9 +243,9 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res);
 
if ((c & mask) != res) {/* DRQ must be 1, BSY 0 */
-   printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d 
status 0x%02x\n",
+   printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d 
status %#02x\n",
   device, c);
-   err = 0xFF;
+   err = 0xff;
goto AI_OUT;
}
 
@@ -271,9 +270,9 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
log_debug("1 returned sense key %x status %02x\n",
  err, c);
} else {
-   printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x)  
status 0x%02x\n",
+   printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x)  
status %#02x\n",
   ccb[0], c);
-   err = 0xFF;
+   err = 0xff;
}
goto AI_OUT;
}
@@ -286,7 +285,7 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
err = 0xff;
goto AI_OUT;
}
-   if ((n == 0) && (buflen < 0)) {
+   if (!n && buflen < 0) {
printf("ERROR, transfer bytes %d requested %d\n", n, buflen);
err = 0xff;
goto AI_OUT;
@@ -295,12 +294,12 @@ static unsigned char atapi_issue(int device, unsigned 
char *ccb, int ccblen,
log_debug("WARNING, transfer bytes %d not equal with requested 
%d\n",
  n, buflen);
}
-   if (n != 0) {   /* data transfer */
+   if (n) {/* data transfer */
log_debug("ATAPI_ISSUE: %d Bytes to t

[PATCH v2 24/30] ide: Move all blk_desc init into ide_ident()

2023-04-25 Thread Simon Glass
Rather than having the caller fill some of this in, do it all in the
ide_ident() function, since it knows all the values.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 16b119ecbe1..b1c897d6a41 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -548,13 +548,16 @@ static int ide_ident(int device, struct blk_desc *desc)
bool is_atapi = false;
int tries = 1;
 
+   memset(desc, '\0', sizeof(*desc));
desc->devnum = device;
+   desc->type = DEV_TYPE_UNKNOWN;
+   desc->uclass_id = UCLASS_IDE;
+   desc->log2blksz = LOG2_INVALID(typeof(desc->log2blksz));
printf("  Device %d: ", device);
 
/* Select device
 */
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-   desc->uclass_id = UCLASS_IDE;
if (IS_ENABLED(CONFIG_ATAPI))
tries = 2;
 
@@ -1035,13 +1038,6 @@ static int ide_probe(struct udevice *udev)
if (!bus_ok[IDE_BUS(i)])
continue;
 
-   ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
-   ide_dev_desc[i].uclass_id = UCLASS_IDE;
-   ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
-   ide_dev_desc[i].blksz = 0;
-   ide_dev_desc[i].log2blksz =
-   LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
-   ide_dev_desc[i].lba = 0;
ret = ide_ident(i, &ide_dev_desc[i]);
dev_print(&ide_dev_desc[i]);
 
-- 
2.40.0.634.g4ca3ef3211-goog



[PATCH v2 22/30] ide: Use desc consistently for struct blk_desc

2023-04-25 Thread Simon Glass
Most of the code uses 'desc' as the variable name for a blk descriptor.
Change ide to do the same.

Tidy up some extra brackets and types while we are here.

Leave the code in ide_probe() alone since it is about to be refactored.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/block/ide.c | 101 +---
 1 file changed, 47 insertions(+), 54 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index d682d6ad9e6..835e781fccb 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -414,8 +414,8 @@ error:
 static ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
void *buffer)
 {
-   struct blk_desc *block_dev = dev_get_uclass_plat(dev);
-   int device = block_dev->devnum;
+   struct blk_desc *desc = dev_get_uclass_plat(dev);
+   int device = desc->devnum;
ulong n = 0;
unsigned char ccb[12];  /* Command descriptor block */
ulong cnt;
@@ -456,15 +456,15 @@ static ulong atapi_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
return n;
 }
 
-static void atapi_inquiry(struct blk_desc *dev_desc)
+static void atapi_inquiry(struct blk_desc *desc)
 {
unsigned char ccb[12];  /* Command descriptor block */
unsigned char iobuf[64];/* temp buf */
unsigned char c;
int device;
 
-   device = dev_desc->devnum;
-   dev_desc->type = DEV_TYPE_UNKNOWN;  /* not yet valid */
+   device = desc->devnum;
+   desc->type = DEV_TYPE_UNKNOWN;  /* not yet valid */
 
memset(ccb, 0, sizeof(ccb));
memset(iobuf, 0, sizeof(iobuf));
@@ -478,20 +478,20 @@ static void atapi_inquiry(struct blk_desc *dev_desc)
return;
 
/* copy device ident strings */
-   ident_cpy((unsigned char *)dev_desc->vendor, &iobuf[8], 8);
-   ident_cpy((unsigned char *)dev_desc->product, &iobuf[16], 16);
-   ident_cpy((unsigned char *)dev_desc->revision, &iobuf[32], 5);
+   ident_cpy((u8 *)desc->vendor, &iobuf[8], 8);
+   ident_cpy((u8 *)desc->product, &iobuf[16], 16);
+   ident_cpy((u8 *)desc->revision, &iobuf[32], 5);
 
-   dev_desc->lun = 0;
-   dev_desc->lba = 0;
-   dev_desc->blksz = 0;
-   dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
-   dev_desc->type = iobuf[0] & 0x1f;
+   desc->lun = 0;
+   desc->lba = 0;
+   desc->blksz = 0;
+   desc->log2blksz = LOG2_INVALID(typeof(desc->log2blksz));
+   desc->type = iobuf[0] & 0x1f;
 
if ((iobuf[1] & 0x80) == 0x80)
-   dev_desc->removable = 1;
+   desc->removable = 1;
else
-   dev_desc->removable = 0;
+   desc->removable = 0;
 
memset(ccb, 0, sizeof(ccb));
memset(iobuf, 0, sizeof(iobuf));
@@ -524,19 +524,17 @@ static void atapi_inquiry(struct blk_desc *dev_desc)
  iobuf[0], iobuf[1], iobuf[2], iobuf[3],
  iobuf[4], iobuf[5], iobuf[6], iobuf[7]);
 
-   dev_desc->lba = ((unsigned long) iobuf[0] << 24) +
-   ((unsigned long) iobuf[1] << 16) +
-   ((unsigned long) iobuf[2] << 8) + ((unsigned long) iobuf[3]);
-   dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
-   ((unsigned long) iobuf[5] << 16) +
-   ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
-   dev_desc->log2blksz = LOG2(dev_desc->blksz);
+   desc->lba = (ulong)iobuf[0] << 24 | (ulong)iobuf[1] << 16 |
+   (ulong)iobuf[2] << 8 | (ulong)iobuf[3];
+   desc->blksz = (ulong)iobuf[4] << 24 | (ulong)iobuf[5] << 16 |
+   (ulong)iobuf[6] << 8 | (ulong)iobuf[7];
+   desc->log2blksz = LOG2(desc->blksz);
 
/* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
-   dev_desc->lba48 = false;
+   desc->lba48 = false;
 }
 
-static void ide_ident(struct blk_desc *dev_desc)
+static void ide_ident(struct blk_desc *desc)
 {
unsigned char c;
hd_driveid_t iop;
@@ -544,13 +542,13 @@ static void ide_ident(struct blk_desc *dev_desc)
int tries = 1;
int device;
 
-   device = dev_desc->devnum;
+   device = desc->devnum;
printf("  Device %d: ", device);
 
/* Select device
 */
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
-   dev_desc->uclass_id = UCLASS_IDE;
+   desc->uclass_id = UCLASS_IDE;
if (IS_ENABLED(CONFIG_ATAPI))
tries = 2;
 
@@ -610,49 +608,44 @@ static void ide_ident(struct blk_desc *dev_desc)
 
ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
 
-   ident_cpy((unsigned char *)dev_desc->revision, iop.fw_rev,
- sizeof(dev_desc->revision));
-   ident_cpy((unsigned char *)dev_desc->vendor, iop.model,
- sizeof(dev_desc->vendor));
-   ident_cpy((unsigned char *)dev_desc->product, iop.serial_no,
- sizeof(dev_des

[PATCH v2 30/30] ide: Make use of U-Boot types

2023-04-25 Thread Simon Glass
Use standard U-Boot types in the file to make the code less verbose.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Rebase to master

 drivers/block/ide.c | 79 +
 1 file changed, 37 insertions(+), 42 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index af0c951eb89..89201dd4d22 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -63,7 +63,7 @@ static void ide_reset(void)
}
 }
 
-static void ide_outb(int dev, int port, unsigned char val)
+static void ide_outb(int dev, int port, u8 val)
 {
log_debug("(dev= %d, port= %#x, val= 0x%02x) : @ 0x%08lx\n",
  dev, port, val, ATA_CURR_BASE(dev) + port);
@@ -71,7 +71,7 @@ static void ide_outb(int dev, int port, unsigned char val)
outb(val, ATA_CURR_BASE(dev) + port);
 }
 
-static unsigned char ide_inb(int dev, int port)
+static u8 ide_inb(int dev, int port)
 {
uchar val;
 
@@ -119,10 +119,9 @@ static uchar ide_wait(int dev, ulong t)
  * terminate the string
  * "len" is the size of available memory including the terminating '\0'
  */
-static void ident_cpy(unsigned char *dst, unsigned char *src,
- unsigned int len)
+static void ident_cpy(u8 *dst, u8 *src, uint len)
 {
-   unsigned char *end, *last;
+   u8 *end, *last;
 
last = dst;
end = src + len - 1;
@@ -209,10 +208,9 @@ static uchar atapi_wait_mask(int dev, ulong t, uchar mask, 
uchar res)
 /*
  * issue an atapi command
  */
-static unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
-unsigned char *buffer, int buflen)
+static u8 atapi_issue(int device, u8 *ccb, int ccblen, u8 *buffer, int buflen)
 {
-   unsigned char c, err, mask, res;
+   u8 c, err, mask, res;
int n;
 
/* Select device
@@ -231,8 +229,8 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
ide_outb(device, ATA_ERROR_REG, 0); /* no DMA, no overlaped */
ide_outb(device, ATA_SECT_CNT, 0);
ide_outb(device, ATA_SECT_NUM, 0);
-   ide_outb(device, ATA_CYL_LOW, (unsigned char)(buflen & 0xff));
-   ide_outb(device, ATA_CYL_HIGH, (unsigned char)((buflen >> 8) & 0xff));
+   ide_outb(device, ATA_CYL_LOW, (u8)(buflen & 0xff));
+   ide_outb(device, ATA_CYL_HIGH, (u8)((buflen >> 8) & 0xff));
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
 
ide_outb(device, ATA_COMMAND, ATA_CMD_PACKET);
@@ -250,7 +248,7 @@ static unsigned char atapi_issue(int device, unsigned char 
*ccb, int ccblen,
}
 
/* write command block */
-   ide_output_data_shorts(device, (unsigned short *)ccb, ccblen / 2);
+   ide_output_data_shorts(device, (ushort *)ccb, ccblen / 2);
 
/* ATAPI Command written wait for completition */
mdelay(5);  /* device must set bsy */
@@ -301,13 +299,11 @@ static unsigned char atapi_issue(int device, unsigned 
char *ccb, int ccblen,
/* ok now decide if it is an in or output */
if (!(ide_inb(device, ATA_SECT_CNT) & 0x02)) {
log_debug("Write to device\n");
-   ide_output_data_shorts(device, (unsigned short *)buffer,
-  n);
+   ide_output_data_shorts(device, (ushort *)buffer, n);
} else {
log_debug("Read from device @ %p shorts %d\n", buffer,
  n);
-   ide_input_data_shorts(device, (unsigned short *)buffer,
- n);
+   ide_input_data_shorts(device, (ushort *)buffer, n);
}
}
mdelay(5);  /* seems that some CD ROMs need this... */
@@ -332,12 +328,11 @@ AI_OUT:
 #define ATAPI_DRIVE_NOT_READY  100
 #define ATAPI_UNIT_ATTN10
 
-static unsigned char atapi_issue_autoreq(int device, unsigned char *ccb,
-int ccblen,
-unsigned char *buffer, int buflen)
+static u8 atapi_issue_autoreq(int device, u8 *ccb, int ccblen, u8 *buffer,
+ int buflen)
 {
-   unsigned char sense_data[18], sense_ccb[12];
-   unsigned char res, key, asc, ascq;
+   u8 sense_data[18], sense_ccb[12];
+   u8 res, key, asc, ascq;
int notready, unitattn;
 
unitattn = ATAPI_UNIT_ATTN;
@@ -415,7 +410,7 @@ static ulong atapi_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
struct blk_desc *desc = dev_get_uclass_plat(dev);
int device = desc->devnum;
ulong n = 0;
-   unsigned char ccb[12];  /* Command descriptor block */
+   u8 ccb[12]; /* Command descriptor block */
ulong cnt;
 
log_debug("%d start " LBAF " blocks " LBAF " buffer at %lx\n", device,
@@ -429,19 +424,19 @@ static ulong a

Re: [PATCH v2 2/2] ARM: dts: stm32mp: alignment with v6.3

2023-04-25 Thread Marek Vasut

On 4/24/23 16:21, Patrick Delaunay wrote:

Device tree alignment with Linux kernel v6.3:
- f5a058023239 - ARM: dts: stm32: add i2c nodes into stm32mp131.dtsi
- 8539ebb435a5 - ARM: dts: stm32: enable i2c1 and i2c5 on
   stm32mp135f-dk.dts
- 8539ebb435a5 - ARM: dts: stm32: add spi nodes into stm32mp131.dtsi
- 15f72e0da4da - ARM: dts: stm32: add pinctrl and disabled spi5 node in
   stm32mp135f-dk
- ea99a5a02ebc - ARM: dts: stm32: Create separate pinmux for qspi cs pin
   in stm32mp15-pinctrl.dtsi
- a306d8962a24 - ARM: dts: stm32: Rename mdio0 to mdio
- 0a5ebb1f3367 - ARM: dts: stm32: Replace SAI format with dai-format DT
   property
- ccdab19738a6 - ARM: dts: stm32: add adc support to stm32mp13
- 022932ab55fd - ARM: dts: stm32: add adc pins muxing on stm32mp135f-dk
- ab2806ddad9d - ARM: dts: stm32: add dummy vdd_adc regulator on
   stm32mp135f-dk
- e46a180c060f - ARM: dts: stm32: add adc support on stm32mp135f-dk
- 9ebf215fbae1 - ARM: dts: stm32: add PWR fixed regulators on stm32mp131
- 16f4ff60519a - ARM: dts: stm32: add USBPHYC and dual USB HS PHY support
   on stm32mp131
- 4a47f0f3e936 - ARM: dts: stm32: add UBSH EHCI and OHCI support on
   stm32mp131
- 2a46bb66c47f - ARM: dts: stm32: add USB OTG HS support on stm32mp131
- 9ebf215fbae1 - ARM: dts: stm32: add fixed regulators to support usb on
   stm32mp135f-dk
- 16f4ff60519a - ARM: dts: stm32: enable USB HS phys on stm32mp135f-dk
- c4e7254cf6dc - ARM: dts: stm32: enable USB Host EHCI on stm32mp135f-dk
- 44978e135916 - ARM: dts: stm32: add pins for stm32g0 typec controller on 
stm32mp13
- 4f532403b1e5 - ARM: dts: stm32: enable USB OTG in dual role mode on
   stm32mp135f-dk
- e1f15571c96c - ARM: dts: stm32: add mcp23017 pinctrl entry for stm32mp13
- 6cc71374002e - ARM: dts: stm32: add mcp23017 IO expander on I2C1 on
   stm32mp135f-dk
- 7ffd2266bd32 - ARM: dts: stm32: Fix qspi pinctrl phandle for
   stm32mp15xx-dhcor-som
- 21d83512bf2b - ARM: dts: stm32: Fix qspi pinctrl phandle for
   stm32mp15xx-dhcom-som
- 732dbcf52f74 - ARM: dts: stm32: Fix qspi pinctrl phandle for
   stm32mp151a-prtt1l
- 003b7c6b24f4 - ARM: dts: stm32: remove sai kernel clock on
   stm32mp15xx-dkx
- f2b17b39bfff - ARM: dts: stm32: rename sound card on stm32mp15xx-dkx
- dee3cb759d3d - ARM: dts: stm32: Remove the pins-are-numbered property
- ae8cf3b48727 - ARM: dts: stm32: add i2s nodes on stm32mp131
- 619746a27bd0 - ARM: dts: stm32: add sai nodes on stm32mp131
- c5e05d08ef90 - ARM: dts: stm32: add spdifrx node on stm32mp131
- 0a5afd3ee0d0 - ARM: dts: stm32: add dfsdm node on stm32mp131
- bf9d876bea2e - ARM: dts: stm32: add timers support on stm32mp131
- a3183748371d - ARM: dts: stm32: add timer pins muxing for stm32mp135f-dk
- a9060c1326bc - ARM: dts: stm32: add timers support on stm32mp135f-dk
- a12154058f75 - ARM: dts: stm32: Fix User button on stm32mp135f-dk
- 2f33df889e99 - ARM: dts: stm32: Use new media bus type macros
- 366384e49551 - ARM: dts: stm32: Update part number NVMEM description on
   stm32mp131


Thanks.

Reviewed-by: Marek Vasut 

You really could've just included the one Linux 6.3 commit hash and 
wrote this is synced with Linux 6.3, since all the commits listed above 
would be part of the Linux 6.3 commit hash anyway . It would make the 
commit message shorter, but this variant is also fine.


Re: [PATCH] environment: ti: Add get_fit_config command to get FIT config string

2023-04-25 Thread Tom Rini
On Tue, Apr 25, 2023 at 11:20:45AM -0500, Andrew Davis wrote:

> When OE is packaging a dtb file into the FIT image it names the node based
> on the dtb filename. Node names can't have "/" so it is turned into "_".
> We select our FIT config using the "fdtfile" env var so we don't duplicate
> the board_name to fdt logic. Result is fdtfile needs mangled when used to
> select a config node from OE made FIT image. Do this here.
> 
> Signed-off-by: Andrew Davis 

Thanks for getting this done!

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] mtd: spi-nor: Add CHIP_ERASE optimization

2023-04-25 Thread Jagan Teki
On Thu, Mar 2, 2023 at 7:16 AM Marek Vasut  wrote:
>
> Add support for CHIP_ERASE opcode 0xc7 . This is useful in case the
> entire SPI NOR is supposed to be erase at once, as is it considerably
> faster than 4k sector erase and even slightly faster than 64k block
> erase. The spi_nor_erase_chip() implementation is adapted from Linux
> 6.1.y as of commit 7d54cb2c26dad ("Linux 6.1.14") . The chip erase is
> only used in case the entire MTD device is being erased, and the chip
> does support this functionality.
>
> Timing figures from W25Q128JW:
> 16 MiB erase using 4kiB sector erase opcode 0x20 ... 107.5s
> 16 MiB erase using 64kiB block erase opcode 0xd8 ... 39.1s
> 16 MiB erase using chip erase opcode 0xc7 .. 38.7s
>
> Signed-off-by: Marek Vasut 
> ---

Reviewed-by: Jagan Teki 

Applied to u-boot-spi/master


Re: [PATCH] spi: f-ospi: Add missing spi_mem_default_supports_op() helper

2023-04-25 Thread Jagan Teki
On Mon, Mar 27, 2023 at 11:05 AM Kunihiko Hayashi
 wrote:
>
> The .supports_op() callback function returns true by default after
> performing driver-specific checks. Therefore the driver cannot apply
> the buswidth in devicetree.
>
> Call spi_mem_default_supports_op() helper to handle the buswidth
> in devicetree.
>
> Fixes: 358f803ae21c ("spi: Add Socionext F_OSPI SPI flash controller driver")
> Signed-off-by: Kunihiko Hayashi 
> ---

Applied to u-boot-spi/master


Re: [PATCH v1] spi: npcm-fiu: add regulator feature and remove set clock

2023-04-25 Thread Jagan Teki
On Tue, Mar 7, 2023 at 1:40 PM Jim Liu  wrote:
>
> NPCM7xx/NPCM8xx default is boot from flash.
> removed set clock feature due to reliability and security.
> the clock will set by bootblock or tip.
>
> Signed-off-by: Jim Liu 
> ---

Reviewed-by: Jagan Teki 

Applied to u-boot-spi/master


Re: [PATCH 1/1] mtd: spi-nor: missing fallthrough in set_4byte()

2023-04-25 Thread Jagan Teki
On Sat, Apr 1, 2023 at 1:04 PM Heinrich Schuchardt
 wrote:
>
> Add a missing fallthrough macro to avoid a -Wimplicit-fallthrough warning.
>
> Signed-off-by: Heinrich Schuchardt 
> ---

Applied to u-boot-spi/master


  1   2   >