Re: [PATCH v3 5/5] bootstd: Add test for bootmeth_android

2024-07-11 Thread Guillaume LA ROQUE
open(fname, 'wb') as outf:
+outf.write(disk_data)
+
+print('wrote to {}'.format(fname))
+
+return fname
  
  def setup_cedit_file(cons):

  infname = os.path.join(cons.config.source_dir,
@@ -478,6 +556,7 @@ def test_ut_dm_init_bootstd(u_boot_console):
  setup_bootmenu_image(u_boot_console)
  setup_cedit_file(u_boot_console)
  setup_cros_image(u_boot_console)
+setup_android_image(u_boot_console)
  
  # Restart so that the new mmc1.img is picked up

  u_boot_console.restart_uboot()


Reviewed-by: Guillaume La Roque 




Re: [PATCH v2 0/5] bootstd: Add Android support

2024-06-14 Thread Guillaume LA ROQUE

Hi,

i apply  patch series with commit you give in cover letter and test on 
TI AM62S-SK board.

Android boot properly , just with a small changes in uboot eenv

setenv vendor_boot_comp_addr_r 0xd000

this changes is need link to patch done by roman on ramdisk and vendor 
boot loading.


so you can add for this series:

Tested-by: Guillaume La Roque 


Guillaume

Le 13/06/2024 à 12:13, Mattijs Korpershoek a écrit :

Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
a. Get slot (A/B) from BCB
b. Run AVB (Android Verified Boot) on boot partitions
c. Load boot and vendor_boot partitions
d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.

For this initial version, only boot image v4 is supported.

This has been tested on sandbox using:
$ ./test/py/test.py --bd sandbox --build -k test_ut

This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
To test on TI board, the following (WIP) patch is needed as well:
https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
[6] 
https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html

Signed-off-by: Mattijs Korpershoek 
---
Changes in v2:
- Dropped patch 2/6 boot: android: Add image_android_get_version() (Igor)
- Fixed multi-line comment style (Igor, Simon)
- Added dependency on CMD_FASTBOOT for BOOTMETH_ANDROID (Igor)
- Fixed various resource leaks (Igor)
- Fixed bootmeth_priv dangling pointer on error cases (Igor)
- Updated test instructions in commit message for patch 6/6
- Added __weak impl of get_avendor_bootimg_addr() in patch 1 (dropped
   Igor's review because of this change)
- Added extra info in Kconfig to detail MMC limitation (Simon)
- Fixed typo Bootmethod->Bootmeth (Simon)
- Documented android_priv structure (Simon)
- Demoted various messages from printf() to log_debug (Simon)
- Fixed some lines too long (Simon)
- Added function documentation to read_slotted_partition() (Simon)
- Added some doc about avb extra_args being modified (Simon)
- Link to v1: 
https://lore.kernel.org/r/20240606-bootmeth-android-v1-0-0c69d4457...@baylibre.com

---
Mattijs Korpershoek (5):
   boot: android: Provide vendor_bootimg_addr in boot_get_fdt()
   bootstd: Add bootflow_iter_check_mmc() helper
   android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()
   bootstd: Add a bootmeth for Android
   bootstd: Add test for bootmeth_android

  MAINTAINERS   |   7 +
  arch/sandbox/dts/test.dts |   8 +
  boot/Kconfig  |  16 ++
  boot/Makefile |   2 +
  boot/bootflow.c   |  12 +
  boot/bootmeth_android.c   | 553 ++
  boot/bootmeth_android.h   |  29 +++
  boot/image-android.c  |   5 +
  boot/image-fdt.c  |   2 +-
  cmd/abootimg.c|  10 +
  configs/sandbox_defconfig |   2 +-
  doc/develop/bootstd.rst   |   6 +
  include/bootflow.h|   9 +
  include/image.h   |  14 ++
  test/boot/bootflow.c  |  65 +-
  test/py/tests/test_ut.py  |  76 +++
  16 files changed, 811 insertions(+), 5 deletions(-)
---
base-commit: f9886bc60f42d5bcfcfa4e474af7dc230400b6be
change-id: 20240605-bootmeth-android-bfc8596e9367

Best regards,





Re: [PATCH v2 5/5] bootstd: Add test for bootmeth_android

2024-06-13 Thread Guillaume LA ROQUE
est state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
+ * Returns 0 on success, -ve on failure
+ */
+static int scan_mmc_android_bootdev(struct unit_test_state *uts, const char 
*mmc_dev)
+{
+   struct bootstd_priv *std;
+   struct udevice *bootstd;
+   const char **old_order;
+
+   ut_assertok(prep_mmc_bootdev(uts, mmc_dev, true, _order));
+
+   console_record_reset_enable();
+   ut_assertok(run_command("bootflow scan", 0));
+   /* Android bootflow might print one or two 'ANDROID:*' logs */
+   ut_check_skipline(uts);
+   ut_check_skipline(uts);
+   ut_assert_console_end();
+
+   /* Restore the order used by the device tree */
+   ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
+   std = dev_get_priv(bootstd);
+   std->bootdev_order = old_order;
+
+   return 0;
+}
+
  /**
   * scan_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake 
Armbian
   *
@@ -1160,3 +1199,23 @@ static int bootflow_cros(struct unit_test_state *uts)
return 0;
  }
  BOOTSTD_TEST(bootflow_cros, 0);
+
+/* Test Android bootmeth  */
+static int bootflow_android(struct unit_test_state *uts)
+{
+   ut_assertok(scan_mmc_android_bootdev(uts, "mmc7"));
+   ut_assertok(run_command("bootflow list", 0));
+
+   ut_assert_nextlinen("Showing all");
+   ut_assert_nextlinen("Seq");
+   ut_assert_nextlinen("---");
+   ut_assert_nextlinen("  0  extlinux");
+   ut_assert_nextlinen("  1  android  ready   mmc  0  
mmc7.bootdev.whole");
+   ut_assert_nextlinen("---");
+   ut_assert_skip_to_line("(2 bootflows, 2 valid)");
+
+   ut_assert_console_end();
+
+   return 0;
+}
+BOOTSTD_TEST(bootflow_android, 0);
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index c169c835e38a..39e1abe02a68 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -423,6 +423,81 @@ def setup_cros_image(cons):
  
  return fname
  
+def setup_android_image(cons):

+"""Create a 20MB disk image with Android partitions"""
+Partition = collections.namedtuple('part', 'start,size,name')
+parts = {}
+disk_data = None
+
+def set_part_data(partnum, data):
+"""Set the contents of a disk partition
+
+This updates disk_data by putting data in the right place
+
+Args:
+partnum (int): Partition number to set
+data (bytes): Data for that partition
+"""
+nonlocal disk_data
+
+start = parts[partnum].start * sect_size
+disk_data = disk_data[:start] + data + disk_data[start + len(data):]
+
+mmc_dev = 7
+fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
+u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
+u_boot_utils.run_and_log(cons, f'cgpt create {fname}')
+
+ptr = 40
+
+# Number of sectors in 1MB
+sect_size = 512
+sect_1mb = (1 << 20) // sect_size
+
+required_parts = [
+{'num': 1, 'label':'misc', 'size': '1M'},
+{'num': 2, 'label':'boot_a', 'size': '4M'},
+{'num': 3, 'label':'boot_b', 'size': '4M'},
+{'num': 4, 'label':'vendor_boot_a', 'size': '4M'},
+{'num': 5, 'label':'vendor_boot_b', 'size': '4M'},
+]
+
+for part in required_parts:
+size_str = part['size']
+if 'M' in size_str:
+size = int(size_str[:-1]) * sect_1mb
+else:
+size = int(size_str)
+u_boot_utils.run_and_log(
+cons,
+f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t 
basicdata {fname}")
+ptr += size
+
+u_boot_utils.run_and_log(cons, f'cgpt boot -p {fname}')
+out = u_boot_utils.run_and_log(cons, f'cgpt show -q {fname}')
+
+# Create a dict (indexed by partition number) containing the above info
+for line in out.splitlines():
+start, size, num, name = line.split(maxsplit=3)
+parts[int(num)] = Partition(int(start), int(size), name)
+
+with open(fname, 'rb') as inf:
+disk_data = inf.read()
+
+boot_img = os.path.join(cons.config.result_dir, 'bootv4.img')
+with open(boot_img, 'rb') as inf:
+set_part_data(2, inf.read())
+
+vendor_boot_img = os.path.join(cons.config.result_dir, 'vendor_boot.img')
+with open(vendor_boot_img, 'rb') as inf:
+set_part_data(4, inf.read())
+
+with open(fname, 'wb') as outf:
+outf.write(disk_data)
+
+print('wrote to {}'.format(fname))
+
+return fname
  
  def setup_cedit_file(cons):

  infname = os.path.join(cons.config.source_dir,
@@ -477,6 +552,7 @@ def test_ut_dm_init_bootstd(u_boot_console):
  setup_bootmenu_image(u_boot_console)
  setup_cedit_file(u_boot_console)
  setup_cros_image(u_boot_console)
+setup_android_image(u_boot_console)
  
  # Restart so that the new mmc1.img is picked up

  u_boot_console.restart_uboot()


Reviewed-by: Guillaume La Roque 




Re: [PATCH v2 1/5] boot: android: Provide vendor_bootimg_addr in boot_get_fdt()

2024-06-13 Thread Guillaume LA ROQUE

Hi,

Le 13/06/2024 à 12:13, Mattijs Korpershoek a écrit :

When calling android_image_get_dtb_by_index() using boot image v3+,
we should also pass the vendor_boot ramdisk address.

Use get_avendor_bootimg_addr() to do so.

Notes: on boot image v2, this is harmless since get_avendor_bootimg_addr()
returns -1.
for legacy implementations that don't have CMD_ABOOTIMG, add a weak
implementation to avoid linking errors.

Signed-off-by: Mattijs Korpershoek 
---
  boot/image-android.c | 5 +
  boot/image-fdt.c | 2 +-
  2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index ee626972c114..09c7a44e058a 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -56,6 +56,11 @@ static ulong add_trailer(ulong bootconfig_start_addr, ulong 
bootconfig_size)
return BOOTCONFIG_TRAILER_SIZE;
  }
  
+__weak ulong get_avendor_bootimg_addr(void)

+{
+   return -1;
+}
+
  static void android_boot_image_v3_v4_parse_hdr(const struct 
andr_boot_img_hdr_v3 *hdr,
   struct andr_image_data *data)
  {
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index 56dd7687f51c..8332792b8e80 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -502,7 +502,7 @@ int boot_get_fdt(void *buf, const char *select, uint arch,
 * Firstly check if this android boot image has dtb field.
 */
dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
-   if (android_image_get_dtb_by_index((ulong)hdr, 0,
+   if (android_image_get_dtb_by_index((ulong)hdr, 
get_avendor_bootimg_addr(),
   dtb_idx, _addr, 
_size)) {
fdt_blob = (char *)map_sysmem(fdt_addr, 0);
if (fdt_check_header(fdt_blob))


Reviewed-by: Guillaume La Roque 



Re: [PATCH v2 3/5] android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()

2024-06-13 Thread Guillaume LA ROQUE

Le 13/06/2024 à 12:13, Mattijs Korpershoek a écrit :

The only way to configure the load addresses for both bootimg and
vendor_bootimg is by using the "abootimg" command.
If we want to use the C API, there is no equivalent.

Add set_abootimg_addr() and set_avendor_bootimg_addr() so that we can
specify the load address from C.

This can be useful for implementing an Android bootmethod.

Reviewed-by: Igor Opaniuk 
Signed-off-by: Mattijs Korpershoek 
---
  cmd/abootimg.c  | 10 ++
  include/image.h | 14 ++
  2 files changed, 24 insertions(+)

diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 327712a536c0..ae7a1a7c83b0 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -22,6 +22,11 @@ ulong get_abootimg_addr(void)
return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
  }
  
+void set_abootimg_addr(ulong addr)

+{
+   _abootimg_addr = addr;
+}
+
  ulong get_ainit_bootimg_addr(void)
  {
return _ainit_bootimg_addr;
@@ -32,6 +37,11 @@ ulong get_avendor_bootimg_addr(void)
return _avendor_bootimg_addr;
  }
  
+void set_avendor_bootimg_addr(ulong addr)

+{
+   _avendor_bootimg_addr = addr;
+}
+
  static int abootimg_get_ver(int argc, char *const argv[])
  {
const struct andr_boot_img_hdr_v0 *hdr;
diff --git a/include/image.h b/include/image.h
index c5b288f62b44..df2decbf5c2a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1970,6 +1970,13 @@ bool is_android_vendor_boot_image_header(const void 
*vendor_boot_img);
   */
  ulong get_abootimg_addr(void);
  
+/**

+ * set_abootimg_addr() - Set Android boot image address
+ *
+ * Return: no returned results
+ */
+void set_abootimg_addr(ulong addr);
+
  /**
   * get_ainit_bootimg_addr() - Get Android init boot image address
   *
@@ -1984,6 +1991,13 @@ ulong get_ainit_bootimg_addr(void);
   */
  ulong get_avendor_bootimg_addr(void);
  
+/**

+ * set_abootimg_addr() - Set Android vendor boot image address
+ *
+ * Return: no returned results
+ */
+void set_avendor_bootimg_addr(ulong addr);
+
  /**
   * board_fit_config_name_match() - Check for a matching board name
   *


Reviewed-by: Guillaume La Roque 



Re: [PATCH v2 2/5] bootstd: Add bootflow_iter_check_mmc() helper

2024-06-13 Thread Guillaume LA ROQUE

Le 13/06/2024 à 12:13, Mattijs Korpershoek a écrit :

Some bootflows might be able to only boot from MMC devices.

Add a helper function these bootflows can use.

Reviewed-by: Igor Opaniuk 
Signed-off-by: Mattijs Korpershoek 
---
  boot/bootflow.c| 12 
  include/bootflow.h |  9 +
  2 files changed, 21 insertions(+)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 9aa3179c3881..59d77d2385f4 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -575,6 +575,18 @@ int bootflow_iter_check_blk(const struct bootflow_iter 
*iter)
return -ENOTSUPP;
  }
  
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter)

+{
+   const struct udevice *media = dev_get_parent(iter->dev);
+   enum uclass_id id = device_get_uclass_id(media);
+
+   log_debug("uclass %d: %s\n", id, uclass_get_name(id));
+   if (id == UCLASS_MMC)
+   return 0;
+
+   return -ENOTSUPP;
+}
+
  int bootflow_iter_check_sf(const struct bootflow_iter *iter)
  {
const struct udevice *media = dev_get_parent(iter->dev);
diff --git a/include/bootflow.h b/include/bootflow.h
index 080ee8501225..6058ddd89b16 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -407,6 +407,15 @@ void bootflow_remove(struct bootflow *bflow);
   */
  int bootflow_iter_check_blk(const struct bootflow_iter *iter);
  
+/**

+ * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
+ *
+ * This checks the bootdev in the bootflow to make sure it uses a mmc device
+ *
+ * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
+ */
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
+
  /**
   * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
   *


Reviewed-by: Guillaume La Roque 



Re: [PATCH v2 1/2] bootstd: Fix a handful of doc typos in bootmeth

2024-06-05 Thread Guillaume LA ROQUE

Hi,


Le 04/06/2024 à 17:15, Mattijs Korpershoek a écrit :

Fix some trivial typos found by browsing the code.
Done with flyspell.

Reviewed-by: Quentin Schulz 
Signed-off-by: Mattijs Korpershoek 
---
  include/bootmeth.h | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/bootmeth.h b/include/bootmeth.h
index 0fc36104ece0..529c4d813d82 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -40,7 +40,7 @@ struct bootmeth_ops {
/**
 * get_state_desc() - get detailed state information
 *
-* Prodecues a textual description of the state of the bootmeth. This
+* Produces a textual description of the state of the bootmeth. This
 * can include newline characters if it extends to multiple lines. It
 * must be a nul-terminated string.
 *
@@ -138,7 +138,7 @@ struct bootmeth_ops {
 * @dev:Bootmethod device to boot
 * @bflow:  Bootflow to boot
 * Return: does not return on success, since it should boot the
-*  Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
+*  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
 *  trying method resulted in finding out that is not actually
 *  supported for this boot and should not be tried again unless
 *  something changes, other -ve on other error
@@ -151,7 +151,7 @@ struct bootmeth_ops {
  /**
   * bootmeth_get_state_desc() - get detailed state information
   *
- * Prodecues a textual description of the state of the bootmeth. This
+ * Produces a textual description of the state of the bootmeth. This
   * can include newline characters if it extends to multiple lines. It
   * must be a nul-terminated string.
   *
@@ -244,7 +244,7 @@ int bootmeth_read_file(struct udevice *dev, struct bootflow 
*bflow,
   * @dev:  Bootmethod device to use
   * @bflow:Bootflow to read
   * Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
   *other error
   */
  int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
@@ -255,7 +255,7 @@ int bootmeth_read_all(struct udevice *dev, struct bootflow 
*bflow);
   * @dev:  Bootmethod device to boot
   * @bflow:Bootflow to boot
   * Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
   *other error
   */
  int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
@@ -264,7 +264,7 @@ int bootmeth_boot(struct udevice *dev, struct bootflow 
*bflow);
   * bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
   *
   * This sets up the ordering information in @iter, based on the selected
- * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
+ * ordering of the bootmeths in bootstd_priv->bootmeth_order. If there is no
   * ordering there, then all bootmethods are added
   *
   * @iter: Iterator to update with the order


Reviewed-by: Guillaume La Roque

Guillaume



Re: [PATCH] cmd: bcb: Fix bcb compilation when CONFIG_CMD_BCB=n

2024-06-05 Thread Guillaume LA ROQUE

hi,

Le 03/06/2024 à 11:04, Mattijs Korpershoek a écrit :

commit dfeb4f0d7935 ("cmd: bcb: extend BCB C API to allow read/write the 
fields")
introduced the bcb_get() function.

When CONFIG_CMD_BCB=n, that function is stubbed.
The stubbed function has a wrong prototype: value_size arg is missing.

Add the missing argument to fix build when CONFIG_CMD_BCB=n.

Fixes: dfeb4f0d7935 ("cmd: bcb: extend BCB C API to allow read/write the 
fields")
Signed-off-by: Mattijs Korpershoek 
---
  include/bcb.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/bcb.h b/include/bcb.h
index 1941d8c28b4f..a56b547595a6 100644
--- a/include/bcb.h
+++ b/include/bcb.h
@@ -58,7 +58,8 @@ static inline int bcb_set(enum bcb_field field, const char 
*value)
return -EOPNOTSUPP;
  }
  
-static inline int bcb_get(enum bcb_field field, char *value_out)

+static inline int bcb_get(enum bcb_field field,
+ char *value_out, size_t value_size)
  {
return -EOPNOTSUPP;
  }

---
base-commit: ea722aa5eb33740ae77e8816aeb72b385e621cd0
change-id: 20240603-bcb-compil-d8eaf7074475

Best regards,


Reviewed-by: Guillaume La Roque

Regards
Guillaume



[PATCH] phy: meson-g12a-usb2: fix ret check on power_domain_get

2023-10-17 Thread Guillaume La Roque
Patch which add A1 SoC support create a regression on khadas vim3/vim3l
boards when we try to use fastboot command:

  => fastboot usb 0
  failed to get power domain
  failed to get power domain
  No USB device found
  USB init failed: -19

Add ENOENT check on ret in probe function.

Fixes: 5533c883ce10 ("phy: support Amlogic A1 family")

Signed-off-by: Guillaume La Roque 
---
 drivers/phy/meson-g12a-usb2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/meson-g12a-usb2.c b/drivers/phy/meson-g12a-usb2.c
index 4ba3992bda70..3958d2404b85 100644
--- a/drivers/phy/meson-g12a-usb2.c
+++ b/drivers/phy/meson-g12a-usb2.c
@@ -328,12 +328,12 @@ int meson_g12a_usb2_phy_probe(struct udevice *dev)
 
 #if CONFIG_IS_ENABLED(POWER_DOMAIN)
ret = power_domain_get(dev, >pwrdm);
-   if (ret < 0 && ret != -ENODEV) {
-   pr_err("failed to get power domain\n");
+   if (ret < 0 && ret != -ENODEV && ret != -ENOENT) {
+   pr_err("failed to get power domain : %d\n", ret);
return ret;
}
 
-   if (ret != -ENODEV) {
+   if (ret != -ENODEV && ret != -ENOENT) {
ret = power_domain_on(>pwrdm);
if (ret < 0) {
pr_err("failed to enable power domain\n");
-- 
2.34.1



Re: [PATCH] drivers: usb: dwc3: Add support for AM62 USB wrapper driver

2022-06-20 Thread Guillaume LA ROQUE

Hi,

Le 07/04/2022 à 09:28, Aswath Govindraju a écrit :

Add support for AM62 USB wrapper for DWC3 Controller in AM62 SoC.

Signed-off-by: Aswath Govindraju 
---

Link to corresponding kernel dt-bindings and driver patches,
- https://patchwork.kernel.org/project/linux-usb/list/?series=629613

  drivers/usb/dwc3/Kconfig |   7 +
  drivers/usb/dwc3/Makefile|   1 +
  drivers/usb/dwc3/dwc3-am62.c | 284 +++
  3 files changed, 292 insertions(+)
  create mode 100644 drivers/usb/dwc3/dwc3-am62.c

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 62aa65bf0cd2..87e19720ab84 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -63,6 +63,13 @@ config USB_DWC3_LAYERSCAPE
  Host and Peripheral operation modes are supported. OTG is not
  supported.
  
+config USB_DWC3_AM62

+   tristate "Texas Instruments AM62 Platforms"
+   depends on ARCH_K3 || COMPILE_TEST
+   default USB_DWC3



some depend or select are missing , driver need to have SYSCON, MISC and 
DWC3_GENERIC  to compile.



Regards
Guillaume


+   help
+ Support of USB2 functionality in TI's AM62 platforms
+
  menu "PHY Subsystem"
  
  config USB_DWC3_PHY_OMAP

diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 0dd1ba87cd94..26bc3a7379b7 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -7,6 +7,7 @@ dwc3-y  := core.o
  obj-$(CONFIG_USB_DWC3_GADGET) += gadget.o ep0.o
  
  obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o

+obj-$(CONFIG_USB_DWC3_AM62)+= dwc3-am62.o
  obj-$(CONFIG_USB_DWC3_MESON_G12A) += dwc3-meson-g12a.o
  obj-$(CONFIG_USB_DWC3_MESON_GXL)  += dwc3-meson-gxl.o
  obj-$(CONFIG_USB_DWC3_GENERIC)+= dwc3-generic.o
diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c
new file mode 100644
index ..a3ad609036e2
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-am62.c
@@ -0,0 +1,284 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * dwc3-am62.c - TI specific Glue layer for AM62 DWC3 USB Controller
+ *
+ * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* USB WRAPPER register offsets */
+#define USBSS_PID  0x0
+#define USBSS_OVERCURRENT_CTRL 0x4
+#define USBSS_PHY_CONFIG   0x8
+#define USBSS_PHY_TEST 0xc
+#define USBSS_CORE_STAT0x14
+#define USBSS_HOST_VBUS_CTRL   0x18
+#define USBSS_MODE_CONTROL 0x1c
+#define USBSS_WAKEUP_CONFIG0x30
+#define USBSS_WAKEUP_STAT  0x34
+#define USBSS_OVERRIDE_CONFIG  0x38
+#define USBSS_IRQ_MISC_STATUS_RAW  0x430
+#define USBSS_IRQ_MISC_STATUS  0x434
+#define USBSS_IRQ_MISC_ENABLE_SET  0x438
+#define USBSS_IRQ_MISC_ENABLE_CLR  0x43c
+#define USBSS_IRQ_MISC_EOI 0x440
+#define USBSS_INTR_TEST0x490
+#define USBSS_VBUS_FILTER  0x614
+#define USBSS_VBUS_STAT0x618
+#define USBSS_DEBUG_CFG0x708
+#define USBSS_DEBUG_DATA   0x70c
+#define USBSS_HOST_HUB_CTRL0x714
+
+/* PHY CONFIG register bits */
+#define USBSS_PHY_VBUS_SEL_MASKGENMASK(2, 1)
+#define USBSS_PHY_VBUS_SEL_SHIFT   1
+#define USBSS_PHY_LANE_REVERSE BIT(0)
+
+/* MODE CONTROL register bits */
+#define USBSS_MODE_VALID   BIT(0)
+
+/* IRQ_MISC_STATUS_RAW register bits */
+#define USBSS_IRQ_MISC_RAW_VBUSVALID   BIT(22)
+#define USBSS_IRQ_MISC_RAW_SESSVALID   BIT(20)
+
+/* IRQ_MISC_STATUS register bits */
+#define USBSS_IRQ_MISC_VBUSVALID   BIT(22)
+#define USBSS_IRQ_MISC_SESSVALID   BIT(20)
+
+/* IRQ_MISC_ENABLE_SET register bits */
+#define USBSS_IRQ_MISC_ENABLE_SET_VBUSVALIDBIT(22)
+#define USBSS_IRQ_MISC_ENABLE_SET_SESSVALIDBIT(20)
+
+/* IRQ_MISC_ENABLE_CLR register bits */
+#define USBSS_IRQ_MISC_ENABLE_CLR_VBUSVALIDBIT(22)
+#define USBSS_IRQ_MISC_ENABLE_CLR_SESSVALIDBIT(20)
+
+/* VBUS_STAT register bits */
+#define USBSS_VBUS_STAT_SESSVALID  BIT(2)
+#define USBSS_VBUS_STAT_VBUSVALID  BIT(0)
+
+/* Mask for PHY PLL REFCLK */
+#define PHY_PLL_REFCLK_MASKGENMASK(3, 0)
+
+struct dwc3_data {
+   struct udevice *dev;
+   void __iomem *usbss;
+   struct regmap *syscon;
+   unsigned int offset;
+   unsigned int vbus_divider;
+};
+
+static inline u32 dwc3_ti_readl(struct dwc3_data *data, u32 offset)
+{
+   return readl(data->usbss + offset);
+}
+
+static inline void dwc3_ti_writel(struct dwc3_data *data, u32 offset, u32 
value)
+{
+   writel(value, data->usbss + offset);
+}
+
+static const int dwc3_ti_rate_table[] = {  /* in KHZ */
+   9600,
+   1,

[PATCH v2] arm: mediatek: merge board Kconfigs into mach-mediatek

2021-09-10 Thread Guillaume La Roque
On MediaTek boards we cannot override the SYS_BOARD / SYS_CONFIG_NAME
variables from defconfig.
This is because in board/mediatek/mt/Kconfig this value was override
by default due to the if CONFIG_TARGET_MT condition.

Merge all the Kconfigs to the mach-medatek/Kconfig.

This way:
- we only define SYS_{SOC,VENDOR} once
- all board definitions are in a single place, simplifying the build logic.

Signed-off-by: Guillaume La Roque 
---
 arch/arm/mach-mediatek/Kconfig   | 42 +++-
 arch/mips/mach-mtmips/Kconfig|  3 ++
 arch/mips/mach-mtmips/mt7620/Kconfig |  8 +-
 arch/mips/mach-mtmips/mt7628/Kconfig |  9 +-
 board/mediatek/mt7620/Kconfig| 12 
 board/mediatek/mt7622/Kconfig| 17 ---
 board/mediatek/mt7623/Kconfig| 13 -
 board/mediatek/mt7628/Kconfig| 12 
 board/mediatek/mt7629/Kconfig| 17 ---
 board/mediatek/mt8183/Kconfig| 13 -
 board/mediatek/mt8512/Kconfig| 14 --
 board/mediatek/mt8516/Kconfig| 13 -
 board/mediatek/mt8518/Kconfig| 14 --
 13 files changed, 53 insertions(+), 134 deletions(-)
 delete mode 100644 board/mediatek/mt7620/Kconfig
 delete mode 100644 board/mediatek/mt7622/Kconfig
 delete mode 100644 board/mediatek/mt7623/Kconfig
 delete mode 100644 board/mediatek/mt7628/Kconfig
 delete mode 100644 board/mediatek/mt7629/Kconfig
 delete mode 100644 board/mediatek/mt8183/Kconfig
 delete mode 100644 board/mediatek/mt8512/Kconfig
 delete mode 100644 board/mediatek/mt8516/Kconfig
 delete mode 100644 board/mediatek/mt8518/Kconfig

diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig
index e067604d9b..43979838e0 100644
--- a/arch/arm/mach-mediatek/Kconfig
+++ b/arch/arm/mach-mediatek/Kconfig
@@ -80,12 +80,40 @@ config TARGET_MT8518
 
 endchoice
 
-source "board/mediatek/mt7622/Kconfig"
-source "board/mediatek/mt7623/Kconfig"
-source "board/mediatek/mt7629/Kconfig"
-source "board/mediatek/mt8183/Kconfig"
-source "board/mediatek/mt8512/Kconfig"
-source "board/mediatek/mt8516/Kconfig"
-source "board/mediatek/mt8518/Kconfig"
+config SYS_BOARD
+   string "Board name"
+   default "mt7622" if TARGET_MT7622
+   default "mt7623" if TARGET_MT7623
+   default "mt7629" if TARGET_MT7629
+   default "mt8183" if TARGET_MT8183
+   default "mt8512" if TARGET_MT8512
+   default "mt8516" if TARGET_MT8516
+   default "mt8518" if TARGET_MT8518
+   default ""
+   help
+ This option contains information about board name.
+ Based on this option board// will
+ be used.
+
+config SYS_CONFIG_NAME
+   string "Board configuration name"
+   default "mt7622" if TARGET_MT7622
+   default "mt7623" if TARGET_MT7623
+   default "mt7629" if TARGET_MT7629
+   default "mt8183" if TARGET_MT8183
+   default "mt8512" if TARGET_MT8512
+   default "mt8516" if TARGET_MT8516
+   default "mt8518" if TARGET_MT8518
+   default ""
+   help
+ This option contains information about board configuration name.
+ Based on this option include/configs/.h header
+ will be used for board configuration.
+
+config MTK_BROM_HEADER_INFO
+   string
+   default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629 
|| TARGET_MT7622
+   default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183
+   default "lk=1" if TARGET_MT7623
 
 endif
diff --git a/arch/mips/mach-mtmips/Kconfig b/arch/mips/mach-mtmips/Kconfig
index 8756cadb0b..05347ff78c 100644
--- a/arch/mips/mach-mtmips/Kconfig
+++ b/arch/mips/mach-mtmips/Kconfig
@@ -1,6 +1,9 @@
 menu "MediaTek MIPS platforms"
depends on ARCH_MTMIPS
 
+config SYS_VENDOR
+   default "mediatek" if BOARD_MT7628_RFB || BOARD_MT7620_RFB || 
BOARD_MT7620_MT7530_RFB
+
 config SYS_MALLOC_F_LEN
default 0x1000
 
diff --git a/arch/mips/mach-mtmips/mt7620/Kconfig 
b/arch/mips/mach-mtmips/mt7620/Kconfig
index 5db83eb9d9..3ca711ad0f 100644
--- a/arch/mips/mach-mtmips/mt7620/Kconfig
+++ b/arch/mips/mach-mtmips/mt7620/Kconfig
@@ -66,6 +66,12 @@ config CPU_FREQ_MULTI
default 6 if CPU_FREQ_600MHZ
default 7 if CPU_FREQ_620MHZ
 
-source "board/mediatek/mt7620/Kconfig"
+config SYS_CONFIG_NAME
+   string "Board configuration name"
+   default "mt7620" if  BOARD_MT7620_RFB || BOARD_MT7620_MT7530_RFB
+
+config SYS_BOARD
+   string "Board name"
+   default "mt7620" if  BOARD_MT7620_RFB || BOARD_MT7620_MT7530_RFB
 
 endif
diff --git a/arch/mips/mach-mtmips/mt7628/Kconfig 
b/arch/

[PATCH] arm: mediatek: merge board Kconfigs into mach-mediatek

2021-07-19 Thread Guillaume La Roque
On MediaTek boards we cannot override the SYS_BOARD / SYS_CONFIG_NAME
variables from defconfig.
This is because in board/mediatek/mt/Kconfig this value was override
by default due to the if CONFIG_TARGET_MT condition.

Merge all the Kconfigs to the mach-medatek/Kconfig.

This way:
- we only define SYS_{SOC,VENDOR} once
- all board definitions are in a single place, simplifying the build logic.

Signed-off-by: Guillaume La Roque 
---
 arch/arm/mach-mediatek/Kconfig   | 42 +++-
 arch/mips/mach-mtmips/Kconfig|  3 ++
 arch/mips/mach-mtmips/mt7620/Kconfig |  8 +-
 arch/mips/mach-mtmips/mt7628/Kconfig | 11 +++-
 board/mediatek/mt7620/Kconfig| 12 
 board/mediatek/mt7622/Kconfig| 17 ---
 board/mediatek/mt7623/Kconfig| 13 -
 board/mediatek/mt7628/Kconfig| 12 
 board/mediatek/mt7629/Kconfig| 17 ---
 board/mediatek/mt8183/Kconfig| 13 -
 board/mediatek/mt8512/Kconfig| 14 --
 board/mediatek/mt8516/Kconfig| 13 -
 board/mediatek/mt8518/Kconfig| 14 --
 13 files changed, 55 insertions(+), 134 deletions(-)
 delete mode 100644 board/mediatek/mt7620/Kconfig
 delete mode 100644 board/mediatek/mt7622/Kconfig
 delete mode 100644 board/mediatek/mt7623/Kconfig
 delete mode 100644 board/mediatek/mt7628/Kconfig
 delete mode 100644 board/mediatek/mt7629/Kconfig
 delete mode 100644 board/mediatek/mt8183/Kconfig
 delete mode 100644 board/mediatek/mt8512/Kconfig
 delete mode 100644 board/mediatek/mt8516/Kconfig
 delete mode 100644 board/mediatek/mt8518/Kconfig

diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig
index e067604d9b..43979838e0 100644
--- a/arch/arm/mach-mediatek/Kconfig
+++ b/arch/arm/mach-mediatek/Kconfig
@@ -80,12 +80,40 @@ config TARGET_MT8518
 
 endchoice
 
-source "board/mediatek/mt7622/Kconfig"
-source "board/mediatek/mt7623/Kconfig"
-source "board/mediatek/mt7629/Kconfig"
-source "board/mediatek/mt8183/Kconfig"
-source "board/mediatek/mt8512/Kconfig"
-source "board/mediatek/mt8516/Kconfig"
-source "board/mediatek/mt8518/Kconfig"
+config SYS_BOARD
+   string "Board name"
+   default "mt7622" if TARGET_MT7622
+   default "mt7623" if TARGET_MT7623
+   default "mt7629" if TARGET_MT7629
+   default "mt8183" if TARGET_MT8183
+   default "mt8512" if TARGET_MT8512
+   default "mt8516" if TARGET_MT8516
+   default "mt8518" if TARGET_MT8518
+   default ""
+   help
+ This option contains information about board name.
+ Based on this option board// will
+ be used.
+
+config SYS_CONFIG_NAME
+   string "Board configuration name"
+   default "mt7622" if TARGET_MT7622
+   default "mt7623" if TARGET_MT7623
+   default "mt7629" if TARGET_MT7629
+   default "mt8183" if TARGET_MT8183
+   default "mt8512" if TARGET_MT8512
+   default "mt8516" if TARGET_MT8516
+   default "mt8518" if TARGET_MT8518
+   default ""
+   help
+ This option contains information about board configuration name.
+ Based on this option include/configs/.h header
+ will be used for board configuration.
+
+config MTK_BROM_HEADER_INFO
+   string
+   default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629 
|| TARGET_MT7622
+   default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183
+   default "lk=1" if TARGET_MT7623
 
 endif
diff --git a/arch/mips/mach-mtmips/Kconfig b/arch/mips/mach-mtmips/Kconfig
index 8756cadb0b..cd078c03ad 100644
--- a/arch/mips/mach-mtmips/Kconfig
+++ b/arch/mips/mach-mtmips/Kconfig
@@ -1,6 +1,9 @@
 menu "MediaTek MIPS platforms"
depends on ARCH_MTMIPS
 
+config SYS_VENDOR
+   default "mediatek"
+
 config SYS_MALLOC_F_LEN
default 0x1000
 
diff --git a/arch/mips/mach-mtmips/mt7620/Kconfig 
b/arch/mips/mach-mtmips/mt7620/Kconfig
index 5db83eb9d9..3ca711ad0f 100644
--- a/arch/mips/mach-mtmips/mt7620/Kconfig
+++ b/arch/mips/mach-mtmips/mt7620/Kconfig
@@ -66,6 +66,12 @@ config CPU_FREQ_MULTI
default 6 if CPU_FREQ_600MHZ
default 7 if CPU_FREQ_620MHZ
 
-source "board/mediatek/mt7620/Kconfig"
+config SYS_CONFIG_NAME
+   string "Board configuration name"
+   default "mt7620" if  BOARD_MT7620_RFB || BOARD_MT7620_MT7530_RFB
+
+config SYS_BOARD
+   string "Board name"
+   default "mt7620" if  BOARD_MT7620_RFB || BOARD_MT7620_MT7530_RFB
 
 endif
diff --git a/arch/mips/mach-mtmips/mt7628/Kconfig 
b/arch/mips/mach-mtmips/mt7628/Kconfig
index e3f56e782e..9b8e588c66 1

Re: [PATCH] serial: meson: handle RX errors

2020-07-21 Thread guillaume La Roque
Hi Neil,


On 7/21/20 1:41 PM, Neil Armstrong wrote:
> This checks and handles RX errors on the Amlogic UART controller
> after experiencing errors on the Khadas VIM3 & VIM3L when UART AO A
> lines are not connected.
>
> When the RX line is not connected, the first byte is erroneous and breaks
> the U-Boot autoboot, breaking automatic boot.
>
> This checks and drops any erroneous RX byte on pending and getc callbacks
> to avoid returning true to pending when an error byte is in the FIFO.
>
> Fixes: bfcef28ae4 ("arm: add initial support for Amlogic Meson and ODROID-C2")
> Signed-off-by: Neil Armstrong 
> ---
>  drivers/serial/serial_meson.c | 43 +++
>  1 file changed, 39 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/serial/serial_meson.c b/drivers/serial/serial_meson.c
> index 439057b1b9..1b1725f6aa 100644
> --- a/drivers/serial/serial_meson.c
> +++ b/drivers/serial/serial_meson.c
> @@ -65,14 +65,36 @@ static int meson_serial_probe(struct udevice *dev)
>   return 0;
>  }
>  
> +static void meson_serial_rx_error(struct udevice *dev)
> +{
> + struct meson_serial_platdata *plat = dev->platdata;
> + struct meson_uart *const uart = plat->reg;
> + u32 val = readl(>control);
> +
> + /* Clear error */
> + val |= AML_UART_CLR_ERR;
> + writel(val, >control);
> + val &= ~AML_UART_CLR_ERR;
> + writel(val, >control);
> +
> + /* Remove spurious byte from fifo */
> + readl(>rfifo);
> +}
> +
>  static int meson_serial_getc(struct udevice *dev)
>  {
>   struct meson_serial_platdata *plat = dev->platdata;
>   struct meson_uart *const uart = plat->reg;
> + uint32_t status = readl(>status);
>  
> - if (readl(>status) & AML_UART_RX_EMPTY)
> + if (status & AML_UART_RX_EMPTY)
>   return -EAGAIN;
>  
> + if (status & AML_UART_ERR) {
> + meson_serial_rx_error(dev);
> + return -EIO;
> + }
> +
>   return readl(>rfifo) & 0xff;
>  }
>  
> @@ -95,10 +117,23 @@ static int meson_serial_pending(struct udevice *dev, 
> bool input)
>   struct meson_uart *const uart = plat->reg;
>   uint32_t status = readl(>status);
>  
> - if (input)
> - return !(status & AML_UART_RX_EMPTY);
> - else
> + if (input) {
> + if (status & AML_UART_RX_EMPTY)
> + return false;
> +
> + /*
> +  * Handle and drop any RX error here to avoid
> +  * returning true here when an error byte is in the FIFO
> +  */
> + if (status & AML_UART_ERR) {
> +         meson_serial_rx_error(dev);
> + return false;
> + }
> +
> + return true;
> + } else {
>   return !(status & AML_UART_TX_FULL);
> + }
>  }
>  
>  static int meson_serial_ofdata_to_platdata(struct udevice *dev)

Tested-by: Guillaume La Roque 

on Khadas VIM3L


thanks for this patch.

Guillaume



[U-Boot] [PATCH 2/3] pinctrl: meson: add support of drive-strength-microamp

2019-06-04 Thread Guillaume La Roque
drive-strength-microamp is a new feature needed for G12A SoC.
the default DS setting after boot is usually 500uA and it is not enough for
many functions. We need to be able to set the drive strength to reliably
enable things like MMC, I2C, etc ...

Signed-off-by: Guillaume La Roque 
---
 drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c |  1 +
 drivers/pinctrl/meson/pinctrl-meson.c | 46 ++-
 drivers/pinctrl/meson/pinctrl-meson.h | 43 +++--
 3 files changed, 76 insertions(+), 14 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c 
b/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c
index f23b188f2f..6af404ed68 100644
--- a/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c
+++ b/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c
@@ -97,6 +97,7 @@ const struct pinconf_param meson_axg_pinconf_params[] = {
{ "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
{ "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
{ "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
+   { "drive-strength-microamp", PIN_CONFIG_DRIVE_STRENGTH_UA, 0 },
 };
 
 const struct pinctrl_ops meson_axg_pinctrl_ops = {
diff --git a/drivers/pinctrl/meson/pinctrl-meson.c 
b/drivers/pinctrl/meson/pinctrl-meson.c
index 8735418c5b..432aaed02e 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -198,6 +198,47 @@ static int meson_pinconf_bias_set(struct udevice *dev, 
unsigned int pin,
return 0;
 }
 
+static int meson_pinconf_drive_strength_set(struct udevice *dev,
+   unsigned int pin,
+   unsigned int drive_strength_ua)
+{
+   struct meson_pinctrl *priv = dev_get_priv(dev);
+   unsigned int offset = pin - priv->data->pin_base;
+   unsigned int reg, bit;
+   unsigned int ds_val;
+   int ret;
+
+   if (!priv->reg_ds) {
+   dev_err(dev, "drive-strength-microamp not supported\n");
+   return -ENOTSUPP;
+   }
+
+   ret = meson_gpio_calc_reg_and_bit(dev, offset, REG_DS, , );
+   if (ret)
+   return ret;
+
+   bit = bit << 1;
+
+   if (drive_strength_ua <= 500) {
+   ds_val = MESON_PINCONF_DRV_500UA;
+   } else if (drive_strength_ua <= 2500) {
+   ds_val = MESON_PINCONF_DRV_2500UA;
+   } else if (drive_strength_ua <= 3000) {
+   ds_val = MESON_PINCONF_DRV_3000UA;
+   } else if (drive_strength_ua <= 4000) {
+   ds_val = MESON_PINCONF_DRV_4000UA;
+   } else {
+   dev_warn(dev,
+"pin %u: invalid drive-strength-microamp : %d , 
default to 4mA\n",
+pin, drive_strength_ua);
+   ds_val = MESON_PINCONF_DRV_4000UA;
+   }
+
+   clrsetbits_le32(priv->reg_ds + reg, 0x3 << bit, ds_val << bit);
+
+   return 0;
+}
+
 int meson_pinconf_set(struct udevice *dev, unsigned int pin,
  unsigned int param, unsigned int arg)
 {
@@ -209,7 +251,9 @@ int meson_pinconf_set(struct udevice *dev, unsigned int pin,
case PIN_CONFIG_BIAS_PULL_DOWN:
ret = meson_pinconf_bias_set(dev, pin, param);
break;
-
+   case PIN_CONFIG_DRIVE_STRENGTH_UA:
+   ret = meson_pinconf_drive_strength_set(dev, pin, arg);
+   break;
default:
dev_err(dev, "unsupported configuration parameter %u\n", param);
return -EINVAL;
diff --git a/drivers/pinctrl/meson/pinctrl-meson.h 
b/drivers/pinctrl/meson/pinctrl-meson.h
index b3683e2073..9261910948 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.h
+++ b/drivers/pinctrl/meson/pinctrl-meson.h
@@ -58,6 +58,16 @@ struct meson_reg_desc {
unsigned int bit;
 };
 
+/**
+ * enum meson_pinconf_drv - value of drive-strength supported
+ */
+enum meson_pinconf_drv {
+   MESON_PINCONF_DRV_500UA,
+   MESON_PINCONF_DRV_2500UA,
+   MESON_PINCONF_DRV_3000UA,
+   MESON_PINCONF_DRV_4000UA,
+};
+
 /**
  * enum meson_reg_type - type of registers encoded in @meson_reg_desc
  */
@@ -67,6 +78,7 @@ enum meson_reg_type {
REG_DIR,
REG_OUT,
REG_IN,
+   REG_DS,
NUM_REG,
 };
 
@@ -99,19 +111,24 @@ struct meson_bank {
.num_groups = ARRAY_SIZE(fn ## _groups),\
}
 
-#define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib)
\
-   {   \
-   .name   = n,\
-   .first  = f,\
-   .last   = l,\
-   .regs   = { \
-   

[U-Boot] [PATCH 3/3] pinctrl: meson: g12a: add DS bank value

2019-06-04 Thread Guillaume La Roque
add drive-strength bank regiter and bit value for G12A SoC

Signed-off-by: Guillaume La Roque 
---
 drivers/pinctrl/meson/pinctrl-meson-g12a.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson-g12a.c 
b/drivers/pinctrl/meson/pinctrl-meson-g12a.c
index 9cc2b9d52b..115e8b5616 100644
--- a/drivers/pinctrl/meson/pinctrl-meson-g12a.c
+++ b/drivers/pinctrl/meson/pinctrl-meson-g12a.c
@@ -1204,19 +1204,19 @@ static struct meson_pmx_func 
meson_g12a_aobus_functions[] = {
 };
 
 static struct meson_bank meson_g12a_periphs_banks[] = {
-   /*name   first   last   pullen  
pull   dir out in   */
-   BANK("Z",PIN(GPIOZ_0, EE_OFF),   PIN(GPIOZ_15, EE_OFF), 4,  0,  4,  
0, 12,  0, 13,  0, 14,  0),
-   BANK("H",PIN(GPIOH_0, EE_OFF),   PIN(GPIOH_8,  EE_OFF), 3,  0,  3,  
0,  9,  0, 10,  0, 11,  0),
-   BANK("BOOT", PIN(BOOT_0,  EE_OFF),   PIN(BOOT_15,  EE_OFF), 0,  0,  0,  
0,  0,  0,  1,  0,  2,  0),
-   BANK("C",PIN(GPIOC_0, EE_OFF),   PIN(GPIOC_7,  EE_OFF), 1,  0,  1,  
0,  3,  0,  4,  0,  5,  0),
-   BANK("A",PIN(GPIOA_0, EE_OFF),   PIN(GPIOA_15, EE_OFF), 5,  0,  5,  
0, 16,  0, 17,  0, 18,  0),
-   BANK("X",PIN(GPIOX_0, EE_OFF),   PIN(GPIOX_19, EE_OFF), 2,  0,  2,  
0,  6,  0,  7,  0,  8,  0),
+   /*   name   first   last   pullen  
pull   dir out in  ds*/
+   BANK_DS("Z",PIN(GPIOZ_0, EE_OFF),   PIN(GPIOZ_15, EE_OFF), 4,  0,  
4,  0, 12,  0, 13,  0, 14,  0, 5, 0),
+   BANK_DS("H",PIN(GPIOH_0, EE_OFF),   PIN(GPIOH_8,  EE_OFF), 3,  0,  
3,  0,  9,  0, 10,  0, 11,  0, 4, 0),
+   BANK_DS("BOOT", PIN(BOOT_0,  EE_OFF),   PIN(BOOT_15,  EE_OFF), 0,  0,  
0,  0,  0,  0,  1,  0,  2,  0, 0, 0),
+   BANK_DS("C",PIN(GPIOC_0, EE_OFF),   PIN(GPIOC_7,  EE_OFF), 1,  0,  
1,  0,  3,  0,  4,  0,  5,  0, 1, 0),
+   BANK_DS("A",PIN(GPIOA_0, EE_OFF),   PIN(GPIOA_15, EE_OFF), 5,  0,  
5,  0, 16,  0, 17,  0, 18,  0, 6, 0),
+   BANK_DS("X",PIN(GPIOX_0, EE_OFF),   PIN(GPIOX_19, EE_OFF), 2,  0,  
2,  0,  6,  0,  7,  0,  8,  0, 2, 0),
 };
 
 static struct meson_bank meson_g12a_aobus_banks[] = {
-   /*   namefirst   last   pullen  
pull   dir out in  */
-   BANK("AO",   PIN(GPIOAO_0, 0),   PIN(GPIOAO_11, 0), 3,  0,  2,  
0,  0,  0,  4,  0,  1,  0),
-   BANK("E",PIN(GPIOE_0, 0),PIN(GPIOE_2, 0),   3, 16,  2, 
16,  0, 16,  4, 16,  1,  16),
+   /*  namefirst   last   pullen  
pull   dir out in  ds*/
+   BANK_DS("AO",   PIN(GPIOAO_0, 0),   PIN(GPIOAO_11, 0), 3,  0,  
2,  0,  0,  0,  4,  0,  1,  0, 0, 0),
+   BANK_DS("E",PIN(GPIOE_0, 0),PIN(GPIOE_2, 0),   3, 16,  
2, 16,  0, 16,  4, 16,  1,  16, 1, 0),
 };
 
 static struct meson_pmx_bank meson_g12a_periphs_pmx_banks[] = {
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/3] dm: pinctrl: Add driver-strength-microamp property

2019-06-04 Thread Guillaume La Roque
Add drive-strength-microamp property support to allow drive strength in uA

Signed-off-by: Guillaume La Roque 
---
 include/dm/pinctrl.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h
index e7b8ad9078..3eca34fbf7 100644
--- a/include/dm/pinctrl.h
+++ b/include/dm/pinctrl.h
@@ -225,6 +225,8 @@ struct pinctrl_ops {
  * push-pull mode, the argument is ignored.
  * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
  * passed as argument. The argument is in mA.
+ * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the 
current
+ * passed as argument. The argument is in uA.
  * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
  * which means it will wait for signals to settle when reading inputs. The
  * argument gives the debounce time in usecs. Setting the
@@ -281,6 +283,7 @@ enum pin_config_param {
PIN_CONFIG_DRIVE_OPEN_SOURCE,
PIN_CONFIG_DRIVE_PUSH_PULL,
PIN_CONFIG_DRIVE_STRENGTH,
+   PIN_CONFIG_DRIVE_STRENGTH_UA,
PIN_CONFIG_INPUT_DEBOUNCE,
PIN_CONFIG_INPUT_ENABLE,
PIN_CONFIG_INPUT_SCHMITT,
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/3] Add drive-strength-microamp in Meson pinctrl driver

2019-06-04 Thread Guillaume La Roque
The purpose of this patchset is to add drive-strength-microamp support in meson 
pinconf
driver. This is a new feature that was added on the g12a. It is critical for us
to support this since many functions are failing with default pad 
drive-strength.

The value achievable by the SoC are 500uA, 2500uA, 3000uA and 4000uA and the DT 
property
'drive-strength-microamp' is expressed in uA.
So this patch add another generic property "drive-strength-microamp". The 
change to do so
would be minimal and could be benefit to other platforms later on.

it's backport from linux :
https://lore.kernel.org/lkml/20190514082652.20686-1-glaro...@baylibre.com/

Cheers
Guillaume

Guillaume La Roque (3):
  dm: pinctrl: Add driver-strength-microamp property
  pinctrl: meson: add support of drive-strength-microamp
  pinctrl: meson: g12a: add DS bank value

 drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c |  1 +
 drivers/pinctrl/meson/pinctrl-meson-g12a.c| 20 
 drivers/pinctrl/meson/pinctrl-meson.c | 46 ++-
 drivers/pinctrl/meson/pinctrl-meson.h | 43 +++--
 include/dm/pinctrl.h  |  3 ++
 5 files changed, 89 insertions(+), 24 deletions(-)

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] pinctrl: meson: axg: Fix PIN and BANK offsets

2019-04-08 Thread Guillaume La Roque
Periphs bank offset must be applied on all pins and
PMX bank to prevent issue in meson_pinconf_set call.
Without offset on pins when a call to pinconf is done
meson_gpio_calc_reg_and_bit return wrong offset.
To avoid breaking pmx function offset is needed in pmx bank structure too.

Signed-off-by: Guillaume La Roque 
---
 drivers/pinctrl/meson/pinctrl-meson-axg.c | 358 +++---
 1 file changed, 179 insertions(+), 179 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson-axg.c 
b/drivers/pinctrl/meson/pinctrl-meson-axg.c
index 3bbbe817b4..8f23c8cef1 100644
--- a/drivers/pinctrl/meson/pinctrl-meson-axg.c
+++ b/drivers/pinctrl/meson/pinctrl-meson-axg.c
@@ -17,239 +17,239 @@
 #define EE_OFF 15
 
 /* emmc */
-static const unsigned int emmc_nand_d0_pins[] = {BOOT_0};
-static const unsigned int emmc_nand_d1_pins[] = {BOOT_1};
-static const unsigned int emmc_nand_d2_pins[] = {BOOT_2};
-static const unsigned int emmc_nand_d3_pins[] = {BOOT_3};
-static const unsigned int emmc_nand_d4_pins[] = {BOOT_4};
-static const unsigned int emmc_nand_d5_pins[] = {BOOT_5};
-static const unsigned int emmc_nand_d6_pins[] = {BOOT_6};
-static const unsigned int emmc_nand_d7_pins[] = {BOOT_7};
-
-static const unsigned int emmc_clk_pins[] = {BOOT_8};
-static const unsigned int emmc_cmd_pins[] = {BOOT_10};
-static const unsigned int emmc_ds_pins[]  = {BOOT_13};
+static const unsigned int emmc_nand_d0_pins[] = { PIN(BOOT_0, EE_OFF) };
+static const unsigned int emmc_nand_d1_pins[] = { PIN(BOOT_1, EE_OFF) };
+static const unsigned int emmc_nand_d2_pins[] = { PIN(BOOT_2, EE_OFF) };
+static const unsigned int emmc_nand_d3_pins[] = { PIN(BOOT_3, EE_OFF) };
+static const unsigned int emmc_nand_d4_pins[] = { PIN(BOOT_4, EE_OFF) };
+static const unsigned int emmc_nand_d5_pins[] = { PIN(BOOT_5, EE_OFF) };
+static const unsigned int emmc_nand_d6_pins[] = { PIN(BOOT_6, EE_OFF) };
+static const unsigned int emmc_nand_d7_pins[] = { PIN(BOOT_7, EE_OFF) };
+
+static const unsigned int emmc_clk_pins[] = { PIN(BOOT_8, EE_OFF) };
+static const unsigned int emmc_cmd_pins[] = { PIN(BOOT_10, EE_OFF) };
+static const unsigned int emmc_ds_pins[]  = { PIN(BOOT_13, EE_OFF) };
 
 /* nand */
-static const unsigned int nand_ce0_pins[] = {BOOT_8};
-static const unsigned int nand_ale_pins[] = {BOOT_9};
-static const unsigned int nand_cle_pins[] = {BOOT_10};
-static const unsigned int nand_wen_clk_pins[] = {BOOT_11};
-static const unsigned int nand_ren_wr_pins[] = {BOOT_12};
-static const unsigned int nand_rb0_pins[] = {BOOT_13};
+static const unsigned int nand_ce0_pins[] = { PIN(BOOT_8, EE_OFF) };
+static const unsigned int nand_ale_pins[] = { PIN(BOOT_9, EE_OFF) };
+static const unsigned int nand_cle_pins[] = { PIN(BOOT_10, EE_OFF) };
+static const unsigned int nand_wen_clk_pins[] = { PIN(BOOT_11, EE_OFF) };
+static const unsigned int nand_ren_wr_pins[] = { PIN(BOOT_12, EE_OFF) };
+static const unsigned int nand_rb0_pins[] = { PIN(BOOT_13, EE_OFF) };
 
 /* nor */
-static const unsigned int nor_hold_pins[] = {BOOT_3};
-static const unsigned int nor_d_pins[] = {BOOT_4};
-static const unsigned int nor_q_pins[] = {BOOT_5};
-static const unsigned int nor_c_pins[] = {BOOT_6};
-static const unsigned int nor_wp_pins[] = {BOOT_9};
-static const unsigned int nor_cs_pins[] = {BOOT_14};
+static const unsigned int nor_hold_pins[] = { PIN(BOOT_3, EE_OFF) };
+static const unsigned int nor_d_pins[] = { PIN(BOOT_4, EE_OFF) };
+static const unsigned int nor_q_pins[] = { PIN(BOOT_5, EE_OFF) };
+static const unsigned int nor_c_pins[] = { PIN(BOOT_6, EE_OFF) };
+static const unsigned int nor_wp_pins[] = { PIN(BOOT_9, EE_OFF) };
+static const unsigned int nor_cs_pins[] = { PIN(BOOT_14, EE_OFF) };
 
 /* sdio */
-static const unsigned int sdio_d0_pins[] = {GPIOX_0};
-static const unsigned int sdio_d1_pins[] = {GPIOX_1};
-static const unsigned int sdio_d2_pins[] = {GPIOX_2};
-static const unsigned int sdio_d3_pins[] = {GPIOX_3};
-static const unsigned int sdio_clk_pins[] = {GPIOX_4};
-static const unsigned int sdio_cmd_pins[] = {GPIOX_5};
+static const unsigned int sdio_d0_pins[] = { PIN(GPIOX_0, EE_OFF) };
+static const unsigned int sdio_d1_pins[] = { PIN(GPIOX_1, EE_OFF) };
+static const unsigned int sdio_d2_pins[] = { PIN(GPIOX_2, EE_OFF) };
+static const unsigned int sdio_d3_pins[] = { PIN(GPIOX_3, EE_OFF) };
+static const unsigned int sdio_clk_pins[] = { PIN(GPIOX_4, EE_OFF) };
+static const unsigned int sdio_cmd_pins[] = { PIN(GPIOX_5, EE_OFF) };
 
 /* spi0 */
-static const unsigned int spi0_clk_pins[] = {GPIOZ_0};
-static const unsigned int spi0_mosi_pins[] = {GPIOZ_1};
-static const unsigned int spi0_miso_pins[] = {GPIOZ_2};
-static const unsigned int spi0_ss0_pins[] = {GPIOZ_3};
-static const unsigned int spi0_ss1_pins[] = {GPIOZ_4};
-static const unsigned int spi0_ss2_pins[] = {GPIOZ_5};
+static const unsigned int spi0_clk_pins[] = { PIN(GPIOZ_0, EE_OFF) };
+static const unsigned int spi0_mosi_pins[] = { PIN(GPIOZ_1, EE_OFF) };
+static const unsigned int

[U-Boot] [PATCH] i2c: meson: add configurable divider factors

2019-03-22 Thread Guillaume La Roque
This patch add support for I2C controller in Meson-AXG SoC,
Due to the IP changes between I2C controller, we need to introduce
a compatible data to make the divider factor configurable.

backport from linux:
931b18e92cd0 ("2c: meson: add configurable divider factors")

Signed-off-by: Guillaume La Roque 
---
 drivers/i2c/meson_i2c.c | 30 +-
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/meson_i2c.c b/drivers/i2c/meson_i2c.c
index 7d06d95cf3..ee59bac123 100644
--- a/drivers/i2c/meson_i2c.c
+++ b/drivers/i2c/meson_i2c.c
@@ -41,7 +41,12 @@ struct i2c_regs {
u32 tok_rdata1;
 };
 
+struct meson_i2c_data {
+   unsigned char div_factor;
+};
+
 struct meson_i2c {
+   const struct meson_i2c_data *data;
struct clk clk;
struct i2c_regs *regs;
struct i2c_msg *msg;/* Current I2C message */
@@ -229,7 +234,7 @@ static int meson_i2c_set_bus_speed(struct udevice *bus, 
unsigned int speed)
if (IS_ERR_VALUE(clk_rate))
return -EINVAL;
 
-   div = DIV_ROUND_UP(clk_rate, speed * 4);
+   div = DIV_ROUND_UP(clk_rate, speed * i2c->data->div_factor);
 
/* clock divider has 12 bits */
if (div >= (1 << 12)) {
@@ -253,6 +258,8 @@ static int meson_i2c_probe(struct udevice *bus)
struct meson_i2c *i2c = dev_get_priv(bus);
int ret;
 
+   i2c->data = (const struct meson_i2c_data *)dev_get_driver_data(bus);
+
ret = clk_get_by_index(bus, 0, >clk);
if (ret < 0)
return ret;
@@ -272,11 +279,24 @@ static const struct dm_i2c_ops meson_i2c_ops = {
.set_bus_speed = meson_i2c_set_bus_speed,
 };
 
+static const struct meson_i2c_data i2c_meson6_data = {
+   .div_factor = 4,
+};
+
+static const struct meson_i2c_data i2c_gxbb_data = {
+   .div_factor = 4,
+};
+
+static const struct meson_i2c_data i2c_axg_data = {
+   .div_factor = 3,
+};
+
 static const struct udevice_id meson_i2c_ids[] = {
-   { .compatible = "amlogic,meson6-i2c" },
-   { .compatible = "amlogic,meson-gx-i2c" },
-   { .compatible = "amlogic,meson-gxbb-i2c" },
-   { }
+   {.compatible = "amlogic,meson6-i2c", .data = (ulong)_meson6_data},
+   {.compatible = "amlogic,meson-gx-i2c", .data = (ulong)_gxbb_data},
+   {.compatible = "amlogic,meson-gxbb-i2c", .data = (ulong)_gxbb_data},
+   {.compatible = "amlogic,meson-axg-i2c", .data = (ulong)_axg_data},
+   {}
 };
 
 U_BOOT_DRIVER(i2c_meson) = {
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot