Re: [PATCH 2/2] global_data: Fix comment for dm_driver_rt

2020-11-29 Thread Heinrich Schuchardt

On 11/30/20 1:07 AM, Simon Glass wrote:

This comment is in the wrong format, so reports an error with
'make htmldocs'. Fix it.

Fixes: a294ead8d25 ("dm: Use an allocated array for run-time device info")
Signed-off-by: Simon Glass 


Reviewed-by: Heinrich Schuchardt 


RE: [PATCH] riscv: timer: Add support for an early timer

2020-11-29 Thread Pragnesh Patel
Hi Rick,

>-Original Message-
[...]
>> >After add CONFIG_TIMER_EARLY, U-Boot boots ok.
>> >But When I try to booting kernel with FTRACE=1, following are the test 
>> >stats:
>> >
>> >ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok.
>> >ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail.
>> >ae350_rv64_defconfig with FTRACE=1, kernel booting is ok
>> >
>> >The failure case seems not reasonable.
>> >Any suggestions ?
>>
>> Strange, Can you please tell me which steps you follow and also send some
>debug logs  if possible.
>>
>
>Following are the configurations, steps and debug logs:
>
>+++ b/configs/ae350_rv64_defconfig
>q+CONFIG_TRACE=y
>+CONFIG_TRACE_BUFFER_SIZE=0x0100
>+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
>+CONFIG_CMD_TRACE=y
>+CONFIG_TIMER_EARLY=y
>
>+++ b/configs/ae350_rv64_spl_defconfig
>+CONFIG_TRACE=y
>+CONFIG_TRACE_BUFFER_SIZE=0x0100
>+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
>+CONFIG_CMD_TRACE=y
>+CONFIG_TIMER_EARLY=y
>
> case 1
>///
>ae350_rv64_defconfig with FTRACE=1, kernel booting is ok
> case 1
>///
>make FTRACE=1 ae350_rv64_defconfig
>make FTRACE=1
>//
>/
>U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:14:28 +0800)
>
>DRAM:  1 GiB
>trace: enabled
>Flash: 64 MiB
>MMC:   mmc@f0e0: 0
>Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
>size 256 Bytes, erase size 4 KiB, total 2 MiB
>OK
>In:serial@f030
>Out:   serial@f030
>Err:   serial@f030
>Net:   no alias for ethernet0
>Warning: mac@e010 (eth0) using random MAC address - de:fa:3e:1b:11:42
>eth0: mac@e010
>Hit any key to stop autoboot:  0
>RISC-V # fatload mmc 0:1 0x2000 ae350_rv64_smp_4_no_fd_coherent.dtb
>6455 bytes read in 67 ms (93.8 KiB/s)
>RISC-V # fatload mmc 0:1 0x0060 bootm_ae350_rv64_smp_bbl.bin
>22518836 bytes read in 11915 ms (1.8 MiB/s)
>RISC-V # bootm 0x0060 - 0x2000
>## Booting kernel from Legacy Image at 0060 ...
>   Image Name:
>   Image Type:   RISC-V Linux Kernel Image (uncompressed)
>   Data Size:22518772 Bytes = 21.5 MiB
>   Load Address: 
>   Entry Point:  
>   Verifying Checksum ... OK
>## Flattened Device Tree blob at 2000
>   Booting using the fdt blob at 0x2000
>   Loading Kernel Image
>   Loading Device Tree to 1effb000, end 1efff936 ... OK
>
>Starting kernel ...(fake run for tracing)
>
>Starting kernel ...
>
>OF: fdt: Ignoring memory range 0x0 - 0x20
>Linux version 4.17.0-00253-g49136e10bcb2 (sqa@atcsqa07) (gcc version
>7.3.0 (2019-04-06_nds64le-linux-glibc-v5_experimental)) #1 SMP PREEMPT
>Sat Apr 6 23:41:49 CST 2019
>bootconsole [early0] enabled
>Initial ramdisk at: 0x(ptrval) (13665712 bytes)
>Zone ranges:
>  DMA32[mem 0x0020-0x3fff]
>  Normal   empty
>Movable zone start for each node
>Early memory node ranges
>...
>...
>
> case 2
>///
>ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail
> case 2
>///
>make FTRACE=1 ae350_rv64_spl_defconfig
>make FTRACE=1
>//
>/
>U-Boot SPL 2020.10-rc2-00175-gfa50824 (Sep 15 2020 - 19:26:29 +0800)
>Trying to boot from MMC1
>U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800)
>Trying to boot from RAM
>U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800)
>DRAM:  1 GiB
>trace: enabled
>Flash: 64 MiB
>MMC:   mmc@f0e0: 0
>Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
>size 256 Bytes, erase size 4 KiB, total 2 MiB
>OK
>In:serial@f030
>Out:   serial@f030
>Err:   serial@f030
>Net:   no alias for ethernet0
>Warning: mac@e010 (eth0) using random MAC address - 36:86:da:0f:8e:8d
>eth0: mac@e010
>Hit any key to stop autoboot:  0
>27689996 bytes read in 15024 ms (1.8 MiB/s)
>6435 bytes read in 25 ms (251 KiB/s)
>## Booting kernel from Legacy Image at 0060 ...
>   Image Name:
>   Image Type:   RISC-V Linux Kernel Image (uncompressed)
>   Data Size:27689932 Bytes = 26.4 MiB
>   Load Address: 0020
>   Entry Point:  0020
>   Verifying Checksum ... OK
>## Flattened Device Tree blob at 2000
>   Booting using the fdt blob at 0x2000
>   Loading Kernel Image
>   Loading Device Tree to 1effb000, end 1efff922 ... OK
>
>Starting kernel ...(fake run for tracing)
>
>Starting kernel ...
>
>(hang here)

Thanks for the logs.

From logs, I can't find where it got stuck. Can you please use gdb to 

Re: [PATCH 1/2] log: Fix comment for LOGC_BOOT

2020-11-29 Thread Heinrich Schuchardt

On 11/30/20 1:07 AM, Simon Glass wrote:

This comment is in the wrong format, so reports an error with
'make htmldocs'. Fix it.

Fixes: b73d61a5565 ("x86: zimage: Add a little more logging")
Signed-off-by: Simon Glass 


Reviewed-by: Heinrich Schuchardt 


Re: [PATCH 01/27] linker_lists: Fix alignment issue

2020-11-29 Thread Heinrich Schuchardt
Am 30. November 2020 02:53:36 MEZ schrieb Simon Glass :
>The linker script uses alphabetic sorting to group the different linker
>lists together. Each group has its own struct and potentially its own
>alignment. But when the linker packs the structs together it cannot
>ensure that a linker list starts on the expected alignment boundary.
>
>For example, if the first list has a struct size of 8 and we place 3 of
>them in the image, that means that the next struct will start at offset
>0x18 from the start of the linker_list section. If the next struct has
>a size of 16 then it will start at an 8-byte aligned offset, but not a
>16-byte aligned offset.
>
>With sandbox on x86_64, a reference to a linker list item using
>ll_entry_get() can force alignment of that particular linker_list item,
>if it is in the same file as the linker_list item is declared.
>
>Consider this example, where struct driver is 0x80 bytes:
>
>   ll_entry_declare(struct driver, fred, driver)
>
>...
>
>   void *p = ll_entry_get(struct driver, fred, driver)
>
>If these two lines of code are in the same file, then the entry is
>forced
>to be aligned at the 'struct driver' alignment, which is 16 bytes. If
>the
>second line of code is in a different file, then no action is taken,
>since
>the compiler cannot update the alignment of the linker_list item.
>
>In the first case, an 8-byte 'fill' region is added:
>
> .u_boot_list_2_driver_2_testbus_drv
>0x00270018   0x80 test/built-in.o
>0x00270018
>   _u_boot_list_2_driver_2_testbus_drv
> .u_boot_list_2_driver_2_testfdt1_drv
>0x00270098   0x80 test/built-in.o
>0x00270098
>   _u_boot_list_2_driver_2_testfdt1_drv
> *fill* 0x002701180x8
> .u_boot_list_2_driver_2_testfdt_drv
>0x00270120   0x80 test/built-in.o
>0x00270120
>   _u_boot_list_2_driver_2_testfdt_drv
> .u_boot_list_2_driver_2_testprobe_drv
>0x002701a0   0x80 test/built-in.o
>0x002701a0
>   _u_boot_list_2_driver_2_testprobe_drv
>
>With this, the linker_list no-longer works since items after
>testfdt1_drv
>are not at the expected address.
>
>Ideally we would have a way to tell gcc not to align structs in this
>way.
>It is not clear how we could do this, and in any case it would require
>us
>to adjust every struct used by the linker_list feature.
>
>One possible fix is to force each separate linker_list to start on the
>largest possible boundary that can be required by the compiler. However
>that does not seem to work on x86_64, which uses 16-byte alignment in
>this
>case but needs 32-byte alignment.
>
>So add a Kconfig option to handle this. Set the default value to 4 so
>as to avoid changing platforms that don't need it.
>
>Update the ll_entry_start() accordingly.
>
>Signed-off-by: Simon Glass 
>---
>
> arch/Kconfig | 11 +++
> doc/api/linker_lists.rst | 62 
> include/linker_lists.h   |  3 +-
> 3 files changed, 75 insertions(+), 1 deletion(-)
>
>diff --git a/arch/Kconfig b/arch/Kconfig
>index 3aa99e08fce..aa8664212f1 100644
>--- a/arch/Kconfig
>+++ b/arch/Kconfig
>@@ -7,6 +7,17 @@ config HAVE_ARCH_IOREMAP
> config NEEDS_MANUAL_RELOC
>   bool
> 
>+config LINKER_LIST_ALIGN
>+  int
>+  default 32 if SANDBOX

What is so special about the sandbox?
Just evaluate if the host is 64 bit and use 8 or 4 accordingly?

>+  default 8 if ARM64 || X86

Shouldn't the default be 8 on all 64 bit platforms? And 4 on all 32 bit 
platforms?

Best regards

Heinrich


>+  default 4
>+  help
>+Force the each linker list to be aligned to this boundary. This
>+is required if ll_entry_get() is used, since otherwise the linker
>+may add padding into the table, thus breaking it.
>+See linker_lists.rst for full details.
>+
> choice
>   prompt "Architecture select"
>   default SANDBOX
>diff --git a/doc/api/linker_lists.rst b/doc/api/linker_lists.rst
>index 72f514e0ac0..7a37db52ba8 100644
>--- a/doc/api/linker_lists.rst
>+++ b/doc/api/linker_lists.rst
>@@ -96,5 +96,67 @@ defined for the whole list and each sub-list:
>   %u_boot_list_2_drivers_2_pci_3
>   %u_boot_list_2_drivers_3
> 
>+Alignment issues
>+
>+
>+The linker script uses alphabetic sorting to group the different
>linker
>+lists together. Each group has its own struct and potentially its own
>+alignment. But when the linker packs the structs together it cannot
>ensure
>+that a linker list starts on the expected alignment boundary.
>+
>+For example, if the first list has a struct size of 8 and we place 3
>of
>+them in the image, that means that the next struct will start at
>offset
>+0x18 from the start of the linker_list section. If the next struct has
>+a size of 16 

Re: [PATCH v4] usb: xhci: fix lack of short packet event trb handling

2020-11-29 Thread Bin Meng
Hi Ran,

On Mon, Nov 30, 2020 at 9:42 AM Ran Wang  wrote:
>
> Hi Marek, Bin,
>
>
> On Wednesday, November 18, 2020 3:49 PM, Ran Wang wrote:
> >
> > For bulk IN transfer, the codes will set ISP flag to request event TRB being
> > generated by xHC for the case of short packet. So when encountering
> > buffer-cross-64K-boundary (which we will divide payload and enqueuqe more
> > than 1 transfer TRB), and the first TRB ends up with a short packet 
> > condition it
> > will trigger an short packet code transfer event per that flag and cause 
> > more
> > than 1 event TRB generated for this transfer.
> >
> > However, current codes will only handle the first transfer event TRB then 
> > mark
> > current transfer completed, causing next transfer failure due to event TRB
> > mis-match.
> >
> > Such issue has been observed on some Layerscape platforms (LS1028A,
> > LS1088A, etc) with USB ethernet device.
> >
> > This patch adds a loop to make sure the event TRB for last transfer TRB has
> > been handled in time.
> >
> > Signed-off-by: Ran Wang 
> > Reviewed-by: Bin Meng 
> > ---
> > Change in v4:
> >  - Update commit message: 'for case of short packet' => 'for the case of 
> > short
> > packet'
>
>Has this v4 patch been accepted?

I believe Marek will apply this patch.

Regards,
Bin


[PATCH 03/27] dm: Avoid accessing seq directly

2020-11-29 Thread Simon Glass
At present various drivers etc. access the device's 'seq' member directly.
This makes it harder to change the meaning of that member. Change access
to go through a function instead.

The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now.

Signed-off-by: Simon Glass 
---

 arch/arm/include/asm/mach-imx/mxc_i2c.h  |  2 +-
 arch/x86/cpu/broadwell/cpu_full.c|  2 +-
 arch/x86/cpu/ivybridge/model_206ax.c |  2 +-
 board/xilinx/versal/board.c  | 12 
 board/xilinx/zynqmp/zynqmp.c | 12 
 cmd/axi.c|  4 +--
 cmd/cpu.c|  2 +-
 cmd/i2c.c|  4 +--
 cmd/misc.c   |  2 +-
 cmd/osd.c|  4 +--
 cmd/pci.c|  7 +++--
 cmd/pmic.c   |  4 +--
 cmd/remoteproc.c |  2 +-
 cmd/w1.c |  4 +--
 drivers/core/device.c|  2 +-
 drivers/core/dump.c  |  4 +--
 drivers/core/uclass.c|  6 ++--
 drivers/gpio/octeon_gpio.c   |  2 +-
 drivers/i2c/ast_i2c.c|  4 +--
 drivers/i2c/davinci_i2c.c|  2 +-
 drivers/i2c/exynos_hs_i2c.c  |  2 +-
 drivers/i2c/i2c-gpio.c   |  2 +-
 drivers/i2c/imx_lpi2c.c  | 12 
 drivers/i2c/lpc32xx_i2c.c|  6 +++-
 drivers/i2c/mxc_i2c.c| 10 +++
 drivers/i2c/nx_i2c.c |  2 +-
 drivers/i2c/octeon_i2c.c |  2 +-
 drivers/i2c/s3c24x0_i2c.c|  2 +-
 drivers/i2c/tegra_i2c.c  |  5 ++--
 drivers/mmc/fsl_esdhc_imx.c  |  4 +--
 drivers/mtd/spi/sandbox.c|  4 +--
 drivers/net/fec_mxc.c|  7 +++--
 drivers/net/fsl-mc/mc.c  |  2 +-
 drivers/net/fsl_mcdmafec.c   |  2 +-
 drivers/net/ftgmac100.c  |  2 +-
 drivers/net/higmacv300.c |  2 +-
 drivers/net/mcffec.c |  2 +-
 drivers/net/octeontx/nicvf_main.c|  9 +++---
 drivers/net/octeontx/smi.c   |  2 +-
 drivers/net/octeontx2/nix.c  |  2 +-
 drivers/net/octeontx2/rvu_pf.c   |  6 ++--
 drivers/net/xilinx_axi_emac.c|  2 +-
 drivers/net/xilinx_emaclite.c|  2 +-
 drivers/net/zynq_gem.c   |  2 +-
 drivers/pci/pci-aardvark.c   |  2 +-
 drivers/pci/pci-uclass.c | 36 
 drivers/pci/pci_auto.c   |  6 ++--
 drivers/pci/pcie_dw_mvebu.c  |  6 ++--
 drivers/pci/pcie_dw_ti.c |  6 ++--
 drivers/pci/pcie_ecam_generic.c  |  2 +-
 drivers/pci/pcie_fsl.c   | 16 +--
 drivers/pci/pcie_intel_fpga.c|  2 +-
 drivers/pci/pcie_layerscape_fixup.c  |  4 +--
 drivers/pci/pcie_layerscape_gen4.c   | 10 +++
 drivers/pci/pcie_layerscape_gen4_fixup.c |  2 +-
 drivers/pci/pcie_layerscape_rc.c | 12 
 drivers/pci/pcie_mediatek.c  |  2 +-
 drivers/pci/pcie_rockchip.c  |  6 ++--
 drivers/serial/serial_mcf.c  |  2 +-
 drivers/serial/serial_s5p.c  |  2 +-
 drivers/spi/altera_spi.c |  2 +-
 drivers/spi/cf_spi.c | 12 
 drivers/spi/fsl_dspi.c   |  6 ++--
 drivers/spi/fsl_espi.c   |  2 +-
 drivers/spi/octeon_spi.c |  2 +-
 drivers/spi/pic32_spi.c  |  4 +--
 drivers/spi/sandbox_spi.c|  2 +-
 drivers/spi/tegra114_spi.c   |  2 +-
 drivers/spi/tegra20_sflash.c |  2 +-
 drivers/spi/tegra20_slink.c  |  2 +-
 drivers/spi/tegra210_qspi.c  |  2 +-
 drivers/spi/xilinx_spi.c |  2 +-
 drivers/spi/zynq_qspi.c  |  2 +-
 drivers/spi/zynq_spi.c   |  2 +-
 drivers/usb/gadget/max3420_udc.c |  2 +-
 drivers/usb/host/ehci-mx5.c  |  2 +-
 drivers/usb/host/ehci-mx6.c  |  2 +-
 drivers/usb/host/ehci-omap.c |  2 +-
 drivers/usb/host/ehci-vf.c   |  2 +-
 drivers/usb/host/usb-sandbox.c   |  2 +-
 drivers/usb/host/usb-uclass.c|  2 +-
 drivers/video/vidconsole-uclass.c|  4 +--
 drivers/virtio/virtio-uclass.c   |  2 +-
 drivers/watchdog/ast_wdt.c   |  2 +-
 drivers/watchdog/at91sam9_wdt.c  |  2 +-
 drivers/watchdog/cdns_wdt.c  |  2 +-
 drivers/watchdog/omap_wdt.c  |  2 +-
 drivers/watchdog/orion_wdt.c |  2 +-
 drivers/watchdog/sbsa_gwdt.c |  2 +-
 drivers/watchdog/sp805_wdt.c |  2 +-
 drivers/watchdog/tangier_wdt.c   |  2 +-
 drivers/watchdog/xilinx_tb_wdt.c |  2 +-
 

[PATCH 00/27] dm: Change the way sequence numbers are implemented

2020-11-29 Thread Simon Glass
At present each device has two sequence numbers, with 'req_seq' being
set up at bind time and 'seq' at probe time. The idea is that devices
can 'request' a sequence number and then the conflicts are resolved when
the device is probed.

This makes things complicated in a few cases, since we don't really know
(at bind time) what the sequence number will end up being. We want to
honour the bind-time requests if at all possible, but in fact the only
source of these at present is the devicetree aliases.

Apart from the obvious need for sequence numbers to supports U-Boot's
numbering on devices on the command line, the current scheme was
designed to:

- avoid calculating the sequence number until it is needed, to save
  execution time
- allow multiple devices to obtain a particular sequence number as they
  are probed and removed
- retain a record of the 'requested' sequence number even if it turns out
  that a device could not get it (to allow debugging and retrying)

After some years using the current scheme it seems on balance that these
goals don't have as much merit as first thought. The first point would
be persuasive except that we end up reading the devicetree aliases at
bind-time anyway. So the work of resolving the sequence numbers during
probing is not that great. The second point hasn't really been an issue,
as there is typically no contention for sequence numbers (boards tend to
allocate them statically in the devicetree). Re the third point, we can
often figure out what was requested by looking at aliases, and in the
cases where we can't, it doesn't seem to matter much.

Since we have the devicetree available at bind time, we may as well just
use it, in the hope that the required processing will turn out to be
useful later (i.e. the device actually gets used). In addition, it is
simpler to use a single sequence number, since it avoids confusion and
some extra code.

This series moves U-Boot to use a single, bind-time sequence number. All
uclasses with the DM_UC_FLAG_SEQ_ALIAS flag enabled will assign sequence
numbers to their devices, so that as soon as a device is bound, it has a
sequence number. If a devicetree alias provides the number, it will be
used. Otherwise, during initial binding, the first free number is used.
For ad-hoc calls to device_bind() afterwards (e.g. from driver code), the
sequence is set to the maximum sequence number for the uclass + 1.

Apart from the simplicity gains, overall these changes seem to reduce the
number of tweaks and workarounds needed to get the desired behaviour.

However there will certainly be some problems created, so board
maintainers should test this out.


Simon Glass (27):
  linker_lists: Fix alignment issue
  efi: Drop unwanted message in efi_uc_destroy()
  dm: Avoid accessing seq directly
  dm: core: Update uclass_find_next_free_req_seq() args
  dm: core: Add a new sequence number for devices
  dm: test: Add support for new sequence numbers
  dm: core: Switch binding to use new sequence numbers
  dm: Fix return value in dev_read_alias_seq()
  dm: test: Drop assumptions of no sequence numbers
  octeon: Don't attempt to set the sequence number
  i2c: Update for new sequence numbers
  net: Update to use new sequence numbers
  pci: Update to use new sequence numbers
  spi: Update for new sequence numbers
  usb: ehci-mx6: Drop assignment of sequence number
  usb: Update for new sequence numbers
  x86: Drop unnecessary mp_init logic
  x86: Simplify acpi_device_infer_name()
  gpio: Update for new sequence numbers
  pinctrl: Update for new sequence numbers
  dm: Switch over to use new sequence number for dev_seq()
  dm: Drop uclass_resolve_seq()
  dm: Drop the unused arg in uclass_find_device_by_seq()
  dm: core: Simplify uclass_find_next_free_req_seq()
  cmd: Drop use of old sequence numbers in commands
  dm: core: Drop seq and req_seq
  dm: Update documentation for new sequence numbers

 arch/Kconfig |  11 +++
 arch/arm/include/asm/mach-imx/mxc_i2c.h  |   2 +-
 arch/arm/mach-k3/am6_init.c  |   2 +-
 arch/arm/mach-k3/j721e_init.c|   2 +-
 arch/arm/mach-k3/sysfw-loader.c  |   2 +-
 arch/sandbox/dts/test.dts|   2 +-
 arch/x86/cpu/apollolake/cpu.c|   2 +-
 arch/x86/cpu/broadwell/cpu_full.c|   2 +-
 arch/x86/cpu/ivybridge/model_206ax.c |   2 +-
 arch/x86/cpu/mp_init.c   |  23 ++---
 arch/x86/include/asm/mp.h|   2 +-
 board/xilinx/versal/board.c  |  12 +--
 board/xilinx/zynqmp/zynqmp.c |  12 +--
 cmd/axi.c|   6 +-
 cmd/cpu.c|   2 +-
 cmd/i2c.c|   6 +-
 cmd/misc.c   |   2 +-
 cmd/osd.c|   6 +-
 cmd/pci.c|   7 +-
 cmd/pmic.c   |   4 +-
 cmd/remoteproc.c |   2 +-
 cmd/w1.c 

[PATCH 18/27] x86: Simplify acpi_device_infer_name()

2020-11-29 Thread Simon Glass
There is no-longer any need to check if sequence numbers are valid, since
this is ensured by driver model. Drop the unwanted logic.

Signed-off-by: Simon Glass 
---

 lib/acpi/acpi_device.c | 27 +++
 test/dm/acpi.c |  6 +-
 2 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c
index c3439a59883..ba0e6bf9ea8 100644
--- a/lib/acpi/acpi_device.c
+++ b/lib/acpi/acpi_device.c
@@ -784,16 +784,6 @@ static const char *acpi_name_from_id(enum uclass_id id)
}
 }
 
