diff mbox series

[v2,26/26] dm: mmc: Add a library function to parse generic dt binding

Message ID 1506004213-22620-27-git-send-email-jjhiblot@ti.com
State New
Headers show
Series None | expand

Commit Message

Jean-Jacques Hiblot Sept. 21, 2017, 2:30 p.m. UTC
From: Kishon Vijay Abraham I <kishon@ti.com>

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
 drivers/mmc/mmc-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/mmc.h            |  1 +
 2 files changed, 47 insertions(+)

Comments

Jaehoon Chung Sept. 22, 2017, 1:54 p.m. UTC | #1
On 09/21/2017 11:30 PM, Jean-Jacques Hiblot wrote:
> From: Kishon Vijay Abraham I <kishon@ti.com>
> 
> Add a new function to parse host controller dt node and
> set mmc_config. This function can be used by mmc controller
> drivers to set the generic mmc_config.
> This function can be extended to set other UHS mode caps
> once UHS mode support is added.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
>  drivers/mmc/mmc-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/mmc.h            |  1 +
>  2 files changed, 47 insertions(+)
> 
> diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
> index 7856e0a..e30cde7 100644
> --- a/drivers/mmc/mmc-uclass.c
> +++ b/drivers/mmc/mmc-uclass.c
> @@ -120,6 +120,52 @@ int mmc_execute_tuning(struct mmc *mmc, uint opcode)
>  	return dm_mmc_execute_tuning(mmc->dev, opcode);
>  }
>  
> +int mmc_of_parse(const void *fdt, int node, struct mmc_config *cfg)
> +{
> +	int val;
> +
> +	val = fdtdec_get_int(fdt, node, "bus-width", 1);
> +
> +	switch (val) {
> +	case 0x8:
> +		cfg->host_caps |= MMC_MODE_8BIT;
> +		/* fall through */
> +	case 0x4:
> +		cfg->host_caps |= MMC_MODE_4BIT;
> +		/* fall through */
> +	case 0x1:
> +		cfg->host_caps |= MMC_MODE_1BIT;
> +		break;
> +	default:
> +		printf("error: %s invalid bus-width property %d\n",
> +		       fdt_get_name(fdt, node, NULL), val);

I guess it can be set to 1-bit by default and just display message about invalid bus-width property.

> +		return -ENOENT;
> +	}
> +
> +	cfg->f_max = fdtdec_get_int(fdt, node, "max-frequency", 52000000);
> +
> +	if (fdtdec_get_bool(fdt, node, "cap-sd-highspeed"))
> +		cfg->host_caps |= MMC_CAP(SD_HS);
> +	if (fdtdec_get_bool(fdt, node, "cap-mmc-highspeed"))
> +		cfg->host_caps |= MMC_CAP(MMC_HS);
> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr12"))
> +		cfg->host_caps |= MMC_CAP(UHS_SDR12);
> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr25"))
> +		cfg->host_caps |= MMC_CAP(UHS_SDR25);
> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr50"))
> +		cfg->host_caps |= MMC_CAP(UHS_SDR50);
> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr104"))
> +		cfg->host_caps |= MMC_CAP(UHS_SDR104);
> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-ddr50"))
> +		cfg->host_caps |= MMC_CAP(UHS_DDR50);
> +	if (fdtdec_get_bool(fdt, node, "mmc-ddr-1_8v"))
> +		cfg->host_caps |= MMC_CAP(MMC_DDR_52);
> +	if (fdtdec_get_bool(fdt, node, "mmc-hs200-1_8v"))
> +		cfg->host_caps |= MMC_CAP(MMC_HS_200);

Don't need to check about 1.2v?

> +
> +	return 0;
> +}
> +
>  struct mmc *mmc_get_mmc_dev(struct udevice *dev)
>  {
>  	struct mmc_uclass_priv *upriv;
> diff --git a/include/mmc.h b/include/mmc.h
> index 79be6b4..6230a32 100644
> --- a/include/mmc.h
> +++ b/include/mmc.h
> @@ -651,6 +651,7 @@ int mmc_unbind(struct udevice *dev);
>  int mmc_initialize(bd_t *bis);
>  int mmc_init(struct mmc *mmc);
>  int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error);
> +int mmc_of_parse(const void *fdt, int node, struct mmc_config *cfg);
>  int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
>  
>  /**
>
Simon Glass Sept. 25, 2017, 2:14 a.m. UTC | #2
On 21 September 2017 at 08:30, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
> From: Kishon Vijay Abraham I <kishon@ti.com>
>
> Add a new function to parse host controller dt node and
> set mmc_config. This function can be used by mmc controller
> drivers to set the generic mmc_config.
> This function can be extended to set other UHS mode caps
> once UHS mode support is added.
>
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
>  drivers/mmc/mmc-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/mmc.h            |  1 +
>  2 files changed, 47 insertions(+)

Can you please use the live API here - e.g. dev_read_bool(). Otherwise
boards which use live tree will fail.

Regards,
Simon
Jean-Jacques Hiblot Oct. 2, 2017, 9:08 a.m. UTC | #3
On 22/09/2017 15:54, Jaehoon Chung wrote:
> On 09/21/2017 11:30 PM, Jean-Jacques Hiblot wrote:
>> From: Kishon Vijay Abraham I <kishon@ti.com>
>>
>> Add a new function to parse host controller dt node and
>> set mmc_config. This function can be used by mmc controller
>> drivers to set the generic mmc_config.
>> This function can be extended to set other UHS mode caps
>> once UHS mode support is added.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
>> ---
>>   drivers/mmc/mmc-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>>   include/mmc.h            |  1 +
>>   2 files changed, 47 insertions(+)
>>
>> diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
>> index 7856e0a..e30cde7 100644
>> --- a/drivers/mmc/mmc-uclass.c
>> +++ b/drivers/mmc/mmc-uclass.c
>> @@ -120,6 +120,52 @@ int mmc_execute_tuning(struct mmc *mmc, uint opcode)
>>   	return dm_mmc_execute_tuning(mmc->dev, opcode);
>>   }
>>   
>> +int mmc_of_parse(const void *fdt, int node, struct mmc_config *cfg)
>> +{
>> +	int val;
>> +
>> +	val = fdtdec_get_int(fdt, node, "bus-width", 1);
>> +
>> +	switch (val) {
>> +	case 0x8:
>> +		cfg->host_caps |= MMC_MODE_8BIT;
>> +		/* fall through */
>> +	case 0x4:
>> +		cfg->host_caps |= MMC_MODE_4BIT;
>> +		/* fall through */
>> +	case 0x1:
>> +		cfg->host_caps |= MMC_MODE_1BIT;
>> +		break;
>> +	default:
>> +		printf("error: %s invalid bus-width property %d\n",
>> +		       fdt_get_name(fdt, node, NULL), val);
> I guess it can be set to 1-bit by default and just display message about invalid bus-width property.
OK.
>
>> +		return -ENOENT;
>> +	}
>> +
>> +	cfg->f_max = fdtdec_get_int(fdt, node, "max-frequency", 52000000);
>> +
>> +	if (fdtdec_get_bool(fdt, node, "cap-sd-highspeed"))
>> +		cfg->host_caps |= MMC_CAP(SD_HS);
>> +	if (fdtdec_get_bool(fdt, node, "cap-mmc-highspeed"))
>> +		cfg->host_caps |= MMC_CAP(MMC_HS);
>> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr12"))
>> +		cfg->host_caps |= MMC_CAP(UHS_SDR12);
>> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr25"))
>> +		cfg->host_caps |= MMC_CAP(UHS_SDR25);
>> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr50"))
>> +		cfg->host_caps |= MMC_CAP(UHS_SDR50);
>> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr104"))
>> +		cfg->host_caps |= MMC_CAP(UHS_SDR104);
>> +	if (fdtdec_get_bool(fdt, node, "sd-uhs-ddr50"))
>> +		cfg->host_caps |= MMC_CAP(UHS_DDR50);
>> +	if (fdtdec_get_bool(fdt, node, "mmc-ddr-1_8v"))
>> +		cfg->host_caps |= MMC_CAP(MMC_DDR_52);
>> +	if (fdtdec_get_bool(fdt, node, "mmc-hs200-1_8v"))
>> +		cfg->host_caps |= MMC_CAP(MMC_HS_200);
> Don't need to check about 1.2v?
I'll add it. I won't be able to test though by lack of hardware.

