[u-boot,v2016.07-aspeed-openbmc] Add MTD support to Aspeed Flash driver

Message ID 1502140837-48939-1-git-send-email-anoo@linux.vnet.ibm.com
State Accepted, archived
Headers show

Commit Message

Adriana Kobylak Aug. 7, 2017, 9:20 p.m.
Add support to the aspeed flash driver to enable the common mtd layer
through CONFIG_FLASH_CFI_MTD.

This enables the flash to be used by u-boot mtd drivers including
the mtdparts and ubi commands.

Signed-off-by: Adriana Kobylak <anoo@linux.vnet.ibm.com>
Acked-by: Milton Miller <miltonm@us.ibm.com>
---
 arch/arm/mach-aspeed/flash.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Joel Stanley Aug. 21, 2017, 11:06 a.m. | #1
On Tue, Aug 8, 2017 at 6:50 AM, Adriana Kobylak <anoo@linux.vnet.ibm.com> wrote:
> Add support to the aspeed flash driver to enable the common mtd layer
> through CONFIG_FLASH_CFI_MTD.
>
> This enables the flash to be used by u-boot mtd drivers including
> the mtdparts and ubi commands.
>
> Signed-off-by: Adriana Kobylak <anoo@linux.vnet.ibm.com>
> Acked-by: Milton Miller <miltonm@us.ibm.com>
> ---
>  arch/arm/mach-aspeed/flash.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/arch/arm/mach-aspeed/flash.c b/arch/arm/mach-aspeed/flash.c
> index 9c5ead6..e1e3cf8 100644
> --- a/arch/arm/mach-aspeed/flash.c
> +++ b/arch/arm/mach-aspeed/flash.c
> @@ -124,6 +124,22 @@ flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];               /* FLASH chips info */
>  /* specificspi */
>  #define SpecificSPI_N25Q512    0x00000001
>
> +#ifdef CONFIG_FLASH_CFI_MTD
> +static uint flash_verbose=1;
> +void flash_set_verbose(uint v)
> +{
> +       flash_verbose = v;
> +}
> +
> +unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect)
> +{
> +       if (sect != (info->sector_count - 1))
> +               return info->start[sect + 1] - info->start[sect];
> +       else
> +               return info->start[0] + info->size - info->start[sect];
> +}

This function looks like it's copied from cfi_flash.c (line 197).

Can you explain why we're duplicating it here?

> +#endif
> +
>  /*-----------------------------------------------------------------------*/
>  static u32 ast_spi_calculate_divisor(u32 max_speed_hz)
>  {
> @@ -1372,6 +1388,10 @@ unsigned long flash_init (void)
>                        flash_get_info(CONFIG_ENV_ADDR_REDUND));
>  #endif
>
> +#ifdef CONFIG_FLASH_CFI_MTD
> +       cfi_mtd_init();
> +#endif
> +
>         return (size);
>  }
>
> --
> 1.8.2.2
>
Adriana Kobylak Aug. 21, 2017, 2:35 p.m. | #2
On 2017-08-21 06:06, Joel Stanley wrote:
> On Tue, Aug 8, 2017 at 6:50 AM, Adriana Kobylak 
> <anoo@linux.vnet.ibm.com> wrote:
>> Add support to the aspeed flash driver to enable the common mtd layer
>> through CONFIG_FLASH_CFI_MTD.
>> 
>> This enables the flash to be used by u-boot mtd drivers including
>> the mtdparts and ubi commands.
>> 
>> Signed-off-by: Adriana Kobylak <anoo@linux.vnet.ibm.com>
>> Acked-by: Milton Miller <miltonm@us.ibm.com>
>> ---
>>  arch/arm/mach-aspeed/flash.c | 20 ++++++++++++++++++++
>>  1 file changed, 20 insertions(+)
>> 
>> diff --git a/arch/arm/mach-aspeed/flash.c 
>> b/arch/arm/mach-aspeed/flash.c
>> index 9c5ead6..e1e3cf8 100644
>> --- a/arch/arm/mach-aspeed/flash.c
>> +++ b/arch/arm/mach-aspeed/flash.c
>> @@ -124,6 +124,22 @@ flash_info_t 
>> flash_info[CONFIG_SYS_MAX_FLASH_BANKS];               /* FLASH chips 
>> info */
>>  /* specificspi */
>>  #define SpecificSPI_N25Q512    0x00000001
>> 
>> +#ifdef CONFIG_FLASH_CFI_MTD
>> +static uint flash_verbose=1;
>> +void flash_set_verbose(uint v)
>> +{
>> +       flash_verbose = v;
>> +}
>> +
>> +unsigned long flash_sector_size(flash_info_t *info, flash_sect_t 
>> sect)
>> +{
>> +       if (sect != (info->sector_count - 1))
>> +               return info->start[sect + 1] - info->start[sect];
>> +       else
>> +               return info->start[0] + info->size - 
>> info->start[sect];
>> +}
> 
> This function looks like it's copied from cfi_flash.c (line 197).
> 
> Can you explain why we're duplicating it here?