-static int acpi_check_seq(const struct udevice *dev)
-{
-   if (dev->req_seq == -1) {
-   log_warning("Device '%s' has no seq\n", dev->name);
-   return log_msg_ret("no seq", -ENXIO);
-   }
-
-   return dev->req_seq;
-}
-
 /* If you change this function, add test cases to dm_test_acpi_get_name() */
 int acpi_device_infer_name(const struct udevice *dev, char *out_name)
 {
@@ -826,29 +816,18 @@ int acpi_device_infer_name(const struct udevice *dev, 
char *out_name)
}
}
if (!name) {
-   int num;
-
switch (id) {
/* DSDT: acpi/lpss.asl */
case UCLASS_SERIAL:
-   num = acpi_check_seq(dev);
-   if (num < 0)
-   return num;
-   sprintf(out_name, "URT%d", num);
+   sprintf(out_name, "URT%d", dev_seq(dev));
name = out_name;
break;
case UCLASS_I2C:
-   num = acpi_check_seq(dev);
-   if (num < 0)
-   return num;
-   sprintf(out_name, "I2C%d", num);
+   sprintf(out_name, "I2C%d", dev_seq(dev));
name = out_name;
break;
case UCLASS_SPI:
-   num = acpi_check_seq(dev);
-   if (num < 0)
-   return num;
-   sprintf(out_name, "SPI%d", num);
+   sprintf(out_name, "SPI%d", dev_seq(dev));
name = out_name;
break;
default:
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index f5eddac10d0..021f776845e 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -123,7 +123,7 @@ UCLASS_DRIVER(testacpi) = {
 static int dm_test_acpi_get_name(struct unit_test_state *uts)
 {
char name[ACPI_NAME_MAX];
-   struct udevice *dev, *dev2, *i2c, *spi, *serial, *timer, *sound;
+   struct udevice *dev, *dev2, *i2c, *spi, *timer, *sound;
struct udevice *pci, *root;
 
/* Test getting the name from the driver */
@@ -146,10 +146,6 @@ static int dm_test_acpi_get_name(struct unit_test_state 
*uts)
ut_assertok(acpi_get_name(spi, name));
ut_asserteq_str("SPI0", name);
 
-   /* The uart has no sequence number, so this should fail */
-   ut_assertok(uclass_first_device(UCLASS_SERIAL, ));
-   ut_asserteq(-ENXIO, acpi_get_name(serial, name));
-
/* ACPI doesn't know about the timer */
ut_assertok(uclass_first_device(UCLASS_TIMER, ));
ut_asserteq(-ENOENT, acpi_get_name(timer, name));
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 17/27] x86: Drop unnecessary mp_init logic

2020-11-29 Thread Simon Glass
Now that sequence numbers are set up when devices are bound, this code is
not needed. Also, we should use dev_seq() instead of req_seq. Update the
whole file accordingly.

Also fix up APL cpu while we are here.

Signed-off-by: Simon Glass 
---

 arch/x86/cpu/apollolake/cpu.c |  2 +-
 arch/x86/cpu/mp_init.c| 23 +++
 arch/x86/include/asm/mp.h |  2 +-
 3 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/arch/x86/cpu/apollolake/cpu.c b/arch/x86/cpu/apollolake/cpu.c
index d37f91d1ce1..328f79255f8 100644
--- a/arch/x86/cpu/apollolake/cpu.c
+++ b/arch/x86/cpu/apollolake/cpu.c
@@ -63,7 +63,7 @@ static int apl_get_info(const struct udevice *dev, struct 
cpu_info *info)
 
 static int acpi_cpu_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
 {
-   uint core_id = dev->req_seq;
+   uint core_id = dev_seq(dev);
int cores_per_package;
int ret;
 
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index d2f1ee38cf0..5bb7abdf873 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -87,7 +87,7 @@ DECLARE_GLOBAL_DATA_PTR;
  * intel,apic-id = <2>;
  * };
  *
- * Here the 'reg' property is the CPU number and then is placed in dev->req_seq
+ * Here the 'reg' property is the CPU number and then is placed in dev_seq(cpu)
  * so that we can index into ap_callbacks[] using that. The APIC ID is 
different
  * and may not be sequential (it typically is if hyperthreading is supported).
  *
@@ -135,7 +135,7 @@ struct mp_flight_plan {
  *
  * @func: Function to run
  * @arg: Argument to pass to the function
- * @logical_cpu_number: Either a CPU number (i.e. dev->req_seq) or a special
+ * @logical_cpu_number: Either a CPU number (i.e. dev_seq(cpu) or a special
  * value like MP_SELECT_BSP. It tells the AP whether it should process this
  * callback
  */
@@ -152,7 +152,7 @@ static struct mp_flight_plan mp_info;
  * ap_callbacks - Callback mailbox array
  *
  * Array of callback, one entry for each available CPU, indexed by the CPU
- * number, which is dev->req_seq. The entry for the main CPU is never used.
+ * number, which is dev_seq(cpu). The entry for the main CPU is never used.
  * When this is NULL, there is no pending work for the CPU to run. When
  * non-NULL it points to the mp_callback structure. This is shared between all
  * CPUs, so should only be written by the main CPU.
@@ -562,7 +562,7 @@ static int get_bsp(struct udevice **devp, int *cpu_countp)
if (cpu_countp)
*cpu_countp = ret;
 
-   return dev->req_seq >= 0 ? dev->req_seq : 0;
+   return dev_seq(dev) >= 0 ? dev_seq(dev) : 0;
 }
 
 /**
@@ -614,7 +614,7 @@ static void store_callback(struct mp_callback **slot, 
struct mp_callback *val)
 static int run_ap_work(struct mp_callback *callback, struct udevice *bsp,
   int num_cpus, uint expire_ms)
 {
-   int cur_cpu = bsp->req_seq;
+   int cur_cpu = dev_seq(bsp);
int num_aps = num_cpus - 1; /* number of non-BSPs to get this message */
int cpus_accepted;
ulong start;
@@ -679,7 +679,7 @@ static int ap_wait_for_instruction(struct udevice *cpu, 
void *unused)
if (!IS_ENABLED(CONFIG_SMP_AP_WORK))
return 0;
 
-   per_cpu_slot = _callbacks[cpu->req_seq];
+   per_cpu_slot = _callbacks[dev_seq(cpu)];
 
while (1) {
struct mp_callback *cb = read_callback(per_cpu_slot);
@@ -694,7 +694,7 @@ static int ap_wait_for_instruction(struct udevice *cpu, 
void *unused)
mfence();
if (lcb.logical_cpu_number == MP_SELECT_ALL ||
lcb.logical_cpu_number == MP_SELECT_APS ||
-   cpu->req_seq == lcb.logical_cpu_number)
+   dev_seq(cpu) == lcb.logical_cpu_number)
lcb.func(lcb.arg);
 
/* Indicate we are finished */
@@ -839,7 +839,6 @@ int mp_init(void)
int num_aps, num_cpus;
atomic_t *ap_count;
struct udevice *cpu;
-   struct uclass *uc;
int ret;
 
if (IS_ENABLED(CONFIG_QFW)) {
@@ -848,14 +847,6 @@ int mp_init(void)
return ret;
}
 
-   /*
-* Multiple APs are brought up simultaneously and they may get the same
-* seq num in the uclass_resolve_seq() during device_probe(). To avoid
-* this, set req_seq to the reg number in the device tree in advance.
-*/
-   uclass_id_foreach_dev(UCLASS_CPU, cpu, uc)
-   cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
-
ret = get_bsp(, _cpus);
if (ret < 0) {
debug("Cannot init boot CPU: err=%d\n", ret);
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index 5f9b8c65643..1e4e35321de 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -114,7 +114,7 @@ typedef void (*mp_run_func)(void *arg);
  * Running on anything other than the 

[PATCH 19/27] gpio: Update for new sequence numbers

2020-11-29 Thread Simon Glass
Use the dev_seq() sequence number in all cases.

Signed-off-by: Simon Glass 
---

 drivers/gpio/imx_rgpio2p.c | 2 +-
 drivers/gpio/iproc_gpio.c  | 2 +-
 drivers/gpio/mvebu_gpio.c  | 2 +-
 drivers/gpio/mxc_gpio.c| 2 +-
 drivers/gpio/vybrid_gpio.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c
index 1e876f69147..428844db0cc 100644
--- a/drivers/gpio/imx_rgpio2p.c
+++ b/drivers/gpio/imx_rgpio2p.c
@@ -183,7 +183,7 @@ static int imx_rgpio2p_bind(struct udevice *dev)
return -ENOMEM;
 
plat->regs = (struct gpio_regs *)addr;
-   plat->bank_index = dev->req_seq;
+   plat->bank_index = dev_seq(dev);
dev->platdata = plat;
 
return 0;
diff --git a/drivers/gpio/iproc_gpio.c b/drivers/gpio/iproc_gpio.c
index cc26a1306b6..2371d0d0d77 100644
--- a/drivers/gpio/iproc_gpio.c
+++ b/drivers/gpio/iproc_gpio.c
@@ -252,7 +252,7 @@ static int iproc_gpio_ofdata_to_platdata(struct udevice 
*dev)
return ret;
}
 
-   snprintf(name, sizeof(name), "GPIO%d", dev->req_seq);
+   snprintf(name, sizeof(name), "GPIO%d", dev_seq(dev));
plat->name = strdup(name);
if (!plat->name)
return -ENOMEM;
diff --git a/drivers/gpio/mvebu_gpio.c b/drivers/gpio/mvebu_gpio.c
index 65eaa71c201..3639388e2f7 100644
--- a/drivers/gpio/mvebu_gpio.c
+++ b/drivers/gpio/mvebu_gpio.c
@@ -92,7 +92,7 @@ static int mvebu_gpio_probe(struct udevice *dev)
 
priv->regs = dev_read_addr_ptr(dev);
uc_priv->gpio_count = MVEBU_GPIOS_PER_BANK;
-   priv->name[0] = 'A' + dev->req_seq;
+   priv->name[0] = 'A' + dev_seq(dev);
uc_priv->bank_name = priv->name;
 
return 0;
diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 88b920a0746..28ca57149c1 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -318,7 +318,7 @@ static int mxc_gpio_ofdata_to_platdata(struct udevice *dev)
 
plat->regs = (struct gpio_regs *)addr;
}
-   plat->bank_index = dev->req_seq;
+   plat->bank_index = dev_seq(dev);
 
return 0;
 }
diff --git a/drivers/gpio/vybrid_gpio.c b/drivers/gpio/vybrid_gpio.c
index 4efff5c3643..0474d2df2da 100644
--- a/drivers/gpio/vybrid_gpio.c
+++ b/drivers/gpio/vybrid_gpio.c
@@ -114,7 +114,7 @@ static int vybrid_gpio_odata_to_platdata(struct udevice 
*dev)
return -EINVAL;
 
plat->base = base_addr;
-   plat->chip = dev->req_seq;
+   plat->chip = dev_seq(dev);
plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL);
 
return 0;
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 20/27] pinctrl: Update for new sequence numbers

2020-11-29 Thread Simon Glass
Use the dev_seq() sequence number in all cases.

Signed-off-by: Simon Glass 
---

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

diff --git a/drivers/pinctrl/exynos/pinctrl-exynos.c 
b/drivers/pinctrl/exynos/pinctrl-exynos.c
index 4cdc071d559..64d78213a86 100644
--- a/drivers/pinctrl/exynos/pinctrl-exynos.c
+++ b/drivers/pinctrl/exynos/pinctrl-exynos.c
@@ -133,7 +133,7 @@ int exynos_pinctrl_probe(struct udevice *dev)
 
priv->base = base;
priv->pin_ctrl = (struct samsung_pin_ctrl *)dev_get_driver_data(dev) +
-   dev->req_seq;
+   dev_seq(dev);
 
return 0;
 }
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 27/27] dm: Update documentation for new sequence numbers

2020-11-29 Thread Simon Glass
Update the driver model documention to describe how sequence numbers now
work.

Signed-off-by: Simon Glass 
---

 doc/driver-model/design.rst | 58 +
 1 file changed, 33 insertions(+), 25 deletions(-)

diff --git a/doc/driver-model/design.rst b/doc/driver-model/design.rst
index 96525b6ccc5..2db00e660e1 100644
--- a/doc/driver-model/design.rst
+++ b/doc/driver-model/design.rst
@@ -515,11 +515,15 @@ cases. While it might be tempting to automatically 
renumber the devices
 where there are gaps in the sequence, this can lead to confusion and is
 not the way that U-Boot works.
 
-Each device can request a sequence number. If none is required then the
-device will be automatically allocated the next available sequence number.
+Whether a device gets a sequence number is controlled by the DM_SEQ_ALIAS
+Kconfig option, which can have a different value in U-Boot proper and SPL.
+If this option is not set, aliases are ignored and no devices will get
+sequence numbers.
 
-To specify the sequence number in the device tree an alias is typically
-used. Make sure that the uclass has the DM_UC_FLAG_SEQ_ALIAS flag set.
+Even if DM_SEQ_ALIAS is enabled, the uclass must have the DM_UC_FLAG_SEQ_ALIAS
+flag set, for its devices to be sequenced. If DM_UC_FLAG_SEQ_ALIAS is set for
+the uclass, all devices in that uclass will get a sequence number, either one
+set from the aliases, or the next available sequence number.
 
 .. code-block:: none
 
@@ -546,12 +550,23 @@ More commonly you can use node references, which expand 
to the full path:
 The alias resolves to the same string in this case, but this version is
 easier to read.
 
-Device sequence numbers are resolved when a device is probed. Before then
-the sequence number is only a request which may or may not be honoured,
-depending on what other devices have been probed. However the numbering is
-entirely under the control of the board author so a conflict is generally
-an error.
+Device sequence numbers are resolved when a device is bound and the number does
+not change for the life of the device.
 
+When U-Boot initially binds all its devices, it sets a flag called
+GD_FLG_DM_NO_SEQ. This makes it check the aliases first. Then the devices with
+no alias fill in the gaps.
+
+For example, if aliases mmc2 and mmc3 are defined but there is a third mmc
+device with no alias, it will be assigned a sequence number of 0. However once
+the initial setup is complete, the GD_FLG_DM_NO_SEQ flag is cleared and further
+devices will be assigned numbers after all existing ones for that uclass. So
+in this case calling device_bind() for a fourth mmc device will cause it to
+get a sequence number of 4, not 1. This helps separate the aliases (which are
+considered officially allocated numbers) from ad-hoc devices.
+
+Note that changing the sequence number for a device (e.g. in driver) is not
+permitted. If it is felt to be necessary, ask on the mailing list.
 
 Bus Drivers
 ---
@@ -673,6 +688,10 @@ platdata will be NULL, but of_offset will be the offset of 
the device tree
 node that caused the device to be created. The uclass is set correctly for
 the device.
 
+The device's sequence number is assigned, either the requested one or the next
+available one (after all aliases are processed) if nothing particular is
+requested.
+
 The device's bind() method is permitted to perform simple actions, but
 should not scan the device tree node, not initialise hardware, nor set up
 structures or allocate memory. All of these tasks should be left for
@@ -735,7 +754,7 @@ The steps are:
that U-Boot will cache platform data for devices which are regularly
de/activated).
 
-   5. The device is marked 'platdata valid'.
+   6. The device is marked 'platdata valid'.
 
 Note that ofdata reading is always done (for a child and all its parents)
 before probing starts. Thus devices go through two distinct states when
@@ -780,11 +799,7 @@ as above and then following these steps (see 
device_probe()):
This means (for example) that an I2C driver will require that its bus
be activated.
 
-   2. The device's sequence number is assigned, either the requested one
-   (assuming no conflicts) or the next available one if there is a conflict
-   or nothing particular is requested.
-
-   4. The device's probe() method is called. This should do anything that
+   2. The device's probe() method is called. This should do anything that
is required by the device to get it going. This could include checking
that the hardware is actually present, setting up clocks for the
hardware and setting up hardware registers to initial values. The code
@@ -799,9 +814,9 @@ as above and then following these steps (see 
device_probe()):
allocate the priv space here yourself. The same applies also to
platdata_auto_alloc_size. Remember to free them in the remove() method.
 
-   5. The device is marked 'activated'
+   3. The device is marked 'activated'
 
-   10. The 

[PATCH 26/27] dm: core: Drop seq and req_seq

2020-11-29 Thread Simon Glass
Now that migration to the new sequence numbers is complete, drop the old
fields. Add a test that covers the new behaviour.

Also drop the check for OF_PRIOR_STAGE since we always assign sequence
numbers now.

Signed-off-by: Simon Glass 
---

 drivers/core/device-remove.c |  1 -
 drivers/core/device.c| 18 +++---
 include/dm/device.h  |  9 +
 test/dm/test-fdt.c   | 28 
 4 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index efdb0f29058..114bb1bcea8 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -207,7 +207,6 @@ int device_remove(struct udevice *dev, uint flags)
if (flags_remove(flags, drv->flags)) {
device_free(dev);
 
-   dev->seq = -1;
dev->flags &= ~DM_FLAG_ACTIVATED;
}
 
diff --git a/drivers/core/device.c b/drivers/core/device.c
index d9648f9394e..bcf437ac231 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -72,34 +72,23 @@ static int device_bind_common(struct udevice *parent, const 
struct driver *drv,
dev->driver = drv;
dev->uclass = uc;
 
-   dev->seq = -1;
-   dev->req_seq = -1;
dev->sqq = -1;
if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
(uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
/*
 * Some devices, such as a SPI bus, I2C bus and serial ports
 * are numbered using aliases.
-*
-* This is just a 'requested' sequence, and will be
-* resolved (and ->seq updated) when the device is probed.
 */
if (CONFIG_IS_ENABLED(OF_CONTROL) &&
!CONFIG_IS_ENABLED(OF_PLATDATA)) {
if (uc->uc_drv->name && ofnode_valid(node)) {
-   dev_read_alias_seq(dev, >sqq);
-   dev_read_alias_seq(dev, >req_seq);
-   }
-   if (CONFIG_IS_ENABLED(OF_PRIOR_STAGE)) {
-   if (dev->req_seq == -1) {
+   if (dev_read_alias_seq(dev, >sqq))
auto_seq = true;
-   dev->req_seq =
-   uclass_find_next_free_seq(uc);
-   }
+   } else {
+   auto_seq = true;
}
} else {
auto_seq = true;
-   dev->req_seq = uclass_find_next_free_seq(uc);
}
if (auto_seq && !(gd->flags & GD_FLG_DM_NO_SEQ))
dev->sqq = uclass_find_next_free_seq(uc);
@@ -518,7 +507,6 @@ fail_uclass:
 fail:
dev->flags &= ~DM_FLAG_ACTIVATED;
 
-   dev->seq = -1;
device_free(dev);
 
return ret;
diff --git a/include/dm/device.h b/include/dm/device.h
index 073c5438fc2..b95aa346820 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -131,16 +131,11 @@ enum {
  * @child_head: List of children of this device
  * @sibling_node: Next device in list of all devices
  * @flags: Flags for this device DM_FLAG_...
- * @sqq: Allocated sequence number for this device (-1 = none). This is set up
+ * @seq: Allocated sequence number for this device (-1 = none). This is set up
  * when the device is bound and is unique within the device's uclass. If the
  * device has an alias in the devicetree then that is used to set the sequence
  * number. Otherwise, the next available number is used. Sequence numbers are
  * used by certain commands that need device to be numbered (e.g. 'mmc dev')
- *
- * The following two fields are deprecated:
- * @req_seq: Requested sequence number for this device (-1 = any)
- * @seq: Allocated sequence number for this device (-1 = none). This is set up
- * when the device is probed and will be unique within the device's uclass.
  * @devres_head: List of memory allocations associated with this device.
  * When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
  * add to this list. Memory so-allocated will be freed
@@ -164,8 +159,6 @@ struct udevice {
struct list_head sibling_node;
uint32_t flags;
int sqq;
-   int req_seq;
-   int seq;
 #ifdef CONFIG_DEVRES
struct list_head devres_head;
 #endif
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 50267f2fc26..c4de91da102 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -386,6 +386,34 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state 
*uts)
 }
 DM_TEST(dm_test_fdt_uclass_seq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+/* More tests for sequence numbers */
+static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+ 

[PATCH 24/27] dm: core: Simplify uclass_find_next_free_req_seq()

2020-11-29 Thread Simon Glass
This function current deals with req_seq which is deprecated. Update it to
use the new sequence numbers. Rename the function to make this clear.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c|  7 +++
 drivers/core/uclass.c|  6 +++---
 include/dm/uclass-internal.h | 14 +++---
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index d57a8bc1343..d9648f9394e 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -94,16 +94,15 @@ static int device_bind_common(struct udevice *parent, const 
struct driver *drv,
if (dev->req_seq == -1) {
auto_seq = true;
dev->req_seq =
-   uclass_find_next_free_req_seq(
-   uc);
+   uclass_find_next_free_seq(uc);
}
}
} else {
auto_seq = true;
-   dev->req_seq = uclass_find_next_free_req_seq(uc);
+   dev->req_seq = uclass_find_next_free_seq(uc);
}
if (auto_seq && !(gd->flags & GD_FLG_DM_NO_SEQ))
-   dev->sqq = uclass_find_next_free_req_seq(uc);
+   dev->sqq = uclass_find_next_free_seq(uc);
}
 
if (drv->platdata_auto_alloc_size) {
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 48d81221c38..8d5e92da288 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -272,14 +272,14 @@ int uclass_find_device_by_name(enum uclass_id id, const 
char *name,
return -ENODEV;
 }
 
-int uclass_find_next_free_req_seq(struct uclass *uc)
+int uclass_find_next_free_seq(struct uclass *uc)
 {
struct udevice *dev;
int max = -1;
 
list_for_each_entry(dev, >dev_head, uclass_node) {
-   if ((dev->req_seq != -1) && (dev->req_seq > max))
-   max = dev->req_seq;
+   if (dev->sqq != -1 && dev->sqq > max)
+   max = dev->sqq;
}
 
if (max == -1)
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index 9c23d3f223e..50431bd847c 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -12,17 +12,17 @@
 #include 
 
 /**
- * uclass_find_next_free_req_seq() - Get the next free req_seq number
+ * uclass_find_next_free_seq() - Get the next free sequence number
  *
- * This returns the next free req_seq number. This is useful only if
- * OF_CONTROL is not used. The next free req_seq number is simply the
- * maximum req_seq of the uclass + 1.
- * This allows assiging req_seq number in the binding order.
+ * This returns the next free sequence number. This is useful only if
+ * OF_CONTROL is not used. The next free sequence number is simply the
+ * maximum sequence number used by al devices in the uclass + 1.
+ * This allows assiging the sequence number in the binding order.
  *
  * @uc:uclass to check
- * @return The next free req_seq number
+ * @return The next free sequence number
  */
-int uclass_find_next_free_req_seq(struct uclass *uc);
+int uclass_find_next_free_seq(struct uclass *uc);
 
 /**
  * uclass_get_device_tail() - handle the end of a get_device call
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 25/27] cmd: Drop use of old sequence numbers in commands

2020-11-29 Thread Simon Glass
Several commands use sequence numbers. Update them to use the new ones.

Signed-off-by: Simon Glass 
---

 cmd/axi.c   | 4 ++--
 cmd/i2c.c   | 2 +-
 cmd/osd.c   | 4 ++--
 drivers/core/dump.c | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cmd/axi.c b/cmd/axi.c
index f7e206c04a7..c72197ee82b 100644
--- a/cmd/axi.c
+++ b/cmd/axi.c
@@ -33,9 +33,9 @@ static void show_bus(struct udevice *bus)
 {
struct udevice *dev;
 
-   printf("Bus %d:\t%s", bus->req_seq, bus->name);
+   printf("Bus %d:\t%s", dev_seq(bus), bus->name);
if (device_active(bus))
-   printf("  (active %d)", dev_seq(bus));
+   printf("  (active)");
printf("\n");
for (device_find_first_child(bus, );
 dev;
diff --git a/cmd/i2c.c b/cmd/i2c.c
index f97d437af47..c5cace6a9c6 100644
--- a/cmd/i2c.c
+++ b/cmd/i2c.c
@@ -1700,7 +1700,7 @@ static void show_bus(struct udevice *bus)
 {
struct udevice *dev;
 
-   printf("Bus %d:\t%s", bus->req_seq, bus->name);
+   printf("Bus %d:\t%s", dev_seq(bus), bus->name);
if (device_active(bus))
printf("  (active %d)", dev_seq(bus));
printf("\n");
diff --git a/cmd/osd.c b/cmd/osd.c
index 9b8fd5c921e..703d640b04e 100644
--- a/cmd/osd.c
+++ b/cmd/osd.c
@@ -75,9 +75,9 @@ static int osd_get_osd_cur(struct udevice **osdp)
  */
 static void show_osd(struct udevice *osd)
 {
-   printf("OSD %d:\t%s", osd->req_seq, osd->name);
+   printf("OSD %d:\t%s", dev_seq(osd), osd->name);
if (device_active(osd))
-   printf("  (active %d)", dev_seq(osd));
+   printf("  (active)");
printf("\n");
 }
 
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index 9f440366734..83456d7e6e8 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -67,8 +67,8 @@ static void dm_display_line(struct udevice *dev, int index)
printf("%-3i %c %s @ %08lx", index,
   dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
   dev->name, (ulong)map_to_sysmem(dev));
-   if (dev_seq(dev) != -1 || dev->req_seq != -1)
-   printf(", seq %d, (req %d)", dev_seq(dev), dev->req_seq);
+   if (dev->sqq != -1)
+   printf(", seq %d", dev_seq(dev));
puts("\n");
 }
 
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 23/27] dm: Drop the unused arg in uclass_find_device_by_seq()

2020-11-29 Thread Simon Glass
Now that there is only one sequence number (rather than both requested and
assigned ones) we can simplify this function. Also update its caller to
simplify the logic.

Signed-off-by: Simon Glass 
---

 arch/arm/mach-k3/am6_init.c |  2 +-
 arch/arm/mach-k3/j721e_init.c   |  2 +-
 arch/arm/mach-k3/sysfw-loader.c |  2 +-
 drivers/core/device.c   | 16 +
 drivers/core/uclass.c   | 22 ++
 drivers/spi/spi-uclass.c|  4 ++--
 drivers/usb/host/usb-uclass.c   |  4 ++--
 include/dm/device.h | 18 +--
 include/dm/uclass-internal.h| 18 +--
 net/eth-uclass.c|  2 +-
 test/dm/bus.c   | 16 ++---
 test/dm/test-fdt.c  | 40 -
 12 files changed, 58 insertions(+), 88 deletions(-)

diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c
index 603834e5078..0fed5aec59d 100644
--- a/arch/arm/mach-k3/am6_init.c
+++ b/arch/arm/mach-k3/am6_init.c
@@ -208,7 +208,7 @@ void board_init_f(ulong dummy)
 * firmware (SYSFW) image for various purposes and SYSFW depends on us
 * to initialize its pin settings.
 */
-   ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, );
+   ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, );
if (!ret)
pinctrl_select_state(dev, "default");
 
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index a36e4ed603b..0201690f93c 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -167,7 +167,7 @@ void board_init_f(ulong dummy)
 * firmware (SYSFW) image for various purposes and SYSFW depends on us
 * to initialize its pin settings.
 */
-   ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, );
+   ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, );
if (!ret)
pinctrl_select_state(dev, "default");
 
diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
index 78c158c63f7..708d9c8508e 100644
--- a/arch/arm/mach-k3/sysfw-loader.c
+++ b/arch/arm/mach-k3/sysfw-loader.c
@@ -223,7 +223,7 @@ static void *k3_sysfw_get_spi_addr(void)
int ret;
 
ret = uclass_find_device_by_seq(UCLASS_SPI, CONFIG_SF_DEFAULT_BUS,
-   true, );
+   );
if (ret)
return NULL;
 
diff --git a/drivers/core/device.c b/drivers/core/device.c
index df188620149..d57a8bc1343 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -653,15 +653,15 @@ int device_get_child_count(const struct udevice *parent)
return count;
 }
 
-int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq,
-bool find_req_seq, struct udevice **devp)
+int device_find_child_by_seq(const struct udevice *parent, int seq,
+struct udevice **devp)
 {
struct udevice *dev;
 
*devp = NULL;
 
list_for_each_entry(dev, >child_head, sibling_node) {
-   if (dev->sqq == seq_or_req_seq) {
+   if (dev->sqq == seq) {
*devp = dev;
return 0;
}
@@ -677,14 +677,8 @@ int device_get_child_by_seq(const struct udevice *parent, 
int seq,
int ret;
 
*devp = NULL;
-   ret = device_find_child_by_seq(parent, seq, false, );
-   if (ret == -ENODEV) {
-   /*
-* We didn't find it in probed devices. See if there is one
-* that will request this seq if probed.
-*/
-   ret = device_find_child_by_seq(parent, seq, true, );
-   }
+   ret = device_find_child_by_seq(parent, seq, );
+
return device_get_device_tail(dev, ret, devp);
 }
 
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index b63ebb5d1e7..48d81221c38 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -328,25 +328,23 @@ void uclass_alloc_all_seqs(void)
}
 }
 
-int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
- bool find_req_seq, struct udevice **devp)
+int uclass_find_device_by_seq(enum uclass_id id, int seq, struct udevice 
**devp)
 {
struct uclass *uc;
struct udevice *dev;
int ret;
 
*devp = NULL;
-   log_debug("%d %d\n", find_req_seq, seq_or_req_seq);
-   if (seq_or_req_seq == -1)
+   log_debug("%d\n", seq);
+   if (seq == -1)
return -ENODEV;
ret = uclass_get(id, );
if (ret)
return ret;
 
uclass_foreach_dev(dev, uc) {
-   log_debug("   - %d %d '%s'\n",
- dev->req_seq, dev_seq(dev), dev->name);
-   if (dev_seq(dev) == seq_or_req_seq) {
+   log_debug("   - %d '%s'\n", dev->sqq, dev->name);
+   if (dev->sqq 

[PATCH 16/27] usb: Update for new sequence numbers

2020-11-29 Thread Simon Glass
Use the new sequence number in all cases. Since all devices are assigned
a number when bound, this hack should not be needed.

Signed-off-by: Simon Glass 
---

 drivers/usb/host/ehci-vf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 92b70ba1b30..dd82669b284 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -296,16 +296,14 @@ static const struct ehci_ops vf_ehci_ops = {
 
 static int vf_usb_bind(struct udevice *dev)
 {
-   static int num_controllers;
-
/*
 * Without this hack, if we return ENODEV for USB Controller 0, on
 * probe for the next controller, USB Controller 1 will be given a
 * sequence number of 0. This conflicts with our requirement of
 * sequence numbers while initialising the peripherals.
+*
+* FIXME: Check that this still works OK with the new sequence numbers
 */
-   dev->req_seq = num_controllers;
-   num_controllers++;
 
return 0;
 }
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 21/27] dm: Switch over to use new sequence number for dev_seq()

2020-11-29 Thread Simon Glass
Update this function to use the new sequence number and fix up the test
that deals with this.

For networking, the sequence number has changed, so update to code to
suit.

Signed-off-by: Simon Glass 
---

 arch/sandbox/dts/test.dts |  2 +-
 drivers/core/uclass.c |  6 ++
 include/configs/sandbox.h |  2 +-
 include/dm/device.h   |  2 +-
 test/dm/eth.c | 14 ++---
 test/dm/test-fdt.c| 42 +--
 6 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index f3b766271d3..fb838049be5 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -33,7 +33,7 @@
testfdt6 = "/e-test";
testbus3 = "/some-bus";
testfdt0 = "/some-bus/c-test@0";
-   testfdt1 = "/some-bus/c-test@1";
+   testfdt12 = "/some-bus/c-test@1";
testfdt3 = "/b-test";
testfdt5 = "/some-bus/c-test@5";
testfdt8 = "/a-test";
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index d4de88bfb57..e28eea05f62 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -346,8 +346,7 @@ int uclass_find_device_by_seq(enum uclass_id id, int 
seq_or_req_seq,
uclass_foreach_dev(dev, uc) {
log_debug("   - %d %d '%s'\n",
  dev->req_seq, dev_seq(dev), dev->name);
-   if ((find_req_seq ? dev->req_seq : dev_seq(dev)) ==
-   seq_or_req_seq) {
+   if (dev_seq(dev) == seq_or_req_seq) {
*devp = dev;
log_debug("   - found\n");
return 0;
@@ -732,8 +731,7 @@ int uclass_resolve_seq(struct udevice *dev)
assert(dev_seq(dev) == -1);
ret = uclass_find_device_by_seq(uc_drv->id, dev->req_seq, false, );
if (!ret) {
-   dm_warn("Device '%s': seq %d is in use by '%s'\n",
-   dev->name, dev->req_seq, dup->name);
+   /* Do nothing here for now */
} else if (ret == -ENODEV) {
/* Our requested sequence number is available */
if (dev->req_seq != -1)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index e0708fe5739..70433bf5760 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -95,7 +95,7 @@
 #define SANDBOX_ETH_SETTINGS   "ethaddr=00:00:11:22:33:44\0" \
"eth3addr=00:00:11:22:33:45\0" \
"eth5addr=00:00:11:22:33:46\0" \
-   "eth6addr=00:00:11:22:33:47\0" \
+   "eth1addr=00:00:11:22:33:47\0" \
"ipaddr=1.2.3.4\0"
 
 #define MEM_LAYOUT_ENV_SETTINGS \
diff --git a/include/dm/device.h b/include/dm/device.h
index 80cd0955362..3362569dc98 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -192,7 +192,7 @@ static inline bool dev_has_of_node(struct udevice *dev)
 
 static inline int dev_seq(const struct udevice *dev)
 {
-   return dev->seq;
+   return dev->sqq;
 }
 
 /**
diff --git a/test/dm/eth.c b/test/dm/eth.c
index fa8a69da701..8e0d784a92d 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -49,7 +49,7 @@ static int dm_test_eth_alias(struct unit_test_state *uts)
ut_assertok(net_loop(PING));
ut_asserteq_str("eth@10002000", env_get("ethact"));
 
-   env_set("ethact", "eth6");
+   env_set("ethact", "eth1");
ut_assertok(net_loop(PING));
ut_asserteq_str("eth@10004000", env_get("ethact"));
 
@@ -106,7 +106,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)
const char *ethname[DM_TEST_ETH_NUM] = {"eth@10002000", "eth@10003000",
"sbe5", "eth@10004000"};
const char *addrname[DM_TEST_ETH_NUM] = {"ethaddr", "eth5addr",
-"eth3addr", "eth6addr"};
+"eth3addr", "eth1addr"};
char ethaddr[DM_TEST_ETH_NUM][18];
int i;
 
@@ -189,15 +189,15 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
 
/* Invalidate eth1's MAC address */
memset(ethaddr, '\0', sizeof(ethaddr));
-   strncpy(ethaddr, env_get("eth6addr"), 17);
-   /* Must disable access protection for eth6addr before clearing */
-   env_set(".flags", "eth6addr");
-   env_set("eth6addr", NULL);
+   strncpy(ethaddr, env_get("eth1addr"), 17);
+   /* Must disable access protection for eth1addr before clearing */
+   env_set(".flags", "eth1addr");
+   env_set("eth1addr", NULL);
 
retval = _dm_test_eth_rotate1(uts);
 
/* Restore the env */
-   env_set("eth6addr", ethaddr);
+   env_set("eth1addr", ethaddr);
env_set("ethrotate", NULL);
 
if 

[PATCH 22/27] dm: Drop uclass_resolve_seq()

2020-11-29 Thread Simon Glass
This function is not needed anymore. Drop it.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c |  8 
 drivers/core/uclass.c | 39 ---
 include/dm/uclass.h   | 15 ---
 3 files changed, 62 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index bd58a9e946d..df188620149 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -427,7 +427,6 @@ int device_probe(struct udevice *dev)
 {
const struct driver *drv;
int ret;
-   int seq;
 
if (!dev)
return -EINVAL;
@@ -458,13 +457,6 @@ int device_probe(struct udevice *dev)
return 0;
}
 
-   seq = uclass_resolve_seq(dev);
-   if (seq < 0) {
-   ret = seq;
-   goto fail;
-   }
-   dev->seq = seq;
-
dev->flags |= DM_FLAG_ACTIVATED;
 
/*
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index e28eea05f62..b63ebb5d1e7 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -720,45 +720,6 @@ int uclass_unbind_device(struct udevice *dev)
 }
 #endif
 
-int uclass_resolve_seq(struct udevice *dev)
-{
-   struct uclass *uc = dev->uclass;
-   struct uclass_driver *uc_drv = uc->uc_drv;
-   struct udevice *dup;
-   int seq = 0;
-   int ret;
-
-   assert(dev_seq(dev) == -1);
-   ret = uclass_find_device_by_seq(uc_drv->id, dev->req_seq, false, );
-   if (!ret) {
-   /* Do nothing here for now */
-   } else if (ret == -ENODEV) {
-   /* Our requested sequence number is available */
-   if (dev->req_seq != -1)
-   return dev->req_seq;
-   } else {
-   return ret;
-   }
-
-   if (CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
-   (uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
-   /*
-* dev_read_alias_highest_id() will return -1 if there no
-* alias. Thus we can always add one.
-*/
-   seq = dev_read_alias_highest_id(uc_drv->name) + 1;
-   }
-
-   for (; seq < DM_MAX_SEQ; seq++) {
-   ret = uclass_find_device_by_seq(uc_drv->id, seq, false, );
-   if (ret == -ENODEV)
-   break;
-   if (ret)
-   return ret;
-   }
-   return seq;
-}
-
 int uclass_pre_probe_device(struct udevice *dev)
 {
struct uclass_driver *uc_drv;
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index d1906236976..69a073a2733 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -365,21 +365,6 @@ int uclass_next_device_check(struct udevice **devp);
 int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
struct udevice **devp);
 
-/**
- * uclass_resolve_seq() - Resolve a device's sequence number
- *
- * On entry dev->seq is -1, and dev->req_seq may be -1 (to allocate a
- * sequence number automatically, or >= 0 to select a particular number.
- * If the requested sequence number is in use, then this device will
- * be allocated another one.
- *
- * Note that the device's seq value is not changed by this function.
- *
- * @dev: Device for which to allocate sequence number
- * @return sequence number allocated, or -ve on error
- */
-int uclass_resolve_seq(struct udevice *dev);
-
 /**
  * uclass_alloc_all_seqs() - Make sure that all devices have sequence numbers
  *
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 15/27] usb: ehci-mx6: Drop assignment of sequence number

2020-11-29 Thread Simon Glass
This hack cannot work in the new sequence-numbering scheme. Remove it
while we wait for the maintainer to complete DM conversion as noted in
the existing comment.

Signed-off-by: Simon Glass 
---

 drivers/usb/host/ehci-mx6.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 8fa136f4eeb..d7a6ee6d0e6 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -569,10 +569,16 @@ static int ehci_usb_bind(struct udevice *dev)
 * With these changes in place, the ad-hoc indexing goes away and
 * the driver is fully converted to DT probing.
 */
-   u32 controller_spacing = is_mx7() ? 0x1 : 0x200;
-   fdt_addr_t addr = devfdt_get_addr_index(dev, 0);
 
-   dev->req_seq = (addr - USB_BASE_ADDR) / controller_spacing;
+   /*
+* FIXME: This cannot work with the new sequence numbers.
+* Please complete the DM conversion.
+*
+* u32 controller_spacing = is_mx7() ? 0x1 : 0x200;
+* fdt_addr_t addr = devfdt_get_addr_index(dev, 0);
+*
+* dev->req_seq = (addr - USB_BASE_ADDR) / controller_spacing;
+*/
 
return 0;
 }
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 14/27] spi: Update for new sequence numbers

2020-11-29 Thread Simon Glass
Use the new sequence number in all cases. Drop the rockchip case because
the sequence number should be 0 anyway, and assigning to the sequence
number is not permitted.

Signed-off-by: Simon Glass 
---

 drivers/spi/fsl_dspi.c | 2 +-
 drivers/spi/rk_spi.c   | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/spi/fsl_dspi.c b/drivers/spi/fsl_dspi.c
index 71b045e04cb..67807b2e109 100644
--- a/drivers/spi/fsl_dspi.c
+++ b/drivers/spi/fsl_dspi.c
@@ -569,7 +569,7 @@ static int fsl_dspi_release_bus(struct udevice *dev)
  */
 static int fsl_dspi_bind(struct udevice *bus)
 {
-   debug("%s assigned req_seq %d.\n", bus->name, bus->req_seq);
+   debug("%s assigned seq %d.\n", bus->name, dev_seq(bus));
return 0;
 }
 
diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c
index c5363c24190..3f71ec99b11 100644
--- a/drivers/spi/rk_spi.c
+++ b/drivers/spi/rk_spi.c
@@ -186,7 +186,6 @@ static int conv_of_platdata(struct udevice *dev)
ret = clk_get_by_driver_info(dev, dtplat->clocks, >clk);
if (ret < 0)
return ret;
-   dev->req_seq = 0;
 
return 0;
 }
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 12/27] net: Update to use new sequence numbers

2020-11-29 Thread Simon Glass
Checking for seq == -1 is effectively checking that the device is
activated. The new sequence numbers are never -1 for a bound device, so
update the check.

Also drop the note about valid sequence numbers so it is accurate with the
new approach.

Signed-off-by: Simon Glass 
---

 drivers/net/dwc_eth_qos.c | 2 +-
 net/eth-uclass.c  | 7 ++-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index db1102562f6..74893f5e8b1 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -1155,7 +1155,7 @@ static int eqos_read_rom_hwaddr(struct udevice *dev)
struct eth_pdata *pdata = dev_get_platdata(dev);
 
 #ifdef CONFIG_ARCH_IMX8M
-   imx_get_mac_from_fuse(dev->req_seq, pdata->enetaddr);
+   imx_get_mac_from_fuse(dev_seq(dev), pdata->enetaddr);
 #endif
return !is_valid_ethaddr(pdata->enetaddr);
 }
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index e6a3cd1ee6a..5c1ee57fb59 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -126,9 +126,6 @@ struct udevice *eth_get_dev_by_name(const char *devname)
 
uclass_foreach_dev(it, uc) {
/*
-* We need the seq to be valid, so try to probe it.
-* If the probe fails, the seq will not match since it will be
-* -1 instead of what we are looking for.
 * We don't care about errors from probe here. Either they won't
 * match an alias or it will match a literal name and we'll pick
 * up the error when we try to probe again in eth_set_dev().
@@ -434,7 +431,7 @@ int eth_initialize(void)
 
bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
do {
-   if (dev_seq(dev) != -1) {
+   if (device_active(dev)) {
if (num_devices)
printf(", ");
 
@@ -446,7 +443,7 @@ int eth_initialize(void)
 
eth_write_hwaddr(dev);
 
-   if (dev_seq(dev) != -1)
+   if (device_active(dev))
num_devices++;
uclass_next_device_check();
} while (dev);
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 13/27] pci: Update to use new sequence numbers

2020-11-29 Thread Simon Glass
Now that we know the sequence number at bind time, there is no need for
special-case code in dm_pci_hose_probe_bus().

Note: the PCI_CAP_ID_EA code may need a look, but there are no test
failures so I have left it as is.

Signed-off-by: Simon Glass 
---

 drivers/pci/pci-uclass.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 99dcd342efe..abc3de84db3 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -632,7 +632,7 @@ int dm_pci_hose_probe_bus(struct udevice *bus)
);
sub_bus = reg;
} else {
-   sub_bus = pci_get_bus_max() + 1;
+   sub_bus = dev_seq(bus);
}
debug("%s: bus = %d/%s\n", __func__, sub_bus, bus->name);
dm_pciauto_prescan_setup_bridge(bus, sub_bus);
@@ -644,14 +644,6 @@ int dm_pci_hose_probe_bus(struct udevice *bus)
return ret;
}
 
-   if (!ea_pos) {
-   if (sub_bus != dev_seq(bus)) {
-   debug("%s: Internal error, bus '%s' got seq %d, 
expected %d\n",
- __func__, bus->name, dev_seq(bus), sub_bus);
-   return -EPIPE;
-   }
-   sub_bus = pci_get_bus_max();
-   }
dm_pciauto_postscan_setup_bridge(bus, sub_bus);
 
return sub_bus;
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 11/27] i2c: Update for new sequence numbers

2020-11-29 Thread Simon Glass
Use the new sequence number in all cases. Drop the logic to check for a
valid number in designware_i2c, since it will always be valid.

Signed-off-by: Simon Glass 
---

 drivers/i2c/designware_i2c_pci.c   | 22 +-
 drivers/i2c/i2c-uclass.c   |  8 +---
 drivers/i2c/i2c-versatile.c|  5 -
 drivers/i2c/intel_i2c.c| 12 +---
 drivers/i2c/muxes/i2c-mux-uclass.c |  4 ++--
 drivers/i2c/mvtwsi.c   |  4 ++--
 6 files changed, 7 insertions(+), 48 deletions(-)

diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c
index 04921a304ac..9237726b475 100644
--- a/drivers/i2c/designware_i2c_pci.c
+++ b/drivers/i2c/designware_i2c_pci.c
@@ -90,32 +90,12 @@ static int designware_i2c_pci_probe(struct udevice *dev)
 
 static int designware_i2c_pci_bind(struct udevice *dev)
 {
-   struct uclass *uc;
char name[20];
-   int ret;
 
if (dev_of_valid(dev))
return 0;
 
-   /*
-* Create a unique device name for PCI type devices
-* ToDo:
-* Setting req_seq in the driver is probably not recommended.
-* But without a DT alias the number is not configured. And
-* using this driver is impossible for PCIe I2C devices.
-* This can be removed, once a better (correct) way for this
-* is found and implemented.
-*
-* TODO(s...@chromium.org): Perhaps if uclasses had platdata this would
-* be possible. We cannot use static data in drivers since they may be
-* used in SPL or before relocation.
-*/
-   ret = uclass_get(UCLASS_I2C, );
-   if (ret)
-   return ret;
-
-   dev->req_seq = uclass_find_next_free_req_seq(uc);
-   sprintf(name, "i2c_designware#%u", dev->req_seq);
+   sprintf(name, "i2c_designware#%u", dev_seq(dev));
device_set_name(dev, name);
 
return 0;
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 5c4626b0442..2625bd72dc8 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -700,13 +700,7 @@ static int i2c_post_bind(struct udevice *dev)
if (!priv)
return -ENOMEM;
 
-   debug("%s: %s, req_seq=%d\n", __func__, dev->name, dev->req_seq);
-
-   /* if there is no alias ID, use the first free */
-   if (dev->req_seq == -1)
-   dev->req_seq = ++priv->max_id;
-
-   debug("%s: %s, new req_seq=%d\n", __func__, dev->name, dev->req_seq);
+   debug("%s: %s, seq=%d\n", __func__, dev->name, dev_seq(dev));
 
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
ret = dm_scan_fdt_dev(dev);
diff --git a/drivers/i2c/i2c-versatile.c b/drivers/i2c/i2c-versatile.c
index 62831522bd3..69042d54205 100644
--- a/drivers/i2c/i2c-versatile.c
+++ b/drivers/i2c/i2c-versatile.c
@@ -252,11 +252,6 @@ static int versatile_i2c_probe(struct udevice *dev)
 
priv->base = (phys_addr_t)dev_read_addr(dev);
priv->delay = 25;   /* 25us * 4 = 100kHz */
-   /*
-* U-Boot still doesn't assign automatically
-* sequence numbers to devices
-*/
-   dev->req_seq = 1;
 
return 0;
 }
diff --git a/drivers/i2c/intel_i2c.c b/drivers/i2c/intel_i2c.c
index 3b79cb40cd3..66d017a2615 100644
--- a/drivers/i2c/intel_i2c.c
+++ b/drivers/i2c/intel_i2c.c
@@ -269,21 +269,11 @@ static int intel_i2c_probe(struct udevice *dev)
 
 static int intel_i2c_bind(struct udevice *dev)
 {
-   static int num_cards __attribute__ ((section(".data")));
char name[20];
 
/* Create a unique device name for PCI type devices */
if (device_is_on_pci_bus(dev)) {
-   /*
-* ToDo:
-* Setting req_seq in the driver is probably not recommended.
-* But without a DT alias the number is not configured. And
-* using this driver is impossible for PCIe I2C devices.
-* This can be removed, once a better (correct) way for this
-* is found and implemented.
-*/
-   dev->req_seq = num_cards;
-   sprintf(name, "intel_i2c#%u", num_cards++);
+   sprintf(name, "intel_i2c#%u", dev_seq(dev));
device_set_name(dev, name);
}
 
diff --git a/drivers/i2c/muxes/i2c-mux-uclass.c 
b/drivers/i2c/muxes/i2c-mux-uclass.c
index 26897554b0f..9a8cf8fb172 100644
--- a/drivers/i2c/muxes/i2c-mux-uclass.c
+++ b/drivers/i2c/muxes/i2c-mux-uclass.c
@@ -87,8 +87,8 @@ static int i2c_mux_post_bind(struct udevice *mux)
 
ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv",
 full_name, node, );
-   debug("   - bind ret=%d, %s, req_seq %d\n", ret,
- dev ? dev->name : NULL, dev->req_seq);
+   debug("   - bind ret=%d, %s, seq %d\n", ret,
+ dev ? dev->name : NULL, dev_seq(dev));

[PATCH 09/27] dm: test: Drop assumptions of no sequence numbers

2020-11-29 Thread Simon Glass
Drop code in a few tests which assumes that sequence numbers are only
valid when a device is probed.

Signed-off-by: Simon Glass 
---

 test/dm/blk.c | 3 ---
 test/dm/i2c.c | 3 ---
 test/dm/spi.c | 3 ---
 3 files changed, 9 deletions(-)

diff --git a/test/dm/blk.c b/test/dm/blk.c
index f34c13f7511..ea5e0955d98 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -19,9 +19,6 @@ static int dm_test_blk_base(struct unit_test_state *uts)
 {
struct udevice *blk1, *blk3, *dev;
 
-   /* Make sure there are no block devices */
-   ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_BLK, 0, ));
-
/* Create two, one the parent of the other */
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
  IF_TYPE_HOST, 1, 512, 2, ));
diff --git a/test/dm/i2c.c b/test/dm/i2c.c
index 681ce45107c..d74f5f9fbc7 100644
--- a/test/dm/i2c.c
+++ b/test/dm/i2c.c
@@ -28,9 +28,6 @@ static int dm_test_i2c_find(struct unit_test_state *uts)
struct udevice *bus, *dev;
const int no_chip = 0x10;
 
-   ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_I2C, busnum,
-  false, ));
-
/*
 * The post_bind() method will bind devices to chip selects. Check
 * this then remove the emulation and the slave device.
diff --git a/test/dm/spi.c b/test/dm/spi.c
index fb180aed1f0..b767cf9c4a0 100644
--- a/test/dm/spi.c
+++ b/test/dm/spi.c
@@ -26,9 +26,6 @@ static int dm_test_spi_find(struct unit_test_state *uts)
struct spi_cs_info info;
ofnode node;
 
-   ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_SPI, busnum,
-  false, ));
-
/*
 * The post_bind() method will bind devices to chip selects. Check
 * this then remove the emulation and the slave device.
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 08/27] dm: Fix return value in dev_read_alias_seq()

2020-11-29 Thread Simon Glass
This should return 0 on success but currently does not. Fix it.

Signed-off-by: Simon Glass 
---

 drivers/core/read.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/core/read.c b/drivers/core/read.c
index 076125824ca..fc74d64814f 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -281,8 +281,10 @@ int dev_read_alias_seq(const struct udevice *dev, int 
*devnump)
 
if (ofnode_is_np(node)) {
ret = of_alias_get_id(ofnode_to_np(node), uc_name);
-   if (ret >= 0)
+   if (ret >= 0) {
*devnump = ret;
+   ret = 0;
+   }
} else {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 07/27] dm: core: Switch binding to use new sequence numbers

2020-11-29 Thread Simon Glass
Update the core logic to use the new approach. For now the old code is
left as is. Update one test so it still passes.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c | 5 +
 test/dm/bus.c | 3 ++-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 2f449b3e8fa..bd58a9e946d 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -667,12 +667,9 @@ int device_find_child_by_seq(const struct udevice *parent, 
int seq_or_req_seq,
struct udevice *dev;
 
*devp = NULL;
-   if (seq_or_req_seq == -1)
-   return -ENODEV;
 
list_for_each_entry(dev, >child_head, sibling_node) {
-   if ((find_req_seq ? dev->req_seq : dev_seq(dev)) ==
-   seq_or_req_seq) {
+   if (dev->sqq == seq_or_req_seq) {
*devp = dev;
return 0;
}
diff --git a/test/dm/bus.c b/test/dm/bus.c
index 27b72666457..e1fa67d91e1 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -160,9 +160,10 @@ static int dm_test_bus_children_funcs(struct 
unit_test_state *uts)
ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, true, ));
ut_assertok(device_find_child_by_seq(bus, 0, true, ));
ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
-   ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 0, false, ));
+   ut_asserteq(0, device_find_child_by_seq(bus, 0, false, ));
ut_assertok(device_get_child_by_seq(bus, 0, ));
ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+   ut_asserteq(0, device_find_child_by_seq(bus, 0, false, ));
 
/* There is no device with sequence number 2 */
ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, false, ));
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 06/27] dm: test: Add support for new sequence numbers

2020-11-29 Thread Simon Glass
Tests need to rebuild the driver model data structures to avoid being
affected by the operation of an earlier test. Do the same for the new
bind-time sequence numbers.

Also add a test that the new sequence numbers work as expected. Every
device should get one.

Signed-off-by: Simon Glass 
---

 test/dm/core.c  | 19 +++
 test/dm/test-main.c |  6 ++
 2 files changed, 25 insertions(+)

diff --git a/test/dm/core.c b/test/dm/core.c
index 71ebb36d88b..0514813b817 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -1066,3 +1066,22 @@ static int dm_test_inactive_child(struct unit_test_state 
*uts)
return 0;
 }
 DM_TEST(dm_test_inactive_child, UT_TESTF_SCAN_PDATA);
+
+/* Make sure all bound devices have a sequence number */
+static int dm_test_all_have_seq(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+   struct uclass *uc;
+
+   list_for_each_entry(uc, >uclass_root, sibling_node) {
+   list_for_each_entry(dev, >dev_head, uclass_node) {
+   if (dev->sqq == -1)
+   printf("Device '%s' has no seq (%d)\n",
+  dev->name, dev->sqq);
+   ut_assert(dev->sqq != -1);
+   }
+   }
+
+   return 0;
+}
+DM_TEST(dm_test_all_have_seq, UT_TESTF_SCAN_PDATA);
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 4814e186cb7..4ff7a01d5aa 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -88,6 +88,7 @@ static int dm_do_test(struct unit_test_state *uts, struct 
unit_test *test,
ut_assertok(dm_test_init(uts, of_live));
 
uts->start = mallinfo();
+   gd->flags |= GD_FLG_DM_NO_SEQ;
if (test->flags & UT_TESTF_SCAN_PDATA)
ut_assertok(dm_scan_platdata(false));
if (test->flags & UT_TESTF_PROBE_TEST)
@@ -95,6 +96,8 @@ static int dm_do_test(struct unit_test_state *uts, struct 
unit_test *test,
if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
(test->flags & UT_TESTF_SCAN_FDT))
ut_assertok(dm_extended_scan(false));
+   uclass_alloc_all_seqs();
+   gd->flags &= ~GD_FLG_DM_NO_SEQ;
 
/*
 * Silence the console and rely on console recording to get
@@ -208,12 +211,15 @@ int dm_test_main(const char *test_name)
printf("Failures: %d\n", uts->fail_count);
 
/* Put everything back to normal so that sandbox works as expected */
+   gd->flags |= GD_FLG_DM_NO_SEQ;
gd_set_of_root(uts->of_root);
gd->dm_root = NULL;
ut_assertok(dm_init(CONFIG_IS_ENABLED(OF_LIVE)));
dm_scan_platdata(false);
if (!CONFIG_IS_ENABLED(OF_PLATDATA))
dm_scan_fdt(false);
+   uclass_alloc_all_seqs();
+   gd->flags &= ~GD_FLG_DM_NO_SEQ;
 
return uts->fail_count ? CMD_RET_FAILURE : 0;
 }
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 04/27] dm: core: Update uclass_find_next_free_req_seq() args

2020-11-29 Thread Simon Glass
At present this is passed a uclass ID and it has to do a lookup. The
callers all have the uclass pointer, except for the I2C uclass where the
code will soon be deleted.

Update the argument to a uclass * instead of an ID since it is more
efficient.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c| 4 ++--
 drivers/core/uclass.c| 8 +---
 drivers/i2c/designware_i2c_pci.c | 8 +++-
 include/dm/uclass-internal.h | 4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 5660310c754..5febdb67503 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -89,10 +89,10 @@ static int device_bind_common(struct udevice *parent, const 
struct driver *drv,
 #if CONFIG_IS_ENABLED(OF_PRIOR_STAGE)
if (dev->req_seq == -1)
dev->req_seq =
-   uclass_find_next_free_req_seq(drv->id);
+   uclass_find_next_free_req_seq(uc);
 #endif
} else {
-   dev->req_seq = uclass_find_next_free_req_seq(drv->id);
+   dev->req_seq = uclass_find_next_free_req_seq(uc);
}
}
 
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 699f24843cf..cdf0674cd82 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -272,17 +272,11 @@ int uclass_find_device_by_name(enum uclass_id id, const 
char *name,
return -ENODEV;
 }
 