>
>> +
>> +	return 0;
>> +}
>> +
>>   struct mmc *mmc_get_mmc_dev(struct udevice *dev)
>>   {
>>   	struct mmc_uclass_priv *upriv;
>> diff --git a/include/mmc.h b/include/mmc.h
>> index 79be6b4..6230a32 100644
>> --- a/include/mmc.h
>> +++ b/include/mmc.h
>> @@ -651,6 +651,7 @@ int mmc_unbind(struct udevice *dev);
>>   int mmc_initialize(bd_t *bis);
>>   int mmc_init(struct mmc *mmc);
>>   int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error);
>> +int mmc_of_parse(const void *fdt, int node, struct mmc_config *cfg);
>>   int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
>>   
>>   /**
>>
>
diff mbox series

Patch

diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 7856e0a..e30cde7 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -120,6 +120,52 @@  int mmc_execute_tuning(struct mmc *mmc, uint opcode)
 	return dm_mmc_execute_tuning(mmc->dev, opcode);
 }
 
+int mmc_of_parse(const void *fdt, int node, struct mmc_config *cfg)
+{
+	int val;
+
+	val = fdtdec_get_int(fdt, node, "bus-width", 1);
+
+	switch (val) {
+	case 0x8:
+		cfg->host_caps |= MMC_MODE_8BIT;
+		/* fall through */
+	case 0x4:
+		cfg->host_caps |= MMC_MODE_4BIT;
+		/* fall through */
+	case 0x1:
+		cfg->host_caps |= MMC_MODE_1BIT;
+		break;
+	default:
+		printf("error: %s invalid bus-width property %d\n",
+		       fdt_get_name(fdt, node, NULL), val);
+		return -ENOENT;
+	}
+
+	cfg->f_max = fdtdec_get_int(fdt, node, "max-frequency", 52000000);
+
+	if (fdtdec_get_bool(fdt, node, "cap-sd-highspeed"))
+		cfg->host_caps |= MMC_CAP(SD_HS);
+	if (fdtdec_get_bool(fdt, node, "cap-mmc-highspeed"))
+		cfg->host_caps |= MMC_CAP(MMC_HS);
+	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr12"))
+		cfg->host_caps |= MMC_CAP(UHS_SDR12);
+	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr25"))
+		cfg->host_caps |= MMC_CAP(UHS_SDR25);
+	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr50"))
+		cfg->host_caps |= MMC_CAP(UHS_SDR50);
+	if (fdtdec_get_bool(fdt, node, "sd-uhs-sdr104"))
+		cfg->host_caps |= MMC_CAP(UHS_SDR104);
+	if (fdtdec_get_bool(fdt, node, "sd-uhs-ddr50"))
+		cfg->host_caps |= MMC_CAP(UHS_DDR50);
+	if (fdtdec_get_bool(fdt, node, "mmc-ddr-1_8v"))
+		cfg->host_caps |= MMC_CAP(MMC_DDR_52);
+	if (fdtdec_get_bool(fdt, node, "mmc-hs200-1_8v"))
+		cfg->host_caps |= MMC_CAP(MMC_HS_200);
+
+	return 0;
+}
+
 struct mmc *mmc_get_mmc_dev(struct udevice *dev)
 {
 	struct mmc_uclass_priv *upriv;
diff --git a/include/mmc.h b/include/mmc.h
index 79be6b4..6230a32 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -651,6 +651,7 @@  int mmc_unbind(struct udevice *dev);
 int mmc_initialize(bd_t *bis);
 int mmc_init(struct mmc *mmc);
 int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error);
+int mmc_of_parse(const void *fdt, int node, struct mmc_config *cfg);
 int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
 
 /**