diff mbox series

[2/4] board: add support for Milk-V Mars CM

Message ID 20240415115035.46199-3-heinrich.schuchardt@canonical.com
State New
Delegated to: Andes
Headers show
Series board: starfive: add Milk-V Mars CM support | expand

Commit Message

Heinrich Schuchardt April 15, 2024, 11:50 a.m. UTC
We already support the VisionFive 2 and the Milk-V Mars board by
patching the VisionFive 2 device tree. With this patch the same
is done for the Milk-V Mars CM.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
 .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

Comments

E Shattow April 16, 2024, 12:58 p.m. UTC | #1
On Mon, Apr 15, 2024 at 4:50 AM Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> We already support the VisionFive 2 and the Milk-V Mars board by
> patching the VisionFive 2 device tree. With this patch the same
> is done for the Milk-V Mars CM.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
>  .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
> index 45848db6d8b..bb0f28d7aad 100644
> --- a/board/starfive/visionfive2/spl.c
> +++ b/board/starfive/visionfive2/spl.c
> @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
>         }
>  }
>
> +void spl_fdt_fixup_marc(void *fdt)
> +{
> +       const char *compat;
> +       const char *model;
> +
> +       spl_fdt_fixup_mars(fdt);
> +
> +       if (!get_mmc_size_from_eeprom()) {
> +               int offset;
> +
> +               model = "Milk-V Mars CM SDCard";
> +               compat = "milkv,mars-cm-sdcard\0starfive,jh7110";
> +
> +               offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
> +               fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);

Note this is:

- pinmux = <GPIOMUX(62, GPOUT_SYS_SDIO0_RST,
+ pinmux = <GPIOMUX(22, GPOUT_SYS_SDIO0_RST,

As in the vendor code repo for Mars CM Lite branch:

https://github.com/milkv-mars/mars-buildroot-sdk/commit/880a249518f72ecf1e2947dfeb2c66e5035fce90

But the GPIOMUX macro here (for code readability) would bring in
another header to include. Add a comment of what the magic number is
for.

Does anyone have a better explanation of why this is needed than the
vendor "u-boot: configure sdio0 as mars-cm sdcard version" commit
message?

> +       } else {
> +               model = "Milk-V Mars CM eMMC";
> +               compat = "milkv,mars-cm-emmc\0starfive,jh7110";
> +       }
> +       fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
> +       fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
> +}
> +
>  void spl_fdt_fixup_version_a(void *fdt)
>  {
>         static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
> @@ -236,7 +259,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
>                 pr_err("Can't read EEPROM\n");
>                 return;
>         }
> -       if (!strncmp(product_id, "MARS", 4)) {
> +       if (!strncmp(product_id, "MARC", 4)) {
> +               spl_fdt_fixup_marc(spl_image->fdt_addr);
> +       } else if (!strncmp(product_id, "MARS", 4)) {
>                 spl_fdt_fixup_mars(spl_image->fdt_addr);
>         } else if (!strncmp(product_id, "VF7110", 6)) {
>                 version = get_pcb_revision_from_eeprom();
> diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
> index a86bca533b2..be6ca85b030 100644
> --- a/board/starfive/visionfive2/starfive_visionfive2.c
> +++ b/board/starfive/visionfive2/starfive_visionfive2.c
> @@ -17,6 +17,10 @@
>  DECLARE_GLOBAL_DATA_PTR;
>  #define JH7110_L2_PREFETCHER_BASE_ADDR         0x2030000
>  #define JH7110_L2_PREFETCHER_HART_OFFSET       0x2000
> +#define FDTFILE_MILK_V_MARC_SD \
> +       "starfive/jh7110-milkv-mars-cm-sdcard.dtb"
> +#define FDTFILE_MILK_V_MARC_MMC \
> +       "starfive/jh7110-milkv-mars-cm-emmc.dtb"
>  #define FDTFILE_MILK_V_MARS \
>         "starfive/jh7110-milkv-mars.dtb"
>  #define FDTFILE_VISIONFIVE2_1_2A \
> @@ -61,7 +65,12 @@ static void set_fdtfile(void)
>                 log_err("Can't read EEPROM\n");
>                 return;
>         }
> -       if (!strncmp(product_id, "MARS", 4)) {
> +       if (!strncmp(product_id, "MARC", 4)) {
> +               if (get_mmc_size_from_eeprom())
> +                       fdtfile = FDTFILE_MILK_V_MARC_MMC;
> +               else
> +                       fdtfile = FDTFILE_MILK_V_MARC_SD;
> +       } else if (!strncmp(product_id, "MARS", 4)) {
>                 fdtfile = FDTFILE_MILK_V_MARS;
>         } else if (!strncmp(product_id, "VF7110", 6)) {
>                 version = get_pcb_revision_from_eeprom();
> --
> 2.43.0
>
Emil Renner Berthing April 28, 2024, 4:13 p.m. UTC | #2
Heinrich Schuchardt wrote:
> We already support the VisionFive 2 and the Milk-V Mars board by
> patching the VisionFive 2 device tree. With this patch the same
> is done for the Milk-V Mars CM.

Hi Heinrich.

Thanks for the patch. As far as I can tell the Milk-V documentation[1] is
pretty consistent in calling the version without eMMC "Milk-V Mars CM Lite"
and the version with eMMC just "Milk-V Mars CM". So I'd prefer the model,
compatible and filenames suggested below.

[1]: https://milkv.io/docs/mars/compute-module/introduction#design-philosophy

> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
>  .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
> index 45848db6d8b..bb0f28d7aad 100644
> --- a/board/starfive/visionfive2/spl.c
> +++ b/board/starfive/visionfive2/spl.c
> @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
>  	}
>  }
>
> +void spl_fdt_fixup_marc(void *fdt)
> +{
> +	const char *compat;
> +	const char *model;
> +
> +	spl_fdt_fixup_mars(fdt);
> +
> +	if (!get_mmc_size_from_eeprom()) {
> +		int offset;
> +
> +		model = "Milk-V Mars CM SDCard";

"Milk-V Mars CM Lite"

> +		compat = "milkv,mars-cm-sdcard\0starfive,jh7110";

"milkv,mars-cm-lite\0starfive,jh7110"

> +
> +		offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
> +		fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
> +	} else {
> +		model = "Milk-V Mars CM eMMC";

"Milk-V Mars CM"

> +		compat = "milkv,mars-cm-emmc\0starfive,jh7110";

"milkv,mars-cm\0starfive,jh7110"

> +	}
> +	fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
> +	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
> +}
> +
>  void spl_fdt_fixup_version_a(void *fdt)
>  {
>  	static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
> @@ -236,7 +259,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
>  		pr_err("Can't read EEPROM\n");
>  		return;
>  	}
> -	if (!strncmp(product_id, "MARS", 4)) {
> +	if (!strncmp(product_id, "MARC", 4)) {
> +		spl_fdt_fixup_marc(spl_image->fdt_addr);
> +	} else if (!strncmp(product_id, "MARS", 4)) {
>  		spl_fdt_fixup_mars(spl_image->fdt_addr);
>  	} else if (!strncmp(product_id, "VF7110", 6)) {
>  		version = get_pcb_revision_from_eeprom();
> diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
> index a86bca533b2..be6ca85b030 100644
> --- a/board/starfive/visionfive2/starfive_visionfive2.c
> +++ b/board/starfive/visionfive2/starfive_visionfive2.c
> @@ -17,6 +17,10 @@
>  DECLARE_GLOBAL_DATA_PTR;
>  #define JH7110_L2_PREFETCHER_BASE_ADDR		0x2030000
>  #define JH7110_L2_PREFETCHER_HART_OFFSET	0x2000
> +#define FDTFILE_MILK_V_MARC_SD \
> +	"starfive/jh7110-milkv-mars-cm-sdcard.dtb"

"starfive/jh7110-milkv-mars-cm-lite.dtb"

> +#define FDTFILE_MILK_V_MARC_MMC \
> +	"starfive/jh7110-milkv-mars-cm-emmc.dtb"

"starfive/jh7110-milkv-mars-cm.dtb"

>  #define FDTFILE_MILK_V_MARS \
>  	"starfive/jh7110-milkv-mars.dtb"
>  #define FDTFILE_VISIONFIVE2_1_2A \
> @@ -61,7 +65,12 @@ static void set_fdtfile(void)
>  		log_err("Can't read EEPROM\n");
>  		return;
>  	}
> -	if (!strncmp(product_id, "MARS", 4)) {
> +	if (!strncmp(product_id, "MARC", 4)) {
> +		if (get_mmc_size_from_eeprom())
> +			fdtfile = FDTFILE_MILK_V_MARC_MMC;
> +		else
> +			fdtfile = FDTFILE_MILK_V_MARC_SD;
> +	} else if (!strncmp(product_id, "MARS", 4)) {
>  		fdtfile = FDTFILE_MILK_V_MARS;
>  	} else if (!strncmp(product_id, "VF7110", 6)) {
>  		version = get_pcb_revision_from_eeprom();
> --
> 2.43.0
>
>
E Shattow April 29, 2024, 10:46 p.m. UTC | #3
On Sun, Apr 28, 2024 at 9:13 AM Emil Renner Berthing
<emil.renner.berthing@canonical.com> wrote:
>
> Heinrich Schuchardt wrote:
> > We already support the VisionFive 2 and the Milk-V Mars board by
> > patching the VisionFive 2 device tree. With this patch the same
> > is done for the Milk-V Mars CM.
>
> Hi Heinrich.
>
> Thanks for the patch. As far as I can tell the Milk-V documentation[1] is
> pretty consistent in calling the version without eMMC "Milk-V Mars CM Lite"
> and the version with eMMC just "Milk-V Mars CM". So I'd prefer the model,
> compatible and filenames suggested below.
>
> [1]: https://milkv.io/docs/mars/compute-module/introduction#design-philosophy
>

Are there any actual differences that need representation in the dtb
file for downstream OS different from Milk-V Mars to Milk-V Mars CM
(or CM Lite)?

I did find this vendor repo commit "kernel: dts reconfig sdio0 for
SDCard version"
https://github.com/milkv-mars/mars-buildroot-sdk/commit/042ea06598995db99ddbbbb252ee439c42b9c1a9
but it does not seem necessary in mainline Linux, SD Card is working
without changes.

It was necessary for U-Boot and the Mars CM Lite with SD Card to apply
s/GPIO62/GPIO22/ as in the vendor commit "u-boot: configure sdio0 as
mars-cm sdcard version"
https://github.com/milkv-mars/mars-buildroot-sdk/commit/880a249518f72ecf1e2947dfeb2c66e5035fce90

Then also there is some mention about PMIC and renamed i2c reference,
already obsolete. That's all, is there more to it? Possibly a dtb for
Mars is enough to also be used on Mars CM and Mars Lite?

-E

> > Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> > ---
> >  board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
> >  .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
> >  2 files changed, 36 insertions(+), 2 deletions(-)
> >
> > diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
> > index 45848db6d8b..bb0f28d7aad 100644
> > --- a/board/starfive/visionfive2/spl.c
> > +++ b/board/starfive/visionfive2/spl.c
> > @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
> >       }
> >  }
> >
> > +void spl_fdt_fixup_marc(void *fdt)
> > +{
> > +     const char *compat;
> > +     const char *model;
> > +
> > +     spl_fdt_fixup_mars(fdt);
> > +
> > +     if (!get_mmc_size_from_eeprom()) {
> > +             int offset;
> > +
> > +             model = "Milk-V Mars CM SDCard";
>
> "Milk-V Mars CM Lite"
>
> > +             compat = "milkv,mars-cm-sdcard\0starfive,jh7110";
>
> "milkv,mars-cm-lite\0starfive,jh7110"
>
> > +
> > +             offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
> > +             fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
> > +     } else {
> > +             model = "Milk-V Mars CM eMMC";
>
> "Milk-V Mars CM"
>
> > +             compat = "milkv,mars-cm-emmc\0starfive,jh7110";
>
> "milkv,mars-cm\0starfive,jh7110"
>
> > +     }
> > +     fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
> > +     fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
> > +}
> > +
> >  void spl_fdt_fixup_version_a(void *fdt)
> >  {
> >       static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
> > @@ -236,7 +259,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
> >               pr_err("Can't read EEPROM\n");
> >               return;
> >       }
> > -     if (!strncmp(product_id, "MARS", 4)) {
> > +     if (!strncmp(product_id, "MARC", 4)) {
> > +             spl_fdt_fixup_marc(spl_image->fdt_addr);
> > +     } else if (!strncmp(product_id, "MARS", 4)) {
> >               spl_fdt_fixup_mars(spl_image->fdt_addr);
> >       } else if (!strncmp(product_id, "VF7110", 6)) {
> >               version = get_pcb_revision_from_eeprom();
> > diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
> > index a86bca533b2..be6ca85b030 100644
> > --- a/board/starfive/visionfive2/starfive_visionfive2.c
> > +++ b/board/starfive/visionfive2/starfive_visionfive2.c
> > @@ -17,6 +17,10 @@
> >  DECLARE_GLOBAL_DATA_PTR;
> >  #define JH7110_L2_PREFETCHER_BASE_ADDR               0x2030000
> >  #define JH7110_L2_PREFETCHER_HART_OFFSET     0x2000
> > +#define FDTFILE_MILK_V_MARC_SD \
> > +     "starfive/jh7110-milkv-mars-cm-sdcard.dtb"
>
> "starfive/jh7110-milkv-mars-cm-lite.dtb"
>
> > +#define FDTFILE_MILK_V_MARC_MMC \
> > +     "starfive/jh7110-milkv-mars-cm-emmc.dtb"
>
> "starfive/jh7110-milkv-mars-cm.dtb"
>
> >  #define FDTFILE_MILK_V_MARS \
> >       "starfive/jh7110-milkv-mars.dtb"
> >  #define FDTFILE_VISIONFIVE2_1_2A \
> > @@ -61,7 +65,12 @@ static void set_fdtfile(void)
> >               log_err("Can't read EEPROM\n");
> >               return;
> >       }
> > -     if (!strncmp(product_id, "MARS", 4)) {
> > +     if (!strncmp(product_id, "MARC", 4)) {
> > +             if (get_mmc_size_from_eeprom())
> > +                     fdtfile = FDTFILE_MILK_V_MARC_MMC;
> > +             else
> > +                     fdtfile = FDTFILE_MILK_V_MARC_SD;
> > +     } else if (!strncmp(product_id, "MARS", 4)) {
> >               fdtfile = FDTFILE_MILK_V_MARS;
> >       } else if (!strncmp(product_id, "VF7110", 6)) {
> >               version = get_pcb_revision_from_eeprom();
> > --
> > 2.43.0
> >
> >
Heinrich Schuchardt April 30, 2024, 7:17 a.m. UTC | #4
On 30.04.24 00:46, E Shattow wrote:
> On Sun, Apr 28, 2024 at 9:13 AM Emil Renner Berthing
> <emil.renner.berthing@canonical.com> wrote:
>>
>> Heinrich Schuchardt wrote:
>>> We already support the VisionFive 2 and the Milk-V Mars board by
>>> patching the VisionFive 2 device tree. With this patch the same
>>> is done for the Milk-V Mars CM.
>>
>> Hi Heinrich.
>>
>> Thanks for the patch. As far as I can tell the Milk-V documentation[1] is
>> pretty consistent in calling the version without eMMC "Milk-V Mars CM Lite"
>> and the version with eMMC just "Milk-V Mars CM". So I'd prefer the model,
>> compatible and filenames suggested below.
>>
>> [1]: https://milkv.io/docs/mars/compute-module/introduction#design-philosophy
>>
> 
> Are there any actual differences that need representation in the dtb
> file for downstream OS different from Milk-V Mars to Milk-V Mars CM
> (or CM Lite)?
> 
> I did find this vendor repo commit "kernel: dts reconfig sdio0 for
> SDCard version"
> https://github.com/milkv-mars/mars-buildroot-sdk/commit/042ea06598995db99ddbbbb252ee439c42b9c1a9
> but it does not seem necessary in mainline Linux, SD Card is working
> without changes.
> 
> It was necessary for U-Boot and the Mars CM Lite with SD Card to apply
> s/GPIO62/GPIO22/ as in the vendor commit "u-boot: configure sdio0 as
> mars-cm sdcard version"
> https://github.com/milkv-mars/mars-buildroot-sdk/commit/880a249518f72ecf1e2947dfeb2c66e5035fce90

This is what is patched in fdt_fixup_marc().

> 
> Then also there is some mention about PMIC and renamed i2c reference,
> already obsolete. That's all, is there more to it? Possibly a dtb for
> Mars is enough to also be used on Mars CM and Mars Lite?

Looking at the schematics the biggest difference between the Mars and 
the Mars CM (Lite) is on the USB side. The Mars board has USB 3.0 via a 
PCIe lane and a VIA VL805/806 while the Mars CM has USB directly via the 
SoC.

To add USB support for the Mars CM we will need an adapted device-tree.

Best regards

Heinrich
> 
>>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
>>> ---
>>>   board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
>>>   .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
>>>   2 files changed, 36 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
>>> index 45848db6d8b..bb0f28d7aad 100644
>>> --- a/board/starfive/visionfive2/spl.c
>>> +++ b/board/starfive/visionfive2/spl.c
>>> @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
>>>        }
>>>   }
>>>
>>> +void spl_fdt_fixup_marc(void *fdt)
>>> +{
>>> +     const char *compat;
>>> +     const char *model;
>>> +
>>> +     spl_fdt_fixup_mars(fdt);
>>> +
>>> +     if (!get_mmc_size_from_eeprom()) {
>>> +             int offset;
>>> +
>>> +             model = "Milk-V Mars CM SDCard";
>>
>> "Milk-V Mars CM Lite"
>>
>>> +             compat = "milkv,mars-cm-sdcard\0starfive,jh7110";
>>
>> "milkv,mars-cm-lite\0starfive,jh7110"
>>
>>> +
>>> +             offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
>>> +             fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
>>> +     } else {
>>> +             model = "Milk-V Mars CM eMMC";
>>
>> "Milk-V Mars CM"
>>
>>> +             compat = "milkv,mars-cm-emmc\0starfive,jh7110";
>>
>> "milkv,mars-cm\0starfive,jh7110"
>>
>>> +     }
>>> +     fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
>>> +     fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
>>> +}
>>> +
>>>   void spl_fdt_fixup_version_a(void *fdt)
>>>   {
>>>        static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
>>> @@ -236,7 +259,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
>>>                pr_err("Can't read EEPROM\n");
>>>                return;
>>>        }
>>> -     if (!strncmp(product_id, "MARS", 4)) {
>>> +     if (!strncmp(product_id, "MARC", 4)) {
>>> +             spl_fdt_fixup_marc(spl_image->fdt_addr);
>>> +     } else if (!strncmp(product_id, "MARS", 4)) {
>>>                spl_fdt_fixup_mars(spl_image->fdt_addr);
>>>        } else if (!strncmp(product_id, "VF7110", 6)) {
>>>                version = get_pcb_revision_from_eeprom();
>>> diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
>>> index a86bca533b2..be6ca85b030 100644
>>> --- a/board/starfive/visionfive2/starfive_visionfive2.c
>>> +++ b/board/starfive/visionfive2/starfive_visionfive2.c
>>> @@ -17,6 +17,10 @@
>>>   DECLARE_GLOBAL_DATA_PTR;
>>>   #define JH7110_L2_PREFETCHER_BASE_ADDR               0x2030000
>>>   #define JH7110_L2_PREFETCHER_HART_OFFSET     0x2000
>>> +#define FDTFILE_MILK_V_MARC_SD \
>>> +     "starfive/jh7110-milkv-mars-cm-sdcard.dtb"
>>
>> "starfive/jh7110-milkv-mars-cm-lite.dtb"
>>
>>> +#define FDTFILE_MILK_V_MARC_MMC \
>>> +     "starfive/jh7110-milkv-mars-cm-emmc.dtb"
>>
>> "starfive/jh7110-milkv-mars-cm.dtb"
>>
>>>   #define FDTFILE_MILK_V_MARS \
>>>        "starfive/jh7110-milkv-mars.dtb"
>>>   #define FDTFILE_VISIONFIVE2_1_2A \
>>> @@ -61,7 +65,12 @@ static void set_fdtfile(void)
>>>                log_err("Can't read EEPROM\n");
>>>                return;
>>>        }
>>> -     if (!strncmp(product_id, "MARS", 4)) {
>>> +     if (!strncmp(product_id, "MARC", 4)) {
>>> +             if (get_mmc_size_from_eeprom())
>>> +                     fdtfile = FDTFILE_MILK_V_MARC_MMC;
>>> +             else
>>> +                     fdtfile = FDTFILE_MILK_V_MARC_SD;
>>> +     } else if (!strncmp(product_id, "MARS", 4)) {
>>>                fdtfile = FDTFILE_MILK_V_MARS;
>>>        } else if (!strncmp(product_id, "VF7110", 6)) {
>>>                version = get_pcb_revision_from_eeprom();
>>> --
>>> 2.43.0
>>>
>>>
E Shattow April 30, 2024, 9:59 a.m. UTC | #5
On Tue, Apr 30, 2024 at 12:18 AM Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> On 30.04.24 00:46, E Shattow wrote:
> > On Sun, Apr 28, 2024 at 9:13 AM Emil Renner Berthing
> > <emil.renner.berthing@canonical.com> wrote:
> >>
> >> Heinrich Schuchardt wrote:
> >>> We already support the VisionFive 2 and the Milk-V Mars board by
> >>> patching the VisionFive 2 device tree. With this patch the same
> >>> is done for the Milk-V Mars CM.
> >>
> >> Hi Heinrich.
> >>
> >> Thanks for the patch. As far as I can tell the Milk-V documentation[1] is
> >> pretty consistent in calling the version without eMMC "Milk-V Mars CM Lite"
> >> and the version with eMMC just "Milk-V Mars CM". So I'd prefer the model,
> >> compatible and filenames suggested below.
> >>
> >> [1]: https://milkv.io/docs/mars/compute-module/introduction#design-philosophy
> >>
> >
> > Are there any actual differences that need representation in the dtb
> > file for downstream OS different from Milk-V Mars to Milk-V Mars CM
> > (or CM Lite)?
> >
> > I did find this vendor repo commit "kernel: dts reconfig sdio0 for
> > SDCard version"
> > https://github.com/milkv-mars/mars-buildroot-sdk/commit/042ea06598995db99ddbbbb252ee439c42b9c1a9
> > but it does not seem necessary in mainline Linux, SD Card is working
> > without changes.
> >
> > It was necessary for U-Boot and the Mars CM Lite with SD Card to apply
> > s/GPIO62/GPIO22/ as in the vendor commit "u-boot: configure sdio0 as
> > mars-cm sdcard version"
> > https://github.com/milkv-mars/mars-buildroot-sdk/commit/880a249518f72ecf1e2947dfeb2c66e5035fce90
>
> This is what is patched in fdt_fixup_marc().

That's the Mars fixup with a conditional for the s/GPIO62/GPIO22/ of
CM Lite;  which Linux seems not to mind either way so long as this was
done at the U-Boot phase, it is functional for eMMC/SD mmc access with
unmodified visionfive2 1.3b dtb (GPIO62 pinmux) from Linux.

It is not clear to me why in vendor U-Boot this is s/GPIO62/GPIO22/
but in vendor Linux kernel this is s/GPIO62/GPIO24/ ? It seems not
needed (in Linux).

>
> >
> > Then also there is some mention about PMIC and renamed i2c reference,
> > already obsolete. That's all, is there more to it? Possibly a dtb for
> > Mars is enough to also be used on Mars CM and Mars Lite?
>
> Looking at the schematics the biggest difference between the Mars and
> the Mars CM (Lite) is on the USB side. The Mars board has USB 3.0 via a
> PCIe lane and a VIA VL805/806 while the Mars CM has USB directly via the
> SoC.
>
> To add USB support for the Mars CM we will need an adapted device-tree.

Mars also needs this direct-to-SoC USB support, as its USB ports are a
mix of VL805 and directly via the SoC. This can be the same for Mars
and Mars CM/Lite.

See this photo from
https://milkv.io/docs/mars/getting-started/bootloader what highlights
this direct SoC USB port of Milk-V Mars:
https://milkv.io/assets/images/mars-usb-port-a-b48fe1ff1003539d42bf5e1dde1725a3.jpg

The over-current errata
https://doc-en.rvspace.org/VisionFive2/DG_USB/JH7110_SDK/usb_overcurrent_debug.html
suggests "please modify the above settings during the U-Boot phase".

-E

>
> Best regards
>
> Heinrich
> >
> >>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> >>> ---
> >>>   board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
> >>>   .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
> >>>   2 files changed, 36 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
> >>> index 45848db6d8b..bb0f28d7aad 100644
> >>> --- a/board/starfive/visionfive2/spl.c
> >>> +++ b/board/starfive/visionfive2/spl.c
> >>> @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
> >>>        }
> >>>   }
> >>>
> >>> +void spl_fdt_fixup_marc(void *fdt)
> >>> +{
> >>> +     const char *compat;
> >>> +     const char *model;
> >>> +
> >>> +     spl_fdt_fixup_mars(fdt);
> >>> +
> >>> +     if (!get_mmc_size_from_eeprom()) {
> >>> +             int offset;
> >>> +
> >>> +             model = "Milk-V Mars CM SDCard";
> >>
> >> "Milk-V Mars CM Lite"
> >>
> >>> +             compat = "milkv,mars-cm-sdcard\0starfive,jh7110";
> >>
> >> "milkv,mars-cm-lite\0starfive,jh7110"
> >>
> >>> +
> >>> +             offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
> >>> +             fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
> >>> +     } else {
> >>> +             model = "Milk-V Mars CM eMMC";
> >>
> >> "Milk-V Mars CM"
> >>
> >>> +             compat = "milkv,mars-cm-emmc\0starfive,jh7110";
> >>
> >> "milkv,mars-cm\0starfive,jh7110"
> >>
> >>> +     }
> >>> +     fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
> >>> +     fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
> >>> +}
> >>> +
> >>>   void spl_fdt_fixup_version_a(void *fdt)
> >>>   {
> >>>        static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
> >>> @@ -236,7 +259,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
> >>>                pr_err("Can't read EEPROM\n");
> >>>                return;
> >>>        }
> >>> -     if (!strncmp(product_id, "MARS", 4)) {
> >>> +     if (!strncmp(product_id, "MARC", 4)) {
> >>> +             spl_fdt_fixup_marc(spl_image->fdt_addr);
> >>> +     } else if (!strncmp(product_id, "MARS", 4)) {
> >>>                spl_fdt_fixup_mars(spl_image->fdt_addr);
> >>>        } else if (!strncmp(product_id, "VF7110", 6)) {
> >>>                version = get_pcb_revision_from_eeprom();
> >>> diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
> >>> index a86bca533b2..be6ca85b030 100644
> >>> --- a/board/starfive/visionfive2/starfive_visionfive2.c
> >>> +++ b/board/starfive/visionfive2/starfive_visionfive2.c
> >>> @@ -17,6 +17,10 @@
> >>>   DECLARE_GLOBAL_DATA_PTR;
> >>>   #define JH7110_L2_PREFETCHER_BASE_ADDR               0x2030000
> >>>   #define JH7110_L2_PREFETCHER_HART_OFFSET     0x2000
> >>> +#define FDTFILE_MILK_V_MARC_SD \
> >>> +     "starfive/jh7110-milkv-mars-cm-sdcard.dtb"
> >>
> >> "starfive/jh7110-milkv-mars-cm-lite.dtb"
> >>
> >>> +#define FDTFILE_MILK_V_MARC_MMC \
> >>> +     "starfive/jh7110-milkv-mars-cm-emmc.dtb"
> >>
> >> "starfive/jh7110-milkv-mars-cm.dtb"
> >>
> >>>   #define FDTFILE_MILK_V_MARS \
> >>>        "starfive/jh7110-milkv-mars.dtb"
> >>>   #define FDTFILE_VISIONFIVE2_1_2A \
> >>> @@ -61,7 +65,12 @@ static void set_fdtfile(void)
> >>>                log_err("Can't read EEPROM\n");
> >>>                return;
> >>>        }
> >>> -     if (!strncmp(product_id, "MARS", 4)) {
> >>> +     if (!strncmp(product_id, "MARC", 4)) {
> >>> +             if (get_mmc_size_from_eeprom())
> >>> +                     fdtfile = FDTFILE_MILK_V_MARC_MMC;
> >>> +             else
> >>> +                     fdtfile = FDTFILE_MILK_V_MARC_SD;
> >>> +     } else if (!strncmp(product_id, "MARS", 4)) {
> >>>                fdtfile = FDTFILE_MILK_V_MARS;
> >>>        } else if (!strncmp(product_id, "VF7110", 6)) {
> >>>                version = get_pcb_revision_from_eeprom();
> >>> --
> >>> 2.43.0
> >>>
> >>>
>
Heinrich Schuchardt April 30, 2024, 11:50 a.m. UTC | #6
On 30.04.24 11:59, E Shattow wrote:
> On Tue, Apr 30, 2024 at 12:18 AM Heinrich Schuchardt
> <heinrich.schuchardt@canonical.com> wrote:
>>
>> On 30.04.24 00:46, E Shattow wrote:
>>> On Sun, Apr 28, 2024 at 9:13 AM Emil Renner Berthing
>>> <emil.renner.berthing@canonical.com> wrote:
>>>>
>>>> Heinrich Schuchardt wrote:
>>>>> We already support the VisionFive 2 and the Milk-V Mars board by
>>>>> patching the VisionFive 2 device tree. With this patch the same
>>>>> is done for the Milk-V Mars CM.
>>>>
>>>> Hi Heinrich.
>>>>
>>>> Thanks for the patch. As far as I can tell the Milk-V documentation[1] is
>>>> pretty consistent in calling the version without eMMC "Milk-V Mars CM Lite"
>>>> and the version with eMMC just "Milk-V Mars CM". So I'd prefer the model,
>>>> compatible and filenames suggested below.
>>>>
>>>> [1]: https://milkv.io/docs/mars/compute-module/introduction#design-philosophy
>>>>
>>>
>>> Are there any actual differences that need representation in the dtb
>>> file for downstream OS different from Milk-V Mars to Milk-V Mars CM
>>> (or CM Lite)?
>>>
>>> I did find this vendor repo commit "kernel: dts reconfig sdio0 for
>>> SDCard version"
>>> https://github.com/milkv-mars/mars-buildroot-sdk/commit/042ea06598995db99ddbbbb252ee439c42b9c1a9
>>> but it does not seem necessary in mainline Linux, SD Card is working
>>> without changes.
>>>
>>> It was necessary for U-Boot and the Mars CM Lite with SD Card to apply
>>> s/GPIO62/GPIO22/ as in the vendor commit "u-boot: configure sdio0 as
>>> mars-cm sdcard version"
>>> https://github.com/milkv-mars/mars-buildroot-sdk/commit/880a249518f72ecf1e2947dfeb2c66e5035fce90
>>
>> This is what is patched in fdt_fixup_marc().
> 
> That's the Mars fixup with a conditional for the s/GPIO62/GPIO22/ of
> CM Lite;  which Linux seems not to mind either way so long as this was
> done at the U-Boot phase, it is functional for eMMC/SD mmc access with
> unmodified visionfive2 1.3b dtb (GPIO62 pinmux) from Linux.
> 
> It is not clear to me why in vendor U-Boot this is s/GPIO62/GPIO22/
> but in vendor Linux kernel this is s/GPIO62/GPIO24/ ? It seems not
> needed (in Linux).

According to the schematics GPIO22 is connected to SD_PWR_ON on the the 
low speed connector both on the Mars CM and the Mars CM Lite. GPIO62 is 
connected to SDMMC_RST_N on the eMMC. Both the SD-card and the eMMC are 
connected to SDI0. This is why only one of them can be usable.

GPIO024 is used for the MIPI camera interface.

I guess unless you reset the SD-card or eMMC GPIO062 and GPI022 are not 
used and this is why Linux is working in both configurations.

> 
>>
>>>
>>> Then also there is some mention about PMIC and renamed i2c reference,
>>> already obsolete. That's all, is there more to it? Possibly a dtb for
>>> Mars is enough to also be used on Mars CM and Mars Lite?
>>
>> Looking at the schematics the biggest difference between the Mars and
>> the Mars CM (Lite) is on the USB side. The Mars board has USB 3.0 via a
>> PCIe lane and a VIA VL805/806 while the Mars CM has USB directly via the
>> SoC.
>>
>> To add USB support for the Mars CM we will need an adapted device-tree.
> 
> Mars also needs this direct-to-SoC USB support, as its USB ports are a
> mix of VL805 and directly via the SoC. This can be the same for Mars
> and Mars CM/Lite.

The schematics say:

"One USB Controller only, supports either USB 2.0 or USB 3.0."

This sounds to me like you cannot have both in functional state.

Maybe Minda or Hal know more?

Best regards

Heinrich

> 
> See this photo from
> https://milkv.io/docs/mars/getting-started/bootloader what highlights
> this direct SoC USB port of Milk-V Mars:
> https://milkv.io/assets/images/mars-usb-port-a-b48fe1ff1003539d42bf5e1dde1725a3.jpg
> 
> The over-current errata
> https://doc-en.rvspace.org/VisionFive2/DG_USB/JH7110_SDK/usb_overcurrent_debug.html
> suggests "please modify the above settings during the U-Boot phase".
> 
> -E
> 
>>
>> Best regards
>>
>> Heinrich
>>>
>>>>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
>>>>> ---
>>>>>    board/starfive/visionfive2/spl.c              | 27 ++++++++++++++++++-
>>>>>    .../visionfive2/starfive_visionfive2.c        | 11 +++++++-
>>>>>    2 files changed, 36 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
>>>>> index 45848db6d8b..bb0f28d7aad 100644
>>>>> --- a/board/starfive/visionfive2/spl.c
>>>>> +++ b/board/starfive/visionfive2/spl.c
>>>>> @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
>>>>>         }
>>>>>    }
>>>>>
>>>>> +void spl_fdt_fixup_marc(void *fdt)
>>>>> +{
>>>>> +     const char *compat;
>>>>> +     const char *model;
>>>>> +
>>>>> +     spl_fdt_fixup_mars(fdt);
>>>>> +
>>>>> +     if (!get_mmc_size_from_eeprom()) {
>>>>> +             int offset;
>>>>> +
>>>>> +             model = "Milk-V Mars CM SDCard";
>>>>
>>>> "Milk-V Mars CM Lite"
>>>>
>>>>> +             compat = "milkv,mars-cm-sdcard\0starfive,jh7110";
>>>>
>>>> "milkv,mars-cm-lite\0starfive,jh7110"
>>>>
>>>>> +
>>>>> +             offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
>>>>> +             fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
>>>>> +     } else {
>>>>> +             model = "Milk-V Mars CM eMMC";
>>>>
>>>> "Milk-V Mars CM"
>>>>
>>>>> +             compat = "milkv,mars-cm-emmc\0starfive,jh7110";
>>>>
>>>> "milkv,mars-cm\0starfive,jh7110"
>>>>
>>>>> +     }
>>>>> +     fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
>>>>> +     fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
>>>>> +}
>>>>> +
>>>>>    void spl_fdt_fixup_version_a(void *fdt)
>>>>>    {
>>>>>         static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
>>>>> @@ -236,7 +259,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
>>>>>                 pr_err("Can't read EEPROM\n");
>>>>>                 return;
>>>>>         }
>>>>> -     if (!strncmp(product_id, "MARS", 4)) {
>>>>> +     if (!strncmp(product_id, "MARC", 4)) {
>>>>> +             spl_fdt_fixup_marc(spl_image->fdt_addr);
>>>>> +     } else if (!strncmp(product_id, "MARS", 4)) {
>>>>>                 spl_fdt_fixup_mars(spl_image->fdt_addr);
>>>>>         } else if (!strncmp(product_id, "VF7110", 6)) {
>>>>>                 version = get_pcb_revision_from_eeprom();
>>>>> diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
>>>>> index a86bca533b2..be6ca85b030 100644
>>>>> --- a/board/starfive/visionfive2/starfive_visionfive2.c
>>>>> +++ b/board/starfive/visionfive2/starfive_visionfive2.c
>>>>> @@ -17,6 +17,10 @@
>>>>>    DECLARE_GLOBAL_DATA_PTR;
>>>>>    #define JH7110_L2_PREFETCHER_BASE_ADDR               0x2030000
>>>>>    #define JH7110_L2_PREFETCHER_HART_OFFSET     0x2000
>>>>> +#define FDTFILE_MILK_V_MARC_SD \
>>>>> +     "starfive/jh7110-milkv-mars-cm-sdcard.dtb"
>>>>
>>>> "starfive/jh7110-milkv-mars-cm-lite.dtb"
>>>>
>>>>> +#define FDTFILE_MILK_V_MARC_MMC \
>>>>> +     "starfive/jh7110-milkv-mars-cm-emmc.dtb"
>>>>
>>>> "starfive/jh7110-milkv-mars-cm.dtb"
>>>>
>>>>>    #define FDTFILE_MILK_V_MARS \
>>>>>         "starfive/jh7110-milkv-mars.dtb"
>>>>>    #define FDTFILE_VISIONFIVE2_1_2A \
>>>>> @@ -61,7 +65,12 @@ static void set_fdtfile(void)
>>>>>                 log_err("Can't read EEPROM\n");
>>>>>                 return;
>>>>>         }
>>>>> -     if (!strncmp(product_id, "MARS", 4)) {
>>>>> +     if (!strncmp(product_id, "MARC", 4)) {
>>>>> +             if (get_mmc_size_from_eeprom())
>>>>> +                     fdtfile = FDTFILE_MILK_V_MARC_MMC;
>>>>> +             else
>>>>> +                     fdtfile = FDTFILE_MILK_V_MARC_SD;
>>>>> +     } else if (!strncmp(product_id, "MARS", 4)) {
>>>>>                 fdtfile = FDTFILE_MILK_V_MARS;
>>>>>         } else if (!strncmp(product_id, "VF7110", 6)) {
>>>>>                 version = get_pcb_revision_from_eeprom();
>>>>> --
>>>>> 2.43.0
>>>>>
>>>>>
>>
diff mbox series

Patch

diff --git a/board/starfive/visionfive2/spl.c b/board/starfive/visionfive2/spl.c
index 45848db6d8b..bb0f28d7aad 100644
--- a/board/starfive/visionfive2/spl.c
+++ b/board/starfive/visionfive2/spl.c
@@ -129,6 +129,29 @@  void spl_fdt_fixup_mars(void *fdt)
 	}
 }
 
+void spl_fdt_fixup_marc(void *fdt)
+{
+	const char *compat;
+	const char *model;
+
+	spl_fdt_fixup_mars(fdt);
+
+	if (!get_mmc_size_from_eeprom()) {
+		int offset;
+
+		model = "Milk-V Mars CM SDCard";
+		compat = "milkv,mars-cm-sdcard\0starfive,jh7110";
+
+		offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
+		fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
+	} else {
+		model = "Milk-V Mars CM eMMC";
+		compat = "milkv,mars-cm-emmc\0starfive,jh7110";
+	}
+	fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
+	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
+}
+
 void spl_fdt_fixup_version_a(void *fdt)
 {
 	static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
@@ -236,7 +259,9 @@  void spl_perform_fixups(struct spl_image_info *spl_image)
 		pr_err("Can't read EEPROM\n");
 		return;
 	}
-	if (!strncmp(product_id, "MARS", 4)) {
+	if (!strncmp(product_id, "MARC", 4)) {
+		spl_fdt_fixup_marc(spl_image->fdt_addr);
+	} else if (!strncmp(product_id, "MARS", 4)) {
 		spl_fdt_fixup_mars(spl_image->fdt_addr);
 	} else if (!strncmp(product_id, "VF7110", 6)) {
 		version = get_pcb_revision_from_eeprom();
diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
index a86bca533b2..be6ca85b030 100644
--- a/board/starfive/visionfive2/starfive_visionfive2.c
+++ b/board/starfive/visionfive2/starfive_visionfive2.c
@@ -17,6 +17,10 @@ 
 DECLARE_GLOBAL_DATA_PTR;
 #define JH7110_L2_PREFETCHER_BASE_ADDR		0x2030000
 #define JH7110_L2_PREFETCHER_HART_OFFSET	0x2000
+#define FDTFILE_MILK_V_MARC_SD \
+	"starfive/jh7110-milkv-mars-cm-sdcard.dtb"
+#define FDTFILE_MILK_V_MARC_MMC \
+	"starfive/jh7110-milkv-mars-cm-emmc.dtb"
 #define FDTFILE_MILK_V_MARS \
 	"starfive/jh7110-milkv-mars.dtb"
 #define FDTFILE_VISIONFIVE2_1_2A \
@@ -61,7 +65,12 @@  static void set_fdtfile(void)
 		log_err("Can't read EEPROM\n");
 		return;
 	}
-	if (!strncmp(product_id, "MARS", 4)) {
+	if (!strncmp(product_id, "MARC", 4)) {
+		if (get_mmc_size_from_eeprom())
+			fdtfile = FDTFILE_MILK_V_MARC_MMC;
+		else
+			fdtfile = FDTFILE_MILK_V_MARC_SD;
+	} else if (!strncmp(product_id, "MARS", 4)) {
 		fdtfile = FDTFILE_MILK_V_MARS;
 	} else if (!strncmp(product_id, "VF7110", 6)) {
 		version = get_pcb_revision_from_eeprom();