-int uclass_find_next_free_req_seq(enum uclass_id id)
+int uclass_find_next_free_req_seq(struct uclass *uc)
 {
-   struct uclass *uc;
struct udevice *dev;
-   int ret;
int max = -1;
 
-   ret = uclass_get(id, );
-   if (ret)
-   return ret;
-
list_for_each_entry(dev, >dev_head, uclass_node) {
if ((dev->req_seq != -1) && (dev->req_seq > max))
max = dev->req_seq;
diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c
index d0d869c81a1..04921a304ac 100644
--- a/drivers/i2c/designware_i2c_pci.c
+++ b/drivers/i2c/designware_i2c_pci.c
@@ -90,7 +90,9 @@ static int designware_i2c_pci_probe(struct udevice *dev)
 
 static int designware_i2c_pci_bind(struct udevice *dev)
 {
+   struct uclass *uc;
char name[20];
+   int ret;
 
if (dev_of_valid(dev))
return 0;
@@ -108,7 +110,11 @@ static int designware_i2c_pci_bind(struct udevice *dev)
 * be possible. We cannot use static data in drivers since they may be
 * used in SPL or before relocation.
 */
-   dev->req_seq = uclass_find_next_free_req_seq(UCLASS_I2C);
+   ret = uclass_get(UCLASS_I2C, );
+   if (ret)
+   return ret;
+
+   dev->req_seq = uclass_find_next_free_req_seq(uc);
sprintf(name, "i2c_designware#%u", dev->req_seq);
device_set_name(dev, name);
 
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index 6e3f15c2b08..2c21871e0fd 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -19,10 +19,10 @@
  * maximum req_seq of the uclass + 1.
  * This allows assiging req_seq number in the binding order.
  *
- * @id:Id number of the uclass
+ * @uc:uclass to check
  * @return The next free req_seq number
  */
-int uclass_find_next_free_req_seq(enum uclass_id id);
+int uclass_find_next_free_req_seq(struct uclass *uc);
 
 /**
  * uclass_get_device_tail() - handle the end of a get_device call
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 10/27] octeon: Don't attempt to set the sequence number

2020-11-29 Thread Simon Glass
Several Octeon drivers operate by setting the sequence number of their
device. This should not be needed with the new sequence number setup. Also
it is not permitted. Drop it.

Signed-off-by: Simon Glass 
---

 drivers/i2c/octeon_i2c.c | 1 -
 drivers/mmc/octeontx_hsmmc.c | 2 --
 drivers/net/octeontx/smi.c   | 1 -
 3 files changed, 4 deletions(-)

diff --git a/drivers/i2c/octeon_i2c.c b/drivers/i2c/octeon_i2c.c
index 38839e45758..85ad357eca9 100644
--- a/drivers/i2c/octeon_i2c.c
+++ b/drivers/i2c/octeon_i2c.c
@@ -791,7 +791,6 @@ static int octeon_i2c_probe(struct udevice *dev)
pci_dev_t bdf = dm_pci_get_bdf(dev);
 
debug("TWSI PCI device: %x\n", bdf);
-   dev->req_seq = PCI_FUNC(bdf);
 
twsi->base = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0,
PCI_REGION_MEM);
diff --git a/drivers/mmc/octeontx_hsmmc.c b/drivers/mmc/octeontx_hsmmc.c
index 38ca3736841..a91aaf31461 100644
--- a/drivers/mmc/octeontx_hsmmc.c
+++ b/drivers/mmc/octeontx_hsmmc.c
@@ -3731,7 +3731,6 @@ U_BOOT_DRIVER(octeontx_hsmmc_slot) = {
  */
 static int octeontx_mmc_host_probe(struct udevice *dev)
 {
-   pci_dev_t bdf = dm_pci_get_bdf(dev);
struct octeontx_mmc_host *host = dev_get_priv(dev);
union mio_emm_int emm_int;
u8 rev;
@@ -3757,7 +3756,6 @@ static int octeontx_mmc_host_probe(struct udevice *dev)
return -1;
}
host->node = dev->node;
-   dev->req_seq = PCI_FUNC(bdf);
host->last_slotid = -1;
if (otx_is_platform(PLATFORM_ASIM))
host->is_asim = true;
diff --git a/drivers/net/octeontx/smi.c b/drivers/net/octeontx/smi.c
index d4baddb7ef5..d1582b968bf 100644
--- a/drivers/net/octeontx/smi.c
+++ b/drivers/net/octeontx/smi.c
@@ -319,7 +319,6 @@ int octeontx_smi_probe(struct udevice *dev)
pci_dev_t bdf = dm_pci_get_bdf(dev);
 
debug("SMI PCI device: %x\n", bdf);
-   dev->req_seq = PCI_FUNC(bdf);
if (!dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, PCI_REGION_MEM)) {
printf("Failed to map PCI region for bdf %x\n", bdf);
return -1;
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 05/27] dm: core: Add a new sequence number for devices

2020-11-29 Thread Simon Glass
At present each device has two sequence numbers, with 'req_seq' being
set up at bind time and 'seq' at probe time. The idea is that devices
can 'request' a sequence number and then the conflicts are resolved when
the device is probed.

This makes things complicated in a few cases, since we don't really know
what the sequence number will end up being. We want to honour the
bind-time requests if at all possible, but in fact the only source of
these at present is the devicetree aliases. Since we have the devicetree
available at bind time, we may as well just use it, in the hope that the
required processing will turn out to be useful later (i.e. the device
actually gets used).

Add a new 'sqq' member, the bind-time sequence number. It operates in
parallel to the old values for now. All devices get a valid sqq value,
i.e. it is never -1.

Drop an #ifdef while we are here.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c | 22 -
 drivers/core/root.c   | 21 +---
 drivers/core/uclass.c | 40 +++
 include/asm-generic/global_data.h |  2 ++
 include/dm/device.h   |  8 +++
 include/dm/uclass.h   |  8 +++
 6 files changed, 92 insertions(+), 9 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 5febdb67503..2f449b3e8fa 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -41,6 +41,7 @@ static int device_bind_common(struct udevice *parent, const 
struct driver *drv,
struct udevice *dev;
struct uclass *uc;
int size, ret = 0;
+   bool auto_seq = false;
 
if (devp)
*devp = NULL;
@@ -73,6 +74,7 @@ static int device_bind_common(struct udevice *parent, const 
struct driver *drv,
 
dev->seq = -1;
dev->req_seq = -1;
+   dev->sqq = -1;
if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
(uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
/*
@@ -84,16 +86,24 @@ static int device_bind_common(struct udevice *parent, const 
struct driver *drv,
 */
if (CONFIG_IS_ENABLED(OF_CONTROL) &&
!CONFIG_IS_ENABLED(OF_PLATDATA)) {
-   if (uc->uc_drv->name && ofnode_valid(node))
+   if (uc->uc_drv->name && ofnode_valid(node)) {
+   dev_read_alias_seq(dev, >sqq);
dev_read_alias_seq(dev, >req_seq);
-#if CONFIG_IS_ENABLED(OF_PRIOR_STAGE)
-   if (dev->req_seq == -1)
-   dev->req_seq =
-   uclass_find_next_free_req_seq(uc);
-#endif
+   }
+   if (CONFIG_IS_ENABLED(OF_PRIOR_STAGE)) {
+   if (dev->req_seq == -1) {
+   auto_seq = true;
+   dev->req_seq =
+   uclass_find_next_free_req_seq(
+   uc);
+   }
+   }
} else {
+   auto_seq = true;
dev->req_seq = uclass_find_next_free_req_seq(uc);
}
+   if (auto_seq && !(gd->flags & GD_FLG_DM_NO_SEQ))
+   dev->sqq = uclass_find_next_free_req_seq(uc);
}
 
if (drv->platdata_auto_alloc_size) {
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 6f8168bb92d..66aabc4b19b 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -308,25 +308,40 @@ int dm_init_and_scan(bool pre_reloc_only)
debug("dm_init() failed: %d\n", ret);
return ret;
}
+   gd->flags |= GD_FLG_DM_NO_SEQ;
ret = dm_scan_platdata(pre_reloc_only);
if (ret) {
debug("dm_scan_platdata() failed: %d\n", ret);
-   return ret;
+   goto fail;
}
 
if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
ret = dm_extended_scan(pre_reloc_only);
if (ret) {
debug("dm_extended_scan() failed: %d\n", ret);
-   return ret;
+   goto fail;
}
}
 
ret = dm_scan_other(pre_reloc_only);
if (ret)
-   return ret;
+   goto fail;
+
+   /*
+* Now that all the alisas have been used to claim sequence numbers, we
+* can allocate every non-aliased device a sequence number
+*/
+   uclass_alloc_all_seqs();
+
+   /*
+* From now on, assign sequence numbers when binding, to ensure that
+* every new device has a sequence number too
+*/
+   gd->flags &= ~GD_FLG_DM_NO_SEQ;
 
return 0;
+fail:
+   return ret;
 }
 
 #ifdef CONFIG_ACPIGEN

[PATCH 01/27] linker_lists: Fix alignment issue

2020-11-29 Thread Simon Glass
The linker script uses alphabetic sorting to group the different linker
lists together. Each group has its own struct and potentially its own
alignment. But when the linker packs the structs together it cannot
ensure that a linker list starts on the expected alignment boundary.

For example, if the first list has a struct size of 8 and we place 3 of
them in the image, that means that the next struct will start at offset
0x18 from the start of the linker_list section. If the next struct has
a size of 16 then it will start at an 8-byte aligned offset, but not a
16-byte aligned offset.

With sandbox on x86_64, a reference to a linker list item using
ll_entry_get() can force alignment of that particular linker_list item,
if it is in the same file as the linker_list item is declared.

Consider this example, where struct driver is 0x80 bytes:

ll_entry_declare(struct driver, fred, driver)

...

void *p = ll_entry_get(struct driver, fred, driver)

If these two lines of code are in the same file, then the entry is forced
to be aligned at the 'struct driver' alignment, which is 16 bytes. If the
second line of code is in a different file, then no action is taken, since
the compiler cannot update the alignment of the linker_list item.

In the first case, an 8-byte 'fill' region is added:

 .u_boot_list_2_driver_2_testbus_drv
0x00270018   0x80 test/built-in.o
0x00270018
_u_boot_list_2_driver_2_testbus_drv
 .u_boot_list_2_driver_2_testfdt1_drv
0x00270098   0x80 test/built-in.o
0x00270098
_u_boot_list_2_driver_2_testfdt1_drv
 *fill* 0x002701180x8
 .u_boot_list_2_driver_2_testfdt_drv
0x00270120   0x80 test/built-in.o
0x00270120
_u_boot_list_2_driver_2_testfdt_drv
 .u_boot_list_2_driver_2_testprobe_drv
0x002701a0   0x80 test/built-in.o
0x002701a0
_u_boot_list_2_driver_2_testprobe_drv

With this, the linker_list no-longer works since items after testfdt1_drv
are not at the expected address.

Ideally we would have a way to tell gcc not to align structs in this way.
It is not clear how we could do this, and in any case it would require us
to adjust every struct used by the linker_list feature.

One possible fix is to force each separate linker_list to start on the
largest possible boundary that can be required by the compiler. However
that does not seem to work on x86_64, which uses 16-byte alignment in this
case but needs 32-byte alignment.

So add a Kconfig option to handle this. Set the default value to 4 so
as to avoid changing platforms that don't need it.

Update the ll_entry_start() accordingly.

Signed-off-by: Simon Glass 
---

 arch/Kconfig | 11 +++
 doc/api/linker_lists.rst | 62 
 include/linker_lists.h   |  3 +-
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 3aa99e08fce..aa8664212f1 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -7,6 +7,17 @@ config HAVE_ARCH_IOREMAP
 config NEEDS_MANUAL_RELOC
bool
 
+config LINKER_LIST_ALIGN
+   int
+   default 32 if SANDBOX
+   default 8 if ARM64 || X86
+   default 4
+   help
+ Force the each linker list to be aligned to this boundary. This
+ is required if ll_entry_get() is used, since otherwise the linker
+ may add padding into the table, thus breaking it.
+ See linker_lists.rst for full details.
+
 choice
prompt "Architecture select"
default SANDBOX
diff --git a/doc/api/linker_lists.rst b/doc/api/linker_lists.rst
index 72f514e0ac0..7a37db52ba8 100644
--- a/doc/api/linker_lists.rst
+++ b/doc/api/linker_lists.rst
@@ -96,5 +96,67 @@ defined for the whole list and each sub-list:
   %u_boot_list_2_drivers_2_pci_3
   %u_boot_list_2_drivers_3
 
+Alignment issues
+
+
+The linker script uses alphabetic sorting to group the different linker
+lists together. Each group has its own struct and potentially its own
+alignment. But when the linker packs the structs together it cannot ensure
+that a linker list starts on the expected alignment boundary.
+
+For example, if the first list has a struct size of 8 and we place 3 of
+them in the image, that means that the next struct will start at offset
+0x18 from the start of the linker_list section. If the next struct has
+a size of 16 then it will start at an 8-byte aligned offset, but not a
+16-byte aligned offset.
+
+With sandbox on x86_64, a reference to a linker list item using
+ll_entry_get() can force alignment of that particular linker_list item,
+if it is in the same file as the linker_list item is declared.
+
+Consider this example, where struct driver is 0x80 bytes:
+
+::
+
+

[PATCH 02/27] efi: Drop unwanted message in efi_uc_destroy()

2020-11-29 Thread Simon Glass
This is not very useful and is printed by some tests, causing confusion.
Drop it.

Signed-off-by: Simon Glass 
---

 lib/efi_driver/efi_uclass.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
index 0cf74b0361d..5b8315472e3 100644
--- a/lib/efi_driver/efi_uclass.c
+++ b/lib/efi_driver/efi_uclass.c
@@ -340,7 +340,6 @@ static int efi_uc_init(struct uclass *class)
  */
 static int efi_uc_destroy(struct uclass *class)
 {
-   printf("Destroying  UCLASS_EFI\n");
return 0;
 }
 
-- 
2.29.2.454.gaff20da3a2-goog



RE: [PATCH v2 1/6] usb: dwc3: Add frame length adjustment quirk

2020-11-29 Thread Ran Wang
Hi Bin, Marek,

  Any comment for this serial? Thanks in advance.

Regards,
Ran

On Wednesday, October 21, 2020 6:02 PM, Ran Wang wrote:
> 
> Register Global frame length adjustment is used to do frame length adjustment
> for SOF/ITP counter which is running on the ref_clk. Allow updating it could 
> help
> on avoiding potential USB 2.0 devices time-out over a longer run.
> 
> Refer to Linux commit db2be4e9e30c (“usb: dwc3: Add frame length
> adjustment quirk”)
> 
> Signed-off-by: Ran Wang 
> ---
> Change in v2:
>  - None
> 
>  drivers/usb/dwc3/core.c | 34 ++
>  drivers/usb/dwc3/core.h |  7 +++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index
> 2e00353..b3d4751 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -310,6 +310,25 @@ static void dwc3_free_scratch_buffers(struct dwc3
> *dwc)
>   kfree(dwc->scratchbuf);
>  }
> 
> +/*
> + * dwc3_frame_length_adjustment - Adjusts frame length if required
> + * @dwc3: Pointer to our controller context structure
> + * @val: Value of frame length
> + */
> +static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 val) {
> + u32 reg;
> + u32 dft;
> +
> + reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
> + dft = reg & DWC3_GFLADJ_30MHZ_MASK;
> + if (dft != val) {
> + reg &= ~DWC3_GFLADJ_30MHZ_MASK;
> + reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | val;
> + dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
> + }
> +}
> +
>  static void dwc3_core_num_eps(struct dwc3 *dwc)  {
>   struct dwc3_hwparams*parms = >hwparams;
> @@ -569,6 +588,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
>   if (ret)
>   goto err1;
> 
> + if (dwc->fladj_quirk && dwc->revision >= DWC3_REVISION_250A)
> + dwc3_frame_length_adjustment(dwc, dwc->fladj);
> +
>   return 0;
> 
>  err1:
> @@ -958,6 +980,18 @@ void dwc3_of_parse(struct dwc3 *dwc)
> 
>   dwc->hird_threshold = hird_threshold
>   | (dwc->is_utmi_l1_suspend << 4);
> +
> + dwc->fladj_quirk = false;
> + if (!dev_read_u32(dev,
> +   "snps,quirk-frame-length-adjustment",
> +   >fladj)) {
> + if (dwc->fladj <=  DWC3_GFLADJ_30MHZ_MASK)
> + dwc->fladj_quirk = true;
> + else
> + dev_err(dev,
> + "snps,quirk-frame-length-adjustment invalid: 
> 0x%x\n",
> + dwc->fladj);
> + }
>  }
> 
>  int dwc3_init(struct dwc3 *dwc)
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index
> 44533fd..4650216 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -115,6 +115,7 @@
>  #define DWC3_GEVNTCOUNT(n)   (0xc40c + (n * 0x10))
> 
>  #define DWC3_GHWPARAMS8  0xc600
> +#define DWC3_GFLADJ  0xc630
> 
>  /* Device Registers */
>  #define DWC3_DCFG0xc700
> @@ -291,6 +292,10 @@
>  #define DWC3_DCTL_ULSTCHNG_COMPLIANCE
>   (DWC3_DCTL_ULSTCHNGREQ(10))
>  #define DWC3_DCTL_ULSTCHNG_LOOPBACK
>   (DWC3_DCTL_ULSTCHNGREQ(11))
> 
> +/* Global Frame Length Adjustment Register */
> +#define DWC3_GFLADJ_30MHZ_SDBND_SEL  BIT(7)
> +#define DWC3_GFLADJ_30MHZ_MASK   0x3f
> +
>  /* Device Event Enable Register */
>  #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN(1 << 12)
>  #define DWC3_DEVTEN_EVNTOVERFLOWEN   (1 << 11)
> @@ -764,6 +769,7 @@ struct dwc3 {
>   u32 num_event_buffers;
>   u32 u1u2;
>   u32 maximum_speed;
> + u32 fladj;
>   u32 revision;
> 
>  #define DWC3_REVISION_173A   0x5533173a
> @@ -845,6 +851,7 @@ struct dwc3 {
> 
>   unsignedtx_de_emphasis_quirk:1;
>   unsignedtx_de_emphasis:2;
> + unsignedfladj_quirk:1;
>   int index;
>   struct list_headlist;
>  };
> --
> 2.7.4



RE: [PATCH v4] usb: xhci: fix lack of short packet event trb handling

2020-11-29 Thread Ran Wang
Hi Marek, Bin,


On Wednesday, November 18, 2020 3:49 PM, Ran Wang wrote:
> 
> For bulk IN transfer, the codes will set ISP flag to request event TRB being
> generated by xHC for the case of short packet. So when encountering
> buffer-cross-64K-boundary (which we will divide payload and enqueuqe more
> than 1 transfer TRB), and the first TRB ends up with a short packet condition 
> it
> will trigger an short packet code transfer event per that flag and cause more
> than 1 event TRB generated for this transfer.
> 
> However, current codes will only handle the first transfer event TRB then mark
> current transfer completed, causing next transfer failure due to event TRB
> mis-match.
> 
> Such issue has been observed on some Layerscape platforms (LS1028A,
> LS1088A, etc) with USB ethernet device.
> 
> This patch adds a loop to make sure the event TRB for last transfer TRB has
> been handled in time.
> 
> Signed-off-by: Ran Wang 
> Reviewed-by: Bin Meng 
> ---
> Change in v4:
>  - Update commit message: 'for case of short packet' => 'for the case of short
> packet'

   Has this v4 patch been accepted?

Thanks & Regards,
Ran

> Change in v3:
>  - Update commit message according to v2 feedback .
>  - Replace (void *) with (uintptr_t) to fix below armv7 compile warning:
>  drivers/usb/host/xhci-ring.c: In function 'xhci_bulk_tx':
>  drivers/usb/host/xhci-ring.c:726:6: warning: cast to pointer from integer of
> different size [-Wint-to-pointer-cast]
>726 |  if ((void *)le64_to_cpu(event->trans_event.buffer) !=
> last_transfer_trb_addr) {
>|   ^
> 
> Change in v2:
>  - Re-write commit message to describe context more clearly.
>  - Add prefix 'le64_to_cpu' for 'event->trans_event.buffer'.
> 
>  drivers/usb/host/xhci-ring.c | 18 +++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index
> 13065d7..d708fc9 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -580,10 +580,13 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned
> long pipe,
>   int ret;
>   u32 trb_fields[4];
>   u64 val_64 = virt_to_phys(buffer);
> + void *last_transfer_trb_addr;
> + int available_length;
> 
>   debug("dev=%p, pipe=%lx, buffer=%p, length=%d\n",
>   udev, pipe, buffer, length);
> 
> + available_length = length;
>   ep_index = usb_pipe_ep_index(pipe);
>   virt_dev = ctrl->devs[slot_id];
> 
> @@ -697,7 +700,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned
> long pipe,
>   trb_fields[2] = length_field;
>   trb_fields[3] = field | TRB_TYPE(TRB_NORMAL);
> 
> - queue_trb(ctrl, ring, (num_trbs > 1), trb_fields);
> + last_transfer_trb_addr = queue_trb(ctrl, ring, (num_trbs > 1),
> +trb_fields);
> 
>   --num_trbs;
> 
> @@ -710,6 +713,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned
> long pipe,
> 
>   giveback_first_trb(udev, ep_index, start_cycle, start_trb);
> 
> +again:
>   event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
>   if (!event) {
>   debug("XHCI bulk transfer timed out, aborting...\n"); @@ -718,12
> +722,20 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
>   udev->act_len = 0;
>   return -ETIMEDOUT;
>   }
> - field = le32_to_cpu(event->trans_event.flags);
> 
> + if ((uintptr_t)(le64_to_cpu(event->trans_event.buffer))
> + != (uintptr_t)last_transfer_trb_addr) {
> + available_length -=
> +
>   (int)EVENT_TRB_LEN(le32_to_cpu(event->trans_event.transfer_len));
> + xhci_acknowledge_event(ctrl);
> + goto again;
> + }
> +
> + field = le32_to_cpu(event->trans_event.flags);
>   BUG_ON(TRB_TO_SLOT_ID(field) != slot_id);
>   BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
> 
> - record_transfer_result(udev, event, length);
> + record_transfer_result(udev, event, available_length);
>   xhci_acknowledge_event(ctrl);
>   xhci_inval_cache((uintptr_t)buffer, length);
> 
> --
> 2.7.4



[PATCH 2/2] global_data: Fix comment for dm_driver_rt

2020-11-29 Thread Simon Glass
This comment is in the wrong format, so reports an error with
'make htmldocs'. Fix it.

Fixes: a294ead8d25 ("dm: Use an allocated array for run-time device info")
Signed-off-by: Simon Glass 
---

 include/asm-generic/global_data.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 0179567a2bb..d272f96bc9b 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -196,7 +196,7 @@ struct global_data {
 */
struct list_head uclass_root;
 # if CONFIG_IS_ENABLED(OF_PLATDATA)
-/** Dynamic info about the driver */
+   /** @dm_driver_rt: Dynamic info about the driver */
struct driver_rt *dm_driver_rt;
 # endif
 #endif
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 1/2] log: Fix comment for LOGC_BOOT

2020-11-29 Thread Simon Glass
This comment is in the wrong format, so reports an error with
'make htmldocs'. Fix it.

Fixes: b73d61a5565 ("x86: zimage: Add a little more logging")
Signed-off-by: Simon Glass 
---

 include/log.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/log.h b/include/log.h
index 29f18a82dcf..e53afa490e8 100644
--- a/include/log.h
+++ b/include/log.h
@@ -96,8 +96,8 @@ enum log_category_t {
LOGC_DEVRES,
/** @LOGC_ACPI: Advanced Configuration and Power Interface (ACPI) */
LOGC_ACPI,
-   LOGC_BOOT,  /* Related to boot process / boot image processing */
-
+   /** @LOGC_BOOT: Related to boot process / boot image processing */
+   LOGC_BOOT,
/** @LOGC_COUNT: Number of log categories */
LOGC_COUNT,
/** @LOGC_END: Sentinel value for lists of log categories */
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH 3/3] TI QSPI: prevent a 4-byte write to the flash on read access

2020-11-29 Thread Jean Pihet
In MMIO mode, a write to the flash generates write commands to the device.
Prevent this from happening when reading from the device.

Signed-off-by: Jean Pihet 
---
 drivers/spi/ti_qspi.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/spi/ti_qspi.c b/drivers/spi/ti_qspi.c
index 57192b9c0a..40e1988df5 100644
--- a/drivers/spi/ti_qspi.c
+++ b/drivers/spi/ti_qspi.c
@@ -305,8 +305,6 @@ static void ti_qspi_copy_mmap(void *data, void *offset, 
size_t len)
 #else
memcpy_fromio(data, offset, len);
 #endif
-
-   *((unsigned int *)offset) += len;
 }
 
 static void ti_qspi_setup_mmap_read(struct ti_qspi_priv *priv, int cs,
-- 
2.26.2



[PATCH 2/3] TI QSPI: add support for dual and quad-bit I/O read

2020-11-29 Thread Jean Pihet
TI QSPI: the TI QSPI IP has a limitation of 64MB of MMIO so use
the MMIO mode to read below 64MB and fallback to the SW generated
sequences to read above 64MB.
The TI QSPI IP has another limitation of 4096 words per frame,
so split the accesses into smaller ones.
Also fix the TI QSPI operating frequency in order to correctly
generate the required SPI CLK frequency.

Signed-off-by: Jean Pihet 
---
 drivers/spi/Kconfig   |  9 ++
 drivers/spi/ti_qspi.c | 68 ---
 2 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index f7a9852565..5d24029ff0 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -395,10 +395,19 @@ config TEGRA210_QSPI
 config TI_QSPI
bool "TI QSPI driver"
imply TI_EDMA3
+   imply TI_QSPI_MQX_FRAME_SIZE
help
  Enable the TI Quad-SPI (QSPI) driver for DRA7xx and AM43xx evms.
  This driver support spi flash single, quad and memory reads.
 
+config TI_QSPI_MAX_FRAME_SIZE
+   int "TI QSPI max frame size"
+   default 4096
+   help
+ TI Quad-SPI (QSPI) IP block has a maximum number of 4096 words in a
+ frame, in non-memory mapped mode. A frame includes the command,
+ arguments and dummy bytes.
+
 config UNIPHIER_SPI
bool "Socionext UniPhier SPI driver"
depends on ARCH_UNIPHIER
diff --git a/drivers/spi/ti_qspi.c b/drivers/spi/ti_qspi.c
index 5fdbb49442..57192b9c0a 100644
--- a/drivers/spi/ti_qspi.c
+++ b/drivers/spi/ti_qspi.c
@@ -29,7 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 /* ti qpsi register bit masks */
 #define QSPI_TIMEOUT200
-#define QSPI_FCLK  19200
+#define QSPI_FCLK   4800
 #define QSPI_DRA7XX_FCLK7680
 #define QSPI_WLEN_MAX_BITS 128
 #define QSPI_WLEN_MAX_BYTES(QSPI_WLEN_MAX_BITS >> 3)
@@ -41,10 +41,11 @@ DECLARE_GLOBAL_DATA_PTR;
 #define QSPI_EN_CS(n)   (n << 28)
 #define QSPI_WLEN(n)((n-1) << 19)
 #define QSPI_3_PIN  BIT(18)
-#define QSPI_RD_SNGLBIT(16)
+#define QSPI_RD_SNGL(1 << 16)
+#define QSPI_RD_DUAL(3 << 16)
+#define QSPI_RD_QUAD(7 << 16)
 #define QSPI_WR_SNGL(2 << 16)
 #define QSPI_INVAL  (4 << 16)
-#define QSPI_RD_QUAD(7 << 16)
 /* device control */
 #define QSPI_CKPHA(n)   (1 << (2 + n*8))
 #define QSPI_CSPOL(n)   (1 << (1 + n*8))
@@ -155,6 +156,7 @@ static int ti_qspi_xfer(struct udevice *dev, unsigned int 
bitlen,
const void *dout, void *din, unsigned long flags)
 {
struct dm_spi_slave_platdata *slave = dev_get_parent_platdata(dev);
+   struct spi_slave *spi_slave = dev_get_parent_priv(dev);
struct ti_qspi_priv *priv;
struct udevice *bus;
uint words = bitlen >> 3; /* fixed 8-bit word length */
@@ -182,7 +184,6 @@ static int ti_qspi_xfer(struct udevice *dev, unsigned int 
bitlen,
 
/* Setup command reg */
priv->cmd = 0;
-   priv->cmd |= QSPI_WLEN(8);
priv->cmd |= QSPI_EN_CS(cs);
if (priv->mode & SPI_3WIRE)
priv->cmd |= QSPI_3_PIN;
@@ -206,15 +207,16 @@ static int ti_qspi_xfer(struct udevice *dev, unsigned int 
bitlen,
writel(data, >base->data1);
data = cpu_to_be32(*txbuf++);
writel(data, >base->data);
-   cmd &= ~QSPI_WLEN_MASK;
cmd |= QSPI_WLEN(QSPI_WLEN_MAX_BITS);
xfer_len = QSPI_WLEN_MAX_BYTES;
} else {
writeb(*txp, >base->data);
+   cmd |= QSPI_WLEN(8);
xfer_len = 1;
}
debug("tx cmd %08x dc %08x\n",
  cmd | QSPI_WR_SNGL, priv->dc);
+   // Only 1-bit write is supported
writel(cmd | QSPI_WR_SNGL, >base->cmd);
status = readl(>base->status);
timeout = QSPI_TIMEOUT;
@@ -229,9 +231,17 @@ static int ti_qspi_xfer(struct udevice *dev, unsigned int 
bitlen,
debug("tx done, status %08x\n", status);
}
if (rxp) {
+   u32 rx;
+   /* Check for dual and quad reads */
+   u32 readcmd_cmd = QSPI_RD_SNGL | QSPI_WLEN(8);
+   if (spi_slave->flags & SPI_XFER_DUAL_READ)
+   readcmd_cmd = QSPI_RD_DUAL | QSPI_WLEN(16);
+   if (spi_slave->flags & SPI_XFER_QUAD_READ)
+   readcmd_cmd = 

[PATCH 1/3] mtd: spi nor: add support for dual and quad bit transfers

2020-11-29 Thread Jean Pihet
Use the flags field of the SPI slave struct to pass the dual and quad
read properties, from the SPI NOR layer to the low level driver.
Tested with TI QSPI in 1, 2 and 4 bits modes.

Signed-off-by: Jean Pihet 
---
 drivers/mtd/spi/spi-nor-core.c | 34 +++---
 drivers/spi/spi-mem.c  |  8 +++-
 include/spi.h  |  2 ++
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index e16b0e1462..54569b3cba 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -94,22 +94,50 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, 
loff_t from, size_t len,
/* convert the dummy cycles to the number of bytes */
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
 
+   /* Check for dual and quad I/O read */
+   switch (op.cmd.opcode) {
+   case SPINOR_OP_READ_1_1_2:
+   case SPINOR_OP_READ_1_2_2:
+   case SPINOR_OP_READ_1_1_2_4B:
+   case SPINOR_OP_READ_1_2_2_4B:
+   case SPINOR_OP_READ_1_2_2_DTR:
+   case SPINOR_OP_READ_1_2_2_DTR_4B:
+   nor->spi->flags |= SPI_XFER_DUAL_READ;
+   break;
+   case SPINOR_OP_READ_1_1_4:
+   case SPINOR_OP_READ_1_4_4:
+   case SPINOR_OP_READ_1_1_4_4B:
+   case SPINOR_OP_READ_1_4_4_4B:
+   case SPINOR_OP_READ_1_4_4_DTR:
+   case SPINOR_OP_READ_1_4_4_DTR_4B:
+   nor->spi->flags |= SPI_XFER_QUAD_READ;
+   break;
+   default:
+   break;
+   }
+
while (remaining) {
op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
ret = spi_mem_adjust_op_size(nor->spi, );
if (ret)
-   return ret;
+   goto out;
 
ret = spi_mem_exec_op(nor->spi, );
if (ret)
-   return ret;
+   goto out;
 
op.addr.val += op.data.nbytes;
remaining -= op.data.nbytes;
op.data.buf.in += op.data.nbytes;
}
 
-   return len;
+   ret = len;
+
+out:
+   /* Reset dual and quad I/O read flags for upcoming transactions */
+   nor->spi->flags &= ~(SPI_XFER_DUAL_READ | SPI_XFER_QUAD_READ);
+
+   return ret;
 }
 
 static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index c095ae9505..24e38ea95e 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -387,9 +387,15 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct 
spi_mem_op *op)
return ret;
 
/* 2nd transfer: rx or tx data path */
+   flag = SPI_XFER_END;
+   /* Check for dual and quad I/O reads */
+   if (slave->flags & SPI_XFER_DUAL_READ)
+   flag |= SPI_XFER_DUAL_READ;
+   if (slave->flags & SPI_XFER_QUAD_READ)
+   flag |= SPI_XFER_QUAD_READ;
if (tx_buf || rx_buf) {
ret = spi_xfer(slave, op->data.nbytes * 8, tx_buf,
-  rx_buf, SPI_XFER_END);
+  rx_buf, flag);
if (ret)
return ret;
}
diff --git a/include/spi.h b/include/spi.h
index ef8c1f6692..cf5f05e526 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -146,6 +146,8 @@ struct spi_slave {
 #define SPI_XFER_BEGIN BIT(0)  /* Assert CS before transfer */
 #define SPI_XFER_END   BIT(1)  /* Deassert CS after transfer */
 #define SPI_XFER_ONCE  (SPI_XFER_BEGIN | SPI_XFER_END)
+#define SPI_XFER_DUAL_READ BIT(2)  /* Dual I/O read */
+#define SPI_XFER_QUAD_READ BIT(3)  /* Quad I/O read */
 };
 
 /**
-- 
2.26.2



[PATCH 00/11] dm: Simplify livetree handling

2020-11-29 Thread Simon Glass
At present there are separate code paths for livetree and flattree in
places where they can be made common. Also there are a few functions
that support flattree but can be moved over to use the livetree API (i.e.
ofnode instead of a DT offset).

This series tidies up these areas.


Simon Glass (11):
  dm: core: Rename device_bind() to device_bind_offset()
  dm: core: Rename device_bind_ofnode() to device_bind()
  dm: core: Add a livetree function to check node status
  dm: Remove uses of device_bind_offset()
  dm: Drop uses of dev_set_of_offset()
  dm: core: Drop dev_set_of_offset()
  dm: core: Drop device_bind_offset()
  dm: core: Add an ofnode function to get the devicetree root
  dm: core: Combine the flattree and livetree binding code
  dm: core: Drop unused parameter from dm_scan_fdt()
  dm: core: Drop unused parameter from dm_extended_scan_fdt()

 drivers/clk/at91/compat.c   | 20 ++---
 drivers/clk/clk.c   |  2 +-
 drivers/core/device.c   | 10 +--
 drivers/core/ofnode.c   | 10 +++
 drivers/core/root.c | 97 ++---
 drivers/firmware/scmi/scmi_agent-uclass.c   |  4 +-
 drivers/gpio/dwapb_gpio.c   |  4 +-
 drivers/gpio/mt7621_gpio.c  |  5 +-
 drivers/gpio/s5p_gpio.c |  6 +-
 drivers/gpio/sunxi_gpio.c   |  5 +-
 drivers/gpio/tegra186_gpio.c|  3 +-
 drivers/gpio/tegra_gpio.c   |  4 +-
 drivers/misc/i2c_eeprom.c   |  4 +-
 drivers/mtd/spi/sandbox.c   |  2 +-
 drivers/net/mvpp2.c |  4 +-
 drivers/pci/pci-uclass.c|  4 +-
 drivers/pci/pci_mvebu.c |  4 +-
 drivers/pinctrl/broadcom/pinctrl-bcm283x.c  |  2 +-
 drivers/pinctrl/meson/pinctrl-meson.c   |  5 +-
 drivers/pinctrl/mscc/pinctrl-jr2.c  |  2 +-
 drivers/pinctrl/mscc/pinctrl-luton.c|  2 +-
 drivers/pinctrl/mscc/pinctrl-ocelot.c   |  2 +-
 drivers/pinctrl/mscc/pinctrl-serval.c   |  2 +-
 drivers/pinctrl/mscc/pinctrl-servalt.c  |  2 +-
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c |  8 +-
 drivers/usb/host/usb-uclass.c   |  4 +-
 include/dm/device-internal.h| 10 +--
 include/dm/device.h |  5 --
 include/dm/ofnode.h | 23 +
 include/dm/root.h   |  8 +-
 test/dm/core.c  |  6 +-
 test/dm/ofnode.c| 12 +++
 test/dm/test-fdt.c  |  4 +-
 test/dm/test-main.c |  4 +-
 34 files changed, 130 insertions(+), 159 deletions(-)

-- 
2.29.2.454.gaff20da3a2-goog



Re: [PATCH v9 08/11] tools: add mkeficapsule command for UEFI capsule update

2020-11-29 Thread AKASHI Takahiro
Heinrich,

On Sun, Nov 29, 2020 at 05:59:41AM +0100, Heinrich Schuchardt wrote:
> On 11/27/20 3:22 PM, Heinrich Schuchardt wrote:
> > Am 25. November 2020 08:32:08 MEZ schrieb AKASHI Takahiro 
> > :
> > > Heinrich,
> > > 
> > > On Wed, Nov 25, 2020 at 07:42:31AM +0100, Heinrich Schuchardt wrote:
> > > > Am 25. November 2020 02:05:06 MEZ schrieb AKASHI Takahiro
> > > :
> > > > > Heinrich,
> > > > > 
> > > > > On Tue, Nov 24, 2020 at 09:23:50PM +0100, Heinrich Schuchardt wrote:
> > > > > > On 11/17/20 1:28 AM, AKASHI Takahiro wrote:
> > > > > > > This is a utility mainly for test purpose.
> > > > > > > mkeficapsule -f: create a test capsule file for FIT image
> > > > > firmware
> > > > > > > 
> > > > > > > Having said that, you will be able to customize the code to fit
> > > > > > > your specific requirements for your platform.
> > > > > > > 
> > > > > > > Signed-off-by: AKASHI Takahiro 
> > > > > > > ---
> > > > > > >tools/Makefile   |   2 +
> > > > > > >tools/mkeficapsule.c | 238
> > > > > +++
> > > > > > >2 files changed, 240 insertions(+)
> > > > > > >create mode 100644 tools/mkeficapsule.c
> > > > > > > 
> > > > > > > diff --git a/tools/Makefile b/tools/Makefile
> > > > > > > index 51123fd92983..66d9376803e3 100644
> > > > > > > --- a/tools/Makefile
> > > > > > > +++ b/tools/Makefile
> > > > > > > @@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs
> > > > > > >hostprogs-$(CONFIG_ASN1_COMPILER)  += asn1_compiler
> > > > > > >HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
> > > > > > > 
> > > > > > > +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
> > > > > > > +
> > > > > > ># We build some files with extra pedantic flags to try to
> > > > > minimize things
> > > > > > ># that won't build on some weird host compiler -- though there
> > > > > are lots of
> > > > > > ># exceptions for files that aren't complaint.
> > > > > > > diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> > > > > > > new file mode 100644
> > > > > > > index ..db95426457cc
> > > > > > > --- /dev/null
> > > > > > > +++ b/tools/mkeficapsule.c
> > > > > > > @@ -0,0 +1,238 @@
> > > > > > > +// SPDX-License-Identifier: GPL-2.0
> > > > > > > +/*
> > > > > > > + * Copyright 2018 Linaro Limited
> > > > > > > + *   Author: AKASHI Takahiro
> > > > > > > + */
> > > > > > > +
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +
> > > > > > > +typedef __u8 u8;
> > > > > > > +typedef __u16 u16;
> > > > > > > +typedef __u32 u32;
> > > > > > > +typedef __u64 u64;
> > > > > > > +typedef __s16 s16;
> > > > > > > +typedef __s32 s32;
> > > > > > > +
> > > > > > > +#define aligned_u64 __aligned_u64
> > > > > > > +
> > > > > > > +#ifndef __packed
> > > > > > > +#define __packed __attribute__((packed))
> > > > > > > +#endif
> > > > > > > +
> > > > > > > +#include 
> > > > > > > +#include 
> > > > > > > +
> > > > > > > +static const char *tool_name = "mkeficapsule";
> > > > > > > +
> > > > > > > +efi_guid_t efi_guid_fm_capsule =
> > > > > EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
> > > > > > > +efi_guid_t efi_guid_image_type_uboot_fit =
> > > > > > > + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID;
> > > > > > > +efi_guid_t efi_guid_image_type_uboot_raw =
> > > > > > > + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID;
> > > > > > > +
> > > > > > > +static struct option options[] = {
> > > > > > > + {"fit", required_argument, NULL, 'f'},
> > > > > > > + {"raw", required_argument, NULL, 'r'},
> > > > > > > + {"index", required_argument, NULL, 'i'},
> > > > > > > + {"instance", required_argument, NULL, 'I'},
> > > > > > > + {"version", required_argument, NULL, 'v'},
> > > > > > > + {"help", no_argument, NULL, 'h'},
> > > > > > > + {NULL, 0, NULL, 0},
> > > > > > > +};
> > > > > > > +
> > > > > > > +static void print_usage(void)
> > > > > > > +{
> > > > > > > + printf("Usage: %s [options] \n"
> > > > > > > +"Options:\n"
> > > > > > > +"\t--fit   new FIT image file\n"
> > > > > > > +"\t--raw   new raw image file\n"
> > > > > > > +"\t--index update image index\n"
> > > > > > > +"\t--instance   update hardware instance\n"
> > > > > > > +"\t--version firmware version\n"
> > > > > > > +"\t--help print a help message\n",
> > > > > > > +tool_name);
> > > > > > > +}
> > > > > > > +
> > > > > > > +static int create_fwbin(char *path, char *bin, efi_guid_t
> > > *guid,
> > > > > > > + unsigned long version, unsigned long index,
> > > > > > > + unsigned long instance)
> > > > > > > +{
> > > > > > > + struct efi_capsule_header header;
> > > > > > > + struct efi_firmware_management_capsule_header capsule;
> > 

[RFC] sunxi phy-mode rgmii-id

2020-11-29 Thread Heinrich Schuchardt

Hello Joe, hello Jagan,

since Linux patch
bbc4d71d6354 ("net: phy: realtek: fix rtl8211e rx/tx delay config")
i.e. since v5.8.15 or v5.9 many if not all Sunxi A64, H6, H5 boards
require phy-mode = "rgmii-id" to provide network in Linux

The U-Boot device-tree is the fallback in the UEFI sub-system if no
other device-tree is provided. So it would make sense to adjust the
U-Boot device-trees too.

The Linux patch has specifically changed the values corresponding to our
U-Boot defines:

#define MIIM_RTL8211E_CONFREG_TXD   0x0002
#define MIIM_RTL8211E_CONFREG_RXD   0x0004

At least my experience with the NanoPi Neo 2 and the Pine64 A64 LTS
indicates that setting phy-mode = "rgmii-id" in the device-tree does not
stop the operation of the network even if the driver is not adjusted.

To avoid breaking boards like Linux did we should change the
device-trees before or in sync with drivers/net/phy/realtek.c.

Best regards

Heinrich


Re: [PATCH] Add fdtfile for Marvell Armada 37xx default environment

2020-11-29 Thread Andre Heider

On 29/11/2020 09:32, Matwey V. Kornilov wrote:



чт, 26 нояб. 2020 г. в 12:40, Andre Heider >:


On 26/11/2020 10:04, Matwey V. Kornilov wrote:
 >
 >
 > чт, 26 нояб. 2020 г. в 06:45, Andre Heider mailto:a.hei...@gmail.com>
 > >>:
 >
 >     On 25/11/2020 10:14, Matwey V. Kornilov wrote:
 >      > Signed-off-by: Matwey V. Kornilov
mailto:matwey.korni...@gmail.com>
 >     >>
 >      > ---
 >      >   configs/mvebu_db-88f3720_defconfig          | 1 +
 >      >   configs/mvebu_espressobin-88f3720_defconfig | 1 +
 >      >   include/configs/mvebu_armada-37xx.h         | 1 +
 >      >   3 files changed, 3 insertions(+)
 >      >
 >      > diff --git a/configs/mvebu_db-88f3720_defconfig
 >     b/configs/mvebu_db-88f3720_defconfig
 >      > index a6bbe1a7af..1a3a267890 100644
 >      > --- a/configs/mvebu_db-88f3720_defconfig
 >      > +++ b/configs/mvebu_db-88f3720_defconfig
 >      > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
 >      >   CONFIG_DEBUG_UART_BASE=0xd0012000
 >      >   CONFIG_DEBUG_UART_CLOCK=25804800
 >      >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-db"
 >      > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-db.dtb"
 >      >   CONFIG_DEBUG_UART=y
 >      >   CONFIG_AHCI=y
 >      >   CONFIG_DISTRO_DEFAULTS=y
 >      > diff --git a/configs/mvebu_espressobin-88f3720_defconfig
 >     b/configs/mvebu_espressobin-88f3720_defconfig
 >      > index 8a859cba2e..56ec482794 100644
 >      > --- a/configs/mvebu_espressobin-88f3720_defconfig
 >      > +++ b/configs/mvebu_espressobin-88f3720_defconfig
 >      > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
 >      >   CONFIG_DEBUG_UART_BASE=0xd0012000
 >      >   CONFIG_DEBUG_UART_CLOCK=25804800
 >      >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin"
 >      > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-espressobin.dtb"
 >
 >     No, that doesn't work for this board, see
 >     68e32e344 "arm: mvebu: Espressobin: Set environment variable
fdtfile"
 >
 >
 > Good point.
 > But why does this autodetection not work for me?

I guess that can only happen if:
- the commit isn't part of you tree
- you disabled CONFIG_BOARD_LATE_INIT or didn't refresh from the
defconfig
- you already have the envvar set/saved


Hi,

I've double checked, and you are right.
It seems that I did "env default" and fdtfile disappeared until the next 
reset.


What do you think? If the patch still needed for 3720-DB?


I'm not so sure anybody cares about that board anymore, but it's not up 
to me ;)


You would need to wrap setting `fdtfile` for the default env with
"#ifdef CONFIG_DEFAULT_FDT_FILE" then though.



 >
 >      >   CONFIG_DEBUG_UART=y
 >      >   CONFIG_AHCI=y
 >      >   CONFIG_DISTRO_DEFAULTS=y
 >      > diff --git a/include/configs/mvebu_armada-37xx.h
 >     b/include/configs/mvebu_armada-37xx.h
 >      > index 0d585606a7..377ac60def 100644
 >      > --- a/include/configs/mvebu_armada-37xx.h
 >      > +++ b/include/configs/mvebu_armada-37xx.h
 >      > @@ -96,6 +96,7 @@
 >      >       "kernel_addr=0x700\0"       \
 >      >       "kernel_addr_r=0x700\0"     \
 >      >       "ramdisk_addr_r=0xa00\0"    \
 >      > +     "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
 >      >       BOOTENV
 >      >
 >      >   #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */
 >      >
 >
 >
 >
 > --
 > With best regards,
 > Matwey V. Kornilov



--
With best regards,
Matwey V. Kornilov




Re: [PATCH 13/13] Nokia RX-51: Enable usbtty serial console by default

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:52:52, Pali Rohár wrote:
> Now when usbtty serial console is fixed in U-Boot enable it for Nokia RX-51
> board by default.
> 
> CONFIG_CONSOLE_MUX is already used and U-Boot console is available for
> all in/out devices. Therefore there is no need to have separate commands
> 'run sercon', 'run usbcon' and 'run vgacon', so remove them.
> 
> As space for U-Boot is limited to 256kB, disable some other unused options
> so CONFIG_USB_TTY can be enabled.
> 
> Nokia RX-51 does not have easily accessible UART serial console so the only
> option for easy debugging is to use device's keyboard+screen or this usbtty
> serial console over USB.
> 
> Signed-off-by: Pali Rohár 

11-13 Reviewed-by: Pavel Machek 

Best regards,
Pavel

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 10/13] arm: omap3: Compile s_init() function only when it is used

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:52:07, Pali Rohár wrote:
> Function s_init() is called only from lowlevel_init(). So compile it only
> when function lowlevel_init() is compiled.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 09/13] arm: omap3: Compile lowlevel_init() function only when it is used

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:51:38, Pali Rohár wrote:
> Function lowlevel_init() is called only from cpu_init_crit() and this
> function is wrapped into #if .. #endif section. So compile also
> lowlevel_init() function under same #if condition.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 08/13] usb: gadget: Use dbg_ep0() macro instead of serial_printf()

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:49:52, Pali Rohár wrote:
> All debug messages from ep0.c except a few are printed by dbg_ep0() macro.
> So for remaining few exception use also dbg_ep0() instead of serial_printf().
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 