Yes, it's duplicated :) . What I understood from Milton is that this 
function would be
available if we enabled the CONFIG_FLASH_CFI_DRIVER, but we don't want 
to enable
the driver as this would cause some collisions, we just want to enable
CONFIG_FLASH_CFI_MTD so these functions are the only ones needed that 
the driver
would provide.

> 
>> +#endif
>> +
>>  
>> /*-----------------------------------------------------------------------*/
>>  static u32 ast_spi_calculate_divisor(u32 max_speed_hz)
>>  {
>> @@ -1372,6 +1388,10 @@ unsigned long flash_init (void)
>>                        flash_get_info(CONFIG_ENV_ADDR_REDUND));
>>  #endif
>> 
>> +#ifdef CONFIG_FLASH_CFI_MTD
>> +       cfi_mtd_init();
>> +#endif
>> +
>>         return (size);
>>  }
>> 
>> --
>> 1.8.2.2
>>
Andrew Jeffery Aug. 24, 2017, 5:11 a.m. | #3
On Mon, 2017-08-07 at 16:20 -0500, Adriana Kobylak wrote:
> Add support to the aspeed flash driver to enable the common mtd layer
> through CONFIG_FLASH_CFI_MTD.
> 
> This enables the flash to be used by u-boot mtd drivers including
> the mtdparts and ubi commands.
> 
> > Signed-off-by: Adriana Kobylak <anoo@linux.vnet.ibm.com>
> Acked-by: Milton Miller <miltonm@us.ibm.com>

Hmm, the flash situation looks pretty messy. I guess the duplication is
warranted for the moment.

Applied with Milton's ack.

Thanks,

Andrew

> ---
>  arch/arm/mach-aspeed/flash.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/arch/arm/mach-aspeed/flash.c b/arch/arm/mach-aspeed/flash.c
> index 9c5ead6..e1e3cf8 100644
> --- a/arch/arm/mach-aspeed/flash.c
> +++ b/arch/arm/mach-aspeed/flash.c
> > @@ -124,6 +124,22 @@ flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];		/* FLASH chips info */
>  /* specificspi */
> >  #define SpecificSPI_N25Q512	0x00000001
>  
> +#ifdef CONFIG_FLASH_CFI_MTD
> +static uint flash_verbose=1;
> +void flash_set_verbose(uint v)
> +{
> > +	flash_verbose = v;
> +}
> +
> +unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect)
> +{
> > +	if (sect != (info->sector_count - 1))
> > +		return info->start[sect + 1] - info->start[sect];
> > +	else
> > +		return info->start[0] + info->size - info->start[sect];
> +}
> +#endif
> +
>  /*-----------------------------------------------------------------------*/
>  static u32 ast_spi_calculate_divisor(u32 max_speed_hz)
>  {
> @@ -1372,6 +1388,10 @@ unsigned long flash_init (void)
> >  		       flash_get_info(CONFIG_ENV_ADDR_REDUND));
>  #endif
>  
> +#ifdef CONFIG_FLASH_CFI_MTD
> > +	cfi_mtd_init();
> +#endif
> +
> >  	return (size);
>  }
>

Patch

diff --git a/arch/arm/mach-aspeed/flash.c b/arch/arm/mach-aspeed/flash.c
index 9c5ead6..e1e3cf8 100644
--- a/arch/arm/mach-aspeed/flash.c
+++ b/arch/arm/mach-aspeed/flash.c
@@ -124,6 +124,22 @@  flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];		/* FLASH chips info */
 /* specificspi */
 #define SpecificSPI_N25Q512	0x00000001
 
+#ifdef CONFIG_FLASH_CFI_MTD
+static uint flash_verbose=1;
+void flash_set_verbose(uint v)
+{
+	flash_verbose = v;
+}
+
+unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect)
+{
+	if (sect != (info->sector_count - 1))
+		return info->start[sect + 1] - info->start[sect];
+	else
+		return info->start[0] + info->size - info->start[sect];
+}
+#endif
+
 /*-----------------------------------------------------------------------*/
 static u32 ast_spi_calculate_divisor(u32 max_speed_hz)
 {
@@ -1372,6 +1388,10 @@  unsigned long flash_init (void)
 		       flash_get_info(CONFIG_ENV_ADDR_REDUND));
 #endif
 
+#ifdef CONFIG_FLASH_CFI_MTD
+	cfi_mtd_init();
+#endif
+
 	return (size);
 }