-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 07/13] usb: gadget: Do not export usbd_device_* arrays

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:12, Pali Rohár wrote:
> Each array is used only in one file (core.c or ep0.c). Move their content
> to correct file, mark them as static and do not export out of current file.
> 
> This change allows to decrease size of u-boot.bin as more of those strings
> are not used.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 


-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 06/13] usb: musb: Fix transmission of bigger buffers

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:11, Pali Rohár wrote:
> If udc_endpoint_write() was called with bigger payload which does not fit
> into one USB packet it needs to be transmitted in more USB packets. First
> packet is transmitted by udc_endpoint_write() call itself and other packets
> are put into waiting queue.
> 
> Implement function musb_peri_tx() which transmit checks when endpoints are
> ready and continue transmitting of waiting queue.
> 
> This patch fixes sending e.g. output of printenv command over usbtty serial
> console.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 05/13] usb: musb: Read value of PERI_RXCSR to 16bit variable

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:10, Pali Rohár wrote:
> PERI_RXCSR is 16bit register so store its value into 16bit local variable.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 04/13] usb: musb: Fix configuring FIFO for endpoints

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:09, Pali Rohár wrote:
> This patch fixes configuring FIFO for one-directional endpoints which have
> either RX or TX queue and therefore only one FIFO.
> 
> Without this patch if FIFO size was zero then idx was incorrectly
> calculated (expr. ffs(0)-1 is not zero) and size overflowed in fifosz
> register. This register uses has only 4 bits for FIFO size.
> 
> This patch is fixing it by setting zero size and zero address when
> particular endpoint does not use FIFO.
> 
> This issue caused loose of packets on USB bus in both directions and
> basically usbtty was unusable.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 


-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 03/13] usb: musb: Always clear the data toggle bit when configuring ep

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:08, Pali Rohár wrote:
> Without this patch it was done only when U-Boot was compiled with MUSB Host
> Controller. But it is needed also for MUSB Device Controller, otherwise
> Device Controller does not work.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 02/13] usb: musb: Fix compilation of gadget code

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:07, Pali Rohár wrote:
> musb udc code depends on usb gadget code provided by CONFIG_USB_DEVICE and
> defined in drivers/usb/gadget/Makefile. But this Makefile is not included
> into U-Boot build when CONFIG_USB_GADGET is not set. As CONFIG_USB_DEVICE
> cannot be enabled together with CONFIG_USB_GADGET it means that dependency
> for musb udc code is not compiled during build. Fix it by including
> drivers/usb/gadget dependency also when CONFIG_USB_DEVICE is set.
> 
_device_event_irq'
> arm-linux-gnueabi-ld.bfd: 
> drivers/usb/musb/built-in.o:u-boot/drivers/usb/musb/musb_udc.c: more 
> undefined references to `usbd_device_event_irq' follow
> arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
> `udc_setup_ep':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `usbd_alloc_urb'
> arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
> `udc_startup_events':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to 
> `usbd_device_event_irq'
> arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
> reference to `usbd_device_event_irq'
> arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
> reference to `usbd_device_event_irq'
> make: *** [Makefile:1762: u-boot] Error 1
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [PATCH 01/13] serial: usbtty: Fix puts function

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:46:06, Pali Rohár wrote:
> This function has incorrect implementation of prepending CR prior LF.
> Without this patch it prepended CR prior whole string which is going to be
> written and let LF without leading CR. Fix this issue by inserting CR at
> correct place to make output on usbtty serial console more readable.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 

-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [maemo-leste] [PATCH] Nokia RX-51: Add test for U-Boot serial console

2020-11-29 Thread Pavel Machek
On Sun 2020-11-29 17:15:05, Pali Rohár wrote:
> This patch adds a new test which checks that U-Boot for Nokia RX-51 running
> in qemu can print test line to serial console and also checks that test
> line appeared on qemu serial console.
> 
> Signed-off-by: Pali Rohár 

Reviewed-by: Pavel Machek 


-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


Re: [maemo-leste] [PATCH] Nokia RX-51: Decrease i2c speed to 100000

2020-11-29 Thread Pavel Machek
On Sat 2020-11-21 23:30:11, Pali Rohár wrote:
> It looks like that i2c bus lot of times timeout on some units. Prior
> migration to CONFIG_DM_I2C i2c speed was set to CONFIG_SYS_OMAP24_I2C_SPEED
> value which was 10. Lower speed fixes timeout problems, so change speed
> back to its previous value.
> 
> Signed-off-by: Pali Rohár 
> Fixes: 8d8c18170325 ("Nokia RX-51: Convert to CONFIG_DM_I2C")

Reviewed-by: Pavel Machek 

Best regards,
Pavel
-- 
http://www.livejournal.com/~pavelmachek


signature.asc
Description: Digital signature


[PATCH 13/13] Nokia RX-51: Enable usbtty serial console by default

2020-11-29 Thread Pali Rohár
Now when usbtty serial console is fixed in U-Boot enable it for Nokia RX-51
board by default.

CONFIG_CONSOLE_MUX is already used and U-Boot console is available for
all in/out devices. Therefore there is no need to have separate commands
'run sercon', 'run usbcon' and 'run vgacon', so remove them.

As space for U-Boot is limited to 256kB, disable some other unused options
so CONFIG_USB_TTY can be enabled.

Nokia RX-51 does not have easily accessible UART serial console so the only
option for easy debugging is to use device's keyboard+screen or this usbtty
serial console over USB.

Signed-off-by: Pali Rohár 
---
 configs/nokia_rx51_defconfig |  6 +++---
 doc/README.nokia_rx51| 15 +--
 include/configs/nokia_rx51.h | 16 
 3 files changed, 8 insertions(+), 29 deletions(-)

diff --git a/configs/nokia_rx51_defconfig b/configs/nokia_rx51_defconfig
index 0f05fe6fc3..e1b874a870 100644
--- a/configs/nokia_rx51_defconfig
+++ b/configs/nokia_rx51_defconfig
@@ -44,18 +44,16 @@ 
CONFIG_MTDPARTS_DEFAULT="mtdparts=onenand:128k(bootloader)ro,384k(config),256k(l
 CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 # CONFIG_NET is not set
-CONFIG_TWL4030_LED=y
 # CONFIG_MMC_HW_PARTITIONING is not set
+# CONFIG_MMC_VERBOSE is not set
 CONFIG_MMC_OMAP_HS=y
 CONFIG_MTD=y
 CONFIG_CONS_INDEX=3
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_USB=y
-CONFIG_USB_MUSB_HCD=y
 CONFIG_USB_MUSB_UDC=y
 CONFIG_USB_OMAP3=y
-CONFIG_TWL4030_USB=y
 CONFIG_CFB_CONSOLE=y
 CONFIG_CFB_CONSOLE_ANSI=y
 # CONFIG_VGA_AS_SINGLE_DEVICE is not set
@@ -66,3 +64,5 @@ CONFIG_DM_I2C=y
 CONFIG_DM_MMC=y
 # CONFIG_DM_DEVICE_REMOVE is not set
 # CONFIG_SYS_MALLOC_F is not set
+# CONFIG_DM_WARN is not set
+# CONFIG_BLOCK_CACHE is not set
diff --git a/doc/README.nokia_rx51 b/doc/README.nokia_rx51
index 320b5efc7d..84d1912ddd 100644
--- a/doc/README.nokia_rx51
+++ b/doc/README.nokia_rx51
@@ -24,8 +24,7 @@ called u-boot-gen-combined. It is available in following 
repository:
 There is support for hardware watchdog. Hardware watchdog is started by
 NOLO so u-boot must kick watchdog to prevent reboot device (but not very
 often, max every 2 seconds). There is also support for framebuffer display
-output with ANSI escape codes and the N900 HW keyboard input. USB tty works
-but is disabled because it prevents the current Maemo kernel from booting.
+output with ANSI escape codes and the N900 HW keyboard input.
 
 When U-Boot is starting it enable IBE bit in Auxiliary Control Register,
 which is needed for Thumb-2 ISA support. It is workaround for errata 430973.
@@ -49,10 +48,6 @@ Boot from SD or eMMC in this order:
 
 Available additional commands/variables:
 
- * run sercon - Use serial port for control
- * run usbcon - Use usbtty for control
- * run vgacon - Use framebuffer and HW keyboard for control (default)
-
  * run sdboot - Boot from external SD card (see boot order)
  * run emmcboot - Boot from internal eMMC memory (see boot order)
  * run attachboot - Boot attached kernel image (attached to U-Boot binary)
@@ -87,14 +82,6 @@ Additional variables for booting kernel:
  and u-boot standard output is set to serial then setup_console_atag is
  automatically set to 1. So output from Maemo kernel would go to serial port.
 
-USB TTY:
-
- Maemo kernel 2.6.28 will crash if u-boot enable usb tty. So USB TTY is 
disabled.
- For enabling USB TTY just add this line to file include/configs/nokia_rx51.h
-
- #define CONFIG_USB_TTY
-
-
 UBIFS support:
 
  UBIFS support is disabled, because U-Boot image is too big and cannot be
diff --git a/include/configs/nokia_rx51.h b/include/configs/nokia_rx51.h
index 6879f52a0c..36b1f9221c 100644
--- a/include/configs/nokia_rx51.h
+++ b/include/configs/nokia_rx51.h
@@ -70,6 +70,7 @@
 
 /* USB device configuration */
 #define CONFIG_USB_DEVICE
+#define CONFIG_USB_TTY
 #define CONFIG_USBD_VENDORID   0x0421
 #define CONFIG_USBD_PRODUCTID  0x01c8
 #define CONFIG_USBD_MANUFACTURER   "Nokia"
@@ -108,15 +109,9 @@ int rx51_kp_getc(struct stdio_dev *sdev);
 /* Environment information */
 #define CONFIG_EXTRA_ENV_SETTINGS \
"usbtty=cdc_acm\0" \
-   "stdin=serial,vga\0" \
-   "stdout=serial,vga\0" \
-   "stderr=serial,vga\0" \
-   "setcon=setenv stdin ${con};" \
-   "setenv stdout ${con};" \
-   "setenv stderr ${con}\0" \
-   "sercon=setenv con serial; run setcon\0" \
-   "usbcon=setenv con usbtty; run setcon\0" \
-   "vgacon=setenv con vga; run setcon\0" \
+   "stdin=usbtty,serial,vga\0" \
+   "stdout=usbtty,serial,vga\0" \
+   "stderr=usbtty,serial,vga\0" \
"slide=gpio input " __stringify(GPIO_SLIDE) "\0" \
"switchmmc=mmc dev ${mmcnum}\0" \
"kernaddr=0x82008000\0" \
@@ -209,9 +204,6 @@ int rx51_kp_getc(struct stdio_dev *sdev);
 #define CONFIG_POSTBOOTMENU \
"echo;" \
"echo Extra commands:;" \
-   "echo run sercon - Use serial port for control.;" \
-   "echo run usbcon - Use 

[PATCH 12/13] Nokia RX-51: Move content of rx51.h to rx51.c

2020-11-29 Thread Pali Rohár
After removal of MUX configuration there is no need to have extra rx51.h.

Signed-off-by: Pali Rohár 
---
 board/nokia/rx51/rx51.c | 17 -
 board/nokia/rx51/rx51.h | 31 ---
 2 files changed, 16 insertions(+), 32 deletions(-)
 delete mode 100644 board/nokia/rx51/rx51.h

diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
index 78edd2145c..58fc779ad3 100644
--- a/board/nokia/rx51/rx51.c
+++ b/board/nokia/rx51/rx51.c
@@ -39,9 +39,24 @@
 #include 
 #include 
 
-#include "rx51.h"
 #include "tag_omap.h"
 
+/* Needed for ROM SMC call */
+struct emu_hal_params_rx51 {
+   u32 num_params;
+   u32 param1;
+   u32 param2;
+   u32 param3;
+   u32 param4;
+};
+
+#define ONENAND_GPMC_CONFIG1_RX51  0xfb001202
+#define ONENAND_GPMC_CONFIG2_RX51  0x0000
+#define ONENAND_GPMC_CONFIG3_RX51  0x00020200
+#define ONENAND_GPMC_CONFIG4_RX51  0x11001102
+#define ONENAND_GPMC_CONFIG5_RX51  0x03101616
+#define ONENAND_GPMC_CONFIG6_RX51  0x9006
+
 DECLARE_GLOBAL_DATA_PTR;
 
 GraphicDevice gdev;
diff --git a/board/nokia/rx51/rx51.h b/board/nokia/rx51/rx51.h
deleted file mode 100644
index 0eddb06219..00
--- a/board/nokia/rx51/rx51.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (C) Copyright 2012
- * Ивайло Димитров 
- *
- * (C) Copyright 2011-2012
- * Pali Rohár 
- *
- * (C) Copyright 2008
- * Dirk Behme 
- */
-#ifndef _RX51_H_
-#define _RX51_H_
-
-/* Needed for ROM SMC call */
-struct emu_hal_params_rx51 {
-   u32 num_params;
-   u32 param1;
-   u32 param2;
-   u32 param3;
-   u32 param4;
-};
-
-#define ONENAND_GPMC_CONFIG1_RX51  0xfb001202
-#define ONENAND_GPMC_CONFIG2_RX51  0x0000
-#define ONENAND_GPMC_CONFIG3_RX51  0x00020200
-#define ONENAND_GPMC_CONFIG4_RX51  0x11001102
-#define ONENAND_GPMC_CONFIG5_RX51  0x03101616
-#define ONENAND_GPMC_CONFIG6_RX51  0x9006
-
-#endif
-- 
2.20.1



[PATCH 11/13] Nokia RX-51: Remove function set_muxconf_regs()

2020-11-29 Thread Pali Rohár
This function is not used and was never called.

This board contains '#define CONFIG_SKIP_LOWLEVEL_INIT' because X-Loader
set everything up, including MUX configuration.

Also this MUX configuration is incorrect and does not match hardware.

So remove this dead, unused and broken code.

This change will decrease size of U-Boot binary.

Signed-off-by: Pali Rohár 
---
 board/nokia/rx51/rx51.c |  11 --
 board/nokia/rx51/rx51.h | 346 
 2 files changed, 357 deletions(-)

diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
index 7390e5be65..78edd2145c 100644
--- a/board/nokia/rx51/rx51.c
+++ b/board/nokia/rx51/rx51.c
@@ -467,17 +467,6 @@ int misc_init_r(void)
return 0;
 }
 
-/*
- * Routine: set_muxconf_regs
- * Description: Setting up the configuration Mux registers specific to the
- * hardware. Many pins need to be moved from protect to primary
- * mode.
- */
-void set_muxconf_regs(void)
-{
-   MUX_RX51();
-}
-
 static unsigned long int twl_wd_time; /* last time of watchdog reset */
 static unsigned long int twl_i2c_lock;
 
diff --git a/board/nokia/rx51/rx51.h b/board/nokia/rx51/rx51.h
index 4eff823a1b..0eddb06219 100644
--- a/board/nokia/rx51/rx51.h
+++ b/board/nokia/rx51/rx51.h
@@ -21,352 +21,6 @@ struct emu_hal_params_rx51 {
u32 param4;
 };
 
-/*
- * IEN  - Input Enable
- * IDIS - Input Disable
- * PTD  - Pull type Down
- * PTU  - Pull type Up
- * DIS  - Pull type selection is inactive
- * EN   - Pull type selection is active
- * M0   - Mode 0
- * The commented string gives the final mux configuration for that pin
- */
-#define MUX_RX51() \
-/* SDRC */\
-   MUX_VAL(CP(SDRC_D0),(IEN  | PTD | DIS | M0)) /*SDRC_D0*/\
-   MUX_VAL(CP(SDRC_D1),(IEN  | PTD | DIS | M0)) /*SDRC_D1*/\
-   MUX_VAL(CP(SDRC_D2),(IEN  | PTD | DIS | M0)) /*SDRC_D2*/\
-   MUX_VAL(CP(SDRC_D3),(IEN  | PTD | DIS | M0)) /*SDRC_D3*/\
-   MUX_VAL(CP(SDRC_D4),(IEN  | PTD | DIS | M0)) /*SDRC_D4*/\
-   MUX_VAL(CP(SDRC_D5),(IEN  | PTD | DIS | M0)) /*SDRC_D5*/\
-   MUX_VAL(CP(SDRC_D6),(IEN  | PTD | DIS | M0)) /*SDRC_D6*/\
-   MUX_VAL(CP(SDRC_D7),(IEN  | PTD | DIS | M0)) /*SDRC_D7*/\
-   MUX_VAL(CP(SDRC_D8),(IEN  | PTD | DIS | M0)) /*SDRC_D8*/\
-   MUX_VAL(CP(SDRC_D9),(IEN  | PTD | DIS | M0)) /*SDRC_D9*/\
-   MUX_VAL(CP(SDRC_D10),   (IEN  | PTD | DIS | M0)) /*SDRC_D10*/\
-   MUX_VAL(CP(SDRC_D11),   (IEN  | PTD | DIS | M0)) /*SDRC_D11*/\
-   MUX_VAL(CP(SDRC_D12),   (IEN  | PTD | DIS | M0)) /*SDRC_D12*/\
-   MUX_VAL(CP(SDRC_D13),   (IEN  | PTD | DIS | M0)) /*SDRC_D13*/\
-   MUX_VAL(CP(SDRC_D14),   (IEN  | PTD | DIS | M0)) /*SDRC_D14*/\
-   MUX_VAL(CP(SDRC_D15),   (IEN  | PTD | DIS | M0)) /*SDRC_D15*/\
-   MUX_VAL(CP(SDRC_D16),   (IEN  | PTD | DIS | M0)) /*SDRC_D16*/\
-   MUX_VAL(CP(SDRC_D17),   (IEN  | PTD | DIS | M0)) /*SDRC_D17*/\
-   MUX_VAL(CP(SDRC_D18),   (IEN  | PTD | DIS | M0)) /*SDRC_D18*/\
-   MUX_VAL(CP(SDRC_D19),   (IEN  | PTD | DIS | M0)) /*SDRC_D19*/\
-   MUX_VAL(CP(SDRC_D20),   (IEN  | PTD | DIS | M0)) /*SDRC_D20*/\
-   MUX_VAL(CP(SDRC_D21),   (IEN  | PTD | DIS | M0)) /*SDRC_D21*/\
-   MUX_VAL(CP(SDRC_D22),   (IEN  | PTD | DIS | M0)) /*SDRC_D22*/\
-   MUX_VAL(CP(SDRC_D23),   (IEN  | PTD | DIS | M0)) /*SDRC_D23*/\
-   MUX_VAL(CP(SDRC_D24),   (IEN  | PTD | DIS | M0)) /*SDRC_D24*/\
-   MUX_VAL(CP(SDRC_D25),   (IEN  | PTD | DIS | M0)) /*SDRC_D25*/\
-   MUX_VAL(CP(SDRC_D26),   (IEN  | PTD | DIS | M0)) /*SDRC_D26*/\
-   MUX_VAL(CP(SDRC_D27),   (IEN  | PTD | DIS | M0)) /*SDRC_D27*/\
-   MUX_VAL(CP(SDRC_D28),   (IEN  | PTD | DIS | M0)) /*SDRC_D28*/\
-   MUX_VAL(CP(SDRC_D29),   (IEN  | PTD | DIS | M0)) /*SDRC_D29*/\
-   MUX_VAL(CP(SDRC_D30),   (IEN  | PTD | DIS | M0)) /*SDRC_D30*/\
-   MUX_VAL(CP(SDRC_D31),   (IEN  | PTD | DIS | M0)) /*SDRC_D31*/\
-   MUX_VAL(CP(SDRC_CLK),   (IEN  | PTD | DIS | M0)) /*SDRC_CLK*/\
-   MUX_VAL(CP(SDRC_DQS0),  (IEN  | PTD | DIS | M0)) /*SDRC_DQS0*/\
-   MUX_VAL(CP(SDRC_DQS1),  (IEN  | PTD | DIS | M0)) /*SDRC_DQS1*/\
-   MUX_VAL(CP(SDRC_DQS2),  (IEN  | PTD | DIS | M0)) /*SDRC_DQS2*/\
-   MUX_VAL(CP(SDRC_DQS3),  (IEN  | PTD | DIS | M0)) /*SDRC_DQS3*/\
-/* GPMC */\
-   MUX_VAL(CP(GPMC_A1),(IDIS | PTD | DIS | M0)) /*GPMC_A1*/\
-   MUX_VAL(CP(GPMC_A2),(IDIS | PTD | DIS | M0)) /*GPMC_A2*/\
-   MUX_VAL(CP(GPMC_A3),(IDIS | PTD | DIS | M0)) /*GPMC_A3*/\
-   MUX_VAL(CP(GPMC_A4),(IDIS | PTD | DIS | M0)) /*GPMC_A4*/\
-   MUX_VAL(CP(GPMC_A5),(IDIS | PTD | DIS | M0)) /*GPMC_A5*/\
- 

[PATCH 10/13] arm: omap3: Compile s_init() function only when it is used

2020-11-29 Thread Pali Rohár
Function s_init() is called only from lowlevel_init(). So compile it only
when function lowlevel_init() is compiled.

Signed-off-by: Pali Rohár 
---
 arch/arm/mach-omap2/omap3/board.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index f08c8ab43a..9ea219fafc 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -179,6 +179,8 @@ void early_system_init(void)
hw_data_init();
 }
 
+#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
+   !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
 /**
  * Routine: s_init
  * Description: Does early system init of muxing and clocks.
@@ -207,6 +209,7 @@ void s_init(void)
ehci_clocks_enable();
 #endif
 }
+#endif
 
 #ifdef CONFIG_SPL_BUILD
 void board_init_f(ulong dummy)
-- 
2.20.1



[PATCH 09/13] arm: omap3: Compile lowlevel_init() function only when it is used

2020-11-29 Thread Pali Rohár
Function lowlevel_init() is called only from cpu_init_crit() and this
function is wrapped into #if .. #endif section. So compile also
lowlevel_init() function under same #if condition.

Signed-off-by: Pali Rohár 
---
 arch/arm/mach-omap2/omap3/lowlevel_init.S | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/omap3/lowlevel_init.S 
b/arch/arm/mach-omap2/omap3/lowlevel_init.S
index 2a05b5e521..4fa89418a1 100644
--- a/arch/arm/mach-omap2/omap3/lowlevel_init.S
+++ b/arch/arm/mach-omap2/omap3/lowlevel_init.S
@@ -45,7 +45,7 @@ ENDPROC(do_omap3_emu_romcode_call)
 ENTRY(cpy_clk_code)
/* Copy DPLL code into SRAM */
adr r0, go_to_speed /* copy from start of go_to_speed... */
-   adr r2, lowlevel_init   /* ... up to start of low_level_init */
+   adr r2, go_to_speed_end /* ... up to start of go_to_speed_end */
 next2:
ldmia   r0!, {r3 - r10} /* copy from source address [r0] */
stmia   r1!, {r3 - r10} /* copy to   target address [r1] */
@@ -167,8 +167,11 @@ pll_div_add5:
 pll_div_val5:
.word CLSEL1_EMU_VAL
 
+go_to_speed_end:
 #endif
 
+#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
+   !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
 ENTRY(lowlevel_init)
ldr sp, SRAM_STACK
str ip, [sp]/* stash ip register */
@@ -187,6 +190,7 @@ ENTRY(lowlevel_init)
b   s_init
 
 ENDPROC(lowlevel_init)
+#endif
 
/* the literal pools origin */
.ltorg
-- 
2.20.1



[PATCH 08/13] usb: gadget: Use dbg_ep0() macro instead of serial_printf()

2020-11-29 Thread Pali Rohár
All debug messages from ep0.c except a few are printed by dbg_ep0() macro.
So for remaining few exception use also dbg_ep0() instead of serial_printf().

Signed-off-by: Pali Rohár 
---
 drivers/usb/gadget/ep0.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c
index 2b15a508c5..aafe2680aa 100644
--- a/drivers/usb/gadget/ep0.c
+++ b/drivers/usb/gadget/ep0.c
@@ -279,7 +279,7 @@ static int ep0_get_descriptor (struct usb_device_instance 
*device,
{
struct usb_string_descriptor *string_descriptor;
if (!(string_descriptor = usbd_get_string (index))) {
-   serial_printf("Invalid string index %d\n", 
index);
+   dbg_ep0(0, "Invalid string index %d\n", index);
return -1;
}
dbg_ep0(3, "string_descriptor: %p length %d", 
string_descriptor, string_descriptor->bLength);
@@ -287,14 +287,14 @@ static int ep0_get_descriptor (struct usb_device_instance 
*device,
}
break;
case USB_DESCRIPTOR_TYPE_INTERFACE:
-   serial_printf("USB_DESCRIPTOR_TYPE_INTERFACE - error not 
implemented\n");
+   dbg_ep0(2, "USB_DESCRIPTOR_TYPE_INTERFACE - error not 
implemented\n");
return -1;
case USB_DESCRIPTOR_TYPE_ENDPOINT:
-   serial_printf("USB_DESCRIPTOR_TYPE_ENDPOINT - error not 
implemented\n");
+   dbg_ep0(2, "USB_DESCRIPTOR_TYPE_ENDPOINT - error not 
implemented\n");
return -1;
case USB_DESCRIPTOR_TYPE_HID:
{
-   serial_printf("USB_DESCRIPTOR_TYPE_HID - error not 
implemented\n");
+   dbg_ep0(2, "USB_DESCRIPTOR_TYPE_HID - error not 
implemented\n");
return -1;  /* unsupported at this time */
 #if 0
int bNumInterface =
@@ -323,7 +323,7 @@ static int ep0_get_descriptor (struct usb_device_instance 
*device,
break;
case USB_DESCRIPTOR_TYPE_REPORT:
{
-   serial_printf("USB_DESCRIPTOR_TYPE_REPORT - error not 
implemented\n");
+   dbg_ep0(2, "USB_DESCRIPTOR_TYPE_REPORT - error not 
implemented\n");
return -1;  /* unsupported at this time */
 #if 0
int bNumInterface =
@@ -516,7 +516,7 @@ int ep0_recv_setup (struct urb *urb)
   le16_to_cpu 
(request->wValue) & 0xff);
 
case USB_REQ_GET_CONFIGURATION:
-   serial_printf("get config %d\n", device->configuration);
+   dbg_ep0(2, "get config %d\n", device->configuration);
return ep0_get_one (device, urb,
device->configuration);
 
@@ -606,14 +606,14 @@ int ep0_recv_setup (struct urb *urb)
device->interface = device->alternate = 0;
 
/*dbg_ep0(2, "set configuration: %d", 
device->configuration); */
-   /*serial_printf("DEVICE_CONFIGURED.. event?\n"); */
+   /*dbg_ep0(2, "DEVICE_CONFIGURED.. event?\n"); */
return 0;
 
case USB_REQ_SET_INTERFACE:
device->interface = le16_to_cpu (request->wIndex);
device->alternate = le16_to_cpu (request->wValue);
/*dbg_ep0(2, "set interface: %d alternate: %d", 
device->interface, device->alternate); */
-   serial_printf("DEVICE_SET_INTERFACE.. event?\n");
+   dbg_ep0(2, "DEVICE_SET_INTERFACE.. event?\n");
return 0;
 
case USB_REQ_GET_STATUS:
-- 
2.20.1



[PATCH 07/13] usb: gadget: Do not export usbd_device_* arrays

2020-11-29 Thread Pali Rohár
Each array is used only in one file (core.c or ep0.c). Move their content
to correct file, mark them as static and do not export out of current file.

This change allows to decrease size of u-boot.bin as more of those strings
are not used.

Signed-off-by: Pali Rohár 
---
 drivers/usb/gadget/core.c | 38 --
 drivers/usb/gadget/ep0.c  | 31 +++
 include/usbdevice.h   | 15 ---
 3 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/drivers/usb/gadget/core.c b/drivers/usb/gadget/core.c
index 3781d25fd6..c86ee2f849 100644
--- a/drivers/usb/gadget/core.c
+++ b/drivers/usb/gadget/core.c
@@ -36,7 +36,7 @@ extern struct usb_function_driver ep0_driver;
 int registered_functions;
 int registered_devices;
 
-char *usbd_device_events[] = {
+__maybe_unused static char *usbd_device_events[] = {
"DEVICE_UNKNOWN",
"DEVICE_INIT",
"DEVICE_CREATE",
@@ -56,34 +56,7 @@ char *usbd_device_events[] = {
"DEVICE_FUNCTION_PRIVATE",
 };
 
-char *usbd_device_states[] = {
-   "STATE_INIT",
-   "STATE_CREATED",
-   "STATE_ATTACHED",
-   "STATE_POWERED",
-   "STATE_DEFAULT",
-   "STATE_ADDRESSED",
-   "STATE_CONFIGURED",
-   "STATE_UNKNOWN",
-};
-
-char *usbd_device_requests[] = {
-   "GET STATUS",   /* 0 */
-   "CLEAR FEATURE",/* 1 */
-   "RESERVED", /* 2 */
-   "SET FEATURE",  /* 3 */
-   "RESERVED", /* 4 */
-   "SET ADDRESS",  /* 5 */
-   "GET DESCRIPTOR",   /* 6 */
-   "SET DESCRIPTOR",   /* 7 */
-   "GET CONFIGURATION",/* 8 */
-   "SET CONFIGURATION",/* 9 */
-   "GET INTERFACE",/* 10 */
-   "SET INTERFACE",/* 11 */
-   "SYNC FRAME",   /* 12 */
-};
-
-char *usbd_device_descriptors[] = {
+__maybe_unused static char *usbd_device_descriptors[] = {
"UNKNOWN",  /* 0 */
"DEVICE",   /* 1 */
"CONFIG",   /* 2 */
@@ -95,13 +68,18 @@ char *usbd_device_descriptors[] = {
"INTERFACE POWER",  /* 8 */
 };
 
-char *usbd_device_status[] = {
+#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int)x <= 
USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? \
+   usbd_device_descriptors[x] : "UNKNOWN")
+
+__maybe_unused static char *usbd_device_status[] = {
"USBD_OPENING",
"USBD_OK",
"USBD_SUSPENDED",
"USBD_CLOSING",
 };
 
+#define USBD_DEVICE_STATUS(x) (((unsigned int)x <= USBD_CLOSING) ? 
usbd_device_status[x] : "UNKNOWN")
+
 
 /* Descriptor support functions 
** */
 
diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c
index 6fabee24ce..2b15a508c5 100644
--- a/drivers/usb/gadget/ep0.c
+++ b/drivers/usb/gadget/ep0.c
@@ -46,6 +46,37 @@
 #define dbg_ep0(lvl,fmt,args...)
 #endif
 
+__maybe_unused static char *usbd_device_states[] = {
+   "STATE_INIT",
+   "STATE_CREATED",
+   "STATE_ATTACHED",
+   "STATE_POWERED",
+   "STATE_DEFAULT",
+   "STATE_ADDRESSED",
+   "STATE_CONFIGURED",
+   "STATE_UNKNOWN",
+};
+
+#define USBD_DEVICE_STATE(x) (((unsigned int)x <= STATE_UNKNOWN) ? 
usbd_device_states[x] : "UNKNOWN")
+
+__maybe_unused static char *usbd_device_requests[] = {
+   "GET STATUS",   /* 0 */
+   "CLEAR FEATURE",/* 1 */
+   "RESERVED", /* 2 */
+   "SET FEATURE",  /* 3 */
+   "RESERVED", /* 4 */
+   "SET ADDRESS",  /* 5 */
+   "GET DESCRIPTOR",   /* 6 */
+   "SET DESCRIPTOR",   /* 7 */
+   "GET CONFIGURATION",/* 8 */
+   "SET CONFIGURATION",/* 9 */
+   "GET INTERFACE",/* 10 */
+   "SET INTERFACE",/* 11 */
+   "SYNC FRAME",   /* 12 */
+};
+
+#define USBD_DEVICE_REQUESTS(x) (((unsigned int)x <= USB_REQ_SYNCH_FRAME) ? 
usbd_device_requests[x] : "UNKNOWN")
+
 /* EP0 Configuration Set 
* */
 
 
diff --git a/include/usbdevice.h b/include/usbdevice.h
index f479724e37..611cd6e4ab 100644
--- a/include/usbdevice.h
+++ b/include/usbdevice.h
@@ -264,8 +264,6 @@ struct usb_bus_instance;
 #define USB_REQ_SET_INTERFACE  0x0B
 #define USB_REQ_SYNCH_FRAME0x0C
 
-#define USBD_DEVICE_REQUESTS(x) (((unsigned int)x <= USB_REQ_SYNCH_FRAME) ? 
usbd_device_requests[x] : "UNKNOWN")
-
 /*
  * HID requests
  */
@@ -332,9 +330,6 @@ struct usb_bus_instance;
 #define USB_DESCRIPTOR_TYPE_HID0x21
 #define USB_DESCRIPTOR_TYPE_REPORT 0x22
 
-#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int)x <= 
USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? \
-   usbd_device_descriptors[x] : "UNKNOWN")
-
 /*
  * standard feature selectors
  */
@@ -388,8 +383,6 @@ typedef enum usb_device_state {
STATE_UNKNOWN, 

[PATCH 06/13] usb: musb: Fix transmission of bigger buffers

2020-11-29 Thread Pali Rohár
If udc_endpoint_write() was called with bigger payload which does not fit
into one USB packet it needs to be transmitted in more USB packets. First
packet is transmitted by udc_endpoint_write() call itself and other packets
are put into waiting queue.

Implement function musb_peri_tx() which transmit checks when endpoints are
ready and continue transmitting of waiting queue.

This patch fixes sending e.g. output of printenv command over usbtty serial
console.

Signed-off-by: Pali Rohár 
---
 drivers/usb/musb/musb_udc.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
index 67d1c56f9a..28719cc3f6 100644
--- a/drivers/usb/musb/musb_udc.c
+++ b/drivers/usb/musb/musb_udc.c
@@ -708,21 +708,16 @@ static void musb_peri_rx(u16 intr)
 
 static void musb_peri_tx(u16 intr)
 {
+   unsigned int ep;
+
/* Check for EP0 */
if (0x01 & intr)
musb_peri_ep0_tx();
 
-   /*
-* Use this in the future when handling epN tx
-*
-* u8 ep;
-*
-* for (ep = 1; ep < 16; ep++) {
-*  if ((1 << ep) & intr) {
-*  / * handle tx for this endpoint * /
-*  }
-* }
-*/
+   for (ep = 1; ep < 16; ep++) {
+   if ((1 << ep) & intr)
+   udc_endpoint_write(GET_ENDPOINT(udc_device, ep));
+   }
 }
 
 void udc_irq(void)
-- 
2.20.1



[PATCH 05/13] usb: musb: Read value of PERI_RXCSR to 16bit variable

2020-11-29 Thread Pali Rohár
PERI_RXCSR is 16bit register so store its value into 16bit local variable.

Signed-off-by: Pali Rohár 
---
 drivers/usb/musb/musb_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
index d901f8777c..67d1c56f9a 100644
--- a/drivers/usb/musb/musb_udc.c
+++ b/drivers/usb/musb/musb_udc.c
@@ -629,7 +629,7 @@ static void musb_peri_ep0(void)
 static void musb_peri_rx_ep(unsigned int ep)
 {
u16 peri_rxcount;
-   u8 peri_rxcsr = readw(>ep[ep].epN.rxcsr);
+   u16 peri_rxcsr = readw(>ep[ep].epN.rxcsr);
 
if (!(peri_rxcsr & MUSB_RXCSR_RXPKTRDY)) {
if (debug_level > 0)
-- 
2.20.1



[PATCH 03/13] usb: musb: Always clear the data toggle bit when configuring ep

2020-11-29 Thread Pali Rohár
Without this patch it was done only when U-Boot was compiled with MUSB Host
Controller. But it is needed also for MUSB Device Controller, otherwise
Device Controller does not work.

Signed-off-by: Pali Rohár 
---
 drivers/usb/musb/musb_core.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 147b2eb929..cc6dc3839d 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -81,10 +81,8 @@ void musb_configure_ep(const struct musb_epinfo *epinfo, u8 
cnt)
config_fifo(tx, idx, fifoaddr);
 
csr = readw(>txcsr);
-#if defined(CONFIG_USB_MUSB_HCD)
/* clear the data toggle bit */
writew(csr | MUSB_TXCSR_CLRDATATOG, >txcsr);
-#endif
/* Flush fifo if required */
if (csr & MUSB_TXCSR_TXPKTRDY)
writew(csr | MUSB_TXCSR_FLUSHFIFO,
@@ -94,10 +92,8 @@ void musb_configure_ep(const struct musb_epinfo *epinfo, u8 
cnt)
config_fifo(rx, idx, fifoaddr);
 
csr = readw(>rxcsr);
-#if defined(CONFIG_USB_MUSB_HCD)
/* clear the data toggle bit */
writew(csr | MUSB_RXCSR_CLRDATATOG, >rxcsr);
-#endif
/* Flush fifo if required */
if (csr & MUSB_RXCSR_RXPKTRDY)
writew(csr | MUSB_RXCSR_FLUSHFIFO,
-- 
2.20.1



[PATCH 04/13] usb: musb: Fix configuring FIFO for endpoints

2020-11-29 Thread Pali Rohár
This patch fixes configuring FIFO for one-directional endpoints which have
either RX or TX queue and therefore only one FIFO.

Without this patch if FIFO size was zero then idx was incorrectly
calculated (expr. ffs(0)-1 is not zero) and size overflowed in fifosz
register. This register uses has only 4 bits for FIFO size.

This patch is fixing it by setting zero size and zero address when
particular endpoint does not use FIFO.

This issue caused loose of packets on USB bus in both directions and
basically usbtty was unusable.

Signed-off-by: Pali Rohár 
---
 drivers/usb/musb/musb_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index cc6dc3839d..75ccd4819d 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -49,8 +49,8 @@ void musb_start(void)
 #else
 # define config_fifo(dir, idx, addr) \
do { \
-   writeb(idx, >dir##fifosz); \
-   writew(fifoaddr >> 3, >dir##fifoadd); \
+   writeb((idx) & 0xF, >dir##fifosz); \
+   writew((idx) ? ((addr) >> 3) : 0, >dir##fifoadd); \
} while (0)
 #endif
 
@@ -73,7 +73,7 @@ void musb_configure_ep(const struct musb_epinfo *epinfo, u8 
cnt)
while (cnt--) {
/* prepare fifosize to write to register */
fifosize = epinfo->epsize >> 3;
-   idx = ffs(fifosize) - 1;
+   idx = fifosize ? (ffs(fifosize) - 1) : 0;
 
writeb(epinfo->epnum, >index);
if (epinfo->epdir) {
-- 
2.20.1



[PATCH 02/13] usb: musb: Fix compilation of gadget code

2020-11-29 Thread Pali Rohár
musb udc code depends on usb gadget code provided by CONFIG_USB_DEVICE and
defined in drivers/usb/gadget/Makefile. But this Makefile is not included
into U-Boot build when CONFIG_USB_GADGET is not set. As CONFIG_USB_DEVICE
cannot be enabled together with CONFIG_USB_GADGET it means that dependency
for musb udc code is not compiled during build. Fix it by including
drivers/usb/gadget dependency also when CONFIG_USB_DEVICE is set.

This patch fixes compile errors:

arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`musb_peri_ep0_rx':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `ep0_recv_setup'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`musb_peri_ep0_idle':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `ep0_recv_setup'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`musb_peri_ep0_zero_data_request':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to 
`usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`musb_peri_ep0_idle':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `ep0_recv_setup'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`musb_peri_ep0_rx':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `usbd_rcv_complete'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`musb_peri_rx_ep':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `usbd_rcv_complete'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`udc_endpoint_write':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `usbd_tx_complete'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function `udc_irq':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to 
`usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
reference to `usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
reference to `usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
reference to `usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
reference to `usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: 
drivers/usb/musb/built-in.o:u-boot/drivers/usb/musb/musb_udc.c: more undefined 
references to `usbd_device_event_irq' follow
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`udc_setup_ep':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to `usbd_alloc_urb'
arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function 
`udc_startup_events':
u-boot/drivers/usb/musb/musb_udc.c: undefined reference to 
`usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
reference to `usbd_device_event_irq'
arm-linux-gnueabi-ld.bfd: u-boot/drivers/usb/musb/musb_udc.c: undefined 
reference to `usbd_device_event_irq'
make: *** [Makefile:1762: u-boot] Error 1

Signed-off-by: Pali Rohár 
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile b/Makefile
index 17719666fb..8b146db22c 100644
--- a/Makefile
+++ b/Makefile
@@ -792,6 +792,7 @@ libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
 libs-y += drivers/usb/eth/
+libs-$(CONFIG_USB_DEVICE) += drivers/usb/gadget/
 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/
 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/
 libs-y += drivers/usb/host/
-- 
2.20.1



[PATCH 01/13] serial: usbtty: Fix puts function

2020-11-29 Thread Pali Rohár
This function has incorrect implementation of prepending CR prior LF.
Without this patch it prepended CR prior whole string which is going to be
written and let LF without leading CR. Fix this issue by inserting CR at
correct place to make output on usbtty serial console more readable.

Signed-off-by: Pali Rohár 
---
 drivers/serial/usbtty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
index f1c1a260da..02f8edf200 100644
--- a/drivers/serial/usbtty.c
+++ b/drivers/serial/usbtty.c
@@ -500,8 +500,8 @@ void usbtty_puts(struct stdio_dev *dev, const char *str)
n = next_nl_pos (str);
 
if (str[n] == '\n') {
-   __usbtty_puts("\r", 1);
-   __usbtty_puts(str, n + 1);
+   __usbtty_puts(str, n);
+   __usbtty_puts("\r\n", 2);
str += (n + 1);
len -= (n + 1);
} else {
-- 
2.20.1



[PATCH 00/13] Nokia RX-51: Fix USB TTY console and enable it

2020-11-29 Thread Pali Rohár
This patch series fix usbtty code (serial console via USB peripheral
mode), fix underlying musb peripheral code, fix compilation of
CONFIG_USB_DEVICE (used by usbtty), remove unused Nokia RX-51 code to
decrease size of U-Boot binary and finally enable usbtty serial console
for Nokia RX-51.

With this patch series debugging of Nokia RX-51 can be done also via USB
serial console.

On computer this serial console is accessible via /dev/ttyACM0 device.

With current implementation there is an issue in musb driver that it
loose receiving bytes from USB bus when too many a characters are send
over USB tty from computer. Typing on keyboard to kermit terminal
connected to /dev/ttyACM0 is working fine. But pasting more more bytes
to terminal cause data lost on receiving side. I do not know where is
the issue or how to fix it (it looks like that data are lost at low
level when reading them from msub FIFO hardware) but typing on keyboard
is working fine. This is rather issue for sending files via x/y/z-modem
or kermit protocol. Currently U-Boot is not able to receive any file
via usbtty with musb driver due to this issue.

Pali Rohár (13):
  serial: usbtty: Fix puts function
  usb: musb: Fix compilation of gadget code
  usb: musb: Always clear the data toggle bit when configuring ep
  usb: musb: Fix configuring FIFO for endpoints
  usb: musb: Read value of PERI_RXCSR to 16bit variable
  usb: musb: Fix transmission of bigger buffers
  usb: gadget: Do not export usbd_device_* arrays
  usb: gadget: Use dbg_ep0() macro instead of serial_printf()
  arm: omap3: Compile lowlevel_init() function only when it is used
  arm: omap3: Compile s_init() function only when it is used
  Nokia RX-51: Remove function set_muxconf_regs()
  Nokia RX-51: Move content of rx51.h to rx51.c
  Nokia RX-51: Enable usbtty serial console by default

 Makefile  |   1 +
 arch/arm/mach-omap2/omap3/board.c |   3 +
 arch/arm/mach-omap2/omap3/lowlevel_init.S |   6 +-
 board/nokia/rx51/rx51.c   |  28 +-
 board/nokia/rx51/rx51.h   | 377 --
 configs/nokia_rx51_defconfig  |   6 +-
 doc/README.nokia_rx51 |  15 +-
 drivers/serial/usbtty.c   |   4 +-
 drivers/usb/gadget/core.c |  38 +--
 drivers/usb/gadget/ep0.c  |  47 ++-
 drivers/usb/musb/musb_core.c  |  10 +-
 drivers/usb/musb/musb_udc.c   |  19 +-
 include/configs/nokia_rx51.h  |  16 +-
 include/usbdevice.h   |  15 -
 14 files changed, 92 insertions(+), 493 deletions(-)
 delete mode 100644 board/nokia/rx51/rx51.h

-- 
2.20.1



[PATCH] Nokia RX-51: Add test for U-Boot serial console

2020-11-29 Thread Pali Rohár
This patch adds a new test which checks that U-Boot for Nokia RX-51 running
in qemu can print test line to serial console and also checks that test
line appeared on qemu serial console.

Signed-off-by: Pali Rohár 
---
 test/nokia_rx51_test.sh | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/test/nokia_rx51_test.sh b/test/nokia_rx51_test.sh
index 23fa935310..ee45e8d6dd 100755
--- a/test/nokia_rx51_test.sh
+++ b/test/nokia_rx51_test.sh
@@ -150,6 +150,15 @@ fakeroot sh -c '
 '
 /usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
 
+# Generate bootmenu for U-Boot serial console testing
+cat > bootmenu_uboot << EOF
+setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; 
echo; echo "Successfully booted"; echo; poweroff';
+setenv bootmenu_1;
+setenv bootmenu_delay 1;
+setenv bootdelay 1;
+EOF
+./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_uboot -d 
bootmenu_uboot bootmenu_uboot.scr
+
 # Generate bootmenu for eMMC booting
 cat > bootmenu_emmc << EOF
 setenv bootmenu_0 'uImage-2.6.28-omap1 from eMMC=setenv mmcnum 1; setenv 
mmcpart 1; setenv mmctype fat; setenv bootargs; setenv setup_omap_atag 1; 
setenv mmckernfile uImage-2.6.28-omap1; run trymmckernboot';
@@ -177,6 +186,11 @@ dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco 
of=zImage-2.6.28-omap
 cp u-boot.bin combined_hack.bin
 dd if=uImage-2.6.28-omap1 of=combined_hack.bin bs=1024 seek=$((2048-2))
 
+# Generate FAT32 eMMC image for U-Boot serial console testing
+truncate -s 50MiB emmc_uboot.img
+mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i 
emmc_uboot.img
+mcopy bootmenu_uboot.scr ::/bootmenu.scr -i emmc_uboot.img
+
 # Generate FAT32 eMMC image for eMMC booting
 truncate -s 50MiB emmc_emmc.img
 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i 
emmc_emmc.img
@@ -188,6 +202,10 @@ truncate -s 50MiB emmc_nand.img
 mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i 
emmc_nand.img
 mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
 
+# Generate MTD image for U-Boot serial console testing
+rm -f mtd_uboot.img
+./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot.bin -m rx51 
-o mtd_uboot.img
+
 # Generate MTD image for RAM booting from bootloader nolo images, compiled 
image and rootfs image
 rm -f mtd_ram.img
 ./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined.bin -r 
ubi.img -m rx51 -o mtd_ram.img
@@ -208,6 +226,18 @@ echo "== Running test images in n900 qemu 
=="
 echo "=="
 echo
 
+# Run MTD image in qemu and wait for 300s if U-Boot prints testing string to 
serial console and poweroff
+rm -f qemu_uboot.log
+./qemu-system-arm -M n900 -mtdblock mtd_uboot.img -sd emmc_uboot.img -serial 
/dev/stdout -display none > qemu_uboot.log &
+qemu_pid=$!
+tail -F qemu_uboot.log &
+tail_pid=$!
+sleep 300 &
+sleep_pid=$!
+wait -n $sleep_pid $qemu_pid || true
+kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
+wait || true
+
 # Run MTD image in qemu and wait for 300s if kernel from RAM is correctly 
booted
 rm -f qemu_ram.log
 ./qemu-system-arm -M n900 -mtdblock mtd_ram.img -serial /dev/stdout -display 
none > qemu_ram.log &
@@ -250,13 +280,14 @@ echo "== Results =="
 echo "="
 echo
 
+if grep -q 'Successfully booted' qemu_uboot.log; then echo "U-Boot serial 
console is working"; else echo "U-Boot serial console test failed"; fi
 if grep -q 'Successfully booted' qemu_ram.log; then echo "Kernel was 
successfully booted from RAM"; else echo "Failed to boot kernel from RAM"; fi
 if grep -q 'Successfully booted' qemu_emmc.log; then echo "Kernel was 
successfully booted from eMMC"; else echo "Failed to boot kernel from eMMC"; fi
 if grep -q 'Successfully booted' qemu_nand.log; then echo "Kernel was 
successfully booted from OneNAND"; else echo "Failed to boot kernel from 
OneNAND"; fi
 
 echo
 
-if grep -q 'Successfully booted' qemu_ram.log && grep -q 'Successfully booted' 
qemu_emmc.log && grep -q 'Successfully booted' qemu_nand.log; then
+if grep -q 'Successfully booted' qemu_uboot.log && grep -q 'Successfully 
booted' qemu_ram.log && grep -q 'Successfully booted' qemu_emmc.log && grep -q 
'Successfully booted' qemu_nand.log; then
echo "All tests passed"
exit 0
 else
-- 
2.20.1



Re: [U-Boot] Please pull from u-boot-i2c

2020-11-29 Thread Tom Rini
On Sat, Nov 28, 2020 at 04:20:45PM +0100, Heiko Schocher wrote:

> Hello Tom,
> 
> The following changes since commit 7889951d0f56eab746a7c8fde350a022ba0361ca:
> 
>   Merge tag 'u-boot-stm32-20201125' of 
> https://gitlab.denx.de/u-boot/custodians/u-boot-stm
> (2020-11-25 11:00:52 -0500)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-i2c.git master
> 
> for you to fetch changes up to f517e5fe98598d933e050b4005af6d745820bdb1:
> 
>   riscv: sifive/fu540: kconfig: Enable support for Opencores I2C controller 
> (2020-11-28 08:30:41 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/3] efi_loader: Introduce eventlog support for TCG2_PROTOCOL

2020-11-29 Thread Ilias Apalodimas
On Sun, Nov 29, 2020 at 02:49:33PM +0100, Heinrich Schuchardt wrote:
> On 11/29/20 2:27 PM, Ilias Apalodimas wrote:
> > On Sun, Nov 29, 2020 at 07:02:39AM +0100, Heinrich Schuchardt wrote:
> >> On 11/27/20 5:29 PM, Ilias Apalodimas wrote:
> >>> In the previous patches we only introduced a minimal subset of the
> >>>
> > [...]
> >>> +#define TPM2_SHA1_DIGEST_SIZE 20
> >>> +#define TPM2_SHA256_DIGEST_SIZE 32
> >>> +#define TPM2_SHA384_DIGEST_SIZE 48
> >>> +#define TPM2_SHA512_DIGEST_SIZE 64
> >>
> >> lib/efi_loader/efi_tcg2.c already includes tpm-v2.h.
> >>
> >> Why should we define the same constant twice?
> >>
> >
> > We don't. That was probably a c/p I forgot to fix when I creted the
> > patches.
> > I'll only keep the declarations in tpm-v2.h.
> >
> >> Best regards
> >>
> >> Heinrich
> >>
> >>> +
> >>> +#define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
> >>> +
> >>> +#define TPM2_EVENT_LOG_SIZE 4096
> >>
> >> What does this size derive from? A comment describing the constant could
> >> help.
> >>
> >
> > There's no guidance for this. This is the size of the eventlog and it's up 
> > to us
> > to define something that makes sense. It obviously depends on:
> > - Number of supported algoriths
> > - Number of events
> > We could move it to a Kconfig?
> 
> That is probably the best choice.
> 
> >
> >>> +
> >>>   typedef u32 efi_tcg_event_log_bitmap;
> >>>   typedef u32 efi_tcg_event_log_format;
> >>>   typedef u32 efi_tcg_event_algorithm_bitmap;
> >>> @@ -65,6 +76,40 @@ struct efi_tcg2_boot_service_capability {
> >>>   sizeof(struct efi_tcg2_boot_service_capability) - \
> >>>   offsetof(struct efi_tcg2_boot_service_capability, 
> >>> number_of_pcr_banks)
> >>>
> >>> +#define tcg_efi_spec_id_event_signature_03 "Spec ID Event03"
> >>> +
> >>> +#define tcg_efi_spec_id_event_spec_version_major_tpm2 2
> >>> +#define tcg_efi_spec_id_event_spec_version_minor_tpm2 0
> >>> +#define tcg_efi_spec_id_event_spec_version_errata_tpm2 0
> >>
> >> Constants should be capitalized.
> >>
> >
> > Ok
> >
> >>> +
> >>
> >> Please, provide Sphinx style comments for structures. Cf.
> >> https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#structure-union-and-enumeration-documentation
> >>
> >
> > Ok
> >
> >>> +struct tcg_efi_spec_id_event_algorithm_size {
> >>> + u16  algorithm_id;
> >>> + u16  digest_size;
> >>> +} __packed;
> >>> +
> >>> +struct tcg_efi_spec_id_event {
> >>> + u8 signature[16];
> >>> + u32 platform_class;
> >>> + u8 spec_version_minor;
> >>> + u8 spec_version_major;
> >>> + u8 spec_errata;
> >>> + u8 uintn_size;
> >>> + u32 number_of_algorithms;
> >>> + struct tcg_efi_spec_id_event_algorithm_size 
> >>> digest_sizes[TPM2_NUM_PCR_BANKS];
> >>> + u8 vendor_info_size;
> >>> + /*
> >>> +  * filled in with vendor_info_size
> >>> +  * currently vendor_info_size = 0
> >>
> >> %s/vendor_info_size = 0/U-Boot does not provide any vendor info/
> >>
> >
> > Ok
> >
> > [...]
> >>> + /* Setup specID event data */
> >>> + spec_event = (struct tcg_efi_spec_id_event *)buffer;
> >>> + memcpy(spec_event->signature, tcg_efi_spec_id_event_signature_03,
> >>> +sizeof(spec_event->signature));
> >>> + put_unaligned_le32(0, _event->platform_class); /* type client */
> >>> + __put_unaligned_le(tcg_efi_spec_id_event_spec_version_minor_tpm2,
> >>> +_event->spec_version_minor);
> >>> + __put_unaligned_le(tcg_efi_spec_id_event_spec_version_major_tpm2,
> >>> +_event->spec_version_major);
> >>> + __put_unaligned_le(tcg_efi_spec_id_event_spec_version_errata_tpm2,
> >>> +_event->spec_errata);
> >>> + __put_unaligned_le(sizeof(efi_uintn_t) / sizeof(u32),
> >>> +_event->uintn_size);
> >
> > Any preference on this?
> > The put_unaligned here is not strictly needed since it's u8 values.
> > It just seemed 'easier' to read since all the other additions to the log
> > are done with put_unaligned16/32.
> 
> U-Boot does not support unaligned access on some platforms before
> allow_unaligned() is called. Furthermore endianness depends on the platform.
> 
> The current function is called after the initialization of the UEFI
> sub-system (actually during the TCG2 protocol invocation). At this point
> U-Boot supports unaligned access. And you know that your system is
> little-endian. So you should use normal assignments which is much more
> readable and reduces code size.
> 
> spec_event->platform_class = 0;

The native cpu endianess is irrelevant here. 
The eventlog data structures need to be LE if I understand the spec 
correctly [1].

Since this is not supposed to run on Arm only (or any platform that supports 
unaligned accesses) I'd prefer keeping the put_unaligned16/32 calls.
I can remove the access to u8 on v2.
Furthermore tcg2_agile_log_append() can be called outside UEFI, in case we want
to extend U-boot and measure events before initializing EFI. In that case 
we got no guarantee on alignment.

[1] 

Re: [PATCH 2/3] efi_loader: Introduce eventlog support for TCG2_PROTOCOL

2020-11-29 Thread Heinrich Schuchardt
On 11/29/20 2:27 PM, Ilias Apalodimas wrote:
> On Sun, Nov 29, 2020 at 07:02:39AM +0100, Heinrich Schuchardt wrote:
>> On 11/27/20 5:29 PM, Ilias Apalodimas wrote:
>>> In the previous patches we only introduced a minimal subset of the
>>>
> [...]
>>> +#define TPM2_SHA1_DIGEST_SIZE 20
>>> +#define TPM2_SHA256_DIGEST_SIZE 32
>>> +#define TPM2_SHA384_DIGEST_SIZE 48
>>> +#define TPM2_SHA512_DIGEST_SIZE 64
>>
>> lib/efi_loader/efi_tcg2.c already includes tpm-v2.h.
>>
>> Why should we define the same constant twice?
>>
>
> We don't. That was probably a c/p I forgot to fix when I creted the
> patches.
> I'll only keep the declarations in tpm-v2.h.
>
>> Best regards
>>
>> Heinrich
>>
>>> +
>>> +#define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
>>> +
>>> +#define TPM2_EVENT_LOG_SIZE 4096
>>
>> What does this size derive from? A comment describing the constant could
>> help.
>>
>
> There's no guidance for this. This is the size of the eventlog and it's up to 
> us
> to define something that makes sense. It obviously depends on:
> - Number of supported algoriths
> - Number of events
> We could move it to a Kconfig?

That is probably the best choice.

>
>>> +
>>>   typedef u32 efi_tcg_event_log_bitmap;
>>>   typedef u32 efi_tcg_event_log_format;
>>>   typedef u32 efi_tcg_event_algorithm_bitmap;
>>> @@ -65,6 +76,40 @@ struct efi_tcg2_boot_service_capability {
>>> sizeof(struct efi_tcg2_boot_service_capability) - \
>>> offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
>>>
>>> +#define tcg_efi_spec_id_event_signature_03 "Spec ID Event03"
>>> +
>>> +#define tcg_efi_spec_id_event_spec_version_major_tpm2 2
>>> +#define tcg_efi_spec_id_event_spec_version_minor_tpm2 0
>>> +#define tcg_efi_spec_id_event_spec_version_errata_tpm2 0
>>
>> Constants should be capitalized.
>>
>
> Ok
>
>>> +
>>
>> Please, provide Sphinx style comments for structures. Cf.
>> https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#structure-union-and-enumeration-documentation
>>
>
> Ok
>
>>> +struct tcg_efi_spec_id_event_algorithm_size {
>>> +   u16  algorithm_id;
>>> +   u16  digest_size;
>>> +} __packed;
>>> +
>>> +struct tcg_efi_spec_id_event {
>>> +   u8 signature[16];
>>> +   u32 platform_class;
>>> +   u8 spec_version_minor;
>>> +   u8 spec_version_major;
>>> +   u8 spec_errata;
>>> +   u8 uintn_size;
>>> +   u32 number_of_algorithms;
>>> +   struct tcg_efi_spec_id_event_algorithm_size 
>>> digest_sizes[TPM2_NUM_PCR_BANKS];
>>> +   u8 vendor_info_size;
>>> +   /*
>>> +* filled in with vendor_info_size
>>> +* currently vendor_info_size = 0
>>
>> %s/vendor_info_size = 0/U-Boot does not provide any vendor info/
>>
>
> Ok
>
> [...]
>>> +   /* Setup specID event data */
>>> +   spec_event = (struct tcg_efi_spec_id_event *)buffer;
>>> +   memcpy(spec_event->signature, tcg_efi_spec_id_event_signature_03,
>>> +  sizeof(spec_event->signature));
>>> +   put_unaligned_le32(0, _event->platform_class); /* type client */
>>> +   __put_unaligned_le(tcg_efi_spec_id_event_spec_version_minor_tpm2,
>>> +  _event->spec_version_minor);
>>> +   __put_unaligned_le(tcg_efi_spec_id_event_spec_version_major_tpm2,
>>> +  _event->spec_version_major);
>>> +   __put_unaligned_le(tcg_efi_spec_id_event_spec_version_errata_tpm2,
>>> +  _event->spec_errata);
>>> +   __put_unaligned_le(sizeof(efi_uintn_t) / sizeof(u32),
>>> +  _event->uintn_size);
>
> Any preference on this?
> The put_unaligned here is not strictly needed since it's u8 values.
> It just seemed 'easier' to read since all the other additions to the log
> are done with put_unaligned16/32.

U-Boot does not support unaligned access on some platforms before
allow_unaligned() is called. Furthermore endianness depends on the platform.

The current function is called after the initialization of the UEFI
sub-system (actually during the TCG2 protocol invocation). At this point
U-Boot supports unaligned access. And you know that your system is
little-endian. So you should use normal assignments which is much more
readable and reduces code size.

spec_event->platform_class = 0;
...
spec_event->uintn_size = efi_uintn_t) / sizeof(u32);

Best regards

Heinrich

>
> [...]
>
> cheerrs
> /Ilias
>



Re: [PATCH 2/3] efi_loader: Introduce eventlog support for TCG2_PROTOCOL

2020-11-29 Thread Ilias Apalodimas
On Sun, Nov 29, 2020 at 07:02:39AM +0100, Heinrich Schuchardt wrote:
> On 11/27/20 5:29 PM, Ilias Apalodimas wrote:
> > In the previous patches we only introduced a minimal subset of the
> > 
[...]
> > +#define TPM2_SHA1_DIGEST_SIZE 20
> > +#define TPM2_SHA256_DIGEST_SIZE 32
> > +#define TPM2_SHA384_DIGEST_SIZE 48
> > +#define TPM2_SHA512_DIGEST_SIZE 64
> 
> lib/efi_loader/efi_tcg2.c already includes tpm-v2.h.
> 
> Why should we define the same constant twice?
> 

We don't. That was probably a c/p I forgot to fix when I creted the 
patches. 
I'll only keep the declarations in tpm-v2.h.

> Best regards
> 
> Heinrich
> 
> > +
> > +#define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
> > +
> > +#define TPM2_EVENT_LOG_SIZE 4096
> 
> What does this size derive from? A comment describing the constant could
> help.
> 

There's no guidance for this. This is the size of the eventlog and it's up to us
to define something that makes sense. It obviously depends on:
- Number of supported algoriths
- Number of events
We could move it to a Kconfig?

> > +
> >   typedef u32 efi_tcg_event_log_bitmap;
> >   typedef u32 efi_tcg_event_log_format;
> >   typedef u32 efi_tcg_event_algorithm_bitmap;
> > @@ -65,6 +76,40 @@ struct efi_tcg2_boot_service_capability {
> > sizeof(struct efi_tcg2_boot_service_capability) - \
> > offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
> > 
> > +#define tcg_efi_spec_id_event_signature_03 "Spec ID Event03"
> > +
> > +#define tcg_efi_spec_id_event_spec_version_major_tpm2 2
> > +#define tcg_efi_spec_id_event_spec_version_minor_tpm2 0
> > +#define tcg_efi_spec_id_event_spec_version_errata_tpm2 0
> 
> Constants should be capitalized.
> 

Ok

> > +
> 
> Please, provide Sphinx style comments for structures. Cf.
> https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#structure-union-and-enumeration-documentation
> 

Ok

> > +struct tcg_efi_spec_id_event_algorithm_size {
> > +   u16  algorithm_id;
> > +   u16  digest_size;
> > +} __packed;
> > +
> > +struct tcg_efi_spec_id_event {
> > +   u8 signature[16];
> > +   u32 platform_class;
> > +   u8 spec_version_minor;
> > +   u8 spec_version_major;
> > +   u8 spec_errata;
> > +   u8 uintn_size;
> > +   u32 number_of_algorithms;
> > +   struct tcg_efi_spec_id_event_algorithm_size 
> > digest_sizes[TPM2_NUM_PCR_BANKS];
> > +   u8 vendor_info_size;
> > +   /*
> > +* filled in with vendor_info_size
> > +* currently vendor_info_size = 0
> 
> %s/vendor_info_size = 0/U-Boot does not provide any vendor info/
> 

Ok

[...]
> > +   /* Setup specID event data */
> > +   spec_event = (struct tcg_efi_spec_id_event *)buffer;
> > +   memcpy(spec_event->signature, tcg_efi_spec_id_event_signature_03,
> > +  sizeof(spec_event->signature));
> > +   put_unaligned_le32(0, _event->platform_class); /* type client */
> > +   __put_unaligned_le(tcg_efi_spec_id_event_spec_version_minor_tpm2,
> > +  _event->spec_version_minor);
> > +   __put_unaligned_le(tcg_efi_spec_id_event_spec_version_major_tpm2,
> > +  _event->spec_version_major);
> > +   __put_unaligned_le(tcg_efi_spec_id_event_spec_version_errata_tpm2,
> > +  _event->spec_errata);
> > +   __put_unaligned_le(sizeof(efi_uintn_t) / sizeof(u32),
> > +  _event->uintn_size);

Any preference on this?
The put_unaligned here is not strictly needed since it's u8 values. 
It just seemed 'easier' to read since all the other additions to the log
are done with put_unaligned16/32.

[...]

cheerrs
/Ilias


Re: [PATCH 4/8] M: dts: r8a77950-u-boot: Remove leading 0x from rpc node

2020-11-29 Thread Lad, Prabhakar
Hi Marek,

Thank you for the review.

On Sun, Nov 29, 2020 at 1:06 PM Marek Vasut  wrote:
>
> On 11/18/20 12:32 PM, Prabhakar Mahadev Lad wrote:
>
> [...]
>
> >> Subject: [PATCH 4/8] M: dts: r8a77950-u-boot: Remove leading 0x from rpc 
> >> node
> >>
> > I missed the typo in the subject s/M/ARM shall I just resend this patch if 
> > that's OK with you.
>
> If you could squash all the RPC fixes into a single patch and send that
> as one patch -- since they are all fixing the exact same problem -- that
> would help.
>
Done posted a v2.

Cheers,
Prabhakar


Re: [PATCH 1/3] tpm: Add tpm2 headers for TCG2 eventlog support

2020-11-29 Thread Ilias Apalodimas
Hi Heinrich,

On Sun, Nov 29, 2020 at 06:28:39AM +0100, Heinrich Schuchardt wrote:
> On 11/27/20 5:29 PM, Ilias Apalodimas wrote:
> > A following patch introduces support for the EFI_TCG2_PROTOCOL
> > evenlog management.
> 
> %s/evenlog/eventlog/
> 
> > Introduce the necessary tpm related headers
> > 
> > Signed-off-by: Ilias Apalodimas 
> > ---
> >   include/tpm-v2.h | 59 
> >   1 file changed, 59 insertions(+)
> > 
> > diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> > index d8c9feda28dc..9637f9be998e 100644
> > --- a/include/tpm-v2.h
> > +++ b/include/tpm-v2.h
> > @@ -18,6 +18,12 @@
> > 
> >   #define TPM2_DIGEST_LEN   32
> 
> Shouldn't TPM2_DIGEST_LEN be renamed to TPM2_SHA256_DIGEST_SIZE in all
> of our code?

Ideally yes. The current tpm2 pre-existing code (apart from tpm2_pcr_extend()
which I changed) uses a hardware SHA256 algorithm.
Should we do it in this patchset though?

> 
> > 
> > +#define TPM2_SHA1_DIGEST_SIZE 20
> > +#define TPM2_SHA256_DIGEST_SIZE32
> > +#define TPM2_SHA384_DIGEST_SIZE48
> > +#define TPM2_SHA512_DIGEST_SIZE64
> > +#define TPM2_SM3_256_DIGEST_SIZE 32
> > +
> >   #define TPM2_MAX_PCRS 32
> >   #define TPM2_PCR_SELECT_MAX ((TPM2_MAX_PCRS + 7) / 8)
> >   #define TPM2_MAX_CAP_BUFFER 1024
> > @@ -45,6 +51,15 @@
> >   #define TPM2_PT_MAX_COMMAND_SIZE  (u32)(TPM2_PT_FIXED + 30)
> >   #define TPM2_PT_MAX_RESPONSE_SIZE (u32)(TPM2_PT_FIXED + 31)
> > 
> > +/* event types */
> > +#define EV_POST_CODE   ((u32)0x0001)
> > +#define EV_NO_ACTION   ((u32)0x0003)
> > +#define EV_SEPARATOR   ((u32)0x0004)
> > +#define EV_S_CRTM_CONTENTS ((u32)0x0007)
> > +#define EV_S_CRTM_VERSION  ((u32)0x0008)
> > +#define EV_CPU_MICROCODE   ((u32)0x0009)
> > +#define EV_TABLE_OF_DEVICES((u32)0x000B)
> > +
> >   /* TPMS_TAGGED_PROPERTY Structure */
> >   struct tpms_tagged_property {
> > u32 property;
> > @@ -86,6 +101,50 @@ struct tpms_capability_data {
> > union tpmu_capabilities data;
> >   } __packed;
> > 
> > +/* defined as TPM_SHA1_160_HASH_LEN in spec */
> > +struct tpm_digest {
> > +   u8 digest[TPM2_SHA1_DIGEST_SIZE];
> > +} __packed;
> > +
> > +/* SHA1 Event Log Entry Format */
> 
> Please, use Sphinx style comments for structures. This allows us to add
> them to the HTML documentation. See
> 
> https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#structure-union-and-enumeration-documentation
> 
> I would appreciate member descriptions, too.
> 

Ok I assumed refering to the spec would be fine.
I'll add description on v2

> > +struct tcg_pcr_event {
> > +   u32 pcr_index;
> > +   u32 event_type;
> > +   struct tpm_digest digest;
> 
> struct tpm_digest is only used here in your patch series.
> 
> The standard has
> 
> typedef UINT8 TCG_DIGEST[TPM2_SHA1_DIGEST_SIZE];
> 
> Can't we simply write
> 
>   u8 digest[20];
> 
> here and get rid of struct tpm_digest?

Yea we can. since it's a complex spec though I am trying to adhere
to it as much as possible to make review and future extentions easier.
I'd prefer keeping this as is tbh.

> 
> Otherwise looks ok to me.
> 

Thanks for the review!. I'll wait a few more days, fix your remarks and post a 
v2

Cheers
/Ilias
> Best regards
> 
> Heinrich
> 
> > +   u32 event_size;
> > +   u8 event[];
> > +} __packed;
> > +
> > +/* Definition of TPMU_HA Union */
> > +union tmpu_ha {
> > +   u8 sha1[TPM2_SHA1_DIGEST_SIZE];
> > +   u8 sha256[TPM2_SHA256_DIGEST_SIZE];
> > +   u8 sm3_256[TPM2_SM3_256_DIGEST_SIZE];
> > +   u8 sha384[TPM2_SHA384_DIGEST_SIZE];
> > +   u8 sha512[TPM2_SHA512_DIGEST_SIZE];
> > +} __packed;
> > +
> > +/* Definition of TPMT_HA Structure */
> > +struct tpmt_ha {
> > +   u16 hash_alg;
> > +   union tmpu_ha digest;
> > +} __packed;
> > +
> > +/* Definition of TPML_DIGEST_VALUES Structure */
> > +struct tpml_digest_values {
> > +   u32 count;
> > +   struct tpmt_ha digests[TPM2_NUM_PCR_BANKS];
> > +} __packed;
> > +
> > +/* Crypto Agile Log Entry Format */
> > +struct tcg_pcr_event2 {
> > +   u32 pcr_index;
> > +   u32 event_type;
> > +   struct tpml_digest_values digests;
> > +   u32 event_size;
> > +   u8 event[];
> > +} __packed;
> > +
> >   /**
> >* TPM2 Structure Tags for command/response buffers.
> >*
> > 
> 


[PATCH v2] ARM: dts: renesas: Remove leading 0x from rpc node

2020-11-29 Thread Lad Prabhakar
Remove the leading "0x" from rpc node to fix the below dtc warning:

Warning (simple_bus_reg): Node /soc/rpc@0xee20 simple-bus unit
address format error, expected "ee20"

Signed-off-by: Lad Prabhakar 
---
Squashed the changes into single patch.
---
 arch/arm/dts/r7s72100-gr-peach-u-boot.dts | 2 +-
 arch/arm/dts/r8a77950-u-boot.dtsi | 2 +-
 arch/arm/dts/r8a77960-u-boot.dtsi | 2 +-
 arch/arm/dts/r8a77965-u-boot.dtsi | 2 +-
 arch/arm/dts/r8a77970-u-boot.dtsi | 2 +-
 arch/arm/dts/r8a77980-u-boot.dtsi | 2 +-
 arch/arm/dts/r8a77990-u-boot.dtsi | 2 +-
 arch/arm/dts/r8a77995-u-boot.dtsi | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm/dts/r7s72100-gr-peach-u-boot.dts 
b/arch/arm/dts/r7s72100-gr-peach-u-boot.dts
index 30e35e47d6..f48121a9a8 100644
--- a/arch/arm/dts/r7s72100-gr-peach-u-boot.dts
+++ b/arch/arm/dts/r7s72100-gr-peach-u-boot.dts
@@ -46,7 +46,7 @@
};
 
 
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r7s72100", "renesas,rpc";
reg = <0x3fefa000 0x100>, <0x1800 0x0800>;
bank-width = <2>;
diff --git a/arch/arm/dts/r8a77950-u-boot.dtsi 
b/arch/arm/dts/r8a77950-u-boot.dtsi
index 0317f47f0f..5a11651464 100644
--- a/arch/arm/dts/r8a77950-u-boot.dtsi
+++ b/arch/arm/dts/r8a77950-u-boot.dtsi
@@ -13,7 +13,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a7795", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
diff --git a/arch/arm/dts/r8a77960-u-boot.dtsi 
b/arch/arm/dts/r8a77960-u-boot.dtsi
index 826c2384bc..f1cae1c359 100644
--- a/arch/arm/dts/r8a77960-u-boot.dtsi
+++ b/arch/arm/dts/r8a77960-u-boot.dtsi
@@ -13,7 +13,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a7796", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
diff --git a/arch/arm/dts/r8a77965-u-boot.dtsi 
b/arch/arm/dts/r8a77965-u-boot.dtsi
index 33ff5b148b..9cc6f20537 100644
--- a/arch/arm/dts/r8a77965-u-boot.dtsi
+++ b/arch/arm/dts/r8a77965-u-boot.dtsi
@@ -13,7 +13,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a77965", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
diff --git a/arch/arm/dts/r8a77970-u-boot.dtsi 
b/arch/arm/dts/r8a77970-u-boot.dtsi
index eabab7ce58..ac3c6be4ad 100644
--- a/arch/arm/dts/r8a77970-u-boot.dtsi
+++ b/arch/arm/dts/r8a77970-u-boot.dtsi
@@ -13,7 +13,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a77970", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
diff --git a/arch/arm/dts/r8a77980-u-boot.dtsi 
b/arch/arm/dts/r8a77980-u-boot.dtsi
index 1050f6e991..365d40ac49 100644
--- a/arch/arm/dts/r8a77980-u-boot.dtsi
+++ b/arch/arm/dts/r8a77980-u-boot.dtsi
@@ -13,7 +13,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a77980", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
diff --git a/arch/arm/dts/r8a77990-u-boot.dtsi 
b/arch/arm/dts/r8a77990-u-boot.dtsi
index ddf8b62627..6655abe875 100644
--- a/arch/arm/dts/r8a77990-u-boot.dtsi
+++ b/arch/arm/dts/r8a77990-u-boot.dtsi
@@ -9,7 +9,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a77990", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
diff --git a/arch/arm/dts/r8a77995-u-boot.dtsi 
b/arch/arm/dts/r8a77995-u-boot.dtsi
index 8e9f6b7a7d..0917a80f09 100644
--- a/arch/arm/dts/r8a77995-u-boot.dtsi
+++ b/arch/arm/dts/r8a77995-u-boot.dtsi
@@ -9,7 +9,7 @@
 
 / {
soc {
-   rpc: rpc@0xee20 {
+   rpc: rpc@ee20 {
compatible = "renesas,rpc-r8a77995", "renesas,rpc";
reg = <0 0xee20 0 0x100>, <0 0x0800 0 0>;
clocks = < CPG_MOD 917>;
-- 
2.17.1



Re: [PATCH 4/8] M: dts: r8a77950-u-boot: Remove leading 0x from rpc node

2020-11-29 Thread Marek Vasut

On 11/18/20 12:32 PM, Prabhakar Mahadev Lad wrote:

[...]


Subject: [PATCH 4/8] M: dts: r8a77950-u-boot: Remove leading 0x from rpc node


I missed the typo in the subject s/M/ARM shall I just resend this patch if 
that's OK with you.


If you could squash all the RPC fixes into a single patch and send that 
as one patch -- since they are all fixing the exact same problem -- that 
would help.


Thanks


Re: [PATCH v7 1/4] arm: rmobile: Add RZ/G2[HMNE] SoC support

2020-11-29 Thread Marek Vasut

On 11/27/20 3:52 PM, Biju Das wrote:

Sorry for the late reply.

[...]


diff --git a/arch/arm/mach-rmobile/cpu_info-rcar.c 
b/arch/arm/mach-rmobile/cpu_info-rcar.c
index 5bde24ae0e..08345503a2 100644
--- a/arch/arm/mach-rmobile/cpu_info-rcar.c
+++ b/arch/arm/mach-rmobile/cpu_info-rcar.c
@@ -6,6 +6,7 @@
   */
  #include 
  #include 
+#include 
  
  #define PRR_MASK		0x7fff

  #define R8A7796_REV_1_0   0x5200
@@ -21,9 +22,28 @@ static u32 rmobile_get_prr(void)
  #endif
  }
  
+static bool is_rzg_family(void)

+{
+   bool rzg_family_type = false;
+   struct udevice *soc;
+   char name[16];
+
+   if (!(soc_get() || soc_get_family(soc, name, 16))) {


This depends on some other patchset, right ?
I will wait for that to land and then apply this one.

Did you check that this is still OK on RCar Gen2 with its size-limited SPL?

Also, do you have a git tree with all the remaining patches applied on 
top? It would be useful to get an overview what's still pending for 
mainline.


Thanks


+   if (!strcmp(name, "RZ/G2"))
+   rzg_family_type = true;
+   }


[...]


Re: [PATCH v4 2/2] pinctrl: renesas: Implement get_pin_muxing() callback

2020-11-29 Thread Marek Vasut

On 11/28/20 2:13 PM, Lad Prabhakar wrote:

Implement get_pin_muxing() callback so that pinmux status
command can be used on Renesas platforms.


Applied, thanks


Re: [PATCH v4 1/2] pinctrl: renesas: Make sure the pin type is updated after setting the MUX

2020-11-29 Thread Marek Vasut

On 11/28/20 2:13 PM, Lad Prabhakar wrote:

By default on startup all the pin types are configured to
PINMUX_TYPE_NONE (in sh_pfc_map_pins()), when pin is set as GPIO the
pin type is updated to PINMUX_TYPE_GPIO. But the type is not updated
when the pin is set as a function in sh_pfc_pinctrl_pin_set() or
sh_pfc_pinctrl_group_set() calls (these calls only set the MUX if
the pin type is PINMUX_TYPE_NONE ie unused).

So with the current implementation pin functionality could be overwritten
silently, for example if the same pin is added for SPI and serial.

This patch makes sure of updating pin type after every successful call to
sh_pfc_config_mux() and thus fixing from pin functionality to be
overwritten. Also a warning message is printed if the current pin is being
overwritten before abort.

This also avoids pin re-muxing to same type that is for example from
command line device is asked to re-probe/select (mmc dev x) we return
early with success in this case as the pin is already muxed.


Applied, thanks


Please pull mmc-2020-11-29

2020-11-29 Thread Peng Fan
Hi Tom

Please pull mmc-2020-11-29

-
mmc minor update for better debug and error check
fsl_esdhc sysctl set and make sure delay check for HS400
-
CI: https://travis-ci.org/github/MrVan/u-boot/builds/746367562

Thanks,
Peng.

The following changes since commit 7889951d0f56eab746a7c8fde350a022ba0361ca:

  Merge tag 'u-boot-stm32-20201125' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-stm (2020-11-25 11:00:52 -0500)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-mmc.git tags/mmc-2020-11-29

for you to fetch changes up to b3dc016caade00e07d5ae45042c9be42f611d625:

  mmc: check a return value about regulator's always-on (2020-11-28 10:44:39 
+0800)


Jaehoon Chung (2):
  mmc: display an error number to debug
  mmc: check a return value about regulator's always-on

Sean Anderson (1):
  mmc: Add some helper functions for retrying on error

Yangbo Lu (2):
  mmc: fsl_esdhc: set sysctl register for clock initialization
  mmc: fsl_esdhc: make sure delay chain locked for HS400

 drivers/mmc/fsl_esdhc.c |  30 +
 drivers/mmc/mmc.c   | 155 
++-
 include/fsl_esdhc.h |   4 
 3 files changed, 95 insertions(+), 94 deletions(-)


[PATCH v2] gpio: Add support for DM GPIO for Kirkwood

2020-11-29 Thread Harm Berntsen
The Armada driver also works on Nedap's custom Kirkwood board with a
Marvell 88F6180 CPU. The original commit of that driver,
commit 704d9a645e17 ("gpio: Add DM GPIO driver for Marvell MVEBU"),
also mentions that this driver would be suitable for Kirkwood. This
does not completely replace the Kirkwood specific driver as there
are still boards depending on that driver.

Signed-off-by: Harm Berntsen 
CC: Stefan Roese ,
---
Canges for v2:
- Made commit message more clear

 drivers/gpio/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 202fcc6f47..1f41bd3d55 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -374,7 +374,7 @@ config SIFIVE_GPIO
 
 config MVEBU_GPIO
bool "Marvell MVEBU GPIO driver"
-   depends on DM_GPIO && ARCH_MVEBU
+   depends on DM_GPIO && (ARCH_MVEBU || ARCH_KIRKWOOD)
default y
help
  Say yes here to support Marvell MVEBU (Armada XP/38x) GPIOs.
-- 
2.29.2



Re: [PATCH] gpio: Add support for DM GPIO for Kirkwood

2020-11-29 Thread Harm Berntsen
Hi Stefan,

Thanks for your review.

I've looked into the usage of the kw_gpio driver. The soft_i2c part I
mentioned in the commit appeared to be specific to my board
configuration. I've replaced the usage of that driver with the DM based
i2c-gpio driver there.

All the usage of the kw_gpio functions is in board-specific code. I
think the kw_gpio driver can be deprecated and board maintainers could
update their code.

Kind regards,
Harm

-Original Message-
From: Stefan Roese 
To: Harm Berntsen , u-boot@lists.denx.de

Subject: Re: [PATCH] gpio: Add support for DM GPIO for Kirkwood
Date: Sat, 28 Nov 2020 11:08:43 +0100

Hi Harm,

On 27.11.20 22:56, Harm Berntsen wrote:
> The Armada driver also works on Nedap's ax8008 Kirkwood board with a
> Marvell 88F6180 CPU. The original commit of that driver,
> 704d9a645e1790e568abf43c5eff2de0d7b135ed also mentions that this
> driver
> would be suitable for Kirkwood.

Well, this was really a long time ago. ;)

> This driver does not completely replace the Kirkwood specific driver
> as
> there are still dependencies on that driver(i.e. soft_i2c.c. in our
> case).

So what work needs to be doney to completely replace the old legacy
kw_gpio driver and remove it completely? Could you perhaps tackle it
as well?

Other than that:

Reviewed-by: Stefan Roese 

Thanks,
Stefan

> Signed-off-by: Harm Berntsen 
> CC: Stefan Roese 
> ---
> 
>   drivers/gpio/Kconfig | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 202fcc6f47..1f41bd3d55 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -374,7 +374,7 @@ config SIFIVE_GPIO
>   
>   config MVEBU_GPIO
> bool "Marvell MVEBU GPIO driver"
> -   depends on DM_GPIO && ARCH_MVEBU
> +   depends on DM_GPIO && (ARCH_MVEBU || ARCH_KIRKWOOD)
> default y
> help
>   Say yes here to support Marvell MVEBU (Armada XP/38x)
> GPIOs.
> 


Viele Grüße,
Stefan




i2c: i2c-gpio: Fix GPIO output

2020-11-29 Thread Harm Berntsen
The dm_gpio_set_dir_flags function cannot be used to update the
configuration of a GPIO pin because it does a bitwise OR with the
existing flags. Looks like commit 788ea834124b ("gpio: add function
_dm_gpio_set_dir_flags") has introduced this behaviour and the i2c-gpio
driver has been broken since.

Signed-off-by: Harm Berntsen 
CC: Heiko Schocher 
CC: Patrick Delaunay 
---

 drivers/i2c/i2c-gpio.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
index 381938c956..9c5e0d4d68 100644
--- a/drivers/i2c/i2c-gpio.c
+++ b/drivers/i2c/i2c-gpio.c
@@ -50,9 +50,10 @@ static void i2c_gpio_sda_set(struct i2c_gpio_bus *bus, int 
bit)
struct gpio_desc *sda = >gpios[PIN_SDA];
 
if (bit)
-   dm_gpio_set_dir_flags(sda, GPIOD_IS_IN);
+   sda->flags = (sda->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
else
-   dm_gpio_set_dir_flags(sda, GPIOD_IS_OUT);
+   sda->flags = (sda->flags & (~GPIOD_IS_IN & 
~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
+   dm_gpio_set_dir(sda);
 }
 
 static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
@@ -61,14 +62,16 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int 
bit)
int count = 0;
 
if (bit) {
-   dm_gpio_set_dir_flags(scl, GPIOD_IS_IN);
+   scl->flags = (scl->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
+   dm_gpio_set_dir(scl);
while (!dm_gpio_get_value(scl) && count++ < 10)
udelay(1);
 
if (!dm_gpio_get_value(scl))
pr_err("timeout waiting on slave to release scl\n");
} else {
-   dm_gpio_set_dir_flags(scl, GPIOD_IS_OUT);
+   scl->flags = (scl->flags & (~GPIOD_IS_IN & 
~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
+   dm_gpio_set_dir(scl);
}
 }
 
@@ -76,11 +79,11 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int 
bit)
 static void i2c_gpio_scl_set_output_only(struct i2c_gpio_bus *bus, int bit)
 {
struct gpio_desc *scl = >gpios[PIN_SCL];
-   ulong flags = GPIOD_IS_OUT;
+   scl->flags = (scl->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | 
GPIOD_IS_OUT;
 
if (bit)
-   flags |= GPIOD_IS_OUT_ACTIVE;
-   dm_gpio_set_dir_flags(scl, flags);
+   scl->flags |= GPIOD_IS_OUT_ACTIVE;
+   dm_gpio_set_dir(scl);
 }
 
 static void i2c_gpio_write_bit(struct i2c_gpio_bus *bus, int delay, uchar bit)
-- 
2.29.2



Pull request for UEFI sub-system for efi-2021-01-rc3 (3)

2020-11-29 Thread Heinrich Schuchardt

Dear Tom,

The following changes since commit 7889951d0f56eab746a7c8fde350a022ba0361ca:

  Merge tag 'u-boot-stm32-20201125' of
https://gitlab.denx.de/u-boot/custodians/u-boot-stm (2020-11-25 11:00:52
-0500)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-efi.git
tags/efi-2021-01-rc3-3

for you to fetch changes up to 6974a4a37348ba272e53dd33effcc0db9e144c59:

  charset: make u16_strnlen accessible at runtime (2020-11-29 05:18:37
+0100)


Pull request for UEFI sub-system for efi-2021-01-rc3 (3)

The following errors are corrected:

* Linux crash when accessing UEFI variables at runtime.
* UEFI variable using standalone MM on 32 bit systems
  not working due to missing packing of communication
  structure
* NULL dereference when FAT16 root directory is full
* FAT files with a short file name starting with 0xE5 (0x05 in directory
  entry) where treated as deleted.

The UEFI SetTime() service is enabled on ARM QEMU and sandbox.

Gitlab CI showed not problem:
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/5443


Etienne Carriere (1):
  lib/efi_loader: fix ABI in efi_mm_communicate_header

Heinrich Schuchardt (4):
  fs: fat: avoid NULL dereference when root dir is full
  fs: fat: directory entries starting with 0x05
  fs: fat: use ATTR_ARCH instead of anonymous 0x20
  efi_loader: enable EFI_SET_TIME on sandbox and QEMU ARM

Ilias Apalodimas (1):
  charset: make u16_strnlen accessible at runtime

 fs/fat/fat.c   | 3 +--
 fs/fat/fat_write.c | 8 
 include/mm_communication.h | 2 +-
 lib/charset.c  | 3 ++-
 lib/efi_loader/Kconfig | 1 +
 5 files changed, 9 insertions(+), 8 deletions(-)


Re: [PATCH] Add fdtfile for Marvell Armada 37xx default environment

2020-11-29 Thread Matwey V. Kornilov
чт, 26 нояб. 2020 г. в 12:40, Andre Heider :

> On 26/11/2020 10:04, Matwey V. Kornilov wrote:
> >
> >
> > чт, 26 нояб. 2020 г. в 06:45, Andre Heider  > >:
> >
> > On 25/11/2020 10:14, Matwey V. Kornilov wrote:
> >  > Signed-off-by: Matwey V. Kornilov  > >
> >  > ---
> >  >   configs/mvebu_db-88f3720_defconfig  | 1 +
> >  >   configs/mvebu_espressobin-88f3720_defconfig | 1 +
> >  >   include/configs/mvebu_armada-37xx.h | 1 +
> >  >   3 files changed, 3 insertions(+)
> >  >
> >  > diff --git a/configs/mvebu_db-88f3720_defconfig
> > b/configs/mvebu_db-88f3720_defconfig
> >  > index a6bbe1a7af..1a3a267890 100644
> >  > --- a/configs/mvebu_db-88f3720_defconfig
> >  > +++ b/configs/mvebu_db-88f3720_defconfig
> >  > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
> >  >   CONFIG_DEBUG_UART_BASE=0xd0012000
> >  >   CONFIG_DEBUG_UART_CLOCK=25804800
> >  >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-db"
> >  > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-db.dtb"
> >  >   CONFIG_DEBUG_UART=y
> >  >   CONFIG_AHCI=y
> >  >   CONFIG_DISTRO_DEFAULTS=y
> >  > diff --git a/configs/mvebu_espressobin-88f3720_defconfig
> > b/configs/mvebu_espressobin-88f3720_defconfig
> >  > index 8a859cba2e..56ec482794 100644
> >  > --- a/configs/mvebu_espressobin-88f3720_defconfig
> >  > +++ b/configs/mvebu_espressobin-88f3720_defconfig
> >  > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
> >  >   CONFIG_DEBUG_UART_BASE=0xd0012000
> >  >   CONFIG_DEBUG_UART_CLOCK=25804800
> >  >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin"
> >  > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-espressobin.dtb"
> >
> > No, that doesn't work for this board, see
> > 68e32e344 "arm: mvebu: Espressobin: Set environment variable fdtfile"
> >
> >
> > Good point.
> > But why does this autodetection not work for me?
>
> I guess that can only happen if:
> - the commit isn't part of you tree
> - you disabled CONFIG_BOARD_LATE_INIT or didn't refresh from the defconfig
> - you already have the envvar set/saved
>
>
Hi,

I've double checked, and you are right.
It seems that I did "env default" and fdtfile disappeared until the next
reset.

What do you think? If the patch still needed for 3720-DB?


> >
> >  >   CONFIG_DEBUG_UART=y
> >  >   CONFIG_AHCI=y
> >  >   CONFIG_DISTRO_DEFAULTS=y
> >  > diff --git a/include/configs/mvebu_armada-37xx.h
> > b/include/configs/mvebu_armada-37xx.h
> >  > index 0d585606a7..377ac60def 100644
> >  > --- a/include/configs/mvebu_armada-37xx.h
> >  > +++ b/include/configs/mvebu_armada-37xx.h
> >  > @@ -96,6 +96,7 @@
> >  >   "kernel_addr=0x700\0"   \
> >  >   "kernel_addr_r=0x700\0" \
> >  >   "ramdisk_addr_r=0xa00\0"\
> >  > + "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
> >  >   BOOTENV
> >  >
> >  >   #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */
> >  >
> >
> >
> >
> > --
> > With best regards,
> > Matwey V. Kornilov
>
>

-- 
With best regards,
Matwey V. Kornilov